diff -r 049f42e44dee -r fdfa3aa18607 demo/topology_demo.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/demo/topology_demo.cc Wed Nov 16 09:15:41 2005 +0000 @@ -0,0 +1,192 @@ +/* -*- C++ -*- + * demo/min_route.cc - Part of LEMON, a generic C++ optimization library + * + * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport + * (Egervary Research Group on Combinatorial Optimization, EGRES). + * + * Permission to use, modify and distribute this software is granted + * provided that this copyright notice appears in all copies. For + * precise terms see the accompanying LICENSE file. + * + * This software is provided "AS IS" with no warranty of any kind, + * express or implied, and with no claim as to its suitability for any + * purpose. + * + */ + +#include +#include +#include +#include +#include + +#include + +#include +#include + +/// \ingroup demos +/// \file +/// \brief Demo what shows the result of some topology functions. +/// +/// Demo what shows the result of some topology functions. +/// +/// \include topology_demo.cc + +using namespace lemon; +using namespace std; + + +Color color(bool val) { + return val ? Color(1.0, 0.0, 0.0) : Color(0.0, 0.0, 1.0); +} + + +void drawConnectedComponents() { + typedef UndirListGraph Graph; + typedef Graph::Node Node; + + Graph graph; + Graph::NodeMap > coords(graph); + + UndirGraphReader("undir_components.lgf", graph). + readNodeMap("coordinates_x", xMap(coords)). + readNodeMap("coordinates_y", yMap(coords)). + run(); + + ColorSet colorSet; + + Graph::NodeMap compMap(graph); + connectedComponents(graph, compMap); + + graphToEps(graph, "connected_components.eps").undir(). + coords(coords).scaleToA4().enableParallel(). + parEdgeDist(20.0).edgeWidthScale(2.0).nodeScale(20.0). + nodeColors(composeMap(colorSet, compMap)).run(); + + std::cout << "Result: connected_components.eps" << std::endl; +} + +void drawStronglyConnectedComponents() { + typedef ListGraph Graph; + typedef Graph::Node Node; + + Graph graph; + Graph::NodeMap > coords(graph); + + GraphReader("dir_components.lgf", graph). + readNodeMap("coordinates_x", xMap(coords)). + readNodeMap("coordinates_y", yMap(coords)). + run(); + + ColorSet colorSet; + + Graph::NodeMap compMap(graph); + Graph::EdgeMap cutMap(graph); + stronglyConnectedComponents(graph, compMap); + stronglyConnectedCutEdges(graph, cutMap); + + graphToEps(graph, "strongly_connected_components.eps"). + coords(coords).scaleToA4().enableParallel(). + drawArrows().arrowWidth(10.0).arrowLength(10.0). + parEdgeDist(20.0).edgeWidthScale(2.0).nodeScale(20.0). + nodeColors(composeMap(colorSet, compMap)). + edgeColors(composeMap(functorMap(&color), cutMap)).run(); + + std::cout << "Result: strongly_connected_components.eps" << std::endl; +} + +void drawNodeBiconnectedComponents() { + typedef UndirListGraph Graph; + typedef Graph::Node Node; + typedef Graph::UndirEdge UndirEdge; + + Graph graph; + Graph::NodeMap > coords(graph); + + UndirGraphReader("undir_components.lgf", graph). + readNodeMap("coordinates_x", xMap(coords)). + readNodeMap("coordinates_y", yMap(coords)). + run(); + + ColorSet colorSet; + + Graph::UndirEdgeMap compMap(graph); + Graph::NodeMap cutMap(graph); + biNodeConnectedComponents(graph, compMap); + biNodeConnectedCutNodes(graph, cutMap); + graphToEps(graph, "bi_node_connected_components.eps").undir(). + coords(coords).scaleToA4().enableParallel(). + parEdgeDist(20.0).edgeWidthScale(5.0).nodeScale(20.0). + edgeColors(composeMap(colorSet, compMap)). + nodeColors(composeMap(functorMap(&color), cutMap)). + run(); + + std::cout << "Result: bi_node_connected_components.eps" << std::endl; +} + +void drawEdgeBiconnectedComponents() { + typedef UndirListGraph Graph; + typedef Graph::Node Node; + typedef Graph::UndirEdge UndirEdge; + + Graph graph; + Graph::NodeMap > coords(graph); + + UndirGraphReader("undir_components.lgf", graph). + readNodeMap("coordinates_x", xMap(coords)). + readNodeMap("coordinates_y", yMap(coords)). + run(); + + ColorSet colorSet; + + Graph::NodeMap compMap(graph); + Graph::UndirEdgeMap cutMap(graph); + biEdgeConnectedComponents(graph, compMap); + biEdgeConnectedCutEdges(graph, cutMap); + + graphToEps(graph, "bi_edge_connected_components.eps").undir(). + coords(coords).scaleToA4().enableParallel(). + parEdgeDist(20.0).edgeWidthScale(2.0).nodeScale(20.0). + nodeColors(composeMap(colorSet, compMap)). + edgeColors(composeMap(functorMap(&color), cutMap)).run(); + + std::cout << "Result: bi_edge_connected_components.eps" << std::endl; +} + +void drawBipartitePartitions() { + typedef UndirListGraph Graph; + typedef Graph::Node Node; + typedef Graph::UndirEdge UndirEdge; + + Graph graph; + Graph::NodeMap > coords(graph); + + UndirGraphReader("partitions.lgf", graph). + readNodeMap("coordinates_x", xMap(coords)). + readNodeMap("coordinates_y", yMap(coords)). + run(); + + ColorSet colorSet; + + Graph::NodeMap partMap(graph); + bipartitePartitions(graph, partMap); + + graphToEps(graph, "bipartite_partitions.eps").undir(). + coords(coords).scaleToA4().enableParallel(). + parEdgeDist(20.0).edgeWidthScale(2.0).nodeScale(20.0). + nodeColors(composeMap(functorMap(&color), partMap)).run(); + + std::cout << "Result: bipartite_partitions.eps" << std::endl; +} + +int main() { + srand(time(0)); + + drawConnectedComponents(); + drawStronglyConnectedComponents(); + drawNodeBiconnectedComponents(); + drawEdgeBiconnectedComponents(); + drawBipartitePartitions(); + return 0; +}