Example #1
0
double V_F(const int& n, const int& fullObs_cumulativeTime, const int& fullObs_cumulativeQuantity)
{
    double v_max;
    
    if (n==N+1)
        v_max = 0;    //V_{N+1}()=0
    else
    {
        auto parameters = make_tuple(n, fullObs_cumulativeTime, fullObs_cumulativeQuantity);
        
        bool found = false;
        //#pragma omp critical (v_map)
        {
            auto  it = v_map.find(parameters);
            if (it != v_map.end()) {
                found = true;
                v_max = it->second;
            }
        }
        
        
        if (!found)
        {
            
            //no need to search for optimal inventory level x, the myopic inventory level is optimal
            int x_opt = find_x_myopic(fullObs_cumulativeTime, fullObs_cumulativeQuantity);
            
            v_max = G_F(n, x_opt, fullObs_cumulativeTime, fullObs_cumulativeQuantity);
            
            
            if (n==1)
            {
                cout << x_opt << "\t" << v_max  << "\t";
                file << x_opt << "\t" << v_max  << "\t";
            }
            
            
            //#pragma omp critical (v_map)
            { v_map.emplace(parameters, v_max); }
            
        }
        
    }
    
    return v_max;
}
Example #2
0
/***********************************************************************
 * Internal format to return the legals in a structure that is easy
 * to check if some move is legal.
 ***********************************************************************/
void State::get_legals(boost::unordered_map<Player, boost::unordered_set<Move> >& result) const
{
    typedef boost::unordered_map<Player, boost::unordered_set<Move> > tmp_t;

    result.clear();
    std::vector<PlayerMove> legalMoves;
    legals(std::back_inserter(legalMoves));

    for(std::vector<PlayerMove>::iterator pm = legalMoves.begin(); pm != legalMoves.end(); pm++) {
        tmp_t::iterator iter_moves(result.find(pm->first));
        if(iter_moves == result.end()) {
            std::pair<tmp_t::iterator, bool> ok = result.emplace(pm->first, boost::unordered_set<Move>());
            ok.first->second.emplace(pm->second);
        } else {
            iter_moves->second.emplace(pm->second);
        }
    }
}