Demo for topology
authordeba
Wed, 16 Nov 2005 09:15:41 +0000
changeset 1802fdfa3aa18607
parent 1801 049f42e44dee
child 1803 ee8dd6872645
Demo for topology
demo/Makefile.am
demo/dir_components.lgf
demo/graph_to_eps_demo.cc
demo/partitions.lgf
demo/topology_demo.cc
demo/undir_components.lgf
     1.1 --- a/demo/Makefile.am	Wed Nov 16 09:11:44 2005 +0000
     1.2 +++ b/demo/Makefile.am	Wed Nov 16 09:15:41 2005 +0000
     1.3 @@ -15,7 +15,8 @@
     1.4  	sub_graph_adaptor_demo \
     1.5  	descriptor_map_demo \
     1.6  	coloring \
     1.7 -	grid_graph_demo
     1.8 +	grid_graph_demo \
     1.9 +	topology_demo
    1.10  
    1.11  if HAVE_GLPK
    1.12  noinst_PROGRAMS += lp_demo lp_maxflow_demo
    1.13 @@ -56,4 +57,6 @@
    1.14  lp_maxflow_demo_SOURCES = lp_maxflow_demo.cc
    1.15  lp_maxflow_demo_CXXFLAGS = $(GLPK_CFLAGS) $(CPLEX_CFLAGS)
    1.16  
    1.17 -descriptor_map_demo_SOURCES = descriptor_map_demo.cc
    1.18 \ No newline at end of file
    1.19 +descriptor_map_demo_SOURCES = descriptor_map_demo.cc
    1.20 +
    1.21 +topology_demo_SOURCES = topology_demo.cc
    1.22 \ No newline at end of file
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/demo/dir_components.lgf	Wed Nov 16 09:15:41 2005 +0000
     2.3 @@ -0,0 +1,52 @@
     2.4 +@nodeset 
     2.5 +coordinates_x	coordinates_y	id	
     2.6 +218.178	27.2723	19	
     2.7 +157.79	-130.517	18	
     2.8 +44.8044	15.5841	17	
     2.9 +-465.576	-42.8564	16	
    2.10 +-675.963	-3.89604	15	
    2.11 +-574.666	-153.893	14	
    2.12 +-490.901	120.777	13	
    2.13 +-368.176	331.163	12	
    2.14 +-266.879	114.933	11	
    2.15 +-251.294	-335.059	10	
    2.16 +-173.374	377.916	9	
    2.17 +169.478	311.683	8	
    2.18 +5.84406	175.322	7	
    2.19 +342.851	111.037	6	
    2.20 +670.118	-118.829	5	
    2.21 +364.28	-222.074	4	
    2.22 +-105.193	-261.035	3	
    2.23 +-227.918	-40.9084	2	
    2.24 +-389.604	-136.361	1	
    2.25 +@edgeset 
    2.26 +		id	
    2.27 +17	19	23	
    2.28 +19	18	24	
    2.29 +18	17	25	
    2.30 +3	17	21	
    2.31 +14	16	18	
    2.32 +13	16	17	
    2.33 +16	15	19	
    2.34 +15	14	20	
    2.35 +11	13	15	
    2.36 +13	12	16	
    2.37 +12	11	14	
    2.38 +1	10	1	
    2.39 +11	9	13	
    2.40 +7	9	12	
    2.41 +6	8	10	
    2.42 +8	7	11	
    2.43 +7	6	9	
    2.44 +4	6	6	
    2.45 +6	5	7	
    2.46 +19	4	22	
    2.47 +5	4	8	
    2.48 +3	4	5	
    2.49 +10	3	2	
    2.50 +3	2	3	
    2.51 +2	1	4	
    2.52 +@nodes 
    2.53 +@edges 
    2.54 +@attributes 
    2.55 +@end
     3.1 --- a/demo/graph_to_eps_demo.cc	Wed Nov 16 09:11:44 2005 +0000
     3.2 +++ b/demo/graph_to_eps_demo.cc	Wed Nov 16 09:15:41 2005 +0000
     3.3 @@ -32,6 +32,7 @@
     3.4  
     3.5  #include<lemon/graph_to_eps.h>
     3.6  #include<lemon/list_graph.h>
     3.7 +#include<lemon/graph_utils.h>
     3.8  
     3.9  using namespace std;
    3.10  using namespace lemon;
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/demo/partitions.lgf	Wed Nov 16 09:15:41 2005 +0000
     4.3 @@ -0,0 +1,58 @@
     4.4 +@nodeset 
     4.5 +coordinates_x	coordinates_y	id	
     4.6 +513.857		-446.322	23	
     4.7 +393.468		566.711		22	
     4.8 +869.153		52.8539		21	
     4.9 +596.074		302.442		20	
    4.10 +-82.2171	593.138		19	
    4.11 +-663.61		546.157		18	
    4.12 +-1077.63	161.498		17	
    4.13 +-1177.47	-234.906	16	
    4.14 +-880.898	-528.539	15	
    4.15 +-499.175	-499.175	14	
    4.16 +79.2808		-528.539	13	
    4.17 +637.183		-184.989	12	
    4.18 +205.543		-322.996	11	
    4.19 +399.34		88.0898		10	
    4.20 +-842.726	243.715		9	
    4.21 +-860.344	-29.3633	8	
    4.22 +-211.415	-452.194	7	
    4.23 +-99.8351	99.8351		6	
    4.24 +120.389		-129.198	5	
    4.25 +108.644		334.741		4	
    4.26 +-484.494	328.869		3	
    4.27 +-607.82		-246.651	2	
    4.28 +-274		-131		1	
    4.29 +@undiredgeset 
    4.30 +		id	
    4.31 +12	23	15	
    4.32 +13	23	14	
    4.33 +4	22	23	
    4.34 +20	21	20	
    4.35 +12	21	19	
    4.36 +22	20	22	
    4.37 +22	19	25	
    4.38 +6	19	24	
    4.39 +9	18	28	
    4.40 +16	15	1	
    4.41 +2	14	8	
    4.42 +7	13	13	
    4.43 +11	12	16	
    4.44 +5	10	18	
    4.45 +17	9	5	
    4.46 +17	8	3	
    4.47 +16	8	2	
    4.48 +14	7	10	
    4.49 +3	6	30	
    4.50 +9	6	27	
    4.51 +11	5	17	
    4.52 +7	5	12	
    4.53 +6	4	26	
    4.54 +10	4	21	
    4.55 +18	3	29	
    4.56 +15	2	7	
    4.57 +8	2	6	
    4.58 +5	1	11	
    4.59 +14	1	9	
    4.60 +9	1	4	
    4.61 +@end
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/demo/topology_demo.cc	Wed Nov 16 09:15:41 2005 +0000
     5.3 @@ -0,0 +1,192 @@
     5.4 +/* -*- C++ -*-
     5.5 + * demo/min_route.cc - Part of LEMON, a generic C++ optimization library
     5.6 + *
     5.7 + * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     5.8 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
     5.9 + *
    5.10 + * Permission to use, modify and distribute this software is granted
    5.11 + * provided that this copyright notice appears in all copies. For
    5.12 + * precise terms see the accompanying LICENSE file.
    5.13 + *
    5.14 + * This software is provided "AS IS" with no warranty of any kind,
    5.15 + * express or implied, and with no claim as to its suitability for any
    5.16 + * purpose.
    5.17 + *
    5.18 + */
    5.19 +
    5.20 +#include <lemon/list_graph.h>
    5.21 +#include <lemon/topology.h>
    5.22 +#include <lemon/graph_to_eps.h>
    5.23 +#include <lemon/graph_reader.h>
    5.24 +#include <lemon/xy.h>
    5.25 +
    5.26 +#include <iostream>
    5.27 +
    5.28 +#include <cstdlib>
    5.29 +#include <ctime>
    5.30 +
    5.31 +/// \ingroup demos
    5.32 +/// \file
    5.33 +/// \brief Demo what shows the result of some topology functions.
    5.34 +///
    5.35 +///  Demo what shows the result of some topology functions.
    5.36 +///
    5.37 +/// \include topology_demo.cc
    5.38 +
    5.39 +using namespace lemon;
    5.40 +using namespace std;
    5.41 +
    5.42 +
    5.43 +Color color(bool val) {
    5.44 +  return val ? Color(1.0, 0.0, 0.0) : Color(0.0, 0.0, 1.0);
    5.45 +}
    5.46 +
    5.47 +
    5.48 +void drawConnectedComponents() {
    5.49 +  typedef UndirListGraph Graph;
    5.50 +  typedef Graph::Node Node;
    5.51 +
    5.52 +  Graph graph;
    5.53 +  Graph::NodeMap<xy<double> > coords(graph);
    5.54 +
    5.55 +  UndirGraphReader<Graph>("undir_components.lgf", graph).
    5.56 +    readNodeMap("coordinates_x", xMap(coords)).
    5.57 +    readNodeMap("coordinates_y", yMap(coords)).
    5.58 +    run();
    5.59 +  
    5.60 +  ColorSet colorSet;
    5.61 +
    5.62 +  Graph::NodeMap<int> compMap(graph);
    5.63 +  connectedComponents(graph, compMap);
    5.64 +
    5.65 +  graphToEps(graph, "connected_components.eps").undir().
    5.66 +    coords(coords).scaleToA4().enableParallel().
    5.67 +    parEdgeDist(20.0).edgeWidthScale(2.0).nodeScale(20.0).
    5.68 +    nodeColors(composeMap(colorSet, compMap)).run();
    5.69 +
    5.70 +  std::cout << "Result: connected_components.eps" << std::endl;
    5.71 +}
    5.72 +
    5.73 +void drawStronglyConnectedComponents() {
    5.74 +  typedef ListGraph Graph;
    5.75 +  typedef Graph::Node Node;
    5.76 +
    5.77 +  Graph graph;
    5.78 +  Graph::NodeMap<xy<double> > coords(graph);
    5.79 +
    5.80 +  GraphReader<Graph>("dir_components.lgf", graph).
    5.81 +    readNodeMap("coordinates_x", xMap(coords)).
    5.82 +    readNodeMap("coordinates_y", yMap(coords)).
    5.83 +    run();
    5.84 +  
    5.85 +  ColorSet colorSet;
    5.86 +
    5.87 +  Graph::NodeMap<int> compMap(graph);
    5.88 +  Graph::EdgeMap<bool> cutMap(graph);
    5.89 +  stronglyConnectedComponents(graph, compMap);
    5.90 +  stronglyConnectedCutEdges(graph, cutMap);
    5.91 +
    5.92 +  graphToEps(graph, "strongly_connected_components.eps").
    5.93 +    coords(coords).scaleToA4().enableParallel().
    5.94 +    drawArrows().arrowWidth(10.0).arrowLength(10.0).
    5.95 +    parEdgeDist(20.0).edgeWidthScale(2.0).nodeScale(20.0).
    5.96 +    nodeColors(composeMap(colorSet, compMap)).
    5.97 +    edgeColors(composeMap(functorMap(&color), cutMap)).run();
    5.98 +
    5.99 +  std::cout << "Result: strongly_connected_components.eps" << std::endl;
   5.100 +}
   5.101 +
   5.102 +void drawNodeBiconnectedComponents() {
   5.103 +  typedef UndirListGraph Graph;
   5.104 +  typedef Graph::Node Node;
   5.105 +  typedef Graph::UndirEdge UndirEdge;
   5.106 +
   5.107 +  Graph graph;
   5.108 +  Graph::NodeMap<xy<double> > coords(graph);
   5.109 +
   5.110 +  UndirGraphReader<Graph>("undir_components.lgf", graph).
   5.111 +    readNodeMap("coordinates_x", xMap(coords)).
   5.112 +    readNodeMap("coordinates_y", yMap(coords)).
   5.113 +    run();
   5.114 +
   5.115 +  ColorSet colorSet;
   5.116 +
   5.117 +  Graph::UndirEdgeMap<int> compMap(graph);
   5.118 +  Graph::NodeMap<bool> cutMap(graph);
   5.119 +  biNodeConnectedComponents(graph, compMap);
   5.120 +  biNodeConnectedCutNodes(graph, cutMap);
   5.121 +  graphToEps(graph, "bi_node_connected_components.eps").undir().
   5.122 +    coords(coords).scaleToA4().enableParallel().
   5.123 +    parEdgeDist(20.0).edgeWidthScale(5.0).nodeScale(20.0).
   5.124 +    edgeColors(composeMap(colorSet, compMap)).
   5.125 +    nodeColors(composeMap(functorMap(&color), cutMap)).
   5.126 +    run();
   5.127 +
   5.128 +  std::cout << "Result: bi_node_connected_components.eps" << std::endl;
   5.129 +}
   5.130 +
   5.131 +void drawEdgeBiconnectedComponents() {
   5.132 +  typedef UndirListGraph Graph;
   5.133 +  typedef Graph::Node Node;
   5.134 +  typedef Graph::UndirEdge UndirEdge;
   5.135 +
   5.136 +  Graph graph;
   5.137 +  Graph::NodeMap<xy<double> > coords(graph);
   5.138 +
   5.139 +  UndirGraphReader<Graph>("undir_components.lgf", graph).
   5.140 +    readNodeMap("coordinates_x", xMap(coords)).
   5.141 +    readNodeMap("coordinates_y", yMap(coords)).
   5.142 +    run();
   5.143 +  
   5.144 +  ColorSet colorSet;
   5.145 +
   5.146 +  Graph::NodeMap<int> compMap(graph);
   5.147 +  Graph::UndirEdgeMap<bool> cutMap(graph);
   5.148 +  biEdgeConnectedComponents(graph, compMap);
   5.149 +  biEdgeConnectedCutEdges(graph, cutMap);
   5.150 +
   5.151 +  graphToEps(graph, "bi_edge_connected_components.eps").undir().
   5.152 +    coords(coords).scaleToA4().enableParallel().
   5.153 +    parEdgeDist(20.0).edgeWidthScale(2.0).nodeScale(20.0).
   5.154 +    nodeColors(composeMap(colorSet, compMap)).
   5.155 +    edgeColors(composeMap(functorMap(&color), cutMap)).run();
   5.156 +  
   5.157 +  std::cout << "Result: bi_edge_connected_components.eps" << std::endl;
   5.158 +}
   5.159 +
   5.160 +void drawBipartitePartitions() {
   5.161 +  typedef UndirListGraph Graph;
   5.162 +  typedef Graph::Node Node;
   5.163 +  typedef Graph::UndirEdge UndirEdge;
   5.164 +
   5.165 +  Graph graph;
   5.166 +  Graph::NodeMap<xy<double> > coords(graph);
   5.167 +
   5.168 +  UndirGraphReader<Graph>("partitions.lgf", graph).
   5.169 +    readNodeMap("coordinates_x", xMap(coords)).
   5.170 +    readNodeMap("coordinates_y", yMap(coords)).
   5.171 +    run();
   5.172 +  
   5.173 +  ColorSet colorSet;
   5.174 +
   5.175 +  Graph::NodeMap<bool> partMap(graph);
   5.176 +  bipartitePartitions(graph, partMap);
   5.177 +
   5.178 +  graphToEps(graph, "bipartite_partitions.eps").undir().
   5.179 +    coords(coords).scaleToA4().enableParallel().
   5.180 +    parEdgeDist(20.0).edgeWidthScale(2.0).nodeScale(20.0).
   5.181 +    nodeColors(composeMap(functorMap(&color), partMap)).run();
   5.182 +  
   5.183 +  std::cout << "Result: bipartite_partitions.eps" << std::endl;
   5.184 +} 
   5.185 +
   5.186 +int main() {
   5.187 +  srand(time(0));
   5.188 +
   5.189 +  drawConnectedComponents();
   5.190 +  drawStronglyConnectedComponents();
   5.191 +  drawNodeBiconnectedComponents();
   5.192 +  drawEdgeBiconnectedComponents();
   5.193 +  drawBipartitePartitions();
   5.194 +  return 0;
   5.195 +}
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/demo/undir_components.lgf	Wed Nov 16 09:15:41 2005 +0000
     6.3 @@ -0,0 +1,103 @@
     6.4 +@nodeset 
     6.5 +coordinates_x	coordinates_y	id	
     6.6 +574.035	177.301	44	
     6.7 +694.579	115.483	43	
     6.8 +280.402	10.3938	42	
     6.9 +212.403	-23.6057	41	
    6.10 +286.584	-48.3327	40	
    6.11 +438.037	-88.514	39	
    6.12 +397.855	-196.694	38	
    6.13 +366.947	-110.15	37	
    6.14 +271.13	-175.058	36	
    6.15 +277.311	-252.33	35	
    6.16 +206.221	-205.967	34	
    6.17 +-840.856	-246.718	18	
    6.18 +-579.033	445.603	17	
    6.19 +-767.847	113.289	16	
    6.20 +906.312	201.403	15	
    6.21 +986.873	-115.807	14	
    6.22 +-470.779	158.605	13	
    6.23 +422.945	521.129	12	
    6.24 +-5.03507	561.41	11	
    6.25 +329.797	314.692	10	
    6.26 +-67.9734	319.727	9	
    6.27 +762.812	-17.6227	8	
    6.28 +526.164	32.7279	7	
    6.29 +730.084	-307.139	6	
    6.30 +415.393	-289.516	5	
    6.31 +-67.9734	-347.42	4	
    6.32 +-309.657	-57.9033	3	
    6.33 +-323.543	-433.964	2	
    6.34 +-539.894	-262.64	1	
    6.35 +-26.6953	-19.9585	19	
    6.36 +116.407	-173.66	20	
    6.37 +201.208	38.3422	21	
    6.38 +-262.548	107.243	22	
    6.39 +-13.4452	133.743	23	
    6.40 +-180.397	245.045	24	
    6.41 +-416.25	345.746	26	
    6.42 +-132.697	451.748	27	
    6.43 +-371.2	568.349	28	
    6.44 +670.264	274.195	29	
    6.45 +588.113	544.499	30	
    6.46 +924.667	409.347	31	
    6.47 +-689.204	-237.261	32	
    6.48 +-567.302	43.6423	33	
    6.49 +@undiredgeset 
    6.50 +		id	
    6.51 +41	42	44	
    6.52 +40	42	43	
    6.53 +37	40	49	
    6.54 +36	40	47	
    6.55 +41	40	42	
    6.56 +38	39	46	
    6.57 +38	37	53	
    6.58 +36	37	48	
    6.59 +39	37	45	
    6.60 +35	36	51	
    6.61 +34	36	50	
    6.62 +34	35	52	
    6.63 +16	17	1	
    6.64 +18	16	2	
    6.65 +14	15	3	
    6.66 +8	15	4	
    6.67 +8	14	5	
    6.68 +17	13	6	
    6.69 +16	13	7	
    6.70 +3	13	8	
    6.71 +11	12	9	
    6.72 +10	12	10	
    6.73 +9	11	11	
    6.74 +9	10	12	
    6.75 +6	8	13	
    6.76 +7	8	14	
    6.77 +5	7	15	
    6.78 +9	7	16	
    6.79 +12	7	17	
    6.80 +5	6	18	
    6.81 +4	5	19	
    6.82 +2	4	20	
    6.83 +1	3	21	
    6.84 +4	3	22	
    6.85 +1	2	23	
    6.86 +22	19	24	
    6.87 +19	20	25	
    6.88 +21	20	26	
    6.89 +19	21	27	
    6.90 +22	23	28	
    6.91 +19	23	29	
    6.92 +22	24	30	
    6.93 +23	24	31	
    6.94 +26	27	32	
    6.95 +24	27	33	
    6.96 +24	27	34	
    6.97 +27	28	35	
    6.98 +26	28	36	
    6.99 +44	29	55	
   6.100 +43	29	54	
   6.101 +29	30	37	
   6.102 +29	31	38	
   6.103 +30	31	39	
   6.104 +32	33	40	
   6.105 +32	33	41	
   6.106 +@end