COIN-OR::LEMON - Graph Library

source: lemon-0.x/demo/graph_to_eps_demo.cc @ 1587:8f1c317ebeb4

Last change on this file since 1587:8f1c317ebeb4 was 1587:8f1c317ebeb4, checked in by Alpar Juttner, 19 years ago

Doc improvements

File size: 6.1 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
[1573]17/// \ingroup demos
18/// \file
19/// \brief Demo of the graph grawing function \ref graphToEps()
20///
21/// This demo program shows examples how to  use the function \ref
22/// graphToEps(). It takes no input but simply creates  six
[1587]23/// <tt>.eps</tt> files demonstrating the capability of \ref
24/// graphToEps(), and showing how to draw directed/undirected graphs,
25/// how to handle parallel egdes, how to change the properties (like
26/// color, shape, size, title etc.) of nodes and edges individually
27/// using appropriate \ref maps-page "graphmapfactory".
[1073]28
[1417]29#include <cmath>
30
[1573]31#include<lemon/graph_to_eps.h>
32#include<lemon/list_graph.h>
[1073]33
34using namespace std;
35using namespace lemon;
36
37int main()
38{
[1178]39  ColorSet colorSet;
40
[1073]41  ListGraph g;
42  typedef ListGraph::Node Node;
43  typedef ListGraph::NodeIt NodeIt;
44  typedef ListGraph::Edge Edge;
45  typedef xy<int> Xy;
46 
47  Node n1=g.addNode();
48  Node n2=g.addNode();
49  Node n3=g.addNode();
50  Node n4=g.addNode();
51  Node n5=g.addNode();
52
53  ListGraph::NodeMap<Xy> coords(g);
54  ListGraph::NodeMap<double> sizes(g);
55  ListGraph::NodeMap<int> colors(g);
[1086]56  ListGraph::NodeMap<int> shapes(g);
[1073]57  ListGraph::EdgeMap<int> ecolors(g);
58  ListGraph::EdgeMap<int> widths(g);
59 
[1086]60  coords[n1]=Xy(50,50);  sizes[n1]=1; colors[n1]=1; shapes[n1]=0;
[1088]61  coords[n2]=Xy(50,70);  sizes[n2]=2; colors[n2]=2; shapes[n2]=2;
[1086]62  coords[n3]=Xy(70,70);  sizes[n3]=1; colors[n3]=3; shapes[n3]=0;
63  coords[n4]=Xy(70,50);  sizes[n4]=2; colors[n4]=4; shapes[n4]=1;
[1088]64  coords[n5]=Xy(85,60);  sizes[n5]=3; colors[n5]=5; shapes[n5]=2;
[1073]65 
66  Edge e;
67
68  e=g.addEdge(n1,n2); ecolors[e]=0; widths[e]=1;
69  e=g.addEdge(n2,n3); ecolors[e]=0; widths[e]=1;
70  e=g.addEdge(n3,n5); ecolors[e]=0; widths[e]=3;
71  e=g.addEdge(n5,n4); ecolors[e]=0; widths[e]=1;
72  e=g.addEdge(n4,n1); ecolors[e]=0; widths[e]=1;
73  e=g.addEdge(n2,n4); ecolors[e]=1; widths[e]=2;
74  e=g.addEdge(n3,n4); ecolors[e]=2; widths[e]=1;
75 
[1268]76  IdMap<ListGraph,Node> id(g);
[1073]77
[1573]78  cout << "Create 'graph_to_eps_demo_out.eps'" << endl;
[1073]79  graphToEps(g,"graph_to_eps_demo_out.eps").scale(10).coords(coords).
[1108]80    title("Sample .eps figure").
[1164]81    copyright("(C) 2005 LEMON Project").
[1073]82    nodeScale(2).nodeSizes(sizes).
[1086]83    nodeShapes(shapes).
[1073]84    nodeColors(composeMap(colorSet,colors)).
85    edgeColors(composeMap(colorSet,ecolors)).
86    edgeWidthScale(.4).edgeWidths(widths).
[1091]87    nodeTexts(id).nodeTextSize(3).
88    run();
[1073]89
[1573]90
91  cout << "Create 'graph_to_eps_demo_out_arr.eps'" << endl;
[1091]92  graphToEps(g,"graph_to_eps_demo_out_arr.eps").scale(10).
[1108]93    title("Sample .eps figure (with arrowheads)").
[1164]94    copyright("(C) 2005 LEMON Project").
[1091]95    nodeColors(composeMap(colorSet,colors)).
96    coords(coords).
[1073]97    nodeScale(2).nodeSizes(sizes).
[1086]98    nodeShapes(shapes).
[1073]99    edgeColors(composeMap(colorSet,ecolors)).
100    edgeWidthScale(.4).edgeWidths(widths).
101    nodeTexts(id).nodeTextSize(3).
[1091]102    drawArrows().arrowWidth(1).arrowLength(1).
103    run();
[1073]104
105  e=g.addEdge(n1,n4); ecolors[e]=2; widths[e]=1;
106  e=g.addEdge(n4,n1); ecolors[e]=1; widths[e]=2;
107
108  e=g.addEdge(n1,n2); ecolors[e]=1; widths[e]=1;
109  e=g.addEdge(n1,n2); ecolors[e]=2; widths[e]=1;
110  e=g.addEdge(n1,n2); ecolors[e]=3; widths[e]=1;
111  e=g.addEdge(n1,n2); ecolors[e]=4; widths[e]=1;
112  e=g.addEdge(n1,n2); ecolors[e]=5; widths[e]=1;
113  e=g.addEdge(n1,n2); ecolors[e]=6; widths[e]=1;
114  e=g.addEdge(n1,n2); ecolors[e]=7; widths[e]=1;
115
[1573]116  cout << "Create 'graph_to_eps_demo_out_par.eps'" << endl;
[1091]117  graphToEps(g,"graph_to_eps_demo_out_par.eps").scale(10).
[1108]118    title("Sample .eps figure (parallel edges)").
[1164]119    copyright("(C) 2005 LEMON Project").
[1091]120    nodeShapes(shapes).
121    coords(coords).
[1073]122    nodeScale(2).nodeSizes(sizes).
123    nodeColors(composeMap(colorSet,colors)).
124    edgeColors(composeMap(colorSet,ecolors)).
125    edgeWidthScale(.4).edgeWidths(widths).
126    nodeTexts(id).nodeTextSize(3).
[1091]127    enableParallel().parEdgeDist(1.5).
128    run();
129 
[1573]130  cout << "Create 'graph_to_eps_demo_out_par_arr.eps'" << endl;
[1091]131  graphToEps(g,"graph_to_eps_demo_out_par_arr.eps").scale(10).
[1108]132    title("Sample .eps figure (parallel edges and arrowheads)").
[1164]133    copyright("(C) 2005 LEMON Project").
[1073]134    nodeScale(2).nodeSizes(sizes).
[1091]135    coords(coords).
[1086]136    nodeShapes(shapes).
[1073]137    nodeColors(composeMap(colorSet,colors)).
138    edgeColors(composeMap(colorSet,ecolors)).
139    edgeWidthScale(.3).edgeWidths(widths).
140    nodeTexts(id).nodeTextSize(3).
141    enableParallel().parEdgeDist(1).
[1091]142    drawArrows().arrowWidth(1).arrowLength(1).
[1103]143    run();
144
[1573]145  cout << "Create 'graph_to_eps_demo_out_a4.eps'" << endl;
[1103]146  graphToEps(g,"graph_to_eps_demo_out_a4.eps").scaleToA4().
[1108]147    title("Sample .eps figure (fits to A4)").
[1164]148    copyright("(C) 2005 LEMON Project").
[1103]149    nodeScale(2).nodeSizes(sizes).
150    coords(coords).
151    nodeShapes(shapes).
152    nodeColors(composeMap(colorSet,colors)).
153    edgeColors(composeMap(colorSet,ecolors)).
154    edgeWidthScale(.3).edgeWidths(widths).
155    nodeTexts(id).nodeTextSize(3).
156    enableParallel().parEdgeDist(1).
157    drawArrows().arrowWidth(1).arrowLength(1).
158    run();
159
[1178]160  ListGraph h;
161  ListGraph::NodeMap<int> hcolors(h);
162  ListGraph::NodeMap<Xy> hcoords(h);
163 
164  int cols=int(sqrt(double(colorSet.size())));
165  for(int i=0;i<int(colorSet.size());i++) {
166    Node n=h.addNode();
167    hcoords[n]=Xy(i%cols,i/cols);
168    hcolors[n]=i;
169  }
170 
[1573]171  cout << "Create 'graph_to_eps_demo_out_colors.eps'" << endl;
[1178]172  graphToEps(h,"graph_to_eps_demo_out_colors.eps").scale(60).
[1573]173    title("Sample .eps figure (ColorSet demo)").
[1178]174    copyright("(C) 2005 LEMON Project").
175    coords(hcoords).
176    nodeScale(.45).
177    distantColorNodeTexts().
178    //    distantBWNodeTexts().
179    nodeTexts(hcolors).nodeTextSize(.6).
180    nodeColors(composeMap(colorSet,hcolors)).
181    run();
182
183
[1073]184}
Note: See TracBrowser for help on using the repository browser.