src/demo/graph_to_eps_demo.cc
author alpar
Tue, 15 Feb 2005 14:54:25 +0000
changeset 1146 ebab0e5ec8b2
parent 1103 f196dc4f1b31
child 1164 80bb73097736
permissions -rw-r--r--
Doc improvements.
alpar@1073
     1
/* -*- C++ -*-
alpar@1073
     2
 * src/lemon/demo/graph_to_eps.cc - 
alpar@1073
     3
 * Part of LEMON, a generic C++ optimization library
alpar@1073
     4
 *
alpar@1073
     5
 * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@1073
     6
 * (Egervary Combinatorial Optimization Research Group, EGRES).
alpar@1073
     7
 *
alpar@1073
     8
 * Permission to use, modify and distribute this software is granted
alpar@1073
     9
 * provided that this copyright notice appears in all copies. For
alpar@1073
    10
 * precise terms see the accompanying LICENSE file.
alpar@1073
    11
 *
alpar@1073
    12
 * This software is provided "AS IS" with no warranty of any kind,
alpar@1073
    13
 * express or implied, and with no claim as to its suitability for any
alpar@1073
    14
 * purpose.
alpar@1073
    15
 *
alpar@1073
    16
 */
alpar@1073
    17
alpar@1073
    18
#include<lemon/graph_to_eps.h>
alpar@1073
    19
#include<lemon/maps.h>
alpar@1073
    20
#include<lemon/list_graph.h>
alpar@1073
    21
alpar@1073
    22
alpar@1073
    23
using namespace std;
alpar@1073
    24
using namespace lemon;
alpar@1073
    25
alpar@1073
    26
class ColorSet : public MapBase<int,Color>
alpar@1073
    27
{
alpar@1073
    28
public:
alpar@1073
    29
  Color operator[](int i) const
alpar@1073
    30
  {
alpar@1073
    31
    switch(i%8){
alpar@1073
    32
    case 0: return Color(0,0,0);
alpar@1073
    33
    case 1: return Color(1,0,0);
alpar@1073
    34
    case 2: return Color(0,1,0);
alpar@1073
    35
    case 3: return Color(0,0,1);
alpar@1073
    36
    case 4: return Color(1,1,0);
alpar@1073
    37
    case 5: return Color(1,0,1);
alpar@1073
    38
    case 6: return Color(0,1,1);
alpar@1073
    39
    case 7: return Color(1,1,1);
alpar@1073
    40
    }
alpar@1073
    41
    return Color(0,0,0);
alpar@1073
    42
  }
alpar@1073
    43
} colorSet;
alpar@1073
    44
alpar@1073
    45
class IdMap :public MapBase<ListGraph::Node,int>
alpar@1073
    46
{
alpar@1073
    47
  const ListGraph &g;
alpar@1073
    48
public:
alpar@1073
    49
  IdMap(const ListGraph &_g) :g(_g) {}
alpar@1073
    50
  Value operator[](Key n) const { return g.id(n); }
alpar@1073
    51
};
alpar@1073
    52
alpar@1073
    53
int main()
alpar@1073
    54
{
alpar@1073
    55
  ListGraph g;
alpar@1073
    56
  typedef ListGraph::Node Node;
alpar@1073
    57
  typedef ListGraph::NodeIt NodeIt;
alpar@1073
    58
  typedef ListGraph::Edge Edge;
alpar@1073
    59
  typedef xy<int> Xy;
alpar@1073
    60
  
alpar@1073
    61
  Node n1=g.addNode();
alpar@1073
    62
  Node n2=g.addNode();
alpar@1073
    63
  Node n3=g.addNode();
alpar@1073
    64
  Node n4=g.addNode();
alpar@1073
    65
  Node n5=g.addNode();
alpar@1073
    66
alpar@1073
    67
  ListGraph::NodeMap<Xy> coords(g);
alpar@1073
    68
  ListGraph::NodeMap<double> sizes(g);
alpar@1073
    69
  ListGraph::NodeMap<int> colors(g);
alpar@1086
    70
  ListGraph::NodeMap<int> shapes(g);
alpar@1073
    71
  ListGraph::EdgeMap<int> ecolors(g);
alpar@1073
    72
  ListGraph::EdgeMap<int> widths(g);
alpar@1073
    73
  
alpar@1086
    74
  coords[n1]=Xy(50,50);  sizes[n1]=1; colors[n1]=1; shapes[n1]=0;
alpar@1088
    75
  coords[n2]=Xy(50,70);  sizes[n2]=2; colors[n2]=2; shapes[n2]=2;
alpar@1086
    76
  coords[n3]=Xy(70,70);  sizes[n3]=1; colors[n3]=3; shapes[n3]=0;
alpar@1086
    77
  coords[n4]=Xy(70,50);  sizes[n4]=2; colors[n4]=4; shapes[n4]=1;
alpar@1088
    78
  coords[n5]=Xy(85,60);  sizes[n5]=3; colors[n5]=5; shapes[n5]=2;
alpar@1073
    79
  
alpar@1073
    80
  Edge e;
alpar@1073
    81
alpar@1073
    82
  e=g.addEdge(n1,n2); ecolors[e]=0; widths[e]=1;
alpar@1073
    83
  e=g.addEdge(n2,n3); ecolors[e]=0; widths[e]=1;
alpar@1073
    84
  e=g.addEdge(n3,n5); ecolors[e]=0; widths[e]=3;
alpar@1073
    85
  e=g.addEdge(n5,n4); ecolors[e]=0; widths[e]=1;
alpar@1073
    86
  e=g.addEdge(n4,n1); ecolors[e]=0; widths[e]=1;
alpar@1073
    87
  e=g.addEdge(n2,n4); ecolors[e]=1; widths[e]=2;
alpar@1073
    88
  e=g.addEdge(n3,n4); ecolors[e]=2; widths[e]=1;
alpar@1073
    89
  
alpar@1073
    90
  IdMap id(g);
alpar@1073
    91
alpar@1073
    92
  graphToEps(g,"graph_to_eps_demo_out.eps").scale(10).coords(coords).
alpar@1108
    93
    title("Sample .eps figure").
alpar@1108
    94
    copyright("(C) 2004 LEMON Project").
alpar@1073
    95
    nodeScale(2).nodeSizes(sizes).
alpar@1086
    96
    nodeShapes(shapes).
alpar@1073
    97
    nodeColors(composeMap(colorSet,colors)).
alpar@1073
    98
    edgeColors(composeMap(colorSet,ecolors)).
alpar@1073
    99
    edgeWidthScale(.4).edgeWidths(widths).
alpar@1091
   100
    nodeTexts(id).nodeTextSize(3).
alpar@1091
   101
    run();
alpar@1073
   102
alpar@1091
   103
  graphToEps(g,"graph_to_eps_demo_out_arr.eps").scale(10).
alpar@1108
   104
    title("Sample .eps figure (with arrowheads)").
alpar@1108
   105
    copyright("(C) 2004 LEMON Project").
alpar@1091
   106
    nodeColors(composeMap(colorSet,colors)).
alpar@1091
   107
    coords(coords).
alpar@1073
   108
    nodeScale(2).nodeSizes(sizes).
alpar@1086
   109
    nodeShapes(shapes).
alpar@1073
   110
    edgeColors(composeMap(colorSet,ecolors)).
alpar@1073
   111
    edgeWidthScale(.4).edgeWidths(widths).
alpar@1073
   112
    nodeTexts(id).nodeTextSize(3).
alpar@1091
   113
    drawArrows().arrowWidth(1).arrowLength(1).
alpar@1091
   114
    run();
alpar@1073
   115
alpar@1073
   116
  e=g.addEdge(n1,n4); ecolors[e]=2; widths[e]=1;
alpar@1073
   117
  e=g.addEdge(n4,n1); ecolors[e]=1; widths[e]=2;
alpar@1073
   118
alpar@1073
   119
  e=g.addEdge(n1,n2); ecolors[e]=1; widths[e]=1;
alpar@1073
   120
  e=g.addEdge(n1,n2); ecolors[e]=2; widths[e]=1;
alpar@1073
   121
  e=g.addEdge(n1,n2); ecolors[e]=3; widths[e]=1;
alpar@1073
   122
  e=g.addEdge(n1,n2); ecolors[e]=4; widths[e]=1;
alpar@1073
   123
  e=g.addEdge(n1,n2); ecolors[e]=5; widths[e]=1;
alpar@1073
   124
  e=g.addEdge(n1,n2); ecolors[e]=6; widths[e]=1;
alpar@1073
   125
  e=g.addEdge(n1,n2); ecolors[e]=7; widths[e]=1;
alpar@1073
   126
alpar@1091
   127
  graphToEps(g,"graph_to_eps_demo_out_par.eps").scale(10).
alpar@1108
   128
    title("Sample .eps figure (parallel edges)").
alpar@1108
   129
    copyright("(C) 2004 LEMON Project").
alpar@1091
   130
    nodeShapes(shapes).
alpar@1091
   131
    coords(coords).
alpar@1073
   132
    nodeScale(2).nodeSizes(sizes).
alpar@1073
   133
    nodeColors(composeMap(colorSet,colors)).
alpar@1073
   134
    edgeColors(composeMap(colorSet,ecolors)).
alpar@1073
   135
    edgeWidthScale(.4).edgeWidths(widths).
alpar@1073
   136
    nodeTexts(id).nodeTextSize(3).
alpar@1091
   137
    enableParallel().parEdgeDist(1.5).
alpar@1091
   138
    run();
alpar@1091
   139
  
alpar@1091
   140
  graphToEps(g,"graph_to_eps_demo_out_par_arr.eps").scale(10).
alpar@1108
   141
    title("Sample .eps figure (parallel edges and arrowheads)").
alpar@1108
   142
    copyright("(C) 2004 LEMON Project").
alpar@1073
   143
    nodeScale(2).nodeSizes(sizes).
alpar@1091
   144
    coords(coords).
alpar@1086
   145
    nodeShapes(shapes).
alpar@1073
   146
    nodeColors(composeMap(colorSet,colors)).
alpar@1073
   147
    edgeColors(composeMap(colorSet,ecolors)).
alpar@1073
   148
    edgeWidthScale(.3).edgeWidths(widths).
alpar@1073
   149
    nodeTexts(id).nodeTextSize(3).
alpar@1073
   150
    enableParallel().parEdgeDist(1).
alpar@1091
   151
    drawArrows().arrowWidth(1).arrowLength(1).
alpar@1103
   152
    run();
alpar@1103
   153
alpar@1103
   154
  graphToEps(g,"graph_to_eps_demo_out_a4.eps").scaleToA4().
alpar@1108
   155
    title("Sample .eps figure (fits to A4)").
alpar@1108
   156
    copyright("(C) 2004 LEMON Project").
alpar@1103
   157
    nodeScale(2).nodeSizes(sizes).
alpar@1103
   158
    coords(coords).
alpar@1103
   159
    nodeShapes(shapes).
alpar@1103
   160
    nodeColors(composeMap(colorSet,colors)).
alpar@1103
   161
    edgeColors(composeMap(colorSet,ecolors)).
alpar@1103
   162
    edgeWidthScale(.3).edgeWidths(widths).
alpar@1103
   163
    nodeTexts(id).nodeTextSize(3).
alpar@1103
   164
    enableParallel().parEdgeDist(1).
alpar@1103
   165
    drawArrows().arrowWidth(1).arrowLength(1).
alpar@1103
   166
    run();
alpar@1103
   167
alpar@1073
   168
}