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