Boost-Graph
view release on metacpan or search on metacpan
include/boost/graph/push_relabel_max_flow.hpp view on Meta::CPAN
//=======================================================================
// Copyright 2000 University of Notre Dame.
// Authors: Jeremy G. Siek, Andrew Lumsdaine, Lie-Quan Lee
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//=======================================================================
#ifndef BOOST_PUSH_RELABEL_MAX_FLOW_HPP
#define BOOST_PUSH_RELABEL_MAX_FLOW_HPP
#include <boost/config.hpp>
#include <cassert>
#include <vector>
#include <list>
#include <iosfwd>
#include <algorithm> // for std::min and std::max
#include <boost/pending/queue.hpp>
#include <boost/limits.hpp>
#include <boost/graph/graph_concepts.hpp>
#include <boost/graph/named_function_params.hpp>
namespace boost {
namespace detail {
// This implementation is based on Goldberg's
// "On Implementing Push-Relabel Method for the Maximum Flow Problem"
// by B.V. Cherkassky and A.V. Goldberg, IPCO '95, pp. 157--171
// and on the h_prf.c and hi_pr.c code written by the above authors.
// This implements the highest-label version of the push-relabel method
// with the global relabeling and gap relabeling heuristics.
// The terms "rank", "distance", "height" are synonyms in
// Goldberg's implementation, paper and in the CLR. A "layer" is a
// group of vertices with the same distance. The vertices in each
// layer are categorized as active or inactive. An active vertex
// has positive excess flow and its distance is less than n (it is
// not blocked).
template <class Vertex>
struct preflow_layer {
std::list<Vertex> active_vertices;
std::list<Vertex> inactive_vertices;
};
template <class Graph,
class EdgeCapacityMap, // integer value type
class ResidualCapacityEdgeMap,
class ReverseEdgeMap,
class VertexIndexMap, // vertex_descriptor -> integer
class FlowValue>
class push_relabel
{
public:
typedef graph_traits<Graph> Traits;
typedef typename Traits::vertex_descriptor vertex_descriptor;
typedef typename Traits::edge_descriptor edge_descriptor;
typedef typename Traits::vertex_iterator vertex_iterator;
typedef typename Traits::out_edge_iterator out_edge_iterator;
typedef typename Traits::vertices_size_type vertices_size_type;
typedef typename Traits::edges_size_type edges_size_type;
typedef preflow_layer<vertex_descriptor> Layer;
typedef std::vector< Layer > LayerArray;
typedef typename LayerArray::iterator layer_iterator;
typedef typename LayerArray::size_type distance_size_type;
typedef color_traits<default_color_type> ColorTraits;
//=======================================================================
// Some helper predicates
inline bool is_admissible(vertex_descriptor u, vertex_descriptor v) {
return distance[u] == distance[v] + 1;
}
inline bool is_residual_edge(edge_descriptor a) {
return 0 < residual_capacity[a];
}
inline bool is_saturated(edge_descriptor a) {
return residual_capacity[a] == 0;
}
//=======================================================================
// Layer List Management Functions
typedef typename std::list<vertex_descriptor>::iterator list_iterator;
void add_to_active_list(vertex_descriptor u, Layer& layer) {
BOOST_USING_STD_MIN();
BOOST_USING_STD_MAX();
layer.active_vertices.push_front(u);
max_active = max BOOST_PREVENT_MACRO_SUBSTITUTION(distance[u], max_active);
min_active = min BOOST_PREVENT_MACRO_SUBSTITUTION(distance[u], min_active);
layer_list_ptr[u] = layer.active_vertices.begin();
}
void remove_from_active_list(vertex_descriptor u) {
layers[distance[u]].active_vertices.erase(layer_list_ptr[u]);
}
( run in 0.453 second using v1.01-cache-2.11-cpan-39bf76dae61 )