コード例 #1
0
/* int Dstar::computeShortestPath()
 * --------------------------
 * As per [S. Koenig, 2002] except for 2 main modifications:
 * 1. We stop planning after a number of steps, 'maxsteps' we do this
 *    because this algorithm can plan forever if the start is
 *    surrounded by obstacles.
 * 2. We lazily remove states from the open list so we never have to
 *    iterate through it.
 */
int Dstar::computeShortestPath() {

  list<state> s;
  list<state>::iterator i;

  if (openList.empty()) return 1;

  int k=0;
  while ((!openList.empty()) &&
         (openList.top() < (s_start = calculateKey(s_start))) ||
         (getRHS(s_start) != getG(s_start))) {

    if (k++ > maxSteps) {
      fprintf(stderr, "At maxsteps\n");
      return -1;
    }


    state u;

    bool test = (getRHS(s_start) != getG(s_start));

    // lazy remove
    while(1) {
      if (openList.empty()) return 1;
      u = openList.top();
      openList.pop();

      if (!isValid(u)) continue;
      if (!(u < s_start) && (!test)) return 2;
      break;
    }

    ds_oh::iterator cur = openHash.find(u);
    openHash.erase(cur);

    state k_old = u;

    if (k_old < calculateKey(u)) { // u is out of date
      insert(u);
    } else if (getG(u) > getRHS(u)) { // needs update (got better)
      setG(u,getRHS(u));
      getPred(u,s);
      for (i=s.begin();i != s.end(); i++) {
        updateVertex(*i);
      }
    } else {   // g <= rhs, state has got worse
      setG(u,INFINITY);
      getPred(u,s);
      for (i=s.begin();i != s.end(); i++) {
        updateVertex(*i);
      }
      updateVertex(u);
    }
  }
  return 0;
}
コード例 #2
0
ファイル: Dstar.cpp プロジェクト: Kingsquee/dstarlite
/* int Dstar::computeShortestPath()
 * --------------------------
 * As per [S. Koenig, 2002] except for 2 main modifications:
 * 1. We stop planning after a number of steps, 'maxsteps' we do this
 *    because this algorithm can plan forever if the start is
 *    surrounded by obstacles. 
 * 2. We lazily remove states from the open list so we never have to
 *    iterate through it.
 */
int Dstar::computeShortestPath() {
  
  list<state> s;
  list<state>::iterator i;

  if (openList.empty()) return 1;

  int k=0;
  while ((!openList.empty()) && 
         (openList.top() < (calculateKey(s_start))) || 
         (!isConsistent(s_start))) {

    if (k++ > maxSteps) {
      fprintf(stderr, "At maxsteps\n");
      return -1;
    }
    
    
    state u;
    
    // check consistency (one of the loop conditions)
    bool test = isConsistent(s_start);
    //(getRHS(s_start) != getG(s_start));
    
    // lazy remove
    while(1) { 
      if (openList.empty()) return 1; // checks outer loop condition #1
      u = openList.top();
      
      if (!queuePop()) continue;
      
      if (!(u < s_start) && test) return 2; // checks outer loop conditions #2,3 still hold
    
      break;
    }
    
    state k_old = u;

    if (k_old < calculateKey(u)) { // u is out of date
      insert(u); // u has been removed already, reinsert into pq with new key
    } else if (getG(u) > getRHS(u)) { // needs update (got better)
      setG(u,getRHS(u));
      getPred(u,s);
      for (i=s.begin();i != s.end(); i++) {
        updateVertex(*i);
      }
    } else {   // g <= rhs, state has got worse
      setG(u,INFINITY);
      getPred(u,s);
      for (i=s.begin();i != s.end(); i++) {
        updateVertex(*i);
      }
      updateVertex(u);
    }
  }
  return 0;
}
コード例 #3
0
ファイル: nodo.cpp プロジェクト: elco45/OrgProyecto
void Nodo::elimHijo(int cont){
	Index* key = llaves[cont];
	if (hijos[cont]->cant_Key >= Orden){
		Index*pred = getPred(cont);
		llaves[cont] = pred;
		hijos[cont]->eliminar(pred);
	}else if(hijos[cont+1]->cant_Key >= Orden){
		Index* succ = getSucc(cont);
		llaves[cont] = succ;
		hijos[cont+1]->eliminar(succ);
	}
	else{
		merge(cont);
		hijos[cont]->eliminar(key);
	}
	return;
}
コード例 #4
0
ファイル: icc_parser.cpp プロジェクト: MIPT-ILab/MIPT-Vis
bool Icc_parser::parseFromStream(std::istream &is)
{
	int strnum = 0;
	bool isContextFound = false;
	BBlock * tbb = 0;
	string fnname;

	BBlock * zeroBlock = 0;
	int zeroBlockStr;

	//dump_info.addFunction();

	while ( !is.eof())
	{
		string current;
		int tmp;

		getline( is, current);
		strnum++;

		if ( ( tmp = bbNum( current)) != -1)
		{
			if ( tmp == 0) //Handling zero blocks for detecting function names
			{
				zeroBlock = new BBlock( strnum);
				zeroBlockStr = strnum;
				tbb = zeroBlock;
			}
			else
				tbb = dump_info.addBBlock( tmp, strnum, fnname);

			isContextFound = false;
			
			while ( !getPred( current, *tbb))
			{
				getline( is, current);
				strnum++;
			}

			while ( !getSucc( current, *tbb))
			{
				getline( is, current);
				strnum++;
			}
			
			continue;
		}

		if ( isRootContext( current))
			isContextFound = false;
		
		if ( isContextFound)
		{
            if ( !tbb)
                throw exNotFound( -1);

			string t;
			if ( ( t = isFnName(current))!= "" && zeroBlock)
			{
				fnname = t;
				dump_info.addFunction( fnname);
				tbb = dump_info.addBBlock( 0, zeroBlockStr, fnname, tbb);
				delete zeroBlock;
				zeroBlock = 0;
			}
			tbb->addText( current, strnum);
		}

		isContextFound |= isContext( current);
	}

	return true;
}