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