alpar@1073
|
1 |
/* -*- C++ -*-
|
alpar@1073
|
2 |
* src/lemon/demo/graph_to_eps.cc -
|
alpar@1073
|
3 |
* Part of LEMON, a generic C++ optimization library
|
alpar@1073
|
4 |
*
|
alpar@1164
|
5 |
* Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
|
alpar@1359
|
6 |
* (Egervary Research Group on Combinatorial Optimization, EGRES).
|
alpar@1073
|
7 |
*
|
alpar@1073
|
8 |
* Permission to use, modify and distribute this software is granted
|
alpar@1073
|
9 |
* provided that this copyright notice appears in all copies. For
|
alpar@1073
|
10 |
* precise terms see the accompanying LICENSE file.
|
alpar@1073
|
11 |
*
|
alpar@1073
|
12 |
* This software is provided "AS IS" with no warranty of any kind,
|
alpar@1073
|
13 |
* express or implied, and with no claim as to its suitability for any
|
alpar@1073
|
14 |
* purpose.
|
alpar@1073
|
15 |
*
|
alpar@1073
|
16 |
*/
|
alpar@1073
|
17 |
|
alpar@1073
|
18 |
#include<lemon/graph_to_eps.h>
|
alpar@1073
|
19 |
#include<lemon/maps.h>
|
alpar@1073
|
20 |
#include<lemon/list_graph.h>
|
alpar@1268
|
21 |
#include<lemon/graph_utils.h>
|
alpar@1073
|
22 |
|
deba@1417
|
23 |
#include <cmath>
|
deba@1417
|
24 |
|
alpar@1073
|
25 |
|
alpar@1073
|
26 |
using namespace std;
|
alpar@1073
|
27 |
using namespace lemon;
|
alpar@1073
|
28 |
|
alpar@1073
|
29 |
int main()
|
alpar@1073
|
30 |
{
|
alpar@1178
|
31 |
ColorSet colorSet;
|
alpar@1178
|
32 |
|
alpar@1073
|
33 |
ListGraph g;
|
alpar@1073
|
34 |
typedef ListGraph::Node Node;
|
alpar@1073
|
35 |
typedef ListGraph::NodeIt NodeIt;
|
alpar@1073
|
36 |
typedef ListGraph::Edge Edge;
|
alpar@1073
|
37 |
typedef xy<int> Xy;
|
alpar@1073
|
38 |
|
alpar@1073
|
39 |
Node n1=g.addNode();
|
alpar@1073
|
40 |
Node n2=g.addNode();
|
alpar@1073
|
41 |
Node n3=g.addNode();
|
alpar@1073
|
42 |
Node n4=g.addNode();
|
alpar@1073
|
43 |
Node n5=g.addNode();
|
alpar@1073
|
44 |
|
alpar@1073
|
45 |
ListGraph::NodeMap<Xy> coords(g);
|
alpar@1073
|
46 |
ListGraph::NodeMap<double> sizes(g);
|
alpar@1073
|
47 |
ListGraph::NodeMap<int> colors(g);
|
alpar@1086
|
48 |
ListGraph::NodeMap<int> shapes(g);
|
alpar@1073
|
49 |
ListGraph::EdgeMap<int> ecolors(g);
|
alpar@1073
|
50 |
ListGraph::EdgeMap<int> widths(g);
|
alpar@1073
|
51 |
|
alpar@1086
|
52 |
coords[n1]=Xy(50,50); sizes[n1]=1; colors[n1]=1; shapes[n1]=0;
|
alpar@1088
|
53 |
coords[n2]=Xy(50,70); sizes[n2]=2; colors[n2]=2; shapes[n2]=2;
|
alpar@1086
|
54 |
coords[n3]=Xy(70,70); sizes[n3]=1; colors[n3]=3; shapes[n3]=0;
|
alpar@1086
|
55 |
coords[n4]=Xy(70,50); sizes[n4]=2; colors[n4]=4; shapes[n4]=1;
|
alpar@1088
|
56 |
coords[n5]=Xy(85,60); sizes[n5]=3; colors[n5]=5; shapes[n5]=2;
|
alpar@1073
|
57 |
|
alpar@1073
|
58 |
Edge e;
|
alpar@1073
|
59 |
|
alpar@1073
|
60 |
e=g.addEdge(n1,n2); ecolors[e]=0; widths[e]=1;
|
alpar@1073
|
61 |
e=g.addEdge(n2,n3); ecolors[e]=0; widths[e]=1;
|
alpar@1073
|
62 |
e=g.addEdge(n3,n5); ecolors[e]=0; widths[e]=3;
|
alpar@1073
|
63 |
e=g.addEdge(n5,n4); ecolors[e]=0; widths[e]=1;
|
alpar@1073
|
64 |
e=g.addEdge(n4,n1); ecolors[e]=0; widths[e]=1;
|
alpar@1073
|
65 |
e=g.addEdge(n2,n4); ecolors[e]=1; widths[e]=2;
|
alpar@1073
|
66 |
e=g.addEdge(n3,n4); ecolors[e]=2; widths[e]=1;
|
alpar@1073
|
67 |
|
alpar@1268
|
68 |
IdMap<ListGraph,Node> id(g);
|
alpar@1073
|
69 |
|
alpar@1073
|
70 |
graphToEps(g,"graph_to_eps_demo_out.eps").scale(10).coords(coords).
|
alpar@1108
|
71 |
title("Sample .eps figure").
|
alpar@1164
|
72 |
copyright("(C) 2005 LEMON Project").
|
alpar@1073
|
73 |
nodeScale(2).nodeSizes(sizes).
|
alpar@1086
|
74 |
nodeShapes(shapes).
|
alpar@1073
|
75 |
nodeColors(composeMap(colorSet,colors)).
|
alpar@1073
|
76 |
edgeColors(composeMap(colorSet,ecolors)).
|
alpar@1073
|
77 |
edgeWidthScale(.4).edgeWidths(widths).
|
alpar@1091
|
78 |
nodeTexts(id).nodeTextSize(3).
|
alpar@1091
|
79 |
run();
|
alpar@1073
|
80 |
|
alpar@1091
|
81 |
graphToEps(g,"graph_to_eps_demo_out_arr.eps").scale(10).
|
alpar@1108
|
82 |
title("Sample .eps figure (with arrowheads)").
|
alpar@1164
|
83 |
copyright("(C) 2005 LEMON Project").
|
alpar@1091
|
84 |
nodeColors(composeMap(colorSet,colors)).
|
alpar@1091
|
85 |
coords(coords).
|
alpar@1073
|
86 |
nodeScale(2).nodeSizes(sizes).
|
alpar@1086
|
87 |
nodeShapes(shapes).
|
alpar@1073
|
88 |
edgeColors(composeMap(colorSet,ecolors)).
|
alpar@1073
|
89 |
edgeWidthScale(.4).edgeWidths(widths).
|
alpar@1073
|
90 |
nodeTexts(id).nodeTextSize(3).
|
alpar@1091
|
91 |
drawArrows().arrowWidth(1).arrowLength(1).
|
alpar@1091
|
92 |
run();
|
alpar@1073
|
93 |
|
alpar@1073
|
94 |
e=g.addEdge(n1,n4); ecolors[e]=2; widths[e]=1;
|
alpar@1073
|
95 |
e=g.addEdge(n4,n1); ecolors[e]=1; widths[e]=2;
|
alpar@1073
|
96 |
|
alpar@1073
|
97 |
e=g.addEdge(n1,n2); ecolors[e]=1; widths[e]=1;
|
alpar@1073
|
98 |
e=g.addEdge(n1,n2); ecolors[e]=2; widths[e]=1;
|
alpar@1073
|
99 |
e=g.addEdge(n1,n2); ecolors[e]=3; widths[e]=1;
|
alpar@1073
|
100 |
e=g.addEdge(n1,n2); ecolors[e]=4; widths[e]=1;
|
alpar@1073
|
101 |
e=g.addEdge(n1,n2); ecolors[e]=5; widths[e]=1;
|
alpar@1073
|
102 |
e=g.addEdge(n1,n2); ecolors[e]=6; widths[e]=1;
|
alpar@1073
|
103 |
e=g.addEdge(n1,n2); ecolors[e]=7; widths[e]=1;
|
alpar@1073
|
104 |
|
alpar@1091
|
105 |
graphToEps(g,"graph_to_eps_demo_out_par.eps").scale(10).
|
alpar@1108
|
106 |
title("Sample .eps figure (parallel edges)").
|
alpar@1164
|
107 |
copyright("(C) 2005 LEMON Project").
|
alpar@1091
|
108 |
nodeShapes(shapes).
|
alpar@1091
|
109 |
coords(coords).
|
alpar@1073
|
110 |
nodeScale(2).nodeSizes(sizes).
|
alpar@1073
|
111 |
nodeColors(composeMap(colorSet,colors)).
|
alpar@1073
|
112 |
edgeColors(composeMap(colorSet,ecolors)).
|
alpar@1073
|
113 |
edgeWidthScale(.4).edgeWidths(widths).
|
alpar@1073
|
114 |
nodeTexts(id).nodeTextSize(3).
|
alpar@1091
|
115 |
enableParallel().parEdgeDist(1.5).
|
alpar@1091
|
116 |
run();
|
alpar@1091
|
117 |
|
alpar@1091
|
118 |
graphToEps(g,"graph_to_eps_demo_out_par_arr.eps").scale(10).
|
alpar@1108
|
119 |
title("Sample .eps figure (parallel edges and arrowheads)").
|
alpar@1164
|
120 |
copyright("(C) 2005 LEMON Project").
|
alpar@1073
|
121 |
nodeScale(2).nodeSizes(sizes).
|
alpar@1091
|
122 |
coords(coords).
|
alpar@1086
|
123 |
nodeShapes(shapes).
|
alpar@1073
|
124 |
nodeColors(composeMap(colorSet,colors)).
|
alpar@1073
|
125 |
edgeColors(composeMap(colorSet,ecolors)).
|
alpar@1073
|
126 |
edgeWidthScale(.3).edgeWidths(widths).
|
alpar@1073
|
127 |
nodeTexts(id).nodeTextSize(3).
|
alpar@1073
|
128 |
enableParallel().parEdgeDist(1).
|
alpar@1091
|
129 |
drawArrows().arrowWidth(1).arrowLength(1).
|
alpar@1103
|
130 |
run();
|
alpar@1103
|
131 |
|
alpar@1103
|
132 |
graphToEps(g,"graph_to_eps_demo_out_a4.eps").scaleToA4().
|
alpar@1108
|
133 |
title("Sample .eps figure (fits to A4)").
|
alpar@1164
|
134 |
copyright("(C) 2005 LEMON Project").
|
alpar@1103
|
135 |
nodeScale(2).nodeSizes(sizes).
|
alpar@1103
|
136 |
coords(coords).
|
alpar@1103
|
137 |
nodeShapes(shapes).
|
alpar@1103
|
138 |
nodeColors(composeMap(colorSet,colors)).
|
alpar@1103
|
139 |
edgeColors(composeMap(colorSet,ecolors)).
|
alpar@1103
|
140 |
edgeWidthScale(.3).edgeWidths(widths).
|
alpar@1103
|
141 |
nodeTexts(id).nodeTextSize(3).
|
alpar@1103
|
142 |
enableParallel().parEdgeDist(1).
|
alpar@1103
|
143 |
drawArrows().arrowWidth(1).arrowLength(1).
|
alpar@1103
|
144 |
run();
|
alpar@1103
|
145 |
|
alpar@1178
|
146 |
ListGraph h;
|
alpar@1178
|
147 |
ListGraph::NodeMap<int> hcolors(h);
|
alpar@1178
|
148 |
ListGraph::NodeMap<Xy> hcoords(h);
|
alpar@1178
|
149 |
|
alpar@1178
|
150 |
int cols=int(sqrt(double(colorSet.size())));
|
alpar@1178
|
151 |
for(int i=0;i<int(colorSet.size());i++) {
|
alpar@1178
|
152 |
Node n=h.addNode();
|
alpar@1178
|
153 |
hcoords[n]=Xy(i%cols,i/cols);
|
alpar@1178
|
154 |
hcolors[n]=i;
|
alpar@1178
|
155 |
}
|
alpar@1178
|
156 |
|
alpar@1178
|
157 |
graphToEps(h,"graph_to_eps_demo_out_colors.eps").scale(60).
|
alpar@1178
|
158 |
title("Sample .eps figure (parallel edges and arrowheads)").
|
alpar@1178
|
159 |
copyright("(C) 2005 LEMON Project").
|
alpar@1178
|
160 |
coords(hcoords).
|
alpar@1178
|
161 |
nodeScale(.45).
|
alpar@1178
|
162 |
distantColorNodeTexts().
|
alpar@1178
|
163 |
// distantBWNodeTexts().
|
alpar@1178
|
164 |
nodeTexts(hcolors).nodeTextSize(.6).
|
alpar@1178
|
165 |
nodeColors(composeMap(colorSet,hcolors)).
|
alpar@1178
|
166 |
run();
|
alpar@1178
|
167 |
|
alpar@1178
|
168 |
|
alpar@1073
|
169 |
}
|