示例#1
0
string		WED_PackageMgr::ReducePath(const string& package, const string& full_file) const
{
	string prefix = ComputePath(package,string());
	string partial(full_file);

#if IBM
	if(prefix.size() >= 2 && partial.size() >= 2 &&
		prefix[1] == ':' && partial[1] == ':' &&
		prefix[0] != partial[0]) return full_file;
#endif

	int n = 0;
	do {
		int p = prefix.find_first_of("\\/:", n);
		if(p == prefix.npos) break;
		++p;
		if(p != prefix.npos && p <= prefix.size() && p <= partial.size() && strncmp(prefix.c_str(), partial.c_str(), p) == 0)
			n = p;
		else
			break;
	} while(1);

	prefix.erase(0,n);
	partial.erase(0,n);

	while(!prefix.empty())
	{
		string::size_type chop = prefix.find_first_of("\\/:");
		if (chop == prefix.npos) break;
		prefix.erase(0,chop+1);
		partial = string("../") + partial;
	}
	return partial;
}
示例#2
0
void CNavigationPath::Create (CSystem *pSystem, CSovereign *pSovereign, CSpaceObject *pStart, CSpaceObject *pEnd, CNavigationPath **retpPath)

//	Create
//
//	Create a path from pStart to pEnd that avoids enemies of pSovereign

	{
	ASSERT(pStart);
	ASSERT(pEnd);

	CVector vStart = pStart->GetPos();
	CVector vEnd = pEnd->GetPos();

	CNavigationPath *pNewPath = new CNavigationPath;
	pNewPath->m_dwID = g_pUniverse->CreateGlobalID();
	pNewPath->m_pSovereign = pSovereign;
	pNewPath->m_iStartIndex = pStart->GetID();
	pNewPath->m_iEndIndex = pEnd->GetID();

	//	Compute the path

	pNewPath->m_vStart = vStart;
	pNewPath->m_iWaypointCount = ComputePath(pSystem, pSovereign, vStart, vEnd, 0, &pNewPath->m_Waypoints);
	ASSERT(pNewPath->m_iWaypointCount > 0);

	//	Done

	*retpPath = pNewPath;
	}
示例#3
0
void CCmpPathfinder::ProcessLongRequests(const std::vector<AsyncLongPathRequest>& longRequests)
{
	for (size_t i = 0; i < longRequests.size(); ++i)
	{
		const AsyncLongPathRequest& req = longRequests[i];
		Path path;
		ComputePath(req.x0, req.z0, req.goal, req.passClass, req.costClass, path);
		CMessagePathResult msg(req.ticket, path);
		GetSimContext().GetComponentManager().PostMessage(req.notify, msg);
	}
}
示例#4
0
void CCmpPathfinder::SetDebugPath(entity_pos_t x0, entity_pos_t z0, const Goal& goal, pass_class_t passClass, cost_class_t costClass)
{
	if (!m_DebugOverlay)
		return;

	delete m_DebugGrid;
	m_DebugGrid = NULL;
	delete m_DebugPath;
	m_DebugPath = new Path();
	ComputePath(x0, z0, goal, passClass, costClass, *m_DebugPath);
	m_DebugPassClass = passClass;
}
示例#5
0
文件: TreeDlg.cpp 项目: geomview/gv2
GvPath *TreeDlg::PathOfItem(HTREEITEM hItemInQuestion)
{
    GetDlgItems();

    GvPath *path = new GvPath();
    path->SetRoot(mpGeom);
    if (hItemInQuestion == TVI_ROOT) return path;

    HTREEITEM hTreeRootItem = mpTreeCtrl->GetRootItem();

    if (ComputePath(path, hTreeRootItem, hItemInQuestion))
        return path;
    else
        return NULL;
}
示例#6
0
文件: TreeDlg.cpp 项目: geomview/gv2
BOOL TreeDlg::ComputePath(GvPath *path,
                          HTREEITEM hCurrentItem,
                          HTREEITEM hItemInQuestion)
{
    GetDlgItems();
    if (hCurrentItem == hItemInQuestion) return TRUE;

    if (mpTreeCtrl->ItemHasChildren(hCurrentItem))
    {
        int n = 0;
        HTREEITEM hChild = mpTreeCtrl->GetChildItem(hCurrentItem);
        while (hChild != NULL)
        {
            path->AppendIndex(n);
            if (ComputePath(path, hChild, hItemInQuestion))
                return TRUE;
            path->RemoveLastIndex();
            ++n;
            hChild = mpTreeCtrl->GetNextSiblingItem(hChild);
        }
    }
    return FALSE;
}
示例#7
0
bool ADPlanner::Search(ADSearchStateSpace_t* pSearchStateSpace, vector<int>& pathIds, int & PathCost, bool bFirstSolution, bool bOptimalSolution, double MaxNumofSecs)
{
	CKey key;
	TimeStarted = clock();
    searchexpands = 0;

#if DEBUG
	fprintf(fDeb, "new search call (call number=%d)\n", pSearchStateSpace->callnumber);
#endif

    if(pSearchStateSpace->bReinitializeSearchStateSpace == true){
        //re-initialize state space 
        ReInitializeSearchStateSpace(pSearchStateSpace);
    }


	if(bOptimalSolution)
	{
		pSearchStateSpace->eps = 1;
		MaxNumofSecs = INFINITECOST;
	}
	else if(bFirstSolution)
	{
		MaxNumofSecs = INFINITECOST;
	}

	//the main loop of AD*
	int prevexpands = 0;
	while(pSearchStateSpace->eps_satisfied > AD_FINAL_EPS && 
		(clock()- TimeStarted) < MaxNumofSecs*(double)CLOCKS_PER_SEC)
	{
		//it will be a new search iteration
		pSearchStateSpace->iteration++;

		//decrease eps for all subsequent iterations
		if(fabs(pSearchStateSpace->eps_satisfied - pSearchStateSpace->eps) < ERR_EPS)
		{
			pSearchStateSpace->eps = pSearchStateSpace->eps - AD_DECREASE_EPS;
			if(pSearchStateSpace->eps < AD_FINAL_EPS)
				pSearchStateSpace->eps = AD_FINAL_EPS;


			pSearchStateSpace->bReevaluatefvals = true;

		}

		//build a new open list by merging it with incons one
		BuildNewOPENList(pSearchStateSpace);
		
		//re-compute f-values if necessary and reorder the heap
		if(pSearchStateSpace->bReevaluatefvals)
			Reevaluatefvals(pSearchStateSpace);


		//improve or compute path
		if(ComputePath(pSearchStateSpace, MaxNumofSecs) == 1){
            pSearchStateSpace->eps_satisfied = pSearchStateSpace->eps;
        }

		//print the solution cost and eps bound
		printf("eps=%f expands=%d g(sstart)=%d\n", pSearchStateSpace->eps_satisfied, searchexpands - prevexpands,
							((ADState*)pSearchStateSpace->searchgoalstate->PlannerSpecificData)->g);

#if DEBUG
        fprintf(fDeb, "eps=%f eps_sat=%f expands=%d g(sstart)=%d\n", pSearchStateSpace->eps, pSearchStateSpace->eps_satisfied, searchexpands - prevexpands,
							((ADState*)pSearchStateSpace->searchgoalstate->PlannerSpecificData)->g);
#endif
		prevexpands = searchexpands;


		//if just the first solution then we are done
		if(bFirstSolution)
			break;

		//no solution exists
		if(((ADState*)pSearchStateSpace->searchgoalstate->PlannerSpecificData)->g == INFINITECOST)
			break;

	}


#if DEBUG
	fflush(fDeb);
#endif

	PathCost = ((ADState*)pSearchStateSpace->searchgoalstate->PlannerSpecificData)->g;
	MaxMemoryCounter += environment_->StateID2IndexMapping.size()*sizeof(int);
	
	printf("MaxMemoryCounter = %d\n", MaxMemoryCounter);

	int solcost = INFINITECOST;
    bool ret = false;
	if(PathCost == INFINITECOST)
	{
		printf("could not find a solution\n");
		ret = false;
	}
	else
	{
		printf("solution is found\n");

    	pathIds = GetSearchPath(pSearchStateSpace, solcost);
        ret = true;
	}

	printf("total expands this call = %d, planning time = %.3f secs, solution cost=%d\n", 
           searchexpands, (clock()-TimeStarted)/((double)CLOCKS_PER_SEC), solcost);
    

    //fprintf(fStat, "%d %d\n", searchexpands, solcost);

	return true;

}
示例#8
0
int CNavigationPath::ComputePath (CSystem *pSystem, CSovereign *pSovereign, const CVector &vFrom, const CVector &vTo, int iDepth, CVector **retpPoints)

//	ComputePath
//
//	This is a recursive function that returns a set of points that define a safe path
//	between the two given points.
//
//	We return an allocated array of CVectors in retpPoints

	{
	int i;

	//	If we're very close to our destination, then the best option is a direct path
	//	If the path is clear, then a direct path is also the best option.

	CSpaceObject *pEnemy;
	CVector vAway;
	if (iDepth >= MAX_PATH_RECURSION
			|| ((vTo - vFrom).Length2() <= MAX_SAFE_DIST2)
			|| PathIsClear(pSystem, pSovereign, vFrom, vTo, &pEnemy, &vAway))
		{
		(*retpPoints) = new CVector;
		(*retpPoints)[0] = vTo;
		return 1;
		}

	//	Otherwise, we deflect the path at the enemy base and recurse for the
	//	two path segments.

	else
		{
		//	Compute the mid-point

		CVector vMidPoint = pEnemy->GetPos() + (AVOID_DIST * vAway);

		//	Recurse

		CVector *pLeftPoints;
		int iLeftCount = ComputePath(pSystem, pSovereign, vFrom, vMidPoint, iDepth+1, &pLeftPoints);

		CVector *pRightPoints;
		int iRightCount = ComputePath(pSystem, pSovereign, vMidPoint, vTo, iDepth+1, &pRightPoints);

		//	Compose the two paths together

		int iCount = iLeftCount + iRightCount;
		ASSERT(iCount > 0);
		(*retpPoints) = new CVector [iCount];

		int iPos = 0;
		for (i = 0; i < iLeftCount; i++)
			(*retpPoints)[iPos++] = pLeftPoints[i];

		for (i = 0; i < iRightCount; i++)
			(*retpPoints)[iPos++] = pRightPoints[i];

		delete [] pLeftPoints;
		delete [] pRightPoints;

		return iCount;
		}
	}