#include #include #include #include #include #include #include #include using namespace lemon; using namespace lemon::dim2; using namespace std; int main(int argc, const char *argv[]) { std::string lgf = argc > 1 ? argv[1] : "steiner.lgf"; std::string eps = argc > 2 ? argv[2] : "steiner.eps"; SmartUGraph graph; SmartUGraph::NodeMap terminal(graph); SmartUGraph::NodeMap label(graph); SmartUGraph::NodeMap > coord(graph); UGraphReader(lgf, graph). readNodeMap("coordinates_x", xMap(coord)). readNodeMap("coordinates_y", yMap(coord)). readNodeMap("terminal", terminal).run(); SmartUGraph::UEdgeMap cost(graph); for (SmartUGraph::UEdgeIt it(graph); it != INVALID; ++it) { cost[it] = sqrt((coord[graph.target(it)] - coord[graph.source(it)]).normSquare()); } SteinerTree steiner(graph, cost); steiner.init(); for (SmartUGraph::NodeIt it(graph); it != INVALID; ++it) { if (terminal[it]) { steiner.addTerminal(it); } } steiner.start(); Palette nodepalette(0); nodepalette.add(Color(1.0, 1.0, 1.0)); nodepalette.add(Color(0.0, 1.0, 0.0)); nodepalette.add(Color(0.5, 0.5, 0.5)); SmartUGraph::NodeMap nodecolor(graph); for (SmartUGraph::NodeIt it(graph); it != INVALID; ++it) { if (steiner.terminal(it)) { nodecolor[it] = 1; } else if (steiner.steiner(it)) { nodecolor[it] = 2; } else { nodecolor[it] = 0; } } Palette edgepalette(0); edgepalette.add(Color(0.0, 0.0, 0.0)); edgepalette.add(Color(1.0, 0.0, 0.0)); SmartUGraph::UEdgeMap edgecolor(graph); for (SmartUGraph::UEdgeIt it(graph); it != INVALID; ++it) { edgecolor[it] = steiner.tree(it) ? 1 : 0; } graphToEps(graph, eps). coords(coord).undirected(). nodeScale(1.0).scaleToA4(). nodeColors(composeMap(nodepalette, nodecolor)). edgeColors(composeMap(edgepalette, edgecolor)). nodeTexts(label).nodeTextSize(8).run(); std::cout << "The tree constructed: " << eps << std::endl; std::cout << "The cost of the tree: " << steiner.treeValue() << std::endl; return 0; }