COIN-OR::LEMON - Graph Library

source: lemon-main/demo/graph_to_eps_demo.cc @ 903:3ffd46dc8e01

Last change on this file since 903:3ffd46dc8e01 was 612:0c8e5c688440, checked in by Alpar Juttner <alpar@…>, 16 years ago

Fix usage of sqrt() (#268)

File size: 6.9 KB
RevLine 
[209]1/* -*- mode: C++; indent-tabs-mode: nil; -*-
[128]2 *
[209]3 * This file is a part of LEMON, a generic C++ optimization library.
[128]4 *
[440]5 * Copyright (C) 2003-2009
[128]6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
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
19/// \ingroup demos
20/// \file
[206]21/// \brief Demo of the graph drawing function \ref graphToEps()
[128]22///
[211]23/// This demo program shows examples how to use the function \ref
24/// graphToEps(). It takes no input but simply creates seven
[128]25/// <tt>.eps</tt> files demonstrating the capability of \ref
[206]26/// graphToEps(), and showing how to draw directed graphs,
[128]27/// how to handle parallel egdes, how to change the properties (like
28/// color, shape, size, title etc.) of nodes and arcs individually
[313]29/// using appropriate graph maps.
[128]30///
31/// \include graph_to_eps_demo.cc
32
33#include<lemon/list_graph.h>
[206]34#include<lemon/graph_to_eps.h>
35#include<lemon/math.h>
[128]36
37using namespace std;
38using namespace lemon;
39
40int main()
41{
42  Palette palette;
[129]43  Palette paletteW(true);
[128]44
[206]45  // Create a small digraph
[128]46  ListDigraph g;
47  typedef ListDigraph::Node Node;
48  typedef ListDigraph::NodeIt NodeIt;
49  typedef ListDigraph::Arc Arc;
50  typedef dim2::Point<int> Point;
[209]51
[128]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  ListDigraph::NodeMap<Point> coords(g);
59  ListDigraph::NodeMap<double> sizes(g);
60  ListDigraph::NodeMap<int> colors(g);
61  ListDigraph::NodeMap<int> shapes(g);
[206]62  ListDigraph::ArcMap<int> acolors(g);
[128]63  ListDigraph::ArcMap<int> widths(g);
[209]64
[128]65  coords[n1]=Point(50,50);  sizes[n1]=1; colors[n1]=1; shapes[n1]=0;
66  coords[n2]=Point(50,70);  sizes[n2]=2; colors[n2]=2; shapes[n2]=2;
67  coords[n3]=Point(70,70);  sizes[n3]=1; colors[n3]=3; shapes[n3]=0;
68  coords[n4]=Point(70,50);  sizes[n4]=2; colors[n4]=4; shapes[n4]=1;
69  coords[n5]=Point(85,60);  sizes[n5]=3; colors[n5]=5; shapes[n5]=2;
[209]70
[206]71  Arc a;
[128]72
[206]73  a=g.addArc(n1,n2); acolors[a]=0; widths[a]=1;
74  a=g.addArc(n2,n3); acolors[a]=0; widths[a]=1;
75  a=g.addArc(n3,n5); acolors[a]=0; widths[a]=3;
76  a=g.addArc(n5,n4); acolors[a]=0; widths[a]=1;
77  a=g.addArc(n4,n1); acolors[a]=0; widths[a]=1;
78  a=g.addArc(n2,n4); acolors[a]=1; widths[a]=2;
79  a=g.addArc(n3,n4); acolors[a]=2; widths[a]=1;
[209]80
[128]81  IdMap<ListDigraph,Node> id(g);
82
[211]83  // Create .eps files showing the digraph with different options
[206]84  cout << "Create 'graph_to_eps_demo_out_1_pure.eps'" << endl;
85  graphToEps(g,"graph_to_eps_demo_out_1_pure.eps").
[128]86    coords(coords).
87    title("Sample .eps figure").
[440]88    copyright("(C) 2003-2009 LEMON Project").
[128]89    run();
90
[206]91  cout << "Create 'graph_to_eps_demo_out_2.eps'" << endl;
92  graphToEps(g,"graph_to_eps_demo_out_2.eps").
[128]93    coords(coords).
94    title("Sample .eps figure").
[440]95    copyright("(C) 2003-2009 LEMON Project").
[128]96    absoluteNodeSizes().absoluteArcWidths().
97    nodeScale(2).nodeSizes(sizes).
98    nodeShapes(shapes).
99    nodeColors(composeMap(palette,colors)).
[206]100    arcColors(composeMap(palette,acolors)).
[128]101    arcWidthScale(.4).arcWidths(widths).
102    nodeTexts(id).nodeTextSize(3).
103    run();
104
[206]105  cout << "Create 'graph_to_eps_demo_out_3_arr.eps'" << endl;
106  graphToEps(g,"graph_to_eps_demo_out_3_arr.eps").
[128]107    title("Sample .eps figure (with arrowheads)").
[440]108    copyright("(C) 2003-2009 LEMON Project").
[128]109    absoluteNodeSizes().absoluteArcWidths().
110    nodeColors(composeMap(palette,colors)).
111    coords(coords).
112    nodeScale(2).nodeSizes(sizes).
113    nodeShapes(shapes).
[206]114    arcColors(composeMap(palette,acolors)).
[128]115    arcWidthScale(.4).arcWidths(widths).
116    nodeTexts(id).nodeTextSize(3).
[206]117    drawArrows().arrowWidth(2).arrowLength(2).
[128]118    run();
119
[211]120  // Add more arcs to the digraph
[206]121  a=g.addArc(n1,n4); acolors[a]=2; widths[a]=1;
122  a=g.addArc(n4,n1); acolors[a]=1; widths[a]=2;
[128]123
[206]124  a=g.addArc(n1,n2); acolors[a]=1; widths[a]=1;
125  a=g.addArc(n1,n2); acolors[a]=2; widths[a]=1;
126  a=g.addArc(n1,n2); acolors[a]=3; widths[a]=1;
127  a=g.addArc(n1,n2); acolors[a]=4; widths[a]=1;
128  a=g.addArc(n1,n2); acolors[a]=5; widths[a]=1;
129  a=g.addArc(n1,n2); acolors[a]=6; widths[a]=1;
130  a=g.addArc(n1,n2); acolors[a]=7; widths[a]=1;
[128]131
[211]132  cout << "Create 'graph_to_eps_demo_out_4_par.eps'" << endl;
133  graphToEps(g,"graph_to_eps_demo_out_4_par.eps").
[128]134    title("Sample .eps figure (parallel arcs)").
[440]135    copyright("(C) 2003-2009 LEMON Project").
[128]136    absoluteNodeSizes().absoluteArcWidths().
137    nodeShapes(shapes).
138    coords(coords).
139    nodeScale(2).nodeSizes(sizes).
140    nodeColors(composeMap(palette,colors)).
[206]141    arcColors(composeMap(palette,acolors)).
[128]142    arcWidthScale(.4).arcWidths(widths).
143    nodeTexts(id).nodeTextSize(3).
144    enableParallel().parArcDist(1.5).
145    run();
[206]146
[211]147  cout << "Create 'graph_to_eps_demo_out_5_par_arr.eps'" << endl;
148  graphToEps(g,"graph_to_eps_demo_out_5_par_arr.eps").
[128]149    title("Sample .eps figure (parallel arcs and arrowheads)").
[440]150    copyright("(C) 2003-2009 LEMON Project").
[128]151    absoluteNodeSizes().absoluteArcWidths().
152    nodeScale(2).nodeSizes(sizes).
153    coords(coords).
154    nodeShapes(shapes).
155    nodeColors(composeMap(palette,colors)).
[206]156    arcColors(composeMap(palette,acolors)).
[128]157    arcWidthScale(.3).arcWidths(widths).
158    nodeTexts(id).nodeTextSize(3).
159    enableParallel().parArcDist(1).
160    drawArrows().arrowWidth(1).arrowLength(1).
161    run();
162
[211]163  cout << "Create 'graph_to_eps_demo_out_6_par_arr_a4.eps'" << endl;
164  graphToEps(g,"graph_to_eps_demo_out_6_par_arr_a4.eps").
[128]165    title("Sample .eps figure (fits to A4)").
[440]166    copyright("(C) 2003-2009 LEMON Project").
[206]167    scaleToA4().
[128]168    absoluteNodeSizes().absoluteArcWidths().
169    nodeScale(2).nodeSizes(sizes).
170    coords(coords).
171    nodeShapes(shapes).
172    nodeColors(composeMap(palette,colors)).
[206]173    arcColors(composeMap(palette,acolors)).
[128]174    arcWidthScale(.3).arcWidths(widths).
175    nodeTexts(id).nodeTextSize(3).
176    enableParallel().parArcDist(1).
177    drawArrows().arrowWidth(1).arrowLength(1).
178    run();
179
[206]180  // Create an .eps file showing the colors of a default Palette
[128]181  ListDigraph h;
182  ListDigraph::NodeMap<int> hcolors(h);
183  ListDigraph::NodeMap<Point> hcoords(h);
[209]184
[612]185  int cols=int(std::sqrt(double(palette.size())));
[128]186  for(int i=0;i<int(paletteW.size());i++) {
187    Node n=h.addNode();
[206]188    hcoords[n]=Point(1+i%cols,1+i/cols);
[128]189    hcolors[n]=i;
190  }
[209]191
[211]192  cout << "Create 'graph_to_eps_demo_out_7_colors.eps'" << endl;
193  graphToEps(h,"graph_to_eps_demo_out_7_colors.eps").
[206]194    scale(60).
[128]195    title("Sample .eps figure (Palette demo)").
[440]196    copyright("(C) 2003-2009 LEMON Project").
[128]197    coords(hcoords).
198    absoluteNodeSizes().absoluteArcWidths().
[132]199    nodeScale(.45).
[128]200    distantColorNodeTexts().
201    nodeTexts(hcolors).nodeTextSize(.6).
202    nodeColors(composeMap(paletteW,hcolors)).
203    run();
[209]204
[206]205  return 0;
[128]206}
Note: See TracBrowser for help on using the repository browser.