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