本文整理汇总了C++中Firm::getproductivity方法的典型用法代码示例。如果您正苦于以下问题:C++ Firm::getproductivity方法的具体用法?C++ Firm::getproductivity怎么用?C++ Firm::getproductivity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Firm
的用法示例。
在下文中一共展示了Firm::getproductivity方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addFirms
void Graph::addFirms(int cycleNum, std::vector<Firm*> firms){
for(int i = 0; i < firms.size();i++){
std::string dk = getDataKey("type","firm");
dk += getDataKey("cycleNum",intToStr(cycleNum));
Firm* firm = firms.at(i);
dk+= getDataKey("numIndividuals",intToStr((int)firm->employees.size()));
dk+= getDataKey("avgProductivity",intToStr(firm->getproductivity()));
dk+= getDataKey("unitsLeft",intToStr((int)firm->unitsLeft));
dk+= getDataKey("capital",intToStr(firm->capital));
dk+= getDataKey("firmId",intToStr(firm->id));
addNode(dk,"Cycle-"+intToStr(cycleNum)+"-Firm-"+intToStr(firm->id));
std::string thisCycle = cycles.at(cycles.size()-1).id;
std::string thisFirm = nodes.at(nodes.size()-1).id;
addEdge(thisCycle,thisFirm, str_existsin,(str_existsin+"-"+intToStr(cycleNum)));
addIndividuals(cycleNum,firm,thisFirm);
}
buildTrades(cycleNum,firms);
}
示例2: cycle
void BusinessCycle::cycle()
{
/*
firms create
If a firm realizes there is no product within a suitable modicum of acceptance, they may invest a certain % of their capital to create a new firm
The mother firm may take starting individuals from the unemployment pool to seed the child firm’s ranks
*/
for(int i = 0; i < firmindex.size(); i++) {
//this firm
Firm* firm = firmindex.at(i);
double productivity = firm->getproductivity();
firm->timeUntraded++;
//get a list of employees with which to work
std::vector<Individual*> empls = firm->getemployees();
//hire fire threshold
double hft = (double)config->get_hire_fire_threshold()/100.0;
//hire fire rate
int hfr = (int)((double)empls.size() * hft);
if(hfr = 0) hfr = 2;
//best product for this firm
Firm* hasBestProduct = firmindex.at(0);
while(hasBestProduct->id == firm->id)
hasBestProduct = firmindex.at(getRandomInt(0,firmindex.size()));
//how close the product is to what is required
double bestDist = 1.0;
//find the best product for this firm
for(int j = 0; j < firmindex.size(); j++) {
if(firmindex.at(j)->unitsLeft > 0 && firmindex.at(j)->id != firm->id) {
gType tempProd = firmindex.at(j)->companyProduct;
double dist = (double)getHammingDistance(tempProd, firm->rawProduct)/(double)tempProd.size();
if(dist < bestDist) {
bestDist = dist;
hasBestProduct = firmindex.at(j);
}
}
}
double q = (double)(100 - config->get_modicum_of_acceptance())/100.0;
if(config->get_avg_starting_capital()/2 < firm->capital && bestDist < q) {
double starting = firm->capital / 2;
firm->capital -= starting;
gType prod = firm->rawProduct;
std::vector<Individual*> startingPpl;
Individual* tempEmp;
for(int c = 0; c < unemployed.size(); c++) {
if((double)unemployed.at(c)->getproductivity(prod) > 1.0-hft/2) {
tempEmp = unemployed.at(c);
startingPpl.push_back(tempEmp);
unemployed.erase(unemployed.begin() + c);
}
else c++;
}
Firm* newFirm = new Firm(0, config->get_start_individuals());
newFirm->unitsLeft = 100;
newFirm->companyProduct = prod;
newFirm->capital = starting;
firmindex.push_back(newFirm);
}
//how much does the product cost?: (quality of raw)
firm->productCost = 1.0;//-bestDist;
//while there is product left and the firm has enough money to purchase it
int raw = 0;
//std::cout << "\n---Firm "<<firm->id << "---\n" <<"\nRaw units available: " << hasBestProduct->unitsLeft << "\n";
double before = firm->capital;
while(hasBestProduct->unitsLeft > 0 && firm->capital >= hasBestProduct->productCost) {
//make it so
hasBestProduct->unitsLeft--;
hasBestProduct->capital += hasBestProduct->productCost;
firm->capital -= hasBestProduct->productCost;
raw++;
}
firm->buysFrom = hasBestProduct;
double after = firm->capital;
//std::cout << "Raw units acquired: " << raw << " from Firm: "<< hasBestProduct->id <<"\n";
//how much product is produced?: (int)(productivity)(qty of raw purchased)*(#employees)
firm->unitsLeft += (int)(((double)productivity+.5)*(double)raw);
//std::cout << "Firm " << firm->id << " created " << (int)((double)productivity*(double)raw) << " units.\n";
//std::cout << "Firm " << firm->id << " has " << firm->unitsLeft << " units that will sell for " << firm->productCost <<" each.\n";
//std::cout << "Our cost was: " << getDelta(before,after) << ". \n";
hasBestProduct->timeUntraded = 0;
//money += qtypurchased*(quality of raw)
//individuals mentor
//declare the product for each employee so we can sort based on productivity
firm->employeeProductUpdate();
std::vector<Individual*> mentors;
// get the number of people who will be mentoring
int numMentors = (int)(empls.size()*(double)config->get_modicum_of_acceptance()/100.0);
//std::cout << firmindex.at(i)->getemployees().size()<<"\n";
firm->sortEmployees();
//get the mentors
for(int j = 0; j < numMentors; j++) {
//a certain percentage of individuals within the firm whose skill sets match the product type most closely
//must mentor new individuals who start at an initial age
if(!empls.at(j)->isRetired()) {
mentors.push_back(empls.at(j));
}
}
//.........这里部分代码省略.........