2
2
1
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-2008 |
|
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 the usage of LEMON's General Flow algorithm |
|
22 |
/// |
|
23 |
/// This demo program reads a general network circulation problem from the |
|
24 |
/// file 'circulation-input.lgf', runs the preflow based algorithm for |
|
25 |
/// finding a feasible solution and writes the output |
|
26 |
/// to 'circulation-input.lgf' |
|
27 |
/// |
|
28 |
/// \include circulation_demo.cc |
|
29 |
|
|
30 |
#include <iostream> |
|
31 |
|
|
32 |
#include "test_tools.h" |
|
33 |
#include <lemon/list_graph.h> |
|
34 |
#include <lemon/circulation.h> |
|
35 |
#include <lemon/lgf_reader.h> |
|
36 |
|
|
37 |
using namespace lemon; |
|
38 |
|
|
39 |
char test_lgf[] = |
|
40 |
"@nodes\n" |
|
41 |
"label delta\n" |
|
42 |
"0 0\n" |
|
43 |
"1 13\n" |
|
44 |
"2 0\n" |
|
45 |
"3 0\n" |
|
46 |
"4 0\n" |
|
47 |
"5 0\n" |
|
48 |
"6 0\n" |
|
49 |
"7 0\n" |
|
50 |
"8 -13\n" |
|
51 |
"9 0\n" |
|
52 |
"@edges\n" |
|
53 |
" label lo_cap up_cap\n" |
|
54 |
"0 1 0 0 20\n" |
|
55 |
"0 2 1 0 0\n" |
|
56 |
"1 1 2 0 3\n" |
|
57 |
"1 2 3 0 8\n" |
|
58 |
"1 3 4 0 8\n" |
|
59 |
"2 5 5 0 5\n" |
|
60 |
"3 2 6 0 5\n" |
|
61 |
"3 5 7 0 5\n" |
|
62 |
"3 6 8 0 5\n" |
|
63 |
"4 3 9 0 3\n" |
|
64 |
"5 7 10 0 3\n" |
|
65 |
"5 6 11 0 10\n" |
|
66 |
"5 8 12 0 10\n" |
|
67 |
"6 8 13 0 8\n" |
|
68 |
"8 9 14 0 20\n" |
|
69 |
"8 1 15 0 5\n" |
|
70 |
"9 5 16 0 5\n" |
|
71 |
"@attributes\n" |
|
72 |
"source 1\n" |
|
73 |
"sink 8\n"; |
|
74 |
|
|
75 |
int main (int, char*[]) |
|
76 |
{ |
|
77 |
|
|
78 |
typedef ListDigraph Digraph; |
|
79 |
typedef Digraph::Node Node; |
|
80 |
typedef Digraph::NodeIt NodeIt; |
|
81 |
typedef Digraph::Arc Arc; |
|
82 |
typedef Digraph::ArcIt ArcIt; |
|
83 |
typedef Digraph::ArcMap<int> ArcMap; |
|
84 |
typedef Digraph::NodeMap<int> NodeMap; |
|
85 |
typedef Digraph::NodeMap<double> DNodeMap; |
|
86 |
|
|
87 |
Digraph g; |
|
88 |
ArcMap lo(g); |
|
89 |
ArcMap up(g); |
|
90 |
NodeMap delta(g); |
|
91 |
NodeMap nid(g); |
|
92 |
ArcMap eid(g); |
|
93 |
Node source, sink; |
|
94 |
|
|
95 |
std::istringstream input(test_lgf); |
|
96 |
DigraphReader<Digraph>(g,input). |
|
97 |
arcMap("lo_cap", lo). |
|
98 |
arcMap("up_cap", up). |
|
99 |
nodeMap("delta", delta). |
|
100 |
arcMap("label", eid). |
|
101 |
nodeMap("label", nid). |
|
102 |
node("source",source). |
|
103 |
node("sink",sink). |
|
104 |
run(); |
|
105 |
|
|
106 |
Circulation<Digraph> gen(g,lo,up,delta); |
|
107 |
bool ret=gen.run(); |
|
108 |
check(ret,"A feasible solution should have been found."); |
|
109 |
check(gen.checkFlow(), "The found flow is corrupt."); |
|
110 |
|
|
111 |
delta[source]=14; |
|
112 |
delta[sink]=-14; |
|
113 |
|
|
114 |
bool ret2=gen.run(); |
|
115 |
check(!ret2,"A feasible solution should not have been found."); |
|
116 |
check(gen.checkBarrier(), "The found barrier is corrupt."); |
|
117 |
|
|
118 |
} |
1 | 1 |
EXTRA_DIST += \ |
2 | 2 |
demo/CMakeLists.txt \ |
3 |
demo/circulation-input.lgf \ |
|
4 | 3 |
demo/digraph.lgf |
5 | 4 |
|
6 | 5 |
if WANT_DEMO |
7 | 6 |
|
8 | 7 |
noinst_PROGRAMS += \ |
9 | 8 |
demo/arg_parser_demo \ |
10 |
demo/circulation_demo \ |
|
11 | 9 |
demo/graph_to_eps_demo \ |
12 | 10 |
demo/lgf_demo |
13 | 11 |
|
14 | 12 |
endif WANT_DEMO |
15 | 13 |
|
16 | 14 |
demo_arg_parser_demo_SOURCES = demo/arg_parser_demo.cc |
17 |
demo_circulation_demo_SOURCES = demo/circulation_demo.cc |
|
18 | 15 |
demo_graph_to_eps_demo_SOURCES = demo/graph_to_eps_demo.cc |
19 | 16 |
demo_lgf_demo_SOURCES = demo/lgf_demo.cc |
1 | 1 |
EXTRA_DIST += \ |
2 | 2 |
test/CMakeLists.txt \ |
3 | 3 |
test/min_cost_flow_test.lgf |
4 | 4 |
|
5 | 5 |
noinst_HEADERS += \ |
6 | 6 |
test/graph_test.h \ |
7 | 7 |
test/test_tools.h |
8 | 8 |
|
9 | 9 |
check_PROGRAMS += \ |
10 | 10 |
test/bfs_test \ |
11 |
test/circulation_test \ |
|
11 | 12 |
test/counter_test \ |
12 | 13 |
test/dfs_test \ |
13 | 14 |
test/digraph_test \ |
14 | 15 |
test/dijkstra_test \ |
15 | 16 |
test/dim_test \ |
16 | 17 |
test/error_test \ |
17 | 18 |
test/graph_copy_test \ |
18 | 19 |
test/graph_test \ |
19 | 20 |
test/graph_utils_test \ |
20 | 21 |
test/heap_test \ |
21 | 22 |
test/kruskal_test \ |
22 | 23 |
test/maps_test \ |
23 | 24 |
test/max_matching_test \ |
24 | 25 |
test/random_test \ |
25 | 26 |
test/path_test \ |
26 | 27 |
test/suurballe_test \ |
27 | 28 |
test/test_tools_fail \ |
28 | 29 |
test/test_tools_pass \ |
29 | 30 |
test/time_measure_test \ |
30 | 31 |
test/unionfind_test |
31 | 32 |
|
32 | 33 |
TESTS += $(check_PROGRAMS) |
33 | 34 |
XFAIL_TESTS += test/test_tools_fail$(EXEEXT) |
34 | 35 |
|
35 | 36 |
test_bfs_test_SOURCES = test/bfs_test.cc |
37 |
test_circulation_test_SOURCES = test/circulation_test.cc |
|
36 | 38 |
test_counter_test_SOURCES = test/counter_test.cc |
37 | 39 |
test_dfs_test_SOURCES = test/dfs_test.cc |
38 | 40 |
test_digraph_test_SOURCES = test/digraph_test.cc |
39 | 41 |
test_dijkstra_test_SOURCES = test/dijkstra_test.cc |
40 | 42 |
test_dim_test_SOURCES = test/dim_test.cc |
41 | 43 |
test_error_test_SOURCES = test/error_test.cc |
42 | 44 |
test_graph_copy_test_SOURCES = test/graph_copy_test.cc |
43 | 45 |
test_graph_test_SOURCES = test/graph_test.cc |
44 | 46 |
test_graph_utils_test_SOURCES = test/graph_utils_test.cc |
45 | 47 |
test_heap_test_SOURCES = test/heap_test.cc |
46 | 48 |
test_kruskal_test_SOURCES = test/kruskal_test.cc |
47 | 49 |
test_maps_test_SOURCES = test/maps_test.cc |
48 | 50 |
test_max_matching_test_SOURCES = test/max_matching_test.cc |
49 | 51 |
test_path_test_SOURCES = test/path_test.cc |
50 | 52 |
test_suurballe_test_SOURCES = test/suurballe_test.cc |
51 | 53 |
test_random_test_SOURCES = test/random_test.cc |
52 | 54 |
test_test_tools_fail_SOURCES = test/test_tools_fail.cc |
53 | 55 |
test_test_tools_pass_SOURCES = test/test_tools_pass.cc |
54 | 56 |
test_time_measure_test_SOURCES = test/time_measure_test.cc |
55 | 57 |
test_unionfind_test_SOURCES = test/unionfind_test.cc |
1 |
@nodes |
|
2 |
coordinates_x coordinates_y delta label |
|
3 |
-396.638 -311.798 0 0 |
|
4 |
154.409 -214.714 13 1 |
|
5 |
-378.119 -135.808 0 2 |
|
6 |
-138.182 -58.0452 0 3 |
|
7 |
55 -76.1018 0 4 |
|
8 |
-167.302 169.88 0 5 |
|
9 |
71.6876 38.7452 0 6 |
|
10 |
-328.784 257.777 0 7 |
|
11 |
354.242 67.9628 -13 8 |
|
12 |
147 266 0 9 |
|
13 |
@edges |
|
14 |
label lo_cap up_cap |
|
15 |
0 1 0 0 20 |
|
16 |
0 2 1 0 0 |
|
17 |
1 1 2 0 3 |
|
18 |
1 2 3 0 8 |
|
19 |
1 3 4 0 8 |
|
20 |
2 5 5 0 5 |
|
21 |
3 2 6 0 5 |
|
22 |
3 5 7 0 5 |
|
23 |
3 6 8 0 5 |
|
24 |
4 3 9 0 3 |
|
25 |
5 7 10 0 3 |
|
26 |
5 6 11 0 10 |
|
27 |
5 8 12 0 10 |
|
28 |
6 8 13 0 8 |
|
29 |
8 9 14 0 20 |
|
30 |
8 1 15 0 5 |
|
31 |
9 5 16 0 5 |
|
32 |
@end |
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-2008 |
|
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 the usage of LEMON's General Flow algorithm |
|
22 |
/// |
|
23 |
/// This demo program reads a general network circulation problem from the |
|
24 |
/// file 'circulation-input.lgf', runs the preflow based algorithm for |
|
25 |
/// finding a feasible solution and writes the output |
|
26 |
/// to 'circulation-input.lgf' |
|
27 |
/// |
|
28 |
/// \include circulation_demo.cc |
|
29 |
|
|
30 |
#include <iostream> |
|
31 |
|
|
32 |
#include <lemon/list_graph.h> |
|
33 |
#include <lemon/circulation.h> |
|
34 |
#include <lemon/lgf_reader.h> |
|
35 |
#include <lemon/lgf_writer.h> |
|
36 |
|
|
37 |
using namespace lemon; |
|
38 |
|
|
39 |
|
|
40 |
int main (int, char*[]) |
|
41 |
{ |
|
42 |
|
|
43 |
typedef ListDigraph Digraph; |
|
44 |
typedef Digraph::Node Node; |
|
45 |
typedef Digraph::NodeIt NodeIt; |
|
46 |
typedef Digraph::Arc Arc; |
|
47 |
typedef Digraph::ArcIt ArcIt; |
|
48 |
typedef Digraph::ArcMap<int> ArcMap; |
|
49 |
typedef Digraph::NodeMap<int> NodeMap; |
|
50 |
typedef Digraph::NodeMap<double> DNodeMap; |
|
51 |
|
|
52 |
Digraph g; |
|
53 |
ArcMap lo(g); |
|
54 |
ArcMap up(g); |
|
55 |
NodeMap delta(g); |
|
56 |
NodeMap nid(g); |
|
57 |
ArcMap eid(g); |
|
58 |
DNodeMap cx(g); |
|
59 |
DNodeMap cy(g); |
|
60 |
|
|
61 |
DigraphReader<Digraph>(g,"circulation-input.lgf"). |
|
62 |
arcMap("lo_cap", lo). |
|
63 |
arcMap("up_cap", up). |
|
64 |
nodeMap("delta", delta). |
|
65 |
arcMap("label", eid). |
|
66 |
nodeMap("label", nid). |
|
67 |
nodeMap("coordinates_x", cx). |
|
68 |
nodeMap("coordinates_y", cy). |
|
69 |
run(); |
|
70 |
|
|
71 |
Circulation<Digraph> gen(g,lo,up,delta); |
|
72 |
bool ret=gen.run(); |
|
73 |
if(ret) |
|
74 |
{ |
|
75 |
std::cout << "\nA feasible flow has been found.\n"; |
|
76 |
if(!gen.checkFlow()) std::cerr << "Oops!!!\n"; |
|
77 |
DigraphWriter<Digraph>(g, "circulation-output.lgf"). |
|
78 |
arcMap("lo_cap", lo). |
|
79 |
arcMap("up_cap", up). |
|
80 |
arcMap("flow", gen.flowMap()). |
|
81 |
nodeMap("delta", delta). |
|
82 |
arcMap("label", eid). |
|
83 |
nodeMap("label", nid). |
|
84 |
nodeMap("coordinates_x", cx). |
|
85 |
nodeMap("coordinates_y", cy). |
|
86 |
run(); |
|
87 |
} |
|
88 |
else { |
|
89 |
std::cout << "\nThere is no such a flow\n"; |
|
90 |
Digraph::NodeMap<int> bar(g); |
|
91 |
gen.barrierMap(bar); |
|
92 |
if(!gen.checkBarrier()) std::cerr << "Dual Oops!!!\n"; |
|
93 |
|
|
94 |
DigraphWriter<Digraph>(g, "circulation-output.lgf"). |
|
95 |
arcMap("lo_cap", lo). |
|
96 |
arcMap("up_cap", up). |
|
97 |
nodeMap("barrier", bar). |
|
98 |
nodeMap("delta", delta). |
|
99 |
arcMap("label", eid). |
|
100 |
nodeMap("label", nid). |
|
101 |
nodeMap("coordinates_x", cx). |
|
102 |
nodeMap("coordinates_y", cy). |
|
103 |
run(); |
|
104 |
} |
|
105 |
std::cout << "The output is written to file 'circulation-output.lgf'\n\n"; |
|
106 |
|
|
107 |
} |
0 comments (0 inline)