src/work/marci/experiment/graph_wrapper_st_ostream_op.h
changeset 986 e997802b855c
parent 921 818510fa3d99
equal deleted inserted replaced
1:8b769eea7e4f 2:ca982b787125
   164     NodeIt& next(NodeIt& i) const { graph->next(i.n); return i; }
   164     NodeIt& next(NodeIt& i) const { graph->next(i.n); return i; }
   165     OutEdgeIt& next(OutEdgeIt& i) const { graph->next(i.e); return i; }
   165     OutEdgeIt& next(OutEdgeIt& i) const { graph->next(i.e); return i; }
   166     InEdgeIt& next(InEdgeIt& i) const { graph->next(i.e); return i; }
   166     InEdgeIt& next(InEdgeIt& i) const { graph->next(i.e); return i; }
   167     EdgeIt& next(EdgeIt& i) const { graph->next(i.e); return i; }    
   167     EdgeIt& next(EdgeIt& i) const { graph->next(i.e); return i; }    
   168 
   168 
   169     Node tail(const Edge& e) const { 
   169     Node source(const Edge& e) const { 
   170       return Node(graph->tail(static_cast<typename Graph::Edge>(e))); }
   170       return Node(graph->source(static_cast<typename Graph::Edge>(e))); }
   171     Node head(const Edge& e) const { 
   171     Node target(const Edge& e) const { 
   172       return Node(graph->head(static_cast<typename Graph::Edge>(e))); }
   172       return Node(graph->target(static_cast<typename Graph::Edge>(e))); }
   173 
   173 
   174     bool valid(const Node& n) const { 
   174     bool valid(const Node& n) const { 
   175       return graph->valid(static_cast<typename Graph::Node>(n)); }
   175       return graph->valid(static_cast<typename Graph::Node>(n)); }
   176     bool valid(const Edge& e) const { 
   176     bool valid(const Edge& e) const { 
   177       return graph->valid(static_cast<typename Graph::Edge>(e)); }
   177       return graph->valid(static_cast<typename Graph::Edge>(e)); }
   183     Node aNode(const InEdgeIt& e) const { return Node(graph->aNode(e.e)); }
   183     Node aNode(const InEdgeIt& e) const { return Node(graph->aNode(e.e)); }
   184     Node bNode(const OutEdgeIt& e) const { return Node(graph->bNode(e.e)); }
   184     Node bNode(const OutEdgeIt& e) const { return Node(graph->bNode(e.e)); }
   185     Node bNode(const InEdgeIt& e) const { return Node(graph->bNode(e.e)); }
   185     Node bNode(const InEdgeIt& e) const { return Node(graph->bNode(e.e)); }
   186   
   186   
   187     Node addNode() const { return Node(graph->addNode()); }
   187     Node addNode() const { return Node(graph->addNode()); }
   188     Edge addEdge(const Node& tail, const Node& head) const { 
   188     Edge addEdge(const Node& source, const Node& target) const { 
   189       return Edge(graph->addEdge(tail, head)); }
   189       return Edge(graph->addEdge(source, target)); }
   190 
   190 
   191     void erase(const Node& i) const { graph->erase(i); }
   191     void erase(const Node& i) const { graph->erase(i); }
   192     void erase(const Edge& i) const { graph->erase(i); }
   192     void erase(const Edge& i) const { graph->erase(i); }
   193   
   193   
   194     void clear() const { graph->clear(); }
   194     void clear() const { graph->clear(); }
   270     Node bNode(const OutEdgeIt& e) const { 
   270     Node bNode(const OutEdgeIt& e) const { 
   271       return Node(this->graph->bNode(e.e)); }
   271       return Node(this->graph->bNode(e.e)); }
   272     Node bNode(const InEdgeIt& e) const { 
   272     Node bNode(const InEdgeIt& e) const { 
   273       return Node(this->graph->bNode(e.e)); }
   273       return Node(this->graph->bNode(e.e)); }
   274 
   274 
   275     Node tail(const Edge& e) const { 
   275     Node source(const Edge& e) const { 
   276       return GraphWrapper<Graph>::head(e); }
   276       return GraphWrapper<Graph>::target(e); }
   277     Node head(const Edge& e) const { 
   277     Node target(const Edge& e) const { 
   278       return GraphWrapper<Graph>::tail(e); }
   278       return GraphWrapper<Graph>::source(e); }
   279 
   279 
   280   };
   280   };
   281 
   281 
   282   /// Wrapper for hiding nodes and edges from a graph.
   282   /// Wrapper for hiding nodes and edges from a graph.
   283   
   283   
   487 //       GraphWrapper<Graph>::next(n);
   487 //       GraphWrapper<Graph>::next(n);
   488 //       return n;
   488 //       return n;
   489 //     }
   489 //     }
   490     OutEdgeIt& next(OutEdgeIt& e) const {
   490     OutEdgeIt& next(OutEdgeIt& e) const {
   491       if (e.out_or_in) {
   491       if (e.out_or_in) {
   492 	typename Graph::Node n=this->graph->tail(e.out);
   492 	typename Graph::Node n=this->graph->source(e.out);
   493 	this->graph->next(e.out);
   493 	this->graph->next(e.out);
   494 	if (!this->graph->valid(e.out)) { 
   494 	if (!this->graph->valid(e.out)) { 
   495 	  e.out_or_in=false; this->graph->first(e.in, n); }
   495 	  e.out_or_in=false; this->graph->first(e.in, n); }
   496       } else {
   496       } else {
   497 	this->graph->next(e.in);
   497 	this->graph->next(e.in);
   504 // //      graph->next(e.e);
   504 // //      graph->next(e.e);
   505 //       return e;
   505 //       return e;
   506 //     }
   506 //     }
   507 
   507 
   508     Node aNode(const OutEdgeIt& e) const { 
   508     Node aNode(const OutEdgeIt& e) const { 
   509       if (e.out_or_in) return this->graph->tail(e); else 
   509       if (e.out_or_in) return this->graph->source(e); else 
   510 	return this->graph->head(e); }
   510 	return this->graph->target(e); }
   511     Node bNode(const OutEdgeIt& e) const { 
   511     Node bNode(const OutEdgeIt& e) const { 
   512       if (e.out_or_in) return this->graph->head(e); else 
   512       if (e.out_or_in) return this->graph->target(e); else 
   513 	return this->graph->tail(e); }
   513 	return this->graph->source(e); }
   514   };
   514   };
   515   
   515   
   516   /// A wrapper for composing the residual graph for directed flow and circulation problems.
   516   /// A wrapper for composing the residual graph for directed flow and circulation problems.
   517 
   517 
   518   /// A wrapper for composing the residual graph for directed flow and circulation problems.
   518   /// A wrapper for composing the residual graph for directed flow and circulation problems.
   722 	  this->graph->next(e.e); } 
   722 	  this->graph->next(e.e); } 
   723       }
   723       }
   724       return e;
   724       return e;
   725     }
   725     }
   726 
   726 
   727     Node tail(Edge e) const { 
   727     Node source(Edge e) const { 
   728       return ((e.forward) ? this->graph->tail(e) : this->graph->head(e)); }
   728       return ((e.forward) ? this->graph->source(e) : this->graph->target(e)); }
   729     Node head(Edge e) const { 
   729     Node target(Edge e) const { 
   730       return ((e.forward) ? this->graph->head(e) : this->graph->tail(e)); }
   730       return ((e.forward) ? this->graph->target(e) : this->graph->source(e)); }
   731 
   731 
   732     Node aNode(OutEdgeIt e) const { 
   732     Node aNode(OutEdgeIt e) const { 
   733       return ((e.forward) ? this->graph->aNode(e.out) : 
   733       return ((e.forward) ? this->graph->aNode(e.out) : 
   734 	      this->graph->aNode(e.in)); }
   734 	      this->graph->aNode(e.in)); }
   735     Node bNode(OutEdgeIt e) const { 
   735     Node bNode(OutEdgeIt e) const { 
   911       return Node(this->graph->bNode(e.e)); }
   911       return Node(this->graph->bNode(e.e)); }
   912 
   912 
   913     void erase(const OutEdgeIt& e) const {
   913     void erase(const OutEdgeIt& e) const {
   914       OutEdgeIt f=e;
   914       OutEdgeIt f=e;
   915       this->next(f);
   915       this->next(f);
   916       first_out_edges->set(this->tail(e), f.e);
   916       first_out_edges->set(this->source(e), f.e);
   917     }
   917     }
   918   };
   918   };
   919 
   919 
   920   /// A wrapper for composing a bipartite graph.
   920   /// A wrapper for composing a bipartite graph.
   921   /// \c _graph have to be a reference to a graph of type \c Graph 
   921   /// \c _graph have to be a reference to a graph of type \c Graph 
  1039 //       this->s_false_t_true_map->next(n); return n; 
  1039 //       this->s_false_t_true_map->next(n); return n; 
  1040 //     }
  1040 //     }
  1041     OutEdgeIt& next(OutEdgeIt& i) const { this->graph->next(i.e); return i; }
  1041     OutEdgeIt& next(OutEdgeIt& i) const { this->graph->next(i.e); return i; }
  1042     InEdgeIt& next(InEdgeIt& i) const { this->graph->next(i.e); return i; }
  1042     InEdgeIt& next(InEdgeIt& i) const { this->graph->next(i.e); return i; }
  1043 
  1043 
  1044     Node tail(const Edge& e) { 
  1044     Node source(const Edge& e) { 
  1045       if (!(*(this->s_false_t_true_map))[this->graph->tail(e)]) 
  1045       if (!(*(this->s_false_t_true_map))[this->graph->source(e)]) 
  1046 	return Node(this->graph->tail(e));
  1046 	return Node(this->graph->source(e));
  1047       else
  1047       else
  1048 	return Node(this->graph->head(e));	
  1048 	return Node(this->graph->target(e));	
  1049     }
  1049     }
  1050     Node head(const Edge& e) { 
  1050     Node target(const Edge& e) { 
  1051       if (!(*(this->s_false_t_true_map))[this->graph->tail(e)]) 
  1051       if (!(*(this->s_false_t_true_map))[this->graph->source(e)]) 
  1052 	return Node(this->graph->head(e));
  1052 	return Node(this->graph->target(e));
  1053       else
  1053       else
  1054 	return Node(this->graph->tail(e));	
  1054 	return Node(this->graph->source(e));	
  1055     }
  1055     }
  1056 
  1056 
  1057     Node aNode(const OutEdgeIt& e) const { 
  1057     Node aNode(const OutEdgeIt& e) const { 
  1058       return Node(this->graph->aNode(e.e)); 
  1058       return Node(this->graph->aNode(e.e)); 
  1059     }
  1059     }
  1467 	  break;
  1467 	  break;
  1468       }
  1468       }
  1469       return i; 
  1469       return i; 
  1470     }    
  1470     }    
  1471 
  1471 
  1472     Node tail(const Edge& e) const { 
  1472     Node source(const Edge& e) const { 
  1473       switch (e.spec) {
  1473       switch (e.spec) {
  1474       case 0: 
  1474       case 0: 
  1475 	return Node(this->graph->tail(e));
  1475 	return Node(this->graph->source(e));
  1476 	break;
  1476 	break;
  1477       case 1:
  1477       case 1:
  1478 	return S_NODE;
  1478 	return S_NODE;
  1479 	break;
  1479 	break;
  1480       case 2:
  1480       case 2:
  1481       default:
  1481       default:
  1482 	return Node(e.n);
  1482 	return Node(e.n);
  1483 	break;
  1483 	break;
  1484       }
  1484       }
  1485     }
  1485     }
  1486     Node head(const Edge& e) const { 
  1486     Node target(const Edge& e) const { 
  1487       switch (e.spec) {
  1487       switch (e.spec) {
  1488       case 0: 
  1488       case 0: 
  1489 	return Node(this->graph->head(e));
  1489 	return Node(this->graph->target(e));
  1490 	break;
  1490 	break;
  1491       case 1:
  1491       case 1:
  1492 	return Node(e.n);
  1492 	return Node(e.n);
  1493 	break;
  1493 	break;
  1494       case 2:
  1494       case 2:
  1504     int nodeNum() const { return this->graph->nodeNum()+2; }
  1504     int nodeNum() const { return this->graph->nodeNum()+2; }
  1505     int edgeNum() const { 
  1505     int edgeNum() const { 
  1506       return this->graph->edgeNum()+this->graph->nodeNum(); 
  1506       return this->graph->edgeNum()+this->graph->nodeNum(); 
  1507     }
  1507     }
  1508   
  1508   
  1509     Node aNode(const OutEdgeIt& e) const { return tail(e); }
  1509     Node aNode(const OutEdgeIt& e) const { return source(e); }
  1510     Node aNode(const InEdgeIt& e) const { return head(e); }
  1510     Node aNode(const InEdgeIt& e) const { return target(e); }
  1511     Node bNode(const OutEdgeIt& e) const { return head(e); }
  1511     Node bNode(const OutEdgeIt& e) const { return target(e); }
  1512     Node bNode(const InEdgeIt& e) const { return tail(e); }
  1512     Node bNode(const InEdgeIt& e) const { return source(e); }
  1513 
  1513 
  1514     void addNode() const { }
  1514     void addNode() const { }
  1515     void addEdge() const { }
  1515     void addEdge() const { }
  1516     
  1516     
  1517 //    Node addNode() const { return Node(this->graph->addNode()); }
  1517 //    Node addNode() const { return Node(this->graph->addNode()); }
  1518 //    Edge addEdge(const Node& tail, const Node& head) const { 
  1518 //    Edge addEdge(const Node& source, const Node& target) const { 
  1519 //      return Edge(this->graph->addEdge(tail, head)); }
  1519 //      return Edge(this->graph->addEdge(source, target)); }
  1520 
  1520 
  1521 //    void erase(const Node& i) const { this->graph->erase(i); }
  1521 //    void erase(const Node& i) const { this->graph->erase(i); }
  1522 //    void erase(const Edge& i) const { this->graph->erase(i); }
  1522 //    void erase(const Edge& i) const { this->graph->erase(i); }
  1523   
  1523   
  1524 //    void clear() const { this->graph->clear(); }
  1524 //    void clear() const { this->graph->clear(); }