src/demo/graph_to_eps_demo.cc
author marci
Tue, 11 Jan 2005 17:16:29 +0000
changeset 1075 789bad021e2d
child 1086 caa13d291528
permissions -rw-r--r--
:-}
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@1073
    70
  ListGraph::EdgeMap<int> ecolors(g);
alpar@1073
    71
  ListGraph::EdgeMap<int> widths(g);
alpar@1073
    72
  
alpar@1073
    73
  coords[n1]=Xy(50,50);  sizes[n1]=1; colors[n1]=1;
alpar@1073
    74
  coords[n2]=Xy(50,70);  sizes[n2]=2; colors[n2]=2;
alpar@1073
    75
  coords[n3]=Xy(70,70);  sizes[n3]=1; colors[n3]=3;
alpar@1073
    76
  coords[n4]=Xy(70,50);  sizes[n4]=2; colors[n4]=4;
alpar@1073
    77
  coords[n5]=Xy(85,60);  sizes[n5]=3; colors[n5]=5;
alpar@1073
    78
  
alpar@1073
    79
  Edge e;
alpar@1073
    80
alpar@1073
    81
  e=g.addEdge(n1,n2); ecolors[e]=0; widths[e]=1;
alpar@1073
    82
  e=g.addEdge(n2,n3); ecolors[e]=0; widths[e]=1;
alpar@1073
    83
  e=g.addEdge(n3,n5); ecolors[e]=0; widths[e]=3;
alpar@1073
    84
  e=g.addEdge(n5,n4); ecolors[e]=0; widths[e]=1;
alpar@1073
    85
  e=g.addEdge(n4,n1); ecolors[e]=0; widths[e]=1;
alpar@1073
    86
  e=g.addEdge(n2,n4); ecolors[e]=1; widths[e]=2;
alpar@1073
    87
  e=g.addEdge(n3,n4); ecolors[e]=2; widths[e]=1;
alpar@1073
    88
  
alpar@1073
    89
  IdMap id(g);
alpar@1073
    90
alpar@1073
    91
  graphToEps(g,"graph_to_eps_demo_out.eps").scale(10).coords(coords).
alpar@1073
    92
    nodeScale(2).nodeSizes(sizes).
alpar@1073
    93
    nodeColors(composeMap(colorSet,colors)).
alpar@1073
    94
    edgeColors(composeMap(colorSet,ecolors)).
alpar@1073
    95
    edgeWidthScale(.4).edgeWidths(widths).
alpar@1073
    96
    nodeTexts(id).nodeTextSize(3);
alpar@1073
    97
alpar@1073
    98
  graphToEps(g,"graph_to_eps_demo_out_arr.eps").scale(10).coords(coords).
alpar@1073
    99
    nodeScale(2).nodeSizes(sizes).
alpar@1073
   100
    nodeColors(composeMap(colorSet,colors)).
alpar@1073
   101
    edgeColors(composeMap(colorSet,ecolors)).
alpar@1073
   102
    edgeWidthScale(.4).edgeWidths(widths).
alpar@1073
   103
    nodeTexts(id).nodeTextSize(3).
alpar@1073
   104
    drawArrows().arrowWidth(1).arrowLength(1);
alpar@1073
   105
alpar@1073
   106
  e=g.addEdge(n1,n4); ecolors[e]=2; widths[e]=1;
alpar@1073
   107
  e=g.addEdge(n4,n1); ecolors[e]=1; widths[e]=2;
alpar@1073
   108
alpar@1073
   109
  e=g.addEdge(n1,n2); ecolors[e]=1; widths[e]=1;
alpar@1073
   110
  e=g.addEdge(n1,n2); ecolors[e]=2; widths[e]=1;
alpar@1073
   111
  e=g.addEdge(n1,n2); ecolors[e]=3; widths[e]=1;
alpar@1073
   112
  e=g.addEdge(n1,n2); ecolors[e]=4; widths[e]=1;
alpar@1073
   113
  e=g.addEdge(n1,n2); ecolors[e]=5; widths[e]=1;
alpar@1073
   114
  e=g.addEdge(n1,n2); ecolors[e]=6; widths[e]=1;
alpar@1073
   115
  e=g.addEdge(n1,n2); ecolors[e]=7; widths[e]=1;
alpar@1073
   116
alpar@1073
   117
  graphToEps(g,"graph_to_eps_demo_out_par.eps").scale(10).coords(coords).
alpar@1073
   118
    nodeScale(2).nodeSizes(sizes).
alpar@1073
   119
    nodeColors(composeMap(colorSet,colors)).
alpar@1073
   120
    edgeColors(composeMap(colorSet,ecolors)).
alpar@1073
   121
    edgeWidthScale(.4).edgeWidths(widths).
alpar@1073
   122
    nodeTexts(id).nodeTextSize(3).
alpar@1073
   123
    enableParallel().parEdgeDist(1.5);
alpar@1073
   124
alpar@1073
   125
  graphToEps(g,"graph_to_eps_demo_out_par_arr.eps").scale(10).coords(coords).
alpar@1073
   126
    nodeScale(2).nodeSizes(sizes).
alpar@1073
   127
    nodeColors(composeMap(colorSet,colors)).
alpar@1073
   128
    edgeColors(composeMap(colorSet,ecolors)).
alpar@1073
   129
    edgeWidthScale(.3).edgeWidths(widths).
alpar@1073
   130
    nodeTexts(id).nodeTextSize(3).
alpar@1073
   131
    enableParallel().parEdgeDist(1).
alpar@1073
   132
    drawArrows().arrowWidth(1).arrowLength(1);
alpar@1073
   133
}