COIN-OR::LEMON - Graph Library

Changeset 2335:27aa03cd3121 in lemon-0.x for test


Ignore:
Timestamp:
01/08/07 11:39:59 (17 years ago)
Author:
Balazs Dezso
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@3123
Message:

New path concept and path structures

TODO: BellmanFord::negativeCycle()

Location:
test
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • test/all_pairs_shortest_path_test.cc

    r2269 r2335  
    2929
    3030#include <lemon/fib_heap.h>
     31
     32#include <lemon/path.h>
    3133
    3234#include <lemon/time_measure.h>
     
    9193  }   
    9294
     95  bool checked_path = false;
     96
    9397  for (NodeIt it(graph); it != INVALID; ++it) {
    9498    for (NodeIt jt(graph); jt != INVALID; ++jt) {
     
    98102            "Wrong connection in all pairs shortest path");
    99103      if (johnson.connected(it, jt)) {
     104        if (it != jt && !checked_path) {
     105          {
     106            Path<Graph> path = johnson.path(it, jt);
     107            check(checkPath(graph, path), "Wrong path.");
     108            check(pathSource(graph, path) == it, "Wrong path.");
     109            check(pathTarget(graph, path) == jt, "Wrong path.");
     110          }
     111          {
     112            Path<Graph> path = floyd.path(it, jt);
     113            check(checkPath(graph, path), "Wrong path.");
     114            check(pathSource(graph, path) == it, "Wrong path.");
     115            check(pathTarget(graph, path) == jt, "Wrong path.");
     116          }
     117          checked_path = true;
     118          std::cout << "Path checked" << std::endl;
     119        }
    100120        check(johnson.dist(it, jt) == floyd.dist(it, jt),
    101121              "Wrong distance in all pairs shortest path");
  • test/bfs_test.cc

    r2260 r2335  
    6060  b  = bfs_test.reached(n);
    6161
    62   Path<Graph> pp(G);
    63   bfs_test.getPath(pp,n);
     62  Path<Graph> pp = bfs_test.path(n);
    6463}
    6564
     
    110109  check(bfs_test.dist(t)==3,"Bfs found a wrong path. " << bfs_test.dist(t));
    111110
    112   Path<Graph> p(G);
    113   check(bfs_test.getPath(p,t),"getPath() failed to set the path.");
     111  Path<Graph> p = bfs_test.path(t);
    114112  check(p.length()==3,"getPath() found a wrong path.");
     113  check(checkPath(G, p),"path() found a wrong path.");
     114  check(pathSource(G, p) == s,"path() found a wrong path.");
     115  check(pathTarget(G, p) == t,"path() found a wrong path.");
    115116 
    116117
  • test/dfs_test.cc

    r2260 r2335  
    6060  b  = dfs_test.reached(n);
    6161
    62   Path<Graph> pp(G);
    63   dfs_test.getPath(pp,n);
     62  Path<Graph> pp = dfs_test.path(n);
    6463}
    6564
     
    109108  dfs_test.run(s); 
    110109 
    111   Path<Graph> p(G);
    112   check(dfs_test.getPath(p,t),"getPath() failed to set the path.");
    113   check(p.length()==dfs_test.dist(t),"getPath() found a wrong path.");
     110  Path<Graph> p = dfs_test.path(t);
     111  check(p.length()==dfs_test.dist(t),"path() found a wrong path.");
     112  check(checkPath(G, p),"path() found a wrong path.");
     113  check(pathSource(G, p) == s,"path() found a wrong path.");
     114  check(pathTarget(G, p) == t,"path() found a wrong path.");
    114115 
    115116  for(NodeIt v(G); v!=INVALID; ++v) {
  • test/dijkstra_test.cc

    r2298 r2335  
    6464  b  = dijkstra_test.reached(n);
    6565
    66   Path<Graph> pp(G);
    67   dijkstra_test.getPath(pp,n);
     66  Path<Graph> pp = dijkstra_test.path(n);
    6867}
    6968
     
    121120
    122121
    123   Path<Graph> p(G);
    124   check(dijkstra_test.getPath(p,t),"getPath() failed to set the path.");
     122  Path<Graph> p = dijkstra_test.path(t);
    125123  check(p.length()==4,"getPath() found a wrong path.");
     124  check(checkPath(G, p),"path() found a wrong path.");
     125  check(pathSource(G, p) == s,"path() found a wrong path.");
     126  check(pathTarget(G, p) == t,"path() found a wrong path.");
    126127 
    127128
  • test/path_test.cc

    r2260 r2335  
    3232
    3333void check_concepts() {
    34   checkConcept<concepts::Path<concepts::Graph>,
    35     concepts::Path<concepts::Graph> >();
    36   checkConcept<concepts::Path<concepts::Graph>,
    37     Path<concepts::Graph> >();
     34  checkConcept<concepts::Path<ListGraph>, concepts::Path<ListGraph> >();
    3835  checkConcept<concepts::Path<ListGraph>, Path<ListGraph> >();
     36  checkConcept<concepts::Path<ListGraph>, SimplePath<ListGraph> >();
     37  checkConcept<concepts::Path<ListGraph>, StaticPath<ListGraph> >();
     38  checkConcept<concepts::Path<ListGraph>, ListPath<ListGraph> >();
    3939}
    4040
    4141int main() {
    42   check_concepts();
    43  
    44   ListGraph g;
    45  
    46   ListGraph::Node n1 = g.addNode();
    47   ListGraph::Node n2 = g.addNode();
    48   ListGraph::Node n3 = g.addNode();
    49   ListGraph::Node n4 = g.addNode();
    50   ListGraph::Node n5 = g.addNode();
    51  
    52   ListGraph::Edge e1 = g.addEdge(n1, n2);
    53   ListGraph::Edge e2 = g.addEdge(n2, n3);
    54   ListGraph::Edge e3 = g.addEdge(n3, n4);
    55   ListGraph::Edge e4 = g.addEdge(n4, n5);
    56   ListGraph::Edge e5 = g.addEdge(n5, n1);
    57 
    58   {
    59     Path<ListGraph> p(g);
    60 
    61     check(p.empty(), "Wrong Path");
    62     check(p.length() == 0, "Wrong Path");
    63    
    64     {
    65       Path<ListGraph>::Builder b(p);
    66       b.setStartNode(n3);
    67       b.commit();
    68     }
    69 
    70     check(!p.empty(), "Wrong Path");
    71     check(p.length() == 0, "Wrong Path");
    72     check(p.source() == n3, "Wrong Path");
    73     check(p.target() == n3, "Wrong Path");
    74 
    75     {
    76       Path<ListGraph>::Builder b(p);
    77       b.pushBack(e3);
    78       b.pushBack(e4);
    79       b.pushFront(e2);
    80       b.commit();
    81     }
    82 
    83     check(!p.empty(), "Wrong Path");
    84     check(p.length() == 3, "Wrong Path");
    85     check(p.source() == n2, "Wrong Path");
    86     check(p.target() == n5, "Wrong Path");
    87    
    88     {
    89       Path<ListGraph>::NodeIt it(p);
    90       check((ListGraph::Node)it == n2, "Wrong Path"); ++it;
    91       check((ListGraph::Node)it == n3, "Wrong Path"); ++it;
    92       check((ListGraph::Node)it == n4, "Wrong Path"); ++it;
    93       check((ListGraph::Node)it == n5, "Wrong Path"); ++it;
    94       check((ListGraph::Node)it == INVALID, "Wrong Path");
    95     }
    96 
    97     {
    98       Path<ListGraph>::EdgeIt it(p);
    99       check((ListGraph::Edge)it == e2, "Wrong Path"); ++it;
    100       check((ListGraph::Edge)it == e3, "Wrong Path"); ++it;
    101       check((ListGraph::Edge)it == e4, "Wrong Path"); ++it;
    102       check((ListGraph::Edge)it == INVALID, "Wrong Path");
    103     }
    104    
    105   }
    106  
     42  check_concepts(); 
    10743  return 0;
    10844}
Note: See TracChangeset for help on using the changeset viewer.