C++ 我在MyGraph属性、顶点名称和边权重方面有问题
在MyGraphBuilder类中,我在执行Graph属性分配时遇到了一些问题:C++ 我在MyGraph属性、顶点名称和边权重方面有问题,c++,boost,graph,boost-graph,C++,Boost,Graph,Boost Graph,在MyGraphBuilder类中,我在执行Graph属性分配时遇到了一些问题: G:\QT\Projects\MY Project\boost\graph\dijkstra\u最短路径。hpp:588:错误:调用“choose\u const\u pmap(const type&,const boost::adjacence\u list&,boost::edge\u weight\t)”时没有匹配函数 选择常量pmap(获取参数(参数、边权重)、g、边权重), 另外,当我使用打印功能只打
G:\QT\Projects\MY Project\boost\graph\dijkstra\u最短路径。hpp:588:错误:调用“choose\u const\u pmap(const type&,const boost::adjacence\u list&,boost::edge\u weight\t)”时没有匹配函数
选择常量pmap(获取参数(参数、边权重)、g、边权重),
\ifndef MYGRAPHBUILDER\u H
#定义MYGRAPHBUILDER\u H
//通用库
//===============================================
#包括
#包括
#包括
//增强库
//===============================================
#包括
#包括
#包括
#包括
#包括
//MyColleague库
//===============================================
#包括
#包括
#包括
#包括
//锇库
//===============================================
#包括
#包括
#包括
#包括
#包括
//===============================================
使用名称空间std;
使用名称空间boost;
//===============================================
typedef锇::无符号对象id类型idType;
typedef地图路线图//定义道路地图及其ID
//==================================================
结构顶点属性
{
id类型id;
锇::位置loc;
};
结构边属性
{
双倍长度;
};
typedef邻接列表graph;
typedef graph\u traits::顶点描述符顶点;//顶点声明
typedef graph\u traits::边\u描述符边;//边作为ID指定的两个节点之间的链接
//==================================================
类MyGraphBuilder
{
private://为了清楚起见,这句话没用
图\u t MyGraph;
/////////////////////////////////////////////////////////
公众:
MyGraphBuilder();//默认构造函数
MyGraphBuilder(模型);//参数构造函数
~MyGraphBuilder();//析构函数
double Distance(idType,idType);//用于计算两个验证之间的距离的函数
//===============================================
//访问者
//函数获取图形
graph_t getGraph();
//===============================================
//突变子
无效集合图(图t);
//===============================================
void printGraph()常量;
//友元类算法;
};//下课
/////////////////////////////////////
#endif//MYGRAPHBUILDER\u H
CPP文件
//泛型库
//===============================================
#包括
//贝拉尔图书馆
//===============================================
#包括
//增强库
//===============================================
使用名称空间std;
使用名称空间boost;
/////////////////////////////////////////////////
MyGraphBuilder::MyGraphBuilder()//默认构造函数
{
模型模型;
WayMap MyWayMap=OurModel.getWayMap();
遍历它;
//it->first;//(key=WayID)
//it->second;//(Value WayData.nodRefList[idType])
for(it=MyWayMap.begin();it!=MyWayMap.end();it++)//循环整个路线图
{
unsigned int NodesOfWayIndex=0;//定义索引
idType VertixID;//定义用于存储Vertix索引的变量
vector WayNodes(it->second.NodeRelist.size());//定义一个具有路径大小的节点向量
对于(auto j=it->second.nodeRefList.begin();j!=it->second.nodeRefList.end();++j){//循环每种方式的整个节点
VertixID=it->second.nodeRefList.at(NodesOfWayIndex);
//VertixID作为绑定属性名称添加到顶点
顶点v=*顶点(MyGraph);
边e=*边(MyGraph);
//=======================================================
MyGraph[v].id=VertixID;
MyGraph[v].loc=OurModel.getNodeLoaction(VertixID);
//=======================================================
WayNodes[NodesOfWayIndex]=VertixID;
如果(NodesOfWayIndex!=0){
MyGraph[e]。长度=距离(WayNodes[NodeSfWayIndex-1],WayNodes[NodeSfWayIndex]);
}
}
NodesOfWayIndex++;
}
coutsecond;//(值WayData.NodeRefList[idType])
for(it=MyWayMap.begin();it!=MyWayMap.end();it++)//循环整个路线图
{
unsigned int NodesOfWayIndex=0;//定义索引
idType VertixID;//定义用于存储Vertix索引的变量
vector WayNodes(it->second.NodeRelist.size());//定义一个具有路径大小的节点向量
对于(auto j=it->second.nodeRefList.begin();j!=it->second.nodeRefList.end();++j){//循环每种方式的整个节点
VertixID=it->second.nodeRefList.at(NodesOfWayIndex);
//VertixID作为绑定属性名称添加到顶点
顶点v=*顶点(MyGraph);
边e=*边(MyGraph);
//=======================================================
MyGraph[v].id=VertixID;
MyGraph[v].loc=OurModel.getNodeLoaction(VertixID);
//=======================================================
WayNodes[NodesOfWayIndex]=VertixID;
如果(NodesOfWayIndex!=0){
MyGraph[e]。长度=距离(WayNodes[NodeSfWayIndex-1],WayNodes[NodeSfWayIndex]);
}
}
NodesOfWayIndex++;
}
coutgetNodeLoaction(Nod2_ID);//获取第二个位置
双距离=0;//距离
双x1=L1.lat();//第一位置纬度
double x2=L2.lat();//第二位置纬度
双y1=L1.lon();//第一个位置经度
double y2=L2.lon();//第二个位置经度
dist=sqrt(pow((x1-x2),2)+pow((y1-y2),2));
返回距离;
G:\QT\Projects\My Project\boost\graph\detail\adjacency_list.hpp:2700: error: forming reference to void
typedef value_type& reference;
G:\QT\Projects\MY Project\boost\graph\dijkstra_shortest_paths.hpp:588: error: no matching function for call to 'choose_const_pmap(const type&, const boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, VertProperty, EdgeProperty>&, boost::edge_weight_t)'
choose_const_pmap(get_param(params, edge_weight), g, edge_weight),
#ifndef MYGRAPHBUILDER_H
#define MYGRAPHBUILDER_H
// Generic Libraries
//===============================================
#include <iostream>
#include <vector>
#include <map>
// Boost Libraries
//===============================================
#include <boost/config.hpp>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/property_map/property_map.hpp>
#include <boost/graph/graph_utility.hpp>
// MyColleague Libraries
//===============================================
#include <modelDataStructure.h>
#include <modelDataHandler.h>
#include <modeldata.h>
#include <model.h>
// Osmium Libraries
//===============================================
#include <osmium/osm.hpp>
#include <osmium/index/map/flex_mem.hpp>
#include <osmium/visitor.hpp>
#include <osmium/osm/location.hpp>
#include <osmium/osm/node_ref.hpp>
//===============================================
using namespace std;
using namespace boost;
//===============================================
typedef osmium::unsigned_object_id_type idType ;
typedef map<idType, wayData> WayMap;//Define map of Ways ans Their ID
//==================================================
struct VertProperty
{
idType id;
osmium::Location loc;
};
struct EdgeProperty
{
double length;
};
typedef adjacency_list < vecS, vecS, directedS,VertProperty,EdgeProperty > graph_t;
typedef graph_traits < graph_t >::vertex_descriptor Vertex; // Vertex declaration
typedef graph_traits < graph_t >::edge_descriptor Edge; // Edge as link between two Nodes specified by ID
//==================================================
class MyGraphBuilder
{
private: // This Line is Useless just for clarity
graph_t MyGraph;
/////////////////////////////////////////////////////////
public:
MyGraphBuilder(); // default Constructor
MyGraphBuilder(Model); // Parameters Constructor
~MyGraphBuilder(); // Destructor
double Distance(idType,idType); // function to calculate the distance between 2 Verices
//===============================================
//Accessors
// function to get the Graph
graph_t getGraph();
//===============================================
// Mutators
void setGraph(graph_t);
//===============================================
void printGraph() const;
//friend class MyAlgorithm;
};//end of the Class
/////////////////////////////////////
#endif // MYGRAPHBUILDER_H
// Generic Libraries
//===============================================
#include <math.h>
// Belal Libraries
//===============================================
#include <mygraphbuilder.h>
// Boost Libraries
//===============================================
using namespace std;
using namespace boost;
/////////////////////////////////////////////////
MyGraphBuilder::MyGraphBuilder() // default Constructor
{
Model OurModel;
WayMap MyWayMap = OurModel.getWayMap();
WayMap::iterator it;
// it->first ;// (key = WayID)
// it->second ;// (Value WayData.nodRefList[idType])
for ( it = MyWayMap.begin(); it != MyWayMap.end(); it++ ) // Loop the Whole Way Map
{
unsigned int NodesOfWayIndex = 0; //define Index
idType VertixID; // define Variable to Store Vertix Index
vector<Vertex> WayNodes(it->second.nodeRefList.size());//define a vector of nodes with size of Way
for(auto j = it->second.nodeRefList.begin(); j != it->second.nodeRefList.end(); ++j){// Loop The Whole Nodes of Each way
VertixID = it->second.nodeRefList.at(NodesOfWayIndex);
//VertixID added as Bundeled property name to the vertex
Vertex v = *vertices(MyGraph).first;
Edge e = *edges(MyGraph).first;
//=======================================================
MyGraph[v].id = VertixID;
MyGraph[v].loc = OurModel.getNodeLoaction(VertixID);
//=======================================================
WayNodes[NodesOfWayIndex] = VertixID;
if(NodesOfWayIndex != 0) {
MyGraph[e].length = Distance(WayNodes[NodesOfWayIndex - 1], WayNodes[NodesOfWayIndex]);
}
}
NodesOfWayIndex++;
}
cout<<"\n\n Graph Was Built ...\n\n";
}
//===========================================================================
MyGraphBuilder::MyGraphBuilder(Model OurModel){ // Parameters Constructor
WayMap MyWayMap = OurModel.getWayMap();
WayMap::iterator it;
// it->first ;// (key = WayID)
// it->second ;// (Value WayData.nodRefList[idType])
for ( it = MyWayMap.begin(); it != MyWayMap.end(); it++ ) // Loop the Whole Way Map
{
unsigned int NodesOfWayIndex = 0; //define Index
idType VertixID; // define Variable to Store Vertix Index
vector<Vertex> WayNodes(it->second.nodeRefList.size());//define a vector of nodes with size of Way
for(auto j = it->second.nodeRefList.begin(); j != it->second.nodeRefList.end(); ++j){// Loop The Whole Nodes of Each way
VertixID = it->second.nodeRefList.at(NodesOfWayIndex);
//VertixID added as Bundeled property name to the vertex
Vertex v = *vertices(MyGraph).first;
Edge e = *edges(MyGraph).first;
//=======================================================
MyGraph[v].id = VertixID;
MyGraph[v].loc = OurModel.getNodeLoaction(VertixID);
//=======================================================
WayNodes[NodesOfWayIndex] = VertixID;
if(NodesOfWayIndex != 0) {
MyGraph[e].length = Distance(WayNodes[NodesOfWayIndex - 1], WayNodes[NodesOfWayIndex]);
}
}
NodesOfWayIndex++;
}
cout<<"\n\n Graph Was Built ...\n\n";
}
MyGraphBuilder::~MyGraphBuilder (){ // default Destructor
}
double MyGraphBuilder::Distance(idType Nod1_ID, idType Nod2_ID){ // Function to calculate Euclidean Distance between Vertices
modelData*m_Data = new modelData;
osmium::Location L1,L2; // define any 2 locations on earth
L1 = m_Data->getNodeLoaction(Nod1_ID) ; // get first location
L2 = m_Data->getNodeLoaction(Nod2_ID) ; // get second location
double dist = 0; // distance
double x1 = L1.lat(); // first location latitude
double x2 = L2.lat(); // second location latitude
double y1 = L1.lon(); // first location longitude
double y2 = L2.lon(); // second location longitude
dist = sqrt(pow((x1-x2),2)+pow((y1-y2),2));
return dist;
}
// Accessors
graph_t MyGraphBuilder::getGraph(){
return MyGraph;
}
// Mutators
void MyGraphBuilder::setGraph(graph_t YourGraph){
MyGraphBuilder::MyGraph = YourGraph;
}
//=========================================
void MyGraphBuilder::printGraph()const{
unsigned long long NodesCount = num_vertices(MyGraph);
cout<<"Number of Vertices is :\t"<<NodesCount<<"\n";
unsigned long long EdgesCount = num_edges(MyGraphBuilder::MyGraph);
cout<<"Number of Edges is :\t"<<EdgesCount<<"\n";
//for (auto v : make_iterator_range(vertices(MyGraph))) {
// cout << "Nodes " << v << " name " << MyGraph[v].name << "\n";
// for (auto oe : make_iterator_range(out_edges(v, MyGraph))) {
// cout << "Edge " << oe << " weight " << MyGraph[oe].weight << "\n";
// }
// }
}
cout << "Nodes " << v << " name " << MyGraph[v].name << "\n";
property<vertex_name_t, idType>
boost::put(boost::vertex_name, MyGraph, 0, "one");
auto name_pmap = boost::get(boost::vertex_name, MyGraph);
name_pmap[0] = "one";
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graph_utility.hpp>
#include <iostream>
#include <random>
using idType = std::string; // mock osmium stuff?
using graph_t = boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS,
boost::property<boost::vertex_name_t, idType>,
boost::property<boost::edge_weight_t, double> >;
using boost::make_iterator_range;
class MyGraphBuilder {
graph_t MyGraph;
public:
void generate();
void printGraph() const;
};
#include <boost/graph/random.hpp>
void MyGraphBuilder::generate() {
std::mt19937 prng { 42 }; // fixed random seed
generate_random_graph(MyGraph, 5, 5, prng);
boost::put(boost::vertex_name, MyGraph, 0, "one");
// or grab a propertymap first:
auto name_pmap = boost::get(boost::vertex_name, MyGraph);
name_pmap[0] = "one";
name_pmap[1] = "two";
name_pmap[2] = "three";
name_pmap[3] = "four";
name_pmap[4] = "five";
auto weight_pmap = boost::get(boost::edge_weight, MyGraph);
for (auto e : make_iterator_range(edges(MyGraph))) {
weight_pmap[e] = std::uniform_real_distribution<>(1.0, 10.0)(prng);
}
}
void MyGraphBuilder::printGraph() const {
std::cout << "Number of Vertices is:" << num_vertices(MyGraph) << "\n";
std::cout << "Number of Edges is:" << num_edges(MyGraph) << "\n";
print_graph(MyGraph, get(boost::vertex_name, MyGraph), std::cout);
// to print with edge weights:
for (auto v : make_iterator_range(vertices(MyGraph))) {
for (auto oe : make_iterator_range(out_edges(v, MyGraph))) {
std::cout << "Edge " << oe << " weight " << boost::get(boost::edge_weight, MyGraph, oe) << "\n";
}
}
}
int main() {
MyGraphBuilder builder;
builder.generate();
builder.printGraph();
}
Number of Vertices is:5
Number of Edges is:5
one -->
two --> four
three --> one one
four --> three
five --> one
Edge (1,3) weight 1.52275
Edge (2,0) weight 8.79559
Edge (2,0) weight 6.41004
Edge (3,2) weight 7.37265
Edge (4,0) weight 1.18526