demo/graph_to_eps_demo.cc
changeset 214 60eecd3fe37a
parent 206 4e22275a2b52
child 211 542dd614cbb4
equal deleted inserted replaced
3:8638ae505a6b 4:1f7a72dfa261
     1 /* -*- C++ -*-
     1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
     2  *
     2  *
     3  * This file is a part of LEMON, a generic C++ optimization library
     3  * This file is a part of LEMON, a generic C++ optimization library.
     4  *
     4  *
     5  * Copyright (C) 2003-2008
     5  * Copyright (C) 2003-2008
     6  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     6  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     7  * (Egervary Research Group on Combinatorial Optimization, EGRES).
     7  * (Egervary Research Group on Combinatorial Optimization, EGRES).
     8  *
     8  *
    47   ListDigraph g;
    47   ListDigraph g;
    48   typedef ListDigraph::Node Node;
    48   typedef ListDigraph::Node Node;
    49   typedef ListDigraph::NodeIt NodeIt;
    49   typedef ListDigraph::NodeIt NodeIt;
    50   typedef ListDigraph::Arc Arc;
    50   typedef ListDigraph::Arc Arc;
    51   typedef dim2::Point<int> Point;
    51   typedef dim2::Point<int> Point;
    52   
    52 
    53   Node n1=g.addNode();
    53   Node n1=g.addNode();
    54   Node n2=g.addNode();
    54   Node n2=g.addNode();
    55   Node n3=g.addNode();
    55   Node n3=g.addNode();
    56   Node n4=g.addNode();
    56   Node n4=g.addNode();
    57   Node n5=g.addNode();
    57   Node n5=g.addNode();
    60   ListDigraph::NodeMap<double> sizes(g);
    60   ListDigraph::NodeMap<double> sizes(g);
    61   ListDigraph::NodeMap<int> colors(g);
    61   ListDigraph::NodeMap<int> colors(g);
    62   ListDigraph::NodeMap<int> shapes(g);
    62   ListDigraph::NodeMap<int> shapes(g);
    63   ListDigraph::ArcMap<int> acolors(g);
    63   ListDigraph::ArcMap<int> acolors(g);
    64   ListDigraph::ArcMap<int> widths(g);
    64   ListDigraph::ArcMap<int> widths(g);
    65   
    65 
    66   coords[n1]=Point(50,50);  sizes[n1]=1; colors[n1]=1; shapes[n1]=0;
    66   coords[n1]=Point(50,50);  sizes[n1]=1; colors[n1]=1; shapes[n1]=0;
    67   coords[n2]=Point(50,70);  sizes[n2]=2; colors[n2]=2; shapes[n2]=2;
    67   coords[n2]=Point(50,70);  sizes[n2]=2; colors[n2]=2; shapes[n2]=2;
    68   coords[n3]=Point(70,70);  sizes[n3]=1; colors[n3]=3; shapes[n3]=0;
    68   coords[n3]=Point(70,70);  sizes[n3]=1; colors[n3]=3; shapes[n3]=0;
    69   coords[n4]=Point(70,50);  sizes[n4]=2; colors[n4]=4; shapes[n4]=1;
    69   coords[n4]=Point(70,50);  sizes[n4]=2; colors[n4]=4; shapes[n4]=1;
    70   coords[n5]=Point(85,60);  sizes[n5]=3; colors[n5]=5; shapes[n5]=2;
    70   coords[n5]=Point(85,60);  sizes[n5]=3; colors[n5]=5; shapes[n5]=2;
    71   
    71 
    72   Arc a;
    72   Arc a;
    73 
    73 
    74   a=g.addArc(n1,n2); acolors[a]=0; widths[a]=1;
    74   a=g.addArc(n1,n2); acolors[a]=0; widths[a]=1;
    75   a=g.addArc(n2,n3); acolors[a]=0; widths[a]=1;
    75   a=g.addArc(n2,n3); acolors[a]=0; widths[a]=1;
    76   a=g.addArc(n3,n5); acolors[a]=0; widths[a]=3;
    76   a=g.addArc(n3,n5); acolors[a]=0; widths[a]=3;
    77   a=g.addArc(n5,n4); acolors[a]=0; widths[a]=1;
    77   a=g.addArc(n5,n4); acolors[a]=0; widths[a]=1;
    78   a=g.addArc(n4,n1); acolors[a]=0; widths[a]=1;
    78   a=g.addArc(n4,n1); acolors[a]=0; widths[a]=1;
    79   a=g.addArc(n2,n4); acolors[a]=1; widths[a]=2;
    79   a=g.addArc(n2,n4); acolors[a]=1; widths[a]=2;
    80   a=g.addArc(n3,n4); acolors[a]=2; widths[a]=1;
    80   a=g.addArc(n3,n4); acolors[a]=2; widths[a]=1;
    81   
    81 
    82   IdMap<ListDigraph,Node> id(g);
    82   IdMap<ListDigraph,Node> id(g);
    83 
    83 
    84   // Create five .eps files showing the digraph with different options
    84   // Create five .eps files showing the digraph with different options
    85   cout << "Create 'graph_to_eps_demo_out_1_pure.eps'" << endl;
    85   cout << "Create 'graph_to_eps_demo_out_1_pure.eps'" << endl;
    86   graphToEps(g,"graph_to_eps_demo_out_1_pure.eps").
    86   graphToEps(g,"graph_to_eps_demo_out_1_pure.eps").
   180 
   180 
   181   // Create an .eps file showing the colors of a default Palette
   181   // Create an .eps file showing the colors of a default Palette
   182   ListDigraph h;
   182   ListDigraph h;
   183   ListDigraph::NodeMap<int> hcolors(h);
   183   ListDigraph::NodeMap<int> hcolors(h);
   184   ListDigraph::NodeMap<Point> hcoords(h);
   184   ListDigraph::NodeMap<Point> hcoords(h);
   185   
   185 
   186   int cols=int(sqrt(double(palette.size())));
   186   int cols=int(sqrt(double(palette.size())));
   187   for(int i=0;i<int(paletteW.size());i++) {
   187   for(int i=0;i<int(paletteW.size());i++) {
   188     Node n=h.addNode();
   188     Node n=h.addNode();
   189     hcoords[n]=Point(1+i%cols,1+i/cols);
   189     hcoords[n]=Point(1+i%cols,1+i/cols);
   190     hcolors[n]=i;
   190     hcolors[n]=i;
   191   }
   191   }
   192   
   192 
   193   cout << "Create 'graph_to_eps_demo_out_6_colors.eps'" << endl;
   193   cout << "Create 'graph_to_eps_demo_out_6_colors.eps'" << endl;
   194   graphToEps(h,"graph_to_eps_demo_out_6_colors.eps").
   194   graphToEps(h,"graph_to_eps_demo_out_6_colors.eps").
   195     scale(60).
   195     scale(60).
   196     title("Sample .eps figure (Palette demo)").
   196     title("Sample .eps figure (Palette demo)").
   197     copyright("(C) 2003-2008 LEMON Project").
   197     copyright("(C) 2003-2008 LEMON Project").
   200     nodeScale(.45).
   200     nodeScale(.45).
   201     distantColorNodeTexts().
   201     distantColorNodeTexts().
   202     nodeTexts(hcolors).nodeTextSize(.6).
   202     nodeTexts(hcolors).nodeTextSize(.6).
   203     nodeColors(composeMap(paletteW,hcolors)).
   203     nodeColors(composeMap(paletteW,hcolors)).
   204     run();
   204     run();
   205     
   205 
   206   return 0;
   206   return 0;
   207 }
   207 }