0
46
8
1 |
%%%%% Defining LEMON %%%%% |
|
2 |
|
|
3 |
@misc{lemon, |
|
4 |
key = {LEMON}, |
|
5 |
title = {{LEMON} -- {L}ibrary for {E}fficient {M}odeling and |
|
6 |
{O}ptimization in {N}etworks}, |
|
7 |
howpublished = {\url{http://lemon.cs.elte.hu/}}, |
|
8 |
year = 2009 |
|
9 |
} |
|
10 |
|
|
11 |
@misc{egres, |
|
12 |
key = {EGRES}, |
|
13 |
title = {{EGRES} -- {E}gerv{\'a}ry {R}esearch {G}roup on |
|
14 |
{C}ombinatorial {O}ptimization}, |
|
15 |
url = {http://www.cs.elte.hu/egres/} |
|
16 |
} |
|
17 |
|
|
18 |
@misc{coinor, |
|
19 |
key = {COIN-OR}, |
|
20 |
title = {{COIN-OR} -- {C}omputational {I}nfrastructure for |
|
21 |
{O}perations {R}esearch}, |
|
22 |
url = {http://www.coin-or.org/} |
|
23 |
} |
|
24 |
|
|
25 |
|
|
26 |
%%%%% Other libraries %%%%%% |
|
27 |
|
|
28 |
@misc{boost, |
|
29 |
key = {Boost}, |
|
30 |
title = {{B}oost {C++} {L}ibraries}, |
|
31 |
url = {http://www.boost.org/} |
|
32 |
} |
|
33 |
|
|
34 |
@book{bglbook, |
|
35 |
author = {Jeremy G. Siek and Lee-Quan Lee and Andrew |
|
36 |
Lumsdaine}, |
|
37 |
title = {The Boost Graph Library: User Guide and Reference |
|
38 |
Manual}, |
|
39 |
publisher = {Addison-Wesley}, |
|
40 |
year = 2002 |
|
41 |
} |
|
42 |
|
|
43 |
@misc{leda, |
|
44 |
key = {LEDA}, |
|
45 |
title = {{LEDA} -- {L}ibrary of {E}fficient {D}ata {T}ypes and |
|
46 |
{A}lgorithms}, |
|
47 |
url = {http://www.algorithmic-solutions.com/} |
|
48 |
} |
|
49 |
|
|
50 |
@book{ledabook, |
|
51 |
author = {Kurt Mehlhorn and Stefan N{\"a}her}, |
|
52 |
title = {{LEDA}: {A} platform for combinatorial and geometric |
|
53 |
computing}, |
|
54 |
isbn = {0-521-56329-1}, |
|
55 |
publisher = {Cambridge University Press}, |
|
56 |
address = {New York, NY, USA}, |
|
57 |
year = 1999 |
|
58 |
} |
|
59 |
|
|
60 |
|
|
61 |
%%%%% Tools that LEMON depends on %%%%% |
|
62 |
|
|
63 |
@misc{cmake, |
|
64 |
key = {CMake}, |
|
65 |
title = {{CMake} -- {C}ross {P}latform {M}ake}, |
|
66 |
url = {http://www.cmake.org/} |
|
67 |
} |
|
68 |
|
|
69 |
@misc{doxygen, |
|
70 |
key = {Doxygen}, |
|
71 |
title = {{Doxygen} -- {S}ource code documentation generator |
|
72 |
tool}, |
|
73 |
url = {http://www.doxygen.org/} |
|
74 |
} |
|
75 |
|
|
76 |
|
|
77 |
%%%%% LP/MIP libraries %%%%% |
|
78 |
|
|
79 |
@misc{glpk, |
|
80 |
key = {GLPK}, |
|
81 |
title = {{GLPK} -- {GNU} {L}inear {P}rogramming {K}it}, |
|
82 |
url = {http://www.gnu.org/software/glpk/} |
|
83 |
} |
|
84 |
|
|
85 |
@misc{clp, |
|
86 |
key = {Clp}, |
|
87 |
title = {{Clp} -- {Coin-Or} {L}inear {P}rogramming}, |
|
88 |
url = {http://projects.coin-or.org/Clp/} |
|
89 |
} |
|
90 |
|
|
91 |
@misc{cbc, |
|
92 |
key = {Cbc}, |
|
93 |
title = {{Cbc} -- {Coin-Or} {B}ranch and {C}ut}, |
|
94 |
url = {http://projects.coin-or.org/Cbc/} |
|
95 |
} |
|
96 |
|
|
97 |
@misc{cplex, |
|
98 |
key = {CPLEX}, |
|
99 |
title = {{ILOG} {CPLEX}}, |
|
100 |
url = {http://www.ilog.com/} |
|
101 |
} |
|
102 |
|
|
103 |
@misc{soplex, |
|
104 |
key = {SoPlex}, |
|
105 |
title = {{SoPlex} -- {T}he {S}equential {O}bject-{O}riented |
|
106 |
{S}implex}, |
|
107 |
url = {http://soplex.zib.de/} |
|
108 |
} |
|
109 |
|
|
110 |
|
|
111 |
%%%%% General books %%%%% |
|
112 |
|
|
113 |
@book{amo93networkflows, |
|
114 |
author = {Ravindra K. Ahuja and Thomas L. Magnanti and James |
|
115 |
B. Orlin}, |
|
116 |
title = {Network Flows: Theory, Algorithms, and Applications}, |
|
117 |
publisher = {Prentice-Hall, Inc.}, |
|
118 |
year = 1993, |
|
119 |
month = feb, |
|
120 |
isbn = {978-0136175490} |
|
121 |
} |
|
122 |
|
|
123 |
@book{schrijver03combinatorial, |
|
124 |
author = {Alexander Schrijver}, |
|
125 |
title = {Combinatorial Optimization: Polyhedra and Efficiency}, |
|
126 |
publisher = {Springer-Verlag}, |
|
127 |
year = 2003, |
|
128 |
isbn = {978-3540443896} |
|
129 |
} |
|
130 |
|
|
131 |
@book{clrs01algorithms, |
|
132 |
author = {Thomas H. Cormen and Charles E. Leiserson and Ronald |
|
133 |
L. Rivest and Clifford Stein}, |
|
134 |
title = {Introduction to Algorithms}, |
|
135 |
publisher = {The MIT Press}, |
|
136 |
year = 2001, |
|
137 |
edition = {2nd} |
|
138 |
} |
|
139 |
|
|
140 |
@book{stroustrup00cpp, |
|
141 |
author = {Bjarne Stroustrup}, |
|
142 |
title = {The C++ Programming Language}, |
|
143 |
edition = {3rd}, |
|
144 |
publisher = {Addison-Wesley Professional}, |
|
145 |
isbn = 0201700735, |
|
146 |
month = {February}, |
|
147 |
year = 2000 |
|
148 |
} |
|
149 |
|
|
150 |
|
|
151 |
%%%%% Maximum flow algorithms %%%%% |
|
152 |
|
|
153 |
@article{edmondskarp72theoretical, |
|
154 |
author = {Jack Edmonds and Richard M. Karp}, |
|
155 |
title = {Theoretical improvements in algorithmic efficiency |
|
156 |
for network flow problems}, |
|
157 |
journal = {Journal of the ACM}, |
|
158 |
year = 1972, |
|
159 |
volume = 19, |
|
160 |
number = 2, |
|
161 |
pages = {248-264} |
|
162 |
} |
|
163 |
|
|
164 |
@article{goldberg88newapproach, |
|
165 |
author = {Andrew V. Goldberg and Robert E. Tarjan}, |
|
166 |
title = {A new approach to the maximum flow problem}, |
|
167 |
journal = {Journal of the ACM}, |
|
168 |
year = 1988, |
|
169 |
volume = 35, |
|
170 |
number = 4, |
|
171 |
pages = {921-940} |
|
172 |
} |
|
173 |
|
|
174 |
@article{dinic70algorithm, |
|
175 |
author = {E. A. Dinic}, |
|
176 |
title = {Algorithm for solution of a problem of maximum flow |
|
177 |
in a network with power estimation}, |
|
178 |
journal = {Soviet Math. Doklady}, |
|
179 |
year = 1970, |
|
180 |
volume = 11, |
|
181 |
pages = {1277-1280} |
|
182 |
} |
|
183 |
|
|
184 |
@article{goldberg08partial, |
|
185 |
author = {Andrew V. Goldberg}, |
|
186 |
title = {The Partial Augment-Relabel Algorithm for the |
|
187 |
Maximum Flow Problem}, |
|
188 |
journal = {16th Annual European Symposium on Algorithms}, |
|
189 |
year = 2008, |
|
190 |
pages = {466-477} |
|
191 |
} |
|
192 |
|
|
193 |
@article{sleator83dynamic, |
|
194 |
author = {Daniel D. Sleator and Robert E. Tarjan}, |
|
195 |
title = {A data structure for dynamic trees}, |
|
196 |
journal = {Journal of Computer and System Sciences}, |
|
197 |
year = 1983, |
|
198 |
volume = 26, |
|
199 |
number = 3, |
|
200 |
pages = {362-391} |
|
201 |
} |
|
202 |
|
|
203 |
|
|
204 |
%%%%% Minimum mean cycle algorithms %%%%% |
|
205 |
|
|
206 |
@article{karp78characterization, |
|
207 |
author = {Richard M. Karp}, |
|
208 |
title = {A characterization of the minimum cycle mean in a |
|
209 |
digraph}, |
|
210 |
journal = {Discrete Math.}, |
|
211 |
year = 1978, |
|
212 |
volume = 23, |
|
213 |
pages = {309-311} |
|
214 |
} |
|
215 |
|
|
216 |
@article{dasdan98minmeancycle, |
|
217 |
author = {Ali Dasdan and Rajesh K. Gupta}, |
|
218 |
title = {Faster Maximum and Minimum Mean Cycle Alogrithms for |
|
219 |
System Performance Analysis}, |
|
220 |
journal = {IEEE Transactions on Computer-Aided Design of |
|
221 |
Integrated Circuits and Systems}, |
|
222 |
year = 1998, |
|
223 |
volume = 17, |
|
224 |
number = 10, |
|
225 |
pages = {889-899} |
|
226 |
} |
|
227 |
|
|
228 |
|
|
229 |
%%%%% Minimum cost flow algorithms %%%%% |
|
230 |
|
|
231 |
@article{klein67primal, |
|
232 |
author = {Morton Klein}, |
|
233 |
title = {A primal method for minimal cost flows with |
|
234 |
applications to the assignment and transportation |
|
235 |
problems}, |
|
236 |
journal = {Management Science}, |
|
237 |
year = 1967, |
|
238 |
volume = 14, |
|
239 |
pages = {205-220} |
|
240 |
} |
|
241 |
|
|
242 |
@article{goldberg89cyclecanceling, |
|
243 |
author = {Andrew V. Goldberg and Robert E. Tarjan}, |
|
244 |
title = {Finding minimum-cost circulations by canceling |
|
245 |
negative cycles}, |
|
246 |
journal = {Journal of the ACM}, |
|
247 |
year = 1989, |
|
248 |
volume = 36, |
|
249 |
number = 4, |
|
250 |
pages = {873-886} |
|
251 |
} |
|
252 |
|
|
253 |
@article{goldberg90approximation, |
|
254 |
author = {Andrew V. Goldberg and Robert E. Tarjan}, |
|
255 |
title = {Finding Minimum-Cost Circulations by Successive |
|
256 |
Approximation}, |
|
257 |
journal = {Mathematics of Operations Research}, |
|
258 |
year = 1990, |
|
259 |
volume = 15, |
|
260 |
number = 3, |
|
261 |
pages = {430-466} |
|
262 |
} |
|
263 |
|
|
264 |
@article{goldberg97efficient, |
|
265 |
author = {Andrew V. Goldberg}, |
|
266 |
title = {An Efficient Implementation of a Scaling |
|
267 |
Minimum-Cost Flow Algorithm}, |
|
268 |
journal = {Journal of Algorithms}, |
|
269 |
year = 1997, |
|
270 |
volume = 22, |
|
271 |
number = 1, |
|
272 |
pages = {1-29} |
|
273 |
} |
|
274 |
|
|
275 |
@article{bunnagel98efficient, |
|
276 |
author = {Ursula B{\"u}nnagel and Bernhard Korte and Jens |
|
277 |
Vygen}, |
|
278 |
title = {Efficient implementation of the {G}oldberg-{T}arjan |
|
279 |
minimum-cost flow algorithm}, |
|
280 |
journal = {Optimization Methods and Software}, |
|
281 |
year = 1998, |
|
282 |
volume = 10, |
|
283 |
pages = {157-174} |
|
284 |
} |
|
285 |
|
|
286 |
@book{dantzig63linearprog, |
|
287 |
author = {George B. Dantzig}, |
|
288 |
title = {Linear Programming and Extensions}, |
|
289 |
publisher = {Princeton University Press}, |
|
290 |
year = 1963 |
|
291 |
} |
|
292 |
|
|
293 |
@mastersthesis{kellyoneill91netsimplex, |
|
294 |
author = {Damian J. Kelly and Garrett M. O'Neill}, |
|
295 |
title = {The Minimum Cost Flow Problem and The Network |
|
296 |
Simplex Method}, |
|
297 |
school = {University College}, |
|
298 |
address = {Dublin, Ireland}, |
|
299 |
year = 1991, |
|
300 |
month = sep, |
|
301 |
} |
1 | 1 |
CMAKE_MINIMUM_REQUIRED(VERSION 2.6) |
2 | 2 |
|
3 | 3 |
SET(PROJECT_NAME "LEMON") |
4 | 4 |
PROJECT(${PROJECT_NAME}) |
5 | 5 |
|
6 | 6 |
IF(EXISTS ${PROJECT_SOURCE_DIR}/cmake/version.cmake) |
7 | 7 |
INCLUDE(${PROJECT_SOURCE_DIR}/cmake/version.cmake) |
8 | 8 |
ELSEIF(DEFINED ENV{LEMON_VERSION}) |
9 | 9 |
SET(LEMON_VERSION $ENV{LEMON_VERSION} CACHE STRING "LEMON version string.") |
10 | 10 |
ELSE() |
11 | 11 |
EXECUTE_PROCESS( |
12 | 12 |
COMMAND hg id -i |
13 | 13 |
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} |
14 | 14 |
OUTPUT_VARIABLE HG_REVISION |
15 | 15 |
ERROR_QUIET |
16 | 16 |
OUTPUT_STRIP_TRAILING_WHITESPACE |
17 | 17 |
) |
18 | 18 |
IF(HG_REVISION STREQUAL "") |
19 | 19 |
SET(HG_REVISION "hg-tip") |
20 | 20 |
ENDIF() |
21 | 21 |
SET(LEMON_VERSION ${HG_REVISION} CACHE STRING "LEMON version string.") |
22 | 22 |
ENDIF() |
23 | 23 |
|
24 | 24 |
SET(PROJECT_VERSION ${LEMON_VERSION}) |
25 | 25 |
|
26 | 26 |
SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) |
27 | 27 |
|
28 | 28 |
FIND_PACKAGE(Doxygen) |
29 | 29 |
FIND_PACKAGE(Ghostscript) |
30 | 30 |
FIND_PACKAGE(GLPK 4.33) |
31 | 31 |
FIND_PACKAGE(CPLEX) |
32 | 32 |
FIND_PACKAGE(COIN) |
33 | 33 |
|
34 | 34 |
INCLUDE(CheckTypeSize) |
35 | 35 |
CHECK_TYPE_SIZE("long long" LONG_LONG) |
36 | 36 |
SET(LEMON_HAVE_LONG_LONG ${HAVE_LONG_LONG}) |
37 | 37 |
|
38 |
INCLUDE(FindPythonInterp) |
|
39 |
|
|
38 | 40 |
ENABLE_TESTING() |
39 | 41 |
|
40 | 42 |
ADD_SUBDIRECTORY(lemon) |
41 | 43 |
IF(${CMAKE_SOURCE_DIR} STREQUAL ${PROJECT_SOURCE_DIR}) |
42 | 44 |
ADD_SUBDIRECTORY(demo) |
43 | 45 |
ADD_SUBDIRECTORY(tools) |
44 | 46 |
ADD_SUBDIRECTORY(doc) |
45 | 47 |
ADD_SUBDIRECTORY(test) |
46 | 48 |
ENDIF() |
47 | 49 |
|
48 | 50 |
CONFIGURE_FILE( |
49 | 51 |
${PROJECT_SOURCE_DIR}/cmake/LEMONConfig.cmake.in |
50 | 52 |
${PROJECT_BINARY_DIR}/cmake/LEMONConfig.cmake |
51 | 53 |
@ONLY |
52 | 54 |
) |
53 | 55 |
IF(UNIX) |
54 | 56 |
INSTALL( |
55 | 57 |
FILES ${PROJECT_BINARY_DIR}/cmake/LEMONConfig.cmake |
56 | 58 |
DESTINATION share/lemon/cmake |
57 | 59 |
) |
58 | 60 |
ELSEIF(WIN32) |
59 | 61 |
INSTALL( |
60 | 62 |
FILES ${PROJECT_BINARY_DIR}/cmake/LEMONConfig.cmake |
61 | 63 |
DESTINATION cmake |
62 | 64 |
) |
63 | 65 |
ENDIF() |
64 | 66 |
|
65 | 67 |
IF(${CMAKE_SOURCE_DIR} STREQUAL ${PROJECT_SOURCE_DIR} AND WIN32) |
66 | 68 |
SET(CPACK_PACKAGE_NAME ${PROJECT_NAME}) |
67 | 69 |
SET(CPACK_PACKAGE_VENDOR "EGRES") |
68 | 70 |
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY |
69 | 71 |
"LEMON - Library for Efficient Modeling and Optimization in Networks") |
70 | 72 |
SET(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE") |
71 | 73 |
|
72 | 74 |
SET(CPACK_PACKAGE_VERSION ${PROJECT_VERSION}) |
73 | 75 |
|
74 | 76 |
SET(CPACK_PACKAGE_INSTALL_DIRECTORY |
75 | 77 |
"${PROJECT_NAME} ${PROJECT_VERSION}") |
76 | 78 |
SET(CPACK_PACKAGE_INSTALL_REGISTRY_KEY |
77 | 79 |
"${PROJECT_NAME} ${PROJECT_VERSION}") |
78 | 80 |
|
79 | 81 |
SET(CPACK_COMPONENTS_ALL headers library html_documentation bin) |
80 | 82 |
|
81 | 83 |
SET(CPACK_COMPONENT_HEADERS_DISPLAY_NAME "C++ headers") |
82 | 84 |
SET(CPACK_COMPONENT_LIBRARY_DISPLAY_NAME "Dynamic-link library") |
83 | 85 |
SET(CPACK_COMPONENT_BIN_DISPLAY_NAME "Command line utilities") |
84 | 86 |
SET(CPACK_COMPONENT_HTML_DOCUMENTATION_DISPLAY_NAME "HTML documentation") |
85 | 87 |
|
86 | 88 |
SET(CPACK_COMPONENT_HEADERS_DESCRIPTION |
87 | 89 |
"C++ header files") |
88 | 90 |
SET(CPACK_COMPONENT_LIBRARY_DESCRIPTION |
89 | 91 |
"DLL and import library") |
90 | 92 |
SET(CPACK_COMPONENT_BIN_DESCRIPTION |
91 | 93 |
"Command line utilities") |
92 | 94 |
SET(CPACK_COMPONENT_HTML_DOCUMENTATION_DESCRIPTION |
93 | 95 |
"Doxygen generated documentation") |
94 | 96 |
|
95 | 97 |
SET(CPACK_COMPONENT_HEADERS_DEPENDS library) |
96 | 98 |
|
97 | 99 |
SET(CPACK_COMPONENT_HEADERS_GROUP "Development") |
98 | 100 |
SET(CPACK_COMPONENT_LIBRARY_GROUP "Development") |
99 | 101 |
SET(CPACK_COMPONENT_HTML_DOCUMENTATION_GROUP "Documentation") |
100 | 102 |
|
101 | 103 |
SET(CPACK_COMPONENT_GROUP_DEVELOPMENT_DESCRIPTION |
102 | 104 |
"Components needed to develop software using LEMON") |
103 | 105 |
SET(CPACK_COMPONENT_GROUP_DOCUMENTATION_DESCRIPTION |
104 | 106 |
"Documentation of LEMON") |
105 | 107 |
|
106 | 108 |
SET(CPACK_ALL_INSTALL_TYPES Full Developer) |
107 | 109 |
|
108 | 110 |
SET(CPACK_COMPONENT_HEADERS_INSTALL_TYPES Developer Full) |
109 | 111 |
SET(CPACK_COMPONENT_LIBRARY_INSTALL_TYPES Developer Full) |
110 | 112 |
SET(CPACK_COMPONENT_HTML_DOCUMENTATION_INSTALL_TYPES Full) |
111 | 113 |
|
112 | 114 |
SET(CPACK_GENERATOR "NSIS") |
113 | 115 |
SET(CPACK_NSIS_MUI_ICON "${PROJECT_SOURCE_DIR}/cmake/nsis/lemon.ico") |
114 | 116 |
SET(CPACK_NSIS_MUI_UNIICON "${PROJECT_SOURCE_DIR}/cmake/nsis/uninstall.ico") |
115 | 117 |
#SET(CPACK_PACKAGE_ICON "${PROJECT_SOURCE_DIR}/cmake/nsis\\\\installer.bmp") |
116 | 118 |
SET(CPACK_NSIS_INSTALLED_ICON_NAME "bin\\\\lemon.ico") |
117 | 119 |
SET(CPACK_NSIS_DISPLAY_NAME "${CPACK_PACKAGE_INSTALL_DIRECTORY} ${PROJECT_NAME}") |
118 | 120 |
SET(CPACK_NSIS_HELP_LINK "http:\\\\\\\\lemon.cs.elte.hu") |
119 | 121 |
SET(CPACK_NSIS_URL_INFO_ABOUT "http:\\\\\\\\lemon.cs.elte.hu") |
120 | 122 |
SET(CPACK_NSIS_CONTACT "lemon-user@lemon.cs.elte.hu") |
121 | 123 |
SET(CPACK_NSIS_CREATE_ICONS_EXTRA " |
122 | 124 |
CreateShortCut \\\"$SMPROGRAMS\\\\$STARTMENU_FOLDER\\\\Documentation.lnk\\\" \\\"$INSTDIR\\\\share\\\\doc\\\\index.html\\\" |
123 | 125 |
") |
124 | 126 |
SET(CPACK_NSIS_DELETE_ICONS_EXTRA " |
125 | 127 |
!insertmacro MUI_STARTMENU_GETFOLDER Application $MUI_TEMP |
126 | 128 |
Delete \\\"$SMPROGRAMS\\\\$MUI_TEMP\\\\Documentation.lnk\\\" |
127 | 129 |
") |
128 | 130 |
|
129 | 131 |
INCLUDE(CPack) |
130 | 132 |
ENDIF() |
1 | 1 |
ACLOCAL_AMFLAGS = -I m4 |
2 | 2 |
|
3 | 3 |
AM_CXXFLAGS = $(WARNINGCXXFLAGS) |
4 | 4 |
|
5 | 5 |
AM_CPPFLAGS = -I$(top_srcdir) -I$(top_builddir) |
6 | 6 |
LDADD = $(top_builddir)/lemon/libemon.la |
7 | 7 |
|
8 | 8 |
EXTRA_DIST = \ |
9 | 9 |
AUTHORS \ |
10 | 10 |
LICENSE \ |
11 | 11 |
m4/lx_check_cplex.m4 \ |
12 | 12 |
m4/lx_check_glpk.m4 \ |
13 | 13 |
m4/lx_check_soplex.m4 \ |
14 | 14 |
m4/lx_check_coin.m4 \ |
15 | 15 |
CMakeLists.txt \ |
16 | 16 |
cmake/FindGhostscript.cmake \ |
17 | 17 |
cmake/FindCPLEX.cmake \ |
18 | 18 |
cmake/FindGLPK.cmake \ |
19 | 19 |
cmake/FindCOIN.cmake \ |
20 |
cmake/LEMONConfig.cmake.in \ |
|
20 | 21 |
cmake/version.cmake.in \ |
21 | 22 |
cmake/version.cmake \ |
22 | 23 |
cmake/nsis/lemon.ico \ |
23 | 24 |
cmake/nsis/uninstall.ico |
24 | 25 |
|
25 | 26 |
pkgconfigdir = $(libdir)/pkgconfig |
26 | 27 |
lemondir = $(pkgincludedir) |
27 | 28 |
bitsdir = $(lemondir)/bits |
28 | 29 |
conceptdir = $(lemondir)/concepts |
29 | 30 |
pkgconfig_DATA = |
30 | 31 |
lib_LTLIBRARIES = |
31 | 32 |
lemon_HEADERS = |
32 | 33 |
bits_HEADERS = |
33 | 34 |
concept_HEADERS = |
34 | 35 |
noinst_HEADERS = |
35 | 36 |
noinst_PROGRAMS = |
36 | 37 |
bin_PROGRAMS = |
37 | 38 |
check_PROGRAMS = |
38 | 39 |
dist_bin_SCRIPTS = |
39 | 40 |
TESTS = |
40 | 41 |
XFAIL_TESTS = |
41 | 42 |
|
42 | 43 |
include lemon/Makefile.am |
43 | 44 |
include test/Makefile.am |
44 | 45 |
include doc/Makefile.am |
45 | 46 |
include tools/Makefile.am |
46 | 47 |
|
47 | 48 |
DIST_SUBDIRS = demo |
48 | 49 |
|
49 | 50 |
demo: |
50 | 51 |
$(MAKE) $(AM_MAKEFLAGS) -C demo |
51 | 52 |
|
52 | 53 |
MRPROPERFILES = \ |
53 | 54 |
aclocal.m4 \ |
54 | 55 |
config.h.in \ |
55 | 56 |
config.h.in~ \ |
56 | 57 |
configure \ |
57 | 58 |
Makefile.in \ |
58 | 59 |
build-aux/config.guess \ |
59 | 60 |
build-aux/config.sub \ |
60 | 61 |
build-aux/depcomp \ |
61 | 62 |
build-aux/install-sh \ |
62 | 63 |
build-aux/ltmain.sh \ |
63 | 64 |
build-aux/missing \ |
64 | 65 |
doc/doxygen.log |
65 | 66 |
|
66 | 67 |
mrproper: |
67 | 68 |
$(MAKE) $(AM_MAKEFLAGS) maintainer-clean |
68 | 69 |
-rm -f $(MRPROPERFILES) |
69 | 70 |
|
70 | 71 |
dist-bz2: dist |
71 | 72 |
zcat $(PACKAGE)-$(VERSION).tar.gz | \ |
72 | 73 |
bzip2 --best -c > $(PACKAGE)-$(VERSION).tar.bz2 |
73 | 74 |
|
74 | 75 |
distcheck-bz2: distcheck |
75 | 76 |
zcat $(PACKAGE)-$(VERSION).tar.gz | \ |
76 | 77 |
bzip2 --best -c > $(PACKAGE)-$(VERSION).tar.bz2 |
77 | 78 |
|
78 | 79 |
.PHONY: demo mrproper dist-bz2 distcheck-bz2 |
1 | 1 |
dnl Process this file with autoconf to produce a configure script. |
2 | 2 |
|
3 | 3 |
dnl Version information. |
4 | 4 |
m4_define([lemon_version_number], |
5 | 5 |
[m4_normalize(esyscmd([echo ${LEMON_VERSION}]))]) |
6 | 6 |
dnl m4_define([lemon_version_number], []) |
7 | 7 |
m4_define([lemon_hg_path], [m4_normalize(esyscmd([./scripts/chg-len.py]))]) |
8 | 8 |
m4_define([lemon_hg_revision], [m4_normalize(esyscmd([hg id -i 2> /dev/null]))]) |
9 | 9 |
m4_define([lemon_version], [ifelse(lemon_version_number(), |
10 | 10 |
[], |
11 | 11 |
[ifelse(lemon_hg_revision(), |
12 | 12 |
[], |
13 | 13 |
[hg-tip], |
14 | 14 |
[lemon_hg_path().lemon_hg_revision()])], |
15 | 15 |
[lemon_version_number()])]) |
16 | 16 |
|
17 | 17 |
AC_PREREQ([2.59]) |
18 | 18 |
AC_INIT([LEMON], [lemon_version()], [lemon-user@lemon.cs.elte.hu], [lemon]) |
19 | 19 |
AC_CONFIG_AUX_DIR([build-aux]) |
20 | 20 |
AC_CONFIG_MACRO_DIR([m4]) |
21 | 21 |
AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects nostdinc]) |
22 | 22 |
AC_CONFIG_SRCDIR([lemon/list_graph.h]) |
23 | 23 |
AC_CONFIG_HEADERS([config.h lemon/config.h]) |
24 | 24 |
|
25 | 25 |
AC_DEFINE([LEMON_VERSION], [lemon_version()], [The version string]) |
26 | 26 |
|
27 | 27 |
dnl Do compilation tests using the C++ compiler. |
28 | 28 |
AC_LANG([C++]) |
29 | 29 |
|
30 | 30 |
dnl Check the existence of long long type. |
31 | 31 |
AC_CHECK_TYPE(long long, [long_long_found=yes], [long_long_found=no]) |
32 | 32 |
if test x"$long_long_found" = x"yes"; then |
33 | 33 |
AC_DEFINE([LEMON_HAVE_LONG_LONG], [1], [Define to 1 if you have long long.]) |
34 | 34 |
fi |
35 | 35 |
|
36 | 36 |
dnl Checks for programs. |
37 | 37 |
AC_PROG_CXX |
38 | 38 |
AC_PROG_CXXCPP |
39 | 39 |
AC_PROG_INSTALL |
40 | 40 |
AC_DISABLE_SHARED |
41 | 41 |
AC_PROG_LIBTOOL |
42 | 42 |
|
43 | 43 |
AC_CHECK_PROG([doxygen_found],[doxygen],[yes],[no]) |
44 |
AC_CHECK_PROG([python_found],[python],[yes],[no]) |
|
44 | 45 |
AC_CHECK_PROG([gs_found],[gs],[yes],[no]) |
45 | 46 |
|
46 | 47 |
dnl Detect Intel compiler. |
47 | 48 |
AC_MSG_CHECKING([whether we are using the Intel C++ compiler]) |
48 | 49 |
AC_COMPILE_IFELSE([#ifndef __INTEL_COMPILER |
49 | 50 |
choke me |
50 | 51 |
#endif], [ICC=[yes]], [ICC=[no]]) |
51 | 52 |
if test x"$ICC" = x"yes"; then |
52 | 53 |
AC_MSG_RESULT([yes]) |
53 | 54 |
else |
54 | 55 |
AC_MSG_RESULT([no]) |
55 | 56 |
fi |
56 | 57 |
|
57 | 58 |
dnl Set custom compiler flags when using g++. |
58 | 59 |
if test "$GXX" = yes -a "$ICC" = no; then |
59 | 60 |
WARNINGCXXFLAGS="-Wall -W -Wall -W -Wunused -Wformat=2 -Wctor-dtor-privacy -Wnon-virtual-dtor -Wno-char-subscripts -Wwrite-strings -Wno-char-subscripts -Wreturn-type -Wcast-qual -Wcast-align -Wsign-promo -Woverloaded-virtual -ansi -fno-strict-aliasing -Wold-style-cast -Wno-unknown-pragmas" |
60 | 61 |
fi |
61 | 62 |
AC_SUBST([WARNINGCXXFLAGS]) |
62 | 63 |
|
63 | 64 |
dnl Checks for libraries. |
64 | 65 |
LX_CHECK_GLPK |
65 | 66 |
LX_CHECK_CPLEX |
66 | 67 |
LX_CHECK_SOPLEX |
67 | 68 |
LX_CHECK_COIN |
68 | 69 |
|
69 | 70 |
AM_CONDITIONAL([HAVE_LP], [test x"$lx_lp_found" = x"yes"]) |
70 | 71 |
AM_CONDITIONAL([HAVE_MIP], [test x"$lx_mip_found" = x"yes"]) |
71 | 72 |
|
72 | 73 |
dnl Disable/enable building the binary tools. |
73 | 74 |
AC_ARG_ENABLE([tools], |
74 | 75 |
AS_HELP_STRING([--enable-tools], [build additional tools @<:@default@:>@]) |
75 | 76 |
AS_HELP_STRING([--disable-tools], [do not build additional tools]), |
76 | 77 |
[], [enable_tools=yes]) |
77 | 78 |
AC_MSG_CHECKING([whether to build the additional tools]) |
78 | 79 |
if test x"$enable_tools" != x"no"; then |
79 | 80 |
AC_MSG_RESULT([yes]) |
80 | 81 |
else |
81 | 82 |
AC_MSG_RESULT([no]) |
82 | 83 |
fi |
83 | 84 |
AM_CONDITIONAL([WANT_TOOLS], [test x"$enable_tools" != x"no"]) |
84 | 85 |
|
85 | 86 |
dnl Checks for header files. |
86 | 87 |
AC_CHECK_HEADERS(limits.h sys/time.h sys/times.h unistd.h) |
87 | 88 |
|
88 | 89 |
dnl Checks for typedefs, structures, and compiler characteristics. |
89 | 90 |
AC_C_CONST |
90 | 91 |
AC_C_INLINE |
91 | 92 |
AC_TYPE_SIZE_T |
92 | 93 |
AC_HEADER_TIME |
93 | 94 |
AC_STRUCT_TM |
94 | 95 |
|
95 | 96 |
dnl Checks for library functions. |
96 | 97 |
AC_HEADER_STDC |
97 | 98 |
AC_CHECK_FUNCS(gettimeofday times ctime_r) |
98 | 99 |
|
99 | 100 |
dnl Add dependencies on files generated by configure. |
100 | 101 |
AC_SUBST([CONFIG_STATUS_DEPENDENCIES], |
101 | 102 |
['$(top_srcdir)/doc/Doxyfile.in $(top_srcdir)/lemon/lemon.pc.in $(top_srcdir)/cmake/version.cmake.in']) |
102 | 103 |
|
103 | 104 |
AC_CONFIG_FILES([ |
104 | 105 |
Makefile |
105 | 106 |
demo/Makefile |
106 | 107 |
cmake/version.cmake |
107 | 108 |
doc/Doxyfile |
108 | 109 |
lemon/lemon.pc |
109 | 110 |
]) |
110 | 111 |
|
111 | 112 |
AC_OUTPUT |
112 | 113 |
|
113 | 114 |
echo |
114 | 115 |
echo '****************************** SUMMARY ******************************' |
115 | 116 |
echo |
116 | 117 |
echo Package version............... : $PACKAGE-$VERSION |
117 | 118 |
echo |
118 | 119 |
echo C++ compiler.................. : $CXX |
119 | 120 |
echo C++ compiles flags............ : $WARNINGCXXFLAGS $CXXFLAGS |
120 | 121 |
echo |
121 | 122 |
echo Compiler supports long long... : $long_long_found |
122 | 123 |
echo |
123 | 124 |
echo GLPK support.................. : $lx_glpk_found |
124 | 125 |
echo CPLEX support................. : $lx_cplex_found |
125 | 126 |
echo SOPLEX support................ : $lx_soplex_found |
126 | 127 |
echo CLP support................... : $lx_clp_found |
127 | 128 |
echo CBC support................... : $lx_cbc_found |
128 | 129 |
echo |
129 | 130 |
echo Build additional tools........ : $enable_tools |
130 | 131 |
echo |
131 | 132 |
echo The packace will be installed in |
132 | 133 |
echo -n ' ' |
133 | 134 |
echo $prefix. |
134 | 135 |
echo |
135 | 136 |
echo '*********************************************************************' |
136 | 137 |
|
137 | 138 |
echo |
138 | 139 |
echo Configure complete, now type \'make\' and then \'make install\'. |
139 | 140 |
echo |
1 | 1 |
SET(PACKAGE_NAME ${PROJECT_NAME}) |
2 | 2 |
SET(PACKAGE_VERSION ${PROJECT_VERSION}) |
3 | 3 |
SET(abs_top_srcdir ${PROJECT_SOURCE_DIR}) |
4 | 4 |
SET(abs_top_builddir ${PROJECT_BINARY_DIR}) |
5 | 5 |
|
6 | 6 |
CONFIGURE_FILE( |
7 | 7 |
${PROJECT_SOURCE_DIR}/doc/Doxyfile.in |
8 | 8 |
${PROJECT_BINARY_DIR}/doc/Doxyfile |
9 | 9 |
@ONLY |
10 | 10 |
) |
11 | 11 |
|
12 |
IF(DOXYGEN_EXECUTABLE AND GHOSTSCRIPT_EXECUTABLE) |
|
12 |
IF(DOXYGEN_EXECUTABLE AND PYTHONINTERP_FOUND AND GHOSTSCRIPT_EXECUTABLE) |
|
13 | 13 |
FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html/) |
14 | 14 |
SET(GHOSTSCRIPT_OPTIONS -dNOPAUSE -dBATCH -q -dEPSCrop -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDEVICE=pngalpha) |
15 | 15 |
ADD_CUSTOM_TARGET(html |
16 | 16 |
COMMAND ${CMAKE_COMMAND} -E remove_directory gen-images |
17 | 17 |
COMMAND ${CMAKE_COMMAND} -E make_directory gen-images |
18 | 18 |
COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r18 -sOutputFile=gen-images/bipartite_matching.png ${CMAKE_CURRENT_SOURCE_DIR}/images/bipartite_matching.eps |
19 | 19 |
COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r18 -sOutputFile=gen-images/bipartite_partitions.png ${CMAKE_CURRENT_SOURCE_DIR}/images/bipartite_partitions.eps |
20 | 20 |
COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r18 -sOutputFile=gen-images/connected_components.png ${CMAKE_CURRENT_SOURCE_DIR}/images/connected_components.eps |
21 | 21 |
COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r18 -sOutputFile=gen-images/edge_biconnected_components.png ${CMAKE_CURRENT_SOURCE_DIR}/images/edge_biconnected_components.eps |
22 | 22 |
COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r18 -sOutputFile=gen-images/grid_graph.png ${CMAKE_CURRENT_SOURCE_DIR}/images/grid_graph.eps |
23 | 23 |
COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r18 -sOutputFile=gen-images/node_biconnected_components.png ${CMAKE_CURRENT_SOURCE_DIR}/images/node_biconnected_components.eps |
24 | 24 |
COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r18 -sOutputFile=gen-images/nodeshape_0.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_0.eps |
25 | 25 |
COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r18 -sOutputFile=gen-images/nodeshape_1.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_1.eps |
26 | 26 |
COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r18 -sOutputFile=gen-images/nodeshape_2.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_2.eps |
27 | 27 |
COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r18 -sOutputFile=gen-images/nodeshape_3.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_3.eps |
28 | 28 |
COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r18 -sOutputFile=gen-images/nodeshape_4.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_4.eps |
29 | 29 |
COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r18 -sOutputFile=gen-images/strongly_connected_components.png ${CMAKE_CURRENT_SOURCE_DIR}/images/strongly_connected_components.eps |
30 | 30 |
COMMAND ${CMAKE_COMMAND} -E remove_directory html |
31 |
COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/scripts/bib2dox.py ${CMAKE_CURRENT_SOURCE_DIR}/references.bib >references.dox |
|
31 | 32 |
COMMAND ${DOXYGEN_EXECUTABLE} Doxyfile |
32 | 33 |
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
33 | 34 |
) |
34 | 35 |
|
35 | 36 |
SET_TARGET_PROPERTIES(html PROPERTIES PROJECT_LABEL BUILD_DOC) |
36 | 37 |
|
37 | 38 |
IF(UNIX) |
38 | 39 |
INSTALL( |
39 | 40 |
DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html/ |
40 | 41 |
DESTINATION share/doc/lemon/html |
41 | 42 |
COMPONENT html_documentation |
42 | 43 |
) |
43 | 44 |
ELSEIF(WIN32) |
44 | 45 |
INSTALL( |
45 | 46 |
DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html/ |
46 | 47 |
DESTINATION doc |
47 | 48 |
COMPONENT html_documentation |
48 | 49 |
) |
49 | 50 |
ENDIF() |
50 | 51 |
|
51 | 52 |
ENDIF() |
1 |
# Doxyfile 1.5. |
|
1 |
# Doxyfile 1.5.9 |
|
2 | 2 |
|
3 | 3 |
#--------------------------------------------------------------------------- |
4 | 4 |
# Project related configuration options |
5 | 5 |
#--------------------------------------------------------------------------- |
6 | 6 |
DOXYFILE_ENCODING = UTF-8 |
7 | 7 |
PROJECT_NAME = @PACKAGE_NAME@ |
8 | 8 |
PROJECT_NUMBER = @PACKAGE_VERSION@ |
9 | 9 |
OUTPUT_DIRECTORY = |
10 | 10 |
CREATE_SUBDIRS = NO |
11 | 11 |
OUTPUT_LANGUAGE = English |
12 | 12 |
BRIEF_MEMBER_DESC = YES |
13 | 13 |
REPEAT_BRIEF = NO |
14 | 14 |
ABBREVIATE_BRIEF = |
15 | 15 |
ALWAYS_DETAILED_SEC = NO |
16 | 16 |
INLINE_INHERITED_MEMB = NO |
17 | 17 |
FULL_PATH_NAMES = YES |
18 | 18 |
STRIP_FROM_PATH = "@abs_top_srcdir@" |
19 | 19 |
STRIP_FROM_INC_PATH = "@abs_top_srcdir@" |
20 | 20 |
SHORT_NAMES = YES |
21 | 21 |
JAVADOC_AUTOBRIEF = NO |
22 | 22 |
QT_AUTOBRIEF = NO |
23 | 23 |
MULTILINE_CPP_IS_BRIEF = NO |
24 |
DETAILS_AT_TOP = YES |
|
25 | 24 |
INHERIT_DOCS = NO |
26 | 25 |
SEPARATE_MEMBER_PAGES = NO |
27 | 26 |
TAB_SIZE = 8 |
28 | 27 |
ALIASES = |
29 | 28 |
OPTIMIZE_OUTPUT_FOR_C = NO |
30 | 29 |
OPTIMIZE_OUTPUT_JAVA = NO |
31 | 30 |
OPTIMIZE_FOR_FORTRAN = NO |
32 | 31 |
OPTIMIZE_OUTPUT_VHDL = NO |
33 | 32 |
BUILTIN_STL_SUPPORT = YES |
34 | 33 |
CPP_CLI_SUPPORT = NO |
35 | 34 |
SIP_SUPPORT = NO |
36 | 35 |
IDL_PROPERTY_SUPPORT = YES |
37 | 36 |
DISTRIBUTE_GROUP_DOC = NO |
38 | 37 |
SUBGROUPING = YES |
39 | 38 |
TYPEDEF_HIDES_STRUCT = NO |
40 | 39 |
SYMBOL_CACHE_SIZE = 0 |
41 | 40 |
#--------------------------------------------------------------------------- |
42 | 41 |
# Build related configuration options |
43 | 42 |
#--------------------------------------------------------------------------- |
44 | 43 |
EXTRACT_ALL = NO |
45 | 44 |
EXTRACT_PRIVATE = YES |
46 | 45 |
EXTRACT_STATIC = YES |
47 | 46 |
EXTRACT_LOCAL_CLASSES = NO |
48 | 47 |
EXTRACT_LOCAL_METHODS = NO |
49 | 48 |
EXTRACT_ANON_NSPACES = NO |
50 | 49 |
HIDE_UNDOC_MEMBERS = YES |
51 | 50 |
HIDE_UNDOC_CLASSES = YES |
52 | 51 |
HIDE_FRIEND_COMPOUNDS = NO |
53 | 52 |
HIDE_IN_BODY_DOCS = NO |
54 | 53 |
INTERNAL_DOCS = NO |
55 | 54 |
CASE_SENSE_NAMES = YES |
56 | 55 |
HIDE_SCOPE_NAMES = YES |
57 | 56 |
SHOW_INCLUDE_FILES = YES |
58 | 57 |
INLINE_INFO = YES |
59 | 58 |
SORT_MEMBER_DOCS = NO |
60 | 59 |
SORT_BRIEF_DOCS = NO |
61 | 60 |
SORT_GROUP_NAMES = NO |
62 | 61 |
SORT_BY_SCOPE_NAME = NO |
63 | 62 |
GENERATE_TODOLIST = YES |
64 | 63 |
GENERATE_TESTLIST = YES |
65 | 64 |
GENERATE_BUGLIST = YES |
66 | 65 |
GENERATE_DEPRECATEDLIST= YES |
67 | 66 |
ENABLED_SECTIONS = |
68 | 67 |
MAX_INITIALIZER_LINES = 5 |
69 | 68 |
SHOW_USED_FILES = NO |
70 | 69 |
SHOW_DIRECTORIES = YES |
71 | 70 |
SHOW_FILES = YES |
72 | 71 |
SHOW_NAMESPACES = YES |
73 | 72 |
FILE_VERSION_FILTER = |
74 | 73 |
LAYOUT_FILE = DoxygenLayout.xml |
75 | 74 |
#--------------------------------------------------------------------------- |
76 | 75 |
# configuration options related to warning and progress messages |
77 | 76 |
#--------------------------------------------------------------------------- |
78 | 77 |
QUIET = NO |
79 | 78 |
WARNINGS = YES |
80 | 79 |
WARN_IF_UNDOCUMENTED = YES |
81 | 80 |
WARN_IF_DOC_ERROR = YES |
82 | 81 |
WARN_NO_PARAMDOC = NO |
83 | 82 |
WARN_FORMAT = "$file:$line: $text" |
84 | 83 |
WARN_LOGFILE = doxygen.log |
85 | 84 |
#--------------------------------------------------------------------------- |
86 | 85 |
# configuration options related to the input files |
87 | 86 |
#--------------------------------------------------------------------------- |
88 | 87 |
INPUT = "@abs_top_srcdir@/doc" \ |
89 | 88 |
"@abs_top_srcdir@/lemon" \ |
90 | 89 |
"@abs_top_srcdir@/lemon/bits" \ |
91 | 90 |
"@abs_top_srcdir@/lemon/concepts" \ |
92 | 91 |
"@abs_top_srcdir@/demo" \ |
93 | 92 |
"@abs_top_srcdir@/tools" \ |
94 |
"@abs_top_srcdir@/test/test_tools.h" |
|
93 |
"@abs_top_srcdir@/test/test_tools.h" \ |
|
94 |
"@abs_top_builddir@/doc/references.dox" |
|
95 | 95 |
INPUT_ENCODING = UTF-8 |
96 | 96 |
FILE_PATTERNS = *.h \ |
97 | 97 |
*.cc \ |
98 | 98 |
*.dox |
99 | 99 |
RECURSIVE = NO |
100 | 100 |
EXCLUDE = |
101 | 101 |
EXCLUDE_SYMLINKS = NO |
102 | 102 |
EXCLUDE_PATTERNS = |
103 | 103 |
EXCLUDE_SYMBOLS = |
104 | 104 |
EXAMPLE_PATH = "@abs_top_srcdir@/demo" \ |
105 | 105 |
"@abs_top_srcdir@/LICENSE" \ |
106 | 106 |
"@abs_top_srcdir@/doc" |
107 | 107 |
EXAMPLE_PATTERNS = |
108 | 108 |
EXAMPLE_RECURSIVE = NO |
109 | 109 |
IMAGE_PATH = "@abs_top_srcdir@/doc/images" \ |
110 | 110 |
"@abs_top_builddir@/doc/gen-images" |
111 | 111 |
INPUT_FILTER = |
112 | 112 |
FILTER_PATTERNS = |
113 | 113 |
FILTER_SOURCE_FILES = NO |
114 | 114 |
#--------------------------------------------------------------------------- |
115 | 115 |
# configuration options related to source browsing |
116 | 116 |
#--------------------------------------------------------------------------- |
117 | 117 |
SOURCE_BROWSER = NO |
118 | 118 |
INLINE_SOURCES = NO |
119 | 119 |
STRIP_CODE_COMMENTS = YES |
120 | 120 |
REFERENCED_BY_RELATION = NO |
121 | 121 |
REFERENCES_RELATION = NO |
122 | 122 |
REFERENCES_LINK_SOURCE = YES |
123 | 123 |
USE_HTAGS = NO |
124 | 124 |
VERBATIM_HEADERS = NO |
125 | 125 |
#--------------------------------------------------------------------------- |
126 | 126 |
# configuration options related to the alphabetical class index |
127 | 127 |
#--------------------------------------------------------------------------- |
128 | 128 |
ALPHABETICAL_INDEX = YES |
129 | 129 |
COLS_IN_ALPHA_INDEX = 2 |
130 | 130 |
IGNORE_PREFIX = |
131 | 131 |
#--------------------------------------------------------------------------- |
132 | 132 |
# configuration options related to the HTML output |
133 | 133 |
#--------------------------------------------------------------------------- |
134 | 134 |
GENERATE_HTML = YES |
135 | 135 |
HTML_OUTPUT = html |
136 | 136 |
HTML_FILE_EXTENSION = .html |
137 | 137 |
HTML_HEADER = |
138 | 138 |
HTML_FOOTER = |
139 | 139 |
HTML_STYLESHEET = |
140 | 140 |
HTML_ALIGN_MEMBERS = YES |
141 | 141 |
HTML_DYNAMIC_SECTIONS = NO |
142 | 142 |
GENERATE_DOCSET = NO |
143 | 143 |
DOCSET_FEEDNAME = "Doxygen generated docs" |
144 | 144 |
DOCSET_BUNDLE_ID = org.doxygen.Project |
145 | 145 |
GENERATE_HTMLHELP = NO |
146 | 146 |
CHM_FILE = |
147 | 147 |
HHC_LOCATION = |
148 | 148 |
GENERATE_CHI = NO |
149 | 149 |
CHM_INDEX_ENCODING = |
150 | 150 |
BINARY_TOC = NO |
151 | 151 |
TOC_EXPAND = NO |
152 | 152 |
GENERATE_QHP = NO |
153 | 153 |
QCH_FILE = |
154 | 154 |
QHP_NAMESPACE = org.doxygen.Project |
155 | 155 |
QHP_VIRTUAL_FOLDER = doc |
156 | 156 |
QHG_LOCATION = |
157 | 157 |
DISABLE_INDEX = NO |
158 | 158 |
ENUM_VALUES_PER_LINE = 4 |
159 | 159 |
GENERATE_TREEVIEW = NO |
160 | 160 |
TREEVIEW_WIDTH = 250 |
161 | 161 |
FORMULA_FONTSIZE = 10 |
162 | 162 |
#--------------------------------------------------------------------------- |
163 | 163 |
# configuration options related to the LaTeX output |
164 | 164 |
#--------------------------------------------------------------------------- |
165 | 165 |
GENERATE_LATEX = NO |
166 | 166 |
LATEX_OUTPUT = latex |
167 | 167 |
LATEX_CMD_NAME = latex |
168 | 168 |
MAKEINDEX_CMD_NAME = makeindex |
169 | 169 |
COMPACT_LATEX = YES |
170 | 170 |
PAPER_TYPE = a4wide |
171 | 171 |
EXTRA_PACKAGES = amsmath \ |
172 | 172 |
amssymb |
173 | 173 |
LATEX_HEADER = |
174 | 174 |
PDF_HYPERLINKS = YES |
175 | 175 |
USE_PDFLATEX = YES |
176 | 176 |
LATEX_BATCHMODE = NO |
177 | 177 |
LATEX_HIDE_INDICES = NO |
178 | 178 |
#--------------------------------------------------------------------------- |
179 | 179 |
# configuration options related to the RTF output |
180 | 180 |
#--------------------------------------------------------------------------- |
181 | 181 |
GENERATE_RTF = NO |
182 | 182 |
RTF_OUTPUT = rtf |
183 | 183 |
COMPACT_RTF = NO |
184 | 184 |
RTF_HYPERLINKS = NO |
185 | 185 |
RTF_STYLESHEET_FILE = |
186 | 186 |
RTF_EXTENSIONS_FILE = |
187 | 187 |
#--------------------------------------------------------------------------- |
188 | 188 |
# configuration options related to the man page output |
189 | 189 |
#--------------------------------------------------------------------------- |
190 | 190 |
GENERATE_MAN = NO |
191 | 191 |
MAN_OUTPUT = man |
192 | 192 |
MAN_EXTENSION = .3 |
193 | 193 |
MAN_LINKS = NO |
194 | 194 |
#--------------------------------------------------------------------------- |
195 | 195 |
# configuration options related to the XML output |
196 | 196 |
#--------------------------------------------------------------------------- |
197 | 197 |
GENERATE_XML = NO |
198 | 198 |
XML_OUTPUT = xml |
199 | 199 |
XML_SCHEMA = |
200 | 200 |
XML_DTD = |
201 | 201 |
XML_PROGRAMLISTING = YES |
202 | 202 |
#--------------------------------------------------------------------------- |
203 | 203 |
# configuration options for the AutoGen Definitions output |
204 | 204 |
#--------------------------------------------------------------------------- |
205 | 205 |
GENERATE_AUTOGEN_DEF = NO |
206 | 206 |
#--------------------------------------------------------------------------- |
207 | 207 |
# configuration options related to the Perl module output |
208 | 208 |
#--------------------------------------------------------------------------- |
209 | 209 |
GENERATE_PERLMOD = NO |
210 | 210 |
PERLMOD_LATEX = NO |
211 | 211 |
PERLMOD_PRETTY = YES |
212 | 212 |
PERLMOD_MAKEVAR_PREFIX = |
213 | 213 |
#--------------------------------------------------------------------------- |
214 | 214 |
# Configuration options related to the preprocessor |
215 | 215 |
#--------------------------------------------------------------------------- |
216 | 216 |
ENABLE_PREPROCESSING = YES |
217 | 217 |
MACRO_EXPANSION = NO |
218 | 218 |
EXPAND_ONLY_PREDEF = NO |
219 | 219 |
SEARCH_INCLUDES = YES |
220 | 220 |
INCLUDE_PATH = |
221 | 221 |
INCLUDE_FILE_PATTERNS = |
222 | 222 |
PREDEFINED = DOXYGEN |
223 | 223 |
EXPAND_AS_DEFINED = |
224 | 224 |
SKIP_FUNCTION_MACROS = YES |
225 | 225 |
#--------------------------------------------------------------------------- |
226 |
# |
|
226 |
# Options related to the search engine |
|
227 | 227 |
#--------------------------------------------------------------------------- |
228 | 228 |
TAGFILES = "@abs_top_srcdir@/doc/libstdc++.tag = http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/ " |
229 | 229 |
GENERATE_TAGFILE = html/lemon.tag |
230 | 230 |
ALLEXTERNALS = NO |
231 | 231 |
EXTERNAL_GROUPS = NO |
232 | 232 |
PERL_PATH = /usr/bin/perl |
233 | 233 |
#--------------------------------------------------------------------------- |
234 | 234 |
# Configuration options related to the dot tool |
235 | 235 |
#--------------------------------------------------------------------------- |
236 | 236 |
CLASS_DIAGRAMS = YES |
237 | 237 |
MSCGEN_PATH = |
238 | 238 |
HIDE_UNDOC_RELATIONS = YES |
239 | 239 |
HAVE_DOT = YES |
240 | 240 |
DOT_FONTNAME = FreeSans |
241 | 241 |
DOT_FONTSIZE = 10 |
242 | 242 |
DOT_FONTPATH = |
243 | 243 |
CLASS_GRAPH = YES |
244 | 244 |
COLLABORATION_GRAPH = NO |
245 | 245 |
GROUP_GRAPHS = NO |
246 | 246 |
UML_LOOK = NO |
247 | 247 |
TEMPLATE_RELATIONS = NO |
248 | 248 |
INCLUDE_GRAPH = NO |
249 | 249 |
INCLUDED_BY_GRAPH = NO |
250 | 250 |
CALL_GRAPH = NO |
251 | 251 |
CALLER_GRAPH = NO |
252 | 252 |
GRAPHICAL_HIERARCHY = NO |
253 | 253 |
DIRECTORY_GRAPH = NO |
254 | 254 |
DOT_IMAGE_FORMAT = png |
255 | 255 |
DOT_PATH = |
256 | 256 |
DOTFILE_DIRS = |
257 | 257 |
DOT_GRAPH_MAX_NODES = 50 |
258 | 258 |
MAX_DOT_GRAPH_DEPTH = 0 |
259 | 259 |
DOT_TRANSPARENT = NO |
260 | 260 |
DOT_MULTI_TARGETS = NO |
261 | 261 |
GENERATE_LEGEND = YES |
262 | 262 |
DOT_CLEANUP = YES |
263 | 263 |
#--------------------------------------------------------------------------- |
264 | 264 |
# Configuration::additions related to the search engine |
265 | 265 |
#--------------------------------------------------------------------------- |
266 | 266 |
SEARCHENGINE = NO |
1 | 1 |
EXTRA_DIST += \ |
2 | 2 |
doc/Doxyfile.in \ |
3 | 3 |
doc/DoxygenLayout.xml \ |
4 | 4 |
doc/coding_style.dox \ |
5 | 5 |
doc/dirs.dox \ |
6 | 6 |
doc/groups.dox \ |
7 | 7 |
doc/lgf.dox \ |
8 | 8 |
doc/license.dox \ |
9 | 9 |
doc/mainpage.dox \ |
10 | 10 |
doc/migration.dox \ |
11 | 11 |
doc/min_cost_flow.dox \ |
12 | 12 |
doc/named-param.dox \ |
13 | 13 |
doc/namespaces.dox \ |
14 | 14 |
doc/html \ |
15 | 15 |
doc/CMakeLists.txt |
16 | 16 |
|
17 | 17 |
DOC_EPS_IMAGES18 = \ |
18 | 18 |
grid_graph.eps \ |
19 | 19 |
nodeshape_0.eps \ |
20 | 20 |
nodeshape_1.eps \ |
21 | 21 |
nodeshape_2.eps \ |
22 | 22 |
nodeshape_3.eps \ |
23 | 23 |
nodeshape_4.eps |
24 | 24 |
|
25 | 25 |
DOC_EPS_IMAGES27 = \ |
26 | 26 |
bipartite_matching.eps \ |
27 | 27 |
bipartite_partitions.eps \ |
28 | 28 |
connected_components.eps \ |
29 | 29 |
edge_biconnected_components.eps \ |
30 | 30 |
node_biconnected_components.eps \ |
31 | 31 |
strongly_connected_components.eps |
32 | 32 |
|
33 | 33 |
DOC_EPS_IMAGES = \ |
34 | 34 |
$(DOC_EPS_IMAGES18) \ |
35 | 35 |
$(DOC_EPS_IMAGES27) |
36 | 36 |
|
37 | 37 |
DOC_PNG_IMAGES = \ |
38 | 38 |
$(DOC_EPS_IMAGES:%.eps=doc/gen-images/%.png) |
39 | 39 |
|
40 | 40 |
EXTRA_DIST += $(DOC_EPS_IMAGES:%=doc/images/%) |
41 | 41 |
|
42 | 42 |
doc/html: |
43 | 43 |
$(MAKE) $(AM_MAKEFLAGS) html |
44 | 44 |
|
45 | 45 |
GS_COMMAND=gs -dNOPAUSE -dBATCH -q -dEPSCrop -dTextAlphaBits=4 -dGraphicsAlphaBits=4 |
46 | 46 |
|
47 | 47 |
$(DOC_EPS_IMAGES18:%.eps=doc/gen-images/%.png): doc/gen-images/%.png: doc/images/%.eps |
48 | 48 |
-mkdir doc/gen-images |
49 | 49 |
if test ${gs_found} = yes; then \ |
50 | 50 |
$(GS_COMMAND) -sDEVICE=pngalpha -r18 -sOutputFile=$@ $<; \ |
51 | 51 |
else \ |
52 | 52 |
echo; \ |
53 | 53 |
echo "Ghostscript not found."; \ |
54 | 54 |
echo; \ |
55 | 55 |
exit 1; \ |
56 | 56 |
fi |
57 | 57 |
|
58 | 58 |
$(DOC_EPS_IMAGES27:%.eps=doc/gen-images/%.png): doc/gen-images/%.png: doc/images/%.eps |
59 | 59 |
-mkdir doc/gen-images |
60 | 60 |
if test ${gs_found} = yes; then \ |
61 | 61 |
$(GS_COMMAND) -sDEVICE=pngalpha -r27 -sOutputFile=$@ $<; \ |
62 | 62 |
else \ |
63 | 63 |
echo; \ |
64 | 64 |
echo "Ghostscript not found."; \ |
65 | 65 |
echo; \ |
66 | 66 |
exit 1; \ |
67 | 67 |
fi |
68 | 68 |
|
69 |
|
|
69 |
references.dox: doc/references.bib |
|
70 |
if test ${python_found} = yes; then \ |
|
71 |
cd doc; \ |
|
72 |
python @abs_top_srcdir@/scripts/bib2dox.py @abs_top_builddir@/$< >$@; \ |
|
73 |
cd ..; \ |
|
74 |
else \ |
|
75 |
echo; \ |
|
76 |
echo "Python not found."; \ |
|
77 |
echo; \ |
|
78 |
exit 1; \ |
|
79 |
fi |
|
80 |
|
|
81 |
html-local: $(DOC_PNG_IMAGES) references.dox |
|
70 | 82 |
if test ${doxygen_found} = yes; then \ |
71 | 83 |
cd doc; \ |
72 | 84 |
doxygen Doxyfile; \ |
73 | 85 |
cd ..; \ |
74 | 86 |
else \ |
75 | 87 |
echo; \ |
76 | 88 |
echo "Doxygen not found."; \ |
77 | 89 |
echo; \ |
78 | 90 |
exit 1; \ |
79 | 91 |
fi |
80 | 92 |
|
81 | 93 |
clean-local: |
82 | 94 |
-rm -rf doc/html |
83 | 95 |
-rm -f doc/doxygen.log |
84 | 96 |
-rm -f $(DOC_PNG_IMAGES) |
85 | 97 |
-rm -rf doc/gen-images |
86 | 98 |
|
87 | 99 |
update-external-tags: |
88 | 100 |
wget -O doc/libstdc++.tag.tmp http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/libstdc++.tag && \ |
89 | 101 |
mv doc/libstdc++.tag.tmp doc/libstdc++.tag || \ |
90 | 102 |
rm doc/libstdc++.tag.tmp |
91 | 103 |
|
92 | 104 |
install-html-local: doc/html |
93 | 105 |
@$(NORMAL_INSTALL) |
94 | 106 |
$(mkinstalldirs) $(DESTDIR)$(htmldir)/html |
95 | 107 |
for p in doc/html/*.{html,css,png,map,gif,tag} ; do \ |
96 | 108 |
f="`echo $$p | sed -e 's|^.*/||'`"; \ |
97 | 109 |
echo " $(INSTALL_DATA) $$p $(DESTDIR)$(htmldir)/html/$$f"; \ |
98 | 110 |
$(INSTALL_DATA) $$p $(DESTDIR)$(htmldir)/html/$$f; \ |
99 | 111 |
done |
100 | 112 |
|
101 | 113 |
uninstall-local: |
102 | 114 |
@$(NORMAL_UNINSTALL) |
103 | 115 |
for p in doc/html/*.{html,css,png,map,gif,tag} ; do \ |
104 | 116 |
f="`echo $$p | sed -e 's|^.*/||'`"; \ |
105 | 117 |
echo " rm -f $(DESTDIR)$(htmldir)/html/$$f"; \ |
106 | 118 |
rm -f $(DESTDIR)$(htmldir)/html/$$f; \ |
107 | 119 |
done |
108 | 120 |
|
109 | 121 |
.PHONY: update-external-tags |
... | ... |
@@ -63,653 +63,703 @@ |
63 | 63 |
|
64 | 64 |
/** |
65 | 65 |
@defgroup graph_adaptors Adaptor Classes for Graphs |
66 | 66 |
@ingroup graphs |
67 | 67 |
\brief Adaptor classes for digraphs and graphs |
68 | 68 |
|
69 | 69 |
This group contains several useful adaptor classes for digraphs and graphs. |
70 | 70 |
|
71 | 71 |
The main parts of LEMON are the different graph structures, generic |
72 | 72 |
graph algorithms, graph concepts, which couple them, and graph |
73 | 73 |
adaptors. While the previous notions are more or less clear, the |
74 | 74 |
latter one needs further explanation. Graph adaptors are graph classes |
75 | 75 |
which serve for considering graph structures in different ways. |
76 | 76 |
|
77 | 77 |
A short example makes this much clearer. Suppose that we have an |
78 | 78 |
instance \c g of a directed graph type, say ListDigraph and an algorithm |
79 | 79 |
\code |
80 | 80 |
template <typename Digraph> |
81 | 81 |
int algorithm(const Digraph&); |
82 | 82 |
\endcode |
83 | 83 |
is needed to run on the reverse oriented graph. It may be expensive |
84 | 84 |
(in time or in memory usage) to copy \c g with the reversed |
85 | 85 |
arcs. In this case, an adaptor class is used, which (according |
86 | 86 |
to LEMON \ref concepts::Digraph "digraph concepts") works as a digraph. |
87 | 87 |
The adaptor uses the original digraph structure and digraph operations when |
88 | 88 |
methods of the reversed oriented graph are called. This means that the adaptor |
89 | 89 |
have minor memory usage, and do not perform sophisticated algorithmic |
90 | 90 |
actions. The purpose of it is to give a tool for the cases when a |
91 | 91 |
graph have to be used in a specific alteration. If this alteration is |
92 | 92 |
obtained by a usual construction like filtering the node or the arc set or |
93 | 93 |
considering a new orientation, then an adaptor is worthwhile to use. |
94 | 94 |
To come back to the reverse oriented graph, in this situation |
95 | 95 |
\code |
96 | 96 |
template<typename Digraph> class ReverseDigraph; |
97 | 97 |
\endcode |
98 | 98 |
template class can be used. The code looks as follows |
99 | 99 |
\code |
100 | 100 |
ListDigraph g; |
101 | 101 |
ReverseDigraph<ListDigraph> rg(g); |
102 | 102 |
int result = algorithm(rg); |
103 | 103 |
\endcode |
104 | 104 |
During running the algorithm, the original digraph \c g is untouched. |
105 | 105 |
This techniques give rise to an elegant code, and based on stable |
106 | 106 |
graph adaptors, complex algorithms can be implemented easily. |
107 | 107 |
|
108 | 108 |
In flow, circulation and matching problems, the residual |
109 | 109 |
graph is of particular importance. Combining an adaptor implementing |
110 | 110 |
this with shortest path algorithms or minimum mean cycle algorithms, |
111 | 111 |
a range of weighted and cardinality optimization algorithms can be |
112 | 112 |
obtained. For other examples, the interested user is referred to the |
113 | 113 |
detailed documentation of particular adaptors. |
114 | 114 |
|
115 | 115 |
The behavior of graph adaptors can be very different. Some of them keep |
116 | 116 |
capabilities of the original graph while in other cases this would be |
117 | 117 |
meaningless. This means that the concepts that they meet depend |
118 | 118 |
on the graph adaptor, and the wrapped graph. |
119 | 119 |
For example, if an arc of a reversed digraph is deleted, this is carried |
120 | 120 |
out by deleting the corresponding arc of the original digraph, thus the |
121 | 121 |
adaptor modifies the original digraph. |
122 | 122 |
However in case of a residual digraph, this operation has no sense. |
123 | 123 |
|
124 | 124 |
Let us stand one more example here to simplify your work. |
125 | 125 |
ReverseDigraph has constructor |
126 | 126 |
\code |
127 | 127 |
ReverseDigraph(Digraph& digraph); |
128 | 128 |
\endcode |
129 | 129 |
This means that in a situation, when a <tt>const %ListDigraph&</tt> |
130 | 130 |
reference to a graph is given, then it have to be instantiated with |
131 | 131 |
<tt>Digraph=const %ListDigraph</tt>. |
132 | 132 |
\code |
133 | 133 |
int algorithm1(const ListDigraph& g) { |
134 | 134 |
ReverseDigraph<const ListDigraph> rg(g); |
135 | 135 |
return algorithm2(rg); |
136 | 136 |
} |
137 | 137 |
\endcode |
138 | 138 |
*/ |
139 | 139 |
|
140 | 140 |
/** |
141 | 141 |
@defgroup maps Maps |
142 | 142 |
@ingroup datas |
143 | 143 |
\brief Map structures implemented in LEMON. |
144 | 144 |
|
145 | 145 |
This group contains the map structures implemented in LEMON. |
146 | 146 |
|
147 | 147 |
LEMON provides several special purpose maps and map adaptors that e.g. combine |
148 | 148 |
new maps from existing ones. |
149 | 149 |
|
150 | 150 |
<b>See also:</b> \ref map_concepts "Map Concepts". |
151 | 151 |
*/ |
152 | 152 |
|
153 | 153 |
/** |
154 | 154 |
@defgroup graph_maps Graph Maps |
155 | 155 |
@ingroup maps |
156 | 156 |
\brief Special graph-related maps. |
157 | 157 |
|
158 | 158 |
This group contains maps that are specifically designed to assign |
159 | 159 |
values to the nodes and arcs/edges of graphs. |
160 | 160 |
|
161 | 161 |
If you are looking for the standard graph maps (\c NodeMap, \c ArcMap, |
162 | 162 |
\c EdgeMap), see the \ref graph_concepts "Graph Structure Concepts". |
163 | 163 |
*/ |
164 | 164 |
|
165 | 165 |
/** |
166 | 166 |
\defgroup map_adaptors Map Adaptors |
167 | 167 |
\ingroup maps |
168 | 168 |
\brief Tools to create new maps from existing ones |
169 | 169 |
|
170 | 170 |
This group contains map adaptors that are used to create "implicit" |
171 | 171 |
maps from other maps. |
172 | 172 |
|
173 | 173 |
Most of them are \ref concepts::ReadMap "read-only maps". |
174 | 174 |
They can make arithmetic and logical operations between one or two maps |
175 | 175 |
(negation, shifting, addition, multiplication, logical 'and', 'or', |
176 | 176 |
'not' etc.) or e.g. convert a map to another one of different Value type. |
177 | 177 |
|
178 | 178 |
The typical usage of this classes is passing implicit maps to |
179 | 179 |
algorithms. If a function type algorithm is called then the function |
180 | 180 |
type map adaptors can be used comfortable. For example let's see the |
181 | 181 |
usage of map adaptors with the \c graphToEps() function. |
182 | 182 |
\code |
183 | 183 |
Color nodeColor(int deg) { |
184 | 184 |
if (deg >= 2) { |
185 | 185 |
return Color(0.5, 0.0, 0.5); |
186 | 186 |
} else if (deg == 1) { |
187 | 187 |
return Color(1.0, 0.5, 1.0); |
188 | 188 |
} else { |
189 | 189 |
return Color(0.0, 0.0, 0.0); |
190 | 190 |
} |
191 | 191 |
} |
192 | 192 |
|
193 | 193 |
Digraph::NodeMap<int> degree_map(graph); |
194 | 194 |
|
195 | 195 |
graphToEps(graph, "graph.eps") |
196 | 196 |
.coords(coords).scaleToA4().undirected() |
197 | 197 |
.nodeColors(composeMap(functorToMap(nodeColor), degree_map)) |
198 | 198 |
.run(); |
199 | 199 |
\endcode |
200 | 200 |
The \c functorToMap() function makes an \c int to \c Color map from the |
201 | 201 |
\c nodeColor() function. The \c composeMap() compose the \c degree_map |
202 | 202 |
and the previously created map. The composed map is a proper function to |
203 | 203 |
get the color of each node. |
204 | 204 |
|
205 | 205 |
The usage with class type algorithms is little bit harder. In this |
206 | 206 |
case the function type map adaptors can not be used, because the |
207 | 207 |
function map adaptors give back temporary objects. |
208 | 208 |
\code |
209 | 209 |
Digraph graph; |
210 | 210 |
|
211 | 211 |
typedef Digraph::ArcMap<double> DoubleArcMap; |
212 | 212 |
DoubleArcMap length(graph); |
213 | 213 |
DoubleArcMap speed(graph); |
214 | 214 |
|
215 | 215 |
typedef DivMap<DoubleArcMap, DoubleArcMap> TimeMap; |
216 | 216 |
TimeMap time(length, speed); |
217 | 217 |
|
218 | 218 |
Dijkstra<Digraph, TimeMap> dijkstra(graph, time); |
219 | 219 |
dijkstra.run(source, target); |
220 | 220 |
\endcode |
221 | 221 |
We have a length map and a maximum speed map on the arcs of a digraph. |
222 | 222 |
The minimum time to pass the arc can be calculated as the division of |
223 | 223 |
the two maps which can be done implicitly with the \c DivMap template |
224 | 224 |
class. We use the implicit minimum time map as the length map of the |
225 | 225 |
\c Dijkstra algorithm. |
226 | 226 |
*/ |
227 | 227 |
|
228 | 228 |
/** |
229 | 229 |
@defgroup paths Path Structures |
230 | 230 |
@ingroup datas |
231 | 231 |
\brief %Path structures implemented in LEMON. |
232 | 232 |
|
233 | 233 |
This group contains the path structures implemented in LEMON. |
234 | 234 |
|
235 | 235 |
LEMON provides flexible data structures to work with paths. |
236 | 236 |
All of them have similar interfaces and they can be copied easily with |
237 | 237 |
assignment operators and copy constructors. This makes it easy and |
238 | 238 |
efficient to have e.g. the Dijkstra algorithm to store its result in |
239 | 239 |
any kind of path structure. |
240 | 240 |
|
241 | 241 |
\sa \ref concepts::Path "Path concept" |
242 | 242 |
*/ |
243 | 243 |
|
244 | 244 |
/** |
245 | 245 |
@defgroup heaps Heap Structures |
246 | 246 |
@ingroup datas |
247 | 247 |
\brief %Heap structures implemented in LEMON. |
248 | 248 |
|
249 | 249 |
This group contains the heap structures implemented in LEMON. |
250 | 250 |
|
251 | 251 |
LEMON provides several heap classes. They are efficient implementations |
252 | 252 |
of the abstract data type \e priority \e queue. They store items with |
253 | 253 |
specified values called \e priorities in such a way that finding and |
254 | 254 |
removing the item with minimum priority are efficient. |
255 | 255 |
The basic operations are adding and erasing items, changing the priority |
256 | 256 |
of an item, etc. |
257 | 257 |
|
258 | 258 |
Heaps are crucial in several algorithms, such as Dijkstra and Prim. |
259 | 259 |
The heap implementations have the same interface, thus any of them can be |
260 | 260 |
used easily in such algorithms. |
261 | 261 |
|
262 | 262 |
\sa \ref concepts::Heap "Heap concept" |
263 | 263 |
*/ |
264 | 264 |
|
265 | 265 |
/** |
266 | 266 |
@defgroup matrices Matrices |
267 | 267 |
@ingroup datas |
268 | 268 |
\brief Two dimensional data storages implemented in LEMON. |
269 | 269 |
|
270 | 270 |
This group contains two dimensional data storages implemented in LEMON. |
271 | 271 |
*/ |
272 | 272 |
|
273 | 273 |
/** |
274 | 274 |
@defgroup auxdat Auxiliary Data Structures |
275 | 275 |
@ingroup datas |
276 | 276 |
\brief Auxiliary data structures implemented in LEMON. |
277 | 277 |
|
278 | 278 |
This group contains some data structures implemented in LEMON in |
279 | 279 |
order to make it easier to implement combinatorial algorithms. |
280 | 280 |
*/ |
281 | 281 |
|
282 | 282 |
/** |
283 | 283 |
@defgroup geomdat Geometric Data Structures |
284 | 284 |
@ingroup auxdat |
285 | 285 |
\brief Geometric data structures implemented in LEMON. |
286 | 286 |
|
287 | 287 |
This group contains geometric data structures implemented in LEMON. |
288 | 288 |
|
289 | 289 |
- \ref lemon::dim2::Point "dim2::Point" implements a two dimensional |
290 | 290 |
vector with the usual operations. |
291 | 291 |
- \ref lemon::dim2::Box "dim2::Box" can be used to determine the |
292 | 292 |
rectangular bounding box of a set of \ref lemon::dim2::Point |
293 | 293 |
"dim2::Point"'s. |
294 | 294 |
*/ |
295 | 295 |
|
296 | 296 |
/** |
297 | 297 |
@defgroup matrices Matrices |
298 | 298 |
@ingroup auxdat |
299 | 299 |
\brief Two dimensional data storages implemented in LEMON. |
300 | 300 |
|
301 | 301 |
This group contains two dimensional data storages implemented in LEMON. |
302 | 302 |
*/ |
303 | 303 |
|
304 | 304 |
/** |
305 | 305 |
@defgroup algs Algorithms |
306 | 306 |
\brief This group contains the several algorithms |
307 | 307 |
implemented in LEMON. |
308 | 308 |
|
309 | 309 |
This group contains the several algorithms |
310 | 310 |
implemented in LEMON. |
311 | 311 |
*/ |
312 | 312 |
|
313 | 313 |
/** |
314 | 314 |
@defgroup search Graph Search |
315 | 315 |
@ingroup algs |
316 | 316 |
\brief Common graph search algorithms. |
317 | 317 |
|
318 | 318 |
This group contains the common graph search algorithms, namely |
319 |
\e breadth-first \e search (BFS) and \e depth-first \e search (DFS) |
|
319 |
\e breadth-first \e search (BFS) and \e depth-first \e search (DFS) |
|
320 |
\ref clrs01algorithms. |
|
320 | 321 |
*/ |
321 | 322 |
|
322 | 323 |
/** |
323 | 324 |
@defgroup shortest_path Shortest Path Algorithms |
324 | 325 |
@ingroup algs |
325 | 326 |
\brief Algorithms for finding shortest paths. |
326 | 327 |
|
327 |
This group contains the algorithms for finding shortest paths in digraphs |
|
328 |
This group contains the algorithms for finding shortest paths in digraphs |
|
329 |
\ref clrs01algorithms. |
|
328 | 330 |
|
329 | 331 |
- \ref Dijkstra algorithm for finding shortest paths from a source node |
330 | 332 |
when all arc lengths are non-negative. |
331 | 333 |
- \ref BellmanFord "Bellman-Ford" algorithm for finding shortest paths |
332 | 334 |
from a source node when arc lenghts can be either positive or negative, |
333 | 335 |
but the digraph should not contain directed cycles with negative total |
334 | 336 |
length. |
335 | 337 |
- \ref FloydWarshall "Floyd-Warshall" and \ref Johnson "Johnson" algorithms |
336 | 338 |
for solving the \e all-pairs \e shortest \e paths \e problem when arc |
337 | 339 |
lenghts can be either positive or negative, but the digraph should |
338 | 340 |
not contain directed cycles with negative total length. |
339 | 341 |
- \ref Suurballe A successive shortest path algorithm for finding |
340 | 342 |
arc-disjoint paths between two nodes having minimum total length. |
341 | 343 |
*/ |
342 | 344 |
|
343 | 345 |
/** |
344 | 346 |
@defgroup spantree Minimum Spanning Tree Algorithms |
345 | 347 |
@ingroup algs |
346 | 348 |
\brief Algorithms for finding minimum cost spanning trees and arborescences. |
347 | 349 |
|
348 | 350 |
This group contains the algorithms for finding minimum cost spanning |
349 |
trees and arborescences. |
|
351 |
trees and arborescences \ref clrs01algorithms. |
|
350 | 352 |
*/ |
351 | 353 |
|
352 | 354 |
/** |
353 | 355 |
@defgroup max_flow Maximum Flow Algorithms |
354 | 356 |
@ingroup algs |
355 | 357 |
\brief Algorithms for finding maximum flows. |
356 | 358 |
|
357 | 359 |
This group contains the algorithms for finding maximum flows and |
358 |
feasible circulations. |
|
360 |
feasible circulations \ref clrs01algorithms, \ref amo93networkflows. |
|
359 | 361 |
|
360 | 362 |
The \e maximum \e flow \e problem is to find a flow of maximum value between |
361 | 363 |
a single source and a single target. Formally, there is a \f$G=(V,A)\f$ |
362 | 364 |
digraph, a \f$cap: A\rightarrow\mathbf{R}^+_0\f$ capacity function and |
363 | 365 |
\f$s, t \in V\f$ source and target nodes. |
364 | 366 |
A maximum flow is an \f$f: A\rightarrow\mathbf{R}^+_0\f$ solution of the |
365 | 367 |
following optimization problem. |
366 | 368 |
|
367 | 369 |
\f[ \max\sum_{sv\in A} f(sv) - \sum_{vs\in A} f(vs) \f] |
368 | 370 |
\f[ \sum_{uv\in A} f(uv) = \sum_{vu\in A} f(vu) |
369 | 371 |
\quad \forall u\in V\setminus\{s,t\} \f] |
370 | 372 |
\f[ 0 \leq f(uv) \leq cap(uv) \quad \forall uv\in A \f] |
371 | 373 |
|
372 | 374 |
LEMON contains several algorithms for solving maximum flow problems: |
373 |
- \ref EdmondsKarp Edmonds-Karp algorithm. |
|
374 |
- \ref Preflow Goldberg-Tarjan's preflow push-relabel algorithm. |
|
375 |
- \ref DinitzSleatorTarjan Dinitz's blocking flow algorithm with dynamic trees. |
|
376 |
- \ref GoldbergTarjan Preflow push-relabel algorithm with dynamic trees. |
|
375 |
- \ref EdmondsKarp Edmonds-Karp algorithm |
|
376 |
\ref edmondskarp72theoretical. |
|
377 |
- \ref Preflow Goldberg-Tarjan's preflow push-relabel algorithm |
|
378 |
\ref goldberg88newapproach. |
|
379 |
- \ref DinitzSleatorTarjan Dinitz's blocking flow algorithm with dynamic trees |
|
380 |
\ref dinic70algorithm, \ref sleator83dynamic. |
|
381 |
- \ref GoldbergTarjan !Preflow push-relabel algorithm with dynamic trees |
|
382 |
\ref goldberg88newapproach, \ref sleator83dynamic. |
|
377 | 383 |
|
378 |
In most cases the \ref Preflow |
|
384 |
In most cases the \ref Preflow algorithm provides the |
|
379 | 385 |
fastest method for computing a maximum flow. All implementations |
380 | 386 |
also provide functions to query the minimum cut, which is the dual |
381 | 387 |
problem of maximum flow. |
382 | 388 |
|
383 | 389 |
\ref Circulation is a preflow push-relabel algorithm implemented directly |
384 | 390 |
for finding feasible circulations, which is a somewhat different problem, |
385 | 391 |
but it is strongly related to maximum flow. |
386 | 392 |
For more information, see \ref Circulation. |
387 | 393 |
*/ |
388 | 394 |
|
389 | 395 |
/** |
390 | 396 |
@defgroup min_cost_flow_algs Minimum Cost Flow Algorithms |
391 | 397 |
@ingroup algs |
392 | 398 |
|
393 | 399 |
\brief Algorithms for finding minimum cost flows and circulations. |
394 | 400 |
|
395 | 401 |
This group contains the algorithms for finding minimum cost flows and |
396 |
circulations. For more information about this problem and its dual |
|
397 |
solution see \ref min_cost_flow "Minimum Cost Flow Problem". |
|
402 |
circulations \ref amo93networkflows. For more information about this |
|
403 |
problem and its dual solution, see \ref min_cost_flow |
|
404 |
"Minimum Cost Flow Problem". |
|
398 | 405 |
|
399 | 406 |
LEMON contains several algorithms for this problem. |
400 | 407 |
- \ref NetworkSimplex Primal Network Simplex algorithm with various |
401 |
pivot strategies. |
|
408 |
pivot strategies \ref dantzig63linearprog, \ref kellyoneill91netsimplex. |
|
402 | 409 |
- \ref CostScaling Push-Relabel and Augment-Relabel algorithms based on |
403 |
cost scaling |
|
410 |
cost scaling \ref goldberg90approximation, \ref goldberg97efficient, |
|
411 |
\ref bunnagel98efficient. |
|
404 | 412 |
- \ref CapacityScaling Successive Shortest %Path algorithm with optional |
405 |
capacity scaling. |
|
406 |
- \ref CancelAndTighten The Cancel and Tighten algorithm. |
|
407 |
|
|
413 |
capacity scaling \ref edmondskarp72theoretical. |
|
414 |
- \ref CancelAndTighten The Cancel and Tighten algorithm |
|
415 |
\ref goldberg89cyclecanceling. |
|
416 |
- \ref CycleCanceling Cycle-Canceling algorithms |
|
417 |
\ref klein67primal, \ref goldberg89cyclecanceling. |
|
408 | 418 |
|
409 | 419 |
In general NetworkSimplex is the most efficient implementation, |
410 | 420 |
but in special cases other algorithms could be faster. |
411 | 421 |
For example, if the total supply and/or capacities are rather small, |
412 | 422 |
CapacityScaling is usually the fastest algorithm (without effective scaling). |
413 | 423 |
*/ |
414 | 424 |
|
415 | 425 |
/** |
416 | 426 |
@defgroup min_cut Minimum Cut Algorithms |
417 | 427 |
@ingroup algs |
418 | 428 |
|
419 | 429 |
\brief Algorithms for finding minimum cut in graphs. |
420 | 430 |
|
421 | 431 |
This group contains the algorithms for finding minimum cut in graphs. |
422 | 432 |
|
423 | 433 |
The \e minimum \e cut \e problem is to find a non-empty and non-complete |
424 | 434 |
\f$X\f$ subset of the nodes with minimum overall capacity on |
425 | 435 |
outgoing arcs. Formally, there is a \f$G=(V,A)\f$ digraph, a |
426 | 436 |
\f$cap: A\rightarrow\mathbf{R}^+_0\f$ capacity function. The minimum |
427 | 437 |
cut is the \f$X\f$ solution of the next optimization problem: |
428 | 438 |
|
429 | 439 |
\f[ \min_{X \subset V, X\not\in \{\emptyset, V\}} |
430 | 440 |
\sum_{uv\in A: u\in X, v\not\in X}cap(uv) \f] |
431 | 441 |
|
432 | 442 |
LEMON contains several algorithms related to minimum cut problems: |
433 | 443 |
|
434 | 444 |
- \ref HaoOrlin "Hao-Orlin algorithm" for calculating minimum cut |
435 | 445 |
in directed graphs. |
436 | 446 |
- \ref NagamochiIbaraki "Nagamochi-Ibaraki algorithm" for |
437 | 447 |
calculating minimum cut in undirected graphs. |
438 | 448 |
- \ref GomoryHu "Gomory-Hu tree computation" for calculating |
439 | 449 |
all-pairs minimum cut in undirected graphs. |
440 | 450 |
|
441 | 451 |
If you want to find minimum cut just between two distinict nodes, |
442 | 452 |
see the \ref max_flow "maximum flow problem". |
443 | 453 |
*/ |
444 | 454 |
|
445 | 455 |
/** |
456 |
@defgroup min_mean_cycle Minimum Mean Cycle Algorithms |
|
457 |
@ingroup algs |
|
458 |
\brief Algorithms for finding minimum mean cycles. |
|
459 |
|
|
460 |
This group contains the algorithms for finding minimum mean cycles |
|
461 |
\ref clrs01algorithms, \ref amo93networkflows. |
|
462 |
|
|
463 |
The \e minimum \e mean \e cycle \e problem is to find a directed cycle |
|
464 |
of minimum mean length (cost) in a digraph. |
|
465 |
The mean length of a cycle is the average length of its arcs, i.e. the |
|
466 |
ratio between the total length of the cycle and the number of arcs on it. |
|
467 |
|
|
468 |
This problem has an important connection to \e conservative \e length |
|
469 |
\e functions, too. A length function on the arcs of a digraph is called |
|
470 |
conservative if and only if there is no directed cycle of negative total |
|
471 |
length. For an arbitrary length function, the negative of the minimum |
|
472 |
cycle mean is the smallest \f$\epsilon\f$ value so that increasing the |
|
473 |
arc lengths uniformly by \f$\epsilon\f$ results in a conservative length |
|
474 |
function. |
|
475 |
|
|
476 |
LEMON contains three algorithms for solving the minimum mean cycle problem: |
|
477 |
- \ref Karp "Karp"'s original algorithm \ref amo93networkflows, |
|
478 |
\ref dasdan98minmeancycle. |
|
479 |
- \ref HartmannOrlin "Hartmann-Orlin"'s algorithm, which is an improved |
|
480 |
version of Karp's algorithm \ref dasdan98minmeancycle. |
|
481 |
- \ref Howard "Howard"'s policy iteration algorithm |
|
482 |
\ref dasdan98minmeancycle. |
|
483 |
|
|
484 |
In practice, the Howard algorithm proved to be by far the most efficient |
|
485 |
one, though the best known theoretical bound on its running time is |
|
486 |
exponential. |
|
487 |
Both Karp and HartmannOrlin algorithms run in time O(ne) and use space |
|
488 |
O(n<sup>2</sup>+e), but the latter one is typically faster due to the |
|
489 |
applied early termination scheme. |
|
490 |
*/ |
|
491 |
|
|
492 |
/** |
|
446 | 493 |
@defgroup matching Matching Algorithms |
447 | 494 |
@ingroup algs |
448 | 495 |
\brief Algorithms for finding matchings in graphs and bipartite graphs. |
449 | 496 |
|
450 | 497 |
This group contains the algorithms for calculating |
451 | 498 |
matchings in graphs and bipartite graphs. The general matching problem is |
452 | 499 |
finding a subset of the edges for which each node has at most one incident |
453 | 500 |
edge. |
454 | 501 |
|
455 | 502 |
There are several different algorithms for calculate matchings in |
456 | 503 |
graphs. The matching problems in bipartite graphs are generally |
457 | 504 |
easier than in general graphs. The goal of the matching optimization |
458 | 505 |
can be finding maximum cardinality, maximum weight or minimum cost |
459 | 506 |
matching. The search can be constrained to find perfect or |
460 | 507 |
maximum cardinality matching. |
461 | 508 |
|
462 | 509 |
The matching algorithms implemented in LEMON: |
463 | 510 |
- \ref MaxBipartiteMatching Hopcroft-Karp augmenting path algorithm |
464 | 511 |
for calculating maximum cardinality matching in bipartite graphs. |
465 | 512 |
- \ref PrBipartiteMatching Push-relabel algorithm |
466 | 513 |
for calculating maximum cardinality matching in bipartite graphs. |
467 | 514 |
- \ref MaxWeightedBipartiteMatching |
468 | 515 |
Successive shortest path algorithm for calculating maximum weighted |
469 | 516 |
matching and maximum weighted bipartite matching in bipartite graphs. |
470 | 517 |
- \ref MinCostMaxBipartiteMatching |
471 | 518 |
Successive shortest path algorithm for calculating minimum cost maximum |
472 | 519 |
matching in bipartite graphs. |
473 | 520 |
- \ref MaxMatching Edmond's blossom shrinking algorithm for calculating |
474 | 521 |
maximum cardinality matching in general graphs. |
475 | 522 |
- \ref MaxWeightedMatching Edmond's blossom shrinking algorithm for calculating |
476 | 523 |
maximum weighted matching in general graphs. |
477 | 524 |
- \ref MaxWeightedPerfectMatching |
478 | 525 |
Edmond's blossom shrinking algorithm for calculating maximum weighted |
479 | 526 |
perfect matching in general graphs. |
480 | 527 |
|
481 | 528 |
\image html bipartite_matching.png |
482 | 529 |
\image latex bipartite_matching.eps "Bipartite Matching" width=\textwidth |
483 | 530 |
*/ |
484 | 531 |
|
485 | 532 |
/** |
486 | 533 |
@defgroup graph_properties Connectivity and Other Graph Properties |
487 | 534 |
@ingroup algs |
488 | 535 |
\brief Algorithms for discovering the graph properties |
489 | 536 |
|
490 | 537 |
This group contains the algorithms for discovering the graph properties |
491 | 538 |
like connectivity, bipartiteness, euler property, simplicity etc. |
492 | 539 |
|
493 | 540 |
\image html connected_components.png |
494 | 541 |
\image latex connected_components.eps "Connected components" width=\textwidth |
495 | 542 |
*/ |
496 | 543 |
|
497 | 544 |
/** |
498 | 545 |
@defgroup planar Planarity Embedding and Drawing |
499 | 546 |
@ingroup algs |
500 | 547 |
\brief Algorithms for planarity checking, embedding and drawing |
501 | 548 |
|
502 | 549 |
This group contains the algorithms for planarity checking, |
503 | 550 |
embedding and drawing. |
504 | 551 |
|
505 | 552 |
\image html planar.png |
506 | 553 |
\image latex planar.eps "Plane graph" width=\textwidth |
507 | 554 |
*/ |
508 | 555 |
|
509 | 556 |
/** |
510 | 557 |
@defgroup approx Approximation Algorithms |
511 | 558 |
@ingroup algs |
512 | 559 |
\brief Approximation algorithms. |
513 | 560 |
|
514 | 561 |
This group contains the approximation and heuristic algorithms |
515 | 562 |
implemented in LEMON. |
516 | 563 |
*/ |
517 | 564 |
|
518 | 565 |
/** |
519 | 566 |
@defgroup auxalg Auxiliary Algorithms |
520 | 567 |
@ingroup algs |
521 | 568 |
\brief Auxiliary algorithms implemented in LEMON. |
522 | 569 |
|
523 | 570 |
This group contains some algorithms implemented in LEMON |
524 | 571 |
in order to make it easier to implement complex algorithms. |
525 | 572 |
*/ |
526 | 573 |
|
527 | 574 |
/** |
528 | 575 |
@defgroup gen_opt_group General Optimization Tools |
529 | 576 |
\brief This group contains some general optimization frameworks |
530 | 577 |
implemented in LEMON. |
531 | 578 |
|
532 | 579 |
This group contains some general optimization frameworks |
533 | 580 |
implemented in LEMON. |
534 | 581 |
*/ |
535 | 582 |
|
536 | 583 |
/** |
537 |
@defgroup lp_group |
|
584 |
@defgroup lp_group LP and MIP Solvers |
|
538 | 585 |
@ingroup gen_opt_group |
539 |
\brief |
|
586 |
\brief LP and MIP solver interfaces for LEMON. |
|
540 | 587 |
|
541 |
This group contains Lp and Mip solver interfaces for LEMON. The |
|
542 |
various LP solvers could be used in the same manner with this |
|
543 |
|
|
588 |
This group contains LP and MIP solver interfaces for LEMON. |
|
589 |
Various LP solvers could be used in the same manner with this |
|
590 |
high-level interface. |
|
591 |
|
|
592 |
The currently supported solvers are \ref glpk, \ref clp, \ref cbc, |
|
593 |
\ref cplex, \ref soplex. |
|
544 | 594 |
*/ |
545 | 595 |
|
546 | 596 |
/** |
547 | 597 |
@defgroup lp_utils Tools for Lp and Mip Solvers |
548 | 598 |
@ingroup lp_group |
549 | 599 |
\brief Helper tools to the Lp and Mip solvers. |
550 | 600 |
|
551 | 601 |
This group adds some helper tools to general optimization framework |
552 | 602 |
implemented in LEMON. |
553 | 603 |
*/ |
554 | 604 |
|
555 | 605 |
/** |
556 | 606 |
@defgroup metah Metaheuristics |
557 | 607 |
@ingroup gen_opt_group |
558 | 608 |
\brief Metaheuristics for LEMON library. |
559 | 609 |
|
560 | 610 |
This group contains some metaheuristic optimization tools. |
561 | 611 |
*/ |
562 | 612 |
|
563 | 613 |
/** |
564 | 614 |
@defgroup utils Tools and Utilities |
565 | 615 |
\brief Tools and utilities for programming in LEMON |
566 | 616 |
|
567 | 617 |
Tools and utilities for programming in LEMON. |
568 | 618 |
*/ |
569 | 619 |
|
570 | 620 |
/** |
571 | 621 |
@defgroup gutils Basic Graph Utilities |
572 | 622 |
@ingroup utils |
573 | 623 |
\brief Simple basic graph utilities. |
574 | 624 |
|
575 | 625 |
This group contains some simple basic graph utilities. |
576 | 626 |
*/ |
577 | 627 |
|
578 | 628 |
/** |
579 | 629 |
@defgroup misc Miscellaneous Tools |
580 | 630 |
@ingroup utils |
581 | 631 |
\brief Tools for development, debugging and testing. |
582 | 632 |
|
583 | 633 |
This group contains several useful tools for development, |
584 | 634 |
debugging and testing. |
585 | 635 |
*/ |
586 | 636 |
|
587 | 637 |
/** |
588 | 638 |
@defgroup timecount Time Measuring and Counting |
589 | 639 |
@ingroup misc |
590 | 640 |
\brief Simple tools for measuring the performance of algorithms. |
591 | 641 |
|
592 | 642 |
This group contains simple tools for measuring the performance |
593 | 643 |
of algorithms. |
594 | 644 |
*/ |
595 | 645 |
|
596 | 646 |
/** |
597 | 647 |
@defgroup exceptions Exceptions |
598 | 648 |
@ingroup utils |
599 | 649 |
\brief Exceptions defined in LEMON. |
600 | 650 |
|
601 | 651 |
This group contains the exceptions defined in LEMON. |
602 | 652 |
*/ |
603 | 653 |
|
604 | 654 |
/** |
605 | 655 |
@defgroup io_group Input-Output |
606 | 656 |
\brief Graph Input-Output methods |
607 | 657 |
|
608 | 658 |
This group contains the tools for importing and exporting graphs |
609 | 659 |
and graph related data. Now it supports the \ref lgf-format |
610 | 660 |
"LEMON Graph Format", the \c DIMACS format and the encapsulated |
611 | 661 |
postscript (EPS) format. |
612 | 662 |
*/ |
613 | 663 |
|
614 | 664 |
/** |
615 | 665 |
@defgroup lemon_io LEMON Graph Format |
616 | 666 |
@ingroup io_group |
617 | 667 |
\brief Reading and writing LEMON Graph Format. |
618 | 668 |
|
619 | 669 |
This group contains methods for reading and writing |
620 | 670 |
\ref lgf-format "LEMON Graph Format". |
621 | 671 |
*/ |
622 | 672 |
|
623 | 673 |
/** |
624 | 674 |
@defgroup eps_io Postscript Exporting |
625 | 675 |
@ingroup io_group |
626 | 676 |
\brief General \c EPS drawer and graph exporter |
627 | 677 |
|
628 | 678 |
This group contains general \c EPS drawing methods and special |
629 | 679 |
graph exporting tools. |
630 | 680 |
*/ |
631 | 681 |
|
632 | 682 |
/** |
633 | 683 |
@defgroup dimacs_group DIMACS Format |
634 | 684 |
@ingroup io_group |
635 | 685 |
\brief Read and write files in DIMACS format |
636 | 686 |
|
637 | 687 |
Tools to read a digraph from or write it to a file in DIMACS format data. |
638 | 688 |
*/ |
639 | 689 |
|
640 | 690 |
/** |
641 | 691 |
@defgroup nauty_group NAUTY Format |
642 | 692 |
@ingroup io_group |
643 | 693 |
\brief Read \e Nauty format |
644 | 694 |
|
645 | 695 |
Tool to read graphs from \e Nauty format data. |
646 | 696 |
*/ |
647 | 697 |
|
648 | 698 |
/** |
649 | 699 |
@defgroup concept Concepts |
650 | 700 |
\brief Skeleton classes and concept checking classes |
651 | 701 |
|
652 | 702 |
This group contains the data/algorithm skeletons and concept checking |
653 | 703 |
classes implemented in LEMON. |
654 | 704 |
|
655 | 705 |
The purpose of the classes in this group is fourfold. |
656 | 706 |
|
657 | 707 |
- These classes contain the documentations of the %concepts. In order |
658 | 708 |
to avoid document multiplications, an implementation of a concept |
659 | 709 |
simply refers to the corresponding concept class. |
660 | 710 |
|
661 | 711 |
- These classes declare every functions, <tt>typedef</tt>s etc. an |
662 | 712 |
implementation of the %concepts should provide, however completely |
663 | 713 |
without implementations and real data structures behind the |
664 | 714 |
interface. On the other hand they should provide nothing else. All |
665 | 715 |
the algorithms working on a data structure meeting a certain concept |
666 | 716 |
should compile with these classes. (Though it will not run properly, |
667 | 717 |
of course.) In this way it is easily to check if an algorithm |
668 | 718 |
doesn't use any extra feature of a certain implementation. |
669 | 719 |
|
670 | 720 |
- The concept descriptor classes also provide a <em>checker class</em> |
671 | 721 |
that makes it possible to check whether a certain implementation of a |
672 | 722 |
concept indeed provides all the required features. |
673 | 723 |
|
674 | 724 |
- Finally, They can serve as a skeleton of a new implementation of a concept. |
675 | 725 |
*/ |
676 | 726 |
|
677 | 727 |
/** |
678 | 728 |
@defgroup graph_concepts Graph Structure Concepts |
679 | 729 |
@ingroup concept |
680 | 730 |
\brief Skeleton and concept checking classes for graph structures |
681 | 731 |
|
682 |
This group contains the skeletons and concept checking classes of LEMON's |
|
683 |
graph structures and helper classes used to implement these. |
|
732 |
This group contains the skeletons and concept checking classes of |
|
733 |
graph structures. |
|
684 | 734 |
*/ |
685 | 735 |
|
686 | 736 |
/** |
687 | 737 |
@defgroup map_concepts Map Concepts |
688 | 738 |
@ingroup concept |
689 | 739 |
\brief Skeleton and concept checking classes for maps |
690 | 740 |
|
691 | 741 |
This group contains the skeletons and concept checking classes of maps. |
692 | 742 |
*/ |
693 | 743 |
|
694 | 744 |
/** |
695 | 745 |
@defgroup tools Standalone Utility Applications |
696 | 746 |
|
697 | 747 |
Some utility applications are listed here. |
698 | 748 |
|
699 | 749 |
The standard compilation procedure (<tt>./configure;make</tt>) will compile |
700 | 750 |
them, as well. |
701 | 751 |
*/ |
702 | 752 |
|
703 | 753 |
/** |
704 | 754 |
\anchor demoprograms |
705 | 755 |
|
706 | 756 |
@defgroup demos Demo Programs |
707 | 757 |
|
708 | 758 |
Some demo programs are listed here. Their full source codes can be found in |
709 | 759 |
the \c demo subdirectory of the source tree. |
710 | 760 |
|
711 | 761 |
In order to compile them, use the <tt>make demo</tt> or the |
712 | 762 |
<tt>make check</tt> commands. |
713 | 763 |
*/ |
714 | 764 |
|
715 | 765 |
} |
1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
2 | 2 |
* |
3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2009 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
8 | 8 |
* |
9 | 9 |
* Permission to use, modify and distribute this software is granted |
10 | 10 |
* provided that this copyright notice appears in all copies. For |
11 | 11 |
* precise terms see the accompanying LICENSE file. |
12 | 12 |
* |
13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
14 | 14 |
* express or implied, and with no claim as to its suitability for any |
15 | 15 |
* purpose. |
16 | 16 |
* |
17 | 17 |
*/ |
18 | 18 |
|
19 | 19 |
/** |
20 | 20 |
\mainpage LEMON Documentation |
21 | 21 |
|
22 | 22 |
\section intro Introduction |
23 | 23 |
|
24 |
\subsection whatis What is LEMON |
|
25 |
|
|
26 |
LEMON stands for <b>L</b>ibrary for <b>E</b>fficient <b>M</b>odeling |
|
27 |
and <b>O</b>ptimization in <b>N</b>etworks. |
|
28 |
It is a C++ template |
|
29 |
library aimed at combinatorial optimization tasks which |
|
30 |
often involve in working |
|
31 |
with graphs. |
|
24 |
<b>LEMON</b> stands for <i><b>L</b>ibrary for <b>E</b>fficient <b>M</b>odeling |
|
25 |
and <b>O</b>ptimization in <b>N</b>etworks</i>. |
|
26 |
It is a C++ template library providing efficient implementation of common |
|
27 |
data structures and algorithms with focus on combinatorial optimization |
|
28 |
problems in graphs and networks. |
|
32 | 29 |
|
33 | 30 |
<b> |
34 | 31 |
LEMON is an <a class="el" href="http://opensource.org/">open source</a> |
35 | 32 |
project. |
36 | 33 |
You are free to use it in your commercial or |
37 | 34 |
non-commercial applications under very permissive |
38 | 35 |
\ref license "license terms". |
39 | 36 |
</b> |
40 | 37 |
|
41 |
|
|
38 |
The project is maintained by the |
|
39 |
<a href="http://www.cs.elte.hu/egres/">Egerváry Research Group on |
|
40 |
Combinatorial Optimization</a> \ref egres |
|
41 |
at the Operations Research Department of the |
|
42 |
<a href="http://www.elte.hu/">Eötvös Loránd University, |
|
43 |
Budapest</a>, Hungary. |
|
44 |
LEMON is also a member of the <a href="http://www.coin-or.org/">COIN-OR</a> |
|
45 |
initiative \ref coinor. |
|
46 |
|
|
47 |
\section howtoread How to Read the Documentation |
|
42 | 48 |
|
43 | 49 |
If you would like to get to know the library, see |
44 | 50 |
<a class="el" href="http://lemon.cs.elte.hu/pub/tutorial/">LEMON Tutorial</a>. |
45 | 51 |
|
46 | 52 |
If you know what you are looking for, then try to find it under the |
47 | 53 |
<a class="el" href="modules.html">Modules</a> section. |
48 | 54 |
|
49 | 55 |
If you are a user of the old (0.x) series of LEMON, please check out the |
50 | 56 |
\ref migration "Migration Guide" for the backward incompatibilities. |
51 | 57 |
*/ |
1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
2 | 2 |
* |
3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2009 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
8 | 8 |
* |
9 | 9 |
* Permission to use, modify and distribute this software is granted |
10 | 10 |
* provided that this copyright notice appears in all copies. For |
11 | 11 |
* precise terms see the accompanying LICENSE file. |
12 | 12 |
* |
13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
14 | 14 |
* express or implied, and with no claim as to its suitability for any |
15 | 15 |
* purpose. |
16 | 16 |
* |
17 | 17 |
*/ |
18 | 18 |
|
19 | 19 |
namespace lemon { |
20 | 20 |
|
21 | 21 |
/** |
22 | 22 |
\page min_cost_flow Minimum Cost Flow Problem |
23 | 23 |
|
24 | 24 |
\section mcf_def Definition (GEQ form) |
25 | 25 |
|
26 | 26 |
The \e minimum \e cost \e flow \e problem is to find a feasible flow of |
27 | 27 |
minimum total cost from a set of supply nodes to a set of demand nodes |
28 | 28 |
in a network with capacity constraints (lower and upper bounds) |
29 |
and arc costs. |
|
29 |
and arc costs \ref amo93networkflows. |
|
30 | 30 |
|
31 | 31 |
Formally, let \f$G=(V,A)\f$ be a digraph, \f$lower: A\rightarrow\mathbf{R}\f$, |
32 | 32 |
\f$upper: A\rightarrow\mathbf{R}\cup\{+\infty\}\f$ denote the lower and |
33 | 33 |
upper bounds for the flow values on the arcs, for which |
34 | 34 |
\f$lower(uv) \leq upper(uv)\f$ must hold for all \f$uv\in A\f$, |
35 | 35 |
\f$cost: A\rightarrow\mathbf{R}\f$ denotes the cost per unit flow |
36 | 36 |
on the arcs and \f$sup: V\rightarrow\mathbf{R}\f$ denotes the |
37 | 37 |
signed supply values of the nodes. |
38 | 38 |
If \f$sup(u)>0\f$, then \f$u\f$ is a supply node with \f$sup(u)\f$ |
39 | 39 |
supply, if \f$sup(u)<0\f$, then \f$u\f$ is a demand node with |
40 | 40 |
\f$-sup(u)\f$ demand. |
41 | 41 |
A minimum cost flow is an \f$f: A\rightarrow\mathbf{R}\f$ solution |
42 | 42 |
of the following optimization problem. |
43 | 43 |
|
44 | 44 |
\f[ \min\sum_{uv\in A} f(uv) \cdot cost(uv) \f] |
45 | 45 |
\f[ \sum_{uv\in A} f(uv) - \sum_{vu\in A} f(vu) \geq |
46 | 46 |
sup(u) \quad \forall u\in V \f] |
47 | 47 |
\f[ lower(uv) \leq f(uv) \leq upper(uv) \quad \forall uv\in A \f] |
48 | 48 |
|
49 | 49 |
The sum of the supply values, i.e. \f$\sum_{u\in V} sup(u)\f$ must be |
50 | 50 |
zero or negative in order to have a feasible solution (since the sum |
51 | 51 |
of the expressions on the left-hand side of the inequalities is zero). |
52 | 52 |
It means that the total demand must be greater or equal to the total |
53 | 53 |
supply and all the supplies have to be carried out from the supply nodes, |
54 | 54 |
but there could be demands that are not satisfied. |
55 | 55 |
If \f$\sum_{u\in V} sup(u)\f$ is zero, then all the supply/demand |
56 | 56 |
constraints have to be satisfied with equality, i.e. all demands |
57 | 57 |
have to be satisfied and all supplies have to be used. |
58 | 58 |
|
59 | 59 |
|
60 | 60 |
\section mcf_algs Algorithms |
61 | 61 |
|
62 | 62 |
LEMON contains several algorithms for solving this problem, for more |
63 | 63 |
information see \ref min_cost_flow_algs "Minimum Cost Flow Algorithms". |
64 | 64 |
|
65 | 65 |
A feasible solution for this problem can be found using \ref Circulation. |
66 | 66 |
|
67 | 67 |
|
68 | 68 |
\section mcf_dual Dual Solution |
69 | 69 |
|
70 | 70 |
The dual solution of the minimum cost flow problem is represented by |
71 | 71 |
node potentials \f$\pi: V\rightarrow\mathbf{R}\f$. |
72 | 72 |
An \f$f: A\rightarrow\mathbf{R}\f$ primal feasible solution is optimal |
73 | 73 |
if and only if for some \f$\pi: V\rightarrow\mathbf{R}\f$ node potentials |
74 | 74 |
the following \e complementary \e slackness optimality conditions hold. |
75 | 75 |
|
76 | 76 |
- For all \f$uv\in A\f$ arcs: |
77 | 77 |
- if \f$cost^\pi(uv)>0\f$, then \f$f(uv)=lower(uv)\f$; |
78 | 78 |
- if \f$lower(uv)<f(uv)<upper(uv)\f$, then \f$cost^\pi(uv)=0\f$; |
79 | 79 |
- if \f$cost^\pi(uv)<0\f$, then \f$f(uv)=upper(uv)\f$. |
80 | 80 |
- For all \f$u\in V\f$ nodes: |
81 | 81 |
- \f$\pi(u)<=0\f$; |
82 | 82 |
- if \f$\sum_{uv\in A} f(uv) - \sum_{vu\in A} f(vu) \neq sup(u)\f$, |
83 | 83 |
then \f$\pi(u)=0\f$. |
84 | 84 |
|
85 | 85 |
Here \f$cost^\pi(uv)\f$ denotes the \e reduced \e cost of the arc |
86 | 86 |
\f$uv\in A\f$ with respect to the potential function \f$\pi\f$, i.e. |
87 | 87 |
\f[ cost^\pi(uv) = cost(uv) + \pi(u) - \pi(v).\f] |
88 | 88 |
|
89 | 89 |
All algorithms provide dual solution (node potentials), as well, |
90 | 90 |
if an optimal flow is found. |
91 | 91 |
|
92 | 92 |
|
93 | 93 |
\section mcf_eq Equality Form |
94 | 94 |
|
95 | 95 |
The above \ref mcf_def "definition" is actually more general than the |
96 | 96 |
usual formulation of the minimum cost flow problem, in which strict |
97 | 97 |
equalities are required in the supply/demand contraints. |
98 | 98 |
|
99 | 99 |
\f[ \min\sum_{uv\in A} f(uv) \cdot cost(uv) \f] |
100 | 100 |
\f[ \sum_{uv\in A} f(uv) - \sum_{vu\in A} f(vu) = |
101 | 101 |
sup(u) \quad \forall u\in V \f] |
102 | 102 |
\f[ lower(uv) \leq f(uv) \leq upper(uv) \quad \forall uv\in A \f] |
103 | 103 |
|
104 | 104 |
However if the sum of the supply values is zero, then these two problems |
105 | 105 |
are equivalent. |
106 | 106 |
The \ref min_cost_flow_algs "algorithms" in LEMON support the general |
107 | 107 |
form, so if you need the equality form, you have to ensure this additional |
108 | 108 |
contraint manually. |
109 | 109 |
|
110 | 110 |
|
111 | 111 |
\section mcf_leq Opposite Inequalites (LEQ Form) |
112 | 112 |
|
113 | 113 |
Another possible definition of the minimum cost flow problem is |
114 | 114 |
when there are <em>"less or equal"</em> (LEQ) supply/demand constraints, |
115 | 115 |
instead of the <em>"greater or equal"</em> (GEQ) constraints. |
116 | 116 |
|
117 | 117 |
\f[ \min\sum_{uv\in A} f(uv) \cdot cost(uv) \f] |
118 | 118 |
\f[ \sum_{uv\in A} f(uv) - \sum_{vu\in A} f(vu) \leq |
119 | 119 |
sup(u) \quad \forall u\in V \f] |
120 | 120 |
\f[ lower(uv) \leq f(uv) \leq upper(uv) \quad \forall uv\in A \f] |
121 | 121 |
|
122 | 122 |
It means that the total demand must be less or equal to the |
123 | 123 |
total supply (i.e. \f$\sum_{u\in V} sup(u)\f$ must be zero or |
124 | 124 |
positive) and all the demands have to be satisfied, but there |
125 | 125 |
could be supplies that are not carried out from the supply |
126 | 126 |
nodes. |
127 | 127 |
The equality form is also a special case of this form, of course. |
128 | 128 |
|
129 | 129 |
You could easily transform this case to the \ref mcf_def "GEQ form" |
130 | 130 |
of the problem by reversing the direction of the arcs and taking the |
131 | 131 |
negative of the supply values (e.g. using \ref ReverseDigraph and |
132 | 132 |
\ref NegMap adaptors). |
133 | 133 |
However \ref NetworkSimplex algorithm also supports this form directly |
134 | 134 |
for the sake of convenience. |
135 | 135 |
|
136 | 136 |
Note that the optimality conditions for this supply constraint type are |
137 | 137 |
slightly differ from the conditions that are discussed for the GEQ form, |
138 | 138 |
namely the potentials have to be non-negative instead of non-positive. |
139 | 139 |
An \f$f: A\rightarrow\mathbf{R}\f$ feasible solution of this problem |
140 | 140 |
is optimal if and only if for some \f$\pi: V\rightarrow\mathbf{R}\f$ |
141 | 141 |
node potentials the following conditions hold. |
142 | 142 |
|
143 | 143 |
- For all \f$uv\in A\f$ arcs: |
144 | 144 |
- if \f$cost^\pi(uv)>0\f$, then \f$f(uv)=lower(uv)\f$; |
145 | 145 |
- if \f$lower(uv)<f(uv)<upper(uv)\f$, then \f$cost^\pi(uv)=0\f$; |
146 | 146 |
- if \f$cost^\pi(uv)<0\f$, then \f$f(uv)=upper(uv)\f$. |
147 | 147 |
- For all \f$u\in V\f$ nodes: |
148 | 148 |
- \f$\pi(u)>=0\f$; |
149 | 149 |
- if \f$\sum_{uv\in A} f(uv) - \sum_{vu\in A} f(vu) \neq sup(u)\f$, |
150 | 150 |
then \f$\pi(u)=0\f$. |
151 | 151 |
|
152 | 152 |
*/ |
153 | 153 |
} |
1 | 1 |
EXTRA_DIST += \ |
2 | 2 |
lemon/lemon.pc.in \ |
3 | 3 |
lemon/CMakeLists.txt \ |
4 | 4 |
lemon/config.h.cmake |
5 | 5 |
|
6 | 6 |
pkgconfig_DATA += lemon/lemon.pc |
7 | 7 |
|
8 | 8 |
lib_LTLIBRARIES += lemon/libemon.la |
9 | 9 |
|
10 | 10 |
lemon_libemon_la_SOURCES = \ |
11 | 11 |
lemon/arg_parser.cc \ |
12 | 12 |
lemon/base.cc \ |
13 | 13 |
lemon/color.cc \ |
14 | 14 |
lemon/lp_base.cc \ |
15 | 15 |
lemon/lp_skeleton.cc \ |
16 | 16 |
lemon/random.cc \ |
17 | 17 |
lemon/bits/windows.cc |
18 | 18 |
|
19 | 19 |
nodist_lemon_HEADERS = lemon/config.h |
20 | 20 |
|
21 | 21 |
lemon_libemon_la_CXXFLAGS = \ |
22 | 22 |
$(AM_CXXFLAGS) \ |
23 | 23 |
$(GLPK_CFLAGS) \ |
24 | 24 |
$(CPLEX_CFLAGS) \ |
25 | 25 |
$(SOPLEX_CXXFLAGS) \ |
26 | 26 |
$(CLP_CXXFLAGS) \ |
27 | 27 |
$(CBC_CXXFLAGS) |
28 | 28 |
|
29 | 29 |
lemon_libemon_la_LDFLAGS = \ |
30 | 30 |
$(GLPK_LIBS) \ |
31 | 31 |
$(CPLEX_LIBS) \ |
32 | 32 |
$(SOPLEX_LIBS) \ |
33 | 33 |
$(CLP_LIBS) \ |
34 | 34 |
$(CBC_LIBS) |
35 | 35 |
|
36 | 36 |
if HAVE_GLPK |
37 | 37 |
lemon_libemon_la_SOURCES += lemon/glpk.cc |
38 | 38 |
endif |
39 | 39 |
|
40 | 40 |
if HAVE_CPLEX |
41 | 41 |
lemon_libemon_la_SOURCES += lemon/cplex.cc |
42 | 42 |
endif |
43 | 43 |
|
44 | 44 |
if HAVE_SOPLEX |
45 | 45 |
lemon_libemon_la_SOURCES += lemon/soplex.cc |
46 | 46 |
endif |
47 | 47 |
|
48 | 48 |
if HAVE_CLP |
49 | 49 |
lemon_libemon_la_SOURCES += lemon/clp.cc |
50 | 50 |
endif |
51 | 51 |
|
52 | 52 |
if HAVE_CBC |
53 | 53 |
lemon_libemon_la_SOURCES += lemon/cbc.cc |
54 | 54 |
endif |
55 | 55 |
|
56 | 56 |
lemon_HEADERS += \ |
57 | 57 |
lemon/adaptors.h \ |
58 | 58 |
lemon/arg_parser.h \ |
59 | 59 |
lemon/assert.h \ |
60 | 60 |
lemon/bellman_ford.h \ |
61 | 61 |
lemon/bfs.h \ |
62 | 62 |
lemon/bin_heap.h \ |
63 | 63 |
lemon/binom_heap.h \ |
64 | 64 |
lemon/bucket_heap.h \ |
65 | 65 |
lemon/cbc.h \ |
66 | 66 |
lemon/circulation.h \ |
67 | 67 |
lemon/clp.h \ |
68 | 68 |
lemon/color.h \ |
69 | 69 |
lemon/concept_check.h \ |
70 | 70 |
lemon/connectivity.h \ |
71 | 71 |
lemon/counter.h \ |
72 | 72 |
lemon/core.h \ |
73 | 73 |
lemon/cplex.h \ |
74 | 74 |
lemon/dfs.h \ |
75 | 75 |
lemon/dijkstra.h \ |
76 | 76 |
lemon/dim2.h \ |
77 | 77 |
lemon/dimacs.h \ |
78 | 78 |
lemon/edge_set.h \ |
79 | 79 |
lemon/elevator.h \ |
80 | 80 |
lemon/error.h \ |
81 | 81 |
lemon/euler.h \ |
82 | 82 |
lemon/fib_heap.h \ |
83 | 83 |
lemon/fourary_heap.h \ |
84 | 84 |
lemon/full_graph.h \ |
85 | 85 |
lemon/glpk.h \ |
86 | 86 |
lemon/gomory_hu.h \ |
87 | 87 |
lemon/graph_to_eps.h \ |
88 | 88 |
lemon/grid_graph.h \ |
89 |
lemon/hartmann_orlin.h \ |
|
90 |
lemon/howard.h \ |
|
89 | 91 |
lemon/hypercube_graph.h \ |
92 |
lemon/karp.h \ |
|
90 | 93 |
lemon/kary_heap.h \ |
91 | 94 |
lemon/kruskal.h \ |
92 | 95 |
lemon/hao_orlin.h \ |
93 | 96 |
lemon/lgf_reader.h \ |
94 | 97 |
lemon/lgf_writer.h \ |
95 | 98 |
lemon/list_graph.h \ |
96 | 99 |
lemon/lp.h \ |
97 | 100 |
lemon/lp_base.h \ |
98 | 101 |
lemon/lp_skeleton.h \ |
99 | 102 |
lemon/maps.h \ |
100 | 103 |
lemon/matching.h \ |
101 | 104 |
lemon/math.h \ |
102 | 105 |
lemon/min_cost_arborescence.h \ |
103 | 106 |
lemon/nauty_reader.h \ |
104 | 107 |
lemon/network_simplex.h \ |
105 | 108 |
lemon/pairing_heap.h \ |
106 | 109 |
lemon/path.h \ |
107 | 110 |
lemon/preflow.h \ |
108 | 111 |
lemon/radix_heap.h \ |
109 | 112 |
lemon/radix_sort.h \ |
110 | 113 |
lemon/random.h \ |
111 | 114 |
lemon/smart_graph.h \ |
112 | 115 |
lemon/soplex.h \ |
116 |
lemon/static_graph.h \ |
|
113 | 117 |
lemon/suurballe.h \ |
114 | 118 |
lemon/time_measure.h \ |
115 | 119 |
lemon/tolerance.h \ |
116 | 120 |
lemon/unionfind.h \ |
117 | 121 |
lemon/bits/windows.h |
118 | 122 |
|
119 | 123 |
bits_HEADERS += \ |
120 | 124 |
lemon/bits/alteration_notifier.h \ |
121 | 125 |
lemon/bits/array_map.h \ |
122 | 126 |
lemon/bits/bezier.h \ |
123 | 127 |
lemon/bits/default_map.h \ |
124 | 128 |
lemon/bits/edge_set_extender.h \ |
125 | 129 |
lemon/bits/enable_if.h \ |
126 | 130 |
lemon/bits/graph_adaptor_extender.h \ |
127 | 131 |
lemon/bits/graph_extender.h \ |
128 | 132 |
lemon/bits/map_extender.h \ |
129 | 133 |
lemon/bits/path_dump.h \ |
130 | 134 |
lemon/bits/solver_bits.h \ |
131 | 135 |
lemon/bits/traits.h \ |
132 | 136 |
lemon/bits/variant.h \ |
133 | 137 |
lemon/bits/vector_map.h |
134 | 138 |
|
135 | 139 |
concept_HEADERS += \ |
136 | 140 |
lemon/concepts/digraph.h \ |
137 | 141 |
lemon/concepts/graph.h \ |
138 | 142 |
lemon/concepts/graph_components.h \ |
139 | 143 |
lemon/concepts/heap.h \ |
140 | 144 |
lemon/concepts/maps.h \ |
141 | 145 |
lemon/concepts/path.h |
1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
2 | 2 |
* |
3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2009 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
8 | 8 |
* |
9 | 9 |
* Permission to use, modify and distribute this software is granted |
10 | 10 |
* provided that this copyright notice appears in all copies. For |
11 | 11 |
* precise terms see the accompanying LICENSE file. |
12 | 12 |
* |
13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
14 | 14 |
* express or implied, and with no claim as to its suitability for any |
15 | 15 |
* purpose. |
16 | 16 |
* |
17 | 17 |
*/ |
18 | 18 |
|
19 | 19 |
#ifndef LEMON_BITS_GRAPH_EXTENDER_H |
20 | 20 |
#define LEMON_BITS_GRAPH_EXTENDER_H |
21 | 21 |
|
22 | 22 |
#include <lemon/core.h> |
23 | 23 |
|
24 | 24 |
#include <lemon/bits/map_extender.h> |
25 | 25 |
#include <lemon/bits/default_map.h> |
26 | 26 |
|
27 | 27 |
#include <lemon/concept_check.h> |
28 | 28 |
#include <lemon/concepts/maps.h> |
29 | 29 |
|
30 | 30 |
//\ingroup graphbits |
31 | 31 |
//\file |
32 | 32 |
//\brief Extenders for the graph types |
33 | 33 |
namespace lemon { |
34 | 34 |
|
35 | 35 |
// \ingroup graphbits |
36 | 36 |
// |
37 | 37 |
// \brief Extender for the digraph implementations |
38 | 38 |
template <typename Base> |
39 | 39 |
class DigraphExtender : public Base { |
40 | 40 |
typedef Base Parent; |
41 | 41 |
|
42 | 42 |
public: |
43 | 43 |
|
44 | 44 |
typedef DigraphExtender Digraph; |
45 | 45 |
|
46 | 46 |
// Base extensions |
47 | 47 |
|
48 | 48 |
typedef typename Parent::Node Node; |
49 | 49 |
typedef typename Parent::Arc Arc; |
50 | 50 |
|
51 | 51 |
int maxId(Node) const { |
52 | 52 |
return Parent::maxNodeId(); |
53 | 53 |
} |
54 | 54 |
|
55 | 55 |
int maxId(Arc) const { |
56 | 56 |
return Parent::maxArcId(); |
57 | 57 |
} |
58 | 58 |
|
59 |
Node fromId(int id, Node) |
|
59 |
static Node fromId(int id, Node) { |
|
60 | 60 |
return Parent::nodeFromId(id); |
61 | 61 |
} |
62 | 62 |
|
63 |
Arc fromId(int id, Arc) |
|
63 |
static Arc fromId(int id, Arc) { |
|
64 | 64 |
return Parent::arcFromId(id); |
65 | 65 |
} |
66 | 66 |
|
67 | 67 |
Node oppositeNode(const Node &node, const Arc &arc) const { |
68 | 68 |
if (node == Parent::source(arc)) |
69 | 69 |
return Parent::target(arc); |
70 | 70 |
else if(node == Parent::target(arc)) |
71 | 71 |
return Parent::source(arc); |
72 | 72 |
else |
73 | 73 |
return INVALID; |
74 | 74 |
} |
75 | 75 |
|
76 | 76 |
// Alterable extension |
77 | 77 |
|
78 | 78 |
typedef AlterationNotifier<DigraphExtender, Node> NodeNotifier; |
79 | 79 |
typedef AlterationNotifier<DigraphExtender, Arc> ArcNotifier; |
80 | 80 |
|
81 | 81 |
|
82 | 82 |
protected: |
83 | 83 |
|
84 | 84 |
mutable NodeNotifier node_notifier; |
85 | 85 |
mutable ArcNotifier arc_notifier; |
86 | 86 |
|
87 | 87 |
public: |
88 | 88 |
|
89 | 89 |
NodeNotifier& notifier(Node) const { |
90 | 90 |
return node_notifier; |
91 | 91 |
} |
92 | 92 |
|
93 | 93 |
ArcNotifier& notifier(Arc) const { |
94 | 94 |
return arc_notifier; |
95 | 95 |
} |
96 | 96 |
|
97 | 97 |
class NodeIt : public Node { |
98 | 98 |
const Digraph* _digraph; |
99 | 99 |
public: |
100 | 100 |
|
101 | 101 |
NodeIt() {} |
102 | 102 |
|
103 | 103 |
NodeIt(Invalid i) : Node(i) { } |
104 | 104 |
|
105 | 105 |
explicit NodeIt(const Digraph& digraph) : _digraph(&digraph) { |
106 | 106 |
_digraph->first(static_cast<Node&>(*this)); |
107 | 107 |
} |
108 | 108 |
|
109 | 109 |
NodeIt(const Digraph& digraph, const Node& node) |
110 | 110 |
: Node(node), _digraph(&digraph) {} |
111 | 111 |
|
112 | 112 |
NodeIt& operator++() { |
113 | 113 |
_digraph->next(*this); |
114 | 114 |
return *this; |
115 | 115 |
} |
116 | 116 |
|
117 | 117 |
}; |
118 | 118 |
|
119 | 119 |
|
120 | 120 |
class ArcIt : public Arc { |
121 | 121 |
const Digraph* _digraph; |
122 | 122 |
public: |
123 | 123 |
|
124 | 124 |
ArcIt() { } |
125 | 125 |
|
126 | 126 |
ArcIt(Invalid i) : Arc(i) { } |
127 | 127 |
|
128 | 128 |
explicit ArcIt(const Digraph& digraph) : _digraph(&digraph) { |
129 | 129 |
_digraph->first(static_cast<Arc&>(*this)); |
130 | 130 |
} |
131 | 131 |
|
132 | 132 |
ArcIt(const Digraph& digraph, const Arc& arc) : |
133 | 133 |
Arc(arc), _digraph(&digraph) { } |
134 | 134 |
|
135 | 135 |
ArcIt& operator++() { |
136 | 136 |
_digraph->next(*this); |
137 | 137 |
return *this; |
138 | 138 |
} |
139 | 139 |
|
140 | 140 |
}; |
141 | 141 |
|
142 | 142 |
|
143 | 143 |
class OutArcIt : public Arc { |
144 | 144 |
const Digraph* _digraph; |
145 | 145 |
public: |
146 | 146 |
|
147 | 147 |
OutArcIt() { } |
148 | 148 |
|
149 | 149 |
OutArcIt(Invalid i) : Arc(i) { } |
150 | 150 |
|
151 | 151 |
OutArcIt(const Digraph& digraph, const Node& node) |
152 | 152 |
: _digraph(&digraph) { |
153 | 153 |
_digraph->firstOut(*this, node); |
154 | 154 |
} |
155 | 155 |
|
156 | 156 |
OutArcIt(const Digraph& digraph, const Arc& arc) |
157 | 157 |
: Arc(arc), _digraph(&digraph) {} |
158 | 158 |
|
159 | 159 |
OutArcIt& operator++() { |
160 | 160 |
_digraph->nextOut(*this); |
161 | 161 |
return *this; |
162 | 162 |
} |
163 | 163 |
|
164 | 164 |
}; |
165 | 165 |
|
166 | 166 |
|
167 | 167 |
class InArcIt : public Arc { |
168 | 168 |
const Digraph* _digraph; |
169 | 169 |
public: |
170 | 170 |
|
171 | 171 |
InArcIt() { } |
172 | 172 |
|
173 | 173 |
InArcIt(Invalid i) : Arc(i) { } |
174 | 174 |
|
175 | 175 |
InArcIt(const Digraph& digraph, const Node& node) |
176 | 176 |
: _digraph(&digraph) { |
177 | 177 |
_digraph->firstIn(*this, node); |
178 | 178 |
} |
179 | 179 |
|
180 | 180 |
InArcIt(const Digraph& digraph, const Arc& arc) : |
181 | 181 |
Arc(arc), _digraph(&digraph) {} |
182 | 182 |
|
183 | 183 |
InArcIt& operator++() { |
184 | 184 |
_digraph->nextIn(*this); |
185 | 185 |
return *this; |
186 | 186 |
} |
187 | 187 |
|
188 | 188 |
}; |
189 | 189 |
|
190 | 190 |
// \brief Base node of the iterator |
191 | 191 |
// |
192 | 192 |
// Returns the base node (i.e. the source in this case) of the iterator |
193 | 193 |
Node baseNode(const OutArcIt &arc) const { |
194 | 194 |
return Parent::source(arc); |
195 | 195 |
} |
196 | 196 |
// \brief Running node of the iterator |
197 | 197 |
// |
198 | 198 |
// Returns the running node (i.e. the target in this case) of the |
199 | 199 |
// iterator |
200 | 200 |
Node runningNode(const OutArcIt &arc) const { |
201 | 201 |
return Parent::target(arc); |
202 | 202 |
} |
203 | 203 |
|
204 | 204 |
// \brief Base node of the iterator |
205 | 205 |
// |
206 | 206 |
// Returns the base node (i.e. the target in this case) of the iterator |
207 | 207 |
Node baseNode(const InArcIt &arc) const { |
208 | 208 |
return Parent::target(arc); |
209 | 209 |
} |
210 | 210 |
// \brief Running node of the iterator |
211 | 211 |
// |
212 | 212 |
// Returns the running node (i.e. the source in this case) of the |
213 | 213 |
// iterator |
214 | 214 |
Node runningNode(const InArcIt &arc) const { |
215 | 215 |
return Parent::source(arc); |
216 | 216 |
} |
217 | 217 |
|
218 | 218 |
|
219 | 219 |
template <typename _Value> |
220 | 220 |
class NodeMap |
221 | 221 |
: public MapExtender<DefaultMap<Digraph, Node, _Value> > { |
222 | 222 |
typedef MapExtender<DefaultMap<Digraph, Node, _Value> > Parent; |
223 | 223 |
|
224 | 224 |
public: |
225 | 225 |
explicit NodeMap(const Digraph& digraph) |
226 | 226 |
: Parent(digraph) {} |
227 | 227 |
NodeMap(const Digraph& digraph, const _Value& value) |
228 | 228 |
: Parent(digraph, value) {} |
229 | 229 |
|
230 | 230 |
private: |
231 | 231 |
NodeMap& operator=(const NodeMap& cmap) { |
232 | 232 |
return operator=<NodeMap>(cmap); |
233 | 233 |
} |
234 | 234 |
|
235 | 235 |
template <typename CMap> |
236 | 236 |
NodeMap& operator=(const CMap& cmap) { |
237 | 237 |
Parent::operator=(cmap); |
238 | 238 |
return *this; |
239 | 239 |
} |
240 | 240 |
|
241 | 241 |
}; |
242 | 242 |
|
243 | 243 |
template <typename _Value> |
244 | 244 |
class ArcMap |
245 | 245 |
: public MapExtender<DefaultMap<Digraph, Arc, _Value> > { |
246 | 246 |
typedef MapExtender<DefaultMap<Digraph, Arc, _Value> > Parent; |
247 | 247 |
|
248 | 248 |
public: |
249 | 249 |
explicit ArcMap(const Digraph& digraph) |
250 | 250 |
: Parent(digraph) {} |
251 | 251 |
ArcMap(const Digraph& digraph, const _Value& value) |
252 | 252 |
: Parent(digraph, value) {} |
253 | 253 |
|
254 | 254 |
private: |
255 | 255 |
ArcMap& operator=(const ArcMap& cmap) { |
256 | 256 |
return operator=<ArcMap>(cmap); |
257 | 257 |
} |
258 | 258 |
|
259 | 259 |
template <typename CMap> |
260 | 260 |
ArcMap& operator=(const CMap& cmap) { |
261 | 261 |
Parent::operator=(cmap); |
262 | 262 |
return *this; |
263 | 263 |
} |
264 | 264 |
}; |
265 | 265 |
|
266 | 266 |
|
267 | 267 |
Node addNode() { |
268 | 268 |
Node node = Parent::addNode(); |
269 | 269 |
notifier(Node()).add(node); |
270 | 270 |
return node; |
271 | 271 |
} |
272 | 272 |
|
273 | 273 |
Arc addArc(const Node& from, const Node& to) { |
274 | 274 |
Arc arc = Parent::addArc(from, to); |
275 | 275 |
notifier(Arc()).add(arc); |
276 | 276 |
return arc; |
277 | 277 |
} |
278 | 278 |
|
279 | 279 |
void clear() { |
280 | 280 |
notifier(Arc()).clear(); |
281 | 281 |
notifier(Node()).clear(); |
282 | 282 |
Parent::clear(); |
283 | 283 |
} |
284 | 284 |
|
285 | 285 |
template <typename Digraph, typename NodeRefMap, typename ArcRefMap> |
286 | 286 |
void build(const Digraph& digraph, NodeRefMap& nodeRef, ArcRefMap& arcRef) { |
287 | 287 |
Parent::build(digraph, nodeRef, arcRef); |
288 | 288 |
notifier(Node()).build(); |
289 | 289 |
notifier(Arc()).build(); |
290 | 290 |
} |
291 | 291 |
|
292 | 292 |
void erase(const Node& node) { |
293 | 293 |
Arc arc; |
294 | 294 |
Parent::firstOut(arc, node); |
295 | 295 |
while (arc != INVALID ) { |
296 | 296 |
erase(arc); |
297 | 297 |
Parent::firstOut(arc, node); |
298 | 298 |
} |
299 | 299 |
|
300 | 300 |
Parent::firstIn(arc, node); |
301 | 301 |
while (arc != INVALID ) { |
302 | 302 |
erase(arc); |
303 | 303 |
Parent::firstIn(arc, node); |
304 | 304 |
} |
305 | 305 |
|
306 | 306 |
notifier(Node()).erase(node); |
307 | 307 |
Parent::erase(node); |
308 | 308 |
} |
309 | 309 |
|
310 | 310 |
void erase(const Arc& arc) { |
311 | 311 |
notifier(Arc()).erase(arc); |
312 | 312 |
Parent::erase(arc); |
313 | 313 |
} |
314 | 314 |
|
315 | 315 |
DigraphExtender() { |
316 | 316 |
node_notifier.setContainer(*this); |
317 | 317 |
arc_notifier.setContainer(*this); |
318 | 318 |
} |
319 | 319 |
|
320 | 320 |
|
321 | 321 |
~DigraphExtender() { |
322 | 322 |
arc_notifier.clear(); |
323 | 323 |
node_notifier.clear(); |
324 | 324 |
} |
325 | 325 |
}; |
326 | 326 |
|
327 | 327 |
// \ingroup _graphbits |
328 | 328 |
// |
329 | 329 |
// \brief Extender for the Graphs |
330 | 330 |
template <typename Base> |
331 | 331 |
class GraphExtender : public Base { |
332 | 332 |
typedef Base Parent; |
333 | 333 |
|
334 | 334 |
public: |
335 | 335 |
|
336 | 336 |
typedef GraphExtender Graph; |
337 | 337 |
|
338 | 338 |
typedef True UndirectedTag; |
339 | 339 |
|
340 | 340 |
typedef typename Parent::Node Node; |
341 | 341 |
typedef typename Parent::Arc Arc; |
342 | 342 |
typedef typename Parent::Edge Edge; |
343 | 343 |
|
344 | 344 |
// Graph extension |
345 | 345 |
|
346 | 346 |
int maxId(Node) const { |
347 | 347 |
return Parent::maxNodeId(); |
348 | 348 |
} |
349 | 349 |
|
350 | 350 |
int maxId(Arc) const { |
351 | 351 |
return Parent::maxArcId(); |
352 | 352 |
} |
353 | 353 |
|
354 | 354 |
int maxId(Edge) const { |
355 | 355 |
return Parent::maxEdgeId(); |
356 | 356 |
} |
357 | 357 |
|
358 |
Node fromId(int id, Node) |
|
358 |
static Node fromId(int id, Node) { |
|
359 | 359 |
return Parent::nodeFromId(id); |
360 | 360 |
} |
361 | 361 |
|
362 |
Arc fromId(int id, Arc) |
|
362 |
static Arc fromId(int id, Arc) { |
|
363 | 363 |
return Parent::arcFromId(id); |
364 | 364 |
} |
365 | 365 |
|
366 |
Edge fromId(int id, Edge) |
|
366 |
static Edge fromId(int id, Edge) { |
|
367 | 367 |
return Parent::edgeFromId(id); |
368 | 368 |
} |
369 | 369 |
|
370 | 370 |
Node oppositeNode(const Node &n, const Edge &e) const { |
371 | 371 |
if( n == Parent::u(e)) |
372 | 372 |
return Parent::v(e); |
373 | 373 |
else if( n == Parent::v(e)) |
374 | 374 |
return Parent::u(e); |
375 | 375 |
else |
376 | 376 |
return INVALID; |
377 | 377 |
} |
378 | 378 |
|
379 | 379 |
Arc oppositeArc(const Arc &arc) const { |
380 | 380 |
return Parent::direct(arc, !Parent::direction(arc)); |
381 | 381 |
} |
382 | 382 |
|
383 | 383 |
using Parent::direct; |
384 | 384 |
Arc direct(const Edge &edge, const Node &node) const { |
385 | 385 |
return Parent::direct(edge, Parent::u(edge) == node); |
386 | 386 |
} |
387 | 387 |
|
388 | 388 |
// Alterable extension |
389 | 389 |
|
390 | 390 |
typedef AlterationNotifier<GraphExtender, Node> NodeNotifier; |
391 | 391 |
typedef AlterationNotifier<GraphExtender, Arc> ArcNotifier; |
392 | 392 |
typedef AlterationNotifier<GraphExtender, Edge> EdgeNotifier; |
393 | 393 |
|
394 | 394 |
|
395 | 395 |
protected: |
396 | 396 |
|
397 | 397 |
mutable NodeNotifier node_notifier; |
398 | 398 |
mutable ArcNotifier arc_notifier; |
399 | 399 |
mutable EdgeNotifier edge_notifier; |
400 | 400 |
|
401 | 401 |
public: |
402 | 402 |
|
403 | 403 |
NodeNotifier& notifier(Node) const { |
404 | 404 |
return node_notifier; |
405 | 405 |
} |
406 | 406 |
|
407 | 407 |
ArcNotifier& notifier(Arc) const { |
408 | 408 |
return arc_notifier; |
409 | 409 |
} |
410 | 410 |
|
411 | 411 |
EdgeNotifier& notifier(Edge) const { |
412 | 412 |
return edge_notifier; |
413 | 413 |
} |
414 | 414 |
|
415 | 415 |
|
416 | 416 |
|
417 | 417 |
class NodeIt : public Node { |
418 | 418 |
const Graph* _graph; |
419 | 419 |
public: |
420 | 420 |
|
421 | 421 |
NodeIt() {} |
422 | 422 |
|
423 | 423 |
NodeIt(Invalid i) : Node(i) { } |
424 | 424 |
|
425 | 425 |
explicit NodeIt(const Graph& graph) : _graph(&graph) { |
426 | 426 |
_graph->first(static_cast<Node&>(*this)); |
427 | 427 |
} |
428 | 428 |
|
429 | 429 |
NodeIt(const Graph& graph, const Node& node) |
430 | 430 |
: Node(node), _graph(&graph) {} |
431 | 431 |
|
432 | 432 |
NodeIt& operator++() { |
433 | 433 |
_graph->next(*this); |
434 | 434 |
return *this; |
435 | 435 |
} |
436 | 436 |
|
437 | 437 |
}; |
438 | 438 |
|
439 | 439 |
|
440 | 440 |
class ArcIt : public Arc { |
441 | 441 |
const Graph* _graph; |
442 | 442 |
public: |
443 | 443 |
|
444 | 444 |
ArcIt() { } |
445 | 445 |
|
446 | 446 |
ArcIt(Invalid i) : Arc(i) { } |
447 | 447 |
|
448 | 448 |
explicit ArcIt(const Graph& graph) : _graph(&graph) { |
449 | 449 |
_graph->first(static_cast<Arc&>(*this)); |
450 | 450 |
} |
451 | 451 |
|
452 | 452 |
ArcIt(const Graph& graph, const Arc& arc) : |
453 | 453 |
Arc(arc), _graph(&graph) { } |
454 | 454 |
|
455 | 455 |
ArcIt& operator++() { |
456 | 456 |
_graph->next(*this); |
457 | 457 |
return *this; |
458 | 458 |
} |
459 | 459 |
|
460 | 460 |
}; |
461 | 461 |
|
462 | 462 |
|
463 | 463 |
class OutArcIt : public Arc { |
464 | 464 |
const Graph* _graph; |
465 | 465 |
public: |
466 | 466 |
|
467 | 467 |
OutArcIt() { } |
468 | 468 |
|
469 | 469 |
OutArcIt(Invalid i) : Arc(i) { } |
470 | 470 |
|
471 | 471 |
OutArcIt(const Graph& graph, const Node& node) |
472 | 472 |
: _graph(&graph) { |
473 | 473 |
_graph->firstOut(*this, node); |
474 | 474 |
} |
475 | 475 |
|
476 | 476 |
OutArcIt(const Graph& graph, const Arc& arc) |
477 | 477 |
: Arc(arc), _graph(&graph) {} |
478 | 478 |
|
479 | 479 |
OutArcIt& operator++() { |
480 | 480 |
_graph->nextOut(*this); |
481 | 481 |
return *this; |
482 | 482 |
} |
483 | 483 |
|
484 | 484 |
}; |
485 | 485 |
|
486 | 486 |
|
487 | 487 |
class InArcIt : public Arc { |
488 | 488 |
const Graph* _graph; |
489 | 489 |
public: |
490 | 490 |
|
491 | 491 |
InArcIt() { } |
492 | 492 |
|
493 | 493 |
InArcIt(Invalid i) : Arc(i) { } |
494 | 494 |
|
495 | 495 |
InArcIt(const Graph& graph, const Node& node) |
496 | 496 |
: _graph(&graph) { |
497 | 497 |
_graph->firstIn(*this, node); |
498 | 498 |
} |
499 | 499 |
|
500 | 500 |
InArcIt(const Graph& graph, const Arc& arc) : |
501 | 501 |
Arc(arc), _graph(&graph) {} |
502 | 502 |
|
503 | 503 |
InArcIt& operator++() { |
504 | 504 |
_graph->nextIn(*this); |
505 | 505 |
return *this; |
506 | 506 |
} |
507 | 507 |
|
508 | 508 |
}; |
509 | 509 |
|
510 | 510 |
|
511 | 511 |
class EdgeIt : public Parent::Edge { |
512 | 512 |
const Graph* _graph; |
513 | 513 |
public: |
514 | 514 |
|
515 | 515 |
EdgeIt() { } |
516 | 516 |
|
517 | 517 |
EdgeIt(Invalid i) : Edge(i) { } |
518 | 518 |
|
519 | 519 |
explicit EdgeIt(const Graph& graph) : _graph(&graph) { |
520 | 520 |
_graph->first(static_cast<Edge&>(*this)); |
521 | 521 |
} |
522 | 522 |
|
523 | 523 |
EdgeIt(const Graph& graph, const Edge& edge) : |
524 | 524 |
Edge(edge), _graph(&graph) { } |
525 | 525 |
|
526 | 526 |
EdgeIt& operator++() { |
527 | 527 |
_graph->next(*this); |
528 | 528 |
return *this; |
529 | 529 |
} |
530 | 530 |
|
531 | 531 |
}; |
532 | 532 |
|
533 | 533 |
class IncEdgeIt : public Parent::Edge { |
534 | 534 |
friend class GraphExtender; |
535 | 535 |
const Graph* _graph; |
536 | 536 |
bool _direction; |
537 | 537 |
public: |
538 | 538 |
|
539 | 539 |
IncEdgeIt() { } |
540 | 540 |
|
541 | 541 |
IncEdgeIt(Invalid i) : Edge(i), _direction(false) { } |
542 | 542 |
|
543 | 543 |
IncEdgeIt(const Graph& graph, const Node &node) : _graph(&graph) { |
544 | 544 |
_graph->firstInc(*this, _direction, node); |
545 | 545 |
} |
546 | 546 |
|
547 | 547 |
IncEdgeIt(const Graph& graph, const Edge &edge, const Node &node) |
548 | 548 |
: _graph(&graph), Edge(edge) { |
549 | 549 |
_direction = (_graph->source(edge) == node); |
550 | 550 |
} |
551 | 551 |
|
552 | 552 |
IncEdgeIt& operator++() { |
553 | 553 |
_graph->nextInc(*this, _direction); |
554 | 554 |
return *this; |
555 | 555 |
} |
556 | 556 |
}; |
557 | 557 |
|
558 | 558 |
// \brief Base node of the iterator |
559 | 559 |
// |
560 | 560 |
// Returns the base node (ie. the source in this case) of the iterator |
561 | 561 |
Node baseNode(const OutArcIt &arc) const { |
562 | 562 |
return Parent::source(static_cast<const Arc&>(arc)); |
563 | 563 |
} |
564 | 564 |
// \brief Running node of the iterator |
565 | 565 |
// |
566 | 566 |
// Returns the running node (ie. the target in this case) of the |
567 | 567 |
// iterator |
568 | 568 |
Node runningNode(const OutArcIt &arc) const { |
569 | 569 |
return Parent::target(static_cast<const Arc&>(arc)); |
570 | 570 |
} |
571 | 571 |
|
572 | 572 |
// \brief Base node of the iterator |
573 | 573 |
// |
574 | 574 |
// Returns the base node (ie. the target in this case) of the iterator |
575 | 575 |
Node baseNode(const InArcIt &arc) const { |
576 | 576 |
return Parent::target(static_cast<const Arc&>(arc)); |
577 | 577 |
} |
578 | 578 |
// \brief Running node of the iterator |
579 | 579 |
// |
580 | 580 |
// Returns the running node (ie. the source in this case) of the |
581 | 581 |
// iterator |
582 | 582 |
Node runningNode(const InArcIt &arc) const { |
583 | 583 |
return Parent::source(static_cast<const Arc&>(arc)); |
584 | 584 |
} |
585 | 585 |
|
586 | 586 |
// Base node of the iterator |
587 | 587 |
// |
588 | 588 |
// Returns the base node of the iterator |
589 | 589 |
Node baseNode(const IncEdgeIt &edge) const { |
590 | 590 |
return edge._direction ? u(edge) : v(edge); |
591 | 591 |
} |
592 | 592 |
// Running node of the iterator |
593 | 593 |
// |
594 | 594 |
// Returns the running node of the iterator |
595 | 595 |
Node runningNode(const IncEdgeIt &edge) const { |
596 | 596 |
return edge._direction ? v(edge) : u(edge); |
597 | 597 |
} |
598 | 598 |
|
599 | 599 |
// Mappable extension |
600 | 600 |
|
601 | 601 |
template <typename _Value> |
602 | 602 |
class NodeMap |
603 | 603 |
: public MapExtender<DefaultMap<Graph, Node, _Value> > { |
604 | 604 |
typedef MapExtender<DefaultMap<Graph, Node, _Value> > Parent; |
605 | 605 |
|
606 | 606 |
public: |
607 | 607 |
explicit NodeMap(const Graph& graph) |
608 | 608 |
: Parent(graph) {} |
609 | 609 |
NodeMap(const Graph& graph, const _Value& value) |
610 | 610 |
: Parent(graph, value) {} |
611 | 611 |
|
612 | 612 |
private: |
613 | 613 |
NodeMap& operator=(const NodeMap& cmap) { |
614 | 614 |
return operator=<NodeMap>(cmap); |
615 | 615 |
} |
616 | 616 |
|
617 | 617 |
template <typename CMap> |
618 | 618 |
NodeMap& operator=(const CMap& cmap) { |
619 | 619 |
Parent::operator=(cmap); |
620 | 620 |
return *this; |
621 | 621 |
} |
622 | 622 |
1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
2 | 2 |
* |
3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2009 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
8 | 8 |
* |
9 | 9 |
* Permission to use, modify and distribute this software is granted |
10 | 10 |
* provided that this copyright notice appears in all copies. For |
11 | 11 |
* precise terms see the accompanying LICENSE file. |
12 | 12 |
* |
13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
14 | 14 |
* express or implied, and with no claim as to its suitability for any |
15 | 15 |
* purpose. |
16 | 16 |
* |
17 | 17 |
*/ |
18 | 18 |
|
19 | 19 |
///\file |
20 | 20 |
///\brief Implementation of the CBC MIP solver interface. |
21 | 21 |
|
22 | 22 |
#include "cbc.h" |
23 | 23 |
|
24 | 24 |
#include <coin/CoinModel.hpp> |
25 | 25 |
#include <coin/CbcModel.hpp> |
26 | 26 |
#include <coin/OsiSolverInterface.hpp> |
27 | 27 |
|
28 | 28 |
#ifdef COIN_HAS_CLP |
29 | 29 |
#include "coin/OsiClpSolverInterface.hpp" |
30 | 30 |
#endif |
31 | 31 |
#ifdef COIN_HAS_OSL |
32 | 32 |
#include "coin/OsiOslSolverInterface.hpp" |
33 | 33 |
#endif |
34 | 34 |
|
35 | 35 |
#include "coin/CbcCutGenerator.hpp" |
36 | 36 |
#include "coin/CbcHeuristicLocal.hpp" |
37 | 37 |
#include "coin/CbcHeuristicGreedy.hpp" |
38 | 38 |
#include "coin/CbcHeuristicFPump.hpp" |
39 | 39 |
#include "coin/CbcHeuristicRINS.hpp" |
40 | 40 |
|
41 | 41 |
#include "coin/CglGomory.hpp" |
42 | 42 |
#include "coin/CglProbing.hpp" |
43 | 43 |
#include "coin/CglKnapsackCover.hpp" |
44 | 44 |
#include "coin/CglOddHole.hpp" |
45 | 45 |
#include "coin/CglClique.hpp" |
46 | 46 |
#include "coin/CglFlowCover.hpp" |
47 | 47 |
#include "coin/CglMixedIntegerRounding.hpp" |
48 | 48 |
|
49 | 49 |
#include "coin/CbcHeuristic.hpp" |
50 | 50 |
|
51 | 51 |
namespace lemon { |
52 | 52 |
|
53 | 53 |
CbcMip::CbcMip() { |
54 | 54 |
_prob = new CoinModel(); |
55 | 55 |
_prob->setProblemName("LEMON"); |
56 | 56 |
_osi_solver = 0; |
57 | 57 |
_cbc_model = 0; |
58 | 58 |
messageLevel(MESSAGE_NOTHING); |
59 | 59 |
} |
60 | 60 |
|
61 | 61 |
CbcMip::CbcMip(const CbcMip& other) { |
62 | 62 |
_prob = new CoinModel(*other._prob); |
63 | 63 |
_prob->setProblemName("LEMON"); |
64 | 64 |
_osi_solver = 0; |
65 | 65 |
_cbc_model = 0; |
66 | 66 |
messageLevel(MESSAGE_NOTHING); |
67 | 67 |
} |
68 | 68 |
|
69 | 69 |
CbcMip::~CbcMip() { |
70 | 70 |
delete _prob; |
71 | 71 |
if (_osi_solver) delete _osi_solver; |
72 | 72 |
if (_cbc_model) delete _cbc_model; |
73 | 73 |
} |
74 | 74 |
|
75 | 75 |
const char* CbcMip::_solverName() const { return "CbcMip"; } |
76 | 76 |
|
77 | 77 |
int CbcMip::_addCol() { |
78 | 78 |
_prob->addColumn(0, 0, 0, -COIN_DBL_MAX, COIN_DBL_MAX, 0.0, 0, false); |
79 | 79 |
return _prob->numberColumns() - 1; |
80 | 80 |
} |
81 | 81 |
|
82 | 82 |
CbcMip* CbcMip::newSolver() const { |
83 | 83 |
CbcMip* newlp = new CbcMip; |
84 | 84 |
return newlp; |
85 | 85 |
} |
86 | 86 |
|
87 | 87 |
CbcMip* CbcMip::cloneSolver() const { |
88 | 88 |
CbcMip* copylp = new CbcMip(*this); |
89 | 89 |
return copylp; |
90 | 90 |
} |
91 | 91 |
|
92 | 92 |
int CbcMip::_addRow() { |
93 | 93 |
_prob->addRow(0, 0, 0, -COIN_DBL_MAX, COIN_DBL_MAX); |
94 | 94 |
return _prob->numberRows() - 1; |
95 | 95 |
} |
96 | 96 |
|
97 |
int CbcMip::_addRow(Value l, ExprIterator b, ExprIterator e, Value u) { |
|
98 |
std::vector<int> indexes; |
|
99 |
std::vector<Value> values; |
|
100 |
|
|
101 |
for(ExprIterator it = b; it != e; ++it) { |
|
102 |
indexes.push_back(it->first); |
|
103 |
values.push_back(it->second); |
|
104 |
} |
|
105 |
|
|
106 |
_prob->addRow(values.size(), &indexes.front(), &values.front(), l, u); |
|
107 |
return _prob->numberRows() - 1; |
|
108 |
} |
|
97 | 109 |
|
98 | 110 |
void CbcMip::_eraseCol(int i) { |
99 | 111 |
_prob->deleteColumn(i); |
100 | 112 |
} |
101 | 113 |
|
102 | 114 |
void CbcMip::_eraseRow(int i) { |
103 | 115 |
_prob->deleteRow(i); |
104 | 116 |
} |
105 | 117 |
|
106 | 118 |
void CbcMip::_eraseColId(int i) { |
107 | 119 |
cols.eraseIndex(i); |
108 | 120 |
} |
109 | 121 |
|
110 | 122 |
void CbcMip::_eraseRowId(int i) { |
111 | 123 |
rows.eraseIndex(i); |
112 | 124 |
} |
113 | 125 |
|
114 | 126 |
void CbcMip::_getColName(int c, std::string& name) const { |
115 | 127 |
name = _prob->getColumnName(c); |
116 | 128 |
} |
117 | 129 |
|
118 | 130 |
void CbcMip::_setColName(int c, const std::string& name) { |
119 | 131 |
_prob->setColumnName(c, name.c_str()); |
120 | 132 |
} |
121 | 133 |
|
122 | 134 |
int CbcMip::_colByName(const std::string& name) const { |
123 | 135 |
return _prob->column(name.c_str()); |
124 | 136 |
} |
125 | 137 |
|
126 | 138 |
void CbcMip::_getRowName(int r, std::string& name) const { |
127 | 139 |
name = _prob->getRowName(r); |
128 | 140 |
} |
129 | 141 |
|
130 | 142 |
void CbcMip::_setRowName(int r, const std::string& name) { |
131 | 143 |
_prob->setRowName(r, name.c_str()); |
132 | 144 |
} |
133 | 145 |
|
134 | 146 |
int CbcMip::_rowByName(const std::string& name) const { |
135 | 147 |
return _prob->row(name.c_str()); |
136 | 148 |
} |
137 | 149 |
|
138 | 150 |
void CbcMip::_setRowCoeffs(int i, ExprIterator b, ExprIterator e) { |
139 | 151 |
for (ExprIterator it = b; it != e; ++it) { |
140 | 152 |
_prob->setElement(i, it->first, it->second); |
141 | 153 |
} |
142 | 154 |
} |
143 | 155 |
|
144 | 156 |
void CbcMip::_getRowCoeffs(int ix, InsertIterator b) const { |
145 | 157 |
int length = _prob->numberRows(); |
146 | 158 |
|
147 | 159 |
std::vector<int> indices(length); |
148 | 160 |
std::vector<Value> values(length); |
149 | 161 |
|
150 | 162 |
length = _prob->getRow(ix, &indices[0], &values[0]); |
151 | 163 |
|
152 | 164 |
for (int i = 0; i < length; ++i) { |
153 | 165 |
*b = std::make_pair(indices[i], values[i]); |
154 | 166 |
++b; |
155 | 167 |
} |
156 | 168 |
} |
157 | 169 |
|
158 | 170 |
void CbcMip::_setColCoeffs(int ix, ExprIterator b, ExprIterator e) { |
159 | 171 |
for (ExprIterator it = b; it != e; ++it) { |
160 | 172 |
_prob->setElement(it->first, ix, it->second); |
161 | 173 |
} |
162 | 174 |
} |
163 | 175 |
|
164 | 176 |
void CbcMip::_getColCoeffs(int ix, InsertIterator b) const { |
165 | 177 |
int length = _prob->numberColumns(); |
166 | 178 |
|
167 | 179 |
std::vector<int> indices(length); |
168 | 180 |
std::vector<Value> values(length); |
169 | 181 |
|
170 | 182 |
length = _prob->getColumn(ix, &indices[0], &values[0]); |
171 | 183 |
|
172 | 184 |
for (int i = 0; i < length; ++i) { |
173 | 185 |
*b = std::make_pair(indices[i], values[i]); |
174 | 186 |
++b; |
175 | 187 |
} |
176 | 188 |
} |
177 | 189 |
|
178 | 190 |
void CbcMip::_setCoeff(int ix, int jx, Value value) { |
179 | 191 |
_prob->setElement(ix, jx, value); |
180 | 192 |
} |
181 | 193 |
|
182 | 194 |
CbcMip::Value CbcMip::_getCoeff(int ix, int jx) const { |
183 | 195 |
return _prob->getElement(ix, jx); |
184 | 196 |
} |
185 | 197 |
|
186 | 198 |
|
187 | 199 |
void CbcMip::_setColLowerBound(int i, Value lo) { |
188 | 200 |
LEMON_ASSERT(lo != INF, "Invalid bound"); |
189 | 201 |
_prob->setColumnLower(i, lo == - INF ? - COIN_DBL_MAX : lo); |
190 | 202 |
} |
191 | 203 |
|
192 | 204 |
CbcMip::Value CbcMip::_getColLowerBound(int i) const { |
193 | 205 |
double val = _prob->getColumnLower(i); |
194 | 206 |
return val == - COIN_DBL_MAX ? - INF : val; |
195 | 207 |
} |
196 | 208 |
|
197 | 209 |
void CbcMip::_setColUpperBound(int i, Value up) { |
198 | 210 |
LEMON_ASSERT(up != -INF, "Invalid bound"); |
199 | 211 |
_prob->setColumnUpper(i, up == INF ? COIN_DBL_MAX : up); |
200 | 212 |
} |
201 | 213 |
|
202 | 214 |
CbcMip::Value CbcMip::_getColUpperBound(int i) const { |
203 | 215 |
double val = _prob->getColumnUpper(i); |
204 | 216 |
return val == COIN_DBL_MAX ? INF : val; |
205 | 217 |
} |
206 | 218 |
|
207 | 219 |
void CbcMip::_setRowLowerBound(int i, Value lo) { |
208 | 220 |
LEMON_ASSERT(lo != INF, "Invalid bound"); |
209 | 221 |
_prob->setRowLower(i, lo == - INF ? - COIN_DBL_MAX : lo); |
210 | 222 |
} |
211 | 223 |
|
212 | 224 |
CbcMip::Value CbcMip::_getRowLowerBound(int i) const { |
213 | 225 |
double val = _prob->getRowLower(i); |
214 | 226 |
return val == - COIN_DBL_MAX ? - INF : val; |
215 | 227 |
} |
216 | 228 |
|
217 | 229 |
void CbcMip::_setRowUpperBound(int i, Value up) { |
218 | 230 |
LEMON_ASSERT(up != -INF, "Invalid bound"); |
219 | 231 |
_prob->setRowUpper(i, up == INF ? COIN_DBL_MAX : up); |
220 | 232 |
} |
221 | 233 |
|
222 | 234 |
CbcMip::Value CbcMip::_getRowUpperBound(int i) const { |
223 | 235 |
double val = _prob->getRowUpper(i); |
224 | 236 |
return val == COIN_DBL_MAX ? INF : val; |
225 | 237 |
} |
226 | 238 |
|
227 | 239 |
void CbcMip::_setObjCoeffs(ExprIterator b, ExprIterator e) { |
228 | 240 |
int num = _prob->numberColumns(); |
229 | 241 |
for (int i = 0; i < num; ++i) { |
230 | 242 |
_prob->setColumnObjective(i, 0.0); |
231 | 243 |
} |
232 | 244 |
for (ExprIterator it = b; it != e; ++it) { |
233 | 245 |
_prob->setColumnObjective(it->first, it->second); |
234 | 246 |
} |
235 | 247 |
} |
236 | 248 |
|
237 | 249 |
void CbcMip::_getObjCoeffs(InsertIterator b) const { |
238 | 250 |
int num = _prob->numberColumns(); |
239 | 251 |
for (int i = 0; i < num; ++i) { |
240 | 252 |
Value coef = _prob->getColumnObjective(i); |
241 | 253 |
if (coef != 0.0) { |
242 | 254 |
*b = std::make_pair(i, coef); |
243 | 255 |
++b; |
244 | 256 |
} |
245 | 257 |
} |
246 | 258 |
} |
247 | 259 |
|
248 | 260 |
void CbcMip::_setObjCoeff(int i, Value obj_coef) { |
249 | 261 |
_prob->setColumnObjective(i, obj_coef); |
250 | 262 |
} |
251 | 263 |
|
252 | 264 |
CbcMip::Value CbcMip::_getObjCoeff(int i) const { |
253 | 265 |
return _prob->getColumnObjective(i); |
254 | 266 |
} |
255 | 267 |
|
256 | 268 |
CbcMip::SolveExitStatus CbcMip::_solve() { |
257 | 269 |
|
258 | 270 |
if (_osi_solver) { |
259 | 271 |
delete _osi_solver; |
260 | 272 |
} |
261 | 273 |
#ifdef COIN_HAS_CLP |
262 | 274 |
_osi_solver = new OsiClpSolverInterface(); |
263 | 275 |
#elif COIN_HAS_OSL |
264 | 276 |
_osi_solver = new OsiOslSolverInterface(); |
265 | 277 |
#else |
266 | 278 |
#error Cannot instantiate Osi solver |
267 | 279 |
#endif |
268 | 280 |
|
269 | 281 |
_osi_solver->loadFromCoinModel(*_prob); |
270 | 282 |
|
271 | 283 |
if (_cbc_model) { |
272 | 284 |
delete _cbc_model; |
273 | 285 |
} |
274 | 286 |
_cbc_model= new CbcModel(*_osi_solver); |
275 | 287 |
|
276 | 288 |
_osi_solver->messageHandler()->setLogLevel(_message_level); |
277 | 289 |
_cbc_model->setLogLevel(_message_level); |
278 | 290 |
|
279 | 291 |
_cbc_model->initialSolve(); |
280 | 292 |
_cbc_model->solver()->setHintParam(OsiDoReducePrint, true, OsiHintTry); |
281 | 293 |
|
282 | 294 |
if (!_cbc_model->isInitialSolveAbandoned() && |
283 | 295 |
_cbc_model->isInitialSolveProvenOptimal() && |
284 | 296 |
!_cbc_model->isInitialSolveProvenPrimalInfeasible() && |
285 | 297 |
!_cbc_model->isInitialSolveProvenDualInfeasible()) { |
286 | 298 |
|
287 | 299 |
CglProbing generator1; |
288 | 300 |
generator1.setUsingObjective(true); |
289 | 301 |
generator1.setMaxPass(3); |
290 | 302 |
generator1.setMaxProbe(100); |
291 | 303 |
generator1.setMaxLook(50); |
292 | 304 |
generator1.setRowCuts(3); |
293 | 305 |
_cbc_model->addCutGenerator(&generator1, -1, "Probing"); |
294 | 306 |
|
295 | 307 |
CglGomory generator2; |
296 | 308 |
generator2.setLimit(300); |
297 | 309 |
_cbc_model->addCutGenerator(&generator2, -1, "Gomory"); |
298 | 310 |
|
299 | 311 |
CglKnapsackCover generator3; |
300 | 312 |
_cbc_model->addCutGenerator(&generator3, -1, "Knapsack"); |
301 | 313 |
|
302 | 314 |
CglOddHole generator4; |
303 | 315 |
generator4.setMinimumViolation(0.005); |
304 | 316 |
generator4.setMinimumViolationPer(0.00002); |
305 | 317 |
generator4.setMaximumEntries(200); |
306 | 318 |
_cbc_model->addCutGenerator(&generator4, -1, "OddHole"); |
307 | 319 |
|
308 | 320 |
CglClique generator5; |
309 | 321 |
generator5.setStarCliqueReport(false); |
310 | 322 |
generator5.setRowCliqueReport(false); |
311 | 323 |
_cbc_model->addCutGenerator(&generator5, -1, "Clique"); |
312 | 324 |
|
313 | 325 |
CglMixedIntegerRounding mixedGen; |
314 | 326 |
_cbc_model->addCutGenerator(&mixedGen, -1, "MixedIntegerRounding"); |
315 | 327 |
|
316 | 328 |
CglFlowCover flowGen; |
317 | 329 |
_cbc_model->addCutGenerator(&flowGen, -1, "FlowCover"); |
318 | 330 |
|
319 | 331 |
#ifdef COIN_HAS_CLP |
320 | 332 |
OsiClpSolverInterface* osiclp = |
321 | 333 |
dynamic_cast<OsiClpSolverInterface*>(_cbc_model->solver()); |
322 | 334 |
if (osiclp->getNumRows() < 300 && osiclp->getNumCols() < 500) { |
323 | 335 |
osiclp->setupForRepeatedUse(2, 0); |
324 | 336 |
} |
325 | 337 |
#endif |
326 | 338 |
|
327 | 339 |
CbcRounding heuristic1(*_cbc_model); |
328 | 340 |
heuristic1.setWhen(3); |
329 | 341 |
_cbc_model->addHeuristic(&heuristic1); |
330 | 342 |
|
331 | 343 |
CbcHeuristicLocal heuristic2(*_cbc_model); |
332 | 344 |
heuristic2.setWhen(3); |
333 | 345 |
_cbc_model->addHeuristic(&heuristic2); |
334 | 346 |
|
335 | 347 |
CbcHeuristicGreedyCover heuristic3(*_cbc_model); |
336 | 348 |
heuristic3.setAlgorithm(11); |
337 | 349 |
heuristic3.setWhen(3); |
338 | 350 |
_cbc_model->addHeuristic(&heuristic3); |
339 | 351 |
|
340 | 352 |
CbcHeuristicFPump heuristic4(*_cbc_model); |
341 | 353 |
heuristic4.setWhen(3); |
342 | 354 |
_cbc_model->addHeuristic(&heuristic4); |
343 | 355 |
|
344 | 356 |
CbcHeuristicRINS heuristic5(*_cbc_model); |
345 | 357 |
heuristic5.setWhen(3); |
346 | 358 |
_cbc_model->addHeuristic(&heuristic5); |
347 | 359 |
|
348 | 360 |
if (_cbc_model->getNumCols() < 500) { |
349 | 361 |
_cbc_model->setMaximumCutPassesAtRoot(-100); |
350 | 362 |
} else if (_cbc_model->getNumCols() < 5000) { |
351 | 363 |
_cbc_model->setMaximumCutPassesAtRoot(100); |
352 | 364 |
} else { |
1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
2 | 2 |
* |
3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2009 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
8 | 8 |
* |
9 | 9 |
* Permission to use, modify and distribute this software is granted |
10 | 10 |
* provided that this copyright notice appears in all copies. For |
11 | 11 |
* precise terms see the accompanying LICENSE file. |
12 | 12 |
* |
13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
14 | 14 |
* express or implied, and with no claim as to its suitability for any |
15 | 15 |
* purpose. |
16 | 16 |
* |
17 | 17 |
*/ |
18 | 18 |
|
19 | 19 |
// -*- C++ -*- |
20 | 20 |
#ifndef LEMON_CBC_H |
21 | 21 |
#define LEMON_CBC_H |
22 | 22 |
|
23 | 23 |
///\file |
24 | 24 |
///\brief Header of the LEMON-CBC mip solver interface. |
25 | 25 |
///\ingroup lp_group |
26 | 26 |
|
27 | 27 |
#include <lemon/lp_base.h> |
28 | 28 |
|
29 | 29 |
class CoinModel; |
30 | 30 |
class OsiSolverInterface; |
31 | 31 |
class CbcModel; |
32 | 32 |
|
33 | 33 |
namespace lemon { |
34 | 34 |
|
35 | 35 |
/// \brief Interface for the CBC MIP solver |
36 | 36 |
/// |
37 | 37 |
/// This class implements an interface for the CBC MIP solver. |
38 | 38 |
///\ingroup lp_group |
39 | 39 |
class CbcMip : public MipSolver { |
40 | 40 |
protected: |
41 | 41 |
|
42 | 42 |
CoinModel *_prob; |
43 | 43 |
OsiSolverInterface *_osi_solver; |
44 | 44 |
CbcModel *_cbc_model; |
45 | 45 |
|
46 | 46 |
public: |
47 | 47 |
|
48 | 48 |
/// \e |
49 | 49 |
CbcMip(); |
50 | 50 |
/// \e |
51 | 51 |
CbcMip(const CbcMip&); |
52 | 52 |
/// \e |
53 | 53 |
~CbcMip(); |
54 | 54 |
/// \e |
55 | 55 |
virtual CbcMip* newSolver() const; |
56 | 56 |
/// \e |
57 | 57 |
virtual CbcMip* cloneSolver() const; |
58 | 58 |
|
59 | 59 |
protected: |
60 | 60 |
|
61 | 61 |
virtual const char* _solverName() const; |
62 | 62 |
|
63 | 63 |
virtual int _addCol(); |
64 | 64 |
virtual int _addRow(); |
65 |
virtual int _addRow(Value l, ExprIterator b, ExprIterator e, Value u); |
|
65 | 66 |
|
66 | 67 |
virtual void _eraseCol(int i); |
67 | 68 |
virtual void _eraseRow(int i); |
68 | 69 |
|
69 | 70 |
virtual void _eraseColId(int i); |
70 | 71 |
virtual void _eraseRowId(int i); |
71 | 72 |
|
72 | 73 |
virtual void _getColName(int col, std::string& name) const; |
73 | 74 |
virtual void _setColName(int col, const std::string& name); |
74 | 75 |
virtual int _colByName(const std::string& name) const; |
75 | 76 |
|
76 | 77 |
virtual void _getRowName(int row, std::string& name) const; |
77 | 78 |
virtual void _setRowName(int row, const std::string& name); |
78 | 79 |
virtual int _rowByName(const std::string& name) const; |
79 | 80 |
|
80 | 81 |
virtual void _setRowCoeffs(int i, ExprIterator b, ExprIterator e); |
81 | 82 |
virtual void _getRowCoeffs(int i, InsertIterator b) const; |
82 | 83 |
|
83 | 84 |
virtual void _setColCoeffs(int i, ExprIterator b, ExprIterator e); |
84 | 85 |
virtual void _getColCoeffs(int i, InsertIterator b) const; |
85 | 86 |
|
86 | 87 |
virtual void _setCoeff(int row, int col, Value value); |
87 | 88 |
virtual Value _getCoeff(int row, int col) const; |
88 | 89 |
|
89 | 90 |
virtual void _setColLowerBound(int i, Value value); |
90 | 91 |
virtual Value _getColLowerBound(int i) const; |
91 | 92 |
virtual void _setColUpperBound(int i, Value value); |
92 | 93 |
virtual Value _getColUpperBound(int i) const; |
93 | 94 |
|
94 | 95 |
virtual void _setRowLowerBound(int i, Value value); |
95 | 96 |
virtual Value _getRowLowerBound(int i) const; |
96 | 97 |
virtual void _setRowUpperBound(int i, Value value); |
97 | 98 |
virtual Value _getRowUpperBound(int i) const; |
98 | 99 |
|
99 | 100 |
virtual void _setObjCoeffs(ExprIterator b, ExprIterator e); |
100 | 101 |
virtual void _getObjCoeffs(InsertIterator b) const; |
101 | 102 |
|
102 | 103 |
virtual void _setObjCoeff(int i, Value obj_coef); |
103 | 104 |
virtual Value _getObjCoeff(int i) const; |
104 | 105 |
|
105 | 106 |
virtual void _setSense(Sense sense); |
106 | 107 |
virtual Sense _getSense() const; |
107 | 108 |
|
108 | 109 |
virtual ColTypes _getColType(int col) const; |
109 | 110 |
virtual void _setColType(int col, ColTypes col_type); |
110 | 111 |
|
111 | 112 |
virtual SolveExitStatus _solve(); |
112 | 113 |
virtual ProblemType _getType() const; |
113 | 114 |
virtual Value _getSol(int i) const; |
114 | 115 |
virtual Value _getSolValue() const; |
115 | 116 |
|
116 | 117 |
virtual void _clear(); |
117 | 118 |
|
118 | 119 |
virtual void _messageLevel(MessageLevel level); |
119 | 120 |
void _applyMessageLevel(); |
120 | 121 |
|
121 | 122 |
int _message_level; |
122 | 123 |
|
123 | 124 |
|
124 | 125 |
|
125 | 126 |
}; |
126 | 127 |
|
127 | 128 |
} |
128 | 129 |
|
129 | 130 |
#endif |
1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
2 | 2 |
* |
3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2008 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
8 | 8 |
* |
9 | 9 |
* Permission to use, modify and distribute this software is granted |
10 | 10 |
* provided that this copyright notice appears in all copies. For |
11 | 11 |
* precise terms see the accompanying LICENSE file. |
12 | 12 |
* |
13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
14 | 14 |
* express or implied, and with no claim as to its suitability for any |
15 | 15 |
* purpose. |
16 | 16 |
* |
17 | 17 |
*/ |
18 | 18 |
|
19 | 19 |
#include <lemon/clp.h> |
20 | 20 |
#include <coin/ClpSimplex.hpp> |
21 | 21 |
|
22 | 22 |
namespace lemon { |
23 | 23 |
|
24 | 24 |
ClpLp::ClpLp() { |
25 | 25 |
_prob = new ClpSimplex(); |
26 | 26 |
_init_temporals(); |
27 | 27 |
messageLevel(MESSAGE_NOTHING); |
28 | 28 |
} |
29 | 29 |
|
30 | 30 |
ClpLp::ClpLp(const ClpLp& other) { |
31 | 31 |
_prob = new ClpSimplex(*other._prob); |
32 | 32 |
rows = other.rows; |
33 | 33 |
cols = other.cols; |
34 | 34 |
_init_temporals(); |
35 | 35 |
messageLevel(MESSAGE_NOTHING); |
36 | 36 |
} |
37 | 37 |
|
38 | 38 |
ClpLp::~ClpLp() { |
39 | 39 |
delete _prob; |
40 | 40 |
_clear_temporals(); |
41 | 41 |
} |
42 | 42 |
|
43 | 43 |
void ClpLp::_init_temporals() { |
44 | 44 |
_primal_ray = 0; |
45 | 45 |
_dual_ray = 0; |
46 | 46 |
} |
47 | 47 |
|
48 | 48 |
void ClpLp::_clear_temporals() { |
49 | 49 |
if (_primal_ray) { |
50 | 50 |
delete[] _primal_ray; |
51 | 51 |
_primal_ray = 0; |
52 | 52 |
} |
53 | 53 |
if (_dual_ray) { |
54 | 54 |
delete[] _dual_ray; |
55 | 55 |
_dual_ray = 0; |
56 | 56 |
} |
57 | 57 |
} |
58 | 58 |
|
59 | 59 |
ClpLp* ClpLp::newSolver() const { |
60 | 60 |
ClpLp* newlp = new ClpLp; |
61 | 61 |
return newlp; |
62 | 62 |
} |
63 | 63 |
|
64 | 64 |
ClpLp* ClpLp::cloneSolver() const { |
65 | 65 |
ClpLp* copylp = new ClpLp(*this); |
66 | 66 |
return copylp; |
67 | 67 |
} |
68 | 68 |
|
69 | 69 |
const char* ClpLp::_solverName() const { return "ClpLp"; } |
70 | 70 |
|
71 | 71 |
int ClpLp::_addCol() { |
72 | 72 |
_prob->addColumn(0, 0, 0, -COIN_DBL_MAX, COIN_DBL_MAX, 0.0); |
73 | 73 |
return _prob->numberColumns() - 1; |
74 | 74 |
} |
75 | 75 |
|
76 | 76 |
int ClpLp::_addRow() { |
77 | 77 |
_prob->addRow(0, 0, 0, -COIN_DBL_MAX, COIN_DBL_MAX); |
78 | 78 |
return _prob->numberRows() - 1; |
79 | 79 |
} |
80 | 80 |
|
81 |
int ClpLp::_addRow(Value l, ExprIterator b, ExprIterator e, Value u) { |
|
82 |
std::vector<int> indexes; |
|
83 |
std::vector<Value> values; |
|
84 |
|
|
85 |
for(ExprIterator it = b; it != e; ++it) { |
|
86 |
indexes.push_back(it->first); |
|
87 |
values.push_back(it->second); |
|
88 |
} |
|
89 |
|
|
90 |
_prob->addRow(values.size(), &indexes.front(), &values.front(), l, u); |
|
91 |
return _prob->numberRows() - 1; |
|
92 |
} |
|
93 |
|
|
81 | 94 |
|
82 | 95 |
void ClpLp::_eraseCol(int c) { |
83 | 96 |
_col_names_ref.erase(_prob->getColumnName(c)); |
84 | 97 |
_prob->deleteColumns(1, &c); |
85 | 98 |
} |
86 | 99 |
|
87 | 100 |
void ClpLp::_eraseRow(int r) { |
88 | 101 |
_row_names_ref.erase(_prob->getRowName(r)); |
89 | 102 |
_prob->deleteRows(1, &r); |
90 | 103 |
} |
91 | 104 |
|
92 | 105 |
void ClpLp::_eraseColId(int i) { |
93 | 106 |
cols.eraseIndex(i); |
94 | 107 |
cols.shiftIndices(i); |
95 | 108 |
} |
96 | 109 |
|
97 | 110 |
void ClpLp::_eraseRowId(int i) { |
98 | 111 |
rows.eraseIndex(i); |
99 | 112 |
rows.shiftIndices(i); |
100 | 113 |
} |
101 | 114 |
|
102 | 115 |
void ClpLp::_getColName(int c, std::string& name) const { |
103 | 116 |
name = _prob->getColumnName(c); |
104 | 117 |
} |
105 | 118 |
|
106 | 119 |
void ClpLp::_setColName(int c, const std::string& name) { |
107 | 120 |
_prob->setColumnName(c, const_cast<std::string&>(name)); |
108 | 121 |
_col_names_ref[name] = c; |
109 | 122 |
} |
110 | 123 |
|
111 | 124 |
int ClpLp::_colByName(const std::string& name) const { |
112 | 125 |
std::map<std::string, int>::const_iterator it = _col_names_ref.find(name); |
113 | 126 |
return it != _col_names_ref.end() ? it->second : -1; |
114 | 127 |
} |
115 | 128 |
|
116 | 129 |
void ClpLp::_getRowName(int r, std::string& name) const { |
117 | 130 |
name = _prob->getRowName(r); |
118 | 131 |
} |
119 | 132 |
|
120 | 133 |
void ClpLp::_setRowName(int r, const std::string& name) { |
121 | 134 |
_prob->setRowName(r, const_cast<std::string&>(name)); |
122 | 135 |
_row_names_ref[name] = r; |
123 | 136 |
} |
124 | 137 |
|
125 | 138 |
int ClpLp::_rowByName(const std::string& name) const { |
126 | 139 |
std::map<std::string, int>::const_iterator it = _row_names_ref.find(name); |
127 | 140 |
return it != _row_names_ref.end() ? it->second : -1; |
128 | 141 |
} |
129 | 142 |
|
130 | 143 |
|
131 | 144 |
void ClpLp::_setRowCoeffs(int ix, ExprIterator b, ExprIterator e) { |
132 | 145 |
std::map<int, Value> coeffs; |
133 | 146 |
|
134 | 147 |
int n = _prob->clpMatrix()->getNumCols(); |
135 | 148 |
|
136 | 149 |
const int* indices = _prob->clpMatrix()->getIndices(); |
137 | 150 |
const double* elements = _prob->clpMatrix()->getElements(); |
138 | 151 |
|
139 | 152 |
for (int i = 0; i < n; ++i) { |
140 | 153 |
CoinBigIndex begin = _prob->clpMatrix()->getVectorStarts()[i]; |
141 | 154 |
CoinBigIndex end = begin + _prob->clpMatrix()->getVectorLengths()[i]; |
142 | 155 |
|
143 | 156 |
const int* it = std::lower_bound(indices + begin, indices + end, ix); |
144 | 157 |
if (it != indices + end && *it == ix && elements[it - indices] != 0.0) { |
145 | 158 |
coeffs[i] = 0.0; |
146 | 159 |
} |
147 | 160 |
} |
148 | 161 |
|
149 | 162 |
for (ExprIterator it = b; it != e; ++it) { |
150 | 163 |
coeffs[it->first] = it->second; |
151 | 164 |
} |
152 | 165 |
|
153 | 166 |
for (std::map<int, Value>::iterator it = coeffs.begin(); |
154 | 167 |
it != coeffs.end(); ++it) { |
155 | 168 |
_prob->modifyCoefficient(ix, it->first, it->second); |
156 | 169 |
} |
157 | 170 |
} |
158 | 171 |
|
159 | 172 |
void ClpLp::_getRowCoeffs(int ix, InsertIterator b) const { |
160 | 173 |
int n = _prob->clpMatrix()->getNumCols(); |
161 | 174 |
|
162 | 175 |
const int* indices = _prob->clpMatrix()->getIndices(); |
163 | 176 |
const double* elements = _prob->clpMatrix()->getElements(); |
164 | 177 |
|
165 | 178 |
for (int i = 0; i < n; ++i) { |
166 | 179 |
CoinBigIndex begin = _prob->clpMatrix()->getVectorStarts()[i]; |
167 | 180 |
CoinBigIndex end = begin + _prob->clpMatrix()->getVectorLengths()[i]; |
168 | 181 |
|
169 | 182 |
const int* it = std::lower_bound(indices + begin, indices + end, ix); |
170 | 183 |
if (it != indices + end && *it == ix) { |
171 | 184 |
*b = std::make_pair(i, elements[it - indices]); |
172 | 185 |
} |
173 | 186 |
} |
174 | 187 |
} |
175 | 188 |
|
176 | 189 |
void ClpLp::_setColCoeffs(int ix, ExprIterator b, ExprIterator e) { |
177 | 190 |
std::map<int, Value> coeffs; |
178 | 191 |
|
179 | 192 |
CoinBigIndex begin = _prob->clpMatrix()->getVectorStarts()[ix]; |
180 | 193 |
CoinBigIndex end = begin + _prob->clpMatrix()->getVectorLengths()[ix]; |
181 | 194 |
|
182 | 195 |
const int* indices = _prob->clpMatrix()->getIndices(); |
183 | 196 |
const double* elements = _prob->clpMatrix()->getElements(); |
184 | 197 |
|
185 | 198 |
for (CoinBigIndex i = begin; i != end; ++i) { |
186 | 199 |
if (elements[i] != 0.0) { |
187 | 200 |
coeffs[indices[i]] = 0.0; |
188 | 201 |
} |
189 | 202 |
} |
190 | 203 |
for (ExprIterator it = b; it != e; ++it) { |
191 | 204 |
coeffs[it->first] = it->second; |
192 | 205 |
} |
193 | 206 |
for (std::map<int, Value>::iterator it = coeffs.begin(); |
194 | 207 |
it != coeffs.end(); ++it) { |
195 | 208 |
_prob->modifyCoefficient(it->first, ix, it->second); |
196 | 209 |
} |
197 | 210 |
} |
198 | 211 |
|
199 | 212 |
void ClpLp::_getColCoeffs(int ix, InsertIterator b) const { |
200 | 213 |
CoinBigIndex begin = _prob->clpMatrix()->getVectorStarts()[ix]; |
201 | 214 |
CoinBigIndex end = begin + _prob->clpMatrix()->getVectorLengths()[ix]; |
202 | 215 |
|
203 | 216 |
const int* indices = _prob->clpMatrix()->getIndices(); |
204 | 217 |
const double* elements = _prob->clpMatrix()->getElements(); |
205 | 218 |
|
206 | 219 |
for (CoinBigIndex i = begin; i != end; ++i) { |
207 | 220 |
*b = std::make_pair(indices[i], elements[i]); |
208 | 221 |
++b; |
209 | 222 |
} |
210 | 223 |
} |
211 | 224 |
|
212 | 225 |
void ClpLp::_setCoeff(int ix, int jx, Value value) { |
213 | 226 |
_prob->modifyCoefficient(ix, jx, value); |
214 | 227 |
} |
215 | 228 |
|
216 | 229 |
ClpLp::Value ClpLp::_getCoeff(int ix, int jx) const { |
217 | 230 |
CoinBigIndex begin = _prob->clpMatrix()->getVectorStarts()[ix]; |
218 | 231 |
CoinBigIndex end = begin + _prob->clpMatrix()->getVectorLengths()[ix]; |
219 | 232 |
|
220 | 233 |
const int* indices = _prob->clpMatrix()->getIndices(); |
221 | 234 |
const double* elements = _prob->clpMatrix()->getElements(); |
222 | 235 |
|
223 | 236 |
const int* it = std::lower_bound(indices + begin, indices + end, jx); |
224 | 237 |
if (it != indices + end && *it == jx) { |
225 | 238 |
return elements[it - indices]; |
226 | 239 |
} else { |
227 | 240 |
return 0.0; |
228 | 241 |
} |
229 | 242 |
} |
230 | 243 |
|
231 | 244 |
void ClpLp::_setColLowerBound(int i, Value lo) { |
232 | 245 |
_prob->setColumnLower(i, lo == - INF ? - COIN_DBL_MAX : lo); |
233 | 246 |
} |
234 | 247 |
|
235 | 248 |
ClpLp::Value ClpLp::_getColLowerBound(int i) const { |
236 | 249 |
double val = _prob->getColLower()[i]; |
237 | 250 |
return val == - COIN_DBL_MAX ? - INF : val; |
238 | 251 |
} |
239 | 252 |
|
240 | 253 |
void ClpLp::_setColUpperBound(int i, Value up) { |
241 | 254 |
_prob->setColumnUpper(i, up == INF ? COIN_DBL_MAX : up); |
242 | 255 |
} |
243 | 256 |
|
244 | 257 |
ClpLp::Value ClpLp::_getColUpperBound(int i) const { |
245 | 258 |
double val = _prob->getColUpper()[i]; |
246 | 259 |
return val == COIN_DBL_MAX ? INF : val; |
247 | 260 |
} |
248 | 261 |
|
249 | 262 |
void ClpLp::_setRowLowerBound(int i, Value lo) { |
250 | 263 |
_prob->setRowLower(i, lo == - INF ? - COIN_DBL_MAX : lo); |
251 | 264 |
} |
252 | 265 |
|
253 | 266 |
ClpLp::Value ClpLp::_getRowLowerBound(int i) const { |
254 | 267 |
double val = _prob->getRowLower()[i]; |
255 | 268 |
return val == - COIN_DBL_MAX ? - INF : val; |
256 | 269 |
} |
257 | 270 |
|
258 | 271 |
void ClpLp::_setRowUpperBound(int i, Value up) { |
259 | 272 |
_prob->setRowUpper(i, up == INF ? COIN_DBL_MAX : up); |
260 | 273 |
} |
261 | 274 |
|
262 | 275 |
ClpLp::Value ClpLp::_getRowUpperBound(int i) const { |
263 | 276 |
double val = _prob->getRowUpper()[i]; |
264 | 277 |
return val == COIN_DBL_MAX ? INF : val; |
265 | 278 |
} |
266 | 279 |
|
267 | 280 |
void ClpLp::_setObjCoeffs(ExprIterator b, ExprIterator e) { |
268 | 281 |
int num = _prob->clpMatrix()->getNumCols(); |
269 | 282 |
for (int i = 0; i < num; ++i) { |
270 | 283 |
_prob->setObjectiveCoefficient(i, 0.0); |
271 | 284 |
} |
272 | 285 |
for (ExprIterator it = b; it != e; ++it) { |
273 | 286 |
_prob->setObjectiveCoefficient(it->first, it->second); |
274 | 287 |
} |
275 | 288 |
} |
276 | 289 |
|
277 | 290 |
void ClpLp::_getObjCoeffs(InsertIterator b) const { |
278 | 291 |
int num = _prob->clpMatrix()->getNumCols(); |
279 | 292 |
for (int i = 0; i < num; ++i) { |
280 | 293 |
Value coef = _prob->getObjCoefficients()[i]; |
281 | 294 |
if (coef != 0.0) { |
282 | 295 |
*b = std::make_pair(i, coef); |
283 | 296 |
++b; |
284 | 297 |
} |
285 | 298 |
} |
286 | 299 |
} |
287 | 300 |
|
288 | 301 |
void ClpLp::_setObjCoeff(int i, Value obj_coef) { |
289 | 302 |
_prob->setObjectiveCoefficient(i, obj_coef); |
290 | 303 |
} |
291 | 304 |
|
292 | 305 |
ClpLp::Value ClpLp::_getObjCoeff(int i) const { |
293 | 306 |
return _prob->getObjCoefficients()[i]; |
294 | 307 |
} |
295 | 308 |
|
296 | 309 |
ClpLp::SolveExitStatus ClpLp::_solve() { |
297 | 310 |
return _prob->primal() >= 0 ? SOLVED : UNSOLVED; |
298 | 311 |
} |
299 | 312 |
|
300 | 313 |
ClpLp::SolveExitStatus ClpLp::solvePrimal() { |
301 | 314 |
return _prob->primal() >= 0 ? SOLVED : UNSOLVED; |
302 | 315 |
} |
303 | 316 |
|
304 | 317 |
ClpLp::SolveExitStatus ClpLp::solveDual() { |
305 | 318 |
return _prob->dual() >= 0 ? SOLVED : UNSOLVED; |
306 | 319 |
} |
307 | 320 |
|
308 | 321 |
ClpLp::SolveExitStatus ClpLp::solveBarrier() { |
309 | 322 |
return _prob->barrier() >= 0 ? SOLVED : UNSOLVED; |
310 | 323 |
} |
311 | 324 |
|
312 | 325 |
ClpLp::Value ClpLp::_getPrimal(int i) const { |
313 | 326 |
return _prob->primalColumnSolution()[i]; |
314 | 327 |
} |
315 | 328 |
ClpLp::Value ClpLp::_getPrimalValue() const { |
316 | 329 |
return _prob->objectiveValue(); |
317 | 330 |
} |
318 | 331 |
|
319 | 332 |
ClpLp::Value ClpLp::_getDual(int i) const { |
320 | 333 |
return _prob->dualRowSolution()[i]; |
321 | 334 |
} |
322 | 335 |
|
323 | 336 |
ClpLp::Value ClpLp::_getPrimalRay(int i) const { |
324 | 337 |
if (!_primal_ray) { |
325 | 338 |
_primal_ray = _prob->unboundedRay(); |
326 | 339 |
LEMON_ASSERT(_primal_ray != 0, "Primal ray is not provided"); |
327 | 340 |
} |
328 | 341 |
return _primal_ray[i]; |
329 | 342 |
} |
330 | 343 |
|
331 | 344 |
ClpLp::Value ClpLp::_getDualRay(int i) const { |
332 | 345 |
if (!_dual_ray) { |
333 | 346 |
_dual_ray = _prob->infeasibilityRay(); |
334 | 347 |
LEMON_ASSERT(_dual_ray != 0, "Dual ray is not provided"); |
335 | 348 |
} |
336 | 349 |
return _dual_ray[i]; |
1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
2 | 2 |
* |
3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2008 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
8 | 8 |
* |
9 | 9 |
* Permission to use, modify and distribute this software is granted |
10 | 10 |
* provided that this copyright notice appears in all copies. For |
11 | 11 |
* precise terms see the accompanying LICENSE file. |
12 | 12 |
* |
13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
14 | 14 |
* express or implied, and with no claim as to its suitability for any |
15 | 15 |
* purpose. |
16 | 16 |
* |
17 | 17 |
*/ |
18 | 18 |
|
19 | 19 |
#ifndef LEMON_CLP_H |
20 | 20 |
#define LEMON_CLP_H |
21 | 21 |
|
22 | 22 |
///\file |
23 | 23 |
///\brief Header of the LEMON-CLP lp solver interface. |
24 | 24 |
|
25 | 25 |
#include <vector> |
26 | 26 |
#include <string> |
27 | 27 |
|
28 | 28 |
#include <lemon/lp_base.h> |
29 | 29 |
|
30 | 30 |
class ClpSimplex; |
31 | 31 |
|
32 | 32 |
namespace lemon { |
33 | 33 |
|
34 | 34 |
/// \ingroup lp_group |
35 | 35 |
/// |
36 | 36 |
/// \brief Interface for the CLP solver |
37 | 37 |
/// |
38 | 38 |
/// This class implements an interface for the Clp LP solver. The |
39 | 39 |
/// Clp library is an object oriented lp solver library developed at |
40 | 40 |
/// the IBM. The CLP is part of the COIN-OR package and it can be |
41 | 41 |
/// used with Common Public License. |
42 | 42 |
class ClpLp : public LpSolver { |
43 | 43 |
protected: |
44 | 44 |
|
45 | 45 |
ClpSimplex* _prob; |
46 | 46 |
|
47 | 47 |
std::map<std::string, int> _col_names_ref; |
48 | 48 |
std::map<std::string, int> _row_names_ref; |
49 | 49 |
|
50 | 50 |
public: |
51 | 51 |
|
52 | 52 |
/// \e |
53 | 53 |
ClpLp(); |
54 | 54 |
/// \e |
55 | 55 |
ClpLp(const ClpLp&); |
56 | 56 |
/// \e |
57 | 57 |
~ClpLp(); |
58 | 58 |
|
59 | 59 |
/// \e |
60 | 60 |
virtual ClpLp* newSolver() const; |
61 | 61 |
/// \e |
62 | 62 |
virtual ClpLp* cloneSolver() const; |
63 | 63 |
|
64 | 64 |
protected: |
65 | 65 |
|
66 | 66 |
mutable double* _primal_ray; |
67 | 67 |
mutable double* _dual_ray; |
68 | 68 |
|
69 | 69 |
void _init_temporals(); |
70 | 70 |
void _clear_temporals(); |
71 | 71 |
|
72 | 72 |
protected: |
73 | 73 |
|
74 | 74 |
virtual const char* _solverName() const; |
75 | 75 |
|
76 | 76 |
virtual int _addCol(); |
77 | 77 |
virtual int _addRow(); |
78 |
virtual int _addRow(Value l, ExprIterator b, ExprIterator e, Value u); |
|
78 | 79 |
|
79 | 80 |
virtual void _eraseCol(int i); |
80 | 81 |
virtual void _eraseRow(int i); |
81 | 82 |
|
82 | 83 |
virtual void _eraseColId(int i); |
83 | 84 |
virtual void _eraseRowId(int i); |
84 | 85 |
|
85 | 86 |
virtual void _getColName(int col, std::string& name) const; |
86 | 87 |
virtual void _setColName(int col, const std::string& name); |
87 | 88 |
virtual int _colByName(const std::string& name) const; |
88 | 89 |
|
89 | 90 |
virtual void _getRowName(int row, std::string& name) const; |
90 | 91 |
virtual void _setRowName(int row, const std::string& name); |
91 | 92 |
virtual int _rowByName(const std::string& name) const; |
92 | 93 |
|
93 | 94 |
virtual void _setRowCoeffs(int i, ExprIterator b, ExprIterator e); |
94 | 95 |
virtual void _getRowCoeffs(int i, InsertIterator b) const; |
95 | 96 |
|
96 | 97 |
virtual void _setColCoeffs(int i, ExprIterator b, ExprIterator e); |
97 | 98 |
virtual void _getColCoeffs(int i, InsertIterator b) const; |
98 | 99 |
|
99 | 100 |
virtual void _setCoeff(int row, int col, Value value); |
100 | 101 |
virtual Value _getCoeff(int row, int col) const; |
101 | 102 |
|
102 | 103 |
virtual void _setColLowerBound(int i, Value value); |
103 | 104 |
virtual Value _getColLowerBound(int i) const; |
104 | 105 |
virtual void _setColUpperBound(int i, Value value); |
105 | 106 |
virtual Value _getColUpperBound(int i) const; |
106 | 107 |
|
107 | 108 |
virtual void _setRowLowerBound(int i, Value value); |
108 | 109 |
virtual Value _getRowLowerBound(int i) const; |
109 | 110 |
virtual void _setRowUpperBound(int i, Value value); |
110 | 111 |
virtual Value _getRowUpperBound(int i) const; |
111 | 112 |
|
112 | 113 |
virtual void _setObjCoeffs(ExprIterator, ExprIterator); |
113 | 114 |
virtual void _getObjCoeffs(InsertIterator) const; |
114 | 115 |
|
115 | 116 |
virtual void _setObjCoeff(int i, Value obj_coef); |
116 | 117 |
virtual Value _getObjCoeff(int i) const; |
117 | 118 |
|
118 | 119 |
virtual void _setSense(Sense sense); |
119 | 120 |
virtual Sense _getSense() const; |
120 | 121 |
|
121 | 122 |
virtual SolveExitStatus _solve(); |
122 | 123 |
|
123 | 124 |
virtual Value _getPrimal(int i) const; |
124 | 125 |
virtual Value _getDual(int i) const; |
125 | 126 |
|
126 | 127 |
virtual Value _getPrimalValue() const; |
127 | 128 |
|
128 | 129 |
virtual Value _getPrimalRay(int i) const; |
129 | 130 |
virtual Value _getDualRay(int i) const; |
130 | 131 |
|
131 | 132 |
virtual VarStatus _getColStatus(int i) const; |
132 | 133 |
virtual VarStatus _getRowStatus(int i) const; |
133 | 134 |
|
134 | 135 |
virtual ProblemType _getPrimalType() const; |
135 | 136 |
virtual ProblemType _getDualType() const; |
136 | 137 |
|
137 | 138 |
virtual void _clear(); |
138 | 139 |
|
139 | 140 |
virtual void _messageLevel(MessageLevel); |
140 | 141 |
|
141 | 142 |
public: |
142 | 143 |
|
143 | 144 |
///Solves LP with primal simplex method. |
144 | 145 |
SolveExitStatus solvePrimal(); |
145 | 146 |
|
146 | 147 |
///Solves LP with dual simplex method. |
147 | 148 |
SolveExitStatus solveDual(); |
148 | 149 |
|
149 | 150 |
///Solves LP with barrier method. |
150 | 151 |
SolveExitStatus solveBarrier(); |
151 | 152 |
|
152 | 153 |
///Returns the constraint identifier understood by CLP. |
153 | 154 |
int clpRow(Row r) const { return rows(id(r)); } |
154 | 155 |
|
155 | 156 |
///Returns the variable identifier understood by CLP. |
156 | 157 |
int clpCol(Col c) const { return cols(id(c)); } |
157 | 158 |
|
158 | 159 |
}; |
159 | 160 |
|
160 | 161 |
} //END OF NAMESPACE LEMON |
161 | 162 |
|
162 | 163 |
#endif //LEMON_CLP_H |
163 | 164 |
1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
2 | 2 |
* |
3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2009 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
8 | 8 |
* |
9 | 9 |
* Permission to use, modify and distribute this software is granted |
10 | 10 |
* provided that this copyright notice appears in all copies. For |
11 | 11 |
* precise terms see the accompanying LICENSE file. |
12 | 12 |
* |
13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
14 | 14 |
* express or implied, and with no claim as to its suitability for any |
15 | 15 |
* purpose. |
16 | 16 |
* |
17 | 17 |
*/ |
18 | 18 |
|
19 | 19 |
#ifndef LEMON_CONCEPTS_DIGRAPH_H |
20 | 20 |
#define LEMON_CONCEPTS_DIGRAPH_H |
21 | 21 |
|
22 | 22 |
///\ingroup graph_concepts |
23 | 23 |
///\file |
24 | 24 |
///\brief The concept of directed graphs. |
25 | 25 |
|
26 | 26 |
#include <lemon/core.h> |
27 | 27 |
#include <lemon/concepts/maps.h> |
28 | 28 |
#include <lemon/concept_check.h> |
29 | 29 |
#include <lemon/concepts/graph_components.h> |
30 | 30 |
|
31 | 31 |
namespace lemon { |
32 | 32 |
namespace concepts { |
33 | 33 |
|
34 | 34 |
/// \ingroup graph_concepts |
35 | 35 |
/// |
36 | 36 |
/// \brief Class describing the concept of directed graphs. |
37 | 37 |
/// |
38 |
/// This class describes the \ref concept "concept" of the |
|
39 |
/// immutable directed digraphs. |
|
38 |
/// This class describes the common interface of all directed |
|
39 |
/// graphs (digraphs). |
|
40 | 40 |
/// |
41 |
/// Note that actual digraph implementation like @ref ListDigraph or |
|
42 |
/// @ref SmartDigraph may have several additional functionality. |
|
41 |
/// Like all concept classes, it only provides an interface |
|
42 |
/// without any sensible implementation. So any general algorithm for |
|
43 |
/// directed graphs should compile with this class, but it will not |
|
44 |
/// run properly, of course. |
|
45 |
/// An actual digraph implementation like \ref ListDigraph or |
|
46 |
/// \ref SmartDigraph may have additional functionality. |
|
43 | 47 |
/// |
44 |
/// \sa |
|
48 |
/// \sa Graph |
|
45 | 49 |
class Digraph { |
46 | 50 |
private: |
47 |
/// |
|
51 |
/// Diraphs are \e not copy constructible. Use DigraphCopy instead. |
|
52 |
Digraph(const Digraph &) {} |
|
53 |
/// \brief Assignment of a digraph to another one is \e not allowed. |
|
54 |
/// Use DigraphCopy instead. |
|
55 |
void operator=(const Digraph &) {} |
|
48 | 56 |
|
49 |
///Digraphs are \e not copy constructible. Use DigraphCopy() instead. |
|
50 |
/// |
|
51 |
Digraph(const Digraph &) {}; |
|
52 |
///\brief Assignment of \ref Digraph "Digraph"s to another ones are |
|
53 |
|
|
57 |
public: |
|
58 |
/// Default constructor. |
|
59 |
Digraph() { } |
|
54 | 60 |
|
55 |
///Assignment of \ref Digraph "Digraph"s to another ones are |
|
56 |
///\e not allowed. Use DigraphCopy() instead. |
|
57 |
|
|
58 |
void operator=(const Digraph &) {} |
|
59 |
public: |
|
60 |
///\e |
|
61 |
|
|
62 |
/// Defalult constructor. |
|
63 |
|
|
64 |
/// Defalult constructor. |
|
65 |
/// |
|
66 |
Digraph() { } |
|
67 |
/// |
|
61 |
/// The node type of the digraph |
|
68 | 62 |
|
69 | 63 |
/// This class identifies a node of the digraph. It also serves |
70 | 64 |
/// as a base class of the node iterators, |
71 |
/// thus they |
|
65 |
/// thus they convert to this type. |
|
72 | 66 |
class Node { |
73 | 67 |
public: |
74 | 68 |
/// Default constructor |
75 | 69 |
|
76 |
/// @warning The default constructor sets the iterator |
|
77 |
/// to an undefined value. |
|
70 |
/// Default constructor. |
|
71 |
/// \warning It sets the object to an undefined value. |
|
78 | 72 |
Node() { } |
79 | 73 |
/// Copy constructor. |
80 | 74 |
|
81 | 75 |
/// Copy constructor. |
82 | 76 |
/// |
83 | 77 |
Node(const Node&) { } |
84 | 78 |
|
85 |
/// Invalid constructor \& conversion. |
|
79 |
/// %Invalid constructor \& conversion. |
|
86 | 80 |
|
87 |
/// |
|
81 |
/// Initializes the object to be invalid. |
|
88 | 82 |
/// \sa Invalid for more details. |
89 | 83 |
Node(Invalid) { } |
90 | 84 |
/// Equality operator |
91 | 85 |
|
86 |
/// Equality operator. |
|
87 |
/// |
|
92 | 88 |
/// Two iterators are equal if and only if they point to the |
93 |
/// same object or both are |
|
89 |
/// same object or both are \c INVALID. |
|
94 | 90 |
bool operator==(Node) const { return true; } |
95 | 91 |
|
96 | 92 |
/// Inequality operator |
97 | 93 |
|
98 |
/// \sa operator==(Node n) |
|
99 |
/// |
|
94 |
/// Inequality operator. |
|
100 | 95 |
bool operator!=(Node) const { return true; } |
101 | 96 |
|
102 | 97 |
/// Artificial ordering operator. |
103 | 98 |
|
104 |
/// To allow the use of digraph descriptors as key type in std::map or |
|
105 |
/// similar associative container we require this. |
|
99 |
/// Artificial ordering operator. |
|
106 | 100 |
/// |
107 |
/// \note This operator only have to define some strict ordering of |
|
108 |
/// the items; this order has nothing to do with the iteration |
|
109 |
/// ordering of |
|
101 |
/// \note This operator only has to define some strict ordering of |
|
102 |
/// the nodes; this order has nothing to do with the iteration |
|
103 |
/// ordering of the nodes. |
|
110 | 104 |
bool operator<(Node) const { return false; } |
111 |
|
|
112 | 105 |
}; |
113 | 106 |
|
114 |
/// |
|
107 |
/// Iterator class for the nodes. |
|
115 | 108 |
|
116 |
/// This iterator goes through each node. |
|
109 |
/// This iterator goes through each node of the digraph. |
|
117 | 110 |
/// Its usage is quite simple, for example you can count the number |
118 |
/// of nodes in digraph \c g of type \c Digraph like this: |
|
111 |
/// of nodes in a digraph \c g of type \c %Digraph like this: |
|
119 | 112 |
///\code |
120 | 113 |
/// int count=0; |
121 | 114 |
/// for (Digraph::NodeIt n(g); n!=INVALID; ++n) ++count; |
122 | 115 |
///\endcode |
123 | 116 |
class NodeIt : public Node { |
124 | 117 |
public: |
125 | 118 |
/// Default constructor |
126 | 119 |
|
127 |
/// @warning The default constructor sets the iterator |
|
128 |
/// to an undefined value. |
|
120 |
/// Default constructor. |
|
121 |
/// \warning It sets the iterator to an undefined value. |
|
129 | 122 |
NodeIt() { } |
130 | 123 |
/// Copy constructor. |
131 | 124 |
|
132 | 125 |
/// Copy constructor. |
133 | 126 |
/// |
134 | 127 |
NodeIt(const NodeIt& n) : Node(n) { } |
135 |
/// Invalid constructor \& conversion. |
|
128 |
/// %Invalid constructor \& conversion. |
|
136 | 129 |
|
137 |
/// |
|
130 |
/// Initializes the iterator to be invalid. |
|
138 | 131 |
/// \sa Invalid for more details. |
139 | 132 |
NodeIt(Invalid) { } |
140 | 133 |
/// Sets the iterator to the first node. |
141 | 134 |
|
142 |
/// Sets the iterator to the first node of |
|
135 |
/// Sets the iterator to the first node of the given digraph. |
|
143 | 136 |
/// |
144 |
NodeIt(const Digraph&) { } |
|
145 |
/// Node -> NodeIt conversion. |
|
137 |
explicit NodeIt(const Digraph&) { } |
|
138 |
/// Sets the iterator to the given node. |
|
146 | 139 |
|
147 |
/// Sets the iterator to the node of \c the digraph pointed by |
|
148 |
/// the trivial iterator. |
|
149 |
/// This feature necessitates that each time we |
|
150 |
/// iterate the arc-set, the iteration order is the same. |
|
140 |
/// Sets the iterator to the given node of the given digraph. |
|
141 |
/// |
|
151 | 142 |
NodeIt(const Digraph&, const Node&) { } |
152 | 143 |
/// Next node. |
153 | 144 |
|
154 | 145 |
/// Assign the iterator to the next node. |
155 | 146 |
/// |
156 | 147 |
NodeIt& operator++() { return *this; } |
157 | 148 |
}; |
158 | 149 |
|
159 | 150 |
|
160 |
/// |
|
151 |
/// The arc type of the digraph |
|
161 | 152 |
|
162 | 153 |
/// This class identifies an arc of the digraph. It also serves |
163 | 154 |
/// as a base class of the arc iterators, |
164 | 155 |
/// thus they will convert to this type. |
165 | 156 |
class Arc { |
166 | 157 |
public: |
167 | 158 |
/// Default constructor |
168 | 159 |
|
169 |
/// @warning The default constructor sets the iterator |
|
170 |
/// to an undefined value. |
|
160 |
/// Default constructor. |
|
161 |
/// \warning It sets the object to an undefined value. |
|
171 | 162 |
Arc() { } |
172 | 163 |
/// Copy constructor. |
173 | 164 |
|
174 | 165 |
/// Copy constructor. |
175 | 166 |
/// |
176 | 167 |
Arc(const Arc&) { } |
177 |
/// |
|
168 |
/// %Invalid constructor \& conversion. |
|
178 | 169 |
|
179 |
/// Initialize the iterator to be invalid. |
|
180 |
/// |
|
170 |
/// Initializes the object to be invalid. |
|
171 |
/// \sa Invalid for more details. |
|
181 | 172 |
Arc(Invalid) { } |
182 | 173 |
/// Equality operator |
183 | 174 |
|
175 |
/// Equality operator. |
|
176 |
/// |
|
184 | 177 |
/// Two iterators are equal if and only if they point to the |
185 |
/// same object or both are |
|
178 |
/// same object or both are \c INVALID. |
|
186 | 179 |
bool operator==(Arc) const { return true; } |
187 | 180 |
/// Inequality operator |
188 | 181 |
|
189 |
/// \sa operator==(Arc n) |
|
190 |
/// |
|
182 |
/// Inequality operator. |
|
191 | 183 |
bool operator!=(Arc) const { return true; } |
192 | 184 |
|
193 | 185 |
/// Artificial ordering operator. |
194 | 186 |
|
195 |
/// To allow the use of digraph descriptors as key type in std::map or |
|
196 |
/// similar associative container we require this. |
|
187 |
/// Artificial ordering operator. |
|
197 | 188 |
/// |
198 |
/// \note This operator only have to define some strict ordering of |
|
199 |
/// the items; this order has nothing to do with the iteration |
|
200 |
/// ordering of |
|
189 |
/// \note This operator only has to define some strict ordering of |
|
190 |
/// the arcs; this order has nothing to do with the iteration |
|
191 |
/// ordering of the arcs. |
|
201 | 192 |
bool operator<(Arc) const { return false; } |
202 | 193 |
}; |
203 | 194 |
|
204 |
/// |
|
195 |
/// Iterator class for the outgoing arcs of a node. |
|
205 | 196 |
|
206 | 197 |
/// This iterator goes trough the \e outgoing arcs of a certain node |
207 | 198 |
/// of a digraph. |
208 | 199 |
/// Its usage is quite simple, for example you can count the number |
209 | 200 |
/// of outgoing arcs of a node \c n |
210 |
/// in digraph \c g of type \c Digraph as follows. |
|
201 |
/// in a digraph \c g of type \c %Digraph as follows. |
|
211 | 202 |
///\code |
212 | 203 |
/// int count=0; |
213 |
/// for (Digraph::OutArcIt |
|
204 |
/// for (Digraph::OutArcIt a(g, n); a!=INVALID; ++a) ++count; |
|
214 | 205 |
///\endcode |
215 |
|
|
216 | 206 |
class OutArcIt : public Arc { |
217 | 207 |
public: |
218 | 208 |
/// Default constructor |
219 | 209 |
|
220 |
/// @warning The default constructor sets the iterator |
|
221 |
/// to an undefined value. |
|
210 |
/// Default constructor. |
|
211 |
/// \warning It sets the iterator to an undefined value. |
|
222 | 212 |
OutArcIt() { } |
223 | 213 |
/// Copy constructor. |
224 | 214 |
|
225 | 215 |
/// Copy constructor. |
226 | 216 |
/// |
227 | 217 |
OutArcIt(const OutArcIt& e) : Arc(e) { } |
228 |
/// |
|
218 |
/// %Invalid constructor \& conversion. |
|
229 | 219 |
|
230 |
/// |
|
220 |
/// Initializes the iterator to be invalid. |
|
221 |
/// \sa Invalid for more details. |
|
222 |
OutArcIt(Invalid) { } |
|
223 |
/// Sets the iterator to the first outgoing arc. |
|
224 |
|
|
225 |
/// Sets the iterator to the first outgoing arc of the given node. |
|
231 | 226 |
/// |
232 |
OutArcIt(Invalid) { } |
|
233 |
/// This constructor sets the iterator to the first outgoing arc. |
|
227 |
OutArcIt(const Digraph&, const Node&) { } |
|
228 |
/// Sets the iterator to the given arc. |
|
234 | 229 |
|
235 |
/// This constructor sets the iterator to the first outgoing arc of |
|
236 |
/// the node. |
|
237 |
OutArcIt(const Digraph&, const Node&) { } |
|
238 |
/// Arc -> OutArcIt conversion |
|
239 |
|
|
240 |
/// Sets the iterator to the value of the trivial iterator. |
|
241 |
/// This feature necessitates that each time we |
|
242 |
/// iterate the arc-set, the iteration order is the same. |
|
230 |
/// Sets the iterator to the given arc of the given digraph. |
|
231 |
/// |
|
243 | 232 |
OutArcIt(const Digraph&, const Arc&) { } |
244 |
///Next outgoing arc |
|
233 |
/// Next outgoing arc |
|
245 | 234 |
|
246 | 235 |
/// Assign the iterator to the next |
247 | 236 |
/// outgoing arc of the corresponding node. |
248 | 237 |
OutArcIt& operator++() { return *this; } |
249 | 238 |
}; |
250 | 239 |
|
251 |
/// |
|
240 |
/// Iterator class for the incoming arcs of a node. |
|
252 | 241 |
|
253 | 242 |
/// This iterator goes trough the \e incoming arcs of a certain node |
254 | 243 |
/// of a digraph. |
255 | 244 |
/// Its usage is quite simple, for example you can count the number |
256 |
/// of outgoing arcs of a node \c n |
|
257 |
/// in digraph \c g of type \c Digraph as follows. |
|
245 |
/// of incoming arcs of a node \c n |
|
246 |
/// in a digraph \c g of type \c %Digraph as follows. |
|
258 | 247 |
///\code |
259 | 248 |
/// int count=0; |
260 |
/// for(Digraph::InArcIt |
|
249 |
/// for(Digraph::InArcIt a(g, n); a!=INVALID; ++a) ++count; |
|
261 | 250 |
///\endcode |
262 |
|
|
263 | 251 |
class InArcIt : public Arc { |
264 | 252 |
public: |
265 | 253 |
/// Default constructor |
266 | 254 |
|
267 |
/// @warning The default constructor sets the iterator |
|
268 |
/// to an undefined value. |
|
255 |
/// Default constructor. |
|
256 |
/// \warning It sets the iterator to an undefined value. |
|
269 | 257 |
InArcIt() { } |
270 | 258 |
/// Copy constructor. |
271 | 259 |
|
272 | 260 |
/// Copy constructor. |
273 | 261 |
/// |
274 | 262 |
InArcIt(const InArcIt& e) : Arc(e) { } |
275 |
/// |
|
263 |
/// %Invalid constructor \& conversion. |
|
276 | 264 |
|
277 |
/// |
|
265 |
/// Initializes the iterator to be invalid. |
|
266 |
/// \sa Invalid for more details. |
|
267 |
InArcIt(Invalid) { } |
|
268 |
/// Sets the iterator to the first incoming arc. |
|
269 |
|
|
270 |
/// Sets the iterator to the first incoming arc of the given node. |
|
278 | 271 |
/// |
279 |
InArcIt(Invalid) { } |
|
280 |
/// This constructor sets the iterator to first incoming arc. |
|
272 |
InArcIt(const Digraph&, const Node&) { } |
|
273 |
/// Sets the iterator to the given arc. |
|
281 | 274 |
|
282 |
/// This constructor set the iterator to the first incoming arc of |
|
283 |
/// the node. |
|
284 |
InArcIt(const Digraph&, const Node&) { } |
|
285 |
/// Arc -> InArcIt conversion |
|
286 |
|
|
287 |
/// Sets the iterator to the value of the trivial iterator \c e. |
|
288 |
/// This feature necessitates that each time we |
|
289 |
/// iterate the arc-set, the iteration order is the same. |
|
275 |
/// Sets the iterator to the given arc of the given digraph. |
|
276 |
/// |
|
290 | 277 |
InArcIt(const Digraph&, const Arc&) { } |
291 | 278 |
/// Next incoming arc |
292 | 279 |
|
293 |
/// Assign the iterator to the next inarc of the corresponding node. |
|
294 |
/// |
|
280 |
/// Assign the iterator to the next |
|
281 |
/// incoming arc of the corresponding node. |
|
295 | 282 |
InArcIt& operator++() { return *this; } |
296 | 283 |
}; |
297 |
/// This iterator goes through each arc. |
|
298 | 284 |
|
299 |
/// |
|
285 |
/// Iterator class for the arcs. |
|
286 |
|
|
287 |
/// This iterator goes through each arc of the digraph. |
|
300 | 288 |
/// Its usage is quite simple, for example you can count the number |
301 |
/// of arcs in a digraph \c g of type \c Digraph as follows: |
|
289 |
/// of arcs in a digraph \c g of type \c %Digraph as follows: |
|
302 | 290 |
///\code |
303 | 291 |
/// int count=0; |
304 |
/// for(Digraph::ArcIt |
|
292 |
/// for(Digraph::ArcIt a(g); a!=INVALID; ++a) ++count; |
|
305 | 293 |
///\endcode |
306 | 294 |
class ArcIt : public Arc { |
307 | 295 |
public: |
308 | 296 |
/// Default constructor |
309 | 297 |
|
310 |
/// @warning The default constructor sets the iterator |
|
311 |
/// to an undefined value. |
|
298 |
/// Default constructor. |
|
299 |
/// \warning It sets the iterator to an undefined value. |
|
312 | 300 |
ArcIt() { } |
313 | 301 |
/// Copy constructor. |
314 | 302 |
|
315 | 303 |
/// Copy constructor. |
316 | 304 |
/// |
317 | 305 |
ArcIt(const ArcIt& e) : Arc(e) { } |
318 |
/// |
|
306 |
/// %Invalid constructor \& conversion. |
|
319 | 307 |
|
320 |
/// |
|
308 |
/// Initializes the iterator to be invalid. |
|
309 |
/// \sa Invalid for more details. |
|
310 |
ArcIt(Invalid) { } |
|
311 |
/// Sets the iterator to the first arc. |
|
312 |
|
|
313 |
/// Sets the iterator to the first arc of the given digraph. |
|
321 | 314 |
/// |
322 |
ArcIt(Invalid) { } |
|
323 |
/// This constructor sets the iterator to the first arc. |
|
315 |
explicit ArcIt(const Digraph& g) { ignore_unused_variable_warning(g); } |
|
316 |
/// Sets the iterator to the given arc. |
|
324 | 317 |
|
325 |
/// This constructor sets the iterator to the first arc of \c g. |
|
326 |
///@param g the digraph |
|
327 |
ArcIt(const Digraph& g) { ignore_unused_variable_warning(g); } |
|
328 |
/// Arc -> ArcIt conversion |
|
329 |
|
|
330 |
/// Sets the iterator to the value of the trivial iterator \c e. |
|
331 |
/// This feature necessitates that each time we |
|
332 |
/// iterate the arc-set, the iteration order is the same. |
|
318 |
/// Sets the iterator to the given arc of the given digraph. |
|
319 |
/// |
|
333 | 320 |
ArcIt(const Digraph&, const Arc&) { } |
334 |
///Next arc |
|
321 |
/// Next arc |
|
335 | 322 |
|
336 | 323 |
/// Assign the iterator to the next arc. |
324 |
/// |
|
337 | 325 |
ArcIt& operator++() { return *this; } |
338 | 326 |
}; |
339 |
///Gives back the target node of an arc. |
|
340 | 327 |
|
341 |
/// |
|
328 |
/// \brief The source node of the arc. |
|
342 | 329 |
/// |
343 |
Node target(Arc) const { return INVALID; } |
|
344 |
///Gives back the source node of an arc. |
|
345 |
|
|
346 |
///Gives back the source node of an arc. |
|
347 |
/// |
|
330 |
/// Returns the source node of the given arc. |
|
348 | 331 |
Node source(Arc) const { return INVALID; } |
349 | 332 |
|
350 |
/// \brief |
|
333 |
/// \brief The target node of the arc. |
|
334 |
/// |
|
335 |
/// Returns the target node of the given arc. |
|
336 |
Node target(Arc) const { return INVALID; } |
|
337 |
|
|
338 |
/// \brief The ID of the node. |
|
339 |
/// |
|
340 |
/// Returns the ID of the given node. |
|
351 | 341 |
int id(Node) const { return -1; } |
352 | 342 |
|
353 |
/// \brief |
|
343 |
/// \brief The ID of the arc. |
|
344 |
/// |
|
345 |
/// Returns the ID of the given arc. |
|
354 | 346 |
int id(Arc) const { return -1; } |
355 | 347 |
|
356 |
/// \brief |
|
348 |
/// \brief The node with the given ID. |
|
357 | 349 |
/// |
358 |
/// |
|
350 |
/// Returns the node with the given ID. |
|
351 |
/// \pre The argument should be a valid node ID in the digraph. |
|
359 | 352 |
Node nodeFromId(int) const { return INVALID; } |
360 | 353 |
|
361 |
/// \brief |
|
354 |
/// \brief The arc with the given ID. |
|
362 | 355 |
/// |
363 |
/// |
|
356 |
/// Returns the arc with the given ID. |
|
357 |
/// \pre The argument should be a valid arc ID in the digraph. |
|
364 | 358 |
Arc arcFromId(int) const { return INVALID; } |
365 | 359 |
|
366 |
/// \brief |
|
360 |
/// \brief An upper bound on the node IDs. |
|
361 |
/// |
|
362 |
/// Returns an upper bound on the node IDs. |
|
367 | 363 |
int maxNodeId() const { return -1; } |
368 | 364 |
|
369 |
/// \brief |
|
365 |
/// \brief An upper bound on the arc IDs. |
|
366 |
/// |
|
367 |
/// Returns an upper bound on the arc IDs. |
|
370 | 368 |
int maxArcId() const { return -1; } |
371 | 369 |
|
372 | 370 |
void first(Node&) const {} |
373 | 371 |
void next(Node&) const {} |
374 | 372 |
|
375 | 373 |
void first(Arc&) const {} |
376 | 374 |
void next(Arc&) const {} |
377 | 375 |
|
378 | 376 |
|
379 | 377 |
void firstIn(Arc&, const Node&) const {} |
380 | 378 |
void nextIn(Arc&) const {} |
381 | 379 |
|
382 | 380 |
void firstOut(Arc&, const Node&) const {} |
383 | 381 |
void nextOut(Arc&) const {} |
384 | 382 |
|
385 | 383 |
// The second parameter is dummy. |
386 | 384 |
Node fromId(int, Node) const { return INVALID; } |
387 | 385 |
// The second parameter is dummy. |
388 | 386 |
Arc fromId(int, Arc) const { return INVALID; } |
389 | 387 |
|
390 | 388 |
// Dummy parameter. |
391 | 389 |
int maxId(Node) const { return -1; } |
392 | 390 |
// Dummy parameter. |
393 | 391 |
int maxId(Arc) const { return -1; } |
394 | 392 |
|
393 |
/// \brief The opposite node on the arc. |
|
394 |
/// |
|
395 |
/// Returns the opposite node on the given arc. |
|
396 |
Node oppositeNode(Node, Arc) const { return INVALID; } |
|
397 |
|
|
395 | 398 |
/// \brief The base node of the iterator. |
396 | 399 |
/// |
397 |
/// Gives back the base node of the iterator. |
|
398 |
/// It is always the target of the pointed arc. |
|
399 |
|
|
400 |
/// Returns the base node of the given outgoing arc iterator |
|
401 |
/// (i.e. the source node of the corresponding arc). |
|
402 |
Node baseNode(OutArcIt) const { return INVALID; } |
|
400 | 403 |
|
401 | 404 |
/// \brief The running node of the iterator. |
402 | 405 |
/// |
403 |
/// Gives back the running node of the iterator. |
|
404 |
/// It is always the source of the pointed arc. |
|
405 |
|
|
406 |
/// Returns the running node of the given outgoing arc iterator |
|
407 |
/// (i.e. the target node of the corresponding arc). |
|
408 |
Node runningNode(OutArcIt) const { return INVALID; } |
|
406 | 409 |
|
407 | 410 |
/// \brief The base node of the iterator. |
408 | 411 |
/// |
409 |
/// Gives back the base node of the iterator. |
|
410 |
/// It is always the source of the pointed arc. |
|
411 |
|
|
412 |
/// Returns the base node of the given incomming arc iterator |
|
413 |
/// (i.e. the target node of the corresponding arc). |
|
414 |
Node baseNode(InArcIt) const { return INVALID; } |
|
412 | 415 |
|
413 | 416 |
/// \brief The running node of the iterator. |
414 | 417 |
/// |
415 |
/// Gives back the running node of the iterator. |
|
416 |
/// It is always the target of the pointed arc. |
|
417 |
|
|
418 |
/// Returns the running node of the given incomming arc iterator |
|
419 |
/// (i.e. the source node of the corresponding arc). |
|
420 |
Node runningNode(InArcIt) const { return INVALID; } |
|
418 | 421 |
|
419 |
/// \brief |
|
422 |
/// \brief Standard graph map type for the nodes. |
|
420 | 423 |
/// |
421 |
/// Gives back the opposite node on the given arc. |
|
422 |
Node oppositeNode(const Node&, const Arc&) const { return INVALID; } |
|
423 |
|
|
424 |
/// \brief Reference map of the nodes to type \c T. |
|
425 |
/// |
|
426 |
/// Reference map of the nodes to type \c T. |
|
424 |
/// Standard graph map type for the nodes. |
|
425 |
/// It conforms to the ReferenceMap concept. |
|
427 | 426 |
template<class T> |
428 | 427 |
class NodeMap : public ReferenceMap<Node, T, T&, const T&> { |
429 | 428 |
public: |
430 | 429 |
|
431 |
///\e |
|
432 |
NodeMap(const Digraph&) { } |
|
433 |
/// |
|
430 |
/// Constructor |
|
431 |
explicit NodeMap(const Digraph&) { } |
|
432 |
/// Constructor with given initial value |
|
434 | 433 |
NodeMap(const Digraph&, T) { } |
435 | 434 |
|
436 | 435 |
private: |
437 | 436 |
///Copy constructor |
438 | 437 |
NodeMap(const NodeMap& nm) : |
439 | 438 |
ReferenceMap<Node, T, T&, const T&>(nm) { } |
440 | 439 |
///Assignment operator |
441 | 440 |
template <typename CMap> |
442 | 441 |
NodeMap& operator=(const CMap&) { |
443 | 442 |
checkConcept<ReadMap<Node, T>, CMap>(); |
444 | 443 |
return *this; |
445 | 444 |
} |
446 | 445 |
}; |
447 | 446 |
|
448 |
/// \brief |
|
447 |
/// \brief Standard graph map type for the arcs. |
|
449 | 448 |
/// |
450 |
/// |
|
449 |
/// Standard graph map type for the arcs. |
|
450 |
/// It conforms to the ReferenceMap concept. |
|
451 | 451 |
template<class T> |
452 | 452 |
class ArcMap : public ReferenceMap<Arc, T, T&, const T&> { |
453 | 453 |
public: |
454 | 454 |
|
455 |
///\e |
|
456 |
ArcMap(const Digraph&) { } |
|
457 |
/// |
|
455 |
/// Constructor |
|
456 |
explicit ArcMap(const Digraph&) { } |
|
457 |
/// Constructor with given initial value |
|
458 | 458 |
ArcMap(const Digraph&, T) { } |
459 |
|
|
459 | 460 |
private: |
460 | 461 |
///Copy constructor |
461 | 462 |
ArcMap(const ArcMap& em) : |
462 | 463 |
ReferenceMap<Arc, T, T&, const T&>(em) { } |
463 | 464 |
///Assignment operator |
464 | 465 |
template <typename CMap> |
465 | 466 |
ArcMap& operator=(const CMap&) { |
466 | 467 |
checkConcept<ReadMap<Arc, T>, CMap>(); |
467 | 468 |
return *this; |
468 | 469 |
} |
469 | 470 |
}; |
470 | 471 |
|
471 | 472 |
template <typename _Digraph> |
472 | 473 |
struct Constraints { |
473 | 474 |
void constraints() { |
474 | 475 |
checkConcept<BaseDigraphComponent, _Digraph>(); |
475 | 476 |
checkConcept<IterableDigraphComponent<>, _Digraph>(); |
476 | 477 |
checkConcept<IDableDigraphComponent<>, _Digraph>(); |
477 | 478 |
checkConcept<MappableDigraphComponent<>, _Digraph>(); |
478 | 479 |
} |
479 | 480 |
}; |
480 | 481 |
|
481 | 482 |
}; |
482 | 483 |
|
483 | 484 |
} //namespace concepts |
484 | 485 |
} //namespace lemon |
485 | 486 |
|
486 | 487 |
|
487 | 488 |
|
488 | 489 |
#endif |
1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
2 | 2 |
* |
3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2009 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
8 | 8 |
* |
9 | 9 |
* Permission to use, modify and distribute this software is granted |
10 | 10 |
* provided that this copyright notice appears in all copies. For |
11 | 11 |
* precise terms see the accompanying LICENSE file. |
12 | 12 |
* |
13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
14 | 14 |
* express or implied, and with no claim as to its suitability for any |
15 | 15 |
* purpose. |
16 | 16 |
* |
17 | 17 |
*/ |
18 | 18 |
|
19 | 19 |
///\ingroup graph_concepts |
20 | 20 |
///\file |
21 |
///\brief The concept of |
|
21 |
///\brief The concept of undirected graphs. |
|
22 | 22 |
|
23 | 23 |
#ifndef LEMON_CONCEPTS_GRAPH_H |
24 | 24 |
#define LEMON_CONCEPTS_GRAPH_H |
25 | 25 |
|
26 | 26 |
#include <lemon/concepts/graph_components.h> |
27 |
#include <lemon/concepts/maps.h> |
|
28 |
#include <lemon/concept_check.h> |
|
27 | 29 |
#include <lemon/core.h> |
28 | 30 |
|
29 | 31 |
namespace lemon { |
30 | 32 |
namespace concepts { |
31 | 33 |
|
32 | 34 |
/// \ingroup graph_concepts |
33 | 35 |
/// |
34 |
/// \brief Class describing the concept of |
|
36 |
/// \brief Class describing the concept of undirected graphs. |
|
35 | 37 |
/// |
36 |
/// This class describes the common interface of all Undirected |
|
37 |
/// Graphs. |
|
38 |
/// This class describes the common interface of all undirected |
|
39 |
/// graphs. |
|
38 | 40 |
/// |
39 |
/// As all concept describing classes it provides only interface |
|
40 |
/// without any sensible implementation. So any algorithm for |
|
41 |
/// |
|
41 |
/// Like all concept classes, it only provides an interface |
|
42 |
/// without any sensible implementation. So any general algorithm for |
|
43 |
/// undirected graphs should compile with this class, but it will not |
|
42 | 44 |
/// run properly, of course. |
45 |
/// An actual graph implementation like \ref ListGraph or |
|
46 |
/// \ref SmartGraph may have additional functionality. |
|
43 | 47 |
/// |
44 |
/// The LEMON undirected graphs also fulfill the concept of |
|
45 |
/// directed graphs (\ref lemon::concepts::Digraph "Digraph |
|
46 |
/// Concept"). Each edges can be seen as two opposite |
|
47 |
/// directed arc and consequently the undirected graph can be |
|
48 |
/// seen as the direceted graph of these directed arcs. The |
|
49 |
/// Graph has the Edge inner class for the edges and |
|
50 |
/// the Arc type for the directed arcs. The Arc type is |
|
51 |
/// convertible to Edge or inherited from it so from a directed |
|
52 |
/// |
|
48 |
/// The undirected graphs also fulfill the concept of \ref Digraph |
|
49 |
/// "directed graphs", since each edge can also be regarded as two |
|
50 |
/// oppositely directed arcs. |
|
51 |
/// Undirected graphs provide an Edge type for the undirected edges and |
|
52 |
/// an Arc type for the directed arcs. The Arc type is convertible to |
|
53 |
/// Edge or inherited from it, i.e. the corresponding edge can be |
|
54 |
/// obtained from an arc. |
|
55 |
/// EdgeIt and EdgeMap classes can be used for the edges, while ArcIt |
|
56 |
/// and ArcMap classes can be used for the arcs (just like in digraphs). |
|
57 |
/// Both InArcIt and OutArcIt iterates on the same edges but with |
|
58 |
/// opposite direction. IncEdgeIt also iterates on the same edges |
|
59 |
/// as OutArcIt and InArcIt, but it is not convertible to Arc, |
|
60 |
/// only to Edge. |
|
53 | 61 |
/// |
54 |
/// In the sense of the LEMON each edge has a default |
|
55 |
/// direction (it should be in every computer implementation, |
|
56 |
/// because the order of edge's nodes defines an |
|
57 |
/// orientation). With the default orientation we can define that |
|
58 |
/// the directed arc is forward or backward directed. With the \c |
|
59 |
/// direction() and \c direct() function we can get the direction |
|
60 |
/// |
|
62 |
/// In LEMON, each undirected edge has an inherent orientation. |
|
63 |
/// Thus it can defined if an arc is forward or backward oriented in |
|
64 |
/// an undirected graph with respect to this default oriantation of |
|
65 |
/// the represented edge. |
|
66 |
/// With the direction() and direct() functions the direction |
|
67 |
/// of an arc can be obtained and set, respectively. |
|
61 | 68 |
/// |
62 |
/// The EdgeIt is an iterator for the edges. We can use |
|
63 |
/// the EdgeMap to map values for the edges. The InArcIt and |
|
64 |
/// OutArcIt iterates on the same edges but with opposite |
|
65 |
/// direction. The IncEdgeIt iterates also on the same edges |
|
66 |
/// as the OutArcIt and InArcIt but it is not convertible to Arc just |
|
67 |
/// to Edge. |
|
69 |
/// Only nodes and edges can be added to or removed from an undirected |
|
70 |
/// graph and the corresponding arcs are added or removed automatically. |
|
71 |
/// |
|
72 |
/// \sa Digraph |
|
68 | 73 |
class Graph { |
74 |
private: |
|
75 |
/// Graphs are \e not copy constructible. Use DigraphCopy instead. |
|
76 |
Graph(const Graph&) {} |
|
77 |
/// \brief Assignment of a graph to another one is \e not allowed. |
|
78 |
/// Use DigraphCopy instead. |
|
79 |
void operator=(const Graph&) {} |
|
80 |
|
|
69 | 81 |
public: |
70 |
/// \brief The undirected graph should be tagged by the |
|
71 |
/// UndirectedTag. |
|
82 |
/// Default constructor. |
|
83 |
Graph() {} |
|
84 |
|
|
85 |
/// \brief Undirected graphs should be tagged with \c UndirectedTag. |
|
72 | 86 |
/// |
73 |
/// The undirected graph should be tagged by the UndirectedTag. This |
|
74 |
/// tag helps the enable_if technics to make compile time |
|
87 |
/// Undirected graphs should be tagged with \c UndirectedTag. |
|
88 |
/// |
|
89 |
/// This tag helps the \c enable_if technics to make compile time |
|
75 | 90 |
/// specializations for undirected graphs. |
76 | 91 |
typedef True UndirectedTag; |
77 | 92 |
|
78 |
/// \brief The base type of node iterators, |
|
79 |
/// or in other words, the trivial node iterator. |
|
80 |
/// |
|
81 |
/// This is the base type of each node iterator, |
|
82 |
/// thus each kind of node iterator converts to this. |
|
83 |
/// More precisely each kind of node iterator should be inherited |
|
84 |
/// |
|
93 |
/// The node type of the graph |
|
94 |
|
|
95 |
/// This class identifies a node of the graph. It also serves |
|
96 |
/// as a base class of the node iterators, |
|
97 |
/// thus they convert to this type. |
|
85 | 98 |
class Node { |
86 | 99 |
public: |
87 | 100 |
/// Default constructor |
88 | 101 |
|
89 |
/// @warning The default constructor sets the iterator |
|
90 |
/// to an undefined value. |
|
102 |
/// Default constructor. |
|
103 |
/// \warning It sets the object to an undefined value. |
|
91 | 104 |
Node() { } |
92 | 105 |
/// Copy constructor. |
93 | 106 |
|
94 | 107 |
/// Copy constructor. |
95 | 108 |
/// |
96 | 109 |
Node(const Node&) { } |
97 | 110 |
|
98 |
/// Invalid constructor \& conversion. |
|
111 |
/// %Invalid constructor \& conversion. |
|
99 | 112 |
|
100 |
/// |
|
113 |
/// Initializes the object to be invalid. |
|
101 | 114 |
/// \sa Invalid for more details. |
102 | 115 |
Node(Invalid) { } |
103 | 116 |
/// Equality operator |
104 | 117 |
|
118 |
/// Equality operator. |
|
119 |
/// |
|
105 | 120 |
/// Two iterators are equal if and only if they point to the |
106 |
/// same object or both are |
|
121 |
/// same object or both are \c INVALID. |
|
107 | 122 |
bool operator==(Node) const { return true; } |
108 | 123 |
|
109 | 124 |
/// Inequality operator |
110 | 125 |
|
111 |
/// \sa operator==(Node n) |
|
112 |
/// |
|
126 |
/// Inequality operator. |
|
113 | 127 |
bool operator!=(Node) const { return true; } |
114 | 128 |
|
115 | 129 |
/// Artificial ordering operator. |
116 | 130 |
|
117 |
/// To allow the use of graph descriptors as key type in std::map or |
|
118 |
/// similar associative container we require this. |
|
131 |
/// Artificial ordering operator. |
|
119 | 132 |
/// |
120 |
/// \note This operator only |
|
133 |
/// \note This operator only has to define some strict ordering of |
|
121 | 134 |
/// the items; this order has nothing to do with the iteration |
122 | 135 |
/// ordering of the items. |
123 | 136 |
bool operator<(Node) const { return false; } |
124 | 137 |
|
125 | 138 |
}; |
126 | 139 |
|
127 |
/// |
|
140 |
/// Iterator class for the nodes. |
|
128 | 141 |
|
129 |
/// This iterator goes through each node. |
|
142 |
/// This iterator goes through each node of the graph. |
|
130 | 143 |
/// Its usage is quite simple, for example you can count the number |
131 |
/// of nodes in graph \c g of type \c Graph like this: |
|
144 |
/// of nodes in a graph \c g of type \c %Graph like this: |
|
132 | 145 |
///\code |
133 | 146 |
/// int count=0; |
134 | 147 |
/// for (Graph::NodeIt n(g); n!=INVALID; ++n) ++count; |
135 | 148 |
///\endcode |
136 | 149 |
class NodeIt : public Node { |
137 | 150 |
public: |
138 | 151 |
/// Default constructor |
139 | 152 |
|
140 |
/// @warning The default constructor sets the iterator |
|
141 |
/// to an undefined value. |
|
153 |
/// Default constructor. |
|
154 |
/// \warning It sets the iterator to an undefined value. |
|
142 | 155 |
NodeIt() { } |
143 | 156 |
/// Copy constructor. |
144 | 157 |
|
145 | 158 |
/// Copy constructor. |
146 | 159 |
/// |
147 | 160 |
NodeIt(const NodeIt& n) : Node(n) { } |
148 |
/// Invalid constructor \& conversion. |
|
161 |
/// %Invalid constructor \& conversion. |
|
149 | 162 |
|
150 |
/// |
|
163 |
/// Initializes the iterator to be invalid. |
|
151 | 164 |
/// \sa Invalid for more details. |
152 | 165 |
NodeIt(Invalid) { } |
153 | 166 |
/// Sets the iterator to the first node. |
154 | 167 |
|
155 |
/// Sets the iterator to the first node of |
|
168 |
/// Sets the iterator to the first node of the given digraph. |
|
156 | 169 |
/// |
157 |
NodeIt(const Graph&) { } |
|
158 |
/// Node -> NodeIt conversion. |
|
170 |
explicit NodeIt(const Graph&) { } |
|
171 |
/// Sets the iterator to the given node. |
|
159 | 172 |
|
160 |
/// Sets the iterator to the node of \c the graph pointed by |
|
161 |
/// the trivial iterator. |
|
162 |
/// This feature necessitates that each time we |
|
163 |
/// iterate the arc-set, the iteration order is the same. |
|
173 |
/// Sets the iterator to the given node of the given digraph. |
|
174 |
/// |
|
164 | 175 |
NodeIt(const Graph&, const Node&) { } |
165 | 176 |
/// Next node. |
166 | 177 |
|
167 | 178 |
/// Assign the iterator to the next node. |
168 | 179 |
/// |
169 | 180 |
NodeIt& operator++() { return *this; } |
170 | 181 |
}; |
171 | 182 |
|
172 | 183 |
|
173 |
/// The |
|
184 |
/// The edge type of the graph |
|
174 | 185 |
|
175 |
/// The base type of the edge iterators. |
|
176 |
/// |
|
186 |
/// This class identifies an edge of the graph. It also serves |
|
187 |
/// as a base class of the edge iterators, |
|
188 |
/// thus they will convert to this type. |
|
177 | 189 |
class Edge { |
178 | 190 |
public: |
179 | 191 |
/// Default constructor |
180 | 192 |
|
181 |
/// @warning The default constructor sets the iterator |
|
182 |
/// to an undefined value. |
|
193 |
/// Default constructor. |
|
194 |
/// \warning It sets the object to an undefined value. |
|
183 | 195 |
Edge() { } |
184 | 196 |
/// Copy constructor. |
185 | 197 |
|
186 | 198 |
/// Copy constructor. |
187 | 199 |
/// |
188 | 200 |
Edge(const Edge&) { } |
189 |
/// |
|
201 |
/// %Invalid constructor \& conversion. |
|
190 | 202 |
|
191 |
/// Initialize the iterator to be invalid. |
|
192 |
/// |
|
203 |
/// Initializes the object to be invalid. |
|
204 |
/// \sa Invalid for more details. |
|
193 | 205 |
Edge(Invalid) { } |
194 | 206 |
/// Equality operator |
195 | 207 |
|
208 |
/// Equality operator. |
|
209 |
/// |
|
196 | 210 |
/// Two iterators are equal if and only if they point to the |
197 |
/// same object or both are |
|
211 |
/// same object or both are \c INVALID. |
|
198 | 212 |
bool operator==(Edge) const { return true; } |
199 | 213 |
/// Inequality operator |
200 | 214 |
|
201 |
/// \sa operator==(Edge n) |
|
202 |
/// |
|
215 |
/// Inequality operator. |
|
203 | 216 |
bool operator!=(Edge) const { return true; } |
204 | 217 |
|
205 | 218 |
/// Artificial ordering operator. |
206 | 219 |
|
207 |
/// To allow the use of graph descriptors as key type in std::map or |
|
208 |
/// similar associative container we require this. |
|
220 |
/// Artificial ordering operator. |
|
209 | 221 |
/// |
210 |
/// \note This operator only have to define some strict ordering of |
|
211 |
/// the items; this order has nothing to do with the iteration |
|
212 |
/// ordering of |
|
222 |
/// \note This operator only has to define some strict ordering of |
|
223 |
/// the edges; this order has nothing to do with the iteration |
|
224 |
/// ordering of the edges. |
|
213 | 225 |
bool operator<(Edge) const { return false; } |
214 | 226 |
}; |
215 | 227 |
|
216 |
/// |
|
228 |
/// Iterator class for the edges. |
|
217 | 229 |
|
218 |
/// This iterator goes through each edge of |
|
230 |
/// This iterator goes through each edge of the graph. |
|
219 | 231 |
/// Its usage is quite simple, for example you can count the number |
220 |
/// of edges in a graph \c g of type \c Graph as follows: |
|
232 |
/// of edges in a graph \c g of type \c %Graph as follows: |
|
221 | 233 |
///\code |
222 | 234 |
/// int count=0; |
223 | 235 |
/// for(Graph::EdgeIt e(g); e!=INVALID; ++e) ++count; |
224 | 236 |
///\endcode |
225 | 237 |
class EdgeIt : public Edge { |
226 | 238 |
public: |
227 | 239 |
/// Default constructor |
228 | 240 |
|
229 |
/// @warning The default constructor sets the iterator |
|
230 |
/// to an undefined value. |
|
241 |
/// Default constructor. |
|
242 |
/// \warning It sets the iterator to an undefined value. |
|
231 | 243 |
EdgeIt() { } |
232 | 244 |
/// Copy constructor. |
233 | 245 |
|
234 | 246 |
/// Copy constructor. |
235 | 247 |
/// |
236 | 248 |
EdgeIt(const EdgeIt& e) : Edge(e) { } |
237 |
/// |
|
249 |
/// %Invalid constructor \& conversion. |
|
238 | 250 |
|
239 |
/// |
|
251 |
/// Initializes the iterator to be invalid. |
|
252 |
/// \sa Invalid for more details. |
|
253 |
EdgeIt(Invalid) { } |
|
254 |
/// Sets the iterator to the first edge. |
|
255 |
|
|
256 |
/// Sets the iterator to the first edge of the given graph. |
|
240 | 257 |
/// |
241 |
EdgeIt(Invalid) { } |
|
242 |
/// This constructor sets the iterator to the first edge. |
|
258 |
explicit EdgeIt(const Graph&) { } |
|
259 |
/// Sets the iterator to the given edge. |
|
243 | 260 |
|
244 |
/// This constructor sets the iterator to the first edge. |
|
245 |
EdgeIt(const Graph&) { } |
|
246 |
/// Edge -> EdgeIt conversion |
|
247 |
|
|
248 |
/// Sets the iterator to the value of the trivial iterator. |
|
249 |
/// This feature necessitates that each time we |
|
250 |
/// iterate the edge-set, the iteration order is the |
|
251 |
/// same. |
|
261 |
/// Sets the iterator to the given edge of the given graph. |
|
262 |
/// |
|
252 | 263 |
EdgeIt(const Graph&, const Edge&) { } |
253 | 264 |
/// Next edge |
254 | 265 |
|
255 | 266 |
/// Assign the iterator to the next edge. |
267 |
/// |
|
256 | 268 |
EdgeIt& operator++() { return *this; } |
257 | 269 |
}; |
258 | 270 |
|
259 |
/// \brief This iterator goes trough the incident undirected |
|
260 |
/// arcs of a node. |
|
261 |
/// |
|
262 |
/// This iterator goes trough the incident edges |
|
263 |
/// of a certain node of a graph. You should assume that the |
|
264 |
/// loop arcs will be iterated twice. |
|
265 |
/// |
|
271 |
/// Iterator class for the incident edges of a node. |
|
272 |
|
|
273 |
/// This iterator goes trough the incident undirected edges |
|
274 |
/// of a certain node of a graph. |
|
266 | 275 |
/// Its usage is quite simple, for example you can compute the |
267 |
/// degree (i.e. count the number of incident arcs of a node \c n |
|
268 |
/// in graph \c g of type \c Graph as follows. |
|
276 |
/// degree (i.e. the number of incident edges) of a node \c n |
|
277 |
/// in a graph \c g of type \c %Graph as follows. |
|
269 | 278 |
/// |
270 | 279 |
///\code |
271 | 280 |
/// int count=0; |
272 | 281 |
/// for(Graph::IncEdgeIt e(g, n); e!=INVALID; ++e) ++count; |
273 | 282 |
///\endcode |
283 |
/// |
|
284 |
/// \warning Loop edges will be iterated twice. |
|
274 | 285 |
class IncEdgeIt : public Edge { |
275 | 286 |
public: |
276 | 287 |
/// Default constructor |
277 | 288 |
|
278 |
/// @warning The default constructor sets the iterator |
|
279 |
/// to an undefined value. |
|
289 |
/// Default constructor. |
|
290 |
/// \warning It sets the iterator to an undefined value. |
|
280 | 291 |
IncEdgeIt() { } |
281 | 292 |
/// Copy constructor. |
282 | 293 |
|
283 | 294 |
/// Copy constructor. |
284 | 295 |
/// |
285 | 296 |
IncEdgeIt(const IncEdgeIt& e) : Edge(e) { } |
286 |
/// |
|
297 |
/// %Invalid constructor \& conversion. |
|
287 | 298 |
|
288 |
/// |
|
299 |
/// Initializes the iterator to be invalid. |
|
300 |
/// \sa Invalid for more details. |
|
301 |
IncEdgeIt(Invalid) { } |
|
302 |
/// Sets the iterator to the first incident edge. |
|
303 |
|
|
304 |
/// Sets the iterator to the first incident edge of the given node. |
|
289 | 305 |
/// |
290 |
IncEdgeIt(Invalid) { } |
|
291 |
/// This constructor sets the iterator to first incident arc. |
|
306 |
IncEdgeIt(const Graph&, const Node&) { } |
|
307 |
/// Sets the iterator to the given edge. |
|
292 | 308 |
|
293 |
/// This constructor set the iterator to the first incident arc of |
|
294 |
/// the node. |
|
295 |
IncEdgeIt(const Graph&, const Node&) { } |
|
296 |
/// Edge -> IncEdgeIt conversion |
|
309 |
/// Sets the iterator to the given edge of the given graph. |
|
310 |
/// |
|
311 |
IncEdgeIt(const Graph&, const Edge&) { } |
|
312 |
/// Next incident edge |
|
297 | 313 |
|
298 |
/// Sets the iterator to the value of the trivial iterator \c e. |
|
299 |
/// This feature necessitates that each time we |
|
300 |
/// iterate the arc-set, the iteration order is the same. |
|
301 |
IncEdgeIt(const Graph&, const Edge&) { } |
|
302 |
/// Next incident arc |
|
303 |
|
|
304 |
/// Assign the iterator to the next incident |
|
314 |
/// Assign the iterator to the next incident edge |
|
305 | 315 |
/// of the corresponding node. |
306 | 316 |
IncEdgeIt& operator++() { return *this; } |
307 | 317 |
}; |
308 | 318 |
|
309 |
/// The |
|
319 |
/// The arc type of the graph |
|
310 | 320 |
|
311 |
/// The directed arc type. It can be converted to the |
|
312 |
/// edge or it should be inherited from the undirected |
|
313 |
/// |
|
321 |
/// This class identifies a directed arc of the graph. It also serves |
|
322 |
/// as a base class of the arc iterators, |
|
323 |
/// thus they will convert to this type. |
|
314 | 324 |
class Arc { |
315 | 325 |
public: |
316 | 326 |
/// Default constructor |
317 | 327 |
|
318 |
/// @warning The default constructor sets the iterator |
|
319 |
/// to an undefined value. |
|
328 |
/// Default constructor. |
|
329 |
/// \warning It sets the object to an undefined value. |
|
320 | 330 |
Arc() { } |
321 | 331 |
/// Copy constructor. |
322 | 332 |
|
323 | 333 |
/// Copy constructor. |
324 | 334 |
/// |
325 | 335 |
Arc(const Arc&) { } |
326 |
/// |
|
336 |
/// %Invalid constructor \& conversion. |
|
327 | 337 |
|
328 |
/// Initialize the iterator to be invalid. |
|
329 |
/// |
|
338 |
/// Initializes the object to be invalid. |
|
339 |
/// \sa Invalid for more details. |
|
330 | 340 |
Arc(Invalid) { } |
331 | 341 |
/// Equality operator |
332 | 342 |
|
343 |
/// Equality operator. |
|
344 |
/// |
|
333 | 345 |
/// Two iterators are equal if and only if they point to the |
334 |
/// same object or both are |
|
346 |
/// same object or both are \c INVALID. |
|
335 | 347 |
bool operator==(Arc) const { return true; } |
336 | 348 |
/// Inequality operator |
337 | 349 |
|
338 |
/// \sa operator==(Arc n) |
|
339 |
/// |
|
350 |
/// Inequality operator. |
|
340 | 351 |
bool operator!=(Arc) const { return true; } |
341 | 352 |
|
342 | 353 |
/// Artificial ordering operator. |
343 | 354 |
|
344 |
/// To allow the use of graph descriptors as key type in std::map or |
|
345 |
/// similar associative container we require this. |
|
355 |
/// Artificial ordering operator. |
|
346 | 356 |
/// |
347 |
/// \note This operator only have to define some strict ordering of |
|
348 |
/// the items; this order has nothing to do with the iteration |
|
349 |
/// ordering of |
|
357 |
/// \note This operator only has to define some strict ordering of |
|
358 |
/// the arcs; this order has nothing to do with the iteration |
|
359 |
/// ordering of the arcs. |
|
350 | 360 |
bool operator<(Arc) const { return false; } |
351 | 361 |
|
352 |
/// Converison to Edge |
|
362 |
/// Converison to \c Edge |
|
363 |
|
|
364 |
/// Converison to \c Edge. |
|
365 |
/// |
|
353 | 366 |
operator Edge() const { return Edge(); } |
354 | 367 |
}; |
355 |
/// This iterator goes through each directed arc. |
|
356 | 368 |
|
357 |
/// |
|
369 |
/// Iterator class for the arcs. |
|
370 |
|
|
371 |
/// This iterator goes through each directed arc of the graph. |
|
358 | 372 |
/// Its usage is quite simple, for example you can count the number |
359 |
/// of arcs in a graph \c g of type \c Graph as follows: |
|
373 |
/// of arcs in a graph \c g of type \c %Graph as follows: |
|
360 | 374 |
///\code |
361 | 375 |
/// int count=0; |
362 |
/// for(Graph::ArcIt |
|
376 |
/// for(Graph::ArcIt a(g); a!=INVALID; ++a) ++count; |
|
363 | 377 |
///\endcode |
364 | 378 |
class ArcIt : public Arc { |
365 | 379 |
public: |
366 | 380 |
/// Default constructor |
367 | 381 |
|
368 |
/// @warning The default constructor sets the iterator |
|
369 |
/// to an undefined value. |
|
382 |
/// Default constructor. |
|
383 |
/// \warning It sets the iterator to an undefined value. |
|
370 | 384 |
ArcIt() { } |
371 | 385 |
/// Copy constructor. |
372 | 386 |
|
373 | 387 |
/// Copy constructor. |
374 | 388 |
/// |
375 | 389 |
ArcIt(const ArcIt& e) : Arc(e) { } |
376 |
/// |
|
390 |
/// %Invalid constructor \& conversion. |
|
377 | 391 |
|
378 |
/// |
|
392 |
/// Initializes the iterator to be invalid. |
|
393 |
/// \sa Invalid for more details. |
|
394 |
ArcIt(Invalid) { } |
|
395 |
/// Sets the iterator to the first arc. |
|
396 |
|
|
397 |
/// Sets the iterator to the first arc of the given graph. |
|
379 | 398 |
/// |
380 |
ArcIt(Invalid) { } |
|
381 |
/// This constructor sets the iterator to the first arc. |
|
399 |
explicit ArcIt(const Graph &g) { ignore_unused_variable_warning(g); } |
|
400 |
/// Sets the iterator to the given arc. |
|
382 | 401 |
|
383 |
/// This constructor sets the iterator to the first arc of \c g. |
|
384 |
///@param g the graph |
|
385 |
ArcIt(const Graph &g) { ignore_unused_variable_warning(g); } |
|
386 |
/// Arc -> ArcIt conversion |
|
387 |
|
|
388 |
/// Sets the iterator to the value of the trivial iterator \c e. |
|
389 |
/// This feature necessitates that each time we |
|
390 |
/// iterate the arc-set, the iteration order is the same. |
|
402 |
/// Sets the iterator to the given arc of the given graph. |
|
403 |
/// |
|
391 | 404 |
ArcIt(const Graph&, const Arc&) { } |
392 |
///Next arc |
|
405 |
/// Next arc |
|
393 | 406 |
|
394 | 407 |
/// Assign the iterator to the next arc. |
408 |
/// |
|
395 | 409 |
ArcIt& operator++() { return *this; } |
396 | 410 |
}; |
397 | 411 |
|
398 |
/// |
|
412 |
/// Iterator class for the outgoing arcs of a node. |
|
399 | 413 |
|
400 |
/// This iterator goes trough the \e outgoing arcs of a certain node |
|
401 |
/// of a graph. |
|
414 |
/// This iterator goes trough the \e outgoing directed arcs of a |
|
415 |
/// certain node of a graph. |
|
402 | 416 |
/// Its usage is quite simple, for example you can count the number |
403 | 417 |
/// of outgoing arcs of a node \c n |
404 |
/// in graph \c g of type \c Graph as follows. |
|
418 |
/// in a graph \c g of type \c %Graph as follows. |
|
405 | 419 |
///\code |
406 | 420 |
/// int count=0; |
407 |
/// for ( |
|
421 |
/// for (Digraph::OutArcIt a(g, n); a!=INVALID; ++a) ++count; |
|
408 | 422 |
///\endcode |
409 |
|
|
410 | 423 |
class OutArcIt : public Arc { |
411 | 424 |
public: |
412 | 425 |
/// Default constructor |
413 | 426 |
|
414 |
/// @warning The default constructor sets the iterator |
|
415 |
/// to an undefined value. |
|
427 |
/// Default constructor. |
|
428 |
/// \warning It sets the iterator to an undefined value. |
|
416 | 429 |
OutArcIt() { } |
417 | 430 |
/// Copy constructor. |
418 | 431 |
|
419 | 432 |
/// Copy constructor. |
420 | 433 |
/// |
421 | 434 |
OutArcIt(const OutArcIt& e) : Arc(e) { } |
422 |
/// |
|
435 |
/// %Invalid constructor \& conversion. |
|
423 | 436 |
|
424 |
/// |
|
437 |
/// Initializes the iterator to be invalid. |
|
438 |
/// \sa Invalid for more details. |
|
439 |
OutArcIt(Invalid) { } |
|
440 |
/// Sets the iterator to the first outgoing arc. |
|
441 |
|
|
442 |
/// Sets the iterator to the first outgoing arc of the given node. |
|
425 | 443 |
/// |
426 |
OutArcIt(Invalid) { } |
|
427 |
/// This constructor sets the iterator to the first outgoing arc. |
|
428 |
|
|
429 |
/// This constructor sets the iterator to the first outgoing arc of |
|
430 |
/// the node. |
|
431 |
///@param n the node |
|
432 |
///@param g the graph |
|
433 | 444 |
OutArcIt(const Graph& n, const Node& g) { |
434 | 445 |
ignore_unused_variable_warning(n); |
435 | 446 |
ignore_unused_variable_warning(g); |
436 | 447 |
} |
437 |
/// |
|
448 |
/// Sets the iterator to the given arc. |
|
438 | 449 |
|
439 |
/// Sets the iterator to the value of the trivial iterator. |
|
440 |
/// This feature necessitates that each time we |
|
441 |
/// |
|
450 |
/// Sets the iterator to the given arc of the given graph. |
|
451 |
/// |
|
442 | 452 |
OutArcIt(const Graph&, const Arc&) { } |
443 |
///Next outgoing arc |
|
453 |
/// Next outgoing arc |
|
444 | 454 |
|
445 | 455 |
/// Assign the iterator to the next |
446 | 456 |
/// outgoing arc of the corresponding node. |
447 | 457 |
OutArcIt& operator++() { return *this; } |
448 | 458 |
}; |
449 | 459 |
|
450 |
/// |
|
460 |
/// Iterator class for the incoming arcs of a node. |
|
451 | 461 |
|
452 |
/// This iterator goes trough the \e incoming arcs of a certain node |
|
453 |
/// of a graph. |
|
462 |
/// This iterator goes trough the \e incoming directed arcs of a |
|
463 |
/// certain node of a graph. |
|
454 | 464 |
/// Its usage is quite simple, for example you can count the number |
455 |
/// of outgoing arcs of a node \c n |
|
456 |
/// in graph \c g of type \c Graph as follows. |
|
465 |
/// of incoming arcs of a node \c n |
|
466 |
/// in a graph \c g of type \c %Graph as follows. |
|
457 | 467 |
///\code |
458 | 468 |
/// int count=0; |
459 |
/// for( |
|
469 |
/// for (Digraph::InArcIt a(g, n); a!=INVALID; ++a) ++count; |
|
460 | 470 |
///\endcode |
461 |
|
|
462 | 471 |
class InArcIt : public Arc { |
463 | 472 |
public: |
464 | 473 |
/// Default constructor |
465 | 474 |
|
466 |
/// @warning The default constructor sets the iterator |
|
467 |
/// to an undefined value. |
|
475 |
/// Default constructor. |
|
476 |
/// \warning It sets the iterator to an undefined value. |
|
468 | 477 |
InArcIt() { } |
469 | 478 |
/// Copy constructor. |
470 | 479 |
|
471 | 480 |
/// Copy constructor. |
472 | 481 |
/// |
473 | 482 |
InArcIt(const InArcIt& e) : Arc(e) { } |
474 |
/// |
|
483 |
/// %Invalid constructor \& conversion. |
|
475 | 484 |
|
476 |
/// |
|
485 |
/// Initializes the iterator to be invalid. |
|
486 |
/// \sa Invalid for more details. |
|
487 |
InArcIt(Invalid) { } |
|
488 |
/// Sets the iterator to the first incoming arc. |
|
489 |
|
|
490 |
/// Sets the iterator to the first incoming arc of the given node. |
|
477 | 491 |
/// |
478 |
InArcIt(Invalid) { } |
|
479 |
/// This constructor sets the iterator to first incoming arc. |
|
480 |
|
|
481 |
/// This constructor set the iterator to the first incoming arc of |
|
482 |
/// the node. |
|
483 |
///@param n the node |
|
484 |
///@param g the graph |
|
485 | 492 |
InArcIt(const Graph& g, const Node& n) { |
486 | 493 |
ignore_unused_variable_warning(n); |
487 | 494 |
ignore_unused_variable_warning(g); |
488 | 495 |
} |
489 |
/// |
|
496 |
/// Sets the iterator to the given arc. |
|
490 | 497 |
|
491 |
/// Sets the iterator to the value of the trivial iterator \c e. |
|
492 |
/// This feature necessitates that each time we |
|
493 |
/// |
|
498 |
/// Sets the iterator to the given arc of the given graph. |
|
499 |
/// |
|
494 | 500 |
InArcIt(const Graph&, const Arc&) { } |
495 | 501 |
/// Next incoming arc |
496 | 502 |
|
497 |
/// Assign the iterator to the next inarc of the corresponding node. |
|
498 |
/// |
|
503 |
/// Assign the iterator to the next |
|
504 |
/// incoming arc of the corresponding node. |
|
499 | 505 |
InArcIt& operator++() { return *this; } |
500 | 506 |
}; |
501 | 507 |
|
502 |
/// \brief |
|
508 |
/// \brief Standard graph map type for the nodes. |
|
503 | 509 |
/// |
504 |
/// |
|
510 |
/// Standard graph map type for the nodes. |
|
511 |
/// It conforms to the ReferenceMap concept. |
|
505 | 512 |
template<class T> |
506 | 513 |
class NodeMap : public ReferenceMap<Node, T, T&, const T&> |
507 | 514 |
{ |
508 | 515 |
public: |
509 | 516 |
|
510 |
///\e |
|
511 |
NodeMap(const Graph&) { } |
|
512 |
/// |
|
517 |
/// Constructor |
|
518 |
explicit NodeMap(const Graph&) { } |
|
519 |
/// Constructor with given initial value |
|
513 | 520 |
NodeMap(const Graph&, T) { } |
514 | 521 |
|
515 | 522 |
private: |
516 | 523 |
///Copy constructor |
517 | 524 |
NodeMap(const NodeMap& nm) : |
518 | 525 |
ReferenceMap<Node, T, T&, const T&>(nm) { } |
519 | 526 |
///Assignment operator |
520 | 527 |
template <typename CMap> |
521 | 528 |
NodeMap& operator=(const CMap&) { |
522 | 529 |
checkConcept<ReadMap<Node, T>, CMap>(); |
523 | 530 |
return *this; |
524 | 531 |
} |
525 | 532 |
}; |
526 | 533 |
|
527 |
/// \brief |
|
534 |
/// \brief Standard graph map type for the arcs. |
|
528 | 535 |
/// |
529 |
/// |
|
536 |
/// Standard graph map type for the arcs. |
|
537 |
/// It conforms to the ReferenceMap concept. |
|
530 | 538 |
template<class T> |
531 | 539 |
class ArcMap : public ReferenceMap<Arc, T, T&, const T&> |
532 | 540 |
{ |
533 | 541 |
public: |
534 | 542 |
|
535 |
///\e |
|
536 |
ArcMap(const Graph&) { } |
|
537 |
/// |
|
543 |
/// Constructor |
|
544 |
explicit ArcMap(const Graph&) { } |
|
545 |
/// Constructor with given initial value |
|
538 | 546 |
ArcMap(const Graph&, T) { } |
547 |
|
|
539 | 548 |
private: |
540 | 549 |
///Copy constructor |
541 | 550 |
ArcMap(const ArcMap& em) : |
542 | 551 |
ReferenceMap<Arc, T, T&, const T&>(em) { } |
543 | 552 |
///Assignment operator |
544 | 553 |
template <typename CMap> |
545 | 554 |
ArcMap& operator=(const CMap&) { |
546 | 555 |
checkConcept<ReadMap<Arc, T>, CMap>(); |
547 | 556 |
return *this; |
548 | 557 |
} |
549 | 558 |
}; |
550 | 559 |
|
551 |
/// Reference map of the edges to type \c T. |
|
552 |
|
|
553 |
/// |
|
560 |
/// \brief Standard graph map type for the edges. |
|
561 |
/// |
|
562 |
/// Standard graph map type for the edges. |
|
563 |
/// It conforms to the ReferenceMap concept. |
|
554 | 564 |
template<class T> |
555 | 565 |
class EdgeMap : public ReferenceMap<Edge, T, T&, const T&> |
556 | 566 |
{ |
557 | 567 |
public: |
558 | 568 |
|
559 |
///\e |
|
560 |
EdgeMap(const Graph&) { } |
|
561 |
/// |
|
569 |
/// Constructor |
|
570 |
explicit EdgeMap(const Graph&) { } |
|
571 |
/// Constructor with given initial value |
|
562 | 572 |
EdgeMap(const Graph&, T) { } |
573 |
|
|
563 | 574 |
private: |
564 | 575 |
///Copy constructor |
565 | 576 |
EdgeMap(const EdgeMap& em) : |
566 | 577 |
ReferenceMap<Edge, T, T&, const T&>(em) {} |
567 | 578 |
///Assignment operator |
568 | 579 |
template <typename CMap> |
569 | 580 |
EdgeMap& operator=(const CMap&) { |
570 | 581 |
checkConcept<ReadMap<Edge, T>, CMap>(); |
571 | 582 |
return *this; |
572 | 583 |
} |
573 | 584 |
}; |
574 | 585 |
|
575 |
/// \brief |
|
586 |
/// \brief The first node of the edge. |
|
576 | 587 |
/// |
577 |
/// Direct the given edge. The returned arc source |
|
578 |
/// will be the given node. |
|
579 |
Arc direct(const Edge&, const Node&) const { |
|
580 |
return INVALID; |
|
581 |
} |
|
582 |
|
|
583 |
/// |
|
588 |
/// Returns the first node of the given edge. |
|
584 | 589 |
/// |
585 |
/// Direct the given edge. The returned arc |
|
586 |
/// represents the given edge and the direction comes |
|
587 |
/// from the bool parameter. The source of the edge and |
|
588 |
/// the directed arc is the same when the given bool is true. |
|
589 |
Arc direct(const Edge&, bool) const { |
|
590 |
return INVALID; |
|
591 |
} |
|
592 |
|
|
593 |
/// \brief Returns true if the arc has default orientation. |
|
594 |
/// |
|
595 |
/// Returns whether the given directed arc is same orientation as |
|
596 |
/// the corresponding edge's default orientation. |
|
597 |
bool direction(Arc) const { return true; } |
|
598 |
|
|
599 |
/// \brief Returns the opposite directed arc. |
|
600 |
/// |
|
601 |
/// Returns the opposite directed arc. |
|
602 |
Arc oppositeArc(Arc) const { return INVALID; } |
|
603 |
|
|
604 |
/// \brief Opposite node on an arc |
|
605 |
/// |
|
606 |
/// \return The opposite of the given node on the given edge. |
|
607 |
Node oppositeNode(Node, Edge) const { return INVALID; } |
|
608 |
|
|
609 |
/// \brief First node of the edge. |
|
610 |
/// |
|
611 |
/// \return The first node of the given edge. |
|
612 |
/// |
|
613 |
/// Naturally edges don't have direction and thus |
|
614 |
/// don't have source and target node. However we use \c u() and \c v() |
|
615 |
/// methods to query the two nodes of the arc. The direction of the |
|
616 |
/// arc which arises this way is called the inherent direction of the |
|
617 |
/// edge, and is used to define the "default" direction |
|
618 |
/// of the directed versions of the arcs. |
|
590 |
/// Edges don't have source and target nodes, however methods |
|
591 |
/// u() and v() are used to query the two end-nodes of an edge. |
|
592 |
/// The orientation of an edge that arises this way is called |
|
593 |
/// the inherent direction, it is used to define the default |
|
594 |
/// direction for the corresponding arcs. |
|
619 | 595 |
/// \sa v() |
620 | 596 |
/// \sa direction() |
621 | 597 |
Node u(Edge) const { return INVALID; } |
622 | 598 |
|
623 |
/// \brief |
|
599 |
/// \brief The second node of the edge. |
|
624 | 600 |
/// |
625 |
/// |
|
601 |
/// Returns the second node of the given edge. |
|
626 | 602 |
/// |
627 |
/// Naturally edges don't have direction and thus |
|
628 |
/// don't have source and target node. However we use \c u() and \c v() |
|
629 |
/// methods to query the two nodes of the arc. The direction of the |
|
630 |
/// arc which arises this way is called the inherent direction of the |
|
631 |
/// edge, and is used to define the "default" direction |
|
632 |
/// of the directed versions of the arcs. |
|
603 |
/// Edges don't have source and target nodes, however methods |
|
604 |
/// u() and v() are used to query the two end-nodes of an edge. |
|
605 |
/// The orientation of an edge that arises this way is called |
|
606 |
/// the inherent direction, it is used to define the default |
|
607 |
/// direction for the corresponding arcs. |
|
633 | 608 |
/// \sa u() |
634 | 609 |
/// \sa direction() |
635 | 610 |
Node v(Edge) const { return INVALID; } |
636 | 611 |
|
637 |
/// \brief |
|
612 |
/// \brief The source node of the arc. |
|
613 |
/// |
|
614 |
/// Returns the source node of the given arc. |
|
638 | 615 |
Node source(Arc) const { return INVALID; } |
639 | 616 |
|
640 |
/// \brief |
|
617 |
/// \brief The target node of the arc. |
|
618 |
/// |
|
619 |
/// Returns the target node of the given arc. |
|
641 | 620 |
Node target(Arc) const { return INVALID; } |
642 | 621 |
|
643 |
/// \brief |
|
622 |
/// \brief The ID of the node. |
|
623 |
/// |
|
624 |
/// Returns the ID of the given node. |
|
644 | 625 |
int id(Node) const { return -1; } |
645 | 626 |
|
646 |
/// \brief |
|
627 |
/// \brief The ID of the edge. |
|
628 |
/// |
|
629 |
/// Returns the ID of the given edge. |
|
647 | 630 |
int id(Edge) const { return -1; } |
648 | 631 |
|
649 |
/// \brief |
|
632 |
/// \brief The ID of the arc. |
|
633 |
/// |
|
634 |
/// Returns the ID of the given arc. |
|
650 | 635 |
int id(Arc) const { return -1; } |
651 | 636 |
|
652 |
/// \brief |
|
637 |
/// \brief The node with the given ID. |
|
653 | 638 |
/// |
654 |
/// |
|
639 |
/// Returns the node with the given ID. |
|
640 |
/// \pre The argument should be a valid node ID in the graph. |
|
655 | 641 |
Node nodeFromId(int) const { return INVALID; } |
656 | 642 |
|
657 |
/// \brief |
|
643 |
/// \brief The edge with the given ID. |
|
658 | 644 |
/// |
659 |
/// |
|
645 |
/// Returns the edge with the given ID. |
|
646 |
/// \pre The argument should be a valid edge ID in the graph. |
|
660 | 647 |
Edge edgeFromId(int) const { return INVALID; } |
661 | 648 |
|
662 |
/// \brief |
|
649 |
/// \brief The arc with the given ID. |
|
663 | 650 |
/// |
664 |
/// |
|
651 |
/// Returns the arc with the given ID. |
|
652 |
/// \pre The argument should be a valid arc ID in the graph. |
|
665 | 653 |
Arc arcFromId(int) const { return INVALID; } |
666 | 654 |
|
667 |
/// \brief |
|
655 |
/// \brief An upper bound on the node IDs. |
|
656 |
/// |
|
657 |
/// Returns an upper bound on the node IDs. |
|
668 | 658 |
int maxNodeId() const { return -1; } |
669 | 659 |
|
670 |
/// \brief |
|
660 |
/// \brief An upper bound on the edge IDs. |
|
661 |
/// |
|
662 |
/// Returns an upper bound on the edge IDs. |
|
671 | 663 |
int maxEdgeId() const { return -1; } |
672 | 664 |
|
673 |
/// \brief |
|
665 |
/// \brief An upper bound on the arc IDs. |
|
666 |
/// |
|
667 |
/// Returns an upper bound on the arc IDs. |
|
674 | 668 |
int maxArcId() const { return -1; } |
675 | 669 |
|
670 |
/// \brief The direction of the arc. |
|
671 |
/// |
|
672 |
/// Returns \c true if the direction of the given arc is the same as |
|
673 |
/// the inherent orientation of the represented edge. |
|
674 |
bool direction(Arc) const { return true; } |
|
675 |
|
|
676 |
/// \brief Direct the edge. |
|
677 |
/// |
|
678 |
/// Direct the given edge. The returned arc |
|
679 |
/// represents the given edge and its direction comes |
|
680 |
/// from the bool parameter. If it is \c true, then the direction |
|
681 |
/// of the arc is the same as the inherent orientation of the edge. |
|
682 |
Arc direct(Edge, bool) const { |
|
683 |
return INVALID; |
|
684 |
} |
|
685 |
|
|
686 |
/// \brief Direct the edge. |
|
687 |
/// |
|
688 |
/// Direct the given edge. The returned arc represents the given |
|
689 |
/// edge and its source node is the given node. |
|
690 |
Arc direct(Edge, Node) const { |
|
691 |
return INVALID; |
|
692 |
} |
|
693 |
|
|
694 |
/// \brief The oppositely directed arc. |
|
695 |
/// |
|
696 |
/// Returns the oppositely directed arc representing the same edge. |
|
697 |
Arc oppositeArc(Arc) const { return INVALID; } |
|
698 |
|
|
699 |
/// \brief The opposite node on the edge. |
|
700 |
/// |
|
701 |
/// Returns the opposite node on the given edge. |
|
702 |
Node oppositeNode(Node, Edge) const { return INVALID; } |
|
703 |
|
|
676 | 704 |
void first(Node&) const {} |
677 | 705 |
void next(Node&) const {} |
678 | 706 |
|
679 | 707 |
void first(Edge&) const {} |
680 | 708 |
void next(Edge&) const {} |
681 | 709 |
|
682 | 710 |
void first(Arc&) const {} |
683 | 711 |
void next(Arc&) const {} |
684 | 712 |
|
685 | 713 |
void firstOut(Arc&, Node) const {} |
686 | 714 |
void nextOut(Arc&) const {} |
687 | 715 |
|
688 | 716 |
void firstIn(Arc&, Node) const {} |
689 | 717 |
void nextIn(Arc&) const {} |
690 | 718 |
|
691 | 719 |
void firstInc(Edge &, bool &, const Node &) const {} |
692 | 720 |
void nextInc(Edge &, bool &) const {} |
693 | 721 |
|
694 | 722 |
// The second parameter is dummy. |
695 | 723 |
Node fromId(int, Node) const { return INVALID; } |
696 | 724 |
// The second parameter is dummy. |
697 | 725 |
Edge fromId(int, Edge) const { return INVALID; } |
698 | 726 |
// The second parameter is dummy. |
699 | 727 |
Arc fromId(int, Arc) const { return INVALID; } |
700 | 728 |
|
701 | 729 |
// Dummy parameter. |
702 | 730 |
int maxId(Node) const { return -1; } |
703 | 731 |
// Dummy parameter. |
704 | 732 |
int maxId(Edge) const { return -1; } |
705 | 733 |
// Dummy parameter. |
706 | 734 |
int maxId(Arc) const { return -1; } |
707 | 735 |
|
708 |
/// \brief |
|
736 |
/// \brief The base node of the iterator. |
|
709 | 737 |
/// |
710 |
/// Returns the base node (the source in this case) of the iterator |
|
711 |
Node baseNode(OutArcIt e) const { |
|
712 |
return source(e); |
|
713 |
} |
|
714 |
/// |
|
738 |
/// Returns the base node of the given incident edge iterator. |
|
739 |
Node baseNode(IncEdgeIt) const { return INVALID; } |
|
740 |
|
|
741 |
/// \brief The running node of the iterator. |
|
715 | 742 |
/// |
716 |
/// Returns the running node (the target in this case) of the |
|
717 |
/// iterator |
|
718 |
Node runningNode(OutArcIt e) const { |
|
719 |
return target(e); |
|
720 |
|
|
743 |
/// Returns the running node of the given incident edge iterator. |
|
744 |
Node runningNode(IncEdgeIt) const { return INVALID; } |
|
721 | 745 |
|
722 |
/// \brief |
|
746 |
/// \brief The base node of the iterator. |
|
723 | 747 |
/// |
724 |
/// Returns the base node (the target in this case) of the iterator |
|
725 |
Node baseNode(InArcIt e) const { |
|
726 |
return target(e); |
|
727 |
} |
|
728 |
/// |
|
748 |
/// Returns the base node of the given outgoing arc iterator |
|
749 |
/// (i.e. the source node of the corresponding arc). |
|
750 |
Node baseNode(OutArcIt) const { return INVALID; } |
|
751 |
|
|
752 |
/// \brief The running node of the iterator. |
|
729 | 753 |
/// |
730 |
/// Returns the running node (the source in this case) of the |
|
731 |
/// iterator |
|
732 |
Node runningNode(InArcIt e) const { |
|
733 |
return source(e); |
|
734 |
|
|
754 |
/// Returns the running node of the given outgoing arc iterator |
|
755 |
/// (i.e. the target node of the corresponding arc). |
|
756 |
Node runningNode(OutArcIt) const { return INVALID; } |
|
735 | 757 |
|
736 |
/// \brief |
|
758 |
/// \brief The base node of the iterator. |
|
737 | 759 |
/// |
738 |
/// Returns the base node of the iterator |
|
739 |
Node baseNode(IncEdgeIt) const { |
|
740 |
return INVALID; |
|
741 |
} |
|
760 |
/// Returns the base node of the given incomming arc iterator |
|
761 |
/// (i.e. the target node of the corresponding arc). |
|
762 |
Node baseNode(InArcIt) const { return INVALID; } |
|
742 | 763 |
|
743 |
/// \brief |
|
764 |
/// \brief The running node of the iterator. |
|
744 | 765 |
/// |
745 |
/// Returns the running node of the iterator |
|
746 |
Node runningNode(IncEdgeIt) const { |
|
747 |
return INVALID; |
|
748 |
} |
|
766 |
/// Returns the running node of the given incomming arc iterator |
|
767 |
/// (i.e. the source node of the corresponding arc). |
|
768 |
Node runningNode(InArcIt) const { return INVALID; } |
|
749 | 769 |
|
750 | 770 |
template <typename _Graph> |
751 | 771 |
struct Constraints { |
752 | 772 |
void constraints() { |
753 | 773 |
checkConcept<BaseGraphComponent, _Graph>(); |
754 | 774 |
checkConcept<IterableGraphComponent<>, _Graph>(); |
755 | 775 |
checkConcept<IDableGraphComponent<>, _Graph>(); |
756 | 776 |
checkConcept<MappableGraphComponent<>, _Graph>(); |
757 | 777 |
} |
758 | 778 |
}; |
759 | 779 |
|
760 | 780 |
}; |
761 | 781 |
|
762 | 782 |
} |
763 | 783 |
|
764 | 784 |
} |
765 | 785 |
|
766 | 786 |
#endif |
1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
2 | 2 |
* |
3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2009 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
8 | 8 |
* |
9 | 9 |
* Permission to use, modify and distribute this software is granted |
10 | 10 |
* provided that this copyright notice appears in all copies. For |
11 | 11 |
* precise terms see the accompanying LICENSE file. |
12 | 12 |
* |
13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
14 | 14 |
* express or implied, and with no claim as to its suitability for any |
15 | 15 |
* purpose. |
16 | 16 |
* |
17 | 17 |
*/ |
18 | 18 |
|
19 | 19 |
///\ingroup graph_concepts |
20 | 20 |
///\file |
21 | 21 |
///\brief The concept of graph components. |
22 | 22 |
|
23 | 23 |
#ifndef LEMON_CONCEPTS_GRAPH_COMPONENTS_H |
24 | 24 |
#define LEMON_CONCEPTS_GRAPH_COMPONENTS_H |
25 | 25 |
|
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 | 74 |
/// \brief Assignment operator for INVALID. |
75 | 75 |
/// |
76 | 76 |
/// This operator makes the item invalid. |
77 | 77 |
GraphItem& operator=(Invalid) { return *this; } |
78 | 78 |
|
79 | 79 |
/// \brief Equality operator. |
80 | 80 |
/// |
81 | 81 |
/// Equality operator. |
82 | 82 |
bool operator==(const GraphItem&) const { return false; } |
83 | 83 |
|
84 | 84 |
/// \brief Inequality operator. |
85 | 85 |
/// |
86 | 86 |
/// Inequality operator. |
87 | 87 |
bool operator!=(const GraphItem&) const { return false; } |
88 | 88 |
|
89 | 89 |
/// \brief Ordering operator. |
90 | 90 |
/// |
91 | 91 |
/// This operator defines an ordering of the items. |
92 | 92 |
/// It makes possible to use graph item types as key types in |
93 | 93 |
/// associative containers (e.g. \c std::map). |
94 | 94 |
/// |
95 |
/// \note This operator only |
|
95 |
/// \note This operator only has to define some strict ordering of |
|
96 | 96 |
/// the items; this order has nothing to do with the iteration |
97 | 97 |
/// ordering of the items. |
98 | 98 |
bool operator<(const GraphItem&) const { return false; } |
99 | 99 |
|
100 | 100 |
template<typename _GraphItem> |
101 | 101 |
struct Constraints { |
102 | 102 |
void constraints() { |
103 | 103 |
_GraphItem i1; |
104 | 104 |
i1=INVALID; |
105 | 105 |
_GraphItem i2 = i1; |
106 | 106 |
_GraphItem i3 = INVALID; |
107 | 107 |
|
108 | 108 |
i1 = i2 = i3; |
109 | 109 |
|
110 | 110 |
bool b; |
111 | 111 |
b = (ia == ib) && (ia != ib); |
112 | 112 |
b = (ia == INVALID) && (ib != INVALID); |
113 | 113 |
b = (ia < ib); |
114 | 114 |
} |
115 | 115 |
|
116 | 116 |
const _GraphItem &ia; |
117 | 117 |
const _GraphItem &ib; |
118 | 118 |
}; |
119 | 119 |
}; |
120 | 120 |
|
121 | 121 |
/// \brief Base skeleton class for directed graphs. |
122 | 122 |
/// |
123 | 123 |
/// This class describes the base interface of directed graph types. |
124 | 124 |
/// All digraph %concepts have to conform to this class. |
125 | 125 |
/// It just provides types for nodes and arcs and functions |
126 | 126 |
/// to get the source and the target nodes of arcs. |
127 | 127 |
class BaseDigraphComponent { |
128 | 128 |
public: |
129 | 129 |
|
130 | 130 |
typedef BaseDigraphComponent Digraph; |
131 | 131 |
|
132 | 132 |
/// \brief Node class of the digraph. |
133 | 133 |
/// |
134 | 134 |
/// This class represents the nodes of the digraph. |
135 | 135 |
typedef GraphItem<'n'> Node; |
136 | 136 |
|
137 | 137 |
/// \brief Arc class of the digraph. |
138 | 138 |
/// |
139 | 139 |
/// This class represents the arcs of the digraph. |
140 | 140 |
typedef GraphItem<'a'> Arc; |
141 | 141 |
|
142 | 142 |
/// \brief Return the source node of an arc. |
143 | 143 |
/// |
144 | 144 |
/// This function returns the source node of an arc. |
145 | 145 |
Node source(const Arc&) const { return INVALID; } |
146 | 146 |
|
147 | 147 |
/// \brief Return the target node of an arc. |
148 | 148 |
/// |
149 | 149 |
/// This function returns the target node of an arc. |
150 | 150 |
Node target(const Arc&) const { return INVALID; } |
151 | 151 |
|
152 | 152 |
/// \brief Return the opposite node on the given arc. |
153 | 153 |
/// |
154 | 154 |
/// This function returns the opposite node on the given arc. |
155 | 155 |
Node oppositeNode(const Node&, const Arc&) const { |
156 | 156 |
return INVALID; |
157 | 157 |
} |
158 | 158 |
|
159 | 159 |
template <typename _Digraph> |
160 | 160 |
struct Constraints { |
161 | 161 |
typedef typename _Digraph::Node Node; |
162 | 162 |
typedef typename _Digraph::Arc Arc; |
163 | 163 |
|
164 | 164 |
void constraints() { |
165 | 165 |
checkConcept<GraphItem<'n'>, Node>(); |
166 | 166 |
checkConcept<GraphItem<'a'>, Arc>(); |
167 | 167 |
{ |
168 | 168 |
Node n; |
169 | 169 |
Arc e(INVALID); |
170 | 170 |
n = digraph.source(e); |
171 | 171 |
n = digraph.target(e); |
172 | 172 |
n = digraph.oppositeNode(n, e); |
173 | 173 |
} |
174 | 174 |
} |
175 | 175 |
|
176 | 176 |
const _Digraph& digraph; |
177 | 177 |
}; |
178 | 178 |
}; |
179 | 179 |
|
180 | 180 |
/// \brief Base skeleton class for undirected graphs. |
181 | 181 |
/// |
182 | 182 |
/// This class describes the base interface of undirected graph types. |
183 | 183 |
/// All graph %concepts have to conform to this class. |
184 | 184 |
/// It extends the interface of \ref BaseDigraphComponent with an |
185 | 185 |
/// \c Edge type and functions to get the end nodes of edges, |
186 | 186 |
/// to convert from arcs to edges and to get both direction of edges. |
187 | 187 |
class BaseGraphComponent : public BaseDigraphComponent { |
188 | 188 |
public: |
189 | 189 |
|
190 | 190 |
typedef BaseGraphComponent Graph; |
191 | 191 |
|
192 | 192 |
typedef BaseDigraphComponent::Node Node; |
193 | 193 |
typedef BaseDigraphComponent::Arc Arc; |
194 | 194 |
|
195 | 195 |
/// \brief Undirected edge class of the graph. |
196 | 196 |
/// |
197 | 197 |
/// This class represents the undirected edges of the graph. |
198 | 198 |
/// Undirected graphs can be used as directed graphs, each edge is |
199 | 199 |
/// represented by two opposite directed arcs. |
200 | 200 |
class Edge : public GraphItem<'e'> { |
201 | 201 |
typedef GraphItem<'e'> Parent; |
202 | 202 |
|
203 | 203 |
public: |
204 | 204 |
/// \brief Default constructor. |
205 | 205 |
/// |
206 | 206 |
/// Default constructor. |
207 | 207 |
/// \warning The default constructor is not required to set |
208 | 208 |
/// the item to some well-defined value. So you should consider it |
209 | 209 |
/// as uninitialized. |
210 | 210 |
Edge() {} |
211 | 211 |
|
212 | 212 |
/// \brief Copy constructor. |
213 | 213 |
/// |
214 | 214 |
/// Copy constructor. |
215 | 215 |
Edge(const Edge &) : Parent() {} |
216 | 216 |
|
217 | 217 |
/// \brief Constructor for conversion from \c INVALID. |
218 | 218 |
/// |
219 | 219 |
/// Constructor for conversion from \c INVALID. |
220 | 220 |
/// It initializes the item to be invalid. |
221 | 221 |
/// \sa Invalid for more details. |
222 | 222 |
Edge(Invalid) {} |
223 | 223 |
|
224 | 224 |
/// \brief Constructor for conversion from an arc. |
225 | 225 |
/// |
226 | 226 |
/// Constructor for conversion from an arc. |
227 | 227 |
/// Besides the core graph item functionality each arc should |
228 | 228 |
/// be convertible to the represented edge. |
229 | 229 |
Edge(const Arc&) {} |
230 | 230 |
}; |
231 | 231 |
|
232 | 232 |
/// \brief Return one end node of an edge. |
233 | 233 |
/// |
234 | 234 |
/// This function returns one end node of an edge. |
235 | 235 |
Node u(const Edge&) const { return INVALID; } |
236 | 236 |
|
237 | 237 |
/// \brief Return the other end node of an edge. |
238 | 238 |
/// |
239 | 239 |
/// This function returns the other end node of an edge. |
240 | 240 |
Node v(const Edge&) const { return INVALID; } |
241 | 241 |
|
242 | 242 |
/// \brief Return a directed arc related to an edge. |
243 | 243 |
/// |
244 | 244 |
/// This function returns a directed arc from its direction and the |
245 | 245 |
/// represented edge. |
246 | 246 |
Arc direct(const Edge&, bool) const { return INVALID; } |
247 | 247 |
|
248 | 248 |
/// \brief Return a directed arc related to an edge. |
249 | 249 |
/// |
250 | 250 |
/// This function returns a directed arc from its source node and the |
251 | 251 |
/// represented edge. |
252 | 252 |
Arc direct(const Edge&, const Node&) const { return INVALID; } |
253 | 253 |
|
254 | 254 |
/// \brief Return the direction of the arc. |
255 | 255 |
/// |
256 | 256 |
/// Returns the direction of the arc. Each arc represents an |
257 | 257 |
/// edge with a direction. It gives back the |
258 | 258 |
/// direction. |
259 | 259 |
bool direction(const Arc&) const { return true; } |
260 | 260 |
|
261 | 261 |
/// \brief Return the opposite arc. |
262 | 262 |
/// |
263 | 263 |
/// This function returns the opposite arc, i.e. the arc representing |
264 | 264 |
/// the same edge and has opposite direction. |
265 | 265 |
Arc oppositeArc(const Arc&) const { return INVALID; } |
266 | 266 |
|
267 | 267 |
template <typename _Graph> |
268 | 268 |
struct Constraints { |
269 | 269 |
typedef typename _Graph::Node Node; |
270 | 270 |
typedef typename _Graph::Arc Arc; |
271 | 271 |
typedef typename _Graph::Edge Edge; |
272 | 272 |
|
273 | 273 |
void constraints() { |
274 | 274 |
checkConcept<BaseDigraphComponent, _Graph>(); |
275 | 275 |
checkConcept<GraphItem<'e'>, Edge>(); |
276 | 276 |
{ |
277 | 277 |
Node n; |
278 | 278 |
Edge ue(INVALID); |
279 | 279 |
Arc e; |
280 | 280 |
n = graph.u(ue); |
281 | 281 |
n = graph.v(ue); |
282 | 282 |
e = graph.direct(ue, true); |
283 | 283 |
e = graph.direct(ue, false); |
284 | 284 |
e = graph.direct(ue, n); |
285 | 285 |
e = graph.oppositeArc(e); |
286 | 286 |
ue = e; |
287 | 287 |
bool d = graph.direction(e); |
288 | 288 |
ignore_unused_variable_warning(d); |
289 | 289 |
} |
290 | 290 |
} |
291 | 291 |
|
292 | 292 |
const _Graph& graph; |
293 | 293 |
}; |
294 | 294 |
|
295 | 295 |
}; |
296 | 296 |
|
297 | 297 |
/// \brief Skeleton class for \e idable directed graphs. |
298 | 298 |
/// |
299 | 299 |
/// This class describes the interface of \e idable directed graphs. |
300 | 300 |
/// It extends \ref BaseDigraphComponent with the core ID functions. |
301 | 301 |
/// The ids of the items must be unique and immutable. |
302 | 302 |
/// This concept is part of the Digraph concept. |
303 | 303 |
template <typename BAS = BaseDigraphComponent> |
304 | 304 |
class IDableDigraphComponent : public BAS { |
305 | 305 |
public: |
306 | 306 |
|
307 | 307 |
typedef BAS Base; |
308 | 308 |
typedef typename Base::Node Node; |
309 | 309 |
typedef typename Base::Arc Arc; |
310 | 310 |
|
311 | 311 |
/// \brief Return a unique integer id for the given node. |
312 | 312 |
/// |
313 | 313 |
/// This function returns a unique integer id for the given node. |
314 | 314 |
int id(const Node&) const { return -1; } |
315 | 315 |
|
316 | 316 |
/// \brief Return the node by its unique id. |
317 | 317 |
/// |
318 | 318 |
/// This function returns the node by its unique id. |
319 | 319 |
/// If the digraph does not contain a node with the given id, |
320 | 320 |
/// then the result of the function is undefined. |
321 | 321 |
Node nodeFromId(int) const { return INVALID; } |
322 | 322 |
|
323 | 323 |
/// \brief Return a unique integer id for the given arc. |
324 | 324 |
/// |
325 | 325 |
/// This function returns a unique integer id for the given arc. |
326 | 326 |
int id(const Arc&) const { return -1; } |
327 | 327 |
|
328 | 328 |
/// \brief Return the arc by its unique id. |
329 | 329 |
/// |
330 | 330 |
/// This function returns the arc by its unique id. |
331 | 331 |
/// If the digraph does not contain an arc with the given id, |
332 | 332 |
/// then the result of the function is undefined. |
333 | 333 |
Arc arcFromId(int) const { return INVALID; } |
334 | 334 |
|
335 | 335 |
/// \brief Return an integer greater or equal to the maximum |
336 | 336 |
/// node id. |
337 | 337 |
/// |
338 | 338 |
/// This function returns an integer greater or equal to the |
339 | 339 |
/// maximum node id. |
340 | 340 |
int maxNodeId() const { return -1; } |
341 | 341 |
|
342 | 342 |
/// \brief Return an integer greater or equal to the maximum |
343 | 343 |
/// arc id. |
344 | 344 |
/// |
345 | 345 |
/// This function returns an integer greater or equal to the |
346 | 346 |
/// maximum arc id. |
347 | 347 |
int maxArcId() const { return -1; } |
348 | 348 |
|
349 | 349 |
template <typename _Digraph> |
350 | 350 |
struct Constraints { |
351 | 351 |
1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
2 | 2 |
* |
3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2009 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
8 | 8 |
* |
9 | 9 |
* Permission to use, modify and distribute this software is granted |
10 | 10 |
* provided that this copyright notice appears in all copies. For |
11 | 11 |
* precise terms see the accompanying LICENSE file. |
12 | 12 |
* |
13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
14 | 14 |
* express or implied, and with no claim as to its suitability for any |
15 | 15 |
* purpose. |
16 | 16 |
* |
17 | 17 |
*/ |
18 | 18 |
|
19 | 19 |
#include <iostream> |
20 | 20 |
#include <vector> |
21 | 21 |
#include <cstring> |
22 | 22 |
|
23 | 23 |
#include <lemon/cplex.h> |
24 | 24 |
|
25 | 25 |
extern "C" { |
26 | 26 |
#include <ilcplex/cplex.h> |
27 | 27 |
} |
28 | 28 |
|
29 | 29 |
|
30 | 30 |
///\file |
31 | 31 |
///\brief Implementation of the LEMON-CPLEX lp solver interface. |
32 | 32 |
namespace lemon { |
33 | 33 |
|
34 | 34 |
CplexEnv::LicenseError::LicenseError(int status) { |
35 | 35 |
if (!CPXgeterrorstring(0, status, _message)) { |
36 | 36 |
std::strcpy(_message, "Cplex unknown error"); |
37 | 37 |
} |
38 | 38 |
} |
39 | 39 |
|
40 | 40 |
CplexEnv::CplexEnv() { |
41 | 41 |
int status; |
42 | 42 |
_cnt = new int; |
43 | 43 |
_env = CPXopenCPLEX(&status); |
44 | 44 |
if (_env == 0) { |
45 | 45 |
delete _cnt; |
46 | 46 |
_cnt = 0; |
47 | 47 |
throw LicenseError(status); |
48 | 48 |
} |
49 | 49 |
} |
50 | 50 |
|
51 | 51 |
CplexEnv::CplexEnv(const CplexEnv& other) { |
52 | 52 |
_env = other._env; |
53 | 53 |
_cnt = other._cnt; |
54 | 54 |
++(*_cnt); |
55 | 55 |
} |
56 | 56 |
|
57 | 57 |
CplexEnv& CplexEnv::operator=(const CplexEnv& other) { |
58 | 58 |
_env = other._env; |
59 | 59 |
_cnt = other._cnt; |
60 | 60 |
++(*_cnt); |
61 | 61 |
return *this; |
62 | 62 |
} |
63 | 63 |
|
64 | 64 |
CplexEnv::~CplexEnv() { |
65 | 65 |
--(*_cnt); |
66 | 66 |
if (*_cnt == 0) { |
67 | 67 |
delete _cnt; |
68 | 68 |
CPXcloseCPLEX(&_env); |
69 | 69 |
} |
70 | 70 |
} |
71 | 71 |
|
72 | 72 |
CplexBase::CplexBase() : LpBase() { |
73 | 73 |
int status; |
74 | 74 |
_prob = CPXcreateprob(cplexEnv(), &status, "Cplex problem"); |
75 | 75 |
messageLevel(MESSAGE_NOTHING); |
76 | 76 |
} |
77 | 77 |
|
78 | 78 |
CplexBase::CplexBase(const CplexEnv& env) |
79 | 79 |
: LpBase(), _env(env) { |
80 | 80 |
int status; |
81 | 81 |
_prob = CPXcreateprob(cplexEnv(), &status, "Cplex problem"); |
82 | 82 |
messageLevel(MESSAGE_NOTHING); |
83 | 83 |
} |
84 | 84 |
|
85 | 85 |
CplexBase::CplexBase(const CplexBase& cplex) |
86 | 86 |
: LpBase() { |
87 | 87 |
int status; |
88 | 88 |
_prob = CPXcloneprob(cplexEnv(), cplex._prob, &status); |
89 | 89 |
rows = cplex.rows; |
90 | 90 |
cols = cplex.cols; |
91 | 91 |
messageLevel(MESSAGE_NOTHING); |
92 | 92 |
} |
93 | 93 |
|
94 | 94 |
CplexBase::~CplexBase() { |
95 | 95 |
CPXfreeprob(cplexEnv(),&_prob); |
96 | 96 |
} |
97 | 97 |
|
98 | 98 |
int CplexBase::_addCol() { |
99 | 99 |
int i = CPXgetnumcols(cplexEnv(), _prob); |
100 | 100 |
double lb = -INF, ub = INF; |
101 | 101 |
CPXnewcols(cplexEnv(), _prob, 1, 0, &lb, &ub, 0, 0); |
102 | 102 |
return i; |
103 | 103 |
} |
104 | 104 |
|
105 | 105 |
|
106 | 106 |
int CplexBase::_addRow() { |
107 | 107 |
int i = CPXgetnumrows(cplexEnv(), _prob); |
108 | 108 |
const double ub = INF; |
109 | 109 |
const char s = 'L'; |
110 | 110 |
CPXnewrows(cplexEnv(), _prob, 1, &ub, &s, 0, 0); |
111 | 111 |
return i; |
112 | 112 |
} |
113 | 113 |
|
114 |
int CplexBase::_addRow(Value lb, ExprIterator b, |
|
115 |
ExprIterator e, Value ub) { |
|
116 |
int i = CPXgetnumrows(cplexEnv(), _prob); |
|
117 |
if (lb == -INF) { |
|
118 |
const char s = 'L'; |
|
119 |
CPXnewrows(cplexEnv(), _prob, 1, &ub, &s, 0, 0); |
|
120 |
} else if (ub == INF) { |
|
121 |
const char s = 'G'; |
|
122 |
CPXnewrows(cplexEnv(), _prob, 1, &lb, &s, 0, 0); |
|
123 |
} else if (lb == ub){ |
|
124 |
const char s = 'E'; |
|
125 |
CPXnewrows(cplexEnv(), _prob, 1, &lb, &s, 0, 0); |
|
126 |
} else { |
|
127 |
const char s = 'R'; |
|
128 |
double len = ub - lb; |
|
129 |
CPXnewrows(cplexEnv(), _prob, 1, &lb, &s, &len, 0); |
|
130 |
} |
|
131 |
|
|
132 |
std::vector<int> indices; |
|
133 |
std::vector<int> rowlist; |
|
134 |
std::vector<Value> values; |
|
135 |
|
|
136 |
for(ExprIterator it=b; it!=e; ++it) { |
|
137 |
indices.push_back(it->first); |
|
138 |
values.push_back(it->second); |
|
139 |
rowlist.push_back(i); |
|
140 |
} |
|
141 |
|
|
142 |
CPXchgcoeflist(cplexEnv(), _prob, values.size(), |
|
143 |
&rowlist.front(), &indices.front(), &values.front()); |
|
144 |
|
|
145 |
return i; |
|
146 |
} |
|
114 | 147 |
|
115 | 148 |
void CplexBase::_eraseCol(int i) { |
116 | 149 |
CPXdelcols(cplexEnv(), _prob, i, i); |
117 | 150 |
} |
118 | 151 |
|
119 | 152 |
void CplexBase::_eraseRow(int i) { |
120 | 153 |
CPXdelrows(cplexEnv(), _prob, i, i); |
121 | 154 |
} |
122 | 155 |
|
123 | 156 |
void CplexBase::_eraseColId(int i) { |
124 | 157 |
cols.eraseIndex(i); |
125 | 158 |
cols.shiftIndices(i); |
126 | 159 |
} |
127 | 160 |
void CplexBase::_eraseRowId(int i) { |
128 | 161 |
rows.eraseIndex(i); |
129 | 162 |
rows.shiftIndices(i); |
130 | 163 |
} |
131 | 164 |
|
132 | 165 |
void CplexBase::_getColName(int col, std::string &name) const { |
133 | 166 |
int size; |
134 | 167 |
CPXgetcolname(cplexEnv(), _prob, 0, 0, 0, &size, col, col); |
135 | 168 |
if (size == 0) { |
136 | 169 |
name.clear(); |
137 | 170 |
return; |
138 | 171 |
} |
139 | 172 |
|
140 | 173 |
size *= -1; |
141 | 174 |
std::vector<char> buf(size); |
142 | 175 |
char *cname; |
143 | 176 |
int tmp; |
144 | 177 |
CPXgetcolname(cplexEnv(), _prob, &cname, &buf.front(), size, |
145 | 178 |
&tmp, col, col); |
146 | 179 |
name = cname; |
147 | 180 |
} |
148 | 181 |
|
149 | 182 |
void CplexBase::_setColName(int col, const std::string &name) { |
150 | 183 |
char *cname; |
151 | 184 |
cname = const_cast<char*>(name.c_str()); |
152 | 185 |
CPXchgcolname(cplexEnv(), _prob, 1, &col, &cname); |
153 | 186 |
} |
154 | 187 |
|
155 | 188 |
int CplexBase::_colByName(const std::string& name) const { |
156 | 189 |
int index; |
157 | 190 |
if (CPXgetcolindex(cplexEnv(), _prob, |
158 | 191 |
const_cast<char*>(name.c_str()), &index) == 0) { |
159 | 192 |
return index; |
160 | 193 |
} |
161 | 194 |
return -1; |
162 | 195 |
} |
163 | 196 |
|
164 | 197 |
void CplexBase::_getRowName(int row, std::string &name) const { |
165 | 198 |
int size; |
166 | 199 |
CPXgetrowname(cplexEnv(), _prob, 0, 0, 0, &size, row, row); |
167 | 200 |
if (size == 0) { |
168 | 201 |
name.clear(); |
169 | 202 |
return; |
170 | 203 |
} |
171 | 204 |
|
172 | 205 |
size *= -1; |
173 | 206 |
std::vector<char> buf(size); |
174 | 207 |
char *cname; |
175 | 208 |
int tmp; |
176 | 209 |
CPXgetrowname(cplexEnv(), _prob, &cname, &buf.front(), size, |
177 | 210 |
&tmp, row, row); |
178 | 211 |
name = cname; |
179 | 212 |
} |
180 | 213 |
|
181 | 214 |
void CplexBase::_setRowName(int row, const std::string &name) { |
182 | 215 |
char *cname; |
183 | 216 |
cname = const_cast<char*>(name.c_str()); |
184 | 217 |
CPXchgrowname(cplexEnv(), _prob, 1, &row, &cname); |
185 | 218 |
} |
186 | 219 |
|
187 | 220 |
int CplexBase::_rowByName(const std::string& name) const { |
188 | 221 |
int index; |
189 | 222 |
if (CPXgetrowindex(cplexEnv(), _prob, |
190 | 223 |
const_cast<char*>(name.c_str()), &index) == 0) { |
191 | 224 |
return index; |
192 | 225 |
} |
193 | 226 |
return -1; |
194 | 227 |
} |
195 | 228 |
|
196 | 229 |
void CplexBase::_setRowCoeffs(int i, ExprIterator b, |
197 | 230 |
ExprIterator e) |
198 | 231 |
{ |
199 | 232 |
std::vector<int> indices; |
200 | 233 |
std::vector<int> rowlist; |
201 | 234 |
std::vector<Value> values; |
202 | 235 |
|
203 | 236 |
for(ExprIterator it=b; it!=e; ++it) { |
204 | 237 |
indices.push_back(it->first); |
205 | 238 |
values.push_back(it->second); |
206 | 239 |
rowlist.push_back(i); |
207 | 240 |
} |
208 | 241 |
|
209 | 242 |
CPXchgcoeflist(cplexEnv(), _prob, values.size(), |
210 | 243 |
&rowlist.front(), &indices.front(), &values.front()); |
211 | 244 |
} |
212 | 245 |
|
213 | 246 |
void CplexBase::_getRowCoeffs(int i, InsertIterator b) const { |
214 | 247 |
int tmp1, tmp2, tmp3, length; |
215 | 248 |
CPXgetrows(cplexEnv(), _prob, &tmp1, &tmp2, 0, 0, 0, &length, i, i); |
216 | 249 |
|
217 | 250 |
length = -length; |
218 | 251 |
std::vector<int> indices(length); |
219 | 252 |
std::vector<double> values(length); |
220 | 253 |
|
221 | 254 |
CPXgetrows(cplexEnv(), _prob, &tmp1, &tmp2, |
222 | 255 |
&indices.front(), &values.front(), |
223 | 256 |
length, &tmp3, i, i); |
224 | 257 |
|
225 | 258 |
for (int i = 0; i < length; ++i) { |
226 | 259 |
*b = std::make_pair(indices[i], values[i]); |
227 | 260 |
++b; |
228 | 261 |
} |
229 | 262 |
} |
230 | 263 |
|
231 | 264 |
void CplexBase::_setColCoeffs(int i, ExprIterator b, ExprIterator e) { |
232 | 265 |
std::vector<int> indices; |
233 | 266 |
std::vector<int> collist; |
234 | 267 |
std::vector<Value> values; |
235 | 268 |
|
236 | 269 |
for(ExprIterator it=b; it!=e; ++it) { |
237 | 270 |
indices.push_back(it->first); |
238 | 271 |
values.push_back(it->second); |
239 | 272 |
collist.push_back(i); |
240 | 273 |
} |
241 | 274 |
|
242 | 275 |
CPXchgcoeflist(cplexEnv(), _prob, values.size(), |
243 | 276 |
&indices.front(), &collist.front(), &values.front()); |
244 | 277 |
} |
245 | 278 |
|
246 | 279 |
void CplexBase::_getColCoeffs(int i, InsertIterator b) const { |
247 | 280 |
|
248 | 281 |
int tmp1, tmp2, tmp3, length; |
249 | 282 |
CPXgetcols(cplexEnv(), _prob, &tmp1, &tmp2, 0, 0, 0, &length, i, i); |
250 | 283 |
|
251 | 284 |
length = -length; |
252 | 285 |
std::vector<int> indices(length); |
253 | 286 |
std::vector<double> values(length); |
254 | 287 |
|
255 | 288 |
CPXgetcols(cplexEnv(), _prob, &tmp1, &tmp2, |
256 | 289 |
&indices.front(), &values.front(), |
257 | 290 |
length, &tmp3, i, i); |
258 | 291 |
|
259 | 292 |
for (int i = 0; i < length; ++i) { |
260 | 293 |
*b = std::make_pair(indices[i], values[i]); |
261 | 294 |
++b; |
262 | 295 |
} |
263 | 296 |
|
264 | 297 |
} |
265 | 298 |
|
266 | 299 |
void CplexBase::_setCoeff(int row, int col, Value value) { |
267 | 300 |
CPXchgcoef(cplexEnv(), _prob, row, col, value); |
268 | 301 |
} |
269 | 302 |
|
270 | 303 |
CplexBase::Value CplexBase::_getCoeff(int row, int col) const { |
271 | 304 |
CplexBase::Value value; |
272 | 305 |
CPXgetcoef(cplexEnv(), _prob, row, col, &value); |
273 | 306 |
return value; |
274 | 307 |
} |
275 | 308 |
|
276 | 309 |
void CplexBase::_setColLowerBound(int i, Value value) { |
277 | 310 |
const char s = 'L'; |
278 | 311 |
CPXchgbds(cplexEnv(), _prob, 1, &i, &s, &value); |
279 | 312 |
} |
280 | 313 |
|
281 | 314 |
CplexBase::Value CplexBase::_getColLowerBound(int i) const { |
282 | 315 |
CplexBase::Value res; |
283 | 316 |
CPXgetlb(cplexEnv(), _prob, &res, i, i); |
284 | 317 |
return res <= -CPX_INFBOUND ? -INF : res; |
285 | 318 |
} |
286 | 319 |
|
287 | 320 |
void CplexBase::_setColUpperBound(int i, Value value) |
288 | 321 |
{ |
289 | 322 |
const char s = 'U'; |
290 | 323 |
CPXchgbds(cplexEnv(), _prob, 1, &i, &s, &value); |
291 | 324 |
} |
292 | 325 |
|
293 | 326 |
CplexBase::Value CplexBase::_getColUpperBound(int i) const { |
294 | 327 |
CplexBase::Value res; |
295 | 328 |
CPXgetub(cplexEnv(), _prob, &res, i, i); |
296 | 329 |
return res >= CPX_INFBOUND ? INF : res; |
297 | 330 |
} |
298 | 331 |
|
299 | 332 |
CplexBase::Value CplexBase::_getRowLowerBound(int i) const { |
300 | 333 |
char s; |
301 | 334 |
CPXgetsense(cplexEnv(), _prob, &s, i, i); |
302 | 335 |
CplexBase::Value res; |
303 | 336 |
|
304 | 337 |
switch (s) { |
305 | 338 |
case 'G': |
306 | 339 |
case 'R': |
307 | 340 |
case 'E': |
308 | 341 |
CPXgetrhs(cplexEnv(), _prob, &res, i, i); |
309 | 342 |
return res <= -CPX_INFBOUND ? -INF : res; |
310 | 343 |
default: |
311 | 344 |
return -INF; |
312 | 345 |
} |
313 | 346 |
} |
314 | 347 |
|
315 | 348 |
CplexBase::Value CplexBase::_getRowUpperBound(int i) const { |
316 | 349 |
char s; |
317 | 350 |
CPXgetsense(cplexEnv(), _prob, &s, i, i); |
318 | 351 |
CplexBase::Value res; |
319 | 352 |
|
320 | 353 |
switch (s) { |
321 | 354 |
case 'L': |
322 | 355 |
case 'E': |
323 | 356 |
CPXgetrhs(cplexEnv(), _prob, &res, i, i); |
324 | 357 |
return res >= CPX_INFBOUND ? INF : res; |
325 | 358 |
case 'R': |
326 | 359 |
CPXgetrhs(cplexEnv(), _prob, &res, i, i); |
327 | 360 |
{ |
328 | 361 |
double rng; |
329 | 362 |
CPXgetrngval(cplexEnv(), _prob, &rng, i, i); |
330 | 363 |
res += rng; |
331 | 364 |
} |
332 | 365 |
return res >= CPX_INFBOUND ? INF : res; |
333 | 366 |
default: |
334 | 367 |
return INF; |
335 | 368 |
} |
336 | 369 |
} |
337 | 370 |
|
338 | 371 |
//This is easier to implement |
339 | 372 |
void CplexBase::_set_row_bounds(int i, Value lb, Value ub) { |
340 | 373 |
if (lb == -INF) { |
341 | 374 |
const char s = 'L'; |
342 | 375 |
CPXchgsense(cplexEnv(), _prob, 1, &i, &s); |
343 | 376 |
CPXchgrhs(cplexEnv(), _prob, 1, &i, &ub); |
344 | 377 |
} else if (ub == INF) { |
345 | 378 |
const char s = 'G'; |
346 | 379 |
CPXchgsense(cplexEnv(), _prob, 1, &i, &s); |
347 | 380 |
CPXchgrhs(cplexEnv(), _prob, 1, &i, &lb); |
348 | 381 |
} else if (lb == ub){ |
349 | 382 |
const char s = 'E'; |
350 | 383 |
CPXchgsense(cplexEnv(), _prob, 1, &i, &s); |
351 | 384 |
CPXchgrhs(cplexEnv(), _prob, 1, &i, &lb); |
352 | 385 |
} else { |
353 | 386 |
const char s = 'R'; |
354 | 387 |
CPXchgsense(cplexEnv(), _prob, 1, &i, &s); |
355 | 388 |
CPXchgrhs(cplexEnv(), _prob, 1, &i, &lb); |
356 | 389 |
double len = ub - lb; |
357 | 390 |
CPXchgrngval(cplexEnv(), _prob, 1, &i, &len); |
358 | 391 |
} |
359 | 392 |
} |
360 | 393 |
|
361 | 394 |
void CplexBase::_setRowLowerBound(int i, Value lb) |
362 | 395 |
{ |
363 | 396 |
LEMON_ASSERT(lb != INF, "Invalid bound"); |
364 | 397 |
_set_row_bounds(i, lb, CplexBase::_getRowUpperBound(i)); |
365 | 398 |
} |
366 | 399 |
|
367 | 400 |
void CplexBase::_setRowUpperBound(int i, Value ub) |
368 | 401 |
{ |
369 | 402 |
1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
2 | 2 |
* |
3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2009 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
8 | 8 |
* |
9 | 9 |
* Permission to use, modify and distribute this software is granted |
10 | 10 |
* provided that this copyright notice appears in all copies. For |
11 | 11 |
* precise terms see the accompanying LICENSE file. |
12 | 12 |
* |
13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
14 | 14 |
* express or implied, and with no claim as to its suitability for any |
15 | 15 |
* purpose. |
16 | 16 |
* |
17 | 17 |
*/ |
18 | 18 |
|
19 | 19 |
#ifndef LEMON_CPLEX_H |
20 | 20 |
#define LEMON_CPLEX_H |
21 | 21 |
|
22 | 22 |
///\file |
23 | 23 |
///\brief Header of the LEMON-CPLEX lp solver interface. |
24 | 24 |
|
25 | 25 |
#include <lemon/lp_base.h> |
26 | 26 |
|
27 | 27 |
struct cpxenv; |
28 | 28 |
struct cpxlp; |
29 | 29 |
|
30 | 30 |
namespace lemon { |
31 | 31 |
|
32 | 32 |
/// \brief Reference counted wrapper around cpxenv pointer |
33 | 33 |
/// |
34 | 34 |
/// The cplex uses environment object which is responsible for |
35 | 35 |
/// checking the proper license usage. This class provides a simple |
36 | 36 |
/// interface for share the environment object between different |
37 | 37 |
/// problems. |
38 | 38 |
class CplexEnv { |
39 | 39 |
friend class CplexBase; |
40 | 40 |
private: |
41 | 41 |
cpxenv* _env; |
42 | 42 |
mutable int* _cnt; |
43 | 43 |
|
44 | 44 |
public: |
45 | 45 |
|
46 | 46 |
/// \brief This exception is thrown when the license check is not |
47 | 47 |
/// sufficient |
48 | 48 |
class LicenseError : public Exception { |
49 | 49 |
friend class CplexEnv; |
50 | 50 |
private: |
51 | 51 |
|
52 | 52 |
LicenseError(int status); |
53 | 53 |
char _message[510]; |
54 | 54 |
|
55 | 55 |
public: |
56 | 56 |
|
57 | 57 |
/// The short error message |
58 | 58 |
virtual const char* what() const throw() { |
59 | 59 |
return _message; |
60 | 60 |
} |
61 | 61 |
}; |
62 | 62 |
|
63 | 63 |
/// Constructor |
64 | 64 |
CplexEnv(); |
65 | 65 |
/// Shallow copy constructor |
66 | 66 |
CplexEnv(const CplexEnv&); |
67 | 67 |
/// Shallow assignement |
68 | 68 |
CplexEnv& operator=(const CplexEnv&); |
69 | 69 |
/// Destructor |
70 | 70 |
virtual ~CplexEnv(); |
71 | 71 |
|
72 | 72 |
protected: |
73 | 73 |
|
74 | 74 |
cpxenv* cplexEnv() { return _env; } |
75 | 75 |
const cpxenv* cplexEnv() const { return _env; } |
76 | 76 |
}; |
77 | 77 |
|
78 | 78 |
/// \brief Base interface for the CPLEX LP and MIP solver |
79 | 79 |
/// |
80 | 80 |
/// This class implements the common interface of the CPLEX LP and |
81 | 81 |
/// MIP solvers. |
82 | 82 |
/// \ingroup lp_group |
83 | 83 |
class CplexBase : virtual public LpBase { |
84 | 84 |
protected: |
85 | 85 |
|
86 | 86 |
CplexEnv _env; |
87 | 87 |
cpxlp* _prob; |
88 | 88 |
|
89 | 89 |
CplexBase(); |
90 | 90 |
CplexBase(const CplexEnv&); |
91 | 91 |
CplexBase(const CplexBase &); |
92 | 92 |
virtual ~CplexBase(); |
93 | 93 |
|
94 | 94 |
virtual int _addCol(); |
95 | 95 |
virtual int _addRow(); |
96 |
virtual int _addRow(Value l, ExprIterator b, ExprIterator e, Value u); |
|
96 | 97 |
|
97 | 98 |
virtual void _eraseCol(int i); |
98 | 99 |
virtual void _eraseRow(int i); |
99 | 100 |
|
100 | 101 |
virtual void _eraseColId(int i); |
101 | 102 |
virtual void _eraseRowId(int i); |
102 | 103 |
|
103 | 104 |
virtual void _getColName(int col, std::string& name) const; |
104 | 105 |
virtual void _setColName(int col, const std::string& name); |
105 | 106 |
virtual int _colByName(const std::string& name) const; |
106 | 107 |
|
107 | 108 |
virtual void _getRowName(int row, std::string& name) const; |
108 | 109 |
virtual void _setRowName(int row, const std::string& name); |
109 | 110 |
virtual int _rowByName(const std::string& name) const; |
110 | 111 |
|
111 | 112 |
virtual void _setRowCoeffs(int i, ExprIterator b, ExprIterator e); |
112 | 113 |
virtual void _getRowCoeffs(int i, InsertIterator b) const; |
113 | 114 |
|
114 | 115 |
virtual void _setColCoeffs(int i, ExprIterator b, ExprIterator e); |
115 | 116 |
virtual void _getColCoeffs(int i, InsertIterator b) const; |
116 | 117 |
|
117 | 118 |
virtual void _setCoeff(int row, int col, Value value); |
118 | 119 |
virtual Value _getCoeff(int row, int col) const; |
119 | 120 |
|
120 | 121 |
virtual void _setColLowerBound(int i, Value value); |
121 | 122 |
virtual Value _getColLowerBound(int i) const; |
122 | 123 |
|
123 | 124 |
virtual void _setColUpperBound(int i, Value value); |
124 | 125 |
virtual Value _getColUpperBound(int i) const; |
125 | 126 |
|
126 | 127 |
private: |
127 | 128 |
void _set_row_bounds(int i, Value lb, Value ub); |
128 | 129 |
protected: |
129 | 130 |
|
130 | 131 |
virtual void _setRowLowerBound(int i, Value value); |
131 | 132 |
virtual Value _getRowLowerBound(int i) const; |
132 | 133 |
|
133 | 134 |
virtual void _setRowUpperBound(int i, Value value); |
134 | 135 |
virtual Value _getRowUpperBound(int i) const; |
135 | 136 |
|
136 | 137 |
virtual void _setObjCoeffs(ExprIterator b, ExprIterator e); |
137 | 138 |
virtual void _getObjCoeffs(InsertIterator b) const; |
138 | 139 |
|
139 | 140 |
virtual void _setObjCoeff(int i, Value obj_coef); |
140 | 141 |
virtual Value _getObjCoeff(int i) const; |
141 | 142 |
|
142 | 143 |
virtual void _setSense(Sense sense); |
143 | 144 |
virtual Sense _getSense() const; |
144 | 145 |
|
145 | 146 |
virtual void _clear(); |
146 | 147 |
|
147 | 148 |
virtual void _messageLevel(MessageLevel level); |
148 | 149 |
void _applyMessageLevel(); |
149 | 150 |
|
150 | 151 |
bool _message_enabled; |
151 | 152 |
|
152 | 153 |
public: |
153 | 154 |
|
154 | 155 |
/// Returns the used \c CplexEnv instance |
155 | 156 |
const CplexEnv& env() const { return _env; } |
156 | 157 |
|
157 | 158 |
/// \brief Returns the const cpxenv pointer |
158 | 159 |
/// |
159 | 160 |
/// \note The cpxenv might be destructed with the solver. |
160 | 161 |
const cpxenv* cplexEnv() const { return _env.cplexEnv(); } |
161 | 162 |
|
162 | 163 |
/// \brief Returns the const cpxenv pointer |
163 | 164 |
/// |
164 | 165 |
/// \note The cpxenv might be destructed with the solver. |
165 | 166 |
cpxenv* cplexEnv() { return _env.cplexEnv(); } |
166 | 167 |
|
167 | 168 |
/// Returns the cplex problem object |
168 | 169 |
cpxlp* cplexLp() { return _prob; } |
169 | 170 |
/// Returns the cplex problem object |
170 | 171 |
const cpxlp* cplexLp() const { return _prob; } |
171 | 172 |
|
172 | 173 |
}; |
173 | 174 |
|
174 | 175 |
/// \brief Interface for the CPLEX LP solver |
175 | 176 |
/// |
176 | 177 |
/// This class implements an interface for the CPLEX LP solver. |
177 | 178 |
///\ingroup lp_group |
178 | 179 |
class CplexLp : public LpSolver, public CplexBase { |
179 | 180 |
public: |
180 | 181 |
/// \e |
181 | 182 |
CplexLp(); |
182 | 183 |
/// \e |
183 | 184 |
CplexLp(const CplexEnv&); |
184 | 185 |
/// \e |
185 | 186 |
CplexLp(const CplexLp&); |
186 | 187 |
/// \e |
187 | 188 |
virtual ~CplexLp(); |
188 | 189 |
|
189 | 190 |
/// \e |
190 | 191 |
virtual CplexLp* cloneSolver() const; |
191 | 192 |
/// \e |
192 | 193 |
virtual CplexLp* newSolver() const; |
193 | 194 |
|
194 | 195 |
private: |
195 | 196 |
|
196 | 197 |
// these values cannot retrieved element by element |
197 | 198 |
mutable std::vector<int> _col_status; |
198 | 199 |
mutable std::vector<int> _row_status; |
199 | 200 |
|
200 | 201 |
mutable std::vector<Value> _primal_ray; |
201 | 202 |
mutable std::vector<Value> _dual_ray; |
202 | 203 |
|
203 | 204 |
void _clear_temporals(); |
204 | 205 |
|
205 | 206 |
SolveExitStatus convertStatus(int status); |
206 | 207 |
|
207 | 208 |
protected: |
208 | 209 |
|
209 | 210 |
virtual const char* _solverName() const; |
210 | 211 |
|
211 | 212 |
virtual SolveExitStatus _solve(); |
212 | 213 |
virtual Value _getPrimal(int i) const; |
213 | 214 |
virtual Value _getDual(int i) const; |
214 | 215 |
virtual Value _getPrimalValue() const; |
215 | 216 |
|
216 | 217 |
virtual VarStatus _getColStatus(int i) const; |
217 | 218 |
virtual VarStatus _getRowStatus(int i) const; |
218 | 219 |
|
219 | 220 |
virtual Value _getPrimalRay(int i) const; |
220 | 221 |
virtual Value _getDualRay(int i) const; |
221 | 222 |
|
222 | 223 |
virtual ProblemType _getPrimalType() const; |
223 | 224 |
virtual ProblemType _getDualType() const; |
224 | 225 |
|
225 | 226 |
public: |
226 | 227 |
|
227 | 228 |
/// Solve with primal simplex method |
228 | 229 |
SolveExitStatus solvePrimal(); |
229 | 230 |
|
230 | 231 |
/// Solve with dual simplex method |
231 | 232 |
SolveExitStatus solveDual(); |
232 | 233 |
|
233 | 234 |
/// Solve with barrier method |
234 | 235 |
SolveExitStatus solveBarrier(); |
235 | 236 |
|
236 | 237 |
}; |
237 | 238 |
|
238 | 239 |
/// \brief Interface for the CPLEX MIP solver |
239 | 240 |
/// |
240 | 241 |
/// This class implements an interface for the CPLEX MIP solver. |
241 | 242 |
///\ingroup lp_group |
242 | 243 |
class CplexMip : public MipSolver, public CplexBase { |
243 | 244 |
public: |
244 | 245 |
/// \e |
245 | 246 |
CplexMip(); |
246 | 247 |
/// \e |
247 | 248 |
CplexMip(const CplexEnv&); |
248 | 249 |
/// \e |
249 | 250 |
CplexMip(const CplexMip&); |
250 | 251 |
/// \e |
251 | 252 |
virtual ~CplexMip(); |
252 | 253 |
|
253 | 254 |
/// \e |
254 | 255 |
virtual CplexMip* cloneSolver() const; |
255 | 256 |
/// \e |
256 | 257 |
virtual CplexMip* newSolver() const; |
257 | 258 |
|
258 | 259 |
protected: |
259 | 260 |
|
260 | 261 |
|
261 | 262 |
virtual const char* _solverName() const; |
262 | 263 |
|
263 | 264 |
virtual ColTypes _getColType(int col) const; |
264 | 265 |
virtual void _setColType(int col, ColTypes col_type); |
265 | 266 |
|
266 | 267 |
virtual SolveExitStatus _solve(); |
267 | 268 |
virtual ProblemType _getType() const; |
268 | 269 |
virtual Value _getSol(int i) const; |
269 | 270 |
virtual Value _getSolValue() const; |
270 | 271 |
|
271 | 272 |
}; |
272 | 273 |
|
273 | 274 |
} //END OF NAMESPACE LEMON |
274 | 275 |
|
275 | 276 |
#endif //LEMON_CPLEX_H |
276 | 277 |
... | ... |
@@ -614,803 +614,803 @@ |
614 | 614 |
} |
615 | 615 |
|
616 | 616 |
static Arc direct(Edge edge, bool dir) { |
617 | 617 |
return Arc(edge.id * 2 + (dir ? 1 : 0)); |
618 | 618 |
} |
619 | 619 |
|
620 | 620 |
int id(const Node& node) const { return _graph->id(node); } |
621 | 621 |
static int id(Arc e) { return e.id; } |
622 | 622 |
static int id(Edge e) { return e.id; } |
623 | 623 |
|
624 | 624 |
Node nodeFromId(int id) const { return _graph->nodeFromId(id); } |
625 | 625 |
static Arc arcFromId(int id) { return Arc(id);} |
626 | 626 |
static Edge edgeFromId(int id) { return Edge(id);} |
627 | 627 |
|
628 | 628 |
int maxNodeId() const { return _graph->maxNodeId(); }; |
629 | 629 |
int maxEdgeId() const { return arcs.size() / 2 - 1; } |
630 | 630 |
int maxArcId() const { return arcs.size()-1; } |
631 | 631 |
|
632 | 632 |
Node source(Arc e) const { return arcs[e.id ^ 1].target; } |
633 | 633 |
Node target(Arc e) const { return arcs[e.id].target; } |
634 | 634 |
|
635 | 635 |
Node u(Edge e) const { return arcs[2 * e.id].target; } |
636 | 636 |
Node v(Edge e) const { return arcs[2 * e.id + 1].target; } |
637 | 637 |
|
638 | 638 |
typedef typename ItemSetTraits<GR, Node>::ItemNotifier NodeNotifier; |
639 | 639 |
|
640 | 640 |
NodeNotifier& notifier(Node) const { |
641 | 641 |
return _graph->notifier(Node()); |
642 | 642 |
} |
643 | 643 |
|
644 | 644 |
template <typename V> |
645 | 645 |
class NodeMap : public GR::template NodeMap<V> { |
646 | 646 |
typedef typename GR::template NodeMap<V> Parent; |
647 | 647 |
|
648 | 648 |
public: |
649 | 649 |
|
650 | 650 |
explicit NodeMap(const ListEdgeSetBase<GR>& arcset) |
651 | 651 |
: Parent(*arcset._graph) {} |
652 | 652 |
|
653 | 653 |
NodeMap(const ListEdgeSetBase<GR>& arcset, const V& value) |
654 | 654 |
: Parent(*arcset._graph, value) {} |
655 | 655 |
|
656 | 656 |
NodeMap& operator=(const NodeMap& cmap) { |
657 | 657 |
return operator=<NodeMap>(cmap); |
658 | 658 |
} |
659 | 659 |
|
660 | 660 |
template <typename CMap> |
661 | 661 |
NodeMap& operator=(const CMap& cmap) { |
662 | 662 |
Parent::operator=(cmap); |
663 | 663 |
return *this; |
664 | 664 |
} |
665 | 665 |
}; |
666 | 666 |
|
667 | 667 |
}; |
668 | 668 |
|
669 | 669 |
/// \ingroup graphs |
670 | 670 |
/// |
671 | 671 |
/// \brief Graph using a node set of another digraph or graph and an |
672 | 672 |
/// own edge set. |
673 | 673 |
/// |
674 | 674 |
/// This structure can be used to establish another graph over a |
675 | 675 |
/// node set of an existing one. This class uses the same Node type |
676 | 676 |
/// as the underlying graph, and each valid node of the original |
677 | 677 |
/// graph is valid in this arc set, therefore the node objects of |
678 | 678 |
/// the original graph can be used directly with this class. The |
679 | 679 |
/// node handling functions (id handling, observing, and iterators) |
680 | 680 |
/// works equivalently as in the original graph. |
681 | 681 |
/// |
682 | 682 |
/// This implementation is based on doubly-linked lists, from each |
683 | 683 |
/// node the incident edges make up lists, therefore one edge can be |
684 | 684 |
/// erased in constant time. It also makes possible, that node can |
685 | 685 |
/// be removed from the underlying graph, in this case all edges |
686 | 686 |
/// incident to the given node is erased from the arc set. |
687 | 687 |
/// |
688 | 688 |
/// \param GR The type of the graph which shares its node set |
689 | 689 |
/// with this class. Its interface must conform to the |
690 | 690 |
/// \ref concepts::Digraph "Digraph" or \ref concepts::Graph "Graph" |
691 | 691 |
/// concept. |
692 | 692 |
/// |
693 | 693 |
/// This class fully conforms to the \ref concepts::Graph "Graph" |
694 | 694 |
/// concept. |
695 | 695 |
template <typename GR> |
696 | 696 |
class ListEdgeSet : public EdgeSetExtender<ListEdgeSetBase<GR> > { |
697 | 697 |
typedef EdgeSetExtender<ListEdgeSetBase<GR> > Parent; |
698 | 698 |
|
699 | 699 |
public: |
700 | 700 |
|
701 | 701 |
typedef typename Parent::Node Node; |
702 | 702 |
typedef typename Parent::Arc Arc; |
703 | 703 |
typedef typename Parent::Edge Edge; |
704 | 704 |
|
705 | 705 |
typedef typename Parent::NodesImplBase NodesImplBase; |
706 | 706 |
|
707 | 707 |
void eraseNode(const Node& node) { |
708 | 708 |
Arc arc; |
709 | 709 |
Parent::firstOut(arc, node); |
710 | 710 |
while (arc != INVALID ) { |
711 | 711 |
erase(arc); |
712 | 712 |
Parent::firstOut(arc, node); |
713 | 713 |
} |
714 | 714 |
|
715 | 715 |
} |
716 | 716 |
|
717 | 717 |
void clearNodes() { |
718 | 718 |
Parent::clear(); |
719 | 719 |
} |
720 | 720 |
|
721 | 721 |
class NodesImpl : public NodesImplBase { |
722 | 722 |
typedef NodesImplBase Parent; |
723 | 723 |
|
724 | 724 |
public: |
725 | 725 |
NodesImpl(const GR& graph, ListEdgeSet& arcset) |
726 | 726 |
: Parent(graph), _arcset(arcset) {} |
727 | 727 |
|
728 | 728 |
virtual ~NodesImpl() {} |
729 | 729 |
|
730 | 730 |
protected: |
731 | 731 |
|
732 | 732 |
virtual void erase(const Node& node) { |
733 | 733 |
_arcset.eraseNode(node); |
734 | 734 |
Parent::erase(node); |
735 | 735 |
} |
736 | 736 |
virtual void erase(const std::vector<Node>& nodes) { |
737 | 737 |
for (int i = 0; i < int(nodes.size()); ++i) { |
738 | 738 |
_arcset.eraseNode(nodes[i]); |
739 | 739 |
} |
740 | 740 |
Parent::erase(nodes); |
741 | 741 |
} |
742 | 742 |
virtual void clear() { |
743 | 743 |
_arcset.clearNodes(); |
744 | 744 |
Parent::clear(); |
745 | 745 |
} |
746 | 746 |
|
747 | 747 |
private: |
748 | 748 |
ListEdgeSet& _arcset; |
749 | 749 |
}; |
750 | 750 |
|
751 | 751 |
NodesImpl _nodes; |
752 | 752 |
|
753 | 753 |
public: |
754 | 754 |
|
755 | 755 |
/// \brief Constructor of the EdgeSet. |
756 | 756 |
/// |
757 | 757 |
/// Constructor of the EdgeSet. |
758 | 758 |
ListEdgeSet(const GR& graph) : _nodes(graph, *this) { |
759 | 759 |
Parent::initalize(graph, _nodes); |
760 | 760 |
} |
761 | 761 |
|
762 | 762 |
/// \brief Add a new edge to the graph. |
763 | 763 |
/// |
764 | 764 |
/// Add a new edge to the graph with node \c u |
765 | 765 |
/// and node \c v endpoints. |
766 | 766 |
/// \return The new edge. |
767 | 767 |
Edge addEdge(const Node& u, const Node& v) { |
768 | 768 |
return Parent::addEdge(u, v); |
769 | 769 |
} |
770 | 770 |
|
771 | 771 |
/// \brief Erase an edge from the graph. |
772 | 772 |
/// |
773 | 773 |
/// Erase the edge \c e from the graph. |
774 | 774 |
void erase(const Edge& e) { |
775 | 775 |
return Parent::erase(e); |
776 | 776 |
} |
777 | 777 |
|
778 | 778 |
}; |
779 | 779 |
|
780 | 780 |
template <typename GR> |
781 | 781 |
class SmartArcSetBase { |
782 | 782 |
public: |
783 | 783 |
|
784 | 784 |
typedef typename GR::Node Node; |
785 | 785 |
typedef typename GR::NodeIt NodeIt; |
786 | 786 |
|
787 | 787 |
protected: |
788 | 788 |
|
789 | 789 |
struct NodeT { |
790 | 790 |
int first_out, first_in; |
791 | 791 |
NodeT() : first_out(-1), first_in(-1) {} |
792 | 792 |
}; |
793 | 793 |
|
794 | 794 |
typedef typename ItemSetTraits<GR, Node>:: |
795 | 795 |
template Map<NodeT>::Type NodesImplBase; |
796 | 796 |
|
797 | 797 |
NodesImplBase* _nodes; |
798 | 798 |
|
799 | 799 |
struct ArcT { |
800 | 800 |
Node source, target; |
801 | 801 |
int next_out, next_in; |
802 | 802 |
ArcT() {} |
803 | 803 |
}; |
804 | 804 |
|
805 | 805 |
std::vector<ArcT> arcs; |
806 | 806 |
|
807 | 807 |
const GR* _graph; |
808 | 808 |
|
809 | 809 |
void initalize(const GR& graph, NodesImplBase& nodes) { |
810 | 810 |
_graph = &graph; |
811 | 811 |
_nodes = &nodes; |
812 | 812 |
} |
813 | 813 |
|
814 | 814 |
public: |
815 | 815 |
|
816 | 816 |
class Arc { |
817 | 817 |
friend class SmartArcSetBase<GR>; |
818 | 818 |
protected: |
819 | 819 |
Arc(int _id) : id(_id) {} |
820 | 820 |
int id; |
821 | 821 |
public: |
822 | 822 |
Arc() {} |
823 | 823 |
Arc(Invalid) : id(-1) {} |
824 | 824 |
bool operator==(const Arc& arc) const { return id == arc.id; } |
825 | 825 |
bool operator!=(const Arc& arc) const { return id != arc.id; } |
826 | 826 |
bool operator<(const Arc& arc) const { return id < arc.id; } |
827 | 827 |
}; |
828 | 828 |
|
829 | 829 |
SmartArcSetBase() {} |
830 | 830 |
|
831 | 831 |
Node addNode() { |
832 | 832 |
LEMON_ASSERT(false, |
833 | 833 |
"This graph structure does not support node insertion"); |
834 | 834 |
return INVALID; // avoid warning |
835 | 835 |
} |
836 | 836 |
|
837 | 837 |
Arc addArc(const Node& u, const Node& v) { |
838 | 838 |
int n = arcs.size(); |
839 | 839 |
arcs.push_back(ArcT()); |
840 | 840 |
arcs[n].next_in = (*_nodes)[v].first_in; |
841 | 841 |
(*_nodes)[v].first_in = n; |
842 | 842 |
arcs[n].next_out = (*_nodes)[u].first_out; |
843 | 843 |
(*_nodes)[u].first_out = n; |
844 | 844 |
arcs[n].source = u; |
845 | 845 |
arcs[n].target = v; |
846 | 846 |
return Arc(n); |
847 | 847 |
} |
848 | 848 |
|
849 | 849 |
void clear() { |
850 | 850 |
Node node; |
851 | 851 |
for (first(node); node != INVALID; next(node)) { |
852 | 852 |
(*_nodes)[node].first_in = -1; |
853 | 853 |
(*_nodes)[node].first_out = -1; |
854 | 854 |
} |
855 | 855 |
arcs.clear(); |
856 | 856 |
} |
857 | 857 |
|
858 | 858 |
void first(Node& node) const { |
859 | 859 |
_graph->first(node); |
860 | 860 |
} |
861 | 861 |
|
862 | 862 |
void next(Node& node) const { |
863 | 863 |
_graph->next(node); |
864 | 864 |
} |
865 | 865 |
|
866 | 866 |
void first(Arc& arc) const { |
867 | 867 |
arc.id = arcs.size() - 1; |
868 | 868 |
} |
869 | 869 |
|
870 |
void next(Arc& arc) |
|
870 |
static void next(Arc& arc) { |
|
871 | 871 |
--arc.id; |
872 | 872 |
} |
873 | 873 |
|
874 | 874 |
void firstOut(Arc& arc, const Node& node) const { |
875 | 875 |
arc.id = (*_nodes)[node].first_out; |
876 | 876 |
} |
877 | 877 |
|
878 | 878 |
void nextOut(Arc& arc) const { |
879 | 879 |
arc.id = arcs[arc.id].next_out; |
880 | 880 |
} |
881 | 881 |
|
882 | 882 |
void firstIn(Arc& arc, const Node& node) const { |
883 | 883 |
arc.id = (*_nodes)[node].first_in; |
884 | 884 |
} |
885 | 885 |
|
886 | 886 |
void nextIn(Arc& arc) const { |
887 | 887 |
arc.id = arcs[arc.id].next_in; |
888 | 888 |
} |
889 | 889 |
|
890 | 890 |
int id(const Node& node) const { return _graph->id(node); } |
891 | 891 |
int id(const Arc& arc) const { return arc.id; } |
892 | 892 |
|
893 | 893 |
Node nodeFromId(int ix) const { return _graph->nodeFromId(ix); } |
894 | 894 |
Arc arcFromId(int ix) const { return Arc(ix); } |
895 | 895 |
|
896 | 896 |
int maxNodeId() const { return _graph->maxNodeId(); }; |
897 | 897 |
int maxArcId() const { return arcs.size() - 1; } |
898 | 898 |
|
899 | 899 |
Node source(const Arc& arc) const { return arcs[arc.id].source;} |
900 | 900 |
Node target(const Arc& arc) const { return arcs[arc.id].target;} |
901 | 901 |
|
902 | 902 |
typedef typename ItemSetTraits<GR, Node>::ItemNotifier NodeNotifier; |
903 | 903 |
|
904 | 904 |
NodeNotifier& notifier(Node) const { |
905 | 905 |
return _graph->notifier(Node()); |
906 | 906 |
} |
907 | 907 |
|
908 | 908 |
template <typename V> |
909 | 909 |
class NodeMap : public GR::template NodeMap<V> { |
910 | 910 |
typedef typename GR::template NodeMap<V> Parent; |
911 | 911 |
|
912 | 912 |
public: |
913 | 913 |
|
914 | 914 |
explicit NodeMap(const SmartArcSetBase<GR>& arcset) |
915 | 915 |
: Parent(*arcset._graph) { } |
916 | 916 |
|
917 | 917 |
NodeMap(const SmartArcSetBase<GR>& arcset, const V& value) |
918 | 918 |
: Parent(*arcset._graph, value) { } |
919 | 919 |
|
920 | 920 |
NodeMap& operator=(const NodeMap& cmap) { |
921 | 921 |
return operator=<NodeMap>(cmap); |
922 | 922 |
} |
923 | 923 |
|
924 | 924 |
template <typename CMap> |
925 | 925 |
NodeMap& operator=(const CMap& cmap) { |
926 | 926 |
Parent::operator=(cmap); |
927 | 927 |
return *this; |
928 | 928 |
} |
929 | 929 |
}; |
930 | 930 |
|
931 | 931 |
}; |
932 | 932 |
|
933 | 933 |
|
934 | 934 |
/// \ingroup graphs |
935 | 935 |
/// |
936 | 936 |
/// \brief Digraph using a node set of another digraph or graph and |
937 | 937 |
/// an own arc set. |
938 | 938 |
/// |
939 | 939 |
/// This structure can be used to establish another directed graph |
940 | 940 |
/// over a node set of an existing one. This class uses the same |
941 | 941 |
/// Node type as the underlying graph, and each valid node of the |
942 | 942 |
/// original graph is valid in this arc set, therefore the node |
943 | 943 |
/// objects of the original graph can be used directly with this |
944 | 944 |
/// class. The node handling functions (id handling, observing, and |
945 | 945 |
/// iterators) works equivalently as in the original graph. |
946 | 946 |
/// |
947 | 947 |
/// \param GR The type of the graph which shares its node set with |
948 | 948 |
/// this class. Its interface must conform to the |
949 | 949 |
/// \ref concepts::Digraph "Digraph" or \ref concepts::Graph "Graph" |
950 | 950 |
/// concept. |
951 | 951 |
/// |
952 | 952 |
/// This implementation is slightly faster than the \c ListArcSet, |
953 | 953 |
/// because it uses continuous storage for arcs and it uses just |
954 | 954 |
/// single-linked lists for enumerate outgoing and incoming |
955 | 955 |
/// arcs. Therefore the arcs cannot be erased from the arc sets. |
956 | 956 |
/// |
957 | 957 |
/// \warning If a node is erased from the underlying graph and this |
958 | 958 |
/// node is the source or target of one arc in the arc set, then |
959 | 959 |
/// the arc set is invalidated, and it cannot be used anymore. The |
960 | 960 |
/// validity can be checked with the \c valid() member function. |
961 | 961 |
/// |
962 | 962 |
/// This class fully conforms to the \ref concepts::Digraph |
963 | 963 |
/// "Digraph" concept. |
964 | 964 |
template <typename GR> |
965 | 965 |
class SmartArcSet : public ArcSetExtender<SmartArcSetBase<GR> > { |
966 | 966 |
typedef ArcSetExtender<SmartArcSetBase<GR> > Parent; |
967 | 967 |
|
968 | 968 |
public: |
969 | 969 |
|
970 | 970 |
typedef typename Parent::Node Node; |
971 | 971 |
typedef typename Parent::Arc Arc; |
972 | 972 |
|
973 | 973 |
protected: |
974 | 974 |
|
975 | 975 |
typedef typename Parent::NodesImplBase NodesImplBase; |
976 | 976 |
|
977 | 977 |
void eraseNode(const Node& node) { |
978 | 978 |
if (typename Parent::InArcIt(*this, node) == INVALID && |
979 | 979 |
typename Parent::OutArcIt(*this, node) == INVALID) { |
980 | 980 |
return; |
981 | 981 |
} |
982 | 982 |
throw typename NodesImplBase::Notifier::ImmediateDetach(); |
983 | 983 |
} |
984 | 984 |
|
985 | 985 |
void clearNodes() { |
986 | 986 |
Parent::clear(); |
987 | 987 |
} |
988 | 988 |
|
989 | 989 |
class NodesImpl : public NodesImplBase { |
990 | 990 |
typedef NodesImplBase Parent; |
991 | 991 |
|
992 | 992 |
public: |
993 | 993 |
NodesImpl(const GR& graph, SmartArcSet& arcset) |
994 | 994 |
: Parent(graph), _arcset(arcset) {} |
995 | 995 |
|
996 | 996 |
virtual ~NodesImpl() {} |
997 | 997 |
|
998 | 998 |
bool attached() const { |
999 | 999 |
return Parent::attached(); |
1000 | 1000 |
} |
1001 | 1001 |
|
1002 | 1002 |
protected: |
1003 | 1003 |
|
1004 | 1004 |
virtual void erase(const Node& node) { |
1005 | 1005 |
try { |
1006 | 1006 |
_arcset.eraseNode(node); |
1007 | 1007 |
Parent::erase(node); |
1008 | 1008 |
} catch (const typename NodesImplBase::Notifier::ImmediateDetach&) { |
1009 | 1009 |
Parent::clear(); |
1010 | 1010 |
throw; |
1011 | 1011 |
} |
1012 | 1012 |
} |
1013 | 1013 |
virtual void erase(const std::vector<Node>& nodes) { |
1014 | 1014 |
try { |
1015 | 1015 |
for (int i = 0; i < int(nodes.size()); ++i) { |
1016 | 1016 |
_arcset.eraseNode(nodes[i]); |
1017 | 1017 |
} |
1018 | 1018 |
Parent::erase(nodes); |
1019 | 1019 |
} catch (const typename NodesImplBase::Notifier::ImmediateDetach&) { |
1020 | 1020 |
Parent::clear(); |
1021 | 1021 |
throw; |
1022 | 1022 |
} |
1023 | 1023 |
} |
1024 | 1024 |
virtual void clear() { |
1025 | 1025 |
_arcset.clearNodes(); |
1026 | 1026 |
Parent::clear(); |
1027 | 1027 |
} |
1028 | 1028 |
|
1029 | 1029 |
private: |
1030 | 1030 |
SmartArcSet& _arcset; |
1031 | 1031 |
}; |
1032 | 1032 |
|
1033 | 1033 |
NodesImpl _nodes; |
1034 | 1034 |
|
1035 | 1035 |
public: |
1036 | 1036 |
|
1037 | 1037 |
/// \brief Constructor of the ArcSet. |
1038 | 1038 |
/// |
1039 | 1039 |
/// Constructor of the ArcSet. |
1040 | 1040 |
SmartArcSet(const GR& graph) : _nodes(graph, *this) { |
1041 | 1041 |
Parent::initalize(graph, _nodes); |
1042 | 1042 |
} |
1043 | 1043 |
|
1044 | 1044 |
/// \brief Add a new arc to the digraph. |
1045 | 1045 |
/// |
1046 | 1046 |
/// Add a new arc to the digraph with source node \c s |
1047 | 1047 |
/// and target node \c t. |
1048 | 1048 |
/// \return The new arc. |
1049 | 1049 |
Arc addArc(const Node& s, const Node& t) { |
1050 | 1050 |
return Parent::addArc(s, t); |
1051 | 1051 |
} |
1052 | 1052 |
|
1053 | 1053 |
/// \brief Validity check |
1054 | 1054 |
/// |
1055 | 1055 |
/// This functions gives back false if the ArcSet is |
1056 | 1056 |
/// invalidated. It occurs when a node in the underlying graph is |
1057 | 1057 |
/// erased and it is not isolated in the ArcSet. |
1058 | 1058 |
bool valid() const { |
1059 | 1059 |
return _nodes.attached(); |
1060 | 1060 |
} |
1061 | 1061 |
|
1062 | 1062 |
}; |
1063 | 1063 |
|
1064 | 1064 |
|
1065 | 1065 |
template <typename GR> |
1066 | 1066 |
class SmartEdgeSetBase { |
1067 | 1067 |
public: |
1068 | 1068 |
|
1069 | 1069 |
typedef typename GR::Node Node; |
1070 | 1070 |
typedef typename GR::NodeIt NodeIt; |
1071 | 1071 |
|
1072 | 1072 |
protected: |
1073 | 1073 |
|
1074 | 1074 |
struct NodeT { |
1075 | 1075 |
int first_out; |
1076 | 1076 |
NodeT() : first_out(-1) {} |
1077 | 1077 |
}; |
1078 | 1078 |
|
1079 | 1079 |
typedef typename ItemSetTraits<GR, Node>:: |
1080 | 1080 |
template Map<NodeT>::Type NodesImplBase; |
1081 | 1081 |
|
1082 | 1082 |
NodesImplBase* _nodes; |
1083 | 1083 |
|
1084 | 1084 |
struct ArcT { |
1085 | 1085 |
Node target; |
1086 | 1086 |
int next_out; |
1087 | 1087 |
ArcT() {} |
1088 | 1088 |
}; |
1089 | 1089 |
|
1090 | 1090 |
std::vector<ArcT> arcs; |
1091 | 1091 |
|
1092 | 1092 |
const GR* _graph; |
1093 | 1093 |
|
1094 | 1094 |
void initalize(const GR& graph, NodesImplBase& nodes) { |
1095 | 1095 |
_graph = &graph; |
1096 | 1096 |
_nodes = &nodes; |
1097 | 1097 |
} |
1098 | 1098 |
|
1099 | 1099 |
public: |
1100 | 1100 |
|
1101 | 1101 |
class Edge { |
1102 | 1102 |
friend class SmartEdgeSetBase; |
1103 | 1103 |
protected: |
1104 | 1104 |
|
1105 | 1105 |
int id; |
1106 | 1106 |
explicit Edge(int _id) { id = _id;} |
1107 | 1107 |
|
1108 | 1108 |
public: |
1109 | 1109 |
Edge() {} |
1110 | 1110 |
Edge (Invalid) { id = -1; } |
1111 | 1111 |
bool operator==(const Edge& arc) const {return id == arc.id;} |
1112 | 1112 |
bool operator!=(const Edge& arc) const {return id != arc.id;} |
1113 | 1113 |
bool operator<(const Edge& arc) const {return id < arc.id;} |
1114 | 1114 |
}; |
1115 | 1115 |
|
1116 | 1116 |
class Arc { |
1117 | 1117 |
friend class SmartEdgeSetBase; |
1118 | 1118 |
protected: |
1119 | 1119 |
Arc(int _id) : id(_id) {} |
1120 | 1120 |
int id; |
1121 | 1121 |
public: |
1122 | 1122 |
operator Edge() const { return edgeFromId(id / 2); } |
1123 | 1123 |
|
1124 | 1124 |
Arc() {} |
1125 | 1125 |
Arc(Invalid) : id(-1) {} |
1126 | 1126 |
bool operator==(const Arc& arc) const { return id == arc.id; } |
1127 | 1127 |
bool operator!=(const Arc& arc) const { return id != arc.id; } |
1128 | 1128 |
bool operator<(const Arc& arc) const { return id < arc.id; } |
1129 | 1129 |
}; |
1130 | 1130 |
|
1131 | 1131 |
SmartEdgeSetBase() {} |
1132 | 1132 |
|
1133 | 1133 |
Node addNode() { |
1134 | 1134 |
LEMON_ASSERT(false, |
1135 | 1135 |
"This graph structure does not support node insertion"); |
1136 | 1136 |
return INVALID; // avoid warning |
1137 | 1137 |
} |
1138 | 1138 |
|
1139 | 1139 |
Edge addEdge(const Node& u, const Node& v) { |
1140 | 1140 |
int n = arcs.size(); |
1141 | 1141 |
arcs.push_back(ArcT()); |
1142 | 1142 |
arcs.push_back(ArcT()); |
1143 | 1143 |
|
1144 | 1144 |
arcs[n].target = u; |
1145 | 1145 |
arcs[n | 1].target = v; |
1146 | 1146 |
|
1147 | 1147 |
arcs[n].next_out = (*_nodes)[v].first_out; |
1148 | 1148 |
(*_nodes)[v].first_out = n; |
1149 | 1149 |
|
1150 | 1150 |
arcs[n | 1].next_out = (*_nodes)[u].first_out; |
1151 | 1151 |
(*_nodes)[u].first_out = (n | 1); |
1152 | 1152 |
|
1153 | 1153 |
return Edge(n / 2); |
1154 | 1154 |
} |
1155 | 1155 |
|
1156 | 1156 |
void clear() { |
1157 | 1157 |
Node node; |
1158 | 1158 |
for (first(node); node != INVALID; next(node)) { |
1159 | 1159 |
(*_nodes)[node].first_out = -1; |
1160 | 1160 |
} |
1161 | 1161 |
arcs.clear(); |
1162 | 1162 |
} |
1163 | 1163 |
|
1164 | 1164 |
void first(Node& node) const { |
1165 | 1165 |
_graph->first(node); |
1166 | 1166 |
} |
1167 | 1167 |
|
1168 | 1168 |
void next(Node& node) const { |
1169 | 1169 |
_graph->next(node); |
1170 | 1170 |
} |
1171 | 1171 |
|
1172 | 1172 |
void first(Arc& arc) const { |
1173 | 1173 |
arc.id = arcs.size() - 1; |
1174 | 1174 |
} |
1175 | 1175 |
|
1176 |
void next(Arc& arc) |
|
1176 |
static void next(Arc& arc) { |
|
1177 | 1177 |
--arc.id; |
1178 | 1178 |
} |
1179 | 1179 |
|
1180 | 1180 |
void first(Edge& arc) const { |
1181 | 1181 |
arc.id = arcs.size() / 2 - 1; |
1182 | 1182 |
} |
1183 | 1183 |
|
1184 |
void next(Edge& arc) |
|
1184 |
static void next(Edge& arc) { |
|
1185 | 1185 |
--arc.id; |
1186 | 1186 |
} |
1187 | 1187 |
|
1188 | 1188 |
void firstOut(Arc& arc, const Node& node) const { |
1189 | 1189 |
arc.id = (*_nodes)[node].first_out; |
1190 | 1190 |
} |
1191 | 1191 |
|
1192 | 1192 |
void nextOut(Arc& arc) const { |
1193 | 1193 |
arc.id = arcs[arc.id].next_out; |
1194 | 1194 |
} |
1195 | 1195 |
|
1196 | 1196 |
void firstIn(Arc& arc, const Node& node) const { |
1197 | 1197 |
arc.id = (((*_nodes)[node].first_out) ^ 1); |
1198 | 1198 |
if (arc.id == -2) arc.id = -1; |
1199 | 1199 |
} |
1200 | 1200 |
|
1201 | 1201 |
void nextIn(Arc& arc) const { |
1202 | 1202 |
arc.id = ((arcs[arc.id ^ 1].next_out) ^ 1); |
1203 | 1203 |
if (arc.id == -2) arc.id = -1; |
1204 | 1204 |
} |
1205 | 1205 |
|
1206 | 1206 |
void firstInc(Edge &arc, bool& dir, const Node& node) const { |
1207 | 1207 |
int de = (*_nodes)[node].first_out; |
1208 | 1208 |
if (de != -1 ) { |
1209 | 1209 |
arc.id = de / 2; |
1210 | 1210 |
dir = ((de & 1) == 1); |
1211 | 1211 |
} else { |
1212 | 1212 |
arc.id = -1; |
1213 | 1213 |
dir = true; |
1214 | 1214 |
} |
1215 | 1215 |
} |
1216 | 1216 |
void nextInc(Edge &arc, bool& dir) const { |
1217 | 1217 |
int de = (arcs[(arc.id * 2) | (dir ? 1 : 0)].next_out); |
1218 | 1218 |
if (de != -1 ) { |
1219 | 1219 |
arc.id = de / 2; |
1220 | 1220 |
dir = ((de & 1) == 1); |
1221 | 1221 |
} else { |
1222 | 1222 |
arc.id = -1; |
1223 | 1223 |
dir = true; |
1224 | 1224 |
} |
1225 | 1225 |
} |
1226 | 1226 |
|
1227 | 1227 |
static bool direction(Arc arc) { |
1228 | 1228 |
return (arc.id & 1) == 1; |
1229 | 1229 |
} |
1230 | 1230 |
|
1231 | 1231 |
static Arc direct(Edge edge, bool dir) { |
1232 | 1232 |
return Arc(edge.id * 2 + (dir ? 1 : 0)); |
1233 | 1233 |
} |
1234 | 1234 |
|
1235 | 1235 |
int id(Node node) const { return _graph->id(node); } |
1236 | 1236 |
static int id(Arc arc) { return arc.id; } |
1237 | 1237 |
static int id(Edge arc) { return arc.id; } |
1238 | 1238 |
|
1239 | 1239 |
Node nodeFromId(int id) const { return _graph->nodeFromId(id); } |
1240 | 1240 |
static Arc arcFromId(int id) { return Arc(id); } |
1241 | 1241 |
static Edge edgeFromId(int id) { return Edge(id);} |
1242 | 1242 |
|
1243 | 1243 |
int maxNodeId() const { return _graph->maxNodeId(); }; |
1244 | 1244 |
int maxArcId() const { return arcs.size() - 1; } |
1245 | 1245 |
int maxEdgeId() const { return arcs.size() / 2 - 1; } |
1246 | 1246 |
|
1247 | 1247 |
Node source(Arc e) const { return arcs[e.id ^ 1].target; } |
1248 | 1248 |
Node target(Arc e) const { return arcs[e.id].target; } |
1249 | 1249 |
|
1250 | 1250 |
Node u(Edge e) const { return arcs[2 * e.id].target; } |
1251 | 1251 |
Node v(Edge e) const { return arcs[2 * e.id + 1].target; } |
1252 | 1252 |
|
1253 | 1253 |
typedef typename ItemSetTraits<GR, Node>::ItemNotifier NodeNotifier; |
1254 | 1254 |
|
1255 | 1255 |
NodeNotifier& notifier(Node) const { |
1256 | 1256 |
return _graph->notifier(Node()); |
1257 | 1257 |
} |
1258 | 1258 |
|
1259 | 1259 |
template <typename V> |
1260 | 1260 |
class NodeMap : public GR::template NodeMap<V> { |
1261 | 1261 |
typedef typename GR::template NodeMap<V> Parent; |
1262 | 1262 |
|
1263 | 1263 |
public: |
1264 | 1264 |
|
1265 | 1265 |
explicit NodeMap(const SmartEdgeSetBase<GR>& arcset) |
1266 | 1266 |
: Parent(*arcset._graph) { } |
1267 | 1267 |
|
1268 | 1268 |
NodeMap(const SmartEdgeSetBase<GR>& arcset, const V& value) |
1269 | 1269 |
: Parent(*arcset._graph, value) { } |
1270 | 1270 |
|
1271 | 1271 |
NodeMap& operator=(const NodeMap& cmap) { |
1272 | 1272 |
return operator=<NodeMap>(cmap); |
1273 | 1273 |
} |
1274 | 1274 |
|
1275 | 1275 |
template <typename CMap> |
1276 | 1276 |
NodeMap& operator=(const CMap& cmap) { |
1277 | 1277 |
Parent::operator=(cmap); |
1278 | 1278 |
return *this; |
1279 | 1279 |
} |
1280 | 1280 |
}; |
1281 | 1281 |
|
1282 | 1282 |
}; |
1283 | 1283 |
|
1284 | 1284 |
/// \ingroup graphs |
1285 | 1285 |
/// |
1286 | 1286 |
/// \brief Graph using a node set of another digraph or graph and an |
1287 | 1287 |
/// own edge set. |
1288 | 1288 |
/// |
1289 | 1289 |
/// This structure can be used to establish another graph over a |
1290 | 1290 |
/// node set of an existing one. This class uses the same Node type |
1291 | 1291 |
/// as the underlying graph, and each valid node of the original |
1292 | 1292 |
/// graph is valid in this arc set, therefore the node objects of |
1293 | 1293 |
/// the original graph can be used directly with this class. The |
1294 | 1294 |
/// node handling functions (id handling, observing, and iterators) |
1295 | 1295 |
/// works equivalently as in the original graph. |
1296 | 1296 |
/// |
1297 | 1297 |
/// \param GR The type of the graph which shares its node set |
1298 | 1298 |
/// with this class. Its interface must conform to the |
1299 | 1299 |
/// \ref concepts::Digraph "Digraph" or \ref concepts::Graph "Graph" |
1300 | 1300 |
/// concept. |
1301 | 1301 |
/// |
1302 | 1302 |
/// This implementation is slightly faster than the \c ListEdgeSet, |
1303 | 1303 |
/// because it uses continuous storage for edges and it uses just |
1304 | 1304 |
/// single-linked lists for enumerate incident edges. Therefore the |
1305 | 1305 |
/// edges cannot be erased from the edge sets. |
1306 | 1306 |
/// |
1307 | 1307 |
/// \warning If a node is erased from the underlying graph and this |
1308 | 1308 |
/// node is incident to one edge in the edge set, then the edge set |
1309 | 1309 |
/// is invalidated, and it cannot be used anymore. The validity can |
1310 | 1310 |
/// be checked with the \c valid() member function. |
1311 | 1311 |
/// |
1312 | 1312 |
/// This class fully conforms to the \ref concepts::Graph |
1313 | 1313 |
/// "Graph" concept. |
1314 | 1314 |
template <typename GR> |
1315 | 1315 |
class SmartEdgeSet : public EdgeSetExtender<SmartEdgeSetBase<GR> > { |
1316 | 1316 |
typedef EdgeSetExtender<SmartEdgeSetBase<GR> > Parent; |
1317 | 1317 |
|
1318 | 1318 |
public: |
1319 | 1319 |
|
1320 | 1320 |
typedef typename Parent::Node Node; |
1321 | 1321 |
typedef typename Parent::Arc Arc; |
1322 | 1322 |
typedef typename Parent::Edge Edge; |
1323 | 1323 |
|
1324 | 1324 |
protected: |
1325 | 1325 |
|
1326 | 1326 |
typedef typename Parent::NodesImplBase NodesImplBase; |
1327 | 1327 |
|
1328 | 1328 |
void eraseNode(const Node& node) { |
1329 | 1329 |
if (typename Parent::IncEdgeIt(*this, node) == INVALID) { |
1330 | 1330 |
return; |
1331 | 1331 |
} |
1332 | 1332 |
throw typename NodesImplBase::Notifier::ImmediateDetach(); |
1333 | 1333 |
} |
1334 | 1334 |
|
1335 | 1335 |
void clearNodes() { |
1336 | 1336 |
Parent::clear(); |
1337 | 1337 |
} |
1338 | 1338 |
|
1339 | 1339 |
class NodesImpl : public NodesImplBase { |
1340 | 1340 |
typedef NodesImplBase Parent; |
1341 | 1341 |
|
1342 | 1342 |
public: |
1343 | 1343 |
NodesImpl(const GR& graph, SmartEdgeSet& arcset) |
1344 | 1344 |
: Parent(graph), _arcset(arcset) {} |
1345 | 1345 |
|
1346 | 1346 |
virtual ~NodesImpl() {} |
1347 | 1347 |
|
1348 | 1348 |
bool attached() const { |
1349 | 1349 |
return Parent::attached(); |
1350 | 1350 |
} |
1351 | 1351 |
|
1352 | 1352 |
protected: |
1353 | 1353 |
|
1354 | 1354 |
virtual void erase(const Node& node) { |
1355 | 1355 |
try { |
1356 | 1356 |
_arcset.eraseNode(node); |
1357 | 1357 |
Parent::erase(node); |
1358 | 1358 |
} catch (const typename NodesImplBase::Notifier::ImmediateDetach&) { |
1359 | 1359 |
Parent::clear(); |
1360 | 1360 |
throw; |
1361 | 1361 |
} |
1362 | 1362 |
} |
1363 | 1363 |
virtual void erase(const std::vector<Node>& nodes) { |
1364 | 1364 |
try { |
1365 | 1365 |
for (int i = 0; i < int(nodes.size()); ++i) { |
1366 | 1366 |
_arcset.eraseNode(nodes[i]); |
1367 | 1367 |
} |
1368 | 1368 |
Parent::erase(nodes); |
1369 | 1369 |
} catch (const typename NodesImplBase::Notifier::ImmediateDetach&) { |
1370 | 1370 |
Parent::clear(); |
1371 | 1371 |
throw; |
1372 | 1372 |
} |
1373 | 1373 |
} |
1374 | 1374 |
virtual void clear() { |
1375 | 1375 |
_arcset.clearNodes(); |
1376 | 1376 |
Parent::clear(); |
1377 | 1377 |
} |
1378 | 1378 |
|
1379 | 1379 |
private: |
1380 | 1380 |
SmartEdgeSet& _arcset; |
1381 | 1381 |
}; |
1382 | 1382 |
|
1383 | 1383 |
NodesImpl _nodes; |
1384 | 1384 |
|
1385 | 1385 |
public: |
1386 | 1386 |
|
1387 | 1387 |
/// \brief Constructor of the EdgeSet. |
1388 | 1388 |
/// |
1389 | 1389 |
/// Constructor of the EdgeSet. |
1390 | 1390 |
SmartEdgeSet(const GR& graph) : _nodes(graph, *this) { |
1391 | 1391 |
Parent::initalize(graph, _nodes); |
1392 | 1392 |
} |
1393 | 1393 |
|
1394 | 1394 |
/// \brief Add a new edge to the graph. |
1395 | 1395 |
/// |
1396 | 1396 |
/// Add a new edge to the graph with node \c u |
1397 | 1397 |
/// and node \c v endpoints. |
1398 | 1398 |
/// \return The new edge. |
1399 | 1399 |
Edge addEdge(const Node& u, const Node& v) { |
1400 | 1400 |
return Parent::addEdge(u, v); |
1401 | 1401 |
} |
1402 | 1402 |
|
1403 | 1403 |
/// \brief Validity check |
1404 | 1404 |
/// |
1405 | 1405 |
/// This functions gives back false if the EdgeSet is |
1406 | 1406 |
/// invalidated. It occurs when a node in the underlying graph is |
1407 | 1407 |
/// erased and it is not isolated in the EdgeSet. |
1408 | 1408 |
bool valid() const { |
1409 | 1409 |
return _nodes.attached(); |
1410 | 1410 |
} |
1411 | 1411 |
|
1412 | 1412 |
}; |
1413 | 1413 |
|
1414 | 1414 |
} |
1415 | 1415 |
|
1416 | 1416 |
#endif |
Changeset was too big and was cut off... Show full diff
0 comments (0 inline)