diff --git a/CMakeLists.txt b/CMakeLists.txt index e63b35b1529e624d459094ed9e049472730592ac..90b954515e91fe8738b0f8fad7e6738e0aaab713 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,8 @@ project(GreedyAlgorithm) set(CMAKE_CXX_STANDARD 23) +add_definitions(-DDEBUG_TRANSIT_PRECOMPUTE) + add_executable(GreedyAlgorithm src/instance/graph/Node.cpp src/instance/graph/Node.h diff --git a/src/ShortestPath/Transit/TransitAlgorithmState.h b/src/ShortestPath/Transit/TransitAlgorithmState.h index bd06b3230912017ac4da10d6e1406e6fdabfb788..f0cfded693f0a72ad79cd40965d5232c1d54cce5 100644 --- a/src/ShortestPath/Transit/TransitAlgorithmState.h +++ b/src/ShortestPath/Transit/TransitAlgorithmState.h @@ -7,6 +7,7 @@ #include <array> +#include <cstdint> #include "../../instance/graph/LineStop.h" class TransitAlgorithmState { @@ -151,6 +152,25 @@ public: return *this; } + [[nodiscard]] std::string toString() const { + std::string res = "Node: " + std::to_string(_nodeIndex) + ", Instant: " + std::to_string(_instant); + + //Add line names in order if needed + if(!_connections.empty()) { + res += ", Connections: "; + if(_connections.size() > 1) { + for(int i = 0; i < _connections.size() - 1; ++i) { + res += _connections.at(i).getLineRef().getLineId() + " -> "; + } + } + + res += _connections.at(_connections.size() - 1).getLineRef().getLineId(); + + } + + return res; + } + }; diff --git a/src/ShortestPath/Transit/TransitShortestPathPrecompute.cpp b/src/ShortestPath/Transit/TransitShortestPathPrecompute.cpp index 1eaffdae06c951168dabbafd747999e07b11940e..1a6db6427c77302e40acd17e820364448dc85bb3 100644 --- a/src/ShortestPath/Transit/TransitShortestPathPrecompute.cpp +++ b/src/ShortestPath/Transit/TransitShortestPathPrecompute.cpp @@ -6,6 +6,13 @@ #include "TransitStateContainer.h" #include <queue> +#ifdef DEBUG_TRANSIT_PRECOMPUTE +#include <iostream> +#define DEBUG_MSG(str) do { std::cout << str << std::endl; } while( false ) +#else +#define DEBUG_MSG(str) do { } while ( false ) +#endif + //TODO: // Tests : // - priority queue order @@ -27,6 +34,8 @@ TransitStateContainer TransitShortestPathPrecompute::executeAlgorithm(const Grap currentState = statePriorityQueue.top(); statePriorityQueue.pop(); if(!solutionsContainer.getBestSolution(currentState.getNodeIndex()).strictlyDominates(currentState)) { + DEBUG_MSG("Comparing state " + currentState.toString() + " and \n" + solutionsContainer.getBestSolution(currentState.getNodeIndex()).toString()); + DEBUG_MSG("State isn't dominated, trying to extend it"); for (auto& lineStop : graph.getNode(currentState.getNodeIndex()).getPTLinesSet()) { int nextNode = lineStop.getNextNodeIndex(); @@ -48,8 +57,11 @@ TransitStateContainer TransitShortestPathPrecompute::executeAlgorithm(const Grap newState.setInstant(lineStop.getLineRef().getInstant(lineStop.getStopIndex() + 1, currentState.getPassageIndex())); //replace time with } + DEBUG_MSG("Created new state " + newState.toString()); + //Add new state to the solution container and the priority queue if it's not strictly dominated by an existing solution if(!solutionsContainer.getBestSolution(currentState.getNodeIndex()).strictlyDominates(currentState)) { + DEBUG_MSG("Candidate state " + newState.toString() + " is being added to solution container and priority queue"); solutionsContainer.tryAddNewState(nextNode, newState); statePriorityQueue.emplace(newState); } diff --git a/test/debug.cpp b/test/debug.cpp index a8a617b5a232276814475fef844430a274d34e0f..dfc3ba10be74b155f22633dd655e5a6612099706 100644 --- a/test/debug.cpp +++ b/test/debug.cpp @@ -12,7 +12,7 @@ int main() { // "../resources/test/instances/basic_debug_instance/PT_lines.csv"); // std::string instanceFolder = "basic_debug_instance/"; - std::string instanceFolder = "two_lines_debug_instance/"; + std::string instanceFolder = "contiguous_lines_debug_instance/"; std::string datFile = "graph.dat"; Graph graphFromSingleFile("../resources/test/instances/" + instanceFolder + datFile);