src/work/marci/graph_wrapper.h
changeset 417 4ce3d5f675ea
parent 406 e8377ac921b6
child 435 8f1dece01cc4
equal deleted inserted replaced
49:54f006427391 50:07f839db93b0
   921     typedef IterableBoolMap< typename Graph::template NodeMap<int> > 
   921     typedef IterableBoolMap< typename Graph::template NodeMap<int> > 
   922     SFalseTTrueMap;
   922     SFalseTTrueMap;
   923     SFalseTTrueMap* s_false_t_true_map;
   923     SFalseTTrueMap* s_false_t_true_map;
   924 
   924 
   925   public:
   925   public:
   926     static const bool S_CLASS=false;
   926     //marci
   927     static const bool T_CLASS=true;
   927     //FIXME vhogy igy kellene, csak az en forditom nem eszi meg
       
   928     //static const bool S_CLASS=false;
       
   929     //static const bool T_CLASS=true;
   928     
   930     
       
   931     bool S_CLASS;
       
   932     bool T_CLASS;
       
   933 
   929     BipartiteGraphWrapper(Graph& _graph, SFalseTTrueMap& _s_false_t_true_map) 
   934     BipartiteGraphWrapper(Graph& _graph, SFalseTTrueMap& _s_false_t_true_map) 
   930       : GraphWrapper<Graph>(_graph), s_false_t_true_map(&_s_false_t_true_map) {
   935       : GraphWrapper<Graph>(_graph), s_false_t_true_map(&_s_false_t_true_map), 
   931     }
   936       S_CLASS(false), T_CLASS(true) { }
   932     typedef typename GraphWrapper<Graph>::Node Node;
   937     typedef typename GraphWrapper<Graph>::Node Node;
   933     //using GraphWrapper<Graph>::NodeIt;
   938     //using GraphWrapper<Graph>::NodeIt;
   934     typedef typename GraphWrapper<Graph>::Edge Edge;
   939     typedef typename GraphWrapper<Graph>::Edge Edge;
   935     //using GraphWrapper<Graph>::EdgeIt;
   940     //using GraphWrapper<Graph>::EdgeIt;
   936     class ClassNodeIt;
   941     class ClassNodeIt;
  1100 //(first, 0, invalid) ...
  1105 //(first, 0, invalid) ...
  1101 //(invalid, 1, vmi)
  1106 //(invalid, 1, vmi)
  1102 //(invalid, 2, vmi)
  1107 //(invalid, 2, vmi)
  1103 //invalid, 3, invalid)
  1108 //invalid, 3, invalid)
  1104     template <typename T> class NodeMap;
  1109     template <typename T> class NodeMap;
  1105     template <typename T> class EdgeMap;
  1110     template <typename T, typename Parent> class EdgeMap;
  1106 
  1111 
  1107 //    template <typename T> friend class NodeMap;
  1112 //    template <typename T> friend class NodeMap;
  1108 //    template <typename T> friend class EdgeMap;
  1113 //    template <typename T> friend class EdgeMap;
  1109 
  1114 
  1110     const Node S_NODE;
  1115     const Node S_NODE;
  1139       } 
  1144       } 
  1140       friend bool operator!=(const Node& u, const Node& v) { 
  1145       friend bool operator!=(const Node& u, const Node& v) { 
  1141 	return (v.spec!=u.spec || 
  1146 	return (v.spec!=u.spec || 
  1142 		static_cast<typename Graph::Node>(u)!=
  1147 		static_cast<typename Graph::Node>(u)!=
  1143 		static_cast<typename Graph::Node>(v));
  1148 		static_cast<typename Graph::Node>(v));
  1144       } 
  1149       }
       
  1150       friend std::ostream& operator<<(std::ostream& os, const Node& i);
  1145       int getSpec() const { return spec; }
  1151       int getSpec() const { return spec; }
  1146     };
  1152     };
       
  1153 
  1147     class NodeIt { 
  1154     class NodeIt { 
  1148       friend class GraphWrapper<Graph>;
  1155       friend class GraphWrapper<Graph>;
  1149       friend class stGraphWrapper<Graph>;
  1156       friend class stGraphWrapper<Graph>;
  1150       typename Graph::NodeIt n;
  1157       typename Graph::NodeIt n;
  1151       int spec; 
  1158       int spec; 
  1153       NodeIt() { }
  1160       NodeIt() { }
  1154       NodeIt(const typename Graph::NodeIt& _n, int _spec) : 
  1161       NodeIt(const typename Graph::NodeIt& _n, int _spec) : 
  1155 	n(_n), spec(_spec) { }
  1162 	n(_n), spec(_spec) { }
  1156       NodeIt(const Invalid& i) : n(i), spec(3) { }
  1163       NodeIt(const Invalid& i) : n(i), spec(3) { }
  1157       NodeIt(const stGraphWrapper<Graph>& _G) : n(*(_G.graph)), spec(0) { 
  1164       NodeIt(const stGraphWrapper<Graph>& _G) : n(*(_G.graph)), spec(0) { 
  1158 	if (!_G->valid(n)) spec=1;
  1165 	if (!_G.graph->valid(n)) spec=1;
  1159       }
  1166       }
  1160       operator Node() const { return Node(n, spec); }
  1167       operator Node() const { return Node(n, spec); }
  1161     };
  1168     };
       
  1169 
  1162     class Edge : public Graph::Edge {
  1170     class Edge : public Graph::Edge {
  1163       friend class GraphWrapper<Graph>;
  1171       friend class GraphWrapper<Graph>;
  1164       friend class stGraphWrapper<Graph>;
  1172       friend class stGraphWrapper<Graph>;
  1165       template <typename T> friend class EdgeMap;
  1173       template <typename T, typename Parent> friend class EdgeMap;
  1166       int spec;
  1174       int spec;
  1167       typename Graph::Node n;
  1175       typename Graph::Node n;
  1168     public:
  1176     public:
  1169       Edge() { }
  1177       Edge() { }
  1170       Edge(const typename Graph::Edge& _e, int _spec, 
  1178       Edge(const typename Graph::Edge& _e, int _spec, 
  1182 	return (v.spec!=u.spec || 
  1190 	return (v.spec!=u.spec || 
  1183 		static_cast<typename Graph::Edge>(u)!=
  1191 		static_cast<typename Graph::Edge>(u)!=
  1184 		static_cast<typename Graph::Edge>(v) || 
  1192 		static_cast<typename Graph::Edge>(v) || 
  1185 		u.n!=v.n);
  1193 		u.n!=v.n);
  1186       } 
  1194       } 
       
  1195       friend std::ostream& operator<<(std::ostream& os, const Edge& i);
  1187       int getSpec() const { return spec; }
  1196       int getSpec() const { return spec; }
  1188     };
  1197     };
       
  1198 
  1189     class OutEdgeIt { 
  1199     class OutEdgeIt { 
  1190       friend class GraphWrapper<Graph>;
  1200       friend class GraphWrapper<Graph>;
  1191       friend class stGraphWrapper<Graph>;
  1201       friend class stGraphWrapper<Graph>;
  1192       typename Graph::OutEdgeIt e;
  1202       typename Graph::OutEdgeIt e;
  1193       int spec;
  1203       int spec;
  1227 	    break;
  1237 	    break;
  1228 	}
  1238 	}
  1229       }
  1239       }
  1230       operator Edge() const { return Edge(e, spec, n); }
  1240       operator Edge() const { return Edge(e, spec, n); }
  1231     };
  1241     };
       
  1242 
  1232     class InEdgeIt { 
  1243     class InEdgeIt { 
  1233       friend class GraphWrapper<Graph>;
  1244       friend class GraphWrapper<Graph>;
  1234       friend class stGraphWrapper<Graph>;
  1245       friend class stGraphWrapper<Graph>;
  1235       typename Graph::InEdgeIt e;
  1246       typename Graph::InEdgeIt e;
  1236       int spec;
  1247       int spec;
  1259 	    break;
  1270 	    break;
  1260 	  case 1:
  1271 	  case 1:
  1261 	    e=INVALID;
  1272 	    e=INVALID;
  1262 	    spec=3;
  1273 	    spec=3;
  1263 	    n=INVALID;
  1274 	    n=INVALID;
       
  1275 	    break;
  1264 	  case 2:
  1276 	  case 2:
  1265 	    e=INVALID;
  1277 	    e=INVALID;
  1266 	    spec=1;
  1278 	    spec=2;
  1267 	    _G.graph->first(n, T_CLASS); //vmi->t;
  1279 	    _G.graph->first(n, T_CLASS); //vmi->t;
  1268 	    if (!_G.graph->valid(n)) spec=3; //Ha T ures
  1280 	    if (!_G.graph->valid(n)) spec=3; //Ha T ures
  1269 	    break;
  1281 	    break;
  1270 	}
  1282 	}
  1271       }
  1283       }
  1272       operator Edge() const { return Edge(e, spec, n); }
  1284       operator Edge() const { return Edge(e, spec, n); }
  1273     };
  1285     };
       
  1286 
  1274     class EdgeIt { 
  1287     class EdgeIt { 
  1275       friend class GraphWrapper<Graph>;
  1288       friend class GraphWrapper<Graph>;
  1276       friend class stGraphWrapper<Graph>;
  1289       friend class stGraphWrapper<Graph>;
  1277       typename Graph::EdgeIt e;
  1290       typename Graph::EdgeIt e;
  1278       int spec;
  1291       int spec;
  1332     }
  1345     }
  1333     OutEdgeIt& next(OutEdgeIt& i) const { 
  1346     OutEdgeIt& next(OutEdgeIt& i) const { 
  1334       typename Graph::Node v;
  1347       typename Graph::Node v;
  1335       switch (i.spec) {
  1348       switch (i.spec) {
  1336 	case 0: //normal edge
  1349 	case 0: //normal edge
  1337 	  this->graph->aNode(i.e);
  1350 	  v=this->graph->aNode(i.e);
  1338 	  this->graph->next(i.e);
  1351 	  this->graph->next(i.e);
  1339 	  if (!this->graph->valid(i.e)) { //Az igazi elek vegere ertunk
  1352 	  if (!this->graph->valid(i.e)) { //Az igazi elek vegere ertunk
  1340 	    if (this->graph->inSClass(v)) { //S, nincs kiel
  1353 	    if (this->graph->inSClass(v)) { //S, nincs kiel
  1341 	      i.spec=3;
  1354 	      i.spec=3;
  1342 	      i.n=INVALID;
  1355 	      i.n=INVALID;
  1445     }
  1458     }
  1446 
  1459 
  1447     bool valid(const Node& n) const { return (n.spec<3); }
  1460     bool valid(const Node& n) const { return (n.spec<3); }
  1448     bool valid(const Edge& e) const { return (e.spec<3); }
  1461     bool valid(const Edge& e) const { return (e.spec<3); }
  1449 
  1462 
  1450 //    int nodeNum() const { return this->graph->nodeNum(); }
  1463     int nodeNum() const { return this->graph->nodeNum()+2; }
  1451 //    int edgeNum() const { return this->graph->edgeNum(); }
  1464     int edgeNum() const { 
       
  1465       return this->graph->edgeNum()+this->graph->nodeNum(); 
       
  1466     }
  1452   
  1467   
  1453     Node aNode(const OutEdgeIt& e) const { return tail(e); }
  1468     Node aNode(const OutEdgeIt& e) const { return tail(e); }
  1454     Node aNode(const InEdgeIt& e) const { return head(e); }
  1469     Node aNode(const InEdgeIt& e) const { return head(e); }
  1455     Node bNode(const OutEdgeIt& e) const { return head(e); }
  1470     Node bNode(const OutEdgeIt& e) const { return head(e); }
  1456     Node bNode(const InEdgeIt& e) const { return tail(e); }
  1471     Node bNode(const InEdgeIt& e) const { return tail(e); }
  1457   
  1472 
       
  1473     void addNode() const { }
       
  1474     void addEdge() const { }
       
  1475     
  1458 //    Node addNode() const { return Node(this->graph->addNode()); }
  1476 //    Node addNode() const { return Node(this->graph->addNode()); }
  1459 //    Edge addEdge(const Node& tail, const Node& head) const { 
  1477 //    Edge addEdge(const Node& tail, const Node& head) const { 
  1460 //      return Edge(this->graph->addEdge(tail, head)); }
  1478 //      return Edge(this->graph->addEdge(tail, head)); }
  1461 
  1479 
  1462 //    void erase(const Node& i) const { this->graph->erase(i); }
  1480 //    void erase(const Node& i) const { this->graph->erase(i); }
  1466     
  1484     
  1467     template<typename T> class NodeMap : public GraphWrapper<Graph>::template NodeMap<T> { 
  1485     template<typename T> class NodeMap : public GraphWrapper<Graph>::template NodeMap<T> { 
  1468       typedef typename GraphWrapper<Graph>::template NodeMap<T> Parent;
  1486       typedef typename GraphWrapper<Graph>::template NodeMap<T> Parent;
  1469       T s_value, t_value;
  1487       T s_value, t_value;
  1470     public:
  1488     public:
  1471       NodeMap(const stGraphWrapper<Graph>& _G) :  Parent(_G) { }
  1489       NodeMap(const stGraphWrapper<Graph>& _G) :  Parent(_G), 
       
  1490 						  s_value(), 
       
  1491 						  t_value() { }
  1472       NodeMap(const stGraphWrapper<Graph>& _G, T a) : Parent(_G, a), 
  1492       NodeMap(const stGraphWrapper<Graph>& _G, T a) : Parent(_G, a), 
  1473 						      s_value(a), 
  1493 						      s_value(a), 
  1474 						      t_value(a) { }
  1494 						      t_value(a) { }
  1475       T operator[](const Node& n) const { 
  1495       T operator[](const Node& n) const { 
  1476 	switch (n.spec) {
  1496 	switch (n.spec) {
  1500 	  break;
  1520 	  break;
  1501 	}
  1521 	}
  1502       }
  1522       }
  1503     };
  1523     };
  1504 
  1524 
  1505     template<typename T> class EdgeMap : public GraphWrapper<Graph>::template EdgeMap<T> { 
  1525     template<typename T, 
  1506       typedef typename GraphWrapper<Graph>::template EdgeMap<T> Parent;
  1526 	     typename Parent=
       
  1527 	     typename GraphWrapper<Graph>::template EdgeMap<T> > 
       
  1528     class EdgeMap : public Parent { 
       
  1529       //typedef typename GraphWrapper<Graph>::template EdgeMap<T> Parent;
  1507       typename GraphWrapper<Graph>::template NodeMap<T> node_value;
  1530       typename GraphWrapper<Graph>::template NodeMap<T> node_value;
  1508     public:
  1531     public:
  1509       EdgeMap(const stGraphWrapper<Graph>& _G) : Parent(_G), 
  1532       EdgeMap(const stGraphWrapper<Graph>& _G) : Parent(_G), 
  1510 						 node_value(_G) { }
  1533 						 node_value(_G) { }
  1511       EdgeMap(const stGraphWrapper<Graph>& _G, T a) : Parent(_G, a), 
  1534       EdgeMap(const stGraphWrapper<Graph>& _G, T a) : Parent(_G, a), 
  1525 	}
  1548 	}
  1526       }
  1549       }
  1527       void set(const Edge& e, T t) { 
  1550       void set(const Edge& e, T t) { 
  1528 	switch (e.spec) {
  1551 	switch (e.spec) {
  1529 	case 0: 
  1552 	case 0: 
  1530 	  GraphWrapper<Graph>::template EdgeMap<T>::set(e, t);
  1553 	  Parent::set(e, t);
  1531 	  break;
  1554 	  break;
  1532 	case 1:
  1555 	case 1:
  1533 	  node_value.set(e.n, t);
  1556 	  node_value.set(e.n, t);
  1534 	  break;
  1557 	  break;
  1535 	case 2:
  1558 	case 2:
  1537 	  node_value.set(e.n, t);
  1560 	  node_value.set(e.n, t);
  1538 	  break;
  1561 	  break;
  1539 	}
  1562 	}
  1540       }
  1563       }
  1541     };
  1564     };
       
  1565 
       
  1566 //     template<typename T> class EdgeMap : public GraphWrapper<Graph>::template EdgeMap<T> { 
       
  1567 //       typedef typename GraphWrapper<Graph>::template EdgeMap<T> Parent;
       
  1568 //       typename GraphWrapper<Graph>::template NodeMap<T> node_value;
       
  1569 //     public:
       
  1570 //       EdgeMap(const stGraphWrapper<Graph>& _G) : Parent(_G), 
       
  1571 // 						 node_value(_G) { }
       
  1572 //       EdgeMap(const stGraphWrapper<Graph>& _G, T a) : Parent(_G, a), 
       
  1573 // 						      node_value(_G, a) { }
       
  1574 //       T operator[](const Edge& e) const { 
       
  1575 // 	switch (e.spec) {
       
  1576 // 	case 0: 
       
  1577 // 	  return Parent::operator[](e);
       
  1578 // 	  break;
       
  1579 // 	case 1:
       
  1580 // 	  return node_value[e.n];
       
  1581 // 	  break;
       
  1582 // 	case 2:
       
  1583 // 	default:
       
  1584 // 	  return node_value[e.n];
       
  1585 // 	  break;
       
  1586 // 	}
       
  1587 //       }
       
  1588 //       void set(const Edge& e, T t) { 
       
  1589 // 	switch (e.spec) {
       
  1590 // 	case 0: 
       
  1591 // 	  GraphWrapper<Graph>::template EdgeMap<T>::set(e, t);
       
  1592 // 	  break;
       
  1593 // 	case 1:
       
  1594 // 	  node_value.set(e.n, t);
       
  1595 // 	  break;
       
  1596 // 	case 2:
       
  1597 // 	default:
       
  1598 // 	  node_value.set(e.n, t);
       
  1599 // 	  break;
       
  1600 // 	}
       
  1601 //       }
       
  1602 //     };
       
  1603 
       
  1604     friend std::ostream& operator<<(std::ostream& os, const Node& i) { 
       
  1605       os << "(node: " << typename Graph::Node(i) << " spec: " << i.spec <<")"; 
       
  1606       return os; 
       
  1607     }
       
  1608     friend std::ostream& operator<<(std::ostream& os, const Edge& i) { 
       
  1609       os << "(edge: " << typename Graph::Edge(i) << " spec: " << i.spec << 
       
  1610 	" node: " << i.n << ")"; 
       
  1611       return os; 
       
  1612     }
       
  1613 
  1542   };
  1614   };
  1543 
  1615 
  1544   ///@}
  1616   ///@}
  1545 
  1617 
  1546 } //namespace hugo
  1618 } //namespace hugo