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