本文整理汇总了C++中Graph::GetNodes方法的典型用法代码示例。如果您正苦于以下问题:C++ Graph::GetNodes方法的具体用法?C++ Graph::GetNodes怎么用?C++ Graph::GetNodes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Graph
的用法示例。
在下文中一共展示了Graph::GetNodes方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PerformPathFinding
// TODO: this is the only missing part... will do this tomorrow :)
void PerformPathFinding(NodeIdxT start, NodeIdxT end)
{
const NodeT * nodes = mPtrGraph->GetNodes();
NodeValT currdist, mindist;
NodeIdxT currentNode = start;
mPath.clear();
while (true)
{
mindist = MAX_INVALID_NODE;
int nodeConnectedSize = nodes[currentNode].nodesConnected.size();
for (int ctr = 0; ctr < nodeConnectedSize; ctr++)
{
currdist = mPtrGraph->GetDistanceDirect(*mPtrGraph, currentNode,
nodes[currentNode].nodesConnected[ctr]);
if (currdist != INVALID_NODE)
{
mindist = currdist;
}
}
break;
}
this->mDistance = mindist;
}
示例2: primPrincipal
std::vector<int> primPrincipal(Graph & G, float & length, int v)
{
int size = G->GetNodes();
std::vector<float> distances (size,inf);
std::vector<bool> visitedNodes (size,false);
std::vector<int> parents (size,-1);
std::deque<QueueItem> queue;
for(int i=0; i<size; i++)
{
QueueItem q;
q.VertexID = i+1;
q.distance = inf;
queue.push_back(q);
}
distances[v-1] = 0;
visitedNodes[v-1] = true;
while(!queue.empty())
{
std::sort(queue.begin(), queue.end(), sortQueue);
QueueItem u = queue.front();
queue.pop_front();
SnapEdge EI;
if(parents[u.VertexID-1] != -1)
{
TNodeEDatNet<TInt, TFlt>::TEdgeI EI = G->GetEI(parents[u.VertexID-1],u.VertexID);
length+=(float)EI.GetDat();
}
visitedNodes[u.VertexID-1] = true;
SnapNode NI = G->GetNI(u.VertexID);
for (int e = 0; e < NI.GetOutDeg(); e++)
{
SnapEdge EI = G->GetEI(u.VertexID,NI.GetOutNDat(e));
int outNode = NI.GetOutNDat(e);
float edgeWeight = (float)EI.GetDat();
if(!visitedNodes[outNode-1] && distances[outNode-1] > edgeWeight)
{
parents[outNode-1] = u.VertexID;
distances[outNode-1] = edgeWeight;
for(int i=0; i< queue.size(); i++)
{
if(queue[i].VertexID == outNode)
queue[i].distance = edgeWeight;
}
}
}
}
return parents;
}
示例3: dijkstra
void dijkstra(Graph & G, int v, bool bench)
{
int size = G->GetNodes();
std::vector<float> distances (size,inf);
std::vector<int> parents (size,-1);
std::priority_queue<std::pair<float, Graph::TObj::TNodeI> > queue;
distances[v-1] = 0;
parents[v-1] = -1;
for(SnapNode NI = G->BegNI(); NI != G->EndNI(); NI++)
{
queue.push(std::make_pair(distances[NI.GetDat()-1], NI));
}
while(!queue.empty())
{
SnapNode u = queue.top().second;
float dist = queue.top().first;
queue.pop();
int sourceNode = u.GetDat();
for (int ed = 0; ed < u.GetOutDeg(); ed++)//For each adjacent vertex to node NI
{
int destNode = u.GetOutNDat(ed);
SnapEdge e = G->GetEI(sourceNode,destNode);
float alt = dist + e.GetDat();
if(alt < distances[destNode-1])//relax
{
distances[destNode-1] = alt;
parents[destNode-1] = sourceNode;
queue.push(std::make_pair(alt, G->GetNI(destNode)));
}
}
}
if(!bench)
{
int node = 1;
for (int i = 0 ; i< parents.size(); i++)
{
if(parents[node-1] == -1)
std::cout << "start -> " << node << " distance: " << distances[node-1] << std::endl;
else
std::cout << parents[node-1] << " -> " << node << " distance: " << distances[node-1] << std::endl;
node++;
}
}
}