| 1 | /* -*- C++ -*- | 
|---|
| 2 |  * demo/graph_to_eps.cc - Part of LEMON, a generic C++ optimization library | 
|---|
| 3 |  * | 
|---|
| 4 |  * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport | 
|---|
| 5 |  * (Egervary Research Group on Combinatorial Optimization, EGRES). | 
|---|
| 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 |  | 
|---|
| 17 | #include<lemon/graph_to_eps.h> | 
|---|
| 18 | #include<lemon/maps.h> | 
|---|
| 19 | #include<lemon/list_graph.h> | 
|---|
| 20 | #include<lemon/graph_utils.h> | 
|---|
| 21 |  | 
|---|
| 22 | #include <cmath> | 
|---|
| 23 |  | 
|---|
| 24 |  | 
|---|
| 25 | using namespace std; | 
|---|
| 26 | using namespace lemon; | 
|---|
| 27 |  | 
|---|
| 28 | int main() | 
|---|
| 29 | { | 
|---|
| 30 |   ColorSet colorSet; | 
|---|
| 31 |  | 
|---|
| 32 |   ListGraph g; | 
|---|
| 33 |   typedef ListGraph::Node Node; | 
|---|
| 34 |   typedef ListGraph::NodeIt NodeIt; | 
|---|
| 35 |   typedef ListGraph::Edge Edge; | 
|---|
| 36 |   typedef xy<int> Xy; | 
|---|
| 37 |    | 
|---|
| 38 |   Node n1=g.addNode(); | 
|---|
| 39 |   Node n2=g.addNode(); | 
|---|
| 40 |   Node n3=g.addNode(); | 
|---|
| 41 |   Node n4=g.addNode(); | 
|---|
| 42 |   Node n5=g.addNode(); | 
|---|
| 43 |  | 
|---|
| 44 |   ListGraph::NodeMap<Xy> coords(g); | 
|---|
| 45 |   ListGraph::NodeMap<double> sizes(g); | 
|---|
| 46 |   ListGraph::NodeMap<int> colors(g); | 
|---|
| 47 |   ListGraph::NodeMap<int> shapes(g); | 
|---|
| 48 |   ListGraph::EdgeMap<int> ecolors(g); | 
|---|
| 49 |   ListGraph::EdgeMap<int> widths(g); | 
|---|
| 50 |    | 
|---|
| 51 |   coords[n1]=Xy(50,50);  sizes[n1]=1; colors[n1]=1; shapes[n1]=0; | 
|---|
| 52 |   coords[n2]=Xy(50,70);  sizes[n2]=2; colors[n2]=2; shapes[n2]=2; | 
|---|
| 53 |   coords[n3]=Xy(70,70);  sizes[n3]=1; colors[n3]=3; shapes[n3]=0; | 
|---|
| 54 |   coords[n4]=Xy(70,50);  sizes[n4]=2; colors[n4]=4; shapes[n4]=1; | 
|---|
| 55 |   coords[n5]=Xy(85,60);  sizes[n5]=3; colors[n5]=5; shapes[n5]=2; | 
|---|
| 56 |    | 
|---|
| 57 |   Edge e; | 
|---|
| 58 |  | 
|---|
| 59 |   e=g.addEdge(n1,n2); ecolors[e]=0; widths[e]=1; | 
|---|
| 60 |   e=g.addEdge(n2,n3); ecolors[e]=0; widths[e]=1; | 
|---|
| 61 |   e=g.addEdge(n3,n5); ecolors[e]=0; widths[e]=3; | 
|---|
| 62 |   e=g.addEdge(n5,n4); ecolors[e]=0; widths[e]=1; | 
|---|
| 63 |   e=g.addEdge(n4,n1); ecolors[e]=0; widths[e]=1; | 
|---|
| 64 |   e=g.addEdge(n2,n4); ecolors[e]=1; widths[e]=2; | 
|---|
| 65 |   e=g.addEdge(n3,n4); ecolors[e]=2; widths[e]=1; | 
|---|
| 66 |    | 
|---|
| 67 |   IdMap<ListGraph,Node> id(g); | 
|---|
| 68 |  | 
|---|
| 69 |   graphToEps(g,"graph_to_eps_demo_out.eps").scale(10).coords(coords). | 
|---|
| 70 |     title("Sample .eps figure"). | 
|---|
| 71 |     copyright("(C) 2005 LEMON Project"). | 
|---|
| 72 |     nodeScale(2).nodeSizes(sizes). | 
|---|
| 73 |     nodeShapes(shapes). | 
|---|
| 74 |     nodeColors(composeMap(colorSet,colors)). | 
|---|
| 75 |     edgeColors(composeMap(colorSet,ecolors)). | 
|---|
| 76 |     edgeWidthScale(.4).edgeWidths(widths). | 
|---|
| 77 |     nodeTexts(id).nodeTextSize(3). | 
|---|
| 78 |     run(); | 
|---|
| 79 |  | 
|---|
| 80 |   graphToEps(g,"graph_to_eps_demo_out_arr.eps").scale(10). | 
|---|
| 81 |     title("Sample .eps figure (with arrowheads)"). | 
|---|
| 82 |     copyright("(C) 2005 LEMON Project"). | 
|---|
| 83 |     nodeColors(composeMap(colorSet,colors)). | 
|---|
| 84 |     coords(coords). | 
|---|
| 85 |     nodeScale(2).nodeSizes(sizes). | 
|---|
| 86 |     nodeShapes(shapes). | 
|---|
| 87 |     edgeColors(composeMap(colorSet,ecolors)). | 
|---|
| 88 |     edgeWidthScale(.4).edgeWidths(widths). | 
|---|
| 89 |     nodeTexts(id).nodeTextSize(3). | 
|---|
| 90 |     drawArrows().arrowWidth(1).arrowLength(1). | 
|---|
| 91 |     run(); | 
|---|
| 92 |  | 
|---|
| 93 |   e=g.addEdge(n1,n4); ecolors[e]=2; widths[e]=1; | 
|---|
| 94 |   e=g.addEdge(n4,n1); ecolors[e]=1; widths[e]=2; | 
|---|
| 95 |  | 
|---|
| 96 |   e=g.addEdge(n1,n2); ecolors[e]=1; widths[e]=1; | 
|---|
| 97 |   e=g.addEdge(n1,n2); ecolors[e]=2; widths[e]=1; | 
|---|
| 98 |   e=g.addEdge(n1,n2); ecolors[e]=3; widths[e]=1; | 
|---|
| 99 |   e=g.addEdge(n1,n2); ecolors[e]=4; widths[e]=1; | 
|---|
| 100 |   e=g.addEdge(n1,n2); ecolors[e]=5; widths[e]=1; | 
|---|
| 101 |   e=g.addEdge(n1,n2); ecolors[e]=6; widths[e]=1; | 
|---|
| 102 |   e=g.addEdge(n1,n2); ecolors[e]=7; widths[e]=1; | 
|---|
| 103 |  | 
|---|
| 104 |   graphToEps(g,"graph_to_eps_demo_out_par.eps").scale(10). | 
|---|
| 105 |     title("Sample .eps figure (parallel edges)"). | 
|---|
| 106 |     copyright("(C) 2005 LEMON Project"). | 
|---|
| 107 |     nodeShapes(shapes). | 
|---|
| 108 |     coords(coords). | 
|---|
| 109 |     nodeScale(2).nodeSizes(sizes). | 
|---|
| 110 |     nodeColors(composeMap(colorSet,colors)). | 
|---|
| 111 |     edgeColors(composeMap(colorSet,ecolors)). | 
|---|
| 112 |     edgeWidthScale(.4).edgeWidths(widths). | 
|---|
| 113 |     nodeTexts(id).nodeTextSize(3). | 
|---|
| 114 |     enableParallel().parEdgeDist(1.5). | 
|---|
| 115 |     run(); | 
|---|
| 116 |    | 
|---|
| 117 |   graphToEps(g,"graph_to_eps_demo_out_par_arr.eps").scale(10). | 
|---|
| 118 |     title("Sample .eps figure (parallel edges and arrowheads)"). | 
|---|
| 119 |     copyright("(C) 2005 LEMON Project"). | 
|---|
| 120 |     nodeScale(2).nodeSizes(sizes). | 
|---|
| 121 |     coords(coords). | 
|---|
| 122 |     nodeShapes(shapes). | 
|---|
| 123 |     nodeColors(composeMap(colorSet,colors)). | 
|---|
| 124 |     edgeColors(composeMap(colorSet,ecolors)). | 
|---|
| 125 |     edgeWidthScale(.3).edgeWidths(widths). | 
|---|
| 126 |     nodeTexts(id).nodeTextSize(3). | 
|---|
| 127 |     enableParallel().parEdgeDist(1). | 
|---|
| 128 |     drawArrows().arrowWidth(1).arrowLength(1). | 
|---|
| 129 |     run(); | 
|---|
| 130 |  | 
|---|
| 131 |   graphToEps(g,"graph_to_eps_demo_out_a4.eps").scaleToA4(). | 
|---|
| 132 |     title("Sample .eps figure (fits to A4)"). | 
|---|
| 133 |     copyright("(C) 2005 LEMON Project"). | 
|---|
| 134 |     nodeScale(2).nodeSizes(sizes). | 
|---|
| 135 |     coords(coords). | 
|---|
| 136 |     nodeShapes(shapes). | 
|---|
| 137 |     nodeColors(composeMap(colorSet,colors)). | 
|---|
| 138 |     edgeColors(composeMap(colorSet,ecolors)). | 
|---|
| 139 |     edgeWidthScale(.3).edgeWidths(widths). | 
|---|
| 140 |     nodeTexts(id).nodeTextSize(3). | 
|---|
| 141 |     enableParallel().parEdgeDist(1). | 
|---|
| 142 |     drawArrows().arrowWidth(1).arrowLength(1). | 
|---|
| 143 |     run(); | 
|---|
| 144 |  | 
|---|
| 145 |   ListGraph h; | 
|---|
| 146 |   ListGraph::NodeMap<int> hcolors(h); | 
|---|
| 147 |   ListGraph::NodeMap<Xy> hcoords(h); | 
|---|
| 148 |    | 
|---|
| 149 |   int cols=int(sqrt(double(colorSet.size()))); | 
|---|
| 150 |   for(int i=0;i<int(colorSet.size());i++) { | 
|---|
| 151 |     Node n=h.addNode(); | 
|---|
| 152 |     hcoords[n]=Xy(i%cols,i/cols); | 
|---|
| 153 |     hcolors[n]=i; | 
|---|
| 154 |   } | 
|---|
| 155 |    | 
|---|
| 156 |   graphToEps(h,"graph_to_eps_demo_out_colors.eps").scale(60). | 
|---|
| 157 |     title("Sample .eps figure (parallel edges and arrowheads)"). | 
|---|
| 158 |     copyright("(C) 2005 LEMON Project"). | 
|---|
| 159 |     coords(hcoords). | 
|---|
| 160 |     nodeScale(.45). | 
|---|
| 161 |     distantColorNodeTexts(). | 
|---|
| 162 |     //    distantBWNodeTexts(). | 
|---|
| 163 |     nodeTexts(hcolors).nodeTextSize(.6). | 
|---|
| 164 |     nodeColors(composeMap(colorSet,hcolors)). | 
|---|
| 165 |     run(); | 
|---|
| 166 |  | 
|---|
| 167 |  | 
|---|
| 168 | } | 
|---|