Ejemplo n.º 1
0
//! suggest the node to solve
//! @param[in] strategy     "0" = short-sighted, "1" = long-sighted
//! @return                 name of the suggested node
string AOgraph::suggestNext(bool strategy)
{
    // issue a warning if the graph has been solved already
    if (head->nSolved == true)
    {
        cout<<"[WARNING] The graph is solved. No suggestion possible." <<endl;
        return "end";
    }
    
    int optimalPathIndex = 0;
        
    // short-sighted strategy:
    // pick the path which received the highest benefit from the last action
    if (strategy == false)
    {
        // find the path with highest benefit from last action
        for (int i=1; i< (int)pUpdate.size(); i++)
            if (pUpdate[i] > pUpdate[optimalPathIndex])
                optimalPathIndex = pIndices[i];
    }
    // long-sighted strategy:
    // pick the path which minimizes the cost to completion
    if (strategy == true)
        optimalPathIndex = findOptimalPath();

    AOnode* suggestion = paths[optimalPathIndex].suggestNode();
    cout<<"ENDOR suggestion: " <<endl
        <<"Suggested path = " <<optimalPathIndex <<endl
        <<"Suggested node = " <<suggestion->nName <<endl;
    
    return suggestion->nName;
}
CDynamicProgrammingStrategy::CDynamicProgrammingStrategy(const Map &_map,
                                                         const PlayerState &_initialState)
    : map(_map)
    , initialState(_initialState)
    , minPath(
            _map.sizeOnXaxis(),
            _map.sizeOnYaxis(),
            UNREACHABLE
    )
{
    minPath.SetStepCount(initialState, 0);
    stateQueue.push(initialState);

    calculatePaths();
    findOptimalPath();
}