src/demo/graph_to_eps_demo.cc
changeset 1073 bedab8bd915f
child 1086 caa13d291528
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/demo/graph_to_eps_demo.cc	Tue Jan 11 09:15:25 2005 +0000
     1.3 @@ -0,0 +1,133 @@
     1.4 +/* -*- C++ -*-
     1.5 + * src/lemon/demo/graph_to_eps.cc - 
     1.6 + * Part of LEMON, a generic C++ optimization library
     1.7 + *
     1.8 + * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     1.9 + * (Egervary Combinatorial Optimization Research Group, EGRES).
    1.10 + *
    1.11 + * Permission to use, modify and distribute this software is granted
    1.12 + * provided that this copyright notice appears in all copies. For
    1.13 + * precise terms see the accompanying LICENSE file.
    1.14 + *
    1.15 + * This software is provided "AS IS" with no warranty of any kind,
    1.16 + * express or implied, and with no claim as to its suitability for any
    1.17 + * purpose.
    1.18 + *
    1.19 + */
    1.20 +
    1.21 +#include<lemon/graph_to_eps.h>
    1.22 +#include<lemon/maps.h>
    1.23 +#include<lemon/list_graph.h>
    1.24 +
    1.25 +
    1.26 +using namespace std;
    1.27 +using namespace lemon;
    1.28 +
    1.29 +class ColorSet : public MapBase<int,Color>
    1.30 +{
    1.31 +public:
    1.32 +  Color operator[](int i) const
    1.33 +  {
    1.34 +    switch(i%8){
    1.35 +    case 0: return Color(0,0,0);
    1.36 +    case 1: return Color(1,0,0);
    1.37 +    case 2: return Color(0,1,0);
    1.38 +    case 3: return Color(0,0,1);
    1.39 +    case 4: return Color(1,1,0);
    1.40 +    case 5: return Color(1,0,1);
    1.41 +    case 6: return Color(0,1,1);
    1.42 +    case 7: return Color(1,1,1);
    1.43 +    }
    1.44 +    return Color(0,0,0);
    1.45 +  }
    1.46 +} colorSet;
    1.47 +
    1.48 +class IdMap :public MapBase<ListGraph::Node,int>
    1.49 +{
    1.50 +  const ListGraph &g;
    1.51 +public:
    1.52 +  IdMap(const ListGraph &_g) :g(_g) {}
    1.53 +  Value operator[](Key n) const { return g.id(n); }
    1.54 +};
    1.55 +
    1.56 +int main()
    1.57 +{
    1.58 +  ListGraph g;
    1.59 +  typedef ListGraph::Node Node;
    1.60 +  typedef ListGraph::NodeIt NodeIt;
    1.61 +  typedef ListGraph::Edge Edge;
    1.62 +  typedef xy<int> Xy;
    1.63 +  
    1.64 +  Node n1=g.addNode();
    1.65 +  Node n2=g.addNode();
    1.66 +  Node n3=g.addNode();
    1.67 +  Node n4=g.addNode();
    1.68 +  Node n5=g.addNode();
    1.69 +
    1.70 +  ListGraph::NodeMap<Xy> coords(g);
    1.71 +  ListGraph::NodeMap<double> sizes(g);
    1.72 +  ListGraph::NodeMap<int> colors(g);
    1.73 +  ListGraph::EdgeMap<int> ecolors(g);
    1.74 +  ListGraph::EdgeMap<int> widths(g);
    1.75 +  
    1.76 +  coords[n1]=Xy(50,50);  sizes[n1]=1; colors[n1]=1;
    1.77 +  coords[n2]=Xy(50,70);  sizes[n2]=2; colors[n2]=2;
    1.78 +  coords[n3]=Xy(70,70);  sizes[n3]=1; colors[n3]=3;
    1.79 +  coords[n4]=Xy(70,50);  sizes[n4]=2; colors[n4]=4;
    1.80 +  coords[n5]=Xy(85,60);  sizes[n5]=3; colors[n5]=5;
    1.81 +  
    1.82 +  Edge e;
    1.83 +
    1.84 +  e=g.addEdge(n1,n2); ecolors[e]=0; widths[e]=1;
    1.85 +  e=g.addEdge(n2,n3); ecolors[e]=0; widths[e]=1;
    1.86 +  e=g.addEdge(n3,n5); ecolors[e]=0; widths[e]=3;
    1.87 +  e=g.addEdge(n5,n4); ecolors[e]=0; widths[e]=1;
    1.88 +  e=g.addEdge(n4,n1); ecolors[e]=0; widths[e]=1;
    1.89 +  e=g.addEdge(n2,n4); ecolors[e]=1; widths[e]=2;
    1.90 +  e=g.addEdge(n3,n4); ecolors[e]=2; widths[e]=1;
    1.91 +  
    1.92 +  IdMap id(g);
    1.93 +
    1.94 +  graphToEps(g,"graph_to_eps_demo_out.eps").scale(10).coords(coords).
    1.95 +    nodeScale(2).nodeSizes(sizes).
    1.96 +    nodeColors(composeMap(colorSet,colors)).
    1.97 +    edgeColors(composeMap(colorSet,ecolors)).
    1.98 +    edgeWidthScale(.4).edgeWidths(widths).
    1.99 +    nodeTexts(id).nodeTextSize(3);
   1.100 +
   1.101 +  graphToEps(g,"graph_to_eps_demo_out_arr.eps").scale(10).coords(coords).
   1.102 +    nodeScale(2).nodeSizes(sizes).
   1.103 +    nodeColors(composeMap(colorSet,colors)).
   1.104 +    edgeColors(composeMap(colorSet,ecolors)).
   1.105 +    edgeWidthScale(.4).edgeWidths(widths).
   1.106 +    nodeTexts(id).nodeTextSize(3).
   1.107 +    drawArrows().arrowWidth(1).arrowLength(1);
   1.108 +
   1.109 +  e=g.addEdge(n1,n4); ecolors[e]=2; widths[e]=1;
   1.110 +  e=g.addEdge(n4,n1); ecolors[e]=1; widths[e]=2;
   1.111 +
   1.112 +  e=g.addEdge(n1,n2); ecolors[e]=1; widths[e]=1;
   1.113 +  e=g.addEdge(n1,n2); ecolors[e]=2; widths[e]=1;
   1.114 +  e=g.addEdge(n1,n2); ecolors[e]=3; widths[e]=1;
   1.115 +  e=g.addEdge(n1,n2); ecolors[e]=4; widths[e]=1;
   1.116 +  e=g.addEdge(n1,n2); ecolors[e]=5; widths[e]=1;
   1.117 +  e=g.addEdge(n1,n2); ecolors[e]=6; widths[e]=1;
   1.118 +  e=g.addEdge(n1,n2); ecolors[e]=7; widths[e]=1;
   1.119 +
   1.120 +  graphToEps(g,"graph_to_eps_demo_out_par.eps").scale(10).coords(coords).
   1.121 +    nodeScale(2).nodeSizes(sizes).
   1.122 +    nodeColors(composeMap(colorSet,colors)).
   1.123 +    edgeColors(composeMap(colorSet,ecolors)).
   1.124 +    edgeWidthScale(.4).edgeWidths(widths).
   1.125 +    nodeTexts(id).nodeTextSize(3).
   1.126 +    enableParallel().parEdgeDist(1.5);
   1.127 +
   1.128 +  graphToEps(g,"graph_to_eps_demo_out_par_arr.eps").scale(10).coords(coords).
   1.129 +    nodeScale(2).nodeSizes(sizes).
   1.130 +    nodeColors(composeMap(colorSet,colors)).
   1.131 +    edgeColors(composeMap(colorSet,ecolors)).
   1.132 +    edgeWidthScale(.3).edgeWidths(widths).
   1.133 +    nodeTexts(id).nodeTextSize(3).
   1.134 +    enableParallel().parEdgeDist(1).
   1.135 +    drawArrows().arrowWidth(1).arrowLength(1);
   1.136 +}