Advertisement
Guest User

Untitled

a guest
Nov 27th, 2015
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.75 KB | None | 0 0
  1. void StaticSimulationClass::startSimulation()
  2. {
  3.     /*for(long long i = 0; i<nodes.size(); ++i)
  4.     {
  5.         nodes[i].addEnergyPoints(i);
  6.         nodes[i].addConflict(i+1);
  7.         nodes[i].changeStatus();
  8.     }*/
  9.     clock_t s, f;
  10.     srand((unsigned int) time( NULL ));
  11.     unsigned long randSlot = 0;  // random slot
  12.     unsigned long tempSize = 0; // temporary W size
  13.     s = clock();
  14.     while(!checkNodes())
  15.     {
  16.         //cout << endl << "ROUND: " << numberOfRounds << endl;
  17.         for(auto i : nodes)
  18.         {
  19.             if(!i->getSendingStatus()) // true if sending status is false; the package was not sent
  20.             {
  21.                 randSlot = rand() % W->size();
  22.                 //cout <<"NodeID :" << i.getId() << " RandomSlot: " << randSlot << endl;//" W.size() = " << W->size() << endl;
  23.                 nodes[i->getId()]->addEnergyPoints();
  24.                 if(W->at(randSlot) != -1)  // if true, we have conflict
  25.                 {
  26.                     //cout << "Conflict on slot " << randSlot << endl;
  27.                     nodes[i->getId()]->addConflict();
  28.                     W->at(randSlot) = -2;
  29.                     numberOfConflicts++;
  30.                 }
  31.                 else  // no conflict, assign node id to slot
  32.                 {
  33.                     W->at(randSlot) = i->getId();
  34.                 }
  35.             }
  36.         }
  37.         for(int i = 0; i<W->size(); ++i)
  38.         {
  39.             if(W->at(i) != -2 && W->at(i) != -1)
  40.                 nodes[W->at(i)]->changeStatus();
  41.         }
  42.         numberOfRounds++;
  43.         tempSize = W->size();
  44.         W->clear();
  45.         W->resize(2*tempSize, -1);
  46.     }
  47.     f = clock();
  48.     //cout << endl << endl;
  49.     //cout << "End of the simulation." << endl;
  50.     timeOfRunning = f-s;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement