lemongraph 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.yardopts +8 -0
- data/LICENSE +674 -0
- data/README.md +6 -0
- data/ext/lemon-1.3.1/AUTHORS +26 -0
- data/ext/lemon-1.3.1/CMakeLists.txt +371 -0
- data/ext/lemon-1.3.1/INSTALL +167 -0
- data/ext/lemon-1.3.1/LICENSE +32 -0
- data/ext/lemon-1.3.1/NEWS +337 -0
- data/ext/lemon-1.3.1/README +50 -0
- data/ext/lemon-1.3.1/cmake/FindCOIN.cmake +110 -0
- data/ext/lemon-1.3.1/cmake/FindGLPK.cmake +55 -0
- data/ext/lemon-1.3.1/cmake/FindGhostscript.cmake +10 -0
- data/ext/lemon-1.3.1/cmake/FindILOG.cmake +102 -0
- data/ext/lemon-1.3.1/cmake/FindSOPLEX.cmake +23 -0
- data/ext/lemon-1.3.1/cmake/LEMONConfig.cmake.in +13 -0
- data/ext/lemon-1.3.1/cmake/nsis/lemon.ico +0 -0
- data/ext/lemon-1.3.1/cmake/nsis/uninstall.ico +0 -0
- data/ext/lemon-1.3.1/cmake/version.cmake +1 -0
- data/ext/lemon-1.3.1/cmake/version.cmake.in +1 -0
- data/ext/lemon-1.3.1/contrib/CMakeLists.txt +19 -0
- data/ext/lemon-1.3.1/lemon/CMakeLists.txt +91 -0
- data/ext/lemon-1.3.1/lemon/adaptors.h +3638 -0
- data/ext/lemon-1.3.1/lemon/arg_parser.cc +474 -0
- data/ext/lemon-1.3.1/lemon/arg_parser.h +440 -0
- data/ext/lemon-1.3.1/lemon/assert.h +214 -0
- data/ext/lemon-1.3.1/lemon/base.cc +37 -0
- data/ext/lemon-1.3.1/lemon/bellman_ford.h +1116 -0
- data/ext/lemon-1.3.1/lemon/bfs.h +1754 -0
- data/ext/lemon-1.3.1/lemon/bin_heap.h +347 -0
- data/ext/lemon-1.3.1/lemon/binomial_heap.h +445 -0
- data/ext/lemon-1.3.1/lemon/bits/alteration_notifier.h +472 -0
- data/ext/lemon-1.3.1/lemon/bits/array_map.h +351 -0
- data/ext/lemon-1.3.1/lemon/bits/bezier.h +174 -0
- data/ext/lemon-1.3.1/lemon/bits/default_map.h +182 -0
- data/ext/lemon-1.3.1/lemon/bits/edge_set_extender.h +627 -0
- data/ext/lemon-1.3.1/lemon/bits/enable_if.h +131 -0
- data/ext/lemon-1.3.1/lemon/bits/graph_adaptor_extender.h +401 -0
- data/ext/lemon-1.3.1/lemon/bits/graph_extender.h +1332 -0
- data/ext/lemon-1.3.1/lemon/bits/lock.h +65 -0
- data/ext/lemon-1.3.1/lemon/bits/map_extender.h +332 -0
- data/ext/lemon-1.3.1/lemon/bits/path_dump.h +177 -0
- data/ext/lemon-1.3.1/lemon/bits/solver_bits.h +194 -0
- data/ext/lemon-1.3.1/lemon/bits/traits.h +388 -0
- data/ext/lemon-1.3.1/lemon/bits/variant.h +494 -0
- data/ext/lemon-1.3.1/lemon/bits/vector_map.h +244 -0
- data/ext/lemon-1.3.1/lemon/bits/windows.cc +166 -0
- data/ext/lemon-1.3.1/lemon/bits/windows.h +44 -0
- data/ext/lemon-1.3.1/lemon/bucket_heap.h +594 -0
- data/ext/lemon-1.3.1/lemon/capacity_scaling.h +1014 -0
- data/ext/lemon-1.3.1/lemon/cbc.cc +460 -0
- data/ext/lemon-1.3.1/lemon/cbc.h +129 -0
- data/ext/lemon-1.3.1/lemon/christofides_tsp.h +254 -0
- data/ext/lemon-1.3.1/lemon/circulation.h +807 -0
- data/ext/lemon-1.3.1/lemon/clp.cc +464 -0
- data/ext/lemon-1.3.1/lemon/clp.h +164 -0
- data/ext/lemon-1.3.1/lemon/color.cc +44 -0
- data/ext/lemon-1.3.1/lemon/color.h +204 -0
- data/ext/lemon-1.3.1/lemon/concept_check.h +77 -0
- data/ext/lemon-1.3.1/lemon/concepts/bpgraph.h +1029 -0
- data/ext/lemon-1.3.1/lemon/concepts/digraph.h +491 -0
- data/ext/lemon-1.3.1/lemon/concepts/graph.h +788 -0
- data/ext/lemon-1.3.1/lemon/concepts/graph_components.h +2134 -0
- data/ext/lemon-1.3.1/lemon/concepts/heap.h +324 -0
- data/ext/lemon-1.3.1/lemon/concepts/maps.h +223 -0
- data/ext/lemon-1.3.1/lemon/concepts/path.h +312 -0
- data/ext/lemon-1.3.1/lemon/config.h.in +22 -0
- data/ext/lemon-1.3.1/lemon/connectivity.h +1688 -0
- data/ext/lemon-1.3.1/lemon/core.h +2506 -0
- data/ext/lemon-1.3.1/lemon/cost_scaling.h +1607 -0
- data/ext/lemon-1.3.1/lemon/counter.h +249 -0
- data/ext/lemon-1.3.1/lemon/cplex.cc +994 -0
- data/ext/lemon-1.3.1/lemon/cplex.h +292 -0
- data/ext/lemon-1.3.1/lemon/cycle_canceling.h +1230 -0
- data/ext/lemon-1.3.1/lemon/dfs.h +1637 -0
- data/ext/lemon-1.3.1/lemon/dheap.h +352 -0
- data/ext/lemon-1.3.1/lemon/dijkstra.h +1303 -0
- data/ext/lemon-1.3.1/lemon/dim2.h +726 -0
- data/ext/lemon-1.3.1/lemon/dimacs.h +448 -0
- data/ext/lemon-1.3.1/lemon/edge_set.h +1420 -0
- data/ext/lemon-1.3.1/lemon/edmonds_karp.h +556 -0
- data/ext/lemon-1.3.1/lemon/elevator.h +982 -0
- data/ext/lemon-1.3.1/lemon/error.h +276 -0
- data/ext/lemon-1.3.1/lemon/euler.h +287 -0
- data/ext/lemon-1.3.1/lemon/fib_heap.h +475 -0
- data/ext/lemon-1.3.1/lemon/fractional_matching.h +2139 -0
- data/ext/lemon-1.3.1/lemon/full_graph.h +1082 -0
- data/ext/lemon-1.3.1/lemon/glpk.cc +1012 -0
- data/ext/lemon-1.3.1/lemon/glpk.h +263 -0
- data/ext/lemon-1.3.1/lemon/gomory_hu.h +568 -0
- data/ext/lemon-1.3.1/lemon/graph_to_eps.h +1186 -0
- data/ext/lemon-1.3.1/lemon/greedy_tsp.h +251 -0
- data/ext/lemon-1.3.1/lemon/grid_graph.h +699 -0
- data/ext/lemon-1.3.1/lemon/grosso_locatelli_pullan_mc.h +840 -0
- data/ext/lemon-1.3.1/lemon/hao_orlin.h +1015 -0
- data/ext/lemon-1.3.1/lemon/hartmann_orlin_mmc.h +654 -0
- data/ext/lemon-1.3.1/lemon/howard_mmc.h +651 -0
- data/ext/lemon-1.3.1/lemon/hypercube_graph.h +459 -0
- data/ext/lemon-1.3.1/lemon/insertion_tsp.h +533 -0
- data/ext/lemon-1.3.1/lemon/karp_mmc.h +590 -0
- data/ext/lemon-1.3.1/lemon/kruskal.h +324 -0
- data/ext/lemon-1.3.1/lemon/lemon.pc.in +10 -0
- data/ext/lemon-1.3.1/lemon/lgf_reader.h +3854 -0
- data/ext/lemon-1.3.1/lemon/lgf_writer.h +2687 -0
- data/ext/lemon-1.3.1/lemon/list_graph.h +2510 -0
- data/ext/lemon-1.3.1/lemon/lp.h +95 -0
- data/ext/lemon-1.3.1/lemon/lp_base.cc +30 -0
- data/ext/lemon-1.3.1/lemon/lp_base.h +2147 -0
- data/ext/lemon-1.3.1/lemon/lp_skeleton.cc +143 -0
- data/ext/lemon-1.3.1/lemon/lp_skeleton.h +234 -0
- data/ext/lemon-1.3.1/lemon/maps.h +4057 -0
- data/ext/lemon-1.3.1/lemon/matching.h +3505 -0
- data/ext/lemon-1.3.1/lemon/math.h +77 -0
- data/ext/lemon-1.3.1/lemon/max_cardinality_search.h +794 -0
- data/ext/lemon-1.3.1/lemon/min_cost_arborescence.h +808 -0
- data/ext/lemon-1.3.1/lemon/nagamochi_ibaraki.h +702 -0
- data/ext/lemon-1.3.1/lemon/nauty_reader.h +113 -0
- data/ext/lemon-1.3.1/lemon/nearest_neighbor_tsp.h +238 -0
- data/ext/lemon-1.3.1/lemon/network_simplex.h +1659 -0
- data/ext/lemon-1.3.1/lemon/opt2_tsp.h +367 -0
- data/ext/lemon-1.3.1/lemon/pairing_heap.h +474 -0
- data/ext/lemon-1.3.1/lemon/path.h +1164 -0
- data/ext/lemon-1.3.1/lemon/planarity.h +2754 -0
- data/ext/lemon-1.3.1/lemon/preflow.h +985 -0
- data/ext/lemon-1.3.1/lemon/quad_heap.h +343 -0
- data/ext/lemon-1.3.1/lemon/radix_heap.h +438 -0
- data/ext/lemon-1.3.1/lemon/radix_sort.h +487 -0
- data/ext/lemon-1.3.1/lemon/random.cc +29 -0
- data/ext/lemon-1.3.1/lemon/random.h +1005 -0
- data/ext/lemon-1.3.1/lemon/smart_graph.h +1344 -0
- data/ext/lemon-1.3.1/lemon/soplex.cc +465 -0
- data/ext/lemon-1.3.1/lemon/soplex.h +158 -0
- data/ext/lemon-1.3.1/lemon/static_graph.h +476 -0
- data/ext/lemon-1.3.1/lemon/suurballe.h +776 -0
- data/ext/lemon-1.3.1/lemon/time_measure.h +610 -0
- data/ext/lemon-1.3.1/lemon/tolerance.h +242 -0
- data/ext/lemon-1.3.1/lemon/unionfind.h +1824 -0
- data/ext/lemon-1.3.1/scripts/unify-sources.sh +390 -0
- data/ext/lemon-1.3.1/scripts/valgrind-wrapper.sh +22 -0
- data/ext/lemongraph/arc_map.cc +1007 -0
- data/ext/lemongraph/digraph.cc +282 -0
- data/ext/lemongraph/digraph_arc.cc +153 -0
- data/ext/lemongraph/digraph_node.cc +277 -0
- data/ext/lemongraph/edge_map.cc +770 -0
- data/ext/lemongraph/extconf.rb +53 -0
- data/ext/lemongraph/graph.cc +351 -0
- data/ext/lemongraph/graph_arc.cc +95 -0
- data/ext/lemongraph/graph_edge.cc +153 -0
- data/ext/lemongraph/graph_item.cc +76 -0
- data/ext/lemongraph/graph_node.cc +321 -0
- data/ext/lemongraph/lemongraph.cc +260 -0
- data/ext/lemongraph/lemongraph.hh +295 -0
- data/ext/lemongraph/lemongraph.map +6 -0
- data/ext/lemongraph/lemongraph_export.hh +31 -0
- data/ext/lemongraph/node_map.cc +1011 -0
- data/lemongraph.gemspec +176 -0
- data/lib/lemongraph/graphviz.rb +240 -0
- data/lib/lemongraph/version.rb +4 -0
- data/lib/lemongraph.rb +21 -0
- data/samples/lemondeps.rb +38 -0
- metadata +202 -0
|
@@ -0,0 +1,254 @@
|
|
|
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_CHRISTOFIDES_TSP_H
|
|
20
|
+
#define LEMON_CHRISTOFIDES_TSP_H
|
|
21
|
+
|
|
22
|
+
/// \ingroup tsp
|
|
23
|
+
/// \file
|
|
24
|
+
/// \brief Christofides algorithm for symmetric TSP
|
|
25
|
+
|
|
26
|
+
#include <lemon/full_graph.h>
|
|
27
|
+
#include <lemon/smart_graph.h>
|
|
28
|
+
#include <lemon/kruskal.h>
|
|
29
|
+
#include <lemon/matching.h>
|
|
30
|
+
#include <lemon/euler.h>
|
|
31
|
+
|
|
32
|
+
namespace lemon {
|
|
33
|
+
|
|
34
|
+
/// \ingroup tsp
|
|
35
|
+
///
|
|
36
|
+
/// \brief Christofides algorithm for symmetric TSP.
|
|
37
|
+
///
|
|
38
|
+
/// ChristofidesTsp implements Christofides' heuristic for solving
|
|
39
|
+
/// symmetric \ref tsp "TSP".
|
|
40
|
+
///
|
|
41
|
+
/// This a well-known approximation method for the TSP problem with
|
|
42
|
+
/// metric cost function.
|
|
43
|
+
/// It has a guaranteed approximation factor of 3/2 (i.e. it finds a tour
|
|
44
|
+
/// whose total cost is at most 3/2 of the optimum), but it usually
|
|
45
|
+
/// provides better solutions in practice.
|
|
46
|
+
/// This implementation runs in O(n<sup>3</sup>log(n)) time.
|
|
47
|
+
///
|
|
48
|
+
/// The algorithm starts with a \ref spantree "minimum cost spanning tree" and
|
|
49
|
+
/// finds a \ref MaxWeightedPerfectMatching "minimum cost perfect matching"
|
|
50
|
+
/// in the subgraph induced by the nodes that have odd degree in the
|
|
51
|
+
/// spanning tree.
|
|
52
|
+
/// Finally, it constructs the tour from the \ref EulerIt "Euler traversal"
|
|
53
|
+
/// of the union of the spanning tree and the matching.
|
|
54
|
+
/// During this last step, the algorithm simply skips the visited nodes
|
|
55
|
+
/// (i.e. creates shortcuts) assuming that the triangle inequality holds
|
|
56
|
+
/// for the cost function.
|
|
57
|
+
///
|
|
58
|
+
/// \tparam CM Type of the cost map.
|
|
59
|
+
///
|
|
60
|
+
/// \warning CM::Value must be a signed number type.
|
|
61
|
+
template <typename CM>
|
|
62
|
+
class ChristofidesTsp
|
|
63
|
+
{
|
|
64
|
+
public:
|
|
65
|
+
|
|
66
|
+
/// Type of the cost map
|
|
67
|
+
typedef CM CostMap;
|
|
68
|
+
/// Type of the edge costs
|
|
69
|
+
typedef typename CM::Value Cost;
|
|
70
|
+
|
|
71
|
+
private:
|
|
72
|
+
|
|
73
|
+
GRAPH_TYPEDEFS(FullGraph);
|
|
74
|
+
|
|
75
|
+
const FullGraph &_gr;
|
|
76
|
+
const CostMap &_cost;
|
|
77
|
+
std::vector<Node> _path;
|
|
78
|
+
Cost _sum;
|
|
79
|
+
|
|
80
|
+
public:
|
|
81
|
+
|
|
82
|
+
/// \brief Constructor
|
|
83
|
+
///
|
|
84
|
+
/// Constructor.
|
|
85
|
+
/// \param gr The \ref FullGraph "full graph" the algorithm runs on.
|
|
86
|
+
/// \param cost The cost map.
|
|
87
|
+
ChristofidesTsp(const FullGraph &gr, const CostMap &cost)
|
|
88
|
+
: _gr(gr), _cost(cost) {}
|
|
89
|
+
|
|
90
|
+
/// \name Execution Control
|
|
91
|
+
/// @{
|
|
92
|
+
|
|
93
|
+
/// \brief Runs the algorithm.
|
|
94
|
+
///
|
|
95
|
+
/// This function runs the algorithm.
|
|
96
|
+
///
|
|
97
|
+
/// \return The total cost of the found tour.
|
|
98
|
+
Cost run() {
|
|
99
|
+
_path.clear();
|
|
100
|
+
|
|
101
|
+
if (_gr.nodeNum() == 0) return _sum = 0;
|
|
102
|
+
else if (_gr.nodeNum() == 1) {
|
|
103
|
+
_path.push_back(_gr(0));
|
|
104
|
+
return _sum = 0;
|
|
105
|
+
}
|
|
106
|
+
else if (_gr.nodeNum() == 2) {
|
|
107
|
+
_path.push_back(_gr(0));
|
|
108
|
+
_path.push_back(_gr(1));
|
|
109
|
+
return _sum = 2 * _cost[_gr.edge(_gr(0), _gr(1))];
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Compute min. cost spanning tree
|
|
113
|
+
std::vector<Edge> tree;
|
|
114
|
+
kruskal(_gr, _cost, std::back_inserter(tree));
|
|
115
|
+
|
|
116
|
+
FullGraph::NodeMap<int> deg(_gr, 0);
|
|
117
|
+
for (int i = 0; i != int(tree.size()); ++i) {
|
|
118
|
+
Edge e = tree[i];
|
|
119
|
+
++deg[_gr.u(e)];
|
|
120
|
+
++deg[_gr.v(e)];
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Copy the induced subgraph of odd nodes
|
|
124
|
+
std::vector<Node> odd_nodes;
|
|
125
|
+
for (NodeIt u(_gr); u != INVALID; ++u) {
|
|
126
|
+
if (deg[u] % 2 == 1) odd_nodes.push_back(u);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
SmartGraph sgr;
|
|
130
|
+
SmartGraph::EdgeMap<Cost> scost(sgr);
|
|
131
|
+
for (int i = 0; i != int(odd_nodes.size()); ++i) {
|
|
132
|
+
sgr.addNode();
|
|
133
|
+
}
|
|
134
|
+
for (int i = 0; i != int(odd_nodes.size()); ++i) {
|
|
135
|
+
for (int j = 0; j != int(odd_nodes.size()); ++j) {
|
|
136
|
+
if (j == i) continue;
|
|
137
|
+
SmartGraph::Edge e =
|
|
138
|
+
sgr.addEdge(sgr.nodeFromId(i), sgr.nodeFromId(j));
|
|
139
|
+
scost[e] = -_cost[_gr.edge(odd_nodes[i], odd_nodes[j])];
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Compute min. cost perfect matching
|
|
144
|
+
MaxWeightedPerfectMatching<SmartGraph, SmartGraph::EdgeMap<Cost> >
|
|
145
|
+
mwpm(sgr, scost);
|
|
146
|
+
mwpm.run();
|
|
147
|
+
|
|
148
|
+
for (SmartGraph::EdgeIt e(sgr); e != INVALID; ++e) {
|
|
149
|
+
if (mwpm.matching(e)) {
|
|
150
|
+
tree.push_back( _gr.edge(odd_nodes[sgr.id(sgr.u(e))],
|
|
151
|
+
odd_nodes[sgr.id(sgr.v(e))]) );
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Join the spanning tree and the matching
|
|
156
|
+
sgr.clear();
|
|
157
|
+
for (int i = 0; i != _gr.nodeNum(); ++i) {
|
|
158
|
+
sgr.addNode();
|
|
159
|
+
}
|
|
160
|
+
for (int i = 0; i != int(tree.size()); ++i) {
|
|
161
|
+
int ui = _gr.id(_gr.u(tree[i])),
|
|
162
|
+
vi = _gr.id(_gr.v(tree[i]));
|
|
163
|
+
sgr.addEdge(sgr.nodeFromId(ui), sgr.nodeFromId(vi));
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Compute the tour from the Euler traversal
|
|
167
|
+
SmartGraph::NodeMap<bool> visited(sgr, false);
|
|
168
|
+
for (EulerIt<SmartGraph> e(sgr); e != INVALID; ++e) {
|
|
169
|
+
SmartGraph::Node n = sgr.target(e);
|
|
170
|
+
if (!visited[n]) {
|
|
171
|
+
_path.push_back(_gr(sgr.id(n)));
|
|
172
|
+
visited[n] = true;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
_sum = _cost[_gr.edge(_path.back(), _path.front())];
|
|
177
|
+
for (int i = 0; i < int(_path.size())-1; ++i) {
|
|
178
|
+
_sum += _cost[_gr.edge(_path[i], _path[i+1])];
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return _sum;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/// @}
|
|
185
|
+
|
|
186
|
+
/// \name Query Functions
|
|
187
|
+
/// @{
|
|
188
|
+
|
|
189
|
+
/// \brief The total cost of the found tour.
|
|
190
|
+
///
|
|
191
|
+
/// This function returns the total cost of the found tour.
|
|
192
|
+
///
|
|
193
|
+
/// \pre run() must be called before using this function.
|
|
194
|
+
Cost tourCost() const {
|
|
195
|
+
return _sum;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/// \brief Returns a const reference to the node sequence of the
|
|
199
|
+
/// found tour.
|
|
200
|
+
///
|
|
201
|
+
/// This function returns a const reference to a vector
|
|
202
|
+
/// that stores the node sequence of the found tour.
|
|
203
|
+
///
|
|
204
|
+
/// \pre run() must be called before using this function.
|
|
205
|
+
const std::vector<Node>& tourNodes() const {
|
|
206
|
+
return _path;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/// \brief Gives back the node sequence of the found tour.
|
|
210
|
+
///
|
|
211
|
+
/// This function copies the node sequence of the found tour into
|
|
212
|
+
/// an STL container through the given output iterator. The
|
|
213
|
+
/// <tt>value_type</tt> of the container must be <tt>FullGraph::Node</tt>.
|
|
214
|
+
/// For example,
|
|
215
|
+
/// \code
|
|
216
|
+
/// std::vector<FullGraph::Node> nodes(countNodes(graph));
|
|
217
|
+
/// tsp.tourNodes(nodes.begin());
|
|
218
|
+
/// \endcode
|
|
219
|
+
/// or
|
|
220
|
+
/// \code
|
|
221
|
+
/// std::list<FullGraph::Node> nodes;
|
|
222
|
+
/// tsp.tourNodes(std::back_inserter(nodes));
|
|
223
|
+
/// \endcode
|
|
224
|
+
///
|
|
225
|
+
/// \pre run() must be called before using this function.
|
|
226
|
+
template <typename Iterator>
|
|
227
|
+
void tourNodes(Iterator out) const {
|
|
228
|
+
std::copy(_path.begin(), _path.end(), out);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/// \brief Gives back the found tour as a path.
|
|
232
|
+
///
|
|
233
|
+
/// This function copies the found tour as a list of arcs/edges into
|
|
234
|
+
/// the given \ref lemon::concepts::Path "path structure".
|
|
235
|
+
///
|
|
236
|
+
/// \pre run() must be called before using this function.
|
|
237
|
+
template <typename Path>
|
|
238
|
+
void tour(Path &path) const {
|
|
239
|
+
path.clear();
|
|
240
|
+
for (int i = 0; i < int(_path.size()) - 1; ++i) {
|
|
241
|
+
path.addBack(_gr.arc(_path[i], _path[i+1]));
|
|
242
|
+
}
|
|
243
|
+
if (int(_path.size()) >= 2) {
|
|
244
|
+
path.addBack(_gr.arc(_path.back(), _path.front()));
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/// @}
|
|
249
|
+
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
}; // namespace lemon
|
|
253
|
+
|
|
254
|
+
#endif
|