3 * This file is a part of LEMON, a generic C++ optimization library
5 * Copyright (C) 2003-2008
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
9 * Permission to use, modify and distribute this software is granted
10 * provided that this copyright notice appears in all copies. For
11 * precise terms see the accompanying LICENSE file.
13 * This software is provided "AS IS" with no warranty of any kind,
14 * express or implied, and with no claim as to its suitability for any
21 /// \brief Demo of the graph drawing function \ref graphToEps()
23 /// This demo program shows examples how to use the function \ref
24 /// graphToEps(). It takes no input but simply creates six
25 /// <tt>.eps</tt> files demonstrating the capability of \ref
26 /// graphToEps(), and showing how to draw directed graphs,
27 /// how to handle parallel egdes, how to change the properties (like
28 /// color, shape, size, title etc.) of nodes and arcs individually
29 /// using appropriate \ref maps-page "graph maps".
31 /// \include graph_to_eps_demo.cc
33 #include<lemon/list_graph.h>
34 #include<lemon/graph_utils.h>
35 #include<lemon/graph_to_eps.h>
36 #include<lemon/math.h>
39 using namespace lemon;
44 Palette paletteW(true);
46 // Create a small digraph
48 typedef ListDigraph::Node Node;
49 typedef ListDigraph::NodeIt NodeIt;
50 typedef ListDigraph::Arc Arc;
51 typedef dim2::Point<int> Point;
59 ListDigraph::NodeMap<Point> coords(g);
60 ListDigraph::NodeMap<double> sizes(g);
61 ListDigraph::NodeMap<int> colors(g);
62 ListDigraph::NodeMap<int> shapes(g);
63 ListDigraph::ArcMap<int> acolors(g);
64 ListDigraph::ArcMap<int> widths(g);
66 coords[n1]=Point(50,50); sizes[n1]=1; colors[n1]=1; shapes[n1]=0;
67 coords[n2]=Point(50,70); sizes[n2]=2; colors[n2]=2; shapes[n2]=2;
68 coords[n3]=Point(70,70); sizes[n3]=1; colors[n3]=3; shapes[n3]=0;
69 coords[n4]=Point(70,50); sizes[n4]=2; colors[n4]=4; shapes[n4]=1;
70 coords[n5]=Point(85,60); sizes[n5]=3; colors[n5]=5; shapes[n5]=2;
74 a=g.addArc(n1,n2); acolors[a]=0; widths[a]=1;
75 a=g.addArc(n2,n3); acolors[a]=0; widths[a]=1;
76 a=g.addArc(n3,n5); acolors[a]=0; widths[a]=3;
77 a=g.addArc(n5,n4); acolors[a]=0; widths[a]=1;
78 a=g.addArc(n4,n1); acolors[a]=0; widths[a]=1;
79 a=g.addArc(n2,n4); acolors[a]=1; widths[a]=2;
80 a=g.addArc(n3,n4); acolors[a]=2; widths[a]=1;
82 IdMap<ListDigraph,Node> id(g);
84 // Create five .eps files showing the digraph with different options
85 cout << "Create 'graph_to_eps_demo_out_1_pure.eps'" << endl;
86 graphToEps(g,"graph_to_eps_demo_out_1_pure.eps").
88 title("Sample .eps figure").
89 copyright("(C) 2003-2008 LEMON Project").
92 cout << "Create 'graph_to_eps_demo_out_2.eps'" << endl;
93 graphToEps(g,"graph_to_eps_demo_out_2.eps").
95 title("Sample .eps figure").
96 copyright("(C) 2003-2008 LEMON Project").
97 absoluteNodeSizes().absoluteArcWidths().
98 nodeScale(2).nodeSizes(sizes).
100 nodeColors(composeMap(palette,colors)).
101 arcColors(composeMap(palette,acolors)).
102 arcWidthScale(.4).arcWidths(widths).
103 nodeTexts(id).nodeTextSize(3).
106 cout << "Create 'graph_to_eps_demo_out_3_arr.eps'" << endl;
107 graphToEps(g,"graph_to_eps_demo_out_3_arr.eps").
108 title("Sample .eps figure (with arrowheads)").
109 copyright("(C) 2003-2008 LEMON Project").
110 absoluteNodeSizes().absoluteArcWidths().
111 nodeColors(composeMap(palette,colors)).
113 nodeScale(2).nodeSizes(sizes).
115 arcColors(composeMap(palette,acolors)).
116 arcWidthScale(.4).arcWidths(widths).
117 nodeTexts(id).nodeTextSize(3).
118 drawArrows().arrowWidth(2).arrowLength(2).
121 a=g.addArc(n1,n4); acolors[a]=2; widths[a]=1;
122 a=g.addArc(n4,n1); acolors[a]=1; widths[a]=2;
124 a=g.addArc(n1,n2); acolors[a]=1; widths[a]=1;
125 a=g.addArc(n1,n2); acolors[a]=2; widths[a]=1;
126 a=g.addArc(n1,n2); acolors[a]=3; widths[a]=1;
127 a=g.addArc(n1,n2); acolors[a]=4; widths[a]=1;
128 a=g.addArc(n1,n2); acolors[a]=5; widths[a]=1;
129 a=g.addArc(n1,n2); acolors[a]=6; widths[a]=1;
130 a=g.addArc(n1,n2); acolors[a]=7; widths[a]=1;
132 cout << "Create 'graph_to_eps_demo_out_par.eps'" << endl;
133 graphToEps(g,"graph_to_eps_demo_out_par.eps").
135 title("Sample .eps figure (parallel arcs)").
136 copyright("(C) 2003-2008 LEMON Project").
137 absoluteNodeSizes().absoluteArcWidths().
140 nodeScale(2).nodeSizes(sizes).
141 nodeColors(composeMap(palette,colors)).
142 arcColors(composeMap(palette,acolors)).
143 arcWidthScale(.4).arcWidths(widths).
144 nodeTexts(id).nodeTextSize(3).
145 enableParallel().parArcDist(1.5).
148 cout << "Create 'graph_to_eps_demo_out_4_par_arr.eps'" << endl;
149 graphToEps(g,"graph_to_eps_demo_out_4_par_arr.eps").
150 title("Sample .eps figure (parallel arcs and arrowheads)").
151 copyright("(C) 2003-2008 LEMON Project").
152 absoluteNodeSizes().absoluteArcWidths().
153 nodeScale(2).nodeSizes(sizes).
156 nodeColors(composeMap(palette,colors)).
157 arcColors(composeMap(palette,acolors)).
158 arcWidthScale(.3).arcWidths(widths).
159 nodeTexts(id).nodeTextSize(3).
160 enableParallel().parArcDist(1).
161 drawArrows().arrowWidth(1).arrowLength(1).
164 cout << "Create 'graph_to_eps_demo_out_5_par_arr_a4.eps'" << endl;
165 graphToEps(g,"graph_to_eps_demo_out_5_par_arr_a4.eps").
166 title("Sample .eps figure (fits to A4)").
167 copyright("(C) 2003-2008 LEMON Project").
169 absoluteNodeSizes().absoluteArcWidths().
170 nodeScale(2).nodeSizes(sizes).
173 nodeColors(composeMap(palette,colors)).
174 arcColors(composeMap(palette,acolors)).
175 arcWidthScale(.3).arcWidths(widths).
176 nodeTexts(id).nodeTextSize(3).
177 enableParallel().parArcDist(1).
178 drawArrows().arrowWidth(1).arrowLength(1).
181 // Create an .eps file showing the colors of a default Palette
183 ListDigraph::NodeMap<int> hcolors(h);
184 ListDigraph::NodeMap<Point> hcoords(h);
186 int cols=int(sqrt(double(palette.size())));
187 for(int i=0;i<int(paletteW.size());i++) {
189 hcoords[n]=Point(1+i%cols,1+i/cols);
193 cout << "Create 'graph_to_eps_demo_out_6_colors.eps'" << endl;
194 graphToEps(h,"graph_to_eps_demo_out_6_colors.eps").
196 title("Sample .eps figure (Palette demo)").
197 copyright("(C) 2003-2008 LEMON Project").
199 absoluteNodeSizes().absoluteArcWidths().
201 distantColorNodeTexts().
202 nodeTexts(hcolors).nodeTextSize(.6).
203 nodeColors(composeMap(paletteW,hcolors)).