src/demo/graph_to_eps_demo.cc
author alpar
Fri, 08 Apr 2005 15:46:12 +0000
changeset 1329 1bfaec33215b
parent 1178 3c176c65d33b
child 1359 1581f961cfaa
permissions -rw-r--r--
- Insert LP stuff into the module structure
     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 #include<lemon/graph_utils.h>
    22 
    23 
    24 using namespace std;
    25 using namespace lemon;
    26 
    27 int main()
    28 {
    29   ColorSet colorSet;
    30 
    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);
    46   ListGraph::NodeMap<int> shapes(g);
    47   ListGraph::EdgeMap<int> ecolors(g);
    48   ListGraph::EdgeMap<int> widths(g);
    49   
    50   coords[n1]=Xy(50,50);  sizes[n1]=1; colors[n1]=1; shapes[n1]=0;
    51   coords[n2]=Xy(50,70);  sizes[n2]=2; colors[n2]=2; shapes[n2]=2;
    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;
    54   coords[n5]=Xy(85,60);  sizes[n5]=3; colors[n5]=5; shapes[n5]=2;
    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   
    66   IdMap<ListGraph,Node> id(g);
    67 
    68   graphToEps(g,"graph_to_eps_demo_out.eps").scale(10).coords(coords).
    69     title("Sample .eps figure").
    70     copyright("(C) 2005 LEMON Project").
    71     nodeScale(2).nodeSizes(sizes).
    72     nodeShapes(shapes).
    73     nodeColors(composeMap(colorSet,colors)).
    74     edgeColors(composeMap(colorSet,ecolors)).
    75     edgeWidthScale(.4).edgeWidths(widths).
    76     nodeTexts(id).nodeTextSize(3).
    77     run();
    78 
    79   graphToEps(g,"graph_to_eps_demo_out_arr.eps").scale(10).
    80     title("Sample .eps figure (with arrowheads)").
    81     copyright("(C) 2005 LEMON Project").
    82     nodeColors(composeMap(colorSet,colors)).
    83     coords(coords).
    84     nodeScale(2).nodeSizes(sizes).
    85     nodeShapes(shapes).
    86     edgeColors(composeMap(colorSet,ecolors)).
    87     edgeWidthScale(.4).edgeWidths(widths).
    88     nodeTexts(id).nodeTextSize(3).
    89     drawArrows().arrowWidth(1).arrowLength(1).
    90     run();
    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 
   103   graphToEps(g,"graph_to_eps_demo_out_par.eps").scale(10).
   104     title("Sample .eps figure (parallel edges)").
   105     copyright("(C) 2005 LEMON Project").
   106     nodeShapes(shapes).
   107     coords(coords).
   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).
   113     enableParallel().parEdgeDist(1.5).
   114     run();
   115   
   116   graphToEps(g,"graph_to_eps_demo_out_par_arr.eps").scale(10).
   117     title("Sample .eps figure (parallel edges and arrowheads)").
   118     copyright("(C) 2005 LEMON Project").
   119     nodeScale(2).nodeSizes(sizes).
   120     coords(coords).
   121     nodeShapes(shapes).
   122     nodeColors(composeMap(colorSet,colors)).
   123     edgeColors(composeMap(colorSet,ecolors)).
   124     edgeWidthScale(.3).edgeWidths(widths).
   125     nodeTexts(id).nodeTextSize(3).
   126     enableParallel().parEdgeDist(1).
   127     drawArrows().arrowWidth(1).arrowLength(1).
   128     run();
   129 
   130   graphToEps(g,"graph_to_eps_demo_out_a4.eps").scaleToA4().
   131     title("Sample .eps figure (fits to A4)").
   132     copyright("(C) 2005 LEMON Project").
   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 
   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 
   167 }