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