COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/demo/graph_to_eps_demo.cc @ 1248:ca613a9e3567

Last change on this file since 1248:ca613a9e3567 was 1178:3c176c65d33b, checked in by Alpar Juttner, 20 years ago
File size: 5.4 KB
RevLine 
[1073]1/* -*- C++ -*-
2 * src/lemon/demo/graph_to_eps.cc -
3 * Part of LEMON, a generic C++ optimization library
4 *
[1164]5 * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
[1073]6 * (Egervary Combinatorial Optimization Research Group, EGRES).
7 *
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.
11 *
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
14 * purpose.
15 *
16 */
17
18#include<lemon/graph_to_eps.h>
19#include<lemon/maps.h>
20#include<lemon/list_graph.h>
21
22
23using namespace std;
24using namespace lemon;
25
26class IdMap :public MapBase<ListGraph::Node,int>
27{
28  const ListGraph &g;
29public:
30  IdMap(const ListGraph &_g) :g(_g) {}
31  Value operator[](Key n) const { return g.id(n); }
32};
33
34int main()
35{
[1178]36  ColorSet colorSet;
37
[1073]38  ListGraph g;
39  typedef ListGraph::Node Node;
40  typedef ListGraph::NodeIt NodeIt;
41  typedef ListGraph::Edge Edge;
42  typedef xy<int> Xy;
43 
44  Node n1=g.addNode();
45  Node n2=g.addNode();
46  Node n3=g.addNode();
47  Node n4=g.addNode();
48  Node n5=g.addNode();
49
50  ListGraph::NodeMap<Xy> coords(g);
51  ListGraph::NodeMap<double> sizes(g);
52  ListGraph::NodeMap<int> colors(g);
[1086]53  ListGraph::NodeMap<int> shapes(g);
[1073]54  ListGraph::EdgeMap<int> ecolors(g);
55  ListGraph::EdgeMap<int> widths(g);
56 
[1086]57  coords[n1]=Xy(50,50);  sizes[n1]=1; colors[n1]=1; shapes[n1]=0;
[1088]58  coords[n2]=Xy(50,70);  sizes[n2]=2; colors[n2]=2; shapes[n2]=2;
[1086]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;
[1088]61  coords[n5]=Xy(85,60);  sizes[n5]=3; colors[n5]=5; shapes[n5]=2;
[1073]62 
63  Edge e;
64
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;
72 
73  IdMap id(g);
74
75  graphToEps(g,"graph_to_eps_demo_out.eps").scale(10).coords(coords).
[1108]76    title("Sample .eps figure").
[1164]77    copyright("(C) 2005 LEMON Project").
[1073]78    nodeScale(2).nodeSizes(sizes).
[1086]79    nodeShapes(shapes).
[1073]80    nodeColors(composeMap(colorSet,colors)).
81    edgeColors(composeMap(colorSet,ecolors)).
82    edgeWidthScale(.4).edgeWidths(widths).
[1091]83    nodeTexts(id).nodeTextSize(3).
84    run();
[1073]85
[1091]86  graphToEps(g,"graph_to_eps_demo_out_arr.eps").scale(10).
[1108]87    title("Sample .eps figure (with arrowheads)").
[1164]88    copyright("(C) 2005 LEMON Project").
[1091]89    nodeColors(composeMap(colorSet,colors)).
90    coords(coords).
[1073]91    nodeScale(2).nodeSizes(sizes).
[1086]92    nodeShapes(shapes).
[1073]93    edgeColors(composeMap(colorSet,ecolors)).
94    edgeWidthScale(.4).edgeWidths(widths).
95    nodeTexts(id).nodeTextSize(3).
[1091]96    drawArrows().arrowWidth(1).arrowLength(1).
97    run();
[1073]98
99  e=g.addEdge(n1,n4); ecolors[e]=2; widths[e]=1;
100  e=g.addEdge(n4,n1); ecolors[e]=1; widths[e]=2;
101
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;
109
[1091]110  graphToEps(g,"graph_to_eps_demo_out_par.eps").scale(10).
[1108]111    title("Sample .eps figure (parallel edges)").
[1164]112    copyright("(C) 2005 LEMON Project").
[1091]113    nodeShapes(shapes).
114    coords(coords).
[1073]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).
[1091]120    enableParallel().parEdgeDist(1.5).
121    run();
122 
123  graphToEps(g,"graph_to_eps_demo_out_par_arr.eps").scale(10).
[1108]124    title("Sample .eps figure (parallel edges and arrowheads)").
[1164]125    copyright("(C) 2005 LEMON Project").
[1073]126    nodeScale(2).nodeSizes(sizes).
[1091]127    coords(coords).
[1086]128    nodeShapes(shapes).
[1073]129    nodeColors(composeMap(colorSet,colors)).
130    edgeColors(composeMap(colorSet,ecolors)).
131    edgeWidthScale(.3).edgeWidths(widths).
132    nodeTexts(id).nodeTextSize(3).
133    enableParallel().parEdgeDist(1).
[1091]134    drawArrows().arrowWidth(1).arrowLength(1).
[1103]135    run();
136
137  graphToEps(g,"graph_to_eps_demo_out_a4.eps").scaleToA4().
[1108]138    title("Sample .eps figure (fits to A4)").
[1164]139    copyright("(C) 2005 LEMON Project").
[1103]140    nodeScale(2).nodeSizes(sizes).
141    coords(coords).
142    nodeShapes(shapes).
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).
149    run();
150
[1178]151  ListGraph h;
152  ListGraph::NodeMap<int> hcolors(h);
153  ListGraph::NodeMap<Xy> hcoords(h);
154 
155  int cols=int(sqrt(double(colorSet.size())));
156  for(int i=0;i<int(colorSet.size());i++) {
157    Node n=h.addNode();
158    hcoords[n]=Xy(i%cols,i/cols);
159    hcolors[n]=i;
160  }
161 
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").
165    coords(hcoords).
166    nodeScale(.45).
167    distantColorNodeTexts().
168    //    distantBWNodeTexts().
169    nodeTexts(hcolors).nodeTextSize(.6).
170    nodeColors(composeMap(colorSet,hcolors)).
171    run();
172
173
[1073]174}
Note: See TracBrowser for help on using the repository browser.