1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
 
     3  * This file is a part of LEMON, a generic C++ optimization library.
 
     5  * Copyright (C) 2003-2009
 
     6  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
 
     7  * (Egervary Research Group on Combinatorial Optimization, EGRES).
 
     9  * Permission to use, modify and distribute this software is granted
 
    10  * provided that this copyright notice appears in all copies. For
 
    11  * precise terms see the accompanying LICENSE file.
 
    13  * This software is provided "AS IS" with no warranty of any kind,
 
    14  * express or implied, and with no claim as to its suitability for any
 
    21 /// \brief Demo of the graph drawing function \ref graphToEps()
 
    23 /// This demo program shows examples how to use the function \ref
 
    24 /// graphToEps(). It takes no input but simply creates seven
 
    25 /// <tt>.eps</tt> files demonstrating the capability of \ref
 
    26 /// graphToEps(), and showing how to draw directed graphs,
 
    27 /// how to handle parallel egdes, how to change the properties (like
 
    28 /// color, shape, size, title etc.) of nodes and arcs individually
 
    29 /// using appropriate graph maps.
 
    31 /// \include graph_to_eps_demo.cc
 
    33 #include<lemon/list_graph.h>
 
    34 #include<lemon/graph_to_eps.h>
 
    35 #include<lemon/math.h>
 
    38 using namespace lemon;
 
    43   Palette paletteW(true);
 
    45   // Create a small digraph
 
    47   typedef ListDigraph::Node Node;
 
    48   typedef ListDigraph::NodeIt NodeIt;
 
    49   typedef ListDigraph::Arc Arc;
 
    50   typedef dim2::Point<int> Point;
 
    58   ListDigraph::NodeMap<Point> coords(g);
 
    59   ListDigraph::NodeMap<double> sizes(g);
 
    60   ListDigraph::NodeMap<int> colors(g);
 
    61   ListDigraph::NodeMap<int> shapes(g);
 
    62   ListDigraph::ArcMap<int> acolors(g);
 
    63   ListDigraph::ArcMap<int> widths(g);
 
    65   coords[n1]=Point(50,50);  sizes[n1]=1; colors[n1]=1; shapes[n1]=0;
 
    66   coords[n2]=Point(50,70);  sizes[n2]=2; colors[n2]=2; shapes[n2]=2;
 
    67   coords[n3]=Point(70,70);  sizes[n3]=1; colors[n3]=3; shapes[n3]=0;
 
    68   coords[n4]=Point(70,50);  sizes[n4]=2; colors[n4]=4; shapes[n4]=1;
 
    69   coords[n5]=Point(85,60);  sizes[n5]=3; colors[n5]=5; shapes[n5]=2;
 
    73   a=g.addArc(n1,n2); acolors[a]=0; widths[a]=1;
 
    74   a=g.addArc(n2,n3); acolors[a]=0; widths[a]=1;
 
    75   a=g.addArc(n3,n5); acolors[a]=0; widths[a]=3;
 
    76   a=g.addArc(n5,n4); acolors[a]=0; widths[a]=1;
 
    77   a=g.addArc(n4,n1); acolors[a]=0; widths[a]=1;
 
    78   a=g.addArc(n2,n4); acolors[a]=1; widths[a]=2;
 
    79   a=g.addArc(n3,n4); acolors[a]=2; widths[a]=1;
 
    81   IdMap<ListDigraph,Node> id(g);
 
    83   // Create .eps files showing the digraph with different options
 
    84   cout << "Create 'graph_to_eps_demo_out_1_pure.eps'" << endl;
 
    85   graphToEps(g,"graph_to_eps_demo_out_1_pure.eps").
 
    87     title("Sample .eps figure").
 
    88     copyright("(C) 2003-2009 LEMON Project").
 
    91   cout << "Create 'graph_to_eps_demo_out_2.eps'" << endl;
 
    92   graphToEps(g,"graph_to_eps_demo_out_2.eps").
 
    94     title("Sample .eps figure").
 
    95     copyright("(C) 2003-2009 LEMON Project").
 
    96     absoluteNodeSizes().absoluteArcWidths().
 
    97     nodeScale(2).nodeSizes(sizes).
 
    99     nodeColors(composeMap(palette,colors)).
 
   100     arcColors(composeMap(palette,acolors)).
 
   101     arcWidthScale(.4).arcWidths(widths).
 
   102     nodeTexts(id).nodeTextSize(3).
 
   105   cout << "Create 'graph_to_eps_demo_out_3_arr.eps'" << endl;
 
   106   graphToEps(g,"graph_to_eps_demo_out_3_arr.eps").
 
   107     title("Sample .eps figure (with arrowheads)").
 
   108     copyright("(C) 2003-2009 LEMON Project").
 
   109     absoluteNodeSizes().absoluteArcWidths().
 
   110     nodeColors(composeMap(palette,colors)).
 
   112     nodeScale(2).nodeSizes(sizes).
 
   114     arcColors(composeMap(palette,acolors)).
 
   115     arcWidthScale(.4).arcWidths(widths).
 
   116     nodeTexts(id).nodeTextSize(3).
 
   117     drawArrows().arrowWidth(2).arrowLength(2).
 
   120   // Add more arcs to the digraph
 
   121   a=g.addArc(n1,n4); acolors[a]=2; widths[a]=1;
 
   122   a=g.addArc(n4,n1); acolors[a]=1; widths[a]=2;
 
   124   a=g.addArc(n1,n2); acolors[a]=1; widths[a]=1;
 
   125   a=g.addArc(n1,n2); acolors[a]=2; widths[a]=1;
 
   126   a=g.addArc(n1,n2); acolors[a]=3; widths[a]=1;
 
   127   a=g.addArc(n1,n2); acolors[a]=4; widths[a]=1;
 
   128   a=g.addArc(n1,n2); acolors[a]=5; widths[a]=1;
 
   129   a=g.addArc(n1,n2); acolors[a]=6; widths[a]=1;
 
   130   a=g.addArc(n1,n2); acolors[a]=7; widths[a]=1;
 
   132   cout << "Create 'graph_to_eps_demo_out_4_par.eps'" << endl;
 
   133   graphToEps(g,"graph_to_eps_demo_out_4_par.eps").
 
   134     title("Sample .eps figure (parallel arcs)").
 
   135     copyright("(C) 2003-2009 LEMON Project").
 
   136     absoluteNodeSizes().absoluteArcWidths().
 
   139     nodeScale(2).nodeSizes(sizes).
 
   140     nodeColors(composeMap(palette,colors)).
 
   141     arcColors(composeMap(palette,acolors)).
 
   142     arcWidthScale(.4).arcWidths(widths).
 
   143     nodeTexts(id).nodeTextSize(3).
 
   144     enableParallel().parArcDist(1.5).
 
   147   cout << "Create 'graph_to_eps_demo_out_5_par_arr.eps'" << endl;
 
   148   graphToEps(g,"graph_to_eps_demo_out_5_par_arr.eps").
 
   149     title("Sample .eps figure (parallel arcs and arrowheads)").
 
   150     copyright("(C) 2003-2009 LEMON Project").
 
   151     absoluteNodeSizes().absoluteArcWidths().
 
   152     nodeScale(2).nodeSizes(sizes).
 
   155     nodeColors(composeMap(palette,colors)).
 
   156     arcColors(composeMap(palette,acolors)).
 
   157     arcWidthScale(.3).arcWidths(widths).
 
   158     nodeTexts(id).nodeTextSize(3).
 
   159     enableParallel().parArcDist(1).
 
   160     drawArrows().arrowWidth(1).arrowLength(1).
 
   163   cout << "Create 'graph_to_eps_demo_out_6_par_arr_a4.eps'" << endl;
 
   164   graphToEps(g,"graph_to_eps_demo_out_6_par_arr_a4.eps").
 
   165     title("Sample .eps figure (fits to A4)").
 
   166     copyright("(C) 2003-2009 LEMON Project").
 
   168     absoluteNodeSizes().absoluteArcWidths().
 
   169     nodeScale(2).nodeSizes(sizes).
 
   172     nodeColors(composeMap(palette,colors)).
 
   173     arcColors(composeMap(palette,acolors)).
 
   174     arcWidthScale(.3).arcWidths(widths).
 
   175     nodeTexts(id).nodeTextSize(3).
 
   176     enableParallel().parArcDist(1).
 
   177     drawArrows().arrowWidth(1).arrowLength(1).
 
   180   // Create an .eps file showing the colors of a default Palette
 
   182   ListDigraph::NodeMap<int> hcolors(h);
 
   183   ListDigraph::NodeMap<Point> hcoords(h);
 
   185   int cols=int(std::sqrt(double(palette.size())));
 
   186   for(int i=0;i<int(paletteW.size());i++) {
 
   188     hcoords[n]=Point(1+i%cols,1+i/cols);
 
   192   cout << "Create 'graph_to_eps_demo_out_7_colors.eps'" << endl;
 
   193   graphToEps(h,"graph_to_eps_demo_out_7_colors.eps").
 
   195     title("Sample .eps figure (Palette demo)").
 
   196     copyright("(C) 2003-2009 LEMON Project").
 
   198     absoluteNodeSizes().absoluteArcWidths().
 
   200     distantColorNodeTexts().
 
   201     nodeTexts(hcolors).nodeTextSize(.6).
 
   202     nodeColors(composeMap(paletteW,hcolors)).