int Population::starSimulation(int timeSimulation, double maxThreshold){ this->thresholdToBuy = maxThreshold; srand((unsigned)time(NULL)); // Loop for time for(int time = 0; time < timeSimulation; time++) { // Loop for evaluate every agent cout << "Iteration #: " << time << endl; for (int i = 0; i < this->totalPopulation; i++) { Agent *testAgent = &listOfAgent.at(i); /*First, if Agent threshold is less than global threshold, Agent buys if not, then Agent will question random agent */ if(!testAgent->getBuyState()) { if (testAgent->getThreshold() < thresholdToBuy) { // Change Agent's buy state to TRUE testAgent->setBuyState(true); cout << " Agent #: " << i << " Bought without ask" << endl; } else { //Chose a random Agent int randomAgent = (rand() % (int) (this->totalPopulation)); // Get a random Agent Agent *toAskAgent = &listOfAgent.at(randomAgent); // After Agent ask, It will take a desicion based on Random Agent's threshold if (toAskAgent->getThreshold() < thresholdToBuy) { // Change Agent's buy state to TRUE testAgent->setBuyState(true); cout << " Agent #: " << i << " Bought asking to Agent " << randomAgent << endl; } } } } } }