lemon/graph_adaptor.h
changeset 2386 81b47fc5c444
parent 2384 805c5a2a36dd
child 2391 14a343be7a5a
equal deleted inserted replaced
43:b970e4c777ab 44:346747910baa
    91     
    91     
    92     typedef EdgeNumTagIndicator<Graph> EdgeNumTag;
    92     typedef EdgeNumTagIndicator<Graph> EdgeNumTag;
    93     int edgeNum() const { return graph->edgeNum(); }
    93     int edgeNum() const { return graph->edgeNum(); }
    94 
    94 
    95     typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
    95     typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
    96     Edge findEdge(const Node& source, const Node& target, 
    96     Edge findEdge(const Node& u, const Node& v, 
    97 		  const Edge& prev = INVALID) {
    97 		  const Edge& prev = INVALID) {
    98       return graph->findEdge(source, target, prev);
    98       return graph->findEdge(u, v, prev);
    99     }
    99     }
   100   
   100   
   101     Node addNode() const { 
   101     Node addNode() const { 
   102       return Node(graph->addNode()); 
   102       return Node(graph->addNode()); 
   103     }
   103     }
   104 
   104 
   105     Edge addEdge(const Node& source, const Node& target) const { 
   105     Edge addEdge(const Node& u, const Node& v) const { 
   106       return Edge(graph->addEdge(source, target)); 
   106       return Edge(graph->addEdge(u, v)); 
   107     }
   107     }
   108 
   108 
   109     void erase(const Node& i) const { graph->erase(i); }
   109     void erase(const Node& i) const { graph->erase(i); }
   110     void erase(const Edge& i) const { graph->erase(i); }
   110     void erase(const Edge& i) const { graph->erase(i); }
   111   
   111   
   112     void clear() const { graph->clear(); }
   112     void clear() const { graph->clear(); }
   113     
   113     
   114     int id(const Node& v) const { return graph->id(v); }
   114     int id(const Node& v) const { return graph->id(v); }
   115     int id(const Edge& e) const { return graph->id(e); }
   115     int id(const Edge& e) const { return graph->id(e); }
   116 
   116 
   117     Node fromNodeId(int id) const {
   117     Node fromNodeId(int ix) const {
   118       return graph->fromNodeId(id);
   118       return graph->fromNodeId(ix);
   119     }
   119     }
   120 
   120 
   121     Edge fromEdgeId(int id) const {
   121     Edge fromEdgeId(int ix) const {
   122       return graph->fromEdgeId(id);
   122       return graph->fromEdgeId(ix);
   123     }
   123     }
   124 
   124 
   125     int maxNodeId() const {
   125     int maxNodeId() const {
   126       return graph->maxNodeId();
   126       return graph->maxNodeId();
   127     }
   127     }
   241 
   241 
   242     Node source(const Edge& e) const { return Parent::target(e); }
   242     Node source(const Edge& e) const { return Parent::target(e); }
   243     Node target(const Edge& e) const { return Parent::source(e); }
   243     Node target(const Edge& e) const { return Parent::source(e); }
   244 
   244 
   245     typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
   245     typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
   246     Edge findEdge(const Node& source, const Node& target, 
   246     Edge findEdge(const Node& u, const Node& v, 
   247 		  const Edge& prev = INVALID) {
   247 		  const Edge& prev = INVALID) {
   248       return Parent::findEdge(target, source, prev);
   248       return Parent::findEdge(v, u, prev);
   249     }
   249     }
   250 
   250 
   251   };
   251   };
   252     
   252     
   253 
   253 
   458     public:
   458     public:
   459       typedef Adaptor Graph;
   459       typedef Adaptor Graph;
   460       typedef SubMapExtender<Adaptor, typename Parent::
   460       typedef SubMapExtender<Adaptor, typename Parent::
   461                              template NodeMap<_Value> > Parent;
   461                              template NodeMap<_Value> > Parent;
   462     
   462     
   463       NodeMap(const Graph& graph) 
   463       NodeMap(const Graph& g) 
   464 	: Parent(graph) {}
   464 	: Parent(g) {}
   465       NodeMap(const Graph& graph, const _Value& value) 
   465       NodeMap(const Graph& g, const _Value& v) 
   466 	: Parent(graph, value) {}
   466 	: Parent(g, v) {}
   467     
   467     
   468       NodeMap& operator=(const NodeMap& cmap) {
   468       NodeMap& operator=(const NodeMap& cmap) {
   469 	return operator=<NodeMap>(cmap);
   469 	return operator=<NodeMap>(cmap);
   470       }
   470       }
   471     
   471     
   484     public:
   484     public:
   485       typedef Adaptor Graph;
   485       typedef Adaptor Graph;
   486       typedef SubMapExtender<Adaptor, typename Parent::
   486       typedef SubMapExtender<Adaptor, typename Parent::
   487                              template EdgeMap<_Value> > Parent;
   487                              template EdgeMap<_Value> > Parent;
   488     
   488     
   489       EdgeMap(const Graph& graph) 
   489       EdgeMap(const Graph& g) 
   490 	: Parent(graph) {}
   490 	: Parent(g) {}
   491       EdgeMap(const Graph& graph, const _Value& value) 
   491       EdgeMap(const Graph& g, const _Value& v) 
   492 	: Parent(graph, value) {}
   492 	: Parent(g, v) {}
   493     
   493     
   494       EdgeMap& operator=(const EdgeMap& cmap) {
   494       EdgeMap& operator=(const EdgeMap& cmap) {
   495 	return operator=<EdgeMap>(cmap);
   495 	return operator=<EdgeMap>(cmap);
   496       }
   496       }
   497     
   497     
   631     public:
   631     public:
   632       typedef Adaptor Graph;
   632       typedef Adaptor Graph;
   633       typedef SubMapExtender<Adaptor, typename Parent::
   633       typedef SubMapExtender<Adaptor, typename Parent::
   634                              template NodeMap<_Value> > Parent;
   634                              template NodeMap<_Value> > Parent;
   635     
   635     
   636       NodeMap(const Graph& graph) 
   636       NodeMap(const Graph& g) 
   637 	: Parent(graph) {}
   637 	: Parent(g) {}
   638       NodeMap(const Graph& graph, const _Value& value) 
   638       NodeMap(const Graph& g, const _Value& v) 
   639 	: Parent(graph, value) {}
   639 	: Parent(g, v) {}
   640     
   640     
   641       NodeMap& operator=(const NodeMap& cmap) {
   641       NodeMap& operator=(const NodeMap& cmap) {
   642 	return operator=<NodeMap>(cmap);
   642 	return operator=<NodeMap>(cmap);
   643       }
   643       }
   644     
   644     
   657     public:
   657     public:
   658       typedef Adaptor Graph;
   658       typedef Adaptor Graph;
   659       typedef SubMapExtender<Adaptor, typename Parent::
   659       typedef SubMapExtender<Adaptor, typename Parent::
   660                              template EdgeMap<_Value> > Parent;
   660                              template EdgeMap<_Value> > Parent;
   661     
   661     
   662       EdgeMap(const Graph& graph) 
   662       EdgeMap(const Graph& g) 
   663 	: Parent(graph) {}
   663 	: Parent(g) {}
   664       EdgeMap(const Graph& graph, const _Value& value) 
   664       EdgeMap(const Graph& g, const _Value& v) 
   665 	: Parent(graph, value) {}
   665 	: Parent(g, v) {}
   666     
   666     
   667       EdgeMap& operator=(const EdgeMap& cmap) {
   667       EdgeMap& operator=(const EdgeMap& cmap) {
   668 	return operator=<EdgeMap>(cmap);
   668 	return operator=<EdgeMap>(cmap);
   669       }
   669       }
   670     
   670     
  1103     {
  1103     {
  1104     public:
  1104     public:
  1105       typedef Adaptor Graph;
  1105       typedef Adaptor Graph;
  1106       typedef SubMapExtender<Adaptor, EdgeMapBase<_Value> > Parent;
  1106       typedef SubMapExtender<Adaptor, EdgeMapBase<_Value> > Parent;
  1107     
  1107     
  1108       EdgeMap(const Graph& graph) 
  1108       EdgeMap(const Graph& g) 
  1109 	: Parent(graph) {}
  1109 	: Parent(g) {}
  1110       EdgeMap(const Graph& graph, const _Value& value) 
  1110       EdgeMap(const Graph& g, const _Value& v) 
  1111 	: Parent(graph, value) {}
  1111 	: Parent(g, v) {}
  1112     
  1112     
  1113       EdgeMap& operator=(const EdgeMap& cmap) {
  1113       EdgeMap& operator=(const EdgeMap& cmap) {
  1114 	return operator=<EdgeMap>(cmap);
  1114 	return operator=<EdgeMap>(cmap);
  1115       }
  1115       }
  1116     
  1116     
  1178   protected:
  1178   protected:
  1179 
  1179 
  1180     AlterableUndirGraphAdaptor() 
  1180     AlterableUndirGraphAdaptor() 
  1181       : Parent(), edge_notifier(*this), edge_notifier_proxy(*this) {}
  1181       : Parent(), edge_notifier(*this), edge_notifier_proxy(*this) {}
  1182 
  1182 
  1183     void setGraph(_Graph& graph) {
  1183     void setGraph(_Graph& g) {
  1184       Parent::setGraph(graph);
  1184       Parent::setGraph(g);
  1185       edge_notifier_proxy.setNotifier(graph.notifier(GraphEdge()));
  1185       edge_notifier_proxy.setNotifier(g.notifier(GraphEdge()));
  1186     }
  1186     }
  1187 
  1187 
  1188   public:
  1188   public:
  1189 
  1189 
  1190     ~AlterableUndirGraphAdaptor() {
  1190     ~AlterableUndirGraphAdaptor() {
  1218         if (Parent::attached()) {
  1218         if (Parent::attached()) {
  1219           Parent::detach();
  1219           Parent::detach();
  1220         }
  1220         }
  1221       }
  1221       }
  1222 
  1222 
  1223       void setNotifier(typename Graph::EdgeNotifier& notifier) {
  1223       void setNotifier(typename Graph::EdgeNotifier& nf) {
  1224         Parent::attach(notifier);
  1224         Parent::attach(nf);
  1225       }
  1225       }
  1226 
  1226 
  1227       
  1227       
  1228     protected:
  1228     protected:
  1229 
  1229 
  1233         edges.push_back(AdaptorBase::Parent::direct(ge, false));
  1233         edges.push_back(AdaptorBase::Parent::direct(ge, false));
  1234         adaptor->notifier(Edge()).add(edges);
  1234         adaptor->notifier(Edge()).add(edges);
  1235       }
  1235       }
  1236       virtual void add(const std::vector<GraphEdge>& ge) {
  1236       virtual void add(const std::vector<GraphEdge>& ge) {
  1237         std::vector<Edge> edges;
  1237         std::vector<Edge> edges;
  1238         for (int i = 0; i < (int)ge.size(); ++i) { 
  1238         for (int i = 0; i < int(ge.size()); ++i) { 
  1239           edges.push_back(AdaptorBase::Parent::direct(ge[i], true));
  1239           edges.push_back(AdaptorBase::Parent::direct(ge[i], true));
  1240           edges.push_back(AdaptorBase::Parent::direct(ge[i], false));
  1240           edges.push_back(AdaptorBase::Parent::direct(ge[i], false));
  1241         }
  1241         }
  1242         adaptor->notifier(Edge()).add(edges);
  1242         adaptor->notifier(Edge()).add(edges);
  1243       }
  1243       }
  1247         edges.push_back(AdaptorBase::Parent::direct(ge, false));
  1247         edges.push_back(AdaptorBase::Parent::direct(ge, false));
  1248         adaptor->notifier(Edge()).erase(edges);
  1248         adaptor->notifier(Edge()).erase(edges);
  1249       }
  1249       }
  1250       virtual void erase(const std::vector<GraphEdge>& ge) {
  1250       virtual void erase(const std::vector<GraphEdge>& ge) {
  1251         std::vector<Edge> edges;
  1251         std::vector<Edge> edges;
  1252         for (int i = 0; i < (int)ge.size(); ++i) { 
  1252         for (int i = 0; i < int(ge.size()); ++i) { 
  1253           edges.push_back(AdaptorBase::Parent::direct(ge[i], true));
  1253           edges.push_back(AdaptorBase::Parent::direct(ge[i], true));
  1254           edges.push_back(AdaptorBase::Parent::direct(ge[i], false));
  1254           edges.push_back(AdaptorBase::Parent::direct(ge[i], false));
  1255         }
  1255         }
  1256         adaptor->notifier(Edge()).erase(edges);
  1256         adaptor->notifier(Edge()).erase(edges);
  1257       }
  1257       }
  1819       operator GraphEdge() const { return item.first(); }
  1819       operator GraphEdge() const { return item.first(); }
  1820       operator GraphNode() const { return item.second(); }
  1820       operator GraphNode() const { return item.second(); }
  1821 
  1821 
  1822     };
  1822     };
  1823 
  1823 
  1824     void first(Node& node) const {
  1824     void first(Node& n) const {
  1825       Parent::first(node);
  1825       Parent::first(n);
  1826       node.in_node = true;
  1826       n.in_node = true;
  1827     }
  1827     }
  1828 
  1828 
  1829     void next(Node& node) const {
  1829     void next(Node& n) const {
  1830       if (node.in_node) {
  1830       if (n.in_node) {
  1831 	node.in_node = false;
  1831 	n.in_node = false;
  1832       } else {
  1832       } else {
  1833 	node.in_node = true;
  1833 	n.in_node = true;
  1834 	Parent::next(node);
  1834 	Parent::next(n);
  1835       }
  1835       }
  1836     }
  1836     }
  1837 
  1837 
  1838     void first(Edge& edge) const {
  1838     void first(Edge& e) const {
  1839       edge.item.setSecond();
  1839       e.item.setSecond();
  1840       Parent::first(edge.item.second());
  1840       Parent::first(e.item.second());
  1841       if (edge.item.second() == INVALID) {
  1841       if (e.item.second() == INVALID) {
  1842         edge.item.setFirst();
  1842         e.item.setFirst();
  1843 	Parent::first(edge.item.first());
  1843 	Parent::first(e.item.first());
  1844       }
  1844       }
  1845     }
  1845     }
  1846 
  1846 
  1847     void next(Edge& edge) const {
  1847     void next(Edge& e) const {
  1848       if (edge.item.secondState()) {
  1848       if (e.item.secondState()) {
  1849 	Parent::next(edge.item.second());
  1849 	Parent::next(e.item.second());
  1850         if (edge.item.second() == INVALID) {
  1850         if (e.item.second() == INVALID) {
  1851           edge.item.setFirst();
  1851           e.item.setFirst();
  1852           Parent::first(edge.item.first());
  1852           Parent::first(e.item.first());
  1853         }
  1853         }
  1854       } else {
  1854       } else {
  1855 	Parent::next(edge.item.first());
  1855 	Parent::next(e.item.first());
  1856       }      
  1856       }      
  1857     }
  1857     }
  1858 
  1858 
  1859     void firstOut(Edge& edge, const Node& node) const {
  1859     void firstOut(Edge& e, const Node& n) const {
  1860       if (node.in_node) {
  1860       if (n.in_node) {
  1861         edge.item.setSecond(node);
  1861         e.item.setSecond(n);
  1862       } else {
  1862       } else {
  1863         edge.item.setFirst();
  1863         e.item.setFirst();
  1864 	Parent::firstOut(edge.item.first(), node);
  1864 	Parent::firstOut(e.item.first(), n);
  1865       }
  1865       }
  1866     }
  1866     }
  1867 
  1867 
  1868     void nextOut(Edge& edge) const {
  1868     void nextOut(Edge& e) const {
  1869       if (!edge.item.firstState()) {
  1869       if (!e.item.firstState()) {
  1870 	edge.item.setFirst(INVALID);
  1870 	e.item.setFirst(INVALID);
  1871       } else {
  1871       } else {
  1872 	Parent::nextOut(edge.item.first());
  1872 	Parent::nextOut(e.item.first());
  1873       }      
  1873       }      
  1874     }
  1874     }
  1875 
  1875 
  1876     void firstIn(Edge& edge, const Node& node) const {
  1876     void firstIn(Edge& e, const Node& n) const {
  1877       if (!node.in_node) {
  1877       if (!n.in_node) {
  1878         edge.item.setSecond(node);        
  1878         e.item.setSecond(n);        
  1879       } else {
  1879       } else {
  1880         edge.item.setFirst();
  1880         e.item.setFirst();
  1881 	Parent::firstIn(edge.item.first(), node);
  1881 	Parent::firstIn(e.item.first(), n);
  1882       }
  1882       }
  1883     }
  1883     }
  1884 
  1884 
  1885     void nextIn(Edge& edge) const {
  1885     void nextIn(Edge& e) const {
  1886       if (!edge.item.firstState()) {
  1886       if (!e.item.firstState()) {
  1887 	edge.item.setFirst(INVALID);
  1887 	e.item.setFirst(INVALID);
  1888       } else {
  1888       } else {
  1889 	Parent::nextIn(edge.item.first());
  1889 	Parent::nextIn(e.item.first());
  1890       }
  1890       }
  1891     }
  1891     }
  1892 
  1892 
  1893     Node source(const Edge& edge) const {
  1893     Node source(const Edge& e) const {
  1894       if (edge.item.firstState()) {
  1894       if (e.item.firstState()) {
  1895 	return Node(Parent::source(edge.item.first()), false);
  1895 	return Node(Parent::source(e.item.first()), false);
  1896       } else {
  1896       } else {
  1897 	return Node(edge.item.second(), true);
  1897 	return Node(e.item.second(), true);
  1898       }
  1898       }
  1899     }
  1899     }
  1900 
  1900 
  1901     Node target(const Edge& edge) const {
  1901     Node target(const Edge& e) const {
  1902       if (edge.item.firstState()) {
  1902       if (e.item.firstState()) {
  1903 	return Node(Parent::target(edge.item.first()), true);
  1903 	return Node(Parent::target(e.item.first()), true);
  1904       } else {
  1904       } else {
  1905 	return Node(edge.item.second(), false);
  1905 	return Node(e.item.second(), false);
  1906       }
  1906       }
  1907     }
  1907     }
  1908 
  1908 
  1909     int id(const Node& node) const {
  1909     int id(const Node& n) const {
  1910       return (Parent::id(node) << 1) | (node.in_node ? 0 : 1);
  1910       return (Parent::id(n) << 1) | (n.in_node ? 0 : 1);
  1911     }
  1911     }
  1912     Node nodeFromId(int id) const {
  1912     Node nodeFromId(int ix) const {
  1913       return Node(Parent::nodeFromId(id >> 1), (id & 1) == 0);
  1913       return Node(Parent::nodeFromId(ix >> 1), (ix & 1) == 0);
  1914     }
  1914     }
  1915     int maxNodeId() const {
  1915     int maxNodeId() const {
  1916       return 2 * Parent::maxNodeId() + 1;
  1916       return 2 * Parent::maxNodeId() + 1;
  1917     }
  1917     }
  1918 
  1918 
  1919     int id(const Edge& edge) const {
  1919     int id(const Edge& e) const {
  1920       if (edge.item.firstState()) {
  1920       if (e.item.firstState()) {
  1921         return Parent::id(edge.item.first()) << 1;
  1921         return Parent::id(e.item.first()) << 1;
  1922       } else {
  1922       } else {
  1923         return (Parent::id(edge.item.second()) << 1) | 1;
  1923         return (Parent::id(e.item.second()) << 1) | 1;
  1924       }
  1924       }
  1925     }
  1925     }
  1926     Edge edgeFromId(int id) const {
  1926     Edge edgeFromId(int ix) const {
  1927       if ((id & 1) == 0) {
  1927       if ((ix & 1) == 0) {
  1928         return Edge(Parent::edgeFromId(id >> 1));
  1928         return Edge(Parent::edgeFromId(ix >> 1));
  1929       } else {
  1929       } else {
  1930         return Edge(Parent::nodeFromId(id >> 1));
  1930         return Edge(Parent::nodeFromId(ix >> 1));
  1931       }
  1931       }
  1932     }
  1932     }
  1933     int maxEdgeId() const {
  1933     int maxEdgeId() const {
  1934       return std::max(Parent::maxNodeId() << 1, 
  1934       return std::max(Parent::maxNodeId() << 1, 
  1935                       (Parent::maxEdgeId() << 1) | 1);
  1935                       (Parent::maxEdgeId() << 1) | 1);
  1936     }
  1936     }
  1937 
  1937 
  1938     /// \brief Returns true when the node is in-node.
  1938     /// \brief Returns true when the node is in-node.
  1939     ///
  1939     ///
  1940     /// Returns true when the node is in-node.
  1940     /// Returns true when the node is in-node.
  1941     static bool inNode(const Node& node) {
  1941     static bool inNode(const Node& n) {
  1942       return node.in_node;
  1942       return n.in_node;
  1943     }
  1943     }
  1944 
  1944 
  1945     /// \brief Returns true when the node is out-node.
  1945     /// \brief Returns true when the node is out-node.
  1946     ///
  1946     ///
  1947     /// Returns true when the node is out-node.
  1947     /// Returns true when the node is out-node.
  1948     static bool outNode(const Node& node) {
  1948     static bool outNode(const Node& n) {
  1949       return !node.in_node;
  1949       return !n.in_node;
  1950     }
  1950     }
  1951 
  1951 
  1952     /// \brief Returns true when the edge is edge in the original graph.
  1952     /// \brief Returns true when the edge is edge in the original graph.
  1953     ///
  1953     ///
  1954     /// Returns true when the edge is edge in the original graph.
  1954     /// Returns true when the edge is edge in the original graph.
  1955     static bool origEdge(const Edge& edge) {
  1955     static bool origEdge(const Edge& e) {
  1956       return edge.item.firstState();
  1956       return e.item.firstState();
  1957     }
  1957     }
  1958 
  1958 
  1959     /// \brief Returns true when the edge binds an in-node and an out-node.
  1959     /// \brief Returns true when the edge binds an in-node and an out-node.
  1960     ///
  1960     ///
  1961     /// Returns true when the edge binds an in-node and an out-node.
  1961     /// Returns true when the edge binds an in-node and an out-node.
  1962     static bool bindEdge(const Edge& edge) {
  1962     static bool bindEdge(const Edge& e) {
  1963       return edge.item.secondState();
  1963       return e.item.secondState();
  1964     }
  1964     }
  1965 
  1965 
  1966     /// \brief Gives back the in-node created from the \c node.
  1966     /// \brief Gives back the in-node created from the \c node.
  1967     ///
  1967     ///
  1968     /// Gives back the in-node created from the \c node.
  1968     /// Gives back the in-node created from the \c node.
  1969     static Node inNode(const GraphNode& node) {
  1969     static Node inNode(const GraphNode& n) {
  1970       return Node(node, true);
  1970       return Node(n, true);
  1971     }
  1971     }
  1972 
  1972 
  1973     /// \brief Gives back the out-node created from the \c node.
  1973     /// \brief Gives back the out-node created from the \c node.
  1974     ///
  1974     ///
  1975     /// Gives back the out-node created from the \c node.
  1975     /// Gives back the out-node created from the \c node.
  1976     static Node outNode(const GraphNode& node) {
  1976     static Node outNode(const GraphNode& n) {
  1977       return Node(node, false);
  1977       return Node(n, false);
  1978     }
  1978     }
  1979 
  1979 
  1980     /// \brief Gives back the edge binds the two part of the node.
  1980     /// \brief Gives back the edge binds the two part of the node.
  1981     /// 
  1981     /// 
  1982     /// Gives back the edge binds the two part of the node.
  1982     /// Gives back the edge binds the two part of the node.
  1983     static Edge edge(const GraphNode& node) {
  1983     static Edge edge(const GraphNode& n) {
  1984       return Edge(node);
  1984       return Edge(n);
  1985     }
  1985     }
  1986 
  1986 
  1987     /// \brief Gives back the edge of the original edge.
  1987     /// \brief Gives back the edge of the original edge.
  1988     /// 
  1988     /// 
  1989     /// Gives back the edge of the original edge.
  1989     /// Gives back the edge of the original edge.
  1990     static Edge edge(const GraphEdge& edge) {
  1990     static Edge edge(const GraphEdge& e) {
  1991       return Edge(edge);
  1991       return Edge(e);
  1992     }
  1992     }
  1993 
  1993 
  1994     typedef True NodeNumTag;
  1994     typedef True NodeNumTag;
  1995 
  1995 
  1996     int nodeNum() const {
  1996     int nodeNum() const {
  2003       return countEdges(*Parent::graph) + countNodes(*Parent::graph);
  2003       return countEdges(*Parent::graph) + countNodes(*Parent::graph);
  2004     }
  2004     }
  2005 
  2005 
  2006     typedef True FindEdgeTag;
  2006     typedef True FindEdgeTag;
  2007 
  2007 
  2008     Edge findEdge(const Node& source, const Node& target, 
  2008     Edge findEdge(const Node& u, const Node& v, 
  2009 		  const Edge& prev = INVALID) const {
  2009 		  const Edge& prev = INVALID) const {
  2010       if (inNode(source)) {
  2010       if (inNode(u)) {
  2011         if (outNode(target)) {
  2011         if (outNode(v)) {
  2012           if ((GraphNode&)source == (GraphNode&)target && prev == INVALID) {
  2012           if (static_cast<const GraphNode&>(u) == 
  2013             return Edge(source);
  2013               static_cast<const GraphNode&>(v) && prev == INVALID) {
       
  2014             return Edge(u);
  2014           }
  2015           }
  2015         }
  2016         }
  2016       } else {
  2017       } else {
  2017         if (inNode(target)) {
  2018         if (inNode(v)) {
  2018           return Edge(findEdge(*Parent::graph, source, target, prev));
  2019           return Edge(findEdge(*Parent::graph, u, v, prev));
  2019         }
  2020         }
  2020       }
  2021       }
  2021       return INVALID;
  2022       return INVALID;
  2022     }
  2023     }
  2023     
  2024     
  2189         adaptor->notifier(Node()).add(nodes);
  2190         adaptor->notifier(Node()).add(nodes);
  2190       }
  2191       }
  2191 
  2192 
  2192       virtual void add(const std::vector<GraphNode>& gn) {
  2193       virtual void add(const std::vector<GraphNode>& gn) {
  2193         std::vector<Node> nodes;
  2194         std::vector<Node> nodes;
  2194         for (int i = 0; i < (int)gn.size(); ++i) {
  2195         for (int i = 0; i < int(gn.size()); ++i) {
  2195           nodes.push_back(AdaptorBase::Parent::inNode(gn[i]));
  2196           nodes.push_back(AdaptorBase::Parent::inNode(gn[i]));
  2196           nodes.push_back(AdaptorBase::Parent::outNode(gn[i]));
  2197           nodes.push_back(AdaptorBase::Parent::outNode(gn[i]));
  2197         }
  2198         }
  2198         adaptor->notifier(Node()).add(nodes);
  2199         adaptor->notifier(Node()).add(nodes);
  2199       }
  2200       }
  2205         adaptor->notifier(Node()).erase(nodes);
  2206         adaptor->notifier(Node()).erase(nodes);
  2206       }
  2207       }
  2207 
  2208 
  2208       virtual void erase(const std::vector<GraphNode>& gn) {
  2209       virtual void erase(const std::vector<GraphNode>& gn) {
  2209         std::vector<Node> nodes;
  2210         std::vector<Node> nodes;
  2210         for (int i = 0; i < (int)gn.size(); ++i) {
  2211         for (int i = 0; i < int(gn.size()); ++i) {
  2211           nodes.push_back(AdaptorBase::Parent::inNode(gn[i]));
  2212           nodes.push_back(AdaptorBase::Parent::inNode(gn[i]));
  2212           nodes.push_back(AdaptorBase::Parent::outNode(gn[i]));
  2213           nodes.push_back(AdaptorBase::Parent::outNode(gn[i]));
  2213         }
  2214         }
  2214         adaptor->notifier(Node()).erase(nodes);
  2215         adaptor->notifier(Node()).erase(nodes);
  2215       }
  2216       }
  2251     
  2252     
  2252     AlterableSplitGraphAdaptor() 
  2253     AlterableSplitGraphAdaptor() 
  2253       : Parent(), node_notifier(*this), edge_notifier(*this), 
  2254       : Parent(), node_notifier(*this), edge_notifier(*this), 
  2254         node_notifier_proxy(*this), edge_notifier_proxy(*this) {}
  2255         node_notifier_proxy(*this), edge_notifier_proxy(*this) {}
  2255     
  2256     
  2256     void setGraph(_Graph& graph) {
  2257     void setGraph(_Graph& g) {
  2257       Parent::setGraph(graph);
  2258       Parent::setGraph(g);
  2258       node_notifier_proxy.setNotifier(graph.notifier(GraphNode()));
  2259       node_notifier_proxy.setNotifier(g.notifier(GraphNode()));
  2259       edge_notifier_proxy.setNotifier(graph.notifier(GraphEdge()));
  2260       edge_notifier_proxy.setNotifier(g.notifier(GraphEdge()));
  2260     }
  2261     }
  2261 
  2262 
  2262   public:
  2263   public:
  2263 
  2264 
  2264     ~AlterableSplitGraphAdaptor() {
  2265     ~AlterableSplitGraphAdaptor() {
  2305         adaptor->notifier(Edge()).add(AdaptorBase::Parent::edge(gn));
  2306         adaptor->notifier(Edge()).add(AdaptorBase::Parent::edge(gn));
  2306       }
  2307       }
  2307       virtual void add(const std::vector<GraphNode>& gn) {
  2308       virtual void add(const std::vector<GraphNode>& gn) {
  2308         std::vector<Node> nodes;
  2309         std::vector<Node> nodes;
  2309         std::vector<Edge> edges;
  2310         std::vector<Edge> edges;
  2310         for (int i = 0; i < (int)gn.size(); ++i) {
  2311         for (int i = 0; i < int(gn.size()); ++i) {
  2311           edges.push_back(AdaptorBase::Parent::edge(gn[i]));
  2312           edges.push_back(AdaptorBase::Parent::edge(gn[i]));
  2312           nodes.push_back(AdaptorBase::Parent::inNode(gn[i]));
  2313           nodes.push_back(AdaptorBase::Parent::inNode(gn[i]));
  2313           nodes.push_back(AdaptorBase::Parent::outNode(gn[i]));
  2314           nodes.push_back(AdaptorBase::Parent::outNode(gn[i]));
  2314         }
  2315         }
  2315         adaptor->notifier(Node()).add(nodes);
  2316         adaptor->notifier(Node()).add(nodes);
  2323         adaptor->notifier(Node()).erase(nodes);
  2324         adaptor->notifier(Node()).erase(nodes);
  2324       }
  2325       }
  2325       virtual void erase(const std::vector<GraphNode>& gn) {
  2326       virtual void erase(const std::vector<GraphNode>& gn) {
  2326         std::vector<Node> nodes;
  2327         std::vector<Node> nodes;
  2327         std::vector<Edge> edges;
  2328         std::vector<Edge> edges;
  2328         for (int i = 0; i < (int)gn.size(); ++i) {
  2329         for (int i = 0; i < int(gn.size()); ++i) {
  2329           edges.push_back(AdaptorBase::Parent::edge(gn[i]));
  2330           edges.push_back(AdaptorBase::Parent::edge(gn[i]));
  2330           nodes.push_back(AdaptorBase::Parent::inNode(gn[i]));
  2331           nodes.push_back(AdaptorBase::Parent::inNode(gn[i]));
  2331           nodes.push_back(AdaptorBase::Parent::outNode(gn[i]));
  2332           nodes.push_back(AdaptorBase::Parent::outNode(gn[i]));
  2332         }
  2333         }
  2333         adaptor->notifier(Edge()).erase(edges);
  2334         adaptor->notifier(Edge()).erase(edges);
  2334         adaptor->notifier(Node()).erase(nodes);
  2335         adaptor->notifier(Node()).erase(nodes);
  2335       }
  2336       }
  2336       virtual void build() {
  2337       virtual void build() {
  2337         std::vector<Edge> edges;
  2338         std::vector<Edge> edges;
  2338         const typename Parent::Notifier* notifier = Parent::notifier();
  2339         const typename Parent::Notifier* nf = Parent::notifier();
  2339         GraphNode it;
  2340         GraphNode it;
  2340         for (notifier->first(it); it != INVALID; notifier->next(it)) {
  2341         for (nf->first(it); it != INVALID; nf->next(it)) {
  2341           edges.push_back(AdaptorBase::Parent::edge(it));
  2342           edges.push_back(AdaptorBase::Parent::edge(it));
  2342         }
  2343         }
  2343         adaptor->notifier(Node()).build();
  2344         adaptor->notifier(Node()).build();
  2344         adaptor->notifier(Edge()).add(edges);        
  2345         adaptor->notifier(Edge()).add(edges);        
  2345       }
  2346       }
  2346       virtual void clear() {
  2347       virtual void clear() {
  2347         std::vector<Edge> edges;
  2348         std::vector<Edge> edges;
  2348         const typename Parent::Notifier* notifier = Parent::notifier();
  2349         const typename Parent::Notifier* nf = Parent::notifier();
  2349         GraphNode it;
  2350         GraphNode it;
  2350         for (notifier->first(it); it != INVALID; notifier->next(it)) {
  2351         for (nf->first(it); it != INVALID; nf->next(it)) {
  2351           edges.push_back(AdaptorBase::Parent::edge(it));
  2352           edges.push_back(AdaptorBase::Parent::edge(it));
  2352         }
  2353         }
  2353         adaptor->notifier(Edge()).erase(edges);        
  2354         adaptor->notifier(Edge()).erase(edges);        
  2354         adaptor->notifier(Node()).clear();
  2355         adaptor->notifier(Node()).clear();
  2355       }
  2356       }
  2383       virtual void add(const GraphEdge& ge) {
  2384       virtual void add(const GraphEdge& ge) {
  2384         adaptor->notifier(Edge()).add(AdaptorBase::edge(ge));
  2385         adaptor->notifier(Edge()).add(AdaptorBase::edge(ge));
  2385       }
  2386       }
  2386       virtual void add(const std::vector<GraphEdge>& ge) {
  2387       virtual void add(const std::vector<GraphEdge>& ge) {
  2387         std::vector<Edge> edges;
  2388         std::vector<Edge> edges;
  2388         for (int i = 0; i < (int)ge.size(); ++i) {
  2389         for (int i = 0; i < int(ge.size()); ++i) {
  2389           edges.push_back(AdaptorBase::edge(ge[i]));
  2390           edges.push_back(AdaptorBase::edge(ge[i]));
  2390         }
  2391         }
  2391         adaptor->notifier(Edge()).add(edges);
  2392         adaptor->notifier(Edge()).add(edges);
  2392       }
  2393       }
  2393       virtual void erase(const GraphEdge& ge) {
  2394       virtual void erase(const GraphEdge& ge) {
  2394         adaptor->notifier(Edge()).erase(AdaptorBase::edge(ge));
  2395         adaptor->notifier(Edge()).erase(AdaptorBase::edge(ge));
  2395       }
  2396       }
  2396       virtual void erase(const std::vector<GraphEdge>& ge) {
  2397       virtual void erase(const std::vector<GraphEdge>& ge) {
  2397         std::vector<Edge> edges;
  2398         std::vector<Edge> edges;
  2398         for (int i = 0; i < (int)ge.size(); ++i) {
  2399         for (int i = 0; i < int(ge.size()); ++i) {
  2399           edges.push_back(AdaptorBase::edge(ge[i]));
  2400           edges.push_back(AdaptorBase::edge(ge[i]));
  2400         }
  2401         }
  2401         adaptor->notifier(Edge()).erase(edges);
  2402         adaptor->notifier(Edge()).erase(edges);
  2402       }
  2403       }
  2403       virtual void build() {
  2404       virtual void build() {
  2404         std::vector<Edge> edges;
  2405         std::vector<Edge> edges;
  2405         const typename Parent::Notifier* notifier = Parent::notifier();
  2406         const typename Parent::Notifier* nf = Parent::notifier();
  2406         GraphEdge it;
  2407         GraphEdge it;
  2407         for (notifier->first(it); it != INVALID; notifier->next(it)) {
  2408         for (nf->first(it); it != INVALID; nf->next(it)) {
  2408           edges.push_back(AdaptorBase::Parent::edge(it));
  2409           edges.push_back(AdaptorBase::Parent::edge(it));
  2409         }
  2410         }
  2410         adaptor->notifier(Edge()).add(edges);
  2411         adaptor->notifier(Edge()).add(edges);
  2411       }
  2412       }
  2412       virtual void clear() {
  2413       virtual void clear() {
  2413         std::vector<Edge> edges;
  2414         std::vector<Edge> edges;
  2414         const typename Parent::Notifier* notifier = Parent::notifier();
  2415         const typename Parent::Notifier* nf = Parent::notifier();
  2415         GraphEdge it;
  2416         GraphEdge it;
  2416         for (notifier->first(it); it != INVALID; notifier->next(it)) {
  2417         for (nf->first(it); it != INVALID; nf->next(it)) {
  2417           edges.push_back(AdaptorBase::Parent::edge(it));
  2418           edges.push_back(AdaptorBase::Parent::edge(it));
  2418         }
  2419         }
  2419         adaptor->notifier(Edge()).erase(edges);
  2420         adaptor->notifier(Edge()).erase(edges);
  2420       }
  2421       }
  2421 
  2422 
  2507     typedef typename Parent::Edge Edge;
  2508     typedef typename Parent::Edge Edge;
  2508 
  2509 
  2509     /// \brief Constructor of the adaptor.
  2510     /// \brief Constructor of the adaptor.
  2510     ///
  2511     ///
  2511     /// Constructor of the adaptor.
  2512     /// Constructor of the adaptor.
  2512     SplitGraphAdaptor(_Graph& graph) {
  2513     SplitGraphAdaptor(_Graph& g) {
  2513       Parent::setGraph(graph);
  2514       Parent::setGraph(g);
  2514     }
  2515     }
  2515 
  2516 
  2516     /// \brief NodeMap combined from two original NodeMap
  2517     /// \brief NodeMap combined from two original NodeMap
  2517     ///
  2518     ///
  2518     /// This class adapt two of the original graph NodeMap to
  2519     /// This class adapt two of the original graph NodeMap to