本文整理汇总了C++中Graph::GetVertexes方法的典型用法代码示例。如果您正苦于以下问题:C++ Graph::GetVertexes方法的具体用法?C++ Graph::GetVertexes怎么用?C++ Graph::GetVertexes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Graph
的用法示例。
在下文中一共展示了Graph::GetVertexes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Execute
void AStar::Execute(const Graph &Graph, const string &VetexId)
{
const auto& Vertexes = Graph.GetVertexes();
Vertex* pVertexStart = Vertexes.find(VetexId)->second;
vector< Vertex* > Q;
// 初始化顶点
for (auto& it : Vertexes)
{
Vertex* pV = it.second;
pV->PathfindingData.Cost = 0;
pV->PathfindingData.pParent = nullptr;
pV->PathfindingData.Heuristic = 0x0FFFFFFF;
pV->PathfindingData.Flag = false;
}
// 初始化起始顶点
pVertexStart->PathfindingData.pParent = 0;
pVertexStart->PathfindingData.Cost = 0;
pVertexStart->PathfindingData.Heuristic = Estimate(pVertexStart, m_pVTarget);
// 把起始顶点放入列表中
Q.push_back(pVertexStart);
pVertexStart->PathfindingData.Flag = true;
for (; Q.size() > 0;)
{
// 选出最小路径估计的顶点
auto v = ExtractMin(Q);
v->PathfindingData.Flag = false;
if (v == m_pVTarget)
{
return;
}
// 对所有的出边进行“松弛”
const auto& EO = v->GetEdgesOut();
for (auto& it : EO)
{
Edge* pEdge = it.second;
Vertex* pVEnd = pEdge->GetEndVertex();
bool bRet = Relax(v, pVEnd, pEdge->GetWeight());
// 如果松弛成功,加入列表中
if (bRet && pVEnd->PathfindingData.Flag == false)
{
Q.push_back(pVEnd);
pVEnd->PathfindingData.Flag = true;
}
}
}
}
示例2: Execute
void Dijkstra::Execute(const Graph& graph, const string& vetexId)
{
m_Ret.PathTree.clear();
const auto &Vertexes = graph.GetVertexes();
Vertex* pVertexStart = Vertexes.find(vetexId)->second;
vector< Vertex* > Q;
//// 初始化
//for (auto& it : Vertexes)
//{
// it.second->PathfindingData.Cost = 0x0FFFFFFF;
// Q.push_back(it.second);
// pVertexStart->PathfindingData.pParent = nullptr;
//}
////m_Ret.PathTree[pVertexStart] = 0; // 起始顶点的前驱顶点为空
//pVertexStart->PathfindingData.Cost = 0;
//for (; Q.size() > 0;)
//{
// // 选出最小路径估计的顶点
// auto v = ExtractMin(Q);
// // 对所有的出边进行“松弛”
// const auto& EO = v->GetEdgesOut();
// for (auto& it : EO)
// {
// Edge* pEdge = it.second;
// Relax(v, pEdge->GetEndVertex(), pEdge->GetWeight());
// }
//}
// 初始化
for (auto& it : Vertexes)
{
it.second->PathfindingData.Cost = 0x0FFFFFFF;
pVertexStart->PathfindingData.pParent = nullptr;
}
// 初始化起始顶点
//m_Ret.PathTree[pVertexStart] = 0; // 起始顶点的前驱顶点为空
pVertexStart->PathfindingData.Cost = 0;
pVertexStart->PathfindingData.pParent = nullptr;
// 把起始顶点放入列表中
Q.push_back(pVertexStart);
pVertexStart->PathfindingData.Flag = true;
for (; Q.size() > 0;)
{
// 选出最小路径估计的顶点
auto v = ExtractMin(Q);
v->PathfindingData.Flag = false;
// 对所有的出边进行“松弛”
const auto& EO = v->GetEdgesOut();
for (auto& it : EO)
{
Edge* pEdge = it.second;
Vertex* pVEnd = pEdge->GetEndVertex();
bool bRel = Relax(v, pVEnd, pEdge->GetWeight());
if (bRel && pVEnd->PathfindingData.Flag == false)
{
Q.push_back(pVEnd);
pVEnd->PathfindingData.Flag = true;
}
}
}
}