本文整理汇总了C++中Graph::GetValue方法的典型用法代码示例。如果您正苦于以下问题:C++ Graph::GetValue方法的具体用法?C++ Graph::GetValue怎么用?C++ Graph::GetValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Graph
的用法示例。
在下文中一共展示了Graph::GetValue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: aStarSearch
/*----------------------------------------------------------*/
void aStarSearch(Graph <string> & graph, int cost_type)
{
// retrieval current nodes
list <SocialHeuristic *> open_list;
// store retrieved nodes
list <SocialHeuristic *> close_list;
// store all nodes to clean up memory
list <SocialHeuristic *> clean_list;
// record the cost have paid
// cost_time_map[person_start] = 0;
// cost_risk_map[person_start] = 0;
SocialHeuristic * start = new SocialHeuristic(person_start, 0, 0);
open_list.push_back(start);
clean_list.push_back(start);
while(!open_list.empty())
{
// get the first node in the list (has the smallest cost)
SocialHeuristic * heuristic = open_list.front();
open_list.pop_front();
// get name and heuristic cost
string pname = heuristic -> name;
// push the node into close to avoid retrieval again
close_list.push_back(heuristic);
// push all the child node (in order)
ArcNode * arc = graph.FirstArc(pname);
// check whether find the target
bool found = false;
while(arc != 0)
{
string name = graph.GetValue(arc -> adjvex);
// if not retrieved, push into open list
if(!checkIsRetrieved(close_list, name))
{
int time_cost = heuristic -> time_cost + arc -> _time;
int risk_cost = heuristic -> risk_cost + arc -> risk;
SocialHeuristic * heuristic_child = new SocialHeuristic(name, getHeurTime(name) + time_cost, getHeurRisk(name) + risk_cost);
heuristic_child -> time_cost = time_cost;
heuristic_child -> risk_cost = risk_cost;
heuristic_child -> lastNode = heuristic;
insertHeurList(open_list, heuristic_child, cost_type);
clean_list.push_back(heuristic_child);
// find the target
if(name == person_target)
{
found = true;
printListPath(heuristic_child, "A-star", cost_type);
break;
}
}
arc = arc -> nextArc;
}
if(found)
break;
}
cleanList(clean_list);
}
示例2: traversalGraph
void traversalGraph(Graph <string> & graph)
{
printTitle("Graph");
for(int i = 0; i < graph.vexNum; i++)
{
cout << graph.vertices[i].data;
ArcNode * arc = graph.vertices[i].firstArc;
while(arc)
{
cout << " -> " << graph.GetValue(arc -> adjvex);
arc = arc -> nextArc;
}
cout << endl;
}
}