本文整理汇总了C++中NodeRef::GetCost方法的典型用法代码示例。如果您正苦于以下问题:C++ NodeRef::GetCost方法的具体用法?C++ NodeRef::GetCost怎么用?C++ NodeRef::GetCost使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NodeRef
的用法示例。
在下文中一共展示了NodeRef::GetCost方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Dijkstra
int Dijkstra(NodeRef start, int want, color color){ //to find distance, create node.prev which contains the prev node.you can go backwards and add up all nodes.
priority_queue<NodeRef, vector<NodeRef>, Compare> openSet;
vector<NodeRef> closedSet;
openSet.push(start); //add initial node to open set
while(openSet.size()!=0){
NodeRef current = openSet.top(); //node with least cost
closedSet.push_back(current);
current -> visited = true;
if(current->GetId() == want){ //if wanted node is found
return CalculateCost(edgeList.at(want));
}
openSet.pop(); //remove current node from open set
if(current->GetCost()==INT_MAX){ //current node has no connections
cout<<"No connections found, break"<<endl;
break;
}
for(int link=0; link<(current)->links.size(); link++){
if((!current->links.at(link)->visited) && current->links.at(link)->color == color){ //if unvisited and correct color
current->links.at(link)->Visited(true);
current->links.at(link)->prev = current;
int alt = CalculateCost(current) + (CalculateCost(current->links.at(link)) - CalculateCost(current)); //relaxing the edge
if(alt<CalculateCost(current)){ //if found a faster way
(current->links.at(link))->cost = alt;
}
openSet.push(current->links.at(link));
}
}
}
return INT_MAX; //failed to find node
}
示例2: CalculateCost
int CalculateCost(NodeRef n){ //run backwards up the list to calculate total cost//works
int cost = 0;
while(n->prev!=NULL){
cost = cost+ n->GetCost();
n = n->prev;
}
return cost;
}
示例3: CalculateCost
/*Uses stack to run backwards and calculate cost from start to this node. Used for Dijkstra.*/
int CalculateCost(NodeRef n){
int cost = 0;
while(n->prev!=NULL){
cost = cost+ n->GetCost();
n=n->prev;
}
return cost;
}
示例4: operator
bool operator() (NodeRef a, NodeRef b){
return a->GetCost()<b->GetCost();
}