SHARE
TWEET

Untitled

a guest Jun 18th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Graph g(10); // graph with 10 nodes
  2. cin>>a>>b>>weight1>>weight2>>weight3>>weight4;
  3.      
  4. #include <boost/property_map/function_property_map.hpp>
  5. #include <iostream>
  6.  
  7. struct weights_t {
  8.     float weight1, weight2, weight3, weight4;
  9. };
  10.  
  11. using namespace boost;
  12.  
  13. int main() {
  14.     std::vector<weights_t> weight_data { // index is vertex id
  15.         { 1,2,3,4 },
  16.         { 5,6,7,8 },
  17.         { 9,10,11,12 },
  18.         { 13,14,15,16 },
  19.     };
  20.  
  21.     auto wmap1 = make_function_property_map<unsigned, float>([&weight_data](unsigned vertex_id) { return weight_data.at(vertex_id).weight1; });
  22.     auto wmap2 = make_function_property_map<unsigned, float>([&weight_data](unsigned vertex_id) { return weight_data.at(vertex_id).weight2; });
  23.     auto wmap3 = make_function_property_map<unsigned, float>([&weight_data](unsigned vertex_id) { return weight_data.at(vertex_id).weight3; });
  24.     auto wmap4 = make_function_property_map<unsigned, float>([&weight_data](unsigned vertex_id) { return weight_data.at(vertex_id).weight4; });
  25.  
  26.     for (unsigned vertex = 0; vertex < weight_data.size(); ++vertex)
  27.         std::cout << wmap1[vertex] << "t" << wmap2[vertex] << "t" << wmap3[vertex] << "t"<< wmap4[vertex] << "n";
  28. }
  29.      
  30. #include <boost/property_map/transform_value_property_map.hpp>
  31. #include <iostream>
  32.  
  33. struct weights_t {
  34.     float weight1, weight2, weight3, weight4;
  35.  
  36.     weights_t(float w1, float w2, float w3, float w4)
  37.         : weight1(w1), weight2(w2), weight3(w3), weight4(w4)
  38.     { }
  39.  
  40.     template <int which> struct access {
  41.         typedef float result_type;
  42.  
  43.         float operator()(weights_t const& w) const {
  44.             BOOST_STATIC_ASSERT(which >= 1 && which <= 4);
  45.             switch (which) {
  46.                 case 1: return w.weight1;
  47.                 case 2: return w.weight2;
  48.                 case 3: return w.weight3;
  49.                 case 4: return w.weight4;
  50.             }
  51.         }
  52.     };
  53. };
  54.  
  55. using namespace boost;
  56.  
  57. int main() {
  58.     std::vector<weights_t> weight_data; // index is vertex id
  59.     weight_data.push_back(weights_t(1,2,3,4));
  60.     weight_data.push_back(weights_t(5,6,7,8));
  61.     weight_data.push_back(weights_t(9,10,11,12));
  62.     weight_data.push_back(weights_t(13,14,15,16));
  63.  
  64.     boost::transform_value_property_map<weights_t::access<1>, weights_t*, float> wmap1 = make_transform_value_property_map(weights_t::access<1>(), &weight_data[0]);
  65.     boost::transform_value_property_map<weights_t::access<2>, weights_t*, float> wmap2 = make_transform_value_property_map(weights_t::access<2>(), &weight_data[0]);
  66.     boost::transform_value_property_map<weights_t::access<3>, weights_t*, float> wmap3 = make_transform_value_property_map(weights_t::access<3>(), &weight_data[0]);
  67.     boost::transform_value_property_map<weights_t::access<4>, weights_t*, float> wmap4 = make_transform_value_property_map(weights_t::access<4>(), &weight_data[0]);
  68.  
  69.     for (unsigned vertex = 0; vertex < weight_data.size(); ++vertex)
  70.         std::cout << wmap1[vertex] << "t" << wmap2[vertex] << "t" << wmap3[vertex] << "t"<< wmap4[vertex] << "n";
  71. }
  72.      
  73. 1   2   3   4
  74. 5   6   7   8
  75. 9   10  11  12
  76. 13  14  15  16
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top