Improved documentation.
3 * This file is a part of LEMON, a generic C++ optimization library
5 * Copyright (C) 2003-2006
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/list_graph.h>
20 #include <lemon/topology.h>
21 #include <lemon/graph_to_eps.h>
22 #include <lemon/graph_reader.h>
23 #include <lemon/dim2.h>
32 /// \brief Demo what shows the result of some topology functions.
34 /// Demo what shows the result of some topology functions.
36 /// \include topology_demo.cc
38 using namespace lemon;
42 Color color(bool val) {
43 return val ? RED : BLUE;
47 void drawConnectedComponents() {
48 typedef ListUGraph Graph;
49 typedef Graph::Node Node;
52 Graph::NodeMap<dim2::Point<double> > coords(graph);
54 UGraphReader<Graph>("u_components.lgf", graph).
55 readNodeMap("coordinates_x", xMap(coords)).
56 readNodeMap("coordinates_y", yMap(coords)).
61 Graph::NodeMap<int> compMap(graph);
62 connectedComponents(graph, compMap);
64 graphToEps(graph, "connected_components.eps").undirected().
65 coords(coords).scaleToA4().enableParallel().
66 parEdgeDist(20.0).edgeWidthScale(2.0).nodeScale(20.0).
67 nodeColors(composeMap(palette, compMap)).run();
69 std::cout << "Result: connected_components.eps" << std::endl;
72 void drawStronglyConnectedComponents() {
73 typedef ListGraph Graph;
74 typedef Graph::Node Node;
77 Graph::NodeMap<dim2::Point<double> > coords(graph);
79 GraphReader<Graph>("dir_components.lgf", graph).
80 readNodeMap("coordinates_x", xMap(coords)).
81 readNodeMap("coordinates_y", yMap(coords)).
86 Graph::NodeMap<int> compMap(graph);
87 Graph::EdgeMap<bool> cutMap(graph);
88 stronglyConnectedComponents(graph, compMap);
89 stronglyConnectedCutEdges(graph, cutMap);
91 graphToEps(graph, "strongly_connected_components.eps").
92 coords(coords).scaleToA4().enableParallel().
93 drawArrows().arrowWidth(10.0).arrowLength(10.0).
94 parEdgeDist(20.0).edgeWidthScale(2.0).nodeScale(20.0).
95 nodeColors(composeMap(palette, compMap)).
96 edgeColors(composeMap(functorMap(&color), cutMap)).run();
98 std::cout << "Result: strongly_connected_components.eps" << std::endl;
101 void drawNodeBiconnectedComponents() {
102 typedef ListUGraph Graph;
103 typedef Graph::Node Node;
104 typedef Graph::UEdge UEdge;
107 Graph::NodeMap<dim2::Point<double> > coords(graph);
109 UGraphReader<Graph>("u_components.lgf", graph).
110 readNodeMap("coordinates_x", xMap(coords)).
111 readNodeMap("coordinates_y", yMap(coords)).
116 Graph::UEdgeMap<int> compMap(graph);
117 Graph::NodeMap<bool> cutMap(graph);
118 biNodeConnectedComponents(graph, compMap);
119 biNodeConnectedCutNodes(graph, cutMap);
121 graphToEps(graph, "bi_node_connected_components.eps").undirected().
122 coords(coords).scaleToA4().enableParallel().
123 parEdgeDist(20.0).edgeWidthScale(5.0).nodeScale(20.0).
124 edgeColors(composeMap(palette, compMap)).
125 nodeColors(composeMap(functorMap(&color), cutMap)).
128 std::cout << "Result: bi_node_connected_components.eps" << std::endl;
131 void drawEdgeBiconnectedComponents() {
132 typedef ListUGraph Graph;
133 typedef Graph::Node Node;
134 typedef Graph::UEdge UEdge;
137 Graph::NodeMap<dim2::Point<double> > coords(graph);
139 UGraphReader<Graph>("u_components.lgf", graph).
140 readNodeMap("coordinates_x", xMap(coords)).
141 readNodeMap("coordinates_y", yMap(coords)).
146 Graph::NodeMap<int> compMap(graph);
147 Graph::UEdgeMap<bool> cutMap(graph);
148 biEdgeConnectedComponents(graph, compMap);
149 biEdgeConnectedCutEdges(graph, cutMap);
151 graphToEps(graph, "bi_edge_connected_components.eps").undirected().
152 coords(coords).scaleToA4().enableParallel().
153 parEdgeDist(20.0).edgeWidthScale(2.0).nodeScale(20.0).
154 nodeColors(composeMap(palette, compMap)).
155 edgeColors(composeMap(functorMap(&color), cutMap)).run();
157 std::cout << "Result: bi_edge_connected_components.eps" << std::endl;
160 void drawBipartitePartitions() {
161 typedef ListUGraph Graph;
162 typedef Graph::Node Node;
163 typedef Graph::UEdge UEdge;
166 Graph::NodeMap<dim2::Point<double> > coords(graph);
168 UGraphReader<Graph>("partitions.lgf", graph).
169 readNodeMap("coordinates_x", xMap(coords)).
170 readNodeMap("coordinates_y", yMap(coords)).
175 Graph::NodeMap<bool> partMap(graph);
176 bipartitePartitions(graph, partMap);
178 graphToEps(graph, "bipartite_partitions.eps").undirected().
179 coords(coords).scaleToA4().enableParallel().
180 parEdgeDist(20.0).edgeWidthScale(2.0).nodeScale(20.0).
181 nodeColors(composeMap(functorMap(&color), partMap)).run();
183 std::cout << "Result: bipartite_partitions.eps" << std::endl;
189 drawConnectedComponents();
190 drawStronglyConnectedComponents();
191 drawNodeBiconnectedComponents();
192 drawEdgeBiconnectedComponents();
193 drawBipartitePartitions();