deba@1623
|
1 |
/* -*- C++ -*-
|
deba@1623
|
2 |
* lemon/grid_graph.h - Part of LEMON, a generic C++ optimization library
|
deba@1623
|
3 |
*
|
deba@1623
|
4 |
* Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
|
deba@1623
|
5 |
* (Egervary Research Group on Combinatorial Optimization, EGRES).
|
deba@1623
|
6 |
*
|
deba@1623
|
7 |
* Permission to use, modify and distribute this software is granted
|
deba@1623
|
8 |
* provided that this copyright notice appears in all copies. For
|
deba@1623
|
9 |
* precise terms see the accompanying LICENSE file.
|
deba@1623
|
10 |
*
|
deba@1623
|
11 |
* This software is provided "AS IS" with no warranty of any kind,
|
deba@1623
|
12 |
* express or implied, and with no claim as to its suitability for any
|
deba@1623
|
13 |
* purpose.
|
deba@1623
|
14 |
*
|
deba@1623
|
15 |
*/
|
deba@1623
|
16 |
|
deba@1623
|
17 |
#ifndef GRID_GRAPH_H
|
deba@1623
|
18 |
#define GRID_GRAPH_H
|
deba@1623
|
19 |
|
deba@1623
|
20 |
#include <iostream>
|
deba@1623
|
21 |
#include <lemon/invalid.h>
|
deba@1623
|
22 |
#include <lemon/utility.h>
|
deba@1623
|
23 |
|
deba@1623
|
24 |
#include <lemon/bits/iterable_graph_extender.h>
|
deba@1623
|
25 |
#include <lemon/bits/alteration_notifier.h>
|
deba@1703
|
26 |
#include <lemon/bits/static_map.h>
|
deba@1623
|
27 |
|
deba@1623
|
28 |
#include <lemon/bits/undir_graph_extender.h>
|
deba@1623
|
29 |
|
deba@1693
|
30 |
#include <lemon/xy.h>
|
deba@1693
|
31 |
|
deba@1693
|
32 |
///\ingroup graphs
|
deba@1693
|
33 |
///\file
|
deba@1693
|
34 |
///\brief GridGraph class.
|
deba@1693
|
35 |
|
deba@1623
|
36 |
namespace lemon {
|
deba@1623
|
37 |
|
deba@1693
|
38 |
/// \brief Base graph for GridGraph.
|
deba@1693
|
39 |
///
|
deba@1693
|
40 |
/// Base graph for grid graph. It describes some member functions
|
deba@1693
|
41 |
/// which can be used in the GridGraph.
|
deba@1693
|
42 |
///
|
deba@1693
|
43 |
/// \warning Always use the GridGraph instead of this.
|
deba@1693
|
44 |
/// \see GridGraph
|
deba@1623
|
45 |
class GridGraphBase {
|
deba@1623
|
46 |
|
deba@1623
|
47 |
public:
|
deba@1623
|
48 |
|
deba@1623
|
49 |
typedef GridGraphBase Graph;
|
deba@1623
|
50 |
|
deba@1623
|
51 |
class Node;
|
deba@1623
|
52 |
class Edge;
|
deba@1623
|
53 |
|
deba@1623
|
54 |
public:
|
deba@1623
|
55 |
|
deba@1623
|
56 |
GridGraphBase() {}
|
deba@1623
|
57 |
|
deba@1623
|
58 |
protected:
|
deba@1623
|
59 |
|
deba@1623
|
60 |
/// \brief Creates a grid graph with the given size.
|
deba@1623
|
61 |
///
|
deba@1623
|
62 |
/// Creates a grid graph with the given size.
|
deba@1680
|
63 |
void construct(int width, int height) {
|
deba@1623
|
64 |
_height = height; _width = width;
|
deba@1623
|
65 |
_nodeNum = height * width; _edgeNum = 2 * _nodeNum - width - height;
|
deba@1623
|
66 |
_edgeLimit = _nodeNum - width;
|
deba@1623
|
67 |
}
|
deba@1623
|
68 |
|
deba@1680
|
69 |
/// \brief Gives back the edge goes down from the node.
|
deba@1680
|
70 |
///
|
deba@1680
|
71 |
/// Gives back the edge goes down from the node. If there is not
|
deba@1680
|
72 |
/// outgoing edge then it gives back INVALID.
|
deba@1680
|
73 |
Edge _down(Node n) const {
|
deba@1680
|
74 |
if (n.id < _nodeNum - _width) {
|
deba@1680
|
75 |
return Edge(n.id);
|
deba@1680
|
76 |
} else {
|
deba@1680
|
77 |
return INVALID;
|
deba@1680
|
78 |
}
|
deba@1680
|
79 |
}
|
deba@1680
|
80 |
|
deba@1680
|
81 |
/// \brief Gives back the edge comes from up into the node.
|
deba@1680
|
82 |
///
|
deba@1680
|
83 |
/// Gives back the edge comes from up into the node. If there is not
|
deba@1680
|
84 |
/// incoming edge then it gives back INVALID.
|
deba@1680
|
85 |
Edge _up(Node n) const {
|
deba@1680
|
86 |
if (n.id >= _width) {
|
deba@1680
|
87 |
return Edge(n.id - _width);
|
deba@1680
|
88 |
} else {
|
deba@1680
|
89 |
return INVALID;
|
deba@1680
|
90 |
}
|
deba@1680
|
91 |
}
|
deba@1680
|
92 |
|
deba@1680
|
93 |
/// \brief Gives back the edge goes right from the node.
|
deba@1680
|
94 |
///
|
deba@1680
|
95 |
/// Gives back the edge goes right from the node. If there is not
|
deba@1680
|
96 |
/// outgoing edge then it gives back INVALID.
|
deba@1680
|
97 |
Edge _right(Node n) const {
|
deba@1680
|
98 |
if (n.id % _width < _width - 1) {
|
deba@1680
|
99 |
return _edgeLimit + n.id % _width + (n.id / _width) * (_width - 1);
|
deba@1680
|
100 |
} else {
|
deba@1680
|
101 |
return INVALID;
|
deba@1680
|
102 |
}
|
deba@1680
|
103 |
}
|
deba@1680
|
104 |
|
deba@1680
|
105 |
/// \brief Gives back the edge comes from left into the node.
|
deba@1680
|
106 |
///
|
deba@1680
|
107 |
/// Gives back the edge comes left up into the node. If there is not
|
deba@1680
|
108 |
/// incoming edge then it gives back INVALID.
|
deba@1680
|
109 |
Edge _left(Node n) const {
|
deba@1680
|
110 |
if (n.id % _width > 0) {
|
deba@1680
|
111 |
return _edgeLimit + n.id % _width + (n.id / _width) * (_width - 1) - 1;
|
deba@1680
|
112 |
} else {
|
deba@1680
|
113 |
return INVALID;
|
deba@1680
|
114 |
}
|
deba@1680
|
115 |
}
|
deba@1680
|
116 |
|
deba@1680
|
117 |
|
deba@1623
|
118 |
public:
|
deba@1623
|
119 |
|
deba@1623
|
120 |
/// \brief The node on the given position.
|
deba@1623
|
121 |
///
|
deba@1623
|
122 |
/// Gives back the node on the given position.
|
deba@1623
|
123 |
Node operator()(int i, int j) const {
|
deba@1680
|
124 |
return Node(i + j * _width);
|
deba@1623
|
125 |
}
|
deba@1623
|
126 |
|
deba@1623
|
127 |
/// \brief Gives back the row index of the node.
|
deba@1623
|
128 |
///
|
deba@1623
|
129 |
/// Gives back the row index of the node.
|
deba@1623
|
130 |
int row(Node n) const {
|
deba@1623
|
131 |
return n.id / _width;
|
deba@1623
|
132 |
}
|
deba@1623
|
133 |
|
deba@1623
|
134 |
/// \brief Gives back the coloumn index of the node.
|
deba@1623
|
135 |
///
|
deba@1623
|
136 |
/// Gives back the coloumn index of the node.
|
deba@1680
|
137 |
int col(Node n) const {
|
deba@1623
|
138 |
return n.id % _width;
|
deba@1623
|
139 |
}
|
deba@1623
|
140 |
|
deba@1623
|
141 |
/// \brief Gives back the width of the graph.
|
deba@1623
|
142 |
///
|
deba@1623
|
143 |
/// Gives back the width of the graph.
|
deba@1623
|
144 |
int width() const {
|
deba@1623
|
145 |
return _width;
|
deba@1623
|
146 |
}
|
deba@1623
|
147 |
|
deba@1623
|
148 |
/// \brief Gives back the height of the graph.
|
deba@1623
|
149 |
///
|
deba@1623
|
150 |
/// Gives back the height of the graph.
|
deba@1623
|
151 |
int height() const {
|
deba@1623
|
152 |
return _height;
|
deba@1623
|
153 |
}
|
deba@1623
|
154 |
|
deba@1623
|
155 |
typedef True NodeNumTag;
|
deba@1623
|
156 |
typedef True EdgeNumTag;
|
deba@1623
|
157 |
|
deba@1623
|
158 |
///Number of nodes.
|
deba@1623
|
159 |
int nodeNum() const { return _nodeNum; }
|
deba@1623
|
160 |
///Number of edges.
|
deba@1623
|
161 |
int edgeNum() const { return _edgeNum; }
|
deba@1623
|
162 |
|
deba@1623
|
163 |
/// Maximum node ID.
|
deba@1623
|
164 |
|
deba@1623
|
165 |
/// Maximum node ID.
|
deba@1623
|
166 |
///\sa id(Node)
|
deba@1623
|
167 |
int maxId(Node = INVALID) const { return nodeNum() - 1; }
|
deba@1623
|
168 |
/// Maximum edge ID.
|
deba@1623
|
169 |
|
deba@1623
|
170 |
/// Maximum edge ID.
|
deba@1623
|
171 |
///\sa id(Edge)
|
deba@1623
|
172 |
int maxId(Edge = INVALID) const { return edgeNum() - 1; }
|
deba@1623
|
173 |
|
deba@1623
|
174 |
/// \brief Gives back the source node of an edge.
|
deba@1623
|
175 |
///
|
deba@1623
|
176 |
/// Gives back the source node of an edge.
|
deba@1623
|
177 |
Node source(Edge e) const {
|
deba@1623
|
178 |
if (e.id < _edgeLimit) {
|
deba@1623
|
179 |
return e.id;
|
deba@1623
|
180 |
} else {
|
deba@1623
|
181 |
return (e.id - _edgeLimit) % (_width - 1) +
|
deba@1623
|
182 |
(e.id - _edgeLimit) / (_width - 1) * _width;
|
deba@1623
|
183 |
}
|
deba@1623
|
184 |
}
|
deba@1623
|
185 |
|
deba@1623
|
186 |
/// \brief Gives back the target node of an edge.
|
deba@1623
|
187 |
///
|
deba@1623
|
188 |
/// Gives back the target node of an edge.
|
deba@1623
|
189 |
Node target(Edge e) const {
|
deba@1623
|
190 |
if (e.id < _edgeLimit) {
|
deba@1623
|
191 |
return e.id + _width;
|
deba@1623
|
192 |
} else {
|
deba@1623
|
193 |
return (e.id - _edgeLimit) % (_width - 1) +
|
deba@1623
|
194 |
(e.id - _edgeLimit) / (_width - 1) * _width + 1;
|
deba@1623
|
195 |
}
|
deba@1623
|
196 |
}
|
deba@1623
|
197 |
|
deba@1623
|
198 |
/// Node ID.
|
deba@1623
|
199 |
|
deba@1623
|
200 |
/// The ID of a valid Node is a nonnegative integer not greater than
|
deba@1623
|
201 |
/// \ref maxNodeId(). The range of the ID's is not surely continuous
|
deba@1623
|
202 |
/// and the greatest node ID can be actually less then \ref maxNodeId().
|
deba@1623
|
203 |
///
|
deba@1623
|
204 |
/// The ID of the \ref INVALID node is -1.
|
deba@1623
|
205 |
///\return The ID of the node \c v.
|
deba@1623
|
206 |
|
deba@1623
|
207 |
static int id(Node v) { return v.id; }
|
deba@1623
|
208 |
/// Edge ID.
|
deba@1623
|
209 |
|
deba@1623
|
210 |
/// The ID of a valid Edge is a nonnegative integer not greater than
|
deba@1623
|
211 |
/// \ref maxEdgeId(). The range of the ID's is not surely continuous
|
deba@1623
|
212 |
/// and the greatest edge ID can be actually less then \ref maxEdgeId().
|
deba@1623
|
213 |
///
|
deba@1623
|
214 |
/// The ID of the \ref INVALID edge is -1.
|
deba@1623
|
215 |
///\return The ID of the edge \c e.
|
deba@1623
|
216 |
static int id(Edge e) { return e.id; }
|
deba@1623
|
217 |
|
deba@1623
|
218 |
static Node fromId(int id, Node) { return Node(id);}
|
deba@1623
|
219 |
|
deba@1623
|
220 |
static Edge fromId(int id, Edge) { return Edge(id);}
|
deba@1623
|
221 |
|
deba@1623
|
222 |
typedef True FindEdgeTag;
|
deba@1623
|
223 |
|
deba@1623
|
224 |
/// Finds an edge between two nodes.
|
deba@1623
|
225 |
|
deba@1623
|
226 |
/// Finds an edge from node \c u to node \c v.
|
deba@1623
|
227 |
///
|
deba@1623
|
228 |
/// If \c prev is \ref INVALID (this is the default value), then
|
deba@1623
|
229 |
/// It finds the first edge from \c u to \c v. Otherwise it looks for
|
deba@1623
|
230 |
/// the next edge from \c u to \c v after \c prev.
|
deba@1623
|
231 |
/// \return The found edge or INVALID if there is no such an edge.
|
deba@1623
|
232 |
Edge findEdge(Node u, Node v, Edge prev = INVALID) {
|
deba@1623
|
233 |
if (prev != INVALID) return INVALID;
|
deba@1623
|
234 |
if (v.id - u.id == _width) return Edge(u.id);
|
deba@1623
|
235 |
if (v.id - u.id == 1 && u.id % _width < _width - 1) {
|
deba@1623
|
236 |
return Edge(u.id / _width * (_width - 1) +
|
deba@1623
|
237 |
u.id % _width + _edgeLimit);
|
deba@1623
|
238 |
}
|
deba@1623
|
239 |
return INVALID;
|
deba@1623
|
240 |
}
|
deba@1623
|
241 |
|
deba@1623
|
242 |
|
deba@1623
|
243 |
class Node {
|
deba@1623
|
244 |
friend class GridGraphBase;
|
deba@1623
|
245 |
|
deba@1623
|
246 |
protected:
|
deba@1623
|
247 |
int id;
|
deba@1623
|
248 |
Node(int _id) { id = _id;}
|
deba@1623
|
249 |
public:
|
deba@1623
|
250 |
Node() {}
|
deba@1623
|
251 |
Node (Invalid) { id = -1; }
|
deba@1623
|
252 |
bool operator==(const Node node) const {return id == node.id;}
|
deba@1623
|
253 |
bool operator!=(const Node node) const {return id != node.id;}
|
deba@1623
|
254 |
bool operator<(const Node node) const {return id < node.id;}
|
deba@1623
|
255 |
};
|
deba@1623
|
256 |
|
deba@1623
|
257 |
|
deba@1623
|
258 |
|
deba@1623
|
259 |
class Edge {
|
deba@1623
|
260 |
friend class GridGraphBase;
|
deba@1623
|
261 |
|
deba@1623
|
262 |
protected:
|
deba@1623
|
263 |
int id;
|
deba@1623
|
264 |
|
deba@1623
|
265 |
Edge(int _id) : id(_id) {}
|
deba@1623
|
266 |
|
deba@1623
|
267 |
public:
|
deba@1623
|
268 |
Edge() { }
|
deba@1623
|
269 |
Edge (Invalid) { id = -1; }
|
deba@1623
|
270 |
bool operator==(const Edge edge) const {return id == edge.id;}
|
deba@1623
|
271 |
bool operator!=(const Edge edge) const {return id != edge.id;}
|
deba@1623
|
272 |
bool operator<(const Edge edge) const {return id < edge.id;}
|
deba@1623
|
273 |
};
|
deba@1623
|
274 |
|
deba@1623
|
275 |
void first(Node& node) const {
|
deba@1623
|
276 |
node.id = nodeNum() - 1;
|
deba@1623
|
277 |
}
|
deba@1623
|
278 |
|
deba@1623
|
279 |
static void next(Node& node) {
|
deba@1623
|
280 |
--node.id;
|
deba@1623
|
281 |
}
|
deba@1623
|
282 |
|
deba@1623
|
283 |
void first(Edge& edge) const {
|
deba@1623
|
284 |
edge.id = edgeNum() - 1;
|
deba@1623
|
285 |
}
|
deba@1623
|
286 |
|
deba@1623
|
287 |
static void next(Edge& edge) {
|
deba@1623
|
288 |
--edge.id;
|
deba@1623
|
289 |
}
|
deba@1623
|
290 |
|
deba@1623
|
291 |
void firstOut(Edge& edge, const Node& node) const {
|
deba@1623
|
292 |
if (node.id < _nodeNum - _width) {
|
deba@1623
|
293 |
edge.id = node.id;
|
deba@1623
|
294 |
} else if (node.id % _width < _width - 1) {
|
deba@1623
|
295 |
edge.id = _edgeLimit + node.id % _width +
|
deba@1623
|
296 |
(node.id / _width) * (_width - 1);
|
deba@1623
|
297 |
} else {
|
deba@1623
|
298 |
edge.id = -1;
|
deba@1623
|
299 |
}
|
deba@1623
|
300 |
}
|
deba@1623
|
301 |
|
deba@1623
|
302 |
void nextOut(Edge& edge) const {
|
deba@1623
|
303 |
if (edge.id >= _edgeLimit) {
|
deba@1623
|
304 |
edge.id = -1;
|
deba@1623
|
305 |
} else if (edge.id % _width < _width - 1) {
|
deba@1623
|
306 |
edge.id = _edgeLimit + edge.id % _width +
|
deba@1623
|
307 |
(edge.id / _width) * (_width - 1);
|
deba@1623
|
308 |
} else {
|
deba@1623
|
309 |
edge.id = -1;
|
deba@1623
|
310 |
}
|
deba@1623
|
311 |
}
|
deba@1623
|
312 |
|
deba@1623
|
313 |
void firstIn(Edge& edge, const Node& node) const {
|
deba@1623
|
314 |
if (node.id >= _width) {
|
deba@1623
|
315 |
edge.id = node.id - _width;
|
deba@1623
|
316 |
} else if (node.id % _width > 0) {
|
deba@1623
|
317 |
edge.id = _edgeLimit + node.id % _width +
|
deba@1623
|
318 |
(node.id / _width) * (_width - 1) - 1;
|
deba@1623
|
319 |
} else {
|
deba@1623
|
320 |
edge.id = -1;
|
deba@1623
|
321 |
}
|
deba@1623
|
322 |
}
|
deba@1623
|
323 |
|
deba@1623
|
324 |
void nextIn(Edge& edge) const {
|
deba@1623
|
325 |
if (edge.id >= _edgeLimit) {
|
deba@1623
|
326 |
edge.id = -1;
|
deba@1623
|
327 |
} else if (edge.id % _width > 0) {
|
deba@1623
|
328 |
edge.id = _edgeLimit + edge.id % _width +
|
deba@1623
|
329 |
(edge.id / _width + 1) * (_width - 1) - 1;
|
deba@1623
|
330 |
} else {
|
deba@1623
|
331 |
edge.id = -1;
|
deba@1623
|
332 |
}
|
deba@1623
|
333 |
}
|
deba@1623
|
334 |
|
deba@1623
|
335 |
private:
|
deba@1623
|
336 |
int _width, _height;
|
deba@1623
|
337 |
int _nodeNum, _edgeNum;
|
deba@1623
|
338 |
int _edgeLimit;
|
deba@1623
|
339 |
};
|
deba@1623
|
340 |
|
deba@1623
|
341 |
|
deba@1703
|
342 |
typedef StaticMappableUndirGraphExtender<
|
deba@1680
|
343 |
IterableUndirGraphExtender<
|
deba@1680
|
344 |
AlterableUndirGraphExtender<
|
deba@1680
|
345 |
UndirGraphExtender<GridGraphBase> > > > ExtendedGridGraphBase;
|
deba@1623
|
346 |
|
deba@1623
|
347 |
/// \ingroup graphs
|
deba@1623
|
348 |
///
|
deba@1623
|
349 |
/// \brief Grid graph class
|
deba@1623
|
350 |
///
|
deba@1623
|
351 |
/// This class implements a special graph type. The nodes of the
|
deba@1623
|
352 |
/// graph can be indiced by two integer \c (i,j) value where \c i
|
deba@1623
|
353 |
/// is in the \c [0,height) range and j is in the [0, width) range.
|
deba@1623
|
354 |
/// Two nodes are connected in the graph if the indices differ only
|
deba@1623
|
355 |
/// on one position and only one is the difference.
|
deba@1623
|
356 |
///
|
deba@1623
|
357 |
/// The graph can be indiced in the following way:
|
deba@1623
|
358 |
/// \code
|
deba@1623
|
359 |
/// GridGraph graph(h, w);
|
deba@1623
|
360 |
/// GridGraph::NodeMap<int> val(graph);
|
deba@1623
|
361 |
/// for (int i = 0; i < graph.height(); ++i) {
|
deba@1623
|
362 |
/// for (int j = 0; j < graph.width(); ++j) {
|
deba@1623
|
363 |
/// val[graph(i, j)] = i + j;
|
deba@1623
|
364 |
/// }
|
deba@1623
|
365 |
/// }
|
deba@1623
|
366 |
/// \endcode
|
deba@1623
|
367 |
///
|
deba@1623
|
368 |
/// The graph type is fully conform to the \ref concept::UndirGraph
|
deba@1623
|
369 |
/// "Undirected Graph" concept.
|
deba@1623
|
370 |
///
|
deba@1623
|
371 |
/// \author Balazs Dezso
|
deba@1693
|
372 |
/// \see GridGraphBase
|
deba@1680
|
373 |
class GridGraph : public ExtendedGridGraphBase {
|
deba@1623
|
374 |
public:
|
deba@1693
|
375 |
|
deba@1693
|
376 |
/// \brief Map to get the indices of the nodes as xy<int>.
|
deba@1693
|
377 |
///
|
deba@1693
|
378 |
/// Map to get the indices of the nodes as xy<int>.
|
deba@1693
|
379 |
class IndexMap {
|
deba@1693
|
380 |
public:
|
deba@1693
|
381 |
typedef True NeedCopy;
|
deba@1693
|
382 |
/// \brief The key type of the map
|
deba@1693
|
383 |
typedef GridGraph::Node Key;
|
deba@1693
|
384 |
/// \brief The value type of the map
|
deba@1693
|
385 |
typedef xy<int> Value;
|
deba@1693
|
386 |
|
deba@1693
|
387 |
/// \brief Constructor
|
deba@1693
|
388 |
///
|
deba@1693
|
389 |
/// Constructor
|
deba@1693
|
390 |
IndexMap(const GridGraph& _graph) : graph(_graph) {}
|
deba@1693
|
391 |
|
deba@1693
|
392 |
/// \brief The subscript operator
|
deba@1693
|
393 |
///
|
deba@1693
|
394 |
/// The subscript operator.
|
deba@1693
|
395 |
Value operator[](Key key) const {
|
deba@1693
|
396 |
return xy<int>(graph.row(key), graph.col(key));
|
deba@1693
|
397 |
}
|
deba@1693
|
398 |
|
deba@1693
|
399 |
private:
|
deba@1693
|
400 |
const GridGraph& graph;
|
deba@1693
|
401 |
};
|
deba@1693
|
402 |
|
deba@1693
|
403 |
/// \brief Map to get the row of the nodes.
|
deba@1693
|
404 |
///
|
deba@1693
|
405 |
/// Map to get the row of the nodes.
|
deba@1693
|
406 |
class RowMap {
|
deba@1693
|
407 |
public:
|
deba@1693
|
408 |
typedef True NeedCopy;
|
deba@1693
|
409 |
/// \brief The key type of the map
|
deba@1693
|
410 |
typedef GridGraph::Node Key;
|
deba@1693
|
411 |
/// \brief The value type of the map
|
deba@1693
|
412 |
typedef int Value;
|
deba@1693
|
413 |
|
deba@1693
|
414 |
/// \brief Constructor
|
deba@1693
|
415 |
///
|
deba@1693
|
416 |
/// Constructor
|
deba@1693
|
417 |
RowMap(const GridGraph& _graph) : graph(_graph) {}
|
deba@1693
|
418 |
|
deba@1693
|
419 |
/// \brief The subscript operator
|
deba@1693
|
420 |
///
|
deba@1693
|
421 |
/// The subscript operator.
|
deba@1693
|
422 |
Value operator[](Key key) const {
|
deba@1693
|
423 |
return graph.row(key);
|
deba@1693
|
424 |
}
|
deba@1693
|
425 |
|
deba@1693
|
426 |
private:
|
deba@1693
|
427 |
const GridGraph& graph;
|
deba@1693
|
428 |
};
|
deba@1693
|
429 |
|
deba@1693
|
430 |
/// \brief Map to get the column of the nodes.
|
deba@1693
|
431 |
///
|
deba@1693
|
432 |
/// Map to get the column of the nodes.
|
deba@1693
|
433 |
class ColMap {
|
deba@1693
|
434 |
public:
|
deba@1693
|
435 |
typedef True NeedCopy;
|
deba@1693
|
436 |
/// \brief The key type of the map
|
deba@1693
|
437 |
typedef GridGraph::Node Key;
|
deba@1693
|
438 |
/// \brief The value type of the map
|
deba@1693
|
439 |
typedef int Value;
|
deba@1693
|
440 |
|
deba@1693
|
441 |
/// \brief Constructor
|
deba@1693
|
442 |
///
|
deba@1693
|
443 |
/// Constructor
|
deba@1693
|
444 |
ColMap(const GridGraph& _graph) : graph(_graph) {}
|
deba@1693
|
445 |
|
deba@1693
|
446 |
/// \brief The subscript operator
|
deba@1693
|
447 |
///
|
deba@1693
|
448 |
/// The subscript operator.
|
deba@1693
|
449 |
Value operator[](Key key) const {
|
deba@1693
|
450 |
return graph.col(key);
|
deba@1693
|
451 |
}
|
deba@1693
|
452 |
|
deba@1693
|
453 |
private:
|
deba@1693
|
454 |
const GridGraph& graph;
|
deba@1693
|
455 |
};
|
deba@1693
|
456 |
|
deba@1680
|
457 |
GridGraph(int n, int m) { construct(n, m); }
|
deba@1680
|
458 |
|
deba@1680
|
459 |
/// \brief Gives back the edge goes down from the node.
|
deba@1680
|
460 |
///
|
deba@1680
|
461 |
/// Gives back the edge goes down from the node. If there is not
|
deba@1680
|
462 |
/// outgoing edge then it gives back INVALID.
|
deba@1680
|
463 |
Edge down(Node n) const {
|
deba@1680
|
464 |
UndirEdge ue = _down(n);
|
deba@1680
|
465 |
return ue != INVALID ? direct(ue, true) : INVALID;
|
deba@1680
|
466 |
}
|
deba@1680
|
467 |
|
deba@1680
|
468 |
/// \brief Gives back the edge goes up from the node.
|
deba@1680
|
469 |
///
|
deba@1680
|
470 |
/// Gives back the edge goes up from the node. If there is not
|
deba@1680
|
471 |
/// outgoing edge then it gives back INVALID.
|
deba@1680
|
472 |
Edge up(Node n) const {
|
deba@1680
|
473 |
UndirEdge ue = _up(n);
|
deba@1680
|
474 |
return ue != INVALID ? direct(ue, false) : INVALID;
|
deba@1680
|
475 |
}
|
deba@1680
|
476 |
|
deba@1680
|
477 |
/// \brief Gives back the edge goes right from the node.
|
deba@1680
|
478 |
///
|
deba@1680
|
479 |
/// Gives back the edge goes right from the node. If there is not
|
deba@1680
|
480 |
/// outgoing edge then it gives back INVALID.
|
deba@1680
|
481 |
Edge right(Node n) const {
|
deba@1680
|
482 |
UndirEdge ue = _right(n);
|
deba@1680
|
483 |
return ue != INVALID ? direct(ue, true) : INVALID;
|
deba@1680
|
484 |
}
|
deba@1680
|
485 |
|
deba@1680
|
486 |
/// \brief Gives back the edge goes left from the node.
|
deba@1680
|
487 |
///
|
deba@1680
|
488 |
/// Gives back the edge goes left from the node. If there is not
|
deba@1680
|
489 |
/// outgoing edge then it gives back INVALID.
|
deba@1680
|
490 |
Edge left(Node n) const {
|
deba@1680
|
491 |
UndirEdge ue = _left(n);
|
deba@1680
|
492 |
return ue != INVALID ? direct(ue, false) : INVALID;
|
deba@1680
|
493 |
}
|
deba@1680
|
494 |
|
deba@1623
|
495 |
};
|
deba@1693
|
496 |
|
deba@1693
|
497 |
/// \brief Index map of the grid graph
|
deba@1693
|
498 |
///
|
deba@1693
|
499 |
/// Just returns an IndexMap for the grid graph.
|
deba@1693
|
500 |
GridGraph::IndexMap indexMap(const GridGraph& graph) {
|
deba@1693
|
501 |
return GridGraph::IndexMap(graph);
|
deba@1693
|
502 |
}
|
deba@1693
|
503 |
|
deba@1693
|
504 |
/// \brief Row map of the grid graph
|
deba@1693
|
505 |
///
|
deba@1693
|
506 |
/// Just returns an RowMap for the grid graph.
|
deba@1693
|
507 |
GridGraph::RowMap rowMap(const GridGraph& graph) {
|
deba@1693
|
508 |
return GridGraph::RowMap(graph);
|
deba@1693
|
509 |
}
|
deba@1693
|
510 |
|
deba@1693
|
511 |
/// \brief Coloumn map of the grid graph
|
deba@1693
|
512 |
///
|
deba@1693
|
513 |
/// Just returns an ColMap for the grid graph.
|
deba@1693
|
514 |
GridGraph::ColMap colMap(const GridGraph& graph) {
|
deba@1693
|
515 |
return GridGraph::ColMap(graph);
|
deba@1693
|
516 |
}
|
deba@1623
|
517 |
}
|
deba@1623
|
518 |
#endif
|