Revert to long long int since currently I don't know a better solution.
3 * This file is a part of LEMON, a generic C++ optimization library
5 * Copyright (C) 2003-2008
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
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.
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
21 ///\brief Calculating an approximate Steiner-tree.
23 /// Calculating an approximate Steiner-tree.
25 /// \include steiner_demo.cc
27 #include <lemon/smart_graph.h>
28 #include <lemon/kruskal.h>
29 #include <lemon/graph_reader.h>
30 #include <lemon/time_measure.h>
31 #include <lemon/graph_to_eps.h>
32 #include <lemon/steiner.h>
33 #include <lemon/math.h>
37 using namespace lemon;
38 using namespace lemon::dim2;
42 int main(int argc, const char *argv[]) {
43 std::string lgf = argc > 1 ? argv[1] : "steiner.lgf";
44 std::string eps = argc > 2 ? argv[2] : "steiner.eps";
47 SmartUGraph::NodeMap<bool> terminal(graph);
48 SmartUGraph::NodeMap<int> label(graph);
49 SmartUGraph::NodeMap<Point<double> > coord(graph);
51 UGraphReader<SmartUGraph>(lgf, graph).
52 readNodeMap("coordinates_x", xMap(coord)).
53 readNodeMap("coordinates_y", yMap(coord)).
54 readNodeMap("terminal", terminal).run();
56 SmartUGraph::UEdgeMap<double> cost(graph);
57 for (SmartUGraph::UEdgeIt it(graph); it != INVALID; ++it) {
58 cost[it] = sqrt((coord[graph.target(it)] -
59 coord[graph.source(it)]).normSquare());
62 SteinerTree<SmartUGraph> steiner(graph, cost);
65 for (SmartUGraph::NodeIt it(graph); it != INVALID; ++it) {
67 steiner.addTerminal(it);
73 Palette nodepalette(0);
74 nodepalette.add(Color(1.0, 1.0, 1.0));
75 nodepalette.add(Color(0.0, 1.0, 0.0));
76 nodepalette.add(Color(0.5, 0.5, 0.5));
77 SmartUGraph::NodeMap<int> nodecolor(graph);
78 for (SmartUGraph::NodeIt it(graph); it != INVALID; ++it) {
79 if (steiner.terminal(it)) {
81 } else if (steiner.steiner(it)) {
89 Palette edgepalette(0);
90 edgepalette.add(Color(0.0, 0.0, 0.0));
91 edgepalette.add(Color(1.0, 0.0, 0.0));
92 SmartUGraph::UEdgeMap<int> edgecolor(graph);
93 for (SmartUGraph::UEdgeIt it(graph); it != INVALID; ++it) {
94 edgecolor[it] = steiner.tree(it) ? 1 : 0;
98 graphToEps(graph, eps).
99 coords(coord).undirected().
100 nodeScale(1.0).scaleToA4().
101 nodeColors(composeMap(nodepalette, nodecolor)).
102 edgeColors(composeMap(edgepalette, edgecolor)).
103 nodeTexts(label).nodeTextSize(8).run();
105 std::cout << "The tree constructed: " << eps << std::endl;
106 std::cout << "The cost of the tree: " << steiner.treeValue() << std::endl;