demo/graph_to_eps_demo.cc
author alpar
Tue, 18 Jul 2006 15:57:55 +0000
changeset 2153 b1fb96088350
parent 1930 92b70deed0c5
child 2172 4b25e7003868
permissions -rw-r--r--
Better 'Naming Convention' conformance.
alpar@1073
     1
/* -*- C++ -*-
alpar@1073
     2
 *
alpar@1956
     3
 * This file is a part of LEMON, a generic C++ optimization library
alpar@1956
     4
 *
alpar@1956
     5
 * Copyright (C) 2003-2006
alpar@1956
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@1359
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
alpar@1073
     8
 *
alpar@1073
     9
 * Permission to use, modify and distribute this software is granted
alpar@1073
    10
 * provided that this copyright notice appears in all copies. For
alpar@1073
    11
 * precise terms see the accompanying LICENSE file.
alpar@1073
    12
 *
alpar@1073
    13
 * This software is provided "AS IS" with no warranty of any kind,
alpar@1073
    14
 * express or implied, and with no claim as to its suitability for any
alpar@1073
    15
 * purpose.
alpar@1073
    16
 *
alpar@1073
    17
 */
alpar@1073
    18
alpar@1573
    19
/// \ingroup demos
alpar@1573
    20
/// \file
alpar@1573
    21
/// \brief Demo of the graph grawing function \ref graphToEps()
alpar@1573
    22
///
alpar@1573
    23
/// This demo program shows examples how to  use the function \ref
alpar@1573
    24
/// graphToEps(). It takes no input but simply creates  six
alpar@1587
    25
/// <tt>.eps</tt> files demonstrating the capability of \ref
alpar@1587
    26
/// graphToEps(), and showing how to draw directed/undirected graphs,
alpar@1587
    27
/// how to handle parallel egdes, how to change the properties (like
alpar@1587
    28
/// color, shape, size, title etc.) of nodes and edges individually
alpar@1630
    29
/// using appropriate \ref maps-page "graph maps".
alpar@1641
    30
///
alpar@1641
    31
/// \include graph_to_eps_demo.cc
alpar@1073
    32
deba@1417
    33
#include <cmath>
deba@1417
    34
alpar@1573
    35
#include<lemon/graph_to_eps.h>
alpar@1573
    36
#include<lemon/list_graph.h>
deba@1802
    37
#include<lemon/graph_utils.h>
alpar@1073
    38
alpar@1073
    39
using namespace std;
alpar@1073
    40
using namespace lemon;
alpar@1073
    41
alpar@1073
    42
int main()
alpar@1073
    43
{
alpar@1178
    44
  ColorSet colorSet;
alpar@1178
    45
alpar@1073
    46
  ListGraph g;
alpar@1073
    47
  typedef ListGraph::Node Node;
alpar@1073
    48
  typedef ListGraph::NodeIt NodeIt;
alpar@1073
    49
  typedef ListGraph::Edge Edge;
alpar@1073
    50
  typedef xy<int> Xy;
alpar@1073
    51
  
alpar@1073
    52
  Node n1=g.addNode();
alpar@1073
    53
  Node n2=g.addNode();
alpar@1073
    54
  Node n3=g.addNode();
alpar@1073
    55
  Node n4=g.addNode();
alpar@1073
    56
  Node n5=g.addNode();
alpar@1073
    57
alpar@1073
    58
  ListGraph::NodeMap<Xy> coords(g);
alpar@1073
    59
  ListGraph::NodeMap<double> sizes(g);
alpar@1073
    60
  ListGraph::NodeMap<int> colors(g);
alpar@1086
    61
  ListGraph::NodeMap<int> shapes(g);
alpar@1073
    62
  ListGraph::EdgeMap<int> ecolors(g);
alpar@1073
    63
  ListGraph::EdgeMap<int> widths(g);
alpar@1073
    64
  
alpar@1086
    65
  coords[n1]=Xy(50,50);  sizes[n1]=1; colors[n1]=1; shapes[n1]=0;
alpar@1088
    66
  coords[n2]=Xy(50,70);  sizes[n2]=2; colors[n2]=2; shapes[n2]=2;
alpar@1086
    67
  coords[n3]=Xy(70,70);  sizes[n3]=1; colors[n3]=3; shapes[n3]=0;
alpar@1086
    68
  coords[n4]=Xy(70,50);  sizes[n4]=2; colors[n4]=4; shapes[n4]=1;
alpar@1088
    69
  coords[n5]=Xy(85,60);  sizes[n5]=3; colors[n5]=5; shapes[n5]=2;
alpar@1073
    70
  
alpar@1073
    71
  Edge e;
alpar@1073
    72
alpar@1073
    73
  e=g.addEdge(n1,n2); ecolors[e]=0; widths[e]=1;
alpar@1073
    74
  e=g.addEdge(n2,n3); ecolors[e]=0; widths[e]=1;
alpar@1073
    75
  e=g.addEdge(n3,n5); ecolors[e]=0; widths[e]=3;
alpar@1073
    76
  e=g.addEdge(n5,n4); ecolors[e]=0; widths[e]=1;
alpar@1073
    77
  e=g.addEdge(n4,n1); ecolors[e]=0; widths[e]=1;
alpar@1073
    78
  e=g.addEdge(n2,n4); ecolors[e]=1; widths[e]=2;
alpar@1073
    79
  e=g.addEdge(n3,n4); ecolors[e]=2; widths[e]=1;
alpar@1073
    80
  
alpar@1268
    81
  IdMap<ListGraph,Node> id(g);
alpar@1073
    82
alpar@1573
    83
  cout << "Create 'graph_to_eps_demo_out.eps'" << endl;
alpar@1930
    84
  graphToEps(g,"graph_to_eps_demo_out.eps").
alpar@1930
    85
    //scale(10).
alpar@1930
    86
    coords(coords).
alpar@1108
    87
    title("Sample .eps figure").
alpar@1875
    88
    copyright("(C) 2006 LEMON Project").
alpar@1073
    89
    nodeScale(2).nodeSizes(sizes).
alpar@1086
    90
    nodeShapes(shapes).
alpar@1073
    91
    nodeColors(composeMap(colorSet,colors)).
alpar@1073
    92
    edgeColors(composeMap(colorSet,ecolors)).
alpar@1073
    93
    edgeWidthScale(.4).edgeWidths(widths).
alpar@1091
    94
    nodeTexts(id).nodeTextSize(3).
alpar@1091
    95
    run();
alpar@1073
    96
alpar@1573
    97
alpar@1573
    98
  cout << "Create 'graph_to_eps_demo_out_arr.eps'" << endl;
alpar@1930
    99
  graphToEps(g,"graph_to_eps_demo_out_arr.eps").
alpar@1930
   100
    //scale(10).
alpar@1108
   101
    title("Sample .eps figure (with arrowheads)").
alpar@1875
   102
    copyright("(C) 2006 LEMON Project").
alpar@1091
   103
    nodeColors(composeMap(colorSet,colors)).
alpar@1091
   104
    coords(coords).
alpar@1073
   105
    nodeScale(2).nodeSizes(sizes).
alpar@1086
   106
    nodeShapes(shapes).
alpar@1073
   107
    edgeColors(composeMap(colorSet,ecolors)).
alpar@1073
   108
    edgeWidthScale(.4).edgeWidths(widths).
alpar@1073
   109
    nodeTexts(id).nodeTextSize(3).
alpar@1091
   110
    drawArrows().arrowWidth(1).arrowLength(1).
alpar@1091
   111
    run();
alpar@1073
   112
alpar@1073
   113
  e=g.addEdge(n1,n4); ecolors[e]=2; widths[e]=1;
alpar@1073
   114
  e=g.addEdge(n4,n1); ecolors[e]=1; widths[e]=2;
alpar@1073
   115
alpar@1073
   116
  e=g.addEdge(n1,n2); ecolors[e]=1; widths[e]=1;
alpar@1073
   117
  e=g.addEdge(n1,n2); ecolors[e]=2; widths[e]=1;
alpar@1073
   118
  e=g.addEdge(n1,n2); ecolors[e]=3; widths[e]=1;
alpar@1073
   119
  e=g.addEdge(n1,n2); ecolors[e]=4; widths[e]=1;
alpar@1073
   120
  e=g.addEdge(n1,n2); ecolors[e]=5; widths[e]=1;
alpar@1073
   121
  e=g.addEdge(n1,n2); ecolors[e]=6; widths[e]=1;
alpar@1073
   122
  e=g.addEdge(n1,n2); ecolors[e]=7; widths[e]=1;
alpar@1073
   123
alpar@1573
   124
  cout << "Create 'graph_to_eps_demo_out_par.eps'" << endl;
alpar@1930
   125
  graphToEps(g,"graph_to_eps_demo_out_par.eps").
alpar@1930
   126
    //scale(10).
alpar@1108
   127
    title("Sample .eps figure (parallel edges)").
alpar@1875
   128
    copyright("(C) 2006 LEMON Project").
alpar@1091
   129
    nodeShapes(shapes).
alpar@1091
   130
    coords(coords).
alpar@1073
   131
    nodeScale(2).nodeSizes(sizes).
alpar@1073
   132
    nodeColors(composeMap(colorSet,colors)).
alpar@1073
   133
    edgeColors(composeMap(colorSet,ecolors)).
alpar@1073
   134
    edgeWidthScale(.4).edgeWidths(widths).
alpar@1073
   135
    nodeTexts(id).nodeTextSize(3).
alpar@1091
   136
    enableParallel().parEdgeDist(1.5).
alpar@1091
   137
    run();
alpar@1091
   138
  
alpar@1573
   139
  cout << "Create 'graph_to_eps_demo_out_par_arr.eps'" << endl;
alpar@1930
   140
  graphToEps(g,"graph_to_eps_demo_out_par_arr.eps").
alpar@1930
   141
    //scale(10).
alpar@1108
   142
    title("Sample .eps figure (parallel edges and arrowheads)").
alpar@1875
   143
    copyright("(C) 2006 LEMON Project").
alpar@1073
   144
    nodeScale(2).nodeSizes(sizes).
alpar@1091
   145
    coords(coords).
alpar@1086
   146
    nodeShapes(shapes).
alpar@1073
   147
    nodeColors(composeMap(colorSet,colors)).
alpar@1073
   148
    edgeColors(composeMap(colorSet,ecolors)).
alpar@1073
   149
    edgeWidthScale(.3).edgeWidths(widths).
alpar@1073
   150
    nodeTexts(id).nodeTextSize(3).
alpar@1073
   151
    enableParallel().parEdgeDist(1).
alpar@1091
   152
    drawArrows().arrowWidth(1).arrowLength(1).
alpar@1103
   153
    run();
alpar@1103
   154
alpar@1573
   155
  cout << "Create 'graph_to_eps_demo_out_a4.eps'" << endl;
alpar@1103
   156
  graphToEps(g,"graph_to_eps_demo_out_a4.eps").scaleToA4().
alpar@1108
   157
    title("Sample .eps figure (fits to A4)").
alpar@1875
   158
    copyright("(C) 2006 LEMON Project").
alpar@1103
   159
    nodeScale(2).nodeSizes(sizes).
alpar@1103
   160
    coords(coords).
alpar@1103
   161
    nodeShapes(shapes).
alpar@1103
   162
    nodeColors(composeMap(colorSet,colors)).
alpar@1103
   163
    edgeColors(composeMap(colorSet,ecolors)).
alpar@1103
   164
    edgeWidthScale(.3).edgeWidths(widths).
alpar@1103
   165
    nodeTexts(id).nodeTextSize(3).
alpar@1103
   166
    enableParallel().parEdgeDist(1).
alpar@1103
   167
    drawArrows().arrowWidth(1).arrowLength(1).
alpar@1103
   168
    run();
alpar@1103
   169
alpar@1178
   170
  ListGraph h;
alpar@1178
   171
  ListGraph::NodeMap<int> hcolors(h);
alpar@1178
   172
  ListGraph::NodeMap<Xy> hcoords(h);
alpar@1178
   173
  
alpar@1178
   174
  int cols=int(sqrt(double(colorSet.size())));
alpar@1178
   175
  for(int i=0;i<int(colorSet.size());i++) {
alpar@1178
   176
    Node n=h.addNode();
alpar@1178
   177
    hcoords[n]=Xy(i%cols,i/cols);
alpar@1178
   178
    hcolors[n]=i;
alpar@1178
   179
  }
alpar@1178
   180
  
alpar@1573
   181
  cout << "Create 'graph_to_eps_demo_out_colors.eps'" << endl;
alpar@1930
   182
  graphToEps(h,"graph_to_eps_demo_out_colors.eps").
alpar@1930
   183
    //scale(60).
alpar@1573
   184
    title("Sample .eps figure (ColorSet demo)").
alpar@1875
   185
    copyright("(C) 2006 LEMON Project").
alpar@1178
   186
    coords(hcoords).
alpar@1178
   187
    nodeScale(.45).
alpar@1178
   188
    distantColorNodeTexts().
alpar@1178
   189
    //    distantBWNodeTexts().
alpar@1178
   190
    nodeTexts(hcolors).nodeTextSize(.6).
alpar@1178
   191
    nodeColors(composeMap(colorSet,hcolors)).
alpar@1178
   192
    run();
alpar@1178
   193
alpar@1178
   194
alpar@1073
   195
}