1.1 --- a/demo/Makefile.am Wed Feb 22 12:45:59 2006 +0000
1.2 +++ b/demo/Makefile.am Wed Feb 22 18:26:56 2006 +0000
1.3 @@ -16,7 +16,7 @@
1.4 sub_graph_adaptor_demo \
1.5 descriptor_map_demo \
1.6 coloring \
1.7 - grid_graph_demo \
1.8 + grid_ugraph_demo \
1.9 topology_demo \
1.10 simann_maxcut_demo
1.11
1.12 @@ -43,7 +43,7 @@
1.13
1.14 graph_to_eps_demo_SOURCES = graph_to_eps_demo.cc
1.15
1.16 -grid_graph_demo_SOURCES = grid_graph_demo.cc
1.17 +grid_ugraph_demo_SOURCES = grid_ugraph_demo.cc
1.18
1.19 graph_orientation_SOURCES = graph_orientation.cc
1.20
2.1 --- a/demo/grid_graph_demo.cc Wed Feb 22 12:45:59 2006 +0000
2.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
2.3 @@ -1,102 +0,0 @@
2.4 -/* -*- C++ -*-
2.5 - *
2.6 - * This file is a part of LEMON, a generic C++ optimization library
2.7 - *
2.8 - * Copyright (C) 2003-2006
2.9 - * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
2.10 - * (Egervary Research Group on Combinatorial Optimization, EGRES).
2.11 - *
2.12 - * Permission to use, modify and distribute this software is granted
2.13 - * provided that this copyright notice appears in all copies. For
2.14 - * precise terms see the accompanying LICENSE file.
2.15 - *
2.16 - * This software is provided "AS IS" with no warranty of any kind,
2.17 - * express or implied, and with no claim as to its suitability for any
2.18 - * purpose.
2.19 - *
2.20 - */
2.21 -
2.22 -#include <lemon/grid_graph.h>
2.23 -#include <lemon/graph_adaptor.h>
2.24 -#include <lemon/graph_to_eps.h>
2.25 -#include <lemon/bfs.h>
2.26 -#include <lemon/xy.h>
2.27 -
2.28 -#include <iostream>
2.29 -#include <fstream>
2.30 -
2.31 -///\ingroup demos
2.32 -///\file
2.33 -///\brief Labirinth example with grid graph.
2.34 -///
2.35 -/// Labirinth example with grid graph.
2.36 -///
2.37 -/// The input file is:
2.38 -///
2.39 -/// \include grid_graph_demo.in
2.40 -///
2.41 -/// The result:
2.42 -///
2.43 -/// \image html grid_graph_demo.png
2.44 -/// \image latex grid_graph_demo.eps "The labirinth" width=\textwidth
2.45 -///
2.46 -/// The source:
2.47 -///
2.48 -/// \include grid_graph_demo.cc
2.49 -
2.50 -using namespace lemon;
2.51 -using namespace std;
2.52 -
2.53 -int main() {
2.54 - ifstream in("grid_graph_demo.in");
2.55 - int width, height;
2.56 - in >> width >> height;
2.57 - int start_x, start_y;
2.58 - in >> start_x >> start_y;
2.59 - int stop_x, stop_y;
2.60 - in >> stop_x >> stop_y;
2.61 -
2.62 - GridGraph graph(width, height);
2.63 - GridGraph::Node start = graph(start_x - 1, start_y - 1);
2.64 - GridGraph::Node stop = graph(stop_x - 1, stop_y - 1);
2.65 - GridGraph::NodeMap<bool> filter(graph);
2.66 -
2.67 - for (int j = 0; j < height; ++j) {
2.68 - in >> ws;
2.69 - for (int i = 0; i < width; ++i) {
2.70 - char c; in >> c;
2.71 - filter[graph(i, j)] = (c == '.');
2.72 - }
2.73 - }
2.74 -
2.75 - typedef NodeSubGraphAdaptor<GridGraph,
2.76 - GridGraph::NodeMap<bool> > FilteredGraph;
2.77 -
2.78 - FilteredGraph filtered(graph, filter);
2.79 -
2.80 - Bfs<FilteredGraph> bfs(filtered);
2.81 - std::cout << "The length of shortest path: " <<
2.82 - bfs.run(start, stop) << std::endl;
2.83 -
2.84 - FilteredGraph::EdgeMap<bool> path(filtered, false);
2.85 -
2.86 - for (GridGraph::Node node = stop;
2.87 - node != start; node = bfs.predNode(node)) {
2.88 - path[bfs.predEdge(node)] = true;
2.89 - }
2.90 -
2.91 - graphToEps(filtered, "grid_graph_demo.eps").scaleToA4().
2.92 - title("Grid graph").
2.93 - copyright("(C) 2006 LEMON Project").
2.94 - coords(scaleMap(indexMap(graph), 10)).
2.95 - enableParallel().
2.96 - nodeScale(0.5).
2.97 - drawArrows().
2.98 - edgeColors(composeMap(ColorSet(), path)).
2.99 - run();
2.100 -
2.101 - std::cout << "The shortest path is written to grid_graph_demo.eps"
2.102 - << std::endl;
2.103 -
2.104 - return 0;
2.105 -}
3.1 --- a/demo/grid_graph_demo.in Wed Feb 22 12:45:59 2006 +0000
3.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
3.3 @@ -1,10 +0,0 @@
3.4 -10 8
3.5 -1 1 10 8
3.6 -..X....X.X
3.7 -.XX.X.XX..
3.8 -....X..XX.
3.9 -XXXXXX.X..
3.10 -.........X
3.11 -.X.XXXXXXX
3.12 -.X...XX...
3.13 -.X.X....X.
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/demo/grid_ugraph_demo.cc Wed Feb 22 18:26:56 2006 +0000
4.3 @@ -0,0 +1,102 @@
4.4 +/* -*- C++ -*-
4.5 + *
4.6 + * This file is a part of LEMON, a generic C++ optimization library
4.7 + *
4.8 + * Copyright (C) 2003-2006
4.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
4.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
4.11 + *
4.12 + * Permission to use, modify and distribute this software is granted
4.13 + * provided that this copyright notice appears in all copies. For
4.14 + * precise terms see the accompanying LICENSE file.
4.15 + *
4.16 + * This software is provided "AS IS" with no warranty of any kind,
4.17 + * express or implied, and with no claim as to its suitability for any
4.18 + * purpose.
4.19 + *
4.20 + */
4.21 +
4.22 +#include <lemon/grid_ugraph.h>
4.23 +#include <lemon/graph_adaptor.h>
4.24 +#include <lemon/graph_to_eps.h>
4.25 +#include <lemon/bfs.h>
4.26 +#include <lemon/xy.h>
4.27 +
4.28 +#include <iostream>
4.29 +#include <fstream>
4.30 +
4.31 +///\ingroup demos
4.32 +///\file
4.33 +///\brief Labirinth example with grid ugraph.
4.34 +///
4.35 +/// Labirinth example with grid ugraph.
4.36 +///
4.37 +/// The input file is:
4.38 +///
4.39 +/// \include grid_ugraph_demo.in
4.40 +///
4.41 +/// The result:
4.42 +///
4.43 +/// \image html grid_ugraph_demo.png
4.44 +/// \image latex grid_ugraph_demo.eps "The labirinth" width=\textwidth
4.45 +///
4.46 +/// The source:
4.47 +///
4.48 +/// \include grid_ugraph_demo.cc
4.49 +
4.50 +using namespace lemon;
4.51 +using namespace std;
4.52 +
4.53 +int main() {
4.54 + ifstream in("grid_ugraph_demo.in");
4.55 + int width, height;
4.56 + in >> width >> height;
4.57 + int start_x, start_y;
4.58 + in >> start_x >> start_y;
4.59 + int stop_x, stop_y;
4.60 + in >> stop_x >> stop_y;
4.61 +
4.62 + GridUGraph ugraph(width, height);
4.63 + GridUGraph::Node start = ugraph(start_x - 1, start_y - 1);
4.64 + GridUGraph::Node stop = ugraph(stop_x - 1, stop_y - 1);
4.65 + GridUGraph::NodeMap<bool> filter(ugraph);
4.66 +
4.67 + for (int j = 0; j < height; ++j) {
4.68 + in >> ws;
4.69 + for (int i = 0; i < width; ++i) {
4.70 + char c; in >> c;
4.71 + filter[ugraph(i, j)] = (c == '.');
4.72 + }
4.73 + }
4.74 +
4.75 + typedef NodeSubGraphAdaptor<GridUGraph,
4.76 + GridUGraph::NodeMap<bool> > FilteredGraph;
4.77 +
4.78 + FilteredGraph filtered(ugraph, filter);
4.79 +
4.80 + Bfs<FilteredGraph> bfs(filtered);
4.81 + std::cout << "The length of shortest path: " <<
4.82 + bfs.run(start, stop) << std::endl;
4.83 +
4.84 + FilteredGraph::EdgeMap<bool> path(filtered, false);
4.85 +
4.86 + for (GridUGraph::Node node = stop;
4.87 + node != start; node = bfs.predNode(node)) {
4.88 + path[bfs.predEdge(node)] = true;
4.89 + }
4.90 +
4.91 + graphToEps(filtered, "grid_ugraph_demo.eps").scaleToA4().
4.92 + title("Grid ugraph").
4.93 + copyright("(C) 2006 LEMON Project").
4.94 + coords(scaleMap(indexMap(ugraph), 10)).
4.95 + enableParallel().
4.96 + nodeScale(0.5).
4.97 + drawArrows().
4.98 + edgeColors(composeMap(ColorSet(), path)).
4.99 + run();
4.100 +
4.101 + std::cout << "The shortest path is written to grid_ugraph_demo.eps"
4.102 + << std::endl;
4.103 +
4.104 + return 0;
4.105 +}
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/demo/grid_ugraph_demo.in Wed Feb 22 18:26:56 2006 +0000
5.3 @@ -0,0 +1,10 @@
5.4 +10 8
5.5 +1 1 10 8
5.6 +..X....X.X
5.7 +.XX.X.XX..
5.8 +....X..XX.
5.9 +XXXXXX.X..
5.10 +.........X
5.11 +.X.XXXXXXX
5.12 +.X...XX...
5.13 +.X.X....X.
6.1 --- a/lemon/Makefile.am Wed Feb 22 12:45:59 2006 +0000
6.2 +++ b/lemon/Makefile.am Wed Feb 22 18:26:56 2006 +0000
6.3 @@ -40,7 +40,7 @@
6.4 floyd_warshall.h \
6.5 fredman_tarjan.h \
6.6 full_graph.h \
6.7 - grid_graph.h \
6.8 + grid_ugraph.h \
6.9 graph_adaptor.h \
6.10 graph_utils.h \
6.11 graph_to_eps.h \
6.12 @@ -75,6 +75,7 @@
6.13 time_measure.h \
6.14 topology.h \
6.15 traits.h \
6.16 + ugraph_adaptor.h \
6.17 unionfind.h \
6.18 xy.h \
6.19 concept_check.h \
6.20 @@ -87,14 +88,12 @@
6.21 bits/alteration_notifier.h \
6.22 bits/array_map.h \
6.23 bits/default_map.h \
6.24 + bits/static_map.h \
6.25 bits/vector_map.h \
6.26 - bits/iterable_graph_extender.h \
6.27 - bits/extendable_graph_extender.h \
6.28 - bits/clearable_graph_extender.h \
6.29 - bits/erasable_graph_extender.h \
6.30 + bits/map_extender.h \
6.31 bits/graph_extender.h \
6.32 - bits/map_extender.h \
6.33 - bits/static_map.h \
6.34 + bits/graph_adaptor_extender.h \
6.35 + bits/edge_set_extender.h \
6.36 bits/item_reader.h \
6.37 bits/item_writer.h \
6.38 concept/bpugraph.h \
7.1 --- a/lemon/bits/alteration_notifier.h Wed Feb 22 12:45:59 2006 +0000
7.2 +++ b/lemon/bits/alteration_notifier.h Wed Feb 22 18:26:56 2006 +0000
7.3 @@ -265,8 +265,16 @@
7.4 ///
7.5 void add(const Item& item) {
7.6 typename Container::iterator it;
7.7 - for (it = container.begin(); it != container.end(); ++it) {
7.8 - (*it)->add(item);
7.9 + try {
7.10 + for (it = container.begin(); it != container.end(); ++it) {
7.11 + (*it)->add(item);
7.12 + }
7.13 + } catch (...) {
7.14 + typename Container::iterator jt;
7.15 + for (jt = container.begin(); jt != it; ++it) {
7.16 + (*it)->erase(item);
7.17 + }
7.18 + throw;
7.19 }
7.20 }
7.21
7.22 @@ -278,8 +286,16 @@
7.23 ///
7.24 void add(const std::vector<Item>& items) {
7.25 typename Container::iterator it;
7.26 - for (it = container.begin(); it != container.end(); ++it) {
7.27 - (*it)->add(items);
7.28 + try {
7.29 + for (it = container.begin(); it != container.end(); ++it) {
7.30 + (*it)->add(items);
7.31 + }
7.32 + } catch (...) {
7.33 + typename Container::iterator jt;
7.34 + for (jt = container.begin(); jt != it; ++it) {
7.35 + (*it)->erase(items);
7.36 + }
7.37 + throw;
7.38 }
7.39 }
7.40
7.41 @@ -316,8 +332,16 @@
7.42 /// from an empty container.
7.43 void build() {
7.44 typename Container::iterator it;
7.45 - for (it = container.begin(); it != container.end(); ++it) {
7.46 - (*it)->build();
7.47 + try {
7.48 + for (it = container.begin(); it != container.end(); ++it) {
7.49 + (*it)->build();
7.50 + }
7.51 + } catch (...) {
7.52 + typename Container::iterator jt;
7.53 + for (jt = container.begin(); jt != it; ++it) {
7.54 + (*it)->clear();
7.55 + }
7.56 + throw;
7.57 }
7.58 }
7.59
7.60 @@ -335,232 +359,6 @@
7.61 }
7.62 };
7.63
7.64 -
7.65 - /// \brief Class to extend a graph with the functionality of alteration
7.66 - /// observing.
7.67 - ///
7.68 - /// AlterableGraphExtender extends the _Base graphs functionality with
7.69 - /// the possibility of alteration observing. It defines two observer
7.70 - /// registrys for the nodes and mapes.
7.71 - ///
7.72 - /// \todo Document what "alteration observing" is. And probably find a
7.73 - /// better (shorter) name.
7.74 - ///
7.75 - /// \param _Base is the base class to extend.
7.76 - ///
7.77 - /// \pre _Base is conform to the BaseGraphComponent concept.
7.78 - ///
7.79 - /// \post AlterableGraphExtender<_Base> is conform to the
7.80 - /// AlterableGraphComponent concept.
7.81 - ///
7.82 - /// \author Balazs Dezso
7.83 -
7.84 - template <typename _Base>
7.85 - class AlterableGraphExtender : public _Base {
7.86 - public:
7.87 -
7.88 - typedef AlterableGraphExtender Graph;
7.89 - typedef _Base Parent;
7.90 -
7.91 - typedef typename Parent::Node Node;
7.92 - typedef typename Parent::Edge Edge;
7.93 -
7.94 - /// The edge observer registry.
7.95 - typedef AlterationNotifier<Edge> EdgeNotifier;
7.96 - /// The node observer registry.
7.97 - typedef AlterationNotifier<Node> NodeNotifier;
7.98 -
7.99 -
7.100 - protected:
7.101 -
7.102 - mutable EdgeNotifier edge_notifier;
7.103 -
7.104 - mutable NodeNotifier node_notifier;
7.105 -
7.106 - public:
7.107 -
7.108 - /// \brief Gives back the edge alteration notifier.
7.109 - ///
7.110 - /// Gives back the edge alteration notifier.
7.111 - EdgeNotifier& getNotifier(Edge) const {
7.112 - return edge_notifier;
7.113 - }
7.114 -
7.115 - /// \brief Gives back the node alteration notifier.
7.116 - ///
7.117 - /// Gives back the node alteration notifier.
7.118 - NodeNotifier& getNotifier(Node) const {
7.119 - return node_notifier;
7.120 - }
7.121 -
7.122 - ~AlterableGraphExtender() {
7.123 - node_notifier.clear();
7.124 - edge_notifier.clear();
7.125 - }
7.126 -
7.127 - };
7.128 -
7.129 -
7.130 - template <typename _Base>
7.131 - class AlterableEdgeSetExtender : public _Base {
7.132 - public:
7.133 -
7.134 - typedef AlterableEdgeSetExtender Graph;
7.135 - typedef _Base Parent;
7.136 -
7.137 - typedef typename Parent::Edge Edge;
7.138 -
7.139 - /// The edge observer registry.
7.140 - typedef AlterationNotifier<Edge> EdgeNotifier;
7.141 -
7.142 - protected:
7.143 -
7.144 - mutable EdgeNotifier edge_notifier;
7.145 -
7.146 - public:
7.147 -
7.148 - /// \brief Gives back the edge alteration notifier.
7.149 - ///
7.150 - /// Gives back the edge alteration notifier.
7.151 - EdgeNotifier& getNotifier(Edge) const {
7.152 - return edge_notifier;
7.153 - }
7.154 -
7.155 - ~AlterableEdgeSetExtender() {
7.156 - edge_notifier.clear();
7.157 - }
7.158 -
7.159 - };
7.160 -
7.161 - /// \brief Class to extend an undirected graph with the functionality of
7.162 - /// alteration observing.
7.163 - ///
7.164 - /// \todo Document.
7.165 - ///
7.166 - /// \sa AlterableGraphExtender
7.167 - ///
7.168 - /// \bug This should be done some other way. Possibilities: template
7.169 - /// specialization (not very easy, if at all possible); some kind of
7.170 - /// enable_if boost technique?
7.171 -
7.172 - template <typename _Base>
7.173 - class AlterableUGraphExtender
7.174 - : public AlterableGraphExtender<_Base> {
7.175 - public:
7.176 -
7.177 - typedef AlterableUGraphExtender Graph;
7.178 - typedef AlterableGraphExtender<_Base> Parent;
7.179 -
7.180 - typedef typename Parent::UEdge UEdge;
7.181 -
7.182 - /// The edge observer registry.
7.183 - typedef AlterationNotifier<UEdge> UEdgeNotifier;
7.184 -
7.185 - protected:
7.186 -
7.187 - mutable UEdgeNotifier u_edge_notifier;
7.188 -
7.189 - public:
7.190 -
7.191 - using Parent::getNotifier;
7.192 - UEdgeNotifier& getNotifier(UEdge) const {
7.193 - return u_edge_notifier;
7.194 - }
7.195 -
7.196 - ~AlterableUGraphExtender() {
7.197 - u_edge_notifier.clear();
7.198 - }
7.199 - };
7.200 -
7.201 - template <typename _Base>
7.202 - class AlterableUEdgeSetExtender
7.203 - : public AlterableEdgeSetExtender<_Base> {
7.204 - public:
7.205 -
7.206 - typedef AlterableUEdgeSetExtender Graph;
7.207 - typedef AlterableEdgeSetExtender<_Base> Parent;
7.208 -
7.209 - typedef typename Parent::UEdge UEdge;
7.210 -
7.211 - typedef AlterationNotifier<UEdge> UEdgeNotifier;
7.212 -
7.213 - protected:
7.214 -
7.215 - mutable UEdgeNotifier u_edge_notifier;
7.216 -
7.217 - public:
7.218 -
7.219 - using Parent::getNotifier;
7.220 - UEdgeNotifier& getNotifier(UEdge) const {
7.221 - return u_edge_notifier;
7.222 - }
7.223 -
7.224 - ~AlterableUEdgeSetExtender() {
7.225 - u_edge_notifier.clear();
7.226 - }
7.227 - };
7.228 -
7.229 -
7.230 -
7.231 - template <typename _Base>
7.232 - class AlterableBpUGraphExtender : public _Base {
7.233 - public:
7.234 -
7.235 - typedef _Base Parent;
7.236 - typedef AlterableBpUGraphExtender Graph;
7.237 -
7.238 - typedef typename Parent::Node Node;
7.239 - typedef typename Parent::BNode BNode;
7.240 - typedef typename Parent::ANode ANode;
7.241 - typedef typename Parent::Edge Edge;
7.242 - typedef typename Parent::UEdge UEdge;
7.243 -
7.244 -
7.245 - typedef AlterationNotifier<Node> NodeNotifier;
7.246 - typedef AlterationNotifier<BNode> BNodeNotifier;
7.247 - typedef AlterationNotifier<ANode> ANodeNotifier;
7.248 - typedef AlterationNotifier<Edge> EdgeNotifier;
7.249 - typedef AlterationNotifier<UEdge> UEdgeNotifier;
7.250 -
7.251 - protected:
7.252 -
7.253 - mutable NodeNotifier nodeNotifier;
7.254 - mutable BNodeNotifier bNodeNotifier;
7.255 - mutable ANodeNotifier aNodeNotifier;
7.256 - mutable EdgeNotifier edgeNotifier;
7.257 - mutable UEdgeNotifier uEdgeNotifier;
7.258 -
7.259 - public:
7.260 -
7.261 - NodeNotifier& getNotifier(Node) const {
7.262 - return nodeNotifier;
7.263 - }
7.264 -
7.265 - BNodeNotifier& getNotifier(BNode) const {
7.266 - return bNodeNotifier;
7.267 - }
7.268 -
7.269 - ANodeNotifier& getNotifier(ANode) const {
7.270 - return aNodeNotifier;
7.271 - }
7.272 -
7.273 - EdgeNotifier& getNotifier(Edge) const {
7.274 - return edgeNotifier;
7.275 - }
7.276 -
7.277 - UEdgeNotifier& getNotifier(UEdge) const {
7.278 - return uEdgeNotifier;
7.279 - }
7.280 -
7.281 - ~AlterableBpUGraphExtender() {
7.282 - nodeNotifier.clear();
7.283 - bNodeNotifier.clear();
7.284 - aNodeNotifier.clear();
7.285 - edgeNotifier.clear();
7.286 - uEdgeNotifier.clear();
7.287 - }
7.288 -
7.289 - };
7.290
7.291 /// @}
7.292
8.1 --- a/lemon/bits/clearable_graph_extender.h Wed Feb 22 12:45:59 2006 +0000
8.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
8.3 @@ -1,123 +0,0 @@
8.4 -/* -*- C++ -*-
8.5 - *
8.6 - * This file is a part of LEMON, a generic C++ optimization library
8.7 - *
8.8 - * Copyright (C) 2003-2006
8.9 - * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
8.10 - * (Egervary Research Group on Combinatorial Optimization, EGRES).
8.11 - *
8.12 - * Permission to use, modify and distribute this software is granted
8.13 - * provided that this copyright notice appears in all copies. For
8.14 - * precise terms see the accompanying LICENSE file.
8.15 - *
8.16 - * This software is provided "AS IS" with no warranty of any kind,
8.17 - * express or implied, and with no claim as to its suitability for any
8.18 - * purpose.
8.19 - *
8.20 - */
8.21 -
8.22 -#ifndef LEMON_CLEARABLE_GRAPH_EXTENDER_H
8.23 -#define LEMON_CLEARABLE_GRAPH_EXTENDER_H
8.24 -
8.25 -#include <lemon/invalid.h>
8.26 -
8.27 -
8.28 -namespace lemon {
8.29 -
8.30 - template <typename _Base>
8.31 - class ClearableGraphExtender : public _Base {
8.32 - public:
8.33 -
8.34 - typedef ClearableGraphExtender Graph;
8.35 - typedef _Base Parent;
8.36 - typedef typename Parent::Node Node;
8.37 - typedef typename Parent::Edge Edge;
8.38 -
8.39 - void clear() {
8.40 - Parent::getNotifier(Node()).clear();
8.41 - Parent::getNotifier(Edge()).clear();
8.42 - Parent::clear();
8.43 - }
8.44 -
8.45 - };
8.46 -
8.47 - template <typename _Base>
8.48 - class ClearableEdgeSetExtender : public _Base {
8.49 - public:
8.50 -
8.51 - typedef ClearableEdgeSetExtender Graph;
8.52 - typedef _Base Parent;
8.53 - typedef typename Parent::Node Node;
8.54 - typedef typename Parent::Edge Edge;
8.55 -
8.56 - void clear() {
8.57 - Parent::getNotifier(Edge()).clear();
8.58 - Parent::clear();
8.59 - }
8.60 -
8.61 - };
8.62 -
8.63 - template <typename _Base>
8.64 - class ClearableUGraphExtender : public _Base {
8.65 - public:
8.66 -
8.67 - typedef ClearableUGraphExtender Graph;
8.68 - typedef _Base Parent;
8.69 - typedef typename Parent::Node Node;
8.70 - typedef typename Parent::UEdge UEdge;
8.71 - typedef typename Parent::Edge Edge;
8.72 -
8.73 - void clear() {
8.74 - Parent::getNotifier(Node()).clear();
8.75 - Parent::getNotifier(UEdge()).clear();
8.76 - Parent::getNotifier(Edge()).clear();
8.77 - Parent::clear();
8.78 - }
8.79 - };
8.80 -
8.81 - template <typename _Base>
8.82 - class ClearableUEdgeSetExtender : public _Base {
8.83 - public:
8.84 -
8.85 - typedef ClearableUEdgeSetExtender Graph;
8.86 - typedef _Base Parent;
8.87 - typedef typename Parent::Node Node;
8.88 - typedef typename Parent::UEdge UEdge;
8.89 - typedef typename Parent::Edge Edge;
8.90 -
8.91 - void clear() {
8.92 - Parent::getNotifier(UEdge()).clear();
8.93 - Parent::getNotifier(Edge()).clear();
8.94 - Parent::clear();
8.95 - }
8.96 -
8.97 - };
8.98 -
8.99 -
8.100 - template <typename _Base>
8.101 - class ClearableBpUGraphExtender : public _Base {
8.102 - public:
8.103 -
8.104 - typedef _Base Parent;
8.105 - typedef ClearableBpUGraphExtender Graph;
8.106 -
8.107 - typedef typename Parent::Node Node;
8.108 - typedef typename Parent::BNode BNode;
8.109 - typedef typename Parent::ANode ANode;
8.110 - typedef typename Parent::Edge Edge;
8.111 - typedef typename Parent::UEdge UEdge;
8.112 -
8.113 - void clear() {
8.114 - Parent::getNotifier(Edge()).clear();
8.115 - Parent::getNotifier(UEdge()).clear();
8.116 - Parent::getNotifier(Node()).clear();
8.117 - Parent::getNotifier(BNode()).clear();
8.118 - Parent::getNotifier(ANode()).clear();
8.119 - Parent::clear();
8.120 - }
8.121 -
8.122 - };
8.123 -
8.124 -}
8.125 -
8.126 -#endif
9.1 --- a/lemon/bits/default_map.h Wed Feb 22 12:45:59 2006 +0000
9.2 +++ b/lemon/bits/default_map.h Wed Feb 22 18:26:56 2006 +0000
9.3 @@ -22,6 +22,7 @@
9.4
9.5 #include <lemon/bits/array_map.h>
9.6 #include <lemon/bits/vector_map.h>
9.7 +#include <lemon/bits/static_map.h>
9.8
9.9 ///\ingroup graphmapfactory
9.10 ///\file
9.11 @@ -30,7 +31,8 @@
9.12
9.13 namespace lemon {
9.14
9.15 -#ifndef GLIBCXX_DEBUG
9.16 +
9.17 +#ifndef _GLIBCXX_DEBUG
9.18
9.19 template <typename _Graph, typename _Item, typename _Value>
9.20 struct DefaultMapSelector {
9.21 @@ -167,483 +169,6 @@
9.22
9.23 };
9.24
9.25 -
9.26 - /// \e
9.27 - template <typename _Base>
9.28 - class MappableGraphExtender : public _Base {
9.29 - public:
9.30 -
9.31 - typedef MappableGraphExtender<_Base> Graph;
9.32 - typedef _Base Parent;
9.33 -
9.34 - typedef typename Parent::Node Node;
9.35 - typedef typename Parent::NodeIt NodeIt;
9.36 -
9.37 - typedef typename Parent::Edge Edge;
9.38 - typedef typename Parent::EdgeIt EdgeIt;
9.39 -
9.40 -
9.41 - template <typename _Value>
9.42 - class NodeMap
9.43 - : public IterableMapExtender<DefaultMap<Graph, Node, _Value> > {
9.44 - public:
9.45 - typedef MappableGraphExtender Graph;
9.46 - typedef IterableMapExtender<DefaultMap<Graph, Node, _Value> > Parent;
9.47 -
9.48 - NodeMap(const Graph& _g)
9.49 - : Parent(_g) {}
9.50 - NodeMap(const Graph& _g, const _Value& _v)
9.51 - : Parent(_g, _v) {}
9.52 -
9.53 - NodeMap& operator=(const NodeMap& cmap) {
9.54 - return operator=<NodeMap>(cmap);
9.55 - }
9.56 -
9.57 -
9.58 - /// \brief Template assign operator.
9.59 - ///
9.60 - /// The given parameter should be conform to the ReadMap
9.61 - /// concecpt and could be indiced by the current item set of
9.62 - /// the NodeMap. In this case the value for each item
9.63 - /// is assigned by the value of the given ReadMap.
9.64 - template <typename CMap>
9.65 - NodeMap& operator=(const CMap& cmap) {
9.66 - checkConcept<concept::ReadMap<Node, _Value>, CMap>();
9.67 - const typename Parent::Graph* graph = Parent::getGraph();
9.68 - Node it;
9.69 - for (graph->first(it); it != INVALID; graph->next(it)) {
9.70 - Parent::set(it, cmap[it]);
9.71 - }
9.72 - return *this;
9.73 - }
9.74 -
9.75 - };
9.76 -
9.77 - template <typename _Value>
9.78 - class EdgeMap
9.79 - : public IterableMapExtender<DefaultMap<Graph, Edge, _Value> > {
9.80 - public:
9.81 - typedef MappableGraphExtender Graph;
9.82 - typedef IterableMapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
9.83 -
9.84 - EdgeMap(const Graph& _g)
9.85 - : Parent(_g) {}
9.86 - EdgeMap(const Graph& _g, const _Value& _v)
9.87 - : Parent(_g, _v) {}
9.88 -
9.89 - EdgeMap& operator=(const EdgeMap& cmap) {
9.90 - return operator=<EdgeMap>(cmap);
9.91 - }
9.92 -
9.93 - template <typename CMap>
9.94 - EdgeMap& operator=(const CMap& cmap) {
9.95 - checkConcept<concept::ReadMap<Edge, _Value>, CMap>();
9.96 - const typename Parent::Graph* graph = Parent::getGraph();
9.97 - Edge it;
9.98 - for (graph->first(it); it != INVALID; graph->next(it)) {
9.99 - Parent::set(it, cmap[it]);
9.100 - }
9.101 - return *this;
9.102 - }
9.103 - };
9.104 -
9.105 - };
9.106 -
9.107 - /// \e
9.108 - template <typename _Base>
9.109 - class MappableEdgeSetExtender : public _Base {
9.110 - public:
9.111 -
9.112 - typedef MappableEdgeSetExtender<_Base> Graph;
9.113 - typedef _Base Parent;
9.114 -
9.115 - typedef typename Parent::Edge Edge;
9.116 - typedef typename Parent::EdgeIt EdgeIt;
9.117 -
9.118 - template <typename _Value>
9.119 - class EdgeMap
9.120 - : public IterableMapExtender<DefaultMap<Graph, Edge, _Value> > {
9.121 - public:
9.122 - typedef MappableEdgeSetExtender Graph;
9.123 - typedef IterableMapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
9.124 -
9.125 - EdgeMap(const Graph& _g)
9.126 - : Parent(_g) {}
9.127 - EdgeMap(const Graph& _g, const _Value& _v)
9.128 - : Parent(_g, _v) {}
9.129 -
9.130 - EdgeMap& operator=(const EdgeMap& cmap) {
9.131 - return operator=<EdgeMap>(cmap);
9.132 - }
9.133 -
9.134 - template <typename CMap>
9.135 - EdgeMap& operator=(const CMap& cmap) {
9.136 - checkConcept<concept::ReadMap<Edge, _Value>, CMap>();
9.137 - const typename Parent::Graph* graph = Parent::getGraph();
9.138 - Edge it;
9.139 - for (graph->first(it); it != INVALID; graph->next(it)) {
9.140 - Parent::set(it, cmap[it]);
9.141 - }
9.142 - return *this;
9.143 - }
9.144 - };
9.145 -
9.146 - };
9.147 -
9.148 - /// \e
9.149 - template <typename _Base>
9.150 - class MappableUGraphExtender :
9.151 - public MappableGraphExtender<_Base> {
9.152 - public:
9.153 -
9.154 - typedef MappableUGraphExtender Graph;
9.155 - typedef MappableGraphExtender<_Base> Parent;
9.156 -
9.157 - typedef typename Parent::UEdge UEdge;
9.158 -
9.159 - template <typename _Value>
9.160 - class UEdgeMap
9.161 - : public IterableMapExtender<DefaultMap<Graph, UEdge, _Value> > {
9.162 - public:
9.163 - typedef MappableUGraphExtender Graph;
9.164 - typedef IterableMapExtender<
9.165 - DefaultMap<Graph, UEdge, _Value> > Parent;
9.166 -
9.167 - UEdgeMap(const Graph& _g)
9.168 - : Parent(_g) {}
9.169 - UEdgeMap(const Graph& _g, const _Value& _v)
9.170 - : Parent(_g, _v) {}
9.171 -
9.172 - UEdgeMap& operator=(const UEdgeMap& cmap) {
9.173 - return operator=<UEdgeMap>(cmap);
9.174 - }
9.175 -
9.176 - template <typename CMap>
9.177 - UEdgeMap& operator=(const CMap& cmap) {
9.178 - checkConcept<concept::ReadMap<UEdge, _Value>, CMap>();
9.179 - const typename Parent::Graph* graph = Parent::getGraph();
9.180 - UEdge it;
9.181 - for (graph->first(it); it != INVALID; graph->next(it)) {
9.182 - Parent::set(it, cmap[it]);
9.183 - }
9.184 - return *this;
9.185 - }
9.186 - };
9.187 -
9.188 -
9.189 - };
9.190 -
9.191 - /// \e
9.192 - template <typename _Base>
9.193 - class MappableUEdgeSetExtender :
9.194 - public MappableEdgeSetExtender<_Base> {
9.195 - public:
9.196 -
9.197 - typedef MappableUEdgeSetExtender Graph;
9.198 - typedef MappableEdgeSetExtender<_Base> Parent;
9.199 -
9.200 - typedef typename Parent::UEdge UEdge;
9.201 -
9.202 - template <typename _Value>
9.203 - class UEdgeMap
9.204 - : public IterableMapExtender<DefaultMap<Graph, UEdge, _Value> > {
9.205 - public:
9.206 - typedef MappableUEdgeSetExtender Graph;
9.207 - typedef IterableMapExtender<
9.208 - DefaultMap<Graph, UEdge, _Value> > Parent;
9.209 -
9.210 - UEdgeMap(const Graph& _g)
9.211 - : Parent(_g) {}
9.212 - UEdgeMap(const Graph& _g, const _Value& _v)
9.213 - : Parent(_g, _v) {}
9.214 -
9.215 - UEdgeMap& operator=(const UEdgeMap& cmap) {
9.216 - return operator=<UEdgeMap>(cmap);
9.217 - }
9.218 -
9.219 - template <typename CMap>
9.220 - UEdgeMap& operator=(const CMap& cmap) {
9.221 - checkConcept<concept::ReadMap<UEdge, _Value>, CMap>();
9.222 - const typename Parent::Graph* graph = Parent::getGraph();
9.223 - UEdge it;
9.224 - for (graph->first(it); it != INVALID; graph->next(it)) {
9.225 - Parent::set(it, cmap[it]);
9.226 - }
9.227 - return *this;
9.228 - }
9.229 - };
9.230 -
9.231 -
9.232 - };
9.233 -
9.234 -
9.235 - template <typename _Base>
9.236 - class MappableBpUGraphExtender : public _Base {
9.237 - public:
9.238 -
9.239 - typedef _Base Parent;
9.240 - typedef MappableBpUGraphExtender Graph;
9.241 -
9.242 - typedef typename Parent::Node Node;
9.243 - typedef typename Parent::ANode ANode;
9.244 - typedef typename Parent::BNode BNode;
9.245 - typedef typename Parent::Edge Edge;
9.246 - typedef typename Parent::UEdge UEdge;
9.247 -
9.248 - template <typename _Value>
9.249 - class ANodeMap
9.250 - : public IterableMapExtender<DefaultMap<Graph, ANode, _Value> > {
9.251 - public:
9.252 - typedef MappableBpUGraphExtender Graph;
9.253 - typedef IterableMapExtender<DefaultMap<Graph, ANode, _Value> >
9.254 - Parent;
9.255 -
9.256 - ANodeMap(const Graph& _g)
9.257 - : Parent(_g) {}
9.258 - ANodeMap(const Graph& _g, const _Value& _v)
9.259 - : Parent(_g, _v) {}
9.260 -
9.261 - ANodeMap& operator=(const ANodeMap& cmap) {
9.262 - return operator=<ANodeMap>(cmap);
9.263 - }
9.264 -
9.265 -
9.266 - /// \brief Template assign operator.
9.267 - ///
9.268 - /// The given parameter should be conform to the ReadMap
9.269 - /// concept and could be indiced by the current item set of
9.270 - /// the ANodeMap. In this case the value for each item
9.271 - /// is assigned by the value of the given ReadMap.
9.272 - template <typename CMap>
9.273 - ANodeMap& operator=(const CMap& cmap) {
9.274 - checkConcept<concept::ReadMap<ANode, _Value>, CMap>();
9.275 - const typename Parent::Graph* graph = Parent::getGraph();
9.276 - ANode it;
9.277 - for (graph->first(it); it != INVALID; graph->next(it)) {
9.278 - Parent::set(it, cmap[it]);
9.279 - }
9.280 - return *this;
9.281 - }
9.282 -
9.283 - };
9.284 -
9.285 - template <typename _Value>
9.286 - class BNodeMap
9.287 - : public IterableMapExtender<DefaultMap<Graph, BNode, _Value> > {
9.288 - public:
9.289 - typedef MappableBpUGraphExtender Graph;
9.290 - typedef IterableMapExtender<DefaultMap<Graph, BNode, _Value> >
9.291 - Parent;
9.292 -
9.293 - BNodeMap(const Graph& _g)
9.294 - : Parent(_g) {}
9.295 - BNodeMap(const Graph& _g, const _Value& _v)
9.296 - : Parent(_g, _v) {}
9.297 -
9.298 - BNodeMap& operator=(const BNodeMap& cmap) {
9.299 - return operator=<BNodeMap>(cmap);
9.300 - }
9.301 -
9.302 -
9.303 - /// \brief Template assign operator.
9.304 - ///
9.305 - /// The given parameter should be conform to the ReadMap
9.306 - /// concept and could be indiced by the current item set of
9.307 - /// the BNodeMap. In this case the value for each item
9.308 - /// is assigned by the value of the given ReadMap.
9.309 - template <typename CMap>
9.310 - BNodeMap& operator=(const CMap& cmap) {
9.311 - checkConcept<concept::ReadMap<BNode, _Value>, CMap>();
9.312 - const typename Parent::Graph* graph = Parent::getGraph();
9.313 - BNode it;
9.314 - for (graph->first(it); it != INVALID; graph->next(it)) {
9.315 - Parent::set(it, cmap[it]);
9.316 - }
9.317 - return *this;
9.318 - }
9.319 -
9.320 - };
9.321 -
9.322 - protected:
9.323 -
9.324 - template <typename _Value>
9.325 - class NodeMapBase : public Parent::NodeNotifier::ObserverBase {
9.326 - public:
9.327 - typedef MappableBpUGraphExtender Graph;
9.328 -
9.329 - typedef Node Key;
9.330 - typedef _Value Value;
9.331 -
9.332 - /// The reference type of the map;
9.333 - typedef typename BNodeMap<_Value>::Reference Reference;
9.334 - /// The pointer type of the map;
9.335 - typedef typename BNodeMap<_Value>::Pointer Pointer;
9.336 -
9.337 - /// The const value type of the map.
9.338 - typedef const Value ConstValue;
9.339 - /// The const reference type of the map;
9.340 - typedef typename BNodeMap<_Value>::ConstReference ConstReference;
9.341 - /// The pointer type of the map;
9.342 - typedef typename BNodeMap<_Value>::ConstPointer ConstPointer;
9.343 -
9.344 - typedef True ReferenceMapTag;
9.345 -
9.346 - NodeMapBase(const Graph& _g)
9.347 - : graph(&_g), bNodeMap(_g), aNodeMap(_g) {
9.348 - Parent::NodeNotifier::ObserverBase::attach(_g.getNotifier(Node()));
9.349 - }
9.350 - NodeMapBase(const Graph& _g, const _Value& _v)
9.351 - : graph(&_g), bNodeMap(_g, _v),
9.352 - aNodeMap(_g, _v) {
9.353 - Parent::NodeNotifier::ObserverBase::attach(_g.getNotifier(Node()));
9.354 - }
9.355 -
9.356 - virtual ~NodeMapBase() {
9.357 - if (Parent::NodeNotifier::ObserverBase::attached()) {
9.358 - Parent::NodeNotifier::ObserverBase::detach();
9.359 - }
9.360 - }
9.361 -
9.362 - ConstReference operator[](const Key& node) const {
9.363 - if (Parent::aNode(node)) {
9.364 - return aNodeMap[node];
9.365 - } else {
9.366 - return bNodeMap[node];
9.367 - }
9.368 - }
9.369 -
9.370 - Reference operator[](const Key& node) {
9.371 - if (Parent::aNode(node)) {
9.372 - return aNodeMap[node];
9.373 - } else {
9.374 - return bNodeMap[node];
9.375 - }
9.376 - }
9.377 -
9.378 - void set(const Key& node, const Value& value) {
9.379 - if (Parent::aNode(node)) {
9.380 - aNodeMap.set(node, value);
9.381 - } else {
9.382 - bNodeMap.set(node, value);
9.383 - }
9.384 - }
9.385 -
9.386 - protected:
9.387 -
9.388 - virtual void add(const Node&) {}
9.389 - virtual void add(const std::vector<Node>&) {}
9.390 - virtual void erase(const Node&) {}
9.391 - virtual void erase(const std::vector<Node>&) {}
9.392 - virtual void clear() {}
9.393 - virtual void build() {}
9.394 -
9.395 - const Graph* getGraph() const { return graph; }
9.396 -
9.397 - private:
9.398 - const Graph* graph;
9.399 - BNodeMap<_Value> bNodeMap;
9.400 - ANodeMap<_Value> aNodeMap;
9.401 - };
9.402 -
9.403 - public:
9.404 -
9.405 - template <typename _Value>
9.406 - class NodeMap
9.407 - : public IterableMapExtender<NodeMapBase<_Value> > {
9.408 - public:
9.409 - typedef MappableBpUGraphExtender Graph;
9.410 - typedef IterableMapExtender< NodeMapBase<_Value> > Parent;
9.411 -
9.412 - NodeMap(const Graph& _g)
9.413 - : Parent(_g) {}
9.414 - NodeMap(const Graph& _g, const _Value& _v)
9.415 - : Parent(_g, _v) {}
9.416 -
9.417 - NodeMap& operator=(const NodeMap& cmap) {
9.418 - return operator=<NodeMap>(cmap);
9.419 - }
9.420 -
9.421 -
9.422 - /// \brief Template assign operator.
9.423 - ///
9.424 - /// The given parameter should be conform to the ReadMap
9.425 - /// concept and could be indiced by the current item set of
9.426 - /// the NodeMap. In this case the value for each item
9.427 - /// is assigned by the value of the given ReadMap.
9.428 - template <typename CMap>
9.429 - NodeMap& operator=(const CMap& cmap) {
9.430 - checkConcept<concept::ReadMap<Node, _Value>, CMap>();
9.431 - const typename Parent::Graph* graph = Parent::getGraph();
9.432 - Node it;
9.433 - for (graph->first(it); it != INVALID; graph->next(it)) {
9.434 - Parent::set(it, cmap[it]);
9.435 - }
9.436 - return *this;
9.437 - }
9.438 -
9.439 - };
9.440 -
9.441 -
9.442 -
9.443 - template <typename _Value>
9.444 - class EdgeMap
9.445 - : public IterableMapExtender<DefaultMap<Graph, Edge, _Value> > {
9.446 - public:
9.447 - typedef MappableBpUGraphExtender Graph;
9.448 - typedef IterableMapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
9.449 -
9.450 - EdgeMap(const Graph& _g)
9.451 - : Parent(_g) {}
9.452 - EdgeMap(const Graph& _g, const _Value& _v)
9.453 - : Parent(_g, _v) {}
9.454 -
9.455 - EdgeMap& operator=(const EdgeMap& cmap) {
9.456 - return operator=<EdgeMap>(cmap);
9.457 - }
9.458 -
9.459 - template <typename CMap>
9.460 - EdgeMap& operator=(const CMap& cmap) {
9.461 - checkConcept<concept::ReadMap<Edge, _Value>, CMap>();
9.462 - const typename Parent::Graph* graph = Parent::getGraph();
9.463 - Edge it;
9.464 - for (graph->first(it); it != INVALID; graph->next(it)) {
9.465 - Parent::set(it, cmap[it]);
9.466 - }
9.467 - return *this;
9.468 - }
9.469 - };
9.470 -
9.471 - template <typename _Value>
9.472 - class UEdgeMap
9.473 - : public IterableMapExtender<DefaultMap<Graph, UEdge, _Value> > {
9.474 - public:
9.475 - typedef MappableBpUGraphExtender Graph;
9.476 - typedef IterableMapExtender<DefaultMap<Graph, UEdge, _Value> >
9.477 - Parent;
9.478 -
9.479 - UEdgeMap(const Graph& _g)
9.480 - : Parent(_g) {}
9.481 - UEdgeMap(const Graph& _g, const _Value& _v)
9.482 - : Parent(_g, _v) {}
9.483 -
9.484 - UEdgeMap& operator=(const UEdgeMap& cmap) {
9.485 - return operator=<UEdgeMap>(cmap);
9.486 - }
9.487 -
9.488 - template <typename CMap>
9.489 - UEdgeMap& operator=(const CMap& cmap) {
9.490 - checkConcept<concept::ReadMap<UEdge, _Value>, CMap>();
9.491 - const typename Parent::Graph* graph = Parent::getGraph();
9.492 - UEdge it;
9.493 - for (graph->first(it); it != INVALID; graph->next(it)) {
9.494 - Parent::set(it, cmap[it]);
9.495 - }
9.496 - return *this;
9.497 - }
9.498 - };
9.499 -
9.500 - };
9.501 -
9.502 }
9.503
9.504 #endif
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
10.2 +++ b/lemon/bits/edge_set_extender.h Wed Feb 22 18:26:56 2006 +0000
10.3 @@ -0,0 +1,606 @@
10.4 +/* -*- C++ -*-
10.5 + *
10.6 + * This file is a part of LEMON, a generic C++ optimization library
10.7 + *
10.8 + * Copyright (C) 2003-2006
10.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
10.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
10.11 + *
10.12 + * Permission to use, modify and distribute this software is granted
10.13 + * provided that this copyright notice appears in all copies. For
10.14 + * precise terms see the accompanying LICENSE file.
10.15 + *
10.16 + * This software is provided "AS IS" with no warranty of any kind,
10.17 + * express or implied, and with no claim as to its suitability for any
10.18 + * purpose.
10.19 + *
10.20 + */
10.21 +
10.22 +
10.23 +namespace lemon {
10.24 +
10.25 + template <typename Base>
10.26 + class EdgeSetExtender : public Base {
10.27 + public:
10.28 +
10.29 + typedef Base Parent;
10.30 + typedef EdgeSetExtender Graph;
10.31 +
10.32 + // Base extensions
10.33 +
10.34 + typedef typename Parent::Node Node;
10.35 + typedef typename Parent::Edge Edge;
10.36 +
10.37 + int maxId(Node) const {
10.38 + return Parent::maxNodeId();
10.39 + }
10.40 +
10.41 + int maxId(Edge) const {
10.42 + return Parent::maxEdgeId();
10.43 + }
10.44 +
10.45 + Node fromId(int id, Node) const {
10.46 + return Parent::nodeFromId(id);
10.47 + }
10.48 +
10.49 + Edge fromId(int id, Edge) const {
10.50 + return Parent::edgeFromId(id);
10.51 + }
10.52 +
10.53 + Node oppositeNode(const Node &n, const Edge &e) const {
10.54 + if (n == Parent::source(e))
10.55 + return Parent::target(e);
10.56 + else if(n==Parent::target(e))
10.57 + return Parent::source(e);
10.58 + else
10.59 + return INVALID;
10.60 + }
10.61 +
10.62 +
10.63 + // Alteration notifier extensions
10.64 +
10.65 + /// The edge observer registry.
10.66 + typedef AlterationNotifier<Edge> EdgeNotifier;
10.67 +
10.68 + protected:
10.69 +
10.70 + mutable EdgeNotifier edge_notifier;
10.71 +
10.72 + public:
10.73 +
10.74 + /// \brief Gives back the edge alteration notifier.
10.75 + ///
10.76 + /// Gives back the edge alteration notifier.
10.77 + EdgeNotifier& getNotifier(Edge) const {
10.78 + return edge_notifier;
10.79 + }
10.80 +
10.81 + // Iterable extensions
10.82 +
10.83 + class NodeIt : public Node {
10.84 + const Graph* graph;
10.85 + public:
10.86 +
10.87 + NodeIt() {}
10.88 +
10.89 + NodeIt(Invalid i) : Node(i) { }
10.90 +
10.91 + explicit NodeIt(const Graph& _graph) : graph(&_graph) {
10.92 + _graph.first(*static_cast<Node*>(this));
10.93 + }
10.94 +
10.95 + NodeIt(const Graph& _graph, const Node& node)
10.96 + : Node(node), graph(&_graph) {}
10.97 +
10.98 + NodeIt& operator++() {
10.99 + graph->next(*this);
10.100 + return *this;
10.101 + }
10.102 +
10.103 + };
10.104 +
10.105 +
10.106 + class EdgeIt : public Edge {
10.107 + const Graph* graph;
10.108 + public:
10.109 +
10.110 + EdgeIt() { }
10.111 +
10.112 + EdgeIt(Invalid i) : Edge(i) { }
10.113 +
10.114 + explicit EdgeIt(const Graph& _graph) : graph(&_graph) {
10.115 + _graph.first(*static_cast<Edge*>(this));
10.116 + }
10.117 +
10.118 + EdgeIt(const Graph& _graph, const Edge& e) :
10.119 + Edge(e), graph(&_graph) { }
10.120 +
10.121 + EdgeIt& operator++() {
10.122 + graph->next(*this);
10.123 + return *this;
10.124 + }
10.125 +
10.126 + };
10.127 +
10.128 +
10.129 + class OutEdgeIt : public Edge {
10.130 + const Graph* graph;
10.131 + public:
10.132 +
10.133 + OutEdgeIt() { }
10.134 +
10.135 + OutEdgeIt(Invalid i) : Edge(i) { }
10.136 +
10.137 + OutEdgeIt(const Graph& _graph, const Node& node)
10.138 + : graph(&_graph) {
10.139 + _graph.firstOut(*this, node);
10.140 + }
10.141 +
10.142 + OutEdgeIt(const Graph& _graph, const Edge& edge)
10.143 + : Edge(edge), graph(&_graph) {}
10.144 +
10.145 + OutEdgeIt& operator++() {
10.146 + graph->nextOut(*this);
10.147 + return *this;
10.148 + }
10.149 +
10.150 + };
10.151 +
10.152 +
10.153 + class InEdgeIt : public Edge {
10.154 + const Graph* graph;
10.155 + public:
10.156 +
10.157 + InEdgeIt() { }
10.158 +
10.159 + InEdgeIt(Invalid i) : Edge(i) { }
10.160 +
10.161 + InEdgeIt(const Graph& _graph, const Node& node)
10.162 + : graph(&_graph) {
10.163 + _graph.firstIn(*this, node);
10.164 + }
10.165 +
10.166 + InEdgeIt(const Graph& _graph, const Edge& edge) :
10.167 + Edge(edge), graph(&_graph) {}
10.168 +
10.169 + InEdgeIt& operator++() {
10.170 + graph->nextIn(*this);
10.171 + return *this;
10.172 + }
10.173 +
10.174 + };
10.175 +
10.176 + /// \brief Base node of the iterator
10.177 + ///
10.178 + /// Returns the base node (ie. the source in this case) of the iterator
10.179 + Node baseNode(const OutEdgeIt &e) const {
10.180 + return Parent::source((Edge)e);
10.181 + }
10.182 + /// \brief Running node of the iterator
10.183 + ///
10.184 + /// Returns the running node (ie. the target in this case) of the
10.185 + /// iterator
10.186 + Node runningNode(const OutEdgeIt &e) const {
10.187 + return Parent::target((Edge)e);
10.188 + }
10.189 +
10.190 + /// \brief Base node of the iterator
10.191 + ///
10.192 + /// Returns the base node (ie. the target in this case) of the iterator
10.193 + Node baseNode(const InEdgeIt &e) const {
10.194 + return Parent::target((Edge)e);
10.195 + }
10.196 + /// \brief Running node of the iterator
10.197 + ///
10.198 + /// Returns the running node (ie. the source in this case) of the
10.199 + /// iterator
10.200 + Node runningNode(const InEdgeIt &e) const {
10.201 + return Parent::source((Edge)e);
10.202 + }
10.203 +
10.204 + using Parent::first;
10.205 +
10.206 + // Mappable extension
10.207 +
10.208 + template <typename _Value>
10.209 + class EdgeMap
10.210 + : public IterableMapExtender<DefaultMap<Graph, Edge, _Value> > {
10.211 + public:
10.212 + typedef EdgeSetExtender Graph;
10.213 + typedef IterableMapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
10.214 +
10.215 + EdgeMap(const Graph& _g)
10.216 + : Parent(_g) {}
10.217 + EdgeMap(const Graph& _g, const _Value& _v)
10.218 + : Parent(_g, _v) {}
10.219 +
10.220 + EdgeMap& operator=(const EdgeMap& cmap) {
10.221 + return operator=<EdgeMap>(cmap);
10.222 + }
10.223 +
10.224 + template <typename CMap>
10.225 + EdgeMap& operator=(const CMap& cmap) {
10.226 + checkConcept<concept::ReadMap<Edge, _Value>, CMap>();
10.227 + const typename Parent::Graph* graph = Parent::getGraph();
10.228 + Edge it;
10.229 + for (graph->first(it); it != INVALID; graph->next(it)) {
10.230 + Parent::set(it, cmap[it]);
10.231 + }
10.232 + return *this;
10.233 + }
10.234 + };
10.235 +
10.236 +
10.237 + // Alteration extension
10.238 +
10.239 + Edge addEdge(const Node& from, const Node& to) {
10.240 + Edge edge = Parent::addEdge(from, to);
10.241 + getNotifier(Edge()).add(edge);
10.242 + return edge;
10.243 + }
10.244 +
10.245 + void clear() {
10.246 + getNotifier(Edge()).clear();
10.247 + Parent::clear();
10.248 + }
10.249 +
10.250 + void erase(const Edge& edge) {
10.251 + getNotifier(Edge()).erase(edge);
10.252 + Parent::erase(edge);
10.253 + }
10.254 +
10.255 +
10.256 + ~EdgeSetExtender() {
10.257 + edge_notifier.clear();
10.258 + }
10.259 +
10.260 + };
10.261 +
10.262 +
10.263 + template <typename Base>
10.264 + class UEdgeSetExtender : public Base {
10.265 +
10.266 + public:
10.267 +
10.268 + typedef Base Parent;
10.269 + typedef UEdgeSetExtender Graph;
10.270 +
10.271 + typedef typename Parent::Node Node;
10.272 + typedef typename Parent::Edge Edge;
10.273 + typedef typename Parent::UEdge UEdge;
10.274 +
10.275 +
10.276 + int maxId(Node) const {
10.277 + return Parent::maxNodeId();
10.278 + }
10.279 +
10.280 + int maxId(Edge) const {
10.281 + return Parent::maxEdgeId();
10.282 + }
10.283 +
10.284 + int maxId(UEdge) const {
10.285 + return Parent::maxUEdgeId();
10.286 + }
10.287 +
10.288 + Node fromId(int id, Node) const {
10.289 + return Parent::nodeFromId(id);
10.290 + }
10.291 +
10.292 + Edge fromId(int id, Edge) const {
10.293 + return Parent::edgeFromId(id);
10.294 + }
10.295 +
10.296 + UEdge fromId(int id, UEdge) const {
10.297 + return Parent::uEdgeFromId(id);
10.298 + }
10.299 +
10.300 + Node oppositeNode(const Node &n, const UEdge &e) const {
10.301 + if( n == Parent::source(e))
10.302 + return Parent::target(e);
10.303 + else if( n == Parent::target(e))
10.304 + return Parent::source(e);
10.305 + else
10.306 + return INVALID;
10.307 + }
10.308 +
10.309 + Edge oppositeEdge(const Edge &e) const {
10.310 + return Parent::direct(e, !Parent::direction(e));
10.311 + }
10.312 +
10.313 + using Parent::direct;
10.314 + Edge direct(const UEdge &ue, const Node &s) const {
10.315 + return Parent::direct(ue, Parent::source(ue) == s);
10.316 + }
10.317 +
10.318 + typedef AlterationNotifier<Edge> EdgeNotifier;
10.319 + typedef AlterationNotifier<UEdge> UEdgeNotifier;
10.320 +
10.321 +
10.322 + protected:
10.323 +
10.324 + mutable EdgeNotifier edge_notifier;
10.325 + mutable UEdgeNotifier uedge_notifier;
10.326 +
10.327 + public:
10.328 +
10.329 + EdgeNotifier& getNotifier(Edge) const {
10.330 + return edge_notifier;
10.331 + }
10.332 +
10.333 + UEdgeNotifier& getNotifier(UEdge) const {
10.334 + return uedge_notifier;
10.335 + }
10.336 +
10.337 +
10.338 + class NodeIt : public Node {
10.339 + const Graph* graph;
10.340 + public:
10.341 +
10.342 + NodeIt() {}
10.343 +
10.344 + NodeIt(Invalid i) : Node(i) { }
10.345 +
10.346 + explicit NodeIt(const Graph& _graph) : graph(&_graph) {
10.347 + _graph.first(*static_cast<Node*>(this));
10.348 + }
10.349 +
10.350 + NodeIt(const Graph& _graph, const Node& node)
10.351 + : Node(node), graph(&_graph) {}
10.352 +
10.353 + NodeIt& operator++() {
10.354 + graph->next(*this);
10.355 + return *this;
10.356 + }
10.357 +
10.358 + };
10.359 +
10.360 +
10.361 + class EdgeIt : public Edge {
10.362 + const Graph* graph;
10.363 + public:
10.364 +
10.365 + EdgeIt() { }
10.366 +
10.367 + EdgeIt(Invalid i) : Edge(i) { }
10.368 +
10.369 + explicit EdgeIt(const Graph& _graph) : graph(&_graph) {
10.370 + _graph.first(*static_cast<Edge*>(this));
10.371 + }
10.372 +
10.373 + EdgeIt(const Graph& _graph, const Edge& e) :
10.374 + Edge(e), graph(&_graph) { }
10.375 +
10.376 + EdgeIt& operator++() {
10.377 + graph->next(*this);
10.378 + return *this;
10.379 + }
10.380 +
10.381 + };
10.382 +
10.383 +
10.384 + class OutEdgeIt : public Edge {
10.385 + const Graph* graph;
10.386 + public:
10.387 +
10.388 + OutEdgeIt() { }
10.389 +
10.390 + OutEdgeIt(Invalid i) : Edge(i) { }
10.391 +
10.392 + OutEdgeIt(const Graph& _graph, const Node& node)
10.393 + : graph(&_graph) {
10.394 + _graph.firstOut(*this, node);
10.395 + }
10.396 +
10.397 + OutEdgeIt(const Graph& _graph, const Edge& edge)
10.398 + : Edge(edge), graph(&_graph) {}
10.399 +
10.400 + OutEdgeIt& operator++() {
10.401 + graph->nextOut(*this);
10.402 + return *this;
10.403 + }
10.404 +
10.405 + };
10.406 +
10.407 +
10.408 + class InEdgeIt : public Edge {
10.409 + const Graph* graph;
10.410 + public:
10.411 +
10.412 + InEdgeIt() { }
10.413 +
10.414 + InEdgeIt(Invalid i) : Edge(i) { }
10.415 +
10.416 + InEdgeIt(const Graph& _graph, const Node& node)
10.417 + : graph(&_graph) {
10.418 + _graph.firstIn(*this, node);
10.419 + }
10.420 +
10.421 + InEdgeIt(const Graph& _graph, const Edge& edge) :
10.422 + Edge(edge), graph(&_graph) {}
10.423 +
10.424 + InEdgeIt& operator++() {
10.425 + graph->nextIn(*this);
10.426 + return *this;
10.427 + }
10.428 +
10.429 + };
10.430 +
10.431 +
10.432 + class UEdgeIt : public Parent::UEdge {
10.433 + const Graph* graph;
10.434 + public:
10.435 +
10.436 + UEdgeIt() { }
10.437 +
10.438 + UEdgeIt(Invalid i) : UEdge(i) { }
10.439 +
10.440 + explicit UEdgeIt(const Graph& _graph) : graph(&_graph) {
10.441 + _graph.first(*static_cast<UEdge*>(this));
10.442 + }
10.443 +
10.444 + UEdgeIt(const Graph& _graph, const UEdge& e) :
10.445 + UEdge(e), graph(&_graph) { }
10.446 +
10.447 + UEdgeIt& operator++() {
10.448 + graph->next(*this);
10.449 + return *this;
10.450 + }
10.451 +
10.452 + };
10.453 +
10.454 + class IncEdgeIt : public Parent::UEdge {
10.455 + friend class UEdgeSetExtender;
10.456 + const Graph* graph;
10.457 + bool direction;
10.458 + public:
10.459 +
10.460 + IncEdgeIt() { }
10.461 +
10.462 + IncEdgeIt(Invalid i) : UEdge(i), direction(false) { }
10.463 +
10.464 + IncEdgeIt(const Graph& _graph, const Node &n) : graph(&_graph) {
10.465 + _graph.firstInc(*this, direction, n);
10.466 + }
10.467 +
10.468 + IncEdgeIt(const Graph& _graph, const UEdge &ue, const Node &n)
10.469 + : graph(&_graph), UEdge(ue) {
10.470 + direction = (_graph.source(ue) == n);
10.471 + }
10.472 +
10.473 + IncEdgeIt& operator++() {
10.474 + graph->nextInc(*this, direction);
10.475 + return *this;
10.476 + }
10.477 + };
10.478 +
10.479 + /// \brief Base node of the iterator
10.480 + ///
10.481 + /// Returns the base node (ie. the source in this case) of the iterator
10.482 + Node baseNode(const OutEdgeIt &e) const {
10.483 + return Parent::source((Edge)e);
10.484 + }
10.485 + /// \brief Running node of the iterator
10.486 + ///
10.487 + /// Returns the running node (ie. the target in this case) of the
10.488 + /// iterator
10.489 + Node runningNode(const OutEdgeIt &e) const {
10.490 + return Parent::target((Edge)e);
10.491 + }
10.492 +
10.493 + /// \brief Base node of the iterator
10.494 + ///
10.495 + /// Returns the base node (ie. the target in this case) of the iterator
10.496 + Node baseNode(const InEdgeIt &e) const {
10.497 + return Parent::target((Edge)e);
10.498 + }
10.499 + /// \brief Running node of the iterator
10.500 + ///
10.501 + /// Returns the running node (ie. the source in this case) of the
10.502 + /// iterator
10.503 + Node runningNode(const InEdgeIt &e) const {
10.504 + return Parent::source((Edge)e);
10.505 + }
10.506 +
10.507 + /// Base node of the iterator
10.508 + ///
10.509 + /// Returns the base node of the iterator
10.510 + Node baseNode(const IncEdgeIt &e) const {
10.511 + return e.direction ? source(e) : target(e);
10.512 + }
10.513 + /// Running node of the iterator
10.514 + ///
10.515 + /// Returns the running node of the iterator
10.516 + Node runningNode(const IncEdgeIt &e) const {
10.517 + return e.direction ? target(e) : source(e);
10.518 + }
10.519 +
10.520 +
10.521 + template <typename _Value>
10.522 + class EdgeMap
10.523 + : public IterableMapExtender<DefaultMap<Graph, Edge, _Value> > {
10.524 + public:
10.525 + typedef UEdgeSetExtender Graph;
10.526 + typedef IterableMapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
10.527 +
10.528 + EdgeMap(const Graph& _g)
10.529 + : Parent(_g) {}
10.530 + EdgeMap(const Graph& _g, const _Value& _v)
10.531 + : Parent(_g, _v) {}
10.532 +
10.533 + EdgeMap& operator=(const EdgeMap& cmap) {
10.534 + return operator=<EdgeMap>(cmap);
10.535 + }
10.536 +
10.537 + template <typename CMap>
10.538 + EdgeMap& operator=(const CMap& cmap) {
10.539 + checkConcept<concept::ReadMap<Edge, _Value>, CMap>();
10.540 + const typename Parent::Graph* graph = Parent::getGraph();
10.541 + Edge it;
10.542 + for (graph->first(it); it != INVALID; graph->next(it)) {
10.543 + Parent::set(it, cmap[it]);
10.544 + }
10.545 + return *this;
10.546 + }
10.547 + };
10.548 +
10.549 +
10.550 + template <typename _Value>
10.551 + class UEdgeMap
10.552 + : public IterableMapExtender<DefaultMap<Graph, UEdge, _Value> > {
10.553 + public:
10.554 + typedef UEdgeSetExtender Graph;
10.555 + typedef IterableMapExtender<DefaultMap<Graph, UEdge, _Value> > Parent;
10.556 +
10.557 + UEdgeMap(const Graph& _g)
10.558 + : Parent(_g) {}
10.559 + UEdgeMap(const Graph& _g, const _Value& _v)
10.560 + : Parent(_g, _v) {}
10.561 +
10.562 + UEdgeMap& operator=(const UEdgeMap& cmap) {
10.563 + return operator=<UEdgeMap>(cmap);
10.564 + }
10.565 +
10.566 + template <typename CMap>
10.567 + UEdgeMap& operator=(const CMap& cmap) {
10.568 + checkConcept<concept::ReadMap<UEdge, _Value>, CMap>();
10.569 + const typename Parent::Graph* graph = Parent::getGraph();
10.570 + UEdge it;
10.571 + for (graph->first(it); it != INVALID; graph->next(it)) {
10.572 + Parent::set(it, cmap[it]);
10.573 + }
10.574 + return *this;
10.575 + }
10.576 + };
10.577 +
10.578 +
10.579 + // Alteration extension
10.580 +
10.581 + UEdge addEdge(const Node& from, const Node& to) {
10.582 + UEdge uedge = Parent::addEdge(from, to);
10.583 + getNotifier(UEdge()).add(uedge);
10.584 + getNotifier(Edge()).add(Parent::direct(uedge, true));
10.585 + getNotifier(Edge()).add(Parent::direct(uedge, false));
10.586 + return uedge;
10.587 + }
10.588 +
10.589 + void clear() {
10.590 + getNotifier(Edge()).clear();
10.591 + getNotifier(UEdge()).clear();
10.592 + Parent::clear();
10.593 + }
10.594 +
10.595 + void erase(const UEdge& uedge) {
10.596 + getNotifier(Edge()).erase(Parent::direct(uedge, true));
10.597 + getNotifier(Edge()).erase(Parent::direct(uedge, false));
10.598 + getNotifier(UEdge()).erase(uedge);
10.599 + Parent::erase(uedge);
10.600 + }
10.601 +
10.602 +
10.603 + ~UEdgeSetExtender() {
10.604 + getNotifier(Edge()).clear();
10.605 + getNotifier(UEdge()).clear();
10.606 + }
10.607 +
10.608 + };
10.609 +}
11.1 --- a/lemon/bits/erasable_graph_extender.h Wed Feb 22 12:45:59 2006 +0000
11.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
11.3 @@ -1,138 +0,0 @@
11.4 -/* -*- C++ -*-
11.5 - *
11.6 - * This file is a part of LEMON, a generic C++ optimization library
11.7 - *
11.8 - * Copyright (C) 2003-2006
11.9 - * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
11.10 - * (Egervary Research Group on Combinatorial Optimization, EGRES).
11.11 - *
11.12 - * Permission to use, modify and distribute this software is granted
11.13 - * provided that this copyright notice appears in all copies. For
11.14 - * precise terms see the accompanying LICENSE file.
11.15 - *
11.16 - * This software is provided "AS IS" with no warranty of any kind,
11.17 - * express or implied, and with no claim as to its suitability for any
11.18 - * purpose.
11.19 - *
11.20 - */
11.21 -
11.22 -#ifndef LEMON_ERASABLE_GRAPH_EXTENDER_H
11.23 -#define LEMON_ERASABLE_GRAPH_EXTENDER_H
11.24 -
11.25 -#include <vector>
11.26 -
11.27 -#include <lemon/invalid.h>
11.28 -
11.29 -
11.30 -namespace lemon {
11.31 -
11.32 - template <typename _Base>
11.33 - class ErasableGraphExtender : public _Base {
11.34 - public:
11.35 -
11.36 - typedef ErasableGraphExtender Graph;
11.37 - typedef _Base Parent;
11.38 -
11.39 - typedef typename Parent::Node Node;
11.40 - typedef typename Parent::Edge Edge;
11.41 -
11.42 - void erase(const Node& node) {
11.43 - Edge edge;
11.44 - Parent::firstOut(edge, node);
11.45 - while (edge != INVALID ) {
11.46 - erase(edge);
11.47 - Parent::firstOut(edge, node);
11.48 - }
11.49 -
11.50 - Parent::firstIn(edge, node);
11.51 - while (edge != INVALID ) {
11.52 - erase(edge);
11.53 - Parent::firstIn(edge, node);
11.54 - }
11.55 -
11.56 - Parent::getNotifier(Node()).erase(node);
11.57 - Parent::erase(node);
11.58 - }
11.59 -
11.60 - void erase(const Edge& edge) {
11.61 - Parent::getNotifier(Edge()).erase(edge);
11.62 - Parent::erase(edge);
11.63 - }
11.64 -
11.65 - };
11.66 -
11.67 - template <typename _Base>
11.68 - class ErasableEdgeSetExtender : public _Base {
11.69 - public:
11.70 -
11.71 - typedef ErasableEdgeSetExtender Graph;
11.72 - typedef _Base Parent;
11.73 -
11.74 - typedef typename Parent::Edge Edge;
11.75 -
11.76 - void erase(const Edge& edge) {
11.77 - Parent::getNotifier(Edge()).erase(edge);
11.78 - Parent::erase(edge);
11.79 - }
11.80 -
11.81 - };
11.82 -
11.83 - template <typename _Base>
11.84 - class ErasableUGraphExtender : public _Base {
11.85 - public:
11.86 -
11.87 - typedef ErasableUGraphExtender Graph;
11.88 - typedef _Base Parent;
11.89 -
11.90 - typedef typename Parent::Node Node;
11.91 - typedef typename Parent::UEdge UEdge;
11.92 - typedef typename Parent::Edge Edge;
11.93 -
11.94 - void erase(const Node& node) {
11.95 - Edge edge;
11.96 - Parent::firstOut(edge, node);
11.97 - while (edge != INVALID ) {
11.98 - erase(edge);
11.99 - Parent::firstOut(edge, node);
11.100 - }
11.101 -
11.102 - Parent::getNotifier(Node()).erase(node);
11.103 - Parent::erase(node);
11.104 - }
11.105 -
11.106 - void erase(const UEdge& uedge) {
11.107 - std::vector<Edge> edges;
11.108 - edges.push_back(Parent::direct(uedge,true));
11.109 - edges.push_back(Parent::direct(uedge,false));
11.110 - Parent::getNotifier(Edge()).erase(edges);
11.111 - Parent::getNotifier(UEdge()).erase(uedge);
11.112 - Parent::erase(uedge);
11.113 - }
11.114 -
11.115 - };
11.116 -
11.117 - template <typename _Base>
11.118 - class ErasableUEdgeSetExtender : public _Base {
11.119 - public:
11.120 -
11.121 - typedef ErasableUEdgeSetExtender Graph;
11.122 - typedef _Base Parent;
11.123 -
11.124 - typedef typename Parent::Node Node;
11.125 - typedef typename Parent::UEdge UEdge;
11.126 - typedef typename Parent::Edge Edge;
11.127 -
11.128 - void erase(const UEdge& uedge) {
11.129 - std::vector<Edge> edges;
11.130 - edges.push_back(Parent::direct(uedge,true));
11.131 - edges.push_back(Parent::direct(uedge,false));
11.132 - Parent::getNotifier(Edge()).erase(edges);
11.133 - Parent::getNotifier(UEdge()).erase(uedge);
11.134 - Parent::erase(uedge);
11.135 - }
11.136 -
11.137 - };
11.138 -
11.139 -}
11.140 -
11.141 -#endif
12.1 --- a/lemon/bits/extendable_graph_extender.h Wed Feb 22 12:45:59 2006 +0000
12.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
12.3 @@ -1,166 +0,0 @@
12.4 -/* -*- C++ -*-
12.5 - *
12.6 - * This file is a part of LEMON, a generic C++ optimization library
12.7 - *
12.8 - * Copyright (C) 2003-2006
12.9 - * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
12.10 - * (Egervary Research Group on Combinatorial Optimization, EGRES).
12.11 - *
12.12 - * Permission to use, modify and distribute this software is granted
12.13 - * provided that this copyright notice appears in all copies. For
12.14 - * precise terms see the accompanying LICENSE file.
12.15 - *
12.16 - * This software is provided "AS IS" with no warranty of any kind,
12.17 - * express or implied, and with no claim as to its suitability for any
12.18 - * purpose.
12.19 - *
12.20 - */
12.21 -
12.22 -#ifndef LEMON_EXTENDABLE_GRAPH_EXTENDER_H
12.23 -#define LEMON_EXTENDABLE_GRAPH_EXTENDER_H
12.24 -
12.25 -namespace lemon {
12.26 -
12.27 - template <typename _Base>
12.28 - class ExtendableGraphExtender : public _Base {
12.29 - public:
12.30 -
12.31 - typedef ExtendableGraphExtender Graph;
12.32 - typedef _Base Parent;
12.33 -
12.34 - typedef typename Parent::Node Node;
12.35 - typedef typename Parent::Edge Edge;
12.36 -
12.37 - Node addNode() {
12.38 - Node node = Parent::addNode();
12.39 - Parent::getNotifier(Node()).add(node);
12.40 - return node;
12.41 - }
12.42 -
12.43 - Edge addEdge(const Node& from, const Node& to) {
12.44 - Edge edge = Parent::addEdge(from, to);
12.45 - Parent::getNotifier(Edge()).add(edge);
12.46 - return edge;
12.47 - }
12.48 -
12.49 - };
12.50 -
12.51 - template <typename _Base>
12.52 - class ExtendableEdgeSetExtender : public _Base {
12.53 - public:
12.54 -
12.55 - typedef ExtendableEdgeSetExtender Graph;
12.56 - typedef _Base Parent;
12.57 -
12.58 - typedef typename Parent::Edge Edge;
12.59 - typedef typename Parent::Node Node;
12.60 -
12.61 - Edge addEdge(const Node& from, const Node& to) {
12.62 - Edge edge = Parent::addEdge(from, to);
12.63 - Parent::getNotifier(Edge()).add(edge);
12.64 - return edge;
12.65 - }
12.66 -
12.67 - };
12.68 -
12.69 - template <typename _Base>
12.70 - class ExtendableUGraphExtender : public _Base {
12.71 - public:
12.72 -
12.73 - typedef ExtendableUGraphExtender Graph;
12.74 - typedef _Base Parent;
12.75 -
12.76 - typedef typename Parent::Node Node;
12.77 - typedef typename Parent::Edge Edge;
12.78 - typedef typename Parent::UEdge UEdge;
12.79 -
12.80 - Node addNode() {
12.81 - Node node = Parent::addNode();
12.82 - Parent::getNotifier(Node()).add(node);
12.83 - return node;
12.84 - }
12.85 -
12.86 - UEdge addEdge(const Node& from, const Node& to) {
12.87 - UEdge uedge = Parent::addEdge(from, to);
12.88 - Parent::getNotifier(UEdge()).add(uedge);
12.89 -
12.90 - std::vector<Edge> edges;
12.91 - edges.push_back(Parent::direct(uedge, true));
12.92 - edges.push_back(Parent::direct(uedge, false));
12.93 - Parent::getNotifier(Edge()).add(edges);
12.94 -
12.95 - return uedge;
12.96 - }
12.97 -
12.98 - };
12.99 -
12.100 - template <typename _Base>
12.101 - class ExtendableUEdgeSetExtender : public _Base {
12.102 - public:
12.103 -
12.104 - typedef ExtendableUEdgeSetExtender Graph;
12.105 - typedef _Base Parent;
12.106 -
12.107 - typedef typename Parent::Node Node;
12.108 - typedef typename Parent::Edge Edge;
12.109 - typedef typename Parent::UEdge UEdge;
12.110 -
12.111 - UEdge addEdge(const Node& from, const Node& to) {
12.112 - UEdge uedge = Parent::addEdge(from, to);
12.113 - Parent::getNotifier(UEdge()).add(uedge);
12.114 -
12.115 - std::vector<Edge> edges;
12.116 - edges.push_back(Parent::direct(uedge, true));
12.117 - edges.push_back(Parent::direct(uedge, false));
12.118 - Parent::getNotifier(Edge()).add(edges);
12.119 -
12.120 - return uedge;
12.121 - }
12.122 -
12.123 - };
12.124 -
12.125 -
12.126 - template <typename _Base>
12.127 - class ExtendableBpUGraphExtender : public _Base {
12.128 - public:
12.129 -
12.130 - typedef _Base Parent;
12.131 - typedef ExtendableBpUGraphExtender Graph;
12.132 -
12.133 - typedef typename Parent::Node Node;
12.134 - typedef typename Parent::BNode BNode;
12.135 - typedef typename Parent::ANode ANode;
12.136 - typedef typename Parent::Edge Edge;
12.137 - typedef typename Parent::UEdge UEdge;
12.138 -
12.139 - Node addANode() {
12.140 - Node node = Parent::addANode();
12.141 - Parent::getNotifier(ANode()).add(node);
12.142 - Parent::getNotifier(Node()).add(node);
12.143 - return node;
12.144 - }
12.145 -
12.146 - Node addBNode() {
12.147 - Node node = Parent::addBNode();
12.148 - Parent::getNotifier(BNode()).add(node);
12.149 - Parent::getNotifier(Node()).add(node);
12.150 - return node;
12.151 - }
12.152 -
12.153 - UEdge addEdge(const Node& source, const Node& target) {
12.154 - UEdge uedge = Parent::addEdge(source, target);
12.155 - Parent::getNotifier(UEdge()).add(uedge);
12.156 -
12.157 - std::vector<Edge> edges;
12.158 - edges.push_back(Parent::direct(uedge, true));
12.159 - edges.push_back(Parent::direct(uedge, false));
12.160 - Parent::getNotifier(Edge()).add(edges);
12.161 -
12.162 - return uedge;
12.163 - }
12.164 -
12.165 - };
12.166 -
12.167 -}
12.168 -
12.169 -#endif
13.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
13.2 +++ b/lemon/bits/graph_adaptor_extender.h Wed Feb 22 18:26:56 2006 +0000
13.3 @@ -0,0 +1,429 @@
13.4 +/* -*- C++ -*-
13.5 + *
13.6 + * This file is a part of LEMON, a generic C++ optimization library
13.7 + *
13.8 + * Copyright (C) 2003-2006
13.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
13.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
13.11 + *
13.12 + * Permission to use, modify and distribute this software is granted
13.13 + * provided that this copyright notice appears in all copies. For
13.14 + * precise terms see the accompanying LICENSE file.
13.15 + *
13.16 + * This software is provided "AS IS" with no warranty of any kind,
13.17 + * express or implied, and with no claim as to its suitability for any
13.18 + * purpose.
13.19 + *
13.20 + */
13.21 +
13.22 +#ifndef LEMON_GRAPH_ADAPTOR_EXTENDER_H
13.23 +#define LEMON_GRAPH_ADAPTOR_EXTENDER_H
13.24 +
13.25 +
13.26 +namespace lemon {
13.27 +
13.28 + template <typename Base>
13.29 + class GraphAdaptorExtender : public Base {
13.30 + public:
13.31 +
13.32 + typedef Base Parent;
13.33 + typedef GraphAdaptorExtender Graph;
13.34 +
13.35 + // Base extensions
13.36 +
13.37 + typedef typename Parent::Node Node;
13.38 + typedef typename Parent::Edge Edge;
13.39 +
13.40 + int maxId(Node) const {
13.41 + return Parent::maxNodeId();
13.42 + }
13.43 +
13.44 + int maxId(Edge) const {
13.45 + return Parent::maxEdgeId();
13.46 + }
13.47 +
13.48 + Node fromId(int id, Node) const {
13.49 + return Parent::nodeFromId(id);
13.50 + }
13.51 +
13.52 + Edge fromId(int id, Edge) const {
13.53 + return Parent::edgeFromId(id);
13.54 + }
13.55 +
13.56 + Node oppositeNode(const Node &n, const Edge &e) const {
13.57 + if (n == Parent::source(e))
13.58 + return Parent::target(e);
13.59 + else if(n==Parent::target(e))
13.60 + return Parent::source(e);
13.61 + else
13.62 + return INVALID;
13.63 + }
13.64 +
13.65 + class NodeIt : public Node {
13.66 + const Graph* graph;
13.67 + public:
13.68 +
13.69 + NodeIt() {}
13.70 +
13.71 + NodeIt(Invalid i) : Node(i) { }
13.72 +
13.73 + explicit NodeIt(const Graph& _graph) : graph(&_graph) {
13.74 + _graph.first(*static_cast<Node*>(this));
13.75 + }
13.76 +
13.77 + NodeIt(const Graph& _graph, const Node& node)
13.78 + : Node(node), graph(&_graph) {}
13.79 +
13.80 + NodeIt& operator++() {
13.81 + graph->next(*this);
13.82 + return *this;
13.83 + }
13.84 +
13.85 + };
13.86 +
13.87 +
13.88 + class EdgeIt : public Edge {
13.89 + const Graph* graph;
13.90 + public:
13.91 +
13.92 + EdgeIt() { }
13.93 +
13.94 + EdgeIt(Invalid i) : Edge(i) { }
13.95 +
13.96 + explicit EdgeIt(const Graph& _graph) : graph(&_graph) {
13.97 + _graph.first(*static_cast<Edge*>(this));
13.98 + }
13.99 +
13.100 + EdgeIt(const Graph& _graph, const Edge& e) :
13.101 + Edge(e), graph(&_graph) { }
13.102 +
13.103 + EdgeIt& operator++() {
13.104 + graph->next(*this);
13.105 + return *this;
13.106 + }
13.107 +
13.108 + };
13.109 +
13.110 +
13.111 + class OutEdgeIt : public Edge {
13.112 + const Graph* graph;
13.113 + public:
13.114 +
13.115 + OutEdgeIt() { }
13.116 +
13.117 + OutEdgeIt(Invalid i) : Edge(i) { }
13.118 +
13.119 + OutEdgeIt(const Graph& _graph, const Node& node)
13.120 + : graph(&_graph) {
13.121 + _graph.firstOut(*this, node);
13.122 + }
13.123 +
13.124 + OutEdgeIt(const Graph& _graph, const Edge& edge)
13.125 + : Edge(edge), graph(&_graph) {}
13.126 +
13.127 + OutEdgeIt& operator++() {
13.128 + graph->nextOut(*this);
13.129 + return *this;
13.130 + }
13.131 +
13.132 + };
13.133 +
13.134 +
13.135 + class InEdgeIt : public Edge {
13.136 + const Graph* graph;
13.137 + public:
13.138 +
13.139 + InEdgeIt() { }
13.140 +
13.141 + InEdgeIt(Invalid i) : Edge(i) { }
13.142 +
13.143 + InEdgeIt(const Graph& _graph, const Node& node)
13.144 + : graph(&_graph) {
13.145 + _graph.firstIn(*this, node);
13.146 + }
13.147 +
13.148 + InEdgeIt(const Graph& _graph, const Edge& edge) :
13.149 + Edge(edge), graph(&_graph) {}
13.150 +
13.151 + InEdgeIt& operator++() {
13.152 + graph->nextIn(*this);
13.153 + return *this;
13.154 + }
13.155 +
13.156 + };
13.157 +
13.158 + /// \brief Base node of the iterator
13.159 + ///
13.160 + /// Returns the base node (ie. the source in this case) of the iterator
13.161 + Node baseNode(const OutEdgeIt &e) const {
13.162 + return Parent::source(e);
13.163 + }
13.164 + /// \brief Running node of the iterator
13.165 + ///
13.166 + /// Returns the running node (ie. the target in this case) of the
13.167 + /// iterator
13.168 + Node runningNode(const OutEdgeIt &e) const {
13.169 + return Parent::target(e);
13.170 + }
13.171 +
13.172 + /// \brief Base node of the iterator
13.173 + ///
13.174 + /// Returns the base node (ie. the target in this case) of the iterator
13.175 + Node baseNode(const InEdgeIt &e) const {
13.176 + return Parent::target(e);
13.177 + }
13.178 + /// \brief Running node of the iterator
13.179 + ///
13.180 + /// Returns the running node (ie. the source in this case) of the
13.181 + /// iterator
13.182 + Node runningNode(const InEdgeIt &e) const {
13.183 + return Parent::source(e);
13.184 + }
13.185 +
13.186 + };
13.187 +
13.188 +
13.189 + template <typename Base>
13.190 + class UGraphAdaptorExtender : public Base {
13.191 + public:
13.192 +
13.193 + typedef Base Parent;
13.194 + typedef UGraphAdaptorExtender Graph;
13.195 +
13.196 + typedef typename Parent::Node Node;
13.197 + typedef typename Parent::Edge Edge;
13.198 + typedef typename Parent::UEdge UEdge;
13.199 +
13.200 + // UGraph extension
13.201 +
13.202 + int maxId(Node) const {
13.203 + return Parent::maxNodeId();
13.204 + }
13.205 +
13.206 + int maxId(Edge) const {
13.207 + return Parent::maxEdgeId();
13.208 + }
13.209 +
13.210 + int maxId(UEdge) const {
13.211 + return Parent::maxUEdgeId();
13.212 + }
13.213 +
13.214 + Node fromId(int id, Node) const {
13.215 + return Parent::nodeFromId(id);
13.216 + }
13.217 +
13.218 + Edge fromId(int id, Edge) const {
13.219 + return Parent::edgeFromId(id);
13.220 + }
13.221 +
13.222 + UEdge fromId(int id, UEdge) const {
13.223 + return Parent::uEdgeFromId(id);
13.224 + }
13.225 +
13.226 + Node oppositeNode(const Node &n, const UEdge &e) const {
13.227 + if( n == Parent::source(e))
13.228 + return Parent::target(e);
13.229 + else if( n == Parent::target(e))
13.230 + return Parent::source(e);
13.231 + else
13.232 + return INVALID;
13.233 + }
13.234 +
13.235 + Edge oppositeEdge(const Edge &e) const {
13.236 + return Parent::direct(e, !Parent::direction(e));
13.237 + }
13.238 +
13.239 + using Parent::direct;
13.240 + Edge direct(const UEdge &ue, const Node &s) const {
13.241 + return Parent::direct(ue, Parent::source(ue) == s);
13.242 + }
13.243 +
13.244 +
13.245 + class NodeIt : public Node {
13.246 + const Graph* graph;
13.247 + public:
13.248 +
13.249 + NodeIt() {}
13.250 +
13.251 + NodeIt(Invalid i) : Node(i) { }
13.252 +
13.253 + explicit NodeIt(const Graph& _graph) : graph(&_graph) {
13.254 + _graph.first(*static_cast<Node*>(this));
13.255 + }
13.256 +
13.257 + NodeIt(const Graph& _graph, const Node& node)
13.258 + : Node(node), graph(&_graph) {}
13.259 +
13.260 + NodeIt& operator++() {
13.261 + graph->next(*this);
13.262 + return *this;
13.263 + }
13.264 +
13.265 + };
13.266 +
13.267 +
13.268 + class EdgeIt : public Edge {
13.269 + const Graph* graph;
13.270 + public:
13.271 +
13.272 + EdgeIt() { }
13.273 +
13.274 + EdgeIt(Invalid i) : Edge(i) { }
13.275 +
13.276 + explicit EdgeIt(const Graph& _graph) : graph(&_graph) {
13.277 + _graph.first(*static_cast<Edge*>(this));
13.278 + }
13.279 +
13.280 + EdgeIt(const Graph& _graph, const Edge& e) :
13.281 + Edge(e), graph(&_graph) { }
13.282 +
13.283 + EdgeIt& operator++() {
13.284 + graph->next(*this);
13.285 + return *this;
13.286 + }
13.287 +
13.288 + };
13.289 +
13.290 +
13.291 + class OutEdgeIt : public Edge {
13.292 + const Graph* graph;
13.293 + public:
13.294 +
13.295 + OutEdgeIt() { }
13.296 +
13.297 + OutEdgeIt(Invalid i) : Edge(i) { }
13.298 +
13.299 + OutEdgeIt(const Graph& _graph, const Node& node)
13.300 + : graph(&_graph) {
13.301 + _graph.firstOut(*this, node);
13.302 + }
13.303 +
13.304 + OutEdgeIt(const Graph& _graph, const Edge& edge)
13.305 + : Edge(edge), graph(&_graph) {}
13.306 +
13.307 + OutEdgeIt& operator++() {
13.308 + graph->nextOut(*this);
13.309 + return *this;
13.310 + }
13.311 +
13.312 + };
13.313 +
13.314 +
13.315 + class InEdgeIt : public Edge {
13.316 + const Graph* graph;
13.317 + public:
13.318 +
13.319 + InEdgeIt() { }
13.320 +
13.321 + InEdgeIt(Invalid i) : Edge(i) { }
13.322 +
13.323 + InEdgeIt(const Graph& _graph, const Node& node)
13.324 + : graph(&_graph) {
13.325 + _graph.firstIn(*this, node);
13.326 + }
13.327 +
13.328 + InEdgeIt(const Graph& _graph, const Edge& edge) :
13.329 + Edge(edge), graph(&_graph) {}
13.330 +
13.331 + InEdgeIt& operator++() {
13.332 + graph->nextIn(*this);
13.333 + return *this;
13.334 + }
13.335 +
13.336 + };
13.337 +
13.338 + class UEdgeIt : public Parent::UEdge {
13.339 + const Graph* graph;
13.340 + public:
13.341 +
13.342 + UEdgeIt() { }
13.343 +
13.344 + UEdgeIt(Invalid i) : UEdge(i) { }
13.345 +
13.346 + explicit UEdgeIt(const Graph& _graph) : graph(&_graph) {
13.347 + _graph.first(*static_cast<UEdge*>(this));
13.348 + }
13.349 +
13.350 + UEdgeIt(const Graph& _graph, const UEdge& e) :
13.351 + UEdge(e), graph(&_graph) { }
13.352 +
13.353 + UEdgeIt& operator++() {
13.354 + graph->next(*this);
13.355 + return *this;
13.356 + }
13.357 +
13.358 + };
13.359 +
13.360 + class IncEdgeIt : public Parent::UEdge {
13.361 + friend class UGraphAdaptorExtender;
13.362 + const Graph* graph;
13.363 + bool direction;
13.364 + public:
13.365 +
13.366 + IncEdgeIt() { }
13.367 +
13.368 + IncEdgeIt(Invalid i) : UEdge(i), direction(false) { }
13.369 +
13.370 + IncEdgeIt(const Graph& _graph, const Node &n) : graph(&_graph) {
13.371 + _graph.firstInc(static_cast<UEdge&>(*this), direction, n);
13.372 + }
13.373 +
13.374 + IncEdgeIt(const Graph& _graph, const UEdge &ue, const Node &n)
13.375 + : graph(&_graph), UEdge(ue) {
13.376 + direction = (_graph.source(ue) == n);
13.377 + }
13.378 +
13.379 + IncEdgeIt& operator++() {
13.380 + graph->nextInc(*this, direction);
13.381 + return *this;
13.382 + }
13.383 + };
13.384 +
13.385 + /// \brief Base node of the iterator
13.386 + ///
13.387 + /// Returns the base node (ie. the source in this case) of the iterator
13.388 + Node baseNode(const OutEdgeIt &e) const {
13.389 + return Parent::source((Edge)e);
13.390 + }
13.391 + /// \brief Running node of the iterator
13.392 + ///
13.393 + /// Returns the running node (ie. the target in this case) of the
13.394 + /// iterator
13.395 + Node runningNode(const OutEdgeIt &e) const {
13.396 + return Parent::target((Edge)e);
13.397 + }
13.398 +
13.399 + /// \brief Base node of the iterator
13.400 + ///
13.401 + /// Returns the base node (ie. the target in this case) of the iterator
13.402 + Node baseNode(const InEdgeIt &e) const {
13.403 + return Parent::target((Edge)e);
13.404 + }
13.405 + /// \brief Running node of the iterator
13.406 + ///
13.407 + /// Returns the running node (ie. the source in this case) of the
13.408 + /// iterator
13.409 + Node runningNode(const InEdgeIt &e) const {
13.410 + return Parent::source((Edge)e);
13.411 + }
13.412 +
13.413 + /// Base node of the iterator
13.414 + ///
13.415 + /// Returns the base node of the iterator
13.416 + Node baseNode(const IncEdgeIt &e) const {
13.417 + return e.direction ? source(e) : target(e);
13.418 + }
13.419 + /// Running node of the iterator
13.420 + ///
13.421 + /// Returns the running node of the iterator
13.422 + Node runningNode(const IncEdgeIt &e) const {
13.423 + return e.direction ? target(e) : source(e);
13.424 + }
13.425 +
13.426 + };
13.427 +
13.428 +
13.429 +}
13.430 +
13.431 +
13.432 +#endif
14.1 --- a/lemon/bits/graph_extender.h Wed Feb 22 12:45:59 2006 +0000
14.2 +++ b/lemon/bits/graph_extender.h Wed Feb 22 18:26:56 2006 +0000
14.3 @@ -22,15 +22,19 @@
14.4 #include <lemon/invalid.h>
14.5 #include <lemon/error.h>
14.6
14.7 +#include <lemon/bits/default_map.h>
14.8 +
14.9 namespace lemon {
14.10
14.11 - template <typename _Base>
14.12 - class GraphExtender : public _Base {
14.13 + template <typename Base>
14.14 + class GraphExtender : public Base {
14.15 public:
14.16
14.17 - typedef _Base Parent;
14.18 + typedef Base Parent;
14.19 typedef GraphExtender Graph;
14.20
14.21 + // Base extensions
14.22 +
14.23 typedef typename Parent::Node Node;
14.24 typedef typename Parent::Edge Edge;
14.25
14.26 @@ -59,24 +63,278 @@
14.27 return INVALID;
14.28 }
14.29
14.30 - };
14.31 + // Alterable extension
14.32
14.33 - template <typename _Base>
14.34 - class UGraphExtender : public _Base {
14.35 - typedef _Base Parent;
14.36 - typedef UGraphExtender Graph;
14.37 + typedef AlterationNotifier<Node> NodeNotifier;
14.38 + typedef AlterationNotifier<Edge> EdgeNotifier;
14.39 +
14.40 +
14.41 + protected:
14.42 +
14.43 + mutable NodeNotifier node_notifier;
14.44 + mutable EdgeNotifier edge_notifier;
14.45
14.46 public:
14.47
14.48 + NodeNotifier& getNotifier(Node) const {
14.49 + return node_notifier;
14.50 + }
14.51 +
14.52 + EdgeNotifier& getNotifier(Edge) const {
14.53 + return edge_notifier;
14.54 + }
14.55 +
14.56 + class NodeIt : public Node {
14.57 + const Graph* graph;
14.58 + public:
14.59 +
14.60 + NodeIt() {}
14.61 +
14.62 + NodeIt(Invalid i) : Node(i) { }
14.63 +
14.64 + explicit NodeIt(const Graph& _graph) : graph(&_graph) {
14.65 + _graph.first(*static_cast<Node*>(this));
14.66 + }
14.67 +
14.68 + NodeIt(const Graph& _graph, const Node& node)
14.69 + : Node(node), graph(&_graph) {}
14.70 +
14.71 + NodeIt& operator++() {
14.72 + graph->next(*this);
14.73 + return *this;
14.74 + }
14.75 +
14.76 + };
14.77 +
14.78 +
14.79 + class EdgeIt : public Edge {
14.80 + const Graph* graph;
14.81 + public:
14.82 +
14.83 + EdgeIt() { }
14.84 +
14.85 + EdgeIt(Invalid i) : Edge(i) { }
14.86 +
14.87 + explicit EdgeIt(const Graph& _graph) : graph(&_graph) {
14.88 + _graph.first(*static_cast<Edge*>(this));
14.89 + }
14.90 +
14.91 + EdgeIt(const Graph& _graph, const Edge& e) :
14.92 + Edge(e), graph(&_graph) { }
14.93 +
14.94 + EdgeIt& operator++() {
14.95 + graph->next(*this);
14.96 + return *this;
14.97 + }
14.98 +
14.99 + };
14.100 +
14.101 +
14.102 + class OutEdgeIt : public Edge {
14.103 + const Graph* graph;
14.104 + public:
14.105 +
14.106 + OutEdgeIt() { }
14.107 +
14.108 + OutEdgeIt(Invalid i) : Edge(i) { }
14.109 +
14.110 + OutEdgeIt(const Graph& _graph, const Node& node)
14.111 + : graph(&_graph) {
14.112 + _graph.firstOut(*this, node);
14.113 + }
14.114 +
14.115 + OutEdgeIt(const Graph& _graph, const Edge& edge)
14.116 + : Edge(edge), graph(&_graph) {}
14.117 +
14.118 + OutEdgeIt& operator++() {
14.119 + graph->nextOut(*this);
14.120 + return *this;
14.121 + }
14.122 +
14.123 + };
14.124 +
14.125 +
14.126 + class InEdgeIt : public Edge {
14.127 + const Graph* graph;
14.128 + public:
14.129 +
14.130 + InEdgeIt() { }
14.131 +
14.132 + InEdgeIt(Invalid i) : Edge(i) { }
14.133 +
14.134 + InEdgeIt(const Graph& _graph, const Node& node)
14.135 + : graph(&_graph) {
14.136 + _graph.firstIn(*this, node);
14.137 + }
14.138 +
14.139 + InEdgeIt(const Graph& _graph, const Edge& edge) :
14.140 + Edge(edge), graph(&_graph) {}
14.141 +
14.142 + InEdgeIt& operator++() {
14.143 + graph->nextIn(*this);
14.144 + return *this;
14.145 + }
14.146 +
14.147 + };
14.148 +
14.149 + /// \brief Base node of the iterator
14.150 + ///
14.151 + /// Returns the base node (ie. the source in this case) of the iterator
14.152 + Node baseNode(const OutEdgeIt &e) const {
14.153 + return Parent::source(e);
14.154 + }
14.155 + /// \brief Running node of the iterator
14.156 + ///
14.157 + /// Returns the running node (ie. the target in this case) of the
14.158 + /// iterator
14.159 + Node runningNode(const OutEdgeIt &e) const {
14.160 + return Parent::target(e);
14.161 + }
14.162 +
14.163 + /// \brief Base node of the iterator
14.164 + ///
14.165 + /// Returns the base node (ie. the target in this case) of the iterator
14.166 + Node baseNode(const InEdgeIt &e) const {
14.167 + return Parent::target(e);
14.168 + }
14.169 + /// \brief Running node of the iterator
14.170 + ///
14.171 + /// Returns the running node (ie. the source in this case) of the
14.172 + /// iterator
14.173 + Node runningNode(const InEdgeIt &e) const {
14.174 + return Parent::source(e);
14.175 + }
14.176 +
14.177 +
14.178 + template <typename _Value>
14.179 + class NodeMap
14.180 + : public IterableMapExtender<DefaultMap<Graph, Node, _Value> > {
14.181 + public:
14.182 + typedef GraphExtender Graph;
14.183 + typedef IterableMapExtender<DefaultMap<Graph, Node, _Value> > Parent;
14.184 +
14.185 + NodeMap(const Graph& _g)
14.186 + : Parent(_g) {}
14.187 + NodeMap(const Graph& _g, const _Value& _v)
14.188 + : Parent(_g, _v) {}
14.189 +
14.190 + NodeMap& operator=(const NodeMap& cmap) {
14.191 + return operator=<NodeMap>(cmap);
14.192 + }
14.193 +
14.194 +
14.195 + /// \brief Template assign operator.
14.196 + ///
14.197 + /// The given parameter should be conform to the ReadMap
14.198 + /// concecpt and could be indiced by the current item set of
14.199 + /// the NodeMap. In this case the value for each item
14.200 + /// is assigned by the value of the given ReadMap.
14.201 + template <typename CMap>
14.202 + NodeMap& operator=(const CMap& cmap) {
14.203 + checkConcept<concept::ReadMap<Node, _Value>, CMap>();
14.204 + const typename Parent::Graph* graph = Parent::getGraph();
14.205 + Node it;
14.206 + for (graph->first(it); it != INVALID; graph->next(it)) {
14.207 + Parent::set(it, cmap[it]);
14.208 + }
14.209 + return *this;
14.210 + }
14.211 +
14.212 + };
14.213 +
14.214 + template <typename _Value>
14.215 + class EdgeMap
14.216 + : public IterableMapExtender<DefaultMap<Graph, Edge, _Value> > {
14.217 + public:
14.218 + typedef GraphExtender Graph;
14.219 + typedef IterableMapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
14.220 +
14.221 + EdgeMap(const Graph& _g)
14.222 + : Parent(_g) {}
14.223 + EdgeMap(const Graph& _g, const _Value& _v)
14.224 + : Parent(_g, _v) {}
14.225 +
14.226 + EdgeMap& operator=(const EdgeMap& cmap) {
14.227 + return operator=<EdgeMap>(cmap);
14.228 + }
14.229 +
14.230 + template <typename CMap>
14.231 + EdgeMap& operator=(const CMap& cmap) {
14.232 + checkConcept<concept::ReadMap<Edge, _Value>, CMap>();
14.233 + const typename Parent::Graph* graph = Parent::getGraph();
14.234 + Edge it;
14.235 + for (graph->first(it); it != INVALID; graph->next(it)) {
14.236 + Parent::set(it, cmap[it]);
14.237 + }
14.238 + return *this;
14.239 + }
14.240 + };
14.241 +
14.242 +
14.243 + Node addNode() {
14.244 + Node node = Parent::addNode();
14.245 + getNotifier(Node()).add(node);
14.246 + return node;
14.247 + }
14.248 +
14.249 + Edge addEdge(const Node& from, const Node& to) {
14.250 + Edge edge = Parent::addEdge(from, to);
14.251 + getNotifier(Edge()).add(edge);
14.252 + return edge;
14.253 + }
14.254 +
14.255 + void clear() {
14.256 + getNotifier(Edge()).clear();
14.257 + getNotifier(Node()).clear();
14.258 + Parent::clear();
14.259 + }
14.260 +
14.261 +
14.262 + void erase(const Node& node) {
14.263 + Edge edge;
14.264 + Parent::firstOut(edge, node);
14.265 + while (edge != INVALID ) {
14.266 + erase(edge);
14.267 + Parent::firstOut(edge, node);
14.268 + }
14.269 +
14.270 + Parent::firstIn(edge, node);
14.271 + while (edge != INVALID ) {
14.272 + erase(edge);
14.273 + Parent::firstIn(edge, node);
14.274 + }
14.275 +
14.276 + getNotifier(Node()).erase(node);
14.277 + Parent::erase(node);
14.278 + }
14.279 +
14.280 + void erase(const Edge& edge) {
14.281 + getNotifier(Edge()).erase(edge);
14.282 + Parent::erase(edge);
14.283 + }
14.284 +
14.285 +
14.286 + ~GraphExtender() {
14.287 + getNotifier(Edge()).clear();
14.288 + getNotifier(Node()).clear();
14.289 + }
14.290 + };
14.291 +
14.292 + template <typename Base>
14.293 + class UGraphBaseExtender : public Base {
14.294 +
14.295 + public:
14.296 +
14.297 + typedef Base Parent;
14.298 typedef typename Parent::Edge UEdge;
14.299 typedef typename Parent::Node Node;
14.300
14.301 + typedef True UndirectedTag;
14.302 +
14.303 class Edge : public UEdge {
14.304 - friend class UGraphExtender;
14.305 + friend class UGraphBaseExtender;
14.306
14.307 protected:
14.308 - // FIXME: Marci use opposite logic in his graph adaptors. It would
14.309 - // be reasonable to syncronize...
14.310 bool forward;
14.311
14.312 Edge(const UEdge &ue, bool _forward) :
14.313 @@ -101,16 +359,7 @@
14.314 };
14.315
14.316
14.317 - /// \brief Edge of opposite direction.
14.318 - ///
14.319 - /// Returns the Edge of opposite direction.
14.320 - Edge oppositeEdge(const Edge &e) const {
14.321 - return Edge(e,!e.forward);
14.322 - }
14.323
14.324 - public:
14.325 - /// \todo Shouldn't the "source" of an undirected edge be called "aNode"
14.326 - /// or something???
14.327 using Parent::source;
14.328
14.329 /// Source of the given Edge.
14.330 @@ -118,8 +367,6 @@
14.331 return e.forward ? Parent::source(e) : Parent::target(e);
14.332 }
14.333
14.334 - /// \todo Shouldn't the "target" of an undirected edge be called "bNode"
14.335 - /// or something???
14.336 using Parent::target;
14.337
14.338 /// Target of the given Edge.
14.339 @@ -127,24 +374,6 @@
14.340 return e.forward ? Parent::target(e) : Parent::source(e);
14.341 }
14.342
14.343 - Node oppositeNode(const Node &n, const UEdge &e) const {
14.344 - if( n == Parent::source(e))
14.345 - return Parent::target(e);
14.346 - else if( n == Parent::target(e))
14.347 - return Parent::source(e);
14.348 - else
14.349 - return INVALID;
14.350 - }
14.351 -
14.352 - /// \brief Directed edge from an undirected edge and a source node.
14.353 - ///
14.354 - /// Returns a (directed) Edge corresponding to the specified UEdge
14.355 - /// and source Node.
14.356 - ///
14.357 - Edge direct(const UEdge &ue, const Node &s) const {
14.358 - return Edge(ue, s == source(ue));
14.359 - }
14.360 -
14.361 /// \brief Directed edge from an undirected edge.
14.362 ///
14.363 /// Returns a directed edge corresponding to the specified UEdge.
14.364 @@ -163,12 +392,13 @@
14.365
14.366
14.367 using Parent::first;
14.368 + using Parent::next;
14.369 +
14.370 void first(Edge &e) const {
14.371 Parent::first(e);
14.372 e.forward=true;
14.373 }
14.374
14.375 - using Parent::next;
14.376 void next(Edge &e) const {
14.377 if( e.forward ) {
14.378 e.forward = false;
14.379 @@ -179,8 +409,6 @@
14.380 }
14.381 }
14.382
14.383 - public:
14.384 -
14.385 void firstOut(Edge &e, const Node &n) const {
14.386 Parent::firstIn(e,n);
14.387 if( UEdge(e) != INVALID ) {
14.388 @@ -229,21 +457,6 @@
14.389 }
14.390 }
14.391
14.392 - void firstInc(UEdge &e, const Node &n) const {
14.393 - Parent::firstOut(e, n);
14.394 - if (e != INVALID) return;
14.395 - Parent::firstIn(e, n);
14.396 - }
14.397 - void nextInc(UEdge &e, const Node &n) const {
14.398 - if (Parent::source(e) == n) {
14.399 - Parent::nextOut(e);
14.400 - if (e != INVALID) return;
14.401 - Parent::firstIn(e, n);
14.402 - } else {
14.403 - Parent::nextIn(e);
14.404 - }
14.405 - }
14.406 -
14.407 void firstInc(UEdge &e, bool &d, const Node &n) const {
14.408 d = true;
14.409 Parent::firstOut(e, n);
14.410 @@ -251,6 +464,7 @@
14.411 d = false;
14.412 Parent::firstIn(e, n);
14.413 }
14.414 +
14.415 void nextInc(UEdge &e, bool &d) const {
14.416 if (d) {
14.417 Node s = Parent::source(e);
14.418 @@ -263,14 +477,17 @@
14.419 }
14.420 }
14.421
14.422 - // Miscellaneous stuff:
14.423 + Node nodeFromId(int id) const {
14.424 + return Parent::nodeFromId(id);
14.425 + }
14.426
14.427 - /// \todo these methods (id, maxEdgeId) should be moved into separate
14.428 - /// Extender
14.429 + Edge edgeFromId(int id) const {
14.430 + return direct(Parent::edgeFromId(id >> 1), bool(id & 1));
14.431 + }
14.432
14.433 - // using Parent::id;
14.434 - // Using "using" is not a good idea, cause it could be that there is
14.435 - // no "id" in Parent...
14.436 + UEdge uEdgeFromId(int id) const {
14.437 + return Parent::edgeFromId(id >> 1);
14.438 + }
14.439
14.440 int id(const Node &n) const {
14.441 return Parent::id(n);
14.442 @@ -296,16 +513,6 @@
14.443 return Parent::maxEdgeId();
14.444 }
14.445
14.446 - int maxId(Node) const {
14.447 - return maxNodeId();
14.448 - }
14.449 -
14.450 - int maxId(Edge) const {
14.451 - return maxEdgeId();
14.452 - }
14.453 - int maxId(UEdge) const {
14.454 - return maxUEdgeId();
14.455 - }
14.456
14.457 int edgeNum() const {
14.458 return 2 * Parent::edgeNum();
14.459 @@ -315,31 +522,6 @@
14.460 return Parent::edgeNum();
14.461 }
14.462
14.463 - Node nodeFromId(int id) const {
14.464 - return Parent::nodeFromId(id);
14.465 - }
14.466 -
14.467 - Edge edgeFromId(int id) const {
14.468 - return direct(Parent::edgeFromId(id >> 1), bool(id & 1));
14.469 - }
14.470 -
14.471 - UEdge uEdgeFromId(int id) const {
14.472 - return Parent::edgeFromId(id >> 1);
14.473 - }
14.474 -
14.475 - Node fromId(int id, Node) const {
14.476 - return nodeFromId(id);
14.477 - }
14.478 -
14.479 - Edge fromId(int id, Edge) const {
14.480 - return edgeFromId(id);
14.481 - }
14.482 -
14.483 - UEdge fromId(int id, UEdge) const {
14.484 - return uEdgeFromId(id);
14.485 - }
14.486 -
14.487 -
14.488 Edge findEdge(Node source, Node target, Edge prev) const {
14.489 if (prev == INVALID) {
14.490 UEdge edge = Parent::findEdge(source, target);
14.491 @@ -375,24 +557,486 @@
14.492 }
14.493 return INVALID;
14.494 }
14.495 + };
14.496 +
14.497 +
14.498 + template <typename Base>
14.499 + class UGraphExtender : public Base {
14.500 + public:
14.501 +
14.502 + typedef Base Parent;
14.503 + typedef UGraphExtender Graph;
14.504 +
14.505 + typedef typename Parent::Node Node;
14.506 + typedef typename Parent::Edge Edge;
14.507 + typedef typename Parent::UEdge UEdge;
14.508 +
14.509 + // UGraph extension
14.510 +
14.511 + int maxId(Node) const {
14.512 + return Parent::maxNodeId();
14.513 + }
14.514 +
14.515 + int maxId(Edge) const {
14.516 + return Parent::maxEdgeId();
14.517 + }
14.518 +
14.519 + int maxId(UEdge) const {
14.520 + return Parent::maxUEdgeId();
14.521 + }
14.522 +
14.523 + Node fromId(int id, Node) const {
14.524 + return Parent::nodeFromId(id);
14.525 + }
14.526 +
14.527 + Edge fromId(int id, Edge) const {
14.528 + return Parent::edgeFromId(id);
14.529 + }
14.530 +
14.531 + UEdge fromId(int id, UEdge) const {
14.532 + return Parent::uEdgeFromId(id);
14.533 + }
14.534 +
14.535 + Node oppositeNode(const Node &n, const UEdge &e) const {
14.536 + if( n == Parent::source(e))
14.537 + return Parent::target(e);
14.538 + else if( n == Parent::target(e))
14.539 + return Parent::source(e);
14.540 + else
14.541 + return INVALID;
14.542 + }
14.543 +
14.544 + Edge oppositeEdge(const Edge &e) const {
14.545 + return Parent::direct(e, !Parent::direction(e));
14.546 + }
14.547 +
14.548 + using Parent::direct;
14.549 + Edge direct(const UEdge &ue, const Node &s) const {
14.550 + return Parent::direct(ue, Parent::source(ue) == s);
14.551 + }
14.552 +
14.553 + // Alterable extension
14.554 +
14.555 + typedef AlterationNotifier<Node> NodeNotifier;
14.556 + typedef AlterationNotifier<Edge> EdgeNotifier;
14.557 + typedef AlterationNotifier<UEdge> UEdgeNotifier;
14.558 +
14.559 +
14.560 + protected:
14.561 +
14.562 + mutable NodeNotifier node_notifier;
14.563 + mutable EdgeNotifier edge_notifier;
14.564 + mutable UEdgeNotifier uedge_notifier;
14.565 +
14.566 + public:
14.567 +
14.568 + NodeNotifier& getNotifier(Node) const {
14.569 + return node_notifier;
14.570 + }
14.571 +
14.572 + EdgeNotifier& getNotifier(Edge) const {
14.573 + return edge_notifier;
14.574 + }
14.575 +
14.576 + UEdgeNotifier& getNotifier(UEdge) const {
14.577 + return uedge_notifier;
14.578 + }
14.579 +
14.580 +
14.581 +
14.582 + class NodeIt : public Node {
14.583 + const Graph* graph;
14.584 + public:
14.585 +
14.586 + NodeIt() {}
14.587 +
14.588 + NodeIt(Invalid i) : Node(i) { }
14.589 +
14.590 + explicit NodeIt(const Graph& _graph) : graph(&_graph) {
14.591 + _graph.first(*static_cast<Node*>(this));
14.592 + }
14.593 +
14.594 + NodeIt(const Graph& _graph, const Node& node)
14.595 + : Node(node), graph(&_graph) {}
14.596 +
14.597 + NodeIt& operator++() {
14.598 + graph->next(*this);
14.599 + return *this;
14.600 + }
14.601 +
14.602 + };
14.603 +
14.604 +
14.605 + class EdgeIt : public Edge {
14.606 + const Graph* graph;
14.607 + public:
14.608 +
14.609 + EdgeIt() { }
14.610 +
14.611 + EdgeIt(Invalid i) : Edge(i) { }
14.612 +
14.613 + explicit EdgeIt(const Graph& _graph) : graph(&_graph) {
14.614 + _graph.first(*static_cast<Edge*>(this));
14.615 + }
14.616 +
14.617 + EdgeIt(const Graph& _graph, const Edge& e) :
14.618 + Edge(e), graph(&_graph) { }
14.619 +
14.620 + EdgeIt& operator++() {
14.621 + graph->next(*this);
14.622 + return *this;
14.623 + }
14.624 +
14.625 + };
14.626 +
14.627 +
14.628 + class OutEdgeIt : public Edge {
14.629 + const Graph* graph;
14.630 + public:
14.631 +
14.632 + OutEdgeIt() { }
14.633 +
14.634 + OutEdgeIt(Invalid i) : Edge(i) { }
14.635 +
14.636 + OutEdgeIt(const Graph& _graph, const Node& node)
14.637 + : graph(&_graph) {
14.638 + _graph.firstOut(*this, node);
14.639 + }
14.640 +
14.641 + OutEdgeIt(const Graph& _graph, const Edge& edge)
14.642 + : Edge(edge), graph(&_graph) {}
14.643 +
14.644 + OutEdgeIt& operator++() {
14.645 + graph->nextOut(*this);
14.646 + return *this;
14.647 + }
14.648 +
14.649 + };
14.650 +
14.651 +
14.652 + class InEdgeIt : public Edge {
14.653 + const Graph* graph;
14.654 + public:
14.655 +
14.656 + InEdgeIt() { }
14.657 +
14.658 + InEdgeIt(Invalid i) : Edge(i) { }
14.659 +
14.660 + InEdgeIt(const Graph& _graph, const Node& node)
14.661 + : graph(&_graph) {
14.662 + _graph.firstIn(*this, node);
14.663 + }
14.664 +
14.665 + InEdgeIt(const Graph& _graph, const Edge& edge) :
14.666 + Edge(edge), graph(&_graph) {}
14.667 +
14.668 + InEdgeIt& operator++() {
14.669 + graph->nextIn(*this);
14.670 + return *this;
14.671 + }
14.672 +
14.673 + };
14.674 +
14.675 +
14.676 + class UEdgeIt : public Parent::UEdge {
14.677 + const Graph* graph;
14.678 + public:
14.679 +
14.680 + UEdgeIt() { }
14.681 +
14.682 + UEdgeIt(Invalid i) : UEdge(i) { }
14.683 +
14.684 + explicit UEdgeIt(const Graph& _graph) : graph(&_graph) {
14.685 + _graph.first(*static_cast<UEdge*>(this));
14.686 + }
14.687 +
14.688 + UEdgeIt(const Graph& _graph, const UEdge& e) :
14.689 + UEdge(e), graph(&_graph) { }
14.690 +
14.691 + UEdgeIt& operator++() {
14.692 + graph->next(*this);
14.693 + return *this;
14.694 + }
14.695 +
14.696 + };
14.697 +
14.698 + class IncEdgeIt : public Parent::UEdge {
14.699 + friend class UGraphExtender;
14.700 + const Graph* graph;
14.701 + bool direction;
14.702 + public:
14.703 +
14.704 + IncEdgeIt() { }
14.705 +
14.706 + IncEdgeIt(Invalid i) : UEdge(i), direction(false) { }
14.707 +
14.708 + IncEdgeIt(const Graph& _graph, const Node &n) : graph(&_graph) {
14.709 + _graph.firstInc(*this, direction, n);
14.710 + }
14.711 +
14.712 + IncEdgeIt(const Graph& _graph, const UEdge &ue, const Node &n)
14.713 + : graph(&_graph), UEdge(ue) {
14.714 + direction = (_graph.source(ue) == n);
14.715 + }
14.716 +
14.717 + IncEdgeIt& operator++() {
14.718 + graph->nextInc(*this, direction);
14.719 + return *this;
14.720 + }
14.721 + };
14.722 +
14.723 + /// \brief Base node of the iterator
14.724 + ///
14.725 + /// Returns the base node (ie. the source in this case) of the iterator
14.726 + Node baseNode(const OutEdgeIt &e) const {
14.727 + return Parent::source((Edge)e);
14.728 + }
14.729 + /// \brief Running node of the iterator
14.730 + ///
14.731 + /// Returns the running node (ie. the target in this case) of the
14.732 + /// iterator
14.733 + Node runningNode(const OutEdgeIt &e) const {
14.734 + return Parent::target((Edge)e);
14.735 + }
14.736 +
14.737 + /// \brief Base node of the iterator
14.738 + ///
14.739 + /// Returns the base node (ie. the target in this case) of the iterator
14.740 + Node baseNode(const InEdgeIt &e) const {
14.741 + return Parent::target((Edge)e);
14.742 + }
14.743 + /// \brief Running node of the iterator
14.744 + ///
14.745 + /// Returns the running node (ie. the source in this case) of the
14.746 + /// iterator
14.747 + Node runningNode(const InEdgeIt &e) const {
14.748 + return Parent::source((Edge)e);
14.749 + }
14.750 +
14.751 + /// Base node of the iterator
14.752 + ///
14.753 + /// Returns the base node of the iterator
14.754 + Node baseNode(const IncEdgeIt &e) const {
14.755 + return e.direction ? source(e) : target(e);
14.756 + }
14.757 + /// Running node of the iterator
14.758 + ///
14.759 + /// Returns the running node of the iterator
14.760 + Node runningNode(const IncEdgeIt &e) const {
14.761 + return e.direction ? target(e) : source(e);
14.762 + }
14.763 +
14.764 + // Mappable extension
14.765 +
14.766 + template <typename _Value>
14.767 + class NodeMap
14.768 + : public IterableMapExtender<DefaultMap<Graph, Node, _Value> > {
14.769 + public:
14.770 + typedef UGraphExtender Graph;
14.771 + typedef IterableMapExtender<DefaultMap<Graph, Node, _Value> > Parent;
14.772 +
14.773 + NodeMap(const Graph& _g)
14.774 + : Parent(_g) {}
14.775 + NodeMap(const Graph& _g, const _Value& _v)
14.776 + : Parent(_g, _v) {}
14.777 +
14.778 + NodeMap& operator=(const NodeMap& cmap) {
14.779 + return operator=<NodeMap>(cmap);
14.780 + }
14.781 +
14.782 +
14.783 + /// \brief Template assign operator.
14.784 + ///
14.785 + /// The given parameter should be conform to the ReadMap
14.786 + /// concecpt and could be indiced by the current item set of
14.787 + /// the NodeMap. In this case the value for each item
14.788 + /// is assigned by the value of the given ReadMap.
14.789 + template <typename CMap>
14.790 + NodeMap& operator=(const CMap& cmap) {
14.791 + checkConcept<concept::ReadMap<Node, _Value>, CMap>();
14.792 + const typename Parent::Graph* graph = Parent::getGraph();
14.793 + Node it;
14.794 + for (graph->first(it); it != INVALID; graph->next(it)) {
14.795 + Parent::set(it, cmap[it]);
14.796 + }
14.797 + return *this;
14.798 + }
14.799 +
14.800 + };
14.801 +
14.802 + template <typename _Value>
14.803 + class EdgeMap
14.804 + : public IterableMapExtender<DefaultMap<Graph, Edge, _Value> > {
14.805 + public:
14.806 + typedef UGraphExtender Graph;
14.807 + typedef IterableMapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
14.808 +
14.809 + EdgeMap(const Graph& _g)
14.810 + : Parent(_g) {}
14.811 + EdgeMap(const Graph& _g, const _Value& _v)
14.812 + : Parent(_g, _v) {}
14.813 +
14.814 + EdgeMap& operator=(const EdgeMap& cmap) {
14.815 + return operator=<EdgeMap>(cmap);
14.816 + }
14.817 +
14.818 + template <typename CMap>
14.819 + EdgeMap& operator=(const CMap& cmap) {
14.820 + checkConcept<concept::ReadMap<Edge, _Value>, CMap>();
14.821 + const typename Parent::Graph* graph = Parent::getGraph();
14.822 + Edge it;
14.823 + for (graph->first(it); it != INVALID; graph->next(it)) {
14.824 + Parent::set(it, cmap[it]);
14.825 + }
14.826 + return *this;
14.827 + }
14.828 + };
14.829 +
14.830 +
14.831 + template <typename _Value>
14.832 + class UEdgeMap
14.833 + : public IterableMapExtender<DefaultMap<Graph, UEdge, _Value> > {
14.834 + public:
14.835 + typedef UGraphExtender Graph;
14.836 + typedef IterableMapExtender<DefaultMap<Graph, UEdge, _Value> > Parent;
14.837 +
14.838 + UEdgeMap(const Graph& _g)
14.839 + : Parent(_g) {}
14.840 + UEdgeMap(const Graph& _g, const _Value& _v)
14.841 + : Parent(_g, _v) {}
14.842 +
14.843 + UEdgeMap& operator=(const UEdgeMap& cmap) {
14.844 + return operator=<UEdgeMap>(cmap);
14.845 + }
14.846 +
14.847 + template <typename CMap>
14.848 + UEdgeMap& operator=(const CMap& cmap) {
14.849 + checkConcept<concept::ReadMap<UEdge, _Value>, CMap>();
14.850 + const typename Parent::Graph* graph = Parent::getGraph();
14.851 + UEdge it;
14.852 + for (graph->first(it); it != INVALID; graph->next(it)) {
14.853 + Parent::set(it, cmap[it]);
14.854 + }
14.855 + return *this;
14.856 + }
14.857 + };
14.858 +
14.859 + // Alteration extension
14.860 +
14.861 + Node addNode() {
14.862 + Node node = Parent::addNode();
14.863 + getNotifier(Node()).add(node);
14.864 + return node;
14.865 + }
14.866 +
14.867 + UEdge addEdge(const Node& from, const Node& to) {
14.868 + UEdge uedge = Parent::addEdge(from, to);
14.869 + getNotifier(UEdge()).add(uedge);
14.870 + getNotifier(Edge()).add(Parent::direct(uedge, true));
14.871 + getNotifier(Edge()).add(Parent::direct(uedge, false));
14.872 + return uedge;
14.873 + }
14.874 +
14.875 + void clear() {
14.876 + getNotifier(Edge()).clear();
14.877 + getNotifier(UEdge()).clear();
14.878 + getNotifier(Node()).clear();
14.879 + Parent::clear();
14.880 + }
14.881 +
14.882 + void erase(const Node& node) {
14.883 + Edge edge;
14.884 + Parent::firstOut(edge, node);
14.885 + while (edge != INVALID ) {
14.886 + erase(edge);
14.887 + Parent::firstOut(edge, node);
14.888 + }
14.889 +
14.890 + Parent::firstIn(edge, node);
14.891 + while (edge != INVALID ) {
14.892 + erase(edge);
14.893 + Parent::firstIn(edge, node);
14.894 + }
14.895 +
14.896 + getNotifier(Node()).erase(node);
14.897 + Parent::erase(node);
14.898 + }
14.899 +
14.900 + void erase(const UEdge& uedge) {
14.901 + getNotifier(Edge()).erase(Parent::direct(uedge, true));
14.902 + getNotifier(Edge()).erase(Parent::direct(uedge, false));
14.903 + getNotifier(UEdge()).erase(uedge);
14.904 + Parent::erase(uedge);
14.905 + }
14.906 +
14.907 + ~UGraphExtender() {
14.908 + getNotifier(Edge()).clear();
14.909 + getNotifier(UEdge()).clear();
14.910 + getNotifier(Node()).clear();
14.911 + }
14.912
14.913 };
14.914
14.915
14.916 - template <typename _Base>
14.917 - class BpUGraphExtender : public _Base {
14.918 + template <typename Base>
14.919 + class BpUGraphBaseExtender : public Base {
14.920 public:
14.921 - typedef _Base Parent;
14.922 - typedef BpUGraphExtender Graph;
14.923 + typedef Base Parent;
14.924 + typedef BpUGraphBaseExtender Graph;
14.925
14.926 typedef typename Parent::Node Node;
14.927 typedef typename Parent::Edge UEdge;
14.928
14.929 +
14.930 using Parent::first;
14.931 using Parent::next;
14.932
14.933 using Parent::id;
14.934
14.935 + class ANode : public Node {
14.936 + friend class BpUGraphBaseExtender;
14.937 + public:
14.938 + ANode() {}
14.939 + ANode(const Node& node) : Node(node) {
14.940 + LEMON_ASSERT(Parent::aNode(node) || node == INVALID,
14.941 + typename Parent::NodeSetError());
14.942 + }
14.943 + ANode(Invalid) : Node(INVALID) {}
14.944 + };
14.945 +
14.946 + void first(ANode& node) const {
14.947 + Parent::firstANode(static_cast<Node&>(node));
14.948 + }
14.949 + void next(ANode& node) const {
14.950 + Parent::nextANode(static_cast<Node&>(node));
14.951 + }
14.952 +
14.953 + int id(const ANode& node) const {
14.954 + return Parent::aNodeId(node);
14.955 + }
14.956 +
14.957 + class BNode : public Node {
14.958 + friend class BpUGraphBaseExtender;
14.959 + public:
14.960 + BNode() {}
14.961 + BNode(const Node& node) : Node(node) {
14.962 + LEMON_ASSERT(Parent::bNode(node) || node == INVALID,
14.963 + typename Parent::NodeSetError());
14.964 + }
14.965 + BNode(Invalid) : Node(INVALID) {}
14.966 + };
14.967 +
14.968 + void first(BNode& node) const {
14.969 + Parent::firstBNode(static_cast<Node&>(node));
14.970 + }
14.971 + void next(BNode& node) const {
14.972 + Parent::nextBNode(static_cast<Node&>(node));
14.973 + }
14.974 +
14.975 + int id(const BNode& node) const {
14.976 + return Parent::aNodeId(node);
14.977 + }
14.978 +
14.979 Node source(const UEdge& edge) const {
14.980 return aNode(edge);
14.981 }
14.982 @@ -427,7 +1071,7 @@
14.983 }
14.984
14.985 class Edge : public UEdge {
14.986 - friend class BpUGraphExtender;
14.987 + friend class BpUGraphBaseExtender;
14.988 protected:
14.989 bool forward;
14.990
14.991 @@ -504,27 +1148,6 @@
14.992 return edge.forward ? Parent::bNode(edge) : Parent::aNode(edge);
14.993 }
14.994
14.995 - bool direction(const Edge& edge) const {
14.996 - return edge.forward;
14.997 - }
14.998 -
14.999 - Edge direct(const UEdge& edge, const Node& node) const {
14.1000 - return Edge(edge, node == Parent::source(edge));
14.1001 - }
14.1002 -
14.1003 - Edge direct(const UEdge& edge, bool direction) const {
14.1004 - return Edge(edge, direction);
14.1005 - }
14.1006 -
14.1007 - Node oppositeNode(const UEdge& edge, const Node& node) const {
14.1008 - return source(edge) == node ?
14.1009 - target(edge) : source(edge);
14.1010 - }
14.1011 -
14.1012 - Edge oppositeEdge(const Edge& edge) const {
14.1013 - return Edge(edge, !edge.forward);
14.1014 - }
14.1015 -
14.1016 int id(const Edge& edge) const {
14.1017 return (Parent::id(edge) << 1) + (edge.forward ? 0 : 1);
14.1018 }
14.1019 @@ -535,50 +1158,40 @@
14.1020 return (Parent::maxId(UEdge()) << 1) + 1;
14.1021 }
14.1022
14.1023 - class ANode : public Node {
14.1024 - friend class BpUGraphExtender;
14.1025 - public:
14.1026 - ANode() {}
14.1027 - ANode(const Node& node) : Node(node) {
14.1028 - LEMON_ASSERT(Parent::aNode(node) || node == INVALID,
14.1029 - typename Parent::NodeSetError());
14.1030 - }
14.1031 - ANode(Invalid) : Node(INVALID) {}
14.1032 - };
14.1033 -
14.1034 - void first(ANode& node) const {
14.1035 - Parent::firstANode(static_cast<Node&>(node));
14.1036 - }
14.1037 - void next(ANode& node) const {
14.1038 - Parent::nextANode(static_cast<Node&>(node));
14.1039 + bool direction(const Edge& edge) const {
14.1040 + return edge.forward;
14.1041 }
14.1042
14.1043 - int id(const ANode& node) const {
14.1044 - return Parent::aNodeId(node);
14.1045 + Edge direct(const UEdge& edge, bool direction) const {
14.1046 + return Edge(edge, direction);
14.1047 + }
14.1048 + };
14.1049 +
14.1050 + template <typename Base>
14.1051 + class BpUGraphExtender : public Base {
14.1052 + public:
14.1053 + typedef Base Parent;
14.1054 + typedef BpUGraphExtender Graph;
14.1055 +
14.1056 + typedef typename Parent::Node Node;
14.1057 + typedef typename Parent::BNode BNode;
14.1058 + typedef typename Parent::ANode ANode;
14.1059 + typedef typename Parent::Edge Edge;
14.1060 + typedef typename Parent::UEdge UEdge;
14.1061 +
14.1062 + Node oppositeNode(const UEdge& edge, const Node& node) const {
14.1063 + return source(edge) == node ?
14.1064 + target(edge) : source(edge);
14.1065 }
14.1066
14.1067 - class BNode : public Node {
14.1068 - friend class BpUGraphExtender;
14.1069 - public:
14.1070 - BNode() {}
14.1071 - BNode(const Node& node) : Node(node) {
14.1072 - LEMON_ASSERT(Parent::bNode(node) || node == INVALID,
14.1073 - typename Parent::NodeSetError());
14.1074 - }
14.1075 - BNode(Invalid) : Node(INVALID) {}
14.1076 - };
14.1077 -
14.1078 - void first(BNode& node) const {
14.1079 - Parent::firstBNode(static_cast<Node&>(node));
14.1080 - }
14.1081 - void next(BNode& node) const {
14.1082 - Parent::nextBNode(static_cast<Node&>(node));
14.1083 - }
14.1084 -
14.1085 - int id(const BNode& node) const {
14.1086 - return Parent::aNodeId(node);
14.1087 + using Parent::direct;
14.1088 + Edge direct(const UEdge& edge, const Node& node) const {
14.1089 + return Edge(edge, node == Parent::source(edge));
14.1090 }
14.1091
14.1092 + Edge oppositeEdge(const Edge& edge) const {
14.1093 + return Parent::direct(edge, !Parent::direction(edge));
14.1094 + }
14.1095
14.1096
14.1097 int maxId(Node) const {
14.1098 @@ -591,10 +1204,10 @@
14.1099 return Parent::maxANodeId();
14.1100 }
14.1101 int maxId(Edge) const {
14.1102 - return maxEdgeId();
14.1103 + return Parent::maxEdgeId();
14.1104 }
14.1105 int maxId(UEdge) const {
14.1106 - return maxUEdgeId();
14.1107 + return Parent::maxUEdgeId();
14.1108 }
14.1109
14.1110
14.1111 @@ -608,12 +1221,605 @@
14.1112 return Parent::fromBNodeId(id);
14.1113 }
14.1114 Edge fromId(int id, Edge) const {
14.1115 - return edgeFromId(id);
14.1116 + return Parent::edgeFromId(id);
14.1117 }
14.1118 UEdge fromId(int id, UEdge) const {
14.1119 - return uEdgeFromId(id);
14.1120 + return Parent::uEdgeFromId(id);
14.1121 + }
14.1122 +
14.1123 + typedef AlterationNotifier<Node> NodeNotifier;
14.1124 + typedef AlterationNotifier<BNode> BNodeNotifier;
14.1125 + typedef AlterationNotifier<ANode> ANodeNotifier;
14.1126 + typedef AlterationNotifier<Edge> EdgeNotifier;
14.1127 + typedef AlterationNotifier<UEdge> UEdgeNotifier;
14.1128 +
14.1129 + protected:
14.1130 +
14.1131 + mutable NodeNotifier nodeNotifier;
14.1132 + mutable BNodeNotifier bNodeNotifier;
14.1133 + mutable ANodeNotifier aNodeNotifier;
14.1134 + mutable EdgeNotifier edgeNotifier;
14.1135 + mutable UEdgeNotifier uEdgeNotifier;
14.1136 +
14.1137 + public:
14.1138 +
14.1139 + NodeNotifier& getNotifier(Node) const {
14.1140 + return nodeNotifier;
14.1141 }
14.1142
14.1143 + BNodeNotifier& getNotifier(BNode) const {
14.1144 + return bNodeNotifier;
14.1145 + }
14.1146 +
14.1147 + ANodeNotifier& getNotifier(ANode) const {
14.1148 + return aNodeNotifier;
14.1149 + }
14.1150 +
14.1151 + EdgeNotifier& getNotifier(Edge) const {
14.1152 + return edgeNotifier;
14.1153 + }
14.1154 +
14.1155 + UEdgeNotifier& getNotifier(UEdge) const {
14.1156 + return uEdgeNotifier;
14.1157 + }
14.1158 +
14.1159 + ~BpUGraphExtender() {
14.1160 + getNotifier(UEdge()).clear();
14.1161 + getNotifier(Edge()).clear();
14.1162 + getNotifier(ANode()).clear();
14.1163 + getNotifier(BNode()).clear();
14.1164 + getNotifier(Node()).clear();
14.1165 + }
14.1166 +
14.1167 +
14.1168 + class NodeIt : public Node {
14.1169 + const Graph* graph;
14.1170 + public:
14.1171 +
14.1172 + NodeIt() { }
14.1173 +
14.1174 + NodeIt(Invalid i) : Node(INVALID) { }
14.1175 +
14.1176 + explicit NodeIt(const Graph& _graph) : graph(&_graph) {
14.1177 + graph->first(static_cast<Node&>(*this));
14.1178 + }
14.1179 +
14.1180 + NodeIt(const Graph& _graph, const Node& node)
14.1181 + : Node(node), graph(&_graph) { }
14.1182 +
14.1183 + NodeIt& operator++() {
14.1184 + graph->next(*this);
14.1185 + return *this;
14.1186 + }
14.1187 +
14.1188 + };
14.1189 +
14.1190 + class ANodeIt : public Node {
14.1191 + friend class BpUGraphExtender;
14.1192 + const Graph* graph;
14.1193 + public:
14.1194 +
14.1195 + ANodeIt() { }
14.1196 +
14.1197 + ANodeIt(Invalid i) : Node(INVALID) { }
14.1198 +
14.1199 + explicit ANodeIt(const Graph& _graph) : graph(&_graph) {
14.1200 + graph->firstANode(static_cast<Node&>(*this));
14.1201 + }
14.1202 +
14.1203 + ANodeIt(const Graph& _graph, const Node& node)
14.1204 + : Node(node), graph(&_graph) {}
14.1205 +
14.1206 + ANodeIt& operator++() {
14.1207 + graph->nextANode(*this);
14.1208 + return *this;
14.1209 + }
14.1210 + };
14.1211 +
14.1212 + class BNodeIt : public Node {
14.1213 + friend class BpUGraphExtender;
14.1214 + const Graph* graph;
14.1215 + public:
14.1216 +
14.1217 + BNodeIt() { }
14.1218 +
14.1219 + BNodeIt(Invalid i) : Node(INVALID) { }
14.1220 +
14.1221 + explicit BNodeIt(const Graph& _graph) : graph(&_graph) {
14.1222 + graph->firstBNode(static_cast<Node&>(*this));
14.1223 + }
14.1224 +
14.1225 + BNodeIt(const Graph& _graph, const Node& node)
14.1226 + : Node(node), graph(&_graph) {}
14.1227 +
14.1228 + BNodeIt& operator++() {
14.1229 + graph->nextBNode(*this);
14.1230 + return *this;
14.1231 + }
14.1232 + };
14.1233 +
14.1234 + class EdgeIt : public Edge {
14.1235 + friend class BpUGraphExtender;
14.1236 + const Graph* graph;
14.1237 + public:
14.1238 +
14.1239 + EdgeIt() { }
14.1240 +
14.1241 + EdgeIt(Invalid i) : Edge(INVALID) { }
14.1242 +
14.1243 + explicit EdgeIt(const Graph& _graph) : graph(&_graph) {
14.1244 + graph->first(static_cast<Edge&>(*this));
14.1245 + }
14.1246 +
14.1247 + EdgeIt(const Graph& _graph, const Edge& edge)
14.1248 + : Edge(edge), graph(&_graph) { }
14.1249 +
14.1250 + EdgeIt& operator++() {
14.1251 + graph->next(*this);
14.1252 + return *this;
14.1253 + }
14.1254 +
14.1255 + };
14.1256 +
14.1257 + class UEdgeIt : public UEdge {
14.1258 + friend class BpUGraphExtender;
14.1259 + const Graph* graph;
14.1260 + public:
14.1261 +
14.1262 + UEdgeIt() { }
14.1263 +
14.1264 + UEdgeIt(Invalid i) : UEdge(INVALID) { }
14.1265 +
14.1266 + explicit UEdgeIt(const Graph& _graph) : graph(&_graph) {
14.1267 + graph->first(static_cast<UEdge&>(*this));
14.1268 + }
14.1269 +
14.1270 + UEdgeIt(const Graph& _graph, const UEdge& edge)
14.1271 + : UEdge(edge), graph(&_graph) { }
14.1272 +
14.1273 + UEdgeIt& operator++() {
14.1274 + graph->next(*this);
14.1275 + return *this;
14.1276 + }
14.1277 + };
14.1278 +
14.1279 + class OutEdgeIt : public Edge {
14.1280 + friend class BpUGraphExtender;
14.1281 + const Graph* graph;
14.1282 + public:
14.1283 +
14.1284 + OutEdgeIt() { }
14.1285 +
14.1286 + OutEdgeIt(Invalid i) : Edge(i) { }
14.1287 +
14.1288 + OutEdgeIt(const Graph& _graph, const Node& node)
14.1289 + : graph(&_graph) {
14.1290 + graph->firstOut(*this, node);
14.1291 + }
14.1292 +
14.1293 + OutEdgeIt(const Graph& _graph, const Edge& edge)
14.1294 + : Edge(edge), graph(&_graph) {}
14.1295 +
14.1296 + OutEdgeIt& operator++() {
14.1297 + graph->nextOut(*this);
14.1298 + return *this;
14.1299 + }
14.1300 +
14.1301 + };
14.1302 +
14.1303 +
14.1304 + class InEdgeIt : public Edge {
14.1305 + friend class BpUGraphExtender;
14.1306 + const Graph* graph;
14.1307 + public:
14.1308 +
14.1309 + InEdgeIt() { }
14.1310 +
14.1311 + InEdgeIt(Invalid i) : Edge(i) { }
14.1312 +
14.1313 + InEdgeIt(const Graph& _graph, const Node& node)
14.1314 + : graph(&_graph) {
14.1315 + graph->firstIn(*this, node);
14.1316 + }
14.1317 +
14.1318 + InEdgeIt(const Graph& _graph, const Edge& edge) :
14.1319 + Edge(edge), graph(&_graph) {}
14.1320 +
14.1321 + InEdgeIt& operator++() {
14.1322 + graph->nextIn(*this);
14.1323 + return *this;
14.1324 + }
14.1325 +
14.1326 + };
14.1327 +
14.1328 + /// \brief Base node of the iterator
14.1329 + ///
14.1330 + /// Returns the base node (ie. the source in this case) of the iterator
14.1331 + Node baseNode(const OutEdgeIt &e) const {
14.1332 + return Parent::source((Edge&)e);
14.1333 + }
14.1334 + /// \brief Running node of the iterator
14.1335 + ///
14.1336 + /// Returns the running node (ie. the target in this case) of the
14.1337 + /// iterator
14.1338 + Node runningNode(const OutEdgeIt &e) const {
14.1339 + return Parent::target((Edge&)e);
14.1340 + }
14.1341 +
14.1342 + /// \brief Base node of the iterator
14.1343 + ///
14.1344 + /// Returns the base node (ie. the target in this case) of the iterator
14.1345 + Node baseNode(const InEdgeIt &e) const {
14.1346 + return Parent::target((Edge&)e);
14.1347 + }
14.1348 + /// \brief Running node of the iterator
14.1349 + ///
14.1350 + /// Returns the running node (ie. the source in this case) of the
14.1351 + /// iterator
14.1352 + Node runningNode(const InEdgeIt &e) const {
14.1353 + return Parent::source((Edge&)e);
14.1354 + }
14.1355 +
14.1356 + class IncEdgeIt : public Parent::UEdge {
14.1357 + friend class BpUGraphExtender;
14.1358 + const Graph* graph;
14.1359 + bool direction;
14.1360 + public:
14.1361 +
14.1362 + IncEdgeIt() { }
14.1363 +
14.1364 + IncEdgeIt(Invalid i) : UEdge(i), direction(true) { }
14.1365 +
14.1366 + IncEdgeIt(const Graph& _graph, const Node &n) : graph(&_graph) {
14.1367 + graph->firstInc(*this, direction, n);
14.1368 + }
14.1369 +
14.1370 + IncEdgeIt(const Graph& _graph, const UEdge &ue, const Node &n)
14.1371 + : graph(&_graph), UEdge(ue) {
14.1372 + direction = (graph->source(ue) == n);
14.1373 + }
14.1374 +
14.1375 + IncEdgeIt& operator++() {
14.1376 + graph->nextInc(*this, direction);
14.1377 + return *this;
14.1378 + }
14.1379 + };
14.1380 +
14.1381 +
14.1382 + /// Base node of the iterator
14.1383 + ///
14.1384 + /// Returns the base node of the iterator
14.1385 + Node baseNode(const IncEdgeIt &e) const {
14.1386 + return e.direction ? source(e) : target(e);
14.1387 + }
14.1388 +
14.1389 + /// Running node of the iterator
14.1390 + ///
14.1391 + /// Returns the running node of the iterator
14.1392 + Node runningNode(const IncEdgeIt &e) const {
14.1393 + return e.direction ? target(e) : source(e);
14.1394 + }
14.1395 +
14.1396 + template <typename _Value>
14.1397 + class ANodeMap
14.1398 + : public IterableMapExtender<DefaultMap<Graph, ANode, _Value> > {
14.1399 + public:
14.1400 + typedef BpUGraphExtender Graph;
14.1401 + typedef IterableMapExtender<DefaultMap<Graph, ANode, _Value> >
14.1402 + Parent;
14.1403 +
14.1404 + ANodeMap(const Graph& _g)
14.1405 + : Parent(_g) {}
14.1406 + ANodeMap(const Graph& _g, const _Value& _v)
14.1407 + : Parent(_g, _v) {}
14.1408 +
14.1409 + ANodeMap& operator=(const ANodeMap& cmap) {
14.1410 + return operator=<ANodeMap>(cmap);
14.1411 + }
14.1412 +
14.1413 +
14.1414 + /// \brief Template assign operator.
14.1415 + ///
14.1416 + /// The given parameter should be conform to the ReadMap
14.1417 + /// concept and could be indiced by the current item set of
14.1418 + /// the ANodeMap. In this case the value for each item
14.1419 + /// is assigned by the value of the given ReadMap.
14.1420 + template <typename CMap>
14.1421 + ANodeMap& operator=(const CMap& cmap) {
14.1422 + checkConcept<concept::ReadMap<ANode, _Value>, CMap>();
14.1423 + const typename Parent::Graph* graph = Parent::getGraph();
14.1424 + ANode it;
14.1425 + for (graph->first(it); it != INVALID; graph->next(it)) {
14.1426 + Parent::set(it, cmap[it]);
14.1427 + }
14.1428 + return *this;
14.1429 + }
14.1430 +
14.1431 + };
14.1432 +
14.1433 + template <typename _Value>
14.1434 + class BNodeMap
14.1435 + : public IterableMapExtender<DefaultMap<Graph, BNode, _Value> > {
14.1436 + public:
14.1437 + typedef BpUGraphExtender Graph;
14.1438 + typedef IterableMapExtender<DefaultMap<Graph, BNode, _Value> >
14.1439 + Parent;
14.1440 +
14.1441 + BNodeMap(const Graph& _g)
14.1442 + : Parent(_g) {}
14.1443 + BNodeMap(const Graph& _g, const _Value& _v)
14.1444 + : Parent(_g, _v) {}
14.1445 +
14.1446 + BNodeMap& operator=(const BNodeMap& cmap) {
14.1447 + return operator=<BNodeMap>(cmap);
14.1448 + }
14.1449 +
14.1450 +
14.1451 + /// \brief Template assign operator.
14.1452 + ///
14.1453 + /// The given parameter should be conform to the ReadMap
14.1454 + /// concept and could be indiced by the current item set of
14.1455 + /// the BNodeMap. In this case the value for each item
14.1456 + /// is assigned by the value of the given ReadMap.
14.1457 + template <typename CMap>
14.1458 + BNodeMap& operator=(const CMap& cmap) {
14.1459 + checkConcept<concept::ReadMap<BNode, _Value>, CMap>();
14.1460 + const typename Parent::Graph* graph = Parent::getGraph();
14.1461 + BNode it;
14.1462 + for (graph->first(it); it != INVALID; graph->next(it)) {
14.1463 + Parent::set(it, cmap[it]);
14.1464 + }
14.1465 + return *this;
14.1466 + }
14.1467 +
14.1468 + };
14.1469 +
14.1470 + protected:
14.1471 +
14.1472 + template <typename _Value>
14.1473 + class NodeMapBase : public NodeNotifier::ObserverBase {
14.1474 + public:
14.1475 + typedef BpUGraphExtender Graph;
14.1476 +
14.1477 + typedef Node Key;
14.1478 + typedef _Value Value;
14.1479 +
14.1480 + /// The reference type of the map;
14.1481 + typedef typename BNodeMap<_Value>::Reference Reference;
14.1482 + /// The pointer type of the map;
14.1483 + typedef typename BNodeMap<_Value>::Pointer Pointer;
14.1484 +
14.1485 + /// The const value type of the map.
14.1486 + typedef const Value ConstValue;
14.1487 + /// The const reference type of the map;
14.1488 + typedef typename BNodeMap<_Value>::ConstReference ConstReference;
14.1489 + /// The pointer type of the map;
14.1490 + typedef typename BNodeMap<_Value>::ConstPointer ConstPointer;
14.1491 +
14.1492 + typedef True ReferenceMapTag;
14.1493 +
14.1494 + NodeMapBase(const Graph& _g)
14.1495 + : graph(&_g), bNodeMap(_g), aNodeMap(_g) {
14.1496 + NodeNotifier::ObserverBase::attach(_g.getNotifier(Node()));
14.1497 + }
14.1498 + NodeMapBase(const Graph& _g, const _Value& _v)
14.1499 + : graph(&_g), bNodeMap(_g, _v),
14.1500 + aNodeMap(_g, _v) {
14.1501 + NodeNotifier::ObserverBase::attach(_g.getNotifier(Node()));
14.1502 + }
14.1503 +
14.1504 + virtual ~NodeMapBase() {
14.1505 + if (NodeNotifier::ObserverBase::attached()) {
14.1506 + NodeNotifier::ObserverBase::detach();
14.1507 + }
14.1508 + }
14.1509 +
14.1510 + ConstReference operator[](const Key& node) const {
14.1511 + if (Parent::aNode(node)) {
14.1512 + return aNodeMap[node];
14.1513 + } else {
14.1514 + return bNodeMap[node];
14.1515 + }
14.1516 + }
14.1517 +
14.1518 + Reference operator[](const Key& node) {
14.1519 + if (Parent::aNode(node)) {
14.1520 + return aNodeMap[node];
14.1521 + } else {
14.1522 + return bNodeMap[node];
14.1523 + }
14.1524 + }
14.1525 +
14.1526 + void set(const Key& node, const Value& value) {
14.1527 + if (Parent::aNode(node)) {
14.1528 + aNodeMap.set(node, value);
14.1529 + } else {
14.1530 + bNodeMap.set(node, value);
14.1531 + }
14.1532 + }
14.1533 +
14.1534 + protected:
14.1535 +
14.1536 + virtual void add(const Node&) {}
14.1537 + virtual void add(const std::vector<Node>&) {}
14.1538 + virtual void erase(const Node&) {}
14.1539 + virtual void erase(const std::vector<Node>&) {}
14.1540 + virtual void clear() {}
14.1541 + virtual void build() {}
14.1542 +
14.1543 + const Graph* getGraph() const { return graph; }
14.1544 +
14.1545 + private:
14.1546 + const Graph* graph;
14.1547 + BNodeMap<_Value> bNodeMap;
14.1548 + ANodeMap<_Value> aNodeMap;
14.1549 + };
14.1550 +
14.1551 + public:
14.1552 +
14.1553 + template <typename _Value>
14.1554 + class NodeMap
14.1555 + : public IterableMapExtender<NodeMapBase<_Value> > {
14.1556 + public:
14.1557 + typedef BpUGraphExtender Graph;
14.1558 + typedef IterableMapExtender< NodeMapBase<_Value> > Parent;
14.1559 +
14.1560 + NodeMap(const Graph& _g)
14.1561 + : Parent(_g) {}
14.1562 + NodeMap(const Graph& _g, const _Value& _v)
14.1563 + : Parent(_g, _v) {}
14.1564 +
14.1565 + NodeMap& operator=(const NodeMap& cmap) {
14.1566 + return operator=<NodeMap>(cmap);
14.1567 + }
14.1568 +
14.1569 +
14.1570 + /// \brief Template assign operator.
14.1571 + ///
14.1572 + /// The given parameter should be conform to the ReadMap
14.1573 + /// concept and could be indiced by the current item set of
14.1574 + /// the NodeMap. In this case the value for each item
14.1575 + /// is assigned by the value of the given ReadMap.
14.1576 + template <typename CMap>
14.1577 + NodeMap& operator=(const CMap& cmap) {
14.1578 + checkConcept<concept::ReadMap<Node, _Value>, CMap>();
14.1579 + const typename Parent::Graph* graph = Parent::getGraph();
14.1580 + Node it;
14.1581 + for (graph->first(it); it != INVALID; graph->next(it)) {
14.1582 + Parent::set(it, cmap[it]);
14.1583 + }
14.1584 + return *this;
14.1585 + }
14.1586 +
14.1587 + };
14.1588 +
14.1589 +
14.1590 +
14.1591 + template <typename _Value>
14.1592 + class EdgeMap
14.1593 + : public IterableMapExtender<DefaultMap<Graph, Edge, _Value> > {
14.1594 + public:
14.1595 + typedef BpUGraphExtender Graph;
14.1596 + typedef IterableMapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
14.1597 +
14.1598 + EdgeMap(const Graph& _g)
14.1599 + : Parent(_g) {}
14.1600 + EdgeMap(const Graph& _g, const _Value& _v)
14.1601 + : Parent(_g, _v) {}
14.1602 +
14.1603 + EdgeMap& operator=(const EdgeMap& cmap) {
14.1604 + return operator=<EdgeMap>(cmap);
14.1605 + }
14.1606 +
14.1607 + template <typename CMap>
14.1608 + EdgeMap& operator=(const CMap& cmap) {
14.1609 + checkConcept<concept::ReadMap<Edge, _Value>, CMap>();
14.1610 + const typename Parent::Graph* graph = Parent::getGraph();
14.1611 + Edge it;
14.1612 + for (graph->first(it); it != INVALID; graph->next(it)) {
14.1613 + Parent::set(it, cmap[it]);
14.1614 + }
14.1615 + return *this;
14.1616 + }
14.1617 + };
14.1618 +
14.1619 + template <typename _Value>
14.1620 + class UEdgeMap
14.1621 + : public IterableMapExtender<DefaultMap<Graph, UEdge, _Value> > {
14.1622 + public:
14.1623 + typedef BpUGraphExtender Graph;
14.1624 + typedef IterableMapExtender<DefaultMap<Graph, UEdge, _Value> >
14.1625 + Parent;
14.1626 +
14.1627 + UEdgeMap(const Graph& _g)
14.1628 + : Parent(_g) {}
14.1629 + UEdgeMap(const Graph& _g, const _Value& _v)
14.1630 + : Parent(_g, _v) {}
14.1631 +
14.1632 + UEdgeMap& operator=(const UEdgeMap& cmap) {
14.1633 + return operator=<UEdgeMap>(cmap);
14.1634 + }
14.1635 +
14.1636 + template <typename CMap>
14.1637 + UEdgeMap& operator=(const CMap& cmap) {
14.1638 + checkConcept<concept::ReadMap<UEdge, _Value>, CMap>();
14.1639 + const typename Parent::Graph* graph = Parent::getGraph();
14.1640 + UEdge it;
14.1641 + for (graph->first(it); it != INVALID; graph->next(it)) {
14.1642 + Parent::set(it, cmap[it]);
14.1643 + }
14.1644 + return *this;
14.1645 + }
14.1646 + };
14.1647 +
14.1648 +
14.1649 + Node addANode() {
14.1650 + Node node = Parent::addANode();
14.1651 + getNotifier(ANode()).add(node);
14.1652 + getNotifier(Node()).add(node);
14.1653 + return node;
14.1654 + }
14.1655 +
14.1656 + Node addBNode() {
14.1657 + Node node = Parent::addBNode();
14.1658 + getNotifier(BNode()).add(node);
14.1659 + getNotifier(Node()).add(node);
14.1660 + return node;
14.1661 + }
14.1662 +
14.1663 + UEdge addEdge(const Node& source, const Node& target) {
14.1664 + UEdge uedge = Parent::addEdge(source, target);
14.1665 + getNotifier(UEdge()).add(uedge);
14.1666 +
14.1667 + std::vector<Edge> edges;
14.1668 + edges.push_back(direct(uedge, true));
14.1669 + edges.push_back(direct(uedge, false));
14.1670 + getNotifier(Edge()).add(edges);
14.1671 +
14.1672 + return uedge;
14.1673 + }
14.1674 +
14.1675 + void clear() {
14.1676 + getNotifier(Edge()).clear();
14.1677 + getNotifier(UEdge()).clear();
14.1678 + getNotifier(Node()).clear();
14.1679 + getNotifier(BNode()).clear();
14.1680 + getNotifier(ANode()).clear();
14.1681 + Parent::clear();
14.1682 + }
14.1683 +
14.1684 + void erase(const Node& node) {
14.1685 + UEdge uedge;
14.1686 + bool dir;
14.1687 + Parent::firstInc(uedge, dir, node);
14.1688 + while (uedge != INVALID ) {
14.1689 + erase(uedge);
14.1690 + Parent::firstInc(uedge, dir, node);
14.1691 + }
14.1692 +
14.1693 + getNotifier(Node()).erase(node);
14.1694 + Parent::erase(node);
14.1695 + }
14.1696 +
14.1697 + void erase(const UEdge& uedge) {
14.1698 + std::vector<Edge> edges;
14.1699 + edges.push_back(direct(uedge, true));
14.1700 + edges.push_back(direct(uedge, false));
14.1701 + getNotifier(Edge()).erase(edges);
14.1702 + getNotifier(UEdge()).erase(uedge);
14.1703 + Parent::erase(uedge);
14.1704 + }
14.1705 +
14.1706 +
14.1707 + ~BpUGraphExtender() {
14.1708 + getNotifier(Edge()).clear();
14.1709 + getNotifier(UEdge()).clear();
14.1710 + getNotifier(Node()).clear();
14.1711 + getNotifier(BNode()).clear();
14.1712 + getNotifier(ANode()).clear();
14.1713 + }
14.1714 +
14.1715 +
14.1716 };
14.1717
14.1718 }
15.1 --- a/lemon/bits/iterable_graph_extender.h Wed Feb 22 12:45:59 2006 +0000
15.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
15.3 @@ -1,533 +0,0 @@
15.4 -/* -*- C++ -*-
15.5 - *
15.6 - * This file is a part of LEMON, a generic C++ optimization library
15.7 - *
15.8 - * Copyright (C) 2003-2006
15.9 - * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
15.10 - * (Egervary Research Group on Combinatorial Optimization, EGRES).
15.11 - *
15.12 - * Permission to use, modify and distribute this software is granted
15.13 - * provided that this copyright notice appears in all copies. For
15.14 - * precise terms see the accompanying LICENSE file.
15.15 - *
15.16 - * This software is provided "AS IS" with no warranty of any kind,
15.17 - * express or implied, and with no claim as to its suitability for any
15.18 - * purpose.
15.19 - *
15.20 - */
15.21 -
15.22 -#ifndef LEMON_ITERABLE_GRAPH_EXTENDER_H
15.23 -#define LEMON_ITERABLE_GRAPH_EXTENDER_H
15.24 -
15.25 -#include <lemon/invalid.h>
15.26 -#include <lemon/utility.h>
15.27 -
15.28 -namespace lemon {
15.29 -
15.30 - template <typename _Base>
15.31 - class IterableGraphExtender : public _Base {
15.32 - public:
15.33 -
15.34 - /// Indicates that the graph is undirected.
15.35 -
15.36 - ///\todo Better name?
15.37 - ///
15.38 - ///\bug Should it be here?
15.39 - typedef False UTag;
15.40 -
15.41 - typedef _Base Parent;
15.42 - typedef IterableGraphExtender<_Base> Graph;
15.43 -
15.44 - typedef typename Parent::Node Node;
15.45 - typedef typename Parent::Edge Edge;
15.46 -
15.47 -
15.48 - class NodeIt : public Node {
15.49 - const Graph* graph;
15.50 - public:
15.51 -
15.52 - NodeIt() {}
15.53 -
15.54 - NodeIt(Invalid i) : Node(i) { }
15.55 -
15.56 - explicit NodeIt(const Graph& _graph) : graph(&_graph) {
15.57 - _graph.first(*static_cast<Node*>(this));
15.58 - }
15.59 -
15.60 - NodeIt(const Graph& _graph, const Node& node)
15.61 - : Node(node), graph(&_graph) {}
15.62 -
15.63 - NodeIt& operator++() {
15.64 - graph->next(*this);
15.65 - return *this;
15.66 - }
15.67 -
15.68 - };
15.69 -
15.70 -
15.71 - class EdgeIt : public Edge {
15.72 - const Graph* graph;
15.73 - public:
15.74 -
15.75 - EdgeIt() { }
15.76 -
15.77 - EdgeIt(Invalid i) : Edge(i) { }
15.78 -
15.79 - explicit EdgeIt(const Graph& _graph) : graph(&_graph) {
15.80 - _graph.first(*static_cast<Edge*>(this));
15.81 - }
15.82 -
15.83 - EdgeIt(const Graph& _graph, const Edge& e) :
15.84 - Edge(e), graph(&_graph) { }
15.85 -
15.86 - EdgeIt& operator++() {
15.87 - graph->next(*this);
15.88 - return *this;
15.89 - }
15.90 -
15.91 - };
15.92 -
15.93 -
15.94 - class OutEdgeIt : public Edge {
15.95 - const Graph* graph;
15.96 - public:
15.97 -
15.98 - OutEdgeIt() { }
15.99 -
15.100 - OutEdgeIt(Invalid i) : Edge(i) { }
15.101 -
15.102 - OutEdgeIt(const Graph& _graph, const Node& node)
15.103 - : graph(&_graph) {
15.104 - _graph.firstOut(*this, node);
15.105 - }
15.106 -
15.107 - OutEdgeIt(const Graph& _graph, const Edge& edge)
15.108 - : Edge(edge), graph(&_graph) {}
15.109 -
15.110 - OutEdgeIt& operator++() {
15.111 - graph->nextOut(*this);
15.112 - return *this;
15.113 - }
15.114 -
15.115 - };
15.116 -
15.117 -
15.118 - class InEdgeIt : public Edge {
15.119 - const Graph* graph;
15.120 - public:
15.121 -
15.122 - InEdgeIt() { }
15.123 -
15.124 - InEdgeIt(Invalid i) : Edge(i) { }
15.125 -
15.126 - InEdgeIt(const Graph& _graph, const Node& node)
15.127 - : graph(&_graph) {
15.128 - _graph.firstIn(*this, node);
15.129 - }
15.130 -
15.131 - InEdgeIt(const Graph& _graph, const Edge& edge) :
15.132 - Edge(edge), graph(&_graph) {}
15.133 -
15.134 - InEdgeIt& operator++() {
15.135 - graph->nextIn(*this);
15.136 - return *this;
15.137 - }
15.138 -
15.139 - };
15.140 -
15.141 - /// \brief Base node of the iterator
15.142 - ///
15.143 - /// Returns the base node (ie. the source in this case) of the iterator
15.144 - Node baseNode(const OutEdgeIt &e) const {
15.145 - return Parent::source((Edge)e);
15.146 - }
15.147 - /// \brief Running node of the iterator
15.148 - ///
15.149 - /// Returns the running node (ie. the target in this case) of the
15.150 - /// iterator
15.151 - Node runningNode(const OutEdgeIt &e) const {
15.152 - return Parent::target((Edge)e);
15.153 - }
15.154 -
15.155 - /// \brief Base node of the iterator
15.156 - ///
15.157 - /// Returns the base node (ie. the target in this case) of the iterator
15.158 - Node baseNode(const InEdgeIt &e) const {
15.159 - return Parent::target((Edge)e);
15.160 - }
15.161 - /// \brief Running node of the iterator
15.162 - ///
15.163 - /// Returns the running node (ie. the source in this case) of the
15.164 - /// iterator
15.165 - Node runningNode(const InEdgeIt &e) const {
15.166 - return Parent::source((Edge)e);
15.167 - }
15.168 -
15.169 - using Parent::first;
15.170 -
15.171 - /// \brief The opposite node on the given edge.
15.172 - ///
15.173 - /// Gives back the opposite on the given edge.
15.174 - Node oppositeNode(const Node& n, const Edge& e) const {
15.175 - if (Parent::source(e) == n) {
15.176 - return Parent::target(e);
15.177 - } else {
15.178 - return Parent::source(e);
15.179 - }
15.180 - }
15.181 -
15.182 - private:
15.183 -
15.184 - // void first(NodeIt &) const;
15.185 - // void first(EdgeIt &) const;
15.186 - // void first(OutEdgeIt &) const;
15.187 - // void first(InEdgeIt &) const;
15.188 -
15.189 - };
15.190 -
15.191 -
15.192 -
15.193 -
15.194 -
15.195 -
15.196 - template <typename _Base>
15.197 - class IterableUGraphExtender : public IterableGraphExtender<_Base> {
15.198 - public:
15.199 -
15.200 - /// Indicates that the graph is undirected.
15.201 -
15.202 - ///\todo Better name?
15.203 - ///
15.204 - ///\bug Should it be here?
15.205 - ///\bug Should be tested in the concept checker whether it is defined
15.206 - ///correctly.
15.207 - typedef True UTag;
15.208 -
15.209 - typedef IterableGraphExtender<_Base> Parent;
15.210 - typedef IterableUGraphExtender<_Base> Graph;
15.211 - typedef typename Parent::Node Node;
15.212 - typedef typename Parent::Edge Edge;
15.213 - typedef typename Parent::UEdge UEdge;
15.214 -
15.215 - class UEdgeIt : public Parent::UEdge {
15.216 - const Graph* graph;
15.217 - public:
15.218 -
15.219 - UEdgeIt() { }
15.220 -
15.221 - UEdgeIt(Invalid i) : UEdge(i) { }
15.222 -
15.223 - explicit UEdgeIt(const Graph& _graph) : graph(&_graph) {
15.224 - _graph.first(*static_cast<UEdge*>(this));
15.225 - }
15.226 -
15.227 - UEdgeIt(const Graph& _graph, const UEdge& e) :
15.228 - UEdge(e), graph(&_graph) { }
15.229 -
15.230 - UEdgeIt& operator++() {
15.231 - graph->next(*this);
15.232 - return *this;
15.233 - }
15.234 -
15.235 - };
15.236 -
15.237 - class IncEdgeIt : public Parent::UEdge {
15.238 - const Graph* graph;
15.239 - bool direction;
15.240 - friend class IterableUGraphExtender;
15.241 - public:
15.242 -
15.243 - IncEdgeIt() { }
15.244 -
15.245 - IncEdgeIt(Invalid i) : UEdge(i), direction(false) { }
15.246 -
15.247 - IncEdgeIt(const Graph& _graph, const Node &n) : graph(&_graph) {
15.248 - _graph.firstInc(*this, direction, n);
15.249 - }
15.250 -
15.251 - IncEdgeIt(const Graph& _graph, const UEdge &ue, const Node &n)
15.252 - : graph(&_graph), UEdge(ue) {
15.253 - direction = (_graph.source(ue) == n);
15.254 - }
15.255 -
15.256 - IncEdgeIt& operator++() {
15.257 - graph->nextInc(*this, direction);
15.258 - return *this;
15.259 - }
15.260 - };
15.261 -
15.262 - using Parent::baseNode;
15.263 - using Parent::runningNode;
15.264 -
15.265 - /// Base node of the iterator
15.266 - ///
15.267 - /// Returns the base node of the iterator
15.268 - Node baseNode(const IncEdgeIt &e) const {
15.269 - return e.direction ? source(e) : target(e);
15.270 - }
15.271 - /// Running node of the iterator
15.272 - ///
15.273 - /// Returns the running node of the iterator
15.274 - Node runningNode(const IncEdgeIt &e) const {
15.275 - return e.direction ? target(e) : source(e);
15.276 - }
15.277 -
15.278 - /// \brief The opposite node on the given undirected edge.
15.279 - ///
15.280 - /// Gives back the opposite on the given undirected edge.
15.281 - Node oppositeNode(const Node& n, const UEdge& e) const {
15.282 - if (Parent::source(e) == n) {
15.283 - return Parent::target(e);
15.284 - } else {
15.285 - return Parent::source(e);
15.286 - }
15.287 - }
15.288 -
15.289 - };
15.290 -
15.291 -
15.292 - template <typename _Base>
15.293 - class IterableBpUGraphExtender : public _Base {
15.294 - public:
15.295 - typedef _Base Parent;
15.296 - typedef IterableBpUGraphExtender Graph;
15.297 -
15.298 - typedef typename Parent::Node Node;
15.299 - typedef typename Parent::ANode ANode;
15.300 - typedef typename Parent::BNode BNode;
15.301 - typedef typename Parent::Edge Edge;
15.302 - typedef typename Parent::UEdge UEdge;
15.303 -
15.304 - class NodeIt : public Node {
15.305 - const Graph* graph;
15.306 - public:
15.307 -
15.308 - NodeIt() { }
15.309 -
15.310 - NodeIt(Invalid i) : Node(INVALID) { }
15.311 -
15.312 - explicit NodeIt(const Graph& _graph) : graph(&_graph) {
15.313 - graph->first(static_cast<Node&>(*this));
15.314 - }
15.315 -
15.316 - NodeIt(const Graph& _graph, const Node& node)
15.317 - : Node(node), graph(&_graph) { }
15.318 -
15.319 - NodeIt& operator++() {
15.320 - graph->next(*this);
15.321 - return *this;
15.322 - }
15.323 -
15.324 - };
15.325 -
15.326 - class ANodeIt : public Node {
15.327 - friend class IterableBpUGraphExtender;
15.328 - const Graph* graph;
15.329 - public:
15.330 -
15.331 - ANodeIt() { }
15.332 -
15.333 - ANodeIt(Invalid i) : Node(INVALID) { }
15.334 -
15.335 - explicit ANodeIt(const Graph& _graph) : graph(&_graph) {
15.336 - graph->firstANode(static_cast<Node&>(*this));
15.337 - }
15.338 -
15.339 - ANodeIt(const Graph& _graph, const Node& node)
15.340 - : Node(node), graph(&_graph) {}
15.341 -
15.342 - ANodeIt& operator++() {
15.343 - graph->nextANode(*this);
15.344 - return *this;
15.345 - }
15.346 - };
15.347 -
15.348 - class BNodeIt : public Node {
15.349 - friend class IterableBpUGraphExtender;
15.350 - const Graph* graph;
15.351 - public:
15.352 -
15.353 - BNodeIt() { }
15.354 -
15.355 - BNodeIt(Invalid i) : Node(INVALID) { }
15.356 -
15.357 - explicit BNodeIt(const Graph& _graph) : graph(&_graph) {
15.358 - graph->firstBNode(static_cast<Node&>(*this));
15.359 - }
15.360 -
15.361 - BNodeIt(const Graph& _graph, const Node& node)
15.362 - : Node(node), graph(&_graph) {}
15.363 -
15.364 - BNodeIt& operator++() {
15.365 - graph->nextBNode(*this);
15.366 - return *this;
15.367 - }
15.368 - };
15.369 -
15.370 - class EdgeIt : public Edge {
15.371 - friend class IterableBpUGraphExtender;
15.372 - const Graph* graph;
15.373 - public:
15.374 -
15.375 - EdgeIt() { }
15.376 -
15.377 - EdgeIt(Invalid i) : Edge(INVALID) { }
15.378 -
15.379 - explicit EdgeIt(const Graph& _graph) : graph(&_graph) {
15.380 - graph->first(static_cast<Edge&>(*this));
15.381 - }
15.382 -
15.383 - EdgeIt(const Graph& _graph, const Edge& edge)
15.384 - : Edge(edge), graph(&_graph) { }
15.385 -
15.386 - EdgeIt& operator++() {
15.387 - graph->next(*this);
15.388 - return *this;
15.389 - }
15.390 -
15.391 - };
15.392 -
15.393 - class UEdgeIt : public UEdge {
15.394 - friend class IterableBpUGraphExtender;
15.395 - const Graph* graph;
15.396 - public:
15.397 -
15.398 - UEdgeIt() { }
15.399 -
15.400 - UEdgeIt(Invalid i) : UEdge(INVALID) { }
15.401 -
15.402 - explicit UEdgeIt(const Graph& _graph) : graph(&_graph) {
15.403 - graph->first(static_cast<UEdge&>(*this));
15.404 - }
15.405 -
15.406 - UEdgeIt(const Graph& _graph, const UEdge& edge)
15.407 - : UEdge(edge), graph(&_graph) { }
15.408 -
15.409 - UEdgeIt& operator++() {
15.410 - graph->next(*this);
15.411 - return *this;
15.412 - }
15.413 - };
15.414 -
15.415 - class OutEdgeIt : public Edge {
15.416 - friend class IterableBpUGraphExtender;
15.417 - const Graph* graph;
15.418 - public:
15.419 -
15.420 - OutEdgeIt() { }
15.421 -
15.422 - OutEdgeIt(Invalid i) : Edge(i) { }
15.423 -
15.424 - OutEdgeIt(const Graph& _graph, const Node& node)
15.425 - : graph(&_graph) {
15.426 - graph->firstOut(*this, node);
15.427 - }
15.428 -
15.429 - OutEdgeIt(const Graph& _graph, const Edge& edge)
15.430 - : Edge(edge), graph(&_graph) {}
15.431 -
15.432 - OutEdgeIt& operator++() {
15.433 - graph->nextOut(*this);
15.434 - return *this;
15.435 - }
15.436 -
15.437 - };
15.438 -
15.439 -
15.440 - class InEdgeIt : public Edge {
15.441 - friend class IterableBpUGraphExtender;
15.442 - const Graph* graph;
15.443 - public:
15.444 -
15.445 - InEdgeIt() { }
15.446 -
15.447 - InEdgeIt(Invalid i) : Edge(i) { }
15.448 -
15.449 - InEdgeIt(const Graph& _graph, const Node& node)
15.450 - : graph(&_graph) {
15.451 - graph->firstIn(*this, node);
15.452 - }
15.453 -
15.454 - InEdgeIt(const Graph& _graph, const Edge& edge) :
15.455 - Edge(edge), graph(&_graph) {}
15.456 -
15.457 - InEdgeIt& operator++() {
15.458 - graph->nextIn(*this);
15.459 - return *this;
15.460 - }
15.461 -
15.462 - };
15.463 -
15.464 - /// \brief Base node of the iterator
15.465 - ///
15.466 - /// Returns the base node (ie. the source in this case) of the iterator
15.467 - Node baseNode(const OutEdgeIt &e) const {
15.468 - return Parent::source((Edge&)e);
15.469 - }
15.470 - /// \brief Running node of the iterator
15.471 - ///
15.472 - /// Returns the running node (ie. the target in this case) of the
15.473 - /// iterator
15.474 - Node runningNode(const OutEdgeIt &e) const {
15.475 - return Parent::target((Edge&)e);
15.476 - }
15.477 -
15.478 - /// \brief Base node of the iterator
15.479 - ///
15.480 - /// Returns the base node (ie. the target in this case) of the iterator
15.481 - Node baseNode(const InEdgeIt &e) const {
15.482 - return Parent::target((Edge&)e);
15.483 - }
15.484 - /// \brief Running node of the iterator
15.485 - ///
15.486 - /// Returns the running node (ie. the source in this case) of the
15.487 - /// iterator
15.488 - Node runningNode(const InEdgeIt &e) const {
15.489 - return Parent::source((Edge&)e);
15.490 - }
15.491 -
15.492 - class IncEdgeIt : public Parent::UEdge {
15.493 - friend class IterableBpUGraphExtender;
15.494 - const Graph* graph;
15.495 - bool direction;
15.496 - public:
15.497 -
15.498 - IncEdgeIt() { }
15.499 -
15.500 - IncEdgeIt(Invalid i) : UEdge(i), direction(true) { }
15.501 -
15.502 - IncEdgeIt(const Graph& _graph, const Node &n) : graph(&_graph) {
15.503 - graph->firstInc(*this, direction, n);
15.504 - }
15.505 -
15.506 - IncEdgeIt(const Graph& _graph, const UEdge &ue, const Node &n)
15.507 - : graph(&_graph), UEdge(ue) {
15.508 - direction = (graph->source(ue) == n);
15.509 - }
15.510 -
15.511 - IncEdgeIt& operator++() {
15.512 - graph->nextInc(*this, direction);
15.513 - return *this;
15.514 - }
15.515 - };
15.516 -
15.517 -
15.518 - /// Base node of the iterator
15.519 - ///
15.520 - /// Returns the base node of the iterator
15.521 - Node baseNode(const IncEdgeIt &e) const {
15.522 - return e.direction ? source(e) : target(e);
15.523 - }
15.524 -
15.525 - /// Running node of the iterator
15.526 - ///
15.527 - /// Returns the running node of the iterator
15.528 - Node runningNode(const IncEdgeIt &e) const {
15.529 - return e.direction ? target(e) : source(e);
15.530 - }
15.531 -
15.532 - };
15.533 -
15.534 -}
15.535 -
15.536 -#endif // LEMON_GRAPH_EXTENDER_H
16.1 --- a/lemon/bits/static_map.h Wed Feb 22 12:45:59 2006 +0000
16.2 +++ b/lemon/bits/static_map.h Wed Feb 22 18:26:56 2006 +0000
16.3 @@ -56,11 +56,11 @@
16.4 class StaticMap : public AlterationNotifier<_Item>::ObserverBase {
16.5 public:
16.6
16.7 - /// \brief Exception class for unsinported exceptions.
16.8 - class UnsinportedOperation : public lemon::LogicError {
16.9 + /// \brief Exception class for unsupported exceptions.
16.10 + class UnsupportedOperation : public lemon::LogicError {
16.11 public:
16.12 virtual const char* exceptionName() const {
16.13 - return "lemon::StaticMap::UnsinportedOperation";
16.14 + return "lemon::StaticMap::UnsupportedOperation";
16.15 }
16.16 };
16.17
16.18 @@ -187,7 +187,7 @@
16.19 /// and it overrides the add() member function of the observer base.
16.20
16.21 void add(const Key&) {
16.22 - throw UnsinportedOperation();
16.23 + throw UnsupportedOperation();
16.24 }
16.25
16.26 /// \brief Erases a key from the map.
16.27 @@ -195,7 +195,7 @@
16.28 /// Erase a key from the map. It called by the observer registry
16.29 /// and it overrides the erase() member function of the observer base.
16.30 void erase(const Key&) {
16.31 - throw UnsinportedOperation();
16.32 + throw UnsupportedOperation();
16.33 }
16.34
16.35 /// Buildes the map.
16.36 @@ -224,396 +224,6 @@
16.37
16.38 };
16.39
16.40 - /// \e
16.41 - template <typename _Base>
16.42 - class StaticMappableGraphExtender : public _Base {
16.43 - public:
16.44 -
16.45 - typedef StaticMappableGraphExtender<_Base> Graph;
16.46 - typedef _Base Parent;
16.47 -
16.48 - typedef typename Parent::Node Node;
16.49 - typedef typename Parent::NodeIt NodeIt;
16.50 -
16.51 - typedef typename Parent::Edge Edge;
16.52 - typedef typename Parent::EdgeIt EdgeIt;
16.53 -
16.54 -
16.55 - template <typename _Value>
16.56 - class NodeMap
16.57 - : public IterableMapExtender<StaticMap<Graph, Node, _Value> > {
16.58 - public:
16.59 - typedef StaticMappableGraphExtender Graph;
16.60 - typedef IterableMapExtender<StaticMap<Graph, Node, _Value> > Parent;
16.61 -
16.62 - NodeMap(const Graph& _g)
16.63 - : Parent(_g) {}
16.64 - NodeMap(const Graph& _g, const _Value& _v)
16.65 - : Parent(_g, _v) {}
16.66 -
16.67 - NodeMap& operator=(const NodeMap& cmap) {
16.68 - return operator=<NodeMap>(cmap);
16.69 - }
16.70 -
16.71 -
16.72 - /// \brief Template assign operator.
16.73 - ///
16.74 - /// The given parameter should be conform to the ReadMap
16.75 - /// concecpt and could be indiced by the current item set of
16.76 - /// the NodeMap. In this case the value for each item
16.77 - /// is assigned by the value of the given ReadMap.
16.78 - template <typename CMap>
16.79 - NodeMap& operator=(const CMap& cmap) {
16.80 - checkConcept<concept::ReadMap<Node, _Value>, CMap>();
16.81 - const typename Parent::Graph* graph = Parent::getGraph();
16.82 - Node it;
16.83 - for (graph->first(it); it != INVALID; graph->next(it)) {
16.84 - Parent::set(it, cmap[it]);
16.85 - }
16.86 - return *this;
16.87 - }
16.88 -
16.89 - };
16.90 -
16.91 - template <typename _Value>
16.92 - class EdgeMap
16.93 - : public IterableMapExtender<StaticMap<Graph, Edge, _Value> > {
16.94 - public:
16.95 - typedef StaticMappableGraphExtender Graph;
16.96 - typedef IterableMapExtender<StaticMap<Graph, Edge, _Value> > Parent;
16.97 -
16.98 - EdgeMap(const Graph& _g)
16.99 - : Parent(_g) {}
16.100 - EdgeMap(const Graph& _g, const _Value& _v)
16.101 - : Parent(_g, _v) {}
16.102 -
16.103 - EdgeMap& operator=(const EdgeMap& cmap) {
16.104 - return operator=<EdgeMap>(cmap);
16.105 - }
16.106 -
16.107 - template <typename CMap>
16.108 - EdgeMap& operator=(const CMap& cmap) {
16.109 - checkConcept<concept::ReadMap<Edge, _Value>, CMap>();
16.110 - const typename Parent::Graph* graph = Parent::getGraph();
16.111 - Edge it;
16.112 - for (graph->first(it); it != INVALID; graph->next(it)) {
16.113 - Parent::set(it, cmap[it]);
16.114 - }
16.115 - return *this;
16.116 - }
16.117 - };
16.118 -
16.119 - };
16.120 -
16.121 - /// \e
16.122 - template <typename _Base>
16.123 - class StaticMappableUGraphExtender :
16.124 - public StaticMappableGraphExtender<_Base> {
16.125 - public:
16.126 -
16.127 - typedef StaticMappableUGraphExtender Graph;
16.128 - typedef StaticMappableGraphExtender<_Base> Parent;
16.129 -
16.130 - typedef typename Parent::UEdge UEdge;
16.131 -
16.132 - template <typename _Value>
16.133 - class UEdgeMap
16.134 - : public IterableMapExtender<StaticMap<Graph, UEdge, _Value> > {
16.135 - public:
16.136 - typedef StaticMappableUGraphExtender Graph;
16.137 - typedef IterableMapExtender<
16.138 - StaticMap<Graph, UEdge, _Value> > Parent;
16.139 -
16.140 - UEdgeMap(const Graph& _g)
16.141 - : Parent(_g) {}
16.142 - UEdgeMap(const Graph& _g, const _Value& _v)
16.143 - : Parent(_g, _v) {}
16.144 -
16.145 - UEdgeMap& operator=(const UEdgeMap& cmap) {
16.146 - return operator=<UEdgeMap>(cmap);
16.147 - }
16.148 -
16.149 - template <typename CMap>
16.150 - UEdgeMap& operator=(const CMap& cmap) {
16.151 - checkConcept<concept::ReadMap<UEdge, _Value>, CMap>();
16.152 - const typename Parent::Graph* graph = Parent::getGraph();
16.153 - UEdge it;
16.154 - for (graph->first(it); it != INVALID; graph->next(it)) {
16.155 - Parent::set(it, cmap[it]);
16.156 - }
16.157 - return *this;
16.158 - }
16.159 - };
16.160 -
16.161 - };
16.162 -
16.163 - template <typename _Base>
16.164 - class StaticMappableBpUGraphExtender : public _Base {
16.165 - public:
16.166 -
16.167 - typedef _Base Parent;
16.168 - typedef StaticMappableBpUGraphExtender Graph;
16.169 -
16.170 - typedef typename Parent::Node Node;
16.171 - typedef typename Parent::ANode ANode;
16.172 - typedef typename Parent::BNode BNode;
16.173 - typedef typename Parent::Edge Edge;
16.174 - typedef typename Parent::UEdge UEdge;
16.175 -
16.176 - template <typename _Value>
16.177 - class ANodeMap
16.178 - : public IterableMapExtender<StaticMap<Graph, ANode, _Value> > {
16.179 - public:
16.180 - typedef StaticMappableBpUGraphExtender Graph;
16.181 - typedef IterableMapExtender<StaticMap<Graph, ANode, _Value> >
16.182 - Parent;
16.183 -
16.184 - ANodeMap(const Graph& _g)
16.185 - : Parent(_g) {}
16.186 - ANodeMap(const Graph& _g, const _Value& _v)
16.187 - : Parent(_g, _v) {}
16.188 -
16.189 - ANodeMap& operator=(const ANodeMap& cmap) {
16.190 - return operator=<ANodeMap>(cmap);
16.191 - }
16.192 -
16.193 -
16.194 - /// \brief Template assign operator.
16.195 - ///
16.196 - /// The given parameter should be conform to the ReadMap
16.197 - /// concept and could be indiced by the current item set of
16.198 - /// the ANodeMap. In this case the value for each item
16.199 - /// is assigned by the value of the given ReadMap.
16.200 - template <typename CMap>
16.201 - ANodeMap& operator=(const CMap& cmap) {
16.202 - checkConcept<concept::ReadMap<ANode, _Value>, CMap>();
16.203 - const typename Parent::Graph* graph = Parent::getGraph();
16.204 - ANode it;
16.205 - for (graph->first(it); it != INVALID; graph->next(it)) {
16.206 - Parent::set(it, cmap[it]);
16.207 - }
16.208 - return *this;
16.209 - }
16.210 -
16.211 - };
16.212 -
16.213 - template <typename _Value>
16.214 - class BNodeMap
16.215 - : public IterableMapExtender<StaticMap<Graph, BNode, _Value> > {
16.216 - public:
16.217 - typedef StaticMappableBpUGraphExtender Graph;
16.218 - typedef IterableMapExtender<StaticMap<Graph, BNode, _Value> >
16.219 - Parent;
16.220 -
16.221 - BNodeMap(const Graph& _g)
16.222 - : Parent(_g) {}
16.223 - BNodeMap(const Graph& _g, const _Value& _v)
16.224 - : Parent(_g, _v) {}
16.225 -
16.226 - BNodeMap& operator=(const BNodeMap& cmap) {
16.227 - return operator=<BNodeMap>(cmap);
16.228 - }
16.229 -
16.230 -
16.231 - /// \brief Template assign operator.
16.232 - ///
16.233 - /// The given parameter should be conform to the ReadMap
16.234 - /// concept and could be indiced by the current item set of
16.235 - /// the BNodeMap. In this case the value for each item
16.236 - /// is assigned by the value of the given ReadMap.
16.237 - template <typename CMap>
16.238 - BNodeMap& operator=(const CMap& cmap) {
16.239 - checkConcept<concept::ReadMap<BNode, _Value>, CMap>();
16.240 - const typename Parent::Graph* graph = Parent::getGraph();
16.241 - BNode it;
16.242 - for (graph->first(it); it != INVALID; graph->next(it)) {
16.243 - Parent::set(it, cmap[it]);
16.244 - }
16.245 - return *this;
16.246 - }
16.247 -
16.248 - };
16.249 -
16.250 - protected:
16.251 -
16.252 - template <typename _Value>
16.253 - class NodeMapBase : public Parent::NodeNotifier::ObserverBase {
16.254 - public:
16.255 - typedef StaticMappableBpUGraphExtender Graph;
16.256 -
16.257 - typedef Node Key;
16.258 - typedef _Value Value;
16.259 -
16.260 - /// The reference type of the map;
16.261 - typedef typename BNodeMap<_Value>::Reference Reference;
16.262 - /// The pointer type of the map;
16.263 - typedef typename BNodeMap<_Value>::Pointer Pointer;
16.264 -
16.265 - /// The const value type of the map.
16.266 - typedef const Value ConstValue;
16.267 - /// The const reference type of the map;
16.268 - typedef typename BNodeMap<_Value>::ConstReference ConstReference;
16.269 - /// The pointer type of the map;
16.270 - typedef typename BNodeMap<_Value>::ConstPointer ConstPointer;
16.271 -
16.272 - typedef True ReferenceMapTag;
16.273 -
16.274 - NodeMapBase(const Graph& _g)
16.275 - : graph(&_g), bNodeMap(_g), aNodeMap(_g) {
16.276 - Parent::NodeNotifier::ObserverBase::attach(_g.getNotifier(Node()));
16.277 - }
16.278 - NodeMapBase(const Graph& _g, const _Value& _v)
16.279 - : graph(&_g), bNodeMap(_g, _v),
16.280 - aNodeMap(_g, _v) {
16.281 - Parent::NodeNotifier::ObserverBase::attach(_g.getNotifier(Node()));
16.282 - }
16.283 -
16.284 - virtual ~NodeMapBase() {
16.285 - if (Parent::NodeNotifier::ObserverBase::attached()) {
16.286 - Parent::NodeNotifier::ObserverBase::detach();
16.287 - }
16.288 - }
16.289 -
16.290 - ConstReference operator[](const Key& node) const {
16.291 - if (Parent::aNode(node)) {
16.292 - return aNodeMap[node];
16.293 - } else {
16.294 - return bNodeMap[node];
16.295 - }
16.296 - }
16.297 -
16.298 - Reference operator[](const Key& node) {
16.299 - if (Parent::aNode(node)) {
16.300 - return aNodeMap[node];
16.301 - } else {
16.302 - return bNodeMap[node];
16.303 - }
16.304 - }
16.305 -
16.306 - void set(const Key& node, const Value& value) {
16.307 - if (Parent::aNode(node)) {
16.308 - aNodeMap.set(node, value);
16.309 - } else {
16.310 - bNodeMap.set(node, value);
16.311 - }
16.312 - }
16.313 -
16.314 - protected:
16.315 -
16.316 - virtual void add(const Node&) {}
16.317 - virtual void add(const std::vector<Node>&) {}
16.318 - virtual void erase(const Node&) {}
16.319 - virtual void erase(const std::vector<Node>&) {}
16.320 - virtual void clear() {}
16.321 - virtual void build() {}
16.322 -
16.323 - const Graph* getGraph() const { return graph; }
16.324 -
16.325 - private:
16.326 - const Graph* graph;
16.327 - BNodeMap<_Value> bNodeMap;
16.328 - ANodeMap<_Value> aNodeMap;
16.329 - };
16.330 -
16.331 - public:
16.332 -
16.333 - template <typename _Value>
16.334 - class NodeMap
16.335 - : public IterableMapExtender<NodeMapBase<_Value> > {
16.336 - public:
16.337 - typedef StaticMappableBpUGraphExtender Graph;
16.338 - typedef IterableMapExtender< NodeMapBase<_Value> > Parent;
16.339 -
16.340 - NodeMap(const Graph& _g)
16.341 - : Parent(_g) {}
16.342 - NodeMap(const Graph& _g, const _Value& _v)
16.343 - : Parent(_g, _v) {}
16.344 -
16.345 - NodeMap& operator=(const NodeMap& cmap) {
16.346 - return operator=<NodeMap>(cmap);
16.347 - }
16.348 -
16.349 -
16.350 - /// \brief Template assign operator.
16.351 - ///
16.352 - /// The given parameter should be conform to the ReadMap
16.353 - /// concept and could be indiced by the current item set of
16.354 - /// the NodeMap. In this case the value for each item
16.355 - /// is assigned by the value of the given ReadMap.
16.356 - template <typename CMap>
16.357 - NodeMap& operator=(const CMap& cmap) {
16.358 - checkConcept<concept::ReadMap<Node, _Value>, CMap>();
16.359 - const typename Parent::Graph* graph = Parent::getGraph();
16.360 - Node it;
16.361 - for (graph->first(it); it != INVALID; graph->next(it)) {
16.362 - Parent::set(it, cmap[it]);
16.363 - }
16.364 - return *this;
16.365 - }
16.366 -
16.367 - };
16.368 -
16.369 -
16.370 -
16.371 - template <typename _Value>
16.372 - class EdgeMap
16.373 - : public IterableMapExtender<StaticMap<Graph, Edge, _Value> > {
16.374 - public:
16.375 - typedef StaticMappableBpUGraphExtender Graph;
16.376 - typedef IterableMapExtender<StaticMap<Graph, Edge, _Value> > Parent;
16.377 -
16.378 - EdgeMap(const Graph& _g)
16.379 - : Parent(_g) {}
16.380 - EdgeMap(const Graph& _g, const _Value& _v)
16.381 - : Parent(_g, _v) {}
16.382 -
16.383 - EdgeMap& operator=(const EdgeMap& cmap) {
16.384 - return operator=<EdgeMap>(cmap);
16.385 - }
16.386 -
16.387 - template <typename CMap>
16.388 - EdgeMap& operator=(const CMap& cmap) {
16.389 - checkConcept<concept::ReadMap<Edge, _Value>, CMap>();
16.390 - const typename Parent::Graph* graph = Parent::getGraph();
16.391 - Edge it;
16.392 - for (graph->first(it); it != INVALID; graph->next(it)) {
16.393 - Parent::set(it, cmap[it]);
16.394 - }
16.395 - return *this;
16.396 - }
16.397 - };
16.398 -
16.399 - template <typename _Value>
16.400 - class UEdgeMap
16.401 - : public IterableMapExtender<StaticMap<Graph, UEdge, _Value> > {
16.402 - public:
16.403 - typedef StaticMappableBpUGraphExtender Graph;
16.404 - typedef IterableMapExtender<StaticMap<Graph, UEdge, _Value> >
16.405 - Parent;
16.406 -
16.407 - UEdgeMap(const Graph& _g)
16.408 - : Parent(_g) {}
16.409 - UEdgeMap(const Graph& _g, const _Value& _v)
16.410 - : Parent(_g, _v) {}
16.411 -
16.412 - UEdgeMap& operator=(const UEdgeMap& cmap) {
16.413 - return operator=<UEdgeMap>(cmap);
16.414 - }
16.415 -
16.416 - template <typename CMap>
16.417 - UEdgeMap& operator=(const CMap& cmap) {
16.418 - checkConcept<concept::ReadMap<UEdge, _Value>, CMap>();
16.419 - const typename Parent::Graph* graph = Parent::getGraph();
16.420 - UEdge it;
16.421 - for (graph->first(it); it != INVALID; graph->next(it)) {
16.422 - Parent::set(it, cmap[it]);
16.423 - }
16.424 - return *this;
16.425 - }
16.426 - };
16.427 -
16.428 - };
16.429 -
16.430 }
16.431
16.432 #endif
17.1 --- a/lemon/concept/bpugraph.h Wed Feb 22 12:45:59 2006 +0000
17.2 +++ b/lemon/concept/bpugraph.h Wed Feb 22 18:26:56 2006 +0000
17.3 @@ -70,7 +70,7 @@
17.4 public:
17.5 /// \todo undocumented
17.6 ///
17.7 - typedef True UTag;
17.8 + typedef True UndirectedTag;
17.9
17.10 /// \brief The base type of node iterators,
17.11 /// or in other words, the trivial node iterator.
18.1 --- a/lemon/concept/graph.h Wed Feb 22 12:45:59 2006 +0000
18.2 +++ b/lemon/concept/graph.h Wed Feb 22 18:26:56 2006 +0000
18.3 @@ -44,8 +44,6 @@
18.4 public IterableGraphComponent, public MappableGraphComponent {
18.5 public:
18.6
18.7 - typedef False UTag;
18.8 -
18.9 typedef BaseGraphComponent::Node Node;
18.10 typedef BaseGraphComponent::Edge Edge;
18.11
18.12 @@ -123,10 +121,6 @@
18.13 public:
18.14 ///\e
18.15
18.16 - ///\todo undocumented
18.17 - ///
18.18 - typedef False UTag;
18.19 -
18.20 /// Defalult constructor.
18.21
18.22 /// Defalult constructor.
19.1 --- a/lemon/concept/ugraph.h Wed Feb 22 12:45:59 2006 +0000
19.2 +++ b/lemon/concept/ugraph.h Wed Feb 22 18:26:56 2006 +0000
19.3 @@ -245,7 +245,7 @@
19.4
19.5 ///\todo undocumented
19.6 ///
19.7 - typedef True UTag;
19.8 + typedef True UndirectedTag;
19.9
19.10 /// \brief The base type of node iterators,
19.11 /// or in other words, the trivial node iterator.
20.1 --- a/lemon/edge_set.h Wed Feb 22 12:45:59 2006 +0000
20.2 +++ b/lemon/edge_set.h Wed Feb 22 18:26:56 2006 +0000
20.3 @@ -19,13 +19,8 @@
20.4 #ifndef LEMON_EDGE_SET_H
20.5 #define LEMON_EDGE_SET_H
20.6
20.7 -#include <lemon/bits/erasable_graph_extender.h>
20.8 -#include <lemon/bits/clearable_graph_extender.h>
20.9 -#include <lemon/bits/extendable_graph_extender.h>
20.10 -#include <lemon/bits/iterable_graph_extender.h>
20.11 -#include <lemon/bits/alteration_notifier.h>
20.12 -#include <lemon/bits/default_map.h>
20.13 -#include <lemon/bits/graph_extender.h>
20.14 +
20.15 +#include <lemon/bits/edge_set_extender.h>
20.16
20.17 /// \ingroup graphs
20.18 /// \file
20.19 @@ -229,26 +224,11 @@
20.20 /// In the edge extension and removing it conforms to the
20.21 /// \ref concept::ErasableGraph "ErasableGraph" concept.
20.22 template <typename _Graph>
20.23 - class ListEdgeSet :
20.24 - public ErasableEdgeSetExtender<
20.25 - ClearableEdgeSetExtender<
20.26 - ExtendableEdgeSetExtender<
20.27 - MappableEdgeSetExtender<
20.28 - IterableGraphExtender<
20.29 - AlterableEdgeSetExtender<
20.30 - GraphExtender<
20.31 - ListEdgeSetBase<_Graph> > > > > > > > {
20.32 + class ListEdgeSet : public EdgeSetExtender<ListEdgeSetBase<_Graph> > {
20.33
20.34 public:
20.35
20.36 - typedef ErasableEdgeSetExtender<
20.37 - ClearableEdgeSetExtender<
20.38 - ExtendableEdgeSetExtender<
20.39 - MappableEdgeSetExtender<
20.40 - IterableGraphExtender<
20.41 - AlterableEdgeSetExtender<
20.42 - GraphExtender<
20.43 - ListEdgeSetBase<_Graph> > > > > > > > Parent;
20.44 + typedef EdgeSetExtender<ListEdgeSetBase<_Graph> > Parent;
20.45
20.46 typedef typename Parent::Node Node;
20.47 typedef typename Parent::Edge Edge;
20.48 @@ -336,26 +316,13 @@
20.49 /// In the edge extension and removing it conforms to the
20.50 /// \ref concept::ErasableUGraph "ErasableUGraph" concept.
20.51 template <typename _Graph>
20.52 - class ListUEdgeSet :
20.53 - public ErasableUEdgeSetExtender<
20.54 - ClearableUEdgeSetExtender<
20.55 - ExtendableUEdgeSetExtender<
20.56 - MappableUEdgeSetExtender<
20.57 - IterableUGraphExtender<
20.58 - AlterableUEdgeSetExtender<
20.59 - UGraphExtender<
20.60 - ListEdgeSetBase<_Graph> > > > > > > > {
20.61 + class ListUEdgeSet
20.62 + : public UEdgeSetExtender<UGraphBaseExtender<ListEdgeSetBase<_Graph> > > {
20.63
20.64 public:
20.65
20.66 - typedef ErasableUEdgeSetExtender<
20.67 - ClearableUEdgeSetExtender<
20.68 - ExtendableUEdgeSetExtender<
20.69 - MappableUEdgeSetExtender<
20.70 - IterableUGraphExtender<
20.71 - AlterableUEdgeSetExtender<
20.72 - UGraphExtender<
20.73 - ListEdgeSetBase<_Graph> > > > > > > > Parent;
20.74 + typedef UEdgeSetExtender<UGraphBaseExtender<
20.75 + ListEdgeSetBase<_Graph> > > Parent;
20.76
20.77 typedef typename Parent::Node Node;
20.78 typedef typename Parent::Edge Edge;
20.79 @@ -567,24 +534,11 @@
20.80 /// In the edge extension and removing it conforms to the
20.81 /// \ref concept::ExtendableGraph "ExtendableGraph" concept.
20.82 template <typename _Graph>
20.83 - class SmartEdgeSet :
20.84 - public ClearableEdgeSetExtender<
20.85 - ExtendableEdgeSetExtender<
20.86 - MappableEdgeSetExtender<
20.87 - IterableGraphExtender<
20.88 - AlterableEdgeSetExtender<
20.89 - GraphExtender<
20.90 - SmartEdgeSetBase<_Graph> > > > > > > {
20.91 + class SmartEdgeSet : public EdgeSetExtender<SmartEdgeSetBase<_Graph> > {
20.92
20.93 public:
20.94
20.95 - typedef ClearableEdgeSetExtender<
20.96 - ExtendableEdgeSetExtender<
20.97 - MappableEdgeSetExtender<
20.98 - IterableGraphExtender<
20.99 - AlterableEdgeSetExtender<
20.100 - GraphExtender<
20.101 - SmartEdgeSetBase<_Graph> > > > > > > Parent;
20.102 + typedef EdgeSetExtender<SmartEdgeSetBase<_Graph> > Parent;
20.103
20.104 typedef typename Parent::Node Node;
20.105 typedef typename Parent::Edge Edge;
20.106 @@ -671,24 +625,13 @@
20.107 /// In the edge extension and removing it conforms to the
20.108 /// \ref concept::ExtendableUGraph "ExtendableUGraph" concept.
20.109 template <typename _Graph>
20.110 - class SmartUEdgeSet :
20.111 - public ClearableUEdgeSetExtender<
20.112 - ExtendableUEdgeSetExtender<
20.113 - MappableUEdgeSetExtender<
20.114 - IterableUGraphExtender<
20.115 - AlterableUEdgeSetExtender<
20.116 - UGraphExtender<
20.117 - SmartEdgeSetBase<_Graph> > > > > > > {
20.118 + class SmartUEdgeSet
20.119 + : public UEdgeSetExtender<UGraphBaseExtender<SmartEdgeSetBase<_Graph> > > {
20.120
20.121 public:
20.122
20.123 - typedef ClearableUEdgeSetExtender<
20.124 - ExtendableUEdgeSetExtender<
20.125 - MappableUEdgeSetExtender<
20.126 - IterableUGraphExtender<
20.127 - AlterableUEdgeSetExtender<
20.128 - UGraphExtender<
20.129 - SmartEdgeSetBase<_Graph> > > > > > > Parent;
20.130 + typedef UEdgeSetExtender<UGraphBaseExtender<
20.131 + SmartEdgeSetBase<_Graph> > > Parent;
20.132
20.133 typedef typename Parent::Node Node;
20.134 typedef typename Parent::Edge Edge;
21.1 --- a/lemon/euler.h Wed Feb 22 12:45:59 2006 +0000
21.2 +++ b/lemon/euler.h Wed Feb 22 18:26:56 2006 +0000
21.3 @@ -233,7 +233,7 @@
21.4 #ifdef DOXYGEN
21.5 bool
21.6 #else
21.7 - typename enable_if<typename Graph::UTag,bool>::type
21.8 + typename enable_if<UndirectedTagIndicator<Graph>,bool>::type
21.9 euler(const Graph &g)
21.10 {
21.11 for(typename Graph::NodeIt n(g);n!=INVALID;++n)
21.12 @@ -241,7 +241,7 @@
21.13 return connected(g);
21.14 }
21.15 template<class Graph>
21.16 - typename disable_if<typename Graph::UTag,bool>::type
21.17 + typename disable_if<UndirectedTagIndicator<Graph>,bool>::type
21.18 #endif
21.19 euler(const Graph &g)
21.20 {
22.1 --- a/lemon/fredman_tarjan.h Wed Feb 22 12:45:59 2006 +0000
22.2 +++ b/lemon/fredman_tarjan.h Wed Feb 22 18:26:56 2006 +0000
22.3 @@ -504,7 +504,7 @@
22.4 Create ft(graph,cost);
22.5 ft.treeMap(tree);
22.6 ft.run();
22.7 - };
22.8 + }
22.9
22.10 } //END OF NAMESPACE LEMON
22.11
23.1 --- a/lemon/full_graph.h Wed Feb 22 12:45:59 2006 +0000
23.2 +++ b/lemon/full_graph.h Wed Feb 22 18:26:56 2006 +0000
23.3 @@ -22,11 +22,9 @@
23.4 #include <cmath>
23.5
23.6
23.7 -#include <lemon/bits/iterable_graph_extender.h>
23.8 -#include <lemon/bits/alteration_notifier.h>
23.9 -#include <lemon/bits/static_map.h>
23.10 #include <lemon/bits/graph_extender.h>
23.11
23.12 +
23.13 #include <lemon/invalid.h>
23.14 #include <lemon/utility.h>
23.15
23.16 @@ -191,10 +189,7 @@
23.17
23.18 };
23.19
23.20 - typedef StaticMappableGraphExtender<
23.21 - IterableGraphExtender<
23.22 - AlterableGraphExtender<
23.23 - GraphExtender<FullGraphBase> > > > ExtendedFullGraphBase;
23.24 + typedef GraphExtender<FullGraphBase> ExtendedFullGraphBase;
23.25
23.26 /// \ingroup graphs
23.27 ///
23.28 @@ -211,7 +206,21 @@
23.29 class FullGraph : public ExtendedFullGraphBase {
23.30 public:
23.31
23.32 + typedef ExtendedFullGraphBase Parent;
23.33 +
23.34 + /// \brief Constructor
23.35 + ///
23.36 FullGraph(int n) { construct(n); }
23.37 +
23.38 + /// \brief Resize the graph
23.39 + ///
23.40 + void resize(int n) {
23.41 + Parent::getNotifier(Edge()).clear();
23.42 + Parent::getNotifier(Node()).clear();
23.43 + construct(n);
23.44 + Parent::getNotifier(Node()).build();
23.45 + Parent::getNotifier(Edge()).build();
23.46 + }
23.47 };
23.48
23.49
23.50 @@ -379,10 +388,8 @@
23.51
23.52 };
23.53
23.54 - typedef StaticMappableUGraphExtender<
23.55 - IterableUGraphExtender<
23.56 - AlterableUGraphExtender<
23.57 - UGraphExtender<FullUGraphBase> > > > ExtendedFullUGraphBase;
23.58 + typedef UGraphExtender<UGraphBaseExtender<FullUGraphBase> >
23.59 + ExtendedFullUGraphBase;
23.60
23.61 /// \ingroup graphs
23.62 ///
23.63 @@ -401,7 +408,23 @@
23.64 /// \author Balazs Dezso
23.65 class FullUGraph : public ExtendedFullUGraphBase {
23.66 public:
23.67 +
23.68 + typedef ExtendedFullUGraphBase Parent;
23.69 +
23.70 + /// \brief Constructor
23.71 FullUGraph(int n) { construct(n); }
23.72 +
23.73 + /// \brief Resize the graph
23.74 + ///
23.75 + void resize(int n) {
23.76 + Parent::getNotifier(Edge()).clear();
23.77 + Parent::getNotifier(UEdge()).clear();
23.78 + Parent::getNotifier(Node()).clear();
23.79 + construct(n);
23.80 + Parent::getNotifier(Node()).build();
23.81 + Parent::getNotifier(UEdge()).build();
23.82 + Parent::getNotifier(Edge()).build();
23.83 + }
23.84 };
23.85
23.86
23.87 @@ -577,12 +600,8 @@
23.88 };
23.89
23.90
23.91 - typedef StaticMappableBpUGraphExtender<
23.92 - IterableBpUGraphExtender<
23.93 - AlterableBpUGraphExtender<
23.94 - BpUGraphExtender <
23.95 - FullBpUGraphBase> > > >
23.96 - ExtendedFullBpUGraphBase;
23.97 + typedef BpUGraphExtender< BpUGraphBaseExtender<
23.98 + FullBpUGraphBase> > ExtendedFullBpUGraphBase;
23.99
23.100
23.101 /// \ingroup graphs
23.102 @@ -599,10 +618,23 @@
23.103 class FullBpUGraph :
23.104 public ExtendedFullBpUGraphBase {
23.105 public:
23.106 +
23.107 typedef ExtendedFullBpUGraphBase Parent;
23.108 +
23.109 FullBpUGraph(int aNodeNum, int bNodeNum) {
23.110 Parent::construct(aNodeNum, bNodeNum);
23.111 }
23.112 + /// \brief Resize the graph
23.113 + ///
23.114 + void resize(int n, int m) {
23.115 + Parent::getNotifier(Edge()).clear();
23.116 + Parent::getNotifier(UEdge()).clear();
23.117 + Parent::getNotifier(Node()).clear();
23.118 + construct(n, m);
23.119 + Parent::getNotifier(Node()).build();
23.120 + Parent::getNotifier(UEdge()).build();
23.121 + Parent::getNotifier(Edge()).build();
23.122 + }
23.123 };
23.124
23.125 } //namespace lemon
24.1 --- a/lemon/graph_adaptor.h Wed Feb 22 12:45:59 2006 +0000
24.2 +++ b/lemon/graph_adaptor.h Wed Feb 22 18:26:56 2006 +0000
24.3 @@ -29,13 +29,10 @@
24.4
24.5 #include <lemon/invalid.h>
24.6 #include <lemon/maps.h>
24.7 -#include <lemon/bits/erasable_graph_extender.h>
24.8 -#include <lemon/bits/clearable_graph_extender.h>
24.9 -#include <lemon/bits/extendable_graph_extender.h>
24.10 -#include <lemon/bits/iterable_graph_extender.h>
24.11 -#include <lemon/bits/alteration_notifier.h>
24.12 -#include <lemon/bits/default_map.h>
24.13 +
24.14 +#include <lemon/bits/graph_adaptor_extender.h>
24.15 #include <lemon/bits/graph_extender.h>
24.16 +
24.17 #include <iostream>
24.18
24.19 namespace lemon {
24.20 @@ -117,10 +114,6 @@
24.21 int id(const Node& v) const { return graph->id(v); }
24.22 int id(const Edge& e) const { return graph->id(e); }
24.23
24.24 - Edge oppositeNode(const Edge& e) const {
24.25 - return Edge(graph->opposite(e));
24.26 - }
24.27 -
24.28 template <typename _Value>
24.29 class NodeMap : public _Graph::template NodeMap<_Value> {
24.30 public:
24.31 @@ -145,10 +138,10 @@
24.32
24.33 template <typename _Graph>
24.34 class GraphAdaptor :
24.35 - public IterableGraphExtender<GraphAdaptorBase<_Graph> > {
24.36 + public GraphAdaptorExtender<GraphAdaptorBase<_Graph> > {
24.37 public:
24.38 typedef _Graph Graph;
24.39 - typedef IterableGraphExtender<GraphAdaptorBase<_Graph> > Parent;
24.40 + typedef GraphAdaptorExtender<GraphAdaptorBase<_Graph> > Parent;
24.41 protected:
24.42 GraphAdaptor() : Parent() { }
24.43
24.44 @@ -198,10 +191,10 @@
24.45
24.46 template<typename _Graph>
24.47 class RevGraphAdaptor :
24.48 - public IterableGraphExtender<RevGraphAdaptorBase<_Graph> > {
24.49 + public GraphAdaptorExtender<RevGraphAdaptorBase<_Graph> > {
24.50 public:
24.51 typedef _Graph Graph;
24.52 - typedef IterableGraphExtender<
24.53 + typedef GraphAdaptorExtender<
24.54 RevGraphAdaptorBase<_Graph> > Parent;
24.55 protected:
24.56 RevGraphAdaptor() { }
24.57 @@ -322,6 +315,7 @@
24.58 ///
24.59 bool hidden(const Edge& e) const { return !(*edge_filter_map)[e]; }
24.60
24.61 + typedef False FindEdgeTag;
24.62 typedef False NodeNumTag;
24.63 typedef False EdgeNumTag;
24.64 };
24.65 @@ -428,6 +422,7 @@
24.66 ///
24.67 bool hidden(const Edge& e) const { return !(*edge_filter_map)[e]; }
24.68
24.69 + typedef False FindEdgeTag;
24.70 typedef False NodeNumTag;
24.71 typedef False EdgeNumTag;
24.72 };
24.73 @@ -496,11 +491,11 @@
24.74 template<typename _Graph, typename NodeFilterMap,
24.75 typename EdgeFilterMap, bool checked = true>
24.76 class SubGraphAdaptor :
24.77 - public IterableGraphExtender<
24.78 + public GraphAdaptorExtender<
24.79 SubGraphAdaptorBase<_Graph, NodeFilterMap, EdgeFilterMap, checked> > {
24.80 public:
24.81 typedef _Graph Graph;
24.82 - typedef IterableGraphExtender<
24.83 + typedef GraphAdaptorExtender<
24.84 SubGraphAdaptorBase<_Graph, NodeFilterMap, EdgeFilterMap> > Parent;
24.85 protected:
24.86 SubGraphAdaptor() { }
24.87 @@ -703,13 +698,13 @@
24.88 };
24.89
24.90 template <typename _Graph>
24.91 - class UGraphAdaptorBase :
24.92 - public UGraphExtender<GraphAdaptorBase<_Graph> > {
24.93 + class UndirectGraphAdaptorBase :
24.94 + public UGraphBaseExtender<GraphAdaptorBase<_Graph> > {
24.95 public:
24.96 typedef _Graph Graph;
24.97 - typedef UGraphExtender<GraphAdaptorBase<_Graph> > Parent;
24.98 + typedef UGraphBaseExtender<GraphAdaptorBase<_Graph> > Parent;
24.99 protected:
24.100 - UGraphAdaptorBase() : Parent() { }
24.101 + UndirectGraphAdaptorBase() : Parent() { }
24.102 public:
24.103 typedef typename Parent::UEdge UEdge;
24.104 typedef typename Parent::Edge Edge;
24.105 @@ -717,17 +712,17 @@
24.106 template <typename T>
24.107 class EdgeMap {
24.108 protected:
24.109 - const UGraphAdaptorBase<_Graph>* g;
24.110 + const UndirectGraphAdaptorBase<_Graph>* g;
24.111 template <typename TT> friend class EdgeMap;
24.112 typename _Graph::template EdgeMap<T> forward_map, backward_map;
24.113 public:
24.114 typedef T Value;
24.115 typedef Edge Key;
24.116
24.117 - EdgeMap(const UGraphAdaptorBase<_Graph>& _g) : g(&_g),
24.118 + EdgeMap(const UndirectGraphAdaptorBase<_Graph>& _g) : g(&_g),
24.119 forward_map(*(g->graph)), backward_map(*(g->graph)) { }
24.120
24.121 - EdgeMap(const UGraphAdaptorBase<_Graph>& _g, T a) : g(&_g),
24.122 + EdgeMap(const UndirectGraphAdaptorBase<_Graph>& _g, T a) : g(&_g),
24.123 forward_map(*(g->graph), a), backward_map(*(g->graph), a) { }
24.124
24.125 void set(Edge e, T a) {
24.126 @@ -753,10 +748,10 @@
24.127 typedef T Value;
24.128 typedef UEdge Key;
24.129
24.130 - UEdgeMap(const UGraphAdaptorBase<_Graph>& g) :
24.131 + UEdgeMap(const UndirectGraphAdaptorBase<_Graph>& g) :
24.132 map(*(g.graph)) { }
24.133
24.134 - UEdgeMap(const UGraphAdaptorBase<_Graph>& g, T a) :
24.135 + UEdgeMap(const UndirectGraphAdaptorBase<_Graph>& g, T a) :
24.136 map(*(g.graph), a) { }
24.137
24.138 void set(UEdge e, T a) {
24.139 @@ -778,17 +773,17 @@
24.140 ///
24.141 /// \author Marton Makai
24.142 template<typename _Graph>
24.143 - class UGraphAdaptor :
24.144 - public IterableUGraphExtender<
24.145 - UGraphAdaptorBase<_Graph> > {
24.146 + class UndirectGraphAdaptor :
24.147 + public UGraphAdaptorExtender<
24.148 + UndirectGraphAdaptorBase<_Graph> > {
24.149 public:
24.150 typedef _Graph Graph;
24.151 - typedef IterableUGraphExtender<
24.152 - UGraphAdaptorBase<_Graph> > Parent;
24.153 + typedef UGraphAdaptorExtender<
24.154 + UndirectGraphAdaptorBase<_Graph> > Parent;
24.155 protected:
24.156 - UGraphAdaptor() { }
24.157 + UndirectGraphAdaptor() { }
24.158 public:
24.159 - UGraphAdaptor(_Graph& _graph) {
24.160 + UndirectGraphAdaptor(_Graph& _graph) {
24.161 setGraph(_graph);
24.162 }
24.163 };
24.164 @@ -1083,11 +1078,11 @@
24.165 template<typename _Graph,
24.166 typename ForwardFilterMap, typename BackwardFilterMap>
24.167 class SubBidirGraphAdaptor :
24.168 - public IterableGraphExtender<
24.169 + public GraphAdaptorExtender<
24.170 SubBidirGraphAdaptorBase<_Graph, ForwardFilterMap, BackwardFilterMap> > {
24.171 public:
24.172 typedef _Graph Graph;
24.173 - typedef IterableGraphExtender<
24.174 + typedef GraphAdaptorExtender<
24.175 SubBidirGraphAdaptorBase<
24.176 _Graph, ForwardFilterMap, BackwardFilterMap> > Parent;
24.177 protected:
24.178 @@ -1341,11 +1336,11 @@
24.179 ///
24.180 template <typename _Graph, typename FirstOutEdgesMap>
24.181 class ErasingFirstGraphAdaptor :
24.182 - public IterableGraphExtender<
24.183 + public GraphAdaptorExtender<
24.184 ErasingFirstGraphAdaptorBase<_Graph, FirstOutEdgesMap> > {
24.185 public:
24.186 typedef _Graph Graph;
24.187 - typedef IterableGraphExtender<
24.188 + typedef GraphAdaptorExtender<
24.189 ErasingFirstGraphAdaptorBase<_Graph, FirstOutEdgesMap> > Parent;
24.190 ErasingFirstGraphAdaptor(Graph& _graph,
24.191 FirstOutEdgesMap& _first_out_edges) {
24.192 @@ -1711,9 +1706,9 @@
24.193
24.194 template <typename _Graph>
24.195 class SplitGraphAdaptor
24.196 - : public IterableGraphExtender<SplitGraphAdaptorBase<_Graph> > {
24.197 + : public GraphAdaptorExtender<SplitGraphAdaptorBase<_Graph> > {
24.198 public:
24.199 - typedef IterableGraphExtender<SplitGraphAdaptorBase<_Graph> > Parent;
24.200 + typedef GraphAdaptorExtender<SplitGraphAdaptorBase<_Graph> > Parent;
24.201
24.202 SplitGraphAdaptor(_Graph& graph) {
24.203 Parent::setGraph(graph);
25.1 --- a/lemon/grid_graph.h Wed Feb 22 12:45:59 2006 +0000
25.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
25.3 @@ -1,522 +0,0 @@
25.4 -/* -*- C++ -*-
25.5 - *
25.6 - * This file is a part of LEMON, a generic C++ optimization library
25.7 - *
25.8 - * Copyright (C) 2003-2006
25.9 - * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
25.10 - * (Egervary Research Group on Combinatorial Optimization, EGRES).
25.11 - *
25.12 - * Permission to use, modify and distribute this software is granted
25.13 - * provided that this copyright notice appears in all copies. For
25.14 - * precise terms see the accompanying LICENSE file.
25.15 - *
25.16 - * This software is provided "AS IS" with no warranty of any kind,
25.17 - * express or implied, and with no claim as to its suitability for any
25.18 - * purpose.
25.19 - *
25.20 - */
25.21 -
25.22 -#ifndef GRID_GRAPH_H
25.23 -#define GRID_GRAPH_H
25.24 -
25.25 -#include <iostream>
25.26 -#include <lemon/invalid.h>
25.27 -#include <lemon/utility.h>
25.28 -
25.29 -#include <lemon/bits/iterable_graph_extender.h>
25.30 -#include <lemon/bits/alteration_notifier.h>
25.31 -#include <lemon/bits/static_map.h>
25.32 -#include <lemon/bits/graph_extender.h>
25.33 -
25.34 -#include <lemon/xy.h>
25.35 -
25.36 -///\ingroup graphs
25.37 -///\file
25.38 -///\brief GridGraph class.
25.39 -
25.40 -namespace lemon {
25.41 -
25.42 - /// \brief Base graph for GridGraph.
25.43 - ///
25.44 - /// Base graph for grid graph. It describes some member functions
25.45 - /// which can be used in the GridGraph.
25.46 - ///
25.47 - /// \warning Always use the GridGraph instead of this.
25.48 - /// \see GridGraph
25.49 - class GridGraphBase {
25.50 -
25.51 - public:
25.52 -
25.53 - typedef GridGraphBase Graph;
25.54 -
25.55 - class Node;
25.56 - class Edge;
25.57 -
25.58 - public:
25.59 -
25.60 - GridGraphBase() {}
25.61 -
25.62 - protected:
25.63 -
25.64 - /// \brief Creates a grid graph with the given size.
25.65 - ///
25.66 - /// Creates a grid graph with the given size.
25.67 - void construct(int width, int height) {
25.68 - _height = height; _width = width;
25.69 - _nodeNum = height * width; _edgeNum = 2 * _nodeNum - width - height;
25.70 - _edgeLimit = _nodeNum - width;
25.71 - }
25.72 -
25.73 - /// \brief Gives back the edge goes down from the node.
25.74 - ///
25.75 - /// Gives back the edge goes down from the node. If there is not
25.76 - /// outgoing edge then it gives back INVALID.
25.77 - Edge _down(Node n) const {
25.78 - if (n.id < _nodeNum - _width) {
25.79 - return Edge(n.id);
25.80 - } else {
25.81 - return INVALID;
25.82 - }
25.83 - }
25.84 -
25.85 - /// \brief Gives back the edge comes from up into the node.
25.86 - ///
25.87 - /// Gives back the edge comes from up into the node. If there is not
25.88 - /// incoming edge then it gives back INVALID.
25.89 - Edge _up(Node n) const {
25.90 - if (n.id >= _width) {
25.91 - return Edge(n.id - _width);
25.92 - } else {
25.93 - return INVALID;
25.94 - }
25.95 - }
25.96 -
25.97 - /// \brief Gives back the edge goes right from the node.
25.98 - ///
25.99 - /// Gives back the edge goes right from the node. If there is not
25.100 - /// outgoing edge then it gives back INVALID.
25.101 - Edge _right(Node n) const {
25.102 - if (n.id % _width < _width - 1) {
25.103 - return _edgeLimit + n.id % _width + (n.id / _width) * (_width - 1);
25.104 - } else {
25.105 - return INVALID;
25.106 - }
25.107 - }
25.108 -
25.109 - /// \brief Gives back the edge comes from left into the node.
25.110 - ///
25.111 - /// Gives back the edge comes left up into the node. If there is not
25.112 - /// incoming edge then it gives back INVALID.
25.113 - Edge _left(Node n) const {
25.114 - if (n.id % _width > 0) {
25.115 - return _edgeLimit + n.id % _width + (n.id / _width) * (_width - 1) - 1;
25.116 - } else {
25.117 - return INVALID;
25.118 - }
25.119 - }
25.120 -
25.121 -
25.122 - public:
25.123 -
25.124 - /// \brief The node on the given position.
25.125 - ///
25.126 - /// Gives back the node on the given position.
25.127 - Node operator()(int i, int j) const {
25.128 - return Node(i + j * _width);
25.129 - }
25.130 -
25.131 - /// \brief Gives back the row index of the node.
25.132 - ///
25.133 - /// Gives back the row index of the node.
25.134 - int row(Node n) const {
25.135 - return n.id / _width;
25.136 - }
25.137 -
25.138 - /// \brief Gives back the coloumn index of the node.
25.139 - ///
25.140 - /// Gives back the coloumn index of the node.
25.141 - int col(Node n) const {
25.142 - return n.id % _width;
25.143 - }
25.144 -
25.145 - /// \brief Gives back the width of the graph.
25.146 - ///
25.147 - /// Gives back the width of the graph.
25.148 - int width() const {
25.149 - return _width;
25.150 - }
25.151 -
25.152 - /// \brief Gives back the height of the graph.
25.153 - ///
25.154 - /// Gives back the height of the graph.
25.155 - int height() const {
25.156 - return _height;
25.157 - }
25.158 -
25.159 - typedef True NodeNumTag;
25.160 - typedef True EdgeNumTag;
25.161 -
25.162 - ///Number of nodes.
25.163 - int nodeNum() const { return _nodeNum; }
25.164 - ///Number of edges.
25.165 - int edgeNum() const { return _edgeNum; }
25.166 -
25.167 - /// Maximum node ID.
25.168 -
25.169 - /// Maximum node ID.
25.170 - ///\sa id(Node)
25.171 - int maxNodeId() const { return nodeNum() - 1; }
25.172 - /// Maximum edge ID.
25.173 -
25.174 - /// Maximum edge ID.
25.175 - ///\sa id(Edge)
25.176 - int maxEdgeId() const { return edgeNum() - 1; }
25.177 -
25.178 - /// \brief Gives back the source node of an edge.
25.179 - ///
25.180 - /// Gives back the source node of an edge.
25.181 - Node source(Edge e) const {
25.182 - if (e.id < _edgeLimit) {
25.183 - return e.id;
25.184 - } else {
25.185 - return (e.id - _edgeLimit) % (_width - 1) +
25.186 - (e.id - _edgeLimit) / (_width - 1) * _width;
25.187 - }
25.188 - }
25.189 -
25.190 - /// \brief Gives back the target node of an edge.
25.191 - ///
25.192 - /// Gives back the target node of an edge.
25.193 - Node target(Edge e) const {
25.194 - if (e.id < _edgeLimit) {
25.195 - return e.id + _width;
25.196 - } else {
25.197 - return (e.id - _edgeLimit) % (_width - 1) +
25.198 - (e.id - _edgeLimit) / (_width - 1) * _width + 1;
25.199 - }
25.200 - }
25.201 -
25.202 - /// Node ID.
25.203 -
25.204 - /// The ID of a valid Node is a nonnegative integer not greater than
25.205 - /// \ref maxNodeId(). The range of the ID's is not surely continuous
25.206 - /// and the greatest node ID can be actually less then \ref maxNodeId().
25.207 - ///
25.208 - /// The ID of the \ref INVALID node is -1.
25.209 - ///\return The ID of the node \c v.
25.210 -
25.211 - static int id(Node v) { return v.id; }
25.212 - /// Edge ID.
25.213 -
25.214 - /// The ID of a valid Edge is a nonnegative integer not greater than
25.215 - /// \ref maxEdgeId(). The range of the ID's is not surely continuous
25.216 - /// and the greatest edge ID can be actually less then \ref maxEdgeId().
25.217 - ///
25.218 - /// The ID of the \ref INVALID edge is -1.
25.219 - ///\return The ID of the edge \c e.
25.220 - static int id(Edge e) { return e.id; }
25.221 -
25.222 - static Node nodeFromId(int id) { return Node(id);}
25.223 -
25.224 - static Edge edgeFromId(int id) { return Edge(id);}
25.225 -
25.226 - typedef True FindEdgeTag;
25.227 -
25.228 - /// Finds an edge between two nodes.
25.229 -
25.230 - /// Finds an edge from node \c u to node \c v.
25.231 - ///
25.232 - /// If \c prev is \ref INVALID (this is the default value), then
25.233 - /// It finds the first edge from \c u to \c v. Otherwise it looks for
25.234 - /// the next edge from \c u to \c v after \c prev.
25.235 - /// \return The found edge or INVALID if there is no such an edge.
25.236 - Edge findEdge(Node u, Node v, Edge prev = INVALID) const {
25.237 - if (prev != INVALID) return INVALID;
25.238 - if (v.id - u.id == _width) return Edge(u.id);
25.239 - if (v.id - u.id == 1 && u.id % _width < _width - 1) {
25.240 - return Edge(u.id / _width * (_width - 1) +
25.241 - u.id % _width + _edgeLimit);
25.242 - }
25.243 - return INVALID;
25.244 - }
25.245 -
25.246 -
25.247 - class Node {
25.248 - friend class GridGraphBase;
25.249 -
25.250 - protected:
25.251 - int id;
25.252 - Node(int _id) { id = _id;}
25.253 - public:
25.254 - Node() {}
25.255 - Node (Invalid) { id = -1; }
25.256 - bool operator==(const Node node) const {return id == node.id;}
25.257 - bool operator!=(const Node node) const {return id != node.id;}
25.258 - bool operator<(const Node node) const {return id < node.id;}
25.259 - };
25.260 -
25.261 -
25.262 -
25.263 - class Edge {
25.264 - friend class GridGraphBase;
25.265 -
25.266 - protected:
25.267 - int id;
25.268 -
25.269 - Edge(int _id) : id(_id) {}
25.270 -
25.271 - public:
25.272 - Edge() { }
25.273 - Edge (Invalid) { id = -1; }
25.274 - bool operator==(const Edge edge) const {return id == edge.id;}
25.275 - bool operator!=(const Edge edge) const {return id != edge.id;}
25.276 - bool operator<(const Edge edge) const {return id < edge.id;}
25.277 - };
25.278 -
25.279 - void first(Node& node) const {
25.280 - node.id = nodeNum() - 1;
25.281 - }
25.282 -
25.283 - static void next(Node& node) {
25.284 - --node.id;
25.285 - }
25.286 -
25.287 - void first(Edge& edge) const {
25.288 - edge.id = edgeNum() - 1;
25.289 - }
25.290 -
25.291 - static void next(Edge& edge) {
25.292 - --edge.id;
25.293 - }
25.294 -
25.295 - void firstOut(Edge& edge, const Node& node) const {
25.296 - if (node.id < _nodeNum - _width) {
25.297 - edge.id = node.id;
25.298 - } else if (node.id % _width < _width - 1) {
25.299 - edge.id = _edgeLimit + node.id % _width +
25.300 - (node.id / _width) * (_width - 1);
25.301 - } else {
25.302 - edge.id = -1;
25.303 - }
25.304 - }
25.305 -
25.306 - void nextOut(Edge& edge) const {
25.307 - if (edge.id >= _edgeLimit) {
25.308 - edge.id = -1;
25.309 - } else if (edge.id % _width < _width - 1) {
25.310 - edge.id = _edgeLimit + edge.id % _width +
25.311 - (edge.id / _width) * (_width - 1);
25.312 - } else {
25.313 - edge.id = -1;
25.314 - }
25.315 - }
25.316 -
25.317 - void firstIn(Edge& edge, const Node& node) const {
25.318 - if (node.id >= _width) {
25.319 - edge.id = node.id - _width;
25.320 - } else if (node.id % _width > 0) {
25.321 - edge.id = _edgeLimit + node.id % _width +
25.322 - (node.id / _width) * (_width - 1) - 1;
25.323 - } else {
25.324 - edge.id = -1;
25.325 - }
25.326 - }
25.327 -
25.328 - void nextIn(Edge& edge) const {
25.329 - if (edge.id >= _edgeLimit) {
25.330 - edge.id = -1;
25.331 - } else if (edge.id % _width > 0) {
25.332 - edge.id = _edgeLimit + edge.id % _width +
25.333 - (edge.id / _width + 1) * (_width - 1) - 1;
25.334 - } else {
25.335 - edge.id = -1;
25.336 - }
25.337 - }
25.338 -
25.339 - private:
25.340 - int _width, _height;
25.341 - int _nodeNum, _edgeNum;
25.342 - int _edgeLimit;
25.343 - };
25.344 -
25.345 -
25.346 - typedef StaticMappableUGraphExtender<
25.347 - IterableUGraphExtender<
25.348 - AlterableUGraphExtender<
25.349 - UGraphExtender<GridGraphBase> > > > ExtendedGridGraphBase;
25.350 -
25.351 - /// \ingroup graphs
25.352 - ///
25.353 - /// \brief Grid graph class
25.354 - ///
25.355 - /// This class implements a special graph type. The nodes of the
25.356 - /// graph can be indiced by two integer \c (i,j) value where \c i
25.357 - /// is in the \c [0,width) range and j is in the [0, height) range.
25.358 - /// Two nodes are connected in the graph if the indices differ only
25.359 - /// on one position and only one is the difference.
25.360 - ///
25.361 - /// The graph can be indiced in the following way:
25.362 - ///\code
25.363 - /// GridGraph graph(w, h);
25.364 - /// GridGraph::NodeMap<int> val(graph);
25.365 - /// for (int i = 0; i < graph.width(); ++i) {
25.366 - /// for (int j = 0; j < graph.height(); ++j) {
25.367 - /// val[graph(i, j)] = i + j;
25.368 - /// }
25.369 - /// }
25.370 - ///\endcode
25.371 - ///
25.372 - /// The graph type is fully conform to the \ref concept::UGraph
25.373 - /// "Undirected Graph" concept.
25.374 - ///
25.375 - /// \author Balazs Dezso
25.376 - /// \see GridGraphBase
25.377 - class GridGraph : public ExtendedGridGraphBase {
25.378 - public:
25.379 -
25.380 - /// \brief Map to get the indices of the nodes as xy<int>.
25.381 - ///
25.382 - /// Map to get the indices of the nodes as xy<int>.
25.383 - class IndexMap {
25.384 - public:
25.385 - typedef True NeedCopy;
25.386 - /// \brief The key type of the map
25.387 - typedef GridGraph::Node Key;
25.388 - /// \brief The value type of the map
25.389 - typedef xy<int> Value;
25.390 -
25.391 - /// \brief Constructor
25.392 - ///
25.393 - /// Constructor
25.394 - IndexMap(const GridGraph& _graph) : graph(_graph) {}
25.395 -
25.396 - /// \brief The subscript operator
25.397 - ///
25.398 - /// The subscript operator.
25.399 - Value operator[](Key key) const {
25.400 - return xy<int>(graph.row(key), graph.col(key));
25.401 - }
25.402 -
25.403 - private:
25.404 - const GridGraph& graph;
25.405 - };
25.406 -
25.407 - /// \brief Map to get the row of the nodes.
25.408 - ///
25.409 - /// Map to get the row of the nodes.
25.410 - class RowMap {
25.411 - public:
25.412 - typedef True NeedCopy;
25.413 - /// \brief The key type of the map
25.414 - typedef GridGraph::Node Key;
25.415 - /// \brief The value type of the map
25.416 - typedef int Value;
25.417 -
25.418 - /// \brief Constructor
25.419 - ///
25.420 - /// Constructor
25.421 - RowMap(const GridGraph& _graph) : graph(_graph) {}
25.422 -
25.423 - /// \brief The subscript operator
25.424 - ///
25.425 - /// The subscript operator.
25.426 - Value operator[](Key key) const {
25.427 - return graph.row(key);
25.428 - }
25.429 -
25.430 - private:
25.431 - const GridGraph& graph;
25.432 - };
25.433 -
25.434 - /// \brief Map to get the column of the nodes.
25.435 - ///
25.436 - /// Map to get the column of the nodes.
25.437 - class ColMap {
25.438 - public:
25.439 - typedef True NeedCopy;
25.440 - /// \brief The key type of the map
25.441 - typedef GridGraph::Node Key;
25.442 - /// \brief The value type of the map
25.443 - typedef int Value;
25.444 -
25.445 - /// \brief Constructor
25.446 - ///
25.447 - /// Constructor
25.448 - ColMap(const GridGraph& _graph) : graph(_graph) {}
25.449 -
25.450 - /// \brief The subscript operator
25.451 - ///
25.452 - /// The subscript operator.
25.453 - Value operator[](Key key) const {
25.454 - return graph.col(key);
25.455 - }
25.456 -
25.457 - private:
25.458 - const GridGraph& graph;
25.459 - };
25.460 -
25.461 - /// \brief Constructor
25.462 - ///
25.463 - ///
25.464 - GridGraph(int n, int m) { construct(n, m); }
25.465 -
25.466 - /// \brief Gives back the edge goes down from the node.
25.467 - ///
25.468 - /// Gives back the edge goes down from the node. If there is not
25.469 - /// outgoing edge then it gives back INVALID.
25.470 - Edge down(Node n) const {
25.471 - UEdge ue = _down(n);
25.472 - return ue != INVALID ? direct(ue, true) : INVALID;
25.473 - }
25.474 -
25.475 - /// \brief Gives back the edge goes up from the node.
25.476 - ///
25.477 - /// Gives back the edge goes up from the node. If there is not
25.478 - /// outgoing edge then it gives back INVALID.
25.479 - Edge up(Node n) const {
25.480 - UEdge ue = _up(n);
25.481 - return ue != INVALID ? direct(ue, false) : INVALID;
25.482 - }
25.483 -
25.484 - /// \brief Gives back the edge goes right from the node.
25.485 - ///
25.486 - /// Gives back the edge goes right from the node. If there is not
25.487 - /// outgoing edge then it gives back INVALID.
25.488 - Edge right(Node n) const {
25.489 - UEdge ue = _right(n);
25.490 - return ue != INVALID ? direct(ue, true) : INVALID;
25.491 - }
25.492 -
25.493 - /// \brief Gives back the edge goes left from the node.
25.494 - ///
25.495 - /// Gives back the edge goes left from the node. If there is not
25.496 - /// outgoing edge then it gives back INVALID.
25.497 - Edge left(Node n) const {
25.498 - UEdge ue = _left(n);
25.499 - return ue != INVALID ? direct(ue, false) : INVALID;
25.500 - }
25.501 -
25.502 - };
25.503 -
25.504 - /// \brief Index map of the grid graph
25.505 - ///
25.506 - /// Just returns an IndexMap for the grid graph.
25.507 - GridGraph::IndexMap indexMap(const GridGraph& graph) {
25.508 - return GridGraph::IndexMap(graph);
25.509 - }
25.510 -
25.511 - /// \brief Row map of the grid graph
25.512 - ///
25.513 - /// Just returns a RowMap for the grid graph.
25.514 - GridGraph::RowMap rowMap(const GridGraph& graph) {
25.515 - return GridGraph::RowMap(graph);
25.516 - }
25.517 -
25.518 - /// \brief Column map of the grid graph
25.519 - ///
25.520 - /// Just returns a ColMap for the grid graph.
25.521 - GridGraph::ColMap colMap(const GridGraph& graph) {
25.522 - return GridGraph::ColMap(graph);
25.523 - }
25.524 -}
25.525 -#endif
26.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
26.2 +++ b/lemon/grid_ugraph.h Wed Feb 22 18:26:56 2006 +0000
26.3 @@ -0,0 +1,536 @@
26.4 +/* -*- C++ -*-
26.5 + *
26.6 + * This file is a part of LEMON, a generic C++ optimization library
26.7 + *
26.8 + * Copyright (C) 2003-2006
26.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
26.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
26.11 + *
26.12 + * Permission to use, modify and distribute this software is granted
26.13 + * provided that this copyright notice appears in all copies. For
26.14 + * precise terms see the accompanying LICENSE file.
26.15 + *
26.16 + * This software is provided "AS IS" with no warranty of any kind,
26.17 + * express or implied, and with no claim as to its suitability for any
26.18 + * purpose.
26.19 + *
26.20 + */
26.21 +
26.22 +#ifndef GRID_UGRAPH_H
26.23 +#define GRID_UGRAPH_H
26.24 +
26.25 +#include <iostream>
26.26 +#include <lemon/invalid.h>
26.27 +#include <lemon/utility.h>
26.28 +
26.29 +#include <lemon/bits/graph_extender.h>
26.30 +
26.31 +#include <lemon/xy.h>
26.32 +
26.33 +///\ingroup graphs
26.34 +///\file
26.35 +///\brief GridUGraph class.
26.36 +
26.37 +namespace lemon {
26.38 +
26.39 + /// \brief Base graph for GridUGraph.
26.40 + ///
26.41 + /// Base graph for grid graph. It describes some member functions
26.42 + /// which can be used in the GridUGraph.
26.43 + ///
26.44 + /// \warning Always use the GridUGraph instead of this.
26.45 + /// \see GridUGraph
26.46 + class GridUGraphBase {
26.47 +
26.48 + public:
26.49 +
26.50 + typedef GridUGraphBase UGraph;
26.51 +
26.52 + class Node;
26.53 + class Edge;
26.54 +
26.55 + public:
26.56 +
26.57 + GridUGraphBase() {}
26.58 +
26.59 + protected:
26.60 +
26.61 + /// \brief Creates a grid graph with the given size.
26.62 + ///
26.63 + /// Creates a grid graph with the given size.
26.64 + void construct(int width, int height) {
26.65 + _height = height; _width = width;
26.66 + _nodeNum = height * width; _edgeNum = 2 * _nodeNum - width - height;
26.67 + _edgeLimit = _nodeNum - width;
26.68 + }
26.69 +
26.70 + /// \brief Gives back the edge goes down from the node.
26.71 + ///
26.72 + /// Gives back the edge goes down from the node. If there is not
26.73 + /// outgoing edge then it gives back INVALID.
26.74 + Edge _down(Node n) const {
26.75 + if (n.id < _nodeNum - _width) {
26.76 + return Edge(n.id);
26.77 + } else {
26.78 + return INVALID;
26.79 + }
26.80 + }
26.81 +
26.82 + /// \brief Gives back the edge comes from up into the node.
26.83 + ///
26.84 + /// Gives back the edge comes from up into the node. If there is not
26.85 + /// incoming edge then it gives back INVALID.
26.86 + Edge _up(Node n) const {
26.87 + if (n.id >= _width) {
26.88 + return Edge(n.id - _width);
26.89 + } else {
26.90 + return INVALID;
26.91 + }
26.92 + }
26.93 +
26.94 + /// \brief Gives back the edge goes right from the node.
26.95 + ///
26.96 + /// Gives back the edge goes right from the node. If there is not
26.97 + /// outgoing edge then it gives back INVALID.
26.98 + Edge _right(Node n) const {
26.99 + if (n.id % _width < _width - 1) {
26.100 + return _edgeLimit + n.id % _width + (n.id / _width) * (_width - 1);
26.101 + } else {
26.102 + return INVALID;
26.103 + }
26.104 + }
26.105 +
26.106 + /// \brief Gives back the edge comes from left into the node.
26.107 + ///
26.108 + /// Gives back the edge comes left up into the node. If there is not
26.109 + /// incoming edge then it gives back INVALID.
26.110 + Edge _left(Node n) const {
26.111 + if (n.id % _width > 0) {
26.112 + return _edgeLimit + n.id % _width + (n.id / _width) * (_width - 1) - 1;
26.113 + } else {
26.114 + return INVALID;
26.115 + }
26.116 + }
26.117 +
26.118 + public:
26.119 +
26.120 + class IndexError : public RuntimeError {
26.121 + public:
26.122 + virtual const char* exceptionName() const {
26.123 + return "lemon::GridUGraph::IndexError";
26.124 + }
26.125 + };
26.126 +
26.127 +
26.128 + /// \brief The node on the given position.
26.129 + ///
26.130 + /// Gives back the node on the given position.
26.131 + Node operator()(int i, int j) const {
26.132 + LEMON_ASSERT(0 <= i && i < width() && 0 <= j && j < height(), IndexError());
26.133 + return Node(i + j * _width);
26.134 + }
26.135 +
26.136 + /// \brief Gives back the row index of the node.
26.137 + ///
26.138 + /// Gives back the row index of the node.
26.139 + int row(Node n) const {
26.140 + return n.id / _width;
26.141 + }
26.142 +
26.143 + /// \brief Gives back the coloumn index of the node.
26.144 + ///
26.145 + /// Gives back the coloumn index of the node.
26.146 + int col(Node n) const {
26.147 + return n.id % _width;
26.148 + }
26.149 +
26.150 + /// \brief Gives back the width of the graph.
26.151 + ///
26.152 + /// Gives back the width of the graph.
26.153 + int width() const {
26.154 + return _width;
26.155 + }
26.156 +
26.157 + /// \brief Gives back the height of the graph.
26.158 + ///
26.159 + /// Gives back the height of the graph.
26.160 + int height() const {
26.161 + return _height;
26.162 + }
26.163 +
26.164 + typedef True NodeNumTag;
26.165 + typedef True EdgeNumTag;
26.166 +
26.167 + ///Number of nodes.
26.168 + int nodeNum() const { return _nodeNum; }
26.169 + ///Number of edges.
26.170 + int edgeNum() const { return _edgeNum; }
26.171 +
26.172 + /// Maximum node ID.
26.173 +
26.174 + /// Maximum node ID.
26.175 + ///\sa id(Node)
26.176 + int maxNodeId() const { return nodeNum() - 1; }
26.177 + /// Maximum edge ID.
26.178 +
26.179 + /// Maximum edge ID.
26.180 + ///\sa id(Edge)
26.181 + int maxEdgeId() const { return edgeNum() - 1; }
26.182 +
26.183 + /// \brief Gives back the source node of an edge.
26.184 + ///
26.185 + /// Gives back the source node of an edge.
26.186 + Node source(Edge e) const {
26.187 + if (e.id < _edgeLimit) {
26.188 + return e.id;
26.189 + } else {
26.190 + return (e.id - _edgeLimit) % (_width - 1) +
26.191 + (e.id - _edgeLimit) / (_width - 1) * _width;
26.192 + }
26.193 + }
26.194 +
26.195 + /// \brief Gives back the target node of an edge.
26.196 + ///
26.197 + /// Gives back the target node of an edge.
26.198 + Node target(Edge e) const {
26.199 + if (e.id < _edgeLimit) {
26.200 + return e.id + _width;
26.201 + } else {
26.202 + return (e.id - _edgeLimit) % (_width - 1) +
26.203 + (e.id - _edgeLimit) / (_width - 1) * _width + 1;
26.204 + }
26.205 + }
26.206 +
26.207 + /// Node ID.
26.208 +
26.209 + /// The ID of a valid Node is a nonnegative integer not greater than
26.210 + /// \ref maxNodeId(). The range of the ID's is not surely continuous
26.211 + /// and the greatest node ID can be actually less then \ref maxNodeId().
26.212 + ///
26.213 + /// The ID of the \ref INVALID node is -1.
26.214 + ///\return The ID of the node \c v.
26.215 +
26.216 + static int id(Node v) { return v.id; }
26.217 + /// Edge ID.
26.218 +
26.219 + /// The ID of a valid Edge is a nonnegative integer not greater than
26.220 + /// \ref maxEdgeId(). The range of the ID's is not surely continuous
26.221 + /// and the greatest edge ID can be actually less then \ref maxEdgeId().
26.222 + ///
26.223 + /// The ID of the \ref INVALID edge is -1.
26.224 + ///\return The ID of the edge \c e.
26.225 + static int id(Edge e) { return e.id; }
26.226 +
26.227 + static Node nodeFromId(int id) { return Node(id);}
26.228 +
26.229 + static Edge edgeFromId(int id) { return Edge(id);}
26.230 +
26.231 + typedef True FindEdgeTag;
26.232 +
26.233 + /// Finds an edge between two nodes.
26.234 +
26.235 + /// Finds an edge from node \c u to node \c v.
26.236 + ///
26.237 + /// If \c prev is \ref INVALID (this is the default value), then
26.238 + /// It finds the first edge from \c u to \c v. Otherwise it looks for
26.239 + /// the next edge from \c u to \c v after \c prev.
26.240 + /// \return The found edge or INVALID if there is no such an edge.
26.241 + Edge findEdge(Node u, Node v, Edge prev = INVALID) const {
26.242 + if (prev != INVALID) return INVALID;
26.243 + if (v.id - u.id == _width) return Edge(u.id);
26.244 + if (v.id - u.id == 1 && u.id % _width < _width - 1) {
26.245 + return Edge(u.id / _width * (_width - 1) +
26.246 + u.id % _width + _edgeLimit);
26.247 + }
26.248 + return INVALID;
26.249 + }
26.250 +
26.251 +
26.252 + class Node {
26.253 + friend class GridUGraphBase;
26.254 +
26.255 + protected:
26.256 + int id;
26.257 + Node(int _id) { id = _id;}
26.258 + public:
26.259 + Node() {}
26.260 + Node (Invalid) { id = -1; }
26.261 + bool operator==(const Node node) const {return id == node.id;}
26.262 + bool operator!=(const Node node) const {return id != node.id;}
26.263 + bool operator<(const Node node) const {return id < node.id;}
26.264 + };
26.265 +
26.266 +
26.267 +
26.268 + class Edge {
26.269 + friend class GridUGraphBase;
26.270 +
26.271 + protected:
26.272 + int id;
26.273 +
26.274 + Edge(int _id) : id(_id) {}
26.275 +
26.276 + public:
26.277 + Edge() { }
26.278 + Edge (Invalid) { id = -1; }
26.279 + bool operator==(const Edge edge) const {return id == edge.id;}
26.280 + bool operator!=(const Edge edge) const {return id != edge.id;}
26.281 + bool operator<(const Edge edge) const {return id < edge.id;}
26.282 + };
26.283 +
26.284 + void first(Node& node) const {
26.285 + node.id = nodeNum() - 1;
26.286 + }
26.287 +
26.288 + static void next(Node& node) {
26.289 + --node.id;
26.290 + }
26.291 +
26.292 + void first(Edge& edge) const {
26.293 + edge.id = edgeNum() - 1;
26.294 + }
26.295 +
26.296 + static void next(Edge& edge) {
26.297 + --edge.id;
26.298 + }
26.299 +
26.300 + void firstOut(Edge& edge, const Node& node) const {
26.301 + if (node.id < _nodeNum - _width) {
26.302 + edge.id = node.id;
26.303 + } else if (node.id % _width < _width - 1) {
26.304 + edge.id = _edgeLimit + node.id % _width +
26.305 + (node.id / _width) * (_width - 1);
26.306 + } else {
26.307 + edge.id = -1;
26.308 + }
26.309 + }
26.310 +
26.311 + void nextOut(Edge& edge) const {
26.312 + if (edge.id >= _edgeLimit) {
26.313 + edge.id = -1;
26.314 + } else if (edge.id % _width < _width - 1) {
26.315 + edge.id = _edgeLimit + edge.id % _width +
26.316 + (edge.id / _width) * (_width - 1);
26.317 + } else {
26.318 + edge.id = -1;
26.319 + }
26.320 + }
26.321 +
26.322 + void firstIn(Edge& edge, const Node& node) const {
26.323 + if (node.id >= _width) {
26.324 + edge.id = node.id - _width;
26.325 + } else if (node.id % _width > 0) {
26.326 + edge.id = _edgeLimit + node.id % _width +
26.327 + (node.id / _width) * (_width - 1) - 1;
26.328 + } else {
26.329 + edge.id = -1;
26.330 + }
26.331 + }
26.332 +
26.333 + void nextIn(Edge& edge) const {
26.334 + if (edge.id >= _edgeLimit) {
26.335 + edge.id = -1;
26.336 + } else if (edge.id % _width > 0) {
26.337 + edge.id = _edgeLimit + edge.id % _width +
26.338 + (edge.id / _width + 1) * (_width - 1) - 1;
26.339 + } else {
26.340 + edge.id = -1;
26.341 + }
26.342 + }
26.343 +
26.344 + private:
26.345 + int _width, _height;
26.346 + int _nodeNum, _edgeNum;
26.347 + int _edgeLimit;
26.348 + };
26.349 +
26.350 +
26.351 + typedef UGraphExtender<UGraphBaseExtender<
26.352 + GridUGraphBase> > ExtendedGridUGraphBase;
26.353 +
26.354 + /// \ingroup graphs
26.355 + ///
26.356 + /// \brief Grid graph class
26.357 + ///
26.358 + /// This class implements a special graph type. The nodes of the
26.359 + /// graph can be indiced by two integer \c (i,j) value where \c i
26.360 + /// is in the \c [0,width) range and j is in the [0, height) range.
26.361 + /// Two nodes are connected in the graph if the indices differ only
26.362 + /// on one position and only one is the difference.
26.363 + ///
26.364 + /// The graph can be indiced in the following way:
26.365 + ///\code
26.366 + /// GridUGraph graph(w, h);
26.367 + /// GridUGraph::NodeMap<int> val(graph);
26.368 + /// for (int i = 0; i < graph.width(); ++i) {
26.369 + /// for (int j = 0; j < graph.height(); ++j) {
26.370 + /// val[graph(i, j)] = i + j;
26.371 + /// }
26.372 + /// }
26.373 + ///\endcode
26.374 + ///
26.375 + /// The graph type is fully conform to the \ref concept::UUGraph
26.376 + /// "Undirected UGraph" concept.
26.377 + ///
26.378 + /// \author Balazs Dezso
26.379 + /// \see GridUGraphBase
26.380 + class GridUGraph : public ExtendedGridUGraphBase {
26.381 + public:
26.382 +
26.383 + typedef ExtendedGridUGraphBase Parent;
26.384 +
26.385 + /// \brief Map to get the indices of the nodes as xy<int>.
26.386 + ///
26.387 + /// Map to get the indices of the nodes as xy<int>.
26.388 + class IndexMap {
26.389 + public:
26.390 + /// \brief The key type of the map
26.391 + typedef GridUGraph::Node Key;
26.392 + /// \brief The value type of the map
26.393 + typedef xy<int> Value;
26.394 +
26.395 + /// \brief Constructor
26.396 + ///
26.397 + /// Constructor
26.398 + IndexMap(const GridUGraph& _graph) : graph(_graph) {}
26.399 +
26.400 + /// \brief The subscript operator
26.401 + ///
26.402 + /// The subscript operator.
26.403 + Value operator[](Key key) const {
26.404 + return xy<int>(graph.row(key), graph.col(key));
26.405 + }
26.406 +
26.407 + private:
26.408 + const GridUGraph& graph;
26.409 + };
26.410 +
26.411 + /// \brief Map to get the row of the nodes.
26.412 + ///
26.413 + /// Map to get the row of the nodes.
26.414 + class RowMap {
26.415 + public:
26.416 + /// \brief The key type of the map
26.417 + typedef GridUGraph::Node Key;
26.418 + /// \brief The value type of the map
26.419 + typedef int Value;
26.420 +
26.421 + /// \brief Constructor
26.422 + ///
26.423 + /// Constructor
26.424 + RowMap(const GridUGraph& _graph) : graph(_graph) {}
26.425 +
26.426 + /// \brief The subscript operator
26.427 + ///
26.428 + /// The subscript operator.
26.429 + Value operator[](Key key) const {
26.430 + return graph.row(key);
26.431 + }
26.432 +
26.433 + private:
26.434 + const GridUGraph& graph;
26.435 + };
26.436 +
26.437 + /// \brief Map to get the column of the nodes.
26.438 + ///
26.439 + /// Map to get the column of the nodes.
26.440 + class ColMap {
26.441 + public:
26.442 + /// \brief The key type of the map
26.443 + typedef GridUGraph::Node Key;
26.444 + /// \brief The value type of the map
26.445 + typedef int Value;
26.446 +
26.447 + /// \brief Constructor
26.448 + ///
26.449 + /// Constructor
26.450 + ColMap(const GridUGraph& _graph) : graph(_graph) {}
26.451 +
26.452 + /// \brief The subscript operator
26.453 + ///
26.454 + /// The subscript operator.
26.455 + Value operator[](Key key) const {
26.456 + return graph.col(key);
26.457 + }
26.458 +
26.459 + private:
26.460 + const GridUGraph& graph;
26.461 + };
26.462 +
26.463 + /// \brief Constructor
26.464 + ///
26.465 + ///
26.466 + GridUGraph(int n, int m) { construct(n, m); }
26.467 +
26.468 + /// \brief Resize the graph
26.469 + ///
26.470 + void resize(int n, int m) {
26.471 + Parent::getNotifier(Edge()).clear();
26.472 + Parent::getNotifier(UEdge()).clear();
26.473 + Parent::getNotifier(Node()).clear();
26.474 + construct(n, m);
26.475 + Parent::getNotifier(Node()).build();
26.476 + Parent::getNotifier(UEdge()).build();
26.477 + Parent::getNotifier(Edge()).build();
26.478 + }
26.479 +
26.480 + /// \brief Gives back the edge goes down from the node.
26.481 + ///
26.482 + /// Gives back the edge goes down from the node. If there is not
26.483 + /// outgoing edge then it gives back INVALID.
26.484 + Edge down(Node n) const {
26.485 + UEdge ue = _down(n);
26.486 + return ue != INVALID ? direct(ue, true) : INVALID;
26.487 + }
26.488 +
26.489 + /// \brief Gives back the edge goes up from the node.
26.490 + ///
26.491 + /// Gives back the edge goes up from the node. If there is not
26.492 + /// outgoing edge then it gives back INVALID.
26.493 + Edge up(Node n) const {
26.494 + UEdge ue = _up(n);
26.495 + return ue != INVALID ? direct(ue, false) : INVALID;
26.496 + }
26.497 +
26.498 + /// \brief Gives back the edge goes right from the node.
26.499 + ///
26.500 + /// Gives back the edge goes right from the node. If there is not
26.501 + /// outgoing edge then it gives back INVALID.
26.502 + Edge right(Node n) const {
26.503 + UEdge ue = _right(n);
26.504 + return ue != INVALID ? direct(ue, true) : INVALID;
26.505 + }
26.506 +
26.507 + /// \brief Gives back the edge goes left from the node.
26.508 + ///
26.509 + /// Gives back the edge goes left from the node. If there is not
26.510 + /// outgoing edge then it gives back INVALID.
26.511 + Edge left(Node n) const {
26.512 + UEdge ue = _left(n);
26.513 + return ue != INVALID ? direct(ue, false) : INVALID;
26.514 + }
26.515 +
26.516 + };
26.517 +
26.518 + /// \brief Index map of the grid graph
26.519 + ///
26.520 + /// Just returns an IndexMap for the grid graph.
26.521 + GridUGraph::IndexMap indexMap(const GridUGraph& graph) {
26.522 + return GridUGraph::IndexMap(graph);
26.523 + }
26.524 +
26.525 + /// \brief Row map of the grid graph
26.526 + ///
26.527 + /// Just returns a RowMap for the grid graph.
26.528 + GridUGraph::RowMap rowMap(const GridUGraph& graph) {
26.529 + return GridUGraph::RowMap(graph);
26.530 + }
26.531 +
26.532 + /// \brief Column map of the grid graph
26.533 + ///
26.534 + /// Just returns a ColMap for the grid graph.
26.535 + GridUGraph::ColMap colMap(const GridUGraph& graph) {
26.536 + return GridUGraph::ColMap(graph);
26.537 + }
26.538 +}
26.539 +#endif
27.1 --- a/lemon/hypercube_graph.h Wed Feb 22 12:45:59 2006 +0000
27.2 +++ b/lemon/hypercube_graph.h Wed Feb 22 18:26:56 2006 +0000
27.3 @@ -25,9 +25,6 @@
27.4 #include <lemon/utility.h>
27.5 #include <lemon/error.h>
27.6
27.7 -#include <lemon/bits/iterable_graph_extender.h>
27.8 -#include <lemon/bits/alteration_notifier.h>
27.9 -#include <lemon/bits/static_map.h>
27.10 #include <lemon/bits/graph_extender.h>
27.11
27.12 ///\ingroup graphs
27.13 @@ -236,11 +233,7 @@
27.14 };
27.15
27.16
27.17 - typedef StaticMappableGraphExtender<
27.18 - IterableGraphExtender<
27.19 - AlterableGraphExtender<
27.20 - GraphExtender<
27.21 - HyperCubeGraphBase> > > > ExtendedHyperCubeGraphBase;
27.22 + typedef GraphExtender<HyperCubeGraphBase> ExtendedHyperCubeGraphBase;
27.23
27.24 /// \ingroup graphs
27.25 ///
28.1 --- a/lemon/kruskal.h Wed Feb 22 12:45:59 2006 +0000
28.2 +++ b/lemon/kruskal.h Wed Feb 22 18:26:56 2006 +0000
28.3 @@ -23,6 +23,7 @@
28.4 #include <vector>
28.5 #include <lemon/unionfind.h>
28.6 #include <lemon/utility.h>
28.7 +#include <lemon/traits.h>
28.8
28.9 /**
28.10 @defgroup spantree Minimum Cost Spanning Tree Algorithms
28.11 @@ -228,7 +229,7 @@
28.12 };
28.13
28.14 template<class _GR>
28.15 - typename enable_if<typename _GR::UTag,void>::type
28.16 + typename enable_if<UndirectedTagIndicator<_GR>,void>::type
28.17 fillWithEdges(const _GR& g, const Map& m,dummy<0> = 0)
28.18 {
28.19 for(typename GR::UEdgeIt e(g);e!=INVALID;++e)
28.20 @@ -236,7 +237,7 @@
28.21 }
28.22
28.23 template<class _GR>
28.24 - typename disable_if<typename _GR::UTag,void>::type
28.25 + typename disable_if<UndirectedTagIndicator<_GR>,void>::type
28.26 fillWithEdges(const _GR& g, const Map& m,dummy<1> = 1)
28.27 {
28.28 for(typename GR::EdgeIt e(g);e!=INVALID;++e)
29.1 --- a/lemon/list_graph.h Wed Feb 22 12:45:59 2006 +0000
29.2 +++ b/lemon/list_graph.h Wed Feb 22 18:26:56 2006 +0000
29.3 @@ -23,16 +23,11 @@
29.4 ///\file
29.5 ///\brief ListGraph, ListUGraph classes.
29.6
29.7 -#include <lemon/bits/erasable_graph_extender.h>
29.8 -#include <lemon/bits/clearable_graph_extender.h>
29.9 -#include <lemon/bits/extendable_graph_extender.h>
29.10 -#include <lemon/bits/iterable_graph_extender.h>
29.11 -#include <lemon/bits/alteration_notifier.h>
29.12 -#include <lemon/bits/default_map.h>
29.13 #include <lemon/bits/graph_extender.h>
29.14
29.15 #include <lemon/error.h>
29.16
29.17 +#include <vector>
29.18 #include <list>
29.19
29.20 namespace lemon {
29.21 @@ -311,13 +306,7 @@
29.22
29.23 };
29.24
29.25 - typedef ErasableGraphExtender<
29.26 - ClearableGraphExtender<
29.27 - ExtendableGraphExtender<
29.28 - MappableGraphExtender<
29.29 - IterableGraphExtender<
29.30 - AlterableGraphExtender<
29.31 - GraphExtender<ListGraphBase> > > > > > > ExtendedListGraphBase;
29.32 + typedef GraphExtender<ListGraphBase> ExtendedListGraphBase;
29.33
29.34 /// \addtogroup graphs
29.35 /// @{
29.36 @@ -578,13 +567,8 @@
29.37
29.38 /**************** Undirected List Graph ****************/
29.39
29.40 - typedef ErasableUGraphExtender<
29.41 - ClearableUGraphExtender<
29.42 - ExtendableUGraphExtender<
29.43 - MappableUGraphExtender<
29.44 - IterableUGraphExtender<
29.45 - AlterableUGraphExtender<
29.46 - UGraphExtender<ListGraphBase> > > > > > > ExtendedListUGraphBase;
29.47 + typedef UGraphExtender<UGraphBaseExtender<
29.48 + ListGraphBase> > ExtendedListUGraphBase;
29.49
29.50 /// \addtogroup graphs
29.51 /// @{
30.1 --- a/lemon/prim.h Wed Feb 22 12:45:59 2006 +0000
30.2 +++ b/lemon/prim.h Wed Feb 22 18:26:56 2006 +0000
30.3 @@ -788,7 +788,7 @@
30.4 Create prm(graph,cost);
30.5 prm.treeMap(tree);
30.6 prm.run();
30.7 - };
30.8 + }
30.9
30.10 } //END OF NAMESPACE LEMON
30.11
31.1 --- a/lemon/radix_sort.h Wed Feb 22 12:45:59 2006 +0000
31.2 +++ b/lemon/radix_sort.h Wed Feb 22 18:26:56 2006 +0000
31.3 @@ -264,7 +264,7 @@
31.4 int byte, Functor functor) {
31.5 const int size =
31.6 (unsigned int)std::numeric_limits<unsigned char>::max() + 1;
31.7 - int counter[size];
31.8 + std::vector<int> counter(size);
31.9 for (int i = 0; i < size; ++i) {
31.10 counter[i] = 0;
31.11 }
31.12 @@ -290,7 +290,7 @@
31.13 int byte, Functor functor) {
31.14 const int size =
31.15 (unsigned int)std::numeric_limits<unsigned char>::max() + 1;
31.16 - int counter[size];
31.17 + std::vector<int> counter(size);
31.18 for (int i = 0; i < size; ++i) {
31.19 counter[i] = 0;
31.20 }
32.1 --- a/lemon/smart_graph.h Wed Feb 22 12:45:59 2006 +0000
32.2 +++ b/lemon/smart_graph.h Wed Feb 22 18:26:56 2006 +0000
32.3 @@ -27,16 +27,13 @@
32.4
32.5 #include <lemon/invalid.h>
32.6
32.7 -#include <lemon/bits/clearable_graph_extender.h>
32.8 -#include <lemon/bits/extendable_graph_extender.h>
32.9 -#include <lemon/bits/iterable_graph_extender.h>
32.10 -#include <lemon/bits/alteration_notifier.h>
32.11 -#include <lemon/bits/default_map.h>
32.12 #include <lemon/bits/graph_extender.h>
32.13
32.14 #include <lemon/utility.h>
32.15 #include <lemon/error.h>
32.16
32.17 +#include <lemon/bits/graph_extender.h>
32.18 +
32.19 namespace lemon {
32.20
32.21 class SmartGraph;
32.22 @@ -222,12 +219,7 @@
32.23
32.24 };
32.25
32.26 - typedef ClearableGraphExtender<
32.27 - ExtendableGraphExtender<
32.28 - MappableGraphExtender<
32.29 - IterableGraphExtender<
32.30 - AlterableGraphExtender<
32.31 - GraphExtender<SmartGraphBase> > > > > > ExtendedSmartGraphBase;
32.32 + typedef GraphExtender<SmartGraphBase> ExtendedSmartGraphBase;
32.33
32.34 /// \ingroup graphs
32.35
32.36 @@ -244,7 +236,9 @@
32.37 ///\author Alpar Juttner
32.38 class SmartGraph : public ExtendedSmartGraphBase {
32.39 public:
32.40 -
32.41 +
32.42 + typedef ExtendedSmartGraphBase Parent;
32.43 +
32.44 class Snapshot;
32.45 friend class Snapshot;
32.46
32.47 @@ -355,12 +349,8 @@
32.48
32.49 /**************** Undirected List Graph ****************/
32.50
32.51 - typedef ClearableUGraphExtender<
32.52 - ExtendableUGraphExtender<
32.53 - MappableUGraphExtender<
32.54 - IterableUGraphExtender<
32.55 - AlterableUGraphExtender<
32.56 - UGraphExtender<SmartGraphBase> > > > > > ExtendedSmartUGraphBase;
32.57 + typedef UGraphExtender<UGraphBaseExtender<SmartGraphBase> >
32.58 + ExtendedSmartUGraphBase;
32.59
32.60 /// \ingroup graphs
32.61 ///
32.62 @@ -587,14 +577,8 @@
32.63 };
32.64
32.65
32.66 - typedef ClearableBpUGraphExtender<
32.67 - ExtendableBpUGraphExtender<
32.68 - MappableBpUGraphExtender<
32.69 - IterableBpUGraphExtender<
32.70 - AlterableBpUGraphExtender<
32.71 - BpUGraphExtender <
32.72 - SmartBpUGraphBase> > > > > >
32.73 - ExtendedSmartBpUGraphBase;
32.74 + typedef BpUGraphExtender< BpUGraphBaseExtender<
32.75 + SmartBpUGraphBase> > ExtendedSmartBpUGraphBase;
32.76
32.77 /// \ingroup graphs
32.78 ///
33.1 --- a/lemon/sub_graph.h Wed Feb 22 12:45:59 2006 +0000
33.2 +++ b/lemon/sub_graph.h Wed Feb 22 18:26:56 2006 +0000
33.3 @@ -386,9 +386,9 @@
33.4 /// \see EdgeSubGraphBase
33.5 template <typename Graph>
33.6 class SubGraph
33.7 - : public IterableGraphExtender< SubGraphBase<Graph> > {
33.8 + : public GraphAdaptorExtender< SubGraphBase<Graph> > {
33.9 public:
33.10 - typedef IterableGraphExtender< SubGraphBase<Graph> > Parent;
33.11 + typedef GraphAdaptorExtender< SubGraphBase<Graph> > Parent;
33.12 public:
33.13 /// \brief Constructor for sub-graph.
33.14 ///
33.15 @@ -683,9 +683,9 @@
33.16 /// \see EdgeSubGraphBase
33.17 template <typename Graph>
33.18 class EdgeSubGraph
33.19 - : public IterableGraphExtender< EdgeSubGraphBase<Graph> > {
33.20 + : public GraphAdaptorExtender< EdgeSubGraphBase<Graph> > {
33.21 public:
33.22 - typedef IterableGraphExtender< EdgeSubGraphBase<Graph> > Parent;
33.23 + typedef GraphAdaptorExtender< EdgeSubGraphBase<Graph> > Parent;
33.24 public:
33.25 /// \brief Constructor for sub-graph.
33.26 ///
34.1 --- a/lemon/topology.h Wed Feb 22 12:45:59 2006 +0000
34.2 +++ b/lemon/topology.h Wed Feb 22 18:26:56 2006 +0000
34.3 @@ -1417,7 +1417,7 @@
34.4 if(bfs.dist(graph.source(i))==bfs.dist(graph.target(i)))return false;
34.5 }
34.6 return true;
34.7 - };
34.8 + }
34.9
34.10 /// \ingroup topology
34.11 ///
34.12 @@ -1459,7 +1459,7 @@
34.13 if(bfs.dist(graph.source(i)) == bfs.dist(graph.target(i)))return false;
34.14 }
34.15 return true;
34.16 - };
34.17 + }
34.18
34.19 } //namespace lemon
34.20
35.1 --- a/lemon/traits.h Wed Feb 22 12:45:59 2006 +0000
35.2 +++ b/lemon/traits.h Wed Feb 22 18:26:56 2006 +0000
35.3 @@ -209,6 +209,19 @@
35.4 static const bool value = true;
35.5 };
35.6
35.7 + template <typename Graph, typename Enable = void>
35.8 + struct UndirectedTagIndicator {
35.9 + static const bool value = false;
35.10 + };
35.11 +
35.12 + template <typename Graph>
35.13 + struct UndirectedTagIndicator<
35.14 + Graph,
35.15 + typename enable_if<typename Graph::UndirectedTag, void>::type
35.16 + > {
35.17 + static const bool value = true;
35.18 + };
35.19 +
35.20
35.21
35.22 }
36.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
36.2 +++ b/lemon/ugraph_adaptor.h Wed Feb 22 18:26:56 2006 +0000
36.3 @@ -0,0 +1,803 @@
36.4 +/* -*- C++ -*-
36.5 + *
36.6 + * This file is a part of LEMON, a generic C++ optimization library
36.7 + *
36.8 + * Copyright (C) 2003-2006
36.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
36.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
36.11 + *
36.12 + * Permission to use, modify and distribute this software is granted
36.13 + * provided that this copyright notice appears in all copies. For
36.14 + * precise terms see the accompanying LICENSE file.
36.15 + *
36.16 + * This software is provided "AS IS" with no warranty of any kind,
36.17 + * express or implied, and with no claim as to its suitability for any
36.18 + * purpose.
36.19 + *
36.20 + */
36.21 +
36.22 +#ifndef LEMON_UGRAPH_ADAPTOR_H
36.23 +#define LEMON_UGRAPH_ADAPTOR_H
36.24 +
36.25 +///\ingroup graph_adaptors
36.26 +///\file
36.27 +///\brief Several graph adaptors.
36.28 +///
36.29 +///This file contains several useful ugraph adaptor functions.
36.30 +///
36.31 +///\author Balazs Dezso
36.32 +
36.33 +#include <lemon/invalid.h>
36.34 +#include <lemon/maps.h>
36.35 +
36.36 +#include <lemon/bits/graph_adaptor_extender.h>
36.37 +
36.38 +#include <lemon/traits.h>
36.39 +
36.40 +#include <iostream>
36.41 +
36.42 +namespace lemon {
36.43 +
36.44 + /// \ingroup graph_adaptors
36.45 + ///
36.46 + /// \brief Base type for the Graph Adaptors
36.47 + ///
36.48 + /// \warning Graph adaptors are in even more experimental state than the
36.49 + /// other parts of the lib. Use them at you own risk.
36.50 + ///
36.51 + /// This is the base type for most of LEMON graph adaptors.
36.52 + /// This class implements a trivial graph adaptor i.e. it only wraps the
36.53 + /// functions and types of the graph. The purpose of this class is to
36.54 + /// make easier implementing graph adaptors. E.g. if an adaptor is
36.55 + /// considered which differs from the wrapped graph only in some of its
36.56 + /// functions or types, then it can be derived from GraphAdaptor, and only
36.57 + /// the differences should be implemented.
36.58 + ///
36.59 + /// \author Balazs Dezso
36.60 + template<typename _UGraph>
36.61 + class UGraphAdaptorBase {
36.62 + public:
36.63 + typedef _UGraph Graph;
36.64 + typedef Graph ParentGraph;
36.65 +
36.66 + protected:
36.67 + Graph* graph;
36.68 +
36.69 + UGraphAdaptorBase() : graph(0) {}
36.70 +
36.71 + void setGraph(Graph& _graph) { graph=&_graph; }
36.72 +
36.73 + Graph& getGraph() { return *graph; }
36.74 + const Graph& getGraph() const { return *graph; }
36.75 +
36.76 + public:
36.77 + UGraphAdaptorBase(Graph& _graph) : graph(&_graph) {}
36.78 +
36.79 + typedef typename Graph::Node Node;
36.80 + typedef typename Graph::Edge Edge;
36.81 + typedef typename Graph::UEdge UEdge;
36.82 +
36.83 + void first(Node& i) const { graph->first(i); }
36.84 + void first(Edge& i) const { graph->first(i); }
36.85 + void first(UEdge& i) const { graph->first(i); }
36.86 + void firstIn(Edge& i, const Node& n) const { graph->firstIn(i, n); }
36.87 + void firstOut(Edge& i, const Node& n ) const { graph->firstOut(i, n); }
36.88 + void firstInc(UEdge &i, bool &d, const Node &n) const {
36.89 + graph->firstInc(i, d, n);
36.90 + }
36.91 +
36.92 + void next(Node& i) const { graph->next(i); }
36.93 + void next(Edge& i) const { graph->next(i); }
36.94 + void next(UEdge& i) const { graph->next(i); }
36.95 + void nextIn(Edge& i) const { graph->nextIn(i); }
36.96 + void nextOut(Edge& i) const { graph->nextOut(i); }
36.97 + void nextInc(UEdge &i, bool &d) const { graph->nextInc(i, d); }
36.98 +
36.99 +
36.100 + Node source(const UEdge& e) const { return graph->source(e); }
36.101 + Node target(const UEdge& e) const { return graph->target(e); }
36.102 +
36.103 + Node source(const Edge& e) const { return graph->source(e); }
36.104 + Node target(const Edge& e) const { return graph->target(e); }
36.105 +
36.106 + typedef NodeNumTagIndicator<Graph> NodeNumTag;
36.107 + int nodeNum() const { return graph->nodeNum(); }
36.108 +
36.109 + typedef EdgeNumTagIndicator<Graph> EdgeNumTag;
36.110 + int edgeNum() const { return graph->edgeNum(); }
36.111 +
36.112 + typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
36.113 + Edge findEdge(const Node& source, const Node& target,
36.114 + const Edge& prev = INVALID) {
36.115 + return graph->findEdge(source, target, prev);
36.116 + }
36.117 +
36.118 + UEdge findUEdge(const Node& source, const Node& target,
36.119 + const UEdge& prev = INVALID) {
36.120 + return graph->findUEdge(source, target, prev);
36.121 + }
36.122 +
36.123 + Node addNode() const { return graph->addNode(); }
36.124 + UEdge addEdge(const Node& source, const Node& target) const {
36.125 + return graph->addEdge(source, target);
36.126 + }
36.127 +
36.128 + void erase(const Node& i) const { graph->erase(i); }
36.129 + void erase(const Edge& i) const { graph->erase(i); }
36.130 +
36.131 + void clear() const { graph->clear(); }
36.132 +
36.133 + int id(const Node& v) const { return graph->id(v); }
36.134 + int id(const UEdge& e) const { return graph->id(e); }
36.135 +
36.136 + bool direction(const Edge& e) const { return graph->direction(e); }
36.137 + Edge direct(const UEdge& e, bool d) const { return graph->direct(e, d); }
36.138 + Edge direct(const UEdge& e, const Node& n) const {
36.139 + return graph->direct(e, n);
36.140 + }
36.141 +
36.142 + Node oppositeNode(const Node& n, const Edge& e) const {
36.143 + return graph->oppositeNode(n, e);
36.144 + }
36.145 +
36.146 + Edge oppositeEdge(const Edge& e) const {
36.147 + return graph->oppositeEdge(e);
36.148 + }
36.149 +
36.150 +
36.151 + template <typename _Value>
36.152 + class NodeMap : public Graph::template NodeMap<_Value> {
36.153 + public:
36.154 + typedef typename Graph::template NodeMap<_Value> Parent;
36.155 + explicit NodeMap(const UGraphAdaptorBase<Graph>& ga)
36.156 + : Parent(*ga.graph) {}
36.157 + NodeMap(const UGraphAdaptorBase<Graph>& ga, const _Value& value)
36.158 + : Parent(*ga.graph, value) {}
36.159 +
36.160 + NodeMap& operator=(const NodeMap& cmap) {
36.161 + return operator=<NodeMap>(cmap);
36.162 + }
36.163 +
36.164 + template <typename CMap>
36.165 + NodeMap& operator=(const CMap& cmap) {
36.166 + checkConcept<concept::ReadMap<Node, _Value>, CMap>();
36.167 + const typename Parent::Graph* graph = Parent::getGraph();
36.168 + Node it;
36.169 + for (graph->first(it); it != INVALID; graph->next(it)) {
36.170 + Parent::set(it, cmap[it]);
36.171 + }
36.172 + return *this;
36.173 + }
36.174 + };
36.175 +
36.176 + template <typename _Value>
36.177 + class EdgeMap : public Graph::template EdgeMap<_Value> {
36.178 + public:
36.179 + typedef typename Graph::template EdgeMap<_Value> Parent;
36.180 + explicit EdgeMap(const UGraphAdaptorBase<Graph>& ga)
36.181 + : Parent(*ga.graph) {}
36.182 + EdgeMap(const UGraphAdaptorBase<Graph>& ga, const _Value& value)
36.183 + : Parent(*ga.graph, value) {}
36.184 +
36.185 + EdgeMap& operator=(const EdgeMap& cmap) {
36.186 + return operator=<EdgeMap>(cmap);
36.187 + }
36.188 +
36.189 + template <typename CMap>
36.190 + EdgeMap& operator=(const CMap& cmap) {
36.191 + checkConcept<concept::ReadMap<Edge, _Value>, CMap>();
36.192 + const typename Parent::Graph* graph = Parent::getGraph();
36.193 + Edge it;
36.194 + for (graph->first(it); it != INVALID; graph->next(it)) {
36.195 + Parent::set(it, cmap[it]);
36.196 + }
36.197 + return *this;
36.198 + }
36.199 + };
36.200 +
36.201 + template <typename _Value>
36.202 + class UEdgeMap : public Graph::template UEdgeMap<_Value> {
36.203 + public:
36.204 + typedef typename Graph::template UEdgeMap<_Value> Parent;
36.205 + explicit UEdgeMap(const UGraphAdaptorBase<Graph>& ga)
36.206 + : Parent(*ga.graph) {}
36.207 + UEdgeMap(const UGraphAdaptorBase<Graph>& ga, const _Value& value)
36.208 + : Parent(*ga.graph, value) {}
36.209 +
36.210 + UEdgeMap& operator=(const UEdgeMap& cmap) {
36.211 + return operator=<UEdgeMap>(cmap);
36.212 + }
36.213 +
36.214 + template <typename CMap>
36.215 + UEdgeMap& operator=(const CMap& cmap) {
36.216 + checkConcept<concept::ReadMap<UEdge, _Value>, CMap>();
36.217 + const typename Parent::Graph* graph = Parent::getGraph();
36.218 + UEdge it;
36.219 + for (graph->first(it); it != INVALID; graph->next(it)) {
36.220 + Parent::set(it, cmap[it]);
36.221 + }
36.222 + return *this;
36.223 + }
36.224 + };
36.225 +
36.226 + };
36.227 +
36.228 + /// \ingroup graph_adaptors
36.229 + template <typename _UGraph>
36.230 + class UGraphAdaptor
36.231 + : public UGraphAdaptorExtender< UGraphAdaptorBase<_UGraph> > {
36.232 + public:
36.233 + typedef _UGraph Graph;
36.234 + typedef UGraphAdaptorExtender<UGraphAdaptorBase<_UGraph> > Parent;
36.235 + protected:
36.236 + UGraphAdaptor() : Parent() {}
36.237 +
36.238 + public:
36.239 + explicit UGraphAdaptor(Graph& _graph) { setGraph(_graph); }
36.240 + };
36.241 +
36.242 + template <typename _UGraph, typename NodeFilterMap,
36.243 + typename UEdgeFilterMap, bool checked = true>
36.244 + class SubUGraphAdaptorBase : public UGraphAdaptorBase<_UGraph> {
36.245 + public:
36.246 + typedef _UGraph Graph;
36.247 + typedef UGraphAdaptorBase<_UGraph> Parent;
36.248 + protected:
36.249 +
36.250 + NodeFilterMap* node_filter_map;
36.251 + UEdgeFilterMap* uedge_filter_map;
36.252 +
36.253 + SubUGraphAdaptorBase()
36.254 + : Parent(), node_filter_map(0), uedge_filter_map(0) { }
36.255 +
36.256 + void setNodeFilterMap(NodeFilterMap& _node_filter_map) {
36.257 + node_filter_map=&_node_filter_map;
36.258 + }
36.259 + void setUEdgeFilterMap(UEdgeFilterMap& _uedge_filter_map) {
36.260 + uedge_filter_map=&_uedge_filter_map;
36.261 + }
36.262 +
36.263 + public:
36.264 +
36.265 + typedef typename Parent::Node Node;
36.266 + typedef typename Parent::Edge Edge;
36.267 + typedef typename Parent::UEdge UEdge;
36.268 +
36.269 + void first(Node& i) const {
36.270 + Parent::first(i);
36.271 + while (i!=INVALID && !(*node_filter_map)[i]) Parent::next(i);
36.272 + }
36.273 +
36.274 + void first(Edge& i) const {
36.275 + Parent::first(i);
36.276 + while (i!=INVALID && (!(*uedge_filter_map)[i]
36.277 + || !(*node_filter_map)[Parent::source(i)]
36.278 + || !(*node_filter_map)[Parent::target(i)])) Parent::next(i);
36.279 + }
36.280 +
36.281 + void first(UEdge& i) const {
36.282 + Parent::first(i);
36.283 + while (i!=INVALID && (!(*uedge_filter_map)[i]
36.284 + || !(*node_filter_map)[Parent::source(i)]
36.285 + || !(*node_filter_map)[Parent::target(i)])) Parent::next(i);
36.286 + }
36.287 +
36.288 + void firstIn(Edge& i, const Node& n) const {
36.289 + Parent::firstIn(i, n);
36.290 + while (i!=INVALID && (!(*uedge_filter_map)[i]
36.291 + || !(*node_filter_map)[Parent::source(i)])) Parent::nextIn(i);
36.292 + }
36.293 +
36.294 + void firstOut(Edge& i, const Node& n) const {
36.295 + Parent::firstOut(i, n);
36.296 + while (i!=INVALID && (!(*uedge_filter_map)[i]
36.297 + || !(*node_filter_map)[Parent::target(i)])) Parent::nextOut(i);
36.298 + }
36.299 +
36.300 + void firstInc(UEdge& i, bool& d, const Node& n) const {
36.301 + Parent::firstInc(i, d, n);
36.302 + while (i!=INVALID && (!(*uedge_filter_map)[i]
36.303 + || !(*node_filter_map)[Parent::target(i)])) Parent::nextInc(i, d);
36.304 + }
36.305 +
36.306 + void next(Node& i) const {
36.307 + Parent::next(i);
36.308 + while (i!=INVALID && !(*node_filter_map)[i]) Parent::next(i);
36.309 + }
36.310 +
36.311 + void next(Edge& i) const {
36.312 + Parent::next(i);
36.313 + while (i!=INVALID && (!(*uedge_filter_map)[i]
36.314 + || !(*node_filter_map)[Parent::source(i)]
36.315 + || !(*node_filter_map)[Parent::target(i)])) Parent::next(i);
36.316 + }
36.317 +
36.318 + void next(UEdge& i) const {
36.319 + Parent::next(i);
36.320 + while (i!=INVALID && (!(*uedge_filter_map)[i]
36.321 + || !(*node_filter_map)[Parent::source(i)]
36.322 + || !(*node_filter_map)[Parent::target(i)])) Parent::next(i);
36.323 + }
36.324 +
36.325 + void nextIn(Edge& i) const {
36.326 + Parent::nextIn(i);
36.327 + while (i!=INVALID && (!(*uedge_filter_map)[i]
36.328 + || !(*node_filter_map)[Parent::source(i)])) Parent::nextIn(i);
36.329 + }
36.330 +
36.331 + void nextOut(Edge& i) const {
36.332 + Parent::nextOut(i);
36.333 + while (i!=INVALID && (!(*uedge_filter_map)[i]
36.334 + || !(*node_filter_map)[Parent::target(i)])) Parent::nextOut(i);
36.335 + }
36.336 +
36.337 + void nextInc(UEdge& i, bool& d) const {
36.338 + Parent::nextInc(i, d);
36.339 + while (i!=INVALID && (!(*uedge_filter_map)[i]
36.340 + || !(*node_filter_map)[Parent::source(i)])) Parent::nextInc(i, d);
36.341 + }
36.342 +
36.343 + ///\e
36.344 +
36.345 + /// This function hides \c n in the graph, i.e. the iteration
36.346 + /// jumps over it. This is done by simply setting the value of \c n
36.347 + /// to be false in the corresponding node-map.
36.348 + void hide(const Node& n) const { node_filter_map->set(n, false); }
36.349 +
36.350 + ///\e
36.351 +
36.352 + /// This function hides \c e in the graph, i.e. the iteration
36.353 + /// jumps over it. This is done by simply setting the value of \c e
36.354 + /// to be false in the corresponding edge-map.
36.355 + void hide(const UEdge& e) const { uedge_filter_map->set(e, false); }
36.356 +
36.357 + ///\e
36.358 +
36.359 + /// The value of \c n is set to be true in the node-map which stores
36.360 + /// hide information. If \c n was hidden previuosly, then it is shown
36.361 + /// again
36.362 + void unHide(const Node& n) const { node_filter_map->set(n, true); }
36.363 +
36.364 + ///\e
36.365 +
36.366 + /// The value of \c e is set to be true in the edge-map which stores
36.367 + /// hide information. If \c e was hidden previuosly, then it is shown
36.368 + /// again
36.369 + void unHide(const UEdge& e) const { uedge_filter_map->set(e, true); }
36.370 +
36.371 + /// Returns true if \c n is hidden.
36.372 +
36.373 + ///\e
36.374 + ///
36.375 + bool hidden(const Node& n) const { return !(*node_filter_map)[n]; }
36.376 +
36.377 + /// Returns true if \c n is hidden.
36.378 +
36.379 + ///\e
36.380 + ///
36.381 + bool hidden(const UEdge& e) const { return !(*uedge_filter_map)[e]; }
36.382 +
36.383 + typedef False NodeNumTag;
36.384 + typedef False EdgeNumTag;
36.385 + };
36.386 +
36.387 + template <typename _UGraph, typename NodeFilterMap, typename UEdgeFilterMap>
36.388 + class SubUGraphAdaptorBase<_UGraph, NodeFilterMap, UEdgeFilterMap, false>
36.389 + : public UGraphAdaptorBase<_UGraph> {
36.390 + public:
36.391 + typedef _UGraph Graph;
36.392 + typedef UGraphAdaptorBase<_UGraph> Parent;
36.393 + protected:
36.394 + NodeFilterMap* node_filter_map;
36.395 + UEdgeFilterMap* uedge_filter_map;
36.396 + SubUGraphAdaptorBase() : Parent(),
36.397 + node_filter_map(0), uedge_filter_map(0) { }
36.398 +
36.399 + void setNodeFilterMap(NodeFilterMap& _node_filter_map) {
36.400 + node_filter_map=&_node_filter_map;
36.401 + }
36.402 + void setUEdgeFilterMap(UEdgeFilterMap& _uedge_filter_map) {
36.403 + uedge_filter_map=&_uedge_filter_map;
36.404 + }
36.405 +
36.406 + public:
36.407 +
36.408 + typedef typename Parent::Node Node;
36.409 + typedef typename Parent::Edge Edge;
36.410 + typedef typename Parent::UEdge UEdge;
36.411 +
36.412 + void first(Node& i) const {
36.413 + Parent::first(i);
36.414 + while (i!=INVALID && !(*node_filter_map)[i]) Parent::next(i);
36.415 + }
36.416 +
36.417 + void first(Edge& i) const {
36.418 + Parent::first(i);
36.419 + while (i!=INVALID && !(*uedge_filter_map)[i]) Parent::next(i);
36.420 + }
36.421 +
36.422 + void first(UEdge& i) const {
36.423 + Parent::first(i);
36.424 + while (i!=INVALID && !(*uedge_filter_map)[i]) Parent::next(i);
36.425 + }
36.426 +
36.427 + void firstIn(Edge& i, const Node& n) const {
36.428 + Parent::firstIn(i, n);
36.429 + while (i!=INVALID && !(*uedge_filter_map)[i]) Parent::nextIn(i);
36.430 + }
36.431 +
36.432 + void firstOut(Edge& i, const Node& n) const {
36.433 + Parent::firstOut(i, n);
36.434 + while (i!=INVALID && !(*uedge_filter_map)[i]) Parent::nextOut(i);
36.435 + }
36.436 +
36.437 + void firstInc(UEdge& i, bool& d, const Node& n) const {
36.438 + Parent::firstInc(i, d, n);
36.439 + while (i!=INVALID && !(*uedge_filter_map)[i]) Parent::nextInc(i, d);
36.440 + }
36.441 +
36.442 + void next(Node& i) const {
36.443 + Parent::next(i);
36.444 + while (i!=INVALID && !(*node_filter_map)[i]) Parent::next(i);
36.445 + }
36.446 + void next(Edge& i) const {
36.447 + Parent::next(i);
36.448 + while (i!=INVALID && !(*uedge_filter_map)[i]) Parent::next(i);
36.449 + }
36.450 + void next(UEdge& i) const {
36.451 + Parent::next(i);
36.452 + while (i!=INVALID && !(*uedge_filter_map)[i]) Parent::next(i);
36.453 + }
36.454 + void nextIn(Edge& i) const {
36.455 + Parent::nextIn(i);
36.456 + while (i!=INVALID && !(*uedge_filter_map)[i]) Parent::nextIn(i);
36.457 + }
36.458 +
36.459 + void nextOut(Edge& i) const {
36.460 + Parent::nextOut(i);
36.461 + while (i!=INVALID && !(*uedge_filter_map)[i]) Parent::nextOut(i);
36.462 + }
36.463 + void nextInc(UEdge& i, bool& d) const {
36.464 + Parent::nextInc(i, d);
36.465 + while (i!=INVALID && !(*uedge_filter_map)[i]) Parent::nextInc(i, d);
36.466 + }
36.467 +
36.468 + ///\e
36.469 +
36.470 + /// This function hides \c n in the graph, i.e. the iteration
36.471 + /// jumps over it. This is done by simply setting the value of \c n
36.472 + /// to be false in the corresponding node-map.
36.473 + void hide(const Node& n) const { node_filter_map->set(n, false); }
36.474 +
36.475 + ///\e
36.476 +
36.477 + /// This function hides \c e in the graph, i.e. the iteration
36.478 + /// jumps over it. This is done by simply setting the value of \c e
36.479 + /// to be false in the corresponding edge-map.
36.480 + void hide(const UEdge& e) const { uedge_filter_map->set(e, false); }
36.481 +
36.482 + ///\e
36.483 +
36.484 + /// The value of \c n is set to be true in the node-map which stores
36.485 + /// hide information. If \c n was hidden previuosly, then it is shown
36.486 + /// again
36.487 + void unHide(const Node& n) const { node_filter_map->set(n, true); }
36.488 +
36.489 + ///\e
36.490 +
36.491 + /// The value of \c e is set to be true in the edge-map which stores
36.492 + /// hide information. If \c e was hidden previuosly, then it is shown
36.493 + /// again
36.494 + void unHide(const UEdge& e) const { uedge_filter_map->set(e, true); }
36.495 +
36.496 + /// Returns true if \c n is hidden.
36.497 +
36.498 + ///\e
36.499 + ///
36.500 + bool hidden(const Node& n) const { return !(*node_filter_map)[n]; }
36.501 +
36.502 + /// Returns true if \c n is hidden.
36.503 +
36.504 + ///\e
36.505 + ///
36.506 + bool hidden(const UEdge& e) const { return !(*uedge_filter_map)[e]; }
36.507 +
36.508 + typedef False NodeNumTag;
36.509 + typedef False EdgeNumTag;
36.510 + };
36.511 +
36.512 + /// \ingroup graph_adaptors
36.513 + ///
36.514 + /// \brief A graph adaptor for hiding nodes and edges from an undirected
36.515 + /// graph.
36.516 + ///
36.517 + /// \warning Graph adaptors are in even more experimental state than the
36.518 + /// other parts of the lib. Use them at you own risk.
36.519 + ///
36.520 + /// SubUGraphAdaptor shows the undirected graph with filtered node-set and
36.521 + /// edge-set. If the \c checked parameter is true then it filters the edgeset
36.522 + /// to do not get invalid edges without source or target.
36.523 + ///
36.524 + /// If the \c checked template parameter is false then we have to note that
36.525 + /// the node-iterator cares only the filter on the node-set, and the
36.526 + /// edge-iterator cares only the filter on the edge-set.
36.527 + /// This way the edge-map
36.528 + /// should filter all edges which's source or target is filtered by the
36.529 + /// node-filter.
36.530 + ///
36.531 + /// Note that \c n is of type \c SubGA::NodeIt, but it can be converted to
36.532 + /// \c Graph::Node that is why \c g.id(n) can be applied.
36.533 + ///
36.534 + /// For examples see also the documentation of NodeSubUGraphAdaptor and
36.535 + /// EdgeSubUGraphAdaptor.
36.536 + ///
36.537 + /// \author Marton Makai
36.538 +
36.539 + template<typename _UGraph, typename NodeFilterMap,
36.540 + typename UEdgeFilterMap, bool checked = true>
36.541 + class SubUGraphAdaptor :
36.542 + public UGraphAdaptorExtender<
36.543 + SubUGraphAdaptorBase<_UGraph, NodeFilterMap, UEdgeFilterMap, checked> > {
36.544 + public:
36.545 + typedef _UGraph Graph;
36.546 + typedef UGraphAdaptorExtender<
36.547 + SubUGraphAdaptorBase<_UGraph, NodeFilterMap, UEdgeFilterMap> > Parent;
36.548 + protected:
36.549 + SubUGraphAdaptor() { }
36.550 + public:
36.551 + SubUGraphAdaptor(Graph& _graph, NodeFilterMap& _node_filter_map,
36.552 + UEdgeFilterMap& _uedge_filter_map) {
36.553 + setGraph(_graph);
36.554 + setNodeFilterMap(_node_filter_map);
36.555 + setUEdgeFilterMap(_uedge_filter_map);
36.556 + }
36.557 + };
36.558 +
36.559 + /// \ingroup graph_adaptors
36.560 + ///
36.561 + /// \brief An adaptor for hiding nodes from an undorected graph.
36.562 + ///
36.563 + /// \warning Graph adaptors are in even more experimental state
36.564 + /// than the other
36.565 + /// parts of the lib. Use them at you own risk.
36.566 + ///
36.567 + /// An adaptor for hiding nodes from an undirected graph.
36.568 + /// This adaptor specializes SubUGraphAdaptor in the way that only
36.569 + /// the node-set
36.570 + /// can be filtered. In usual case the checked parameter is true, we get the
36.571 + /// induced subgraph. But if the checked parameter is false then we can only
36.572 + /// filter only isolated nodes.
36.573 + /// \author Marton Makai
36.574 + template<typename _UGraph, typename NodeFilterMap, bool checked = true>
36.575 + class NodeSubUGraphAdaptor :
36.576 + public SubUGraphAdaptor<_UGraph, NodeFilterMap,
36.577 + ConstMap<typename _UGraph::UEdge, bool>, checked> {
36.578 + public:
36.579 + typedef SubUGraphAdaptor<_UGraph, NodeFilterMap,
36.580 + ConstMap<typename _UGraph::UEdge, bool> > Parent;
36.581 + typedef _UGraph Graph;
36.582 + protected:
36.583 + ConstMap<typename _UGraph::Edge, bool> const_true_map;
36.584 + public:
36.585 + NodeSubUGraphAdaptor(Graph& _graph, NodeFilterMap& _node_filter_map) :
36.586 + Parent(), const_true_map(true) {
36.587 + Parent::setGraph(_graph);
36.588 + Parent::setNodeFilterMap(_node_filter_map);
36.589 + Parent::setUEdgeFilterMap(const_true_map);
36.590 + }
36.591 + };
36.592 +
36.593 + template<typename UGraph, typename NodeFilterMap>
36.594 + NodeSubUGraphAdaptor<const UGraph, NodeFilterMap>
36.595 + nodeSubUGraphAdaptor(const UGraph& graph, NodeFilterMap& nfm) {
36.596 + return NodeSubUGraphAdaptor<const UGraph, NodeFilterMap>(graph, nfm);
36.597 + }
36.598 +
36.599 + template<typename UGraph, typename NodeFilterMap>
36.600 + NodeSubUGraphAdaptor<const UGraph, const NodeFilterMap>
36.601 + nodeSubUGraphAdaptor(const UGraph& graph, const NodeFilterMap& nfm) {
36.602 + return NodeSubUGraphAdaptor<const UGraph, const NodeFilterMap>(graph, nfm);
36.603 + }
36.604 +
36.605 +
36.606 + /// \brief An adaptor for hiding undirected edges from an undirected graph.
36.607 + ///
36.608 + /// \warning Graph adaptors are in even more experimental state
36.609 + /// than the other parts of the lib. Use them at you own risk.
36.610 + ///
36.611 + /// An adaptor for hiding undirected edges from an undirected graph.
36.612 + /// This adaptor specializes SubUGraphAdaptor in the way that
36.613 + /// only the edge-set
36.614 + /// can be filtered.
36.615 + ///
36.616 + ///\author Marton Makai
36.617 + template<typename _UGraph, typename UEdgeFilterMap>
36.618 + class EdgeSubUGraphAdaptor :
36.619 + public SubUGraphAdaptor<_UGraph, ConstMap<typename _UGraph::Node,bool>,
36.620 + UEdgeFilterMap, false> {
36.621 + public:
36.622 + typedef SubUGraphAdaptor<_UGraph, ConstMap<typename _UGraph::Node,bool>,
36.623 + UEdgeFilterMap, false> Parent;
36.624 + typedef _UGraph Graph;
36.625 + protected:
36.626 + ConstMap<typename Graph::Node, bool> const_true_map;
36.627 + public:
36.628 + EdgeSubUGraphAdaptor(Graph& _graph, UEdgeFilterMap& _uedge_filter_map) :
36.629 + Parent(), const_true_map(true) {
36.630 + Parent::setGraph(_graph);
36.631 + Parent::setNodeFilterMap(const_true_map);
36.632 + Parent::setUEdgeFilterMap(_uedge_filter_map);
36.633 + }
36.634 + };
36.635 +
36.636 + template<typename UGraph, typename EdgeFilterMap>
36.637 + EdgeSubUGraphAdaptor<const UGraph, EdgeFilterMap>
36.638 + edgeSubUGraphAdaptor(const UGraph& graph, EdgeFilterMap& efm) {
36.639 + return EdgeSubUGraphAdaptor<const UGraph, EdgeFilterMap>(graph, efm);
36.640 + }
36.641 +
36.642 + template<typename UGraph, typename EdgeFilterMap>
36.643 + EdgeSubUGraphAdaptor<const UGraph, const EdgeFilterMap>
36.644 + edgeSubUGraphAdaptor(const UGraph& graph, const EdgeFilterMap& efm) {
36.645 + return EdgeSubUGraphAdaptor<const UGraph, const EdgeFilterMap>(graph, efm);
36.646 + }
36.647 +
36.648 + template <typename _UGraph, typename _DirectionMap>
36.649 + class DirectUGraphAdaptorBase {
36.650 + public:
36.651 +
36.652 + typedef _UGraph Graph;
36.653 + typedef _DirectionMap DirectionMap;
36.654 +
36.655 + typedef typename _UGraph::Node Node;
36.656 + typedef typename _UGraph::UEdge Edge;
36.657 +
36.658 + void first(Node& i) const { graph->first(i); }
36.659 + void first(Edge& i) const { graph->first(i); }
36.660 + void firstIn(Edge& i, const Node& n) const {
36.661 + bool d;
36.662 + graph->firstInc(i, d, n);
36.663 + while (i != INVALID && d == (*direction)[i]) graph->nextInc(i, d);
36.664 + }
36.665 + void firstOut(Edge& i, const Node& n ) const {
36.666 + bool d;
36.667 + graph->firstInc(i, d, n);
36.668 + while (i != INVALID && d != (*direction)[i]) graph->nextInc(i, d);
36.669 + }
36.670 +
36.671 + void next(Node& i) const { graph->next(i); }
36.672 + void next(Edge& i) const { graph->next(i); }
36.673 + void nextIn(Edge& i) const {
36.674 + bool d = !(*direction)[i];
36.675 + graph->nextInc(i, d);
36.676 + while (i != INVALID && d == (*direction)[i]) graph->nextInc(i, d);
36.677 + }
36.678 + void nextOut(Edge& i) const {
36.679 + bool d = (*direction)[i];
36.680 + graph->nextInc(i, d);
36.681 + while (i != INVALID && d != (*direction)[i]) graph->nextInc(i, d);
36.682 + }
36.683 +
36.684 + Node source(const Edge& e) const {
36.685 + return (*direction)[e] ? graph->source(e) : graph->target(e);
36.686 + }
36.687 + Node target(const Edge& e) const {
36.688 + return (*direction)[e] ? graph->target(e) : graph->source(e);
36.689 + }
36.690 +
36.691 + typedef NodeNumTagIndicator<Graph> NodeNumTag;
36.692 + int nodeNum() const { return graph->nodeNum(); }
36.693 +
36.694 + typedef EdgeNumTagIndicator<Graph> EdgeNumTag;
36.695 + int edgeNum() const { return graph->uEdgeNum(); }
36.696 +
36.697 + typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
36.698 + Edge findEdge(const Node& source, const Node& target,
36.699 + const Edge& prev = INVALID) {
36.700 + Edge edge = prev;
36.701 + bool d = edge == INVALID ? true : (*direction)[edge];
36.702 + if (d) {
36.703 + edge = graph->findUEdge(source, target, edge);
36.704 + while (edge != INVALID && !(*direction)[edge]) {
36.705 + graph->findUEdge(source, target, edge);
36.706 + }
36.707 + if (edge != INVALID) return edge;
36.708 + }
36.709 + graph->findUEdge(target, source, edge);
36.710 + while (edge != INVALID && (*direction)[edge]) {
36.711 + graph->findUEdge(source, target, edge);
36.712 + }
36.713 + return edge;
36.714 + }
36.715 +
36.716 + Node addNode() const {
36.717 + return Node(graph->addNode());
36.718 + }
36.719 +
36.720 + Edge addEdge(const Node& source, const Node& target) const {
36.721 + Edge edge = graph->addEdge(source, target);
36.722 + (*direction)[edge] = graph->source(edge) == source;
36.723 + return edge;
36.724 + }
36.725 +
36.726 + void erase(const Node& i) const { graph->erase(i); }
36.727 + void erase(const Edge& i) const { graph->erase(i); }
36.728 +
36.729 + void clear() const { graph->clear(); }
36.730 +
36.731 + int id(const Node& v) const { return graph->id(v); }
36.732 + int id(const Edge& e) const { return graph->id(e); }
36.733 +
36.734 + void reverseEdge(const Edge& edge) {
36.735 + direction->set(edge, !(*direction)[edge]);
36.736 + }
36.737 +
36.738 + template <typename _Value>
36.739 + class NodeMap : public _UGraph::template NodeMap<_Value> {
36.740 + public:
36.741 + typedef typename _UGraph::template NodeMap<_Value> Parent;
36.742 + explicit NodeMap(const DirectUGraphAdaptorBase& ga)
36.743 + : Parent(*ga.graph) { }
36.744 + NodeMap(const DirectUGraphAdaptorBase& ga, const _Value& value)
36.745 + : Parent(*ga.graph, value) { }
36.746 + };
36.747 +
36.748 + template <typename _Value>
36.749 + class EdgeMap : public _UGraph::template UEdgeMap<_Value> {
36.750 + public:
36.751 + typedef typename _UGraph::template EdgeMap<_Value> Parent;
36.752 + explicit EdgeMap(const DirectUGraphAdaptorBase& ga)
36.753 + : Parent(*ga.graph) { }
36.754 + EdgeMap(const DirectUGraphAdaptorBase& ga, const _Value& value)
36.755 + : Parent(*ga.graph, value) { }
36.756 + };
36.757 +
36.758 +
36.759 +
36.760 + protected:
36.761 + Graph* graph;
36.762 + DirectionMap* direction;
36.763 +
36.764 + void setDirectionMap(DirectionMap& _direction) {
36.765 + direction = &_direction;
36.766 + }
36.767 +
36.768 + void setGraph(Graph& _graph) {
36.769 + graph = &_graph;
36.770 + }
36.771 +
36.772 + };
36.773 +
36.774 +
36.775 + template<typename _Graph, typename DirectionMap>
36.776 + class DirectUGraphAdaptor :
36.777 + public GraphAdaptorExtender<
36.778 + DirectUGraphAdaptorBase<_Graph, DirectionMap> > {
36.779 + public:
36.780 + typedef _Graph Graph;
36.781 + typedef GraphAdaptorExtender<
36.782 + DirectUGraphAdaptorBase<_Graph, DirectionMap> > Parent;
36.783 + protected:
36.784 + DirectUGraphAdaptor() { }
36.785 + public:
36.786 + DirectUGraphAdaptor(_Graph& _graph, DirectionMap& _direction_map) {
36.787 + setGraph(_graph);
36.788 + setDirectionMap(_direction_map);
36.789 + }
36.790 + };
36.791 +
36.792 + template<typename UGraph, typename DirectionMap>
36.793 + DirectUGraphAdaptor<const UGraph, DirectionMap>
36.794 + directUGraphAdaptor(const UGraph& graph, DirectionMap& dm) {
36.795 + return DirectUGraphAdaptor<const UGraph, DirectionMap>(graph, dm);
36.796 + }
36.797 +
36.798 + template<typename UGraph, typename DirectionMap>
36.799 + DirectUGraphAdaptor<const UGraph, const DirectionMap>
36.800 + directUGraphAdaptor(const UGraph& graph, const DirectionMap& dm) {
36.801 + return DirectUGraphAdaptor<const UGraph, const DirectionMap>(graph, dm);
36.802 + }
36.803 +
36.804 +}
36.805 +
36.806 +#endif
37.1 --- a/test/graph_adaptor_test.cc Wed Feb 22 12:45:59 2006 +0000
37.2 +++ b/test/graph_adaptor_test.cc Wed Feb 22 18:26:56 2006 +0000
37.3 @@ -67,9 +67,7 @@
37.4 Graph::NodeMap<Graph::Edge> > >();
37.5
37.6 /// \bug why does not compile with StaticGraph
37.7 - checkConcept<BaseIterableUGraphConcept, UGraphAdaptor<ListGraph> >();
37.8 - checkConcept<IterableUGraphConcept, UGraphAdaptor<ListGraph> >();
37.9 - checkConcept<MappableUGraphConcept, UGraphAdaptor<ListGraph> >();
37.10 + checkConcept<UGraph, UndirectGraphAdaptor<ListGraph> >();
37.11 }
37.12 std::cout << __FILE__ ": All tests passed.\n";
37.13
38.1 --- a/test/ugraph_test.cc Wed Feb 22 12:45:59 2006 +0000
38.2 +++ b/test/ugraph_test.cc Wed Feb 22 18:26:56 2006 +0000
38.3 @@ -21,7 +21,7 @@
38.4 #include <lemon/list_graph.h>
38.5 #include <lemon/smart_graph.h>
38.6 #include <lemon/full_graph.h>
38.7 -#include <lemon/grid_graph.h>
38.8 +#include <lemon/grid_ugraph.h>
38.9
38.10 #include <lemon/graph_utils.h>
38.11
38.12 @@ -32,25 +32,6 @@
38.13 using namespace lemon::concept;
38.14
38.15 void check_concepts() {
38.16 - typedef UGraphExtender<ListGraphBase> ListUGraphBase;
38.17 -
38.18 - typedef IterableUGraphExtender<
38.19 - AlterableUGraphExtender<ListUGraphBase> > IterableListUGraph;
38.20 -
38.21 - typedef MappableUGraphExtender<IterableListUGraph>
38.22 - MappableListUGraph;
38.23 -
38.24 - typedef ErasableUGraphExtender<
38.25 - ClearableUGraphExtender<
38.26 - ExtendableUGraphExtender<MappableListUGraph> > > Graph;
38.27 -
38.28 - checkConcept<BaseIterableUGraphConcept, Graph>();
38.29 - checkConcept<IterableUGraphConcept, Graph>();
38.30 - checkConcept<MappableUGraphConcept, Graph>();
38.31 -
38.32 - checkConcept<UGraph, Graph>();
38.33 - checkConcept<ErasableUGraph, Graph>();
38.34 -
38.35 checkConcept<UGraph, ListUGraph>();
38.36 checkConcept<ErasableUGraph, ListUGraph>();
38.37
38.38 @@ -61,7 +42,7 @@
38.39
38.40 checkConcept<UGraph, UGraph>();
38.41
38.42 - checkConcept<UGraph, GridGraph>();
38.43 + checkConcept<UGraph, GridUGraph>();
38.44 }
38.45
38.46 template <typename Graph>
38.47 @@ -150,7 +131,7 @@
38.48 check_item_counts(g,3,2);
38.49 }
38.50
38.51 -void checkGridGraph(const GridGraph& g, int w, int h) {
38.52 +void checkGridUGraph(const GridUGraph& g, int w, int h) {
38.53 check(g.width() == w, "Wrong width");
38.54 check(g.height() == h, "Wrong height");
38.55
38.56 @@ -206,9 +187,9 @@
38.57 }
38.58
38.59 {
38.60 - GridGraph g(5, 6);
38.61 + GridUGraph g(5, 6);
38.62 check_item_counts(g, 30, 49);
38.63 - checkGridGraph(g, 5, 6);
38.64 + checkGridUGraph(g, 5, 6);
38.65 }
38.66
38.67 std::cout << __FILE__ ": All tests passed.\n";