test/dfs_test.cc
author deba
Wed, 01 Mar 2006 10:25:30 +0000
changeset 1991 d7442141d9ef
parent 1875 98698b69a902
child 2111 ea1fa1bc3f6d
permissions -rw-r--r--
The graph adadptors can be alteration observed.
In most cases it uses the adapted graph alteration notifiers.
Only special case is now the UndirGraphAdaptor, where
we have to proxy the signals from the graph.

The SubBidirGraphAdaptor is removed, because it doest not
gives more feature than the EdgeSubGraphAdaptor<UndirGraphAdaptor<Graph>>.

The ResGraphAdaptor is based on this composition.
     1 /* -*- C++ -*-
     2  *
     3  * This file is a part of LEMON, a generic C++ optimization library
     4  *
     5  * Copyright (C) 2003-2006
     6  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     7  * (Egervary Research Group on Combinatorial Optimization, EGRES).
     8  *
     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.
    12  *
    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
    15  * purpose.
    16  *
    17  */
    18 
    19 #include "test_tools.h"
    20 #include <lemon/smart_graph.h>
    21 #include <lemon/dfs.h>
    22 #include <lemon/path.h>
    23 #include <lemon/concept/graph.h>
    24 
    25 using namespace lemon;
    26 
    27 const int PET_SIZE =5;
    28 
    29 
    30 void check_Dfs_SmartGraph_Compile() 
    31 {
    32   typedef concept::StaticGraph Graph;
    33 
    34   typedef Graph::Edge Edge;
    35   typedef Graph::Node Node;
    36   typedef Graph::EdgeIt EdgeIt;
    37   typedef Graph::NodeIt NodeIt;
    38  
    39   typedef Dfs<Graph> DType;
    40   
    41   Graph G;
    42   Node n;
    43   Edge e;
    44   int l;
    45   bool b;
    46   DType::DistMap d(G);
    47   DType::PredMap p(G);
    48   //  DType::PredNodeMap pn(G);
    49   
    50   DType dfs_test(G);
    51   
    52   dfs_test.run(n);
    53   
    54   l  = dfs_test.dist(n);
    55   e  = dfs_test.predEdge(n);
    56   n  = dfs_test.predNode(n);
    57   d  = dfs_test.distMap();
    58   p  = dfs_test.predMap();
    59   //  pn = dfs_test.predNodeMap();
    60   b  = dfs_test.reached(n);
    61 
    62   DirPath<Graph> pp(G);
    63   dfs_test.getPath(pp,n);
    64 }
    65 
    66 
    67 void check_Dfs_Function_Compile() 
    68 {
    69   typedef int VType;
    70   typedef concept::StaticGraph Graph;
    71 
    72   typedef Graph::Edge Edge;
    73   typedef Graph::Node Node;
    74   typedef Graph::EdgeIt EdgeIt;
    75   typedef Graph::NodeIt NodeIt;
    76   typedef concept::ReadMap<Edge,VType> LengthMap;
    77    
    78   dfs(Graph(),Node()).run();
    79   dfs(Graph()).source(Node()).run();
    80   dfs(Graph())
    81     .predMap(concept::WriteMap<Node,Edge>())
    82     .distMap(concept::WriteMap<Node,VType>())
    83     .reachedMap(concept::ReadWriteMap<Node,bool>())
    84     .processedMap(concept::WriteMap<Node,bool>())
    85     .run(Node());
    86   
    87 }
    88 
    89 int main()
    90 {
    91     
    92   typedef SmartGraph Graph;
    93 
    94   typedef Graph::Edge Edge;
    95   typedef Graph::Node Node;
    96   typedef Graph::EdgeIt EdgeIt;
    97   typedef Graph::NodeIt NodeIt;
    98   typedef Graph::EdgeMap<int> LengthMap;
    99 
   100   Graph G;
   101   Node s, t;
   102   PetStruct<Graph> ps = addPetersen(G,PET_SIZE);
   103    
   104   s=ps.outer[2];
   105   t=ps.inner[0];
   106   
   107   Dfs<Graph> dfs_test(G);
   108   dfs_test.run(s);  
   109   
   110   DirPath<Graph> p(G);
   111   check(dfs_test.getPath(p,t),"getPath() failed to set the path.");
   112   check(p.length()==dfs_test.dist(t),"getPath() found a wrong path.");
   113   
   114   for(NodeIt v(G); v!=INVALID; ++v) {
   115     check(dfs_test.reached(v),"Each node should be reached.");
   116     if ( dfs_test.predEdge(v)!=INVALID ) {
   117       Edge e=dfs_test.predEdge(v);
   118       Node u=G.source(e);
   119       check(u==dfs_test.predNode(v),"Wrong tree.");
   120       check(dfs_test.dist(v) - dfs_test.dist(u) == 1,
   121 	    "Wrong distance. (" << dfs_test.dist(u) << "->" 
   122 	    <<dfs_test.dist(v) << ')');
   123     }
   124   }
   125 }
   126