Line data Source code
1 : #include "Static/algos/DijkstraAoN.hpp" 2 : 3 : #include <exception> 4 : #include <iostream> 5 : #include <memory> 6 : 7 : #include "Alg/ShortestPath/DijkstraMany.hpp" 8 : 9 : using namespace std; 10 : using namespace Static; 11 : using namespace Alg; 12 : using namespace Alg::ShortestPath; 13 : 14 : typedef Network::Node Node; 15 : 16 9 : SolutionBase DijkstraAoN::solve( 17 : const Network &supply, 18 : const Demand &demand, 19 : const Solution &x0 20 : ) { 21 9 : Graph G = supply.toGraph(x0); 22 : 23 18 : const vector<Node> startNodes = demand.getStartNodes(); 24 : 25 18 : DijkstraMany shortestPaths; 26 9 : shortestPaths.solve(G, startNodes); 27 : 28 9 : SolutionBase x; 29 : 30 18 : for(const Node &u: startNodes) { 31 18 : const vector<Node> endNodes = demand.getDestinations(u); 32 18 : for(const Node &v: endNodes) { 33 18 : Graph::Path path = shortestPaths.getPath(u, v); 34 : 35 9 : if(path.size() == 1 && path.front().id == Graph::EDGE_INVALID.id) 36 0 : throw logic_error("Could not find path " + to_string(u) + "->" + to_string(v)); 37 : 38 18 : Network::Path pathNetwork; 39 9 : pathNetwork.reserve(path.size()); 40 22 : for(const Graph::Edge &e: path) 41 13 : pathNetwork.push_back(e.id); 42 : 43 9 : Flow f = demand.getDemand(u, v); 44 9 : x.addPath(pathNetwork, f); 45 : } 46 : } 47 : 48 18 : return x; 49 : }