Input file for coloring.
5 \file graph_orientation.cc
6 \brief Graph orientation with lower bound requirement on the
7 in-degree of the nodes.
11 First we include some important headers.
13 The first one defines \ref lemon::ListGraph "ListGraph",
14 the "Swiss army knife" graph implementation.
15 \dontinclude graph_orientation.cc
18 The next is to read a \ref graph-io-page ".lgf" (Lemon Graph Format) file.
21 This provides us with some special purpose graph \ref maps "maps".
24 The following header defines a simple data structure to store and manipulate
25 planar coordinates. It will be used to draw the result.
28 And finally, this header contains a simple graph drawing utility.
31 As we don't want to type in \ref lemon "lemon::" million times, the
32 following line seems to be useful.
35 The following <tt>typedef</tt>s will also save a lot of typing.
39 Well, we are ready to start <tt>main()</tt>.
43 First we check whether the program is called with exactly 1 parameter.
44 If it isn't, we print a short help message end exit.
45 The vast majority of people would probably skip this block.
49 Now, we read a graph \c g, and a map \c f containing
50 the in-deg requirements from a \ref graph-io-page ".lgf" (Lemon Graph Format)
51 file. To generate the output picture, we also read the node titles (\c id) and
52 coordinates (\c coords).
53 So, first we create the graph
55 and the corresponding NodeMaps.
58 \note The graph must be given to the maps' constructor.
60 Then, the following block will read these data from the file, or exit if
61 the file is missing or corrupt.
66 The algorithm needs a "level" integer value assigned to each node. In the
67 beginning, the nodes are on level 0.
70 The deficiency (\c def) of a node is the in-degree requirement minus the
76 A node is \e active if its deficiency is positive (i.e. if it doesn't meet
77 the degree requirement).
81 We also store in a bool map which edges are reverted. Actually this is only
82 used to draw these edges with different color in the output picture. The
83 algorithm will update this map called \c rev, but will not use it otherwise.
87 The variable \c nodeNum will refer to the number of nodes.
90 Here comes the algorithms itself.
91 In each iteration we choose an active node (\c act will store it). If there is
92 no such a node, then the orientation is feasible so we are done.
96 Then we check if there exists an edge leaving this node that steps down exactly
101 If there exists, we decrease the "activity" of the node \c act by reverting
103 Fortunately, \ref lemon::ListGraph "ListGraph"
104 has a special function \ref lemon::ListGraph::reverseEdge() "reverseEdge()"
105 that makes this easy.
106 We also have to update the maps \c def and
111 Otherwise (i.e. if there is no edge stepping down one level). We lift up the
112 current active node \c act. If it reaches level \c nodeNum, then there
113 exists no appropriate orientation so we stop.
121 Believe it or not, this algorithm works and runs fast.
123 Finally, we print the obtained orientation. Note, how the different
125 \c rev are transformed into different \ref lemon::Color "RGB color"s
127 \ref lemon::ColorSet "ColorSet"
128 and the \ref map_adaptors "map adaptor" called
129 \ref lemon::ComposeMap "composeMap".
137 Finally here are again the list of the used include files (because I can't turn