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