alpar@1073: /* -*- C++ -*- alpar@1073: * src/lemon/demo/graph_to_eps.cc - alpar@1073: * Part of LEMON, a generic C++ optimization library alpar@1073: * alpar@1073: * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport alpar@1073: * (Egervary Combinatorial Optimization Research Group, 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@1073: #include alpar@1073: #include alpar@1073: #include alpar@1073: alpar@1073: alpar@1073: using namespace std; alpar@1073: using namespace lemon; alpar@1073: alpar@1073: class ColorSet : public MapBase alpar@1073: { alpar@1073: public: alpar@1073: Color operator[](int i) const alpar@1073: { alpar@1073: switch(i%8){ alpar@1073: case 0: return Color(0,0,0); alpar@1073: case 1: return Color(1,0,0); alpar@1073: case 2: return Color(0,1,0); alpar@1073: case 3: return Color(0,0,1); alpar@1073: case 4: return Color(1,1,0); alpar@1073: case 5: return Color(1,0,1); alpar@1073: case 6: return Color(0,1,1); alpar@1073: case 7: return Color(1,1,1); alpar@1073: } alpar@1073: return Color(0,0,0); alpar@1073: } alpar@1073: } colorSet; alpar@1073: alpar@1073: class IdMap :public MapBase alpar@1073: { alpar@1073: const ListGraph &g; alpar@1073: public: alpar@1073: IdMap(const ListGraph &_g) :g(_g) {} alpar@1073: Value operator[](Key n) const { return g.id(n); } alpar@1073: }; alpar@1073: alpar@1073: int main() alpar@1073: { alpar@1073: ListGraph g; alpar@1073: typedef ListGraph::Node Node; alpar@1073: typedef ListGraph::NodeIt NodeIt; alpar@1073: typedef ListGraph::Edge Edge; alpar@1073: typedef xy Xy; 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@1073: 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@1086: coords[n1]=Xy(50,50); sizes[n1]=1; colors[n1]=1; shapes[n1]=0; alpar@1088: coords[n2]=Xy(50,70); sizes[n2]=2; colors[n2]=2; shapes[n2]=2; alpar@1086: coords[n3]=Xy(70,70); sizes[n3]=1; colors[n3]=3; shapes[n3]=0; alpar@1086: coords[n4]=Xy(70,50); sizes[n4]=2; colors[n4]=4; shapes[n4]=1; alpar@1088: coords[n5]=Xy(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@1073: IdMap id(g); alpar@1073: alpar@1073: graphToEps(g,"graph_to_eps_demo_out.eps").scale(10).coords(coords). alpar@1073: nodeScale(2).nodeSizes(sizes). alpar@1086: nodeShapes(shapes). alpar@1073: nodeColors(composeMap(colorSet,colors)). alpar@1073: edgeColors(composeMap(colorSet,ecolors)). alpar@1073: edgeWidthScale(.4).edgeWidths(widths). alpar@1073: nodeTexts(id).nodeTextSize(3); alpar@1073: alpar@1073: graphToEps(g,"graph_to_eps_demo_out_arr.eps").scale(10).coords(coords). alpar@1073: nodeScale(2).nodeSizes(sizes). alpar@1086: nodeShapes(shapes). alpar@1073: nodeColors(composeMap(colorSet,colors)). alpar@1073: edgeColors(composeMap(colorSet,ecolors)). alpar@1073: edgeWidthScale(.4).edgeWidths(widths). alpar@1073: nodeTexts(id).nodeTextSize(3). alpar@1073: drawArrows().arrowWidth(1).arrowLength(1); 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@1073: graphToEps(g,"graph_to_eps_demo_out_par.eps").scale(10).coords(coords). alpar@1073: nodeScale(2).nodeSizes(sizes). alpar@1086: nodeShapes(shapes). alpar@1073: nodeColors(composeMap(colorSet,colors)). alpar@1073: edgeColors(composeMap(colorSet,ecolors)). alpar@1073: edgeWidthScale(.4).edgeWidths(widths). alpar@1073: nodeTexts(id).nodeTextSize(3). alpar@1073: enableParallel().parEdgeDist(1.5); alpar@1073: alpar@1073: graphToEps(g,"graph_to_eps_demo_out_par_arr.eps").scale(10).coords(coords). alpar@1073: nodeScale(2).nodeSizes(sizes). alpar@1086: nodeShapes(shapes). alpar@1073: nodeColors(composeMap(colorSet,colors)). alpar@1073: edgeColors(composeMap(colorSet,ecolors)). alpar@1073: edgeWidthScale(.3).edgeWidths(widths). alpar@1073: nodeTexts(id).nodeTextSize(3). alpar@1073: enableParallel().parEdgeDist(1). alpar@1086: // hideNodes(). alpar@1073: drawArrows().arrowWidth(1).arrowLength(1); alpar@1073: }