| ... | ... |
@@ -26,121 +26,127 @@ |
| 26 | 26 |
#include <lemon/core.h> |
| 27 | 27 |
#include <lemon/concepts/maps.h> |
| 28 | 28 |
|
| 29 | 29 |
#include <lemon/bits/alteration_notifier.h> |
| 30 | 30 |
|
| 31 | 31 |
namespace lemon {
|
| 32 | 32 |
namespace concepts {
|
| 33 | 33 |
|
| 34 | 34 |
/// \brief Concept class for \c Node, \c Arc and \c Edge types. |
| 35 | 35 |
/// |
| 36 | 36 |
/// This class describes the concept of \c Node, \c Arc and \c Edge |
| 37 | 37 |
/// subtypes of digraph and graph types. |
| 38 | 38 |
/// |
| 39 | 39 |
/// \note This class is a template class so that we can use it to |
| 40 | 40 |
/// create graph skeleton classes. The reason for this is that \c Node |
| 41 | 41 |
/// and \c Arc (or \c Edge) types should \e not derive from the same |
| 42 | 42 |
/// base class. For \c Node you should instantiate it with character |
| 43 | 43 |
/// \c 'n', for \c Arc with \c 'a' and for \c Edge with \c 'e'. |
| 44 | 44 |
#ifndef DOXYGEN |
| 45 | 45 |
template <char sel = '0'> |
| 46 | 46 |
#endif |
| 47 | 47 |
class GraphItem {
|
| 48 | 48 |
public: |
| 49 | 49 |
/// \brief Default constructor. |
| 50 | 50 |
/// |
| 51 | 51 |
/// Default constructor. |
| 52 | 52 |
/// \warning The default constructor is not required to set |
| 53 | 53 |
/// the item to some well-defined value. So you should consider it |
| 54 | 54 |
/// as uninitialized. |
| 55 | 55 |
GraphItem() {}
|
| 56 | 56 |
|
| 57 | 57 |
/// \brief Copy constructor. |
| 58 | 58 |
/// |
| 59 | 59 |
/// Copy constructor. |
| 60 | 60 |
GraphItem(const GraphItem &) {}
|
| 61 | 61 |
|
| 62 | 62 |
/// \brief Constructor for conversion from \c INVALID. |
| 63 | 63 |
/// |
| 64 | 64 |
/// Constructor for conversion from \c INVALID. |
| 65 | 65 |
/// It initializes the item to be invalid. |
| 66 | 66 |
/// \sa Invalid for more details. |
| 67 | 67 |
GraphItem(Invalid) {}
|
| 68 | 68 |
|
| 69 | 69 |
/// \brief Assignment operator. |
| 70 | 70 |
/// |
| 71 | 71 |
/// Assignment operator for the item. |
| 72 | 72 |
GraphItem& operator=(const GraphItem&) { return *this; }
|
| 73 | 73 |
|
| 74 |
/// \brief Assignment operator for INVALID. |
|
| 75 |
/// |
|
| 76 |
/// This operator makes the item invalid. |
|
| 77 |
GraphItem& operator=(Invalid) { return *this; }
|
|
| 78 |
|
|
| 74 | 79 |
/// \brief Equality operator. |
| 75 | 80 |
/// |
| 76 | 81 |
/// Equality operator. |
| 77 | 82 |
bool operator==(const GraphItem&) const { return false; }
|
| 78 | 83 |
|
| 79 | 84 |
/// \brief Inequality operator. |
| 80 | 85 |
/// |
| 81 | 86 |
/// Inequality operator. |
| 82 | 87 |
bool operator!=(const GraphItem&) const { return false; }
|
| 83 | 88 |
|
| 84 | 89 |
/// \brief Ordering operator. |
| 85 | 90 |
/// |
| 86 | 91 |
/// This operator defines an ordering of the items. |
| 87 | 92 |
/// It makes possible to use graph item types as key types in |
| 88 | 93 |
/// associative containers (e.g. \c std::map). |
| 89 | 94 |
/// |
| 90 | 95 |
/// \note This operator only have to define some strict ordering of |
| 91 | 96 |
/// the items; this order has nothing to do with the iteration |
| 92 | 97 |
/// ordering of the items. |
| 93 | 98 |
bool operator<(const GraphItem&) const { return false; }
|
| 94 | 99 |
|
| 95 | 100 |
template<typename _GraphItem> |
| 96 | 101 |
struct Constraints {
|
| 97 | 102 |
void constraints() {
|
| 98 | 103 |
_GraphItem i1; |
| 104 |
i1=INVALID; |
|
| 99 | 105 |
_GraphItem i2 = i1; |
| 100 | 106 |
_GraphItem i3 = INVALID; |
| 101 | 107 |
|
| 102 | 108 |
i1 = i2 = i3; |
| 103 | 109 |
|
| 104 | 110 |
bool b; |
| 105 | 111 |
b = (ia == ib) && (ia != ib); |
| 106 | 112 |
b = (ia == INVALID) && (ib != INVALID); |
| 107 | 113 |
b = (ia < ib); |
| 108 | 114 |
} |
| 109 | 115 |
|
| 110 | 116 |
const _GraphItem &ia; |
| 111 | 117 |
const _GraphItem &ib; |
| 112 | 118 |
}; |
| 113 | 119 |
}; |
| 114 | 120 |
|
| 115 | 121 |
/// \brief Base skeleton class for directed graphs. |
| 116 | 122 |
/// |
| 117 | 123 |
/// This class describes the base interface of directed graph types. |
| 118 | 124 |
/// All digraph %concepts have to conform to this class. |
| 119 | 125 |
/// It just provides types for nodes and arcs and functions |
| 120 | 126 |
/// to get the source and the target nodes of arcs. |
| 121 | 127 |
class BaseDigraphComponent {
|
| 122 | 128 |
public: |
| 123 | 129 |
|
| 124 | 130 |
typedef BaseDigraphComponent Digraph; |
| 125 | 131 |
|
| 126 | 132 |
/// \brief Node class of the digraph. |
| 127 | 133 |
/// |
| 128 | 134 |
/// This class represents the nodes of the digraph. |
| 129 | 135 |
typedef GraphItem<'n'> Node; |
| 130 | 136 |
|
| 131 | 137 |
/// \brief Arc class of the digraph. |
| 132 | 138 |
/// |
| 133 | 139 |
/// This class represents the arcs of the digraph. |
| 134 | 140 |
typedef GraphItem<'a'> Arc; |
| 135 | 141 |
|
| 136 | 142 |
/// \brief Return the source node of an arc. |
| 137 | 143 |
/// |
| 138 | 144 |
/// This function returns the source node of an arc. |
| 139 | 145 |
Node source(const Arc&) const { return INVALID; }
|
| 140 | 146 |
|
| 141 | 147 |
/// \brief Return the target node of an arc. |
| 142 | 148 |
/// |
| 143 | 149 |
/// This function returns the target node of an arc. |
| 144 | 150 |
Node target(const Arc&) const { return INVALID; }
|
| 145 | 151 |
|
| 146 | 152 |
/// \brief Return the opposite node on the given arc. |
| ... | ... |
@@ -176,104 +182,97 @@ |
| 176 | 182 |
/// This class describes the base interface of undirected graph types. |
| 177 | 183 |
/// All graph %concepts have to conform to this class. |
| 178 | 184 |
/// It extends the interface of \ref BaseDigraphComponent with an |
| 179 | 185 |
/// \c Edge type and functions to get the end nodes of edges, |
| 180 | 186 |
/// to convert from arcs to edges and to get both direction of edges. |
| 181 | 187 |
class BaseGraphComponent : public BaseDigraphComponent {
|
| 182 | 188 |
public: |
| 183 | 189 |
|
| 184 | 190 |
typedef BaseGraphComponent Graph; |
| 185 | 191 |
|
| 186 | 192 |
typedef BaseDigraphComponent::Node Node; |
| 187 | 193 |
typedef BaseDigraphComponent::Arc Arc; |
| 188 | 194 |
|
| 189 | 195 |
/// \brief Undirected edge class of the graph. |
| 190 | 196 |
/// |
| 191 | 197 |
/// This class represents the undirected edges of the graph. |
| 192 | 198 |
/// Undirected graphs can be used as directed graphs, each edge is |
| 193 | 199 |
/// represented by two opposite directed arcs. |
| 194 | 200 |
class Edge : public GraphItem<'e'> {
|
| 195 | 201 |
typedef GraphItem<'e'> Parent; |
| 196 | 202 |
|
| 197 | 203 |
public: |
| 198 | 204 |
/// \brief Default constructor. |
| 199 | 205 |
/// |
| 200 | 206 |
/// Default constructor. |
| 201 | 207 |
/// \warning The default constructor is not required to set |
| 202 | 208 |
/// the item to some well-defined value. So you should consider it |
| 203 | 209 |
/// as uninitialized. |
| 204 | 210 |
Edge() {}
|
| 205 | 211 |
|
| 206 | 212 |
/// \brief Copy constructor. |
| 207 | 213 |
/// |
| 208 | 214 |
/// Copy constructor. |
| 209 | 215 |
Edge(const Edge &) : Parent() {}
|
| 210 | 216 |
|
| 211 | 217 |
/// \brief Constructor for conversion from \c INVALID. |
| 212 | 218 |
/// |
| 213 | 219 |
/// Constructor for conversion from \c INVALID. |
| 214 | 220 |
/// It initializes the item to be invalid. |
| 215 | 221 |
/// \sa Invalid for more details. |
| 216 | 222 |
Edge(Invalid) {}
|
| 217 | 223 |
|
| 218 | 224 |
/// \brief Constructor for conversion from an arc. |
| 219 | 225 |
/// |
| 220 | 226 |
/// Constructor for conversion from an arc. |
| 221 | 227 |
/// Besides the core graph item functionality each arc should |
| 222 | 228 |
/// be convertible to the represented edge. |
| 223 | 229 |
Edge(const Arc&) {}
|
| 224 |
|
|
| 225 |
/// \brief Assign an arc to an edge. |
|
| 226 |
/// |
|
| 227 |
/// This function assigns an arc to an edge. |
|
| 228 |
/// Besides the core graph item functionality each arc should |
|
| 229 |
/// be convertible to the represented edge. |
|
| 230 |
Edge& operator=(const Arc&) { return *this; }
|
|
| 231 |
}; |
|
| 230 |
}; |
|
| 232 | 231 |
|
| 233 | 232 |
/// \brief Return one end node of an edge. |
| 234 | 233 |
/// |
| 235 | 234 |
/// This function returns one end node of an edge. |
| 236 | 235 |
Node u(const Edge&) const { return INVALID; }
|
| 237 | 236 |
|
| 238 | 237 |
/// \brief Return the other end node of an edge. |
| 239 | 238 |
/// |
| 240 | 239 |
/// This function returns the other end node of an edge. |
| 241 | 240 |
Node v(const Edge&) const { return INVALID; }
|
| 242 | 241 |
|
| 243 | 242 |
/// \brief Return a directed arc related to an edge. |
| 244 | 243 |
/// |
| 245 | 244 |
/// This function returns a directed arc from its direction and the |
| 246 | 245 |
/// represented edge. |
| 247 | 246 |
Arc direct(const Edge&, bool) const { return INVALID; }
|
| 248 | 247 |
|
| 249 | 248 |
/// \brief Return a directed arc related to an edge. |
| 250 | 249 |
/// |
| 251 | 250 |
/// This function returns a directed arc from its source node and the |
| 252 | 251 |
/// represented edge. |
| 253 | 252 |
Arc direct(const Edge&, const Node&) const { return INVALID; }
|
| 254 | 253 |
|
| 255 | 254 |
/// \brief Return the direction of the arc. |
| 256 | 255 |
/// |
| 257 | 256 |
/// Returns the direction of the arc. Each arc represents an |
| 258 | 257 |
/// edge with a direction. It gives back the |
| 259 | 258 |
/// direction. |
| 260 | 259 |
bool direction(const Arc&) const { return true; }
|
| 261 | 260 |
|
| 262 | 261 |
/// \brief Return the opposite arc. |
| 263 | 262 |
/// |
| 264 | 263 |
/// This function returns the opposite arc, i.e. the arc representing |
| 265 | 264 |
/// the same edge and has opposite direction. |
| 266 | 265 |
Arc oppositeArc(const Arc&) const { return INVALID; }
|
| 267 | 266 |
|
| 268 | 267 |
template <typename _Graph> |
| 269 | 268 |
struct Constraints {
|
| 270 | 269 |
typedef typename _Graph::Node Node; |
| 271 | 270 |
typedef typename _Graph::Arc Arc; |
| 272 | 271 |
typedef typename _Graph::Edge Edge; |
| 273 | 272 |
|
| 274 | 273 |
void constraints() {
|
| 275 | 274 |
checkConcept<BaseDigraphComponent, _Graph>(); |
| 276 | 275 |
checkConcept<GraphItem<'e'>, Edge>(); |
| 277 | 276 |
{
|
| 278 | 277 |
Node n; |
| 279 | 278 |
Edge ue(INVALID); |
| ... | ... |
@@ -308,100 +307,102 @@ |
| 308 | 307 |
typedef BAS Base; |
| 309 | 308 |
typedef typename Base::Node Node; |
| 310 | 309 |
typedef typename Base::Arc Arc; |
| 311 | 310 |
|
| 312 | 311 |
/// \brief Return a unique integer id for the given node. |
| 313 | 312 |
/// |
| 314 | 313 |
/// This function returns a unique integer id for the given node. |
| 315 | 314 |
int id(const Node&) const { return -1; }
|
| 316 | 315 |
|
| 317 | 316 |
/// \brief Return the node by its unique id. |
| 318 | 317 |
/// |
| 319 | 318 |
/// This function returns the node by its unique id. |
| 320 | 319 |
/// If the digraph does not contain a node with the given id, |
| 321 | 320 |
/// then the result of the function is undefined. |
| 322 | 321 |
Node nodeFromId(int) const { return INVALID; }
|
| 323 | 322 |
|
| 324 | 323 |
/// \brief Return a unique integer id for the given arc. |
| 325 | 324 |
/// |
| 326 | 325 |
/// This function returns a unique integer id for the given arc. |
| 327 | 326 |
int id(const Arc&) const { return -1; }
|
| 328 | 327 |
|
| 329 | 328 |
/// \brief Return the arc by its unique id. |
| 330 | 329 |
/// |
| 331 | 330 |
/// This function returns the arc by its unique id. |
| 332 | 331 |
/// If the digraph does not contain an arc with the given id, |
| 333 | 332 |
/// then the result of the function is undefined. |
| 334 | 333 |
Arc arcFromId(int) const { return INVALID; }
|
| 335 | 334 |
|
| 336 | 335 |
/// \brief Return an integer greater or equal to the maximum |
| 337 | 336 |
/// node id. |
| 338 | 337 |
/// |
| 339 | 338 |
/// This function returns an integer greater or equal to the |
| 340 | 339 |
/// maximum node id. |
| 341 | 340 |
int maxNodeId() const { return -1; }
|
| 342 | 341 |
|
| 343 | 342 |
/// \brief Return an integer greater or equal to the maximum |
| 344 | 343 |
/// arc id. |
| 345 | 344 |
/// |
| 346 | 345 |
/// This function returns an integer greater or equal to the |
| 347 | 346 |
/// maximum arc id. |
| 348 | 347 |
int maxArcId() const { return -1; }
|
| 349 | 348 |
|
| 350 | 349 |
template <typename _Digraph> |
| 351 | 350 |
struct Constraints {
|
| 352 | 351 |
|
| 353 | 352 |
void constraints() {
|
| 354 | 353 |
checkConcept<Base, _Digraph >(); |
| 355 | 354 |
typename _Digraph::Node node; |
| 355 |
node=INVALID; |
|
| 356 | 356 |
int nid = digraph.id(node); |
| 357 | 357 |
nid = digraph.id(node); |
| 358 | 358 |
node = digraph.nodeFromId(nid); |
| 359 | 359 |
typename _Digraph::Arc arc; |
| 360 |
arc=INVALID; |
|
| 360 | 361 |
int eid = digraph.id(arc); |
| 361 | 362 |
eid = digraph.id(arc); |
| 362 | 363 |
arc = digraph.arcFromId(eid); |
| 363 | 364 |
|
| 364 | 365 |
nid = digraph.maxNodeId(); |
| 365 | 366 |
ignore_unused_variable_warning(nid); |
| 366 | 367 |
eid = digraph.maxArcId(); |
| 367 | 368 |
ignore_unused_variable_warning(eid); |
| 368 | 369 |
} |
| 369 | 370 |
|
| 370 | 371 |
const _Digraph& digraph; |
| 371 | 372 |
}; |
| 372 | 373 |
}; |
| 373 | 374 |
|
| 374 | 375 |
/// \brief Skeleton class for \e idable undirected graphs. |
| 375 | 376 |
/// |
| 376 | 377 |
/// This class describes the interface of \e idable undirected |
| 377 | 378 |
/// graphs. It extends \ref IDableDigraphComponent with the core ID |
| 378 | 379 |
/// functions of undirected graphs. |
| 379 | 380 |
/// The ids of the items must be unique and immutable. |
| 380 | 381 |
/// This concept is part of the Graph concept. |
| 381 | 382 |
template <typename BAS = BaseGraphComponent> |
| 382 | 383 |
class IDableGraphComponent : public IDableDigraphComponent<BAS> {
|
| 383 | 384 |
public: |
| 384 | 385 |
|
| 385 | 386 |
typedef BAS Base; |
| 386 | 387 |
typedef typename Base::Edge Edge; |
| 387 | 388 |
|
| 388 | 389 |
using IDableDigraphComponent<Base>::id; |
| 389 | 390 |
|
| 390 | 391 |
/// \brief Return a unique integer id for the given edge. |
| 391 | 392 |
/// |
| 392 | 393 |
/// This function returns a unique integer id for the given edge. |
| 393 | 394 |
int id(const Edge&) const { return -1; }
|
| 394 | 395 |
|
| 395 | 396 |
/// \brief Return the edge by its unique id. |
| 396 | 397 |
/// |
| 397 | 398 |
/// This function returns the edge by its unique id. |
| 398 | 399 |
/// If the graph does not contain an edge with the given id, |
| 399 | 400 |
/// then the result of the function is undefined. |
| 400 | 401 |
Edge edgeFromId(int) const { return INVALID; }
|
| 401 | 402 |
|
| 402 | 403 |
/// \brief Return an integer greater or equal to the maximum |
| 403 | 404 |
/// edge id. |
| 404 | 405 |
/// |
| 405 | 406 |
/// This function returns an integer greater or equal to the |
| 406 | 407 |
/// maximum edge id. |
| 407 | 408 |
int maxEdgeId() const { return -1; }
|
0 comments (0 inline)