예제 #1
0
//==============================================================================
value_type MoveSelector::minValue(
    const BitBoardPtr &spBoard,
    const value_type &depth,
    value_type alpha,
    value_type beta
) const
{
    ValidMoveSet vms(m_wpMoveSet, spBoard);
    value_type score = m_evaluator.Score(spBoard, vms);

    if (reachedEndState(depth, score))
    {
        return score;
    }

    MoveList moves = vms.GetMyValidMoves();
    value_type v = s_posInfinity;

    for (auto it = moves.begin(); it != moves.end(); ++it)
    {
        BitBoardPtr spResult = result(spBoard, *it);
        v = std::min(v, maxValue(spResult, depth-1, alpha, beta));

        if (score <= alpha)
        {
            return v;
        }

        beta = std::min(beta, v);
    }

    return v;
}
예제 #2
0
//==============================================================================
Move MoveSelector::GetBestMove(const value_type &maxDepth) const
{
    BitBoardPtr spBoard = m_wpBoard.lock();

    ValidMoveSet vms(m_wpMoveSet, spBoard);
    MoveList moves = vms.GetMyValidMoves();

    value_type bestValue = s_negInfinity;
    Move bestMove;

    for (auto it = moves.begin(); it != moves.end(); ++it)
    {
        BitBoardPtr spResult = result(spBoard, *it);

        value_type oldVal = bestValue;
        value_type min = minValue(spResult, maxDepth, s_negInfinity, s_posInfinity);
        bestValue = std::max(bestValue, min);

        if (bestValue > oldVal)
        {
            bestMove = *it;
        }
    }

    return bestMove;
}
예제 #3
0
//==============================================================================
bool ChessGame::MakeMove(Move &move) const
{
    ValidMoveSet vms(m_wpMoveSet, m_spBoard);
    MoveList list = vms.GetMyValidMoves();

    // Check all valid moves - if this move is valid, make it
    for (auto it = list.begin(); it != list.end(); ++it)
    {
        if (move == *it)
        {
            LOGD(m_gameId, "Made valid move: %s", move);
            m_spBoard->MakeMove(move);
            return true;
        }
    }

    LOGD(m_gameId, "Made invalid move: %s", move);
    return false;
}
    virtual_machines_placement<traits_type> do_placement(data_center_type const& dc)
    {
        DCS_DEBUG_TRACE("BEGIN Initial Placement");//XXX
        ::std::cerr << "[optimal_initial_placement] BEGIN Initial Placement" << ::std::endl;//XXX
        typedef typename traits_type::physical_machine_identifier_type physical_machine_identifier_type;
        typedef typename traits_type::virtual_machine_identifier_type virtual_machine_identifier_type;
        typedef ::std::map<virtual_machine_identifier_type,real_type> virtual_machine_utilization_map;
        typedef typename optimal_solver_type::physical_virtual_machine_map physical_virtual_machine_map;
        typedef typename physical_virtual_machine_map::const_iterator physical_virtual_machine_iterator;
        typedef typename optimal_solver_type::resource_share_container resource_share_container;
        typedef typename data_center_type::physical_machine_type physical_machine_type;
        typedef typename data_center_type::physical_machine_pointer physical_machine_pointer;
        typedef typename data_center_type::virtual_machine_type virtual_machine_type;
        typedef typename data_center_type::virtual_machine_pointer virtual_machine_pointer;
        typedef typename data_center_type::application_type application_type;
        typedef typename application_type::reference_physical_resource_type ref_resource_type;
        typedef typename application_type::reference_physical_resource_container ref_resource_container;
        typedef typename ref_resource_container::const_iterator ref_resource_iterator;


        virtual_machine_utilization_map vm_util_map;

        // Retrieve application performance info
        {
            typedef ::std::vector<virtual_machine_pointer> virtual_machine_container;
            typedef typename virtual_machine_container::const_iterator virtual_machine_iterator;

            virtual_machine_container vms(dc.active_virtual_machines());
            virtual_machine_iterator vm_end_it(vms.end());
            for (virtual_machine_iterator vm_it = vms.begin(); vm_it != vm_end_it; ++vm_it)
            {
                virtual_machine_pointer ptr_vm(*vm_it);

                // paranoid-check: null
                DCS_DEBUG_ASSERT( ptr_vm );

                ref_resource_container rress(ptr_vm->guest_system().application().reference_resources());
                ref_resource_iterator rress_end_it(rress.end());
                for (ref_resource_iterator rress_it = rress.begin(); rress_it != rress_end_it; ++rress_it)
                {
                    ref_resource_type res(*rress_it);

                    //TODO: CPU resource category not yet handle in app simulation model and optimization problem
                    DCS_ASSERT(
                        res.category() == cpu_resource_category,
                        DCS_EXCEPTION_THROW(
                            ::std::runtime_error,
                            "Resource categories other than CPU are not yet implemented."
                        )
                    );

                    vm_util_map[ptr_vm->id()] = ptr_vm->guest_system().application().performance_model().tier_measure(
                                                    ptr_vm->guest_system().id(),
                                                    ::dcs::des::cloud::utilization_performance_measure
                                                );
                    ::std::cerr << "[optimal_initial_placement] VM: " << *ptr_vm << " - U: " << vm_util_map.at(ptr_vm->id()) << ::std::endl;//XXX
                }
            }
        }

        // Solve the optimization problem

        //optimal_solver_type solver;

        ptr_solver_->solve(dc, wp_, ws_, this->reference_share_penalty(), vm_util_map);

        // Check solution and act accordingly

        //FIXME: handle ref_penalty

        if (!ptr_solver_->result().solved())
        {
            throw ::std::runtime_error("[dcs::des::cloud::optimal_initial_placement_strategy] Unable to solve optimal problem.");
        }

        virtual_machines_placement<traits_type> deployment;

        physical_virtual_machine_map pm_vm_map(ptr_solver_->result().placement());
//[XXX]
        ::std::cerr << "CHECK SOLVER INITIAL PLACEMENT" << ::std::endl;//XXX
        for (typename physical_virtual_machine_map::const_iterator it = ptr_solver_->result().placement().begin(); it != ptr_solver_->result().placement().end(); ++it)//XXX
        {   //XXX
            ::std::cerr << "VM ID: " << (it->first.second) << " placed on PM ID: " << (it->first.first) << " with SHARE: " << ((it->second)[0].second) << ::std::endl;//XXX
        }//XXX
//[/XXX]
        physical_virtual_machine_iterator pm_vm_end_it(pm_vm_map.end());
        for (physical_virtual_machine_iterator pm_vm_it = pm_vm_map.begin(); pm_vm_it != pm_vm_end_it; ++pm_vm_it)
        {
            physical_machine_pointer ptr_pm(dc.physical_machine_ptr(pm_vm_it->first.first));
            virtual_machine_pointer ptr_vm(dc.virtual_machine_ptr(pm_vm_it->first.second));
            resource_share_container shares(pm_vm_it->second);

//::std::cerr << "Going to migrate VM (" << pm_vm_it->first.second << "): " << *ptr_vm << " into PM (" << pm_vm_it->first.first << "): " << *ptr_pm << ::std::endl; //XXX
            deployment.place(*ptr_vm,
                             *ptr_pm,
                             shares.begin(),
                             shares.end());
            DCS_DEBUG_TRACE("Placed: VM(" << ptr_vm->id() << ") -> PM(" << ptr_pm->id() << ")");//XXX
        }

        ::std::cerr << "[optimal_initial_placement] END Initial Placement" << ::std::endl;//XXX
        DCS_DEBUG_TRACE("END Initial Placement ==> " << deployment);///XXX
        return deployment;
    }
예제 #5
0
파일: modify.cpp 프로젝트: paud/d2x-xl
 friend vms operator +(vms v1, vms v2) {
   return vms(v1.x+v2.x,v1.y+v2.y,v1.z+v2.z);
 }
예제 #6
0
//==============================================================================
bool ChessGame::anyValidMoves() const
{
    ValidMoveSet vms(m_wpMoveSet, m_spBoard);
    return !vms.GetMyValidMoves().empty();
}