Easy input-output function for common graphs.
Modified Exception handling in graph_reader.
2 * src/lemon/demo/graph_to_eps.cc -
3 * Part of LEMON, a generic C++ optimization library
5 * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
6 * (Egervary Combinatorial Optimization Research Group, EGRES).
8 * Permission to use, modify and distribute this software is granted
9 * provided that this copyright notice appears in all copies. For
10 * precise terms see the accompanying LICENSE file.
12 * This software is provided "AS IS" with no warranty of any kind,
13 * express or implied, and with no claim as to its suitability for any
18 #include<lemon/graph_to_eps.h>
19 #include<lemon/maps.h>
20 #include<lemon/list_graph.h>
24 using namespace lemon;
26 class IdMap :public MapBase<ListGraph::Node,int>
30 IdMap(const ListGraph &_g) :g(_g) {}
31 Value operator[](Key n) const { return g.id(n); }
39 typedef ListGraph::Node Node;
40 typedef ListGraph::NodeIt NodeIt;
41 typedef ListGraph::Edge Edge;
50 ListGraph::NodeMap<Xy> coords(g);
51 ListGraph::NodeMap<double> sizes(g);
52 ListGraph::NodeMap<int> colors(g);
53 ListGraph::NodeMap<int> shapes(g);
54 ListGraph::EdgeMap<int> ecolors(g);
55 ListGraph::EdgeMap<int> widths(g);
57 coords[n1]=Xy(50,50); sizes[n1]=1; colors[n1]=1; shapes[n1]=0;
58 coords[n2]=Xy(50,70); sizes[n2]=2; colors[n2]=2; shapes[n2]=2;
59 coords[n3]=Xy(70,70); sizes[n3]=1; colors[n3]=3; shapes[n3]=0;
60 coords[n4]=Xy(70,50); sizes[n4]=2; colors[n4]=4; shapes[n4]=1;
61 coords[n5]=Xy(85,60); sizes[n5]=3; colors[n5]=5; shapes[n5]=2;
65 e=g.addEdge(n1,n2); ecolors[e]=0; widths[e]=1;
66 e=g.addEdge(n2,n3); ecolors[e]=0; widths[e]=1;
67 e=g.addEdge(n3,n5); ecolors[e]=0; widths[e]=3;
68 e=g.addEdge(n5,n4); ecolors[e]=0; widths[e]=1;
69 e=g.addEdge(n4,n1); ecolors[e]=0; widths[e]=1;
70 e=g.addEdge(n2,n4); ecolors[e]=1; widths[e]=2;
71 e=g.addEdge(n3,n4); ecolors[e]=2; widths[e]=1;
75 graphToEps(g,"graph_to_eps_demo_out.eps").scale(10).coords(coords).
76 title("Sample .eps figure").
77 copyright("(C) 2005 LEMON Project").
78 nodeScale(2).nodeSizes(sizes).
80 nodeColors(composeMap(colorSet,colors)).
81 edgeColors(composeMap(colorSet,ecolors)).
82 edgeWidthScale(.4).edgeWidths(widths).
83 nodeTexts(id).nodeTextSize(3).
86 graphToEps(g,"graph_to_eps_demo_out_arr.eps").scale(10).
87 title("Sample .eps figure (with arrowheads)").
88 copyright("(C) 2005 LEMON Project").
89 nodeColors(composeMap(colorSet,colors)).
91 nodeScale(2).nodeSizes(sizes).
93 edgeColors(composeMap(colorSet,ecolors)).
94 edgeWidthScale(.4).edgeWidths(widths).
95 nodeTexts(id).nodeTextSize(3).
96 drawArrows().arrowWidth(1).arrowLength(1).
99 e=g.addEdge(n1,n4); ecolors[e]=2; widths[e]=1;
100 e=g.addEdge(n4,n1); ecolors[e]=1; widths[e]=2;
102 e=g.addEdge(n1,n2); ecolors[e]=1; widths[e]=1;
103 e=g.addEdge(n1,n2); ecolors[e]=2; widths[e]=1;
104 e=g.addEdge(n1,n2); ecolors[e]=3; widths[e]=1;
105 e=g.addEdge(n1,n2); ecolors[e]=4; widths[e]=1;
106 e=g.addEdge(n1,n2); ecolors[e]=5; widths[e]=1;
107 e=g.addEdge(n1,n2); ecolors[e]=6; widths[e]=1;
108 e=g.addEdge(n1,n2); ecolors[e]=7; widths[e]=1;
110 graphToEps(g,"graph_to_eps_demo_out_par.eps").scale(10).
111 title("Sample .eps figure (parallel edges)").
112 copyright("(C) 2005 LEMON Project").
115 nodeScale(2).nodeSizes(sizes).
116 nodeColors(composeMap(colorSet,colors)).
117 edgeColors(composeMap(colorSet,ecolors)).
118 edgeWidthScale(.4).edgeWidths(widths).
119 nodeTexts(id).nodeTextSize(3).
120 enableParallel().parEdgeDist(1.5).
123 graphToEps(g,"graph_to_eps_demo_out_par_arr.eps").scale(10).
124 title("Sample .eps figure (parallel edges and arrowheads)").
125 copyright("(C) 2005 LEMON Project").
126 nodeScale(2).nodeSizes(sizes).
129 nodeColors(composeMap(colorSet,colors)).
130 edgeColors(composeMap(colorSet,ecolors)).
131 edgeWidthScale(.3).edgeWidths(widths).
132 nodeTexts(id).nodeTextSize(3).
133 enableParallel().parEdgeDist(1).
134 drawArrows().arrowWidth(1).arrowLength(1).
137 graphToEps(g,"graph_to_eps_demo_out_a4.eps").scaleToA4().
138 title("Sample .eps figure (fits to A4)").
139 copyright("(C) 2005 LEMON Project").
140 nodeScale(2).nodeSizes(sizes).
143 nodeColors(composeMap(colorSet,colors)).
144 edgeColors(composeMap(colorSet,ecolors)).
145 edgeWidthScale(.3).edgeWidths(widths).
146 nodeTexts(id).nodeTextSize(3).
147 enableParallel().parEdgeDist(1).
148 drawArrows().arrowWidth(1).arrowLength(1).
152 ListGraph::NodeMap<int> hcolors(h);
153 ListGraph::NodeMap<Xy> hcoords(h);
155 int cols=int(sqrt(double(colorSet.size())));
156 for(int i=0;i<int(colorSet.size());i++) {
158 hcoords[n]=Xy(i%cols,i/cols);
162 graphToEps(h,"graph_to_eps_demo_out_colors.eps").scale(60).
163 title("Sample .eps figure (parallel edges and arrowheads)").
164 copyright("(C) 2005 LEMON Project").
167 distantColorNodeTexts().
168 // distantBWNodeTexts().
169 nodeTexts(hcolors).nodeTextSize(.6).
170 nodeColors(composeMap(colorSet,hcolors)).