Nasty bug in undir_graph_extender.h
authorklao
Fri, 07 Jan 2005 18:53:02 +0000
changeset 10607a24bb2e7480
parent 1059 bd97feae7d90
child 1061 e3433c024123
Nasty bug in undir_graph_extender.h
src/lemon/undir_graph_extender.h
src/work/jacint/bug.cc
     1.1 --- a/src/lemon/undir_graph_extender.h	Fri Jan 07 08:50:38 2005 +0000
     1.2 +++ b/src/lemon/undir_graph_extender.h	Fri Jan 07 18:53:02 2005 +0000
     1.3 @@ -140,53 +140,55 @@
     1.4  
     1.5      template <typename E>
     1.6      void _dirFirstOut(E &e, const Node &n) const {
     1.7 -      Parent::firstOut(e,n);
     1.8 +      Parent::firstIn(e,n);
     1.9        if( UndirEdge(e) != INVALID ) {
    1.10 -	e.forward = true;
    1.11 +	e.forward = false;
    1.12        }
    1.13        else {
    1.14 -	Parent::firstIn(e,n);
    1.15 -	e.forward = false;
    1.16 +	Parent::firstOut(e,n);
    1.17 +	e.forward = true;
    1.18        }
    1.19      }
    1.20      template <typename E>
    1.21      void _dirFirstIn(E &e, const Node &n) const {
    1.22 -      Parent::firstIn(e,n);
    1.23 +      Parent::firstOut(e,n);
    1.24        if( UndirEdge(e) != INVALID ) {
    1.25 -	e.forward = true;
    1.26 +	e.forward = false;
    1.27        }
    1.28        else {
    1.29 -	Parent::firstOut(e,n);
    1.30 -	e.forward = false;
    1.31 +	Parent::firstIn(e,n);
    1.32 +	e.forward = true;
    1.33        }
    1.34      }
    1.35  
    1.36      template <typename E>
    1.37      void _dirNextOut(E &e) const {
    1.38 -      if( e.forward ) {
    1.39 +      if( ! e.forward ) {
    1.40 +	Node n = Parent::target(e);
    1.41 +	Parent::nextIn(e);
    1.42 +	if( UndirEdge(e) == INVALID ) {
    1.43 +	  Parent::firstOut(e, n);
    1.44 +	  e.forward = true;
    1.45 +	}
    1.46 +      }
    1.47 +      else {
    1.48 +	Parent::nextOut(e);
    1.49 +      }
    1.50 +    }
    1.51 +    template <typename E>
    1.52 +    void _dirNextIn(E &e) const {
    1.53 +      if( ! e.forward ) {
    1.54 +	Node n = Parent::source(e);
    1.55  	Parent::nextOut(e);
    1.56  	if( UndirEdge(e) == INVALID ) {
    1.57 -	  Parent::firstIn(e, Parent::source(e));
    1.58 -	  e.forward = false;
    1.59 +	  Parent::firstIn(e, n);
    1.60 +	  e.forward = true;
    1.61  	}
    1.62        }
    1.63        else {
    1.64  	Parent::nextIn(e);
    1.65        }
    1.66      }
    1.67 -    template <typename E>
    1.68 -    void _dirNextIn(E &e) const {
    1.69 -      if( e.forward ) {
    1.70 -	Parent::nextIn(e);
    1.71 -	if( UndirEdge(e) == INVALID ) {
    1.72 -	  Parent::firstOut(e, Parent::target(e));
    1.73 -	  e.forward = false;
    1.74 -	}
    1.75 -      }
    1.76 -      else {
    1.77 -	Parent::nextOut(e);
    1.78 -      }
    1.79 -    }
    1.80  
    1.81    public:
    1.82  
    1.83 @@ -226,7 +228,7 @@
    1.84      }
    1.85  
    1.86  
    1.87 -    int maxId(Node n) const {
    1.88 +    int maxId(Node) const {
    1.89        return Parent::maxId(Node());
    1.90      }
    1.91  
     2.1 --- a/src/work/jacint/bug.cc	Fri Jan 07 08:50:38 2005 +0000
     2.2 +++ b/src/work/jacint/bug.cc	Fri Jan 07 18:53:02 2005 +0000
     2.3 @@ -1,4 +1,3 @@
     2.4 -//lasd megjegyzes a 49-es sorban
     2.5  #include <iostream>
     2.6  #include <queue>
     2.7  #include <vector>
     2.8 @@ -6,23 +5,28 @@
     2.9  
    2.10  #include <lemon/invalid.h>
    2.11  #include <lemon/list_graph.h>
    2.12 +#include <lemon/smart_graph.h>
    2.13  #include <matching.h>
    2.14  
    2.15  using namespace lemon;
    2.16 +using namespace std;
    2.17  
    2.18 -int main(int, char **) {
    2.19  
    2.20 -  typedef UndirListGraph Graph;
    2.21 +int main() {
    2.22 +
    2.23 +  typedef UndirSmartGraph Graph;
    2.24  
    2.25    typedef Graph::Edge Edge;
    2.26    typedef Graph::UndirEdgeIt UndirEdgeIt;
    2.27    typedef Graph::IncEdgeIt IncEdgeIt;
    2.28    typedef Graph::NodeIt NodeIt;
    2.29    typedef Graph::Node Node;
    2.30 +
    2.31 +  typedef Graph::OutEdgeIt OutEdgeIt;
    2.32     
    2.33    Graph G;
    2.34  
    2.35 -  G.clear();
    2.36 +  // G.clear();
    2.37    std::vector<Graph::Node> nodes;
    2.38    for (int i=0; i<5; ++i)
    2.39        nodes.push_back(G.addNode());
    2.40 @@ -35,7 +39,8 @@
    2.41    G.addEdge(nodes[2], nodes[4]);
    2.42  
    2.43    for(UndirEdgeIt e(G); e!=INVALID; ++e) {
    2.44 -    std::cout<<G.id(e)<<" : "<<G.id(G.source(e))<<" " <<G.id(G.target(e))<<std::endl;
    2.45 +    std::cout<<G.id(e)<<" : "<<G.id(G.source(e))
    2.46 +	     <<" " <<G.id(G.target(e))<<std::endl;
    2.47    }
    2.48  
    2.49    std::cout <<"Nodes:"<<std::endl;
    2.50 @@ -44,11 +49,32 @@
    2.51      std::cout<<G.id(v)<<std::endl;
    2.52    }
    2.53  
    2.54 +  cout << "Dev Out edges from node " << G.id(nodes[1])<<std::endl;
    2.55 +  Edge f;
    2.56 +  for(G.firstOut(f, nodes[1]); f!=INVALID; G.nextOut(f)) {
    2.57 +    cout<<"edge " << G.id(f) << " goes"
    2.58 +	     <<" from "<< G.id(G.source(f)) 
    2.59 +	     << " to " << G.id(G.target(f))<<std::endl;
    2.60 +  }
    2.61 +
    2.62 +  cout << "Out edges from node " << G.id(nodes[1])<<std::endl;
    2.63 +  for( OutEdgeIt f(G,nodes[1]); f!=INVALID; ++f ) {
    2.64 +    cout<<"edge " << G.id(f) << " goes"
    2.65 +	     <<" from "<< G.id(G.source(f)) 
    2.66 +	     << " to " << G.id(G.target(f))<<std::endl;
    2.67 +  }
    2.68 +
    2.69    std::cout<<"Edges of node " << G.id(nodes[1])<<std::endl;
    2.70 +  for( IncEdgeIt f(G,nodes[1]); f!=INVALID; ++f ) {
    2.71 +    cout<<"edge " << G.id(f) << " goes"
    2.72 +	     <<" from "<< G.id(G.source(f)) 
    2.73 +	     << " to " << G.id(G.target(f))<<std::endl;
    2.74 +  }
    2.75  
    2.76 -  for( IncEdgeIt f(G,nodes[1]); f!=INVALID; ++f ) {
    2.77 -    std::cout<<"edge " << G.id(f)<< " goes to " << G.id(G.target(f))<<std::endl;
    2.78 -  }//ez a ket for ciklus meg lefut - bar hibas eleken iteral -, de a matching.h-s mar segfaultol
    2.79 +  //return 0;
    2.80 +
    2.81 +  //ez a ket for ciklus meg lefut - bar hibas eleken iteral -, de a
    2.82 +  //matching.h-s mar segfaultol
    2.83  
    2.84    for( IncEdgeIt f(G,nodes[1]); f!=INVALID; ++f ) {
    2.85      std::cout<<"edge " << G.id(f)<< " goes to " << G.id(G.target(f))<<std::endl;