alpar@128
|
1 |
/* -*- C++ -*-
|
alpar@128
|
2 |
*
|
alpar@128
|
3 |
* This file is a part of LEMON, a generic C++ optimization library
|
alpar@128
|
4 |
*
|
alpar@128
|
5 |
* Copyright (C) 2003-2008
|
alpar@128
|
6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
|
alpar@128
|
7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES).
|
alpar@128
|
8 |
*
|
alpar@128
|
9 |
* Permission to use, modify and distribute this software is granted
|
alpar@128
|
10 |
* provided that this copyright notice appears in all copies. For
|
alpar@128
|
11 |
* precise terms see the accompanying LICENSE file.
|
alpar@128
|
12 |
*
|
alpar@128
|
13 |
* This software is provided "AS IS" with no warranty of any kind,
|
alpar@128
|
14 |
* express or implied, and with no claim as to its suitability for any
|
alpar@128
|
15 |
* purpose.
|
alpar@128
|
16 |
*
|
alpar@128
|
17 |
*/
|
alpar@128
|
18 |
|
alpar@128
|
19 |
/// \ingroup demos
|
alpar@128
|
20 |
/// \file
|
alpar@128
|
21 |
/// \brief Demo of the graph grawing function \ref graphToEps()
|
alpar@128
|
22 |
///
|
alpar@128
|
23 |
/// This demo program shows examples how to use the function \ref
|
alpar@128
|
24 |
/// graphToEps(). It takes no input but simply creates six
|
alpar@128
|
25 |
/// <tt>.eps</tt> files demonstrating the capability of \ref
|
alpar@128
|
26 |
/// graphToEps(), and showing how to draw directed/graphs,
|
alpar@128
|
27 |
/// how to handle parallel egdes, how to change the properties (like
|
alpar@128
|
28 |
/// color, shape, size, title etc.) of nodes and arcs individually
|
alpar@128
|
29 |
/// using appropriate \ref maps-page "graph maps".
|
alpar@128
|
30 |
///
|
alpar@128
|
31 |
/// \include graph_to_eps_demo.cc
|
alpar@128
|
32 |
|
alpar@128
|
33 |
#include <lemon/math.h>
|
alpar@128
|
34 |
|
alpar@128
|
35 |
#include<lemon/graph_to_eps.h>
|
alpar@128
|
36 |
#include<lemon/list_graph.h>
|
alpar@128
|
37 |
#include<lemon/graph_utils.h>
|
alpar@128
|
38 |
|
alpar@128
|
39 |
using namespace std;
|
alpar@128
|
40 |
using namespace lemon;
|
alpar@128
|
41 |
|
alpar@128
|
42 |
int main()
|
alpar@128
|
43 |
{
|
alpar@128
|
44 |
Palette palette;
|
alpar@129
|
45 |
Palette paletteW(true);
|
alpar@128
|
46 |
|
alpar@128
|
47 |
ListDigraph g;
|
alpar@128
|
48 |
typedef ListDigraph::Node Node;
|
alpar@128
|
49 |
typedef ListDigraph::NodeIt NodeIt;
|
alpar@128
|
50 |
typedef ListDigraph::Arc Arc;
|
alpar@128
|
51 |
typedef dim2::Point<int> Point;
|
alpar@128
|
52 |
|
alpar@128
|
53 |
Node n1=g.addNode();
|
alpar@128
|
54 |
Node n2=g.addNode();
|
alpar@128
|
55 |
Node n3=g.addNode();
|
alpar@128
|
56 |
Node n4=g.addNode();
|
alpar@128
|
57 |
Node n5=g.addNode();
|
alpar@128
|
58 |
|
alpar@128
|
59 |
ListDigraph::NodeMap<Point> coords(g);
|
alpar@128
|
60 |
ListDigraph::NodeMap<double> sizes(g);
|
alpar@128
|
61 |
ListDigraph::NodeMap<int> colors(g);
|
alpar@128
|
62 |
ListDigraph::NodeMap<int> shapes(g);
|
alpar@128
|
63 |
ListDigraph::ArcMap<int> ecolors(g);
|
alpar@128
|
64 |
ListDigraph::ArcMap<int> widths(g);
|
alpar@128
|
65 |
|
alpar@128
|
66 |
coords[n1]=Point(50,50); sizes[n1]=1; colors[n1]=1; shapes[n1]=0;
|
alpar@128
|
67 |
coords[n2]=Point(50,70); sizes[n2]=2; colors[n2]=2; shapes[n2]=2;
|
alpar@128
|
68 |
coords[n3]=Point(70,70); sizes[n3]=1; colors[n3]=3; shapes[n3]=0;
|
alpar@128
|
69 |
coords[n4]=Point(70,50); sizes[n4]=2; colors[n4]=4; shapes[n4]=1;
|
alpar@128
|
70 |
coords[n5]=Point(85,60); sizes[n5]=3; colors[n5]=5; shapes[n5]=2;
|
alpar@128
|
71 |
|
alpar@128
|
72 |
Arc e;
|
alpar@128
|
73 |
|
alpar@128
|
74 |
e=g.addArc(n1,n2); ecolors[e]=0; widths[e]=1;
|
alpar@128
|
75 |
e=g.addArc(n2,n3); ecolors[e]=0; widths[e]=1;
|
alpar@128
|
76 |
e=g.addArc(n3,n5); ecolors[e]=0; widths[e]=3;
|
alpar@128
|
77 |
e=g.addArc(n5,n4); ecolors[e]=0; widths[e]=1;
|
alpar@128
|
78 |
e=g.addArc(n4,n1); ecolors[e]=0; widths[e]=1;
|
alpar@128
|
79 |
e=g.addArc(n2,n4); ecolors[e]=1; widths[e]=2;
|
alpar@128
|
80 |
e=g.addArc(n3,n4); ecolors[e]=2; widths[e]=1;
|
alpar@128
|
81 |
|
alpar@128
|
82 |
IdMap<ListDigraph,Node> id(g);
|
alpar@128
|
83 |
|
alpar@128
|
84 |
cout << "Create 'graph_to_eps_demo_out_pure.eps'" << endl;
|
alpar@128
|
85 |
graphToEps(g,"graph_to_eps_demo_out_pure.eps").
|
alpar@128
|
86 |
//scale(10).
|
alpar@128
|
87 |
coords(coords).
|
alpar@128
|
88 |
title("Sample .eps figure").
|
alpar@128
|
89 |
copyright("(C) 2003-2007 LEMON Project").
|
alpar@128
|
90 |
run();
|
alpar@128
|
91 |
|
alpar@128
|
92 |
cout << "Create 'graph_to_eps_demo_out.eps'" << endl;
|
alpar@128
|
93 |
graphToEps(g,"graph_to_eps_demo_out.eps").
|
alpar@128
|
94 |
//scale(10).
|
alpar@128
|
95 |
coords(coords).
|
alpar@128
|
96 |
title("Sample .eps figure").
|
alpar@128
|
97 |
copyright("(C) 2003-2007 LEMON Project").
|
alpar@128
|
98 |
absoluteNodeSizes().absoluteArcWidths().
|
alpar@128
|
99 |
nodeScale(2).nodeSizes(sizes).
|
alpar@128
|
100 |
nodeShapes(shapes).
|
alpar@128
|
101 |
nodeColors(composeMap(palette,colors)).
|
alpar@128
|
102 |
arcColors(composeMap(palette,ecolors)).
|
alpar@128
|
103 |
arcWidthScale(.4).arcWidths(widths).
|
alpar@128
|
104 |
nodeTexts(id).nodeTextSize(3).
|
alpar@128
|
105 |
run();
|
alpar@128
|
106 |
|
alpar@128
|
107 |
|
alpar@128
|
108 |
cout << "Create 'graph_to_eps_demo_out_arr.eps'" << endl;
|
alpar@128
|
109 |
graphToEps(g,"graph_to_eps_demo_out_arr.eps").
|
alpar@128
|
110 |
//scale(10).
|
alpar@128
|
111 |
title("Sample .eps figure (with arrowheads)").
|
alpar@128
|
112 |
copyright("(C) 2003-2007 LEMON Project").
|
alpar@128
|
113 |
absoluteNodeSizes().absoluteArcWidths().
|
alpar@128
|
114 |
nodeColors(composeMap(palette,colors)).
|
alpar@128
|
115 |
coords(coords).
|
alpar@128
|
116 |
nodeScale(2).nodeSizes(sizes).
|
alpar@128
|
117 |
nodeShapes(shapes).
|
alpar@128
|
118 |
arcColors(composeMap(palette,ecolors)).
|
alpar@128
|
119 |
arcWidthScale(.4).arcWidths(widths).
|
alpar@128
|
120 |
nodeTexts(id).nodeTextSize(3).
|
alpar@128
|
121 |
drawArrows().arrowWidth(1).arrowLength(1).
|
alpar@128
|
122 |
run();
|
alpar@128
|
123 |
|
alpar@128
|
124 |
e=g.addArc(n1,n4); ecolors[e]=2; widths[e]=1;
|
alpar@128
|
125 |
e=g.addArc(n4,n1); ecolors[e]=1; widths[e]=2;
|
alpar@128
|
126 |
|
alpar@128
|
127 |
e=g.addArc(n1,n2); ecolors[e]=1; widths[e]=1;
|
alpar@128
|
128 |
e=g.addArc(n1,n2); ecolors[e]=2; widths[e]=1;
|
alpar@128
|
129 |
e=g.addArc(n1,n2); ecolors[e]=3; widths[e]=1;
|
alpar@128
|
130 |
e=g.addArc(n1,n2); ecolors[e]=4; widths[e]=1;
|
alpar@128
|
131 |
e=g.addArc(n1,n2); ecolors[e]=5; widths[e]=1;
|
alpar@128
|
132 |
e=g.addArc(n1,n2); ecolors[e]=6; widths[e]=1;
|
alpar@128
|
133 |
e=g.addArc(n1,n2); ecolors[e]=7; widths[e]=1;
|
alpar@128
|
134 |
|
alpar@128
|
135 |
cout << "Create 'graph_to_eps_demo_out_par.eps'" << endl;
|
alpar@128
|
136 |
graphToEps(g,"graph_to_eps_demo_out_par.eps").
|
alpar@128
|
137 |
//scale(10).
|
alpar@128
|
138 |
title("Sample .eps figure (parallel arcs)").
|
alpar@128
|
139 |
copyright("(C) 2003-2007 LEMON Project").
|
alpar@128
|
140 |
absoluteNodeSizes().absoluteArcWidths().
|
alpar@128
|
141 |
nodeShapes(shapes).
|
alpar@128
|
142 |
coords(coords).
|
alpar@128
|
143 |
nodeScale(2).nodeSizes(sizes).
|
alpar@128
|
144 |
nodeColors(composeMap(palette,colors)).
|
alpar@128
|
145 |
arcColors(composeMap(palette,ecolors)).
|
alpar@128
|
146 |
arcWidthScale(.4).arcWidths(widths).
|
alpar@128
|
147 |
nodeTexts(id).nodeTextSize(3).
|
alpar@128
|
148 |
enableParallel().parArcDist(1.5).
|
alpar@128
|
149 |
run();
|
alpar@128
|
150 |
|
alpar@128
|
151 |
cout << "Create 'graph_to_eps_demo_out_par_arr.eps'" << endl;
|
alpar@128
|
152 |
graphToEps(g,"graph_to_eps_demo_out_par_arr.eps").
|
alpar@128
|
153 |
//scale(10).
|
alpar@128
|
154 |
title("Sample .eps figure (parallel arcs and arrowheads)").
|
alpar@128
|
155 |
copyright("(C) 2003-2007 LEMON Project").
|
alpar@128
|
156 |
absoluteNodeSizes().absoluteArcWidths().
|
alpar@128
|
157 |
nodeScale(2).nodeSizes(sizes).
|
alpar@128
|
158 |
coords(coords).
|
alpar@128
|
159 |
nodeShapes(shapes).
|
alpar@128
|
160 |
nodeColors(composeMap(palette,colors)).
|
alpar@128
|
161 |
arcColors(composeMap(palette,ecolors)).
|
alpar@128
|
162 |
arcWidthScale(.3).arcWidths(widths).
|
alpar@128
|
163 |
nodeTexts(id).nodeTextSize(3).
|
alpar@128
|
164 |
enableParallel().parArcDist(1).
|
alpar@128
|
165 |
drawArrows().arrowWidth(1).arrowLength(1).
|
alpar@128
|
166 |
run();
|
alpar@128
|
167 |
|
alpar@128
|
168 |
cout << "Create 'graph_to_eps_demo_out_a4.eps'" << endl;
|
alpar@128
|
169 |
graphToEps(g,"graph_to_eps_demo_out_a4.eps").scaleToA4().
|
alpar@128
|
170 |
title("Sample .eps figure (fits to A4)").
|
alpar@128
|
171 |
copyright("(C) 2003-2007 LEMON Project").
|
alpar@128
|
172 |
absoluteNodeSizes().absoluteArcWidths().
|
alpar@128
|
173 |
nodeScale(2).nodeSizes(sizes).
|
alpar@128
|
174 |
coords(coords).
|
alpar@128
|
175 |
nodeShapes(shapes).
|
alpar@128
|
176 |
nodeColors(composeMap(palette,colors)).
|
alpar@128
|
177 |
arcColors(composeMap(palette,ecolors)).
|
alpar@128
|
178 |
arcWidthScale(.3).arcWidths(widths).
|
alpar@128
|
179 |
nodeTexts(id).nodeTextSize(3).
|
alpar@128
|
180 |
enableParallel().parArcDist(1).
|
alpar@128
|
181 |
drawArrows().arrowWidth(1).arrowLength(1).
|
alpar@128
|
182 |
run();
|
alpar@128
|
183 |
|
alpar@128
|
184 |
ListDigraph h;
|
alpar@128
|
185 |
ListDigraph::NodeMap<int> hcolors(h);
|
alpar@128
|
186 |
ListDigraph::NodeMap<Point> hcoords(h);
|
alpar@128
|
187 |
|
alpar@128
|
188 |
int cols=int(sqrt(double(palette.size())));
|
alpar@128
|
189 |
for(int i=0;i<int(paletteW.size());i++) {
|
alpar@128
|
190 |
Node n=h.addNode();
|
alpar@128
|
191 |
hcoords[n]=Point(i%cols,i/cols);
|
alpar@128
|
192 |
hcolors[n]=i;
|
alpar@128
|
193 |
}
|
alpar@128
|
194 |
|
alpar@128
|
195 |
cout << "Create 'graph_to_eps_demo_out_colors.eps'" << endl;
|
alpar@128
|
196 |
graphToEps(h,"graph_to_eps_demo_out_colors.eps").
|
alpar@128
|
197 |
//scale(60).
|
alpar@128
|
198 |
title("Sample .eps figure (Palette demo)").
|
alpar@128
|
199 |
copyright("(C) 2003-2007 LEMON Project").
|
alpar@128
|
200 |
coords(hcoords).
|
alpar@128
|
201 |
absoluteNodeSizes().absoluteArcWidths().
|
alpar@128
|
202 |
nodeScale(45).
|
alpar@128
|
203 |
distantColorNodeTexts().
|
alpar@128
|
204 |
// distantBWNodeTexts().
|
alpar@128
|
205 |
nodeTexts(hcolors).nodeTextSize(.6).
|
alpar@128
|
206 |
nodeColors(composeMap(paletteW,hcolors)).
|
alpar@128
|
207 |
run();
|
alpar@128
|
208 |
}
|