当前位置: 首页>>代码示例>>C++>>正文


C++ NodeRef::GetCost方法代码示例

本文整理汇总了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
}
开发者ID:smorad,项目名称:advanced-programming,代码行数:31,代码来源:Source.cpp

示例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;
}
开发者ID:smorad,项目名称:advanced-programming,代码行数:8,代码来源:Source.cpp

示例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;
}
开发者ID:smorad,项目名称:advanced-programming,代码行数:9,代码来源:refactor.cpp

示例4: operator

	bool operator() (NodeRef a, NodeRef b){
		return a->GetCost()<b->GetCost();
	}
开发者ID:smorad,项目名称:advanced-programming,代码行数:3,代码来源:Source.cpp


注:本文中的NodeRef::GetCost方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。