3 * This file is a part of LEMON, a generic C++ optimization library
5 * Copyright (C) 2003-2007
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
19 #include <lemon/smart_graph.h>
20 #include <lemon/kruskal.h>
21 #include <lemon/graph_reader.h>
22 #include <lemon/time_measure.h>
23 #include <lemon/graph_to_eps.h>
25 #include <lemon/steiner.h>
30 using namespace lemon;
31 using namespace lemon::dim2;
35 int main(int argc, const char *argv[]) {
36 std::string lgf = argc > 1 ? argv[1] : "steiner.lgf";
37 std::string eps = argc > 2 ? argv[2] : "steiner.eps";
40 SmartUGraph::NodeMap<bool> terminal(graph);
41 SmartUGraph::NodeMap<int> label(graph);
42 SmartUGraph::NodeMap<Point<double> > coord(graph);
44 UGraphReader<SmartUGraph>(lgf, graph).
45 readNodeMap("coordinates_x", xMap(coord)).
46 readNodeMap("coordinates_y", yMap(coord)).
47 readNodeMap("terminal", terminal).run();
49 SmartUGraph::UEdgeMap<double> cost(graph);
50 for (SmartUGraph::UEdgeIt it(graph); it != INVALID; ++it) {
51 cost[it] = sqrt((coord[graph.target(it)] -
52 coord[graph.source(it)]).normSquare());
55 SteinerTree<SmartUGraph> steiner(graph, cost);
58 for (SmartUGraph::NodeIt it(graph); it != INVALID; ++it) {
60 steiner.addTerminal(it);
66 Palette nodepalette(0);
67 nodepalette.add(Color(1.0, 1.0, 1.0));
68 nodepalette.add(Color(0.0, 1.0, 0.0));
69 nodepalette.add(Color(0.5, 0.5, 0.5));
70 SmartUGraph::NodeMap<int> nodecolor(graph);
71 for (SmartUGraph::NodeIt it(graph); it != INVALID; ++it) {
72 if (steiner.terminal(it)) {
74 } else if (steiner.steiner(it)) {
82 Palette edgepalette(0);
83 edgepalette.add(Color(0.0, 0.0, 0.0));
84 edgepalette.add(Color(1.0, 0.0, 0.0));
85 SmartUGraph::UEdgeMap<int> edgecolor(graph);
86 for (SmartUGraph::UEdgeIt it(graph); it != INVALID; ++it) {
87 edgecolor[it] = steiner.tree(it) ? 1 : 0;
91 graphToEps(graph, eps).
92 coords(coord).undirected().
93 nodeScale(1.0).scaleToA4().
94 nodeColors(composeMap(nodepalette, nodecolor)).
95 edgeColors(composeMap(edgepalette, edgecolor)).
96 nodeTexts(label).nodeTextSize(8).run();
98 std::cout << "The tree constructed: " << eps << std::endl;
99 std::cout << "The cost of the tree: " << steiner.treeValue() << std::endl;