3 * This file is a part of LEMON, a generic C++ optimization library
5 * Copyright (C) 2003-2006
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
9 * Permission to use, modify and distribute this software is granted
10 * provided that this copyright notice appears in all copies. For
11 * precise terms see the accompanying LICENSE file.
13 * This software is provided "AS IS" with no warranty of any kind,
14 * express or implied, and with no claim as to its suitability for any
21 ///\brief Demonstrating the usage of LEMON's Dijkstra algorithm
23 /// Dijkstra's algorithm computes shortest paths between two nodes in
24 /// a graph with edge lengths. Here we only show some of the
25 /// facilities supplied by our implementation: for the detailed
26 /// documentation of the LEMON Dijkstra class read \ref lemon::Dijkstra "this".
28 /// \include dijkstra_demo.cc
31 #include <lemon/list_graph.h>
32 #include <lemon/csp.h>
33 #include <lemon/random.h>
36 using namespace lemon;
39 int main (int, char*[])
42 typedef ListGraph Graph;
43 typedef Graph::Node Node;
44 typedef Graph::Edge Edge;
45 typedef Graph::EdgeIt EdgeIt;
46 typedef Graph::EdgeMap<double> LengthMap;
52 std::vector<Node> nodes;
53 std::vector<Edge> edges;
55 for(int i=0;i<N;i++) nodes.push_back(g.addNode());
58 edges.push_back(g.addEdge(nodes[rnd[N]],nodes[rnd[N]]));
62 for(EdgeIt e(g);e!=INVALID;++e)
64 cost[e]=0.01+rnd(.99);
65 delay[e]=0.01+rnd(.99);
68 ConstrainedShortestPath<Graph,LengthMap,LengthMap> csp(g,cost,delay);
69 for(double d=0;d<2;d+=.01)
72 std::cout << d << ": ";
73 SimplePath<Graph> r = csp.larac(nodes[0],nodes[1],d,lo_bo);
74 if(r.empty()) std::cout << "INFEASIBLE\n";
75 else std::cout << "delay: " << csp.delay(r)
76 << " cost: " << csp.cost(r)
78 << " gap: " << csp.cost(r)-lo_bo
79 << " , " << (csp.cost(r)-lo_bo)/csp.cost(r)*100