alpar@209: /* -*- mode: C++; indent-tabs-mode: nil; -*-
alpar@128: *
alpar@209: * This file is a part of LEMON, a generic C++ optimization library.
alpar@128: *
alpar@463: * Copyright (C) 2003-2009
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
kpeter@206: /// \brief Demo of the graph drawing function \ref graphToEps()
alpar@128: ///
kpeter@211: /// This demo program shows examples how to use the function \ref
kpeter@211: /// graphToEps(). It takes no input but simply creates seven
alpar@128: /// .eps files demonstrating the capability of \ref
kpeter@206: /// 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
kpeter@313: /// using appropriate graph maps.
alpar@128: ///
alpar@128: /// \include graph_to_eps_demo.cc
alpar@128:
alpar@128: #include
kpeter@206: #include
kpeter@206: #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:
kpeter@206: // Create a small digraph
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@209:
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);
kpeter@206: ListDigraph::ArcMap acolors(g);
alpar@128: ListDigraph::ArcMap widths(g);
alpar@209:
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@209:
kpeter@206: Arc a;
alpar@128:
kpeter@206: a=g.addArc(n1,n2); acolors[a]=0; widths[a]=1;
kpeter@206: a=g.addArc(n2,n3); acolors[a]=0; widths[a]=1;
kpeter@206: a=g.addArc(n3,n5); acolors[a]=0; widths[a]=3;
kpeter@206: a=g.addArc(n5,n4); acolors[a]=0; widths[a]=1;
kpeter@206: a=g.addArc(n4,n1); acolors[a]=0; widths[a]=1;
kpeter@206: a=g.addArc(n2,n4); acolors[a]=1; widths[a]=2;
kpeter@206: a=g.addArc(n3,n4); acolors[a]=2; widths[a]=1;
alpar@209:
alpar@128: IdMap id(g);
alpar@128:
kpeter@211: // Create .eps files showing the digraph with different options
kpeter@206: cout << "Create 'graph_to_eps_demo_out_1_pure.eps'" << endl;
kpeter@206: graphToEps(g,"graph_to_eps_demo_out_1_pure.eps").
alpar@128: coords(coords).
alpar@128: title("Sample .eps figure").
alpar@463: copyright("(C) 2003-2009 LEMON Project").
alpar@128: run();
alpar@128:
kpeter@206: cout << "Create 'graph_to_eps_demo_out_2.eps'" << endl;
kpeter@206: graphToEps(g,"graph_to_eps_demo_out_2.eps").
alpar@128: coords(coords).
alpar@128: title("Sample .eps figure").
alpar@463: copyright("(C) 2003-2009 LEMON Project").
alpar@128: absoluteNodeSizes().absoluteArcWidths().
alpar@128: nodeScale(2).nodeSizes(sizes).
alpar@128: nodeShapes(shapes).
alpar@128: nodeColors(composeMap(palette,colors)).
kpeter@206: arcColors(composeMap(palette,acolors)).
alpar@128: arcWidthScale(.4).arcWidths(widths).
alpar@128: nodeTexts(id).nodeTextSize(3).
alpar@128: run();
alpar@128:
kpeter@206: cout << "Create 'graph_to_eps_demo_out_3_arr.eps'" << endl;
kpeter@206: graphToEps(g,"graph_to_eps_demo_out_3_arr.eps").
alpar@128: title("Sample .eps figure (with arrowheads)").
alpar@463: copyright("(C) 2003-2009 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).
kpeter@206: arcColors(composeMap(palette,acolors)).
alpar@128: arcWidthScale(.4).arcWidths(widths).
alpar@128: nodeTexts(id).nodeTextSize(3).
kpeter@206: drawArrows().arrowWidth(2).arrowLength(2).
alpar@128: run();
alpar@128:
kpeter@211: // Add more arcs to the digraph
kpeter@206: a=g.addArc(n1,n4); acolors[a]=2; widths[a]=1;
kpeter@206: a=g.addArc(n4,n1); acolors[a]=1; widths[a]=2;
alpar@128:
kpeter@206: a=g.addArc(n1,n2); acolors[a]=1; widths[a]=1;
kpeter@206: a=g.addArc(n1,n2); acolors[a]=2; widths[a]=1;
kpeter@206: a=g.addArc(n1,n2); acolors[a]=3; widths[a]=1;
kpeter@206: a=g.addArc(n1,n2); acolors[a]=4; widths[a]=1;
kpeter@206: a=g.addArc(n1,n2); acolors[a]=5; widths[a]=1;
kpeter@206: a=g.addArc(n1,n2); acolors[a]=6; widths[a]=1;
kpeter@206: a=g.addArc(n1,n2); acolors[a]=7; widths[a]=1;
alpar@128:
kpeter@211: cout << "Create 'graph_to_eps_demo_out_4_par.eps'" << endl;
kpeter@211: graphToEps(g,"graph_to_eps_demo_out_4_par.eps").
alpar@128: title("Sample .eps figure (parallel arcs)").
alpar@463: copyright("(C) 2003-2009 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)).
kpeter@206: arcColors(composeMap(palette,acolors)).
alpar@128: arcWidthScale(.4).arcWidths(widths).
alpar@128: nodeTexts(id).nodeTextSize(3).
alpar@128: enableParallel().parArcDist(1.5).
alpar@128: run();
kpeter@206:
kpeter@211: cout << "Create 'graph_to_eps_demo_out_5_par_arr.eps'" << endl;
kpeter@211: graphToEps(g,"graph_to_eps_demo_out_5_par_arr.eps").
alpar@128: title("Sample .eps figure (parallel arcs and arrowheads)").
alpar@463: copyright("(C) 2003-2009 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)).
kpeter@206: arcColors(composeMap(palette,acolors)).
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:
kpeter@211: cout << "Create 'graph_to_eps_demo_out_6_par_arr_a4.eps'" << endl;
kpeter@211: graphToEps(g,"graph_to_eps_demo_out_6_par_arr_a4.eps").
alpar@128: title("Sample .eps figure (fits to A4)").
alpar@463: copyright("(C) 2003-2009 LEMON Project").
kpeter@206: scaleToA4().
alpar@128: absoluteNodeSizes().absoluteArcWidths().
alpar@128: nodeScale(2).nodeSizes(sizes).
alpar@128: coords(coords).
alpar@128: nodeShapes(shapes).
alpar@128: nodeColors(composeMap(palette,colors)).
kpeter@206: arcColors(composeMap(palette,acolors)).
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:
kpeter@206: // Create an .eps file showing the colors of a default Palette
alpar@128: ListDigraph h;
alpar@128: ListDigraph::NodeMap hcolors(h);
alpar@128: ListDigraph::NodeMap hcoords(h);
alpar@209:
alpar@128: int cols=int(sqrt(double(palette.size())));
alpar@128: for(int i=0;i