Documenatation of MapWin.
2 * demo/graph_orientation.cc - Part of LEMON, a generic C++ optimization library
4 * Copyright (C) 2006 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
5 * (Egervary Research Group on Combinatorial Optimization, EGRES).
7 * Permission to use, modify and distribute this software is granted
8 * provided that this copyright notice appears in all copies. For
9 * precise terms see the accompanying LICENSE file.
11 * This software is provided "AS IS" with no warranty of any kind,
12 * express or implied, and with no claim as to its suitability for any
18 #include <lemon/list_graph.h>
19 #include <lemon/graph_reader.h>
20 #include <lemon/iterable_maps.h>
22 #include <lemon/graph_to_eps.h>
25 using namespace lemon;
28 typedef ListGraph::Node Node;
29 typedef ListGraph::NodeIt NodeIt;
30 typedef ListGraph::Edge Edge;
31 typedef ListGraph::EdgeIt EdgeIt;
32 typedef ListGraph::OutEdgeIt OutEdgeIt;
33 typedef ListGraph::InEdgeIt InEdgeIt;
35 int main(int argc, char** argv)
38 std::cerr << "\n USAGE: " << argv[0]
39 << " input_file.lgf" << std::endl << std::endl;
40 std::cerr << " The file 'input_file.lgf' has to contain "
41 << "at least three node maps called \n 'f', 'coordinates_x' "
42 << "and 'coordinates_y'.\n"
43 << " The in-degree requirement is given by 'f', while the two "
44 << "others is used\n to create to output drawing."
51 ListGraph::NodeMap<int> f(g); //in-deg requirement;
52 ListGraph::NodeMap<int> id(g);
53 ListGraph::NodeMap<xy<double> > coords(g);
56 GraphReader<ListGraph> reader(argv[1],g);
57 reader.readNodeMap("f",f);
58 reader.readNodeMap("id",id);
59 reader.readNodeMap("coordinates_x",xMap(coords));
60 reader.readNodeMap("coordinates_y",yMap(coords));
62 } catch (DataFormatError& error) {
63 std::cerr << error.what() << std::endl;
68 ListGraph::NodeMap<int> level(g,0);
70 ListGraph::NodeMap<int> def(g); //deficiency of the nodes
71 def = subMap(f,InDegMap<ListGraph>(g));
73 IterableBoolNodeMap<ListGraph> active(g,false);
74 for(NodeIt n(g);n!=INVALID;++n) active[n]=(def[n]>0);
76 ListGraph::EdgeMap<bool> rev(g,false); // rev[e]==true <=> e is be
79 int nodeNum=countNodes(g);
82 while((act=IterableBoolNodeMap<ListGraph>::TrueIt(active))!=INVALID) {
83 std::cout << "Process node " << id[act]
84 << " (def=" << def[act]
85 << " lev=" << level[act] << "): ";
87 while(e!=INVALID && level[g.target(e)]>=level[act]) ++e;
89 std::cout << " REVERT EDGE " << g.id(e)
90 << " (" << id[g.source(e)] << "---"
91 << id[g.target(e)] << ")"
93 if(--def[act]==0) active[act]=false;
94 if(++def[g.target(e)]>0) active[g.target(e)]=true;
99 std::cout << " LIFT" << std::endl;
100 if(++level[act]>nodeNum) {
101 std::cout << "NINCS ILYEN\n";
109 graphToEps(g,"graph_orientation.eps").scaleToA4().
110 title("Sample .eps figure (fits to A4)").
111 copyright("(C) 2006 LEMON Project").
115 edgeColors(composeMap(ColorSet(),rev)).
117 nodeTexts(f).nodeTextSize(20).
118 drawArrows().arrowWidth(10).arrowLength(10).