11 Eylül 2017 Pazartesi

grap bgl_named_params

Giriş
Şu satırı dahil ederiz.
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/astar_search.hpp>
#include <boost/property_map/function_property_map.hpp>
#include <iostream>
weight_map metodu
Örnek
Şöyle yaparız
using Graph = boost::adjacency_list<>;

double stepTime(const Graph::vertex_descriptor& source,
                const Graph::vertex_descriptor& target,
                const std::vector<uint8_t>& elevation) {
  std::cout << source << ", " << target << ", {" << elevation.size() << " elements})\n";
  return 42;
}


Graph g(10);
add_edge(4, 5, g);
add_edge(2, 8, g);
add_edge(5, 1, g);
add_edge(1, 3, g);

std::vector<uint8_t> const elevation { 1,2,3,4,5,6 }; // or whatever

// custom weight map
auto custom = boost::make_function_property_map<Graph::edge_descriptor>(
  [&g,&elevation](Graph::edge_descriptor e) {
    return stepTime(boost::source(e, g), boost::target(e, g), elevation);
});

// pass it to an algorithm directly, or wrap it in a named-parameter object:
auto param = boost::weight_map(custom);
param.weight_map2(custom); // or as the alternative weight map

Hiç yorum yok:

Yorum Gönder