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


C++ SearchData::set方法代码示例

本文整理汇总了C++中SearchData::set方法的典型用法代码示例。如果您正苦于以下问题:C++ SearchData::set方法的具体用法?C++ SearchData::set怎么用?C++ SearchData::set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SearchData的用法示例。


在下文中一共展示了SearchData::set方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: 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;
}
开发者ID:cathyatseneca,项目名称:gam671-astar,代码行数:77,代码来源:Design.cpp


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