1

私がr_c_shortest_paths定義したグラフを使用してブーストグラフ機能を使用しようとしています。

ここにグラフといくつかの定義(ファイル内graphs2.h):

#ifndef GRAPHS2_H
#define GRAPHS2_H

#include <boost/graph/adjacency_list.hpp>

namespace Gol {

  class UrbanVertexInfo
  {
  public:
    UrbanVertexInfo() {}
    UrbanVertexInfo(std::string n, std::string id) 
    : name(n), vid(id) {}
    ~UrbanVertexInfo() {}

    std::string name;
    std::string vid;

  };

  class UrbanEdgeInfo
  {
  public:

    UrbanEdgeInfo();

    UrbanEdgeInfo(std::string n, double l, double c)
      : name(n), length(l), cost(c) {}

    ~UrbanEdgeInfo() {}

    std::string name;
    double length;
    double cost;

  };

  typedef boost::property<boost::graph_name_t, std::string,  // name of the graph
              boost::property<boost::graph_id_t, std::string>   // id
              > GraphInfo;                   // property of the graph 

  typedef boost::adjacency_list <boost::setS, boost::vecS, boost::bidirectionalS, UrbanVertexInfo, UrbanEdgeInfo, GraphInfo > UrbanGraph;

  // ResourceContainer model
  struct res_cont {

      res_cont(double c, double l): cost(c), len(l) {};

      res_cont& operator= (const res_cont& other) {

          if(this == &other)
              return *this;
          this->~res_cont();
          new(this) res_cont(other);
          return *this;
      }

      double cost;
      double len;
  };

  bool operator== (const res_cont& one, const res_cont& two) {

      return (one.cost == two.cost && one.len == two.len);
  }

  bool operator< (const res_cont& one, const res_cont& two) {

      if (one.len > two.len)
          return false;
      if (one.len == two.len)
          return (one.cost < two.cost);
      return true;
  }

  // ResourceExtensionFunction model
  class ext_func {
  public:
      inline bool operator() (const UrbanGraph& g, res_cont& new_cont, const res_cont& old_cont, 
                          boost::graph_traits<UrbanGraph>::edge_descriptor ed)  const {
          new_cont.cost = old_cont.cost + get(&UrbanEdgeInfo::cost, g, ed);
          new_cont.len = old_cont.len + get(&UrbanEdgeInfo::length, g, ed);
          return true;
  }
};

  // DominanceFunction model
  class dom_func {
  public:
      inline bool operator() (const res_cont& one, const res_cont& two) const {
          return (one.cost <= two.cost && one.len <= two.len);
      }
};
}
#endif  /* GRAPHS2_H */

これは私のメインでr_c_shortest_paths()、単純なグラフを呼び出そうとしています:

#include <iostream>

#include <boost/graph/graph_traits.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/r_c_shortest_paths.hpp>

#include "graphs2.h"

using namespace boost;

int main(int argc, char** argv) {

  std::cout << "hello boost" << std::endl;

  typedef std::pair <int, int> Edge;
  typedef graph_traits<Gol::UrbanGraph>::vertex_descriptor vertex_descriptor;
  typedef graph_traits<Gol::UrbanGraph>::edge_descriptor edge_descriptor;

  Gol::UrbanGraph g;

  Gol::UrbanVertexInfo sorgente("sorg", "s", 0.0, 0.0);
  Gol::UrbanVertexInfo primo("primo", "A", 1.0, 1.0);
  Gol::UrbanVertexInfo secondo("secondo", "B", 2.0, 2.0);
  Gol::UrbanVertexInfo terzo("terzo", "C", 3.0, 3.0);
  Gol::UrbanVertexInfo quarto("quarto", "D", 4.0, 4.0);
  Gol::UrbanVertexInfo arrivo("arrivo", "t", 5.0, 5.0);
  vertex_descriptor s = add_vertex(sorgente, g);
  vertex_descriptor A = add_vertex(primo, g);
  vertex_descriptor B = add_vertex(secondo, g);
  vertex_descriptor C = add_vertex(terzo, g);
  vertex_descriptor D = add_vertex(quarto, g);
  vertex_descriptor t = add_vertex(arrivo, g);

  Gol::UrbanEdgeInfo ed1("da s a A", 3.0, 0.0);
  Gol::UrbanEdgeInfo ed2("da s a B", 5.0, 4.0);
  Gol::UrbanEdgeInfo ed3("da A a B", 4.0, 0.0);
  Gol::UrbanEdgeInfo ed4("da A a C", 6.0, 1.0);
  Gol::UrbanEdgeInfo ed5("da B a D", 1.0, 3.0);
  Gol::UrbanEdgeInfo ed6("da C a B", 3.0, 0.0);
  Gol::UrbanEdgeInfo ed7("da C a t", 2.0, 2.2);
  Gol::UrbanEdgeInfo ed8("da D a C", 3.0, 5.0);
  Gol::UrbanEdgeInfo ed9("da D a t", 6.0, 0.0);
  edge_descriptor ed;
  bool ins;
  tie(ed, ins) = add_edge(s, A, ed1, g);
  tie(ed, ins) = add_edge(s, B, ed2, g);
  tie(ed, ins) = add_edge(A, B, ed3, g);
  tie(ed, ins) = add_edge(A, C, ed4, g);
  tie(ed, ins) = add_edge(B, D, ed5, g);
  tie(ed, ins) = add_edge(C, B, ed6, g);
  tie(ed, ins) = add_edge(C, t, ed7, g);
  tie(ed, ins) = add_edge(D, C, ed8, g);
  tie(ed, ins) = add_edge(D, t, ed9, g);

  std::vector <std::vector <graph_traits<Gol::UrbanGraph>::edge_descriptor> > opt_solutions;
  std::vector <Gol::res_cont> pareto_opt;

  r_c_shortest_paths (
      g,
      get(&Gol::UrbanVertexInfo::name, g),
      get(&Gol::UrbanEdgeInfo::name, g),
      s,
      t,
      opt_solutions,
      pareto_opt,
      Gol::res_cont(0, 0),
      Gol::ext_func(),
      Gol::dom_func(),
      std::allocator <r_c_shortest_paths_label <Gol::UrbanGraph, Gol::res_cont> >(),
      default_r_c_shortest_paths_visitor() );

  return 0;
}

コンパイルすると、次のエラーが発生します。

/usr/include/boost/graph/r_c_shortest_paths.hpp:501:   instantiated from 'void boost::r_c_shortest_paths(const Graph&, const VertexIndexMap&, const EdgeIndexMap&, typename boost::graph_traits<G>::vertex_descriptor, typename boost::graph_traits<G>::vertex_descriptor, std::vector<std::vector<typename boost::graph_traits<G>::edge_descriptor, std::allocator<typename boost::graph_traits<G>::edge_descriptor> >, std::allocator<std::vector<typename boost::graph_traits<G>::edge_descriptor, std::allocator<typename boost::graph_traits<G>::edge_descriptor> > > >&, std::vector<ValueT, std::allocator<_Tp2> >&, const Resource_Container&, const Resource_Extension_Function&, const Dominance_Function&, Label_Allocator, Visitor) [with Graph = Gol::UrbanGraph, VertexIndexMap = boost::vec_adj_list_vertex_property_map<boost::adjacency_list<boost::setS, boost::vecS, boost::bidirectionalS, Gol::UrbanVertexInfo, Gol::UrbanEdgeInfo, boost::property<boost::graph_name_t, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::property<boost::graph_id_t, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::no_property> >, boost::listS>, boost::adjacency_list<boost::setS, boost::vecS, boost::bidirectionalS, Gol::UrbanVertexInfo, Gol::UrbanEdgeInfo, boost::property<boost::graph_name_t, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::property<boost::graph_id_t, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::no_property> >, boost::listS>*, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::string&, std::string Gol::UrbanVertexInfo::*>, EdgeIndexMap = boost::adj_list_edge_property_map<boost::bidirectional_tag, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::string&, long unsigned int, Gol::UrbanEdgeInfo, std::string Gol::UrbanEdgeInfo::*>, Resource_Container = Gol::res_cont, Resource_Extension_Function = Gol::ext_func, Dominance_Function = Gol::dom_func, Label_Allocator = std::allocator<boost::r_c_shortest_paths_label<boost::adjacency_list<boost::setS, boost::vecS, boost::bidirectionalS, Gol::UrbanVertexInfo, Gol::UrbanEdgeInfo, boost::property<boost::graph_name_t, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::property<boost::graph_id_t, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::no_property> >, boost::listS>, Gol::res_cont> >, Visitor = boost::default_r_c_shortest_paths_visitor]'
main.cpp:115:   instantiated from here
/usr/include/boost/graph/r_c_shortest_paths.hpp:217: error: no match for 'operator[]' in 'vec_vertex_labels[((const boost::vec_adj_list_vertex_property_map<boost::adjacency_list<boost::setS, boost::vecS, boost::bidirectionalS, Gol::UrbanVertexInfo, Gol::UrbanEdgeInfo, boost::property<boost::graph_name_t, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::property<boost::graph_id_t, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::no_property> >, boost::listS>, boost::adjacency_list<boost::setS, boost::vecS, boost::bidirectionalS, Gol::UrbanVertexInfo, Gol::UrbanEdgeInfo, boost::property<boost::graph_name_t, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::property<boost::graph_id_t, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::no_property> >, boost::listS>*, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::string&, std::string Gol::UrbanVertexInfo::*>*)vertex_index_map)->boost::vec_adj_list_vertex_property_map<Graph, GraphPtr, ValueType, Reference, Tag>::operator[] [with Graph = boost::adjacency_list<boost::setS, boost::vecS, boost::bidirectionalS, Gol::UrbanVertexInfo, Gol::UrbanEdgeInfo, boost::property<boost::graph_name_t, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::property<boost::graph_id_t, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::no_property> >, boost::listS>, GraphPtr = boost::adjacency_list<boost::setS, boost::vecS, boost::bidirectionalS, Gol::UrbanVertexInfo, Gol::UrbanEdgeInfo, boost::property<boost::graph_name_t, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::property<boost::graph_id_t, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::no_property> >, boost::listS>*, ValueType = std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Reference = std::string&, Tag = std::string Gol::UrbanVertexInfo::*](s)]'
/usr/include/boost/graph/r_c_shortest_paths.hpp:501:   instantiated from 'void boost::r_c_shortest_paths(const Graph&, const VertexIndexMap&, const EdgeIndexMap&, typename boost::graph_traits<G>::vertex_descriptor, typename boost::graph_traits<G>::vertex_descriptor, std::vector<std::vector<typename boost::graph_traits<G>::edge_descriptor, std::allocator<typename boost::graph_traits<G>::edge_descriptor> >, std::allocator<std::vector<typename boost::graph_traits<G>::edge_descriptor, std::allocator<typename boost::graph_traits<G>::edge_descriptor> > > >&, std::vector<ValueT, std::allocator<_Tp2> >&, const Resource_Container&, const Resource_Extension_Function&, const Dominance_Function&, Label_Allocator, Visitor) [with Graph = Gol::UrbanGraph, VertexIndexMap = boost::vec_adj_list_vertex_property_map<boost::adjacency_list<boost::setS, boost::vecS, boost::bidirectionalS, Gol::UrbanVertexInfo, Gol::UrbanEdgeInfo, boost::property<boost::graph_name_t, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::property<boost::graph_id_t, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::no_property> >, boost::listS>, boost::adjacency_list<boost::setS, boost::vecS, boost::bidirectionalS, Gol::UrbanVertexInfo, Gol::UrbanEdgeInfo, boost::property<boost::graph_name_t, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::property<boost::graph_id_t, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::no_property> >, boost::listS>*, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::string&, std::string Gol::UrbanVertexInfo::*>, EdgeIndexMap = boost::adj_list_edge_property_map<boost::bidirectional_tag, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::string&, long unsigned int, Gol::UrbanEdgeInfo, std::string Gol::UrbanEdgeInfo::*>, Resource_Container = Gol::res_cont, Resource_Extension_Function = Gol::ext_func, Dominance_Function = Gol::dom_func, Label_Allocator = std::allocator<boost::r_c_shortest_paths_label<boost::adjacency_list<boost::setS, boost::vecS, boost::bidirectionalS, Gol::UrbanVertexInfo, Gol::UrbanEdgeInfo, boost::property<boost::graph_name_t, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::property<boost::graph_id_t, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::no_property> >, boost::listS>, Gol::res_cont> >, Visitor = boost::default_r_c_shortest_paths_visitor]'
main.cpp:115:   instantiated from here
/usr/include/boost/graph/r_c_shortest_paths.hpp:408: error: no match for 'operator[]' in 'vec_vertex_labels[((const boost::vec_adj_list_vertex_property_map<boost::adjacency_list<boost::setS, boost::vecS, boost::bidirectionalS, Gol::UrbanVertexInfo, Gol::UrbanEdgeInfo, boost::property<boost::graph_name_t, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::property<boost::graph_id_t, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::no_property> >, boost::listS>, boost::adjacency_list<boost::setS, boost::vecS, boost::bidirectionalS, Gol::UrbanVertexInfo, Gol::UrbanEdgeInfo, boost::property<boost::graph_name_t, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::property<boost::graph_id_t, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::no_property> >, boost::listS>*, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::string&, std::string Gol::UrbanVertexInfo::*>*)vertex_index_map)->boost::vec_adj_list_vertex_property_map<Graph, GraphPtr, ValueType, Reference, Tag>::operator[] [with Graph = boost::adjacency_list<boost::setS, boost::vecS, boost::bidirectionalS, Gol::UrbanVertexInfo, Gol::UrbanEdgeInfo, boost::property<boost::graph_name_t, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::property<boost::graph_id_t, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::no_property> >, boost::listS>, GraphPtr = boost::adjacency_list<boost::setS, boost::vecS, boost::bidirectionalS, Gol::UrbanVertexInfo, Gol::UrbanEdgeInfo, boost::property<boost::graph_name_t, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::property<boost::graph_id_t, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::no_property> >, boost::listS>*, ValueType = std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Reference = std::string&, Tag = std::string Gol::UrbanVertexInfo::*](t)]'

私は本当にエラーを理解できません。誰かがこれを解決する方法を説明してもらえますか?

4

1 に答える 1