当前位置: 首页>>代码示例>>C++>>正文


C++ shared_ptr::GetBGIPforLRF方法代码示例

本文整理汇总了C++中boost::shared_ptr::GetBGIPforLRF方法的典型用法代码示例。如果您正苦于以下问题:C++ shared_ptr::GetBGIPforLRF方法的具体用法?C++ shared_ptr::GetBGIPforLRF怎么用?C++ shared_ptr::GetBGIPforLRF使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在boost::shared_ptr的用法示例。


在下文中一共展示了shared_ptr::GetBGIPforLRF方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Construct_JointType_Factors_CGBG

void BGCG_SolverMaxPlus::Construct_JointType_Factors_CGBG(
        const boost::shared_ptr<const BayesianGameCollaborativeGraphical> &bgcg,
        const vector< vector<Index> >& var_indices,
        const vector< libDAI::Var >& vars,
        vector<libDAI::Factor>& facs,
        int verbosity)
{
    size_t nrLRFs = bgcg->GetNrLRFs();
    //compute nrFacs:
    size_t nrFacs =  0;
    for(Index e=0; e < nrLRFs; e++)
    {
        const BayesianGameIdenticalPayoff * bgip_e = bgcg->GetBGIPforLRF (e);
        size_t nrJT_e = bgip_e->GetNrJointTypes();
        if(verbosity >= 2)
            cout << "Edge "<<e<<" has " << nrJT_e << 
                " local joint types (i.e. factors)" <<endl;
        nrFacs += nrJT_e;
    }
    if(verbosity >= 1)
        cout << "FactorGraph has "<<nrFacs<<" factors"<<endl;
    facs.reserve(nrFacs);


    for(Index e=0; e < nrLRFs; e++)
    {
        //construct the factors for LRF component e.
        const BayesianGameIdenticalPayoff * bgip_e = bgcg->GetBGIPforLRF (e);
        Scope agentScope = bgcg->GetScope(e);

        const size_t nrJA_e =  bgip_e->GetNrJointActions();
        for(Index jtI_e=0; jtI_e < bgip_e->GetNrJointTypes(); jtI_e++)
        {
            vector<Index> indTypes_e =
                bgip_e->JointToIndividualTypeIndices(jtI_e);

            if(verbosity > 5)
                cout << "Adding factor for joint type jtI_e="<<jtI_e<<
                    " ( indtypes_e="<<SoftPrintVector(indTypes_e) << " )"<<endl;

            //compute the agent-type (i.e., factor) indices atI, get the
            //relevant variables and put them in a VarSet
            libDAI::VarSet vs;
            for(Index agI_e=0; agI_e < bgip_e->GetNrAgents(); agI_e++)
            {
                //translate agI_e to global agent index:
                Index agI = agentScope.at(agI_e);
                Index atI = var_indices[agI][indTypes_e[agI_e]];
                vs = vs | vars[atI];
                if(verbosity > 5)
                    cout << "agent "<<agI<<
                        " contributes through variable atI="<<atI<<endl;

            }
            libDAI::Real factor_vals[nrJA_e];
            for(Index jaI_e=0; jaI_e < nrJA_e; jaI_e++)
            {
                vector<Index> indAcs = 
                    bgip_e->JointToIndividualActionIndices(jaI_e);
                vector<size_t> indAcsST(indAcs.size());
                for(Index i=0; i<indAcs.size(); i++)  
                    indAcsST[i] = (size_t) indAcs[i];

                if(verbosity > 5)
                    cout << "Computing joint factor index (JFI) for vs="<<vs
                        <<", (action)indices="<< SoftPrintVector(indAcs) <<endl;
                Index jointFactorIndex = 
                    libDAI::Factor::IndividualToJointFactorIndex(vs, indAcsST);
                
                if(verbosity > 5)
                    cout << "JFI="<<jointFactorIndex<< " Utility "
                         << bgip_e->GetUtility(jtI_e, jaI_e) << " Prob "
                         << bgip_e->GetProbability(jtI_e) << endl;

                double perturbation=(1e-6*rand())/RAND_MAX;
                factor_vals[jointFactorIndex] =
                    (bgip_e->GetUtility(jtI_e, jaI_e) + perturbation) *
                    bgip_e->GetProbability(jtI_e);
            }

            libDAI::Factor f(vs, factor_vals);
            if(verbosity > 4)
            {
                cout << "Added factor f:"<< f << endl;
            }
            facs.push_back(f);
        }// <- end for jtI_e
    }// <- end for e
}
开发者ID:heckj,项目名称:MADP,代码行数:89,代码来源:BGCG_SolverMaxPlus.cpp


注:本文中的boost::shared_ptr::GetBGIPforLRF方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。