alpar@128: /* -*- C++ -*-
alpar@128: *
alpar@128: * This file is a part of LEMON, a generic C++ optimization library
alpar@128: *
alpar@128: * Copyright (C) 2003-2008
alpar@128: * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@128: * (Egervary Research Group on Combinatorial Optimization, EGRES).
alpar@128: *
alpar@128: * Permission to use, modify and distribute this software is granted
alpar@128: * provided that this copyright notice appears in all copies. For
alpar@128: * precise terms see the accompanying LICENSE file.
alpar@128: *
alpar@128: * This software is provided "AS IS" with no warranty of any kind,
alpar@128: * express or implied, and with no claim as to its suitability for any
alpar@128: * purpose.
alpar@128: *
alpar@128: */
alpar@128:
alpar@128: /// \ingroup demos
alpar@128: /// \file
alpar@128: /// \brief Demo of the graph grawing function \ref graphToEps()
alpar@128: ///
alpar@128: /// This demo program shows examples how to use the function \ref
alpar@128: /// graphToEps(). It takes no input but simply creates six
alpar@128: /// .eps files demonstrating the capability of \ref
alpar@128: /// graphToEps(), and showing how to draw directed/graphs,
alpar@128: /// how to handle parallel egdes, how to change the properties (like
alpar@128: /// color, shape, size, title etc.) of nodes and arcs individually
alpar@128: /// using appropriate \ref maps-page "graph maps".
alpar@128: ///
alpar@128: /// \include graph_to_eps_demo.cc
alpar@128:
alpar@128: #include
alpar@128:
alpar@128: #include
alpar@128: #include
alpar@128: #include
alpar@128:
alpar@128: using namespace std;
alpar@128: using namespace lemon;
alpar@128:
alpar@128: int main()
alpar@128: {
alpar@128: Palette palette;
alpar@129: Palette paletteW(true);
alpar@128:
alpar@128: ListDigraph g;
alpar@128: typedef ListDigraph::Node Node;
alpar@128: typedef ListDigraph::NodeIt NodeIt;
alpar@128: typedef ListDigraph::Arc Arc;
alpar@128: typedef dim2::Point Point;
alpar@128:
alpar@128: Node n1=g.addNode();
alpar@128: Node n2=g.addNode();
alpar@128: Node n3=g.addNode();
alpar@128: Node n4=g.addNode();
alpar@128: Node n5=g.addNode();
alpar@128:
alpar@128: ListDigraph::NodeMap coords(g);
alpar@128: ListDigraph::NodeMap sizes(g);
alpar@128: ListDigraph::NodeMap colors(g);
alpar@128: ListDigraph::NodeMap shapes(g);
alpar@128: ListDigraph::ArcMap ecolors(g);
alpar@128: ListDigraph::ArcMap widths(g);
alpar@128:
alpar@128: coords[n1]=Point(50,50); sizes[n1]=1; colors[n1]=1; shapes[n1]=0;
alpar@128: coords[n2]=Point(50,70); sizes[n2]=2; colors[n2]=2; shapes[n2]=2;
alpar@128: coords[n3]=Point(70,70); sizes[n3]=1; colors[n3]=3; shapes[n3]=0;
alpar@128: coords[n4]=Point(70,50); sizes[n4]=2; colors[n4]=4; shapes[n4]=1;
alpar@128: coords[n5]=Point(85,60); sizes[n5]=3; colors[n5]=5; shapes[n5]=2;
alpar@128:
alpar@128: Arc e;
alpar@128:
alpar@128: e=g.addArc(n1,n2); ecolors[e]=0; widths[e]=1;
alpar@128: e=g.addArc(n2,n3); ecolors[e]=0; widths[e]=1;
alpar@128: e=g.addArc(n3,n5); ecolors[e]=0; widths[e]=3;
alpar@128: e=g.addArc(n5,n4); ecolors[e]=0; widths[e]=1;
alpar@128: e=g.addArc(n4,n1); ecolors[e]=0; widths[e]=1;
alpar@128: e=g.addArc(n2,n4); ecolors[e]=1; widths[e]=2;
alpar@128: e=g.addArc(n3,n4); ecolors[e]=2; widths[e]=1;
alpar@128:
alpar@128: IdMap id(g);
alpar@128:
alpar@128: cout << "Create 'graph_to_eps_demo_out_pure.eps'" << endl;
alpar@128: graphToEps(g,"graph_to_eps_demo_out_pure.eps").
alpar@128: //scale(10).
alpar@128: coords(coords).
alpar@128: title("Sample .eps figure").
alpar@128: copyright("(C) 2003-2007 LEMON Project").
alpar@128: run();
alpar@128:
alpar@128: cout << "Create 'graph_to_eps_demo_out.eps'" << endl;
alpar@128: graphToEps(g,"graph_to_eps_demo_out.eps").
alpar@128: //scale(10).
alpar@128: coords(coords).
alpar@128: title("Sample .eps figure").
alpar@128: copyright("(C) 2003-2007 LEMON Project").
alpar@128: absoluteNodeSizes().absoluteArcWidths().
alpar@128: nodeScale(2).nodeSizes(sizes).
alpar@128: nodeShapes(shapes).
alpar@128: nodeColors(composeMap(palette,colors)).
alpar@128: arcColors(composeMap(palette,ecolors)).
alpar@128: arcWidthScale(.4).arcWidths(widths).
alpar@128: nodeTexts(id).nodeTextSize(3).
alpar@128: run();
alpar@128:
alpar@128:
alpar@128: cout << "Create 'graph_to_eps_demo_out_arr.eps'" << endl;
alpar@128: graphToEps(g,"graph_to_eps_demo_out_arr.eps").
alpar@128: //scale(10).
alpar@128: title("Sample .eps figure (with arrowheads)").
alpar@128: copyright("(C) 2003-2007 LEMON Project").
alpar@128: absoluteNodeSizes().absoluteArcWidths().
alpar@128: nodeColors(composeMap(palette,colors)).
alpar@128: coords(coords).
alpar@128: nodeScale(2).nodeSizes(sizes).
alpar@128: nodeShapes(shapes).
alpar@128: arcColors(composeMap(palette,ecolors)).
alpar@128: arcWidthScale(.4).arcWidths(widths).
alpar@128: nodeTexts(id).nodeTextSize(3).
alpar@128: drawArrows().arrowWidth(1).arrowLength(1).
alpar@128: run();
alpar@128:
alpar@128: e=g.addArc(n1,n4); ecolors[e]=2; widths[e]=1;
alpar@128: e=g.addArc(n4,n1); ecolors[e]=1; widths[e]=2;
alpar@128:
alpar@128: e=g.addArc(n1,n2); ecolors[e]=1; widths[e]=1;
alpar@128: e=g.addArc(n1,n2); ecolors[e]=2; widths[e]=1;
alpar@128: e=g.addArc(n1,n2); ecolors[e]=3; widths[e]=1;
alpar@128: e=g.addArc(n1,n2); ecolors[e]=4; widths[e]=1;
alpar@128: e=g.addArc(n1,n2); ecolors[e]=5; widths[e]=1;
alpar@128: e=g.addArc(n1,n2); ecolors[e]=6; widths[e]=1;
alpar@128: e=g.addArc(n1,n2); ecolors[e]=7; widths[e]=1;
alpar@128:
alpar@128: cout << "Create 'graph_to_eps_demo_out_par.eps'" << endl;
alpar@128: graphToEps(g,"graph_to_eps_demo_out_par.eps").
alpar@128: //scale(10).
alpar@128: title("Sample .eps figure (parallel arcs)").
alpar@128: copyright("(C) 2003-2007 LEMON Project").
alpar@128: absoluteNodeSizes().absoluteArcWidths().
alpar@128: nodeShapes(shapes).
alpar@128: coords(coords).
alpar@128: nodeScale(2).nodeSizes(sizes).
alpar@128: nodeColors(composeMap(palette,colors)).
alpar@128: arcColors(composeMap(palette,ecolors)).
alpar@128: arcWidthScale(.4).arcWidths(widths).
alpar@128: nodeTexts(id).nodeTextSize(3).
alpar@128: enableParallel().parArcDist(1.5).
alpar@128: run();
alpar@128:
alpar@128: cout << "Create 'graph_to_eps_demo_out_par_arr.eps'" << endl;
alpar@128: graphToEps(g,"graph_to_eps_demo_out_par_arr.eps").
alpar@128: //scale(10).
alpar@128: title("Sample .eps figure (parallel arcs and arrowheads)").
alpar@128: copyright("(C) 2003-2007 LEMON Project").
alpar@128: absoluteNodeSizes().absoluteArcWidths().
alpar@128: nodeScale(2).nodeSizes(sizes).
alpar@128: coords(coords).
alpar@128: nodeShapes(shapes).
alpar@128: nodeColors(composeMap(palette,colors)).
alpar@128: arcColors(composeMap(palette,ecolors)).
alpar@128: arcWidthScale(.3).arcWidths(widths).
alpar@128: nodeTexts(id).nodeTextSize(3).
alpar@128: enableParallel().parArcDist(1).
alpar@128: drawArrows().arrowWidth(1).arrowLength(1).
alpar@128: run();
alpar@128:
alpar@128: cout << "Create 'graph_to_eps_demo_out_a4.eps'" << endl;
alpar@128: graphToEps(g,"graph_to_eps_demo_out_a4.eps").scaleToA4().
alpar@128: title("Sample .eps figure (fits to A4)").
alpar@128: copyright("(C) 2003-2007 LEMON Project").
alpar@128: absoluteNodeSizes().absoluteArcWidths().
alpar@128: nodeScale(2).nodeSizes(sizes).
alpar@128: coords(coords).
alpar@128: nodeShapes(shapes).
alpar@128: nodeColors(composeMap(palette,colors)).
alpar@128: arcColors(composeMap(palette,ecolors)).
alpar@128: arcWidthScale(.3).arcWidths(widths).
alpar@128: nodeTexts(id).nodeTextSize(3).
alpar@128: enableParallel().parArcDist(1).
alpar@128: drawArrows().arrowWidth(1).arrowLength(1).
alpar@128: run();
alpar@128:
alpar@128: ListDigraph h;
alpar@128: ListDigraph::NodeMap hcolors(h);
alpar@128: ListDigraph::NodeMap hcoords(h);
alpar@128:
alpar@128: int cols=int(sqrt(double(palette.size())));
alpar@128: for(int i=0;i