Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void BFS(char * buff, NodeTuple64 root, HANDLE robot) {
- //queue<NodeTuple64> undiscovered;
- done = false;
- map<uint64, uint64>::iterator it;
- WaitForSingleObject(sema, INFINITE);
- WaitForSingleObject(mutex, INFINITE);
- if (Q.empty()){
- cout << "found empty queue..." << endl;
- Q.push(root);
- visited.insert(pair<uint64, uint64>(root.node, root.node));
- }
- ReleaseMutex(mutex);
- while (!done){
- WaitForSingleObject(mutex, INFINITY);
- NodeTuple64 x = Q.front();
- cout << "Current room: " << x.node << endl << "Current intensity: " << x.intensity << endl;
- if (!Q.empty()){
- Q.pop();
- }
- ReleaseMutex(mutex);
- char * neighbors = move(buff, x.node, robot);
- if (endFound(neighbors)) { //Check if current node has len = 0
- return;
- };
- vector<NodeTuple64> rooms = getNeighbors(neighbors);
- WaitForSingleObject(mutex, INFINITE);
- int counter = 0;
- for (int i = 0; i < rooms.size(); i++){
- it = visited.find(rooms[i].node);
- if (it == visited.end()){ //If at end, rooms[i] not found in visited
- counter ++;
- Q.push(rooms[i]);
- visited.insert(pair<uint64, uint64>(rooms[i].node, rooms[i].node));
- }
- }
- ReleaseMutex(mutex);
- ReleaseSemaphore(sema, counter, NULL);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement