COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/test/minlengthpaths_test.cc @ 518:fcdb561b8c78

Last change on this file since 518:fcdb561b8c78 was 518:fcdb561b8c78, checked in by athos, 18 years ago

Started minlengthpaths_test, but it should not be here

File size: 1.5 KB
RevLine 
[201]1#include <iostream>
[518]2#include <list_graph.h>
3#include <minlengthpaths.h>
[201]4using namespace std;
[207]5using namespace hugo;
[513]6
[518]7
8
9int main()
10{
11
12 
13
[513]14bool passed = true;
15
[516]16void check(bool rc, char *msg="") {
[513]17  passed = passed && rc;
18  if(!rc) {
[516]19    std::cerr << "Test failed! ("<< msg << ")" << std::endl; \
20 
21
[513]22  }
23}
24
25
26
[201]27int main()
28{
[207]29
[518]30  typedef ListGraph::Node Node;
31  typedef ListGraph::Edge Edge;
[207]32
[518]33  ListGraph graph;
[201]34
[518]35  //Ahuja könyv példája
[201]36
[518]37  Node s=graph.addNode();
38  Node v2=graph.addNode();
39  Node v3=graph.addNode();
40  Node v4=graph.addNode();
41  Node v5=graph.addNode();
42  Node t=graph.addNode();
[201]43
[518]44  Edge s_v2=graph.addEdge(s, v2);
45  Edge s_v3=graph.addEdge(s, v3);
46  Edge v2_v4=graph.addEdge(v2, v4);
47  Edge v2_v5=graph.addEdge(v2, v5);
48  Edge v3_v5=graph.addEdge(v3, v5);
49  Edge v4_t=graph.addEdge(v4, t);
50  Edge v5_t=graph.addEdge(v5, t);
51 
[513]52
[518]53  ListGraph::EdgeMap<int> length(graph);
[513]54
[518]55  length.set(s_v2, 10);
56  length.set(s_v3, 10);
57  length.set(v2_v4, 5);
58  length.set(v2_v5, 1);
59  length.set(v3_v5, 5);
60  length.set(v4_t, 8);
61  length.set(v5_t, 8);
[513]62
[518]63  std::cout << "Minlengthpaths algorithm test..." << std::endl;
[513]64
[518]65 
66  int k=3;
67  MinLengthPaths<ListGraph, ListGraph::EdgeMap<int> >
68    surb_test(graph, length);
[513]69
[518]70  check(  surb_test.run(s,t,k) == 2 && suurb_test.totalLength == 46,"Two paths, total length should be 46");
[516]71
[518]72  k=1;
73  check(  surb_test.run(s,t,k) == 1 && suurb_test.totalLength == 19,"One path, total length should be 19");
[516]74
[518]75  cout << (passed ? "All tests passed." : "Some of the tests failed!!!")
76       << endl;
[516]77
[518]78  return passed ? 0 : 1;
[513]79
[201]80}
Note: See TracBrowser for help on using the repository browser.