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