Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.25 KB | None | 0 0
  1. void BFS(char * buff, NodeTuple64 root, HANDLE robot) {
  2.         //queue<NodeTuple64> undiscovered;
  3.         done = false;
  4.         map<uint64, uint64>::iterator it;
  5.         WaitForSingleObject(sema, INFINITE);
  6.         WaitForSingleObject(mutex, INFINITE);
  7.         if (Q.empty()){
  8.             cout << "found empty queue..." << endl;
  9.         Q.push(root);
  10.         visited.insert(pair<uint64, uint64>(root.node, root.node));
  11.         }
  12.         ReleaseMutex(mutex);
  13.  
  14.         while (!done){
  15.             WaitForSingleObject(mutex, INFINITY);
  16.             NodeTuple64 x = Q.front();
  17.             cout << "Current room: " << x.node << endl << "Current intensity: " << x.intensity << endl;
  18.             if (!Q.empty()){
  19.                 Q.pop();
  20.             }
  21.             ReleaseMutex(mutex);
  22.             char * neighbors = move(buff, x.node, robot);
  23.            
  24.             if (endFound(neighbors)) { //Check if current node has len = 0
  25.                 return;
  26.             };
  27.             vector<NodeTuple64> rooms = getNeighbors(neighbors);
  28.             WaitForSingleObject(mutex, INFINITE);
  29.             int counter = 0;
  30.             for (int i = 0; i < rooms.size(); i++){
  31.                 it = visited.find(rooms[i].node);
  32.                 if (it == visited.end()){ //If at end, rooms[i] not found in visited
  33.                     counter ++;
  34.                     Q.push(rooms[i]);
  35.                     visited.insert(pair<uint64, uint64>(rooms[i].node, rooms[i].node));
  36.                 }
  37.             }
  38.         ReleaseMutex(mutex);
  39.         ReleaseSemaphore(sema, counter, NULL);
  40.         }
  41.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement