COIN-OR::LEMON - Graph Library

source: lemon-0.x/demo/graph_to_eps_demo.cc @ 1476:182da222fceb

Last change on this file since 1476:182da222fceb was 1435:8e85e6bbefdf, checked in by Akos Ladanyi, 19 years ago

trunk/src/* move to trunk/

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