У меня есть вопрос об использовании массивов в связанных свойствах в библиотеке графов повышения. Ниже я попытался и оказался в ошибке компиляции.
Ниже приведено мое объявление графа.
struct PT_EdgeProperties{
PT_EdgeId edge_id;
double weights[10];
};
typedef boost::property<boost::vertex_name_t, std::string> PT_VertexProperties;
typedef boost::adjacency_list<boost::vecS,
boost::vecS,
boost::directedS,
PT_VertexProperties,
PT_EdgeProperties> PublicTransitGraph;
vector<sim_mob::StreetDirectory::PT_EdgeId>
Ниже приведен код, который я использую для поиска кратчайшего пути с помощью алгоритма ускорения astar_search.
sim_mob::A_StarPublicTransitShortestPathImpl::searchShortestPath(StreetDirectory::PT_VertexId fromNode,StreetDirectory::PT_VertexId toNode,int cost)
{
vector<StreetDirectory::PT_EdgeId> res;
StreetDirectory::PT_Vertex from=vertexMap.find(fromNode)->second;;
StreetDirectory::PT_Vertex to=vertexMap.find(toNode)->second;;
StreetDirectory::PublicTransitGraph& graph = publictransitMap_;
list<StreetDirectory::PT_Vertex> partialRes;
vector<StreetDirectory::PT_Vertex> p(boost::num_vertices(graph)); //Output variable
vector<double> d(boost::num_vertices(graph)); //Output variable
try {
boost::astar_search(
graph,
from,
distance_heuristic_graph_PT(&graph, to),
boost::weight_map(get(&StreetDirectory::PT_EdgeProperties::weights[cost],graph)).predecessor_map(&p[0]).distance_map(&d[0])
.visitor(astar_pt_goal_visitor(to)));
}
catch (pt_found_goal& goal) {
for (StreetDirectory::PT_Vertex v=to;;v=p[v]) {
partialRes.push_front(v);
if(p[v] == v) {
break;
}
}
std::list<StreetDirectory::PT_Vertex>::const_iterator prev = partialRes.end();
for (std::list<StreetDirectory::PT_Vertex>::const_iterator it=partialRes.begin(); it!=partialRes.end(); it++) {
if (prev!=partialRes.end()) {
std::pair<StreetDirectory::PT_Edge, bool> edge = boost::edge(*prev, *it, graph);
if (!edge.second) {
Warn() <<"ERROR: Boost can't find an edge that it should know about." <<std::endl;
return vector<StreetDirectory::PT_EdgeId>();
}
StreetDirectory::PT_EdgeId edge_id = get(&StreetDirectory::PT_EdgeProperties::edge_id, graph,edge.first);
res.push_back(edge_id);
}
prev = it;
}
}
return res;
}
Ошибка компиляции:
In file included from /home/smart-nus/code/simmobility/dev/Basic/shared/geospatial/streetdir/A_StarPublicTransitShortestPathImpl.hpp:22:0,
from /home/smart-nus/code/simmobility/dev/Basic/shared/geospatial/streetdir/A_StarPublicTransitShortestPathImpl.cpp:5:
/home/smart-nus/code/simmobility/dev/Basic/shared/geospatial/streetdir/StreetDirectory.hpp: In member function ‘virtual std::vector<int> sim_mob::A_StarPublicTransitShortestPathImpl::searchShortestPath(sim_mob::StreetDirectory::PT_VertexId, sim_mob::StreetDirectory::PT_VertexId, int)’:
/home/smart-nus/code/simmobility/dev/Basic/shared/geospatial/streetdir/StreetDirectory.hpp:208:20: error: invalid use of non-static data member ‘sim_mob::StreetDirectory::PT_EdgeProperties::weights’
double weights[10];
^
/home/smart-nus/code/simmobility/dev/Basic/shared/geospatial/streetdir/A_StarPublicTransitShortestPathImpl.cpp:223:64: error: from this location
boost::weight_map(get(&StreetDirectory::PT_EdgeProperties::weights[cost],graph)).predecessor_map(&p[0]).distance_map(&d[0])
^
make[2]: *** [CMakeFiles/SimMob_Shared.dir/shared/geospatial/streetdir/A_StarPublicTransitShortestPathImpl.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [CMakeFiles/SimMob_Shared.dir/all] Error 2
make: *** [all] Error 2
Вопросы: Не могли бы вы помочь мне найти способ использования массивов в связанных свойствах BGL. И как указать алгоритмы повышения в именованных параметрах weight_map boost для использования определенного индекса массива в качестве функции стоимости?
Заранее спасибо .
Привет, Прабху