src/work/marci/experiment/graph_wrapper_1.h
changeset 1209 dc9fdf77007f
parent 921 818510fa3d99
equal deleted inserted replaced
3:e1b2c43e0cac 4:96a5a2ac44e1
    88       It e; this->first(e); return e; }
    88       It e; this->first(e); return e; }
    89 
    89 
    90     template< typename It > It first(const Node& v) const { 
    90     template< typename It > It first(const Node& v) const { 
    91       It e; this->first(e, v); return e; }
    91       It e; this->first(e, v); return e; }
    92 
    92 
    93     Node head(const Edge& e) const { return graph->head(e); }
    93     Node target(const Edge& e) const { return graph->target(e); }
    94     Node tail(const Edge& e) const { return graph->tail(e); }
    94     Node source(const Edge& e) const { return graph->source(e); }
    95 
    95 
    96     template<typename I> bool valid(const I& i) const { 
    96     template<typename I> bool valid(const I& i) const { 
    97       return graph->valid(i); }
    97       return graph->valid(i); }
    98   
    98   
    99     //template<typename I> void setInvalid(const I &i);
    99     //template<typename I> void setInvalid(const I &i);
   106       return graph->aNode(e); }
   106       return graph->aNode(e); }
   107     template<typename I> Node bNode(const I& e) const { 
   107     template<typename I> Node bNode(const I& e) const { 
   108       return graph->bNode(e); }
   108       return graph->bNode(e); }
   109   
   109   
   110     Node addNode() const { return graph->addNode(); }
   110     Node addNode() const { return graph->addNode(); }
   111     Edge addEdge(const Node& tail, const Node& head) const { 
   111     Edge addEdge(const Node& source, const Node& target) const { 
   112       return graph->addEdge(tail, head); }
   112       return graph->addEdge(source, target); }
   113   
   113   
   114     template<typename I> void erase(const I& i) const { graph->erase(i); }
   114     template<typename I> void erase(const I& i) const { graph->erase(i); }
   115   
   115   
   116     void clear() const { graph->clear(); }
   116     void clear() const { graph->clear(); }
   117     
   117     
   233       It e; this->first(e); return e; }
   233       It e; this->first(e); return e; }
   234 
   234 
   235     template< typename It > It first(const Node& v) const { 
   235     template< typename It > It first(const Node& v) const { 
   236       It e; this->first(e, v); return e; }
   236       It e; this->first(e, v); return e; }
   237 
   237 
   238     Node head(const Edge& e) const { return graph->head(e); }
   238     Node target(const Edge& e) const { return graph->target(e); }
   239     Node tail(const Edge& e) const { return graph->tail(e); }
   239     Node source(const Edge& e) const { return graph->source(e); }
   240 
   240 
   241     template<typename I> bool valid(const I& i) const { 
   241     template<typename I> bool valid(const I& i) const { 
   242       return graph->valid(i); }
   242       return graph->valid(i); }
   243   
   243   
   244     //template<typename I> void setInvalid(const I &i);
   244     //template<typename I> void setInvalid(const I &i);
   251       return graph->aNode(e); }
   251       return graph->aNode(e); }
   252     template<typename I> Node bNode(const I& e) const { 
   252     template<typename I> Node bNode(const I& e) const { 
   253       return graph->bNode(e); }
   253       return graph->bNode(e); }
   254   
   254   
   255     Node addNode() const { return graph->addNode(); }
   255     Node addNode() const { return graph->addNode(); }
   256     Edge addEdge(const Node& tail, const Node& head) const { 
   256     Edge addEdge(const Node& source, const Node& target) const { 
   257       return graph->addEdge(tail, head); }
   257       return graph->addEdge(source, target); }
   258   
   258   
   259     template<typename I> void erase(const I& i) const { graph->erase(i); }
   259     template<typename I> void erase(const I& i) const { graph->erase(i); }
   260   
   260   
   261     void clear() const { graph->clear(); }
   261     void clear() const { graph->clear(); }
   262     
   262     
   314 //       It e; first(e); return e; }
   314 //       It e; first(e); return e; }
   315 
   315 
   316 //     template< typename It > It first(const Node& v) const { 
   316 //     template< typename It > It first(const Node& v) const { 
   317 //       It e; first(e, v); return e; }
   317 //       It e; first(e, v); return e; }
   318 
   318 
   319 //     Node head(const Edge& e) const { return graph->tail(e); }
   319 //     Node target(const Edge& e) const { return graph->source(e); }
   320 //     Node tail(const Edge& e) const { return graph->head(e); }
   320 //     Node source(const Edge& e) const { return graph->target(e); }
   321   
   321   
   322 //     template<typename I> bool valid(const I& i) const 
   322 //     template<typename I> bool valid(const I& i) const 
   323 //       { return graph->valid(i); }
   323 //       { return graph->valid(i); }
   324   
   324   
   325 //     //template<typename I> void setInvalid(const I &i);
   325 //     //template<typename I> void setInvalid(const I &i);
   329 //       return graph->aNode(e); }
   329 //       return graph->aNode(e); }
   330 //     template<typename I> Node bNode(const I& e) const { 
   330 //     template<typename I> Node bNode(const I& e) const { 
   331 //       return graph->bNode(e); }
   331 //       return graph->bNode(e); }
   332 
   332 
   333 //     Node addNode() const { return graph->addNode(); }
   333 //     Node addNode() const { return graph->addNode(); }
   334 //     Edge addEdge(const Node& tail, const Node& head) const { 
   334 //     Edge addEdge(const Node& source, const Node& target) const { 
   335 //       return graph->addEdge(tail, head); }
   335 //       return graph->addEdge(source, target); }
   336   
   336   
   337 //     int nodeNum() const { return graph->nodeNum(); }
   337 //     int nodeNum() const { return graph->nodeNum(); }
   338 //     int edgeNum() const { return graph->edgeNum(); }
   338 //     int edgeNum() const { return graph->edgeNum(); }
   339   
   339   
   340 //     template<typename I> void erase(const I& i) const { graph->erase(i); }
   340 //     template<typename I> void erase(const I& i) const { graph->erase(i); }
   376     typedef typename GraphWrapper<Graph>::InEdgeIt OutEdgeIt;
   376     typedef typename GraphWrapper<Graph>::InEdgeIt OutEdgeIt;
   377 
   377 
   378 //     RevGraphWrapper() : GraphWrapper<Graph>() { }
   378 //     RevGraphWrapper() : GraphWrapper<Graph>() { }
   379     RevGraphWrapper(Graph& _graph) : GraphWrapper<Graph>(_graph) { }  
   379     RevGraphWrapper(Graph& _graph) : GraphWrapper<Graph>(_graph) { }  
   380 
   380 
   381     Node head(const Edge& e) const 
   381     Node target(const Edge& e) const 
   382       { return GraphWrapper<Graph>::tail(e); }
   382       { return GraphWrapper<Graph>::source(e); }
   383     Node tail(const Edge& e) const 
   383     Node source(const Edge& e) const 
   384       { return GraphWrapper<Graph>::head(e); }
   384       { return GraphWrapper<Graph>::target(e); }
   385   };
   385   };
   386 
   386 
   387   //Subgraph on the same node-set and partial edge-set
   387   //Subgraph on the same node-set and partial edge-set
   388   template<typename Graph, typename EdgeFilterMap>
   388   template<typename Graph, typename EdgeFilterMap>
   389   class SubGraphWrapper : public GraphWrapper<Graph> {
   389   class SubGraphWrapper : public GraphWrapper<Graph> {
   509 //       return e;
   509 //       return e;
   510 //     }
   510 //     }
   511 
   511 
   512 //     OutEdgeIt& next(OutEdgeIt& e) const {
   512 //     OutEdgeIt& next(OutEdgeIt& e) const {
   513 //       if (e.out_or_in) {
   513 //       if (e.out_or_in) {
   514 // 	Node n=gw.tail(e.out);
   514 // 	Node n=gw.source(e.out);
   515 // 	gw.next(e.out);
   515 // 	gw.next(e.out);
   516 // 	if (!gw.valid(e.out)) {
   516 // 	if (!gw.valid(e.out)) {
   517 // 	  e.out_or_in=false;
   517 // 	  e.out_or_in=false;
   518 // 	  gw.first(e.in, n);
   518 // 	  gw.first(e.in, n);
   519 // 	}
   519 // 	}
   522 //       }
   522 //       }
   523 //       return e;
   523 //       return e;
   524 //     }
   524 //     }
   525 
   525 
   526 //     Node aNode(const OutEdgeIt& e) const { 
   526 //     Node aNode(const OutEdgeIt& e) const { 
   527 //       if (e.out_or_in) return gw.tail(e); else return gw.head(e); }
   527 //       if (e.out_or_in) return gw.source(e); else return gw.target(e); }
   528 //     Node bNode(const OutEdgeIt& e) const { 
   528 //     Node bNode(const OutEdgeIt& e) const { 
   529 //       if (e.out_or_in) return gw.head(e); else return gw.tail(e); }
   529 //       if (e.out_or_in) return gw.target(e); else return gw.source(e); }
   530 
   530 
   531 //     typedef OutEdgeIt InEdgeIt; 
   531 //     typedef OutEdgeIt InEdgeIt; 
   532 
   532 
   533 //     template<typename I> I& first(I& i) const { return gw.first(i); }
   533 //     template<typename I> I& first(I& i) const { return gw.first(i); }
   534 // //     template<typename I, typename P> I& first(I& i, const P& p) const { 
   534 // //     template<typename I, typename P> I& first(I& i, const P& p) const { 
   542 //       It e; first(e); return e; }
   542 //       It e; first(e); return e; }
   543 
   543 
   544 //     template< typename It > It first(const Node& v) const { 
   544 //     template< typename It > It first(const Node& v) const { 
   545 //       It e; first(e, v); return e; }
   545 //       It e; first(e, v); return e; }
   546 
   546 
   547 //     Node head(const Edge& e) const { return gw.head(e); }
   547 //     Node target(const Edge& e) const { return gw.target(e); }
   548 //     Node tail(const Edge& e) const { return gw.tail(e); }
   548 //     Node source(const Edge& e) const { return gw.source(e); }
   549 
   549 
   550 //     template<typename I> bool valid(const I& i) const 
   550 //     template<typename I> bool valid(const I& i) const 
   551 //       { return gw.valid(i); }
   551 //       { return gw.valid(i); }
   552   
   552   
   553 //     //template<typename I> void setInvalid(const I &i);
   553 //     //template<typename I> void setInvalid(const I &i);
   561 // //     template<typename I> Node bNode(const I& e) const { 
   561 // //     template<typename I> Node bNode(const I& e) const { 
   562 // //       return graph->bNode(e); }
   562 // //       return graph->bNode(e); }
   563   
   563   
   564 //     Node addNode() const { return gw.addNode(); }
   564 //     Node addNode() const { return gw.addNode(); }
   565 // // FIXME: ez igy nem jo, mert nem
   565 // // FIXME: ez igy nem jo, mert nem
   566 // //    Edge addEdge(const Node& tail, const Node& head) const { 
   566 // //    Edge addEdge(const Node& source, const Node& target) const { 
   567 // //      return graph->addEdge(tail, head); }
   567 // //      return graph->addEdge(source, target); }
   568   
   568   
   569 //     template<typename I> void erase(const I& i) const { gw.erase(i); }
   569 //     template<typename I> void erase(const I& i) const { gw.erase(i); }
   570   
   570   
   571 //     void clear() const { gw.clear(); }
   571 //     void clear() const { gw.clear(); }
   572     
   572     
   690     template<typename I, typename P> I& first(I& i, const P& p) const { 
   690     template<typename I, typename P> I& first(I& i, const P& p) const { 
   691       graph->first(i, p); return i; }
   691       graph->first(i, p); return i; }
   692 
   692 
   693     OutEdgeIt& next(OutEdgeIt& e) const {
   693     OutEdgeIt& next(OutEdgeIt& e) const {
   694       if (e.out_or_in) {
   694       if (e.out_or_in) {
   695 	Node n=graph->tail(e.out);
   695 	Node n=graph->source(e.out);
   696 	graph->next(e.out);
   696 	graph->next(e.out);
   697 	if (!graph->valid(e.out)) { e.out_or_in=false; graph->first(e.in, n); }
   697 	if (!graph->valid(e.out)) { e.out_or_in=false; graph->first(e.in, n); }
   698       } else {
   698       } else {
   699 	graph->next(e.in);
   699 	graph->next(e.in);
   700       }
   700       }
   701       return e;
   701       return e;
   702     }
   702     }
   703 
   703 
   704     EdgeIt& next(EdgeIt& e) const {
   704     EdgeIt& next(EdgeIt& e) const {
   705       //NodeIt v=tail(e);
   705       //NodeIt v=source(e);
   706       graph->next(e.out);
   706       graph->next(e.out);
   707       while (valid(e.v) && !graph->valid(e.out)) { 
   707       while (valid(e.v) && !graph->valid(e.out)) { 
   708 	next(e.v); 
   708 	next(e.v); 
   709 	if (valid(e.v)) graph->first(e.out, e.v); 
   709 	if (valid(e.v)) graph->first(e.out, e.v); 
   710       }
   710       }
   718       It e; this->first(e); return e; }
   718       It e; this->first(e); return e; }
   719 
   719 
   720     template< typename It > It first(const Node& v) const { 
   720     template< typename It > It first(const Node& v) const { 
   721       It e; this->first(e, v); return e; }
   721       It e; this->first(e, v); return e; }
   722 
   722 
   723 //    Node head(const Edge& e) const { return gw.head(e); }
   723 //    Node target(const Edge& e) const { return gw.target(e); }
   724 //    Node tail(const Edge& e) const { return gw.tail(e); }
   724 //    Node source(const Edge& e) const { return gw.source(e); }
   725 
   725 
   726 //    template<typename I> bool valid(const I& i) const 
   726 //    template<typename I> bool valid(const I& i) const 
   727 //      { return gw.valid(i); }
   727 //      { return gw.valid(i); }
   728   
   728   
   729 //    int nodeNum() const { return gw.nodeNum(); }
   729 //    int nodeNum() const { return gw.nodeNum(); }
   733 //       return graph->aNode(e); }
   733 //       return graph->aNode(e); }
   734 //     template<typename I> Node bNode(const I& e) const { 
   734 //     template<typename I> Node bNode(const I& e) const { 
   735 //       return graph->bNode(e); }
   735 //       return graph->bNode(e); }
   736 
   736 
   737     Node aNode(const OutEdgeIt& e) const { 
   737     Node aNode(const OutEdgeIt& e) const { 
   738       if (e.out_or_in) return graph->tail(e); else return graph->head(e); }
   738       if (e.out_or_in) return graph->source(e); else return graph->target(e); }
   739     Node bNode(const OutEdgeIt& e) const { 
   739     Node bNode(const OutEdgeIt& e) const { 
   740       if (e.out_or_in) return graph->head(e); else return graph->tail(e); }
   740       if (e.out_or_in) return graph->target(e); else return graph->source(e); }
   741   
   741   
   742 //    Node addNode() const { return gw.addNode(); }
   742 //    Node addNode() const { return gw.addNode(); }
   743 
   743 
   744 // FIXME: ez igy nem jo, mert nem
   744 // FIXME: ez igy nem jo, mert nem
   745 //    Edge addEdge(const Node& tail, const Node& head) const { 
   745 //    Edge addEdge(const Node& source, const Node& target) const { 
   746 //      return graph->addEdge(tail, head); }
   746 //      return graph->addEdge(source, target); }
   747   
   747   
   748 //    template<typename I> void erase(const I& i) const { gw.erase(i); }
   748 //    template<typename I> void erase(const I& i) const { gw.erase(i); }
   749   
   749   
   750 //    void clear() const { gw.clear(); }
   750 //    void clear() const { gw.clear(); }
   751     
   751     
   805 //       It e; first(e); return e; }
   805 //       It e; first(e); return e; }
   806 
   806 
   807 //     template< typename It > It first(Node v) const { 
   807 //     template< typename It > It first(Node v) const { 
   808 //       It e; first(e, v); return e; }
   808 //       It e; first(e, v); return e; }
   809 
   809 
   810 //     Node head(const Edge& e) const { return graph->head(e); }
   810 //     Node target(const Edge& e) const { return graph->target(e); }
   811 //     Node tail(const Edge& e) const { return graph->tail(e); }
   811 //     Node source(const Edge& e) const { return graph->source(e); }
   812   
   812   
   813 //     template<typename I> Node aNode(const I& e) const { 
   813 //     template<typename I> Node aNode(const I& e) const { 
   814 //       return graph->aNode(e); }
   814 //       return graph->aNode(e); }
   815 //     template<typename I> Node bNode(const I& e) const { 
   815 //     template<typename I> Node bNode(const I& e) const { 
   816 //       return graph->bNode(e); }
   816 //       return graph->bNode(e); }
   820   
   820   
   821 //     //template<typename I> void setInvalid(const I &i);
   821 //     //template<typename I> void setInvalid(const I &i);
   822 //     //{ return graph->setInvalid(i); }
   822 //     //{ return graph->setInvalid(i); }
   823   
   823   
   824 //     Node addNode() { return graph->addNode(); }
   824 //     Node addNode() { return graph->addNode(); }
   825 //     Edge addEdge(const Node& tail, const Node& head) { 
   825 //     Edge addEdge(const Node& source, const Node& target) { 
   826 //       return graph->addEdge(tail, head); }
   826 //       return graph->addEdge(source, target); }
   827   
   827   
   828 //     template<typename I> void erase(const I& i) { graph->erase(i); }
   828 //     template<typename I> void erase(const I& i) { graph->erase(i); }
   829   
   829   
   830 //     void clear() { graph->clear(); }
   830 //     void clear() { graph->clear(); }
   831   
   831   
  1061       It e;
  1061       It e;
  1062       first(e, v);
  1062       first(e, v);
  1063       return e; 
  1063       return e; 
  1064     }
  1064     }
  1065 
  1065 
  1066     Node tail(Edge e) const { 
  1066     Node source(Edge e) const { 
  1067       return ((e.out_or_in) ? graph->aNode(e.out) : graph->aNode(e.in)); }
  1067       return ((e.out_or_in) ? graph->aNode(e.out) : graph->aNode(e.in)); }
  1068     Node head(Edge e) const { 
  1068     Node target(Edge e) const { 
  1069       return ((e.out_or_in) ? graph->bNode(e.out) : graph->bNode(e.in)); }
  1069       return ((e.out_or_in) ? graph->bNode(e.out) : graph->bNode(e.in)); }
  1070 
  1070 
  1071     Node aNode(OutEdgeIt e) const { 
  1071     Node aNode(OutEdgeIt e) const { 
  1072       return ((e.out_or_in) ? graph->aNode(e.out) : graph->aNode(e.in)); }
  1072       return ((e.out_or_in) ? graph->aNode(e.out) : graph->aNode(e.in)); }
  1073     Node bNode(OutEdgeIt e) const { 
  1073     Node bNode(OutEdgeIt e) const { 
  1190       It e; this->first(e, v); return e; }
  1190       It e; this->first(e, v); return e; }
  1191 
  1191 
  1192     void erase(const OutEdgeIt& e) const {
  1192     void erase(const OutEdgeIt& e) const {
  1193       OutEdgeIt f=e;
  1193       OutEdgeIt f=e;
  1194       this->next(f);
  1194       this->next(f);
  1195       first_out_edges->set(this->tail(e), f);
  1195       first_out_edges->set(this->source(e), f);
  1196     }
  1196     }
  1197   };
  1197   };
  1198 
  1198 
  1199 // // FIXME: comparison should be made better!!!
  1199 // // FIXME: comparison should be made better!!!
  1200 //   template<typename Graph, typename T, typename LowerMap, typename FlowMap, typename UpperMap>
  1200 //   template<typename Graph, typename T, typename LowerMap, typename FlowMap, typename UpperMap>
  1308 //       It e; first(e); return e; }
  1308 //       It e; first(e); return e; }
  1309 
  1309 
  1310 //     template< typename It > It first(Node v) const { 
  1310 //     template< typename It > It first(Node v) const { 
  1311 //       It e; first(e, v); return e; }
  1311 //       It e; first(e, v); return e; }
  1312 
  1312 
  1313 //     Node head(const Edge& e) const { return gw.head(e); }
  1313 //     Node target(const Edge& e) const { return gw.target(e); }
  1314 //     Node tail(const Edge& e) const { return gw.tail(e); }
  1314 //     Node source(const Edge& e) const { return gw.source(e); }
  1315   
  1315   
  1316 //     template<typename I> Node aNode(const I& e) const { 
  1316 //     template<typename I> Node aNode(const I& e) const { 
  1317 //       return gw.aNode(e); }
  1317 //       return gw.aNode(e); }
  1318 //     template<typename I> Node bNode(const I& e) const { 
  1318 //     template<typename I> Node bNode(const I& e) const { 
  1319 //       return gw.bNode(e); }
  1319 //       return gw.bNode(e); }
  1323   
  1323   
  1324 //     //template<typename I> void setInvalid(const I &i);
  1324 //     //template<typename I> void setInvalid(const I &i);
  1325 //     //{ return gw.setInvalid(i); }
  1325 //     //{ return gw.setInvalid(i); }
  1326   
  1326   
  1327 //     Node addNode() { return gw.addNode(); }
  1327 //     Node addNode() { return gw.addNode(); }
  1328 //     Edge addEdge(const Node& tail, const Node& head) { 
  1328 //     Edge addEdge(const Node& source, const Node& target) { 
  1329 //       return gw.addEdge(tail, head); }
  1329 //       return gw.addEdge(source, target); }
  1330   
  1330   
  1331 //     template<typename I> void erase(const I& i) { gw.erase(i); }
  1331 //     template<typename I> void erase(const I& i) { gw.erase(i); }
  1332   
  1332   
  1333 //     void clear() { gw.clear(); }
  1333 //     void clear() { gw.clear(); }
  1334   
  1334