COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/demo/graph_to_eps_demo.cc @ 1173:099978eee03f

Last change on this file since 1173:099978eee03f was 1164:80bb73097736, checked in by Alpar Juttner, 19 years ago

A year has passed again.

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