src/drone.cpp
// PGS Rollout policy
// Computes PGS only for non Checking actions
//TODO: consider going back to "fast" RO PGS
PGS Rollout policy
Computes PGS only for non Checking actions
TODO: consider going back to "fast" RO PGS
PGS Rollout policy Computes PGS only for non Checking actions TODO : consider going back to " fast " RO PGS
void DRONE::GeneratePGS(const STATE& state, const HISTORY& history,
                         vector<int>& legal, const STATUS& status) const
{
    static vector<int> acts;
    acts.clear();
    STATE * newstate;
    PGSLegal(state, history, acts, status);
    int numLegal = acts.size();
    double pgs_values[numLegal];
    STATE * oldstate = Copy(state);
    double pgs_state = PGS(*oldstate);
    int max_p = -1;
    double max_v = -Infinity;
    int observation;
    double reward;
    for(unsigned int i=0; i<numLegal; i++){
        newstate = Copy(state);
        StepNormal(*newstate, acts[i], observation, reward); 
        pgs_values[i] = PGS_RO(*oldstate, *newstate, acts[i], pgs_state);
        FreeState(newstate);
    }
    FreeState(oldstate);
    max_p = std::distance(pgs_values, max_element(pgs_values, pgs_values+numLegal));
    max_v = pgs_values[max_p];
    assert(max_p > -1);
    legal.push_back(acts[max_p]); 
    for(int i=0; i<numLegal; i++){
        if(i != max_p && pgs_values[i] == max_v)
            legal.push_back(acts[i]);
    }
}
void DRONE :: GeneratePGS ( const STATE & state , const HISTORY & history , vector < int > & legal , const STATUS & status ) const { static vector < int > acts ; acts . clear ( ) ; STATE * newstate ; PGSLegal ( state , history , acts , status ) ; int numLegal = acts . size ( ) ; double pgs_values [ numLegal ] ; STATE * oldstate = Copy ( state ) ; double pgs_state = PGS ( * oldstate ) ; int max_p = -1 ; double max_v = - Infinity ; int observation ; double reward ; for ( unsigned int i = 0 ; i < numLegal ; i ++ ) { newstate = Copy ( state ) ; StepNormal ( * newstate , acts [ i ] , observation , reward ) ; pgs_values [ i ] = PGS_RO ( * oldstate , * newstate , acts [ i ] , pgs_state ) ; FreeState ( newstate ) ; } FreeState ( oldstate ) ; max_p = std :: distance ( pgs_values , max_element ( pgs_values , pgs_values + numLegal ) ) ; max_v = pgs_values [ max_p ] ; assert ( max_p > -1 ) ; legal . push_back ( acts [ max_p ] ) ; for ( int i = 0 ; i < numLegal ; i ++ ) { if ( i != max_p && pgs_values [ i ] == max_v ) legal . push_back ( acts [ i ] ) ; } }
PGS Rollout policy
Computes PGS only for non Checking actions
TODO: consider going back to "fast" RO PGS
PGS Rollout policy Computes PGS only for non Checking actions TODO : consider going back to " fast " RO PGS
//cout << "Generating PGS values..." << endl; //cout << "Found " << numLegal << " legal actions." << endl; /*
     * Simulate a transition for each action (eg. lookahead) to get its PGS value
     * */ //Simulate transition with action a //Add only PGS differences (fast) //PGS(*newstate); /*
     * Return action with highest PGS, break ties randomly
     * */ //Add best action to return vector // Add other maxima //if(pgs_values[i] >= 0.5) //cout << "found " << legal.size() << " rollout actions " << endl;