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