本文整理汇总了C++中SearchData::cost方法的典型用法代码示例。如果您正苦于以下问题:C++ SearchData::cost方法的具体用法?C++ SearchData::cost怎么用?C++ SearchData::cost使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SearchData
的用法示例。
在下文中一共展示了SearchData::cost方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
bool operator<(const SearchData& left, const SearchData& right){
bool rc=false;
if(left.cost() < right.cost())
rc=true;
return rc;
}
示例2: greedy
/*code implements Greedy search*/
bool Design::greedy(int dest){
#if DEBUG==3
fprintf(debugfile_,"GREEDY");
fprintf(debugfile_,"dest: %d\n",dest);
fflush(debugfile_);
#endif
MinHeap<SearchData> openlist;
CloseStructure* closelist=new CloseStructure[map_.numvert()];
bool rc=false;
Node<EdgeInfo>* currconnect;
int nn;
SearchData curr;
SearchData tmp;
curr.set(whichbox_,-1,0); //start at current node, parent is -1.
//uniform cost so cost incurred so far is 0
bool done=false;
bool found=false;
float biggestcost=0;
int numclosed=0;
do{
#if DEBUG==3
fprintf(debugfile_,"curr.nodenum: %d\n",curr.nodenum());
fflush(debugfile_);
#endif
LList<EdgeInfo>& edgelist=map_.edges(curr.nodenum()); //get the conections to curr
while(currconnect=edgelist.curr()){ //for each node connected to curr
nn=currconnect->data().to();
if(!closelist[nn].closed_){ //if its not in the closed list
#if DEBUG==3
fprintf(debugfile_,"add to openlist: %d\n",nn);
fflush(debugfile_);
#endif
tmp.set(nn,curr.nodenum(),timeleft(currconnect,dest));
openlist.insert(tmp);
}
edgelist.gonext();
}//while
closelist[curr.nodenum()].closed_=true; //add it to the close list
closelist[curr.nodenum()].nodeinf_=curr;
numclosed++;
if(!openlist.isempty()){ //if there are still nodes to consider
curr=openlist.remove();//remove lowest cost item from list
#if DEBUG == 3
fprintf(debugfile_,"removed from openlist: %d\n",curr.nodenum());
fflush(debugfile_);
#endif
while(!openlist.isempty() && closelist[curr.nodenum()].closed_){ //if already encountered
curr=openlist.remove();//remove lowest cost item from list //consider the next node
}
if(closelist[curr.nodenum()].closed_){
//only way to reach this part of code is if the open list is empty and
//we have not found the next node to examine
done=true;
}
else{
if(curr.nodenum()==dest){
found=true; //found a node to the destination... question is, is it the best.
biggestcost=curr.cost();
}
if(found && curr.cost() > biggestcost){
done=true;
}
}//else still have node
}//if list is not empty
else{
done=true;
}//open list is empty
}while(!done);
if(found){
rc=true;
setPath(closelist,dest);
delete [] closelist;
}
return rc;
}