2
4
2
1 | 1 |
EXTRA_DIST += \ |
2 | 2 |
lemon/lemon.pc.in \ |
3 | 3 |
lemon/CMakeLists.txt |
4 | 4 |
|
5 | 5 |
pkgconfig_DATA += lemon/lemon.pc |
6 | 6 |
|
7 | 7 |
lib_LTLIBRARIES += lemon/libemon.la |
8 | 8 |
|
9 | 9 |
lemon_libemon_la_SOURCES = \ |
10 | 10 |
lemon/arg_parser.cc \ |
11 | 11 |
lemon/base.cc \ |
12 | 12 |
lemon/color.cc \ |
13 | 13 |
lemon/lp_base.cc \ |
14 | 14 |
lemon/lp_skeleton.cc \ |
15 | 15 |
lemon/random.cc \ |
16 | 16 |
lemon/bits/windows.cc |
17 | 17 |
|
18 | 18 |
|
19 | 19 |
lemon_libemon_la_CXXFLAGS = \ |
20 | 20 |
$(AM_CXXFLAGS) \ |
21 | 21 |
$(GLPK_CFLAGS) \ |
22 | 22 |
$(CPLEX_CFLAGS) \ |
23 | 23 |
$(SOPLEX_CXXFLAGS) \ |
24 | 24 |
$(CLP_CXXFLAGS) \ |
25 | 25 |
$(CBC_CXXFLAGS) |
26 | 26 |
|
27 | 27 |
lemon_libemon_la_LDFLAGS = \ |
28 | 28 |
$(GLPK_LIBS) \ |
29 | 29 |
$(CPLEX_LIBS) \ |
30 | 30 |
$(SOPLEX_LIBS) \ |
31 | 31 |
$(CLP_LIBS) \ |
32 | 32 |
$(CBC_LIBS) |
33 | 33 |
|
34 | 34 |
if HAVE_GLPK |
35 | 35 |
lemon_libemon_la_SOURCES += lemon/glpk.cc |
36 | 36 |
endif |
37 | 37 |
|
38 | 38 |
if HAVE_CPLEX |
39 | 39 |
lemon_libemon_la_SOURCES += lemon/cplex.cc |
40 | 40 |
endif |
41 | 41 |
|
42 | 42 |
if HAVE_SOPLEX |
43 | 43 |
lemon_libemon_la_SOURCES += lemon/soplex.cc |
44 | 44 |
endif |
45 | 45 |
|
46 | 46 |
if HAVE_CLP |
47 | 47 |
lemon_libemon_la_SOURCES += lemon/clp.cc |
48 | 48 |
endif |
49 | 49 |
|
50 | 50 |
if HAVE_CBC |
51 | 51 |
lemon_libemon_la_SOURCES += lemon/cbc.cc |
52 | 52 |
endif |
53 | 53 |
|
54 | 54 |
lemon_HEADERS += \ |
55 | 55 |
lemon/adaptors.h \ |
56 | 56 |
lemon/arg_parser.h \ |
57 | 57 |
lemon/assert.h \ |
58 | 58 |
lemon/bfs.h \ |
59 | 59 |
lemon/bin_heap.h \ |
60 | 60 |
lemon/circulation.h \ |
61 | 61 |
lemon/clp.h \ |
62 | 62 |
lemon/color.h \ |
63 | 63 |
lemon/concept_check.h \ |
64 | 64 |
lemon/connectivity.h \ |
65 | 65 |
lemon/counter.h \ |
66 | 66 |
lemon/core.h \ |
67 | 67 |
lemon/cplex.h \ |
68 | 68 |
lemon/dfs.h \ |
69 | 69 |
lemon/dijkstra.h \ |
70 | 70 |
lemon/dim2.h \ |
71 | 71 |
lemon/dimacs.h \ |
72 | 72 |
lemon/edge_set.h \ |
73 | 73 |
lemon/elevator.h \ |
74 | 74 |
lemon/error.h \ |
75 | 75 |
lemon/euler.h \ |
76 | 76 |
lemon/full_graph.h \ |
77 | 77 |
lemon/glpk.h \ |
78 | 78 |
lemon/gomory_hu.h \ |
79 | 79 |
lemon/graph_to_eps.h \ |
80 | 80 |
lemon/grid_graph.h \ |
81 | 81 |
lemon/hypercube_graph.h \ |
82 | 82 |
lemon/kruskal.h \ |
83 | 83 |
lemon/hao_orlin.h \ |
84 | 84 |
lemon/lgf_reader.h \ |
85 | 85 |
lemon/lgf_writer.h \ |
86 | 86 |
lemon/list_graph.h \ |
87 | 87 |
lemon/lp.h \ |
88 | 88 |
lemon/lp_base.h \ |
89 | 89 |
lemon/lp_skeleton.h \ |
90 | 90 |
lemon/list_graph.h \ |
91 | 91 |
lemon/maps.h \ |
92 |
lemon/matching.h \ |
|
92 | 93 |
lemon/math.h \ |
93 |
lemon/max_matching.h \ |
|
94 | 94 |
lemon/min_cost_arborescence.h \ |
95 | 95 |
lemon/nauty_reader.h \ |
96 | 96 |
lemon/path.h \ |
97 | 97 |
lemon/preflow.h \ |
98 | 98 |
lemon/radix_sort.h \ |
99 | 99 |
lemon/random.h \ |
100 | 100 |
lemon/smart_graph.h \ |
101 | 101 |
lemon/soplex.h \ |
102 | 102 |
lemon/suurballe.h \ |
103 | 103 |
lemon/time_measure.h \ |
104 | 104 |
lemon/tolerance.h \ |
105 | 105 |
lemon/unionfind.h \ |
106 | 106 |
lemon/bits/windows.h |
107 | 107 |
|
108 | 108 |
bits_HEADERS += \ |
109 | 109 |
lemon/bits/alteration_notifier.h \ |
110 | 110 |
lemon/bits/array_map.h \ |
111 | 111 |
lemon/bits/base_extender.h \ |
112 | 112 |
lemon/bits/bezier.h \ |
113 | 113 |
lemon/bits/default_map.h \ |
114 | 114 |
lemon/bits/edge_set_extender.h \ |
115 | 115 |
lemon/bits/enable_if.h \ |
116 | 116 |
lemon/bits/graph_adaptor_extender.h \ |
117 | 117 |
lemon/bits/graph_extender.h \ |
118 | 118 |
lemon/bits/map_extender.h \ |
119 | 119 |
lemon/bits/path_dump.h \ |
120 | 120 |
lemon/bits/solver_bits.h \ |
121 | 121 |
lemon/bits/traits.h \ |
122 | 122 |
lemon/bits/variant.h \ |
123 | 123 |
lemon/bits/vector_map.h |
124 | 124 |
|
125 | 125 |
concept_HEADERS += \ |
126 | 126 |
lemon/concepts/digraph.h \ |
127 | 127 |
lemon/concepts/graph.h \ |
128 | 128 |
lemon/concepts/graph_components.h \ |
129 | 129 |
lemon/concepts/heap.h \ |
130 | 130 |
lemon/concepts/maps.h \ |
131 | 131 |
lemon/concepts/path.h |
1 | 1 |
INCLUDE_DIRECTORIES( |
2 | 2 |
${PROJECT_SOURCE_DIR} |
3 | 3 |
${PROJECT_BINARY_DIR} |
4 | 4 |
) |
5 | 5 |
|
6 | 6 |
IF(HAVE_GLPK) |
7 | 7 |
INCLUDE_DIRECTORIES(${GLPK_INCLUDE_DIR}) |
8 | 8 |
ENDIF(HAVE_GLPK) |
9 | 9 |
|
10 | 10 |
LINK_DIRECTORIES(${PROJECT_BINARY_DIR}/lemon) |
11 | 11 |
|
12 | 12 |
SET(TESTS |
13 | 13 |
adaptors_test |
14 | 14 |
bfs_test |
15 | 15 |
circulation_test |
16 | 16 |
counter_test |
17 | 17 |
dfs_test |
18 | 18 |
digraph_test |
19 | 19 |
dijkstra_test |
20 | 20 |
dim_test |
21 | 21 |
edge_set_test |
22 | 22 |
error_test |
23 | 23 |
euler_test |
24 | 24 |
gomory_hu_test |
25 | 25 |
graph_copy_test |
26 | 26 |
graph_test |
27 | 27 |
graph_utils_test |
28 | 28 |
hao_orlin_test |
29 | 29 |
heap_test |
30 | 30 |
kruskal_test |
31 | 31 |
maps_test |
32 |
|
|
32 |
matching_test |
|
33 | 33 |
min_cost_arborescence_test |
34 | 34 |
path_test |
35 | 35 |
preflow_test |
36 | 36 |
radix_sort_test |
37 | 37 |
random_test |
38 | 38 |
suurballe_test |
39 | 39 |
time_measure_test |
40 | 40 |
unionfind_test) |
41 | 41 |
|
42 | 42 |
IF(HAVE_LP) |
43 | 43 |
ADD_EXECUTABLE(lp_test lp_test.cc) |
44 | 44 |
IF(HAVE_GLPK) |
45 | 45 |
TARGET_LINK_LIBRARIES(lp_test lemon ${GLPK_LIBRARIES}) |
46 | 46 |
ENDIF(HAVE_GLPK) |
47 | 47 |
ADD_TEST(lp_test lp_test) |
48 | 48 |
|
49 | 49 |
IF(WIN32 AND HAVE_GLPK) |
50 | 50 |
GET_TARGET_PROPERTY(TARGET_LOC lp_test LOCATION) |
51 | 51 |
GET_FILENAME_COMPONENT(TARGET_PATH ${TARGET_LOC} PATH) |
52 | 52 |
ADD_CUSTOM_COMMAND(TARGET lp_test POST_BUILD |
53 | 53 |
COMMAND cmake -E copy ${GLPK_BIN_DIR}/glpk.dll ${TARGET_PATH} |
54 | 54 |
COMMAND cmake -E copy ${GLPK_BIN_DIR}/libltdl3.dll ${TARGET_PATH} |
55 | 55 |
COMMAND cmake -E copy ${GLPK_BIN_DIR}/zlib1.dll ${TARGET_PATH} |
56 | 56 |
) |
57 | 57 |
ENDIF(WIN32 AND HAVE_GLPK) |
58 | 58 |
ENDIF(HAVE_LP) |
59 | 59 |
|
60 | 60 |
IF(HAVE_MIP) |
61 | 61 |
ADD_EXECUTABLE(mip_test mip_test.cc) |
62 | 62 |
IF(HAVE_GLPK) |
63 | 63 |
TARGET_LINK_LIBRARIES(mip_test lemon ${GLPK_LIBRARIES}) |
64 | 64 |
ENDIF(HAVE_GLPK) |
65 | 65 |
ADD_TEST(mip_test mip_test) |
66 | 66 |
|
67 | 67 |
IF(WIN32 AND HAVE_GLPK) |
68 | 68 |
GET_TARGET_PROPERTY(TARGET_LOC mip_test LOCATION) |
69 | 69 |
GET_FILENAME_COMPONENT(TARGET_PATH ${TARGET_LOC} PATH) |
70 | 70 |
ADD_CUSTOM_COMMAND(TARGET mip_test POST_BUILD |
71 | 71 |
COMMAND cmake -E copy ${GLPK_BIN_DIR}/glpk.dll ${TARGET_PATH} |
72 | 72 |
COMMAND cmake -E copy ${GLPK_BIN_DIR}/libltdl3.dll ${TARGET_PATH} |
73 | 73 |
COMMAND cmake -E copy ${GLPK_BIN_DIR}/zlib1.dll ${TARGET_PATH} |
74 | 74 |
) |
75 | 75 |
ENDIF(WIN32 AND HAVE_GLPK) |
76 | 76 |
ENDIF(HAVE_MIP) |
77 | 77 |
|
78 | 78 |
FOREACH(TEST_NAME ${TESTS}) |
79 | 79 |
ADD_EXECUTABLE(${TEST_NAME} ${TEST_NAME}.cc) |
80 | 80 |
TARGET_LINK_LIBRARIES(${TEST_NAME} lemon) |
81 | 81 |
ADD_TEST(${TEST_NAME} ${TEST_NAME}) |
82 | 82 |
ENDFOREACH(TEST_NAME) |
1 | 1 |
EXTRA_DIST += \ |
2 | 2 |
test/CMakeLists.txt |
3 | 3 |
|
4 | 4 |
noinst_HEADERS += \ |
5 | 5 |
test/graph_test.h \ |
6 | 6 |
test/test_tools.h |
7 | 7 |
|
8 | 8 |
check_PROGRAMS += \ |
9 | 9 |
test/adaptors_test \ |
10 | 10 |
test/bfs_test \ |
11 | 11 |
test/circulation_test \ |
12 | 12 |
test/counter_test \ |
13 | 13 |
test/dfs_test \ |
14 | 14 |
test/digraph_test \ |
15 | 15 |
test/dijkstra_test \ |
16 | 16 |
test/dim_test \ |
17 | 17 |
test/edge_set_test \ |
18 | 18 |
test/error_test \ |
19 | 19 |
test/euler_test \ |
20 | 20 |
test/gomory_hu_test \ |
21 | 21 |
test/graph_copy_test \ |
22 | 22 |
test/graph_test \ |
23 | 23 |
test/graph_utils_test \ |
24 | 24 |
test/hao_orlin_test \ |
25 | 25 |
test/heap_test \ |
26 | 26 |
test/kruskal_test \ |
27 | 27 |
test/maps_test \ |
28 |
test/ |
|
28 |
test/matching_test \ |
|
29 | 29 |
test/min_cost_arborescence_test \ |
30 | 30 |
test/path_test \ |
31 | 31 |
test/preflow_test \ |
32 | 32 |
test/radix_sort_test \ |
33 | 33 |
test/random_test \ |
34 | 34 |
test/suurballe_test \ |
35 | 35 |
test/test_tools_fail \ |
36 | 36 |
test/test_tools_pass \ |
37 | 37 |
test/time_measure_test \ |
38 | 38 |
test/unionfind_test |
39 | 39 |
|
40 | 40 |
test_test_tools_pass_DEPENDENCIES = demo |
41 | 41 |
|
42 | 42 |
if HAVE_LP |
43 | 43 |
check_PROGRAMS += test/lp_test |
44 | 44 |
endif HAVE_LP |
45 | 45 |
if HAVE_MIP |
46 | 46 |
check_PROGRAMS += test/mip_test |
47 | 47 |
endif HAVE_MIP |
48 | 48 |
|
49 | 49 |
TESTS += $(check_PROGRAMS) |
50 | 50 |
XFAIL_TESTS += test/test_tools_fail$(EXEEXT) |
51 | 51 |
|
52 | 52 |
test_adaptors_test_SOURCES = test/adaptors_test.cc |
53 | 53 |
test_bfs_test_SOURCES = test/bfs_test.cc |
54 | 54 |
test_circulation_test_SOURCES = test/circulation_test.cc |
55 | 55 |
test_counter_test_SOURCES = test/counter_test.cc |
56 | 56 |
test_dfs_test_SOURCES = test/dfs_test.cc |
57 | 57 |
test_digraph_test_SOURCES = test/digraph_test.cc |
58 | 58 |
test_dijkstra_test_SOURCES = test/dijkstra_test.cc |
59 | 59 |
test_dim_test_SOURCES = test/dim_test.cc |
60 | 60 |
test_edge_set_test_SOURCES = test/edge_set_test.cc |
61 | 61 |
test_error_test_SOURCES = test/error_test.cc |
62 | 62 |
test_euler_test_SOURCES = test/euler_test.cc |
63 | 63 |
test_gomory_hu_test_SOURCES = test/gomory_hu_test.cc |
64 | 64 |
test_graph_copy_test_SOURCES = test/graph_copy_test.cc |
65 | 65 |
test_graph_test_SOURCES = test/graph_test.cc |
66 | 66 |
test_graph_utils_test_SOURCES = test/graph_utils_test.cc |
67 | 67 |
test_heap_test_SOURCES = test/heap_test.cc |
68 | 68 |
test_kruskal_test_SOURCES = test/kruskal_test.cc |
69 | 69 |
test_hao_orlin_test_SOURCES = test/hao_orlin_test.cc |
70 | 70 |
test_lp_test_SOURCES = test/lp_test.cc |
71 | 71 |
test_maps_test_SOURCES = test/maps_test.cc |
72 | 72 |
test_mip_test_SOURCES = test/mip_test.cc |
73 |
|
|
73 |
test_matching_test_SOURCES = test/matching_test.cc |
|
74 | 74 |
test_min_cost_arborescence_test_SOURCES = test/min_cost_arborescence_test.cc |
75 | 75 |
test_path_test_SOURCES = test/path_test.cc |
76 | 76 |
test_preflow_test_SOURCES = test/preflow_test.cc |
77 | 77 |
test_radix_sort_test_SOURCES = test/radix_sort_test.cc |
78 | 78 |
test_suurballe_test_SOURCES = test/suurballe_test.cc |
79 | 79 |
test_random_test_SOURCES = test/random_test.cc |
80 | 80 |
test_test_tools_fail_SOURCES = test/test_tools_fail.cc |
81 | 81 |
test_test_tools_pass_SOURCES = test/test_tools_pass.cc |
82 | 82 |
test_time_measure_test_SOURCES = test/time_measure_test.cc |
83 | 83 |
test_unionfind_test_SOURCES = test/unionfind_test.cc |
1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
2 | 2 |
* |
3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2009 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
8 | 8 |
* |
9 | 9 |
* Permission to use, modify and distribute this software is granted |
10 | 10 |
* provided that this copyright notice appears in all copies. For |
11 | 11 |
* precise terms see the accompanying LICENSE file. |
12 | 12 |
* |
13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
14 | 14 |
* express or implied, and with no claim as to its suitability for any |
15 | 15 |
* purpose. |
16 | 16 |
* |
17 | 17 |
*/ |
18 | 18 |
|
19 | 19 |
#include <iostream> |
20 | 20 |
#include <sstream> |
21 | 21 |
#include <vector> |
22 | 22 |
#include <queue> |
23 | 23 |
#include <cstdlib> |
24 | 24 |
|
25 |
#include <lemon/ |
|
25 |
#include <lemon/matching.h> |
|
26 | 26 |
#include <lemon/smart_graph.h> |
27 | 27 |
#include <lemon/concepts/graph.h> |
28 | 28 |
#include <lemon/concepts/maps.h> |
29 | 29 |
#include <lemon/lgf_reader.h> |
30 | 30 |
#include <lemon/math.h> |
31 | 31 |
|
32 | 32 |
#include "test_tools.h" |
33 | 33 |
|
34 | 34 |
using namespace std; |
35 | 35 |
using namespace lemon; |
36 | 36 |
|
37 | 37 |
GRAPH_TYPEDEFS(SmartGraph); |
38 | 38 |
|
39 | 39 |
|
40 | 40 |
const int lgfn = 3; |
41 | 41 |
const std::string lgf[lgfn] = { |
42 | 42 |
"@nodes\n" |
43 | 43 |
"label\n" |
44 | 44 |
"0\n" |
45 | 45 |
"1\n" |
46 | 46 |
"2\n" |
47 | 47 |
"3\n" |
48 | 48 |
"4\n" |
49 | 49 |
"5\n" |
50 | 50 |
"6\n" |
51 | 51 |
"7\n" |
52 | 52 |
"@edges\n" |
53 | 53 |
" label weight\n" |
54 | 54 |
"7 4 0 984\n" |
55 | 55 |
"0 7 1 73\n" |
56 | 56 |
"7 1 2 204\n" |
57 | 57 |
"2 3 3 583\n" |
58 | 58 |
"2 7 4 565\n" |
59 | 59 |
"2 1 5 582\n" |
60 | 60 |
"0 4 6 551\n" |
61 | 61 |
"2 5 7 385\n" |
62 | 62 |
"1 5 8 561\n" |
63 | 63 |
"5 3 9 484\n" |
64 | 64 |
"7 5 10 904\n" |
65 | 65 |
"3 6 11 47\n" |
66 | 66 |
"7 6 12 888\n" |
67 | 67 |
"3 0 13 747\n" |
68 | 68 |
"6 1 14 310\n", |
69 | 69 |
|
70 | 70 |
"@nodes\n" |
71 | 71 |
"label\n" |
72 | 72 |
"0\n" |
73 | 73 |
"1\n" |
74 | 74 |
"2\n" |
75 | 75 |
"3\n" |
76 | 76 |
"4\n" |
77 | 77 |
"5\n" |
78 | 78 |
"6\n" |
79 | 79 |
"7\n" |
80 | 80 |
"@edges\n" |
81 | 81 |
" label weight\n" |
82 | 82 |
"2 5 0 710\n" |
83 | 83 |
"0 5 1 241\n" |
84 | 84 |
"2 4 2 856\n" |
85 | 85 |
"2 6 3 762\n" |
86 | 86 |
"4 1 4 747\n" |
87 | 87 |
"6 1 5 962\n" |
88 | 88 |
"4 7 6 723\n" |
89 | 89 |
"1 7 7 661\n" |
90 | 90 |
"2 3 8 376\n" |
91 | 91 |
"1 0 9 416\n" |
92 | 92 |
"6 7 10 391\n", |
93 | 93 |
|
94 | 94 |
"@nodes\n" |
95 | 95 |
"label\n" |
96 | 96 |
"0\n" |
97 | 97 |
"1\n" |
98 | 98 |
"2\n" |
99 | 99 |
"3\n" |
100 | 100 |
"4\n" |
101 | 101 |
"5\n" |
102 | 102 |
"6\n" |
103 | 103 |
"7\n" |
104 | 104 |
"@edges\n" |
105 | 105 |
" label weight\n" |
106 | 106 |
"6 2 0 553\n" |
107 | 107 |
"0 7 1 653\n" |
108 | 108 |
"6 3 2 22\n" |
109 | 109 |
"4 7 3 846\n" |
110 | 110 |
"7 2 4 981\n" |
111 | 111 |
"7 6 5 250\n" |
112 | 112 |
"5 2 6 539\n", |
113 | 113 |
}; |
114 | 114 |
|
115 | 115 |
void checkMaxMatchingCompile() |
116 | 116 |
{ |
117 | 117 |
typedef concepts::Graph Graph; |
118 | 118 |
typedef Graph::Node Node; |
119 | 119 |
typedef Graph::Edge Edge; |
120 | 120 |
typedef Graph::EdgeMap<bool> MatMap; |
121 | 121 |
1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
2 | 2 |
* |
3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2009 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
8 | 8 |
* |
9 | 9 |
* Permission to use, modify and distribute this software is granted |
10 | 10 |
* provided that this copyright notice appears in all copies. For |
11 | 11 |
* precise terms see the accompanying LICENSE file. |
12 | 12 |
* |
13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
14 | 14 |
* express or implied, and with no claim as to its suitability for any |
15 | 15 |
* purpose. |
16 | 16 |
* |
17 | 17 |
*/ |
18 | 18 |
|
19 | 19 |
///\ingroup tools |
20 | 20 |
///\file |
21 | 21 |
///\brief DIMACS problem solver. |
22 | 22 |
/// |
23 | 23 |
/// This program solves various problems given in DIMACS format. |
24 | 24 |
/// |
25 | 25 |
/// See |
26 | 26 |
/// \code |
27 | 27 |
/// dimacs-solver --help |
28 | 28 |
/// \endcode |
29 | 29 |
/// for more info on usage. |
30 | 30 |
|
31 | 31 |
#include <iostream> |
32 | 32 |
#include <fstream> |
33 | 33 |
#include <cstring> |
34 | 34 |
|
35 | 35 |
#include <lemon/smart_graph.h> |
36 | 36 |
#include <lemon/dimacs.h> |
37 | 37 |
#include <lemon/lgf_writer.h> |
38 | 38 |
#include <lemon/time_measure.h> |
39 | 39 |
|
40 | 40 |
#include <lemon/arg_parser.h> |
41 | 41 |
#include <lemon/error.h> |
42 | 42 |
|
43 | 43 |
#include <lemon/dijkstra.h> |
44 | 44 |
#include <lemon/preflow.h> |
45 |
#include <lemon/ |
|
45 |
#include <lemon/matching.h> |
|
46 | 46 |
|
47 | 47 |
using namespace lemon; |
48 | 48 |
typedef SmartDigraph Digraph; |
49 | 49 |
DIGRAPH_TYPEDEFS(Digraph); |
50 | 50 |
typedef SmartGraph Graph; |
51 | 51 |
|
52 | 52 |
template<class Value> |
53 | 53 |
void solve_sp(ArgParser &ap, std::istream &is, std::ostream &, |
54 | 54 |
DimacsDescriptor &desc) |
55 | 55 |
{ |
56 | 56 |
bool report = !ap.given("q"); |
57 | 57 |
Digraph g; |
58 | 58 |
Node s; |
59 | 59 |
Digraph::ArcMap<Value> len(g); |
60 | 60 |
Timer t; |
61 | 61 |
t.restart(); |
62 | 62 |
readDimacsSp(is, g, len, s, desc); |
63 | 63 |
if(report) std::cerr << "Read the file: " << t << '\n'; |
64 | 64 |
t.restart(); |
65 | 65 |
Dijkstra<Digraph, Digraph::ArcMap<Value> > dij(g,len); |
66 | 66 |
if(report) std::cerr << "Setup Dijkstra class: " << t << '\n'; |
67 | 67 |
t.restart(); |
68 | 68 |
dij.run(s); |
69 | 69 |
if(report) std::cerr << "Run Dijkstra: " << t << '\n'; |
70 | 70 |
} |
71 | 71 |
|
72 | 72 |
template<class Value> |
73 | 73 |
void solve_max(ArgParser &ap, std::istream &is, std::ostream &, |
74 | 74 |
Value infty, DimacsDescriptor &desc) |
75 | 75 |
{ |
76 | 76 |
bool report = !ap.given("q"); |
77 | 77 |
Digraph g; |
78 | 78 |
Node s,t; |
79 | 79 |
Digraph::ArcMap<Value> cap(g); |
80 | 80 |
Timer ti; |
81 | 81 |
ti.restart(); |
82 | 82 |
readDimacsMax(is, g, cap, s, t, infty, desc); |
83 | 83 |
if(report) std::cerr << "Read the file: " << ti << '\n'; |
84 | 84 |
ti.restart(); |
85 | 85 |
Preflow<Digraph, Digraph::ArcMap<Value> > pre(g,cap,s,t); |
86 | 86 |
if(report) std::cerr << "Setup Preflow class: " << ti << '\n'; |
87 | 87 |
ti.restart(); |
88 | 88 |
pre.run(); |
89 | 89 |
if(report) std::cerr << "Run Preflow: " << ti << '\n'; |
90 | 90 |
if(report) std::cerr << "\nMax flow value: " << pre.flowValue() << '\n'; |
91 | 91 |
} |
92 | 92 |
|
93 | 93 |
void solve_mat(ArgParser &ap, std::istream &is, std::ostream &, |
94 | 94 |
DimacsDescriptor &desc) |
95 | 95 |
{ |
96 | 96 |
bool report = !ap.given("q"); |
97 | 97 |
Graph g; |
98 | 98 |
Timer ti; |
99 | 99 |
ti.restart(); |
100 | 100 |
readDimacsMat(is, g, desc); |
101 | 101 |
if(report) std::cerr << "Read the file: " << ti << '\n'; |
102 | 102 |
ti.restart(); |
103 | 103 |
MaxMatching<Graph> mat(g); |
104 | 104 |
if(report) std::cerr << "Setup MaxMatching class: " << ti << '\n'; |
105 | 105 |
ti.restart(); |
106 | 106 |
mat.run(); |
107 | 107 |
if(report) std::cerr << "Run MaxMatching: " << ti << '\n'; |
108 | 108 |
if(report) std::cerr << "\nCardinality of max matching: " |
109 | 109 |
<< mat.matchingSize() << '\n'; |
110 | 110 |
} |
111 | 111 |
|
112 | 112 |
|
113 | 113 |
template<class Value> |
114 | 114 |
void solve(ArgParser &ap, std::istream &is, std::ostream &os, |
115 | 115 |
DimacsDescriptor &desc) |
116 | 116 |
{ |
117 | 117 |
std::stringstream iss(static_cast<std::string>(ap["infcap"])); |
118 | 118 |
Value infty; |
119 | 119 |
iss >> infty; |
120 | 120 |
if(iss.fail()) |
121 | 121 |
{ |
122 | 122 |
std::cerr << "Cannot interpret '" |
123 | 123 |
<< static_cast<std::string>(ap["infcap"]) << "' as infinite" |
124 | 124 |
<< std::endl; |
125 | 125 |
exit(1); |
126 | 126 |
} |
127 | 127 |
|
128 | 128 |
switch(desc.type) |
129 | 129 |
{ |
130 | 130 |
case DimacsDescriptor::MIN: |
131 | 131 |
std::cerr << |
132 | 132 |
"\n\n Sorry, the min. cost flow solver is not yet available.\n"; |
133 | 133 |
break; |
134 | 134 |
case DimacsDescriptor::MAX: |
135 | 135 |
solve_max<Value>(ap,is,os,infty,desc); |
136 | 136 |
break; |
137 | 137 |
case DimacsDescriptor::SP: |
138 | 138 |
solve_sp<Value>(ap,is,os,desc); |
139 | 139 |
break; |
140 | 140 |
case DimacsDescriptor::MAT: |
141 | 141 |
solve_mat(ap,is,os,desc); |
0 comments (0 inline)