本文整理汇总了C++中GraphEdge::GetTo方法的典型用法代码示例。如果您正苦于以下问题:C++ GraphEdge::GetTo方法的具体用法?C++ GraphEdge::GetTo怎么用?C++ GraphEdge::GetTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GraphEdge
的用法示例。
在下文中一共展示了GraphEdge::GetTo方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SearchWithTrail
bool Bfs::SearchWithTrail(int from, int to, Trail* trail)
{
// Need to remember which nodes we have already visited
std::set<int> visited;
Breadcrumbs breadcrumbs;
// Breadth first uses a queue to hold nodes we will visit
std::queue<GraphEdge> nodesToVisit;
float cost = 0; // dummy value
// Put dummy edge in stack to start search. TODO better way, e.g. do/while ?
nodesToVisit.push(GraphEdge(from, from, cost));
while (!nodesToVisit.empty())
{
GraphEdge e = nodesToVisit.front();
nodesToVisit.pop();
std::cout << "Trying edge from " << e.GetFrom() << " to " << e.GetTo() << "\n";
breadcrumbs[e.GetTo()] = e.GetFrom(); // map version
//breadcrumbs.push_back(e); // vector version
// In addition to here....
visited.insert(e.GetTo());
if (e.GetTo() == to)
{
// We have found the finish!
std::cout << "Successfully got to the finish!\n";
MakeTrail(from, to, breadcrumbs, trail);
return true;
}
else
{
// Push unvisited neighbours onto stack
const EdgeList& edgelist = m_graph->GetEdgeList(e.GetTo());
for (EdgeList::const_iterator it = edgelist.begin(); it != edgelist.end(); ++it)
{
const GraphEdge& childEdge = *it;
if (visited.count(childEdge.GetTo()) == 0)
{
nodesToVisit.push(childEdge);
// ...we mark node as visited right away here
visited.insert(childEdge.GetTo());
}
}
}
}
return false;
}
示例2: SearchNoTrail
bool Dfs::SearchNoTrail(int from, int to)
{
// Need to remember which nodes we have already visited
std::set<int> visited;
// Depth first uses a stack to hold nodes we will visit
std::stack<GraphEdge> nodesToVisit;
float cost = 0; // dummy value
// Put dummy edge in stack to start search. TODO better way, e.g. do/while ?
nodesToVisit.push(GraphEdge(from, from, cost));
while (!nodesToVisit.empty())
{
GraphEdge e = nodesToVisit.top();
nodesToVisit.pop();
std::cout << "Trying edge from " << e.GetFrom() << " to " << e.GetTo() << "\n";
visited.insert(e.GetTo());
if (e.GetTo() == to)
{
// We have found the finish!
return true;
}
else
{
// Push unvisited neighbours onto stack
const EdgeList& edgelist = m_graph->GetEdgeList(e.GetTo());
for (EdgeList::const_iterator it = edgelist.begin(); it != edgelist.end(); ++it)
{
const GraphEdge& childEdge = *it;
if (visited.count(childEdge.GetTo()) == 0)
{
nodesToVisit.push(childEdge);
}
}
}
}
return false;
}
示例3: SearchWithTrail
bool Dfs::SearchWithTrail(int from, int to, Trail* trail)
{
std::set<int> visited;
Breadcrumbs breadcrumbs;
std::stack<GraphEdge> nodesToVisit;
float cost = 0;
// Put dummy edge in stack
nodesToVisit.push(GraphEdge(from, from, cost));
while (!nodesToVisit.empty())
{
GraphEdge e = nodesToVisit.top();
nodesToVisit.pop();
std::cout << "Trying edge from " << e.GetFrom() << " to " << e.GetTo() << "\n";
breadcrumbs[e.GetTo()] = e.GetFrom(); // map version
// breadcrumbs.push_back(e); // vector version
visited.insert(e.GetTo());
if (e.GetTo() == to)
{
// We have found the finish! Loop back through the breadcrumbs to create the trail.
MakeTrail(from, to, breadcrumbs, trail);
return true;
}
else
{
// Push unvisited neighbours onto stack
const EdgeList& edgelist = m_graph->GetEdgeList(e.GetTo());
for (EdgeList::const_iterator it = edgelist.begin(); it != edgelist.end(); ++it)
{
const GraphEdge& childEdge = *it;
if (visited.count(childEdge.GetTo()) == 0)
{
nodesToVisit.push(childEdge);
}
}
}
}
return false;
}
示例4: AddEdge
//엣지를 추가한다.
void SparseGraph::AddEdge(GraphEdge edge)
{
//엣지의 양끝이 유효한 노드인지 확인한다.
assert((edge.GetFrom() < m_iNextNodeIndex) && (edge.GetTo() < m_iNextNodeIndex) &&
"<SparseGraph::AddEdge>: invalid node index");
//유효한 노드이면
if ((m_Nodes[edge.GetTo()].GetIndex() != -1) &&
(m_Nodes[edge.GetFrom()].GetIndex() != -1))
{
//유니크한 엣지인지 확인한다.
if (UniqueEdge(edge.GetFrom(), edge.GetTo()))
{
m_Edges[edge.GetFrom()].push_back(edge);
}
//거꾸로 방향도 확인한다.
if (UniqueEdge(edge.GetTo(), edge.GetFrom()))
{
GraphEdge NewEdge = edge;
NewEdge.SetTo(edge.GetFrom());
NewEdge.SetFrom(edge.GetTo());
m_Edges[edge.GetTo()].push_back(NewEdge);
}
}
}
示例5: DrawEdge
void DrawEdge(const GraphEdge& edge, const Graph& g)
{
glDisable(GL_LIGHTING);
glBegin(GL_LINES);
const GraphNode& from = g.GetNode(edge.GetFrom());
const GraphNode& to = g.GetNode(edge.GetTo());
const Vec2f& u = from.GetPos();
const Vec2f& v = to.GetPos();
glVertex3f(u.x, 0, u.y);
glVertex3f(v.x, 0, v.y);
glEnd();
glEnable(GL_LIGHTING);
}