├── 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 43 | #ifndef WIN32 44 | #include 45 | #endif 46 | #include 47 | #endif 48 | 49 | #include 50 | #include 51 | 52 | namespace lemon { 53 | namespace bits { 54 | void getWinProcTimes(double &rtime, 55 | double &utime, double &stime, 56 | double &cutime, double &cstime) 57 | { 58 | #ifdef WIN32 59 | static const double ch = 4294967296.0e-7; 60 | static const double cl = 1.0e-7; 61 | 62 | FILETIME system; 63 | GetSystemTimeAsFileTime(&system); 64 | rtime = ch * system.dwHighDateTime + cl * system.dwLowDateTime; 65 | 66 | FILETIME create, exit, kernel, user; 67 | if (GetProcessTimes(GetCurrentProcess(),&create, &exit, &kernel, &user)) { 68 | utime = ch * user.dwHighDateTime + cl * user.dwLowDateTime; 69 | stime = ch * kernel.dwHighDateTime + cl * kernel.dwLowDateTime; 70 | cutime = 0; 71 | cstime = 0; 72 | } else { 73 | rtime = 0; 74 | utime = 0; 75 | stime = 0; 76 | cutime = 0; 77 | cstime = 0; 78 | } 79 | #else 80 | timeval tv; 81 | gettimeofday(&tv, 0); 82 | rtime=tv.tv_sec+double(tv.tv_usec)/1e6; 83 | 84 | tms ts; 85 | double tck=sysconf(_SC_CLK_TCK); 86 | times(&ts); 87 | utime=ts.tms_utime/tck; 88 | stime=ts.tms_stime/tck; 89 | cutime=ts.tms_cutime/tck; 90 | cstime=ts.tms_cstime/tck; 91 | #endif 92 | } 93 | 94 | std::string getWinFormattedDate() 95 | { 96 | std::ostringstream os; 97 | #ifdef WIN32 98 | SYSTEMTIME time; 99 | GetSystemTime(&time); 100 | char buf1[11], buf2[9], buf3[5]; 101 | if (GetDateFormat(MY_LOCALE, 0, &time, 102 | ("ddd MMM dd"), buf1, 11) && 103 | GetTimeFormat(MY_LOCALE, 0, &time, 104 | ("HH':'mm':'ss"), buf2, 9) && 105 | GetDateFormat(MY_LOCALE, 0, &time, 106 | ("yyyy"), buf3, 5)) { 107 | os << buf1 << ' ' << buf2 << ' ' << buf3; 108 | } 109 | else os << "unknown"; 110 | #else 111 | timeval tv; 112 | gettimeofday(&tv, 0); 113 | 114 | char cbuf[26]; 115 | ctime_r(&tv.tv_sec,cbuf); 116 | os << cbuf; 117 | #endif 118 | return os.str(); 119 | } 120 | 121 | int getWinRndSeed() 122 | { 123 | #ifdef WIN32 124 | FILETIME time; 125 | GetSystemTimeAsFileTime(&time); 126 | return GetCurrentProcessId() + time.dwHighDateTime + time.dwLowDateTime; 127 | #else 128 | timeval tv; 129 | gettimeofday(&tv, 0); 130 | return getpid() + tv.tv_sec + tv.tv_usec; 131 | #endif 132 | } 133 | 134 | WinLock::WinLock() { 135 | #ifdef WIN32 136 | CRITICAL_SECTION *lock = new CRITICAL_SECTION; 137 | InitializeCriticalSection(lock); 138 | _repr = lock; 139 | #else 140 | _repr = 0; //Just to avoid 'unused variable' warning with clang 141 | #endif 142 | } 143 | 144 | WinLock::~WinLock() { 145 | #ifdef WIN32 146 | CRITICAL_SECTION *lock = static_cast(_repr); 147 | DeleteCriticalSection(lock); 148 | delete lock; 149 | #endif 150 | } 151 | 152 | void WinLock::lock() { 153 | #ifdef WIN32 154 | CRITICAL_SECTION *lock = static_cast(_repr); 155 | EnterCriticalSection(lock); 156 | #endif 157 | } 158 | 159 | void WinLock::unlock() { 160 | #ifdef WIN32 161 | CRITICAL_SECTION *lock = static_cast(_repr); 162 | LeaveCriticalSection(lock); 163 | #endif 164 | } 165 | } 166 | } 167 | -------------------------------------------------------------------------------- /doc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | SET(PACKAGE_NAME ${PROJECT_NAME}) 2 | SET(PACKAGE_VERSION ${PROJECT_VERSION}) 3 | SET(abs_top_srcdir ${PROJECT_SOURCE_DIR}) 4 | SET(abs_top_builddir ${PROJECT_BINARY_DIR}) 5 | 6 | SET(LEMON_DOC_SOURCE_BROWSER "NO" CACHE STRING "Include source into the doc (YES/NO).") 7 | SET(LEMON_DOC_USE_MATHJAX "NO" CACHE STRING "Use MathJax to display math formulae (YES/NO).") 8 | SET(LEMON_DOC_MATHJAX_RELPATH "http://www.mathjax.org/mathjax" CACHE STRING "MathJax library location.") 9 | 10 | SET(LEMON_DOC_LIBSTDC++_URL 11 | "http://gcc.gnu.org/onlinedocs/gcc-4.7.3/libstdc++/api" 12 | CACHE STRING "GCC libstdc++ doxygen doc url.") 13 | 14 | 15 | CONFIGURE_FILE( 16 | ${PROJECT_SOURCE_DIR}/doc/Doxyfile.in 17 | ${PROJECT_BINARY_DIR}/doc/Doxyfile 18 | @ONLY 19 | ) 20 | 21 | CONFIGURE_FILE( 22 | ${PROJECT_SOURCE_DIR}/doc/mainpage.dox.in 23 | ${PROJECT_BINARY_DIR}/doc/mainpage.dox 24 | @ONLY 25 | ) 26 | 27 | # Copy doc from source (if exists) 28 | IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/html AND 29 | NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/html/index.html) 30 | MESSAGE(STATUS "Copy doc from source tree") 31 | EXECUTE_PROCESS( 32 | COMMAND cmake -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/html ${CMAKE_CURRENT_BINARY_DIR}/html 33 | ) 34 | ENDIF() 35 | 36 | IF(DOXYGEN_EXECUTABLE AND PYTHONINTERP_FOUND AND GHOSTSCRIPT_EXECUTABLE) 37 | FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html/) 38 | SET(GHOSTSCRIPT_OPTIONS -dNOPAUSE -dBATCH -q -dEPSCrop -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDEVICE=pngalpha) 39 | ADD_CUSTOM_TARGET(html 40 | COMMAND ${CMAKE_COMMAND} -E remove_directory gen-images 41 | COMMAND ${CMAKE_COMMAND} -E make_directory gen-images 42 | COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r20 -sOutputFile=gen-images/grid_graph.png ${CMAKE_CURRENT_SOURCE_DIR}/images/grid_graph.eps 43 | COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r32 -sOutputFile=gen-images/adaptors2.png ${CMAKE_CURRENT_SOURCE_DIR}/images/adaptors2.eps 44 | COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r32 -sOutputFile=gen-images/connected_components.png ${CMAKE_CURRENT_SOURCE_DIR}/images/connected_components.eps 45 | COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r32 -sOutputFile=gen-images/strongly_connected_components.png ${CMAKE_CURRENT_SOURCE_DIR}/images/strongly_connected_components.eps 46 | COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r32 -sOutputFile=gen-images/node_biconnected_components.png ${CMAKE_CURRENT_SOURCE_DIR}/images/node_biconnected_components.eps 47 | COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r32 -sOutputFile=gen-images/edge_biconnected_components.png ${CMAKE_CURRENT_SOURCE_DIR}/images/edge_biconnected_components.eps 48 | COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r32 -sOutputFile=gen-images/bipartite_partitions.png ${CMAKE_CURRENT_SOURCE_DIR}/images/bipartite_partitions.eps 49 | COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r24 -sOutputFile=gen-images/matching.png ${CMAKE_CURRENT_SOURCE_DIR}/images/matching.eps 50 | COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r24 -sOutputFile=gen-images/bipartite_matching.png ${CMAKE_CURRENT_SOURCE_DIR}/images/bipartite_matching.eps 51 | COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r40 -sOutputFile=gen-images/planar.png ${CMAKE_CURRENT_SOURCE_DIR}/images/planar.eps 52 | COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r24 -sOutputFile=gen-images/tsp.png ${CMAKE_CURRENT_SOURCE_DIR}/images/tsp.eps 53 | COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r8 -sOutputFile=gen-images/nodeshape_0.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_0.eps 54 | COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r8 -sOutputFile=gen-images/nodeshape_1.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_1.eps 55 | COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r8 -sOutputFile=gen-images/nodeshape_2.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_2.eps 56 | COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r8 -sOutputFile=gen-images/nodeshape_3.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_3.eps 57 | COMMAND ${GHOSTSCRIPT_EXECUTABLE} ${GHOSTSCRIPT_OPTIONS} -r8 -sOutputFile=gen-images/nodeshape_4.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_4.eps 58 | COMMAND ${CMAKE_COMMAND} -E remove_directory html 59 | COMMAND ${DOXYGEN_EXECUTABLE} Doxyfile 60 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} 61 | ) 62 | 63 | SET_TARGET_PROPERTIES(html PROPERTIES PROJECT_LABEL BUILD_DOC) 64 | 65 | IF(UNIX) 66 | INSTALL( 67 | DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html/ 68 | DESTINATION share/doc/lemon/html 69 | COMPONENT html_documentation 70 | ) 71 | ELSEIF(WIN32) 72 | INSTALL( 73 | DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html/ 74 | DESTINATION doc 75 | COMPONENT html_documentation 76 | ) 77 | ENDIF() 78 | 79 | ENDIF() 80 | 81 | IF(WGET_FOUND) 82 | ADD_CUSTOM_TARGET(update-external-tags 83 | COMMAND ${WGET_EXECUTABLE} -N ${LEMON_DOC_LIBSTDC++_URL}/libstdc++.tag 84 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} 85 | ) 86 | ENDIF() 87 | -------------------------------------------------------------------------------- /test/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(TEST_WITH_VALGRIND "NO" CACHE STRING 11 | "Run the test with valgrind (YES/NO).") 12 | SET(VALGRIND_FLAGS "" CACHE STRING "Valgrind flags used by the tests.") 13 | 14 | SET(TESTS 15 | adaptors_test 16 | arc_look_up_test 17 | bellman_ford_test 18 | bfs_test 19 | bpgraph_test 20 | circulation_test 21 | connectivity_test 22 | counter_test 23 | dfs_test 24 | digraph_test 25 | dijkstra_test 26 | dim_test 27 | edge_set_test 28 | error_test 29 | euler_test 30 | fractional_matching_test 31 | gomory_hu_test 32 | graph_copy_test 33 | graph_test 34 | graph_utils_test 35 | hao_orlin_test 36 | heap_test 37 | kruskal_test 38 | lgf_reader_writer_test 39 | lgf_test 40 | maps_test 41 | matching_test 42 | max_cardinality_search_test 43 | max_clique_test 44 | max_flow_test 45 | min_cost_arborescence_test 46 | min_cost_flow_test 47 | min_mean_cycle_test 48 | nagamochi_ibaraki_test 49 | path_test 50 | planarity_test 51 | radix_sort_test 52 | random_test 53 | suurballe_test 54 | time_measure_test 55 | tsp_test 56 | unionfind_test 57 | ) 58 | 59 | IF(LEMON_HAVE_LP) 60 | IF(${CMAKE_BUILD_TYPE} STREQUAL "Maintainer") 61 | ADD_EXECUTABLE(lp_test lp_test.cc) 62 | ELSE() 63 | ADD_EXECUTABLE(lp_test EXCLUDE_FROM_ALL lp_test.cc) 64 | ENDIF() 65 | 66 | SET(LP_TEST_LIBS lemon) 67 | 68 | IF(LEMON_HAVE_GLPK) 69 | SET(LP_TEST_LIBS ${LP_TEST_LIBS} ${GLPK_LIBRARIES}) 70 | ENDIF() 71 | IF(LEMON_HAVE_CPLEX) 72 | SET(LP_TEST_LIBS ${LP_TEST_LIBS} ${ILOG_LIBRARIES}) 73 | ENDIF() 74 | IF(LEMON_HAVE_CLP) 75 | SET(LP_TEST_LIBS ${LP_TEST_LIBS} ${COIN_CLP_LIBRARIES}) 76 | ENDIF() 77 | IF(LEMON_HAVE_SOPLEX) 78 | SET(LP_TEST_LIBS ${LP_TEST_LIBS} ${SOPLEX_LIBRARIES}) 79 | ENDIF() 80 | 81 | TARGET_LINK_LIBRARIES(lp_test ${LP_TEST_LIBS}) 82 | ADD_TEST(lp_test lp_test) 83 | ADD_DEPENDENCIES(check lp_test) 84 | 85 | IF(WIN32 AND LEMON_HAVE_GLPK) 86 | GET_TARGET_PROPERTY(TARGET_LOC lp_test LOCATION) 87 | GET_FILENAME_COMPONENT(TARGET_PATH ${TARGET_LOC} PATH) 88 | ADD_CUSTOM_COMMAND(TARGET lp_test POST_BUILD 89 | COMMAND ${CMAKE_COMMAND} -E copy ${GLPK_BIN_DIR}/glpk.dll ${TARGET_PATH} 90 | COMMAND ${CMAKE_COMMAND} -E copy ${GLPK_BIN_DIR}/libltdl3.dll ${TARGET_PATH} 91 | COMMAND ${CMAKE_COMMAND} -E copy ${GLPK_BIN_DIR}/zlib1.dll ${TARGET_PATH} 92 | ) 93 | ENDIF() 94 | 95 | IF(WIN32 AND LEMON_HAVE_CPLEX) 96 | GET_TARGET_PROPERTY(TARGET_LOC lp_test LOCATION) 97 | GET_FILENAME_COMPONENT(TARGET_PATH ${TARGET_LOC} PATH) 98 | ADD_CUSTOM_COMMAND(TARGET lp_test POST_BUILD 99 | COMMAND ${CMAKE_COMMAND} -E copy ${ILOG_CPLEX_DLL} ${TARGET_PATH} 100 | ) 101 | ENDIF() 102 | ENDIF() 103 | 104 | IF(LEMON_HAVE_MIP) 105 | IF(${CMAKE_BUILD_TYPE} STREQUAL "Maintainer") 106 | ADD_EXECUTABLE(mip_test mip_test.cc) 107 | ELSE() 108 | ADD_EXECUTABLE(mip_test EXCLUDE_FROM_ALL mip_test.cc) 109 | ENDIF() 110 | 111 | SET(MIP_TEST_LIBS lemon) 112 | 113 | IF(LEMON_HAVE_GLPK) 114 | SET(MIP_TEST_LIBS ${MIP_TEST_LIBS} ${GLPK_LIBRARIES}) 115 | ENDIF() 116 | IF(LEMON_HAVE_CPLEX) 117 | SET(MIP_TEST_LIBS ${MIP_TEST_LIBS} ${ILOG_LIBRARIES}) 118 | ENDIF() 119 | IF(LEMON_HAVE_CBC) 120 | SET(MIP_TEST_LIBS ${MIP_TEST_LIBS} ${COIN_CBC_LIBRARIES}) 121 | ENDIF() 122 | 123 | TARGET_LINK_LIBRARIES(mip_test ${MIP_TEST_LIBS}) 124 | ADD_TEST(mip_test mip_test) 125 | ADD_DEPENDENCIES(check mip_test) 126 | 127 | IF(WIN32 AND LEMON_HAVE_GLPK) 128 | GET_TARGET_PROPERTY(TARGET_LOC mip_test LOCATION) 129 | GET_FILENAME_COMPONENT(TARGET_PATH ${TARGET_LOC} PATH) 130 | ADD_CUSTOM_COMMAND(TARGET mip_test POST_BUILD 131 | COMMAND ${CMAKE_COMMAND} -E copy ${GLPK_BIN_DIR}/glpk.dll ${TARGET_PATH} 132 | COMMAND ${CMAKE_COMMAND} -E copy ${GLPK_BIN_DIR}/libltdl3.dll ${TARGET_PATH} 133 | COMMAND ${CMAKE_COMMAND} -E copy ${GLPK_BIN_DIR}/zlib1.dll ${TARGET_PATH} 134 | ) 135 | ENDIF() 136 | 137 | IF(WIN32 AND LEMON_HAVE_CPLEX) 138 | GET_TARGET_PROPERTY(TARGET_LOC mip_test LOCATION) 139 | GET_FILENAME_COMPONENT(TARGET_PATH ${TARGET_LOC} PATH) 140 | ADD_CUSTOM_COMMAND(TARGET mip_test POST_BUILD 141 | COMMAND ${CMAKE_COMMAND} -E copy ${ILOG_CPLEX_DLL} ${TARGET_PATH} 142 | ) 143 | ENDIF() 144 | ENDIF() 145 | 146 | FOREACH(TEST_NAME ${TESTS}) 147 | IF(${CMAKE_BUILD_TYPE} STREQUAL "Maintainer") 148 | ADD_EXECUTABLE(${TEST_NAME} ${TEST_NAME}.cc) 149 | ELSE() 150 | ADD_EXECUTABLE(${TEST_NAME} EXCLUDE_FROM_ALL ${TEST_NAME}.cc) 151 | ENDIF() 152 | TARGET_LINK_LIBRARIES(${TEST_NAME} lemon) 153 | IF(TEST_WITH_VALGRIND) 154 | ADD_TEST(${TEST_NAME} 155 | valgrind --error-exitcode=1 ${VALGRIND_FLAGS} 156 | ${CMAKE_CURRENT_BINARY_DIR}/${TEST_NAME} ) 157 | ELSE() 158 | ADD_TEST(${TEST_NAME} ${TEST_NAME}) 159 | ENDIF() 160 | ADD_DEPENDENCIES(check ${TEST_NAME}) 161 | ENDFOREACH() 162 | -------------------------------------------------------------------------------- /test/circulation_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 | 28 | using namespace lemon; 29 | 30 | char test_lgf[] = 31 | "@nodes\n" 32 | "label\n" 33 | "0\n" 34 | "1\n" 35 | "2\n" 36 | "3\n" 37 | "4\n" 38 | "5\n" 39 | "@arcs\n" 40 | " lcap ucap\n" 41 | "0 1 2 10\n" 42 | "0 2 2 6\n" 43 | "1 3 4 7\n" 44 | "1 4 0 5\n" 45 | "2 4 1 3\n" 46 | "3 5 3 8\n" 47 | "4 5 3 7\n" 48 | "@attributes\n" 49 | "source 0\n" 50 | "sink 5\n"; 51 | 52 | void checkCirculationCompile() 53 | { 54 | typedef int VType; 55 | typedef concepts::Digraph Digraph; 56 | 57 | typedef Digraph::Node Node; 58 | typedef Digraph::Arc Arc; 59 | typedef concepts::ReadMap CapMap; 60 | typedef concepts::ReadMap SupplyMap; 61 | typedef concepts::ReadWriteMap FlowMap; 62 | typedef concepts::WriteMap BarrierMap; 63 | 64 | typedef Elevator Elev; 65 | typedef LinkedElevator LinkedElev; 66 | 67 | Digraph g; 68 | Node n; 69 | Arc a; 70 | CapMap lcap, ucap; 71 | SupplyMap supply; 72 | FlowMap flow; 73 | BarrierMap bar; 74 | VType v; 75 | bool b; 76 | ::lemon::ignore_unused_variable_warning(v,b); 77 | 78 | typedef Circulation 79 | ::SetFlowMap 80 | ::SetElevator 81 | ::SetStandardElevator 82 | ::Create CirculationType; 83 | CirculationType circ_test(g, lcap, ucap, supply); 84 | const CirculationType& const_circ_test = circ_test; 85 | 86 | circ_test 87 | .lowerMap(lcap) 88 | .upperMap(ucap) 89 | .supplyMap(supply) 90 | .flowMap(flow); 91 | 92 | const CirculationType::Elevator& elev = const_circ_test.elevator(); 93 | circ_test.elevator(const_cast(elev)); 94 | CirculationType::Tolerance tol = const_circ_test.tolerance(); 95 | circ_test.tolerance(tol); 96 | 97 | circ_test.init(); 98 | circ_test.greedyInit(); 99 | circ_test.start(); 100 | circ_test.run(); 101 | 102 | v = const_circ_test.flow(a); 103 | const FlowMap& fm = const_circ_test.flowMap(); 104 | b = const_circ_test.barrier(n); 105 | const_circ_test.barrierMap(bar); 106 | 107 | ::lemon::ignore_unused_variable_warning(fm); 108 | } 109 | 110 | template 111 | void checkCirculation(const G& g, const LM& lm, const UM& um, 112 | const DM& dm, bool find) 113 | { 114 | Circulation circ(g, lm, um, dm); 115 | bool ret = circ.run(); 116 | if (find) { 117 | check(ret, "A feasible solution should have been found."); 118 | check(circ.checkFlow(), "The found flow is corrupt."); 119 | check(!circ.checkBarrier(), "A barrier should not have been found."); 120 | } else { 121 | check(!ret, "A feasible solution should not have been found."); 122 | check(circ.checkBarrier(), "The found barrier is corrupt."); 123 | } 124 | } 125 | 126 | int main (int, char*[]) 127 | { 128 | typedef ListDigraph Digraph; 129 | DIGRAPH_TYPEDEFS(Digraph); 130 | 131 | Digraph g; 132 | IntArcMap lo(g), up(g); 133 | IntNodeMap delta(g, 0); 134 | Node s, t; 135 | 136 | std::istringstream input(test_lgf); 137 | DigraphReader(g,input). 138 | arcMap("lcap", lo). 139 | arcMap("ucap", up). 140 | node("source",s). 141 | node("sink",t). 142 | run(); 143 | 144 | delta[s] = 7; delta[t] = -7; 145 | checkCirculation(g, lo, up, delta, true); 146 | 147 | delta[s] = 13; delta[t] = -13; 148 | checkCirculation(g, lo, up, delta, true); 149 | 150 | delta[s] = 6; delta[t] = -6; 151 | checkCirculation(g, lo, up, delta, false); 152 | 153 | delta[s] = 14; delta[t] = -14; 154 | checkCirculation(g, lo, up, delta, false); 155 | 156 | delta[s] = 7; delta[t] = -13; 157 | checkCirculation(g, lo, up, delta, true); 158 | 159 | delta[s] = 5; delta[t] = -15; 160 | checkCirculation(g, lo, up, delta, true); 161 | 162 | delta[s] = 10; delta[t] = -11; 163 | checkCirculation(g, lo, up, delta, true); 164 | 165 | delta[s] = 11; delta[t] = -10; 166 | checkCirculation(g, lo, up, delta, false); 167 | 168 | return 0; 169 | } 170 | -------------------------------------------------------------------------------- /lemon/clp.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_CLP_H 20 | #define LEMON_CLP_H 21 | 22 | ///\file 23 | ///\brief Header of the LEMON-CLP lp solver interface. 24 | 25 | #include 26 | #include 27 | 28 | #include 29 | 30 | class ClpSimplex; 31 | 32 | namespace lemon { 33 | 34 | /// \ingroup lp_group 35 | /// 36 | /// \brief Interface for the CLP solver 37 | /// 38 | /// This class implements an interface for the Clp LP solver. The 39 | /// Clp library is an object oriented lp solver library developed at 40 | /// the IBM. The CLP is part of the COIN-OR package and it can be 41 | /// used with Common Public License. 42 | class ClpLp : public LpSolver { 43 | protected: 44 | 45 | ClpSimplex* _prob; 46 | 47 | std::map _col_names_ref; 48 | std::map _row_names_ref; 49 | 50 | public: 51 | 52 | /// \e 53 | ClpLp(); 54 | /// \e 55 | ClpLp(const ClpLp&); 56 | /// \e 57 | ~ClpLp(); 58 | 59 | /// \e 60 | virtual ClpLp* newSolver() const; 61 | /// \e 62 | virtual ClpLp* cloneSolver() const; 63 | 64 | protected: 65 | 66 | mutable double* _primal_ray; 67 | mutable double* _dual_ray; 68 | 69 | void _init_temporals(); 70 | void _clear_temporals(); 71 | 72 | protected: 73 | 74 | virtual const char* _solverName() const; 75 | 76 | virtual int _addCol(); 77 | virtual int _addRow(); 78 | virtual int _addRow(Value l, ExprIterator b, ExprIterator e, Value u); 79 | 80 | virtual void _eraseCol(int i); 81 | virtual void _eraseRow(int i); 82 | 83 | virtual void _eraseColId(int i); 84 | virtual void _eraseRowId(int i); 85 | 86 | virtual void _getColName(int col, std::string& name) const; 87 | virtual void _setColName(int col, const std::string& name); 88 | virtual int _colByName(const std::string& name) const; 89 | 90 | virtual void _getRowName(int row, std::string& name) const; 91 | virtual void _setRowName(int row, const std::string& name); 92 | virtual int _rowByName(const std::string& name) const; 93 | 94 | virtual void _setRowCoeffs(int i, ExprIterator b, ExprIterator e); 95 | virtual void _getRowCoeffs(int i, InsertIterator b) const; 96 | 97 | virtual void _setColCoeffs(int i, ExprIterator b, ExprIterator e); 98 | virtual void _getColCoeffs(int i, InsertIterator b) const; 99 | 100 | virtual void _setCoeff(int row, int col, Value value); 101 | virtual Value _getCoeff(int row, int col) const; 102 | 103 | virtual void _setColLowerBound(int i, Value value); 104 | virtual Value _getColLowerBound(int i) const; 105 | virtual void _setColUpperBound(int i, Value value); 106 | virtual Value _getColUpperBound(int i) const; 107 | 108 | virtual void _setRowLowerBound(int i, Value value); 109 | virtual Value _getRowLowerBound(int i) const; 110 | virtual void _setRowUpperBound(int i, Value value); 111 | virtual Value _getRowUpperBound(int i) const; 112 | 113 | virtual void _setObjCoeffs(ExprIterator, ExprIterator); 114 | virtual void _getObjCoeffs(InsertIterator) const; 115 | 116 | virtual void _setObjCoeff(int i, Value obj_coef); 117 | virtual Value _getObjCoeff(int i) const; 118 | 119 | virtual void _setSense(Sense sense); 120 | virtual Sense _getSense() const; 121 | 122 | virtual SolveExitStatus _solve(); 123 | 124 | virtual Value _getPrimal(int i) const; 125 | virtual Value _getDual(int i) const; 126 | 127 | virtual Value _getPrimalValue() const; 128 | 129 | virtual Value _getPrimalRay(int i) const; 130 | virtual Value _getDualRay(int i) const; 131 | 132 | virtual VarStatus _getColStatus(int i) const; 133 | virtual VarStatus _getRowStatus(int i) const; 134 | 135 | virtual ProblemType _getPrimalType() const; 136 | virtual ProblemType _getDualType() const; 137 | 138 | virtual void _clear(); 139 | 140 | virtual void _messageLevel(MessageLevel); 141 | 142 | public: 143 | 144 | ///Solves LP with primal simplex method. 145 | SolveExitStatus solvePrimal(); 146 | 147 | ///Solves LP with dual simplex method. 148 | SolveExitStatus solveDual(); 149 | 150 | ///Solves LP with barrier method. 151 | SolveExitStatus solveBarrier(); 152 | 153 | ///Returns the constraint identifier understood by CLP. 154 | int clpRow(Row r) const { return rows(id(r)); } 155 | 156 | ///Returns the variable identifier understood by CLP. 157 | int clpCol(Col c) const { return cols(id(c)); } 158 | 159 | }; 160 | 161 | } //END OF NAMESPACE LEMON 162 | 163 | #endif //LEMON_CLP_H 164 | 165 | -------------------------------------------------------------------------------- /lemon/lp_skeleton.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 | ///\file 22 | ///\brief A skeleton file to implement LP solver interfaces 23 | namespace lemon { 24 | 25 | int SkeletonSolverBase::_addCol() 26 | { 27 | return ++col_num; 28 | } 29 | 30 | int SkeletonSolverBase::_addRow() 31 | { 32 | return ++row_num; 33 | } 34 | 35 | int SkeletonSolverBase::_addRow(Value, ExprIterator, ExprIterator, Value) 36 | { 37 | return ++row_num; 38 | } 39 | 40 | void SkeletonSolverBase::_eraseCol(int) {} 41 | void SkeletonSolverBase::_eraseRow(int) {} 42 | 43 | void SkeletonSolverBase::_getColName(int, std::string &) const {} 44 | void SkeletonSolverBase::_setColName(int, const std::string &) {} 45 | int SkeletonSolverBase::_colByName(const std::string&) const { return -1; } 46 | 47 | void SkeletonSolverBase::_getRowName(int, std::string &) const {} 48 | void SkeletonSolverBase::_setRowName(int, const std::string &) {} 49 | int SkeletonSolverBase::_rowByName(const std::string&) const { return -1; } 50 | 51 | void SkeletonSolverBase::_setRowCoeffs(int, ExprIterator, ExprIterator) {} 52 | void SkeletonSolverBase::_getRowCoeffs(int, InsertIterator) const {} 53 | 54 | void SkeletonSolverBase::_setColCoeffs(int, ExprIterator, ExprIterator) {} 55 | void SkeletonSolverBase::_getColCoeffs(int, InsertIterator) const {} 56 | 57 | void SkeletonSolverBase::_setCoeff(int, int, Value) {} 58 | SkeletonSolverBase::Value SkeletonSolverBase::_getCoeff(int, int) const 59 | { return 0; } 60 | 61 | void SkeletonSolverBase::_setColLowerBound(int, Value) {} 62 | SkeletonSolverBase::Value SkeletonSolverBase::_getColLowerBound(int) const 63 | { return 0; } 64 | 65 | void SkeletonSolverBase::_setColUpperBound(int, Value) {} 66 | SkeletonSolverBase::Value SkeletonSolverBase::_getColUpperBound(int) const 67 | { return 0; } 68 | 69 | void SkeletonSolverBase::_setRowLowerBound(int, Value) {} 70 | SkeletonSolverBase::Value SkeletonSolverBase::_getRowLowerBound(int) const 71 | { return 0; } 72 | 73 | void SkeletonSolverBase::_setRowUpperBound(int, Value) {} 74 | SkeletonSolverBase::Value SkeletonSolverBase::_getRowUpperBound(int) const 75 | { return 0; } 76 | 77 | void SkeletonSolverBase::_setObjCoeffs(ExprIterator, ExprIterator) {} 78 | void SkeletonSolverBase::_getObjCoeffs(InsertIterator) const {}; 79 | 80 | void SkeletonSolverBase::_setObjCoeff(int, Value) {} 81 | SkeletonSolverBase::Value SkeletonSolverBase::_getObjCoeff(int) const 82 | { return 0; } 83 | 84 | void SkeletonSolverBase::_setSense(Sense) {} 85 | SkeletonSolverBase::Sense SkeletonSolverBase::_getSense() const 86 | { return MIN; } 87 | 88 | void SkeletonSolverBase::_clear() { 89 | row_num = col_num = 0; 90 | } 91 | 92 | void SkeletonSolverBase::_messageLevel(MessageLevel) {} 93 | 94 | void SkeletonSolverBase::_write(std::string, std::string) const {} 95 | 96 | LpSkeleton::SolveExitStatus LpSkeleton::_solve() { return SOLVED; } 97 | 98 | LpSkeleton::Value LpSkeleton::_getPrimal(int) const { return 0; } 99 | LpSkeleton::Value LpSkeleton::_getDual(int) const { return 0; } 100 | LpSkeleton::Value LpSkeleton::_getPrimalValue() const { return 0; } 101 | 102 | LpSkeleton::Value LpSkeleton::_getPrimalRay(int) const { return 0; } 103 | LpSkeleton::Value LpSkeleton::_getDualRay(int) const { return 0; } 104 | 105 | LpSkeleton::ProblemType LpSkeleton::_getPrimalType() const 106 | { return UNDEFINED; } 107 | 108 | LpSkeleton::ProblemType LpSkeleton::_getDualType() const 109 | { return UNDEFINED; } 110 | 111 | LpSkeleton::VarStatus LpSkeleton::_getColStatus(int) const 112 | { return BASIC; } 113 | 114 | LpSkeleton::VarStatus LpSkeleton::_getRowStatus(int) const 115 | { return BASIC; } 116 | 117 | LpSkeleton* LpSkeleton::newSolver() const 118 | { return static_cast(0); } 119 | 120 | LpSkeleton* LpSkeleton::cloneSolver() const 121 | { return static_cast(0); } 122 | 123 | const char* LpSkeleton::_solverName() const { return "LpSkeleton"; } 124 | 125 | MipSkeleton::SolveExitStatus MipSkeleton::_solve() 126 | { return SOLVED; } 127 | 128 | MipSkeleton::Value MipSkeleton::_getSol(int) const { return 0; } 129 | MipSkeleton::Value MipSkeleton::_getSolValue() const { return 0; } 130 | 131 | MipSkeleton::ProblemType MipSkeleton::_getType() const 132 | { return UNDEFINED; } 133 | 134 | MipSkeleton* MipSkeleton::newSolver() const 135 | { return static_cast(0); } 136 | 137 | MipSkeleton* MipSkeleton::cloneSolver() const 138 | { return static_cast(0); } 139 | 140 | const char* MipSkeleton::_solverName() const { return "MipSkeleton"; } 141 | 142 | } //namespace lemon 143 | 144 | -------------------------------------------------------------------------------- /doc/images/bipartite_partitions.eps: -------------------------------------------------------------------------------- 1 | %!PS-Adobe-2.0 EPSF-2.0 2 | %%Creator: LEMON, graphToEps() 3 | %%CreationDate: Fri Mar 8 00:18:43 2013 4 | %%BoundingBox: 0 0 842 596 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 | 90 rotate 49 | 0 -842 translate 50 | 71.6378 15 translate 51 | 0.389093 dup scale 52 | 90 rotate 53 | 1197.47 -613.138 translate 54 | %Edges: 55 | gsave 56 | 513.857 -446.322 296.569 -487.43 79.2808 -528.539 0 0 0 7.00153 lb 57 | 513.857 -446.322 575.52 -315.656 637.183 -184.989 0 0 0 7.00153 lb 58 | 393.468 566.711 494.771 434.577 596.074 302.442 0 0 0 7.00153 lb 59 | 393.468 566.711 155.625 579.925 -82.2171 593.138 0 0 0 7.00153 lb 60 | 393.468 566.711 251.056 450.726 108.644 334.741 0 0 0 7.00153 lb 61 | 869.153 52.8539 732.613 177.648 596.074 302.442 0 0 0 7.00153 lb 62 | 869.153 52.8539 753.168 -66.0676 637.183 -184.989 0 0 0 7.00153 lb 63 | -82.2171 593.138 -91.0261 346.487 -99.8351 99.8351 0 0 0 7.00153 lb 64 | -663.61 546.157 -753.168 394.936 -842.726 243.715 0 0 0 7.00153 lb 65 | -663.61 546.157 -574.052 437.513 -484.494 328.869 0 0 0 7.00153 lb 66 | -1077.63 161.498 -960.178 202.606 -842.726 243.715 0 0 0 7.00153 lb 67 | -1077.63 161.498 -968.987 66.0674 -860.344 -29.3633 0 0 0 7.00153 lb 68 | -1177.47 -234.906 -1029.18 -381.722 -880.898 -528.539 0 0 0 7.00153 lb 69 | -1177.47 -234.906 -1018.91 -132.135 -860.344 -29.3633 0 0 0 7.00153 lb 70 | -880.898 -528.539 -744.359 -387.595 -607.82 -246.651 0 0 0 7.00153 lb 71 | -499.175 -499.175 -355.295 -475.685 -211.415 -452.194 0 0 0 7.00153 lb 72 | -499.175 -499.175 -553.498 -372.913 -607.82 -246.651 0 0 0 7.00153 lb 73 | -499.175 -499.175 -386.587 -315.087 -274 -131 0 0 0 7.00153 lb 74 | 79.2808 -528.539 -66.0671 -490.366 -211.415 -452.194 0 0 0 7.00153 lb 75 | 637.183 -184.989 421.363 -253.993 205.543 -322.996 0 0 0 7.00153 lb 76 | 205.543 -322.996 162.966 -226.097 120.389 -129.198 0 0 0 7.00153 lb 77 | 399.34 88.0898 259.865 -20.5541 120.389 -129.198 0 0 0 7.00153 lb 78 | 399.34 88.0898 253.992 211.415 108.644 334.741 0 0 0 7.00153 lb 79 | -842.726 243.715 -471.281 171.775 -99.8351 99.8351 0 0 0 7.00153 lb 80 | -842.726 243.715 -558.363 56.3575 -274 -131 0 0 0 7.00153 lb 81 | -860.344 -29.3633 -734.082 -138.007 -607.82 -246.651 0 0 0 7.00153 lb 82 | -211.415 -452.194 -45.513 -290.696 120.389 -129.198 0 0 0 7.00153 lb 83 | -99.8351 99.8351 4.40445 217.288 108.644 334.741 0 0 0 7.00153 lb 84 | -99.8351 99.8351 -292.165 214.352 -484.494 328.869 0 0 0 7.00153 lb 85 | 120.389 -129.198 -76.8055 -130.099 -274 -131 0 0 0 7.00153 lb 86 | grestore 87 | %Nodes: 88 | gsave 89 | -274 -131 23.3384 1 0 0 nc 90 | -607.82 -246.651 23.3384 1 0 0 nc 91 | -484.494 328.869 23.3384 0 0 1 nc 92 | 108.644 334.741 23.3384 0 0 1 nc 93 | 120.389 -129.198 23.3384 0 0 1 nc 94 | -99.8351 99.8351 23.3384 1 0 0 nc 95 | -211.415 -452.194 23.3384 1 0 0 nc 96 | -860.344 -29.3633 23.3384 0 0 1 nc 97 | -842.726 243.715 23.3384 0 0 1 nc 98 | 399.34 88.0898 23.3384 1 0 0 nc 99 | 205.543 -322.996 23.3384 1 0 0 nc 100 | 637.183 -184.989 23.3384 0 0 1 nc 101 | 79.2808 -528.539 23.3384 0 0 1 nc 102 | -499.175 -499.175 23.3384 0 0 1 nc 103 | -880.898 -528.539 23.3384 0 0 1 nc 104 | -1177.47 -234.906 23.3384 1 0 0 nc 105 | -1077.63 161.498 23.3384 1 0 0 nc 106 | -663.61 546.157 23.3384 1 0 0 nc 107 | -82.2171 593.138 23.3384 0 0 1 nc 108 | 596.074 302.442 23.3384 0 0 1 nc 109 | 869.153 52.8539 23.3384 1 0 0 nc 110 | 393.468 566.711 23.3384 1 0 0 nc 111 | 513.857 -446.322 23.3384 1 0 0 nc 112 | grestore 113 | grestore 114 | showpage 115 | -------------------------------------------------------------------------------- /lemon/bits/path_dump.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_PATH_DUMP_H 20 | #define LEMON_BITS_PATH_DUMP_H 21 | 22 | #include 23 | #include 24 | 25 | namespace lemon { 26 | 27 | template 28 | class PredMapPath { 29 | public: 30 | typedef True RevPathTag; 31 | 32 | typedef _Digraph Digraph; 33 | typedef typename Digraph::Arc Arc; 34 | typedef _PredMap PredMap; 35 | 36 | PredMapPath(const Digraph& _digraph, const PredMap& _predMap, 37 | typename Digraph::Node _target) 38 | : digraph(_digraph), predMap(_predMap), target(_target) {} 39 | 40 | int length() const { 41 | int len = 0; 42 | typename Digraph::Node node = target; 43 | typename Digraph::Arc arc; 44 | while ((arc = predMap[node]) != INVALID) { 45 | node = digraph.source(arc); 46 | ++len; 47 | } 48 | return len; 49 | } 50 | 51 | bool empty() const { 52 | return predMap[target] == INVALID; 53 | } 54 | 55 | class RevArcIt { 56 | public: 57 | RevArcIt() {} 58 | RevArcIt(Invalid) : path(0), current(INVALID) {} 59 | RevArcIt(const PredMapPath& _path) 60 | : path(&_path), current(_path.target) { 61 | if (path->predMap[current] == INVALID) current = INVALID; 62 | } 63 | 64 | operator const typename Digraph::Arc() const { 65 | return path->predMap[current]; 66 | } 67 | 68 | RevArcIt& operator++() { 69 | current = path->digraph.source(path->predMap[current]); 70 | if (path->predMap[current] == INVALID) current = INVALID; 71 | return *this; 72 | } 73 | 74 | bool operator==(const RevArcIt& e) const { 75 | return current == e.current; 76 | } 77 | 78 | bool operator!=(const RevArcIt& e) const { 79 | return current != e.current; 80 | } 81 | 82 | bool operator<(const RevArcIt& e) const { 83 | return current < e.current; 84 | } 85 | 86 | private: 87 | const PredMapPath* path; 88 | typename Digraph::Node current; 89 | }; 90 | 91 | private: 92 | const Digraph& digraph; 93 | const PredMap& predMap; 94 | typename Digraph::Node target; 95 | }; 96 | 97 | 98 | template 99 | class PredMatrixMapPath { 100 | public: 101 | typedef True RevPathTag; 102 | 103 | typedef _Digraph Digraph; 104 | typedef typename Digraph::Arc Arc; 105 | typedef _PredMatrixMap PredMatrixMap; 106 | 107 | PredMatrixMapPath(const Digraph& _digraph, 108 | const PredMatrixMap& _predMatrixMap, 109 | typename Digraph::Node _source, 110 | typename Digraph::Node _target) 111 | : digraph(_digraph), predMatrixMap(_predMatrixMap), 112 | source(_source), target(_target) {} 113 | 114 | int length() const { 115 | int len = 0; 116 | typename Digraph::Node node = target; 117 | typename Digraph::Arc arc; 118 | while ((arc = predMatrixMap(source, node)) != INVALID) { 119 | node = digraph.source(arc); 120 | ++len; 121 | } 122 | return len; 123 | } 124 | 125 | bool empty() const { 126 | return predMatrixMap(source, target) == INVALID; 127 | } 128 | 129 | class RevArcIt { 130 | public: 131 | RevArcIt() {} 132 | RevArcIt(Invalid) : path(0), current(INVALID) {} 133 | RevArcIt(const PredMatrixMapPath& _path) 134 | : path(&_path), current(_path.target) { 135 | if (path->predMatrixMap(path->source, current) == INVALID) 136 | current = INVALID; 137 | } 138 | 139 | operator const typename Digraph::Arc() const { 140 | return path->predMatrixMap(path->source, current); 141 | } 142 | 143 | RevArcIt& operator++() { 144 | current = 145 | path->digraph.source(path->predMatrixMap(path->source, current)); 146 | if (path->predMatrixMap(path->source, current) == INVALID) 147 | current = INVALID; 148 | return *this; 149 | } 150 | 151 | bool operator==(const RevArcIt& e) const { 152 | return current == e.current; 153 | } 154 | 155 | bool operator!=(const RevArcIt& e) const { 156 | return current != e.current; 157 | } 158 | 159 | bool operator<(const RevArcIt& e) const { 160 | return current < e.current; 161 | } 162 | 163 | private: 164 | const PredMatrixMapPath* path; 165 | typename Digraph::Node current; 166 | }; 167 | 168 | private: 169 | const Digraph& digraph; 170 | const PredMatrixMap& predMatrixMap; 171 | typename Digraph::Node source; 172 | typename Digraph::Node target; 173 | }; 174 | 175 | } 176 | 177 | #endif 178 | -------------------------------------------------------------------------------- /lemon/bits/solver_bits.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_SOLVER_BITS_H 20 | #define LEMON_BITS_SOLVER_BITS_H 21 | 22 | #include 23 | 24 | namespace lemon { 25 | 26 | namespace _solver_bits { 27 | 28 | class VarIndex { 29 | private: 30 | struct ItemT { 31 | int prev, next; 32 | int index; 33 | }; 34 | std::vector items; 35 | int first_item, last_item, first_free_item; 36 | 37 | std::vector cross; 38 | 39 | public: 40 | 41 | VarIndex() 42 | : first_item(-1), last_item(-1), first_free_item(-1) { 43 | } 44 | 45 | void clear() { 46 | first_item = -1; 47 | last_item = -1; 48 | first_free_item = -1; 49 | items.clear(); 50 | cross.clear(); 51 | } 52 | 53 | int addIndex(int idx) { 54 | int n; 55 | if (first_free_item == -1) { 56 | n = items.size(); 57 | items.push_back(ItemT()); 58 | } else { 59 | n = first_free_item; 60 | first_free_item = items[n].next; 61 | if (first_free_item != -1) { 62 | items[first_free_item].prev = -1; 63 | } 64 | } 65 | items[n].index = idx; 66 | if (static_cast(cross.size()) <= idx) { 67 | cross.resize(idx + 1, -1); 68 | } 69 | cross[idx] = n; 70 | 71 | items[n].prev = last_item; 72 | items[n].next = -1; 73 | if (last_item != -1) { 74 | items[last_item].next = n; 75 | } else { 76 | first_item = n; 77 | } 78 | last_item = n; 79 | 80 | return n; 81 | } 82 | 83 | int addIndex(int idx, int n) { 84 | while (n >= static_cast(items.size())) { 85 | items.push_back(ItemT()); 86 | items.back().prev = -1; 87 | items.back().next = first_free_item; 88 | if (first_free_item != -1) { 89 | items[first_free_item].prev = items.size() - 1; 90 | } 91 | first_free_item = items.size() - 1; 92 | } 93 | if (items[n].next != -1) { 94 | items[items[n].next].prev = items[n].prev; 95 | } 96 | if (items[n].prev != -1) { 97 | items[items[n].prev].next = items[n].next; 98 | } else { 99 | first_free_item = items[n].next; 100 | } 101 | 102 | items[n].index = idx; 103 | if (static_cast(cross.size()) <= idx) { 104 | cross.resize(idx + 1, -1); 105 | } 106 | cross[idx] = n; 107 | 108 | items[n].prev = last_item; 109 | items[n].next = -1; 110 | if (last_item != -1) { 111 | items[last_item].next = n; 112 | } else { 113 | first_item = n; 114 | } 115 | last_item = n; 116 | 117 | return n; 118 | } 119 | 120 | void eraseIndex(int idx) { 121 | int n = cross[idx]; 122 | 123 | if (items[n].prev != -1) { 124 | items[items[n].prev].next = items[n].next; 125 | } else { 126 | first_item = items[n].next; 127 | } 128 | if (items[n].next != -1) { 129 | items[items[n].next].prev = items[n].prev; 130 | } else { 131 | last_item = items[n].prev; 132 | } 133 | 134 | if (first_free_item != -1) { 135 | items[first_free_item].prev = n; 136 | } 137 | items[n].next = first_free_item; 138 | items[n].prev = -1; 139 | first_free_item = n; 140 | 141 | while (!cross.empty() && cross.back() == -1) { 142 | cross.pop_back(); 143 | } 144 | } 145 | 146 | int maxIndex() const { 147 | return cross.size() - 1; 148 | } 149 | 150 | void shiftIndices(int idx) { 151 | for (int i = idx + 1; i < static_cast(cross.size()); ++i) { 152 | cross[i - 1] = cross[i]; 153 | if (cross[i] != -1) { 154 | --items[cross[i]].index; 155 | } 156 | } 157 | cross.back() = -1; 158 | cross.pop_back(); 159 | while (!cross.empty() && cross.back() == -1) { 160 | cross.pop_back(); 161 | } 162 | } 163 | 164 | void relocateIndex(int idx, int jdx) { 165 | cross[idx] = cross[jdx]; 166 | items[cross[jdx]].index = idx; 167 | cross[jdx] = -1; 168 | 169 | while (!cross.empty() && cross.back() == -1) { 170 | cross.pop_back(); 171 | } 172 | } 173 | 174 | int operator[](int idx) const { 175 | return cross[idx]; 176 | } 177 | 178 | int operator()(int fdx) const { 179 | return items[fdx].index; 180 | } 181 | 182 | void firstItem(int& fdx) const { 183 | fdx = first_item; 184 | } 185 | 186 | void nextItem(int& fdx) const { 187 | fdx = items[fdx].next; 188 | } 189 | 190 | }; 191 | } 192 | } 193 | 194 | #endif 195 | -------------------------------------------------------------------------------- /doc/images/matching.eps: -------------------------------------------------------------------------------- 1 | %!PS-Adobe-2.0 EPSF-2.0 2 | %%Creator: LEMON, graphToEps() 3 | %%CreationDate: Sun Mar 14 09:08:34 2010 4 | %%BoundingBox: -353 -264 559 292 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 | %Arcs: 69 | gsave 70 | 140.321 266.249 -327.729 150.06 0 0 0 4.99223 l 71 | 82.1207 -238.726 -245.288 -110.743 0 0 0 4.99223 l 72 | 336.635 -229.036 533.603 13.109 0 0 0 4.99223 l 73 | 53.8598 -45.8071 -245.288 -110.743 0 0 0 4.99223 l 74 | -75.5617 118.579 -327.729 150.06 0 0 0 4.99223 l 75 | -327.729 150.06 -245.288 -110.743 1 0 0 11.9813 l 76 | 533.603 13.109 218.184 -84.2955 0 0 0 4.99223 l 77 | 39.87 175.035 141.163 67.2575 0 0 0 4.99223 l 78 | 53.8598 -45.8071 -75.5617 118.579 0 0 0 4.99223 l 79 | -102.406 -141.267 82.1207 -238.726 0 0 0 4.99223 l 80 | 399.144 166.894 533.603 13.109 1 0 0 11.9813 l 81 | 39.87 175.035 140.321 266.249 1 0 0 11.9813 l 82 | 399.144 166.894 140.321 266.249 0 0 0 4.99223 l 83 | 399.144 166.894 141.163 67.2575 0 0 0 4.99223 l 84 | 53.8598 -45.8071 204.765 -173.77 0 0 0 4.99223 l 85 | 82.1207 -238.726 204.765 -173.77 0 0 0 4.99223 l 86 | 258.227 61.658 399.144 166.894 0 0 0 4.99223 l 87 | 53.8598 -45.8071 -102.406 -141.267 1 0 0 11.9813 l 88 | 175.073 -37.4477 141.163 67.2575 0 0 0 4.99223 l 89 | 258.227 61.658 380 0 0 0 0 4.99223 l 90 | 34.6739 40.8267 -75.5617 118.579 1 0 0 11.9813 l 91 | 380 0 533.603 13.109 0 0 0 4.99223 l 92 | 175.073 -37.4477 380 0 0 0 0 4.99223 l 93 | 218.184 -84.2955 204.765 -173.77 0 0 0 4.99223 l 94 | 53.8598 -45.8071 34.6739 40.8267 0 0 0 4.99223 l 95 | 167.905 -213.988 82.1207 -238.726 1 0 0 11.9813 l 96 | 336.635 -229.036 204.765 -173.77 1 0 0 11.9813 l 97 | 336.635 -229.036 167.905 -213.988 0 0 0 4.99223 l 98 | 329.08 -26.3098 218.184 -84.2955 0 0 0 4.99223 l 99 | 39.87 175.035 -75.5617 118.579 0 0 0 4.99223 l 100 | 53.8598 -45.8071 175.073 -37.4477 0 0 0 4.99223 l 101 | 34.6739 40.8267 141.163 67.2575 0 0 0 4.99223 l 102 | 258.227 61.658 141.163 67.2575 1 0 0 11.9813 l 103 | 175.073 -37.4477 218.184 -84.2955 1 0 0 11.9813 l 104 | 380 0 329.08 -26.3098 1 0 0 11.9813 l 105 | grestore 106 | %Nodes: 107 | gsave 108 | -245.288 -110.743 14.9767 1 1 1 nc 109 | 204.765 -173.77 14.9767 1 1 1 nc 110 | -327.729 150.06 14.9767 1 1 1 nc 111 | -75.5617 118.579 14.9767 1 1 1 nc 112 | 218.184 -84.2955 14.9767 1 1 1 nc 113 | 140.321 266.249 14.9767 1 1 1 nc 114 | 141.163 67.2575 14.9767 1 1 1 nc 115 | 82.1207 -238.726 14.9767 1 1 1 nc 116 | 329.08 -26.3098 14.9767 1 1 1 nc 117 | -102.406 -141.267 14.9767 1 1 1 nc 118 | 533.603 13.109 14.9767 1 1 1 nc 119 | 167.905 -213.988 14.9767 1 1 1 nc 120 | 336.635 -229.036 14.9767 1 1 1 nc 121 | 380 0 14.9767 1 1 1 nc 122 | 399.144 166.894 14.9767 1 1 1 nc 123 | 34.6739 40.8267 14.9767 1 1 1 nc 124 | 39.87 175.035 14.9767 1 1 1 nc 125 | 175.073 -37.4477 14.9767 1 1 1 nc 126 | 53.8598 -45.8071 14.9767 1 1 1 nc 127 | 258.227 61.658 14.9767 1 1 1 nc 128 | grestore 129 | grestore 130 | showpage 131 | -------------------------------------------------------------------------------- /lemon/bits/bezier.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_BEZIER_H 20 | #define LEMON_BEZIER_H 21 | 22 | //\ingroup misc 23 | //\file 24 | //\brief Classes to compute with Bezier curves. 25 | // 26 | //Up to now this file is used internally by \ref graph_to_eps.h 27 | 28 | #include 29 | 30 | namespace lemon { 31 | namespace dim2 { 32 | 33 | class BezierBase { 34 | public: 35 | typedef lemon::dim2::Point Point; 36 | protected: 37 | static Point conv(Point x,Point y,double t) {return (1-t)*x+t*y;} 38 | }; 39 | 40 | class Bezier1 : public BezierBase 41 | { 42 | public: 43 | Point p1,p2; 44 | 45 | Bezier1() {} 46 | Bezier1(Point _p1, Point _p2) :p1(_p1), p2(_p2) {} 47 | 48 | Point operator()(double t) const 49 | { 50 | // return conv(conv(p1,p2,t),conv(p2,p3,t),t); 51 | return conv(p1,p2,t); 52 | } 53 | Bezier1 before(double t) const 54 | { 55 | return Bezier1(p1,conv(p1,p2,t)); 56 | } 57 | 58 | Bezier1 after(double t) const 59 | { 60 | return Bezier1(conv(p1,p2,t),p2); 61 | } 62 | 63 | Bezier1 revert() const { return Bezier1(p2,p1);} 64 | Bezier1 operator()(double a,double b) const { return before(b).after(a/b); } 65 | Point grad() const { return p2-p1; } 66 | Point norm() const { return rot90(p2-p1); } 67 | Point grad(double) const { return grad(); } 68 | Point norm(double t) const { return rot90(grad(t)); } 69 | }; 70 | 71 | class Bezier2 : public BezierBase 72 | { 73 | public: 74 | Point p1,p2,p3; 75 | 76 | Bezier2() {} 77 | Bezier2(Point _p1, Point _p2, Point _p3) :p1(_p1), p2(_p2), p3(_p3) {} 78 | Bezier2(const Bezier1 &b) : p1(b.p1), p2(conv(b.p1,b.p2,.5)), p3(b.p2) {} 79 | Point operator()(double t) const 80 | { 81 | // return conv(conv(p1,p2,t),conv(p2,p3,t),t); 82 | return ((1-t)*(1-t))*p1+(2*(1-t)*t)*p2+(t*t)*p3; 83 | } 84 | Bezier2 before(double t) const 85 | { 86 | Point q(conv(p1,p2,t)); 87 | Point r(conv(p2,p3,t)); 88 | return Bezier2(p1,q,conv(q,r,t)); 89 | } 90 | 91 | Bezier2 after(double t) const 92 | { 93 | Point q(conv(p1,p2,t)); 94 | Point r(conv(p2,p3,t)); 95 | return Bezier2(conv(q,r,t),r,p3); 96 | } 97 | Bezier2 revert() const { return Bezier2(p3,p2,p1);} 98 | Bezier2 operator()(double a,double b) const { return before(b).after(a/b); } 99 | Bezier1 grad() const { return Bezier1(2.0*(p2-p1),2.0*(p3-p2)); } 100 | Bezier1 norm() const { return Bezier1(2.0*rot90(p2-p1),2.0*rot90(p3-p2)); } 101 | Point grad(double t) const { return grad()(t); } 102 | Point norm(double t) const { return rot90(grad(t)); } 103 | }; 104 | 105 | class Bezier3 : public BezierBase 106 | { 107 | public: 108 | Point p1,p2,p3,p4; 109 | 110 | Bezier3() {} 111 | Bezier3(Point _p1, Point _p2, Point _p3, Point _p4) 112 | : p1(_p1), p2(_p2), p3(_p3), p4(_p4) {} 113 | Bezier3(const Bezier1 &b) : p1(b.p1), p2(conv(b.p1,b.p2,1.0/3.0)), 114 | p3(conv(b.p1,b.p2,2.0/3.0)), p4(b.p2) {} 115 | Bezier3(const Bezier2 &b) : p1(b.p1), p2(conv(b.p1,b.p2,2.0/3.0)), 116 | p3(conv(b.p2,b.p3,1.0/3.0)), p4(b.p3) {} 117 | 118 | Point operator()(double t) const 119 | { 120 | // return Bezier2(conv(p1,p2,t),conv(p2,p3,t),conv(p3,p4,t))(t); 121 | return ((1-t)*(1-t)*(1-t))*p1+(3*t*(1-t)*(1-t))*p2+ 122 | (3*t*t*(1-t))*p3+(t*t*t)*p4; 123 | } 124 | Bezier3 before(double t) const 125 | { 126 | Point p(conv(p1,p2,t)); 127 | Point q(conv(p2,p3,t)); 128 | Point r(conv(p3,p4,t)); 129 | Point a(conv(p,q,t)); 130 | Point b(conv(q,r,t)); 131 | Point c(conv(a,b,t)); 132 | return Bezier3(p1,p,a,c); 133 | } 134 | 135 | Bezier3 after(double t) const 136 | { 137 | Point p(conv(p1,p2,t)); 138 | Point q(conv(p2,p3,t)); 139 | Point r(conv(p3,p4,t)); 140 | Point a(conv(p,q,t)); 141 | Point b(conv(q,r,t)); 142 | Point c(conv(a,b,t)); 143 | return Bezier3(c,b,r,p4); 144 | } 145 | Bezier3 revert() const { return Bezier3(p4,p3,p2,p1);} 146 | Bezier3 operator()(double a,double b) const { return before(b).after(a/b); } 147 | Bezier2 grad() const { return Bezier2(3.0*(p2-p1),3.0*(p3-p2),3.0*(p4-p3)); } 148 | Bezier2 norm() const { return Bezier2(3.0*rot90(p2-p1), 149 | 3.0*rot90(p3-p2), 150 | 3.0*rot90(p4-p3)); } 151 | Point grad(double t) const { return grad()(t); } 152 | Point norm(double t) const { return rot90(grad(t)); } 153 | 154 | template 155 | R recSplit(F &_f,const S &_s,D _d) const 156 | { 157 | const Point a=(p1+p2)/2; 158 | const Point b=(p2+p3)/2; 159 | const Point c=(p3+p4)/2; 160 | const Point d=(a+b)/2; 161 | const Point e=(b+c)/2; 162 | // const Point f=(d+e)/2; 163 | R f1=_f(Bezier3(p1,a,d,e),_d); 164 | R f2=_f(Bezier3(e,d,c,p4),_d); 165 | return _s(f1,f2); 166 | } 167 | 168 | }; 169 | 170 | 171 | } //END OF NAMESPACE dim2 172 | } //END OF NAMESPACE lemon 173 | 174 | #endif // LEMON_BEZIER_H 175 | -------------------------------------------------------------------------------- /INSTALL: -------------------------------------------------------------------------------- 1 | Installation Instructions 2 | ========================= 3 | 4 | This file contains instructions for building and installing LEMON from 5 | source on Linux. The process on Windows is similar. 6 | 7 | Note that it is not necessary to install LEMON in order to use 8 | it. Instead, you can easily integrate it with your own code 9 | directly. For instructions, see 10 | https://lemon.cs.elte.hu/trac/lemon/wiki/HowToCompile 11 | 12 | 13 | In order to install LEMON from the extracted source tarball you have to 14 | issue the following commands: 15 | 16 | 1. Step into the root of the source directory. 17 | 18 | $ cd lemon-x.y.z 19 | 20 | 2. Create a build subdirectory and step into it. 21 | 22 | $ mkdir build 23 | $ cd build 24 | 25 | 3. Perform system checks and create the makefiles. 26 | 27 | $ cmake .. 28 | 29 | 4. Build LEMON. 30 | 31 | $ make 32 | 33 | This command compiles the non-template part of LEMON into 34 | libemon.a file. It also compiles the programs in the 'tools' and 35 | 'demo' subdirectories. 36 | 37 | 5. [Optional] Compile and run the self-tests. 38 | 39 | $ make check 40 | 41 | 5. [Optional] Generate the user documentation. 42 | 43 | $ make html 44 | 45 | The release tarballs already include the documentation. 46 | 47 | Note that for this step you need to have the following tools 48 | installed: Python, Doxygen, Graphviz, Ghostscript, LaTeX. 49 | 50 | 6. [Optional] Install LEMON 51 | 52 | $ make install 53 | 54 | This command installs LEMON under /usr/local (you will need root 55 | privileges to be able to do that). If you want to install it to 56 | some other location, then pass the 57 | -DCMAKE_INSTALL_PREFIX=DIRECTORY flag to cmake in Step 3. 58 | For example: 59 | 60 | $ cmake -DCMAKE_INSTALL_PREFIX=/home/username/lemon' 61 | 62 | Configure Options and Variables 63 | =============================== 64 | 65 | In Step 3, you can customize the build process by passing options to CMAKE. 66 | 67 | $ cmake [OPTIONS] .. 68 | 69 | You find a list of the most useful options below. 70 | 71 | -DCMAKE_INSTALL_PREFIX=PREFIX 72 | 73 | Set the installation prefix to PREFIX. By default it is /usr/local. 74 | 75 | -DCMAKE_BUILD_TYPE=[Release|Debug|Maintainer|...] 76 | 77 | This sets the compiler options. The choices are the following 78 | 79 | 'Release': A strong optimization is turned on (-O3 with gcc). This 80 | is the default setting and we strongly recommend using this for 81 | the final compilation. 82 | 83 | 'Debug': Optimization is turned off and debug info is added (-O0 84 | -ggdb with gcc). If is recommended during the development. 85 | 86 | 'Maintainer': The same as 'Debug' but the compiler warnings are 87 | converted to errors (-Werror with gcc). In addition, 'make' will 88 | also automatically compile and execute the test codes. It is the 89 | best way of ensuring that LEMON codebase is clean and safe. 90 | 91 | 'RelWithDebInfo': Optimized build with debug info. 92 | 93 | 'MinSizeRel': Size optimized build (-Os with gcc) 94 | 95 | -DTEST_WITH_VALGRIND=YES 96 | 97 | Using this, the test codes will be executed using valgrind. It is a 98 | very effective way of identifying indexing problems and memory leaks. 99 | 100 | -DCMAKE_CXX_COMPILER=path-to-compiler 101 | 102 | Change the compiler to be used. 103 | 104 | -DBUILD_SHARED_LIBS=TRUE 105 | 106 | Build shared library instead of static one. Think twice if you 107 | really want to use this option. 108 | 109 | -DLEMON_DOC_SOURCE_BROWSER=YES 110 | 111 | Include the browsable cross referenced LEMON source code into the 112 | doc. It makes the doc quite bloated, but may be useful for 113 | developing LEMON itself. 114 | 115 | -DLEMON_DOC_USE_MATHJAX=YES 116 | 117 | Use MathJax (http://mathjax.org) for rendering the math formulae in 118 | the doc. It of much higher quality compared to the default LaTeX 119 | generated static images and it allows copy&paste of the formulae to 120 | LaTeX, Open Office, MS Word etc. documents. 121 | 122 | On the other hand, it needs either Internet access or a locally 123 | installed version of MathJax to properly render the doc. 124 | 125 | -DLEMON_DOC_MATHJAX_RELPATH=DIRECTORY 126 | 127 | The location of the MathJax library. It defaults to 128 | http://www.mathjax.org/mathjax, which necessitates Internet access 129 | for proper rendering. The easiest way to make it usable offline is 130 | to set this parameter to 'mathjax' and copy all files of the MathJax 131 | library into the 'doc/html/mathjax' subdirectory of the build 132 | location. 133 | 134 | See http://docs.mathjax.org/en/latest/installation.html for more details. 135 | 136 | 137 | -DLEMON_ENABLE_GLPK=NO 138 | -DLEMON_ENABLE_COIN=NO 139 | -DLEMON_ENABLE_ILOG=NO 140 | 141 | Enable optional third party libraries. They are all enabled by default. 142 | 143 | -DLEMON_DEFAULT_LP=GLPK 144 | 145 | Sets the default LP solver backend. The supported values are 146 | CPLEX, CLP and GLPK. By default, it is set to the first one which 147 | is enabled and succesfully discovered. 148 | 149 | -DLEMON_DEFAULT_MIP=GLPK 150 | 151 | Sets the default MIP solver backend. The supported values are 152 | CPLEX, CBC and GLPK. By default, it is set to the first one which 153 | is enabled and succesfully discovered. 154 | 155 | -DGLPK_ROOT_DIR=DIRECTORY 156 | -DCOIN_ROOT_DIR=DIRECTORY 157 | -DILOG_ROOT_DIR=DIRECTORY 158 | 159 | Root directory prefixes of optional third party libraries. 160 | 161 | Makefile Variables 162 | ================== 163 | 164 | make VERBOSE=1 165 | 166 | This results in a more verbose output by showing the full 167 | compiler and linker commands. -------------------------------------------------------------------------------- /lemon/bits/default_map.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_DEFAULT_MAP_H 20 | #define LEMON_BITS_DEFAULT_MAP_H 21 | 22 | #include 23 | #include 24 | #include 25 | //#include 26 | 27 | //\ingroup graphbits 28 | //\file 29 | //\brief Graph maps that construct and destruct their elements dynamically. 30 | 31 | namespace lemon { 32 | 33 | 34 | //#ifndef LEMON_USE_DEBUG_MAP 35 | 36 | template 37 | struct DefaultMapSelector { 38 | typedef ArrayMap<_Graph, _Item, _Value> Map; 39 | }; 40 | 41 | // bool 42 | template 43 | struct DefaultMapSelector<_Graph, _Item, bool> { 44 | typedef VectorMap<_Graph, _Item, bool> Map; 45 | }; 46 | 47 | // char 48 | template 49 | struct DefaultMapSelector<_Graph, _Item, char> { 50 | typedef VectorMap<_Graph, _Item, char> Map; 51 | }; 52 | 53 | template 54 | struct DefaultMapSelector<_Graph, _Item, signed char> { 55 | typedef VectorMap<_Graph, _Item, signed char> Map; 56 | }; 57 | 58 | template 59 | struct DefaultMapSelector<_Graph, _Item, unsigned char> { 60 | typedef VectorMap<_Graph, _Item, unsigned char> Map; 61 | }; 62 | 63 | 64 | // int 65 | template 66 | struct DefaultMapSelector<_Graph, _Item, signed int> { 67 | typedef VectorMap<_Graph, _Item, signed int> Map; 68 | }; 69 | 70 | template 71 | struct DefaultMapSelector<_Graph, _Item, unsigned int> { 72 | typedef VectorMap<_Graph, _Item, unsigned int> Map; 73 | }; 74 | 75 | 76 | // short 77 | template 78 | struct DefaultMapSelector<_Graph, _Item, signed short> { 79 | typedef VectorMap<_Graph, _Item, signed short> Map; 80 | }; 81 | 82 | template 83 | struct DefaultMapSelector<_Graph, _Item, unsigned short> { 84 | typedef VectorMap<_Graph, _Item, unsigned short> Map; 85 | }; 86 | 87 | 88 | // long 89 | template 90 | struct DefaultMapSelector<_Graph, _Item, signed long> { 91 | typedef VectorMap<_Graph, _Item, signed long> Map; 92 | }; 93 | 94 | template 95 | struct DefaultMapSelector<_Graph, _Item, unsigned long> { 96 | typedef VectorMap<_Graph, _Item, unsigned long> Map; 97 | }; 98 | 99 | 100 | #if defined LEMON_HAVE_LONG_LONG 101 | 102 | // long long 103 | template 104 | struct DefaultMapSelector<_Graph, _Item, signed long long> { 105 | typedef VectorMap<_Graph, _Item, signed long long> Map; 106 | }; 107 | 108 | template 109 | struct DefaultMapSelector<_Graph, _Item, unsigned long long> { 110 | typedef VectorMap<_Graph, _Item, unsigned long long> Map; 111 | }; 112 | 113 | #endif 114 | 115 | 116 | // float 117 | template 118 | struct DefaultMapSelector<_Graph, _Item, float> { 119 | typedef VectorMap<_Graph, _Item, float> Map; 120 | }; 121 | 122 | 123 | // double 124 | template 125 | struct DefaultMapSelector<_Graph, _Item, double> { 126 | typedef VectorMap<_Graph, _Item, double> Map; 127 | }; 128 | 129 | 130 | // long double 131 | template 132 | struct DefaultMapSelector<_Graph, _Item, long double> { 133 | typedef VectorMap<_Graph, _Item, long double> Map; 134 | }; 135 | 136 | 137 | // pointer 138 | template 139 | struct DefaultMapSelector<_Graph, _Item, _Ptr*> { 140 | typedef VectorMap<_Graph, _Item, _Ptr*> Map; 141 | }; 142 | 143 | // #else 144 | 145 | // template 146 | // struct DefaultMapSelector { 147 | // typedef DebugMap<_Graph, _Item, _Value> Map; 148 | // }; 149 | 150 | // #endif 151 | 152 | // DefaultMap class 153 | template 154 | class DefaultMap 155 | : public DefaultMapSelector<_Graph, _Item, _Value>::Map { 156 | typedef typename DefaultMapSelector<_Graph, _Item, _Value>::Map Parent; 157 | 158 | public: 159 | typedef DefaultMap<_Graph, _Item, _Value> Map; 160 | 161 | typedef typename Parent::GraphType GraphType; 162 | typedef typename Parent::Value Value; 163 | 164 | explicit DefaultMap(const GraphType& graph) : Parent(graph) {} 165 | DefaultMap(const GraphType& graph, const Value& value) 166 | : Parent(graph, value) {} 167 | 168 | DefaultMap& operator=(const DefaultMap& cmap) { 169 | return operator=(cmap); 170 | } 171 | 172 | template 173 | DefaultMap& operator=(const CMap& cmap) { 174 | Parent::operator=(cmap); 175 | return *this; 176 | } 177 | 178 | }; 179 | 180 | } 181 | 182 | #endif 183 | -------------------------------------------------------------------------------- /test/min_cost_arborescence_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 | #include 22 | #include 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include "test_tools.h" 30 | 31 | using namespace lemon; 32 | using namespace std; 33 | 34 | const 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 | "5\n" 43 | "6\n" 44 | "7\n" 45 | "8\n" 46 | "9\n" 47 | "@arcs\n" 48 | " label cost\n" 49 | "1 8 0 107\n" 50 | "0 3 1 70\n" 51 | "2 1 2 46\n" 52 | "4 1 3 28\n" 53 | "4 4 4 91\n" 54 | "3 9 5 76\n" 55 | "9 8 6 61\n" 56 | "8 1 7 39\n" 57 | "9 8 8 74\n" 58 | "8 0 9 39\n" 59 | "4 3 10 45\n" 60 | "2 2 11 34\n" 61 | "0 1 12 100\n" 62 | "6 3 13 95\n" 63 | "4 1 14 22\n" 64 | "1 1 15 31\n" 65 | "7 2 16 51\n" 66 | "2 6 17 29\n" 67 | "8 3 18 115\n" 68 | "6 9 19 32\n" 69 | "1 1 20 60\n" 70 | "0 3 21 40\n" 71 | "@attributes\n" 72 | "source 0\n"; 73 | 74 | 75 | void checkMinCostArborescenceCompile() 76 | { 77 | typedef double VType; 78 | typedef concepts::Digraph Digraph; 79 | typedef concepts::ReadMap CostMap; 80 | typedef Digraph::Node Node; 81 | typedef Digraph::Arc Arc; 82 | typedef concepts::WriteMap ArbMap; 83 | typedef concepts::ReadWriteMap PredMap; 84 | 85 | typedef MinCostArborescence:: 86 | SetArborescenceMap:: 87 | SetPredMap::Create MinCostArbType; 88 | 89 | Digraph g; 90 | Node s, n; 91 | Arc e; 92 | VType c; 93 | bool b; 94 | ::lemon::ignore_unused_variable_warning(c,b); 95 | int i; 96 | CostMap cost; 97 | ArbMap arb; 98 | PredMap pred; 99 | 100 | MinCostArbType mcarb_test(g, cost); 101 | const MinCostArbType& const_mcarb_test = mcarb_test; 102 | 103 | mcarb_test 104 | .arborescenceMap(arb) 105 | .predMap(pred) 106 | .run(s); 107 | 108 | mcarb_test.init(); 109 | mcarb_test.addSource(s); 110 | mcarb_test.start(); 111 | n = mcarb_test.processNextNode(); 112 | b = const_mcarb_test.emptyQueue(); 113 | i = const_mcarb_test.queueSize(); 114 | 115 | c = const_mcarb_test.arborescenceCost(); 116 | b = const_mcarb_test.arborescence(e); 117 | e = const_mcarb_test.pred(n); 118 | const MinCostArbType::ArborescenceMap &am = 119 | const_mcarb_test.arborescenceMap(); 120 | const MinCostArbType::PredMap &pm = 121 | const_mcarb_test.predMap(); 122 | b = const_mcarb_test.reached(n); 123 | b = const_mcarb_test.processed(n); 124 | 125 | i = const_mcarb_test.dualNum(); 126 | c = const_mcarb_test.dualValue(); 127 | i = const_mcarb_test.dualSize(i); 128 | c = const_mcarb_test.dualValue(i); 129 | 130 | ::lemon::ignore_unused_variable_warning(am); 131 | ::lemon::ignore_unused_variable_warning(pm); 132 | } 133 | 134 | int main() { 135 | typedef SmartDigraph Digraph; 136 | DIGRAPH_TYPEDEFS(Digraph); 137 | 138 | typedef Digraph::ArcMap CostMap; 139 | 140 | Digraph digraph; 141 | CostMap cost(digraph); 142 | Node source; 143 | 144 | std::istringstream is(test_lgf); 145 | digraphReader(digraph, is). 146 | arcMap("cost", cost). 147 | node("source", source).run(); 148 | 149 | MinCostArborescence mca(digraph, cost); 150 | mca.run(source); 151 | 152 | vector > > dualSolution(mca.dualNum()); 153 | 154 | for (int i = 0; i < mca.dualNum(); ++i) { 155 | dualSolution[i].first = mca.dualValue(i); 156 | for (MinCostArborescence::DualIt it(mca, i); 157 | it != INVALID; ++it) { 158 | dualSolution[i].second.insert(it); 159 | } 160 | } 161 | 162 | for (ArcIt it(digraph); it != INVALID; ++it) { 163 | if (mca.reached(digraph.source(it))) { 164 | double sum = 0.0; 165 | for (int i = 0; i < int(dualSolution.size()); ++i) { 166 | if (dualSolution[i].second.find(digraph.target(it)) 167 | != dualSolution[i].second.end() && 168 | dualSolution[i].second.find(digraph.source(it)) 169 | == dualSolution[i].second.end()) { 170 | sum += dualSolution[i].first; 171 | } 172 | } 173 | if (mca.arborescence(it)) { 174 | check(sum == cost[it], "Invalid dual solution"); 175 | } 176 | check(sum <= cost[it], "Invalid dual solution"); 177 | } 178 | } 179 | 180 | 181 | check(mca.dualValue() == mca.arborescenceCost(), "Invalid dual solution"); 182 | 183 | check(mca.reached(source), "Invalid arborescence"); 184 | for (ArcIt a(digraph); a != INVALID; ++a) { 185 | check(!mca.reached(digraph.source(a)) || 186 | mca.reached(digraph.target(a)), "Invalid arborescence"); 187 | } 188 | 189 | for (NodeIt n(digraph); n != INVALID; ++n) { 190 | if (!mca.reached(n)) continue; 191 | int cnt = 0; 192 | for (InArcIt a(digraph, n); a != INVALID; ++a) { 193 | if (mca.arborescence(a)) { 194 | check(mca.pred(n) == a, "Invalid arborescence"); 195 | ++cnt; 196 | } 197 | } 198 | check((n == source ? cnt == 0 : cnt == 1), "Invalid arborescence"); 199 | } 200 | 201 | Digraph::ArcMap arborescence(digraph); 202 | check(mca.arborescenceCost() == 203 | minCostArborescence(digraph, cost, source, arborescence), 204 | "Wrong result of the function interface"); 205 | 206 | return 0; 207 | } 208 | --------------------------------------------------------------------------------