# HG changeset patch # User athos # Date 1109870307 0 # Node ID a1abe9452199f592e2384632e4027491595ca08c # Parent 848b6006941df737532f8c19afe4d6ca4c33c3ec Added two demo programs: of course they are not considered to be complete or finished in any sense. diff -r 848b6006941d -r a1abe9452199 src/demo/dijkstra_demo.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/demo/dijkstra_demo.cc Thu Mar 03 17:18:27 2005 +0000 @@ -0,0 +1,75 @@ +#include + +#include +#include + +using namespace lemon; + + +int main (int, char*[]) +{ + + typedef ListGraph Graph; + typedef Graph::Node Node; + typedef Graph::Edge Edge; + typedef Graph::EdgeMap LengthMap; + + Graph g; + + //An example from Ahuja's book + + Node s=g.addNode(); + Node v2=g.addNode(); + Node v3=g.addNode(); + Node v4=g.addNode(); + Node v5=g.addNode(); + Node t=g.addNode(); + + Edge s_v2=g.addEdge(s, v2); + Edge s_v3=g.addEdge(s, v3); + Edge v2_v4=g.addEdge(v2, v4); + Edge v2_v5=g.addEdge(v2, v5); + Edge v3_v5=g.addEdge(v3, v5); + Edge v4_t=g.addEdge(v4, t); + Edge v5_t=g.addEdge(v5, t); + + LengthMap len(g); + + len.set(s_v2, 10); + len.set(s_v3, 10); + len.set(v2_v4, 5); + len.set(v2_v5, 8); + len.set(v3_v5, 5); + len.set(v4_t, 8); + len.set(v5_t, 8); + + std::cout << "The id of s is " << g.id(s)<< ", the id of t is " << g.id(t)<<"."< dijkstra_test(g,len); + + dijkstra_test.run(s); + + + std::cout << "The distance of node t from node s: " << dijkstra_test.dist(t)< +#include + +#include +#include +#include + + +using namespace std; +using namespace lemon; + + +int main() { + + typedef ListGraph::Node Node; + typedef ListGraph::Edge Edge; + typedef ListGraph::NodeIt NodeIt; + typedef ListGraph::EdgeIt EdgeIt; + + ListGraph G; + + Node s=G.addNode(); + Node v1=G.addNode(); + Node v2=G.addNode(); + Node v3=G.addNode(); + Node v4=G.addNode(); + Node t=G.addNode(); + + Edge e1 = G.addEdge(s, v1); + Edge e2 = G.addEdge(s, v2); + Edge e3 = G.addEdge(v1, v2); + Edge e4 = G.addEdge(v2, v1); + Edge e5 = G.addEdge(v1, v3); + Edge e6 = G.addEdge(v3, v2); + Edge e7 = G.addEdge(v2, v4); + Edge e8 = G.addEdge(v4, v3); + Edge e9 = G.addEdge(v3, t); + Edge e10 = G.addEdge(v4, t); + + typedef ListGraph::EdgeMap ECostMap; + typedef ListGraph::EdgeMap EBoolMap; + + ECostMap edge_cost_map(G, 2); + EBoolMap tree_map(G); + + + //Test with const map. + std::cout << "The weight of the minimum spanning tree is " << kruskalEdgeMap(G, ConstMap(2), tree_map)< tree_edge_vec; + + //Test with a edge map and inserter. + check(kruskalEdgeMap_IteratorOut(G, edge_cost_map, + back_inserter(tree_edge_vec)) + ==-31, + "Total cost should be -31."); + + tree_edge_vec.clear(); + + //The above test could also be coded like this: + check(kruskal(G, + makeKruskalMapInput(G, edge_cost_map), + makeKruskalSequenceOutput(back_inserter(tree_edge_vec))) + ==-31, + "Total cost should be -31."); + + check(tree_edge_vec.size()==5,"The tree should have 5 edges."); + + check(tree_edge_vec[0]==e1 && + tree_edge_vec[1]==e2 && + tree_edge_vec[2]==e5 && + tree_edge_vec[3]==e7 && + tree_edge_vec[4]==e9, + "Wrong tree."); +*/ + return 0; +}