3  * This file is a part of LEMON, a generic C++ optimization library
 
     5  * Copyright (C) 2003-2006
 
     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 grawing function \ref graphToEps()
 
    23 /// This demo program shows examples how to  use the function \ref
 
    24 /// graphToEps(). It takes no input but simply creates  six
 
    25 /// <tt>.eps</tt> files demonstrating the capability of \ref
 
    26 /// graphToEps(), and showing how to draw directed/undirected graphs,
 
    27 /// how to handle parallel egdes, how to change the properties (like
 
    28 /// color, shape, size, title etc.) of nodes and edges individually
 
    29 /// using appropriate \ref maps-page "graph maps".
 
    31 /// \include graph_to_eps_demo.cc
 
    35 #include<lemon/graph_to_eps.h>
 
    36 #include<lemon/list_graph.h>
 
    37 #include<lemon/graph_utils.h>
 
    40 using namespace lemon;
 
    47   typedef ListGraph::Node Node;
 
    48   typedef ListGraph::NodeIt NodeIt;
 
    49   typedef ListGraph::Edge Edge;
 
    58   ListGraph::NodeMap<Xy> coords(g);
 
    59   ListGraph::NodeMap<double> sizes(g);
 
    60   ListGraph::NodeMap<int> colors(g);
 
    61   ListGraph::NodeMap<int> shapes(g);
 
    62   ListGraph::EdgeMap<int> ecolors(g);
 
    63   ListGraph::EdgeMap<int> widths(g);
 
    65   coords[n1]=Xy(50,50);  sizes[n1]=1; colors[n1]=1; shapes[n1]=0;
 
    66   coords[n2]=Xy(50,70);  sizes[n2]=2; colors[n2]=2; shapes[n2]=2;
 
    67   coords[n3]=Xy(70,70);  sizes[n3]=1; colors[n3]=3; shapes[n3]=0;
 
    68   coords[n4]=Xy(70,50);  sizes[n4]=2; colors[n4]=4; shapes[n4]=1;
 
    69   coords[n5]=Xy(85,60);  sizes[n5]=3; colors[n5]=5; shapes[n5]=2;
 
    73   e=g.addEdge(n1,n2); ecolors[e]=0; widths[e]=1;
 
    74   e=g.addEdge(n2,n3); ecolors[e]=0; widths[e]=1;
 
    75   e=g.addEdge(n3,n5); ecolors[e]=0; widths[e]=3;
 
    76   e=g.addEdge(n5,n4); ecolors[e]=0; widths[e]=1;
 
    77   e=g.addEdge(n4,n1); ecolors[e]=0; widths[e]=1;
 
    78   e=g.addEdge(n2,n4); ecolors[e]=1; widths[e]=2;
 
    79   e=g.addEdge(n3,n4); ecolors[e]=2; widths[e]=1;
 
    81   IdMap<ListGraph,Node> id(g);
 
    83   cout << "Create 'graph_to_eps_demo_out.eps'" << endl;
 
    84   graphToEps(g,"graph_to_eps_demo_out.eps").
 
    87     title("Sample .eps figure").
 
    88     copyright("(C) 2006 LEMON Project").
 
    89     nodeScale(2).nodeSizes(sizes).
 
    91     nodeColors(composeMap(colorSet,colors)).
 
    92     edgeColors(composeMap(colorSet,ecolors)).
 
    93     edgeWidthScale(.4).edgeWidths(widths).
 
    94     nodeTexts(id).nodeTextSize(3).
 
    98   cout << "Create 'graph_to_eps_demo_out_arr.eps'" << endl;
 
    99   graphToEps(g,"graph_to_eps_demo_out_arr.eps").
 
   101     title("Sample .eps figure (with arrowheads)").
 
   102     copyright("(C) 2006 LEMON Project").
 
   103     nodeColors(composeMap(colorSet,colors)).
 
   105     nodeScale(2).nodeSizes(sizes).
 
   107     edgeColors(composeMap(colorSet,ecolors)).
 
   108     edgeWidthScale(.4).edgeWidths(widths).
 
   109     nodeTexts(id).nodeTextSize(3).
 
   110     drawArrows().arrowWidth(1).arrowLength(1).
 
   113   e=g.addEdge(n1,n4); ecolors[e]=2; widths[e]=1;
 
   114   e=g.addEdge(n4,n1); ecolors[e]=1; widths[e]=2;
 
   116   e=g.addEdge(n1,n2); ecolors[e]=1; widths[e]=1;
 
   117   e=g.addEdge(n1,n2); ecolors[e]=2; widths[e]=1;
 
   118   e=g.addEdge(n1,n2); ecolors[e]=3; widths[e]=1;
 
   119   e=g.addEdge(n1,n2); ecolors[e]=4; widths[e]=1;
 
   120   e=g.addEdge(n1,n2); ecolors[e]=5; widths[e]=1;
 
   121   e=g.addEdge(n1,n2); ecolors[e]=6; widths[e]=1;
 
   122   e=g.addEdge(n1,n2); ecolors[e]=7; widths[e]=1;
 
   124   cout << "Create 'graph_to_eps_demo_out_par.eps'" << endl;
 
   125   graphToEps(g,"graph_to_eps_demo_out_par.eps").
 
   127     title("Sample .eps figure (parallel edges)").
 
   128     copyright("(C) 2006 LEMON Project").
 
   131     nodeScale(2).nodeSizes(sizes).
 
   132     nodeColors(composeMap(colorSet,colors)).
 
   133     edgeColors(composeMap(colorSet,ecolors)).
 
   134     edgeWidthScale(.4).edgeWidths(widths).
 
   135     nodeTexts(id).nodeTextSize(3).
 
   136     enableParallel().parEdgeDist(1.5).
 
   139   cout << "Create 'graph_to_eps_demo_out_par_arr.eps'" << endl;
 
   140   graphToEps(g,"graph_to_eps_demo_out_par_arr.eps").
 
   142     title("Sample .eps figure (parallel edges and arrowheads)").
 
   143     copyright("(C) 2006 LEMON Project").
 
   144     nodeScale(2).nodeSizes(sizes).
 
   147     nodeColors(composeMap(colorSet,colors)).
 
   148     edgeColors(composeMap(colorSet,ecolors)).
 
   149     edgeWidthScale(.3).edgeWidths(widths).
 
   150     nodeTexts(id).nodeTextSize(3).
 
   151     enableParallel().parEdgeDist(1).
 
   152     drawArrows().arrowWidth(1).arrowLength(1).
 
   155   cout << "Create 'graph_to_eps_demo_out_a4.eps'" << endl;
 
   156   graphToEps(g,"graph_to_eps_demo_out_a4.eps").scaleToA4().
 
   157     title("Sample .eps figure (fits to A4)").
 
   158     copyright("(C) 2006 LEMON Project").
 
   159     nodeScale(2).nodeSizes(sizes).
 
   162     nodeColors(composeMap(colorSet,colors)).
 
   163     edgeColors(composeMap(colorSet,ecolors)).
 
   164     edgeWidthScale(.3).edgeWidths(widths).
 
   165     nodeTexts(id).nodeTextSize(3).
 
   166     enableParallel().parEdgeDist(1).
 
   167     drawArrows().arrowWidth(1).arrowLength(1).
 
   171   ListGraph::NodeMap<int> hcolors(h);
 
   172   ListGraph::NodeMap<Xy> hcoords(h);
 
   174   int cols=int(sqrt(double(colorSet.size())));
 
   175   for(int i=0;i<int(colorSet.size());i++) {
 
   177     hcoords[n]=Xy(i%cols,i/cols);
 
   181   cout << "Create 'graph_to_eps_demo_out_colors.eps'" << endl;
 
   182   graphToEps(h,"graph_to_eps_demo_out_colors.eps").
 
   184     title("Sample .eps figure (ColorSet demo)").
 
   185     copyright("(C) 2006 LEMON Project").
 
   188     distantColorNodeTexts().
 
   189     //    distantBWNodeTexts().
 
   190     nodeTexts(hcolors).nodeTextSize(.6).
 
   191     nodeColors(composeMap(colorSet,hcolors)).