3 * This file is a part of LEMON, a generic C++ optimization library
5 * Copyright (C) 2003-2008
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
9 * Permission to use, modify and distribute this software is granted
10 * provided that this copyright notice appears in all copies. For
11 * precise terms see the accompanying LICENSE file.
13 * This software is provided "AS IS" with no warranty of any kind,
14 * express or implied, and with no claim as to its suitability for any
19 #include <lemon/list_graph.h>
20 #include <lemon/graph_reader.h>
21 #include <lemon/iterable_maps.h>
22 #include <lemon/dim2.h>
23 #include <lemon/graph_to_eps.h>
26 using namespace lemon;
28 GRAPH_TYPEDEFS(ListGraph);
30 int main(int argc, char** argv)
33 std::cerr << "\n USAGE: " << argv[0]
34 << " input_file.lgf" << std::endl << std::endl;
35 std::cerr << " The file 'input_file.lgf' has to contain "
36 << "at least three node maps called \n 'f', 'coordinates_x' "
37 << "and 'coordinates_y'.\n"
38 << " The in-degree requirement is given by 'f', while the two "
39 << "others is used\n to create to output drawing."
46 ListGraph::NodeMap<int> f(g); //in-deg requirement;
47 ListGraph::NodeMap<int> label(g);
48 ListGraph::NodeMap<dim2::Point<double> > coords(g);
51 GraphReader<ListGraph> reader(argv[1],g);
52 reader.readNodeMap("f",f);
53 reader.readNodeMap("label",label);
54 reader.readNodeMap("coordinates_x",xMap(coords));
55 reader.readNodeMap("coordinates_y",yMap(coords));
57 } catch (DataFormatError& error) {
58 std::cerr << error.what() << std::endl;
63 ListGraph::NodeMap<int> level(g,0);
65 ListGraph::NodeMap<int> def(g); //deficiency of the nodes
66 def = subMap(f,InDegMap<ListGraph>(g));
68 IterableBoolMap<ListGraph, Node> active(g,false);
69 for(NodeIt n(g);n!=INVALID;++n) active[n]=(def[n]>0);
71 ListGraph::EdgeMap<bool> rev(g,false); // rev[e]==true <=> e is to be
74 int nodeNum=countNodes(g);
77 while((act=IterableBoolMap<ListGraph, Node>::TrueIt(active))!=INVALID) {
78 std::cout << "Process node " << label[act]
79 << " (def=" << def[act]
80 << " lev=" << level[act] << "): ";
82 while(e!=INVALID && level[g.target(e)]>=level[act]) ++e;
84 std::cout << " REVERT EDGE " << g.id(e)
85 << " (" << label[g.source(e)] << "---"
86 << label[g.target(e)] << ")"
88 if(--def[act]==0) active[act]=false;
89 if(++def[g.target(e)]>0) active[g.target(e)]=true;
94 std::cout << " LIFT" << std::endl;
95 if(++level[act]>nodeNum) {
96 std::cout << "NINCS ILYEN\n";
104 graphToEps(g,"graph_orientation.eps").scaleToA4().
105 title("Sample .eps figure (fits to A4)").
106 copyright("(C) 2003-2007 LEMON Project").
107 absoluteNodeSizes().absoluteEdgeWidths().
111 edgeColors(composeMap(Palette(),rev)).
113 nodeTexts(f).nodeTextSize(20).
114 drawArrows().arrowWidth(10).arrowLength(10).