[Lemon-commits] [lemon_svn] deba: r1892 - hugo/trunk/src/demo
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:48:30 CET 2006
Author: deba
Date: Sat May 14 19:40:45 2005
New Revision: 1892
Added:
hugo/trunk/src/demo/coloring.cc
Modified:
hugo/trunk/src/demo/Makefile.am
Log:
Six-coloring in plan graphs.
Modified: hugo/trunk/src/demo/Makefile.am
==============================================================================
--- hugo/trunk/src/demo/Makefile.am (original)
+++ hugo/trunk/src/demo/Makefile.am Sat May 14 19:40:45 2005
@@ -8,7 +8,8 @@
dim_to_lgf \
graph_to_eps_demo \
min_route \
- sub_graph_adaptor_demo
+ sub_graph_adaptor_demo \
+ coloring
if HAVE_GLPK
noinst_PROGRAMS += lp_demo lp_maxflow_demo
@@ -23,6 +24,8 @@
dim_to_lgf_SOURCES = dim_to_lgf.cc
+coloring_SOURCES = coloring.cc
+
graph_to_eps_demo_SOURCES = graph_to_eps_demo.cc
min_route_SOURCES = min_route.cc
Added: hugo/trunk/src/demo/coloring.cc
==============================================================================
--- (empty file)
+++ hugo/trunk/src/demo/coloring.cc Sat May 14 19:40:45 2005
@@ -0,0 +1,71 @@
+#include <vector>
+
+#include <lemon/smart_graph.h>
+#include <lemon/bin_heap.h>
+#include <lemon/graph_reader.h>
+#include <lemon/graph_to_eps.h>
+
+using namespace std;
+using namespace lemon;
+
+int main() {
+ typedef UndirSmartGraph Graph;
+ typedef Graph::Node Node;
+ typedef Graph::NodeIt NodeIt;
+ typedef Graph::UndirEdge UndirEdge;
+ typedef Graph::IncEdgeIt IncEdgeIt;
+
+ Graph graph;
+
+ UndirGraphReader<Graph> reader(std::cin, graph);
+ Graph::NodeMap<xy<double> > coords(graph);
+ reader.readNodeMap("coords", coords);
+
+ reader.run();
+
+ Graph::NodeMap<int> color(graph, -2);
+
+ Graph::NodeMap<int> heapMap(graph, -1);
+ BinHeap<Node, int, Graph::NodeMap<int> > heap(heapMap);
+
+ for (NodeIt it(graph); it != INVALID; ++it) {
+ heap.push(it, countOutEdges(graph, it));
+ }
+
+ vector<Node> order;
+
+ while (!heap.empty()) {
+ Node node = heap.top();
+ heap.pop();
+ color[node] = -1;
+ order.push_back(node);
+ for (IncEdgeIt it(graph, node); it != INVALID; ++it) {
+ Node target = graph.runningNode(it);
+ if (color[target] == -2) {
+ heap.decrease(target, heap[target] - 1);
+ }
+ }
+ }
+
+ for (int i = order.size() - 1; i >= 0; --i) {
+ set<int> forbidden;
+ for (IncEdgeIt it(graph, order[i]); it != INVALID; ++it) {
+ Node target = graph.runningNode(it);
+ if (color[target] != -1) {
+ forbidden.insert(color[target]);
+ }
+ }
+ int current = 0;
+ while (forbidden.find(current) != forbidden.end()) ++current;
+ color[order[i]] = current;
+ }
+
+ ColorSet colorSet;
+
+ graphToEps(graph, "six_coloring.eps").
+ title("Six Colored Graph").copyright("(C) 2005 LEMON Project").
+ coords(coords).nodeColors(composeMap(colorSet, color)).
+ scaleToA4().run();
+
+ return 0;
+}
More information about the Lemon-commits
mailing list