Fix crash when an arrow is clicked with the delete tool.
2 * demo/min_route.cc - Part of LEMON, a generic C++ optimization library
4 * Copyright (C) 2006 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
5 * (Egervary Research Group on Combinatorial Optimization, EGRES).
7 * Permission to use, modify and distribute this software is granted
8 * provided that this copyright notice appears in all copies. For
9 * precise terms see the accompanying LICENSE file.
11 * This software is provided "AS IS" with no warranty of any kind,
12 * express or implied, and with no claim as to its suitability for any
17 #include <lemon/list_graph.h>
18 #include <lemon/topology.h>
19 #include <lemon/graph_to_eps.h>
20 #include <lemon/graph_reader.h>
30 /// \brief Demo what shows the result of some topology functions.
32 /// Demo what shows the result of some topology functions.
34 /// \include topology_demo.cc
36 using namespace lemon;
40 Color color(bool val) {
41 return val ? Color(1.0, 0.0, 0.0) : Color(0.0, 0.0, 1.0);
45 void drawConnectedComponents() {
46 typedef ListUGraph Graph;
47 typedef Graph::Node Node;
50 Graph::NodeMap<xy<double> > coords(graph);
52 UGraphReader<Graph>("u_components.lgf", graph).
53 readNodeMap("coordinates_x", xMap(coords)).
54 readNodeMap("coordinates_y", yMap(coords)).
59 Graph::NodeMap<int> compMap(graph);
60 connectedComponents(graph, compMap);
62 graphToEps(graph, "connected_components.eps").undirected().
63 coords(coords).scaleToA4().enableParallel().
64 parEdgeDist(20.0).edgeWidthScale(2.0).nodeScale(20.0).
65 nodeColors(composeMap(colorSet, compMap)).run();
67 std::cout << "Result: connected_components.eps" << std::endl;
70 void drawStronglyConnectedComponents() {
71 typedef ListGraph Graph;
72 typedef Graph::Node Node;
75 Graph::NodeMap<xy<double> > coords(graph);
77 GraphReader<Graph>("dir_components.lgf", graph).
78 readNodeMap("coordinates_x", xMap(coords)).
79 readNodeMap("coordinates_y", yMap(coords)).
84 Graph::NodeMap<int> compMap(graph);
85 Graph::EdgeMap<bool> cutMap(graph);
86 stronglyConnectedComponents(graph, compMap);
87 stronglyConnectedCutEdges(graph, cutMap);
89 graphToEps(graph, "strongly_connected_components.eps").
90 coords(coords).scaleToA4().enableParallel().
91 drawArrows().arrowWidth(10.0).arrowLength(10.0).
92 parEdgeDist(20.0).edgeWidthScale(2.0).nodeScale(20.0).
93 nodeColors(composeMap(colorSet, compMap)).
94 edgeColors(composeMap(functorMap(&color), cutMap)).run();
96 std::cout << "Result: strongly_connected_components.eps" << std::endl;
99 void drawNodeBiconnectedComponents() {
100 typedef ListUGraph Graph;
101 typedef Graph::Node Node;
102 typedef Graph::UEdge UEdge;
105 Graph::NodeMap<xy<double> > coords(graph);
107 UGraphReader<Graph>("u_components.lgf", graph).
108 readNodeMap("coordinates_x", xMap(coords)).
109 readNodeMap("coordinates_y", yMap(coords)).
114 Graph::UEdgeMap<int> compMap(graph);
115 Graph::NodeMap<bool> cutMap(graph);
116 biNodeConnectedComponents(graph, compMap);
117 biNodeConnectedCutNodes(graph, cutMap);
119 graphToEps(graph, "bi_node_connected_components.eps").undirected().
120 coords(coords).scaleToA4().enableParallel().
121 parEdgeDist(20.0).edgeWidthScale(5.0).nodeScale(20.0).
122 edgeColors(composeMap(colorSet, compMap)).
123 nodeColors(composeMap(functorMap(&color), cutMap)).
126 std::cout << "Result: bi_node_connected_components.eps" << std::endl;
129 void drawEdgeBiconnectedComponents() {
130 typedef ListUGraph Graph;
131 typedef Graph::Node Node;
132 typedef Graph::UEdge UEdge;
135 Graph::NodeMap<xy<double> > coords(graph);
137 UGraphReader<Graph>("u_components.lgf", graph).
138 readNodeMap("coordinates_x", xMap(coords)).
139 readNodeMap("coordinates_y", yMap(coords)).
144 Graph::NodeMap<int> compMap(graph);
145 Graph::UEdgeMap<bool> cutMap(graph);
146 biEdgeConnectedComponents(graph, compMap);
147 biEdgeConnectedCutEdges(graph, cutMap);
149 graphToEps(graph, "bi_edge_connected_components.eps").undirected().
150 coords(coords).scaleToA4().enableParallel().
151 parEdgeDist(20.0).edgeWidthScale(2.0).nodeScale(20.0).
152 nodeColors(composeMap(colorSet, compMap)).
153 edgeColors(composeMap(functorMap(&color), cutMap)).run();
155 std::cout << "Result: bi_edge_connected_components.eps" << std::endl;
158 void drawBipartitePartitions() {
159 typedef ListUGraph Graph;
160 typedef Graph::Node Node;
161 typedef Graph::UEdge UEdge;
164 Graph::NodeMap<xy<double> > coords(graph);
166 UGraphReader<Graph>("partitions.lgf", graph).
167 readNodeMap("coordinates_x", xMap(coords)).
168 readNodeMap("coordinates_y", yMap(coords)).
173 Graph::NodeMap<bool> partMap(graph);
174 bipartitePartitions(graph, partMap);
176 graphToEps(graph, "bipartite_partitions.eps").undirected().
177 coords(coords).scaleToA4().enableParallel().
178 parEdgeDist(20.0).edgeWidthScale(2.0).nodeScale(20.0).
179 nodeColors(composeMap(functorMap(&color), partMap)).run();
181 std::cout << "Result: bipartite_partitions.eps" << std::endl;
187 drawConnectedComponents();
188 drawStronglyConnectedComponents();
189 drawNodeBiconnectedComponents();
190 drawEdgeBiconnectedComponents();
191 drawBipartitePartitions();