deba@1802
|
1 |
/* -*- C++ -*-
|
deba@1802
|
2 |
* demo/min_route.cc - Part of LEMON, a generic C++ optimization library
|
deba@1802
|
3 |
*
|
deba@1802
|
4 |
* Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
|
deba@1802
|
5 |
* (Egervary Research Group on Combinatorial Optimization, EGRES).
|
deba@1802
|
6 |
*
|
deba@1802
|
7 |
* Permission to use, modify and distribute this software is granted
|
deba@1802
|
8 |
* provided that this copyright notice appears in all copies. For
|
deba@1802
|
9 |
* precise terms see the accompanying LICENSE file.
|
deba@1802
|
10 |
*
|
deba@1802
|
11 |
* This software is provided "AS IS" with no warranty of any kind,
|
deba@1802
|
12 |
* express or implied, and with no claim as to its suitability for any
|
deba@1802
|
13 |
* purpose.
|
deba@1802
|
14 |
*
|
deba@1802
|
15 |
*/
|
deba@1802
|
16 |
|
deba@1802
|
17 |
#include <lemon/list_graph.h>
|
deba@1802
|
18 |
#include <lemon/topology.h>
|
deba@1802
|
19 |
#include <lemon/graph_to_eps.h>
|
deba@1802
|
20 |
#include <lemon/graph_reader.h>
|
deba@1802
|
21 |
#include <lemon/xy.h>
|
deba@1802
|
22 |
|
deba@1802
|
23 |
#include <iostream>
|
deba@1802
|
24 |
|
deba@1802
|
25 |
#include <cstdlib>
|
deba@1802
|
26 |
#include <ctime>
|
deba@1802
|
27 |
|
deba@1802
|
28 |
/// \ingroup demos
|
deba@1802
|
29 |
/// \file
|
deba@1802
|
30 |
/// \brief Demo what shows the result of some topology functions.
|
deba@1802
|
31 |
///
|
deba@1802
|
32 |
/// Demo what shows the result of some topology functions.
|
deba@1802
|
33 |
///
|
deba@1802
|
34 |
/// \include topology_demo.cc
|
deba@1802
|
35 |
|
deba@1802
|
36 |
using namespace lemon;
|
deba@1802
|
37 |
using namespace std;
|
deba@1802
|
38 |
|
deba@1802
|
39 |
|
deba@1802
|
40 |
Color color(bool val) {
|
deba@1802
|
41 |
return val ? Color(1.0, 0.0, 0.0) : Color(0.0, 0.0, 1.0);
|
deba@1802
|
42 |
}
|
deba@1802
|
43 |
|
deba@1802
|
44 |
|
deba@1802
|
45 |
void drawConnectedComponents() {
|
deba@1802
|
46 |
typedef UndirListGraph Graph;
|
deba@1802
|
47 |
typedef Graph::Node Node;
|
deba@1802
|
48 |
|
deba@1802
|
49 |
Graph graph;
|
deba@1802
|
50 |
Graph::NodeMap<xy<double> > coords(graph);
|
deba@1802
|
51 |
|
deba@1802
|
52 |
UndirGraphReader<Graph>("undir_components.lgf", graph).
|
deba@1802
|
53 |
readNodeMap("coordinates_x", xMap(coords)).
|
deba@1802
|
54 |
readNodeMap("coordinates_y", yMap(coords)).
|
deba@1802
|
55 |
run();
|
deba@1802
|
56 |
|
deba@1802
|
57 |
ColorSet colorSet;
|
deba@1802
|
58 |
|
deba@1802
|
59 |
Graph::NodeMap<int> compMap(graph);
|
deba@1802
|
60 |
connectedComponents(graph, compMap);
|
deba@1802
|
61 |
|
deba@1802
|
62 |
graphToEps(graph, "connected_components.eps").undir().
|
deba@1802
|
63 |
coords(coords).scaleToA4().enableParallel().
|
deba@1802
|
64 |
parEdgeDist(20.0).edgeWidthScale(2.0).nodeScale(20.0).
|
deba@1802
|
65 |
nodeColors(composeMap(colorSet, compMap)).run();
|
deba@1802
|
66 |
|
deba@1802
|
67 |
std::cout << "Result: connected_components.eps" << std::endl;
|
deba@1802
|
68 |
}
|
deba@1802
|
69 |
|
deba@1802
|
70 |
void drawStronglyConnectedComponents() {
|
deba@1802
|
71 |
typedef ListGraph Graph;
|
deba@1802
|
72 |
typedef Graph::Node Node;
|
deba@1802
|
73 |
|
deba@1802
|
74 |
Graph graph;
|
deba@1802
|
75 |
Graph::NodeMap<xy<double> > coords(graph);
|
deba@1802
|
76 |
|
deba@1802
|
77 |
GraphReader<Graph>("dir_components.lgf", graph).
|
deba@1802
|
78 |
readNodeMap("coordinates_x", xMap(coords)).
|
deba@1802
|
79 |
readNodeMap("coordinates_y", yMap(coords)).
|
deba@1802
|
80 |
run();
|
deba@1802
|
81 |
|
deba@1802
|
82 |
ColorSet colorSet;
|
deba@1802
|
83 |
|
deba@1802
|
84 |
Graph::NodeMap<int> compMap(graph);
|
deba@1802
|
85 |
Graph::EdgeMap<bool> cutMap(graph);
|
deba@1802
|
86 |
stronglyConnectedComponents(graph, compMap);
|
deba@1802
|
87 |
stronglyConnectedCutEdges(graph, cutMap);
|
deba@1802
|
88 |
|
deba@1802
|
89 |
graphToEps(graph, "strongly_connected_components.eps").
|
deba@1802
|
90 |
coords(coords).scaleToA4().enableParallel().
|
deba@1802
|
91 |
drawArrows().arrowWidth(10.0).arrowLength(10.0).
|
deba@1802
|
92 |
parEdgeDist(20.0).edgeWidthScale(2.0).nodeScale(20.0).
|
deba@1802
|
93 |
nodeColors(composeMap(colorSet, compMap)).
|
deba@1802
|
94 |
edgeColors(composeMap(functorMap(&color), cutMap)).run();
|
deba@1802
|
95 |
|
deba@1802
|
96 |
std::cout << "Result: strongly_connected_components.eps" << std::endl;
|
deba@1802
|
97 |
}
|
deba@1802
|
98 |
|
deba@1802
|
99 |
void drawNodeBiconnectedComponents() {
|
deba@1802
|
100 |
typedef UndirListGraph Graph;
|
deba@1802
|
101 |
typedef Graph::Node Node;
|
deba@1802
|
102 |
typedef Graph::UndirEdge UndirEdge;
|
deba@1802
|
103 |
|
deba@1802
|
104 |
Graph graph;
|
deba@1802
|
105 |
Graph::NodeMap<xy<double> > coords(graph);
|
deba@1802
|
106 |
|
deba@1802
|
107 |
UndirGraphReader<Graph>("undir_components.lgf", graph).
|
deba@1802
|
108 |
readNodeMap("coordinates_x", xMap(coords)).
|
deba@1802
|
109 |
readNodeMap("coordinates_y", yMap(coords)).
|
deba@1802
|
110 |
run();
|
deba@1802
|
111 |
|
deba@1802
|
112 |
ColorSet colorSet;
|
deba@1802
|
113 |
|
deba@1802
|
114 |
Graph::UndirEdgeMap<int> compMap(graph);
|
deba@1802
|
115 |
Graph::NodeMap<bool> cutMap(graph);
|
deba@1802
|
116 |
biNodeConnectedComponents(graph, compMap);
|
deba@1802
|
117 |
biNodeConnectedCutNodes(graph, cutMap);
|
deba@1802
|
118 |
graphToEps(graph, "bi_node_connected_components.eps").undir().
|
deba@1802
|
119 |
coords(coords).scaleToA4().enableParallel().
|
deba@1802
|
120 |
parEdgeDist(20.0).edgeWidthScale(5.0).nodeScale(20.0).
|
deba@1802
|
121 |
edgeColors(composeMap(colorSet, compMap)).
|
deba@1802
|
122 |
nodeColors(composeMap(functorMap(&color), cutMap)).
|
deba@1802
|
123 |
run();
|
deba@1802
|
124 |
|
deba@1802
|
125 |
std::cout << "Result: bi_node_connected_components.eps" << std::endl;
|
deba@1802
|
126 |
}
|
deba@1802
|
127 |
|
deba@1802
|
128 |
void drawEdgeBiconnectedComponents() {
|
deba@1802
|
129 |
typedef UndirListGraph Graph;
|
deba@1802
|
130 |
typedef Graph::Node Node;
|
deba@1802
|
131 |
typedef Graph::UndirEdge UndirEdge;
|
deba@1802
|
132 |
|
deba@1802
|
133 |
Graph graph;
|
deba@1802
|
134 |
Graph::NodeMap<xy<double> > coords(graph);
|
deba@1802
|
135 |
|
deba@1802
|
136 |
UndirGraphReader<Graph>("undir_components.lgf", graph).
|
deba@1802
|
137 |
readNodeMap("coordinates_x", xMap(coords)).
|
deba@1802
|
138 |
readNodeMap("coordinates_y", yMap(coords)).
|
deba@1802
|
139 |
run();
|
deba@1802
|
140 |
|
deba@1802
|
141 |
ColorSet colorSet;
|
deba@1802
|
142 |
|
deba@1802
|
143 |
Graph::NodeMap<int> compMap(graph);
|
deba@1802
|
144 |
Graph::UndirEdgeMap<bool> cutMap(graph);
|
deba@1802
|
145 |
biEdgeConnectedComponents(graph, compMap);
|
deba@1802
|
146 |
biEdgeConnectedCutEdges(graph, cutMap);
|
deba@1802
|
147 |
|
deba@1802
|
148 |
graphToEps(graph, "bi_edge_connected_components.eps").undir().
|
deba@1802
|
149 |
coords(coords).scaleToA4().enableParallel().
|
deba@1802
|
150 |
parEdgeDist(20.0).edgeWidthScale(2.0).nodeScale(20.0).
|
deba@1802
|
151 |
nodeColors(composeMap(colorSet, compMap)).
|
deba@1802
|
152 |
edgeColors(composeMap(functorMap(&color), cutMap)).run();
|
deba@1802
|
153 |
|
deba@1802
|
154 |
std::cout << "Result: bi_edge_connected_components.eps" << std::endl;
|
deba@1802
|
155 |
}
|
deba@1802
|
156 |
|
deba@1802
|
157 |
void drawBipartitePartitions() {
|
deba@1802
|
158 |
typedef UndirListGraph Graph;
|
deba@1802
|
159 |
typedef Graph::Node Node;
|
deba@1802
|
160 |
typedef Graph::UndirEdge UndirEdge;
|
deba@1802
|
161 |
|
deba@1802
|
162 |
Graph graph;
|
deba@1802
|
163 |
Graph::NodeMap<xy<double> > coords(graph);
|
deba@1802
|
164 |
|
deba@1802
|
165 |
UndirGraphReader<Graph>("partitions.lgf", graph).
|
deba@1802
|
166 |
readNodeMap("coordinates_x", xMap(coords)).
|
deba@1802
|
167 |
readNodeMap("coordinates_y", yMap(coords)).
|
deba@1802
|
168 |
run();
|
deba@1802
|
169 |
|
deba@1802
|
170 |
ColorSet colorSet;
|
deba@1802
|
171 |
|
deba@1802
|
172 |
Graph::NodeMap<bool> partMap(graph);
|
deba@1802
|
173 |
bipartitePartitions(graph, partMap);
|
deba@1802
|
174 |
|
deba@1802
|
175 |
graphToEps(graph, "bipartite_partitions.eps").undir().
|
deba@1802
|
176 |
coords(coords).scaleToA4().enableParallel().
|
deba@1802
|
177 |
parEdgeDist(20.0).edgeWidthScale(2.0).nodeScale(20.0).
|
deba@1802
|
178 |
nodeColors(composeMap(functorMap(&color), partMap)).run();
|
deba@1802
|
179 |
|
deba@1802
|
180 |
std::cout << "Result: bipartite_partitions.eps" << std::endl;
|
deba@1802
|
181 |
}
|
deba@1802
|
182 |
|
deba@1802
|
183 |
int main() {
|
deba@1802
|
184 |
srand(time(0));
|
deba@1802
|
185 |
|
deba@1802
|
186 |
drawConnectedComponents();
|
deba@1802
|
187 |
drawStronglyConnectedComponents();
|
deba@1802
|
188 |
drawNodeBiconnectedComponents();
|
deba@1802
|
189 |
drawEdgeBiconnectedComponents();
|
deba@1802
|
190 |
drawBipartitePartitions();
|
deba@1802
|
191 |
return 0;
|
deba@1802
|
192 |
}
|