[Lemon-commits] Alpar Juttner: Port Circulation from svn -r3516 ...
Lemon HG
hg at lemon.cs.elte.hu
Mon Dec 1 15:32:25 CET 2008
details: http://lemon.cs.elte.hu/hg/lemon/rev/5a7dbeaed70e
changeset: 414:5a7dbeaed70e
user: Alpar Juttner <alpar [at] cs.elte.hu>
date: Fri Nov 21 14:42:47 2008 +0000
description:
Port Circulation from svn -r3516 (#175) Namely,
- port the files
- apply the migrate script
- apply the unify script
- fix the compilation
- strip the demo input file
- break long lines
diffstat:
5 files changed, 799 insertions(+)
demo/Makefile.am | 3
demo/circulation-input.lgf | 32 ++
demo/circulation_demo.cc | 107 +++++++
lemon/Makefile.am | 1
lemon/circulation.h | 656 ++++++++++++++++++++++++++++++++++++++++++++
diffs (truncated from 841 to 300 lines):
diff -r fc6954b4fce4 -r 5a7dbeaed70e demo/Makefile.am
--- a/demo/Makefile.am Fri Nov 21 10:49:39 2008 +0000
+++ b/demo/Makefile.am Fri Nov 21 14:42:47 2008 +0000
@@ -1,16 +1,19 @@
EXTRA_DIST += \
demo/CMakeLists.txt \
+ demo/circulation-input.lgf \
demo/digraph.lgf
if WANT_DEMO
noinst_PROGRAMS += \
demo/arg_parser_demo \
+ demo/circulation_demo \
demo/graph_to_eps_demo \
demo/lgf_demo
endif WANT_DEMO
demo_arg_parser_demo_SOURCES = demo/arg_parser_demo.cc
+demo_circulation_demo_SOURCES = demo/circulation_demo.cc
demo_graph_to_eps_demo_SOURCES = demo/graph_to_eps_demo.cc
demo_lgf_demo_SOURCES = demo/lgf_demo.cc
diff -r fc6954b4fce4 -r 5a7dbeaed70e demo/circulation-input.lgf
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/demo/circulation-input.lgf Fri Nov 21 14:42:47 2008 +0000
@@ -0,0 +1,32 @@
+ at nodes
+coordinates_x coordinates_y delta label
+-396.638 -311.798 0 0
+154.409 -214.714 13 1
+-378.119 -135.808 0 2
+-138.182 -58.0452 0 3
+55 -76.1018 0 4
+-167.302 169.88 0 5
+71.6876 38.7452 0 6
+-328.784 257.777 0 7
+354.242 67.9628 -13 8
+147 266 0 9
+ at edges
+ label lo_cap up_cap
+0 1 0 0 20
+0 2 1 0 0
+1 1 2 0 3
+1 2 3 0 8
+1 3 4 0 8
+2 5 5 0 5
+3 2 6 0 5
+3 5 7 0 5
+3 6 8 0 5
+4 3 9 0 3
+5 7 10 0 3
+5 6 11 0 10
+5 8 12 0 10
+6 8 13 0 8
+8 9 14 0 20
+8 1 15 0 5
+9 5 16 0 5
+ at end
diff -r fc6954b4fce4 -r 5a7dbeaed70e demo/circulation_demo.cc
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/demo/circulation_demo.cc Fri Nov 21 14:42:47 2008 +0000
@@ -0,0 +1,107 @@
+/* -*- mode: C++; indent-tabs-mode: nil; -*-
+ *
+ * This file is a part of LEMON, a generic C++ optimization library.
+ *
+ * Copyright (C) 2003-2008
+ * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
+ * (Egervary Research Group on Combinatorial Optimization, EGRES).
+ *
+ * Permission to use, modify and distribute this software is granted
+ * provided that this copyright notice appears in all copies. For
+ * precise terms see the accompanying LICENSE file.
+ *
+ * This software is provided "AS IS" with no warranty of any kind,
+ * express or implied, and with no claim as to its suitability for any
+ * purpose.
+ *
+ */
+
+///\ingroup demos
+///\file
+///\brief Demonstrating the usage of LEMON's General Flow algorithm
+///
+/// This demo program reads a general network circulation problem from the
+/// file 'circulation-input.lgf', runs the preflow based algorithm for
+/// finding a feasible solution and writes the output
+/// to 'circulation-input.lgf'
+///
+/// \include circulation_demo.cc
+
+#include <iostream>
+
+#include <lemon/list_graph.h>
+#include <lemon/circulation.h>
+#include <lemon/lgf_reader.h>
+#include <lemon/lgf_writer.h>
+
+using namespace lemon;
+
+
+int main (int, char*[])
+{
+
+ typedef ListDigraph Digraph;
+ typedef Digraph::Node Node;
+ typedef Digraph::NodeIt NodeIt;
+ typedef Digraph::Arc Arc;
+ typedef Digraph::ArcIt ArcIt;
+ typedef Digraph::ArcMap<int> ArcMap;
+ typedef Digraph::NodeMap<int> NodeMap;
+ typedef Digraph::NodeMap<double> DNodeMap;
+
+ Digraph g;
+ ArcMap lo(g);
+ ArcMap up(g);
+ NodeMap delta(g);
+ NodeMap nid(g);
+ ArcMap eid(g);
+ DNodeMap cx(g);
+ DNodeMap cy(g);
+
+ DigraphReader<Digraph>(g,"circulation-input.lgf").
+ arcMap("lo_cap", lo).
+ arcMap("up_cap", up).
+ nodeMap("delta", delta).
+ arcMap("label", eid).
+ nodeMap("label", nid).
+ nodeMap("coordinates_x", cx).
+ nodeMap("coordinates_y", cy).
+ run();
+
+ Circulation<Digraph> gen(g,lo,up,delta);
+ bool ret=gen.run();
+ if(ret)
+ {
+ std::cout << "\nA feasible flow has been found.\n";
+ if(!gen.checkFlow()) std::cerr << "Oops!!!\n";
+ DigraphWriter<Digraph>(g, "circulation-output.lgf").
+ arcMap("lo_cap", lo).
+ arcMap("up_cap", up).
+ arcMap("flow", gen.flowMap()).
+ nodeMap("delta", delta).
+ arcMap("label", eid).
+ nodeMap("label", nid).
+ nodeMap("coordinates_x", cx).
+ nodeMap("coordinates_y", cy).
+ run();
+ }
+ else {
+ std::cout << "\nThere is no such a flow\n";
+ Digraph::NodeMap<int> bar(g);
+ gen.barrierMap(bar);
+ if(!gen.checkBarrier()) std::cerr << "Dual Oops!!!\n";
+
+ DigraphWriter<Digraph>(g, "circulation-output.lgf").
+ arcMap("lo_cap", lo).
+ arcMap("up_cap", up).
+ nodeMap("barrier", bar).
+ nodeMap("delta", delta).
+ arcMap("label", eid).
+ nodeMap("label", nid).
+ nodeMap("coordinates_x", cx).
+ nodeMap("coordinates_y", cy).
+ run();
+ }
+ std::cout << "The output is written to file 'circulation-output.lgf'\n\n";
+
+}
diff -r fc6954b4fce4 -r 5a7dbeaed70e lemon/Makefile.am
--- a/lemon/Makefile.am Fri Nov 21 10:49:39 2008 +0000
+++ b/lemon/Makefile.am Fri Nov 21 14:42:47 2008 +0000
@@ -20,6 +20,7 @@
lemon/assert.h \
lemon/bfs.h \
lemon/bin_heap.h \
+ lemon/circulation.h \
lemon/color.h \
lemon/concept_check.h \
lemon/counter.h \
diff -r fc6954b4fce4 -r 5a7dbeaed70e lemon/circulation.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lemon/circulation.h Fri Nov 21 14:42:47 2008 +0000
@@ -0,0 +1,656 @@
+/* -*- mode: C++; indent-tabs-mode: nil; -*-
+ *
+ * This file is a part of LEMON, a generic C++ optimization library.
+ *
+ * Copyright (C) 2003-2008
+ * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
+ * (Egervary Research Group on Combinatorial Optimization, EGRES).
+ *
+ * Permission to use, modify and distribute this software is granted
+ * provided that this copyright notice appears in all copies. For
+ * precise terms see the accompanying LICENSE file.
+ *
+ * This software is provided "AS IS" with no warranty of any kind,
+ * express or implied, and with no claim as to its suitability for any
+ * purpose.
+ *
+ */
+
+#ifndef LEMON_CIRCULATION_H
+#define LEMON_CIRCULATION_H
+
+#include <iostream>
+#include <queue>
+#include <lemon/tolerance.h>
+#include <lemon/elevator.h>
+
+///\ingroup max_flow
+///\file
+///\brief Push-prelabel algorithm for finding a feasible circulation.
+///
+namespace lemon {
+
+ /// \brief Default traits class of Circulation class.
+ ///
+ /// Default traits class of Circulation class.
+ /// \param _Graph Digraph type.
+ /// \param _CapacityMap Type of capacity map.
+ template <typename _Graph, typename _LCapMap,
+ typename _UCapMap, typename _DeltaMap>
+ struct CirculationDefaultTraits {
+
+ /// \brief The digraph type the algorithm runs on.
+ typedef _Graph Digraph;
+
+ /// \brief The type of the map that stores the circulation lower
+ /// bound.
+ ///
+ /// The type of the map that stores the circulation lower bound.
+ /// It must meet the \ref concepts::ReadMap "ReadMap" concept.
+ typedef _LCapMap LCapMap;
+
+ /// \brief The type of the map that stores the circulation upper
+ /// bound.
+ ///
+ /// The type of the map that stores the circulation upper bound.
+ /// It must meet the \ref concepts::ReadMap "ReadMap" concept.
+ typedef _UCapMap UCapMap;
+
+ /// \brief The type of the map that stores the upper bound of
+ /// node excess.
+ ///
+ /// The type of the map that stores the lower bound of node
+ /// excess. It must meet the \ref concepts::ReadMap "ReadMap"
+ /// concept.
+ typedef _DeltaMap DeltaMap;
+
+ /// \brief The type of the length of the arcs.
+ typedef typename DeltaMap::Value Value;
+
+ /// \brief The map type that stores the flow values.
+ ///
+ /// The map type that stores the flow values.
+ /// It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
+ typedef typename Digraph::template ArcMap<Value> FlowMap;
+
+ /// \brief Instantiates a FlowMap.
+ ///
+ /// This function instantiates a \ref FlowMap.
+ /// \param digraph The digraph, to which we would like to define
+ /// the flow map.
+ static FlowMap* createFlowMap(const Digraph& digraph) {
+ return new FlowMap(digraph);
+ }
+
+ /// \brief The eleavator type used by Circulation algorithm.
+ ///
+ /// The elevator type used by Circulation algorithm.
+ ///
+ /// \sa Elevator
+ /// \sa LinkedElevator
+ typedef lemon::Elevator<Digraph, typename Digraph::Node> Elevator;
+
+ /// \brief Instantiates an Elevator.
+ ///
+ /// This function instantiates a \ref Elevator.
+ /// \param digraph The digraph, to which we would like to define
+ /// the elevator.
+ /// \param max_level The maximum level of the elevator.
+ static Elevator* createElevator(const Digraph& digraph, int max_level) {
+ return new Elevator(digraph, max_level);
+ }
+
+ /// \brief The tolerance used by the algorithm
+ ///
+ /// The tolerance used by the algorithm to handle inexact computation.
+ typedef lemon::Tolerance<Value> Tolerance;
+
+ };
+
+ ///Push-relabel algorithm for the Network Circulation Problem.
+
+ /**
+ \ingroup max_flow
+ This class implements a push-relabel algorithm
+ or the Network Circulation Problem.
More information about the Lemon-commits
mailing list