/* ~~~ FUNCTION (public) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * This function computes the route to the next vertex to explore. * * INPUTS: * currentVertex - The current vertex in the maze. * * OUTPUTS: * outputRoute - This will be populated with a fastest route from the current vertex to the next * vertex to explore. * * RETURNS: * A boolean value. * If true then there remain vertices to explore and outputRoute is outputted as above. * If false then there are no more vertices to explore and outputRoute is set to empty. * */ bool CMazeMapper::ComputeNextVertex(const int& currentVertex, std::vector<int>& outputRoute) { DEBUG_METHOD(); // Generate graph from the CMap // TODO: Fix this when you now how you will generate the graph / receive the map vector< vector<double> > distanceMatrix; vector<int> vertexLabels; CGraph currentGraph { distanceMatrix, vertexLabels }; // Check there remain vertices to explore if (m_vertsToExplore.size() > 0) return false; // Find closest of the vertices left to explore int nextVertex { m_vertsToExplore[0] }; double currentFastestDist = currentGraph.ShortestDistance(currentVertex, m_vertsToExplore[0], true, outputRoute); for (unsigned int i = 1; i < m_vertsToExplore.size(); ++i) { vector<int> newOutputRoute; double newDist = currentGraph.ShortestDistance(currentVertex, m_vertsToExplore[i], true, newOutputRoute); if (newDist < currentFastestDist) { currentFastestDist = newDist; outputRoute = newOutputRoute; nextVertex = m_vertsToExplore[i]; } else if (newDist == currentFastestDist && VertexScore(m_vertsToExplore[i]) < VertexScore(nextVertex)) { // If there is a tie in distances, choose the one which is closest to the bottom left of the maze // If this is also a tie then do not update nextVertex. This is equivalent to choosing the vertex // which is closer to the top left. outputRoute = newOutputRoute; nextVertex = m_vertsToExplore[i]; } } return true; }