COIN-OR::LEMON - Graph Library

source: lemon-0.x/demo/graph_to_eps_demo.cc @ 2129:43849d6e280a

Last change on this file since 2129:43849d6e280a was 1956:a055123339d5, checked in by Alpar Juttner, 19 years ago

Unified copyright notices

File size: 6.2 KB
RevLine 
[1073]1/* -*- C++ -*-
2 *
[1956]3 * This file is a part of LEMON, a generic C++ optimization library
4 *
5 * Copyright (C) 2003-2006
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
[1359]7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
[1073]8 *
9 * Permission to use, modify and distribute this software is granted
10 * provided that this copyright notice appears in all copies. For
11 * precise terms see the accompanying LICENSE file.
12 *
13 * This software is provided "AS IS" with no warranty of any kind,
14 * express or implied, and with no claim as to its suitability for any
15 * purpose.
16 *
17 */
18
[1573]19/// \ingroup demos
20/// \file
21/// \brief Demo of the graph grawing function \ref graphToEps()
22///
23/// This demo program shows examples how to  use the function \ref
24/// graphToEps(). It takes no input but simply creates  six
[1587]25/// <tt>.eps</tt> files demonstrating the capability of \ref
26/// graphToEps(), and showing how to draw directed/undirected graphs,
27/// how to handle parallel egdes, how to change the properties (like
28/// color, shape, size, title etc.) of nodes and edges individually
[1630]29/// using appropriate \ref maps-page "graph maps".
[1641]30///
31/// \include graph_to_eps_demo.cc
[1073]32
[1417]33#include <cmath>
34
[1573]35#include<lemon/graph_to_eps.h>
36#include<lemon/list_graph.h>
[1802]37#include<lemon/graph_utils.h>
[1073]38
39using namespace std;
40using namespace lemon;
41
42int main()
43{
[1178]44  ColorSet colorSet;
45
[1073]46  ListGraph g;
47  typedef ListGraph::Node Node;
48  typedef ListGraph::NodeIt NodeIt;
49  typedef ListGraph::Edge Edge;
50  typedef xy<int> Xy;
51 
52  Node n1=g.addNode();
53  Node n2=g.addNode();
54  Node n3=g.addNode();
55  Node n4=g.addNode();
56  Node n5=g.addNode();
57
58  ListGraph::NodeMap<Xy> coords(g);
59  ListGraph::NodeMap<double> sizes(g);
60  ListGraph::NodeMap<int> colors(g);
[1086]61  ListGraph::NodeMap<int> shapes(g);
[1073]62  ListGraph::EdgeMap<int> ecolors(g);
63  ListGraph::EdgeMap<int> widths(g);
64 
[1086]65  coords[n1]=Xy(50,50);  sizes[n1]=1; colors[n1]=1; shapes[n1]=0;
[1088]66  coords[n2]=Xy(50,70);  sizes[n2]=2; colors[n2]=2; shapes[n2]=2;
[1086]67  coords[n3]=Xy(70,70);  sizes[n3]=1; colors[n3]=3; shapes[n3]=0;
68  coords[n4]=Xy(70,50);  sizes[n4]=2; colors[n4]=4; shapes[n4]=1;
[1088]69  coords[n5]=Xy(85,60);  sizes[n5]=3; colors[n5]=5; shapes[n5]=2;
[1073]70 
71  Edge e;
72
73  e=g.addEdge(n1,n2); ecolors[e]=0; widths[e]=1;
74  e=g.addEdge(n2,n3); ecolors[e]=0; widths[e]=1;
75  e=g.addEdge(n3,n5); ecolors[e]=0; widths[e]=3;
76  e=g.addEdge(n5,n4); ecolors[e]=0; widths[e]=1;
77  e=g.addEdge(n4,n1); ecolors[e]=0; widths[e]=1;
78  e=g.addEdge(n2,n4); ecolors[e]=1; widths[e]=2;
79  e=g.addEdge(n3,n4); ecolors[e]=2; widths[e]=1;
80 
[1268]81  IdMap<ListGraph,Node> id(g);
[1073]82
[1573]83  cout << "Create 'graph_to_eps_demo_out.eps'" << endl;
[1930]84  graphToEps(g,"graph_to_eps_demo_out.eps").
85    //scale(10).
86    coords(coords).
[1108]87    title("Sample .eps figure").
[1875]88    copyright("(C) 2006 LEMON Project").
[1073]89    nodeScale(2).nodeSizes(sizes).
[1086]90    nodeShapes(shapes).
[1073]91    nodeColors(composeMap(colorSet,colors)).
92    edgeColors(composeMap(colorSet,ecolors)).
93    edgeWidthScale(.4).edgeWidths(widths).
[1091]94    nodeTexts(id).nodeTextSize(3).
95    run();
[1073]96
[1573]97
98  cout << "Create 'graph_to_eps_demo_out_arr.eps'" << endl;
[1930]99  graphToEps(g,"graph_to_eps_demo_out_arr.eps").
100    //scale(10).
[1108]101    title("Sample .eps figure (with arrowheads)").
[1875]102    copyright("(C) 2006 LEMON Project").
[1091]103    nodeColors(composeMap(colorSet,colors)).
104    coords(coords).
[1073]105    nodeScale(2).nodeSizes(sizes).
[1086]106    nodeShapes(shapes).
[1073]107    edgeColors(composeMap(colorSet,ecolors)).
108    edgeWidthScale(.4).edgeWidths(widths).
109    nodeTexts(id).nodeTextSize(3).
[1091]110    drawArrows().arrowWidth(1).arrowLength(1).
111    run();
[1073]112
113  e=g.addEdge(n1,n4); ecolors[e]=2; widths[e]=1;
114  e=g.addEdge(n4,n1); ecolors[e]=1; widths[e]=2;
115
116  e=g.addEdge(n1,n2); ecolors[e]=1; widths[e]=1;
117  e=g.addEdge(n1,n2); ecolors[e]=2; widths[e]=1;
118  e=g.addEdge(n1,n2); ecolors[e]=3; widths[e]=1;
119  e=g.addEdge(n1,n2); ecolors[e]=4; widths[e]=1;
120  e=g.addEdge(n1,n2); ecolors[e]=5; widths[e]=1;
121  e=g.addEdge(n1,n2); ecolors[e]=6; widths[e]=1;
122  e=g.addEdge(n1,n2); ecolors[e]=7; widths[e]=1;
123
[1573]124  cout << "Create 'graph_to_eps_demo_out_par.eps'" << endl;
[1930]125  graphToEps(g,"graph_to_eps_demo_out_par.eps").
126    //scale(10).
[1108]127    title("Sample .eps figure (parallel edges)").
[1875]128    copyright("(C) 2006 LEMON Project").
[1091]129    nodeShapes(shapes).
130    coords(coords).
[1073]131    nodeScale(2).nodeSizes(sizes).
132    nodeColors(composeMap(colorSet,colors)).
133    edgeColors(composeMap(colorSet,ecolors)).
134    edgeWidthScale(.4).edgeWidths(widths).
135    nodeTexts(id).nodeTextSize(3).
[1091]136    enableParallel().parEdgeDist(1.5).
137    run();
138 
[1573]139  cout << "Create 'graph_to_eps_demo_out_par_arr.eps'" << endl;
[1930]140  graphToEps(g,"graph_to_eps_demo_out_par_arr.eps").
141    //scale(10).
[1108]142    title("Sample .eps figure (parallel edges and arrowheads)").
[1875]143    copyright("(C) 2006 LEMON Project").
[1073]144    nodeScale(2).nodeSizes(sizes).
[1091]145    coords(coords).
[1086]146    nodeShapes(shapes).
[1073]147    nodeColors(composeMap(colorSet,colors)).
148    edgeColors(composeMap(colorSet,ecolors)).
149    edgeWidthScale(.3).edgeWidths(widths).
150    nodeTexts(id).nodeTextSize(3).
151    enableParallel().parEdgeDist(1).
[1091]152    drawArrows().arrowWidth(1).arrowLength(1).
[1103]153    run();
154
[1573]155  cout << "Create 'graph_to_eps_demo_out_a4.eps'" << endl;
[1103]156  graphToEps(g,"graph_to_eps_demo_out_a4.eps").scaleToA4().
[1108]157    title("Sample .eps figure (fits to A4)").
[1875]158    copyright("(C) 2006 LEMON Project").
[1103]159    nodeScale(2).nodeSizes(sizes).
160    coords(coords).
161    nodeShapes(shapes).
162    nodeColors(composeMap(colorSet,colors)).
163    edgeColors(composeMap(colorSet,ecolors)).
164    edgeWidthScale(.3).edgeWidths(widths).
165    nodeTexts(id).nodeTextSize(3).
166    enableParallel().parEdgeDist(1).
167    drawArrows().arrowWidth(1).arrowLength(1).
168    run();
169
[1178]170  ListGraph h;
171  ListGraph::NodeMap<int> hcolors(h);
172  ListGraph::NodeMap<Xy> hcoords(h);
173 
174  int cols=int(sqrt(double(colorSet.size())));
175  for(int i=0;i<int(colorSet.size());i++) {
176    Node n=h.addNode();
177    hcoords[n]=Xy(i%cols,i/cols);
178    hcolors[n]=i;
179  }
180 
[1573]181  cout << "Create 'graph_to_eps_demo_out_colors.eps'" << endl;
[1930]182  graphToEps(h,"graph_to_eps_demo_out_colors.eps").
183    //scale(60).
[1573]184    title("Sample .eps figure (ColorSet demo)").
[1875]185    copyright("(C) 2006 LEMON Project").
[1178]186    coords(hcoords).
187    nodeScale(.45).
188    distantColorNodeTexts().
189    //    distantBWNodeTexts().
190    nodeTexts(hcolors).nodeTextSize(.6).
191    nodeColors(composeMap(colorSet,hcolors)).
192    run();
193
194
[1073]195}
Note: See TracBrowser for help on using the repository browser.