Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void StaticSimulationClass::startSimulation()
- {
- /*for(long long i = 0; i<nodes.size(); ++i)
- {
- nodes[i].addEnergyPoints(i);
- nodes[i].addConflict(i+1);
- nodes[i].changeStatus();
- }*/
- clock_t s, f;
- srand((unsigned int) time( NULL ));
- unsigned long randSlot = 0; // random slot
- unsigned long tempSize = 0; // temporary W size
- s = clock();
- while(!checkNodes())
- {
- //cout << endl << "ROUND: " << numberOfRounds << endl;
- for(auto i : nodes)
- {
- if(!i->getSendingStatus()) // true if sending status is false; the package was not sent
- {
- randSlot = rand() % W->size();
- //cout <<"NodeID :" << i.getId() << " RandomSlot: " << randSlot << endl;//" W.size() = " << W->size() << endl;
- nodes[i->getId()]->addEnergyPoints();
- if(W->at(randSlot) != -1) // if true, we have conflict
- {
- //cout << "Conflict on slot " << randSlot << endl;
- nodes[i->getId()]->addConflict();
- W->at(randSlot) = -2;
- numberOfConflicts++;
- }
- else // no conflict, assign node id to slot
- {
- W->at(randSlot) = i->getId();
- }
- }
- }
- for(int i = 0; i<W->size(); ++i)
- {
- if(W->at(i) != -2 && W->at(i) != -1)
- nodes[W->at(i)]->changeStatus();
- }
- numberOfRounds++;
- tempSize = W->size();
- W->clear();
- W->resize(2*tempSize, -1);
- }
- f = clock();
- //cout << endl << endl;
- //cout << "End of the simulation." << endl;
- timeOfRunning = f-s;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement