0
67
10
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 |
} |
... | ... |
@@ -6,64 +6,66 @@ |
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") |
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 |
47 |
include scripts/Makefile.am |
|
46 | 48 |
|
47 | 49 |
DIST_SUBDIRS = demo |
48 | 50 |
|
49 | 51 |
demo: |
50 | 52 |
$(MAKE) $(AM_MAKEFLAGS) -C demo |
51 | 53 |
|
52 | 54 |
MRPROPERFILES = \ |
53 | 55 |
aclocal.m4 \ |
54 | 56 |
config.h.in \ |
55 | 57 |
config.h.in~ \ |
56 | 58 |
configure \ |
57 | 59 |
Makefile.in \ |
58 | 60 |
build-aux/config.guess \ |
59 | 61 |
build-aux/config.sub \ |
60 | 62 |
build-aux/depcomp \ |
61 | 63 |
build-aux/install-sh \ |
62 | 64 |
build-aux/ltmain.sh \ |
63 | 65 |
build-aux/missing \ |
64 | 66 |
doc/doxygen.log |
65 | 67 |
|
66 | 68 |
mrproper: |
67 | 69 |
$(MAKE) $(AM_MAKEFLAGS) maintainer-clean |
68 | 70 |
-rm -f $(MRPROPERFILES) |
69 | 71 |
|
70 | 72 |
dist-bz2: dist |
71 | 73 |
zcat $(PACKAGE)-$(VERSION).tar.gz | \ |
72 | 74 |
bzip2 --best -c > $(PACKAGE)-$(VERSION).tar.bz2 |
73 | 75 |
|
74 | 76 |
distcheck-bz2: distcheck |
75 | 77 |
zcat $(PACKAGE)-$(VERSION).tar.gz | \ |
76 | 78 |
bzip2 --best -c > $(PACKAGE)-$(VERSION).tar.bz2 |
77 | 79 |
... | ... |
@@ -12,128 +12,145 @@ |
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 |
|
86 |
dnl Support for running test cases using valgrind. |
|
87 |
use_valgrind=no |
|
88 |
AC_ARG_ENABLE([valgrind], |
|
89 |
AS_HELP_STRING([--enable-valgrind], [use valgrind when running tests]), |
|
90 |
[use_valgrind=yes]) |
|
91 |
|
|
92 |
if [[ "$use_valgrind" = "yes" ]]; then |
|
93 |
AC_CHECK_PROG(HAVE_VALGRIND, valgrind, yes, no) |
|
94 |
|
|
95 |
if [[ "$HAVE_VALGRIND" = "no" ]]; then |
|
96 |
AC_MSG_ERROR([Valgrind not found in PATH.]) |
|
97 |
fi |
|
98 |
fi |
|
99 |
AM_CONDITIONAL(USE_VALGRIND, [test "$use_valgrind" = "yes"]) |
|
100 |
|
|
85 | 101 |
dnl Checks for header files. |
86 | 102 |
AC_CHECK_HEADERS(limits.h sys/time.h sys/times.h unistd.h) |
87 | 103 |
|
88 | 104 |
dnl Checks for typedefs, structures, and compiler characteristics. |
89 | 105 |
AC_C_CONST |
90 | 106 |
AC_C_INLINE |
91 | 107 |
AC_TYPE_SIZE_T |
92 | 108 |
AC_HEADER_TIME |
93 | 109 |
AC_STRUCT_TM |
94 | 110 |
|
95 | 111 |
dnl Checks for library functions. |
96 | 112 |
AC_HEADER_STDC |
97 | 113 |
AC_CHECK_FUNCS(gettimeofday times ctime_r) |
98 | 114 |
|
99 | 115 |
dnl Add dependencies on files generated by configure. |
100 | 116 |
AC_SUBST([CONFIG_STATUS_DEPENDENCIES], |
101 | 117 |
['$(top_srcdir)/doc/Doxyfile.in $(top_srcdir)/lemon/lemon.pc.in $(top_srcdir)/cmake/version.cmake.in']) |
102 | 118 |
|
103 | 119 |
AC_CONFIG_FILES([ |
104 | 120 |
Makefile |
105 | 121 |
demo/Makefile |
106 | 122 |
cmake/version.cmake |
107 | 123 |
doc/Doxyfile |
108 | 124 |
lemon/lemon.pc |
109 | 125 |
]) |
110 | 126 |
|
111 | 127 |
AC_OUTPUT |
112 | 128 |
|
113 | 129 |
echo |
114 | 130 |
echo '****************************** SUMMARY ******************************' |
115 | 131 |
echo |
116 | 132 |
echo Package version............... : $PACKAGE-$VERSION |
117 | 133 |
echo |
118 | 134 |
echo C++ compiler.................. : $CXX |
119 | 135 |
echo C++ compiles flags............ : $WARNINGCXXFLAGS $CXXFLAGS |
120 | 136 |
echo |
121 | 137 |
echo Compiler supports long long... : $long_long_found |
122 | 138 |
echo |
123 | 139 |
echo GLPK support.................. : $lx_glpk_found |
124 | 140 |
echo CPLEX support................. : $lx_cplex_found |
125 | 141 |
echo SOPLEX support................ : $lx_soplex_found |
126 | 142 |
echo CLP support................... : $lx_clp_found |
127 | 143 |
echo CBC support................... : $lx_cbc_found |
128 | 144 |
echo |
129 | 145 |
echo Build additional tools........ : $enable_tools |
146 |
echo Use valgrind for tests........ : $use_valgrind |
|
130 | 147 |
echo |
131 | 148 |
echo The packace will be installed in |
132 | 149 |
echo -n ' ' |
133 | 150 |
echo $prefix. |
134 | 151 |
echo |
135 | 152 |
echo '*********************************************************************' |
136 | 153 |
|
137 | 154 |
echo |
138 | 155 |
echo Configure complete, now type \'make\' and then \'make install\'. |
139 | 156 |
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 |
... | ... |
@@ -62,65 +61,66 @@ |
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 |
... | ... |
@@ -194,65 +194,65 @@ |
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 |
... | ... |
@@ -37,65 +37,77 @@ |
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: |
... | ... |
@@ -251,303 +251,375 @@ |
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 |
@defgroup geomdat Geometric Data Structures |
|
284 |
@ingroup auxdat |
|
285 |
\brief Geometric data structures implemented in LEMON. |
|
286 |
|
|
287 |
This group contains geometric data structures implemented in LEMON. |
|
288 |
|
|
289 |
- \ref lemon::dim2::Point "dim2::Point" implements a two dimensional |
|
290 |
vector with the usual operations. |
|
291 |
- \ref lemon::dim2::Box "dim2::Box" can be used to determine the |
|
292 |
rectangular bounding box of a set of \ref lemon::dim2::Point |
|
293 |
"dim2::Point"'s. |
|
294 |
*/ |
|
295 |
|
|
296 |
/** |
|
297 |
@defgroup matrices Matrices |
|
298 |
@ingroup auxdat |
|
299 |
\brief Two dimensional data storages implemented in LEMON. |
|
300 |
|
|
301 |
This group contains two dimensional data storages implemented in LEMON. |
|
302 |
*/ |
|
303 |
|
|
304 |
/** |
|
283 | 305 |
@defgroup algs Algorithms |
284 | 306 |
\brief This group contains the several algorithms |
285 | 307 |
implemented in LEMON. |
286 | 308 |
|
287 | 309 |
This group contains the several algorithms |
288 | 310 |
implemented in LEMON. |
289 | 311 |
*/ |
290 | 312 |
|
291 | 313 |
/** |
292 | 314 |
@defgroup search Graph Search |
293 | 315 |
@ingroup algs |
294 | 316 |
\brief Common graph search algorithms. |
295 | 317 |
|
296 | 318 |
This group contains the common graph search algorithms, namely |
297 |
\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. |
|
298 | 321 |
*/ |
299 | 322 |
|
300 | 323 |
/** |
301 | 324 |
@defgroup shortest_path Shortest Path Algorithms |
302 | 325 |
@ingroup algs |
303 | 326 |
\brief Algorithms for finding shortest paths. |
304 | 327 |
|
305 |
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. |
|
306 | 330 |
|
307 | 331 |
- \ref Dijkstra algorithm for finding shortest paths from a source node |
308 | 332 |
when all arc lengths are non-negative. |
309 | 333 |
- \ref BellmanFord "Bellman-Ford" algorithm for finding shortest paths |
310 | 334 |
from a source node when arc lenghts can be either positive or negative, |
311 | 335 |
but the digraph should not contain directed cycles with negative total |
312 | 336 |
length. |
313 | 337 |
- \ref FloydWarshall "Floyd-Warshall" and \ref Johnson "Johnson" algorithms |
314 | 338 |
for solving the \e all-pairs \e shortest \e paths \e problem when arc |
315 | 339 |
lenghts can be either positive or negative, but the digraph should |
316 | 340 |
not contain directed cycles with negative total length. |
317 | 341 |
- \ref Suurballe A successive shortest path algorithm for finding |
318 | 342 |
arc-disjoint paths between two nodes having minimum total length. |
319 | 343 |
*/ |
320 | 344 |
|
321 | 345 |
/** |
346 |
@defgroup spantree Minimum Spanning Tree Algorithms |
|
347 |
@ingroup algs |
|
348 |
\brief Algorithms for finding minimum cost spanning trees and arborescences. |
|
349 |
|
|
350 |
This group contains the algorithms for finding minimum cost spanning |
|
351 |
trees and arborescences \ref clrs01algorithms. |
|
352 |
*/ |
|
353 |
|
|
354 |
/** |
|
322 | 355 |
@defgroup max_flow Maximum Flow Algorithms |
323 | 356 |
@ingroup algs |
324 | 357 |
\brief Algorithms for finding maximum flows. |
325 | 358 |
|
326 | 359 |
This group contains the algorithms for finding maximum flows and |
327 |
feasible circulations. |
|
360 |
feasible circulations \ref clrs01algorithms, \ref amo93networkflows. |
|
328 | 361 |
|
329 | 362 |
The \e maximum \e flow \e problem is to find a flow of maximum value between |
330 | 363 |
a single source and a single target. Formally, there is a \f$G=(V,A)\f$ |
331 | 364 |
digraph, a \f$cap: A\rightarrow\mathbf{R}^+_0\f$ capacity function and |
332 | 365 |
\f$s, t \in V\f$ source and target nodes. |
333 | 366 |
A maximum flow is an \f$f: A\rightarrow\mathbf{R}^+_0\f$ solution of the |
334 | 367 |
following optimization problem. |
335 | 368 |
|
336 | 369 |
\f[ \max\sum_{sv\in A} f(sv) - \sum_{vs\in A} f(vs) \f] |
337 | 370 |
\f[ \sum_{uv\in A} f(uv) = \sum_{vu\in A} f(vu) |
338 | 371 |
\quad \forall u\in V\setminus\{s,t\} \f] |
339 | 372 |
\f[ 0 \leq f(uv) \leq cap(uv) \quad \forall uv\in A \f] |
340 | 373 |
|
341 | 374 |
LEMON contains several algorithms for solving maximum flow problems: |
342 |
- \ref EdmondsKarp Edmonds-Karp algorithm. |
|
343 |
- \ref Preflow Goldberg-Tarjan's preflow push-relabel algorithm. |
|
344 |
- \ref DinitzSleatorTarjan Dinitz's blocking flow algorithm with dynamic trees. |
|
345 |
- \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. |
|
346 | 383 |
|
347 |
In most cases the \ref Preflow |
|
384 |
In most cases the \ref Preflow algorithm provides the |
|
348 | 385 |
fastest method for computing a maximum flow. All implementations |
349 | 386 |
also provide functions to query the minimum cut, which is the dual |
350 | 387 |
problem of maximum flow. |
351 | 388 |
|
352 | 389 |
\ref Circulation is a preflow push-relabel algorithm implemented directly |
353 | 390 |
for finding feasible circulations, which is a somewhat different problem, |
354 | 391 |
but it is strongly related to maximum flow. |
355 | 392 |
For more information, see \ref Circulation. |
356 | 393 |
*/ |
357 | 394 |
|
358 | 395 |
/** |
359 | 396 |
@defgroup min_cost_flow_algs Minimum Cost Flow Algorithms |
360 | 397 |
@ingroup algs |
361 | 398 |
|
362 | 399 |
\brief Algorithms for finding minimum cost flows and circulations. |
363 | 400 |
|
364 | 401 |
This group contains the algorithms for finding minimum cost flows and |
365 |
circulations. For more information about this problem and its dual |
|
366 |
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". |
|
367 | 405 |
|
368 | 406 |
LEMON contains several algorithms for this problem. |
369 | 407 |
- \ref NetworkSimplex Primal Network Simplex algorithm with various |
370 |
pivot strategies. |
|
408 |
pivot strategies \ref dantzig63linearprog, \ref kellyoneill91netsimplex. |
|
371 | 409 |
- \ref CostScaling Push-Relabel and Augment-Relabel algorithms based on |
372 |
cost scaling |
|
410 |
cost scaling \ref goldberg90approximation, \ref goldberg97efficient, |
|
411 |
\ref bunnagel98efficient. |
|
373 | 412 |
- \ref CapacityScaling Successive Shortest %Path algorithm with optional |
374 |
capacity scaling. |
|
375 |
- \ref CancelAndTighten The Cancel and Tighten algorithm. |
|
376 |
|
|
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. |
|
377 | 418 |
|
378 | 419 |
In general NetworkSimplex is the most efficient implementation, |
379 | 420 |
but in special cases other algorithms could be faster. |
380 | 421 |
For example, if the total supply and/or capacities are rather small, |
381 | 422 |
CapacityScaling is usually the fastest algorithm (without effective scaling). |
382 | 423 |
*/ |
383 | 424 |
|
384 | 425 |
/** |
385 | 426 |
@defgroup min_cut Minimum Cut Algorithms |
386 | 427 |
@ingroup algs |
387 | 428 |
|
388 | 429 |
\brief Algorithms for finding minimum cut in graphs. |
389 | 430 |
|
390 | 431 |
This group contains the algorithms for finding minimum cut in graphs. |
391 | 432 |
|
392 | 433 |
The \e minimum \e cut \e problem is to find a non-empty and non-complete |
393 | 434 |
\f$X\f$ subset of the nodes with minimum overall capacity on |
394 | 435 |
outgoing arcs. Formally, there is a \f$G=(V,A)\f$ digraph, a |
395 | 436 |
\f$cap: A\rightarrow\mathbf{R}^+_0\f$ capacity function. The minimum |
396 | 437 |
cut is the \f$X\f$ solution of the next optimization problem: |
397 | 438 |
|
398 | 439 |
\f[ \min_{X \subset V, X\not\in \{\emptyset, V\}} |
399 |
\sum_{uv\in A |
|
440 |
\sum_{uv\in A: u\in X, v\not\in X}cap(uv) \f] |
|
400 | 441 |
|
401 | 442 |
LEMON contains several algorithms related to minimum cut problems: |
402 | 443 |
|
403 | 444 |
- \ref HaoOrlin "Hao-Orlin algorithm" for calculating minimum cut |
404 | 445 |
in directed graphs. |
405 | 446 |
- \ref NagamochiIbaraki "Nagamochi-Ibaraki algorithm" for |
406 | 447 |
calculating minimum cut in undirected graphs. |
407 | 448 |
- \ref GomoryHu "Gomory-Hu tree computation" for calculating |
408 | 449 |
all-pairs minimum cut in undirected graphs. |
409 | 450 |
|
410 | 451 |
If you want to find minimum cut just between two distinict nodes, |
411 | 452 |
see the \ref max_flow "maximum flow problem". |
412 | 453 |
*/ |
413 | 454 |
|
414 | 455 |
/** |
415 |
@defgroup |
|
456 |
@defgroup min_mean_cycle Minimum Mean Cycle Algorithms |
|
416 | 457 |
@ingroup algs |
417 |
\brief Algorithms for |
|
458 |
\brief Algorithms for finding minimum mean cycles. |
|
418 | 459 |
|
419 |
This group contains the algorithms for discovering the graph properties |
|
420 |
like connectivity, bipartiteness, euler property, simplicity etc. |
|
460 |
This group contains the algorithms for finding minimum mean cycles |
|
461 |
\ref clrs01algorithms, \ref amo93networkflows. |
|
421 | 462 |
|
422 |
\image html edge_biconnected_components.png |
|
423 |
\image latex edge_biconnected_components.eps "bi-edge-connected components" width=\textwidth |
|
424 |
|
|
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. |
|
425 | 467 |
|
426 |
/** |
|
427 |
@defgroup planar Planarity Embedding and Drawing |
|
428 |
@ingroup algs |
|
429 |
\brief Algorithms for planarity checking, embedding and drawing |
|
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. |
|
430 | 475 |
|
431 |
This group contains the algorithms for planarity checking, |
|
432 |
embedding and drawing. |
|
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. |
|
433 | 483 |
|
434 |
\image html planar.png |
|
435 |
\image latex planar.eps "Plane graph" width=\textwidth |
|
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. |
|
436 | 490 |
*/ |
437 | 491 |
|
438 | 492 |
/** |
439 | 493 |
@defgroup matching Matching Algorithms |
440 | 494 |
@ingroup algs |
441 | 495 |
\brief Algorithms for finding matchings in graphs and bipartite graphs. |
442 | 496 |
|
443 | 497 |
This group contains the algorithms for calculating |
444 | 498 |
matchings in graphs and bipartite graphs. The general matching problem is |
445 | 499 |
finding a subset of the edges for which each node has at most one incident |
446 | 500 |
edge. |
447 | 501 |
|
448 | 502 |
There are several different algorithms for calculate matchings in |
449 | 503 |
graphs. The matching problems in bipartite graphs are generally |
450 | 504 |
easier than in general graphs. The goal of the matching optimization |
451 | 505 |
can be finding maximum cardinality, maximum weight or minimum cost |
452 | 506 |
matching. The search can be constrained to find perfect or |
453 | 507 |
maximum cardinality matching. |
454 | 508 |
|
455 | 509 |
The matching algorithms implemented in LEMON: |
456 | 510 |
- \ref MaxBipartiteMatching Hopcroft-Karp augmenting path algorithm |
457 | 511 |
for calculating maximum cardinality matching in bipartite graphs. |
458 | 512 |
- \ref PrBipartiteMatching Push-relabel algorithm |
459 | 513 |
for calculating maximum cardinality matching in bipartite graphs. |
460 | 514 |
- \ref MaxWeightedBipartiteMatching |
461 | 515 |
Successive shortest path algorithm for calculating maximum weighted |
462 | 516 |
matching and maximum weighted bipartite matching in bipartite graphs. |
463 | 517 |
- \ref MinCostMaxBipartiteMatching |
464 | 518 |
Successive shortest path algorithm for calculating minimum cost maximum |
465 | 519 |
matching in bipartite graphs. |
466 | 520 |
- \ref MaxMatching Edmond's blossom shrinking algorithm for calculating |
467 | 521 |
maximum cardinality matching in general graphs. |
468 | 522 |
- \ref MaxWeightedMatching Edmond's blossom shrinking algorithm for calculating |
469 | 523 |
maximum weighted matching in general graphs. |
470 | 524 |
- \ref MaxWeightedPerfectMatching |
471 | 525 |
Edmond's blossom shrinking algorithm for calculating maximum weighted |
472 | 526 |
perfect matching in general graphs. |
473 | 527 |
|
474 | 528 |
\image html bipartite_matching.png |
475 | 529 |
\image latex bipartite_matching.eps "Bipartite Matching" width=\textwidth |
476 | 530 |
*/ |
477 | 531 |
|
478 | 532 |
/** |
479 |
@defgroup |
|
533 |
@defgroup graph_properties Connectivity and Other Graph Properties |
|
480 | 534 |
@ingroup algs |
481 |
\brief Algorithms for |
|
535 |
\brief Algorithms for discovering the graph properties |
|
482 | 536 |
|
483 |
This group contains the algorithms for finding minimum cost spanning |
|
484 |
trees and arborescences. |
|
537 |
This group contains the algorithms for discovering the graph properties |
|
538 |
like connectivity, bipartiteness, euler property, simplicity etc. |
|
539 |
|
|
540 |
\image html connected_components.png |
|
541 |
\image latex connected_components.eps "Connected components" width=\textwidth |
|
542 |
*/ |
|
543 |
|
|
544 |
/** |
|
545 |
@defgroup planar Planarity Embedding and Drawing |
|
546 |
@ingroup algs |
|
547 |
\brief Algorithms for planarity checking, embedding and drawing |
|
548 |
|
|
549 |
This group contains the algorithms for planarity checking, |
|
550 |
embedding and drawing. |
|
551 |
|
|
552 |
\image html planar.png |
|
553 |
\image latex planar.eps "Plane graph" width=\textwidth |
|
554 |
*/ |
|
555 |
|
|
556 |
/** |
|
557 |
@defgroup approx Approximation Algorithms |
|
558 |
@ingroup algs |
|
559 |
\brief Approximation algorithms. |
|
560 |
|
|
561 |
This group contains the approximation and heuristic algorithms |
|
562 |
implemented in LEMON. |
|
485 | 563 |
*/ |
486 | 564 |
|
487 | 565 |
/** |
488 | 566 |
@defgroup auxalg Auxiliary Algorithms |
489 | 567 |
@ingroup algs |
490 | 568 |
\brief Auxiliary algorithms implemented in LEMON. |
491 | 569 |
|
492 | 570 |
This group contains some algorithms implemented in LEMON |
493 | 571 |
in order to make it easier to implement complex algorithms. |
494 | 572 |
*/ |
495 | 573 |
|
496 | 574 |
/** |
497 |
@defgroup approx Approximation Algorithms |
|
498 |
@ingroup algs |
|
499 |
\brief Approximation algorithms. |
|
500 |
|
|
501 |
This group contains the approximation and heuristic algorithms |
|
502 |
implemented in LEMON. |
|
503 |
*/ |
|
504 |
|
|
505 |
/** |
|
506 | 575 |
@defgroup gen_opt_group General Optimization Tools |
507 | 576 |
\brief This group contains some general optimization frameworks |
508 | 577 |
implemented in LEMON. |
509 | 578 |
|
510 | 579 |
This group contains some general optimization frameworks |
511 | 580 |
implemented in LEMON. |
512 | 581 |
*/ |
513 | 582 |
|
514 | 583 |
/** |
515 |
@defgroup lp_group |
|
584 |
@defgroup lp_group LP and MIP Solvers |
|
516 | 585 |
@ingroup gen_opt_group |
517 |
\brief |
|
586 |
\brief LP and MIP solver interfaces for LEMON. |
|
518 | 587 |
|
519 |
This group contains Lp and Mip solver interfaces for LEMON. The |
|
520 |
various LP solvers could be used in the same manner with this |
|
521 |
|
|
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. |
|
522 | 594 |
*/ |
523 | 595 |
|
524 | 596 |
/** |
525 | 597 |
@defgroup lp_utils Tools for Lp and Mip Solvers |
526 | 598 |
@ingroup lp_group |
527 | 599 |
\brief Helper tools to the Lp and Mip solvers. |
528 | 600 |
|
529 | 601 |
This group adds some helper tools to general optimization framework |
530 | 602 |
implemented in LEMON. |
531 | 603 |
*/ |
532 | 604 |
|
533 | 605 |
/** |
534 | 606 |
@defgroup metah Metaheuristics |
535 | 607 |
@ingroup gen_opt_group |
536 | 608 |
\brief Metaheuristics for LEMON library. |
537 | 609 |
|
538 | 610 |
This group contains some metaheuristic optimization tools. |
539 | 611 |
*/ |
540 | 612 |
|
541 | 613 |
/** |
542 | 614 |
@defgroup utils Tools and Utilities |
543 | 615 |
\brief Tools and utilities for programming in LEMON |
544 | 616 |
|
545 | 617 |
Tools and utilities for programming in LEMON. |
546 | 618 |
*/ |
547 | 619 |
|
548 | 620 |
/** |
549 | 621 |
@defgroup gutils Basic Graph Utilities |
550 | 622 |
@ingroup utils |
551 | 623 |
\brief Simple basic graph utilities. |
552 | 624 |
|
553 | 625 |
This group contains some simple basic graph utilities. |
... | ... |
@@ -579,115 +651,115 @@ |
579 | 651 |
This group contains the exceptions defined in LEMON. |
580 | 652 |
*/ |
581 | 653 |
|
582 | 654 |
/** |
583 | 655 |
@defgroup io_group Input-Output |
584 | 656 |
\brief Graph Input-Output methods |
585 | 657 |
|
586 | 658 |
This group contains the tools for importing and exporting graphs |
587 | 659 |
and graph related data. Now it supports the \ref lgf-format |
588 | 660 |
"LEMON Graph Format", the \c DIMACS format and the encapsulated |
589 | 661 |
postscript (EPS) format. |
590 | 662 |
*/ |
591 | 663 |
|
592 | 664 |
/** |
593 | 665 |
@defgroup lemon_io LEMON Graph Format |
594 | 666 |
@ingroup io_group |
595 | 667 |
\brief Reading and writing LEMON Graph Format. |
596 | 668 |
|
597 | 669 |
This group contains methods for reading and writing |
598 | 670 |
\ref lgf-format "LEMON Graph Format". |
599 | 671 |
*/ |
600 | 672 |
|
601 | 673 |
/** |
602 | 674 |
@defgroup eps_io Postscript Exporting |
603 | 675 |
@ingroup io_group |
604 | 676 |
\brief General \c EPS drawer and graph exporter |
605 | 677 |
|
606 | 678 |
This group contains general \c EPS drawing methods and special |
607 | 679 |
graph exporting tools. |
608 | 680 |
*/ |
609 | 681 |
|
610 | 682 |
/** |
611 |
@defgroup dimacs_group DIMACS |
|
683 |
@defgroup dimacs_group DIMACS Format |
|
612 | 684 |
@ingroup io_group |
613 | 685 |
\brief Read and write files in DIMACS format |
614 | 686 |
|
615 | 687 |
Tools to read a digraph from or write it to a file in DIMACS format data. |
616 | 688 |
*/ |
617 | 689 |
|
618 | 690 |
/** |
619 | 691 |
@defgroup nauty_group NAUTY Format |
620 | 692 |
@ingroup io_group |
621 | 693 |
\brief Read \e Nauty format |
622 | 694 |
|
623 | 695 |
Tool to read graphs from \e Nauty format data. |
624 | 696 |
*/ |
625 | 697 |
|
626 | 698 |
/** |
627 | 699 |
@defgroup concept Concepts |
628 | 700 |
\brief Skeleton classes and concept checking classes |
629 | 701 |
|
630 | 702 |
This group contains the data/algorithm skeletons and concept checking |
631 | 703 |
classes implemented in LEMON. |
632 | 704 |
|
633 | 705 |
The purpose of the classes in this group is fourfold. |
634 | 706 |
|
635 | 707 |
- These classes contain the documentations of the %concepts. In order |
636 | 708 |
to avoid document multiplications, an implementation of a concept |
637 | 709 |
simply refers to the corresponding concept class. |
638 | 710 |
|
639 | 711 |
- These classes declare every functions, <tt>typedef</tt>s etc. an |
640 | 712 |
implementation of the %concepts should provide, however completely |
641 | 713 |
without implementations and real data structures behind the |
642 | 714 |
interface. On the other hand they should provide nothing else. All |
643 | 715 |
the algorithms working on a data structure meeting a certain concept |
644 | 716 |
should compile with these classes. (Though it will not run properly, |
645 | 717 |
of course.) In this way it is easily to check if an algorithm |
646 | 718 |
doesn't use any extra feature of a certain implementation. |
647 | 719 |
|
648 | 720 |
- The concept descriptor classes also provide a <em>checker class</em> |
649 | 721 |
that makes it possible to check whether a certain implementation of a |
650 | 722 |
concept indeed provides all the required features. |
651 | 723 |
|
652 | 724 |
- Finally, They can serve as a skeleton of a new implementation of a concept. |
653 | 725 |
*/ |
654 | 726 |
|
655 | 727 |
/** |
656 | 728 |
@defgroup graph_concepts Graph Structure Concepts |
657 | 729 |
@ingroup concept |
658 | 730 |
\brief Skeleton and concept checking classes for graph structures |
659 | 731 |
|
660 |
This group contains the skeletons and concept checking classes of LEMON's |
|
661 |
graph structures and helper classes used to implement these. |
|
732 |
This group contains the skeletons and concept checking classes of |
|
733 |
graph structures. |
|
662 | 734 |
*/ |
663 | 735 |
|
664 | 736 |
/** |
665 | 737 |
@defgroup map_concepts Map Concepts |
666 | 738 |
@ingroup concept |
667 | 739 |
\brief Skeleton and concept checking classes for maps |
668 | 740 |
|
669 | 741 |
This group contains the skeletons and concept checking classes of maps. |
670 | 742 |
*/ |
671 | 743 |
|
672 | 744 |
/** |
745 |
@defgroup tools Standalone Utility Applications |
|
746 |
|
|
747 |
Some utility applications are listed here. |
|
748 |
|
|
749 |
The standard compilation procedure (<tt>./configure;make</tt>) will compile |
|
750 |
them, as well. |
|
751 |
*/ |
|
752 |
|
|
753 |
/** |
|
673 | 754 |
\anchor demoprograms |
674 | 755 |
|
675 | 756 |
@defgroup demos Demo Programs |
676 | 757 |
|
677 | 758 |
Some demo programs are listed here. Their full source codes can be found in |
678 | 759 |
the \c demo subdirectory of the source tree. |
679 | 760 |
|
680 | 761 |
In order to compile them, use the <tt>make demo</tt> or the |
681 | 762 |
<tt>make check</tt> commands. |
682 | 763 |
*/ |
683 | 764 |
|
684 |
/** |
|
685 |
@defgroup tools Standalone Utility Applications |
|
686 |
|
|
687 |
Some utility applications are listed here. |
|
688 |
|
|
689 |
The standard compilation procedure (<tt>./configure;make</tt>) will compile |
|
690 |
them, as well. |
|
691 |
*/ |
|
692 |
|
|
693 | 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 |
- \f$\pi(u) |
|
81 |
- \f$\pi(u)\leq 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 |
... | ... |
@@ -116,38 +116,38 @@ |
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 |
- \f$\pi(u) |
|
148 |
- \f$\pi(u)\geq 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 |
} |
... | ... |
@@ -57,86 +57,90 @@ |
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/planarity.h \ |
108 | 111 |
lemon/preflow.h \ |
109 | 112 |
lemon/radix_heap.h \ |
110 | 113 |
lemon/radix_sort.h \ |
111 | 114 |
lemon/random.h \ |
112 | 115 |
lemon/smart_graph.h \ |
113 | 116 |
lemon/soplex.h \ |
117 |
lemon/static_graph.h \ |
|
114 | 118 |
lemon/suurballe.h \ |
115 | 119 |
lemon/time_measure.h \ |
116 | 120 |
lemon/tolerance.h \ |
117 | 121 |
lemon/unionfind.h \ |
118 | 122 |
lemon/bits/windows.h |
119 | 123 |
|
120 | 124 |
bits_HEADERS += \ |
121 | 125 |
lemon/bits/alteration_notifier.h \ |
122 | 126 |
lemon/bits/array_map.h \ |
123 | 127 |
lemon/bits/bezier.h \ |
124 | 128 |
lemon/bits/default_map.h \ |
125 | 129 |
lemon/bits/edge_set_extender.h \ |
126 | 130 |
lemon/bits/enable_if.h \ |
127 | 131 |
lemon/bits/graph_adaptor_extender.h \ |
128 | 132 |
lemon/bits/graph_extender.h \ |
129 | 133 |
lemon/bits/map_extender.h \ |
130 | 134 |
lemon/bits/path_dump.h \ |
131 | 135 |
lemon/bits/solver_bits.h \ |
132 | 136 |
lemon/bits/traits.h \ |
133 | 137 |
lemon/bits/variant.h \ |
134 | 138 |
lemon/bits/vector_map.h |
135 | 139 |
|
136 | 140 |
concept_HEADERS += \ |
137 | 141 |
lemon/concepts/digraph.h \ |
138 | 142 |
lemon/concepts/graph.h \ |
139 | 143 |
lemon/concepts/graph_components.h \ |
140 | 144 |
lemon/concepts/heap.h \ |
141 | 145 |
lemon/concepts/maps.h \ |
142 | 146 |
lemon/concepts/path.h |
... | ... |
@@ -331,64 +331,67 @@ |
331 | 331 |
|
332 | 332 |
void firstIn(Arc& a, const Node& n) const { Parent::firstOut(a, n); } |
333 | 333 |
void firstOut(Arc& a, const Node& n ) const { Parent::firstIn(a, n); } |
334 | 334 |
|
335 | 335 |
void nextIn(Arc& a) const { Parent::nextOut(a); } |
336 | 336 |
void nextOut(Arc& a) const { Parent::nextIn(a); } |
337 | 337 |
|
338 | 338 |
Node source(const Arc& a) const { return Parent::target(a); } |
339 | 339 |
Node target(const Arc& a) const { return Parent::source(a); } |
340 | 340 |
|
341 | 341 |
Arc addArc(const Node& u, const Node& v) { return Parent::addArc(v, u); } |
342 | 342 |
|
343 | 343 |
typedef FindArcTagIndicator<DGR> FindArcTag; |
344 | 344 |
Arc findArc(const Node& u, const Node& v, |
345 | 345 |
const Arc& prev = INVALID) const { |
346 | 346 |
return Parent::findArc(v, u, prev); |
347 | 347 |
} |
348 | 348 |
|
349 | 349 |
}; |
350 | 350 |
|
351 | 351 |
/// \ingroup graph_adaptors |
352 | 352 |
/// |
353 | 353 |
/// \brief Adaptor class for reversing the orientation of the arcs in |
354 | 354 |
/// a digraph. |
355 | 355 |
/// |
356 | 356 |
/// ReverseDigraph can be used for reversing the arcs in a digraph. |
357 | 357 |
/// It conforms to the \ref concepts::Digraph "Digraph" concept. |
358 | 358 |
/// |
359 | 359 |
/// The adapted digraph can also be modified through this adaptor |
360 | 360 |
/// by adding or removing nodes or arcs, unless the \c GR template |
361 | 361 |
/// parameter is set to be \c const. |
362 | 362 |
/// |
363 |
/// This class provides item counting in the same time as the adapted |
|
364 |
/// digraph structure. |
|
365 |
/// |
|
363 | 366 |
/// \tparam DGR The type of the adapted digraph. |
364 | 367 |
/// It must conform to the \ref concepts::Digraph "Digraph" concept. |
365 | 368 |
/// It can also be specified to be \c const. |
366 | 369 |
/// |
367 | 370 |
/// \note The \c Node and \c Arc types of this adaptor and the adapted |
368 | 371 |
/// digraph are convertible to each other. |
369 | 372 |
template<typename DGR> |
370 | 373 |
#ifdef DOXYGEN |
371 | 374 |
class ReverseDigraph { |
372 | 375 |
#else |
373 | 376 |
class ReverseDigraph : |
374 | 377 |
public DigraphAdaptorExtender<ReverseDigraphBase<DGR> > { |
375 | 378 |
#endif |
376 | 379 |
typedef DigraphAdaptorExtender<ReverseDigraphBase<DGR> > Parent; |
377 | 380 |
public: |
378 | 381 |
/// The type of the adapted digraph. |
379 | 382 |
typedef DGR Digraph; |
380 | 383 |
protected: |
381 | 384 |
ReverseDigraph() { } |
382 | 385 |
public: |
383 | 386 |
|
384 | 387 |
/// \brief Constructor |
385 | 388 |
/// |
386 | 389 |
/// Creates a reverse digraph adaptor for the given digraph. |
387 | 390 |
explicit ReverseDigraph(DGR& digraph) { |
388 | 391 |
Parent::initialize(digraph); |
389 | 392 |
} |
390 | 393 |
}; |
391 | 394 |
|
392 | 395 |
/// \brief Returns a read-only ReverseDigraph adaptor |
393 | 396 |
/// |
394 | 397 |
/// This function just returns a read-only \ref ReverseDigraph adaptor. |
... | ... |
@@ -690,64 +693,66 @@ |
690 | 693 |
: Parent(adaptor, value) {} |
691 | 694 |
|
692 | 695 |
private: |
693 | 696 |
ArcMap& operator=(const ArcMap& cmap) { |
694 | 697 |
return operator=<ArcMap>(cmap); |
695 | 698 |
} |
696 | 699 |
|
697 | 700 |
template <typename CMap> |
698 | 701 |
ArcMap& operator=(const CMap& cmap) { |
699 | 702 |
Parent::operator=(cmap); |
700 | 703 |
return *this; |
701 | 704 |
} |
702 | 705 |
}; |
703 | 706 |
|
704 | 707 |
}; |
705 | 708 |
|
706 | 709 |
/// \ingroup graph_adaptors |
707 | 710 |
/// |
708 | 711 |
/// \brief Adaptor class for hiding nodes and arcs in a digraph |
709 | 712 |
/// |
710 | 713 |
/// SubDigraph can be used for hiding nodes and arcs in a digraph. |
711 | 714 |
/// A \c bool node map and a \c bool arc map must be specified, which |
712 | 715 |
/// define the filters for nodes and arcs. |
713 | 716 |
/// Only the nodes and arcs with \c true filter value are |
714 | 717 |
/// shown in the subdigraph. The arcs that are incident to hidden |
715 | 718 |
/// nodes are also filtered out. |
716 | 719 |
/// This adaptor conforms to the \ref concepts::Digraph "Digraph" concept. |
717 | 720 |
/// |
718 | 721 |
/// The adapted digraph can also be modified through this adaptor |
719 | 722 |
/// by adding or removing nodes or arcs, unless the \c GR template |
720 | 723 |
/// parameter is set to be \c const. |
721 | 724 |
/// |
725 |
/// This class provides only linear time counting for nodes and arcs. |
|
726 |
/// |
|
722 | 727 |
/// \tparam DGR The type of the adapted digraph. |
723 | 728 |
/// It must conform to the \ref concepts::Digraph "Digraph" concept. |
724 | 729 |
/// It can also be specified to be \c const. |
725 | 730 |
/// \tparam NF The type of the node filter map. |
726 | 731 |
/// It must be a \c bool (or convertible) node map of the |
727 | 732 |
/// adapted digraph. The default type is |
728 | 733 |
/// \ref concepts::Digraph::NodeMap "DGR::NodeMap<bool>". |
729 | 734 |
/// \tparam AF The type of the arc filter map. |
730 | 735 |
/// It must be \c bool (or convertible) arc map of the |
731 | 736 |
/// adapted digraph. The default type is |
732 | 737 |
/// \ref concepts::Digraph::ArcMap "DGR::ArcMap<bool>". |
733 | 738 |
/// |
734 | 739 |
/// \note The \c Node and \c Arc types of this adaptor and the adapted |
735 | 740 |
/// digraph are convertible to each other. |
736 | 741 |
/// |
737 | 742 |
/// \see FilterNodes |
738 | 743 |
/// \see FilterArcs |
739 | 744 |
#ifdef DOXYGEN |
740 | 745 |
template<typename DGR, typename NF, typename AF> |
741 | 746 |
class SubDigraph { |
742 | 747 |
#else |
743 | 748 |
template<typename DGR, |
744 | 749 |
typename NF = typename DGR::template NodeMap<bool>, |
745 | 750 |
typename AF = typename DGR::template ArcMap<bool> > |
746 | 751 |
class SubDigraph : |
747 | 752 |
public DigraphAdaptorExtender<SubDigraphBase<DGR, NF, AF, true> > { |
748 | 753 |
#endif |
749 | 754 |
public: |
750 | 755 |
/// The type of the adapted digraph. |
751 | 756 |
typedef DGR Digraph; |
752 | 757 |
/// The type of the node filter map. |
753 | 758 |
typedef NF NodeFilterMap; |
... | ... |
@@ -1285,64 +1290,66 @@ |
1285 | 1290 |
|
1286 | 1291 |
private: |
1287 | 1292 |
EdgeMap& operator=(const EdgeMap& cmap) { |
1288 | 1293 |
return operator=<EdgeMap>(cmap); |
1289 | 1294 |
} |
1290 | 1295 |
|
1291 | 1296 |
template <typename CMap> |
1292 | 1297 |
EdgeMap& operator=(const CMap& cmap) { |
1293 | 1298 |
Parent::operator=(cmap); |
1294 | 1299 |
return *this; |
1295 | 1300 |
} |
1296 | 1301 |
}; |
1297 | 1302 |
|
1298 | 1303 |
}; |
1299 | 1304 |
|
1300 | 1305 |
/// \ingroup graph_adaptors |
1301 | 1306 |
/// |
1302 | 1307 |
/// \brief Adaptor class for hiding nodes and edges in an undirected |
1303 | 1308 |
/// graph. |
1304 | 1309 |
/// |
1305 | 1310 |
/// SubGraph can be used for hiding nodes and edges in a graph. |
1306 | 1311 |
/// A \c bool node map and a \c bool edge map must be specified, which |
1307 | 1312 |
/// define the filters for nodes and edges. |
1308 | 1313 |
/// Only the nodes and edges with \c true filter value are |
1309 | 1314 |
/// shown in the subgraph. The edges that are incident to hidden |
1310 | 1315 |
/// nodes are also filtered out. |
1311 | 1316 |
/// This adaptor conforms to the \ref concepts::Graph "Graph" concept. |
1312 | 1317 |
/// |
1313 | 1318 |
/// The adapted graph can also be modified through this adaptor |
1314 | 1319 |
/// by adding or removing nodes or edges, unless the \c GR template |
1315 | 1320 |
/// parameter is set to be \c const. |
1316 | 1321 |
/// |
1322 |
/// This class provides only linear time counting for nodes, edges and arcs. |
|
1323 |
/// |
|
1317 | 1324 |
/// \tparam GR The type of the adapted graph. |
1318 | 1325 |
/// It must conform to the \ref concepts::Graph "Graph" concept. |
1319 | 1326 |
/// It can also be specified to be \c const. |
1320 | 1327 |
/// \tparam NF The type of the node filter map. |
1321 | 1328 |
/// It must be a \c bool (or convertible) node map of the |
1322 | 1329 |
/// adapted graph. The default type is |
1323 | 1330 |
/// \ref concepts::Graph::NodeMap "GR::NodeMap<bool>". |
1324 | 1331 |
/// \tparam EF The type of the edge filter map. |
1325 | 1332 |
/// It must be a \c bool (or convertible) edge map of the |
1326 | 1333 |
/// adapted graph. The default type is |
1327 | 1334 |
/// \ref concepts::Graph::EdgeMap "GR::EdgeMap<bool>". |
1328 | 1335 |
/// |
1329 | 1336 |
/// \note The \c Node, \c Edge and \c Arc types of this adaptor and the |
1330 | 1337 |
/// adapted graph are convertible to each other. |
1331 | 1338 |
/// |
1332 | 1339 |
/// \see FilterNodes |
1333 | 1340 |
/// \see FilterEdges |
1334 | 1341 |
#ifdef DOXYGEN |
1335 | 1342 |
template<typename GR, typename NF, typename EF> |
1336 | 1343 |
class SubGraph { |
1337 | 1344 |
#else |
1338 | 1345 |
template<typename GR, |
1339 | 1346 |
typename NF = typename GR::template NodeMap<bool>, |
1340 | 1347 |
typename EF = typename GR::template EdgeMap<bool> > |
1341 | 1348 |
class SubGraph : |
1342 | 1349 |
public GraphAdaptorExtender<SubGraphBase<GR, NF, EF, true> > { |
1343 | 1350 |
#endif |
1344 | 1351 |
public: |
1345 | 1352 |
/// The type of the adapted graph. |
1346 | 1353 |
typedef GR Graph; |
1347 | 1354 |
/// The type of the node filter map. |
1348 | 1355 |
typedef NF NodeFilterMap; |
... | ... |
@@ -1442,64 +1449,66 @@ |
1442 | 1449 |
|
1443 | 1450 |
template<typename GR, typename NF, typename EF> |
1444 | 1451 |
SubGraph<const GR, NF, const EF> |
1445 | 1452 |
subGraph(const GR& graph, NF& node_filter, const EF& edge_filter) { |
1446 | 1453 |
return SubGraph<const GR, NF, const EF> |
1447 | 1454 |
(graph, node_filter, edge_filter); |
1448 | 1455 |
} |
1449 | 1456 |
|
1450 | 1457 |
template<typename GR, typename NF, typename EF> |
1451 | 1458 |
SubGraph<const GR, const NF, const EF> |
1452 | 1459 |
subGraph(const GR& graph, const NF& node_filter, const EF& edge_filter) { |
1453 | 1460 |
return SubGraph<const GR, const NF, const EF> |
1454 | 1461 |
(graph, node_filter, edge_filter); |
1455 | 1462 |
} |
1456 | 1463 |
|
1457 | 1464 |
|
1458 | 1465 |
/// \ingroup graph_adaptors |
1459 | 1466 |
/// |
1460 | 1467 |
/// \brief Adaptor class for hiding nodes in a digraph or a graph. |
1461 | 1468 |
/// |
1462 | 1469 |
/// FilterNodes adaptor can be used for hiding nodes in a digraph or a |
1463 | 1470 |
/// graph. A \c bool node map must be specified, which defines the filter |
1464 | 1471 |
/// for the nodes. Only the nodes with \c true filter value and the |
1465 | 1472 |
/// arcs/edges incident to nodes both with \c true filter value are shown |
1466 | 1473 |
/// in the subgraph. This adaptor conforms to the \ref concepts::Digraph |
1467 | 1474 |
/// "Digraph" concept or the \ref concepts::Graph "Graph" concept |
1468 | 1475 |
/// depending on the \c GR template parameter. |
1469 | 1476 |
/// |
1470 | 1477 |
/// The adapted (di)graph can also be modified through this adaptor |
1471 | 1478 |
/// by adding or removing nodes or arcs/edges, unless the \c GR template |
1472 | 1479 |
/// parameter is set to be \c const. |
1473 | 1480 |
/// |
1481 |
/// This class provides only linear time item counting. |
|
1482 |
/// |
|
1474 | 1483 |
/// \tparam GR The type of the adapted digraph or graph. |
1475 | 1484 |
/// It must conform to the \ref concepts::Digraph "Digraph" concept |
1476 | 1485 |
/// or the \ref concepts::Graph "Graph" concept. |
1477 | 1486 |
/// It can also be specified to be \c const. |
1478 | 1487 |
/// \tparam NF The type of the node filter map. |
1479 | 1488 |
/// It must be a \c bool (or convertible) node map of the |
1480 | 1489 |
/// adapted (di)graph. The default type is |
1481 | 1490 |
/// \ref concepts::Graph::NodeMap "GR::NodeMap<bool>". |
1482 | 1491 |
/// |
1483 | 1492 |
/// \note The \c Node and <tt>Arc/Edge</tt> types of this adaptor and the |
1484 | 1493 |
/// adapted (di)graph are convertible to each other. |
1485 | 1494 |
#ifdef DOXYGEN |
1486 | 1495 |
template<typename GR, typename NF> |
1487 | 1496 |
class FilterNodes { |
1488 | 1497 |
#else |
1489 | 1498 |
template<typename GR, |
1490 | 1499 |
typename NF = typename GR::template NodeMap<bool>, |
1491 | 1500 |
typename Enable = void> |
1492 | 1501 |
class FilterNodes : |
1493 | 1502 |
public DigraphAdaptorExtender< |
1494 | 1503 |
SubDigraphBase<GR, NF, ConstMap<typename GR::Arc, Const<bool, true> >, |
1495 | 1504 |
true> > { |
1496 | 1505 |
#endif |
1497 | 1506 |
typedef DigraphAdaptorExtender< |
1498 | 1507 |
SubDigraphBase<GR, NF, ConstMap<typename GR::Arc, Const<bool, true> >, |
1499 | 1508 |
true> > Parent; |
1500 | 1509 |
|
1501 | 1510 |
public: |
1502 | 1511 |
|
1503 | 1512 |
typedef GR Digraph; |
1504 | 1513 |
typedef NF NodeFilterMap; |
1505 | 1514 |
|
... | ... |
@@ -1590,64 +1599,66 @@ |
1590 | 1599 |
|
1591 | 1600 |
/// \brief Returns a read-only FilterNodes adaptor |
1592 | 1601 |
/// |
1593 | 1602 |
/// This function just returns a read-only \ref FilterNodes adaptor. |
1594 | 1603 |
/// \ingroup graph_adaptors |
1595 | 1604 |
/// \relates FilterNodes |
1596 | 1605 |
template<typename GR, typename NF> |
1597 | 1606 |
FilterNodes<const GR, NF> |
1598 | 1607 |
filterNodes(const GR& graph, NF& node_filter) { |
1599 | 1608 |
return FilterNodes<const GR, NF>(graph, node_filter); |
1600 | 1609 |
} |
1601 | 1610 |
|
1602 | 1611 |
template<typename GR, typename NF> |
1603 | 1612 |
FilterNodes<const GR, const NF> |
1604 | 1613 |
filterNodes(const GR& graph, const NF& node_filter) { |
1605 | 1614 |
return FilterNodes<const GR, const NF>(graph, node_filter); |
1606 | 1615 |
} |
1607 | 1616 |
|
1608 | 1617 |
/// \ingroup graph_adaptors |
1609 | 1618 |
/// |
1610 | 1619 |
/// \brief Adaptor class for hiding arcs in a digraph. |
1611 | 1620 |
/// |
1612 | 1621 |
/// FilterArcs adaptor can be used for hiding arcs in a digraph. |
1613 | 1622 |
/// A \c bool arc map must be specified, which defines the filter for |
1614 | 1623 |
/// the arcs. Only the arcs with \c true filter value are shown in the |
1615 | 1624 |
/// subdigraph. This adaptor conforms to the \ref concepts::Digraph |
1616 | 1625 |
/// "Digraph" concept. |
1617 | 1626 |
/// |
1618 | 1627 |
/// The adapted digraph can also be modified through this adaptor |
1619 | 1628 |
/// by adding or removing nodes or arcs, unless the \c GR template |
1620 | 1629 |
/// parameter is set to be \c const. |
1621 | 1630 |
/// |
1631 |
/// This class provides only linear time counting for nodes and arcs. |
|
1632 |
/// |
|
1622 | 1633 |
/// \tparam DGR The type of the adapted digraph. |
1623 | 1634 |
/// It must conform to the \ref concepts::Digraph "Digraph" concept. |
1624 | 1635 |
/// It can also be specified to be \c const. |
1625 | 1636 |
/// \tparam AF The type of the arc filter map. |
1626 | 1637 |
/// It must be a \c bool (or convertible) arc map of the |
1627 | 1638 |
/// adapted digraph. The default type is |
1628 | 1639 |
/// \ref concepts::Digraph::ArcMap "DGR::ArcMap<bool>". |
1629 | 1640 |
/// |
1630 | 1641 |
/// \note The \c Node and \c Arc types of this adaptor and the adapted |
1631 | 1642 |
/// digraph are convertible to each other. |
1632 | 1643 |
#ifdef DOXYGEN |
1633 | 1644 |
template<typename DGR, |
1634 | 1645 |
typename AF> |
1635 | 1646 |
class FilterArcs { |
1636 | 1647 |
#else |
1637 | 1648 |
template<typename DGR, |
1638 | 1649 |
typename AF = typename DGR::template ArcMap<bool> > |
1639 | 1650 |
class FilterArcs : |
1640 | 1651 |
public DigraphAdaptorExtender< |
1641 | 1652 |
SubDigraphBase<DGR, ConstMap<typename DGR::Node, Const<bool, true> >, |
1642 | 1653 |
AF, false> > { |
1643 | 1654 |
#endif |
1644 | 1655 |
typedef DigraphAdaptorExtender< |
1645 | 1656 |
SubDigraphBase<DGR, ConstMap<typename DGR::Node, Const<bool, true> >, |
1646 | 1657 |
AF, false> > Parent; |
1647 | 1658 |
|
1648 | 1659 |
public: |
1649 | 1660 |
|
1650 | 1661 |
/// The type of the adapted digraph. |
1651 | 1662 |
typedef DGR Digraph; |
1652 | 1663 |
/// The type of the arc filter map. |
1653 | 1664 |
typedef AF ArcFilterMap; |
... | ... |
@@ -1700,64 +1711,66 @@ |
1700 | 1711 |
|
1701 | 1712 |
/// \brief Returns a read-only FilterArcs adaptor |
1702 | 1713 |
/// |
1703 | 1714 |
/// This function just returns a read-only \ref FilterArcs adaptor. |
1704 | 1715 |
/// \ingroup graph_adaptors |
1705 | 1716 |
/// \relates FilterArcs |
1706 | 1717 |
template<typename DGR, typename AF> |
1707 | 1718 |
FilterArcs<const DGR, AF> |
1708 | 1719 |
filterArcs(const DGR& digraph, AF& arc_filter) { |
1709 | 1720 |
return FilterArcs<const DGR, AF>(digraph, arc_filter); |
1710 | 1721 |
} |
1711 | 1722 |
|
1712 | 1723 |
template<typename DGR, typename AF> |
1713 | 1724 |
FilterArcs<const DGR, const AF> |
1714 | 1725 |
filterArcs(const DGR& digraph, const AF& arc_filter) { |
1715 | 1726 |
return FilterArcs<const DGR, const AF>(digraph, arc_filter); |
1716 | 1727 |
} |
1717 | 1728 |
|
1718 | 1729 |
/// \ingroup graph_adaptors |
1719 | 1730 |
/// |
1720 | 1731 |
/// \brief Adaptor class for hiding edges in a graph. |
1721 | 1732 |
/// |
1722 | 1733 |
/// FilterEdges adaptor can be used for hiding edges in a graph. |
1723 | 1734 |
/// A \c bool edge map must be specified, which defines the filter for |
1724 | 1735 |
/// the edges. Only the edges with \c true filter value are shown in the |
1725 | 1736 |
/// subgraph. This adaptor conforms to the \ref concepts::Graph |
1726 | 1737 |
/// "Graph" concept. |
1727 | 1738 |
/// |
1728 | 1739 |
/// The adapted graph can also be modified through this adaptor |
1729 | 1740 |
/// by adding or removing nodes or edges, unless the \c GR template |
1730 | 1741 |
/// parameter is set to be \c const. |
1731 | 1742 |
/// |
1743 |
/// This class provides only linear time counting for nodes, edges and arcs. |
|
1744 |
/// |
|
1732 | 1745 |
/// \tparam GR The type of the adapted graph. |
1733 | 1746 |
/// It must conform to the \ref concepts::Graph "Graph" concept. |
1734 | 1747 |
/// It can also be specified to be \c const. |
1735 | 1748 |
/// \tparam EF The type of the edge filter map. |
1736 | 1749 |
/// It must be a \c bool (or convertible) edge map of the |
1737 | 1750 |
/// adapted graph. The default type is |
1738 | 1751 |
/// \ref concepts::Graph::EdgeMap "GR::EdgeMap<bool>". |
1739 | 1752 |
/// |
1740 | 1753 |
/// \note The \c Node, \c Edge and \c Arc types of this adaptor and the |
1741 | 1754 |
/// adapted graph are convertible to each other. |
1742 | 1755 |
#ifdef DOXYGEN |
1743 | 1756 |
template<typename GR, |
1744 | 1757 |
typename EF> |
1745 | 1758 |
class FilterEdges { |
1746 | 1759 |
#else |
1747 | 1760 |
template<typename GR, |
1748 | 1761 |
typename EF = typename GR::template EdgeMap<bool> > |
1749 | 1762 |
class FilterEdges : |
1750 | 1763 |
public GraphAdaptorExtender< |
1751 | 1764 |
SubGraphBase<GR, ConstMap<typename GR::Node, Const<bool, true> >, |
1752 | 1765 |
EF, false> > { |
1753 | 1766 |
#endif |
1754 | 1767 |
typedef GraphAdaptorExtender< |
1755 | 1768 |
SubGraphBase<GR, ConstMap<typename GR::Node, Const<bool, true > >, |
1756 | 1769 |
EF, false> > Parent; |
1757 | 1770 |
|
1758 | 1771 |
public: |
1759 | 1772 |
|
1760 | 1773 |
/// The type of the adapted graph. |
1761 | 1774 |
typedef GR Graph; |
1762 | 1775 |
/// The type of the edge filter map. |
1763 | 1776 |
typedef EF EdgeFilterMap; |
... | ... |
@@ -2203,64 +2216,67 @@ |
2203 | 2216 |
|
2204 | 2217 |
typedef typename ItemSetTraits<DGR, Edge>::ItemNotifier EdgeNotifier; |
2205 | 2218 |
EdgeNotifier& notifier(Edge) const { return _digraph->notifier(Edge()); } |
2206 | 2219 |
|
2207 | 2220 |
typedef EdgeNotifier ArcNotifier; |
2208 | 2221 |
ArcNotifier& notifier(Arc) const { return _digraph->notifier(Edge()); } |
2209 | 2222 |
|
2210 | 2223 |
protected: |
2211 | 2224 |
|
2212 | 2225 |
UndirectorBase() : _digraph(0) {} |
2213 | 2226 |
|
2214 | 2227 |
DGR* _digraph; |
2215 | 2228 |
|
2216 | 2229 |
void initialize(DGR& digraph) { |
2217 | 2230 |
_digraph = &digraph; |
2218 | 2231 |
} |
2219 | 2232 |
|
2220 | 2233 |
}; |
2221 | 2234 |
|
2222 | 2235 |
/// \ingroup graph_adaptors |
2223 | 2236 |
/// |
2224 | 2237 |
/// \brief Adaptor class for viewing a digraph as an undirected graph. |
2225 | 2238 |
/// |
2226 | 2239 |
/// Undirector adaptor can be used for viewing a digraph as an undirected |
2227 | 2240 |
/// graph. All arcs of the underlying digraph are showed in the |
2228 | 2241 |
/// adaptor as an edge (and also as a pair of arcs, of course). |
2229 | 2242 |
/// This adaptor conforms to the \ref concepts::Graph "Graph" concept. |
2230 | 2243 |
/// |
2231 | 2244 |
/// The adapted digraph can also be modified through this adaptor |
2232 | 2245 |
/// by adding or removing nodes or edges, unless the \c GR template |
2233 | 2246 |
/// parameter is set to be \c const. |
2234 | 2247 |
/// |
2248 |
/// This class provides item counting in the same time as the adapted |
|
2249 |
/// digraph structure. |
|
2250 |
/// |
|
2235 | 2251 |
/// \tparam DGR The type of the adapted digraph. |
2236 | 2252 |
/// It must conform to the \ref concepts::Digraph "Digraph" concept. |
2237 | 2253 |
/// It can also be specified to be \c const. |
2238 | 2254 |
/// |
2239 | 2255 |
/// \note The \c Node type of this adaptor and the adapted digraph are |
2240 | 2256 |
/// convertible to each other, moreover the \c Edge type of the adaptor |
2241 | 2257 |
/// and the \c Arc type of the adapted digraph are also convertible to |
2242 | 2258 |
/// each other. |
2243 | 2259 |
/// (Thus the \c Arc type of the adaptor is convertible to the \c Arc type |
2244 | 2260 |
/// of the adapted digraph.) |
2245 | 2261 |
template<typename DGR> |
2246 | 2262 |
#ifdef DOXYGEN |
2247 | 2263 |
class Undirector { |
2248 | 2264 |
#else |
2249 | 2265 |
class Undirector : |
2250 | 2266 |
public GraphAdaptorExtender<UndirectorBase<DGR> > { |
2251 | 2267 |
#endif |
2252 | 2268 |
typedef GraphAdaptorExtender<UndirectorBase<DGR> > Parent; |
2253 | 2269 |
public: |
2254 | 2270 |
/// The type of the adapted digraph. |
2255 | 2271 |
typedef DGR Digraph; |
2256 | 2272 |
protected: |
2257 | 2273 |
Undirector() { } |
2258 | 2274 |
public: |
2259 | 2275 |
|
2260 | 2276 |
/// \brief Constructor |
2261 | 2277 |
/// |
2262 | 2278 |
/// Creates an undirected graph from the given digraph. |
2263 | 2279 |
Undirector(DGR& digraph) { |
2264 | 2280 |
initialize(digraph); |
2265 | 2281 |
} |
2266 | 2282 |
|
... | ... |
@@ -2506,64 +2522,67 @@ |
2506 | 2522 |
return *this; |
2507 | 2523 |
} |
2508 | 2524 |
}; |
2509 | 2525 |
|
2510 | 2526 |
|
2511 | 2527 |
|
2512 | 2528 |
protected: |
2513 | 2529 |
Graph* _graph; |
2514 | 2530 |
DM* _direction; |
2515 | 2531 |
|
2516 | 2532 |
void initialize(GR& graph, DM& direction) { |
2517 | 2533 |
_graph = &graph; |
2518 | 2534 |
_direction = &direction; |
2519 | 2535 |
} |
2520 | 2536 |
|
2521 | 2537 |
}; |
2522 | 2538 |
|
2523 | 2539 |
/// \ingroup graph_adaptors |
2524 | 2540 |
/// |
2525 | 2541 |
/// \brief Adaptor class for orienting the edges of a graph to get a digraph |
2526 | 2542 |
/// |
2527 | 2543 |
/// Orienter adaptor can be used for orienting the edges of a graph to |
2528 | 2544 |
/// get a digraph. A \c bool edge map of the underlying graph must be |
2529 | 2545 |
/// specified, which define the direction of the arcs in the adaptor. |
2530 | 2546 |
/// The arcs can be easily reversed by the \c reverseArc() member function |
2531 | 2547 |
/// of the adaptor. |
2532 | 2548 |
/// This class conforms to the \ref concepts::Digraph "Digraph" concept. |
2533 | 2549 |
/// |
2534 | 2550 |
/// The adapted graph can also be modified through this adaptor |
2535 | 2551 |
/// by adding or removing nodes or arcs, unless the \c GR template |
2536 | 2552 |
/// parameter is set to be \c const. |
2537 | 2553 |
/// |
2554 |
/// This class provides item counting in the same time as the adapted |
|
2555 |
/// graph structure. |
|
2556 |
/// |
|
2538 | 2557 |
/// \tparam GR The type of the adapted graph. |
2539 | 2558 |
/// It must conform to the \ref concepts::Graph "Graph" concept. |
2540 | 2559 |
/// It can also be specified to be \c const. |
2541 | 2560 |
/// \tparam DM The type of the direction map. |
2542 | 2561 |
/// It must be a \c bool (or convertible) edge map of the |
2543 | 2562 |
/// adapted graph. The default type is |
2544 | 2563 |
/// \ref concepts::Graph::EdgeMap "GR::EdgeMap<bool>". |
2545 | 2564 |
/// |
2546 | 2565 |
/// \note The \c Node type of this adaptor and the adapted graph are |
2547 | 2566 |
/// convertible to each other, moreover the \c Arc type of the adaptor |
2548 | 2567 |
/// and the \c Edge type of the adapted graph are also convertible to |
2549 | 2568 |
/// each other. |
2550 | 2569 |
#ifdef DOXYGEN |
2551 | 2570 |
template<typename GR, |
2552 | 2571 |
typename DM> |
2553 | 2572 |
class Orienter { |
2554 | 2573 |
#else |
2555 | 2574 |
template<typename GR, |
2556 | 2575 |
typename DM = typename GR::template EdgeMap<bool> > |
2557 | 2576 |
class Orienter : |
2558 | 2577 |
public DigraphAdaptorExtender<OrienterBase<GR, DM> > { |
2559 | 2578 |
#endif |
2560 | 2579 |
typedef DigraphAdaptorExtender<OrienterBase<GR, DM> > Parent; |
2561 | 2580 |
public: |
2562 | 2581 |
|
2563 | 2582 |
/// The type of the adapted graph. |
2564 | 2583 |
typedef GR Graph; |
2565 | 2584 |
/// The type of the direction edge map. |
2566 | 2585 |
typedef DM DirectionMap; |
2567 | 2586 |
|
2568 | 2587 |
typedef typename Parent::Arc Arc; |
2569 | 2588 |
|
... | ... |
@@ -2649,64 +2668,66 @@ |
2649 | 2668 |
|
2650 | 2669 |
ResBackwardFilter(const CM& capacity, const FM& flow, |
2651 | 2670 |
const TL& tolerance = TL()) |
2652 | 2671 |
: _capacity(&capacity), _flow(&flow), _tolerance(tolerance) { } |
2653 | 2672 |
|
2654 | 2673 |
bool operator[](const typename DGR::Arc& a) const { |
2655 | 2674 |
return _tolerance.positive((*_flow)[a]); |
2656 | 2675 |
} |
2657 | 2676 |
}; |
2658 | 2677 |
|
2659 | 2678 |
} |
2660 | 2679 |
|
2661 | 2680 |
/// \ingroup graph_adaptors |
2662 | 2681 |
/// |
2663 | 2682 |
/// \brief Adaptor class for composing the residual digraph for directed |
2664 | 2683 |
/// flow and circulation problems. |
2665 | 2684 |
/// |
2666 | 2685 |
/// ResidualDigraph can be used for composing the \e residual digraph |
2667 | 2686 |
/// for directed flow and circulation problems. Let \f$ G=(V, A) \f$ |
2668 | 2687 |
/// be a directed graph and let \f$ F \f$ be a number type. |
2669 | 2688 |
/// Let \f$ flow, cap: A\to F \f$ be functions on the arcs. |
2670 | 2689 |
/// This adaptor implements a digraph structure with node set \f$ V \f$ |
2671 | 2690 |
/// and arc set \f$ A_{forward}\cup A_{backward} \f$, |
2672 | 2691 |
/// where \f$ A_{forward}=\{uv : uv\in A, flow(uv)<cap(uv)\} \f$ and |
2673 | 2692 |
/// \f$ A_{backward}=\{vu : uv\in A, flow(uv)>0\} \f$, i.e. the so |
2674 | 2693 |
/// called residual digraph. |
2675 | 2694 |
/// When the union \f$ A_{forward}\cup A_{backward} \f$ is taken, |
2676 | 2695 |
/// multiplicities are counted, i.e. the adaptor has exactly |
2677 | 2696 |
/// \f$ |A_{forward}| + |A_{backward}|\f$ arcs (it may have parallel |
2678 | 2697 |
/// arcs). |
2679 | 2698 |
/// This class conforms to the \ref concepts::Digraph "Digraph" concept. |
2680 | 2699 |
/// |
2700 |
/// This class provides only linear time counting for nodes and arcs. |
|
2701 |
/// |
|
2681 | 2702 |
/// \tparam DGR The type of the adapted digraph. |
2682 | 2703 |
/// It must conform to the \ref concepts::Digraph "Digraph" concept. |
2683 | 2704 |
/// It is implicitly \c const. |
2684 | 2705 |
/// \tparam CM The type of the capacity map. |
2685 | 2706 |
/// It must be an arc map of some numerical type, which defines |
2686 | 2707 |
/// the capacities in the flow problem. It is implicitly \c const. |
2687 | 2708 |
/// The default type is |
2688 | 2709 |
/// \ref concepts::Digraph::ArcMap "GR::ArcMap<int>". |
2689 | 2710 |
/// \tparam FM The type of the flow map. |
2690 | 2711 |
/// It must be an arc map of some numerical type, which defines |
2691 | 2712 |
/// the flow values in the flow problem. The default type is \c CM. |
2692 | 2713 |
/// \tparam TL The tolerance type for handling inexact computation. |
2693 | 2714 |
/// The default tolerance type depends on the value type of the |
2694 | 2715 |
/// capacity map. |
2695 | 2716 |
/// |
2696 | 2717 |
/// \note This adaptor is implemented using Undirector and FilterArcs |
2697 | 2718 |
/// adaptors. |
2698 | 2719 |
/// |
2699 | 2720 |
/// \note The \c Node type of this adaptor and the adapted digraph are |
2700 | 2721 |
/// convertible to each other, moreover the \c Arc type of the adaptor |
2701 | 2722 |
/// is convertible to the \c Arc type of the adapted digraph. |
2702 | 2723 |
#ifdef DOXYGEN |
2703 | 2724 |
template<typename DGR, typename CM, typename FM, typename TL> |
2704 | 2725 |
class ResidualDigraph |
2705 | 2726 |
#else |
2706 | 2727 |
template<typename DGR, |
2707 | 2728 |
typename CM = typename DGR::template ArcMap<int>, |
2708 | 2729 |
typename FM = CM, |
2709 | 2730 |
typename TL = Tolerance<typename CM::Value> > |
2710 | 2731 |
class ResidualDigraph |
2711 | 2732 |
: public SubDigraph< |
2712 | 2733 |
Undirector<const DGR>, |
... | ... |
@@ -3296,64 +3317,67 @@ |
3296 | 3317 |
|
3297 | 3318 |
SplitNodesBase() : _digraph(0) {} |
3298 | 3319 |
|
3299 | 3320 |
DGR* _digraph; |
3300 | 3321 |
|
3301 | 3322 |
void initialize(Digraph& digraph) { |
3302 | 3323 |
_digraph = &digraph; |
3303 | 3324 |
} |
3304 | 3325 |
|
3305 | 3326 |
}; |
3306 | 3327 |
|
3307 | 3328 |
/// \ingroup graph_adaptors |
3308 | 3329 |
/// |
3309 | 3330 |
/// \brief Adaptor class for splitting the nodes of a digraph. |
3310 | 3331 |
/// |
3311 | 3332 |
/// SplitNodes adaptor can be used for splitting each node into an |
3312 | 3333 |
/// \e in-node and an \e out-node in a digraph. Formaly, the adaptor |
3313 | 3334 |
/// replaces each node \f$ u \f$ in the digraph with two nodes, |
3314 | 3335 |
/// namely node \f$ u_{in} \f$ and node \f$ u_{out} \f$. |
3315 | 3336 |
/// If there is a \f$ (v, u) \f$ arc in the original digraph, then the |
3316 | 3337 |
/// new target of the arc will be \f$ u_{in} \f$ and similarly the |
3317 | 3338 |
/// source of each original \f$ (u, v) \f$ arc will be \f$ u_{out} \f$. |
3318 | 3339 |
/// The adaptor adds an additional \e bind \e arc from \f$ u_{in} \f$ |
3319 | 3340 |
/// to \f$ u_{out} \f$ for each node \f$ u \f$ of the original digraph. |
3320 | 3341 |
/// |
3321 | 3342 |
/// The aim of this class is running an algorithm with respect to node |
3322 | 3343 |
/// costs or capacities if the algorithm considers only arc costs or |
3323 | 3344 |
/// capacities directly. |
3324 | 3345 |
/// In this case you can use \c SplitNodes adaptor, and set the node |
3325 | 3346 |
/// costs/capacities of the original digraph to the \e bind \e arcs |
3326 | 3347 |
/// in the adaptor. |
3327 | 3348 |
/// |
3349 |
/// This class provides item counting in the same time as the adapted |
|
3350 |
/// digraph structure. |
|
3351 |
/// |
|
3328 | 3352 |
/// \tparam DGR The type of the adapted digraph. |
3329 | 3353 |
/// It must conform to the \ref concepts::Digraph "Digraph" concept. |
3330 | 3354 |
/// It is implicitly \c const. |
3331 | 3355 |
/// |
3332 | 3356 |
/// \note The \c Node type of this adaptor is converible to the \c Node |
3333 | 3357 |
/// type of the adapted digraph. |
3334 | 3358 |
template <typename DGR> |
3335 | 3359 |
#ifdef DOXYGEN |
3336 | 3360 |
class SplitNodes { |
3337 | 3361 |
#else |
3338 | 3362 |
class SplitNodes |
3339 | 3363 |
: public DigraphAdaptorExtender<SplitNodesBase<const DGR> > { |
3340 | 3364 |
#endif |
3341 | 3365 |
typedef DigraphAdaptorExtender<SplitNodesBase<const DGR> > Parent; |
3342 | 3366 |
|
3343 | 3367 |
public: |
3344 | 3368 |
typedef DGR Digraph; |
3345 | 3369 |
|
3346 | 3370 |
typedef typename DGR::Node DigraphNode; |
3347 | 3371 |
typedef typename DGR::Arc DigraphArc; |
3348 | 3372 |
|
3349 | 3373 |
typedef typename Parent::Node Node; |
3350 | 3374 |
typedef typename Parent::Arc Arc; |
3351 | 3375 |
|
3352 | 3376 |
/// \brief Constructor |
3353 | 3377 |
/// |
3354 | 3378 |
/// Constructor of the adaptor. |
3355 | 3379 |
SplitNodes(const DGR& g) { |
3356 | 3380 |
Parent::initialize(g); |
3357 | 3381 |
} |
3358 | 3382 |
|
3359 | 3383 |
/// \brief Returns \c true if the given node is an in-node. |
1 | 1 |
/* -*- C++ -*- |
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_BELLMAN_FORD_H |
20 | 20 |
#define LEMON_BELLMAN_FORD_H |
21 | 21 |
|
22 | 22 |
/// \ingroup shortest_path |
23 | 23 |
/// \file |
24 | 24 |
/// \brief Bellman-Ford algorithm. |
25 | 25 |
|
26 |
#include <lemon/list_graph.h> |
|
26 | 27 |
#include <lemon/bits/path_dump.h> |
27 | 28 |
#include <lemon/core.h> |
28 | 29 |
#include <lemon/error.h> |
29 | 30 |
#include <lemon/maps.h> |
30 | 31 |
#include <lemon/path.h> |
31 | 32 |
|
32 | 33 |
#include <limits> |
33 | 34 |
|
34 | 35 |
namespace lemon { |
35 | 36 |
|
36 | 37 |
/// \brief Default OperationTraits for the BellmanFord algorithm class. |
37 | 38 |
/// |
38 | 39 |
/// This operation traits class defines all computational operations |
39 | 40 |
/// and constants that are used in the Bellman-Ford algorithm. |
40 | 41 |
/// The default implementation is based on the \c numeric_limits class. |
41 | 42 |
/// If the numeric type does not have infinity value, then the maximum |
42 | 43 |
/// value is used as extremal infinity value. |
43 | 44 |
template < |
44 | 45 |
typename V, |
45 | 46 |
bool has_inf = std::numeric_limits<V>::has_infinity> |
46 | 47 |
struct BellmanFordDefaultOperationTraits { |
47 | 48 |
/// \e |
48 | 49 |
typedef V Value; |
49 | 50 |
/// \brief Gives back the zero value of the type. |
50 | 51 |
static Value zero() { |
51 | 52 |
return static_cast<Value>(0); |
52 | 53 |
} |
53 | 54 |
/// \brief Gives back the positive infinity value of the type. |
54 | 55 |
static Value infinity() { |
55 | 56 |
return std::numeric_limits<Value>::infinity(); |
56 | 57 |
} |
57 | 58 |
/// \brief Gives back the sum of the given two elements. |
... | ... |
@@ -270,65 +271,65 @@ |
270 | 271 |
|
271 | 272 |
template <class T> |
272 | 273 |
struct SetDistMapTraits : public Traits { |
273 | 274 |
typedef T DistMap; |
274 | 275 |
static DistMap *createDistMap(const Digraph&) { |
275 | 276 |
LEMON_ASSERT(false, "DistMap is not initialized"); |
276 | 277 |
return 0; // ignore warnings |
277 | 278 |
} |
278 | 279 |
}; |
279 | 280 |
|
280 | 281 |
/// \brief \ref named-templ-param "Named parameter" for setting |
281 | 282 |
/// \c DistMap type. |
282 | 283 |
/// |
283 | 284 |
/// \ref named-templ-param "Named parameter" for setting |
284 | 285 |
/// \c DistMap type. |
285 | 286 |
/// It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
286 | 287 |
template <class T> |
287 | 288 |
struct SetDistMap |
288 | 289 |
: public BellmanFord< Digraph, LengthMap, SetDistMapTraits<T> > { |
289 | 290 |
typedef BellmanFord< Digraph, LengthMap, SetDistMapTraits<T> > Create; |
290 | 291 |
}; |
291 | 292 |
|
292 | 293 |
template <class T> |
293 | 294 |
struct SetOperationTraitsTraits : public Traits { |
294 | 295 |
typedef T OperationTraits; |
295 | 296 |
}; |
296 | 297 |
|
297 | 298 |
/// \brief \ref named-templ-param "Named parameter" for setting |
298 | 299 |
/// \c OperationTraits type. |
299 | 300 |
/// |
300 | 301 |
/// \ref named-templ-param "Named parameter" for setting |
301 | 302 |
/// \c OperationTraits type. |
302 |
/// For more information see \ref BellmanFordDefaultOperationTraits. |
|
303 |
/// For more information, see \ref BellmanFordDefaultOperationTraits. |
|
303 | 304 |
template <class T> |
304 | 305 |
struct SetOperationTraits |
305 | 306 |
: public BellmanFord< Digraph, LengthMap, SetOperationTraitsTraits<T> > { |
306 | 307 |
typedef BellmanFord< Digraph, LengthMap, SetOperationTraitsTraits<T> > |
307 | 308 |
Create; |
308 | 309 |
}; |
309 | 310 |
|
310 | 311 |
///@} |
311 | 312 |
|
312 | 313 |
protected: |
313 | 314 |
|
314 | 315 |
BellmanFord() {} |
315 | 316 |
|
316 | 317 |
public: |
317 | 318 |
|
318 | 319 |
/// \brief Constructor. |
319 | 320 |
/// |
320 | 321 |
/// Constructor. |
321 | 322 |
/// \param g The digraph the algorithm runs on. |
322 | 323 |
/// \param length The length map used by the algorithm. |
323 | 324 |
BellmanFord(const Digraph& g, const LengthMap& length) : |
324 | 325 |
_gr(&g), _length(&length), |
325 | 326 |
_pred(0), _local_pred(false), |
326 | 327 |
_dist(0), _local_dist(false), _mask(0) {} |
327 | 328 |
|
328 | 329 |
///Destructor. |
329 | 330 |
~BellmanFord() { |
330 | 331 |
if(_local_pred) delete _pred; |
331 | 332 |
if(_local_dist) delete _dist; |
332 | 333 |
if(_mask) delete _mask; |
333 | 334 |
} |
334 | 335 |
|
... | ... |
@@ -688,123 +689,123 @@ |
688 | 689 |
/// |
689 | 690 |
/// Gives back the shortest path to the given node from the root(s). |
690 | 691 |
/// |
691 | 692 |
/// \warning \c t should be reached from the root(s). |
692 | 693 |
/// |
693 | 694 |
/// \pre Either \ref run() or \ref init() must be called before |
694 | 695 |
/// using this function. |
695 | 696 |
Path path(Node t) const |
696 | 697 |
{ |
697 | 698 |
return Path(*_gr, *_pred, t); |
698 | 699 |
} |
699 | 700 |
|
700 | 701 |
/// \brief The distance of the given node from the root(s). |
701 | 702 |
/// |
702 | 703 |
/// Returns the distance of the given node from the root(s). |
703 | 704 |
/// |
704 | 705 |
/// \warning If node \c v is not reached from the root(s), then |
705 | 706 |
/// the return value of this function is undefined. |
706 | 707 |
/// |
707 | 708 |
/// \pre Either \ref run() or \ref init() must be called before |
708 | 709 |
/// using this function. |
709 | 710 |
Value dist(Node v) const { return (*_dist)[v]; } |
710 | 711 |
|
711 | 712 |
/// \brief Returns the 'previous arc' of the shortest path tree for |
712 | 713 |
/// the given node. |
713 | 714 |
/// |
714 | 715 |
/// This function returns the 'previous arc' of the shortest path |
715 | 716 |
/// tree for node \c v, i.e. it returns the last arc of a |
716 | 717 |
/// shortest path from a root to \c v. It is \c INVALID if \c v |
717 | 718 |
/// is not reached from the root(s) or if \c v is a root. |
718 | 719 |
/// |
719 | 720 |
/// The shortest path tree used here is equal to the shortest path |
720 |
/// tree used in \ref predNode() and \predMap(). |
|
721 |
/// tree used in \ref predNode() and \ref predMap(). |
|
721 | 722 |
/// |
722 | 723 |
/// \pre Either \ref run() or \ref init() must be called before |
723 | 724 |
/// using this function. |
724 | 725 |
Arc predArc(Node v) const { return (*_pred)[v]; } |
725 | 726 |
|
726 | 727 |
/// \brief Returns the 'previous node' of the shortest path tree for |
727 | 728 |
/// the given node. |
728 | 729 |
/// |
729 | 730 |
/// This function returns the 'previous node' of the shortest path |
730 | 731 |
/// tree for node \c v, i.e. it returns the last but one node of |
731 | 732 |
/// a shortest path from a root to \c v. It is \c INVALID if \c v |
732 | 733 |
/// is not reached from the root(s) or if \c v is a root. |
733 | 734 |
/// |
734 | 735 |
/// The shortest path tree used here is equal to the shortest path |
735 |
/// tree used in \ref predArc() and \predMap(). |
|
736 |
/// tree used in \ref predArc() and \ref predMap(). |
|
736 | 737 |
/// |
737 | 738 |
/// \pre Either \ref run() or \ref init() must be called before |
738 | 739 |
/// using this function. |
739 | 740 |
Node predNode(Node v) const { |
740 | 741 |
return (*_pred)[v] == INVALID ? INVALID : _gr->source((*_pred)[v]); |
741 | 742 |
} |
742 | 743 |
|
743 | 744 |
/// \brief Returns a const reference to the node map that stores the |
744 | 745 |
/// distances of the nodes. |
745 | 746 |
/// |
746 | 747 |
/// Returns a const reference to the node map that stores the distances |
747 | 748 |
/// of the nodes calculated by the algorithm. |
748 | 749 |
/// |
749 | 750 |
/// \pre Either \ref run() or \ref init() must be called before |
750 | 751 |
/// using this function. |
751 | 752 |
const DistMap &distMap() const { return *_dist;} |
752 | 753 |
|
753 | 754 |
/// \brief Returns a const reference to the node map that stores the |
754 | 755 |
/// predecessor arcs. |
755 | 756 |
/// |
756 | 757 |
/// Returns a const reference to the node map that stores the predecessor |
757 | 758 |
/// arcs, which form the shortest path tree (forest). |
758 | 759 |
/// |
759 | 760 |
/// \pre Either \ref run() or \ref init() must be called before |
760 | 761 |
/// using this function. |
761 | 762 |
const PredMap &predMap() const { return *_pred; } |
762 | 763 |
|
763 | 764 |
/// \brief Checks if a node is reached from the root(s). |
764 | 765 |
/// |
765 | 766 |
/// Returns \c true if \c v is reached from the root(s). |
766 | 767 |
/// |
767 | 768 |
/// \pre Either \ref run() or \ref init() must be called before |
768 | 769 |
/// using this function. |
769 | 770 |
bool reached(Node v) const { |
770 | 771 |
return (*_dist)[v] != OperationTraits::infinity(); |
771 | 772 |
} |
772 | 773 |
|
773 | 774 |
/// \brief Gives back a negative cycle. |
774 | 775 |
/// |
775 | 776 |
/// This function gives back a directed cycle with negative total |
776 | 777 |
/// length if the algorithm has already found one. |
777 | 778 |
/// Otherwise it gives back an empty path. |
778 |
lemon::Path<Digraph> negativeCycle() { |
|
779 |
lemon::Path<Digraph> negativeCycle() const { |
|
779 | 780 |
typename Digraph::template NodeMap<int> state(*_gr, -1); |
780 | 781 |
lemon::Path<Digraph> cycle; |
781 | 782 |
for (int i = 0; i < int(_process.size()); ++i) { |
782 | 783 |
if (state[_process[i]] != -1) continue; |
783 | 784 |
for (Node v = _process[i]; (*_pred)[v] != INVALID; |
784 | 785 |
v = _gr->source((*_pred)[v])) { |
785 | 786 |
if (state[v] == i) { |
786 | 787 |
cycle.addFront((*_pred)[v]); |
787 | 788 |
for (Node u = _gr->source((*_pred)[v]); u != v; |
788 | 789 |
u = _gr->source((*_pred)[u])) { |
789 | 790 |
cycle.addFront((*_pred)[u]); |
790 | 791 |
} |
791 | 792 |
return cycle; |
792 | 793 |
} |
793 | 794 |
else if (state[v] >= 0) { |
794 | 795 |
break; |
795 | 796 |
} |
796 | 797 |
state[v] = i; |
797 | 798 |
} |
798 | 799 |
} |
799 | 800 |
return cycle; |
800 | 801 |
} |
801 | 802 |
|
802 | 803 |
///@} |
803 | 804 |
}; |
804 | 805 |
|
805 | 806 |
/// \brief Default traits class of bellmanFord() function. |
806 | 807 |
/// |
807 | 808 |
/// Default traits class of bellmanFord() function. |
808 | 809 |
/// \tparam GR The type of the digraph. |
809 | 810 |
/// \tparam LEN The type of the length map. |
810 | 811 |
template <typename GR, typename LEN> |
... | ... |
@@ -18,114 +18,115 @@ |
18 | 18 |
|
19 | 19 |
#ifndef LEMON_BFS_H |
20 | 20 |
#define LEMON_BFS_H |
21 | 21 |
|
22 | 22 |
///\ingroup search |
23 | 23 |
///\file |
24 | 24 |
///\brief BFS algorithm. |
25 | 25 |
|
26 | 26 |
#include <lemon/list_graph.h> |
27 | 27 |
#include <lemon/bits/path_dump.h> |
28 | 28 |
#include <lemon/core.h> |
29 | 29 |
#include <lemon/error.h> |
30 | 30 |
#include <lemon/maps.h> |
31 | 31 |
#include <lemon/path.h> |
32 | 32 |
|
33 | 33 |
namespace lemon { |
34 | 34 |
|
35 | 35 |
///Default traits class of Bfs class. |
36 | 36 |
|
37 | 37 |
///Default traits class of Bfs class. |
38 | 38 |
///\tparam GR Digraph type. |
39 | 39 |
template<class GR> |
40 | 40 |
struct BfsDefaultTraits |
41 | 41 |
{ |
42 | 42 |
///The type of the digraph the algorithm runs on. |
43 | 43 |
typedef GR Digraph; |
44 | 44 |
|
45 | 45 |
///\brief The type of the map that stores the predecessor |
46 | 46 |
///arcs of the shortest paths. |
47 | 47 |
/// |
48 | 48 |
///The type of the map that stores the predecessor |
49 | 49 |
///arcs of the shortest paths. |
50 |
///It must |
|
50 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
|
51 | 51 |
typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap; |
52 | 52 |
///Instantiates a \c PredMap. |
53 | 53 |
|
54 | 54 |
///This function instantiates a \ref PredMap. |
55 | 55 |
///\param g is the digraph, to which we would like to define the |
56 | 56 |
///\ref PredMap. |
57 | 57 |
static PredMap *createPredMap(const Digraph &g) |
58 | 58 |
{ |
59 | 59 |
return new PredMap(g); |
60 | 60 |
} |
61 | 61 |
|
62 | 62 |
///The type of the map that indicates which nodes are processed. |
63 | 63 |
|
64 | 64 |
///The type of the map that indicates which nodes are processed. |
65 |
///It must |
|
65 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
|
66 |
///By default, it is a NullMap. |
|
66 | 67 |
typedef NullMap<typename Digraph::Node,bool> ProcessedMap; |
67 | 68 |
///Instantiates a \c ProcessedMap. |
68 | 69 |
|
69 | 70 |
///This function instantiates a \ref ProcessedMap. |
70 | 71 |
///\param g is the digraph, to which |
71 | 72 |
///we would like to define the \ref ProcessedMap |
72 | 73 |
#ifdef DOXYGEN |
73 | 74 |
static ProcessedMap *createProcessedMap(const Digraph &g) |
74 | 75 |
#else |
75 | 76 |
static ProcessedMap *createProcessedMap(const Digraph &) |
76 | 77 |
#endif |
77 | 78 |
{ |
78 | 79 |
return new ProcessedMap(); |
79 | 80 |
} |
80 | 81 |
|
81 | 82 |
///The type of the map that indicates which nodes are reached. |
82 | 83 |
|
83 | 84 |
///The type of the map that indicates which nodes are reached. |
84 |
///It must |
|
85 |
///It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" concept. |
|
85 | 86 |
typedef typename Digraph::template NodeMap<bool> ReachedMap; |
86 | 87 |
///Instantiates a \c ReachedMap. |
87 | 88 |
|
88 | 89 |
///This function instantiates a \ref ReachedMap. |
89 | 90 |
///\param g is the digraph, to which |
90 | 91 |
///we would like to define the \ref ReachedMap. |
91 | 92 |
static ReachedMap *createReachedMap(const Digraph &g) |
92 | 93 |
{ |
93 | 94 |
return new ReachedMap(g); |
94 | 95 |
} |
95 | 96 |
|
96 | 97 |
///The type of the map that stores the distances of the nodes. |
97 | 98 |
|
98 | 99 |
///The type of the map that stores the distances of the nodes. |
99 |
///It must |
|
100 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
|
100 | 101 |
typedef typename Digraph::template NodeMap<int> DistMap; |
101 | 102 |
///Instantiates a \c DistMap. |
102 | 103 |
|
103 | 104 |
///This function instantiates a \ref DistMap. |
104 | 105 |
///\param g is the digraph, to which we would like to define the |
105 | 106 |
///\ref DistMap. |
106 | 107 |
static DistMap *createDistMap(const Digraph &g) |
107 | 108 |
{ |
108 | 109 |
return new DistMap(g); |
109 | 110 |
} |
110 | 111 |
}; |
111 | 112 |
|
112 | 113 |
///%BFS algorithm class. |
113 | 114 |
|
114 | 115 |
///\ingroup search |
115 | 116 |
///This class provides an efficient implementation of the %BFS algorithm. |
116 | 117 |
/// |
117 | 118 |
///There is also a \ref bfs() "function-type interface" for the BFS |
118 | 119 |
///algorithm, which is convenient in the simplier cases and it can be |
119 | 120 |
///used easier. |
120 | 121 |
/// |
121 | 122 |
///\tparam GR The type of the digraph the algorithm runs on. |
122 | 123 |
///The default type is \ref ListDigraph. |
123 | 124 |
#ifdef DOXYGEN |
124 | 125 |
template <typename GR, |
125 | 126 |
typename TR> |
126 | 127 |
#else |
127 | 128 |
template <typename GR=ListDigraph, |
128 | 129 |
typename TR=BfsDefaultTraits<GR> > |
129 | 130 |
#endif |
130 | 131 |
class Bfs { |
131 | 132 |
public: |
... | ... |
@@ -196,125 +197,125 @@ |
196 | 197 |
if(!_processed) { |
197 | 198 |
local_processed = true; |
198 | 199 |
_processed = Traits::createProcessedMap(*G); |
199 | 200 |
} |
200 | 201 |
} |
201 | 202 |
|
202 | 203 |
protected: |
203 | 204 |
|
204 | 205 |
Bfs() {} |
205 | 206 |
|
206 | 207 |
public: |
207 | 208 |
|
208 | 209 |
typedef Bfs Create; |
209 | 210 |
|
210 | 211 |
///\name Named Template Parameters |
211 | 212 |
|
212 | 213 |
///@{ |
213 | 214 |
|
214 | 215 |
template <class T> |
215 | 216 |
struct SetPredMapTraits : public Traits { |
216 | 217 |
typedef T PredMap; |
217 | 218 |
static PredMap *createPredMap(const Digraph &) |
218 | 219 |
{ |
219 | 220 |
LEMON_ASSERT(false, "PredMap is not initialized"); |
220 | 221 |
return 0; // ignore warnings |
221 | 222 |
} |
222 | 223 |
}; |
223 | 224 |
///\brief \ref named-templ-param "Named parameter" for setting |
224 | 225 |
///\c PredMap type. |
225 | 226 |
/// |
226 | 227 |
///\ref named-templ-param "Named parameter" for setting |
227 | 228 |
///\c PredMap type. |
228 |
///It must |
|
229 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
|
229 | 230 |
template <class T> |
230 | 231 |
struct SetPredMap : public Bfs< Digraph, SetPredMapTraits<T> > { |
231 | 232 |
typedef Bfs< Digraph, SetPredMapTraits<T> > Create; |
232 | 233 |
}; |
233 | 234 |
|
234 | 235 |
template <class T> |
235 | 236 |
struct SetDistMapTraits : public Traits { |
236 | 237 |
typedef T DistMap; |
237 | 238 |
static DistMap *createDistMap(const Digraph &) |
238 | 239 |
{ |
239 | 240 |
LEMON_ASSERT(false, "DistMap is not initialized"); |
240 | 241 |
return 0; // ignore warnings |
241 | 242 |
} |
242 | 243 |
}; |
243 | 244 |
///\brief \ref named-templ-param "Named parameter" for setting |
244 | 245 |
///\c DistMap type. |
245 | 246 |
/// |
246 | 247 |
///\ref named-templ-param "Named parameter" for setting |
247 | 248 |
///\c DistMap type. |
248 |
///It must |
|
249 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
|
249 | 250 |
template <class T> |
250 | 251 |
struct SetDistMap : public Bfs< Digraph, SetDistMapTraits<T> > { |
251 | 252 |
typedef Bfs< Digraph, SetDistMapTraits<T> > Create; |
252 | 253 |
}; |
253 | 254 |
|
254 | 255 |
template <class T> |
255 | 256 |
struct SetReachedMapTraits : public Traits { |
256 | 257 |
typedef T ReachedMap; |
257 | 258 |
static ReachedMap *createReachedMap(const Digraph &) |
258 | 259 |
{ |
259 | 260 |
LEMON_ASSERT(false, "ReachedMap is not initialized"); |
260 | 261 |
return 0; // ignore warnings |
261 | 262 |
} |
262 | 263 |
}; |
263 | 264 |
///\brief \ref named-templ-param "Named parameter" for setting |
264 | 265 |
///\c ReachedMap type. |
265 | 266 |
/// |
266 | 267 |
///\ref named-templ-param "Named parameter" for setting |
267 | 268 |
///\c ReachedMap type. |
268 |
///It must |
|
269 |
///It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" concept. |
|
269 | 270 |
template <class T> |
270 | 271 |
struct SetReachedMap : public Bfs< Digraph, SetReachedMapTraits<T> > { |
271 | 272 |
typedef Bfs< Digraph, SetReachedMapTraits<T> > Create; |
272 | 273 |
}; |
273 | 274 |
|
274 | 275 |
template <class T> |
275 | 276 |
struct SetProcessedMapTraits : public Traits { |
276 | 277 |
typedef T ProcessedMap; |
277 | 278 |
static ProcessedMap *createProcessedMap(const Digraph &) |
278 | 279 |
{ |
279 | 280 |
LEMON_ASSERT(false, "ProcessedMap is not initialized"); |
280 | 281 |
return 0; // ignore warnings |
281 | 282 |
} |
282 | 283 |
}; |
283 | 284 |
///\brief \ref named-templ-param "Named parameter" for setting |
284 | 285 |
///\c ProcessedMap type. |
285 | 286 |
/// |
286 | 287 |
///\ref named-templ-param "Named parameter" for setting |
287 | 288 |
///\c ProcessedMap type. |
288 |
///It must |
|
289 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
|
289 | 290 |
template <class T> |
290 | 291 |
struct SetProcessedMap : public Bfs< Digraph, SetProcessedMapTraits<T> > { |
291 | 292 |
typedef Bfs< Digraph, SetProcessedMapTraits<T> > Create; |
292 | 293 |
}; |
293 | 294 |
|
294 | 295 |
struct SetStandardProcessedMapTraits : public Traits { |
295 | 296 |
typedef typename Digraph::template NodeMap<bool> ProcessedMap; |
296 | 297 |
static ProcessedMap *createProcessedMap(const Digraph &g) |
297 | 298 |
{ |
298 | 299 |
return new ProcessedMap(g); |
299 | 300 |
return 0; // ignore warnings |
300 | 301 |
} |
301 | 302 |
}; |
302 | 303 |
///\brief \ref named-templ-param "Named parameter" for setting |
303 | 304 |
///\c ProcessedMap type to be <tt>Digraph::NodeMap<bool></tt>. |
304 | 305 |
/// |
305 | 306 |
///\ref named-templ-param "Named parameter" for setting |
306 | 307 |
///\c ProcessedMap type to be <tt>Digraph::NodeMap<bool></tt>. |
307 | 308 |
///If you don't set it explicitly, it will be automatically allocated. |
308 | 309 |
struct SetStandardProcessedMap : |
309 | 310 |
public Bfs< Digraph, SetStandardProcessedMapTraits > { |
310 | 311 |
typedef Bfs< Digraph, SetStandardProcessedMapTraits > Create; |
311 | 312 |
}; |
312 | 313 |
|
313 | 314 |
///@} |
314 | 315 |
|
315 | 316 |
public: |
316 | 317 |
|
317 | 318 |
///Constructor. |
318 | 319 |
|
319 | 320 |
///Constructor. |
320 | 321 |
///\param g The digraph the algorithm runs on. |
... | ... |
@@ -384,66 +385,66 @@ |
384 | 385 |
if(local_processed) { |
385 | 386 |
delete _processed; |
386 | 387 |
local_processed=false; |
387 | 388 |
} |
388 | 389 |
_processed = &m; |
389 | 390 |
return *this; |
390 | 391 |
} |
391 | 392 |
|
392 | 393 |
///Sets the map that stores the distances of the nodes. |
393 | 394 |
|
394 | 395 |
///Sets the map that stores the distances of the nodes calculated by |
395 | 396 |
///the algorithm. |
396 | 397 |
///If you don't use this function before calling \ref run(Node) "run()" |
397 | 398 |
///or \ref init(), an instance will be allocated automatically. |
398 | 399 |
///The destructor deallocates this automatically allocated map, |
399 | 400 |
///of course. |
400 | 401 |
///\return <tt> (*this) </tt> |
401 | 402 |
Bfs &distMap(DistMap &m) |
402 | 403 |
{ |
403 | 404 |
if(local_dist) { |
404 | 405 |
delete _dist; |
405 | 406 |
local_dist=false; |
406 | 407 |
} |
407 | 408 |
_dist = &m; |
408 | 409 |
return *this; |
409 | 410 |
} |
410 | 411 |
|
411 | 412 |
public: |
412 | 413 |
|
413 | 414 |
///\name Execution Control |
414 | 415 |
///The simplest way to execute the BFS algorithm is to use one of the |
415 | 416 |
///member functions called \ref run(Node) "run()".\n |
416 |
///If you need more control on the execution, first you have to call |
|
417 |
///\ref init(), then you can add several source nodes with |
|
417 |
///If you need better control on the execution, you have to call |
|
418 |
///\ref init() first, then you can add several source nodes with |
|
418 | 419 |
///\ref addSource(). Finally the actual path computation can be |
419 | 420 |
///performed with one of the \ref start() functions. |
420 | 421 |
|
421 | 422 |
///@{ |
422 | 423 |
|
423 | 424 |
///\brief Initializes the internal data structures. |
424 | 425 |
/// |
425 | 426 |
///Initializes the internal data structures. |
426 | 427 |
void init() |
427 | 428 |
{ |
428 | 429 |
create_maps(); |
429 | 430 |
_queue.resize(countNodes(*G)); |
430 | 431 |
_queue_head=_queue_tail=0; |
431 | 432 |
_curr_dist=1; |
432 | 433 |
for ( NodeIt u(*G) ; u!=INVALID ; ++u ) { |
433 | 434 |
_pred->set(u,INVALID); |
434 | 435 |
_reached->set(u,false); |
435 | 436 |
_processed->set(u,false); |
436 | 437 |
} |
437 | 438 |
} |
438 | 439 |
|
439 | 440 |
///Adds a new source node. |
440 | 441 |
|
441 | 442 |
///Adds a new source node to the set of nodes to be processed. |
442 | 443 |
/// |
443 | 444 |
void addSource(Node s) |
444 | 445 |
{ |
445 | 446 |
if(!(*_reached)[s]) |
446 | 447 |
{ |
447 | 448 |
_reached->set(s,true); |
448 | 449 |
_pred->set(s,INVALID); |
449 | 450 |
_dist->set(s,0); |
... | ... |
@@ -671,349 +672,336 @@ |
671 | 672 |
/// b.start(); |
672 | 673 |
///\endcode |
673 | 674 |
void run(Node s) { |
674 | 675 |
init(); |
675 | 676 |
addSource(s); |
676 | 677 |
start(); |
677 | 678 |
} |
678 | 679 |
|
679 | 680 |
///Finds the shortest path between \c s and \c t. |
680 | 681 |
|
681 | 682 |
///This method runs the %BFS algorithm from node \c s |
682 | 683 |
///in order to compute the shortest path to node \c t |
683 | 684 |
///(it stops searching when \c t is processed). |
684 | 685 |
/// |
685 | 686 |
///\return \c true if \c t is reachable form \c s. |
686 | 687 |
/// |
687 | 688 |
///\note Apart from the return value, <tt>b.run(s,t)</tt> is just a |
688 | 689 |
///shortcut of the following code. |
689 | 690 |
///\code |
690 | 691 |
/// b.init(); |
691 | 692 |
/// b.addSource(s); |
692 | 693 |
/// b.start(t); |
693 | 694 |
///\endcode |
694 | 695 |
bool run(Node s,Node t) { |
695 | 696 |
init(); |
696 | 697 |
addSource(s); |
697 | 698 |
start(t); |
698 | 699 |
return reached(t); |
699 | 700 |
} |
700 | 701 |
|
701 | 702 |
///Runs the algorithm to visit all nodes in the digraph. |
702 | 703 |
|
703 |
///This method runs the %BFS algorithm in order to |
|
704 |
///compute the shortest path to each node. |
|
705 |
/// |
|
706 |
///The algorithm computes |
|
707 |
///- the shortest path tree (forest), |
|
708 |
///- the distance of each node from the root(s). |
|
704 |
///This method runs the %BFS algorithm in order to visit all nodes |
|
705 |
///in the digraph. |
|
709 | 706 |
/// |
710 | 707 |
///\note <tt>b.run(s)</tt> is just a shortcut of the following code. |
711 | 708 |
///\code |
712 | 709 |
/// b.init(); |
713 | 710 |
/// for (NodeIt n(gr); n != INVALID; ++n) { |
714 | 711 |
/// if (!b.reached(n)) { |
715 | 712 |
/// b.addSource(n); |
716 | 713 |
/// b.start(); |
717 | 714 |
/// } |
718 | 715 |
/// } |
719 | 716 |
///\endcode |
720 | 717 |
void run() { |
721 | 718 |
init(); |
722 | 719 |
for (NodeIt n(*G); n != INVALID; ++n) { |
723 | 720 |
if (!reached(n)) { |
724 | 721 |
addSource(n); |
725 | 722 |
start(); |
726 | 723 |
} |
727 | 724 |
} |
728 | 725 |
} |
729 | 726 |
|
730 | 727 |
///@} |
731 | 728 |
|
732 | 729 |
///\name Query Functions |
733 | 730 |
///The results of the BFS algorithm can be obtained using these |
734 | 731 |
///functions.\n |
735 | 732 |
///Either \ref run(Node) "run()" or \ref start() should be called |
736 | 733 |
///before using them. |
737 | 734 |
|
738 | 735 |
///@{ |
739 | 736 |
|
740 |
///The shortest path to |
|
737 |
///The shortest path to the given node. |
|
741 | 738 |
|
742 |
///Returns the shortest path to |
|
739 |
///Returns the shortest path to the given node from the root(s). |
|
743 | 740 |
/// |
744 | 741 |
///\warning \c t should be reached from the root(s). |
745 | 742 |
/// |
746 | 743 |
///\pre Either \ref run(Node) "run()" or \ref init() |
747 | 744 |
///must be called before using this function. |
748 | 745 |
Path path(Node t) const { return Path(*G, *_pred, t); } |
749 | 746 |
|
750 |
///The distance of |
|
747 |
///The distance of the given node from the root(s). |
|
751 | 748 |
|
752 |
///Returns the distance of |
|
749 |
///Returns the distance of the given node from the root(s). |
|
753 | 750 |
/// |
754 | 751 |
///\warning If node \c v is not reached from the root(s), then |
755 | 752 |
///the return value of this function is undefined. |
756 | 753 |
/// |
757 | 754 |
///\pre Either \ref run(Node) "run()" or \ref init() |
758 | 755 |
///must be called before using this function. |
759 | 756 |
int dist(Node v) const { return (*_dist)[v]; } |
760 | 757 |
|
761 |
///Returns the 'previous arc' of the shortest path tree for a node. |
|
762 |
|
|
758 |
///\brief Returns the 'previous arc' of the shortest path tree for |
|
759 |
///the given node. |
|
760 |
/// |
|
763 | 761 |
///This function returns the 'previous arc' of the shortest path |
764 | 762 |
///tree for the node \c v, i.e. it returns the last arc of a |
765 | 763 |
///shortest path from a root to \c v. It is \c INVALID if \c v |
766 | 764 |
///is not reached from the root(s) or if \c v is a root. |
767 | 765 |
/// |
768 | 766 |
///The shortest path tree used here is equal to the shortest path |
769 |
///tree used in \ref predNode(). |
|
767 |
///tree used in \ref predNode() and \ref predMap(). |
|
770 | 768 |
/// |
771 | 769 |
///\pre Either \ref run(Node) "run()" or \ref init() |
772 | 770 |
///must be called before using this function. |
773 | 771 |
Arc predArc(Node v) const { return (*_pred)[v];} |
774 | 772 |
|
775 |
///Returns the 'previous node' of the shortest path tree for a node. |
|
776 |
|
|
773 |
///\brief Returns the 'previous node' of the shortest path tree for |
|
774 |
///the given node. |
|
775 |
/// |
|
777 | 776 |
///This function returns the 'previous node' of the shortest path |
778 | 777 |
///tree for the node \c v, i.e. it returns the last but one node |
779 |
/// |
|
778 |
///of a shortest path from a root to \c v. It is \c INVALID |
|
780 | 779 |
///if \c v is not reached from the root(s) or if \c v is a root. |
781 | 780 |
/// |
782 | 781 |
///The shortest path tree used here is equal to the shortest path |
783 |
///tree used in \ref predArc(). |
|
782 |
///tree used in \ref predArc() and \ref predMap(). |
|
784 | 783 |
/// |
785 | 784 |
///\pre Either \ref run(Node) "run()" or \ref init() |
786 | 785 |
///must be called before using this function. |
787 | 786 |
Node predNode(Node v) const { return (*_pred)[v]==INVALID ? INVALID: |
788 | 787 |
G->source((*_pred)[v]); } |
789 | 788 |
|
790 | 789 |
///\brief Returns a const reference to the node map that stores the |
791 | 790 |
/// distances of the nodes. |
792 | 791 |
/// |
793 | 792 |
///Returns a const reference to the node map that stores the distances |
794 | 793 |
///of the nodes calculated by the algorithm. |
795 | 794 |
/// |
796 | 795 |
///\pre Either \ref run(Node) "run()" or \ref init() |
797 | 796 |
///must be called before using this function. |
798 | 797 |
const DistMap &distMap() const { return *_dist;} |
799 | 798 |
|
800 | 799 |
///\brief Returns a const reference to the node map that stores the |
801 | 800 |
///predecessor arcs. |
802 | 801 |
/// |
803 | 802 |
///Returns a const reference to the node map that stores the predecessor |
804 |
///arcs, which form the shortest path tree. |
|
803 |
///arcs, which form the shortest path tree (forest). |
|
805 | 804 |
/// |
806 | 805 |
///\pre Either \ref run(Node) "run()" or \ref init() |
807 | 806 |
///must be called before using this function. |
808 | 807 |
const PredMap &predMap() const { return *_pred;} |
809 | 808 |
|
810 |
///Checks if |
|
809 |
///Checks if the given node is reached from the root(s). |
|
811 | 810 |
|
812 | 811 |
///Returns \c true if \c v is reached from the root(s). |
813 | 812 |
/// |
814 | 813 |
///\pre Either \ref run(Node) "run()" or \ref init() |
815 | 814 |
///must be called before using this function. |
816 | 815 |
bool reached(Node v) const { return (*_reached)[v]; } |
817 | 816 |
|
818 | 817 |
///@} |
819 | 818 |
}; |
820 | 819 |
|
821 | 820 |
///Default traits class of bfs() function. |
822 | 821 |
|
823 | 822 |
///Default traits class of bfs() function. |
824 | 823 |
///\tparam GR Digraph type. |
825 | 824 |
template<class GR> |
826 | 825 |
struct BfsWizardDefaultTraits |
827 | 826 |
{ |
828 | 827 |
///The type of the digraph the algorithm runs on. |
829 | 828 |
typedef GR Digraph; |
830 | 829 |
|
831 | 830 |
///\brief The type of the map that stores the predecessor |
832 | 831 |
///arcs of the shortest paths. |
833 | 832 |
/// |
834 | 833 |
///The type of the map that stores the predecessor |
835 | 834 |
///arcs of the shortest paths. |
836 |
///It must |
|
835 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
|
837 | 836 |
typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap; |
838 | 837 |
///Instantiates a PredMap. |
839 | 838 |
|
840 | 839 |
///This function instantiates a PredMap. |
841 | 840 |
///\param g is the digraph, to which we would like to define the |
842 | 841 |
///PredMap. |
843 | 842 |
static PredMap *createPredMap(const Digraph &g) |
844 | 843 |
{ |
845 | 844 |
return new PredMap(g); |
846 | 845 |
} |
847 | 846 |
|
848 | 847 |
///The type of the map that indicates which nodes are processed. |
849 | 848 |
|
850 | 849 |
///The type of the map that indicates which nodes are processed. |
851 |
///It must meet the \ref concepts::WriteMap "WriteMap" concept. |
|
852 |
///By default it is a NullMap. |
|
850 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
|
851 |
///By default, it is a NullMap. |
|
853 | 852 |
typedef NullMap<typename Digraph::Node,bool> ProcessedMap; |
854 | 853 |
///Instantiates a ProcessedMap. |
855 | 854 |
|
856 | 855 |
///This function instantiates a ProcessedMap. |
857 | 856 |
///\param g is the digraph, to which |
858 | 857 |
///we would like to define the ProcessedMap. |
859 | 858 |
#ifdef DOXYGEN |
860 | 859 |
static ProcessedMap *createProcessedMap(const Digraph &g) |
861 | 860 |
#else |
862 | 861 |
static ProcessedMap *createProcessedMap(const Digraph &) |
863 | 862 |
#endif |
864 | 863 |
{ |
865 | 864 |
return new ProcessedMap(); |
866 | 865 |
} |
867 | 866 |
|
868 | 867 |
///The type of the map that indicates which nodes are reached. |
869 | 868 |
|
870 | 869 |
///The type of the map that indicates which nodes are reached. |
871 |
///It must |
|
870 |
///It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" concept. |
|
872 | 871 |
typedef typename Digraph::template NodeMap<bool> ReachedMap; |
873 | 872 |
///Instantiates a ReachedMap. |
874 | 873 |
|
875 | 874 |
///This function instantiates a ReachedMap. |
876 | 875 |
///\param g is the digraph, to which |
877 | 876 |
///we would like to define the ReachedMap. |
878 | 877 |
static ReachedMap *createReachedMap(const Digraph &g) |
879 | 878 |
{ |
880 | 879 |
return new ReachedMap(g); |
881 | 880 |
} |
882 | 881 |
|
883 | 882 |
///The type of the map that stores the distances of the nodes. |
884 | 883 |
|
885 | 884 |
///The type of the map that stores the distances of the nodes. |
886 |
///It must |
|
885 |
///It must conform to the \ref concepts::WriteMap "WriteMap" concept. |
|
887 | 886 |
typedef typename Digraph::template NodeMap<int> DistMap; |
888 | 887 |
///Instantiates a DistMap. |
889 | 888 |
|
890 | 889 |
///This function instantiates a DistMap. |
891 | 890 |
///\param g is the digraph, to which we would like to define |
892 | 891 |
///the DistMap |
893 | 892 |
static DistMap *createDistMap(const Digraph &g) |
894 | 893 |
{ |
895 | 894 |
return new DistMap(g); |
896 | 895 |
} |
897 | 896 |
|
898 | 897 |
///The type of the shortest paths. |
899 | 898 |
|
900 | 899 |
///The type of the shortest paths. |
901 |
///It must |
|
900 |
///It must conform to the \ref concepts::Path "Path" concept. |
|
902 | 901 |
typedef lemon::Path<Digraph> Path; |
903 | 902 |
}; |
904 | 903 |
|
905 | 904 |
/// Default traits class used by BfsWizard |
906 | 905 |
|
907 |
/// To make it easier to use Bfs algorithm |
|
908 |
/// we have created a wizard class. |
|
909 |
/// This \ref BfsWizard class needs default traits, |
|
910 |
/// as well as the \ref Bfs class. |
|
911 |
/// The \ref BfsWizardBase is a class to be the default traits of the |
|
912 |
/// \ref BfsWizard class. |
|
906 |
/// Default traits class used by BfsWizard. |
|
907 |
/// \tparam GR The type of the digraph. |
|
913 | 908 |
template<class GR> |
914 | 909 |
class BfsWizardBase : public BfsWizardDefaultTraits<GR> |
915 | 910 |
{ |
916 | 911 |
|
917 | 912 |
typedef BfsWizardDefaultTraits<GR> Base; |
918 | 913 |
protected: |
919 | 914 |
//The type of the nodes in the digraph. |
920 | 915 |
typedef typename Base::Digraph::Node Node; |
921 | 916 |
|
922 | 917 |
//Pointer to the digraph the algorithm runs on. |
923 | 918 |
void *_g; |
924 | 919 |
//Pointer to the map of reached nodes. |
925 | 920 |
void *_reached; |
926 | 921 |
//Pointer to the map of processed nodes. |
927 | 922 |
void *_processed; |
928 | 923 |
//Pointer to the map of predecessors arcs. |
929 | 924 |
void *_pred; |
930 | 925 |
//Pointer to the map of distances. |
931 | 926 |
void *_dist; |
932 | 927 |
//Pointer to the shortest path to the target node. |
933 | 928 |
void *_path; |
934 | 929 |
//Pointer to the distance of the target node. |
935 | 930 |
int *_di; |
936 | 931 |
|
937 | 932 |
public: |
938 | 933 |
/// Constructor. |
939 | 934 |
|
940 |
/// This constructor does not require parameters, |
|
935 |
/// This constructor does not require parameters, it initiates |
|
941 | 936 |
/// all of the attributes to \c 0. |
942 | 937 |
BfsWizardBase() : _g(0), _reached(0), _processed(0), _pred(0), |
943 | 938 |
_dist(0), _path(0), _di(0) {} |
944 | 939 |
|
945 | 940 |
/// Constructor. |
946 | 941 |
|
947 | 942 |
/// This constructor requires one parameter, |
948 | 943 |
/// others are initiated to \c 0. |
949 | 944 |
/// \param g The digraph the algorithm runs on. |
950 | 945 |
BfsWizardBase(const GR &g) : |
951 | 946 |
_g(reinterpret_cast<void*>(const_cast<GR*>(&g))), |
952 | 947 |
_reached(0), _processed(0), _pred(0), _dist(0), _path(0), _di(0) {} |
953 | 948 |
|
954 | 949 |
}; |
955 | 950 |
|
956 | 951 |
/// Auxiliary class for the function-type interface of BFS algorithm. |
957 | 952 |
|
958 | 953 |
/// This auxiliary class is created to implement the |
959 | 954 |
/// \ref bfs() "function-type interface" of \ref Bfs algorithm. |
960 | 955 |
/// It does not have own \ref run(Node) "run()" method, it uses the |
961 | 956 |
/// functions and features of the plain \ref Bfs. |
962 | 957 |
/// |
963 | 958 |
/// This class should only be used through the \ref bfs() function, |
964 | 959 |
/// which makes it easier to use the algorithm. |
965 | 960 |
template<class TR> |
966 | 961 |
class BfsWizard : public TR |
967 | 962 |
{ |
968 | 963 |
typedef TR Base; |
969 | 964 |
|
970 |
///The type of the digraph the algorithm runs on. |
|
971 | 965 |
typedef typename TR::Digraph Digraph; |
972 | 966 |
|
973 | 967 |
typedef typename Digraph::Node Node; |
974 | 968 |
typedef typename Digraph::NodeIt NodeIt; |
975 | 969 |
typedef typename Digraph::Arc Arc; |
976 | 970 |
typedef typename Digraph::OutArcIt OutArcIt; |
977 | 971 |
|
978 |
///\brief The type of the map that stores the predecessor |
|
979 |
///arcs of the shortest paths. |
|
980 | 972 |
typedef typename TR::PredMap PredMap; |
981 |
///\brief The type of the map that stores the distances of the nodes. |
|
982 | 973 |
typedef typename TR::DistMap DistMap; |
983 |
///\brief The type of the map that indicates which nodes are reached. |
|
984 | 974 |
typedef typename TR::ReachedMap ReachedMap; |
985 |
///\brief The type of the map that indicates which nodes are processed. |
|
986 | 975 |
typedef typename TR::ProcessedMap ProcessedMap; |
987 |
///The type of the shortest paths |
|
988 | 976 |
typedef typename TR::Path Path; |
989 | 977 |
|
990 | 978 |
public: |
991 | 979 |
|
992 | 980 |
/// Constructor. |
993 | 981 |
BfsWizard() : TR() {} |
994 | 982 |
|
995 | 983 |
/// Constructor that requires parameters. |
996 | 984 |
|
997 | 985 |
/// Constructor that requires parameters. |
998 | 986 |
/// These parameters will be the default values for the traits class. |
999 | 987 |
/// \param g The digraph the algorithm runs on. |
1000 | 988 |
BfsWizard(const Digraph &g) : |
1001 | 989 |
TR(g) {} |
1002 | 990 |
|
1003 | 991 |
///Copy constructor |
1004 | 992 |
BfsWizard(const TR &b) : TR(b) {} |
1005 | 993 |
|
1006 | 994 |
~BfsWizard() {} |
1007 | 995 |
|
1008 | 996 |
///Runs BFS algorithm from the given source node. |
1009 | 997 |
|
1010 | 998 |
///This method runs BFS algorithm from node \c s |
1011 | 999 |
///in order to compute the shortest path to each node. |
1012 | 1000 |
void run(Node s) |
1013 | 1001 |
{ |
1014 | 1002 |
Bfs<Digraph,TR> alg(*reinterpret_cast<const Digraph*>(Base::_g)); |
1015 | 1003 |
if (Base::_pred) |
1016 | 1004 |
alg.predMap(*reinterpret_cast<PredMap*>(Base::_pred)); |
1017 | 1005 |
if (Base::_dist) |
1018 | 1006 |
alg.distMap(*reinterpret_cast<DistMap*>(Base::_dist)); |
1019 | 1007 |
if (Base::_reached) |
... | ... |
@@ -1025,136 +1013,141 @@ |
1025 | 1013 |
else |
1026 | 1014 |
alg.run(); |
1027 | 1015 |
} |
1028 | 1016 |
|
1029 | 1017 |
///Finds the shortest path between \c s and \c t. |
1030 | 1018 |
|
1031 | 1019 |
///This method runs BFS algorithm from node \c s |
1032 | 1020 |
///in order to compute the shortest path to node \c t |
1033 | 1021 |
///(it stops searching when \c t is processed). |
1034 | 1022 |
/// |
1035 | 1023 |
///\return \c true if \c t is reachable form \c s. |
1036 | 1024 |
bool run(Node s, Node t) |
1037 | 1025 |
{ |
1038 | 1026 |
Bfs<Digraph,TR> alg(*reinterpret_cast<const Digraph*>(Base::_g)); |
1039 | 1027 |
if (Base::_pred) |
1040 | 1028 |
alg.predMap(*reinterpret_cast<PredMap*>(Base::_pred)); |
1041 | 1029 |
if (Base::_dist) |
1042 | 1030 |
alg.distMap(*reinterpret_cast<DistMap*>(Base::_dist)); |
1043 | 1031 |
if (Base::_reached) |
1044 | 1032 |
alg.reachedMap(*reinterpret_cast<ReachedMap*>(Base::_reached)); |
1045 | 1033 |
if (Base::_processed) |
1046 | 1034 |
alg.processedMap(*reinterpret_cast<ProcessedMap*>(Base::_processed)); |
1047 | 1035 |
alg.run(s,t); |
1048 | 1036 |
if (Base::_path) |
1049 | 1037 |
*reinterpret_cast<Path*>(Base::_path) = alg.path(t); |
1050 | 1038 |
if (Base::_di) |
1051 | 1039 |
*Base::_di = alg.dist(t); |
1052 | 1040 |
return alg.reached(t); |
1053 | 1041 |
} |
1054 | 1042 |
|
1055 | 1043 |
///Runs BFS algorithm to visit all nodes in the digraph. |
1056 | 1044 |
|
1057 |
///This method runs BFS algorithm in order to compute |
|
1058 |
///the shortest path to each node. |
|
1045 |
///This method runs BFS algorithm in order to visit all nodes |
|
1046 |
///in the digraph. |
|
1059 | 1047 |
void run() |
1060 | 1048 |
{ |
1061 | 1049 |
run(INVALID); |
1062 | 1050 |
} |
1063 | 1051 |
|
1064 | 1052 |
template<class T> |
1065 | 1053 |
struct SetPredMapBase : public Base { |
1066 | 1054 |
typedef T PredMap; |
1067 | 1055 |
static PredMap *createPredMap(const Digraph &) { return 0; }; |
1068 | 1056 |
SetPredMapBase(const TR &b) : TR(b) {} |
1069 | 1057 |
}; |
1070 |
///\brief \ref named-func-param "Named parameter" |
|
1071 |
///for setting PredMap object. |
|
1058 |
|
|
1059 |
///\brief \ref named-templ-param "Named parameter" for setting |
|
1060 |
///the predecessor map. |
|
1072 | 1061 |
/// |
1073 |
///\ref named-func-param "Named parameter" |
|
1074 |
///for setting PredMap object. |
|
1062 |
///\ref named-templ-param "Named parameter" function for setting |
|
1063 |
///the map that stores the predecessor arcs of the nodes. |
|
1075 | 1064 |
template<class T> |
1076 | 1065 |
BfsWizard<SetPredMapBase<T> > predMap(const T &t) |
1077 | 1066 |
{ |
1078 | 1067 |
Base::_pred=reinterpret_cast<void*>(const_cast<T*>(&t)); |
1079 | 1068 |
return BfsWizard<SetPredMapBase<T> >(*this); |
1080 | 1069 |
} |
1081 | 1070 |
|
1082 | 1071 |
template<class T> |
1083 | 1072 |
struct SetReachedMapBase : public Base { |
1084 | 1073 |
typedef T ReachedMap; |
1085 | 1074 |
static ReachedMap *createReachedMap(const Digraph &) { return 0; }; |
1086 | 1075 |
SetReachedMapBase(const TR &b) : TR(b) {} |
1087 | 1076 |
}; |
1088 |
///\brief \ref named-func-param "Named parameter" |
|
1089 |
///for setting ReachedMap object. |
|
1077 |
|
|
1078 |
///\brief \ref named-templ-param "Named parameter" for setting |
|
1079 |
///the reached map. |
|
1090 | 1080 |
/// |
1091 |
/// \ref named-func-param "Named parameter" |
|
1092 |
///for setting ReachedMap object. |
|
1081 |
///\ref named-templ-param "Named parameter" function for setting |
|
1082 |
///the map that indicates which nodes are reached. |
|
1093 | 1083 |
template<class T> |
1094 | 1084 |
BfsWizard<SetReachedMapBase<T> > reachedMap(const T &t) |
1095 | 1085 |
{ |
1096 | 1086 |
Base::_reached=reinterpret_cast<void*>(const_cast<T*>(&t)); |
1097 | 1087 |
return BfsWizard<SetReachedMapBase<T> >(*this); |
1098 | 1088 |
} |
1099 | 1089 |
|
1100 | 1090 |
template<class T> |
1101 | 1091 |
struct SetDistMapBase : public Base { |
1102 | 1092 |
typedef T DistMap; |
1103 | 1093 |
static DistMap *createDistMap(const Digraph &) { return 0; }; |
1104 | 1094 |
SetDistMapBase(const TR &b) : TR(b) {} |
1105 | 1095 |
}; |
1106 |
///\brief \ref named-func-param "Named parameter" |
|
1107 |
///for setting DistMap object. |
|
1096 |
|
|
1097 |
///\brief \ref named-templ-param "Named parameter" for setting |
|
1098 |
///the distance map. |
|
1108 | 1099 |
/// |
1109 |
/// \ref named-func-param "Named parameter" |
|
1110 |
///for setting DistMap object. |
|
1100 |
///\ref named-templ-param "Named parameter" function for setting |
|
1101 |
///the map that stores the distances of the nodes calculated |
|
1102 |
///by the algorithm. |
|
1111 | 1103 |
template<class T> |
1112 | 1104 |
BfsWizard<SetDistMapBase<T> > distMap(const T &t) |
1113 | 1105 |
{ |
1114 | 1106 |
Base::_dist=reinterpret_cast<void*>(const_cast<T*>(&t)); |
1115 | 1107 |
return BfsWizard<SetDistMapBase<T> >(*this); |
1116 | 1108 |
} |
1117 | 1109 |
|
1118 | 1110 |
template<class T> |
1119 | 1111 |
struct SetProcessedMapBase : public Base { |
1120 | 1112 |
typedef T ProcessedMap; |
1121 | 1113 |
static ProcessedMap *createProcessedMap(const Digraph &) { return 0; }; |
1122 | 1114 |
SetProcessedMapBase(const TR &b) : TR(b) {} |
1123 | 1115 |
}; |
1124 |
///\brief \ref named-func-param "Named parameter" |
|
1125 |
///for setting ProcessedMap object. |
|
1116 |
|
|
1117 |
///\brief \ref named-func-param "Named parameter" for setting |
|
1118 |
///the processed map. |
|
1126 | 1119 |
/// |
1127 |
/// \ref named-func-param "Named parameter" |
|
1128 |
///for setting ProcessedMap object. |
|
1120 |
///\ref named-templ-param "Named parameter" function for setting |
|
1121 |
///the map that indicates which nodes are processed. |
|
1129 | 1122 |
template<class T> |
1130 | 1123 |
BfsWizard<SetProcessedMapBase<T> > processedMap(const T &t) |
1131 | 1124 |
{ |
1132 | 1125 |
Base::_processed=reinterpret_cast<void*>(const_cast<T*>(&t)); |
1133 | 1126 |
return BfsWizard<SetProcessedMapBase<T> >(*this); |
1134 | 1127 |
} |
1135 | 1128 |
|
1136 | 1129 |
template<class T> |
1137 | 1130 |
struct SetPathBase : public Base { |
1138 | 1131 |
typedef T Path; |
1139 | 1132 |
SetPathBase(const TR &b) : TR(b) {} |
1140 | 1133 |
}; |
1141 | 1134 |
///\brief \ref named-func-param "Named parameter" |
1142 | 1135 |
///for getting the shortest path to the target node. |
1143 | 1136 |
/// |
1144 | 1137 |
///\ref named-func-param "Named parameter" |
1145 | 1138 |
///for getting the shortest path to the target node. |
1146 | 1139 |
template<class T> |
1147 | 1140 |
BfsWizard<SetPathBase<T> > path(const T &t) |
1148 | 1141 |
{ |
1149 | 1142 |
Base::_path=reinterpret_cast<void*>(const_cast<T*>(&t)); |
1150 | 1143 |
return BfsWizard<SetPathBase<T> >(*this); |
1151 | 1144 |
} |
1152 | 1145 |
|
1153 | 1146 |
///\brief \ref named-func-param "Named parameter" |
1154 | 1147 |
///for getting the distance of the target node. |
1155 | 1148 |
/// |
1156 | 1149 |
///\ref named-func-param "Named parameter" |
1157 | 1150 |
///for getting the distance of the target node. |
1158 | 1151 |
BfsWizard dist(const int &d) |
1159 | 1152 |
{ |
1160 | 1153 |
Base::_di=const_cast<int*>(&d); |
... | ... |
@@ -1235,65 +1228,65 @@ |
1235 | 1228 |
void discover(const Arc&) {} |
1236 | 1229 |
void examine(const Arc&) {} |
1237 | 1230 |
|
1238 | 1231 |
template <typename _Visitor> |
1239 | 1232 |
struct Constraints { |
1240 | 1233 |
void constraints() { |
1241 | 1234 |
Arc arc; |
1242 | 1235 |
Node node; |
1243 | 1236 |
visitor.start(node); |
1244 | 1237 |
visitor.reach(node); |
1245 | 1238 |
visitor.process(node); |
1246 | 1239 |
visitor.discover(arc); |
1247 | 1240 |
visitor.examine(arc); |
1248 | 1241 |
} |
1249 | 1242 |
_Visitor& visitor; |
1250 | 1243 |
}; |
1251 | 1244 |
}; |
1252 | 1245 |
#endif |
1253 | 1246 |
|
1254 | 1247 |
/// \brief Default traits class of BfsVisit class. |
1255 | 1248 |
/// |
1256 | 1249 |
/// Default traits class of BfsVisit class. |
1257 | 1250 |
/// \tparam GR The type of the digraph the algorithm runs on. |
1258 | 1251 |
template<class GR> |
1259 | 1252 |
struct BfsVisitDefaultTraits { |
1260 | 1253 |
|
1261 | 1254 |
/// \brief The type of the digraph the algorithm runs on. |
1262 | 1255 |
typedef GR Digraph; |
1263 | 1256 |
|
1264 | 1257 |
/// \brief The type of the map that indicates which nodes are reached. |
1265 | 1258 |
/// |
1266 | 1259 |
/// The type of the map that indicates which nodes are reached. |
1267 |
/// It must |
|
1260 |
/// It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" concept. |
|
1268 | 1261 |
typedef typename Digraph::template NodeMap<bool> ReachedMap; |
1269 | 1262 |
|
1270 | 1263 |
/// \brief Instantiates a ReachedMap. |
1271 | 1264 |
/// |
1272 | 1265 |
/// This function instantiates a ReachedMap. |
1273 | 1266 |
/// \param digraph is the digraph, to which |
1274 | 1267 |
/// we would like to define the ReachedMap. |
1275 | 1268 |
static ReachedMap *createReachedMap(const Digraph &digraph) { |
1276 | 1269 |
return new ReachedMap(digraph); |
1277 | 1270 |
} |
1278 | 1271 |
|
1279 | 1272 |
}; |
1280 | 1273 |
|
1281 | 1274 |
/// \ingroup search |
1282 | 1275 |
/// |
1283 | 1276 |
/// \brief BFS algorithm class with visitor interface. |
1284 | 1277 |
/// |
1285 | 1278 |
/// This class provides an efficient implementation of the BFS algorithm |
1286 | 1279 |
/// with visitor interface. |
1287 | 1280 |
/// |
1288 | 1281 |
/// The BfsVisit class provides an alternative interface to the Bfs |
1289 | 1282 |
/// class. It works with callback mechanism, the BfsVisit object calls |
1290 | 1283 |
/// the member functions of the \c Visitor class on every BFS event. |
1291 | 1284 |
/// |
1292 | 1285 |
/// This interface of the BFS algorithm should be used in special cases |
1293 | 1286 |
/// when extra actions have to be performed in connection with certain |
1294 | 1287 |
/// events of the BFS algorithm. Otherwise consider to use Bfs or bfs() |
1295 | 1288 |
/// instead. |
1296 | 1289 |
/// |
1297 | 1290 |
/// \tparam GR The type of the digraph the algorithm runs on. |
1298 | 1291 |
/// The default type is \ref ListDigraph. |
1299 | 1292 |
/// The value of GR is not used directly by \ref BfsVisit, |
... | ... |
@@ -1396,66 +1389,66 @@ |
1396 | 1389 |
/// \param visitor The visitor object of the algorithm. |
1397 | 1390 |
BfsVisit(const Digraph& digraph, Visitor& visitor) |
1398 | 1391 |
: _digraph(&digraph), _visitor(&visitor), |
1399 | 1392 |
_reached(0), local_reached(false) {} |
1400 | 1393 |
|
1401 | 1394 |
/// \brief Destructor. |
1402 | 1395 |
~BfsVisit() { |
1403 | 1396 |
if(local_reached) delete _reached; |
1404 | 1397 |
} |
1405 | 1398 |
|
1406 | 1399 |
/// \brief Sets the map that indicates which nodes are reached. |
1407 | 1400 |
/// |
1408 | 1401 |
/// Sets the map that indicates which nodes are reached. |
1409 | 1402 |
/// If you don't use this function before calling \ref run(Node) "run()" |
1410 | 1403 |
/// or \ref init(), an instance will be allocated automatically. |
1411 | 1404 |
/// The destructor deallocates this automatically allocated map, |
1412 | 1405 |
/// of course. |
1413 | 1406 |
/// \return <tt> (*this) </tt> |
1414 | 1407 |
BfsVisit &reachedMap(ReachedMap &m) { |
1415 | 1408 |
if(local_reached) { |
1416 | 1409 |
delete _reached; |
1417 | 1410 |
local_reached = false; |
1418 | 1411 |
} |
1419 | 1412 |
_reached = &m; |
1420 | 1413 |
return *this; |
1421 | 1414 |
} |
1422 | 1415 |
|
1423 | 1416 |
public: |
1424 | 1417 |
|
1425 | 1418 |
/// \name Execution Control |
1426 | 1419 |
/// The simplest way to execute the BFS algorithm is to use one of the |
1427 | 1420 |
/// member functions called \ref run(Node) "run()".\n |
1428 |
/// If you need more control on the execution, first you have to call |
|
1429 |
/// \ref init(), then you can add several source nodes with |
|
1421 |
/// If you need better control on the execution, you have to call |
|
1422 |
/// \ref init() first, then you can add several source nodes with |
|
1430 | 1423 |
/// \ref addSource(). Finally the actual path computation can be |
1431 | 1424 |
/// performed with one of the \ref start() functions. |
1432 | 1425 |
|
1433 | 1426 |
/// @{ |
1434 | 1427 |
|
1435 | 1428 |
/// \brief Initializes the internal data structures. |
1436 | 1429 |
/// |
1437 | 1430 |
/// Initializes the internal data structures. |
1438 | 1431 |
void init() { |
1439 | 1432 |
create_maps(); |
1440 | 1433 |
_list.resize(countNodes(*_digraph)); |
1441 | 1434 |
_list_front = _list_back = -1; |
1442 | 1435 |
for (NodeIt u(*_digraph) ; u != INVALID ; ++u) { |
1443 | 1436 |
_reached->set(u, false); |
1444 | 1437 |
} |
1445 | 1438 |
} |
1446 | 1439 |
|
1447 | 1440 |
/// \brief Adds a new source node. |
1448 | 1441 |
/// |
1449 | 1442 |
/// Adds a new source node to the set of nodes to be processed. |
1450 | 1443 |
void addSource(Node s) { |
1451 | 1444 |
if(!(*_reached)[s]) { |
1452 | 1445 |
_reached->set(s,true); |
1453 | 1446 |
_visitor->start(s); |
1454 | 1447 |
_visitor->reach(s); |
1455 | 1448 |
_list[++_list_back] = s; |
1456 | 1449 |
} |
1457 | 1450 |
} |
1458 | 1451 |
|
1459 | 1452 |
/// \brief Processes the next node. |
1460 | 1453 |
/// |
1461 | 1454 |
/// Processes the next node. |
... | ... |
@@ -1669,84 +1662,80 @@ |
1669 | 1662 |
/// b.start(); |
1670 | 1663 |
///\endcode |
1671 | 1664 |
void run(Node s) { |
1672 | 1665 |
init(); |
1673 | 1666 |
addSource(s); |
1674 | 1667 |
start(); |
1675 | 1668 |
} |
1676 | 1669 |
|
1677 | 1670 |
/// \brief Finds the shortest path between \c s and \c t. |
1678 | 1671 |
/// |
1679 | 1672 |
/// This method runs the %BFS algorithm from node \c s |
1680 | 1673 |
/// in order to compute the shortest path to node \c t |
1681 | 1674 |
/// (it stops searching when \c t is processed). |
1682 | 1675 |
/// |
1683 | 1676 |
/// \return \c true if \c t is reachable form \c s. |
1684 | 1677 |
/// |
1685 | 1678 |
/// \note Apart from the return value, <tt>b.run(s,t)</tt> is just a |
1686 | 1679 |
/// shortcut of the following code. |
1687 | 1680 |
///\code |
1688 | 1681 |
/// b.init(); |
1689 | 1682 |
/// b.addSource(s); |
1690 | 1683 |
/// b.start(t); |
1691 | 1684 |
///\endcode |
1692 | 1685 |
bool run(Node s,Node t) { |
1693 | 1686 |
init(); |
1694 | 1687 |
addSource(s); |
1695 | 1688 |
start(t); |
1696 | 1689 |
return reached(t); |
1697 | 1690 |
} |
1698 | 1691 |
|
1699 | 1692 |
/// \brief Runs the algorithm to visit all nodes in the digraph. |
1700 | 1693 |
/// |
1701 |
/// This method runs the %BFS algorithm in order to |
|
1702 |
/// compute the shortest path to each node. |
|
1703 |
/// |
|
1704 |
/// The algorithm computes |
|
1705 |
/// - the shortest path tree (forest), |
|
1706 |
/// - the distance of each node from the root(s). |
|
1694 |
/// This method runs the %BFS algorithm in order to visit all nodes |
|
1695 |
/// in the digraph. |
|
1707 | 1696 |
/// |
1708 | 1697 |
/// \note <tt>b.run(s)</tt> is just a shortcut of the following code. |
1709 | 1698 |
///\code |
1710 | 1699 |
/// b.init(); |
1711 | 1700 |
/// for (NodeIt n(gr); n != INVALID; ++n) { |
1712 | 1701 |
/// if (!b.reached(n)) { |
1713 | 1702 |
/// b.addSource(n); |
1714 | 1703 |
/// b.start(); |
1715 | 1704 |
/// } |
1716 | 1705 |
/// } |
1717 | 1706 |
///\endcode |
1718 | 1707 |
void run() { |
1719 | 1708 |
init(); |
1720 | 1709 |
for (NodeIt it(*_digraph); it != INVALID; ++it) { |
1721 | 1710 |
if (!reached(it)) { |
1722 | 1711 |
addSource(it); |
1723 | 1712 |
start(); |
1724 | 1713 |
} |
1725 | 1714 |
} |
1726 | 1715 |
} |
1727 | 1716 |
|
1728 | 1717 |
///@} |
1729 | 1718 |
|
1730 | 1719 |
/// \name Query Functions |
1731 | 1720 |
/// The results of the BFS algorithm can be obtained using these |
1732 | 1721 |
/// functions.\n |
1733 | 1722 |
/// Either \ref run(Node) "run()" or \ref start() should be called |
1734 | 1723 |
/// before using them. |
1735 | 1724 |
|
1736 | 1725 |
///@{ |
1737 | 1726 |
|
1738 |
/// \brief Checks if |
|
1727 |
/// \brief Checks if the given node is reached from the root(s). |
|
1739 | 1728 |
/// |
1740 | 1729 |
/// Returns \c true if \c v is reached from the root(s). |
1741 | 1730 |
/// |
1742 | 1731 |
/// \pre Either \ref run(Node) "run()" or \ref init() |
1743 | 1732 |
/// must be called before using this function. |
1744 | 1733 |
bool reached(Node v) const { return (*_reached)[v]; } |
1745 | 1734 |
|
1746 | 1735 |
///@} |
1747 | 1736 |
|
1748 | 1737 |
}; |
1749 | 1738 |
|
1750 | 1739 |
} //END OF NAMESPACE LEMON |
1751 | 1740 |
|
1752 | 1741 |
#endif |
... | ... |
@@ -27,69 +27,69 @@ |
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 |
} |
... | ... |
@@ -326,73 +326,73 @@ |
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; |
... | ... |
@@ -20,64 +20,66 @@ |
20 | 20 |
#define LEMON_BITS_MAP_EXTENDER_H |
21 | 21 |
|
22 | 22 |
#include <iterator> |
23 | 23 |
|
24 | 24 |
#include <lemon/bits/traits.h> |
25 | 25 |
|
26 | 26 |
#include <lemon/concept_check.h> |
27 | 27 |
#include <lemon/concepts/maps.h> |
28 | 28 |
|
29 | 29 |
//\file |
30 | 30 |
//\brief Extenders for iterable maps. |
31 | 31 |
|
32 | 32 |
namespace lemon { |
33 | 33 |
|
34 | 34 |
// \ingroup graphbits |
35 | 35 |
// |
36 | 36 |
// \brief Extender for maps |
37 | 37 |
template <typename _Map> |
38 | 38 |
class MapExtender : public _Map { |
39 | 39 |
typedef _Map Parent; |
40 | 40 |
typedef typename Parent::GraphType GraphType; |
41 | 41 |
|
42 | 42 |
public: |
43 | 43 |
|
44 | 44 |
typedef MapExtender Map; |
45 | 45 |
typedef typename Parent::Key Item; |
46 | 46 |
|
47 | 47 |
typedef typename Parent::Key Key; |
48 | 48 |
typedef typename Parent::Value Value; |
49 | 49 |
typedef typename Parent::Reference Reference; |
50 | 50 |
typedef typename Parent::ConstReference ConstReference; |
51 | 51 |
|
52 |
typedef typename Parent::ReferenceMapTag ReferenceMapTag; |
|
53 |
|
|
52 | 54 |
class MapIt; |
53 | 55 |
class ConstMapIt; |
54 | 56 |
|
55 | 57 |
friend class MapIt; |
56 | 58 |
friend class ConstMapIt; |
57 | 59 |
|
58 | 60 |
public: |
59 | 61 |
|
60 | 62 |
MapExtender(const GraphType& graph) |
61 | 63 |
: Parent(graph) {} |
62 | 64 |
|
63 | 65 |
MapExtender(const GraphType& graph, const Value& value) |
64 | 66 |
: Parent(graph, value) {} |
65 | 67 |
|
66 | 68 |
private: |
67 | 69 |
MapExtender& operator=(const MapExtender& cmap) { |
68 | 70 |
return operator=<MapExtender>(cmap); |
69 | 71 |
} |
70 | 72 |
|
71 | 73 |
template <typename CMap> |
72 | 74 |
MapExtender& operator=(const CMap& cmap) { |
73 | 75 |
Parent::operator=(cmap); |
74 | 76 |
return *this; |
75 | 77 |
} |
76 | 78 |
|
77 | 79 |
public: |
78 | 80 |
class MapIt : public Item { |
79 | 81 |
typedef Item Parent; |
80 | 82 |
|
81 | 83 |
public: |
82 | 84 |
|
83 | 85 |
typedef typename Map::Value Value; |
... | ... |
@@ -162,64 +164,66 @@ |
162 | 164 |
ItemIt(const Map& _map, const Item& item) |
163 | 165 |
: Parent(item), map(_map) {} |
164 | 166 |
|
165 | 167 |
ItemIt& operator++() { |
166 | 168 |
map.notifier()->next(*this); |
167 | 169 |
return *this; |
168 | 170 |
} |
169 | 171 |
|
170 | 172 |
protected: |
171 | 173 |
const Map& map; |
172 | 174 |
|
173 | 175 |
}; |
174 | 176 |
}; |
175 | 177 |
|
176 | 178 |
// \ingroup graphbits |
177 | 179 |
// |
178 | 180 |
// \brief Extender for maps which use a subset of the items. |
179 | 181 |
template <typename _Graph, typename _Map> |
180 | 182 |
class SubMapExtender : public _Map { |
181 | 183 |
typedef _Map Parent; |
182 | 184 |
typedef _Graph GraphType; |
183 | 185 |
|
184 | 186 |
public: |
185 | 187 |
|
186 | 188 |
typedef SubMapExtender Map; |
187 | 189 |
typedef typename Parent::Key Item; |
188 | 190 |
|
189 | 191 |
typedef typename Parent::Key Key; |
190 | 192 |
typedef typename Parent::Value Value; |
191 | 193 |
typedef typename Parent::Reference Reference; |
192 | 194 |
typedef typename Parent::ConstReference ConstReference; |
193 | 195 |
|
196 |
typedef typename Parent::ReferenceMapTag ReferenceMapTag; |
|
197 |
|
|
194 | 198 |
class MapIt; |
195 | 199 |
class ConstMapIt; |
196 | 200 |
|
197 | 201 |
friend class MapIt; |
198 | 202 |
friend class ConstMapIt; |
199 | 203 |
|
200 | 204 |
public: |
201 | 205 |
|
202 | 206 |
SubMapExtender(const GraphType& _graph) |
203 | 207 |
: Parent(_graph), graph(_graph) {} |
204 | 208 |
|
205 | 209 |
SubMapExtender(const GraphType& _graph, const Value& _value) |
206 | 210 |
: Parent(_graph, _value), graph(_graph) {} |
207 | 211 |
|
208 | 212 |
private: |
209 | 213 |
SubMapExtender& operator=(const SubMapExtender& cmap) { |
210 | 214 |
return operator=<MapExtender>(cmap); |
211 | 215 |
} |
212 | 216 |
|
213 | 217 |
template <typename CMap> |
214 | 218 |
SubMapExtender& operator=(const CMap& cmap) { |
215 | 219 |
checkConcept<concepts::ReadMap<Key, Value>, CMap>(); |
216 | 220 |
Item it; |
217 | 221 |
for (graph.first(it); it != INVALID; graph.next(it)) { |
218 | 222 |
Parent::set(it, cmap[it]); |
219 | 223 |
} |
220 | 224 |
return *this; |
221 | 225 |
} |
222 | 226 |
|
223 | 227 |
public: |
224 | 228 |
class MapIt : public Item { |
225 | 229 |
typedef Item Parent; |
... | ... |
@@ -65,64 +65,76 @@ |
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 |
} |
... | ... |
@@ -33,64 +33,65 @@ |
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); |
... | ... |
@@ -43,82 +43,89 @@ |
43 | 43 |
|
44 | 44 |
/// \brief The type of the digraph the algorithm runs on. |
45 | 45 |
typedef GR Digraph; |
46 | 46 |
|
47 | 47 |
/// \brief The type of the lower bound map. |
48 | 48 |
/// |
49 | 49 |
/// The type of the map that stores the lower bounds on the arcs. |
50 | 50 |
/// It must conform to the \ref concepts::ReadMap "ReadMap" concept. |
51 | 51 |
typedef LM LowerMap; |
52 | 52 |
|
53 | 53 |
/// \brief The type of the upper bound (capacity) map. |
54 | 54 |
/// |
55 | 55 |
/// The type of the map that stores the upper bounds (capacities) |
56 | 56 |
/// on the arcs. |
57 | 57 |
/// It must conform to the \ref concepts::ReadMap "ReadMap" concept. |
58 | 58 |
typedef UM UpperMap; |
59 | 59 |
|
60 | 60 |
/// \brief The type of supply map. |
61 | 61 |
/// |
62 | 62 |
/// The type of the map that stores the signed supply values of the |
63 | 63 |
/// nodes. |
64 | 64 |
/// It must conform to the \ref concepts::ReadMap "ReadMap" concept. |
65 | 65 |
typedef SM SupplyMap; |
66 | 66 |
|
67 | 67 |
/// \brief The type of the flow and supply values. |
68 | 68 |
typedef typename SupplyMap::Value Value; |
69 | 69 |
|
70 | 70 |
/// \brief The type of the map that stores the flow values. |
71 | 71 |
/// |
72 | 72 |
/// The type of the map that stores the flow values. |
73 | 73 |
/// It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap" |
74 | 74 |
/// concept. |
75 |
#ifdef DOXYGEN |
|
76 |
typedef GR::ArcMap<Value> FlowMap; |
|
77 |
#else |
|
75 | 78 |
typedef typename Digraph::template ArcMap<Value> FlowMap; |
79 |
#endif |
|
76 | 80 |
|
77 | 81 |
/// \brief Instantiates a FlowMap. |
78 | 82 |
/// |
79 | 83 |
/// This function instantiates a \ref FlowMap. |
80 | 84 |
/// \param digraph The digraph for which we would like to define |
81 | 85 |
/// the flow map. |
82 | 86 |
static FlowMap* createFlowMap(const Digraph& digraph) { |
83 | 87 |
return new FlowMap(digraph); |
84 | 88 |
} |
85 | 89 |
|
86 | 90 |
/// \brief The elevator type used by the algorithm. |
87 | 91 |
/// |
88 | 92 |
/// The elevator type used by the algorithm. |
89 | 93 |
/// |
90 |
/// \sa Elevator |
|
91 |
/// \sa LinkedElevator |
|
94 |
/// \sa Elevator, LinkedElevator |
|
95 |
#ifdef DOXYGEN |
|
96 |
typedef lemon::Elevator<GR, GR::Node> Elevator; |
|
97 |
#else |
|
92 | 98 |
typedef lemon::Elevator<Digraph, typename Digraph::Node> Elevator; |
99 |
#endif |
|
93 | 100 |
|
94 | 101 |
/// \brief Instantiates an Elevator. |
95 | 102 |
/// |
96 | 103 |
/// This function instantiates an \ref Elevator. |
97 | 104 |
/// \param digraph The digraph for which we would like to define |
98 | 105 |
/// the elevator. |
99 | 106 |
/// \param max_level The maximum level of the elevator. |
100 | 107 |
static Elevator* createElevator(const Digraph& digraph, int max_level) { |
101 | 108 |
return new Elevator(digraph, max_level); |
102 | 109 |
} |
103 | 110 |
|
104 | 111 |
/// \brief The tolerance used by the algorithm |
105 | 112 |
/// |
106 | 113 |
/// The tolerance used by the algorithm to handle inexact computation. |
107 | 114 |
typedef lemon::Tolerance<Value> Tolerance; |
108 | 115 |
|
109 | 116 |
}; |
110 | 117 |
|
111 | 118 |
/** |
112 | 119 |
\brief Push-relabel algorithm for the network circulation problem. |
113 | 120 |
|
114 | 121 |
\ingroup max_flow |
115 | 122 |
This class implements a push-relabel algorithm for the \e network |
116 | 123 |
\e circulation problem. |
117 | 124 |
It is to find a feasible circulation when lower and upper bounds |
118 | 125 |
are given for the flow values on the arcs and lower bounds are |
119 | 126 |
given for the difference between the outgoing and incoming flow |
120 | 127 |
at the nodes. |
121 | 128 |
|
122 | 129 |
The exact formulation of this problem is the following. |
123 | 130 |
Let \f$G=(V,A)\f$ be a digraph, \f$lower: A\rightarrow\mathbf{R}\f$ |
124 | 131 |
\f$upper: A\rightarrow\mathbf{R}\cup\{\infty\}\f$ denote the lower and |
... | ... |
@@ -270,65 +277,65 @@ |
270 | 277 |
/// Elevator type |
271 | 278 |
/// |
272 | 279 |
/// \ref named-templ-param "Named parameter" for setting Elevator |
273 | 280 |
/// type. If this named parameter is used, then an external |
274 | 281 |
/// elevator object must be passed to the algorithm using the |
275 | 282 |
/// \ref elevator(Elevator&) "elevator()" function before calling |
276 | 283 |
/// \ref run() or \ref init(). |
277 | 284 |
/// \sa SetStandardElevator |
278 | 285 |
template <typename T> |
279 | 286 |
struct SetElevator |
280 | 287 |
: public Circulation<Digraph, LowerMap, UpperMap, SupplyMap, |
281 | 288 |
SetElevatorTraits<T> > { |
282 | 289 |
typedef Circulation<Digraph, LowerMap, UpperMap, SupplyMap, |
283 | 290 |
SetElevatorTraits<T> > Create; |
284 | 291 |
}; |
285 | 292 |
|
286 | 293 |
template <typename T> |
287 | 294 |
struct SetStandardElevatorTraits : public Traits { |
288 | 295 |
typedef T Elevator; |
289 | 296 |
static Elevator *createElevator(const Digraph& digraph, int max_level) { |
290 | 297 |
return new Elevator(digraph, max_level); |
291 | 298 |
} |
292 | 299 |
}; |
293 | 300 |
|
294 | 301 |
/// \brief \ref named-templ-param "Named parameter" for setting |
295 | 302 |
/// Elevator type with automatic allocation |
296 | 303 |
/// |
297 | 304 |
/// \ref named-templ-param "Named parameter" for setting Elevator |
298 | 305 |
/// type with automatic allocation. |
299 | 306 |
/// The Elevator should have standard constructor interface to be |
300 | 307 |
/// able to automatically created by the algorithm (i.e. the |
301 | 308 |
/// digraph and the maximum level should be passed to it). |
302 |
/// However an external elevator object could also be passed to the |
|
309 |
/// However, an external elevator object could also be passed to the |
|
303 | 310 |
/// algorithm with the \ref elevator(Elevator&) "elevator()" function |
304 | 311 |
/// before calling \ref run() or \ref init(). |
305 | 312 |
/// \sa SetElevator |
306 | 313 |
template <typename T> |
307 | 314 |
struct SetStandardElevator |
308 | 315 |
: public Circulation<Digraph, LowerMap, UpperMap, SupplyMap, |
309 | 316 |
SetStandardElevatorTraits<T> > { |
310 | 317 |
typedef Circulation<Digraph, LowerMap, UpperMap, SupplyMap, |
311 | 318 |
SetStandardElevatorTraits<T> > Create; |
312 | 319 |
}; |
313 | 320 |
|
314 | 321 |
/// @} |
315 | 322 |
|
316 | 323 |
protected: |
317 | 324 |
|
318 | 325 |
Circulation() {} |
319 | 326 |
|
320 | 327 |
public: |
321 | 328 |
|
322 | 329 |
/// Constructor. |
323 | 330 |
|
324 | 331 |
/// The constructor of the class. |
325 | 332 |
/// |
326 | 333 |
/// \param graph The digraph the algorithm runs on. |
327 | 334 |
/// \param lower The lower bounds for the flow values on the arcs. |
328 | 335 |
/// \param upper The upper bounds (capacities) for the flow values |
329 | 336 |
/// on the arcs. |
330 | 337 |
/// \param supply The signed supply values of the nodes. |
331 | 338 |
Circulation(const Digraph &graph, const LowerMap &lower, |
332 | 339 |
const UpperMap &upper, const SupplyMap &supply) |
333 | 340 |
: _g(graph), _lo(&lower), _up(&upper), _supply(&supply), |
334 | 341 |
_flow(NULL), _local_flow(false), _level(NULL), _local_level(false), |
... | ... |
@@ -440,66 +447,66 @@ |
440 | 447 |
return *this; |
441 | 448 |
} |
442 | 449 |
|
443 | 450 |
/// \brief Returns a const reference to the elevator. |
444 | 451 |
/// |
445 | 452 |
/// Returns a const reference to the elevator. |
446 | 453 |
/// |
447 | 454 |
/// \pre Either \ref run() or \ref init() must be called before |
448 | 455 |
/// using this function. |
449 | 456 |
const Elevator& elevator() const { |
450 | 457 |
return *_level; |
451 | 458 |
} |
452 | 459 |
|
453 | 460 |
/// \brief Sets the tolerance used by the algorithm. |
454 | 461 |
/// |
455 | 462 |
/// Sets the tolerance object used by the algorithm. |
456 | 463 |
/// \return <tt>(*this)</tt> |
457 | 464 |
Circulation& tolerance(const Tolerance& tolerance) { |
458 | 465 |
_tol = tolerance; |
459 | 466 |
return *this; |
460 | 467 |
} |
461 | 468 |
|
462 | 469 |
/// \brief Returns a const reference to the tolerance. |
463 | 470 |
/// |
464 | 471 |
/// Returns a const reference to the tolerance object used by |
465 | 472 |
/// the algorithm. |
466 | 473 |
const Tolerance& tolerance() const { |
467 | 474 |
return _tol; |
468 | 475 |
} |
469 | 476 |
|
470 | 477 |
/// \name Execution Control |
471 | 478 |
/// The simplest way to execute the algorithm is to call \ref run().\n |
472 |
/// If you need more control on the initial solution or the execution, |
|
473 |
/// first you have to call one of the \ref init() functions, then |
|
479 |
/// If you need better control on the initial solution or the execution, |
|
480 |
/// you have to call one of the \ref init() functions first, then |
|
474 | 481 |
/// the \ref start() function. |
475 | 482 |
|
476 | 483 |
///@{ |
477 | 484 |
|
478 | 485 |
/// Initializes the internal data structures. |
479 | 486 |
|
480 | 487 |
/// Initializes the internal data structures and sets all flow values |
481 | 488 |
/// to the lower bound. |
482 | 489 |
void init() |
483 | 490 |
{ |
484 | 491 |
LEMON_DEBUG(checkBoundMaps(), |
485 | 492 |
"Upper bounds must be greater or equal to the lower bounds"); |
486 | 493 |
|
487 | 494 |
createStructures(); |
488 | 495 |
|
489 | 496 |
for(NodeIt n(_g);n!=INVALID;++n) { |
490 | 497 |
(*_excess)[n] = (*_supply)[n]; |
491 | 498 |
} |
492 | 499 |
|
493 | 500 |
for (ArcIt e(_g);e!=INVALID;++e) { |
494 | 501 |
_flow->set(e, (*_lo)[e]); |
495 | 502 |
(*_excess)[_g.target(e)] += (*_flow)[e]; |
496 | 503 |
(*_excess)[_g.source(e)] -= (*_flow)[e]; |
497 | 504 |
} |
498 | 505 |
|
499 | 506 |
// global relabeling tested, but in general case it provides |
500 | 507 |
// worse performance for random digraphs |
501 | 508 |
_level->initStart(); |
502 | 509 |
for(NodeIt n(_g);n!=INVALID;++n) |
503 | 510 |
_level->initAddItem(n); |
504 | 511 |
_level->initFinish(); |
505 | 512 |
for(NodeIt n(_g);n!=INVALID;++n) |
... | ... |
@@ -49,64 +49,77 @@ |
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); |
... | ... |
@@ -46,64 +46,65 @@ |
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); |
... | ... |
@@ -6,483 +6,484 @@ |
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. |
|
117 |
/// Its usage is quite simple, for example you can count the number |
|
118 |
/// |
|
109 |
/// This iterator goes through each node of the digraph. |
|
110 |
/// Its usage is quite simple, for example, you can count the number |
|
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 |
/// Its usage is quite simple, for example you can count the number |
|
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 |
/// Its usage is quite simple, for example you can count the number |
|
256 |
/// of outgoing arcs of a node \c n |
|
257 |
/// |
|
244 |
/// Its usage is quite simple, for example, you can count the number |
|
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 |
/// This iterator goes through each arc of a digraph. |
|
300 |
/// Its usage is quite simple, for example you can count the number |
|
301 |
/// |
|
285 |
/// Iterator class for the arcs. |
|
286 |
|
|
287 |
/// This iterator goes through each arc of the digraph. |
|
288 |
/// Its usage is quite simple, for example, you can count the number |
|
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. |
|
130 |
/// Its usage is quite simple, for example you can count the number |
|
131 |
/// |
|
142 |
/// This iterator goes through each node of the graph. |
|
143 |
/// Its usage is quite simple, for example, you can count the number |
|
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 a graph. |
|
219 |
/// Its usage is quite simple, for example you can count the number |
|
220 |
/// |
|
230 |
/// This iterator goes through each edge of the graph. |
|
231 |
/// Its usage is quite simple, for example, you can count the number |
|
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 |
/// |
|
266 |
/// 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. |
|
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. |
|
275 |
/// Its usage is quite simple, for example, you can compute the |
|
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 |
/// This iterator goes through each arc of a graph. |
|
358 |
/// Its usage is quite simple, for example you can count the number |
|
359 |
/// |
|
369 |
/// Iterator class for the arcs. |
|
370 |
|
|
371 |
/// This iterator goes through each directed arc of the graph. |
|
372 |
/// Its usage is quite simple, for example, you can count the number |
|
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. |
|
402 |
/// |
|
414 |
/// This iterator goes trough the \e outgoing directed arcs of a |
|
415 |
/// certain node of a graph. |
|
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. |
|
454 |
/// Its usage is quite simple, for example you can count the number |
|
455 |
/// of outgoing arcs of a node \c n |
|
456 |
/// |
|
462 |
/// This iterator goes trough the \e incoming directed arcs of a |
|
463 |
/// certain node of a graph. |
|
464 |
/// Its usage is quite simple, for example, you can count the number |
|
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 |
///\brief The |
|
21 |
///\brief The concepts 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 |
... | ... |
@@ -63,65 +63,65 @@ |
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 { |
... | ... |
@@ -153,64 +153,65 @@ |
153 | 153 |
class ReferenceMap : public ReadWriteMap<K,T> |
154 | 154 |
{ |
155 | 155 |
public: |
156 | 156 |
/// Tag for reference maps. |
157 | 157 |
typedef True ReferenceMapTag; |
158 | 158 |
/// The key type of the map. |
159 | 159 |
typedef K Key; |
160 | 160 |
/// \brief The value type of the map. |
161 | 161 |
/// (The type of objects associated with the keys). |
162 | 162 |
typedef T Value; |
163 | 163 |
/// The reference type of the map. |
164 | 164 |
typedef R Reference; |
165 | 165 |
/// The const reference type of the map. |
166 | 166 |
typedef CR ConstReference; |
167 | 167 |
|
168 | 168 |
public: |
169 | 169 |
|
170 | 170 |
/// Returns a reference to the value associated with the given key. |
171 | 171 |
Reference operator[](const Key &) { |
172 | 172 |
return *static_cast<Value *>(0); |
173 | 173 |
} |
174 | 174 |
|
175 | 175 |
/// Returns a const reference to the value associated with the given key. |
176 | 176 |
ConstReference operator[](const Key &) const { |
177 | 177 |
return *static_cast<Value *>(0); |
178 | 178 |
} |
179 | 179 |
|
180 | 180 |
/// Sets the value associated with the given key. |
181 | 181 |
void set(const Key &k,const Value &t) { operator[](k)=t; } |
182 | 182 |
|
183 | 183 |
template<typename _ReferenceMap> |
184 | 184 |
struct Constraints { |
185 |
|
|
185 |
typename enable_if<typename _ReferenceMap::ReferenceMapTag, void>::type |
|
186 |
constraints() { |
|
186 | 187 |
checkConcept<ReadWriteMap<K, T>, _ReferenceMap >(); |
187 | 188 |
ref = m[key]; |
188 | 189 |
m[key] = val; |
189 | 190 |
m[key] = ref; |
190 | 191 |
m[key] = cref; |
191 | 192 |
own_ref = m[own_key]; |
192 | 193 |
m[own_key] = own_val; |
193 | 194 |
m[own_key] = own_ref; |
194 | 195 |
m[own_key] = own_cref; |
195 | 196 |
m[key] = m[own_key]; |
196 | 197 |
m[own_key] = m[key]; |
197 | 198 |
} |
198 | 199 |
const Key& key; |
199 | 200 |
Value& val; |
200 | 201 |
Reference ref; |
201 | 202 |
ConstReference cref; |
202 | 203 |
const typename _ReferenceMap::Key& own_key; |
203 | 204 |
typename _ReferenceMap::Value& own_val; |
204 | 205 |
typename _ReferenceMap::Reference own_ref; |
205 | 206 |
typename _ReferenceMap::ConstReference own_cref; |
206 | 207 |
_ReferenceMap& m; |
207 | 208 |
}; |
208 | 209 |
}; |
209 | 210 |
|
210 | 211 |
// @} |
211 | 212 |
|
212 | 213 |
} //namespace concepts |
213 | 214 |
|
214 | 215 |
} //namespace lemon |
215 | 216 |
|
216 | 217 |
#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 concept |
20 | 20 |
///\file |
21 |
///\brief |
|
21 |
///\brief The concept of paths |
|
22 | 22 |
/// |
23 | 23 |
|
24 | 24 |
#ifndef LEMON_CONCEPTS_PATH_H |
25 | 25 |
#define LEMON_CONCEPTS_PATH_H |
26 | 26 |
|
27 | 27 |
#include <lemon/core.h> |
28 | 28 |
#include <lemon/concept_check.h> |
29 | 29 |
|
30 | 30 |
namespace lemon { |
31 | 31 |
namespace concepts { |
32 | 32 |
|
33 | 33 |
/// \addtogroup concept |
34 | 34 |
/// @{ |
35 | 35 |
|
36 | 36 |
/// \brief A skeleton structure for representing directed paths in |
37 | 37 |
/// a digraph. |
38 | 38 |
/// |
39 | 39 |
/// A skeleton structure for representing directed paths in a |
40 | 40 |
/// digraph. |
41 |
/// In a sense, a path can be treated as a list of arcs. |
|
42 |
/// LEMON path types just store this list. As a consequence, they cannot |
|
43 |
/// enumerate the nodes on the path directly and a zero length path |
|
44 |
/// cannot store its source node. |
|
45 |
/// |
|
46 |
/// The arcs of a path should be stored in the order of their directions, |
|
47 |
/// i.e. the target node of each arc should be the same as the source |
|
48 |
/// node of the next arc. This consistency could be checked using |
|
49 |
/// \ref checkPath(). |
|
50 |
/// The source and target nodes of a (consistent) path can be obtained |
|
51 |
/// using \ref pathSource() and \ref pathTarget(). |
|
52 |
/// |
|
53 |
/// A path can be constructed from another path of any type using the |
|
54 |
/// copy constructor or the assignment operator. |
|
55 |
/// |
|
41 | 56 |
/// \tparam GR The digraph type in which the path is. |
42 |
/// |
|
43 |
/// In a sense, the path can be treated as a list of arcs. The |
|
44 |
/// lemon path type stores just this list. As a consequence it |
|
45 |
/// cannot enumerate the nodes in the path and the zero length |
|
46 |
/// paths cannot store the source. |
|
47 |
/// |
|
48 | 57 |
template <typename GR> |
49 | 58 |
class Path { |
50 | 59 |
public: |
51 | 60 |
|
52 | 61 |
/// Type of the underlying digraph. |
53 | 62 |
typedef GR Digraph; |
54 | 63 |
/// Arc type of the underlying digraph. |
55 | 64 |
typedef typename Digraph::Arc Arc; |
56 | 65 |
|
57 | 66 |
class ArcIt; |
58 | 67 |
|
59 | 68 |
/// \brief Default constructor |
60 | 69 |
Path() {} |
61 | 70 |
|
62 |
/// \brief Template constructor |
|
71 |
/// \brief Template copy constructor |
|
63 | 72 |
template <typename CPath> |
64 | 73 |
Path(const CPath& cpath) {} |
65 | 74 |
|
66 |
/// \brief Template assigment |
|
75 |
/// \brief Template assigment operator |
|
67 | 76 |
template <typename CPath> |
68 | 77 |
Path& operator=(const CPath& cpath) { |
69 | 78 |
ignore_unused_variable_warning(cpath); |
70 | 79 |
return *this; |
71 | 80 |
} |
72 | 81 |
|
73 |
/// Length of the path |
|
82 |
/// Length of the path, i.e. the number of arcs on the path. |
|
74 | 83 |
int length() const { return 0;} |
75 | 84 |
|
76 | 85 |
/// Returns whether the path is empty. |
77 | 86 |
bool empty() const { return true;} |
78 | 87 |
|
79 | 88 |
/// Resets the path to an empty path. |
80 | 89 |
void clear() {} |
81 | 90 |
|
82 |
/// \brief LEMON style iterator for |
|
91 |
/// \brief LEMON style iterator for enumerating the arcs of a path. |
|
83 | 92 |
/// |
84 |
/// |
|
93 |
/// LEMON style iterator class for enumerating the arcs of a path. |
|
85 | 94 |
class ArcIt { |
86 | 95 |
public: |
87 | 96 |
/// Default constructor |
88 | 97 |
ArcIt() {} |
89 | 98 |
/// Invalid constructor |
90 | 99 |
ArcIt(Invalid) {} |
91 |
/// |
|
100 |
/// Sets the iterator to the first arc of the given path |
|
92 | 101 |
ArcIt(const Path &) {} |
93 | 102 |
|
94 |
/// Conversion to Arc |
|
103 |
/// Conversion to \c Arc |
|
95 | 104 |
operator Arc() const { return INVALID; } |
96 | 105 |
|
97 | 106 |
/// Next arc |
98 | 107 |
ArcIt& operator++() {return *this;} |
99 | 108 |
|
100 | 109 |
/// Comparison operator |
101 | 110 |
bool operator==(const ArcIt&) const {return true;} |
102 | 111 |
/// Comparison operator |
103 | 112 |
bool operator!=(const ArcIt&) const {return true;} |
104 | 113 |
/// Comparison operator |
105 | 114 |
bool operator<(const ArcIt&) const {return false;} |
106 | 115 |
|
107 | 116 |
}; |
108 | 117 |
|
109 | 118 |
template <typename _Path> |
110 | 119 |
struct Constraints { |
111 | 120 |
void constraints() { |
112 | 121 |
Path<Digraph> pc; |
113 | 122 |
_Path p, pp(pc); |
114 | 123 |
int l = p.length(); |
115 | 124 |
int e = p.empty(); |
116 | 125 |
p.clear(); |
117 | 126 |
|
118 | 127 |
p = pc; |
119 | 128 |
|
120 | 129 |
typename _Path::ArcIt id, ii(INVALID), i(p); |
121 | 130 |
|
122 | 131 |
++i; |
123 | 132 |
typename Digraph::Arc ed = i; |
124 | 133 |
|
125 | 134 |
e = (i == ii); |
126 | 135 |
e = (i != ii); |
... | ... |
@@ -163,145 +172,139 @@ |
163 | 172 |
|
164 | 173 |
template <typename _Digraph, typename _Path> |
165 | 174 |
struct PathDumperConstraints< |
166 | 175 |
_Digraph, _Path, |
167 | 176 |
typename enable_if<typename _Path::RevPathTag, void>::type |
168 | 177 |
> { |
169 | 178 |
void constraints() { |
170 | 179 |
int l = p.length(); |
171 | 180 |
int e = p.empty(); |
172 | 181 |
|
173 | 182 |
typename _Path::RevArcIt id, i(p); |
174 | 183 |
|
175 | 184 |
++i; |
176 | 185 |
typename _Digraph::Arc ed = i; |
177 | 186 |
|
178 | 187 |
e = (i == INVALID); |
179 | 188 |
e = (i != INVALID); |
180 | 189 |
|
181 | 190 |
ignore_unused_variable_warning(l); |
182 | 191 |
ignore_unused_variable_warning(e); |
183 | 192 |
ignore_unused_variable_warning(id); |
184 | 193 |
ignore_unused_variable_warning(ed); |
185 | 194 |
} |
186 | 195 |
_Path& p; |
187 | 196 |
}; |
188 | 197 |
|
189 | 198 |
} |
190 | 199 |
|
191 | 200 |
|
192 | 201 |
/// \brief A skeleton structure for path dumpers. |
193 | 202 |
/// |
194 | 203 |
/// A skeleton structure for path dumpers. The path dumpers are |
195 |
/// the generalization of the paths. The path dumpers can |
|
196 |
/// enumerate the arcs of the path wheter in forward or in |
|
197 |
/// backward order. In most time these classes are not used |
|
198 |
/// directly rather it used to assign a dumped class to a real |
|
199 |
/// |
|
204 |
/// the generalization of the paths, they can enumerate the arcs |
|
205 |
/// of the path either in forward or in backward order. |
|
206 |
/// These classes are typically not used directly, they are rather |
|
207 |
/// used to be assigned to a real path type. |
|
200 | 208 |
/// |
201 | 209 |
/// The main purpose of this concept is that the shortest path |
202 |
/// algorithms can enumerate easily the arcs in reverse order. |
|
203 |
/// If we would like to give back a real path from these |
|
204 |
/// algorithms then we should create a temporarly path object. In |
|
205 |
/// LEMON such algorithms gives back a path dumper what can |
|
206 |
/// |
|
210 |
/// algorithms can enumerate the arcs easily in reverse order. |
|
211 |
/// In LEMON, such algorithms give back a (reverse) path dumper that |
|
212 |
/// can be assigned to a real path. The dumpers can be implemented as |
|
207 | 213 |
/// an adaptor class to the predecessor map. |
208 | 214 |
/// |
209 | 215 |
/// \tparam GR The digraph type in which the path is. |
210 |
/// |
|
211 |
/// The paths can be constructed from any path type by a |
|
212 |
/// template constructor or a template assignment operator. |
|
213 | 216 |
template <typename GR> |
214 | 217 |
class PathDumper { |
215 | 218 |
public: |
216 | 219 |
|
217 | 220 |
/// Type of the underlying digraph. |
218 | 221 |
typedef GR Digraph; |
219 | 222 |
/// Arc type of the underlying digraph. |
220 | 223 |
typedef typename Digraph::Arc Arc; |
221 | 224 |
|
222 |
/// Length of the path |
|
225 |
/// Length of the path, i.e. the number of arcs on the path. |
|
223 | 226 |
int length() const { return 0;} |
224 | 227 |
|
225 | 228 |
/// Returns whether the path is empty. |
226 | 229 |
bool empty() const { return true;} |
227 | 230 |
|
228 | 231 |
/// \brief Forward or reverse dumping |
229 | 232 |
/// |
230 |
/// If the RevPathTag is defined and true then reverse dumping |
|
231 |
/// is provided in the path dumper. In this case instead of the |
|
232 |
/// ArcIt the RevArcIt iterator should be implemented in the |
|
233 |
/// dumper. |
|
233 |
/// If this tag is defined to be \c True, then reverse dumping |
|
234 |
/// is provided in the path dumper. In this case, \c RevArcIt |
|
235 |
/// iterator should be implemented instead of \c ArcIt iterator. |
|
234 | 236 |
typedef False RevPathTag; |
235 | 237 |
|
236 |
/// \brief LEMON style iterator for |
|
238 |
/// \brief LEMON style iterator for enumerating the arcs of a path. |
|
237 | 239 |
/// |
238 |
/// |
|
240 |
/// LEMON style iterator class for enumerating the arcs of a path. |
|
239 | 241 |
class ArcIt { |
240 | 242 |
public: |
241 | 243 |
/// Default constructor |
242 | 244 |
ArcIt() {} |
243 | 245 |
/// Invalid constructor |
244 | 246 |
ArcIt(Invalid) {} |
245 |
/// |
|
247 |
/// Sets the iterator to the first arc of the given path |
|
246 | 248 |
ArcIt(const PathDumper&) {} |
247 | 249 |
|
248 |
/// Conversion to Arc |
|
250 |
/// Conversion to \c Arc |
|
249 | 251 |
operator Arc() const { return INVALID; } |
250 | 252 |
|
251 | 253 |
/// Next arc |
252 | 254 |
ArcIt& operator++() {return *this;} |
253 | 255 |
|
254 | 256 |
/// Comparison operator |
255 | 257 |
bool operator==(const ArcIt&) const {return true;} |
256 | 258 |
/// Comparison operator |
257 | 259 |
bool operator!=(const ArcIt&) const {return true;} |
258 | 260 |
/// Comparison operator |
259 | 261 |
bool operator<(const ArcIt&) const {return false;} |
260 | 262 |
|
261 | 263 |
}; |
262 | 264 |
|
263 |
/// \brief LEMON style iterator for |
|
265 |
/// \brief LEMON style iterator for enumerating the arcs of a path |
|
266 |
/// in reverse direction. |
|
264 | 267 |
/// |
265 |
/// This class is used to iterate on the arcs of the paths in |
|
266 |
/// reverse direction. |
|
268 |
/// LEMON style iterator class for enumerating the arcs of a path |
|
269 |
/// in reverse direction. |
|
267 | 270 |
class RevArcIt { |
268 | 271 |
public: |
269 | 272 |
/// Default constructor |
270 | 273 |
RevArcIt() {} |
271 | 274 |
/// Invalid constructor |
272 | 275 |
RevArcIt(Invalid) {} |
273 |
/// |
|
276 |
/// Sets the iterator to the last arc of the given path |
|
274 | 277 |
RevArcIt(const PathDumper &) {} |
275 | 278 |
|
276 |
/// Conversion to Arc |
|
279 |
/// Conversion to \c Arc |
|
277 | 280 |
operator Arc() const { return INVALID; } |
278 | 281 |
|
279 | 282 |
/// Next arc |
280 | 283 |
RevArcIt& operator++() {return *this;} |
281 | 284 |
|
282 | 285 |
/// Comparison operator |
283 | 286 |
bool operator==(const RevArcIt&) const {return true;} |
284 | 287 |
/// Comparison operator |
285 | 288 |
bool operator!=(const RevArcIt&) const {return true;} |
286 | 289 |
/// Comparison operator |
287 | 290 |
bool operator<(const RevArcIt&) const {return false;} |
288 | 291 |
|
289 | 292 |
}; |
290 | 293 |
|
291 | 294 |
template <typename _Path> |
292 | 295 |
struct Constraints { |
293 | 296 |
void constraints() { |
294 | 297 |
function_requires<_path_bits:: |
295 | 298 |
PathDumperConstraints<Digraph, _Path> >(); |
296 | 299 |
} |
297 | 300 |
}; |
298 | 301 |
|
299 | 302 |
}; |
300 | 303 |
|
301 | 304 |
|
302 | 305 |
///@} |
303 | 306 |
} |
304 | 307 |
|
305 | 308 |
} // namespace lemon |
306 | 309 |
|
307 | 310 |
#endif |
... | ... |
@@ -183,65 +183,65 @@ |
183 | 183 |
/// Constructor. |
184 | 184 |
Counter(const char *title,std::ostream &os=std::cerr) |
185 | 185 |
: _title(title), _os(os), count(0) {} |
186 | 186 |
/// Destructor. Prints the given title and the value of the counter. |
187 | 187 |
~Counter() { |
188 | 188 |
_os << _title << count <<std::endl; |
189 | 189 |
} |
190 | 190 |
///\e |
191 | 191 |
Counter &operator++() { count++; return *this;} |
192 | 192 |
///\e |
193 | 193 |
int operator++(int) { return count++;} |
194 | 194 |
///\e |
195 | 195 |
Counter &operator--() { count--; return *this;} |
196 | 196 |
///\e |
197 | 197 |
int operator--(int) { return count--;} |
198 | 198 |
///\e |
199 | 199 |
Counter &operator+=(int c) { count+=c; return *this;} |
200 | 200 |
///\e |
201 | 201 |
Counter &operator-=(int c) { count-=c; return *this;} |
202 | 202 |
/// Resets the counter to the given value. |
203 | 203 |
|
204 | 204 |
/// Resets the counter to the given value. |
205 | 205 |
/// \note This function does not reset the values of |
206 | 206 |
/// \ref SubCounter "SubCounter"s but it resets \ref NoSubCounter |
207 | 207 |
/// "NoSubCounter"s along with the main counter. |
208 | 208 |
void reset(int c=0) {count=c;} |
209 | 209 |
/// Returns the value of the counter. |
210 | 210 |
operator int() {return count;} |
211 | 211 |
}; |
212 | 212 |
|
213 | 213 |
/// 'Do nothing' version of Counter. |
214 | 214 |
|
215 |
/// This class can be used in the same way as \ref Counter |
|
215 |
/// This class can be used in the same way as \ref Counter, but it |
|
216 | 216 |
/// does not count at all and does not print report on destruction. |
217 | 217 |
/// |
218 | 218 |
/// Replacing a \ref Counter with a \ref NoCounter makes it possible |
219 | 219 |
/// to turn off all counting and reporting (SubCounters should also |
220 | 220 |
/// be replaced with NoSubCounters), so it does not affect the |
221 | 221 |
/// efficiency of the program at all. |
222 | 222 |
/// |
223 | 223 |
/// \sa Counter |
224 | 224 |
class NoCounter |
225 | 225 |
{ |
226 | 226 |
public: |
227 | 227 |
typedef _NoSubCounter<NoCounter> SubCounter; |
228 | 228 |
typedef _NoSubCounter<NoCounter> NoSubCounter; |
229 | 229 |
|
230 | 230 |
NoCounter() {} |
231 | 231 |
NoCounter(std::string,std::ostream &) {} |
232 | 232 |
NoCounter(const char *,std::ostream &) {} |
233 | 233 |
NoCounter(std::string) {} |
234 | 234 |
NoCounter(const char *) {} |
235 | 235 |
NoCounter &operator++() { return *this; } |
236 | 236 |
int operator++(int) { return 0; } |
237 | 237 |
NoCounter &operator--() { return *this; } |
238 | 238 |
int operator--(int) { return 0; } |
239 | 239 |
NoCounter &operator+=(int) { return *this;} |
240 | 240 |
NoCounter &operator-=(int) { return *this;} |
241 | 241 |
void reset(int) {} |
242 | 242 |
void reset() {} |
243 | 243 |
operator int() {return 0;} |
244 | 244 |
}; |
245 | 245 |
|
246 | 246 |
///@} |
247 | 247 |
} |
... | ... |
@@ -82,64 +82,97 @@ |
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); |
... | ... |
@@ -64,64 +64,65 @@ |
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); |
Changeset was too big and was cut off... Show full diff
0 comments (0 inline)