| [1073] | 1 | /* -*- C++ -*- | 
|---|
|  | 2 | * | 
|---|
| [1956] | 3 | * This file is a part of LEMON, a generic C++ optimization library | 
|---|
|  | 4 | * | 
|---|
|  | 5 | * Copyright (C) 2003-2006 | 
|---|
|  | 6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport | 
|---|
| [1359] | 7 | * (Egervary Research Group on Combinatorial Optimization, EGRES). | 
|---|
| [1073] | 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 |  | 
|---|
| [1573] | 19 | /// \ingroup demos | 
|---|
|  | 20 | /// \file | 
|---|
|  | 21 | /// \brief Demo of the graph grawing function \ref graphToEps() | 
|---|
|  | 22 | /// | 
|---|
|  | 23 | /// This demo program shows examples how to  use the function \ref | 
|---|
|  | 24 | /// graphToEps(). It takes no input but simply creates  six | 
|---|
| [1587] | 25 | /// <tt>.eps</tt> files demonstrating the capability of \ref | 
|---|
|  | 26 | /// graphToEps(), and showing how to draw directed/undirected graphs, | 
|---|
|  | 27 | /// how to handle parallel egdes, how to change the properties (like | 
|---|
|  | 28 | /// color, shape, size, title etc.) of nodes and edges individually | 
|---|
| [1630] | 29 | /// using appropriate \ref maps-page "graph maps". | 
|---|
| [1641] | 30 | /// | 
|---|
|  | 31 | /// \include graph_to_eps_demo.cc | 
|---|
| [1073] | 32 |  | 
|---|
| [1417] | 33 | #include <cmath> | 
|---|
|  | 34 |  | 
|---|
| [1573] | 35 | #include<lemon/graph_to_eps.h> | 
|---|
|  | 36 | #include<lemon/list_graph.h> | 
|---|
| [1802] | 37 | #include<lemon/graph_utils.h> | 
|---|
| [1073] | 38 |  | 
|---|
|  | 39 | using namespace std; | 
|---|
|  | 40 | using namespace lemon; | 
|---|
|  | 41 |  | 
|---|
|  | 42 | int main() | 
|---|
|  | 43 | { | 
|---|
| [2172] | 44 | Palette palette; | 
|---|
| [2178] | 45 | Palette paletteW(true); | 
|---|
| [1178] | 46 |  | 
|---|
| [1073] | 47 | ListGraph g; | 
|---|
|  | 48 | typedef ListGraph::Node Node; | 
|---|
|  | 49 | typedef ListGraph::NodeIt NodeIt; | 
|---|
|  | 50 | typedef ListGraph::Edge Edge; | 
|---|
| [2207] | 51 | typedef dim2::Point<int> Point; | 
|---|
| [1073] | 52 |  | 
|---|
|  | 53 | Node n1=g.addNode(); | 
|---|
|  | 54 | Node n2=g.addNode(); | 
|---|
|  | 55 | Node n3=g.addNode(); | 
|---|
|  | 56 | Node n4=g.addNode(); | 
|---|
|  | 57 | Node n5=g.addNode(); | 
|---|
|  | 58 |  | 
|---|
| [2207] | 59 | ListGraph::NodeMap<Point> coords(g); | 
|---|
| [1073] | 60 | ListGraph::NodeMap<double> sizes(g); | 
|---|
|  | 61 | ListGraph::NodeMap<int> colors(g); | 
|---|
| [1086] | 62 | ListGraph::NodeMap<int> shapes(g); | 
|---|
| [1073] | 63 | ListGraph::EdgeMap<int> ecolors(g); | 
|---|
|  | 64 | ListGraph::EdgeMap<int> widths(g); | 
|---|
|  | 65 |  | 
|---|
| [2207] | 66 | coords[n1]=Point(50,50);  sizes[n1]=1; colors[n1]=1; shapes[n1]=0; | 
|---|
|  | 67 | coords[n2]=Point(50,70);  sizes[n2]=2; colors[n2]=2; shapes[n2]=2; | 
|---|
|  | 68 | coords[n3]=Point(70,70);  sizes[n3]=1; colors[n3]=3; shapes[n3]=0; | 
|---|
|  | 69 | coords[n4]=Point(70,50);  sizes[n4]=2; colors[n4]=4; shapes[n4]=1; | 
|---|
|  | 70 | coords[n5]=Point(85,60);  sizes[n5]=3; colors[n5]=5; shapes[n5]=2; | 
|---|
| [1073] | 71 |  | 
|---|
|  | 72 | Edge e; | 
|---|
|  | 73 |  | 
|---|
|  | 74 | e=g.addEdge(n1,n2); ecolors[e]=0; widths[e]=1; | 
|---|
|  | 75 | e=g.addEdge(n2,n3); ecolors[e]=0; widths[e]=1; | 
|---|
|  | 76 | e=g.addEdge(n3,n5); ecolors[e]=0; widths[e]=3; | 
|---|
|  | 77 | e=g.addEdge(n5,n4); ecolors[e]=0; widths[e]=1; | 
|---|
|  | 78 | e=g.addEdge(n4,n1); ecolors[e]=0; widths[e]=1; | 
|---|
|  | 79 | e=g.addEdge(n2,n4); ecolors[e]=1; widths[e]=2; | 
|---|
|  | 80 | e=g.addEdge(n3,n4); ecolors[e]=2; widths[e]=1; | 
|---|
|  | 81 |  | 
|---|
| [1268] | 82 | IdMap<ListGraph,Node> id(g); | 
|---|
| [1073] | 83 |  | 
|---|
| [2178] | 84 | cout << "Create 'graph_to_eps_demo_out_pure.eps'" << endl; | 
|---|
|  | 85 | graphToEps(g,"graph_to_eps_demo_out_pure.eps"). | 
|---|
|  | 86 | //scale(10). | 
|---|
|  | 87 | coords(coords). | 
|---|
|  | 88 | title("Sample .eps figure"). | 
|---|
|  | 89 | copyright("(C) 2006 LEMON Project"). | 
|---|
|  | 90 | run(); | 
|---|
|  | 91 |  | 
|---|
| [1573] | 92 | cout << "Create 'graph_to_eps_demo_out.eps'" << endl; | 
|---|
| [1930] | 93 | graphToEps(g,"graph_to_eps_demo_out.eps"). | 
|---|
|  | 94 | //scale(10). | 
|---|
|  | 95 | coords(coords). | 
|---|
| [1108] | 96 | title("Sample .eps figure"). | 
|---|
| [1875] | 97 | copyright("(C) 2006 LEMON Project"). | 
|---|
| [2178] | 98 | absoluteNodeSizes().absoluteEdgeWidths(). | 
|---|
| [1073] | 99 | nodeScale(2).nodeSizes(sizes). | 
|---|
| [1086] | 100 | nodeShapes(shapes). | 
|---|
| [2172] | 101 | nodeColors(composeMap(palette,colors)). | 
|---|
|  | 102 | edgeColors(composeMap(palette,ecolors)). | 
|---|
| [1073] | 103 | edgeWidthScale(.4).edgeWidths(widths). | 
|---|
| [1091] | 104 | nodeTexts(id).nodeTextSize(3). | 
|---|
|  | 105 | run(); | 
|---|
| [1073] | 106 |  | 
|---|
| [1573] | 107 |  | 
|---|
|  | 108 | cout << "Create 'graph_to_eps_demo_out_arr.eps'" << endl; | 
|---|
| [1930] | 109 | graphToEps(g,"graph_to_eps_demo_out_arr.eps"). | 
|---|
|  | 110 | //scale(10). | 
|---|
| [1108] | 111 | title("Sample .eps figure (with arrowheads)"). | 
|---|
| [1875] | 112 | copyright("(C) 2006 LEMON Project"). | 
|---|
| [2178] | 113 | absoluteNodeSizes().absoluteEdgeWidths(). | 
|---|
| [2172] | 114 | nodeColors(composeMap(palette,colors)). | 
|---|
| [1091] | 115 | coords(coords). | 
|---|
| [1073] | 116 | nodeScale(2).nodeSizes(sizes). | 
|---|
| [1086] | 117 | nodeShapes(shapes). | 
|---|
| [2172] | 118 | edgeColors(composeMap(palette,ecolors)). | 
|---|
| [1073] | 119 | edgeWidthScale(.4).edgeWidths(widths). | 
|---|
|  | 120 | nodeTexts(id).nodeTextSize(3). | 
|---|
| [1091] | 121 | drawArrows().arrowWidth(1).arrowLength(1). | 
|---|
|  | 122 | run(); | 
|---|
| [1073] | 123 |  | 
|---|
|  | 124 | e=g.addEdge(n1,n4); ecolors[e]=2; widths[e]=1; | 
|---|
|  | 125 | e=g.addEdge(n4,n1); ecolors[e]=1; widths[e]=2; | 
|---|
|  | 126 |  | 
|---|
|  | 127 | e=g.addEdge(n1,n2); ecolors[e]=1; widths[e]=1; | 
|---|
|  | 128 | e=g.addEdge(n1,n2); ecolors[e]=2; widths[e]=1; | 
|---|
|  | 129 | e=g.addEdge(n1,n2); ecolors[e]=3; widths[e]=1; | 
|---|
|  | 130 | e=g.addEdge(n1,n2); ecolors[e]=4; widths[e]=1; | 
|---|
|  | 131 | e=g.addEdge(n1,n2); ecolors[e]=5; widths[e]=1; | 
|---|
|  | 132 | e=g.addEdge(n1,n2); ecolors[e]=6; widths[e]=1; | 
|---|
|  | 133 | e=g.addEdge(n1,n2); ecolors[e]=7; widths[e]=1; | 
|---|
|  | 134 |  | 
|---|
| [1573] | 135 | cout << "Create 'graph_to_eps_demo_out_par.eps'" << endl; | 
|---|
| [1930] | 136 | graphToEps(g,"graph_to_eps_demo_out_par.eps"). | 
|---|
|  | 137 | //scale(10). | 
|---|
| [1108] | 138 | title("Sample .eps figure (parallel edges)"). | 
|---|
| [1875] | 139 | copyright("(C) 2006 LEMON Project"). | 
|---|
| [2178] | 140 | absoluteNodeSizes().absoluteEdgeWidths(). | 
|---|
| [1091] | 141 | nodeShapes(shapes). | 
|---|
|  | 142 | coords(coords). | 
|---|
| [1073] | 143 | nodeScale(2).nodeSizes(sizes). | 
|---|
| [2172] | 144 | nodeColors(composeMap(palette,colors)). | 
|---|
|  | 145 | edgeColors(composeMap(palette,ecolors)). | 
|---|
| [1073] | 146 | edgeWidthScale(.4).edgeWidths(widths). | 
|---|
|  | 147 | nodeTexts(id).nodeTextSize(3). | 
|---|
| [1091] | 148 | enableParallel().parEdgeDist(1.5). | 
|---|
|  | 149 | run(); | 
|---|
|  | 150 |  | 
|---|
| [1573] | 151 | cout << "Create 'graph_to_eps_demo_out_par_arr.eps'" << endl; | 
|---|
| [1930] | 152 | graphToEps(g,"graph_to_eps_demo_out_par_arr.eps"). | 
|---|
|  | 153 | //scale(10). | 
|---|
| [1108] | 154 | title("Sample .eps figure (parallel edges and arrowheads)"). | 
|---|
| [1875] | 155 | copyright("(C) 2006 LEMON Project"). | 
|---|
| [2178] | 156 | absoluteNodeSizes().absoluteEdgeWidths(). | 
|---|
| [1073] | 157 | nodeScale(2).nodeSizes(sizes). | 
|---|
| [1091] | 158 | coords(coords). | 
|---|
| [1086] | 159 | nodeShapes(shapes). | 
|---|
| [2172] | 160 | nodeColors(composeMap(palette,colors)). | 
|---|
|  | 161 | edgeColors(composeMap(palette,ecolors)). | 
|---|
| [1073] | 162 | edgeWidthScale(.3).edgeWidths(widths). | 
|---|
|  | 163 | nodeTexts(id).nodeTextSize(3). | 
|---|
|  | 164 | enableParallel().parEdgeDist(1). | 
|---|
| [1091] | 165 | drawArrows().arrowWidth(1).arrowLength(1). | 
|---|
| [1103] | 166 | run(); | 
|---|
|  | 167 |  | 
|---|
| [1573] | 168 | cout << "Create 'graph_to_eps_demo_out_a4.eps'" << endl; | 
|---|
| [1103] | 169 | graphToEps(g,"graph_to_eps_demo_out_a4.eps").scaleToA4(). | 
|---|
| [1108] | 170 | title("Sample .eps figure (fits to A4)"). | 
|---|
| [1875] | 171 | copyright("(C) 2006 LEMON Project"). | 
|---|
| [2178] | 172 | absoluteNodeSizes().absoluteEdgeWidths(). | 
|---|
| [1103] | 173 | nodeScale(2).nodeSizes(sizes). | 
|---|
|  | 174 | coords(coords). | 
|---|
|  | 175 | nodeShapes(shapes). | 
|---|
| [2172] | 176 | nodeColors(composeMap(palette,colors)). | 
|---|
|  | 177 | edgeColors(composeMap(palette,ecolors)). | 
|---|
| [1103] | 178 | edgeWidthScale(.3).edgeWidths(widths). | 
|---|
|  | 179 | nodeTexts(id).nodeTextSize(3). | 
|---|
|  | 180 | enableParallel().parEdgeDist(1). | 
|---|
|  | 181 | drawArrows().arrowWidth(1).arrowLength(1). | 
|---|
|  | 182 | run(); | 
|---|
|  | 183 |  | 
|---|
| [1178] | 184 | ListGraph h; | 
|---|
|  | 185 | ListGraph::NodeMap<int> hcolors(h); | 
|---|
| [2207] | 186 | ListGraph::NodeMap<Point> hcoords(h); | 
|---|
| [1178] | 187 |  | 
|---|
| [2172] | 188 | int cols=int(sqrt(double(palette.size()))); | 
|---|
| [2178] | 189 | for(int i=0;i<int(paletteW.size());i++) { | 
|---|
| [1178] | 190 | Node n=h.addNode(); | 
|---|
| [2207] | 191 | hcoords[n]=Point(i%cols,i/cols); | 
|---|
| [1178] | 192 | hcolors[n]=i; | 
|---|
|  | 193 | } | 
|---|
|  | 194 |  | 
|---|
| [1573] | 195 | cout << "Create 'graph_to_eps_demo_out_colors.eps'" << endl; | 
|---|
| [1930] | 196 | graphToEps(h,"graph_to_eps_demo_out_colors.eps"). | 
|---|
|  | 197 | //scale(60). | 
|---|
| [2172] | 198 | title("Sample .eps figure (Palette demo)"). | 
|---|
| [1875] | 199 | copyright("(C) 2006 LEMON Project"). | 
|---|
| [1178] | 200 | coords(hcoords). | 
|---|
| [2178] | 201 | absoluteNodeSizes().absoluteEdgeWidths(). | 
|---|
|  | 202 | nodeScale(45). | 
|---|
| [1178] | 203 | distantColorNodeTexts(). | 
|---|
|  | 204 | //    distantBWNodeTexts(). | 
|---|
|  | 205 | nodeTexts(hcolors).nodeTextSize(.6). | 
|---|
| [2178] | 206 | nodeColors(composeMap(paletteW,hcolors)). | 
|---|
| [1178] | 207 | run(); | 
|---|
| [1073] | 208 | } | 
|---|