COIN-OR::LEMON - Graph Library

source: lemon-0.x/demo/graph_to_eps_demo.cc @ 1581:9bb83c7f479b

Last change on this file since 1581:9bb83c7f479b was 1573:b76a0af36f44, checked in by Alpar Juttner, 19 years ago
  • graph_to_eps_demo.cc is rightly documented
  • Fix/improve documentation of graphToEps()
  • Missing const added to ColorSet::size();
File size: 6.0 KB
Line 
1/* -*- C++ -*-
2 * demo/graph_to_eps.cc - Part of LEMON, a generic C++ optimization library
3 *
4 * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
5 * (Egervary Research Group on Combinatorial Optimization, EGRES).
6 *
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.
10 *
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
13 * purpose.
14 *
15 */
16
17/// \ingroup demos
18/// \file
19/// \brief Demo of the graph grawing function \ref graphToEps()
20///
21/// This demo program shows examples how to  use the function \ref
22/// graphToEps(). It takes no input but simply creates  six
23/// <tt>.eps</tt> files demonstrating how to draw directed/undirected
24/// graphs, how to handle parallel egdes, how to change the properties
25/// (like color, shape, size, title etc.) of nodes and edges
26/// individually using appropriate \ref maps-page "graphmaps".
27
28#include <cmath>
29
30#include<lemon/graph_to_eps.h>
31#include<lemon/list_graph.h>
32
33using namespace std;
34using namespace lemon;
35
36int main()
37{
38  ColorSet colorSet;
39
40  ListGraph g;
41  typedef ListGraph::Node Node;
42  typedef ListGraph::NodeIt NodeIt;
43  typedef ListGraph::Edge Edge;
44  typedef xy<int> Xy;
45 
46  Node n1=g.addNode();
47  Node n2=g.addNode();
48  Node n3=g.addNode();
49  Node n4=g.addNode();
50  Node n5=g.addNode();
51
52  ListGraph::NodeMap<Xy> coords(g);
53  ListGraph::NodeMap<double> sizes(g);
54  ListGraph::NodeMap<int> colors(g);
55  ListGraph::NodeMap<int> shapes(g);
56  ListGraph::EdgeMap<int> ecolors(g);
57  ListGraph::EdgeMap<int> widths(g);
58 
59  coords[n1]=Xy(50,50);  sizes[n1]=1; colors[n1]=1; shapes[n1]=0;
60  coords[n2]=Xy(50,70);  sizes[n2]=2; colors[n2]=2; shapes[n2]=2;
61  coords[n3]=Xy(70,70);  sizes[n3]=1; colors[n3]=3; shapes[n3]=0;
62  coords[n4]=Xy(70,50);  sizes[n4]=2; colors[n4]=4; shapes[n4]=1;
63  coords[n5]=Xy(85,60);  sizes[n5]=3; colors[n5]=5; shapes[n5]=2;
64 
65  Edge e;
66
67  e=g.addEdge(n1,n2); ecolors[e]=0; widths[e]=1;
68  e=g.addEdge(n2,n3); ecolors[e]=0; widths[e]=1;
69  e=g.addEdge(n3,n5); ecolors[e]=0; widths[e]=3;
70  e=g.addEdge(n5,n4); ecolors[e]=0; widths[e]=1;
71  e=g.addEdge(n4,n1); ecolors[e]=0; widths[e]=1;
72  e=g.addEdge(n2,n4); ecolors[e]=1; widths[e]=2;
73  e=g.addEdge(n3,n4); ecolors[e]=2; widths[e]=1;
74 
75  IdMap<ListGraph,Node> id(g);
76
77  cout << "Create 'graph_to_eps_demo_out.eps'" << endl;
78  graphToEps(g,"graph_to_eps_demo_out.eps").scale(10).coords(coords).
79    title("Sample .eps figure").
80    copyright("(C) 2005 LEMON Project").
81    nodeScale(2).nodeSizes(sizes).
82    nodeShapes(shapes).
83    nodeColors(composeMap(colorSet,colors)).
84    edgeColors(composeMap(colorSet,ecolors)).
85    edgeWidthScale(.4).edgeWidths(widths).
86    nodeTexts(id).nodeTextSize(3).
87    run();
88
89
90  cout << "Create 'graph_to_eps_demo_out_arr.eps'" << endl;
91  graphToEps(g,"graph_to_eps_demo_out_arr.eps").scale(10).
92    title("Sample .eps figure (with arrowheads)").
93    copyright("(C) 2005 LEMON Project").
94    nodeColors(composeMap(colorSet,colors)).
95    coords(coords).
96    nodeScale(2).nodeSizes(sizes).
97    nodeShapes(shapes).
98    edgeColors(composeMap(colorSet,ecolors)).
99    edgeWidthScale(.4).edgeWidths(widths).
100    nodeTexts(id).nodeTextSize(3).
101    drawArrows().arrowWidth(1).arrowLength(1).
102    run();
103
104  e=g.addEdge(n1,n4); ecolors[e]=2; widths[e]=1;
105  e=g.addEdge(n4,n1); ecolors[e]=1; widths[e]=2;
106
107  e=g.addEdge(n1,n2); ecolors[e]=1; widths[e]=1;
108  e=g.addEdge(n1,n2); ecolors[e]=2; widths[e]=1;
109  e=g.addEdge(n1,n2); ecolors[e]=3; widths[e]=1;
110  e=g.addEdge(n1,n2); ecolors[e]=4; widths[e]=1;
111  e=g.addEdge(n1,n2); ecolors[e]=5; widths[e]=1;
112  e=g.addEdge(n1,n2); ecolors[e]=6; widths[e]=1;
113  e=g.addEdge(n1,n2); ecolors[e]=7; widths[e]=1;
114
115  cout << "Create 'graph_to_eps_demo_out_par.eps'" << endl;
116  graphToEps(g,"graph_to_eps_demo_out_par.eps").scale(10).
117    title("Sample .eps figure (parallel edges)").
118    copyright("(C) 2005 LEMON Project").
119    nodeShapes(shapes).
120    coords(coords).
121    nodeScale(2).nodeSizes(sizes).
122    nodeColors(composeMap(colorSet,colors)).
123    edgeColors(composeMap(colorSet,ecolors)).
124    edgeWidthScale(.4).edgeWidths(widths).
125    nodeTexts(id).nodeTextSize(3).
126    enableParallel().parEdgeDist(1.5).
127    run();
128 
129  cout << "Create 'graph_to_eps_demo_out_par_arr.eps'" << endl;
130  graphToEps(g,"graph_to_eps_demo_out_par_arr.eps").scale(10).
131    title("Sample .eps figure (parallel edges and arrowheads)").
132    copyright("(C) 2005 LEMON Project").
133    nodeScale(2).nodeSizes(sizes).
134    coords(coords).
135    nodeShapes(shapes).
136    nodeColors(composeMap(colorSet,colors)).
137    edgeColors(composeMap(colorSet,ecolors)).
138    edgeWidthScale(.3).edgeWidths(widths).
139    nodeTexts(id).nodeTextSize(3).
140    enableParallel().parEdgeDist(1).
141    drawArrows().arrowWidth(1).arrowLength(1).
142    run();
143
144  cout << "Create 'graph_to_eps_demo_out_a4.eps'" << endl;
145  graphToEps(g,"graph_to_eps_demo_out_a4.eps").scaleToA4().
146    title("Sample .eps figure (fits to A4)").
147    copyright("(C) 2005 LEMON Project").
148    nodeScale(2).nodeSizes(sizes).
149    coords(coords).
150    nodeShapes(shapes).
151    nodeColors(composeMap(colorSet,colors)).
152    edgeColors(composeMap(colorSet,ecolors)).
153    edgeWidthScale(.3).edgeWidths(widths).
154    nodeTexts(id).nodeTextSize(3).
155    enableParallel().parEdgeDist(1).
156    drawArrows().arrowWidth(1).arrowLength(1).
157    run();
158
159  ListGraph h;
160  ListGraph::NodeMap<int> hcolors(h);
161  ListGraph::NodeMap<Xy> hcoords(h);
162 
163  int cols=int(sqrt(double(colorSet.size())));
164  for(int i=0;i<int(colorSet.size());i++) {
165    Node n=h.addNode();
166    hcoords[n]=Xy(i%cols,i/cols);
167    hcolors[n]=i;
168  }
169 
170  cout << "Create 'graph_to_eps_demo_out_colors.eps'" << endl;
171  graphToEps(h,"graph_to_eps_demo_out_colors.eps").scale(60).
172    title("Sample .eps figure (ColorSet demo)").
173    copyright("(C) 2005 LEMON Project").
174    coords(hcoords).
175    nodeScale(.45).
176    distantColorNodeTexts().
177    //    distantBWNodeTexts().
178    nodeTexts(hcolors).nodeTextSize(.6).
179    nodeColors(composeMap(colorSet,hcolors)).
180    run();
181
182
183}
Note: See TracBrowser for help on using the repository browser.