[Lemon-commits] [lemon_svn] marci: r1253 - hugo/trunk/src/demo
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:44:11 CET 2006
Author: marci
Date: Thu Sep 30 19:32:00 2004
New Revision: 1253
Added:
hugo/trunk/src/demo/dim_to_dot.cc
- copied, changed from r1250, /hugo/trunk/src/demo/sub_graph_wrapper_demo.cc
Modified:
hugo/trunk/src/demo/sub_graph_wrapper_demo.cc
Log:
SubGraphWrapper code example, converter from dimacs to graphviz dot file.
The second one can be a tool for generating documentation of code examples.
Copied: hugo/trunk/src/demo/dim_to_dot.cc (from r1250, /hugo/trunk/src/demo/sub_graph_wrapper_demo.cc)
==============================================================================
--- /hugo/trunk/src/demo/sub_graph_wrapper_demo.cc (original)
+++ hugo/trunk/src/demo/dim_to_dot.cc Thu Sep 30 19:32:00 2004
@@ -1,20 +1,16 @@
// -*- c++ -*-
// Use a DIMACS max flow file as stdin.
-// sub_graph_wrapper_demo < dimacs_max_flow_file
-// This program computes a maximum number of edge-disjoint shortest paths
-// between s and t.
+// dim_to_dot < dimacs_max_flow_file > dot_output_file
+// This program makes a dot file from a dimacs max flow file.
+// This program can be an aid in making up to date visualized documantation
+// of demo programs.
#include <iostream>
#include <fstream>
#include <lemon/smart_graph.h>
-#include <lemon/dijkstra.h>
-#include <lemon/maps.h>
-#include <lemon/graph_wrapper.h>
#include <lemon/dimacs.h>
-#include <lemon/preflow.h>
-#include <lemon/tight_edge_filter_map.h>
using namespace lemon;
@@ -37,42 +33,27 @@
readDimacs(std::cin, g, length, s, t);
- cout << "edges with lengths (of form tail--length->head): " << endl;
- for(EdgeIt e(g); e!=INVALID; ++e)
- cout << " " << g.id(g.tail(e)) << "--"
- << length[e] << "->" << g.id(g.head(e)) << endl;
-
- cout << "s: " << g.id(s) << " t: " << g.id(t) << endl;
-
- typedef Dijkstra<Graph, LengthMap> Dijkstra;
- Dijkstra dijkstra(g, length);
- dijkstra.run(s);
-
- // This map returns true exactly for those edges which are
- // tight w.r.t the length funcion and the potential
- // given by the dijkstra algorithm.
- typedef TightEdgeFilterMap<Graph, const Dijkstra::DistMap, LengthMap>
- TightEdgeFilter;
- TightEdgeFilter tight_edge_filter(g, dijkstra.distMap(), length);
-
- ConstMap<Node, bool> const_true_map(true);
- // This graph contains exaclty the tight edges.
- typedef SubGraphWrapper<Graph, ConstMap<Node, bool>, TightEdgeFilter> SubGW;
- SubGW gw(g, const_true_map, tight_edge_filter);
-
- ConstMap<Edge, int> const_1_map(1);
- Graph::EdgeMap<int> flow(g, 0);
- // Max flow between s and t in the graph of tight edges.
- Preflow<SubGW, int, ConstMap<Edge, int>, Graph::EdgeMap<int> >
- preflow(gw, s, t, const_1_map, flow);
- preflow.run();
-
- cout << "edges of the maximum number of edge-disjoint shortest s-t paths: "
- << endl;
- for(EdgeIt e(g); e!=INVALID; ++e)
- if (flow[e])
- cout << " " << g.id(g.tail(e)) << "--"
- << length[e] << "->" << g.id(g.head(e)) << endl;
-
- return 0;
+ cout << "digraph lemon_dot_example {" << endl;
+ cout << " node [ shape=ellipse, fontname=Helvetica, fontsize=10 ];" << endl;
+ for(NodeIt n(g); n!=INVALID; ++n) {
+ if (n==s) {
+ cout << " n" << g.id(n)
+ << " [ label=\"" << g.id(n) << " (s)\" ]; " << endl;
+ } else {
+ if (n==t) {
+ cout << " n" << g.id(n)
+ << " [ label=\"" << g.id(n) << " (t)\" ]; " << endl;
+ } else {
+ cout << " n" << g.id(n)
+ << " [ label=\"" << g.id(n) << "\" ]; " << endl;
+ }
+ }
+ }
+ cout << " edge [ shape=ellipse, fontname=Helvetica, fontsize=10 ];" << endl;
+ for(EdgeIt e(g); e!=INVALID; ++e) {
+ cout << " n" << g.id(g.tail(e)) << " -> " << " n" << g.id(g.head(e))
+ << " [ label=\"" << g.id(e)
+ << ", length:" << length[e] << "\" ]; " << endl;
+ }
+ cout << "}" << endl;
}
Modified: hugo/trunk/src/demo/sub_graph_wrapper_demo.cc
==============================================================================
--- hugo/trunk/src/demo/sub_graph_wrapper_demo.cc (original)
+++ hugo/trunk/src/demo/sub_graph_wrapper_demo.cc Thu Sep 30 19:32:00 2004
@@ -14,7 +14,7 @@
#include <lemon/graph_wrapper.h>
#include <lemon/dimacs.h>
#include <lemon/preflow.h>
-#include <lemon/tight_edge_filter_map.h>
+#include <tight_edge_filter_map.h>
using namespace lemon;
@@ -37,9 +37,9 @@
readDimacs(std::cin, g, length, s, t);
- cout << "edges with lengths (of form tail--length->head): " << endl;
+ cout << "edges with lengths (of form id, tail--length->head): " << endl;
for(EdgeIt e(g); e!=INVALID; ++e)
- cout << " " << g.id(g.tail(e)) << "--"
+ cout << " " << g.id(e) << ", " << g.id(g.tail(e)) << "--"
<< length[e] << "->" << g.id(g.head(e)) << endl;
cout << "s: " << g.id(s) << " t: " << g.id(t) << endl;
@@ -67,12 +67,13 @@
preflow(gw, s, t, const_1_map, flow);
preflow.run();
+ cout << "maximum number of edge-disjoint shortest path: "
+ << preflow.flowValue() << endl;
cout << "edges of the maximum number of edge-disjoint shortest s-t paths: "
<< endl;
for(EdgeIt e(g); e!=INVALID; ++e)
if (flow[e])
- cout << " " << g.id(g.tail(e)) << "--"
+ cout << " " << g.id(e) << ", "
+ << g.id(g.tail(e)) << "--"
<< length[e] << "->" << g.id(g.head(e)) << endl;
-
- return 0;
}
More information about the Lemon-commits
mailing list