os/ossrv/ossrv_pub/boost_apis/boost/graph/wavefront.hpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
//
sl@0
     2
//=======================================================================
sl@0
     3
// Copyright 2002 Marc Wintermantel (wintermantel@even-ag.ch)
sl@0
     4
// ETH Zurich, Center of Structure Technologies (www.imes.ethz.ch/st)
sl@0
     5
//
sl@0
     6
// Distributed under the Boost Software License, Version 1.0. (See
sl@0
     7
// accompanying file LICENSE_1_0.txt or copy at
sl@0
     8
// http://www.boost.org/LICENSE_1_0.txt)
sl@0
     9
//=======================================================================
sl@0
    10
//
sl@0
    11
sl@0
    12
#ifndef BOOST_GRAPH_WAVEFRONT_HPP
sl@0
    13
#define BOOST_GRAPH_WAVEFRONT_HPP
sl@0
    14
sl@0
    15
#include <boost/config.hpp>
sl@0
    16
#include <boost/graph/graph_traits.hpp>
sl@0
    17
#include <boost/detail/numeric_traits.hpp>
sl@0
    18
#include <boost/graph/bandwidth.hpp>
sl@0
    19
#include <cmath>
sl@0
    20
#include <vector>
sl@0
    21
#include <algorithm> // for std::min and std::max
sl@0
    22
sl@0
    23
namespace boost {
sl@0
    24
sl@0
    25
  template <typename Graph, typename VertexIndexMap>
sl@0
    26
  typename graph_traits<Graph>::vertices_size_type
sl@0
    27
  ith_wavefront(typename graph_traits<Graph>::vertex_descriptor i,
sl@0
    28
                const Graph& g,
sl@0
    29
                VertexIndexMap index)
sl@0
    30
  {
sl@0
    31
    typename graph_traits<Graph>::vertex_descriptor v, w;
sl@0
    32
    typename graph_traits<Graph>::vertices_size_type b = 1;
sl@0
    33
    typename graph_traits<Graph>::out_edge_iterator edge_it2, edge_it2_end; 
sl@0
    34
    typename graph_traits<Graph>::vertices_size_type index_i = index[i];
sl@0
    35
    std::vector<bool> rows_active(num_vertices(g), false);
sl@0
    36
sl@0
    37
    rows_active[index_i] = true;
sl@0
    38
      
sl@0
    39
      typename graph_traits<Graph>::vertex_iterator ui, ui_end;
sl@0
    40
      for (tie(ui, ui_end) = vertices(g); ui != ui_end; ++ui)
sl@0
    41
      {
sl@0
    42
        v = *ui;
sl@0
    43
          if(index[v] <= index_i)
sl@0
    44
            {
sl@0
    45
              for (tie(edge_it2, edge_it2_end) = out_edges(v, g); edge_it2 != edge_it2_end; ++edge_it2)
sl@0
    46
              {
sl@0
    47
                w = target(*edge_it2, g);
sl@0
    48
                if( (index[w] >= index_i) && (!rows_active[index[w]]) )
sl@0
    49
                  {
sl@0
    50
                    b++;
sl@0
    51
                    rows_active[index[w]] = true;
sl@0
    52
                  }
sl@0
    53
              }
sl@0
    54
            }
sl@0
    55
      }
sl@0
    56
 
sl@0
    57
    return b;
sl@0
    58
  }
sl@0
    59
sl@0
    60
sl@0
    61
  template <typename Graph>
sl@0
    62
  typename graph_traits<Graph>::vertices_size_type
sl@0
    63
  ith_wavefront(typename graph_traits<Graph>::vertex_descriptor i,
sl@0
    64
                const Graph& g)
sl@0
    65
  {
sl@0
    66
    return ith_wavefront(i, g, get(vertex_index, g));
sl@0
    67
  }
sl@0
    68
sl@0
    69
sl@0
    70
  template <typename Graph, typename VertexIndexMap>
sl@0
    71
  typename graph_traits<Graph>::vertices_size_type
sl@0
    72
  max_wavefront(const Graph& g, VertexIndexMap index)
sl@0
    73
  {
sl@0
    74
    BOOST_USING_STD_MAX();
sl@0
    75
    typename graph_traits<Graph>::vertices_size_type b = 0;
sl@0
    76
    typename graph_traits<Graph>::vertex_iterator i, end;
sl@0
    77
    for (tie(i, end) = vertices(g); i != end; ++i)
sl@0
    78
      b = max BOOST_PREVENT_MACRO_SUBSTITUTION(b, ith_wavefront(*i, g, index));
sl@0
    79
    return b;
sl@0
    80
  }
sl@0
    81
sl@0
    82
  template <typename Graph>
sl@0
    83
  typename graph_traits<Graph>::vertices_size_type
sl@0
    84
  max_wavefront(const Graph& g)
sl@0
    85
  {
sl@0
    86
    return max_wavefront(g, get(vertex_index, g));
sl@0
    87
  }
sl@0
    88
sl@0
    89
sl@0
    90
  template <typename Graph, typename VertexIndexMap>
sl@0
    91
  double
sl@0
    92
  aver_wavefront(const Graph& g, VertexIndexMap index)
sl@0
    93
  {
sl@0
    94
    double b = 0;
sl@0
    95
    typename graph_traits<Graph>::vertex_iterator i, end;
sl@0
    96
    for (tie(i, end) = vertices(g); i != end; ++i)
sl@0
    97
      b += ith_wavefront(*i, g, index);
sl@0
    98
sl@0
    99
    b /= num_vertices(g);
sl@0
   100
    return b;
sl@0
   101
  }
sl@0
   102
sl@0
   103
  template <typename Graph>
sl@0
   104
  double
sl@0
   105
  aver_wavefront(const Graph& g)
sl@0
   106
  {
sl@0
   107
    return aver_wavefront(g, get(vertex_index, g));
sl@0
   108
  }
sl@0
   109
sl@0
   110
sl@0
   111
  template <typename Graph, typename VertexIndexMap>
sl@0
   112
  double
sl@0
   113
  rms_wavefront(const Graph& g, VertexIndexMap index)
sl@0
   114
  {
sl@0
   115
    double b = 0;
sl@0
   116
    typename graph_traits<Graph>::vertex_iterator i, end;
sl@0
   117
    for (tie(i, end) = vertices(g); i != end; ++i)
sl@0
   118
      b += std::pow(double ( ith_wavefront(*i, g, index) ), 2.0);
sl@0
   119
sl@0
   120
    b /= num_vertices(g);
sl@0
   121
sl@0
   122
    return std::sqrt(b);
sl@0
   123
  }
sl@0
   124
sl@0
   125
  template <typename Graph>
sl@0
   126
  double
sl@0
   127
  rms_wavefront(const Graph& g)
sl@0
   128
  {
sl@0
   129
    return rms_wavefront(g, get(vertex_index, g));
sl@0
   130
  }
sl@0
   131
 
sl@0
   132
  
sl@0
   133
} // namespace boost
sl@0
   134
sl@0
   135
#endif // BOOST_GRAPH_WAVEFRONT_HPP