Boost Graph Library. Property_map. lexical_cast. operator[]
От: e.ustimenko Россия  
Дата: 01.04.11 08:33
Оценка:
Всем привет, у меня есть проблема, в решении которой, надеюсь, вы мне поможете.
Вот код, который я написал:

boost::property_map<Digraph,boost::edge_attribute_t>::type edge_attr_map;
typedef adjacency_list < vecS, vecS, directedS, no_property, property < edge_weight_t, int > > Graph;
typedef boost::adjacency_list<vecS, vecS, directedS, property<vertex_name_t, std::string>, property<edge_weight_t, double> > Digraph;

Graph SearchOptimalWay::copyOrgraphToNumeric(Digraph g_dot)
{
Graph g(num_vertices(g_dot));//for numeric vertexes store
property_map<Digraph, edge_attribute_t >::type edge_attr_map = get(edge_attribute, g_dot);
graph_traits<Digraph>::edge_iterator ei, ei_end;

for(tie(ei, ei_end)=edges(g_dot);ei!=ei_end;++ei)
{
int weight=lexical_cast<int,edge_attribute_t>(edge_attr_map[(*ei)]["weight"]);
property<edge_weight_t, int>edge_property(weight);
add_edge(source((*ei), g_dot),target((*ei), g_dot), edge_property, g);
}

return g;
}

Вот ошибка:

g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/classes/SearchOptimalWay/SearchOptimalWay.d" -MT"src/classes/SearchOptimalWay/SearchOptimalWay.d" -o"src/classes/SearchOptimalWay/SearchOptimalWay.o" "../src/classes/SearchOptimalWay/SearchOptimalWay.cpp"
../src/classes/SearchOptimalWay/SearchOptimalWay.cpp: In member function ‘Graph SearchOptimalWay::copyOrgraphToNumeric(Digraph)’:
../src/classes/SearchOptimalWay/SearchOptimalWay.cpp:38: error: no match for ‘operator[]’ in ‘edge_attr_map.boost::adj_list_edge_property_map<Directed, Value, Ref, Vertex, Property, Tag>::operator[] [with Directed = boost::directed_tag, Value = boost::detail::error_property_not_found, Ref = boost::detail::error_property_not_found&, Vertex = unsigned int, Property = boost::property<boost::edge_weight_t, double, boost::no_property>, Tag = boost::edge_attribute_t](ei.boost::detail::adj_list_edge_iterator<VertexIterator, OutEdgeIterator, Graph>::operator* [with VertexIterator = boost::range_detail::integer_iterator<unsigned int>, OutEdgeIterator = boost::detail::out_edge_iter<__gnu_cxx::__normal_iterator<boost::detail::sep_<unsigned int, boost::property<boost::edge_weight_t, double, boost::no_property> >*, std::vector<boost::detail::sep_<unsigned int, boost::property<boost::edge_weight_t, double, boost::no_property> >, std::allocator<boost::detail::sep_<unsigned int, boost::property<boost::edge_weight_t, double, boost::no_property> > > > >, unsigned int, boost::detail::edge_desc_impl<boost::directed_tag, unsigned int>, int>, Graph = boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, boost::property<boost::vertex_name_t, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::no_property>, boost::property<boost::edge_weight_t, double, boost::no_property>, boost::no_property, boost::listS>]())["weight"]’
../src/classes/SearchOptimalWay/SearchOptimalWay.cpp: In member function ‘vertex_descriptor SearchOptimalWay::searchNeededVertex(std::string, Digraph)’:
../src/classes/SearchOptimalWay/SearchOptimalWay.cpp:55: error: no match for ‘operator[]’ in ‘((SearchOptimalWay*)this)->SearchOptimalWay::vertex_attr_map.boost::vec_adj_list_vertex_property_map<Graph, GraphPtr, ValueType, Reference, Tag>::operator[] [with Graph = boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, boost::property<boost::vertex_name_t, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::no_property>, boost::property<boost::edge_weight_t, double, boost::no_property>, boost::no_property, boost::listS>, GraphPtr = boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, boost::property<boost::vertex_name_t, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::no_property>, boost::property<boost::edge_weight_t, double, boost::no_property>, boost::no_property, boost::listS>*, ValueType = boost::detail::error_property_not_found, Reference = boost::detail::error_property_not_found&, Tag = boost::vertex_attribute_t](((boost::iterator_facade<boost::range_detail::integer_iterator<unsigned int>, unsigned int, boost::random_access_traversal_tag, unsigned int, int>*)(& vi))->boost::iterator_facade<I, V, TC, R, D>::operator* [with Derived = boost::range_detail::integer_iterator<unsigned int>, Value = unsigned int, CategoryOrTraversal = boost::random_access_traversal_tag, Reference = unsigned int, Difference = int]())["weight"]’
make: *** [src/classes/SearchOptimalWay/SearchOptimalWay.o] Error 1

Из этого набора букв понял, что ошибка в том, что в каком-то классе, скорее всего type, нет operator[].
Сделал пример, который шел с библиотекой.

#include <boost/config.hpp>
#include <iostream>
#include <string>
#include <boost/graph/adjacency_list.hpp>
int
main()
{
using namespace boost;
typedef adjacency_list < listS, listS, directedS,
property < vertex_name_t, std::string > >graph_t;
graph_t g;
graph_traits < graph_t >::vertex_descriptor u = add_vertex(g);
property_map < graph_t, vertex_name_t >::type
name_map = get(vertex_name, g);
name_map[u] = "Joe";
std::cout << name_map[u] << std::endl;
return EXIT_SUCCESS;
}

Работает.

Может кто-нибудь указать, в чем ошибка, и способ ее исправления — всевозможные ссылки, можно даже просто код поправить, было бы не плохо.

С уважением, Евгений.
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.