All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Pages
contract_bgl_adjacency_matrix.hpp
Go to the documentation of this file.
1 //=======================================================================
2 // Copyright (c) 2013 Piotr Wygocki
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 //=======================================================================
15 #ifndef PAAL_CONTRACT_BGL_ADJACENCY_MATRIX_HPP
16 #define PAAL_CONTRACT_BGL_ADJACENCY_MATRIX_HPP
17 
20 
21 #include <boost/functional/hash.hpp>
22 #include <boost/graph/adjacency_matrix.hpp>
23 #include <boost/range/as_array.hpp>
24 
25 namespace paal {
26 namespace utils {
27 
29 template <typename Idx, typename... GraphArgs>
30 void contract(boost::adjacency_matrix<GraphArgs...> &amatrix,
31  Idx v, Idx w) {
32  typedef boost::graph_traits<puretype(amatrix)> mtraits;
33  typedef typename mtraits::edge_descriptor MEdge;
34  auto const &weight_map = get(boost::edge_weight, amatrix);
35  weight_map[edge(v, w, amatrix).first] = 0;
36  for (auto && e : boost::as_array(out_edges(v, amatrix))) {
37  MEdge f = edge(w, target(e, amatrix), amatrix).first;
38  auto &we = weight_map[e];
39  auto &wf = weight_map[f];
40  wf = we = std::min(we, wf);
41 
42  // TODO hide checking
43  auto teste = edge(target(e, amatrix), w, amatrix).first;
44  auto testf = edge(target(e, amatrix), v, amatrix).first;
45  auto wte = weight_map[teste];
46  auto wtf = weight_map[testf];
47  assert(wte == wtf && wte == we);
48  }
49 }
50 }
51 }
52 #endif // PAAL_CONTRACT_BGL_ADJACENCY_MATRIX_HPP
void contract(boost::adjacency_matrix< GraphArgs...> &amatrix, Idx v, Idx w)
contracts to vertices in adjacency_matrix