COIN-OR::LEMON - Graph Library

source: lemon-0.x/demo/graph_to_eps_demo.cc @ 1573:b76a0af36f44

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