├── lemon
├── soplex.h
├── lemon.pc.in
├── random.cc
├── lp_base.cc
├── base.cc
├── bits
│ ├── windows.h
│ ├── lock.h
│ ├── enable_if.h
│ ├── windows.cc
│ ├── path_dump.h
│ ├── solver_bits.h
│ ├── bezier.h
│ └── default_map.h
├── color.cc
├── CMakeLists.txt
├── math.h
├── lp.h
├── concept_check.h
├── nauty_reader.h
├── cbc.h
├── clp.h
└── lp_skeleton.cc
├── cmake
├── nsis
│ ├── lemon.ico
│ └── uninstall.ico
├── version.cmake.in
├── FindGhostscript.cmake
├── LEMONConfig.cmake.in
├── FindSOPLEX.cmake
├── FindGLPK.cmake
├── FindCOIN.cmake
└── FindILOG.cmake
├── doc
├── images
│ ├── graph_to_eps.png
│ ├── nodeshape_0.eps
│ ├── nodeshape_1.eps
│ ├── nodeshape_2.eps
│ ├── nodeshape_3.eps
│ ├── nodeshape_4.eps
│ ├── bipartite_partitions.eps
│ └── matching.eps
├── license.dox
├── template.h
├── namespaces.dox
├── mainpage.dox.in
├── dirs.dox
├── coding_style.dox
├── named-param.dox
├── lgf.dox
└── CMakeLists.txt
├── demo
├── CMakeLists.txt
├── digraph.lgf
├── lgf_demo.cc
└── arg_parser_demo.cc
├── scripts
└── valgrind-wrapper.sh
├── .gitignore
├── package.xml
├── contrib
└── CMakeLists.txt
├── tools
├── CMakeLists.txt
└── dimacs-to-lgf.cc
├── test
├── test_tools_pass.cc
├── test_tools_fail.cc
├── random_test.cc
├── time_measure_test.cc
├── arc_look_up_test.cc
├── test_tools.h
├── error_test.cc
├── dim_test.cc
├── unionfind_test.cc
├── counter_test.cc
├── gomory_hu_test.cc
├── mip_test.cc
├── nagamochi_ibaraki_test.cc
├── lgf_test.cc
├── kruskal_test.cc
├── max_cardinality_search_test.cc
├── hao_orlin_test.cc
├── CMakeLists.txt
├── circulation_test.cc
└── min_cost_arborescence_test.cc
├── AUTHORS
├── README
├── LICENSE
└── INSTALL
/lemon/soplex.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tpet/lemon/HEAD/lemon/soplex.h
--------------------------------------------------------------------------------
/cmake/nsis/lemon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tpet/lemon/HEAD/cmake/nsis/lemon.ico
--------------------------------------------------------------------------------
/cmake/nsis/uninstall.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tpet/lemon/HEAD/cmake/nsis/uninstall.ico
--------------------------------------------------------------------------------
/cmake/version.cmake.in:
--------------------------------------------------------------------------------
1 | SET(LEMON_VERSION "@LEMON_VERSION@" CACHE STRING "LEMON version string.")
2 |
--------------------------------------------------------------------------------
/doc/images/graph_to_eps.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tpet/lemon/HEAD/doc/images/graph_to_eps.png
--------------------------------------------------------------------------------
/demo/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | INCLUDE_DIRECTORIES(
2 | ${PROJECT_SOURCE_DIR}
3 | ${PROJECT_BINARY_DIR}
4 | )
5 |
6 | LINK_DIRECTORIES(
7 | ${PROJECT_BINARY_DIR}/lemon
8 | )
9 |
10 | SET(DEMOS
11 | arg_parser_demo
12 | graph_to_eps_demo
13 | lgf_demo
14 | )
15 |
16 | FOREACH(DEMO_NAME ${DEMOS})
17 | ADD_EXECUTABLE(${DEMO_NAME} ${DEMO_NAME}.cc)
18 | TARGET_LINK_LIBRARIES(${DEMO_NAME} lemon)
19 | ENDFOREACH()
20 |
--------------------------------------------------------------------------------
/cmake/FindGhostscript.cmake:
--------------------------------------------------------------------------------
1 | INCLUDE(FindPackageHandleStandardArgs)
2 |
3 | FIND_PROGRAM(GHOSTSCRIPT_EXECUTABLE
4 | NAMES gs gswin32c
5 | PATHS "$ENV{ProgramFiles}/gs"
6 | PATH_SUFFIXES gs8.61/bin gs8.62/bin gs8.63/bin gs8.64/bin gs8.65/bin
7 | DOC "Ghostscript: PostScript and PDF language interpreter and previewer."
8 | )
9 |
10 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(Ghostscript DEFAULT_MSG GHOSTSCRIPT_EXECUTABLE)
11 |
--------------------------------------------------------------------------------
/demo/digraph.lgf:
--------------------------------------------------------------------------------
1 | @nodes
2 | label
3 | 0
4 | 1
5 | 2
6 | 3
7 | 4
8 | 5
9 | 6
10 | 7
11 | @arcs
12 | label capacity
13 | 0 1 0 16
14 | 0 2 1 12
15 | 0 3 2 20
16 | 1 2 3 10
17 | 1 4 4 10
18 | 1 5 5 13
19 | 2 3 6 10
20 | 2 4 7 8
21 | 2 6 8 8
22 | 5 3 9 20
23 | 3 6 10 25
24 | 4 7 11 15
25 | 5 7 12 15
26 | 6 7 13 18
27 | @attributes
28 | source 0
29 | target 7
30 |
--------------------------------------------------------------------------------
/lemon/lemon.pc.in:
--------------------------------------------------------------------------------
1 | prefix=@CMAKE_INSTALL_PREFIX@
2 | exec_prefix=@CMAKE_INSTALL_PREFIX@/bin
3 | libdir=@CMAKE_INSTALL_PREFIX@/lib
4 | includedir=@CMAKE_INSTALL_PREFIX@/include
5 |
6 | Name: @PROJECT_NAME@
7 | Description: Library for Efficient Modeling and Optimization in Networks
8 | Version: @PROJECT_VERSION@
9 | Libs: -L${libdir} -lemon @GLPK_LIBS@ @CPLEX_LIBS@ @SOPLEX_LIBS@ @CLP_LIBS@ @CBC_LIBS@
10 | Cflags: -I${includedir}
11 |
--------------------------------------------------------------------------------
/scripts/valgrind-wrapper.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | # Run in valgrind, with leak checking enabled
4 |
5 | valgrind -q --leak-check=full "$@" 2> .valgrind-log
6 |
7 | # Save the test result
8 |
9 | result="$?"
10 |
11 | # Valgrind should generate no error messages
12 |
13 | log_contents="`cat .valgrind-log`"
14 |
15 | if [ "$log_contents" != "" ]; then
16 | cat .valgrind-log >&2
17 | result=1
18 | fi
19 |
20 | rm -f .valgrind-log
21 |
22 | exit $result
23 |
--------------------------------------------------------------------------------
/cmake/LEMONConfig.cmake.in:
--------------------------------------------------------------------------------
1 | SET(LEMON_INCLUDE_DIR "@CMAKE_INSTALL_PREFIX@/include" CACHE PATH "LEMON include directory")
2 | SET(LEMON_INCLUDE_DIRS "${LEMON_INCLUDE_DIR}")
3 |
4 | IF(UNIX)
5 | SET(LEMON_LIB_NAME "libemon.a")
6 | ELSEIF(WIN32)
7 | SET(LEMON_LIB_NAME "lemon.lib")
8 | ENDIF(UNIX)
9 |
10 | SET(LEMON_LIBRARY "@CMAKE_INSTALL_PREFIX@/lib/${LEMON_LIB_NAME}" CACHE FILEPATH "LEMON library")
11 | SET(LEMON_LIBRARIES "${LEMON_LIBRARY}")
12 |
13 | MARK_AS_ADVANCED(LEMON_LIBRARY LEMON_INCLUDE_DIR)
14 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.obj
2 | *.orig
3 | *.rej
4 | *~
5 | *.o
6 | *.log
7 | *.lo
8 | *.tar.*
9 | *.bak
10 | Makefile.in
11 | aclocal.m4
12 | config.h.in
13 | configure
14 | Makefile
15 | config.h
16 | config.log
17 | config.status
18 | libtool
19 | stamp-h1
20 | lemon/lemon.pc
21 | lemon/libemon.la
22 | lemon/stamp-h2
23 | doc/Doxyfile
24 | doc/references.dox
25 | cmake/version.cmake
26 | .dirstamp
27 | .libs/*
28 | .deps/*
29 | demo/*.eps
30 | m4/libtool.m4
31 | m4/ltoptions.m4
32 | m4/ltsugar.m4
33 | m4/ltversion.m4
34 | m4/lt~obsolete.m4
35 |
--------------------------------------------------------------------------------
/package.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | LEMON
4 | 1.3.1
5 | LEMON Graph Library
6 | Tomas Petricek
7 | Boost Software License, Version 1.0
8 | http://lemon.cs.elte.hu/trac/lemon
9 | See AUTHORS
10 | cmake
11 | catkin
12 |
13 | cmake
14 |
15 |
16 |
--------------------------------------------------------------------------------
/contrib/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | INCLUDE_DIRECTORIES(
2 | ${PROJECT_SOURCE_DIR}
3 | ${PROJECT_BINARY_DIR}
4 | )
5 |
6 | LINK_DIRECTORIES(
7 | ${PROJECT_BINARY_DIR}/lemon
8 | )
9 |
10 | # Uncomment (and adjust) the following two lines. 'myprog' is the name
11 | # of the final executable ('.exe' will automatically be added to the
12 | # name on Windows) and 'myprog-main.cc' is the source code it is
13 | # compiled from. You can add more source files separated by
14 | # whitespaces. Moreover, you can add multiple similar blocks if you
15 | # want to build more than one executables.
16 |
17 | # ADD_EXECUTABLE(myprog myprog-main.cc)
18 | # TARGET_LINK_LIBRARIES(myprog lemon)
19 |
20 |
--------------------------------------------------------------------------------
/cmake/FindSOPLEX.cmake:
--------------------------------------------------------------------------------
1 | SET(SOPLEX_ROOT_DIR "" CACHE PATH "SoPlex root directory")
2 |
3 | FIND_PATH(SOPLEX_INCLUDE_DIR
4 | soplex.h
5 | HINTS ${SOPLEX_ROOT_DIR}/src
6 | )
7 | FIND_LIBRARY(SOPLEX_LIBRARY
8 | soplex
9 | HINTS ${SOPLEX_ROOT_DIR}/lib
10 | )
11 |
12 | INCLUDE(FindPackageHandleStandardArgs)
13 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(SOPLEX DEFAULT_MSG SOPLEX_LIBRARY SOPLEX_INCLUDE_DIR)
14 |
15 | IF(SOPLEX_FOUND)
16 | SET(SOPLEX_INCLUDE_DIRS ${SOPLEX_INCLUDE_DIR})
17 | SET(SOPLEX_LIBRARIES ${SOPLEX_LIBRARY})
18 | IF(CMAKE_SYSTEM_NAME STREQUAL "Linux")
19 | SET(SOPLEX_LIBRARIES "${SOPLEX_LIBRARIES};z")
20 | ENDIF(CMAKE_SYSTEM_NAME STREQUAL "Linux")
21 | ENDIF(SOPLEX_FOUND)
22 |
23 | MARK_AS_ADVANCED(SOPLEX_LIBRARY SOPLEX_INCLUDE_DIR)
24 |
--------------------------------------------------------------------------------
/tools/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | INCLUDE_DIRECTORIES(
2 | ${PROJECT_SOURCE_DIR}
3 | ${PROJECT_BINARY_DIR}
4 | )
5 |
6 | LINK_DIRECTORIES(
7 | ${PROJECT_BINARY_DIR}/lemon
8 | )
9 |
10 | ADD_EXECUTABLE(lgf-gen lgf-gen.cc)
11 | TARGET_LINK_LIBRARIES(lgf-gen lemon)
12 |
13 | ADD_EXECUTABLE(dimacs-to-lgf dimacs-to-lgf.cc)
14 | TARGET_LINK_LIBRARIES(dimacs-to-lgf lemon)
15 |
16 | ADD_EXECUTABLE(dimacs-solver dimacs-solver.cc)
17 | TARGET_LINK_LIBRARIES(dimacs-solver lemon)
18 |
19 | INSTALL(
20 | TARGETS lgf-gen dimacs-to-lgf dimacs-solver
21 | RUNTIME DESTINATION bin
22 | COMPONENT bin
23 | )
24 |
25 | IF(NOT WIN32)
26 | INSTALL(
27 | PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/lemon-0.x-to-1.x.sh
28 | DESTINATION bin
29 | COMPONENT bin
30 | )
31 | ENDIF()
32 |
--------------------------------------------------------------------------------
/doc/license.dox:
--------------------------------------------------------------------------------
1 | /* -*- mode: C++; indent-tabs-mode: nil; -*-
2 | *
3 | * This file is a part of LEMON, a generic C++ optimization library.
4 | *
5 | * Copyright (C) 2003-2009
6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 | * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 | *
9 | * Permission to use, modify and distribute this software is granted
10 | * provided that this copyright notice appears in all copies. For
11 | * precise terms see the accompanying LICENSE file.
12 | *
13 | * This software is provided "AS IS" with no warranty of any kind,
14 | * express or implied, and with no claim as to its suitability for any
15 | * purpose.
16 | *
17 | */
18 |
19 | /**
20 |
21 | \page license License Terms
22 |
23 | \verbinclude LICENSE
24 |
25 | */
26 |
--------------------------------------------------------------------------------
/doc/template.h:
--------------------------------------------------------------------------------
1 | /* -*- mode: C++; indent-tabs-mode: nil; -*-
2 | *
3 | * This file is a part of LEMON, a generic C++ optimization library.
4 | *
5 | * Copyright (C) 2003-2009
6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 | * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 | *
9 | * Permission to use, modify and distribute this software is granted
10 | * provided that this copyright notice appears in all copies. For
11 | * precise terms see the accompanying LICENSE file.
12 | *
13 | * This software is provided "AS IS" with no warranty of any kind,
14 | * express or implied, and with no claim as to its suitability for any
15 | * purpose.
16 | *
17 | */
18 |
19 | #ifndef LEMON_TEMPLATE_H
20 | #define LEMON_TEMPLATE_H
21 |
22 | #endif // LEMON_TEMPLATE_H
23 |
--------------------------------------------------------------------------------
/test/test_tools_pass.cc:
--------------------------------------------------------------------------------
1 | /* -*- mode: C++; indent-tabs-mode: nil; -*-
2 | *
3 | * This file is a part of LEMON, a generic C++ optimization library.
4 | *
5 | * Copyright (C) 2003-2009
6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 | * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 | *
9 | * Permission to use, modify and distribute this software is granted
10 | * provided that this copyright notice appears in all copies. For
11 | * precise terms see the accompanying LICENSE file.
12 | *
13 | * This software is provided "AS IS" with no warranty of any kind,
14 | * express or implied, and with no claim as to its suitability for any
15 | * purpose.
16 | *
17 | */
18 |
19 | #include "test_tools.h"
20 |
21 | int main()
22 | {
23 | check(true, "It should pass.");
24 | return 0;
25 | }
26 |
--------------------------------------------------------------------------------
/test/test_tools_fail.cc:
--------------------------------------------------------------------------------
1 | /* -*- mode: C++; indent-tabs-mode: nil; -*-
2 | *
3 | * This file is a part of LEMON, a generic C++ optimization library.
4 | *
5 | * Copyright (C) 2003-2009
6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 | * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 | *
9 | * Permission to use, modify and distribute this software is granted
10 | * provided that this copyright notice appears in all copies. For
11 | * precise terms see the accompanying LICENSE file.
12 | *
13 | * This software is provided "AS IS" with no warranty of any kind,
14 | * express or implied, and with no claim as to its suitability for any
15 | * purpose.
16 | *
17 | */
18 |
19 | #include "test_tools.h"
20 |
21 | int main()
22 | {
23 | check(false, "Don't panic. Failing is the right behaviour here.");
24 | return 0;
25 | }
26 |
--------------------------------------------------------------------------------
/lemon/random.cc:
--------------------------------------------------------------------------------
1 | /* -*- mode: C++; indent-tabs-mode: nil; -*-
2 | *
3 | * This file is a part of LEMON, a generic C++ optimization library.
4 | *
5 | * Copyright (C) 2003-2009
6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 | * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 | *
9 | * Permission to use, modify and distribute this software is granted
10 | * provided that this copyright notice appears in all copies. For
11 | * precise terms see the accompanying LICENSE file.
12 | *
13 | * This software is provided "AS IS" with no warranty of any kind,
14 | * express or implied, and with no claim as to its suitability for any
15 | * purpose.
16 | *
17 | */
18 |
19 | ///\file
20 | ///\brief Instantiation of the Random class.
21 |
22 | #include
23 |
24 | namespace lemon {
25 | /// \brief Global random number generator instance
26 | ///
27 | /// A global Mersenne Twister random number generator instance.
28 | Random rnd;
29 | }
30 |
--------------------------------------------------------------------------------
/doc/namespaces.dox:
--------------------------------------------------------------------------------
1 | /* -*- mode: C++; indent-tabs-mode: nil; -*-
2 | *
3 | * This file is a part of LEMON, a generic C++ optimization library.
4 | *
5 | * Copyright (C) 2003-2009
6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 | * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 | *
9 | * Permission to use, modify and distribute this software is granted
10 | * provided that this copyright notice appears in all copies. For
11 | * precise terms see the accompanying LICENSE file.
12 | *
13 | * This software is provided "AS IS" with no warranty of any kind,
14 | * express or implied, and with no claim as to its suitability for any
15 | * purpose.
16 | *
17 | */
18 |
19 | /// The namespace of LEMON
20 |
21 | /// The namespace of LEMON
22 | ///
23 | namespace lemon {
24 |
25 | /// The namespace of LEMON concepts and concept checking classes
26 |
27 | /// The namespace of LEMON concepts and concept checking classes
28 | ///
29 | namespace concepts {}
30 | }
31 |
--------------------------------------------------------------------------------
/AUTHORS:
--------------------------------------------------------------------------------
1 | The main developers of release series 1.x are
2 |
3 | * Balazs Dezso
4 | * Alpar Juttner
5 | * Peter Kovacs
6 | * Akos Ladanyi
7 |
8 | For more complete list of contributors, please visit the history of
9 | the LEMON source code repository: http://lemon.cs.elte.hu/hg/lemon
10 |
11 | Moreover, this version is heavily based on version 0.x of LEMON. Here
12 | is the list of people who contributed to those versions.
13 |
14 | * Mihaly Barasz
15 | * Johanna Becker
16 | * Attila Bernath
17 | * Balazs Dezso
18 | * Peter Hegyi
19 | * Alpar Juttner
20 | * Peter Kovacs
21 | * Akos Ladanyi
22 | * Marton Makai
23 | * Jacint Szabo
24 |
25 | Again, please visit the history of the old LEMON repository for more
26 | details: http://lemon.cs.elte.hu/hg/lemon-0.x
--------------------------------------------------------------------------------
/lemon/lp_base.cc:
--------------------------------------------------------------------------------
1 | /* -*- mode: C++; indent-tabs-mode: nil; -*-
2 | *
3 | * This file is a part of LEMON, a generic C++ optimization library.
4 | *
5 | * Copyright (C) 2003-2013
6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 | * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 | *
9 | * Permission to use, modify and distribute this software is granted
10 | * provided that this copyright notice appears in all copies. For
11 | * precise terms see the accompanying LICENSE file.
12 | *
13 | * This software is provided "AS IS" with no warranty of any kind,
14 | * express or implied, and with no claim as to its suitability for any
15 | * purpose.
16 | *
17 | */
18 |
19 | ///\file
20 | ///\brief The implementation of the LP solver interface.
21 |
22 | #include
23 | namespace lemon {
24 |
25 | const LpBase::Value LpBase::INF =
26 | std::numeric_limits::infinity();
27 | const LpBase::Value LpBase::NaN =
28 | std::numeric_limits::quiet_NaN();
29 |
30 | } //namespace lemon
31 |
--------------------------------------------------------------------------------
/lemon/base.cc:
--------------------------------------------------------------------------------
1 | /* -*- mode: C++; indent-tabs-mode: nil; -*-
2 | *
3 | * This file is a part of LEMON, a generic C++ optimization library.
4 | *
5 | * Copyright (C) 2003-2013
6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 | * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 | *
9 | * Permission to use, modify and distribute this software is granted
10 | * provided that this copyright notice appears in all copies. For
11 | * precise terms see the accompanying LICENSE file.
12 | *
13 | * This software is provided "AS IS" with no warranty of any kind,
14 | * express or implied, and with no claim as to its suitability for any
15 | * purpose.
16 | *
17 | */
18 |
19 | ///\file
20 | ///\brief Some basic non-inline functions and static global data.
21 |
22 | #include
23 | #include
24 | #include
25 | namespace lemon {
26 |
27 | float Tolerance::def_epsilon = static_cast(1e-4);
28 | double Tolerance::def_epsilon = 1e-10;
29 | long double Tolerance::def_epsilon = 1e-14;
30 |
31 | #ifndef LEMON_ONLY_TEMPLATES
32 | const Invalid INVALID = Invalid();
33 | #endif
34 |
35 | TimeStamp::Format TimeStamp::_format = TimeStamp::NORMAL;
36 |
37 | } //namespace lemon
38 |
--------------------------------------------------------------------------------
/test/random_test.cc:
--------------------------------------------------------------------------------
1 | /* -*- mode: C++; indent-tabs-mode: nil; -*-
2 | *
3 | * This file is a part of LEMON, a generic C++ optimization library.
4 | *
5 | * Copyright (C) 2003-2009
6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 | * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 | *
9 | * Permission to use, modify and distribute this software is granted
10 | * provided that this copyright notice appears in all copies. For
11 | * precise terms see the accompanying LICENSE file.
12 | *
13 | * This software is provided "AS IS" with no warranty of any kind,
14 | * express or implied, and with no claim as to its suitability for any
15 | * purpose.
16 | *
17 | */
18 |
19 | #include
20 | #include "test_tools.h"
21 |
22 | int seed_array[] = {1, 2};
23 |
24 | int main()
25 | {
26 | double a=lemon::rnd();
27 | check(a<1.0&&a>0.0,"This should be in [0,1)");
28 | a=lemon::rnd.gauss();
29 | a=lemon::rnd.gamma(3.45,0);
30 | a=lemon::rnd.gamma(4);
31 | //Does gamma work with integer k?
32 | a=lemon::rnd.gamma(4.0,0);
33 | a=lemon::rnd.poisson(.5);
34 |
35 | lemon::rnd.seed(100);
36 | lemon::rnd.seed(seed_array, seed_array +
37 | (sizeof(seed_array) / sizeof(seed_array[0])));
38 |
39 | return 0;
40 | }
41 |
--------------------------------------------------------------------------------
/lemon/bits/windows.h:
--------------------------------------------------------------------------------
1 | /* -*- mode: C++; indent-tabs-mode: nil; -*-
2 | *
3 | * This file is a part of LEMON, a generic C++ optimization library.
4 | *
5 | * Copyright (C) 2003-2013
6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 | * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 | *
9 | * Permission to use, modify and distribute this software is granted
10 | * provided that this copyright notice appears in all copies. For
11 | * precise terms see the accompanying LICENSE file.
12 | *
13 | * This software is provided "AS IS" with no warranty of any kind,
14 | * express or implied, and with no claim as to its suitability for any
15 | * purpose.
16 | *
17 | */
18 |
19 | #ifndef LEMON_BITS_WINDOWS_H
20 | #define LEMON_BITS_WINDOWS_H
21 |
22 | #include
23 |
24 | namespace lemon {
25 | namespace bits {
26 | void getWinProcTimes(double &rtime,
27 | double &utime, double &stime,
28 | double &cutime, double &cstime);
29 | std::string getWinFormattedDate();
30 | int getWinRndSeed();
31 |
32 | class WinLock {
33 | public:
34 | WinLock();
35 | ~WinLock();
36 | void lock();
37 | void unlock();
38 | private:
39 | void *_repr;
40 | };
41 | }
42 | }
43 |
44 | #endif
45 |
--------------------------------------------------------------------------------
/lemon/color.cc:
--------------------------------------------------------------------------------
1 | /* -*- mode: C++; indent-tabs-mode: nil; -*-
2 | *
3 | * This file is a part of LEMON, a generic C++ optimization library.
4 | *
5 | * Copyright (C) 2003-2009
6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 | * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 | *
9 | * Permission to use, modify and distribute this software is granted
10 | * provided that this copyright notice appears in all copies. For
11 | * precise terms see the accompanying LICENSE file.
12 | *
13 | * This software is provided "AS IS" with no warranty of any kind,
14 | * express or implied, and with no claim as to its suitability for any
15 | * purpose.
16 | *
17 | */
18 |
19 | ///\file
20 | ///\brief Color constants
21 |
22 | #include
23 |
24 | namespace lemon {
25 |
26 | const Color WHITE(1,1,1);
27 |
28 | const Color BLACK(0,0,0);
29 | const Color RED(1,0,0);
30 | const Color GREEN(0,1,0);
31 | const Color BLUE(0,0,1);
32 | const Color YELLOW(1,1,0);
33 | const Color MAGENTA(1,0,1);
34 | const Color CYAN(0,1,1);
35 |
36 | const Color GREY(0,0,0);
37 | const Color DARK_RED(.5,0,0);
38 | const Color DARK_GREEN(0,.5,0);
39 | const Color DARK_BLUE(0,0,.5);
40 | const Color DARK_YELLOW(.5,.5,0);
41 | const Color DARK_MAGENTA(.5,0,.5);
42 | const Color DARK_CYAN(0,.5,.5);
43 |
44 | } //namespace lemon
45 |
--------------------------------------------------------------------------------
/README:
--------------------------------------------------------------------------------
1 | =====================================================================
2 | LEMON - a Library for Efficient Modeling and Optimization in Networks
3 | =====================================================================
4 |
5 | LEMON is an open source library written in C++. It provides
6 | easy-to-use implementations of common data structures and algorithms
7 | in the area of optimization and helps implementing new ones. The main
8 | focus is on graphs and graph algorithms, thus it is especially
9 | suitable for solving design and optimization problems of
10 | telecommunication networks. To achieve wide usability its data
11 | structures and algorithms provide generic interfaces.
12 |
13 | Contents
14 | ========
15 |
16 | LICENSE
17 |
18 | Copying, distribution and modification conditions and terms.
19 |
20 | NEWS
21 |
22 | News and version history.
23 |
24 | INSTALL
25 |
26 | General building and installation instructions.
27 |
28 | lemon/
29 |
30 | Source code of LEMON library.
31 |
32 | doc/
33 |
34 | Documentation of LEMON. The starting page is doc/html/index.html.
35 |
36 | demo/
37 |
38 | Some example programs to make you easier to get familiar with LEMON.
39 |
40 | scripts/
41 |
42 | Scripts that make it easier to develop LEMON.
43 |
44 | test/
45 |
46 | Programs to check the integrity and correctness of LEMON.
47 |
48 | tools/
49 |
50 | Various utilities related to LEMON.
51 |
--------------------------------------------------------------------------------
/test/time_measure_test.cc:
--------------------------------------------------------------------------------
1 | /* -*- mode: C++; indent-tabs-mode: nil; -*-
2 | *
3 | * This file is a part of LEMON, a generic C++ optimization library.
4 | *
5 | * Copyright (C) 2003-2013
6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 | * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 | *
9 | * Permission to use, modify and distribute this software is granted
10 | * provided that this copyright notice appears in all copies. For
11 | * precise terms see the accompanying LICENSE file.
12 | *
13 | * This software is provided "AS IS" with no warranty of any kind,
14 | * express or implied, and with no claim as to its suitability for any
15 | * purpose.
16 | *
17 | */
18 |
19 | #include
20 | #include
21 |
22 | using namespace lemon;
23 |
24 | void f()
25 | {
26 | double d=0;
27 | for(int i=0;i<1000;i++)
28 | d+=0.1;
29 | }
30 |
31 | void g()
32 | {
33 | static Timer T;
34 |
35 | for(int i=0;i<1000;i++)
36 | {
37 | TimeStamp x(T);
38 | ::lemon::ignore_unused_variable_warning(x);
39 | }
40 | }
41 |
42 | int main()
43 | {
44 | Timer T;
45 | unsigned int n;
46 | for(n=0;T.realTime()<0.1;n++) ;
47 | std::cout << T << " (" << n << " time queries)\n";
48 |
49 | TimeStamp full;
50 | TimeStamp t;
51 | t=runningTimeTest(f,0.1,&n,&full);
52 | std::cout << t << " (" << n << " tests)\n";
53 | std::cout << "Total: " << full << "\n";
54 |
55 | t=runningTimeTest(g,0.1,&n,&full);
56 | std::cout << t << " (" << n << " tests)\n";
57 | std::cout << "Total: " << full << "\n";
58 |
59 | return 0;
60 | }
61 |
--------------------------------------------------------------------------------
/lemon/bits/lock.h:
--------------------------------------------------------------------------------
1 | /* -*- mode: C++; indent-tabs-mode: nil; -*-
2 | *
3 | * This file is a part of LEMON, a generic C++ optimization library.
4 | *
5 | * Copyright (C) 2003-2013
6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 | * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 | *
9 | * Permission to use, modify and distribute this software is granted
10 | * provided that this copyright notice appears in all copies. For
11 | * precise terms see the accompanying LICENSE file.
12 | *
13 | * This software is provided "AS IS" with no warranty of any kind,
14 | * express or implied, and with no claim as to its suitability for any
15 | * purpose.
16 | *
17 | */
18 |
19 | #ifndef LEMON_BITS_LOCK_H
20 | #define LEMON_BITS_LOCK_H
21 |
22 | #include
23 | #if defined(LEMON_USE_PTHREAD)
24 | #include
25 | #elif defined(LEMON_USE_WIN32_THREADS)
26 | #include
27 | #endif
28 |
29 | namespace lemon {
30 | namespace bits {
31 |
32 | #if defined(LEMON_USE_PTHREAD)
33 | class Lock {
34 | public:
35 | Lock() {
36 | pthread_mutex_init(&_lock, 0);
37 | }
38 | ~Lock() {
39 | pthread_mutex_destroy(&_lock);
40 | }
41 | void lock() {
42 | pthread_mutex_lock(&_lock);
43 | }
44 | void unlock() {
45 | pthread_mutex_unlock(&_lock);
46 | }
47 |
48 | private:
49 | pthread_mutex_t _lock;
50 | };
51 | #elif defined(LEMON_USE_WIN32_THREADS)
52 | class Lock : public WinLock {};
53 | #else
54 | class Lock {
55 | public:
56 | Lock() {}
57 | ~Lock() {}
58 | void lock() {}
59 | void unlock() {}
60 | };
61 | #endif
62 | }
63 | }
64 |
65 | #endif
66 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | LEMON code without an explicit copyright notice is covered by the following
2 | copyright/license.
3 |
4 | Copyright (C) 2003-2012 Egervary Jeno Kombinatorikus Optimalizalasi
5 | Kutatocsoport (Egervary Combinatorial Optimization Research Group,
6 | EGRES).
7 |
8 | ===========================================================================
9 | Boost Software License, Version 1.0
10 | ===========================================================================
11 |
12 | Permission is hereby granted, free of charge, to any person or organization
13 | obtaining a copy of the software and accompanying documentation covered by
14 | this license (the "Software") to use, reproduce, display, distribute,
15 | execute, and transmit the Software, and to prepare derivative works of the
16 | Software, and to permit third-parties to whom the Software is furnished to
17 | do so, all subject to the following:
18 |
19 | The copyright notices in the Software and this entire statement, including
20 | the above license grant, this restriction and the following disclaimer,
21 | must be included in all copies of the Software, in whole or in part, and
22 | all derivative works of the Software, unless such copies or derivative
23 | works are solely in the form of machine-executable object code generated by
24 | a source language processor.
25 |
26 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
29 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
30 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
31 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
32 | DEALINGS IN THE SOFTWARE.
33 |
--------------------------------------------------------------------------------
/test/arc_look_up_test.cc:
--------------------------------------------------------------------------------
1 | /* -*- mode: C++; indent-tabs-mode: nil; -*-
2 | *
3 | * This file is a part of LEMON, a generic C++ optimization library.
4 | *
5 | * Copyright (C) 2003-2013
6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 | * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 | *
9 | * Permission to use, modify and distribute this software is granted
10 | * provided that this copyright notice appears in all copies. For
11 | * precise terms see the accompanying LICENSE file.
12 | *
13 | * This software is provided "AS IS" with no warranty of any kind,
14 | * express or implied, and with no claim as to its suitability for any
15 | * purpose.
16 | *
17 | */
18 |
19 | #include
20 | #include "lemon/list_graph.h"
21 | #include "lemon/lgf_reader.h"
22 |
23 | #include "test_tools.h"
24 |
25 | using namespace lemon;
26 |
27 | const std::string lgf =
28 | "@nodes\n"
29 | "label\n"
30 | "0\n"
31 | "1\n"
32 | "2\n"
33 | "3\n"
34 | "4\n"
35 | "5\n"
36 | "6\n"
37 | "@arcs\n"
38 | "label\n"
39 | "5 6 0\n"
40 | "5 4 1\n"
41 | "4 6 2\n"
42 | "3 4 3\n"
43 | "3 4 4\n"
44 | "3 2 5\n"
45 | "3 5 6\n"
46 | "3 5 7\n"
47 | "3 5 8\n"
48 | "3 5 9\n"
49 | "2 4 10\n"
50 | "2 4 11\n"
51 | "2 4 12\n"
52 | "2 4 13\n"
53 | "1 2 14\n"
54 | "1 2 15\n"
55 | "1 0 16\n"
56 | "1 3 17\n"
57 | "1 3 18\n"
58 | "1 3 19\n"
59 | "1 3 20\n"
60 | "0 2 21\n"
61 | "0 2 22\n"
62 | "0 2 23\n"
63 | "0 2 24\n";
64 |
65 |
66 | int main() {
67 | ListDigraph graph;
68 | std::istringstream lgfs(lgf);
69 | DigraphReader(graph, lgfs).run();
70 |
71 | AllArcLookUp lookup(graph);
72 |
73 | int numArcs = countArcs(graph);
74 |
75 | int arcCnt = 0;
76 | for(ListDigraph::NodeIt n1(graph); n1 != INVALID; ++n1)
77 | for(ListDigraph::NodeIt n2(graph); n2 != INVALID; ++n2)
78 | for(ListDigraph::Arc a = lookup(n1, n2); a != INVALID;
79 | a = lookup(n1, n2, a))
80 | ++arcCnt;
81 | check(arcCnt==numArcs, "Wrong total number of arcs");
82 |
83 | return 0;
84 | }
85 |
--------------------------------------------------------------------------------
/test/test_tools.h:
--------------------------------------------------------------------------------
1 | /* -*- mode: C++; indent-tabs-mode: nil; -*-
2 | *
3 | * This file is a part of LEMON, a generic C++ optimization library.
4 | *
5 | * Copyright (C) 2003-2010
6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 | * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 | *
9 | * Permission to use, modify and distribute this software is granted
10 | * provided that this copyright notice appears in all copies. For
11 | * precise terms see the accompanying LICENSE file.
12 | *
13 | * This software is provided "AS IS" with no warranty of any kind,
14 | * express or implied, and with no claim as to its suitability for any
15 | * purpose.
16 | *
17 | */
18 |
19 | #ifndef LEMON_TEST_TEST_TOOLS_H
20 | #define LEMON_TEST_TEST_TOOLS_H
21 |
22 | ///\ingroup misc
23 | ///\file
24 | ///\brief Some utilities to write test programs.
25 |
26 | #include
27 | #include
28 |
29 | ///If \c rc is fail, writes an error message and exits.
30 |
31 | ///If \c rc is fail, writes an error message and exits.
32 | ///The error message contains the file name and the line number of the
33 | ///source code in a standard from, which makes it possible to go there
34 | ///using good source browsers like e.g. \c emacs.
35 | ///
36 | ///For example
37 | ///\code check(0==1,"This is obviously false.");\endcode will
38 | ///print something like this (and then exits).
39 | ///\verbatim file_name.cc:123: error: This is obviously false. \endverbatim
40 | #define check(rc, msg) \
41 | { \
42 | if(!(rc)) { \
43 | std::cerr << __FILE__ ":" << __LINE__ << ": error: " \
44 | << msg << std::endl; \
45 | abort(); \
46 | } else { } \
47 | } \
48 |
49 |
50 | #endif
51 |
--------------------------------------------------------------------------------
/lemon/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | INCLUDE_DIRECTORIES(
2 | ${PROJECT_SOURCE_DIR}
3 | ${PROJECT_BINARY_DIR}
4 | )
5 |
6 | CONFIGURE_FILE(
7 | ${CMAKE_CURRENT_SOURCE_DIR}/config.h.in
8 | ${CMAKE_CURRENT_BINARY_DIR}/config.h
9 | )
10 |
11 | CONFIGURE_FILE(
12 | ${CMAKE_CURRENT_SOURCE_DIR}/lemon.pc.in
13 | ${CMAKE_CURRENT_BINARY_DIR}/lemon.pc
14 | @ONLY
15 | )
16 |
17 | SET(LEMON_SOURCES
18 | arg_parser.cc
19 | base.cc
20 | color.cc
21 | lp_base.cc
22 | lp_skeleton.cc
23 | random.cc
24 | bits/windows.cc
25 | )
26 |
27 | IF(LEMON_HAVE_GLPK)
28 | SET(LEMON_SOURCES ${LEMON_SOURCES} glpk.cc)
29 | INCLUDE_DIRECTORIES(${GLPK_INCLUDE_DIRS})
30 | IF(WIN32)
31 | INSTALL(FILES ${GLPK_BIN_DIR}/glpk.dll DESTINATION bin)
32 | INSTALL(FILES ${GLPK_BIN_DIR}/libltdl3.dll DESTINATION bin)
33 | INSTALL(FILES ${GLPK_BIN_DIR}/zlib1.dll DESTINATION bin)
34 | ENDIF()
35 | ENDIF()
36 |
37 | IF(LEMON_HAVE_CPLEX)
38 | SET(LEMON_SOURCES ${LEMON_SOURCES} cplex.cc)
39 | INCLUDE_DIRECTORIES(${ILOG_INCLUDE_DIRS})
40 | ENDIF()
41 |
42 | IF(LEMON_HAVE_CLP)
43 | SET(LEMON_SOURCES ${LEMON_SOURCES} clp.cc)
44 | INCLUDE_DIRECTORIES(${COIN_INCLUDE_DIRS})
45 | ENDIF()
46 |
47 | IF(LEMON_HAVE_CBC)
48 | SET(LEMON_SOURCES ${LEMON_SOURCES} cbc.cc)
49 | INCLUDE_DIRECTORIES(${COIN_INCLUDE_DIRS})
50 | ENDIF()
51 |
52 | IF(LEMON_HAVE_SOPLEX)
53 | SET(LEMON_SOURCES ${LEMON_SOURCES} soplex.cc)
54 | INCLUDE_DIRECTORIES(${SOPLEX_INCLUDE_DIRS})
55 | ENDIF()
56 |
57 | ADD_LIBRARY(lemon ${LEMON_SOURCES})
58 |
59 | TARGET_LINK_LIBRARIES(lemon
60 | ${GLPK_LIBRARIES} ${COIN_LIBRARIES} ${ILOG_LIBRARIES} ${SOPLEX_LIBRARIES}
61 | )
62 |
63 | IF(UNIX)
64 | SET_TARGET_PROPERTIES(lemon PROPERTIES OUTPUT_NAME emon VERSION ${LEMON_VERSION} SOVERSION ${LEMON_VERSION})
65 | ENDIF()
66 |
67 | INSTALL(
68 | TARGETS lemon
69 | ARCHIVE DESTINATION lib
70 | LIBRARY DESTINATION lib
71 | COMPONENT library
72 | )
73 |
74 | INSTALL(
75 | DIRECTORY . bits concepts
76 | DESTINATION include/lemon
77 | COMPONENT headers
78 | FILES_MATCHING PATTERN "*.h"
79 | )
80 |
81 | INSTALL(
82 | FILES ${CMAKE_CURRENT_BINARY_DIR}/config.h
83 | DESTINATION include/lemon
84 | COMPONENT headers
85 | )
86 |
87 | INSTALL(
88 | FILES ${CMAKE_CURRENT_BINARY_DIR}/lemon.pc
89 | DESTINATION lib/pkgconfig
90 | )
91 |
92 |
--------------------------------------------------------------------------------
/doc/images/nodeshape_0.eps:
--------------------------------------------------------------------------------
1 | %!PS-Adobe-2.0 EPSF-2.0
2 | %%Title: LEMON GraphToEps figure
3 | %%Creator: LEMON GraphToEps function
4 | %%BoundingBox: 0 0 200 200
5 | %%EndComments
6 | /lb { setlinewidth setrgbcolor newpath moveto
7 | 4 2 roll 1 index 1 index curveto stroke } bind def
8 | /l { setlinewidth setrgbcolor newpath moveto lineto stroke } bind def
9 | /c { newpath dup 3 index add 2 index moveto 0 360 arc closepath } bind def
10 | /sq { newpath 2 index 1 index add 2 index 2 index add moveto
11 | 2 index 1 index sub 2 index 2 index add lineto
12 | 2 index 1 index sub 2 index 2 index sub lineto
13 | 2 index 1 index add 2 index 2 index sub lineto
14 | closepath pop pop pop} bind def
15 | /di { newpath 2 index 1 index add 2 index moveto
16 | 2 index 2 index 2 index add lineto
17 | 2 index 1 index sub 2 index lineto
18 | 2 index 2 index 2 index sub lineto
19 | closepath pop pop pop} bind def
20 | /nc { 0 0 0 setrgbcolor 5 index 5 index 5 index c fill
21 | setrgbcolor 1.1 div c fill
22 | } bind def
23 | /nsq { 0 0 0 setrgbcolor 5 index 5 index 5 index sq fill
24 | setrgbcolor 1.1 div sq fill
25 | } bind def
26 | /ndi { 0 0 0 setrgbcolor 5 index 5 index 5 index di fill
27 | setrgbcolor 1.1 div di fill
28 | } bind def
29 | /arrl 1 def
30 | /arrw 0.3 def
31 | /lrl { 2 index mul exch 2 index mul exch rlineto pop} bind def
32 | /arr { setrgbcolor /y1 exch def /x1 exch def /dy exch def /dx exch def
33 | /w exch def /len exch def
34 | newpath x1 dy w 2 div mul add y1 dx w 2 div mul sub moveto
35 | len w sub arrl sub dx dy lrl
36 | arrw dy dx neg lrl
37 | dx arrl w add mul dy w 2 div arrw add mul sub
38 | dy arrl w add mul dx w 2 div arrw add mul add rlineto
39 | dx arrl w add mul neg dy w 2 div arrw add mul sub
40 | dy arrl w add mul neg dx w 2 div arrw add mul add rlineto
41 | arrw dy dx neg lrl
42 | len w sub arrl sub neg dx dy lrl
43 | closepath fill } bind def
44 | /cshow { 2 index 2 index moveto dup stringwidth pop
45 | neg 2 div fosi .35 mul neg rmoveto show pop pop} def
46 |
47 | gsave
48 | 100 dup scale
49 | %Edges:
50 | gsave
51 | grestore
52 | %Nodes:
53 | gsave
54 | 1 1 1 0.2 1 0.2 nc
55 | grestore
56 | grestore
57 | showpage
58 |
--------------------------------------------------------------------------------
/doc/images/nodeshape_1.eps:
--------------------------------------------------------------------------------
1 | %!PS-Adobe-2.0 EPSF-2.0
2 | %%Title: LEMON GraphToEps figure
3 | %%Creator: LEMON GraphToEps function
4 | %%BoundingBox: 0 0 200 200
5 | %%EndComments
6 | /lb { setlinewidth setrgbcolor newpath moveto
7 | 4 2 roll 1 index 1 index curveto stroke } bind def
8 | /l { setlinewidth setrgbcolor newpath moveto lineto stroke } bind def
9 | /c { newpath dup 3 index add 2 index moveto 0 360 arc closepath } bind def
10 | /sq { newpath 2 index 1 index add 2 index 2 index add moveto
11 | 2 index 1 index sub 2 index 2 index add lineto
12 | 2 index 1 index sub 2 index 2 index sub lineto
13 | 2 index 1 index add 2 index 2 index sub lineto
14 | closepath pop pop pop} bind def
15 | /di { newpath 2 index 1 index add 2 index moveto
16 | 2 index 2 index 2 index add lineto
17 | 2 index 1 index sub 2 index lineto
18 | 2 index 2 index 2 index sub lineto
19 | closepath pop pop pop} bind def
20 | /nc { 0 0 0 setrgbcolor 5 index 5 index 5 index c fill
21 | setrgbcolor 1.1 div c fill
22 | } bind def
23 | /nsq { 0 0 0 setrgbcolor 5 index 5 index 5 index sq fill
24 | setrgbcolor 1.1 div sq fill
25 | } bind def
26 | /ndi { 0 0 0 setrgbcolor 5 index 5 index 5 index di fill
27 | setrgbcolor 1.1 div di fill
28 | } bind def
29 | /arrl 1 def
30 | /arrw 0.3 def
31 | /lrl { 2 index mul exch 2 index mul exch rlineto pop} bind def
32 | /arr { setrgbcolor /y1 exch def /x1 exch def /dy exch def /dx exch def
33 | /w exch def /len exch def
34 | newpath x1 dy w 2 div mul add y1 dx w 2 div mul sub moveto
35 | len w sub arrl sub dx dy lrl
36 | arrw dy dx neg lrl
37 | dx arrl w add mul dy w 2 div arrw add mul sub
38 | dy arrl w add mul dx w 2 div arrw add mul add rlineto
39 | dx arrl w add mul neg dy w 2 div arrw add mul sub
40 | dy arrl w add mul neg dx w 2 div arrw add mul add rlineto
41 | arrw dy dx neg lrl
42 | len w sub arrl sub neg dx dy lrl
43 | closepath fill } bind def
44 | /cshow { 2 index 2 index moveto dup stringwidth pop
45 | neg 2 div fosi .35 mul neg rmoveto show pop pop} def
46 |
47 | gsave
48 | 100 dup scale
49 | %Edges:
50 | gsave
51 | grestore
52 | %Nodes:
53 | gsave
54 | 1 1 1 0.2 1 0.2 nsq
55 | grestore
56 | grestore
57 | showpage
58 |
--------------------------------------------------------------------------------
/doc/images/nodeshape_2.eps:
--------------------------------------------------------------------------------
1 | %!PS-Adobe-2.0 EPSF-2.0
2 | %%Title: LEMON GraphToEps figure
3 | %%Creator: LEMON GraphToEps function
4 | %%BoundingBox: 0 0 200 200
5 | %%EndComments
6 | /lb { setlinewidth setrgbcolor newpath moveto
7 | 4 2 roll 1 index 1 index curveto stroke } bind def
8 | /l { setlinewidth setrgbcolor newpath moveto lineto stroke } bind def
9 | /c { newpath dup 3 index add 2 index moveto 0 360 arc closepath } bind def
10 | /sq { newpath 2 index 1 index add 2 index 2 index add moveto
11 | 2 index 1 index sub 2 index 2 index add lineto
12 | 2 index 1 index sub 2 index 2 index sub lineto
13 | 2 index 1 index add 2 index 2 index sub lineto
14 | closepath pop pop pop} bind def
15 | /di { newpath 2 index 1 index add 2 index moveto
16 | 2 index 2 index 2 index add lineto
17 | 2 index 1 index sub 2 index lineto
18 | 2 index 2 index 2 index sub lineto
19 | closepath pop pop pop} bind def
20 | /nc { 0 0 0 setrgbcolor 5 index 5 index 5 index c fill
21 | setrgbcolor 1.1 div c fill
22 | } bind def
23 | /nsq { 0 0 0 setrgbcolor 5 index 5 index 5 index sq fill
24 | setrgbcolor 1.1 div sq fill
25 | } bind def
26 | /ndi { 0 0 0 setrgbcolor 5 index 5 index 5 index di fill
27 | setrgbcolor 1.1 div di fill
28 | } bind def
29 | /arrl 1 def
30 | /arrw 0.3 def
31 | /lrl { 2 index mul exch 2 index mul exch rlineto pop} bind def
32 | /arr { setrgbcolor /y1 exch def /x1 exch def /dy exch def /dx exch def
33 | /w exch def /len exch def
34 | newpath x1 dy w 2 div mul add y1 dx w 2 div mul sub moveto
35 | len w sub arrl sub dx dy lrl
36 | arrw dy dx neg lrl
37 | dx arrl w add mul dy w 2 div arrw add mul sub
38 | dy arrl w add mul dx w 2 div arrw add mul add rlineto
39 | dx arrl w add mul neg dy w 2 div arrw add mul sub
40 | dy arrl w add mul neg dx w 2 div arrw add mul add rlineto
41 | arrw dy dx neg lrl
42 | len w sub arrl sub neg dx dy lrl
43 | closepath fill } bind def
44 | /cshow { 2 index 2 index moveto dup stringwidth pop
45 | neg 2 div fosi .35 mul neg rmoveto show pop pop} def
46 |
47 | gsave
48 | 100 dup scale
49 | %Edges:
50 | gsave
51 | grestore
52 | %Nodes:
53 | gsave
54 | 1 1 1 0.2 1 0.2 ndi
55 | grestore
56 | grestore
57 | showpage
58 |
--------------------------------------------------------------------------------
/cmake/FindGLPK.cmake:
--------------------------------------------------------------------------------
1 | SET(GLPK_ROOT_DIR "" CACHE PATH "GLPK root directory")
2 |
3 | SET(GLPK_REGKEY "[HKEY_LOCAL_MACHINE\\SOFTWARE\\GnuWin32\\Glpk;InstallPath]")
4 | GET_FILENAME_COMPONENT(GLPK_ROOT_PATH ${GLPK_REGKEY} ABSOLUTE)
5 |
6 | FIND_PATH(GLPK_INCLUDE_DIR
7 | glpk.h
8 | PATHS ${GLPK_REGKEY}/include
9 | HINTS ${GLPK_ROOT_DIR}/include
10 | )
11 | FIND_LIBRARY(GLPK_LIBRARY
12 | glpk
13 | PATHS ${GLPK_REGKEY}/lib
14 | HINTS ${GLPK_ROOT_DIR}/lib
15 | )
16 |
17 | IF(GLPK_INCLUDE_DIR AND GLPK_LIBRARY)
18 | FILE(READ ${GLPK_INCLUDE_DIR}/glpk.h GLPK_GLPK_H)
19 |
20 | STRING(REGEX MATCH "define[ ]+GLP_MAJOR_VERSION[ ]+[0-9]+" GLPK_MAJOR_VERSION_LINE "${GLPK_GLPK_H}")
21 | STRING(REGEX REPLACE "define[ ]+GLP_MAJOR_VERSION[ ]+([0-9]+)" "\\1" GLPK_VERSION_MAJOR "${GLPK_MAJOR_VERSION_LINE}")
22 |
23 | STRING(REGEX MATCH "define[ ]+GLP_MINOR_VERSION[ ]+[0-9]+" GLPK_MINOR_VERSION_LINE "${GLPK_GLPK_H}")
24 | STRING(REGEX REPLACE "define[ ]+GLP_MINOR_VERSION[ ]+([0-9]+)" "\\1" GLPK_VERSION_MINOR "${GLPK_MINOR_VERSION_LINE}")
25 |
26 | SET(GLPK_VERSION_STRING "${GLPK_VERSION_MAJOR}.${GLPK_VERSION_MINOR}")
27 |
28 | IF(GLPK_FIND_VERSION)
29 | IF(GLPK_FIND_VERSION_COUNT GREATER 2)
30 | MESSAGE(SEND_ERROR "unexpected version string")
31 | ENDIF(GLPK_FIND_VERSION_COUNT GREATER 2)
32 |
33 | MATH(EXPR GLPK_REQUESTED_VERSION "${GLPK_FIND_VERSION_MAJOR}*100 + ${GLPK_FIND_VERSION_MINOR}")
34 | MATH(EXPR GLPK_FOUND_VERSION "${GLPK_VERSION_MAJOR}*100 + ${GLPK_VERSION_MINOR}")
35 |
36 | IF(GLPK_FOUND_VERSION LESS GLPK_REQUESTED_VERSION)
37 | SET(GLPK_PROPER_VERSION_FOUND FALSE)
38 | ELSE(GLPK_FOUND_VERSION LESS GLPK_REQUESTED_VERSION)
39 | SET(GLPK_PROPER_VERSION_FOUND TRUE)
40 | ENDIF(GLPK_FOUND_VERSION LESS GLPK_REQUESTED_VERSION)
41 | ELSE(GLPK_FIND_VERSION)
42 | SET(GLPK_PROPER_VERSION_FOUND TRUE)
43 | ENDIF(GLPK_FIND_VERSION)
44 | ENDIF(GLPK_INCLUDE_DIR AND GLPK_LIBRARY)
45 |
46 | INCLUDE(FindPackageHandleStandardArgs)
47 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(GLPK DEFAULT_MSG GLPK_LIBRARY GLPK_INCLUDE_DIR GLPK_PROPER_VERSION_FOUND)
48 |
49 | IF(GLPK_FOUND)
50 | SET(GLPK_INCLUDE_DIRS ${GLPK_INCLUDE_DIR})
51 | SET(GLPK_LIBRARIES ${GLPK_LIBRARY})
52 | SET(GLPK_BIN_DIR ${GLPK_ROOT_PATH}/bin)
53 | ENDIF(GLPK_FOUND)
54 |
55 | MARK_AS_ADVANCED(GLPK_LIBRARY GLPK_INCLUDE_DIR GLPK_BIN_DIR)
56 |
--------------------------------------------------------------------------------
/test/error_test.cc:
--------------------------------------------------------------------------------
1 | /* -*- mode: C++; indent-tabs-mode: nil; -*-
2 | *
3 | * This file is a part of LEMON, a generic C++ optimization library.
4 | *
5 | * Copyright (C) 2003-2009
6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 | * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 | *
9 | * Permission to use, modify and distribute this software is granted
10 | * provided that this copyright notice appears in all copies. For
11 | * precise terms see the accompanying LICENSE file.
12 | *
13 | * This software is provided "AS IS" with no warranty of any kind,
14 | * express or implied, and with no claim as to its suitability for any
15 | * purpose.
16 | *
17 | */
18 |
19 | #include
20 |
21 | #include
22 | #include "test_tools.h"
23 |
24 | using namespace lemon;
25 |
26 | #ifdef LEMON_ENABLE_ASSERTS
27 | #undef LEMON_ENABLE_ASSERTS
28 | #endif
29 |
30 | #ifdef LEMON_DISABLE_ASSERTS
31 | #undef LEMON_DISABLE_ASSERTS
32 | #endif
33 |
34 | #ifdef NDEBUG
35 | #undef NDEBUG
36 | #endif
37 |
38 | //checking disabled asserts
39 | #define LEMON_DISABLE_ASSERTS
40 | #include
41 |
42 | void no_assertion_text_disable() {
43 | LEMON_ASSERT(true, "This is a fault message");
44 | }
45 |
46 | void assertion_text_disable() {
47 | LEMON_ASSERT(false, "This is a fault message");
48 | }
49 |
50 | void check_assertion_disable() {
51 | no_assertion_text_disable();
52 | assertion_text_disable();
53 | }
54 | #undef LEMON_DISABLE_ASSERTS
55 |
56 | //checking custom assert handler
57 | #define LEMON_ASSERT_CUSTOM
58 |
59 | static int cnt = 0;
60 | void my_assert_handler(const char*, int, const char*,
61 | const char*, const char*) {
62 | ++cnt;
63 | }
64 |
65 | #define LEMON_CUSTOM_ASSERT_HANDLER my_assert_handler
66 | #include
67 |
68 | void no_assertion_text_custom() {
69 | LEMON_ASSERT(true, "This is a fault message");
70 | }
71 |
72 | void assertion_text_custom() {
73 | LEMON_ASSERT(false, "This is a fault message");
74 | }
75 |
76 | void check_assertion_custom() {
77 | no_assertion_text_custom();
78 | assertion_text_custom();
79 | check(cnt == 1, "The custom assert handler does not work");
80 | }
81 |
82 | #undef LEMON_ASSERT_CUSTOM
83 |
84 |
85 | int main() {
86 | check_assertion_disable();
87 | check_assertion_custom();
88 |
89 | return 0;
90 | }
91 |
--------------------------------------------------------------------------------
/demo/lgf_demo.cc:
--------------------------------------------------------------------------------
1 | /* -*- mode: C++; indent-tabs-mode: nil; -*-
2 | *
3 | * This file is a part of LEMON, a generic C++ optimization library.
4 | *
5 | * Copyright (C) 2003-2009
6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 | * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 | *
9 | * Permission to use, modify and distribute this software is granted
10 | * provided that this copyright notice appears in all copies. For
11 | * precise terms see the accompanying LICENSE file.
12 | *
13 | * This software is provided "AS IS" with no warranty of any kind,
14 | * express or implied, and with no claim as to its suitability for any
15 | * purpose.
16 | *
17 | */
18 |
19 | ///\ingroup demos
20 | ///\file
21 | ///\brief Demonstrating graph input and output
22 | ///
23 | /// This program gives an example of how to read and write a digraph
24 | /// and additional maps from/to a stream or a file using the
25 | /// \ref lgf-format "LGF" format.
26 | ///
27 | /// The \c "digraph.lgf" file:
28 | /// \include digraph.lgf
29 | ///
30 | /// And the program which reads it and prints the digraph to the
31 | /// standard output:
32 | /// \include lgf_demo.cc
33 |
34 | #include
35 | #include
36 | #include
37 | #include
38 |
39 | using namespace lemon;
40 |
41 | int main() {
42 | SmartDigraph g;
43 | SmartDigraph::ArcMap cap(g);
44 | SmartDigraph::Node s, t;
45 |
46 | try {
47 | digraphReader(g, "digraph.lgf"). // read the directed graph into g
48 | arcMap("capacity", cap). // read the 'capacity' arc map into cap
49 | node("source", s). // read 'source' node to s
50 | node("target", t). // read 'target' node to t
51 | run();
52 | } catch (Exception& error) { // check if there was any error
53 | std::cerr << "Error: " << error.what() << std::endl;
54 | return -1;
55 | }
56 |
57 | std::cout << "A digraph is read from 'digraph.lgf'." << std::endl;
58 | std::cout << "Number of nodes: " << countNodes(g) << std::endl;
59 | std::cout << "Number of arcs: " << countArcs(g) << std::endl;
60 |
61 | std::cout << "We can write it to the standard output:" << std::endl;
62 |
63 | digraphWriter(g). // write g to the standard output
64 | arcMap("capacity", cap). // write cap into 'capacity'
65 | node("source", s). // write s to 'source'
66 | node("target", t). // write t to 'target'
67 | run();
68 |
69 | return 0;
70 | }
71 |
--------------------------------------------------------------------------------
/doc/mainpage.dox.in:
--------------------------------------------------------------------------------
1 | /* -*- mode: C++; indent-tabs-mode: nil; -*-
2 | *
3 | * This file is a part of LEMON, a generic C++ optimization library.
4 | *
5 | * Copyright (C) 2003-2010
6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 | * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 | *
9 | * Permission to use, modify and distribute this software is granted
10 | * provided that this copyright notice appears in all copies. For
11 | * precise terms see the accompanying LICENSE file.
12 | *
13 | * This software is provided "AS IS" with no warranty of any kind,
14 | * express or implied, and with no claim as to its suitability for any
15 | * purpose.
16 | *
17 | */
18 |
19 | /**
20 | \mainpage @PACKAGE_NAME@ @PACKAGE_VERSION@ Documentation
21 |
22 | \section intro Introduction
23 |
24 | LEMON stands for Library for Efficient Modeling
25 | and Optimization in Networks.
26 | It is a C++ template library providing efficient implementations of common
27 | data structures and algorithms with focus on combinatorial optimization
28 | tasks connected mainly with graphs and networks \cite DezsoJuttnerKovacs11Lemon.
29 |
30 |
31 | LEMON is an open source
32 | project.
33 | You are free to use it in your commercial or
34 | non-commercial applications under very permissive
35 | \ref license "license terms".
36 |
37 |
38 | The project is maintained by the
39 | Egerváry Research Group on
40 | Combinatorial Optimization \cite egres
41 | at the Operations Research Department of the
42 | Eötvös Loránd University,
43 | Budapest, Hungary.
44 | LEMON is also a member of the COIN-OR
45 | initiative \cite coinor.
46 |
47 | \section howtoread How to Read the Documentation
48 |
49 | If you would like to get to know the library, see
50 | LEMON Tutorial.
51 |
52 | If you are interested in starting to use the library, see the Installation
54 | Guide.
55 |
56 | If you know what you are looking for, then try to find it under the
57 | Modules section.
58 |
59 | If you are a user of the old (0.x) series of LEMON, please check out the
60 | \ref migration "Migration Guide" for the backward incompatibilities.
61 | */
62 |
--------------------------------------------------------------------------------
/lemon/math.h:
--------------------------------------------------------------------------------
1 | /* -*- mode: C++; indent-tabs-mode: nil; -*-
2 | *
3 | * This file is a part of LEMON, a generic C++ optimization library.
4 | *
5 | * Copyright (C) 2003-2013
6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 | * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 | *
9 | * Permission to use, modify and distribute this software is granted
10 | * provided that this copyright notice appears in all copies. For
11 | * precise terms see the accompanying LICENSE file.
12 | *
13 | * This software is provided "AS IS" with no warranty of any kind,
14 | * express or implied, and with no claim as to its suitability for any
15 | * purpose.
16 | *
17 | */
18 |
19 | #ifndef LEMON_MATH_H
20 | #define LEMON_MATH_H
21 |
22 | ///\ingroup misc
23 | ///\file
24 | ///\brief Some extensions to the standard \c cmath library.
25 | ///
26 | ///Some extensions to the standard \c cmath library.
27 | ///
28 | ///This file includes the standard math library (cmath).
29 |
30 | #include
31 |
32 | namespace lemon {
33 |
34 | /// \addtogroup misc
35 | /// @{
36 |
37 | /// The Euler constant
38 | const long double E = 2.7182818284590452353602874713526625L;
39 | /// log_2(e)
40 | const long double LOG2E = 1.4426950408889634073599246810018921L;
41 | /// log_10(e)
42 | const long double LOG10E = 0.4342944819032518276511289189166051L;
43 | /// ln(2)
44 | const long double LN2 = 0.6931471805599453094172321214581766L;
45 | /// ln(10)
46 | const long double LN10 = 2.3025850929940456840179914546843642L;
47 | /// pi
48 | const long double PI = 3.1415926535897932384626433832795029L;
49 | /// pi/2
50 | const long double PI_2 = 1.5707963267948966192313216916397514L;
51 | /// pi/4
52 | const long double PI_4 = 0.7853981633974483096156608458198757L;
53 | /// sqrt(2)
54 | const long double SQRT2 = 1.4142135623730950488016887242096981L;
55 | /// 1/sqrt(2)
56 | const long double SQRT1_2 = 0.7071067811865475244008443621048490L;
57 |
58 | ///Check whether the parameter is NaN or not
59 |
60 | ///This function checks whether the parameter is NaN or not.
61 | ///Is should be equivalent with std::isnan(), but it is not
62 | ///provided by all compilers.
63 | inline bool isNaN(double v)
64 | {
65 | return v!=v;
66 | }
67 |
68 | ///Round a value to its closest integer
69 | inline double round(double r) {
70 | return (r > 0.0) ? std::floor(r + 0.5) : std::ceil(r - 0.5);
71 | }
72 |
73 | /// @}
74 |
75 | } //namespace lemon
76 |
77 | #endif //LEMON_MATH_H
78 |
--------------------------------------------------------------------------------
/doc/dirs.dox:
--------------------------------------------------------------------------------
1 | /* -*- mode: C++; indent-tabs-mode: nil; -*-
2 | *
3 | * This file is a part of LEMON, a generic C++ optimization library.
4 | *
5 | * Copyright (C) 2003-2013
6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 | * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 | *
9 | * Permission to use, modify and distribute this software is granted
10 | * provided that this copyright notice appears in all copies. For
11 | * precise terms see the accompanying LICENSE file.
12 | *
13 | * This software is provided "AS IS" with no warranty of any kind,
14 | * express or implied, and with no claim as to its suitability for any
15 | * purpose.
16 | *
17 | */
18 |
19 | /**
20 | \dir demo
21 | \brief A collection of demo applications.
22 |
23 | This directory contains several simple demo applications, mainly
24 | for educational purposes.
25 | */
26 |
27 | /**
28 | \dir doc
29 | \brief Auxiliary (and the whole generated) documentation.
30 |
31 | This directory contains some auxiliary pages and the whole generated
32 | documentation.
33 | */
34 |
35 | /**
36 | \dir contrib
37 | \brief Directory for user contributed source codes.
38 |
39 | You can place your own C++ code using LEMON into this directory, which
40 | will compile to an executable along with LEMON when you build the
41 | library. This is probably the easiest way of compiling short to medium
42 | codes, for this does require neither a LEMON installed system-wide nor
43 | adding several paths to the compiler.
44 |
45 | Please have a look at contrib/CMakeLists.txt for
46 | instruction on how to add your own files into the build process. */
47 |
48 | /**
49 | \dir test
50 | \brief Test programs.
51 |
52 | This directory contains several test programs that check the consistency
53 | of the code.
54 | */
55 |
56 | /**
57 | \dir tools
58 | \brief Some useful executables.
59 |
60 | This directory contains the sources of some useful complete executables.
61 | */
62 |
63 | /**
64 | \dir lemon
65 | \brief Base include directory of LEMON.
66 |
67 | This is the base directory of LEMON includes, so each include file must be
68 | prefixed with this, e.g.
69 | \code
70 | #include
71 | #include
72 | \endcode
73 | */
74 |
75 | /**
76 | \dir concepts
77 | \brief Concept descriptors and checking classes.
78 |
79 | This directory contains the concept descriptors and concept checking tools.
80 | For more information see the \ref concept "Concepts" module.
81 | */
82 |
83 | /**
84 | \dir bits
85 | \brief Auxiliary tools for implementation.
86 |
87 | This directory contains some auxiliary classes for implementing graphs,
88 | maps and some other classes.
89 | As a user you typically don't have to deal with these files.
90 | */
91 |
--------------------------------------------------------------------------------
/lemon/lp.h:
--------------------------------------------------------------------------------
1 | /* -*- mode: C++; indent-tabs-mode: nil; -*-
2 | *
3 | * This file is a part of LEMON, a generic C++ optimization library.
4 | *
5 | * Copyright (C) 2003-2013
6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 | * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 | *
9 | * Permission to use, modify and distribute this software is granted
10 | * provided that this copyright notice appears in all copies. For
11 | * precise terms see the accompanying LICENSE file.
12 | *
13 | * This software is provided "AS IS" with no warranty of any kind,
14 | * express or implied, and with no claim as to its suitability for any
15 | * purpose.
16 | *
17 | */
18 |
19 | #ifndef LEMON_LP_H
20 | #define LEMON_LP_H
21 |
22 | #include
23 |
24 |
25 | #ifdef LEMON_HAVE_GLPK
26 | #include
27 | #elif LEMON_HAVE_CPLEX
28 | #include
29 | #elif LEMON_HAVE_SOPLEX
30 | #include
31 | #elif LEMON_HAVE_CLP
32 | #include
33 | #elif LEMON_HAVE_CBC
34 | #include
35 | #endif
36 |
37 | ///\file
38 | ///\brief Defines a default LP solver
39 | ///\ingroup lp_group
40 | namespace lemon {
41 |
42 | #ifdef DOXYGEN
43 | ///The default LP solver identifier
44 |
45 | ///The default LP solver identifier.
46 | ///\ingroup lp_group
47 | ///
48 | ///Currently, the possible values are \c _LEMON_GLPK, \c LEMON__CPLEX,
49 | ///\c _LEMON_SOPLEX or \c LEMON__CLP
50 | #define LEMON_DEFAULT_LP SOLVER
51 | ///The default LP solver
52 |
53 | ///The default LP solver.
54 | ///\ingroup lp_group
55 | ///
56 | ///Currently, it is either \c GlpkLp, \c CplexLp, \c SoplexLp or \c ClpLp
57 | typedef GlpkLp Lp;
58 |
59 | ///The default MIP solver identifier
60 |
61 | ///The default MIP solver identifier.
62 | ///\ingroup lp_group
63 | ///
64 | ///Currently, the possible values are \c _LEMON_GLPK, \c LEMON__CPLEX
65 | ///or \c _LEMON_CBC
66 | #define LEMON_DEFAULT_MIP SOLVER
67 | ///The default MIP solver.
68 |
69 | ///The default MIP solver.
70 | ///\ingroup lp_group
71 | ///
72 | ///Currently, it is either \c GlpkMip, \c CplexMip , \c CbcMip
73 | typedef GlpkMip Mip;
74 | #else
75 | #if LEMON_DEFAULT_LP == _LEMON_GLPK
76 | typedef GlpkLp Lp;
77 | #elif LEMON_DEFAULT_LP == _LEMON_CPLEX
78 | typedef CplexLp Lp;
79 | #elif LEMON_DEFAULT_LP == _LEMON_SOPLEX
80 | typedef SoplexLp Lp;
81 | #elif LEMON_DEFAULT_LP == _LEMON_CLP
82 | typedef ClpLp Lp;
83 | #endif
84 | #if LEMON_DEFAULT_MIP == _LEMON_GLPK
85 | typedef GlpkMip Mip;
86 | #elif LEMON_DEFAULT_MIP == _LEMON_CPLEX
87 | typedef CplexMip Mip;
88 | #elif LEMON_DEFAULT_MIP == _LEMON_CBC
89 | typedef CbcMip Mip;
90 | #endif
91 | #endif
92 |
93 | } //namespace lemon
94 |
95 | #endif //LEMON_LP_H
96 |
--------------------------------------------------------------------------------
/test/dim_test.cc:
--------------------------------------------------------------------------------
1 | /* -*- mode: C++; indent-tabs-mode: nil; -*-
2 | *
3 | * This file is a part of LEMON, a generic C++ optimization library.
4 | *
5 | * Copyright (C) 2003-2009
6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 | * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 | *
9 | * Permission to use, modify and distribute this software is granted
10 | * provided that this copyright notice appears in all copies. For
11 | * precise terms see the accompanying LICENSE file.
12 | *
13 | * This software is provided "AS IS" with no warranty of any kind,
14 | * express or implied, and with no claim as to its suitability for any
15 | * purpose.
16 | *
17 | */
18 |
19 | #include
20 | #include
21 | #include "test_tools.h"
22 |
23 | using namespace std;
24 | using namespace lemon;
25 |
26 | int main()
27 | {
28 | typedef dim2::Point Point;
29 |
30 | Point p;
31 | check(p.size()==2, "Wrong dim2::Point initialization.");
32 |
33 | Point a(1,2);
34 | Point b(3,4);
35 | check(a[0]==1 && a[1]==2, "Wrong dim2::Point initialization.");
36 |
37 | p = a+b;
38 | check(p.x==4 && p.y==6, "Wrong dim2::Point addition.");
39 |
40 | p = a-b;
41 | check(p.x==-2 && p.y==-2, "Wrong dim2::Point subtraction.");
42 |
43 | check(a.normSquare()==5,"Wrong dim2::Point norm calculation.");
44 | check(a*b==11, "Wrong dim2::Point scalar product.");
45 |
46 | int l=2;
47 | p = a*l;
48 | check(p.x==2 && p.y==4, "Wrong dim2::Point multiplication by a scalar.");
49 |
50 | p = b/l;
51 | check(p.x==1 && p.y==2, "Wrong dim2::Point division by a scalar.");
52 |
53 | typedef dim2::Box Box;
54 | Box box1;
55 | check(box1.empty(), "Wrong empty() in dim2::Box.");
56 |
57 | box1.add(a);
58 | check(!box1.empty(), "Wrong empty() in dim2::Box.");
59 | box1.add(b);
60 |
61 | check(box1.left()==1 && box1.bottom()==2 &&
62 | box1.right()==3 && box1.top()==4,
63 | "Wrong addition of points to dim2::Box.");
64 |
65 | check(box1.inside(Point(2,3)), "Wrong inside() in dim2::Box.");
66 | check(box1.inside(Point(1,3)), "Wrong inside() in dim2::Box.");
67 | check(!box1.inside(Point(0,3)), "Wrong inside() in dim2::Box.");
68 |
69 | Box box2(Point(2,2));
70 | check(!box2.empty(), "Wrong empty() in dim2::Box.");
71 |
72 | box2.bottomLeft(Point(2,0));
73 | box2.topRight(Point(5,3));
74 | Box box3 = box1 & box2;
75 | check(!box3.empty() &&
76 | box3.left()==2 && box3.bottom()==2 &&
77 | box3.right()==3 && box3.top()==3,
78 | "Wrong intersection of two dim2::Box objects.");
79 |
80 | box1.add(box2);
81 | check(!box1.empty() &&
82 | box1.left()==1 && box1.bottom()==0 &&
83 | box1.right()==5 && box1.top()==4,
84 | "Wrong addition of two dim2::Box objects.");
85 |
86 | return 0;
87 | }
88 |
--------------------------------------------------------------------------------
/lemon/concept_check.h:
--------------------------------------------------------------------------------
1 | /* -*- mode: C++; indent-tabs-mode: nil; -*-
2 | *
3 | * This file is a part of LEMON, a generic C++ optimization library.
4 | *
5 | * Copyright (C) 2003-2013
6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 | * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 | *
9 | * Permission to use, modify and distribute this software is granted
10 | * provided that this copyright notice appears in all copies. For
11 | * precise terms see the accompanying LICENSE file.
12 | *
13 | * This software is provided "AS IS" with no warranty of any kind,
14 | * express or implied, and with no claim as to its suitability for any
15 | * purpose.
16 | *
17 | */
18 |
19 | // The contents of this file was inspired by the concept checking
20 | // utility of the BOOST library (http://www.boost.org).
21 |
22 | ///\file
23 | ///\brief Basic utilities for concept checking.
24 | ///
25 |
26 | #ifndef LEMON_CONCEPT_CHECK_H
27 | #define LEMON_CONCEPT_CHECK_H
28 |
29 | namespace lemon {
30 |
31 | /*
32 | "inline" is used for ignore_unused_variable_warning()
33 | and function_requires() to make sure there is no
34 | overtarget with g++.
35 | */
36 |
37 | template inline void ignore_unused_variable_warning(const T&) { }
38 | template
39 | inline void ignore_unused_variable_warning(const T1&, const T2&) { }
40 | template
41 | inline void ignore_unused_variable_warning(const T1&, const T2&,
42 | const T3&) { }
43 | template
44 | inline void ignore_unused_variable_warning(const T1&, const T2&,
45 | const T3&, const T4&) { }
46 | template
47 | inline void ignore_unused_variable_warning(const T1&, const T2&,
48 | const T3&, const T4&,
49 | const T5&) { }
50 | template
51 | inline void ignore_unused_variable_warning(const T1&, const T2&,
52 | const T3&, const T4&,
53 | const T5&, const T6&) { }
54 |
55 | ///\e
56 | template
57 | inline void function_requires()
58 | {
59 | #if !defined(NDEBUG)
60 | void (Concept::*x)() = & Concept::constraints;
61 | ::lemon::ignore_unused_variable_warning(x);
62 | #endif
63 | }
64 |
65 | ///\e
66 | template
67 | inline void checkConcept() {
68 | #if !defined(NDEBUG)
69 | typedef typename Concept::template Constraints ConceptCheck;
70 | void (ConceptCheck::*x)() = & ConceptCheck::constraints;
71 | ::lemon::ignore_unused_variable_warning(x);
72 | #endif
73 | }
74 |
75 | } // namespace lemon
76 |
77 | #endif // LEMON_CONCEPT_CHECK_H
78 |
--------------------------------------------------------------------------------
/doc/images/nodeshape_3.eps:
--------------------------------------------------------------------------------
1 | %!PS-Adobe-2.0 EPSF-2.0
2 | %%Title: LEMON GraphToEps figure
3 | %%Creator: LEMON GraphToEps function
4 | %%BoundingBox: 0 0 256 372
5 | %%EndComments
6 | /lb { setlinewidth setrgbcolor newpath moveto
7 | 4 2 roll 1 index 1 index curveto stroke } bind def
8 | /l { setlinewidth setrgbcolor newpath moveto lineto stroke } bind def
9 | /c { newpath dup 3 index add 2 index moveto 0 360 arc closepath } bind def
10 | /sq { newpath 2 index 1 index add 2 index 2 index add moveto
11 | 2 index 1 index sub 2 index 2 index add lineto
12 | 2 index 1 index sub 2 index 2 index sub lineto
13 | 2 index 1 index add 2 index 2 index sub lineto
14 | closepath pop pop pop} bind def
15 | /di { newpath 2 index 1 index add 2 index moveto
16 | 2 index 2 index 2 index add lineto
17 | 2 index 1 index sub 2 index lineto
18 | 2 index 2 index 2 index sub lineto
19 | closepath pop pop pop} bind def
20 | /nc { 0 0 0 setrgbcolor 5 index 5 index 5 index c fill
21 | setrgbcolor 1.1 div c fill
22 | } bind def
23 | /nsq { 0 0 0 setrgbcolor 5 index 5 index 5 index sq fill
24 | setrgbcolor 1.1 div sq fill
25 | } bind def
26 | /ndi { 0 0 0 setrgbcolor 5 index 5 index 5 index di fill
27 | setrgbcolor 1.1 div di fill
28 | } bind def
29 | /nfemale { 0 0 0 setrgbcolor 3 index 0.0909091 1.5 mul mul setlinewidth
30 | newpath 5 index 5 index moveto 5 index 5 index 5 index 3.01 mul sub
31 | lineto 5 index 4 index .7 mul sub 5 index 5 index 2.2 mul sub moveto
32 | 5 index 4 index .7 mul add 5 index 5 index 2.2 mul sub lineto stroke
33 | 5 index 5 index 5 index c fill
34 | setrgbcolor 1.1 div c fill
35 | } bind def
36 | /nmale {
37 | 0 0 0 setrgbcolor 3 index 0.0909091 1.5 mul mul setlinewidth
38 | newpath 5 index 5 index moveto
39 | 5 index 4 index 1 mul 1.5 mul add
40 | 5 index 5 index 3 sqrt 1.5 mul mul add
41 | 1 index 1 index lineto
42 | 1 index 1 index 7 index sub moveto
43 | 1 index 1 index lineto
44 | exch 5 index 3 sqrt .5 mul mul sub exch 5 index .5 mul sub lineto
45 | stroke
46 | 5 index 5 index 5 index c fill
47 | setrgbcolor 1.1 div c fill
48 | } bind def
49 | /arrl 1 def
50 | /arrw 0.3 def
51 | /lrl { 2 index mul exch 2 index mul exch rlineto pop} bind def
52 | /arr { setrgbcolor /y1 exch def /x1 exch def /dy exch def /dx exch def
53 | /w exch def /len exch def
54 | newpath x1 dy w 2 div mul add y1 dx w 2 div mul sub moveto
55 | len w sub arrl sub dx dy lrl
56 | arrw dy dx neg lrl
57 | dx arrl w add mul dy w 2 div arrw add mul sub
58 | dy arrl w add mul dx w 2 div arrw add mul add rlineto
59 | dx arrl w add mul neg dy w 2 div arrw add mul sub
60 | dy arrl w add mul neg dx w 2 div arrw add mul add rlineto
61 | arrw dy dx neg lrl
62 | len w sub arrl sub neg dx dy lrl
63 | closepath fill } bind def
64 | /cshow { 2 index 2 index moveto dup stringwidth pop
65 | neg 2 div fosi .35 mul neg rmoveto show pop pop} def
66 |
67 | gsave
68 | 100 dup scale
69 | %Edges:
70 | gsave
71 | grestore
72 | %Nodes:
73 | gsave
74 | 1 1 1 0.2 1 0.2 nmale
75 | grestore
76 | grestore
77 | showpage
78 |
--------------------------------------------------------------------------------
/doc/images/nodeshape_4.eps:
--------------------------------------------------------------------------------
1 | %!PS-Adobe-2.0 EPSF-2.0
2 | %%Title: LEMON GraphToEps figure
3 | %%Creator: LEMON GraphToEps function
4 | %%BoundingBox: 0 -199 200 200
5 | %%EndComments
6 | /lb { setlinewidth setrgbcolor newpath moveto
7 | 4 2 roll 1 index 1 index curveto stroke } bind def
8 | /l { setlinewidth setrgbcolor newpath moveto lineto stroke } bind def
9 | /c { newpath dup 3 index add 2 index moveto 0 360 arc closepath } bind def
10 | /sq { newpath 2 index 1 index add 2 index 2 index add moveto
11 | 2 index 1 index sub 2 index 2 index add lineto
12 | 2 index 1 index sub 2 index 2 index sub lineto
13 | 2 index 1 index add 2 index 2 index sub lineto
14 | closepath pop pop pop} bind def
15 | /di { newpath 2 index 1 index add 2 index moveto
16 | 2 index 2 index 2 index add lineto
17 | 2 index 1 index sub 2 index lineto
18 | 2 index 2 index 2 index sub lineto
19 | closepath pop pop pop} bind def
20 | /nc { 0 0 0 setrgbcolor 5 index 5 index 5 index c fill
21 | setrgbcolor 1.1 div c fill
22 | } bind def
23 | /nsq { 0 0 0 setrgbcolor 5 index 5 index 5 index sq fill
24 | setrgbcolor 1.1 div sq fill
25 | } bind def
26 | /ndi { 0 0 0 setrgbcolor 5 index 5 index 5 index di fill
27 | setrgbcolor 1.1 div di fill
28 | } bind def
29 | /nfemale { 0 0 0 setrgbcolor 3 index 0.0909091 1.5 mul mul setlinewidth
30 | newpath 5 index 5 index moveto 5 index 5 index 5 index 3.01 mul sub
31 | lineto 5 index 4 index .7 mul sub 5 index 5 index 2.2 mul sub moveto
32 | 5 index 4 index .7 mul add 5 index 5 index 2.2 mul sub lineto stroke
33 | 5 index 5 index 5 index c fill
34 | setrgbcolor 1.1 div c fill
35 | } bind def
36 | /nmale {
37 | 0 0 0 setrgbcolor 3 index 0.0909091 1.5 mul mul setlinewidth
38 | newpath 5 index 5 index moveto
39 | 5 index 4 index 1 mul 1.5 mul add
40 | 5 index 5 index 3 sqrt 1.5 mul mul add
41 | 1 index 1 index lineto
42 | 1 index 1 index 7 index sub moveto
43 | 1 index 1 index lineto
44 | exch 5 index 3 sqrt .5 mul mul sub exch 5 index .5 mul sub lineto
45 | stroke
46 | 5 index 5 index 5 index c fill
47 | setrgbcolor 1.1 div c fill
48 | } bind def
49 | /arrl 1 def
50 | /arrw 0.3 def
51 | /lrl { 2 index mul exch 2 index mul exch rlineto pop} bind def
52 | /arr { setrgbcolor /y1 exch def /x1 exch def /dy exch def /dx exch def
53 | /w exch def /len exch def
54 | newpath x1 dy w 2 div mul add y1 dx w 2 div mul sub moveto
55 | len w sub arrl sub dx dy lrl
56 | arrw dy dx neg lrl
57 | dx arrl w add mul dy w 2 div arrw add mul sub
58 | dy arrl w add mul dx w 2 div arrw add mul add rlineto
59 | dx arrl w add mul neg dy w 2 div arrw add mul sub
60 | dy arrl w add mul neg dx w 2 div arrw add mul add rlineto
61 | arrw dy dx neg lrl
62 | len w sub arrl sub neg dx dy lrl
63 | closepath fill } bind def
64 | /cshow { 2 index 2 index moveto dup stringwidth pop
65 | neg 2 div fosi .35 mul neg rmoveto show pop pop} def
66 |
67 | gsave
68 | 100 dup scale
69 | %Edges:
70 | gsave
71 | grestore
72 | %Nodes:
73 | gsave
74 | 1 1 1 0.2 1 0.2 nfemale
75 | grestore
76 | grestore
77 | showpage
78 |
--------------------------------------------------------------------------------
/cmake/FindCOIN.cmake:
--------------------------------------------------------------------------------
1 | SET(COIN_ROOT_DIR "" CACHE PATH "COIN root directory")
2 |
3 | FIND_PATH(COIN_INCLUDE_DIR coin/CoinUtilsConfig.h
4 | HINTS ${COIN_ROOT_DIR}/include
5 | )
6 | FIND_LIBRARY(COIN_CBC_LIBRARY
7 | NAMES Cbc libCbc
8 | HINTS ${COIN_ROOT_DIR}/lib/coin
9 | HINTS ${COIN_ROOT_DIR}/lib
10 | )
11 | FIND_LIBRARY(COIN_CBC_SOLVER_LIBRARY
12 | NAMES CbcSolver libCbcSolver
13 | HINTS ${COIN_ROOT_DIR}/lib/coin
14 | HINTS ${COIN_ROOT_DIR}/lib
15 | )
16 | FIND_LIBRARY(COIN_CGL_LIBRARY
17 | NAMES Cgl libCgl
18 | HINTS ${COIN_ROOT_DIR}/lib/coin
19 | HINTS ${COIN_ROOT_DIR}/lib
20 | )
21 | FIND_LIBRARY(COIN_CLP_LIBRARY
22 | NAMES Clp libClp
23 | HINTS ${COIN_ROOT_DIR}/lib/coin
24 | HINTS ${COIN_ROOT_DIR}/lib
25 | )
26 | FIND_LIBRARY(COIN_COIN_UTILS_LIBRARY
27 | NAMES CoinUtils libCoinUtils
28 | HINTS ${COIN_ROOT_DIR}/lib/coin
29 | HINTS ${COIN_ROOT_DIR}/lib
30 | )
31 | FIND_LIBRARY(COIN_OSI_LIBRARY
32 | NAMES Osi libOsi
33 | HINTS ${COIN_ROOT_DIR}/lib/coin
34 | HINTS ${COIN_ROOT_DIR}/lib
35 | )
36 | FIND_LIBRARY(COIN_OSI_CBC_LIBRARY
37 | NAMES OsiCbc libOsiCbc
38 | HINTS ${COIN_ROOT_DIR}/lib/coin
39 | HINTS ${COIN_ROOT_DIR}/lib
40 | )
41 | FIND_LIBRARY(COIN_OSI_CLP_LIBRARY
42 | NAMES OsiClp libOsiClp
43 | HINTS ${COIN_ROOT_DIR}/lib/coin
44 | HINTS ${COIN_ROOT_DIR}/lib
45 | )
46 | FIND_LIBRARY(COIN_OSI_VOL_LIBRARY
47 | NAMES OsiVol libOsiVol
48 | HINTS ${COIN_ROOT_DIR}/lib/coin
49 | HINTS ${COIN_ROOT_DIR}/lib
50 | )
51 | FIND_LIBRARY(COIN_VOL_LIBRARY
52 | NAMES Vol libVol
53 | HINTS ${COIN_ROOT_DIR}/lib/coin
54 | HINTS ${COIN_ROOT_DIR}/lib
55 | )
56 |
57 | FIND_LIBRARY(COIN_ZLIB_LIBRARY
58 | NAMES z libz
59 | HINTS ${COIN_ROOT_DIR}/lib/coin
60 | HINTS ${COIN_ROOT_DIR}/lib
61 | )
62 | FIND_LIBRARY(COIN_BZ2_LIBRARY
63 | NAMES bz2 libbz2
64 | HINTS ${COIN_ROOT_DIR}/lib/coin
65 | HINTS ${COIN_ROOT_DIR}/lib
66 | )
67 |
68 | INCLUDE(FindPackageHandleStandardArgs)
69 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(COIN DEFAULT_MSG
70 | COIN_INCLUDE_DIR
71 | COIN_CBC_LIBRARY
72 | COIN_CBC_SOLVER_LIBRARY
73 | COIN_CGL_LIBRARY
74 | COIN_CLP_LIBRARY
75 | COIN_COIN_UTILS_LIBRARY
76 | COIN_OSI_LIBRARY
77 | COIN_OSI_CBC_LIBRARY
78 | COIN_OSI_CLP_LIBRARY
79 | # COIN_OSI_VOL_LIBRARY
80 | # COIN_VOL_LIBRARY
81 | )
82 |
83 | IF(COIN_FOUND)
84 | SET(COIN_INCLUDE_DIRS ${COIN_INCLUDE_DIR})
85 | SET(COIN_CLP_LIBRARIES "${COIN_CLP_LIBRARY};${COIN_COIN_UTILS_LIBRARY};${COIN_ZLIB_LIBRARY};${COIN_BZ2_LIBRARY}")
86 | IF(COIN_ZLIB_LIBRARY)
87 | SET(COIN_CLP_LIBRARIES "${COIN_CLP_LIBRARIES};${COIN_ZLIB_LIBRARY}")
88 | ENDIF(COIN_ZLIB_LIBRARY)
89 | IF(COIN_BZ2_LIBRARY)
90 | SET(COIN_CLP_LIBRARIES "${COIN_CLP_LIBRARIES};${COIN_BZ2_LIBRARY}")
91 | ENDIF(COIN_BZ2_LIBRARY)
92 | SET(COIN_CBC_LIBRARIES "${COIN_CBC_LIBRARY};${COIN_CBC_SOLVER_LIBRARY};${COIN_CGL_LIBRARY};${COIN_OSI_LIBRARY};${COIN_OSI_CBC_LIBRARY};${COIN_OSI_CLP_LIBRARY};${COIN_ZLIB_LIBRARY};${COIN_BZ2_LIBRARY};${COIN_CLP_LIBRARIES}")
93 | SET(COIN_LIBRARIES ${COIN_CBC_LIBRARIES})
94 | ENDIF(COIN_FOUND)
95 |
96 | MARK_AS_ADVANCED(
97 | COIN_INCLUDE_DIR
98 | COIN_CBC_LIBRARY
99 | COIN_CBC_SOLVER_LIBRARY
100 | COIN_CGL_LIBRARY
101 | COIN_CLP_LIBRARY
102 | COIN_COIN_UTILS_LIBRARY
103 | COIN_OSI_LIBRARY
104 | COIN_OSI_CBC_LIBRARY
105 | COIN_OSI_CLP_LIBRARY
106 | COIN_OSI_VOL_LIBRARY
107 | COIN_VOL_LIBRARY
108 | COIN_ZLIB_LIBRARY
109 | COIN_BZ2_LIBRARY
110 | )
111 |
--------------------------------------------------------------------------------
/test/unionfind_test.cc:
--------------------------------------------------------------------------------
1 | /* -*- mode: C++; indent-tabs-mode: nil; -*-
2 | *
3 | * This file is a part of LEMON, a generic C++ optimization library.
4 | *
5 | * Copyright (C) 2003-2009
6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 | * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 | *
9 | * Permission to use, modify and distribute this software is granted
10 | * provided that this copyright notice appears in all copies. For
11 | * precise terms see the accompanying LICENSE file.
12 | *
13 | * This software is provided "AS IS" with no warranty of any kind,
14 | * express or implied, and with no claim as to its suitability for any
15 | * purpose.
16 | *
17 | */
18 |
19 | #include
20 | #include
21 | #include
22 | #include "test_tools.h"
23 |
24 | using namespace lemon;
25 | using namespace std;
26 |
27 | typedef UnionFindEnum > UFE;
28 |
29 | int main() {
30 | ListGraph g;
31 | ListGraph::NodeMap base(g);
32 | UFE U(base);
33 | vector n;
34 |
35 | for(int i=0;i<20;i++) n.push_back(g.addNode());
36 |
37 | U.insert(n[1]);
38 | U.insert(n[2]);
39 |
40 | check(U.join(n[1],n[2]) != -1, "Something is wrong with UnionFindEnum");
41 |
42 | U.insert(n[3]);
43 | U.insert(n[4]);
44 | U.insert(n[5]);
45 | U.insert(n[6]);
46 | U.insert(n[7]);
47 |
48 |
49 | check(U.join(n[1],n[4]) != -1, "Something is wrong with UnionFindEnum");
50 | check(U.join(n[2],n[4]) == -1, "Something is wrong with UnionFindEnum");
51 | check(U.join(n[3],n[5]) != -1, "Something is wrong with UnionFindEnum");
52 |
53 |
54 | U.insert(n[8],U.find(n[5]));
55 |
56 |
57 | check(U.size(U.find(n[4])) == 3, "Something is wrong with UnionFindEnum");
58 | check(U.size(U.find(n[5])) == 3, "Something is wrong with UnionFindEnum");
59 | check(U.size(U.find(n[6])) == 1, "Something is wrong with UnionFindEnum");
60 | check(U.size(U.find(n[2])) == 3, "Something is wrong with UnionFindEnum");
61 |
62 |
63 | U.insert(n[9]);
64 | U.insert(n[10],U.find(n[9]));
65 |
66 |
67 | check(U.join(n[8],n[10]) != -1, "Something is wrong with UnionFindEnum");
68 |
69 |
70 | check(U.size(U.find(n[4])) == 3, "Something is wrong with UnionFindEnum");
71 | check(U.size(U.find(n[9])) == 5, "Something is wrong with UnionFindEnum");
72 |
73 | check(U.size(U.find(n[8])) == 5, "Something is wrong with UnionFindEnum");
74 |
75 | U.erase(n[9]);
76 | U.erase(n[1]);
77 |
78 | check(U.size(U.find(n[10])) == 4, "Something is wrong with UnionFindEnum");
79 | check(U.size(U.find(n[2])) == 2, "Something is wrong with UnionFindEnum");
80 |
81 | U.erase(n[6]);
82 | U.split(U.find(n[8]));
83 |
84 |
85 | check(U.size(U.find(n[4])) == 2, "Something is wrong with UnionFindEnum");
86 | check(U.size(U.find(n[3])) == 1, "Something is wrong with UnionFindEnum");
87 | check(U.size(U.find(n[2])) == 2, "Something is wrong with UnionFindEnum");
88 |
89 |
90 | check(U.join(n[3],n[4]) != -1, "Something is wrong with UnionFindEnum");
91 | check(U.join(n[2],n[4]) == -1, "Something is wrong with UnionFindEnum");
92 |
93 |
94 | check(U.size(U.find(n[4])) == 3, "Something is wrong with UnionFindEnum");
95 | check(U.size(U.find(n[3])) == 3, "Something is wrong with UnionFindEnum");
96 | check(U.size(U.find(n[2])) == 3, "Something is wrong with UnionFindEnum");
97 |
98 | U.eraseClass(U.find(n[4]));
99 | U.eraseClass(U.find(n[7]));
100 |
101 | return 0;
102 | }
103 |
--------------------------------------------------------------------------------
/lemon/nauty_reader.h:
--------------------------------------------------------------------------------
1 | /* -*- mode: C++; indent-tabs-mode: nil; -*-
2 | *
3 | * This file is a part of LEMON, a generic C++ optimization library.
4 | *
5 | * Copyright (C) 2003-2009
6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 | * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 | *
9 | * Permission to use, modify and distribute this software is granted
10 | * provided that this copyright notice appears in all copies. For
11 | * precise terms see the accompanying LICENSE file.
12 | *
13 | * This software is provided "AS IS" with no warranty of any kind,
14 | * express or implied, and with no claim as to its suitability for any
15 | * purpose.
16 | *
17 | */
18 |
19 | #ifndef LEMON_NAUTY_READER_H
20 | #define LEMON_NAUTY_READER_H
21 |
22 | #include
23 | #include
24 | #include
25 |
26 | /// \ingroup nauty_group
27 | /// \file
28 | /// \brief Nauty file reader.
29 |
30 | namespace lemon {
31 |
32 | /// \ingroup nauty_group
33 | ///
34 | /// \brief Nauty file reader
35 | ///
36 | /// The \e geng program is in the \e gtools suite of the nauty
37 | /// package. This tool can generate all non-isomorphic undirected
38 | /// graphs of several classes with given node number (e.g.
39 | /// general, connected, biconnected, triangle-free, 4-cycle-free,
40 | /// bipartite and graphs with given edge number and degree
41 | /// constraints). This function reads a \e nauty \e graph6 \e format
42 | /// line from the given stream and builds it in the given graph.
43 | ///
44 | /// The site of nauty package: http://cs.anu.edu.au/~bdm/nauty/
45 | ///
46 | /// For example, the number of all non-isomorphic planar graphs
47 | /// can be computed with the following code.
48 | ///\code
49 | /// int num = 0;
50 | /// SmartGraph graph;
51 | /// while (readNautyGraph(graph, std::cin)) {
52 | /// PlanarityChecking pc(graph);
53 | /// if (pc.run()) ++num;
54 | /// }
55 | /// std::cout << "Number of planar graphs: " << num << std::endl;
56 | ///\endcode
57 | ///
58 | /// The nauty files are quite huge, therefore instead of the direct
59 | /// file generation pipelining is recommended. For example,
60 | ///\code
61 | /// ./geng -c 10 | ./num_of_planar_graphs
62 | ///\endcode
63 | template
64 | std::istream& readNautyGraph(Graph& graph, std::istream& is = std::cin) {
65 | graph.clear();
66 |
67 | std::string line;
68 | if (getline(is, line)) {
69 | int index = 0;
70 |
71 | int n;
72 |
73 | if (line[index] == '>') {
74 | index += 10;
75 | }
76 |
77 | char c = line[index++]; c -= 63;
78 | if (c != 63) {
79 | n = int(c);
80 | } else {
81 | c = line[index++]; c -= 63;
82 | n = (int(c) << 12);
83 | c = line[index++]; c -= 63;
84 | n |= (int(c) << 6);
85 | c = line[index++]; c -= 63;
86 | n |= int(c);
87 | }
88 |
89 | std::vector nodes;
90 | for (int i = 0; i < n; ++i) {
91 | nodes.push_back(graph.addNode());
92 | }
93 |
94 | int bit = -1;
95 | for (int j = 0; j < n; ++j) {
96 | for (int i = 0; i < j; ++i) {
97 | if (bit == -1) {
98 | c = line[index++]; c -= 63;
99 | bit = 5;
100 | }
101 | bool b = (c & (1 << (bit--))) != 0;
102 |
103 | if (b) {
104 | graph.addEdge(nodes[i], nodes[j]);
105 | }
106 | }
107 | }
108 | }
109 | return is;
110 | }
111 | }
112 |
113 | #endif
114 |
--------------------------------------------------------------------------------
/doc/coding_style.dox:
--------------------------------------------------------------------------------
1 | /* -*- mode: C++; indent-tabs-mode: nil; -*-
2 | *
3 | * This file is a part of LEMON, a generic C++ optimization library.
4 | *
5 | * Copyright (C) 2003-2013
6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 | * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 | *
9 | * Permission to use, modify and distribute this software is granted
10 | * provided that this copyright notice appears in all copies. For
11 | * precise terms see the accompanying LICENSE file.
12 | *
13 | * This software is provided "AS IS" with no warranty of any kind,
14 | * express or implied, and with no claim as to its suitability for any
15 | * purpose.
16 | *
17 | */
18 |
19 | /*!
20 |
21 | \page coding_style LEMON Coding Style
22 |
23 | \section naming_conv Naming Conventions
24 |
25 | In order to make development easier we have made some conventions
26 | according to coding style. These include names of types, classes,
27 | functions, variables, constants and exceptions. If these conventions
28 | are met in one's code then it is easier to read and maintain
29 | it. Please comply with these conventions if you want to contribute
30 | developing LEMON library.
31 |
32 | \note When the coding style requires the capitalization of an abbreviation,
33 | only the first letter should be upper case.
34 |
35 | \code
36 | XmlReader
37 | \endcode
38 |
39 |
40 | \warning In some cases we diverge from these rules.
41 | This is primary done because STL uses different naming convention and
42 | in certain cases
43 | it is beneficial to provide STL compatible interface.
44 |
45 | \subsection cs-files File Names
46 |
47 | The header file names should look like the following.
48 |
49 | \code
50 | header_file.h
51 | \endcode
52 |
53 | Note that all standard LEMON headers are located in the \c lemon subdirectory,
54 | so you should include them from C++ source like this:
55 |
56 | \code
57 | #include
58 | \endcode
59 |
60 | The source code files use the same style and they have '.cc' extension.
61 |
62 | \code
63 | source_code.cc
64 | \endcode
65 |
66 | \subsection cs-class Classes and other types
67 |
68 | The name of a class or any type should look like the following.
69 |
70 | \code
71 | AllWordsCapitalizedWithoutUnderscores
72 | \endcode
73 |
74 | \subsection cs-func Methods and other functions
75 |
76 | The name of a function should look like the following.
77 |
78 | \code
79 | firstWordLowerCaseRestCapitalizedWithoutUnderscores
80 | \endcode
81 |
82 | \subsection cs-funcs Constants, Macros
83 |
84 | The names of constants and macros should look like the following.
85 |
86 | \code
87 | ALL_UPPER_CASE_WITH_UNDERSCORES
88 | \endcode
89 |
90 | \subsection cs-loc-var Class and instance member variables, auto variables
91 |
92 | The names of class and instance member variables and auto variables
93 | (=variables used locally in methods) should look like the following.
94 |
95 | \code
96 | all_lower_case_with_underscores
97 | \endcode
98 |
99 | \subsection pri-loc-var Private member variables
100 |
101 | Private member variables should start with underscore.
102 |
103 | \code
104 | _start_with_underscore
105 | \endcode
106 |
107 | \subsection cs-excep Exceptions
108 |
109 | When writing exceptions please comply the following naming conventions.
110 |
111 | \code
112 | ClassNameEndsWithException
113 | \endcode
114 |
115 | or
116 |
117 | \code
118 | ClassNameEndsWithError
119 | \endcode
120 |
121 | \section header-template Template Header File
122 |
123 | Each LEMON header file should look like this:
124 |
125 | \include template.h
126 |
127 | */
128 |
--------------------------------------------------------------------------------
/cmake/FindILOG.cmake:
--------------------------------------------------------------------------------
1 | FIND_PATH(ILOG_ROOT_DIR
2 | NAMES cplex
3 | DOC "CPLEX STUDIO root directory"
4 | PATHS /opt/ibm/ILOG /usr/local/ibm/ILOG /usr/local/ILOG /usr/local/ilog
5 | PATHS "$ENV{HOME}/ILOG" "$ENV{HOME}/.local/ILOG"
6 | PATHS "$ENV{HOME}/ibm/ILOG" "$ENV{HOME}/.local/ibm/ILOG"
7 | PATHS "C:/Program Files/IBM/ILOG"
8 | PATH_SUFFIXES "CPLEX_Studio126" "CPLEX_Studio125"
9 | "CPLEX_Studio124" "CPLEX_Studio123" "CPLEX_Studio122"
10 | NO_DEFAULT_PATH
11 | )
12 |
13 | IF(WIN32)
14 | IF(MSVC_VERSION STREQUAL "1400")
15 | SET(ILOG_WIN_COMPILER "windows_vs2005")
16 | ELSEIF(MSVC_VERSION STREQUAL "1500")
17 | SET(ILOG_WIN_COMPILER "windows_vs2008")
18 | ELSEIF(MSVC_VERSION STREQUAL "1600")
19 | SET(ILOG_WIN_COMPILER "windows_vs2010")
20 | ELSE()
21 | SET(ILOG_WIN_COMPILER "windows_vs2008")
22 | ENDIF()
23 | IF(CMAKE_CL_64)
24 | SET(ILOG_WIN_COMPILER "x64_${ILOG_WIN_COMPILER}")
25 | SET(ILOG_WIN_PLATFORM "x64_win32")
26 | ELSE()
27 | SET(ILOG_WIN_COMPILER "x86_${ILOG_WIN_COMPILER}")
28 | SET(ILOG_WIN_PLATFORM "x86_win32")
29 | ENDIF()
30 | ENDIF()
31 |
32 | FIND_PATH(ILOG_CPLEX_ROOT_DIR
33 | NAMES include/ilcplex
34 | HINTS ${ILOG_ROOT_DIR}/cplex ${ILOG_ROOT_DIR}/cplex121
35 | ${ILOG_ROOT_DIR}/cplex122 ${ILOG_ROOT_DIR}/cplex123
36 | DOC "CPLEX root directory"
37 | NO_DEFAULT_PATH
38 | )
39 |
40 | FIND_PATH(ILOG_CONCERT_ROOT_DIR
41 | NAMES include/ilconcert
42 | HINTS ${ILOG_ROOT_DIR}/concert ${ILOG_ROOT_DIR}/concert29
43 | DOC "CONCERT root directory"
44 | NO_DEFAULT_PATH
45 | )
46 |
47 | FIND_PATH(ILOG_CPLEX_INCLUDE_DIR
48 | ilcplex/cplex.h
49 | HINTS ${ILOG_CPLEX_ROOT_DIR}/include
50 | NO_DEFAULT_PATH
51 | )
52 |
53 | FIND_PATH(ILOG_CONCERT_INCLUDE_DIR
54 | ilconcert/ilobasic.h
55 | HINTS ${ILOG_CONCERT_ROOT_DIR}/include
56 | NO_DEFAULT_PATH
57 | )
58 |
59 | FIND_LIBRARY(ILOG_CPLEX_LIBRARY
60 | cplex cplex121 cplex122 cplex123 cplex124
61 | HINTS ${ILOG_CPLEX_ROOT_DIR}/lib/x86_sles10_4.1/static_pic
62 | ${ILOG_CPLEX_ROOT_DIR}/lib/x86-64_sles10_4.1/static_pic
63 | ${ILOG_CPLEX_ROOT_DIR}/lib/x86_debian4.0_4.1/static_pic
64 | ${ILOG_CPLEX_ROOT_DIR}/lib/x86-64_debian4.0_4.1/static_pic
65 | ${ILOG_CPLEX_ROOT_DIR}/lib/${ILOG_WIN_COMPILER}/stat_mda
66 | NO_DEFAULT_PATH
67 | )
68 |
69 | FIND_LIBRARY(ILOG_CONCERT_LIBRARY
70 | concert
71 | HINTS ${ILOG_CONCERT_ROOT_DIR}/lib/x86_sles10_4.1/static_pic
72 | ${ILOG_CONCERT_ROOT_DIR}/lib/x86-64_sles10_4.1/static_pic
73 | ${ILOG_CONCERT_ROOT_DIR}/lib/x86_debian4.0_4.1/static_pic
74 | ${ILOG_CONCERT_ROOT_DIR}/lib/x86-64_debian4.0_4.1/static_pic
75 | ${ILOG_CONCERT_ROOT_DIR}/lib/${ILOG_WIN_COMPILER}/stat_mda
76 | NO_DEFAULT_PATH
77 | )
78 |
79 | FIND_FILE(ILOG_CPLEX_DLL
80 | cplex121.dll cplex122.dll cplex123.dll cplex124.dll
81 | HINTS ${ILOG_CPLEX_ROOT_DIR}/bin/${ILOG_WIN_PLATFORM}
82 | NO_DEFAULT_PATH
83 | )
84 |
85 | INCLUDE(FindPackageHandleStandardArgs)
86 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(ILOG
87 | DEFAULT_MSG ILOG_CPLEX_LIBRARY ILOG_CPLEX_INCLUDE_DIR
88 | )
89 |
90 | IF(ILOG_FOUND)
91 | SET(ILOG_INCLUDE_DIRS ${ILOG_CPLEX_INCLUDE_DIR} ${ILOG_CONCERT_INCLUDE_DIR})
92 | SET(ILOG_LIBRARIES ${ILOG_CPLEX_LIBRARY} ${ILOG_CONCERT_LIBRARY})
93 | IF(CMAKE_SYSTEM_NAME STREQUAL "Linux")
94 | # SET(CPLEX_LIBRARIES "${CPLEX_LIBRARIES};m;pthread")
95 | SET(ILOG_LIBRARIES ${ILOG_LIBRARIES} "m" "pthread")
96 | ENDIF(CMAKE_SYSTEM_NAME STREQUAL "Linux")
97 | ENDIF(ILOG_FOUND)
98 |
99 | MARK_AS_ADVANCED(
100 | ILOG_CPLEX_LIBRARY ILOG_CPLEX_INCLUDE_DIR ILOG_CPLEX_DLL
101 | ILOG_CONCERT_LIBRARY ILOG_CONCERT_INCLUDE_DIR ILOG_CONCERT_DLL
102 | )
103 |
--------------------------------------------------------------------------------
/test/counter_test.cc:
--------------------------------------------------------------------------------
1 | /* -*- mode: C++; indent-tabs-mode: nil; -*-
2 | *
3 | * This file is a part of LEMON, a generic C++ optimization library.
4 | *
5 | * Copyright (C) 2003-2009
6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 | * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 | *
9 | * Permission to use, modify and distribute this software is granted
10 | * provided that this copyright notice appears in all copies. For
11 | * precise terms see the accompanying LICENSE file.
12 | *
13 | * This software is provided "AS IS" with no warranty of any kind,
14 | * express or implied, and with no claim as to its suitability for any
15 | * purpose.
16 | *
17 | */
18 |
19 | #include
20 | #include
21 | #include
22 |
23 | #include "test/test_tools.h"
24 |
25 | using namespace lemon;
26 |
27 | template
28 | void bubbleSort(std::vector& v) {
29 | std::stringstream s1, s2, s3;
30 | {
31 | Counter op("Bubble Sort - Operations: ", s1);
32 | Counter::SubCounter as(op, "Assignments: ", s2);
33 | Counter::SubCounter co(op, "Comparisons: ", s3);
34 | for (int i = v.size()-1; i > 0; --i) {
35 | for (int j = 0; j < i; ++j) {
36 | if (v[j] > v[j+1]) {
37 | T tmp = v[j];
38 | v[j] = v[j+1];
39 | v[j+1] = tmp;
40 | as += 3;
41 | }
42 | ++co;
43 | }
44 | }
45 | }
46 | check(s1.str() == "Bubble Sort - Operations: 102\n", "Wrong counter");
47 | check(s2.str() == "Assignments: 57\n", "Wrong subcounter");
48 | check(s3.str() == "Comparisons: 45\n", "Wrong subcounter");
49 | }
50 |
51 | template
52 | void insertionSort(std::vector& v) {
53 | std::stringstream s1, s2, s3;
54 | {
55 | Counter op("Insertion Sort - Operations: ", s1);
56 | Counter::SubCounter as(op, "Assignments: ", s2);
57 | Counter::SubCounter co(op, "Comparisons: ", s3);
58 | for (int i = 1; i < int(v.size()); ++i) {
59 | T value = v[i];
60 | ++as;
61 | int j = i;
62 | while (j > 0 && v[j-1] > value) {
63 | v[j] = v[j-1];
64 | --j;
65 | ++co; ++as;
66 | }
67 | v[j] = value;
68 | ++as;
69 | }
70 | }
71 | check(s1.str() == "Insertion Sort - Operations: 56\n", "Wrong counter");
72 | check(s2.str() == "Assignments: 37\n", "Wrong subcounter");
73 | check(s3.str() == "Comparisons: 19\n", "Wrong subcounter");
74 | }
75 |
76 | template
77 | void counterTest(bool output) {
78 | std::stringstream s1, s2, s3;
79 | {
80 | MyCounter c("Main Counter: ", s1);
81 | c++;
82 | typename MyCounter::SubCounter d(c, "SubCounter: ", s2);
83 | d++;
84 | typename MyCounter::SubCounter::NoSubCounter e(d, "SubSubCounter: ", s3);
85 | e++;
86 | d+=3;
87 | c-=4;
88 | e-=2;
89 | c.reset(2);
90 | c.reset();
91 | }
92 | if (output) {
93 | check(s1.str() == "Main Counter: 3\n", "Wrong Counter");
94 | check(s2.str() == "SubCounter: 3\n", "Wrong SubCounter");
95 | check(s3.str() == "", "Wrong NoSubCounter");
96 | } else {
97 | check(s1.str() == "", "Wrong NoCounter");
98 | check(s2.str() == "", "Wrong SubCounter");
99 | check(s3.str() == "", "Wrong NoSubCounter");
100 | }
101 | }
102 |
103 | void init(std::vector& v) {
104 | v[0] = 10; v[1] = 60; v[2] = 20; v[3] = 90; v[4] = 100;
105 | v[5] = 80; v[6] = 40; v[7] = 30; v[8] = 50; v[9] = 70;
106 | }
107 |
108 | int main()
109 | {
110 | counterTest(true);
111 | counterTest(false);
112 |
113 | std::vector x(10);
114 | init(x); bubbleSort(x);
115 | init(x); insertionSort(x);
116 |
117 | return 0;
118 | }
119 |
--------------------------------------------------------------------------------
/lemon/bits/enable_if.h:
--------------------------------------------------------------------------------
1 | /* -*- mode: C++; indent-tabs-mode: nil; -*-
2 | *
3 | * This file is a part of LEMON, a generic C++ optimization library.
4 | *
5 | * Copyright (C) 2003-2009
6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 | * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 | *
9 | * Permission to use, modify and distribute this software is granted
10 | * provided that this copyright notice appears in all copies. For
11 | * precise terms see the accompanying LICENSE file.
12 | *
13 | * This software is provided "AS IS" with no warranty of any kind,
14 | * express or implied, and with no claim as to its suitability for any
15 | * purpose.
16 | *
17 | */
18 |
19 | // This file contains a modified version of the enable_if library from BOOST.
20 | // See the appropriate copyright notice below.
21 |
22 | // Boost enable_if library
23 |
24 | // Copyright 2003 (c) The Trustees of Indiana University.
25 |
26 | // Use, modification, and distribution is subject to the Boost Software
27 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
28 | // http://www.boost.org/LICENSE_1_0.txt)
29 |
30 | // Authors: Jaakko Jarvi (jajarvi at osl.iu.edu)
31 | // Jeremiah Willcock (jewillco at osl.iu.edu)
32 | // Andrew Lumsdaine (lums at osl.iu.edu)
33 |
34 |
35 | #ifndef LEMON_BITS_ENABLE_IF_H
36 | #define LEMON_BITS_ENABLE_IF_H
37 |
38 | //\file
39 | //\brief Miscellaneous basic utilities
40 |
41 | namespace lemon
42 | {
43 |
44 | // Basic type for defining "tags". A "YES" condition for \c enable_if.
45 |
46 | // Basic type for defining "tags". A "YES" condition for \c enable_if.
47 | //
48 | //\sa False
49 | struct True {
50 | //\e
51 | static const bool value = true;
52 | };
53 |
54 | // Basic type for defining "tags". A "NO" condition for \c enable_if.
55 |
56 | // Basic type for defining "tags". A "NO" condition for \c enable_if.
57 | //
58 | //\sa True
59 | struct False {
60 | //\e
61 | static const bool value = false;
62 | };
63 |
64 |
65 |
66 | template
67 | struct Wrap {
68 | const T &value;
69 | Wrap(const T &t) : value(t) {}
70 | };
71 |
72 | /**************** dummy class to avoid ambiguity ****************/
73 |
74 | template struct dummy { dummy(int) {} };
75 |
76 | /**************** enable_if from BOOST ****************/
77 |
78 | template
79 | struct exists {
80 | typedef T type;
81 | };
82 |
83 |
84 | template
85 | struct enable_if_c {
86 | typedef T type;
87 | };
88 |
89 | template
90 | struct enable_if_c {};
91 |
92 | template
93 | struct enable_if : public enable_if_c {};
94 |
95 | template
96 | struct lazy_enable_if_c {
97 | typedef typename T::type type;
98 | };
99 |
100 | template
101 | struct lazy_enable_if_c {};
102 |
103 | template
104 | struct lazy_enable_if : public lazy_enable_if_c {};
105 |
106 |
107 | template
108 | struct disable_if_c {
109 | typedef T type;
110 | };
111 |
112 | template
113 | struct disable_if_c {};
114 |
115 | template
116 | struct disable_if : public disable_if_c {};
117 |
118 | template
119 | struct lazy_disable_if_c {
120 | typedef typename T::type type;
121 | };
122 |
123 | template
124 | struct lazy_disable_if_c {};
125 |
126 | template
127 | struct lazy_disable_if : public lazy_disable_if_c {};
128 |
129 | } // namespace lemon
130 |
131 | #endif
132 |
--------------------------------------------------------------------------------
/test/gomory_hu_test.cc:
--------------------------------------------------------------------------------
1 | /* -*- mode: C++; indent-tabs-mode: nil; -*-
2 | *
3 | * This file is a part of LEMON, a generic C++ optimization library.
4 | *
5 | * Copyright (C) 2003-2013
6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 | * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 | *
9 | * Permission to use, modify and distribute this software is granted
10 | * provided that this copyright notice appears in all copies. For
11 | * precise terms see the accompanying LICENSE file.
12 | *
13 | * This software is provided "AS IS" with no warranty of any kind,
14 | * express or implied, and with no claim as to its suitability for any
15 | * purpose.
16 | *
17 | */
18 |
19 | #include
20 |
21 | #include "test_tools.h"
22 | #include
23 | #include
24 | #include
25 | #include
26 | #include
27 | #include
28 |
29 | using namespace std;
30 | using namespace lemon;
31 |
32 | typedef SmartGraph Graph;
33 |
34 | char test_lgf[] =
35 | "@nodes\n"
36 | "label\n"
37 | "0\n"
38 | "1\n"
39 | "2\n"
40 | "3\n"
41 | "4\n"
42 | "@arcs\n"
43 | " label capacity\n"
44 | "0 1 0 1\n"
45 | "1 2 1 1\n"
46 | "2 3 2 1\n"
47 | "0 3 4 5\n"
48 | "0 3 5 10\n"
49 | "0 3 6 7\n"
50 | "4 2 7 1\n"
51 | "@attributes\n"
52 | "source 0\n"
53 | "target 3\n";
54 |
55 | void checkGomoryHuCompile()
56 | {
57 | typedef int Value;
58 | typedef concepts::Graph Graph;
59 |
60 | typedef Graph::Node Node;
61 | typedef Graph::Edge Edge;
62 | typedef concepts::ReadMap CapMap;
63 | typedef concepts::ReadWriteMap CutMap;
64 |
65 | Graph g;
66 | Node n;
67 | CapMap cap;
68 | CutMap cut;
69 | Value v;
70 | int d;
71 | ::lemon::ignore_unused_variable_warning(v,d);
72 |
73 | GomoryHu gh_test(g, cap);
74 | const GomoryHu&
75 | const_gh_test = gh_test;
76 |
77 | gh_test.run();
78 |
79 | n = const_gh_test.predNode(n);
80 | v = const_gh_test.predValue(n);
81 | d = const_gh_test.rootDist(n);
82 | v = const_gh_test.minCutValue(n, n);
83 | v = const_gh_test.minCutMap(n, n, cut);
84 | }
85 |
86 | GRAPH_TYPEDEFS(Graph);
87 | typedef Graph::EdgeMap IntEdgeMap;
88 | typedef Graph::NodeMap BoolNodeMap;
89 |
90 | int cutValue(const Graph& graph, const BoolNodeMap& cut,
91 | const IntEdgeMap& capacity) {
92 |
93 | int sum = 0;
94 | for (EdgeIt e(graph); e != INVALID; ++e) {
95 | Node s = graph.u(e);
96 | Node t = graph.v(e);
97 |
98 | if (cut[s] != cut[t]) {
99 | sum += capacity[e];
100 | }
101 | }
102 | return sum;
103 | }
104 |
105 |
106 | int main() {
107 | Graph graph;
108 | IntEdgeMap capacity(graph);
109 |
110 | std::istringstream input(test_lgf);
111 | GraphReader(graph, input).
112 | edgeMap("capacity", capacity).run();
113 |
114 | GomoryHu ght(graph, capacity);
115 | ght.run();
116 |
117 | for (NodeIt u(graph); u != INVALID; ++u) {
118 | for (NodeIt v(graph); v != u; ++v) {
119 | Preflow pf(graph, capacity, u, v);
120 | pf.runMinCut();
121 | BoolNodeMap cm(graph);
122 | ght.minCutMap(u, v, cm);
123 | check(pf.flowValue() == ght.minCutValue(u, v), "Wrong cut 1");
124 | check(cm[u] != cm[v], "Wrong cut 2");
125 | check(pf.flowValue() == cutValue(graph, cm, capacity), "Wrong cut 3");
126 |
127 | int sum=0;
128 | for(GomoryHu::MinCutEdgeIt a(ght, u, v);a!=INVALID;++a)
129 | sum+=capacity[a];
130 | check(sum == ght.minCutValue(u, v), "Problem with MinCutEdgeIt");
131 |
132 | sum=0;
133 | for(GomoryHu::MinCutNodeIt n(ght, u, v,true);n!=INVALID;++n)
134 | sum++;
135 | for(GomoryHu::MinCutNodeIt n(ght, u, v,false);n!=INVALID;++n)
136 | sum++;
137 | check(sum == countNodes(graph), "Problem with MinCutNodeIt");
138 | }
139 | }
140 |
141 | return 0;
142 | }
143 |
--------------------------------------------------------------------------------
/test/mip_test.cc:
--------------------------------------------------------------------------------
1 | /* -*- mode: C++; indent-tabs-mode: nil; -*-
2 | *
3 | * This file is a part of LEMON, a generic C++ optimization library.
4 | *
5 | * Copyright (C) 2003-2009
6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 | * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 | *
9 | * Permission to use, modify and distribute this software is granted
10 | * provided that this copyright notice appears in all copies. For
11 | * precise terms see the accompanying LICENSE file.
12 | *
13 | * This software is provided "AS IS" with no warranty of any kind,
14 | * express or implied, and with no claim as to its suitability for any
15 | * purpose.
16 | *
17 | */
18 |
19 | #include "test_tools.h"
20 |
21 | #include
22 |
23 | #ifdef LEMON_HAVE_CPLEX
24 | #include
25 | #endif
26 |
27 | #ifdef LEMON_HAVE_GLPK
28 | #include
29 | #endif
30 |
31 | #ifdef LEMON_HAVE_CBC
32 | #include
33 | #endif
34 |
35 | #ifdef LEMON_HAVE_MIP
36 | #include
37 | #endif
38 |
39 |
40 | using namespace lemon;
41 |
42 | void solveAndCheck(MipSolver& mip, MipSolver::ProblemType stat,
43 | double exp_opt) {
44 | using std::string;
45 |
46 | mip.solve();
47 | //int decimal,sign;
48 | std::ostringstream buf;
49 | buf << "Type should be: " << int(stat)<<" and it is "<
121 | void cloneTest()
122 | {
123 |
124 | MIP* mip = new MIP();
125 | MIP* mipnew = mip->newSolver();
126 | MIP* mipclone = mip->cloneSolver();
127 | delete mip;
128 | delete mipnew;
129 | delete mipclone;
130 | }
131 |
132 | int main()
133 | {
134 |
135 | #ifdef LEMON_HAVE_MIP
136 | {
137 | Mip mip1;
138 | aTest(mip1);
139 | cloneTest();
140 | }
141 | #endif
142 |
143 | #ifdef LEMON_HAVE_GLPK
144 | {
145 | GlpkMip mip1;
146 | aTest(mip1);
147 | cloneTest();
148 | }
149 | #endif
150 |
151 | #ifdef LEMON_HAVE_CPLEX
152 | try {
153 | CplexMip mip2;
154 | aTest(mip2);
155 | cloneTest();
156 | } catch (CplexEnv::LicenseError& error) {
157 | check(false, error.what());
158 | }
159 | #endif
160 |
161 | #ifdef LEMON_HAVE_CBC
162 | {
163 | CbcMip mip1;
164 | aTest(mip1);
165 | cloneTest();
166 | }
167 | #endif
168 |
169 | return 0;
170 |
171 | }
172 |
--------------------------------------------------------------------------------
/lemon/cbc.h:
--------------------------------------------------------------------------------
1 | /* -*- mode: C++; indent-tabs-mode: nil; -*-
2 | *
3 | * This file is a part of LEMON, a generic C++ optimization library.
4 | *
5 | * Copyright (C) 2003-2013
6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 | * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 | *
9 | * Permission to use, modify and distribute this software is granted
10 | * provided that this copyright notice appears in all copies. For
11 | * precise terms see the accompanying LICENSE file.
12 | *
13 | * This software is provided "AS IS" with no warranty of any kind,
14 | * express or implied, and with no claim as to its suitability for any
15 | * purpose.
16 | *
17 | */
18 |
19 | #ifndef LEMON_CBC_H
20 | #define LEMON_CBC_H
21 |
22 | ///\file
23 | ///\brief Header of the LEMON-CBC mip solver interface.
24 | ///\ingroup lp_group
25 |
26 | #include
27 |
28 | class CoinModel;
29 | class OsiSolverInterface;
30 | class CbcModel;
31 |
32 | namespace lemon {
33 |
34 | /// \brief Interface for the CBC MIP solver
35 | ///
36 | /// This class implements an interface for the CBC MIP solver.
37 | ///\ingroup lp_group
38 | class CbcMip : public MipSolver {
39 | protected:
40 |
41 | CoinModel *_prob;
42 | OsiSolverInterface *_osi_solver;
43 | CbcModel *_cbc_model;
44 |
45 | public:
46 |
47 | /// \e
48 | CbcMip();
49 | /// \e
50 | CbcMip(const CbcMip&);
51 | /// \e
52 | ~CbcMip();
53 | /// \e
54 | virtual CbcMip* newSolver() const;
55 | /// \e
56 | virtual CbcMip* cloneSolver() const;
57 |
58 | protected:
59 |
60 | virtual const char* _solverName() const;
61 |
62 | virtual int _addCol();
63 | virtual int _addRow();
64 | virtual int _addRow(Value l, ExprIterator b, ExprIterator e, Value u);
65 |
66 | virtual void _eraseCol(int i);
67 | virtual void _eraseRow(int i);
68 |
69 | virtual void _eraseColId(int i);
70 | virtual void _eraseRowId(int i);
71 |
72 | virtual void _getColName(int col, std::string& name) const;
73 | virtual void _setColName(int col, const std::string& name);
74 | virtual int _colByName(const std::string& name) const;
75 |
76 | virtual void _getRowName(int row, std::string& name) const;
77 | virtual void _setRowName(int row, const std::string& name);
78 | virtual int _rowByName(const std::string& name) const;
79 |
80 | virtual void _setRowCoeffs(int i, ExprIterator b, ExprIterator e);
81 | virtual void _getRowCoeffs(int i, InsertIterator b) const;
82 |
83 | virtual void _setColCoeffs(int i, ExprIterator b, ExprIterator e);
84 | virtual void _getColCoeffs(int i, InsertIterator b) const;
85 |
86 | virtual void _setCoeff(int row, int col, Value value);
87 | virtual Value _getCoeff(int row, int col) const;
88 |
89 | virtual void _setColLowerBound(int i, Value value);
90 | virtual Value _getColLowerBound(int i) const;
91 | virtual void _setColUpperBound(int i, Value value);
92 | virtual Value _getColUpperBound(int i) const;
93 |
94 | virtual void _setRowLowerBound(int i, Value value);
95 | virtual Value _getRowLowerBound(int i) const;
96 | virtual void _setRowUpperBound(int i, Value value);
97 | virtual Value _getRowUpperBound(int i) const;
98 |
99 | virtual void _setObjCoeffs(ExprIterator b, ExprIterator e);
100 | virtual void _getObjCoeffs(InsertIterator b) const;
101 |
102 | virtual void _setObjCoeff(int i, Value obj_coef);
103 | virtual Value _getObjCoeff(int i) const;
104 |
105 | virtual void _setSense(Sense sense);
106 | virtual Sense _getSense() const;
107 |
108 | virtual ColTypes _getColType(int col) const;
109 | virtual void _setColType(int col, ColTypes col_type);
110 |
111 | virtual SolveExitStatus _solve();
112 | virtual ProblemType _getType() const;
113 | virtual Value _getSol(int i) const;
114 | virtual Value _getSolValue() const;
115 |
116 | virtual void _clear();
117 |
118 | virtual void _messageLevel(MessageLevel level);
119 | void _applyMessageLevel();
120 |
121 | int _message_level;
122 |
123 |
124 |
125 | };
126 |
127 | }
128 |
129 | #endif
130 |
--------------------------------------------------------------------------------
/test/nagamochi_ibaraki_test.cc:
--------------------------------------------------------------------------------
1 | /* -*- mode: C++; indent-tabs-mode: nil; -*-
2 | *
3 | * This file is a part of LEMON, a generic C++ optimization library.
4 | *
5 | * Copyright (C) 2003-2013
6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 | * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 | *
9 | * Permission to use, modify and distribute this software is granted
10 | * provided that this copyright notice appears in all copies. For
11 | * precise terms see the accompanying LICENSE file.
12 | *
13 | * This software is provided "AS IS" with no warranty of any kind,
14 | * express or implied, and with no claim as to its suitability for any
15 | * purpose.
16 | *
17 | */
18 |
19 | #include
20 |
21 | #include
22 | #include
23 | #include
24 | #include
25 | #include
26 | #include
27 |
28 | #include "test_tools.h"
29 |
30 | using namespace lemon;
31 | using namespace std;
32 |
33 | const std::string lgf =
34 | "@nodes\n"
35 | "label\n"
36 | "0\n"
37 | "1\n"
38 | "2\n"
39 | "3\n"
40 | "4\n"
41 | "5\n"
42 | "@edges\n"
43 | " cap1 cap2 cap3\n"
44 | "0 1 1 1 1 \n"
45 | "0 2 2 2 4 \n"
46 | "1 2 4 4 4 \n"
47 | "3 4 1 1 1 \n"
48 | "3 5 2 2 4 \n"
49 | "4 5 4 4 4 \n"
50 | "2 3 1 6 6 \n";
51 |
52 | void checkNagamochiIbarakiCompile()
53 | {
54 | typedef int Value;
55 | typedef concepts::Graph Graph;
56 |
57 | typedef Graph::Node Node;
58 | typedef Graph::Edge Edge;
59 | typedef concepts::ReadMap CapMap;
60 | typedef concepts::WriteMap CutMap;
61 |
62 | Graph g;
63 | Node n;
64 | CapMap cap;
65 | CutMap cut;
66 | Value v;
67 | bool b;
68 | ::lemon::ignore_unused_variable_warning(v,b);
69 |
70 | NagamochiIbaraki ni_test(g, cap);
71 | const NagamochiIbaraki& const_ni_test = ni_test;
72 |
73 | ni_test.init();
74 | ni_test.start();
75 | b = ni_test.processNextPhase();
76 | ni_test.run();
77 |
78 | v = const_ni_test.minCutValue();
79 | v = const_ni_test.minCutMap(cut);
80 | }
81 |
82 | template
83 | typename CapMap::Value
84 | cutValue(const Graph& graph, const CapMap& cap, const CutMap& cut)
85 | {
86 | typename CapMap::Value sum = 0;
87 | for (typename Graph::EdgeIt e(graph); e != INVALID; ++e) {
88 | if (cut[graph.u(e)] != cut[graph.v(e)]) {
89 | sum += cap[e];
90 | }
91 | }
92 | return sum;
93 | }
94 |
95 | int main() {
96 | SmartGraph graph;
97 | SmartGraph::EdgeMap cap1(graph), cap2(graph), cap3(graph);
98 | SmartGraph::NodeMap cut(graph);
99 |
100 | istringstream input(lgf);
101 | graphReader(graph, input)
102 | .edgeMap("cap1", cap1)
103 | .edgeMap("cap2", cap2)
104 | .edgeMap("cap3", cap3)
105 | .run();
106 |
107 | {
108 | NagamochiIbaraki ni(graph, cap1);
109 | ni.run();
110 | ni.minCutMap(cut);
111 |
112 | check(ni.minCutValue() == 1, "Wrong cut value");
113 | check(ni.minCutValue() == cutValue(graph, cap1, cut), "Wrong cut value");
114 | }
115 | {
116 | NagamochiIbaraki ni(graph, cap2);
117 | ni.run();
118 | ni.minCutMap(cut);
119 |
120 | check(ni.minCutValue() == 3, "Wrong cut value");
121 | check(ni.minCutValue() == cutValue(graph, cap2, cut), "Wrong cut value");
122 | }
123 | {
124 | NagamochiIbaraki ni(graph, cap3);
125 | ni.run();
126 | ni.minCutMap(cut);
127 |
128 | check(ni.minCutValue() == 5, "Wrong cut value");
129 | check(ni.minCutValue() == cutValue(graph, cap3, cut), "Wrong cut value");
130 | }
131 | {
132 | NagamochiIbaraki::SetUnitCapacity::Create ni(graph);
133 | ni.run();
134 | ni.minCutMap(cut);
135 |
136 | ConstMap cap4(1);
137 | check(ni.minCutValue() == 1, "Wrong cut value");
138 | check(ni.minCutValue() == cutValue(graph, cap4, cut), "Wrong cut value");
139 | }
140 |
141 | return 0;
142 | }
143 |
--------------------------------------------------------------------------------
/demo/arg_parser_demo.cc:
--------------------------------------------------------------------------------
1 | /* -*- mode: C++; indent-tabs-mode: nil; -*-
2 | *
3 | * This file is a part of LEMON, a generic C++ optimization library.
4 | *
5 | * Copyright (C) 2003-2010
6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 | * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 | *
9 | * Permission to use, modify and distribute this software is granted
10 | * provided that this copyright notice appears in all copies. For
11 | * precise terms see the accompanying LICENSE file.
12 | *
13 | * This software is provided "AS IS" with no warranty of any kind,
14 | * express or implied, and with no claim as to its suitability for any
15 | * purpose.
16 | *
17 | */
18 |
19 | ///\ingroup demos
20 | ///\file
21 | ///\brief Argument parser demo
22 | ///
23 | /// This example shows how the argument parser can be used.
24 | ///
25 | /// \include arg_parser_demo.cc
26 |
27 | #include
28 |
29 | using namespace lemon;
30 | int main(int argc, char **argv)
31 | {
32 | // Initialize the argument parser
33 | ArgParser ap(argc, argv);
34 | int i;
35 | std::string s;
36 | double d = 1.0;
37 | bool b, nh;
38 | bool g1, g2, g3;
39 |
40 | // Add a mandatory integer option with storage reference
41 | ap.refOption("n", "An integer input.", i, true);
42 | // Add a double option with storage reference (the default value is 1.0)
43 | ap.refOption("val", "A double input.", d);
44 | // Add a double option without storage reference (the default value is 3.14)
45 | ap.doubleOption("val2", "A double input.", 3.14);
46 | // Set synonym for -val option
47 | ap.synonym("vals", "val");
48 | // Add a string option
49 | ap.refOption("name", "A string input.", s);
50 | // Add bool options
51 | ap.refOption("f", "A switch.", b)
52 | .refOption("nohelp", "", nh)
53 | .refOption("gra", "Choice A", g1)
54 | .refOption("grb", "Choice B", g2)
55 | .refOption("grc", "Choice C", g3);
56 | // Bundle -gr* options into a group
57 | ap.optionGroup("gr", "gra")
58 | .optionGroup("gr", "grb")
59 | .optionGroup("gr", "grc");
60 | // Set the group mandatory
61 | ap.mandatoryGroup("gr");
62 | // Set the options of the group exclusive (only one option can be given)
63 | ap.onlyOneGroup("gr");
64 | // Add non-parsed arguments (e.g. input files)
65 | ap.other("infile", "The input file.")
66 | .other("...");
67 |
68 | // Throw an exception when problems occurs. The default behavior is to
69 | // exit(1) on these cases, but this makes Valgrind falsely warn
70 | // about memory leaks.
71 | ap.throwOnProblems();
72 |
73 | // Perform the parsing process
74 | // (in case of any error it terminates the program)
75 | // The try {} construct is necessary only if the ap.trowOnProblems()
76 | // setting is in use.
77 | try {
78 | ap.parse();
79 | } catch (ArgParserException &) { return 1; }
80 |
81 | // Check each option if it has been given and print its value
82 | std::cout << "Parameters of '" << ap.commandName() << "':\n";
83 |
84 | std::cout << " Value of -n: " << i << std::endl;
85 | if(ap.given("val")) std::cout << " Value of -val: " << d << std::endl;
86 | if(ap.given("val2")) {
87 | d = ap["val2"];
88 | std::cout << " Value of -val2: " << d << std::endl;
89 | }
90 | if(ap.given("name")) std::cout << " Value of -name: " << s << std::endl;
91 | if(ap.given("f")) std::cout << " -f is given\n";
92 | if(ap.given("nohelp")) std::cout << " Value of -nohelp: " << nh << std::endl;
93 | if(ap.given("gra")) std::cout << " -gra is given\n";
94 | if(ap.given("grb")) std::cout << " -grb is given\n";
95 | if(ap.given("grc")) std::cout << " -grc is given\n";
96 |
97 | switch(ap.files().size()) {
98 | case 0:
99 | std::cout << " No file argument was given.\n";
100 | break;
101 | case 1:
102 | std::cout << " 1 file argument was given. It is:\n";
103 | break;
104 | default:
105 | std::cout << " "
106 | << ap.files().size() << " file arguments were given. They are:\n";
107 | }
108 | for(unsigned int i=0;i
20 | #include
21 | #include "test_tools.h"
22 |
23 | using namespace lemon;
24 |
25 | char test_lgf[] =
26 | "@nodes\n"
27 | "label\n"
28 | "0\n"
29 | "1\n"
30 | "@arcs\n"
31 | " label\n"
32 | "0 1 0\n"
33 | "1 0 1\n"
34 | "@attributes\n"
35 | "source 0\n"
36 | "target 1\n";
37 |
38 | char test_lgf_nomap[] =
39 | "@nodes\n"
40 | "label\n"
41 | "0\n"
42 | "1\n"
43 | "@arcs\n"
44 | " -\n"
45 | "0 1\n";
46 |
47 | char test_lgf_bad1[] =
48 | "@nodes\n"
49 | "label\n"
50 | "0\n"
51 | "1\n"
52 | "@arcs\n"
53 | " - another\n"
54 | "0 1\n";
55 |
56 | char test_lgf_bad2[] =
57 | "@nodes\n"
58 | "label\n"
59 | "0\n"
60 | "1\n"
61 | "@arcs\n"
62 | " label -\n"
63 | "0 1\n";
64 |
65 |
66 | int main()
67 | {
68 | {
69 | ListDigraph d;
70 | ListDigraph::Node s,t;
71 | ListDigraph::ArcMap label(d);
72 | std::istringstream input(test_lgf);
73 | digraphReader(d, input).
74 | node("source", s).
75 | node("target", t).
76 | arcMap("label", label).
77 | run();
78 | check(countNodes(d) == 2,"There should be 2 nodes");
79 | check(countArcs(d) == 2,"There should be 2 arcs");
80 | }
81 | {
82 | ListGraph g;
83 | ListGraph::Node s,t;
84 | ListGraph::EdgeMap label(g);
85 | std::istringstream input(test_lgf);
86 | graphReader(g, input).
87 | node("source", s).
88 | node("target", t).
89 | edgeMap("label", label).
90 | run();
91 | check(countNodes(g) == 2,"There should be 2 nodes");
92 | check(countEdges(g) == 2,"There should be 2 arcs");
93 | }
94 |
95 | {
96 | ListDigraph d;
97 | std::istringstream input(test_lgf_nomap);
98 | digraphReader(d, input).
99 | run();
100 | check(countNodes(d) == 2,"There should be 2 nodes");
101 | check(countArcs(d) == 1,"There should be 1 arc");
102 | }
103 | {
104 | ListGraph g;
105 | std::istringstream input(test_lgf_nomap);
106 | graphReader(g, input).
107 | run();
108 | check(countNodes(g) == 2,"There should be 2 nodes");
109 | check(countEdges(g) == 1,"There should be 1 edge");
110 | }
111 |
112 | {
113 | ListDigraph d;
114 | std::istringstream input(test_lgf_bad1);
115 | bool ok=false;
116 | try {
117 | digraphReader(d, input).
118 | run();
119 | }
120 | catch (FormatError&)
121 | {
122 | ok = true;
123 | }
124 | check(ok,"FormatError exception should have occured");
125 | }
126 | {
127 | ListGraph g;
128 | std::istringstream input(test_lgf_bad1);
129 | bool ok=false;
130 | try {
131 | graphReader(g, input).
132 | run();
133 | }
134 | catch (FormatError&)
135 | {
136 | ok = true;
137 | }
138 | check(ok,"FormatError exception should have occured");
139 | }
140 |
141 | {
142 | ListDigraph d;
143 | std::istringstream input(test_lgf_bad2);
144 | bool ok=false;
145 | try {
146 | digraphReader(d, input).
147 | run();
148 | }
149 | catch (FormatError&)
150 | {
151 | ok = true;
152 | }
153 | check(ok,"FormatError exception should have occured");
154 | }
155 | {
156 | ListGraph g;
157 | std::istringstream input(test_lgf_bad2);
158 | bool ok=false;
159 | try {
160 | graphReader(g, input).
161 | run();
162 | }
163 | catch (FormatError&)
164 | {
165 | ok = true;
166 | }
167 | check(ok,"FormatError exception should have occured");
168 | }
169 | }
170 |
--------------------------------------------------------------------------------
/test/kruskal_test.cc:
--------------------------------------------------------------------------------
1 | /* -*- mode: C++; indent-tabs-mode: nil; -*-
2 | *
3 | * This file is a part of LEMON, a generic C++ optimization library.
4 | *
5 | * Copyright (C) 2003-2009
6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 | * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 | *
9 | * Permission to use, modify and distribute this software is granted
10 | * provided that this copyright notice appears in all copies. For
11 | * precise terms see the accompanying LICENSE file.
12 | *
13 | * This software is provided "AS IS" with no warranty of any kind,
14 | * express or implied, and with no claim as to its suitability for any
15 | * purpose.
16 | *
17 | */
18 |
19 | #include
20 | #include
21 |
22 | #include "test_tools.h"
23 | #include
24 | #include
25 | #include
26 |
27 | #include
28 | #include
29 | #include
30 |
31 | using namespace std;
32 | using namespace lemon;
33 |
34 | void checkCompileKruskal()
35 | {
36 | concepts::WriteMap w;
37 | concepts::WriteMap uw;
38 |
39 | concepts::ReadMap r;
40 | concepts::ReadMap ur;
41 |
42 | concepts::Digraph g;
43 | concepts::Graph ug;
44 |
45 | kruskal(g, r, w);
46 | kruskal(ug, ur, uw);
47 |
48 | std::vector > rs;
49 | std::vector > urs;
50 |
51 | kruskal(g, rs, w);
52 | kruskal(ug, urs, uw);
53 |
54 | std::vector ws;
55 | std::vector uws;
56 |
57 | kruskal(g, r, ws.begin());
58 | kruskal(ug, ur, uws.begin());
59 | }
60 |
61 | int main() {
62 |
63 | typedef ListGraph::Node Node;
64 | typedef ListGraph::Edge Edge;
65 | typedef ListGraph::NodeIt NodeIt;
66 | typedef ListGraph::ArcIt ArcIt;
67 |
68 | ListGraph G;
69 |
70 | Node s=G.addNode();
71 | Node v1=G.addNode();
72 | Node v2=G.addNode();
73 | Node v3=G.addNode();
74 | Node v4=G.addNode();
75 | Node t=G.addNode();
76 |
77 | Edge e1 = G.addEdge(s, v1);
78 | Edge e2 = G.addEdge(s, v2);
79 | Edge e3 = G.addEdge(v1, v2);
80 | Edge e4 = G.addEdge(v2, v1);
81 | Edge e5 = G.addEdge(v1, v3);
82 | Edge e6 = G.addEdge(v3, v2);
83 | Edge e7 = G.addEdge(v2, v4);
84 | Edge e8 = G.addEdge(v4, v3);
85 | Edge e9 = G.addEdge(v3, t);
86 | Edge e10 = G.addEdge(v4, t);
87 |
88 | typedef ListGraph::EdgeMap ECostMap;
89 | typedef ListGraph::EdgeMap EBoolMap;
90 |
91 | ECostMap edge_cost_map(G, 2);
92 | EBoolMap tree_map(G);
93 |
94 |
95 | //Test with const map.
96 | check(kruskal(G, ConstMap(2), tree_map)==10,
97 | "Total cost should be 10");
98 | //Test with an edge map (filled with uniform costs).
99 | check(kruskal(G, edge_cost_map, tree_map)==10,
100 | "Total cost should be 10");
101 |
102 | edge_cost_map[e1] = -10;
103 | edge_cost_map[e2] = -9;
104 | edge_cost_map[e3] = -8;
105 | edge_cost_map[e4] = -7;
106 | edge_cost_map[e5] = -6;
107 | edge_cost_map[e6] = -5;
108 | edge_cost_map[e7] = -4;
109 | edge_cost_map[e8] = -3;
110 | edge_cost_map[e9] = -2;
111 | edge_cost_map[e10] = -1;
112 |
113 | vector tree_edge_vec(5);
114 |
115 | //Test with a edge map and inserter.
116 | check(kruskal(G, edge_cost_map,
117 | tree_edge_vec.begin())
118 | ==-31,
119 | "Total cost should be -31.");
120 |
121 | tree_edge_vec.clear();
122 |
123 | check(kruskal(G, edge_cost_map,
124 | back_inserter(tree_edge_vec))
125 | ==-31,
126 | "Total cost should be -31.");
127 |
128 | // tree_edge_vec.clear();
129 |
130 | // //The above test could also be coded like this:
131 | // check(kruskal(G,
132 | // makeKruskalMapInput(G, edge_cost_map),
133 | // makeKruskalSequenceOutput(back_inserter(tree_edge_vec)))
134 | // ==-31,
135 | // "Total cost should be -31.");
136 |
137 | check(tree_edge_vec.size()==5,"The tree should have 5 edges.");
138 |
139 | check(tree_edge_vec[0]==e1 &&
140 | tree_edge_vec[1]==e2 &&
141 | tree_edge_vec[2]==e5 &&
142 | tree_edge_vec[3]==e7 &&
143 | tree_edge_vec[4]==e9,
144 | "Wrong tree.");
145 |
146 | return 0;
147 | }
148 |
--------------------------------------------------------------------------------
/doc/named-param.dox:
--------------------------------------------------------------------------------
1 | /* -*- mode: C++; indent-tabs-mode: nil; -*-
2 | *
3 | * This file is a part of LEMON, a generic C++ optimization library.
4 | *
5 | * Copyright (C) 2003-2009
6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 | * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 | *
9 | * Permission to use, modify and distribute this software is granted
10 | * provided that this copyright notice appears in all copies. For
11 | * precise terms see the accompanying LICENSE file.
12 | *
13 | * This software is provided "AS IS" with no warranty of any kind,
14 | * express or implied, and with no claim as to its suitability for any
15 | * purpose.
16 | *
17 | */
18 |
19 | /*!
20 |
21 | \page named-param Named Parameters
22 |
23 | \section named-func-param Named Function Parameters
24 |
25 | Several modern languages provide a convenient way to refer the
26 | function parameters by name also when you call the function. It is
27 | especially comfortable in case of a function having tons of parameters
28 | with natural default values. Sadly, C++ lack this amenity.
29 |
30 | However, with a crafty trick and with some little
31 | inconvenience, it is possible to emulate is.
32 | The example below shows how to do it.
33 |
34 | \code
35 | class namedFn
36 | {
37 | int _id;
38 | double _val;
39 | int _dim;
40 |
41 | public:
42 | namedFn() : _id(0), _val(1), _dim(2) {}
43 | namedFn& id(int p) { _id = p ; return *this; }
44 | namedFn& val(double p) { _val = p ; return *this; }
45 | namedFn& dim(int p) { _dim = p ; return *this; }
46 |
47 | run() {
48 | std::cout << "Here comes the function itself\n" <<
49 | << "With parameters "
50 | << _id << ", " << _val << ", " << _dim << std::endl;
51 | }
52 | };
53 | \endcode
54 |
55 | Then you can use it like this.
56 |
57 | \code
58 | namedFn().id(3).val(2).run();
59 | \endcode
60 |
61 | The trick is obvious, each "named parameter" changes one component of
62 | the underlying class, then gives back a reference to it. Finally,
63 | run() executes the algorithm itself.
64 |
65 | \note Although it is a class, namedFn is used pretty much like as it were
66 | a function. That it why we called it namedFn instead of \c NamedFn.
67 |
68 | \note In fact, the final .run() could be made unnecessary,
69 | because the algorithm could also be implemented in the destructor of
70 | \c namedFn instead. This however would make it impossible to implement
71 | functions with return values, and would also cause serious problems when
72 | implementing \ref named-templ-func-param "named template parameters".
73 | Therefore, by convention, .run() must be used
74 | explicitly to execute a function having named parameters
75 | everywhere in LEMON.
76 |
77 | \section named-templ-func-param Named Function Template Parameters
78 |
79 | A named parameter can also be a template function. The usage is
80 | exactly the same, but the implementation behind is a kind of black
81 | magic and they are the dirtiest part of the LEMON code.
82 |
83 | You will probably never need to know how it works, but if you really
84 | committed, have a look at \ref lemon/graph_to_eps.h for an example.
85 |
86 | \section traits-classes Traits Classes
87 |
88 | A similar game can also be played when defining classes. In this case
89 | the type of the class attributes can be changed. Initially we have to
90 | define a special class called Traits Class defining the
91 | default type of the attributes. Then the types of these attributes can
92 | be changed in the same way as described in the next section.
93 |
94 | See \ref lemon::DijkstraDefaultTraits for an
95 | example how a traits class implementation looks like.
96 |
97 | \section named-templ-param Named Class Template Parameters
98 |
99 | If we would like to change the type of an attribute in a class that
100 | was instantiated by using a traits class as a template parameter, and
101 | the class contains named parameters, we do not have to instantiate again
102 | the class with new traits class, but instead adaptor classes can
103 | be used as shown in the following example.
104 |
105 | \code
106 | Dijkstra<>::SetPredMap >::Create
107 | \endcode
108 |
109 | It can also be used in conjunction with other named template
110 | parameters in arbitrary order.
111 |
112 | \code
113 | Dijkstra<>::SetDistMap::SetPredMap >::Create
114 | \endcode
115 |
116 | The result will be an instantiated Dijkstra class, in which the
117 | DistMap and the PredMap is modified.
118 |
119 | */
120 |
--------------------------------------------------------------------------------
/tools/dimacs-to-lgf.cc:
--------------------------------------------------------------------------------
1 | /* -*- mode: C++; indent-tabs-mode: nil; -*-
2 | *
3 | * This file is a part of LEMON, a generic C++ optimization library.
4 | *
5 | * Copyright (C) 2003-2009
6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 | * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 | *
9 | * Permission to use, modify and distribute this software is granted
10 | * provided that this copyright notice appears in all copies. For
11 | * precise terms see the accompanying LICENSE file.
12 | *
13 | * This software is provided "AS IS" with no warranty of any kind,
14 | * express or implied, and with no claim as to its suitability for any
15 | * purpose.
16 | *
17 | */
18 |
19 | ///\ingroup tools
20 | ///\file
21 | ///\brief DIMACS to LGF converter.
22 | ///
23 | /// This program converts various DIMACS formats to the LEMON Digraph Format
24 | /// (LGF).
25 | ///
26 | /// See
27 | /// \code
28 | /// dimacs-to-lgf --help
29 | /// \endcode
30 | /// for more info on the usage.
31 |
32 | #include
33 | #include
34 | #include
35 |
36 | #include
37 | #include
38 | #include
39 |
40 | #include
41 | #include
42 |
43 | using namespace std;
44 | using namespace lemon;
45 |
46 |
47 | int main(int argc, const char *argv[]) {
48 | typedef SmartDigraph Digraph;
49 |
50 | typedef Digraph::Arc Arc;
51 | typedef Digraph::Node Node;
52 | typedef Digraph::ArcIt ArcIt;
53 | typedef Digraph::NodeIt NodeIt;
54 | typedef Digraph::ArcMap DoubleArcMap;
55 | typedef Digraph::NodeMap DoubleNodeMap;
56 |
57 | std::string inputName;
58 | std::string outputName;
59 |
60 | ArgParser ap(argc, argv);
61 | ap.other("[INFILE [OUTFILE]]",
62 | "If either the INFILE or OUTFILE file is missing the standard\n"
63 | " input/output will be used instead.")
64 | .run();
65 |
66 | ifstream input;
67 | ofstream output;
68 |
69 | switch(ap.files().size())
70 | {
71 | case 2:
72 | output.open(ap.files()[1].c_str());
73 | if (!output) {
74 | throw IoError("Cannot open the file for writing", ap.files()[1]);
75 | }
76 | case 1:
77 | input.open(ap.files()[0].c_str());
78 | if (!input) {
79 | throw IoError("File cannot be found", ap.files()[0]);
80 | }
81 | case 0:
82 | break;
83 | default:
84 | cerr << ap.commandName() << ": too many arguments\n";
85 | return 1;
86 | }
87 | istream& is = (ap.files().size()<1 ? cin : input);
88 | ostream& os = (ap.files().size()<2 ? cout : output);
89 |
90 | DimacsDescriptor desc = dimacsType(is);
91 | switch(desc.type)
92 | {
93 | case DimacsDescriptor::MIN:
94 | {
95 | Digraph digraph;
96 | DoubleArcMap lower(digraph), capacity(digraph), cost(digraph);
97 | DoubleNodeMap supply(digraph);
98 | readDimacsMin(is, digraph, lower, capacity, cost, supply, 0, desc);
99 | DigraphWriter(digraph, os).
100 | nodeMap("supply", supply).
101 | arcMap("lower", lower).
102 | arcMap("capacity", capacity).
103 | arcMap("cost", cost).
104 | attribute("problem","min").
105 | run();
106 | }
107 | break;
108 | case DimacsDescriptor::MAX:
109 | {
110 | Digraph digraph;
111 | Node s, t;
112 | DoubleArcMap capacity(digraph);
113 | readDimacsMax(is, digraph, capacity, s, t, 0, desc);
114 | DigraphWriter(digraph, os).
115 | arcMap("capacity", capacity).
116 | node("source", s).
117 | node("target", t).
118 | attribute("problem","max").
119 | run();
120 | }
121 | break;
122 | case DimacsDescriptor::SP:
123 | {
124 | Digraph digraph;
125 | Node s;
126 | DoubleArcMap capacity(digraph);
127 | readDimacsSp(is, digraph, capacity, s, desc);
128 | DigraphWriter(digraph, os).
129 | arcMap("capacity", capacity).
130 | node("source", s).
131 | attribute("problem","sp").
132 | run();
133 | }
134 | break;
135 | case DimacsDescriptor::MAT:
136 | {
137 | Digraph digraph;
138 | readDimacsMat(is, digraph,desc);
139 | DigraphWriter(digraph, os).
140 | attribute("problem","mat").
141 | run();
142 | }
143 | break;
144 | default:
145 | break;
146 | }
147 | return 0;
148 | }
149 |
--------------------------------------------------------------------------------
/test/max_cardinality_search_test.cc:
--------------------------------------------------------------------------------
1 | /* -*- mode: C++; indent-tabs-mode: nil; -*-
2 | *
3 | * This file is a part of LEMON, a generic C++ optimization library.
4 | *
5 | * Copyright (C) 2003-2013
6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 | * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 | *
9 | * Permission to use, modify and distribute this software is granted
10 | * provided that this copyright notice appears in all copies. For
11 | * precise terms see the accompanying LICENSE file.
12 | *
13 | * This software is provided "AS IS" with no warranty of any kind,
14 | * express or implied, and with no claim as to its suitability for any
15 | * purpose.
16 | *
17 | */
18 |
19 | #include
20 |
21 | #include "test_tools.h"
22 | #include
23 | #include
24 | #include
25 | #include
26 | #include
27 | #include
28 |
29 | using namespace lemon;
30 | using namespace std;
31 |
32 | char test_lgf[] =
33 | "@nodes\n"
34 | "label\n"
35 | "0\n"
36 | "1\n"
37 | "2\n"
38 | "3\n"
39 | "@arcs\n"
40 | " label capacity\n"
41 | "0 1 0 2\n"
42 | "1 0 1 2\n"
43 | "2 1 2 1\n"
44 | "2 3 3 3\n"
45 | "3 2 4 3\n"
46 | "3 1 5 5\n"
47 | "@attributes\n"
48 | "s 0\n"
49 | "x 1\n"
50 | "y 2\n"
51 | "z 3\n";
52 |
53 | void checkMaxCardSearchCompile() {
54 |
55 | typedef concepts::Digraph Digraph;
56 | typedef int Value;
57 | typedef Digraph::Node Node;
58 | typedef Digraph::Arc Arc;
59 | typedef concepts::ReadMap CapMap;
60 | typedef concepts::ReadWriteMap CardMap;
61 | typedef concepts::ReadWriteMap ProcMap;
62 | typedef Digraph::NodeMap HeapCrossRef;
63 |
64 | Digraph g;
65 | Node n,s;
66 | CapMap cap;
67 | CardMap card;
68 | ProcMap proc;
69 | HeapCrossRef crossref(g);
70 |
71 | typedef MaxCardinalitySearch
72 | ::SetCapacityMap
73 | ::SetCardinalityMap
74 | ::SetProcessedMap
75 | ::SetStandardHeap >
76 | ::Create MaxCardType;
77 |
78 | MaxCardType maxcard(g,cap);
79 | const MaxCardType& const_maxcard = maxcard;
80 |
81 | const MaxCardType::Heap& heap_const = const_maxcard.heap();
82 | MaxCardType::Heap& heap = const_cast(heap_const);
83 | maxcard.heap(heap,crossref);
84 |
85 | maxcard.capacityMap(cap).cardinalityMap(card).processedMap(proc);
86 |
87 | maxcard.init();
88 | maxcard.addSource(s);
89 | n = maxcard.nextNode();
90 | maxcard.processNextNode();
91 | maxcard.start();
92 | maxcard.run(s);
93 | maxcard.run();
94 | }
95 |
96 | void checkWithIntMap( std::istringstream& input)
97 | {
98 | typedef SmartDigraph Digraph;
99 | typedef Digraph::Node Node;
100 | typedef Digraph::ArcMap CapMap;
101 |
102 | Digraph g;
103 | Node s,x,y,z,a;
104 | CapMap cap(g);
105 |
106 | DigraphReader(g,input).
107 | arcMap("capacity", cap).
108 | node("s",s).
109 | node("x",x).
110 | node("y",y).
111 | node("z",z).
112 | run();
113 |
114 | MaxCardinalitySearch maxcard(g,cap);
115 |
116 | maxcard.init();
117 | maxcard.addSource(s);
118 | maxcard.start(x);
119 |
120 | check(maxcard.processed(s) && !maxcard.processed(x) &&
121 | !maxcard.processed(y), "Wrong processed()!");
122 |
123 | a=maxcard.nextNode();
124 | check(maxcard.processNextNode()==a,
125 | "Wrong nextNode() or processNextNode() return value!");
126 |
127 | check(maxcard.processed(a), "Wrong processNextNode()!");
128 |
129 | maxcard.start();
130 | check(maxcard.cardinality(x)==2 && maxcard.cardinality(y)>=4,
131 | "Wrong cardinalities!");
132 | }
133 |
134 | void checkWithConst1Map(std::istringstream &input) {
135 | typedef SmartDigraph Digraph;
136 | typedef Digraph::Node Node;
137 |
138 | Digraph g;
139 | Node s,x,y,z;
140 |
141 | DigraphReader(g,input).
142 | node("s",s).
143 | node("x",x).
144 | node("y",y).
145 | node("z",z).
146 | run();
147 |
148 | MaxCardinalitySearch maxcard(g);
149 | maxcard.run(s);
150 | check(maxcard.cardinality(x)==1 &&
151 | maxcard.cardinality(y)+maxcard.cardinality(z)==3,
152 | "Wrong cardinalities!");
153 | }
154 |
155 | int main() {
156 |
157 | std::istringstream input1(test_lgf);
158 | checkWithIntMap(input1);
159 |
160 | std::istringstream input2(test_lgf);
161 | checkWithConst1Map(input2);
162 | }
163 |
--------------------------------------------------------------------------------
/doc/lgf.dox:
--------------------------------------------------------------------------------
1 | /* -*- mode: C++; indent-tabs-mode: nil; -*-
2 | *
3 | * This file is a part of LEMON, a generic C++ optimization library.
4 | *
5 | * Copyright (C) 2003-2013
6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 | * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 | *
9 | * Permission to use, modify and distribute this software is granted
10 | * provided that this copyright notice appears in all copies. For
11 | * precise terms see the accompanying LICENSE file.
12 | *
13 | * This software is provided "AS IS" with no warranty of any kind,
14 | * express or implied, and with no claim as to its suitability for any
15 | * purpose.
16 | *
17 | */
18 |
19 | namespace lemon {
20 | /*!
21 |
22 |
23 |
24 | \page lgf-format LEMON Graph Format (LGF)
25 |
26 | The \e LGF is a column oriented
27 | file format for storing graphs and associated data like
28 | node and edge maps.
29 |
30 | Each line with \c '#' first non-whitespace
31 | character is considered as a comment line.
32 |
33 | Otherwise the file consists of sections starting with
34 | a header line. The header lines starts with an \c '@' character followed by the
35 | type of section. The standard section types are \c \@nodes, \c
36 | \@arcs and \c \@edges
37 | and \@attributes. Each header line may also have an optional
38 | \e name, which can be use to distinguish the sections of the same
39 | type.
40 |
41 | The standard sections are column oriented, each line consists of
42 | tokens separated by whitespaces. A token can be \e plain or
43 | \e quoted. A plain token is just a sequence of non-whitespace characters,
44 | while a quoted token is a
45 | character sequence surrounded by double quotes, and it can also
46 | contain whitespaces and escape sequences.
47 |
48 | The \c \@nodes section describes a set of nodes and associated
49 | maps. The first is a header line, its columns are the names of the
50 | maps appearing in the following lines.
51 | One of the maps must be called \c
52 | "label", which plays special role in the file.
53 | The following
54 | non-empty lines until the next section describes nodes of the
55 | graph. Each line contains the values of the node maps
56 | associated to the current node.
57 |
58 | \code
59 | @nodes
60 | label coordinates size title
61 | 1 (10,20) 10 "First node"
62 | 2 (80,80) 8 "Second node"
63 | 3 (40,10) 10 "Third node"
64 | \endcode
65 |
66 | The \e LGF files can also contain bipartite graphs, in this case a
67 | \c \@red_nodes and a \c \@blue_nodes sections describe the node set of the
68 | graph. If a map is in both of these sections, then it can be used as a
69 | regular node map.
70 |
71 | \code
72 | @red_nodes
73 | label only_red_map name
74 | 1 "cherry" "John"
75 | 2 "Santa Claus" "Jack"
76 | 3 "blood" "Jason"
77 | @blue_nodes
78 | label name
79 | 4 "Elisabeth"
80 | 5 "Eve"
81 | \endcode
82 |
83 | The \c \@arcs section is very similar to the \c \@nodes section,
84 | it again starts with a header line describing the names of the maps,
85 | but the \c "label" map is not obligatory here. The following lines
86 | describe the arcs. The first two tokens of each line are
87 | the source and the target node of the arc, respectively, then come the map
88 | values. The source and target tokens must be node labels.
89 |
90 | \code
91 | @arcs
92 | capacity
93 | 1 2 16
94 | 1 3 12
95 | 2 3 18
96 | \endcode
97 |
98 | If there is no map in the \c \@arcs section at all, then it must be
99 | indicated by a sole '-' sign in the first line.
100 |
101 | \code
102 | @arcs
103 | -
104 | 1 2
105 | 1 3
106 | 2 3
107 | \endcode
108 |
109 | The \c \@edges is just a synonym of \c \@arcs. The \@arcs section can
110 | also store the edge set of an undirected graph. In such case there is
111 | a conventional method for store arc maps in the file, if two columns
112 | have the same caption with \c '+' and \c '-' prefix, then these columns
113 | can be regarded as the values of an arc map.
114 |
115 | The \c \@attributes section contains key-value pairs, each line
116 | consists of two tokens, an attribute name, and then an attribute
117 | value. The value of the attribute could be also a label value of a
118 | node or an edge, or even an edge label prefixed with \c '+' or \c '-',
119 | which regards to the forward or backward directed arc of the
120 | corresponding edge.
121 |
122 | \code
123 | @attributes
124 | source 1
125 | target 3
126 | caption "LEMON test digraph"
127 | \endcode
128 |
129 | The \e LGF can contain extra sections, but there is no restriction on
130 | the format of such sections.
131 |
132 | */
133 | }
134 |
135 | // LocalWords: whitespace whitespaces
136 |
--------------------------------------------------------------------------------
/test/hao_orlin_test.cc:
--------------------------------------------------------------------------------
1 | /* -*- mode: C++; indent-tabs-mode: nil; -*-
2 | *
3 | * This file is a part of LEMON, a generic C++ optimization library.
4 | *
5 | * Copyright (C) 2003-2013
6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 | * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 | *
9 | * Permission to use, modify and distribute this software is granted
10 | * provided that this copyright notice appears in all copies. For
11 | * precise terms see the accompanying LICENSE file.
12 | *
13 | * This software is provided "AS IS" with no warranty of any kind,
14 | * express or implied, and with no claim as to its suitability for any
15 | * purpose.
16 | *
17 | */
18 |
19 | #include
20 |
21 | #include
22 | #include
23 | #include
24 | #include
25 | #include
26 | #include
27 |
28 | #include "test_tools.h"
29 |
30 | using namespace lemon;
31 | using namespace std;
32 |
33 | const std::string lgf =
34 | "@nodes\n"
35 | "label\n"
36 | "0\n"
37 | "1\n"
38 | "2\n"
39 | "3\n"
40 | "4\n"
41 | "5\n"
42 | "@edges\n"
43 | " cap1 cap2 cap3\n"
44 | "0 1 1 1 1 \n"
45 | "0 2 2 2 4 \n"
46 | "1 2 4 4 4 \n"
47 | "3 4 1 1 1 \n"
48 | "3 5 2 2 4 \n"
49 | "4 5 4 4 4 \n"
50 | "5 4 4 4 4 \n"
51 | "2 3 1 6 6 \n"
52 | "4 0 1 6 6 \n";
53 |
54 | void checkHaoOrlinCompile()
55 | {
56 | typedef int Value;
57 | typedef concepts::Digraph Digraph;
58 |
59 | typedef Digraph::Node Node;
60 | typedef Digraph::Arc Arc;
61 | typedef concepts::ReadMap CapMap;
62 | typedef concepts::WriteMap CutMap;
63 |
64 | Digraph g;
65 | Node n;
66 | CapMap cap;
67 | CutMap cut;
68 | Value v;
69 | ::lemon::ignore_unused_variable_warning(v);
70 |
71 | HaoOrlin ho_test(g, cap);
72 | const HaoOrlin&
73 | const_ho_test = ho_test;
74 |
75 | ho_test.init();
76 | ho_test.init(n);
77 | ho_test.calculateOut();
78 | ho_test.calculateIn();
79 | ho_test.run();
80 | ho_test.run(n);
81 |
82 | v = const_ho_test.minCutValue();
83 | v = const_ho_test.minCutMap(cut);
84 | }
85 |
86 | template
87 | typename CapMap::Value
88 | cutValue(const Graph& graph, const CapMap& cap, const CutMap& cut)
89 | {
90 | typename CapMap::Value sum = 0;
91 | for (typename Graph::ArcIt a(graph); a != INVALID; ++a) {
92 | if (cut[graph.source(a)] && !cut[graph.target(a)])
93 | sum += cap[a];
94 | }
95 | return sum;
96 | }
97 |
98 | int main() {
99 | SmartDigraph graph;
100 | SmartDigraph::ArcMap cap1(graph), cap2(graph), cap3(graph);
101 | SmartDigraph::NodeMap cut(graph);
102 |
103 | istringstream input(lgf);
104 | digraphReader(graph, input)
105 | .arcMap("cap1", cap1)
106 | .arcMap("cap2", cap2)
107 | .arcMap("cap3", cap3)
108 | .run();
109 |
110 | {
111 | HaoOrlin ho(graph, cap1);
112 | ho.run();
113 | ho.minCutMap(cut);
114 |
115 | check(ho.minCutValue() == 1, "Wrong cut value");
116 | check(ho.minCutValue() == cutValue(graph, cap1, cut), "Wrong cut value");
117 | }
118 | {
119 | HaoOrlin ho(graph, cap2);
120 | ho.run();
121 | ho.minCutMap(cut);
122 |
123 | check(ho.minCutValue() == 1, "Wrong cut value");
124 | check(ho.minCutValue() == cutValue(graph, cap2, cut), "Wrong cut value");
125 | }
126 | {
127 | HaoOrlin ho(graph, cap3);
128 | ho.run();
129 | ho.minCutMap(cut);
130 |
131 | check(ho.minCutValue() == 1, "Wrong cut value");
132 | check(ho.minCutValue() == cutValue(graph, cap3, cut), "Wrong cut value");
133 | }
134 |
135 | typedef Undirector UGraph;
136 | UGraph ugraph(graph);
137 |
138 | {
139 | HaoOrlin > ho(ugraph, cap1);
140 | ho.run();
141 | ho.minCutMap(cut);
142 |
143 | check(ho.minCutValue() == 2, "Wrong cut value");
144 | check(ho.minCutValue() == cutValue(ugraph, cap1, cut), "Wrong cut value");
145 | }
146 | {
147 | HaoOrlin > ho(ugraph, cap2);
148 | ho.run();
149 | ho.minCutMap(cut);
150 |
151 | check(ho.minCutValue() == 5, "Wrong cut value");
152 | check(ho.minCutValue() == cutValue(ugraph, cap2, cut), "Wrong cut value");
153 | }
154 | {
155 | HaoOrlin > ho(ugraph, cap3);
156 | ho.run();
157 | ho.minCutMap(cut);
158 |
159 | check(ho.minCutValue() == 5, "Wrong cut value");
160 | check(ho.minCutValue() == cutValue(ugraph, cap3, cut), "Wrong cut value");
161 | }
162 |
163 | return 0;
164 | }
165 |
--------------------------------------------------------------------------------
/lemon/bits/windows.cc:
--------------------------------------------------------------------------------
1 | /* -*- mode: C++; indent-tabs-mode: nil; -*-
2 | *
3 | * This file is a part of LEMON, a generic C++ optimization library.
4 | *
5 | * Copyright (C) 2003-2013
6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 | * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 | *
9 | * Permission to use, modify and distribute this software is granted
10 | * provided that this copyright notice appears in all copies. For
11 | * precise terms see the accompanying LICENSE file.
12 | *
13 | * This software is provided "AS IS" with no warranty of any kind,
14 | * express or implied, and with no claim as to its suitability for any
15 | * purpose.
16 | *
17 | */
18 |
19 | ///\file
20 | ///\brief Some basic non-inline functions and static global data.
21 |
22 | #include
23 |
24 | #ifdef WIN32
25 | #ifndef WIN32_LEAN_AND_MEAN
26 | #define WIN32_LEAN_AND_MEAN
27 | #endif
28 | #ifndef NOMINMAX
29 | #define NOMINMAX
30 | #endif
31 | #ifdef UNICODE
32 | #undef UNICODE
33 | #endif
34 | #include
35 | #ifdef LOCALE_INVARIANT
36 | #define MY_LOCALE LOCALE_INVARIANT
37 | #else
38 | #define MY_LOCALE LOCALE_NEUTRAL
39 | #endif
40 | #else
41 | #include
42 | #include