I only corrected bugs to make things compile: some featured not implemented here yet.
1 #include <lemon/smart_graph.h>
2 #include <lemon/kruskal.h>
3 #include <lemon/graph_reader.h>
4 #include <lemon/time_measure.h>
5 #include <lemon/graph_to_eps.h>
7 #include <lemon/steiner.h>
12 using namespace lemon;
13 using namespace lemon::dim2;
17 int main(int argc, const char *argv[]) {
18 std::string lgf = argc > 1 ? argv[1] : "steiner.lgf";
19 std::string eps = argc > 2 ? argv[2] : "steiner.eps";
22 SmartUGraph::NodeMap<bool> terminal(graph);
23 SmartUGraph::NodeMap<int> label(graph);
24 SmartUGraph::NodeMap<Point<double> > coord(graph);
26 UGraphReader<SmartUGraph>(lgf, graph).
27 readNodeMap("coordinates_x", xMap(coord)).
28 readNodeMap("coordinates_y", yMap(coord)).
29 readNodeMap("terminal", terminal).run();
31 SmartUGraph::UEdgeMap<double> cost(graph);
32 for (SmartUGraph::UEdgeIt it(graph); it != INVALID; ++it) {
33 cost[it] = sqrt((coord[graph.target(it)] -
34 coord[graph.source(it)]).normSquare());
37 SteinerTree<SmartUGraph> steiner(graph, cost);
40 for (SmartUGraph::NodeIt it(graph); it != INVALID; ++it) {
42 steiner.addTerminal(it);
48 Palette nodepalette(0);
49 nodepalette.add(Color(1.0, 1.0, 1.0));
50 nodepalette.add(Color(0.0, 1.0, 0.0));
51 nodepalette.add(Color(0.5, 0.5, 0.5));
52 SmartUGraph::NodeMap<int> nodecolor(graph);
53 for (SmartUGraph::NodeIt it(graph); it != INVALID; ++it) {
54 if (steiner.terminal(it)) {
56 } else if (steiner.steiner(it)) {
64 Palette edgepalette(0);
65 edgepalette.add(Color(0.0, 0.0, 0.0));
66 edgepalette.add(Color(1.0, 0.0, 0.0));
67 SmartUGraph::UEdgeMap<int> edgecolor(graph);
68 for (SmartUGraph::UEdgeIt it(graph); it != INVALID; ++it) {
69 edgecolor[it] = steiner.tree(it) ? 1 : 0;
73 graphToEps(graph, eps).
74 coords(coord).undirected().
75 nodeScale(1.0).scaleToA4().
76 nodeColors(composeMap(nodepalette, nodecolor)).
77 edgeColors(composeMap(edgepalette, edgecolor)).
78 nodeTexts(label).nodeTextSize(8).run();
80 std::cout << "The tree constructed: " << eps << std::endl;
81 std::cout << "The cost of the tree: " << steiner.treeValue() << std::endl;