0
5
0
| 1 | 1 |
CMAKE_MINIMUM_REQUIRED(VERSION 2.6) |
| 2 | 2 |
|
| 3 | 3 |
IF(EXISTS ${CMAKE_SOURCE_DIR}/cmake/version.cmake)
|
| 4 | 4 |
INCLUDE(${CMAKE_SOURCE_DIR}/cmake/version.cmake)
|
| 5 | 5 |
ELSE(EXISTS ${CMAKE_SOURCE_DIR}/cmake/version.cmake)
|
| 6 | 6 |
SET(PROJECT_NAME "LEMON") |
| 7 | 7 |
SET(PROJECT_VERSION "hg-tip" CACHE STRING "LEMON version string.") |
| 8 | 8 |
ENDIF(EXISTS ${CMAKE_SOURCE_DIR}/cmake/version.cmake)
|
| 9 | 9 |
|
| 10 | 10 |
PROJECT(${PROJECT_NAME})
|
| 11 | 11 |
|
| 12 | 12 |
SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
|
| 13 | 13 |
|
| 14 | 14 |
INCLUDE(FindDoxygen) |
| 15 | 15 |
INCLUDE(FindGhostscript) |
| 16 | 16 |
FIND_PACKAGE(GLPK 4.33) |
| 17 | 17 |
FIND_PACKAGE(CPLEX) |
| 18 | 18 |
FIND_PACKAGE(COIN) |
| 19 | 19 |
|
| 20 | 20 |
IF(MSVC) |
| 21 |
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4250 /wd4355 /wd4800 /wd4996")
|
|
| 21 |
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4250 /wd4355 /wd4503 /wd4800 /wd4996")
|
|
| 22 | 22 |
# Suppressed warnings: |
| 23 | 23 |
# C4250: 'class1' : inherits 'class2::member' via dominance |
| 24 | 24 |
# C4355: 'this' : used in base member initializer list |
| 25 |
# C4503: 'function' : decorated name length exceeded, name was truncated |
|
| 25 | 26 |
# C4800: 'type' : forcing value to bool 'true' or 'false' (performance warning) |
| 26 | 27 |
# C4996: 'function': was declared deprecated |
| 27 | 28 |
ENDIF(MSVC) |
| 28 | 29 |
|
| 29 | 30 |
INCLUDE(CheckTypeSize) |
| 30 | 31 |
CHECK_TYPE_SIZE("long long" LEMON_LONG_LONG)
|
| 31 | 32 |
|
| 32 | 33 |
ENABLE_TESTING() |
| 33 | 34 |
|
| 34 | 35 |
ADD_SUBDIRECTORY(lemon) |
| 35 | 36 |
IF(${CMAKE_SOURCE_DIR} STREQUAL ${PROJECT_SOURCE_DIR})
|
| 36 | 37 |
ADD_SUBDIRECTORY(demo) |
| 37 | 38 |
ADD_SUBDIRECTORY(tools) |
| 38 | 39 |
ADD_SUBDIRECTORY(doc) |
| 39 | 40 |
ADD_SUBDIRECTORY(test) |
| 40 | 41 |
ENDIF(${CMAKE_SOURCE_DIR} STREQUAL ${PROJECT_SOURCE_DIR})
|
| 41 | 42 |
|
| 42 | 43 |
IF(${CMAKE_SOURCE_DIR} STREQUAL ${PROJECT_SOURCE_DIR})
|
| 43 | 44 |
IF(WIN32) |
| 44 | 45 |
SET(CPACK_PACKAGE_NAME ${PROJECT_NAME})
|
| 45 | 46 |
SET(CPACK_PACKAGE_VENDOR "EGRES") |
| 46 | 47 |
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY |
| 47 | 48 |
"LEMON - Library for Efficient Modeling and Optimization in Networks") |
| 48 | 49 |
SET(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
|
| 49 | 50 |
|
| 50 | 51 |
SET(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
|
| 51 | 52 |
|
| 52 | 53 |
SET(CPACK_PACKAGE_INSTALL_DIRECTORY |
| 53 | 54 |
"${PROJECT_NAME} ${PROJECT_VERSION}")
|
| 54 | 55 |
SET(CPACK_PACKAGE_INSTALL_REGISTRY_KEY |
| 55 | 56 |
"${PROJECT_NAME} ${PROJECT_VERSION}")
|
| 56 | 57 |
|
| 57 | 58 |
SET(CPACK_COMPONENTS_ALL headers library html_documentation bin) |
| 58 | 59 |
|
| 59 | 60 |
SET(CPACK_COMPONENT_HEADERS_DISPLAY_NAME "C++ headers") |
| 60 | 61 |
SET(CPACK_COMPONENT_LIBRARY_DISPLAY_NAME "Dynamic-link library") |
| 61 | 62 |
SET(CPACK_COMPONENT_BIN_DISPLAY_NAME "Command line utilities") |
| 62 | 63 |
SET(CPACK_COMPONENT_HTML_DOCUMENTATION_DISPLAY_NAME "HTML documentation") |
| 63 | 64 |
|
| 64 | 65 |
SET(CPACK_COMPONENT_HEADERS_DESCRIPTION |
| 65 | 66 |
"C++ header files") |
| 66 | 67 |
SET(CPACK_COMPONENT_LIBRARY_DESCRIPTION |
| 67 | 68 |
"DLL and import library") |
| 68 | 69 |
SET(CPACK_COMPONENT_BIN_DESCRIPTION |
| 69 | 70 |
"Command line utilities") |
| 70 | 71 |
SET(CPACK_COMPONENT_HTML_DOCUMENTATION_DESCRIPTION |
| 71 | 72 |
"Doxygen generated documentation") |
| 72 | 73 |
| 1 | 1 |
EXTRA_DIST += \ |
| 2 | 2 |
lemon/lemon.pc.in \ |
| 3 |
lemon/CMakeLists.txt |
|
| 3 |
lemon/CMakeLists.txt \ |
|
| 4 |
lemon/config.h.cmake |
|
| 4 | 5 |
|
| 5 | 6 |
pkgconfig_DATA += lemon/lemon.pc |
| 6 | 7 |
|
| 7 | 8 |
lib_LTLIBRARIES += lemon/libemon.la |
| 8 | 9 |
|
| 9 | 10 |
lemon_libemon_la_SOURCES = \ |
| 10 | 11 |
lemon/arg_parser.cc \ |
| 11 | 12 |
lemon/base.cc \ |
| 12 | 13 |
lemon/color.cc \ |
| 13 | 14 |
lemon/lp_base.cc \ |
| 14 | 15 |
lemon/lp_skeleton.cc \ |
| 15 | 16 |
lemon/random.cc \ |
| 16 | 17 |
lemon/bits/windows.cc |
| 17 | 18 |
|
| 18 | 19 |
nodist_lemon_HEADERS = lemon/config.h |
| 19 |
|
|
| 20 |
|
|
| 20 | 21 |
lemon_libemon_la_CXXFLAGS = \ |
| 21 | 22 |
$(AM_CXXFLAGS) \ |
| 22 | 23 |
$(GLPK_CFLAGS) \ |
| 23 | 24 |
$(CPLEX_CFLAGS) \ |
| 24 | 25 |
$(SOPLEX_CXXFLAGS) \ |
| 25 | 26 |
$(CLP_CXXFLAGS) \ |
| 26 | 27 |
$(CBC_CXXFLAGS) |
| 27 | 28 |
|
| 28 | 29 |
lemon_libemon_la_LDFLAGS = \ |
| 29 | 30 |
$(GLPK_LIBS) \ |
| 30 | 31 |
$(CPLEX_LIBS) \ |
| 31 | 32 |
$(SOPLEX_LIBS) \ |
| 32 | 33 |
$(CLP_LIBS) \ |
| 33 | 34 |
$(CBC_LIBS) |
| 34 | 35 |
|
| 35 | 36 |
if HAVE_GLPK |
| 36 | 37 |
lemon_libemon_la_SOURCES += lemon/glpk.cc |
| 37 | 38 |
endif |
| 38 | 39 |
|
| 39 | 40 |
if HAVE_CPLEX |
| 40 | 41 |
lemon_libemon_la_SOURCES += lemon/cplex.cc |
| 41 | 42 |
endif |
| 42 | 43 |
|
| 43 | 44 |
if HAVE_SOPLEX |
| 44 | 45 |
lemon_libemon_la_SOURCES += lemon/soplex.cc |
| 45 | 46 |
endif |
| 46 | 47 |
|
| 47 | 48 |
if HAVE_CLP |
| 48 | 49 |
lemon_libemon_la_SOURCES += lemon/clp.cc |
| 49 | 50 |
endif |
| 50 | 51 |
|
| 51 | 52 |
if HAVE_CBC |
| 52 | 53 |
lemon_libemon_la_SOURCES += lemon/cbc.cc |
| 53 | 54 |
endif |
| 54 | 55 |
|
| 55 | 56 |
lemon_HEADERS += \ |
| 56 | 57 |
lemon/adaptors.h \ |
| 57 | 58 |
lemon/arg_parser.h \ |
| 58 | 59 |
lemon/assert.h \ |
| 59 | 60 |
lemon/bfs.h \ |
| 60 | 61 |
lemon/bin_heap.h \ |
| 61 | 62 |
lemon/cbc.h \ |
| 62 | 63 |
lemon/circulation.h \ |
| 63 | 64 |
lemon/clp.h \ |
| 64 | 65 |
lemon/color.h \ |
| 65 | 66 |
lemon/concept_check.h \ |
| 66 | 67 |
lemon/connectivity.h \ |
| 67 | 68 |
lemon/counter.h \ |
| ... | ... |
@@ -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; }
|
| ... | ... |
@@ -39,96 +39,102 @@ |
| 39 | 39 |
protected: |
| 40 | 40 |
|
| 41 | 41 |
struct NodeT {
|
| 42 | 42 |
int first_out, first_in; |
| 43 | 43 |
NodeT() : first_out(-1), first_in(-1) {}
|
| 44 | 44 |
}; |
| 45 | 45 |
|
| 46 | 46 |
typedef typename ItemSetTraits<GR, Node>:: |
| 47 | 47 |
template Map<NodeT>::Type NodesImplBase; |
| 48 | 48 |
|
| 49 | 49 |
NodesImplBase* _nodes; |
| 50 | 50 |
|
| 51 | 51 |
struct ArcT {
|
| 52 | 52 |
Node source, target; |
| 53 | 53 |
int next_out, next_in; |
| 54 | 54 |
int prev_out, prev_in; |
| 55 | 55 |
ArcT() : prev_out(-1), prev_in(-1) {}
|
| 56 | 56 |
}; |
| 57 | 57 |
|
| 58 | 58 |
std::vector<ArcT> arcs; |
| 59 | 59 |
|
| 60 | 60 |
int first_arc; |
| 61 | 61 |
int first_free_arc; |
| 62 | 62 |
|
| 63 | 63 |
const GR* _graph; |
| 64 | 64 |
|
| 65 | 65 |
void initalize(const GR& graph, NodesImplBase& nodes) {
|
| 66 | 66 |
_graph = &graph; |
| 67 | 67 |
_nodes = &nodes; |
| 68 | 68 |
} |
| 69 | 69 |
|
| 70 | 70 |
public: |
| 71 | 71 |
|
| 72 | 72 |
class Arc {
|
| 73 | 73 |
friend class ListArcSetBase<GR>; |
| 74 | 74 |
protected: |
| 75 | 75 |
Arc(int _id) : id(_id) {}
|
| 76 | 76 |
int id; |
| 77 | 77 |
public: |
| 78 | 78 |
Arc() {}
|
| 79 | 79 |
Arc(Invalid) : id(-1) {}
|
| 80 | 80 |
bool operator==(const Arc& arc) const { return id == arc.id; }
|
| 81 | 81 |
bool operator!=(const Arc& arc) const { return id != arc.id; }
|
| 82 | 82 |
bool operator<(const Arc& arc) const { return id < arc.id; }
|
| 83 | 83 |
}; |
| 84 | 84 |
|
| 85 | 85 |
ListArcSetBase() : first_arc(-1), first_free_arc(-1) {}
|
| 86 | 86 |
|
| 87 |
Node addNode() {
|
|
| 88 |
LEMON_ASSERT(false, |
|
| 89 |
"This graph structure does not support node insertion"); |
|
| 90 |
return INVALID; // avoid warning |
|
| 91 |
} |
|
| 92 |
|
|
| 87 | 93 |
Arc addArc(const Node& u, const Node& v) {
|
| 88 | 94 |
int n; |
| 89 | 95 |
if (first_free_arc == -1) {
|
| 90 | 96 |
n = arcs.size(); |
| 91 | 97 |
arcs.push_back(ArcT()); |
| 92 | 98 |
} else {
|
| 93 | 99 |
n = first_free_arc; |
| 94 | 100 |
first_free_arc = arcs[first_free_arc].next_in; |
| 95 | 101 |
} |
| 96 | 102 |
arcs[n].next_in = (*_nodes)[v].first_in; |
| 97 | 103 |
if ((*_nodes)[v].first_in != -1) {
|
| 98 | 104 |
arcs[(*_nodes)[v].first_in].prev_in = n; |
| 99 | 105 |
} |
| 100 | 106 |
(*_nodes)[v].first_in = n; |
| 101 | 107 |
arcs[n].next_out = (*_nodes)[u].first_out; |
| 102 | 108 |
if ((*_nodes)[u].first_out != -1) {
|
| 103 | 109 |
arcs[(*_nodes)[u].first_out].prev_out = n; |
| 104 | 110 |
} |
| 105 | 111 |
(*_nodes)[u].first_out = n; |
| 106 | 112 |
arcs[n].source = u; |
| 107 | 113 |
arcs[n].target = v; |
| 108 | 114 |
return Arc(n); |
| 109 | 115 |
} |
| 110 | 116 |
|
| 111 | 117 |
void erase(const Arc& arc) {
|
| 112 | 118 |
int n = arc.id; |
| 113 | 119 |
if (arcs[n].prev_in != -1) {
|
| 114 | 120 |
arcs[arcs[n].prev_in].next_in = arcs[n].next_in; |
| 115 | 121 |
} else {
|
| 116 | 122 |
(*_nodes)[arcs[n].target].first_in = arcs[n].next_in; |
| 117 | 123 |
} |
| 118 | 124 |
if (arcs[n].next_in != -1) {
|
| 119 | 125 |
arcs[arcs[n].next_in].prev_in = arcs[n].prev_in; |
| 120 | 126 |
} |
| 121 | 127 |
|
| 122 | 128 |
if (arcs[n].prev_out != -1) {
|
| 123 | 129 |
arcs[arcs[n].prev_out].next_out = arcs[n].next_out; |
| 124 | 130 |
} else {
|
| 125 | 131 |
(*_nodes)[arcs[n].source].first_out = arcs[n].next_out; |
| 126 | 132 |
} |
| 127 | 133 |
if (arcs[n].next_out != -1) {
|
| 128 | 134 |
arcs[arcs[n].next_out].prev_out = arcs[n].prev_out; |
| 129 | 135 |
} |
| 130 | 136 |
|
| 131 | 137 |
} |
| 132 | 138 |
|
| 133 | 139 |
void clear() {
|
| 134 | 140 |
Node node; |
| ... | ... |
@@ -371,96 +377,102 @@ |
| 371 | 377 |
}; |
| 372 | 378 |
|
| 373 | 379 |
std::vector<ArcT> arcs; |
| 374 | 380 |
|
| 375 | 381 |
int first_arc; |
| 376 | 382 |
int first_free_arc; |
| 377 | 383 |
|
| 378 | 384 |
const GR* _graph; |
| 379 | 385 |
|
| 380 | 386 |
void initalize(const GR& graph, NodesImplBase& nodes) {
|
| 381 | 387 |
_graph = &graph; |
| 382 | 388 |
_nodes = &nodes; |
| 383 | 389 |
} |
| 384 | 390 |
|
| 385 | 391 |
public: |
| 386 | 392 |
|
| 387 | 393 |
class Edge {
|
| 388 | 394 |
friend class ListEdgeSetBase; |
| 389 | 395 |
protected: |
| 390 | 396 |
|
| 391 | 397 |
int id; |
| 392 | 398 |
explicit Edge(int _id) { id = _id;}
|
| 393 | 399 |
|
| 394 | 400 |
public: |
| 395 | 401 |
Edge() {}
|
| 396 | 402 |
Edge (Invalid) { id = -1; }
|
| 397 | 403 |
bool operator==(const Edge& arc) const {return id == arc.id;}
|
| 398 | 404 |
bool operator!=(const Edge& arc) const {return id != arc.id;}
|
| 399 | 405 |
bool operator<(const Edge& arc) const {return id < arc.id;}
|
| 400 | 406 |
}; |
| 401 | 407 |
|
| 402 | 408 |
class Arc {
|
| 403 | 409 |
friend class ListEdgeSetBase; |
| 404 | 410 |
protected: |
| 405 | 411 |
Arc(int _id) : id(_id) {}
|
| 406 | 412 |
int id; |
| 407 | 413 |
public: |
| 408 | 414 |
operator Edge() const { return edgeFromId(id / 2); }
|
| 409 | 415 |
|
| 410 | 416 |
Arc() {}
|
| 411 | 417 |
Arc(Invalid) : id(-1) {}
|
| 412 | 418 |
bool operator==(const Arc& arc) const { return id == arc.id; }
|
| 413 | 419 |
bool operator!=(const Arc& arc) const { return id != arc.id; }
|
| 414 | 420 |
bool operator<(const Arc& arc) const { return id < arc.id; }
|
| 415 | 421 |
}; |
| 416 | 422 |
|
| 417 | 423 |
ListEdgeSetBase() : first_arc(-1), first_free_arc(-1) {}
|
| 418 | 424 |
|
| 425 |
Node addNode() {
|
|
| 426 |
LEMON_ASSERT(false, |
|
| 427 |
"This graph structure does not support node insertion"); |
|
| 428 |
return INVALID; // avoid warning |
|
| 429 |
} |
|
| 430 |
|
|
| 419 | 431 |
Edge addEdge(const Node& u, const Node& v) {
|
| 420 | 432 |
int n; |
| 421 | 433 |
|
| 422 | 434 |
if (first_free_arc == -1) {
|
| 423 | 435 |
n = arcs.size(); |
| 424 | 436 |
arcs.push_back(ArcT()); |
| 425 | 437 |
arcs.push_back(ArcT()); |
| 426 | 438 |
} else {
|
| 427 | 439 |
n = first_free_arc; |
| 428 | 440 |
first_free_arc = arcs[n].next_out; |
| 429 | 441 |
} |
| 430 | 442 |
|
| 431 | 443 |
arcs[n].target = u; |
| 432 | 444 |
arcs[n | 1].target = v; |
| 433 | 445 |
|
| 434 | 446 |
arcs[n].next_out = (*_nodes)[v].first_out; |
| 435 | 447 |
if ((*_nodes)[v].first_out != -1) {
|
| 436 | 448 |
arcs[(*_nodes)[v].first_out].prev_out = n; |
| 437 | 449 |
} |
| 438 | 450 |
(*_nodes)[v].first_out = n; |
| 439 | 451 |
arcs[n].prev_out = -1; |
| 440 | 452 |
|
| 441 | 453 |
if ((*_nodes)[u].first_out != -1) {
|
| 442 | 454 |
arcs[(*_nodes)[u].first_out].prev_out = (n | 1); |
| 443 | 455 |
} |
| 444 | 456 |
arcs[n | 1].next_out = (*_nodes)[u].first_out; |
| 445 | 457 |
(*_nodes)[u].first_out = (n | 1); |
| 446 | 458 |
arcs[n | 1].prev_out = -1; |
| 447 | 459 |
|
| 448 | 460 |
return Edge(n / 2); |
| 449 | 461 |
} |
| 450 | 462 |
|
| 451 | 463 |
void erase(const Edge& arc) {
|
| 452 | 464 |
int n = arc.id * 2; |
| 453 | 465 |
|
| 454 | 466 |
if (arcs[n].next_out != -1) {
|
| 455 | 467 |
arcs[arcs[n].next_out].prev_out = arcs[n].prev_out; |
| 456 | 468 |
} |
| 457 | 469 |
|
| 458 | 470 |
if (arcs[n].prev_out != -1) {
|
| 459 | 471 |
arcs[arcs[n].prev_out].next_out = arcs[n].next_out; |
| 460 | 472 |
} else {
|
| 461 | 473 |
(*_nodes)[arcs[n | 1].target].first_out = arcs[n].next_out; |
| 462 | 474 |
} |
| 463 | 475 |
|
| 464 | 476 |
if (arcs[n | 1].next_out != -1) {
|
| 465 | 477 |
arcs[arcs[n | 1].next_out].prev_out = arcs[n | 1].prev_out; |
| 466 | 478 |
} |
| ... | ... |
@@ -771,96 +783,102 @@ |
| 771 | 783 |
|
| 772 | 784 |
typedef typename GR::Node Node; |
| 773 | 785 |
typedef typename GR::NodeIt NodeIt; |
| 774 | 786 |
|
| 775 | 787 |
protected: |
| 776 | 788 |
|
| 777 | 789 |
struct NodeT {
|
| 778 | 790 |
int first_out, first_in; |
| 779 | 791 |
NodeT() : first_out(-1), first_in(-1) {}
|
| 780 | 792 |
}; |
| 781 | 793 |
|
| 782 | 794 |
typedef typename ItemSetTraits<GR, Node>:: |
| 783 | 795 |
template Map<NodeT>::Type NodesImplBase; |
| 784 | 796 |
|
| 785 | 797 |
NodesImplBase* _nodes; |
| 786 | 798 |
|
| 787 | 799 |
struct ArcT {
|
| 788 | 800 |
Node source, target; |
| 789 | 801 |
int next_out, next_in; |
| 790 | 802 |
ArcT() {}
|
| 791 | 803 |
}; |
| 792 | 804 |
|
| 793 | 805 |
std::vector<ArcT> arcs; |
| 794 | 806 |
|
| 795 | 807 |
const GR* _graph; |
| 796 | 808 |
|
| 797 | 809 |
void initalize(const GR& graph, NodesImplBase& nodes) {
|
| 798 | 810 |
_graph = &graph; |
| 799 | 811 |
_nodes = &nodes; |
| 800 | 812 |
} |
| 801 | 813 |
|
| 802 | 814 |
public: |
| 803 | 815 |
|
| 804 | 816 |
class Arc {
|
| 805 | 817 |
friend class SmartArcSetBase<GR>; |
| 806 | 818 |
protected: |
| 807 | 819 |
Arc(int _id) : id(_id) {}
|
| 808 | 820 |
int id; |
| 809 | 821 |
public: |
| 810 | 822 |
Arc() {}
|
| 811 | 823 |
Arc(Invalid) : id(-1) {}
|
| 812 | 824 |
bool operator==(const Arc& arc) const { return id == arc.id; }
|
| 813 | 825 |
bool operator!=(const Arc& arc) const { return id != arc.id; }
|
| 814 | 826 |
bool operator<(const Arc& arc) const { return id < arc.id; }
|
| 815 | 827 |
}; |
| 816 | 828 |
|
| 817 | 829 |
SmartArcSetBase() {}
|
| 818 | 830 |
|
| 831 |
Node addNode() {
|
|
| 832 |
LEMON_ASSERT(false, |
|
| 833 |
"This graph structure does not support node insertion"); |
|
| 834 |
return INVALID; // avoid warning |
|
| 835 |
} |
|
| 836 |
|
|
| 819 | 837 |
Arc addArc(const Node& u, const Node& v) {
|
| 820 | 838 |
int n = arcs.size(); |
| 821 | 839 |
arcs.push_back(ArcT()); |
| 822 | 840 |
arcs[n].next_in = (*_nodes)[v].first_in; |
| 823 | 841 |
(*_nodes)[v].first_in = n; |
| 824 | 842 |
arcs[n].next_out = (*_nodes)[u].first_out; |
| 825 | 843 |
(*_nodes)[u].first_out = n; |
| 826 | 844 |
arcs[n].source = u; |
| 827 | 845 |
arcs[n].target = v; |
| 828 | 846 |
return Arc(n); |
| 829 | 847 |
} |
| 830 | 848 |
|
| 831 | 849 |
void clear() {
|
| 832 | 850 |
Node node; |
| 833 | 851 |
for (first(node); node != INVALID; next(node)) {
|
| 834 | 852 |
(*_nodes)[node].first_in = -1; |
| 835 | 853 |
(*_nodes)[node].first_out = -1; |
| 836 | 854 |
} |
| 837 | 855 |
arcs.clear(); |
| 838 | 856 |
} |
| 839 | 857 |
|
| 840 | 858 |
void first(Node& node) const {
|
| 841 | 859 |
_graph->first(node); |
| 842 | 860 |
} |
| 843 | 861 |
|
| 844 | 862 |
void next(Node& node) const {
|
| 845 | 863 |
_graph->next(node); |
| 846 | 864 |
} |
| 847 | 865 |
|
| 848 | 866 |
void first(Arc& arc) const {
|
| 849 | 867 |
arc.id = arcs.size() - 1; |
| 850 | 868 |
} |
| 851 | 869 |
|
| 852 | 870 |
void next(Arc& arc) const {
|
| 853 | 871 |
--arc.id; |
| 854 | 872 |
} |
| 855 | 873 |
|
| 856 | 874 |
void firstOut(Arc& arc, const Node& node) const {
|
| 857 | 875 |
arc.id = (*_nodes)[node].first_out; |
| 858 | 876 |
} |
| 859 | 877 |
|
| 860 | 878 |
void nextOut(Arc& arc) const {
|
| 861 | 879 |
arc.id = arcs[arc.id].next_out; |
| 862 | 880 |
} |
| 863 | 881 |
|
| 864 | 882 |
void firstIn(Arc& arc, const Node& node) const {
|
| 865 | 883 |
arc.id = (*_nodes)[node].first_in; |
| 866 | 884 |
} |
| ... | ... |
@@ -1067,96 +1085,102 @@ |
| 1067 | 1085 |
Node target; |
| 1068 | 1086 |
int next_out; |
| 1069 | 1087 |
ArcT() {}
|
| 1070 | 1088 |
}; |
| 1071 | 1089 |
|
| 1072 | 1090 |
std::vector<ArcT> arcs; |
| 1073 | 1091 |
|
| 1074 | 1092 |
const GR* _graph; |
| 1075 | 1093 |
|
| 1076 | 1094 |
void initalize(const GR& graph, NodesImplBase& nodes) {
|
| 1077 | 1095 |
_graph = &graph; |
| 1078 | 1096 |
_nodes = &nodes; |
| 1079 | 1097 |
} |
| 1080 | 1098 |
|
| 1081 | 1099 |
public: |
| 1082 | 1100 |
|
| 1083 | 1101 |
class Edge {
|
| 1084 | 1102 |
friend class SmartEdgeSetBase; |
| 1085 | 1103 |
protected: |
| 1086 | 1104 |
|
| 1087 | 1105 |
int id; |
| 1088 | 1106 |
explicit Edge(int _id) { id = _id;}
|
| 1089 | 1107 |
|
| 1090 | 1108 |
public: |
| 1091 | 1109 |
Edge() {}
|
| 1092 | 1110 |
Edge (Invalid) { id = -1; }
|
| 1093 | 1111 |
bool operator==(const Edge& arc) const {return id == arc.id;}
|
| 1094 | 1112 |
bool operator!=(const Edge& arc) const {return id != arc.id;}
|
| 1095 | 1113 |
bool operator<(const Edge& arc) const {return id < arc.id;}
|
| 1096 | 1114 |
}; |
| 1097 | 1115 |
|
| 1098 | 1116 |
class Arc {
|
| 1099 | 1117 |
friend class SmartEdgeSetBase; |
| 1100 | 1118 |
protected: |
| 1101 | 1119 |
Arc(int _id) : id(_id) {}
|
| 1102 | 1120 |
int id; |
| 1103 | 1121 |
public: |
| 1104 | 1122 |
operator Edge() const { return edgeFromId(id / 2); }
|
| 1105 | 1123 |
|
| 1106 | 1124 |
Arc() {}
|
| 1107 | 1125 |
Arc(Invalid) : id(-1) {}
|
| 1108 | 1126 |
bool operator==(const Arc& arc) const { return id == arc.id; }
|
| 1109 | 1127 |
bool operator!=(const Arc& arc) const { return id != arc.id; }
|
| 1110 | 1128 |
bool operator<(const Arc& arc) const { return id < arc.id; }
|
| 1111 | 1129 |
}; |
| 1112 | 1130 |
|
| 1113 | 1131 |
SmartEdgeSetBase() {}
|
| 1114 | 1132 |
|
| 1133 |
Node addNode() {
|
|
| 1134 |
LEMON_ASSERT(false, |
|
| 1135 |
"This graph structure does not support node insertion"); |
|
| 1136 |
return INVALID; // avoid warning |
|
| 1137 |
} |
|
| 1138 |
|
|
| 1115 | 1139 |
Edge addEdge(const Node& u, const Node& v) {
|
| 1116 | 1140 |
int n = arcs.size(); |
| 1117 | 1141 |
arcs.push_back(ArcT()); |
| 1118 | 1142 |
arcs.push_back(ArcT()); |
| 1119 | 1143 |
|
| 1120 | 1144 |
arcs[n].target = u; |
| 1121 | 1145 |
arcs[n | 1].target = v; |
| 1122 | 1146 |
|
| 1123 | 1147 |
arcs[n].next_out = (*_nodes)[v].first_out; |
| 1124 | 1148 |
(*_nodes)[v].first_out = n; |
| 1125 | 1149 |
|
| 1126 | 1150 |
arcs[n | 1].next_out = (*_nodes)[u].first_out; |
| 1127 | 1151 |
(*_nodes)[u].first_out = (n | 1); |
| 1128 | 1152 |
|
| 1129 | 1153 |
return Edge(n / 2); |
| 1130 | 1154 |
} |
| 1131 | 1155 |
|
| 1132 | 1156 |
void clear() {
|
| 1133 | 1157 |
Node node; |
| 1134 | 1158 |
for (first(node); node != INVALID; next(node)) {
|
| 1135 | 1159 |
(*_nodes)[node].first_out = -1; |
| 1136 | 1160 |
} |
| 1137 | 1161 |
arcs.clear(); |
| 1138 | 1162 |
} |
| 1139 | 1163 |
|
| 1140 | 1164 |
void first(Node& node) const {
|
| 1141 | 1165 |
_graph->first(node); |
| 1142 | 1166 |
} |
| 1143 | 1167 |
|
| 1144 | 1168 |
void next(Node& node) const {
|
| 1145 | 1169 |
_graph->next(node); |
| 1146 | 1170 |
} |
| 1147 | 1171 |
|
| 1148 | 1172 |
void first(Arc& arc) const {
|
| 1149 | 1173 |
arc.id = arcs.size() - 1; |
| 1150 | 1174 |
} |
| 1151 | 1175 |
|
| 1152 | 1176 |
void next(Arc& arc) const {
|
| 1153 | 1177 |
--arc.id; |
| 1154 | 1178 |
} |
| 1155 | 1179 |
|
| 1156 | 1180 |
void first(Edge& arc) const {
|
| 1157 | 1181 |
arc.id = arcs.size() / 2 - 1; |
| 1158 | 1182 |
} |
| 1159 | 1183 |
|
| 1160 | 1184 |
void next(Edge& arc) const {
|
| 1161 | 1185 |
--arc.id; |
| 1162 | 1186 |
} |
| ... | ... |
@@ -48,132 +48,135 @@ |
| 48 | 48 |
" 11 0 0 0 0 -10 0\n" |
| 49 | 49 |
" 12 -20 -27 0 -30 -30 -20\n" |
| 50 | 50 |
"\n" |
| 51 | 51 |
"@arcs\n" |
| 52 | 52 |
" cost cap low1 low2 low3\n" |
| 53 | 53 |
" 1 2 70 11 0 8 8\n" |
| 54 | 54 |
" 1 3 150 3 0 1 0\n" |
| 55 | 55 |
" 1 4 80 15 0 2 2\n" |
| 56 | 56 |
" 2 8 80 12 0 0 0\n" |
| 57 | 57 |
" 3 5 140 5 0 3 1\n" |
| 58 | 58 |
" 4 6 60 10 0 1 0\n" |
| 59 | 59 |
" 4 7 80 2 0 0 0\n" |
| 60 | 60 |
" 4 8 110 3 0 0 0\n" |
| 61 | 61 |
" 5 7 60 14 0 0 0\n" |
| 62 | 62 |
" 5 11 120 12 0 0 0\n" |
| 63 | 63 |
" 6 3 0 3 0 0 0\n" |
| 64 | 64 |
" 6 9 140 4 0 0 0\n" |
| 65 | 65 |
" 6 10 90 8 0 0 0\n" |
| 66 | 66 |
" 7 1 30 5 0 0 -5\n" |
| 67 | 67 |
" 8 12 60 16 0 4 3\n" |
| 68 | 68 |
" 9 12 50 6 0 0 0\n" |
| 69 | 69 |
"10 12 70 13 0 5 2\n" |
| 70 | 70 |
"10 2 100 7 0 0 0\n" |
| 71 | 71 |
"10 7 60 10 0 0 -3\n" |
| 72 | 72 |
"11 10 20 14 0 6 -20\n" |
| 73 | 73 |
"12 11 30 10 0 0 -10\n" |
| 74 | 74 |
"\n" |
| 75 | 75 |
"@attributes\n" |
| 76 | 76 |
"source 1\n" |
| 77 | 77 |
"target 12\n"; |
| 78 | 78 |
|
| 79 | 79 |
|
| 80 | 80 |
enum SupplyType {
|
| 81 | 81 |
EQ, |
| 82 | 82 |
GEQ, |
| 83 | 83 |
LEQ |
| 84 | 84 |
}; |
| 85 | 85 |
|
| 86 | 86 |
// Check the interface of an MCF algorithm |
| 87 | 87 |
template <typename GR, typename Value, typename Cost> |
| 88 | 88 |
class McfClassConcept |
| 89 | 89 |
{
|
| 90 | 90 |
public: |
| 91 | 91 |
|
| 92 | 92 |
template <typename MCF> |
| 93 | 93 |
struct Constraints {
|
| 94 | 94 |
void constraints() {
|
| 95 | 95 |
checkConcept<concepts::Digraph, GR>(); |
| 96 |
|
|
| 97 |
const Constraints& me = *this; |
|
| 96 | 98 |
|
| 97 |
MCF mcf(g); |
|
| 99 |
MCF mcf(me.g); |
|
| 98 | 100 |
const MCF& const_mcf = mcf; |
| 99 | 101 |
|
| 100 | 102 |
b = mcf.reset() |
| 101 |
.lowerMap(lower) |
|
| 102 |
.upperMap(upper) |
|
| 103 |
.costMap(cost) |
|
| 104 |
.supplyMap(sup) |
|
| 105 |
. |
|
| 103 |
.lowerMap(me.lower) |
|
| 104 |
.upperMap(me.upper) |
|
| 105 |
.costMap(me.cost) |
|
| 106 |
.supplyMap(me.sup) |
|
| 107 |
.stSupply(me.n, me.n, me.k) |
|
| 106 | 108 |
.run(); |
| 107 | 109 |
|
| 108 | 110 |
c = const_mcf.totalCost(); |
| 109 | 111 |
x = const_mcf.template totalCost<double>(); |
| 110 |
v = const_mcf.flow(a); |
|
| 111 |
c = const_mcf.potential(n); |
|
| 112 |
v = const_mcf.flow(me.a); |
|
| 113 |
c = const_mcf.potential(me.n); |
|
| 112 | 114 |
const_mcf.flowMap(fm); |
| 113 | 115 |
const_mcf.potentialMap(pm); |
| 114 | 116 |
} |
| 115 | 117 |
|
| 116 | 118 |
typedef typename GR::Node Node; |
| 117 | 119 |
typedef typename GR::Arc Arc; |
| 118 | 120 |
typedef concepts::ReadMap<Node, Value> NM; |
| 119 | 121 |
typedef concepts::ReadMap<Arc, Value> VAM; |
| 120 | 122 |
typedef concepts::ReadMap<Arc, Cost> CAM; |
| 121 | 123 |
typedef concepts::WriteMap<Arc, Value> FlowMap; |
| 122 | 124 |
typedef concepts::WriteMap<Node, Cost> PotMap; |
| 125 |
|
|
| 126 |
GR g; |
|
| 127 |
VAM lower; |
|
| 128 |
VAM upper; |
|
| 129 |
CAM cost; |
|
| 130 |
NM sup; |
|
| 131 |
Node n; |
|
| 132 |
Arc a; |
|
| 133 |
Value k; |
|
| 123 | 134 |
|
| 124 |
const GR &g; |
|
| 125 |
const VAM &lower; |
|
| 126 |
const VAM &upper; |
|
| 127 |
const CAM &cost; |
|
| 128 |
const NM ⊃ |
|
| 129 |
const Node &n; |
|
| 130 |
const Arc &a; |
|
| 131 |
const Value &k; |
|
| 132 | 135 |
FlowMap fm; |
| 133 | 136 |
PotMap pm; |
| 134 | 137 |
bool b; |
| 135 | 138 |
double x; |
| 136 | 139 |
typename MCF::Value v; |
| 137 | 140 |
typename MCF::Cost c; |
| 138 | 141 |
}; |
| 139 | 142 |
|
| 140 | 143 |
}; |
| 141 | 144 |
|
| 142 | 145 |
|
| 143 | 146 |
// Check the feasibility of the given flow (primal soluiton) |
| 144 | 147 |
template < typename GR, typename LM, typename UM, |
| 145 | 148 |
typename SM, typename FM > |
| 146 | 149 |
bool checkFlow( const GR& gr, const LM& lower, const UM& upper, |
| 147 | 150 |
const SM& supply, const FM& flow, |
| 148 | 151 |
SupplyType type = EQ ) |
| 149 | 152 |
{
|
| 150 | 153 |
TEMPLATE_DIGRAPH_TYPEDEFS(GR); |
| 151 | 154 |
|
| 152 | 155 |
for (ArcIt e(gr); e != INVALID; ++e) {
|
| 153 | 156 |
if (flow[e] < lower[e] || flow[e] > upper[e]) return false; |
| 154 | 157 |
} |
| 155 | 158 |
|
| 156 | 159 |
for (NodeIt n(gr); n != INVALID; ++n) {
|
| 157 | 160 |
typename SM::Value sum = 0; |
| 158 | 161 |
for (OutArcIt e(gr, n); e != INVALID; ++e) |
| 159 | 162 |
sum += flow[e]; |
| 160 | 163 |
for (InArcIt e(gr, n); e != INVALID; ++e) |
| 161 | 164 |
sum -= flow[e]; |
| 162 | 165 |
bool b = (type == EQ && sum == supply[n]) || |
| 163 | 166 |
(type == GEQ && sum >= supply[n]) || |
| 164 | 167 |
(type == LEQ && sum <= supply[n]); |
| 165 | 168 |
if (!b) return false; |
| 166 | 169 |
} |
| 167 | 170 |
|
| 168 | 171 |
return true; |
| 169 | 172 |
} |
| 170 | 173 |
|
| 171 | 174 |
// Check the feasibility of the given potentials (dual soluiton) |
| 172 | 175 |
// using the "Complementary Slackness" optimality condition |
| 173 | 176 |
template < typename GR, typename LM, typename UM, |
| 174 | 177 |
typename CM, typename SM, typename FM, typename PM > |
| 175 | 178 |
bool checkPotential( const GR& gr, const LM& lower, const UM& upper, |
| 176 | 179 |
const CM& cost, const SM& supply, const FM& flow, |
| 177 | 180 |
const PM& pi, SupplyType type ) |
| 178 | 181 |
{
|
| 179 | 182 |
TEMPLATE_DIGRAPH_TYPEDEFS(GR); |
0 comments (0 inline)