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


C++ Domain::formulas_end方法代码示例

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


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

示例1: walksatSolver

boost::unordered_set<Model> MCSat::sampleSat(const Model& initialModel, const Domain& d, boost::mt19937& rng) {
    boost::unordered_set<Model> models;
    models.insert(initialModel); // always include the initial model

    // transform domain into a SAT problem
    Domain dSat;
    for (Domain::fact_const_iterator it = d.facts_begin(); it != d.facts_end(); it++) {
        dSat.addFact(*it);
    }
    for (Domain::formula_const_iterator it = d.formulas_begin(); it != d.formulas_end(); it++) {
        ELSentence s = *it;
        s.setHasInfWeight(true);
        dSat.addFormula(s);
    }
    dSat.addAtoms(d.atoms_begin(), d.atoms_end());
    // perform UP (if possible)
    Domain reduced;
    if (useUnitPropagation_) {
        try {
            reduced = MCSat::applyUP(dSat);
        } catch (contradiction& c) {
            return models;  // can't continue, just return our models which has only one item.
        }
    } else {
        reduced = dSat;
    }

    // rewrite infinite weighted formulas so they have singular weight
    reduced = reduced.replaceInfForms();

    // do some random restarts and hope for different models
    MWSSolver walksatSolver(walksatIterations_, walksatRandomMoveProb_, &reduced);
    for (unsigned int i = 1; i <= walksatNumRandomRestarts_; i++) {
        Model iterInitModel = reduced.randomModel(rng);   // TODO: better way to make random models
        if (reduced.formulas_size() == 0) {
            // just add the random model and continue
            models.insert(reduced.randomModel(rng));
            continue;
        }

        //std::cout << "--\nFormulas for maxwalksat: ";
        //std::copy(reduced.formulas_begin(), reduced.formulas_end(), std::ostream_iterator<ELSentence>(std::cout, ", "));
        //std::cout << std::endl;

        Model iterModel = walksatSolver.run(rng, iterInitModel);
        if (reduced.isFullySatisfied(iterModel)) models.insert(iterModel);
    }
    return models;
}
开发者ID:selmanj,项目名称:repel,代码行数:49,代码来源:MCSat.cpp

示例2: applyUP

Domain MCSat::applyUP(const Domain& d) {
    Domain reduced;
    try {
        reduced = performUnitPropagation(d);
    } catch (contradiction& c) {
        // rewrite error message
        throw contradiction("Contradiction found in MCSat::run() when running unit prop()");
    }

    // default model is guaranteed to satisfy the facts
    Model m = reduced.defaultModel();
    // check to make sure hard clauses are satisfied
    std::vector<ELSentence> hardClauses;
    std::remove_copy_if(reduced.formulas_begin(), reduced.formulas_end(), std::back_inserter(hardClauses), std::not1(IsHardClausePred()));
    for (std::vector<ELSentence>::const_iterator it = hardClauses.begin(); it != hardClauses.end(); it++) {
        if (!it->fullySatisfied(m, reduced)) {
            throw contradiction("Contradiction found in MCSat::run() when verifying hard clauses are satisfied");
        }
    }
    return reduced;
}
开发者ID:selmanj,项目名称:repel,代码行数:21,代码来源:MCSat.cpp


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