示例#1
0
void ADPlanner::UpdateSetMembership(ADState* state)
{
	CKey key;

    if(state->v != state->g)
    {
        if(state->iterationclosed != pSearchStateSpace_->iteration)
        {
			key = ComputeKey(state);
            if(state->heapindex == 0)
                pSearchStateSpace_->heap->insertheap(state, key);
            else
				pSearchStateSpace_->heap->updateheap(state, key);
        }
		else if(state->listelem[AD_INCONS_LIST_ID] == NULL)
		{
			pSearchStateSpace_->inconslist->insert(state, AD_INCONS_LIST_ID);
		}
    }
    else
    {
        if(state->heapindex != 0)
            pSearchStateSpace_->heap->deleteheap(state);
        else if(state->listelem[AD_INCONS_LIST_ID] != NULL)
			pSearchStateSpace_->inconslist->remove(state, AD_INCONS_LIST_ID);
    }
}
示例#2
0
void
TnmSnmpComputeKeys(TnmSnmp *session)
{
    int authProto, privProto;

    authProto = (session->securityLevel & TNM_SNMP_AUTH_MASK);
    privProto = (session->securityLevel & TNM_SNMP_PRIV_MASK);

    if (authProto != TNM_SNMP_AUTH_NONE) {
	ComputeKey(&session->usmAuthKey, session->authPassWord,
		   session->engineID, authProto);
	if (privProto != TNM_SNMP_PRIV_NONE) {
	    ComputeKey(&session->usmPrivKey, session->privPassWord,
		       session->engineID, authProto);
	}
    }
}
示例#3
0
void ADPlanner::PrintSearchState(ADState* searchstateinfo, FILE* fOut)
{
	CKey key = ComputeKey(searchstateinfo);
	fprintf(fOut, "g=%d v=%d h = %d heapindex=%d inconslist=%d key=[%d %d]", 
			searchstateinfo->g, searchstateinfo->v, searchstateinfo->h, searchstateinfo->heapindex, (searchstateinfo->listelem[AD_INCONS_LIST_ID] != NULL),
			(int)key[0], (int)key[1]);

}
示例#4
0
void ADPlanner::PrintSearchState(ADState* searchstateinfo, FILE* fOut)
{

	CKey key = ComputeKey(searchstateinfo);
	fprintf(fOut, "g=%d v=%d h = %d heapindex=%d inconslist=%d key=[%d %d] iterc=%d callnuma=%d expands=%d (current callnum=%d iter=%d)", 
			searchstateinfo->g, searchstateinfo->v, searchstateinfo->h, searchstateinfo->heapindex, (searchstateinfo->listelem[AD_INCONS_LIST_ID] != NULL),
			(int)key[0], (int)key[1], searchstateinfo->iterationclosed, searchstateinfo->callnumberaccessed, searchstateinfo->numofexpands,
				this->pSearchStateSpace_->callnumber, this->pSearchStateSpace_->searchiteration);

}
示例#5
0
void KeyManager::SetCurrentKeySequence(uint32_t aKeySequence)
{
    mPreviousKeyValid = true;
    mPreviousKeySequence = mCurrentKeySequence;
    memcpy(mPreviousKey, mCurrentKey, sizeof(mPreviousKey));

    mCurrentKeySequence = aKeySequence;
    ComputeKey(mCurrentKeySequence, mCurrentKey);

    mMacFrameCounter = 0;
    mMleFrameCounter = 0;

    UpdateNeighbors();
}
示例#6
0
void ADPlanner::Reevaluatefvals(ADSearchStateSpace_t* pSearchStateSpace)
{
	CKey key;
	int i;
	CHeap* pheap = pSearchStateSpace->heap;
	
#if DEBUG
	fprintf(fDeb, "re-computing heap priorities\n");
#endif

	//recompute priorities for states in OPEN and reorder it
	for (i = 1; i <= pheap->currentsize; ++i)
	  {
		ADState* state = (ADState*)pheap->heap[i].heapstate;
		pheap->heap[i].key = ComputeKey(state);
	  }
	pheap->makeheap();

	pSearchStateSpace->bReevaluatefvals = false;
}
示例#7
0
void ADPlanner::BuildNewOPENList(ADSearchStateSpace_t* pSearchStateSpace)
{
	ADState *state;
	CKey key;
	CHeap* pheap = pSearchStateSpace->heap;
	CList* pinconslist = pSearchStateSpace->inconslist; 
		
	//move incons into open
	while(pinconslist->firstelement != NULL)
	  {
	    state = (ADState*)pinconslist->firstelement->liststate;
	    
	    //compute f-value
		key = ComputeKey(state);
	    
	    //insert into OPEN
	    pheap->insertheap(state, key);
	    //remove from INCONS
	    pinconslist->remove(state, AD_INCONS_LIST_ID);
	  }
}
示例#8
0
//initialization before each search
void ADPlanner::ReInitializeSearchStateSpace(ADSearchStateSpace_t* pSearchStateSpace)
{
	CKey key;

	//increase callnumber
	pSearchStateSpace->callnumber++;

	//reset iteration
	pSearchStateSpace->searchiteration = 0;


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



	pSearchStateSpace->heap->makeemptyheap();
	pSearchStateSpace->inconslist->makeemptylist(AD_INCONS_LIST_ID);

    //reset 
	pSearchStateSpace->eps = this->finitial_eps;
    pSearchStateSpace->eps_satisfied = INFINITECOST;

	//initialize start state
	ADState* startstateinfo = (ADState*)(pSearchStateSpace->searchstartstate->PlannerSpecificData);
	if(startstateinfo->callnumberaccessed != pSearchStateSpace->callnumber)
		ReInitializeSearchStateInfo(startstateinfo, pSearchStateSpace);

	startstateinfo->g = 0;

	//insert start state into the heap
	key = ComputeKey(startstateinfo);
	pSearchStateSpace->heap->insertheap(startstateinfo, key);

    pSearchStateSpace->bReinitializeSearchStateSpace = false;
	pSearchStateSpace->bReevaluatefvals = false;
	pSearchStateSpace->bRebuildOpenList = false;
}
示例#9
0
//returns 1 if the solution is found, 0 if the solution does not exist and 2 if it ran out of time
int ADPlanner::ComputePath(ADSearchStateSpace_t* pSearchStateSpace, double MaxNumofSecs)
{
	int expands;
	ADState *state, *searchgoalstate;
	CKey key, minkey;
	CKey goalkey;

	expands = 0;

	if(pSearchStateSpace->searchgoalstate == NULL)
	{
		printf("ERROR searching: no goal state is set\n");
		exit(1);
	}

	//goal state
	searchgoalstate = (ADState*)(pSearchStateSpace->searchgoalstate->PlannerSpecificData);
	if(searchgoalstate->callnumberaccessed != pSearchStateSpace->callnumber)
		ReInitializeSearchStateInfo(searchgoalstate, pSearchStateSpace);

	//set goal key
	goalkey = ComputeKey(searchgoalstate);

	//expand states until done
	minkey = pSearchStateSpace->heap->getminkeyheap();
	CKey oldkey = minkey;
	while(!pSearchStateSpace->heap->emptyheap() && (goalkey > minkey || searchgoalstate->g > searchgoalstate->v) &&
		(clock()-TimeStarted) < MaxNumofSecs*(double)CLOCKS_PER_SEC) 
    {

		//get the state		
		state = (ADState*)pSearchStateSpace->heap->deleteminheap();


#if DEBUG
		CKey debkey = ComputeKey(state);
		fprintf(fDeb, "expanding state(%d): g=%u v=%u h=%d key=[%d %d] iterc=%d callnuma=%d expands=%d (g(goal)=%u)\n",
			state->MDPstate->StateID, state->g, state->v, state->h, (int)debkey[0], (int)debkey[1],  
			state->iterationclosed, state->callnumberaccessed, state->numofexpands, searchgoalstate->g);
		environment_->PrintState(state->MDPstate->StateID, true, fDeb);
		fflush(fDeb);
#endif

#if DEBUG
		if(minkey.key[0] < oldkey.key[0] && fabs(this->finitial_eps - 1.0) < ERR_EPS)
		{
			printf("WARN in search: the sequence of keys decreases in an optimal search\n");
			//exit(1);
		}
		oldkey = minkey;
#endif

		if(state->v == state->g)
		{
			printf("ERROR: consistent state is being expanded\n");
			exit(1);
		}

		//new expand      
		expands++;
		state->numofexpands++;

		if(state->v > state->g)
		{
			//overconsistent expansion

			//recompute state value      
			state->v = state->g;
			state->iterationclosed = pSearchStateSpace->iteration;


#if AD_SEARCH_FORWARD == 0
			UpdatePredsofOverconsState(state, pSearchStateSpace);
#else
			UpdateSuccsofOverconsState(state, pSearchStateSpace);
#endif
		}
		else
		{
			//underconsistent expansion
			printf("underconstistent expansion\n");

			//force the state to be overconsistent
			state->v = INFINITECOST;
	
			//update state membership
			UpdateSetMembership(state);


#if AD_SEARCH_FORWARD == 0
			UpdatePredsofUnderconsState(state, pSearchStateSpace);
#else
			UpdateSuccsofUnderconsState(state, pSearchStateSpace);
#endif

		}
      

		//recompute minkey
		minkey = pSearchStateSpace->heap->getminkeyheap();

		//recompute goalkey if necessary
		goalkey = ComputeKey(searchgoalstate);

		if(expands%100000 == 0 && expands > 0)
		{
			printf("expands so far=%u\n", expands);
		}

	}

	int retv = 1;
	if(searchgoalstate->g == INFINITECOST && pSearchStateSpace->heap->emptyheap())
	{
		printf("solution does not exist: search exited because heap is empty\n");
#if DEBUG
		fprintf(fDeb, "solution does not exist: search exited because heap is empty\n");
#endif
		retv = 0;
	}
	else if(!pSearchStateSpace->heap->emptyheap() && (goalkey > minkey || searchgoalstate->g > searchgoalstate->v))
	{
		printf("search exited because it ran out of time\n");
#if DEBUG
		fprintf(fDeb, "search exited because it ran out of time\n");
#endif
		retv = 2;
	}
	else if(searchgoalstate->g == INFINITECOST && !pSearchStateSpace->heap->emptyheap())
	{
		printf("solution does not exist: search exited because all candidates for expansion have infinite heuristics\n");
#if DEBUG
		fprintf(fDeb, "solution does not exist: search exited because all candidates for expansion have infinite heuristics\n");
#endif
		retv = 0;
	}
	else
	{
		printf("search exited with a solution for eps=%.3f\n", pSearchStateSpace->eps);
#if DEBUG
		fprintf(fDeb, "search exited with a solution for eps=%.3f\n", pSearchStateSpace->eps);
#endif
		retv = 1;
	}

	//fprintf(fDeb, "expanded=%d\n", expands);

	searchexpands += expands;

	return retv;		
}
示例#10
0
const uint8_t *KeyManager::GetTemporaryMleKey(uint32_t aKeySequence)
{
    ComputeKey(aKeySequence, mTemporaryKey);
    return mTemporaryKey;
}