本文整理汇总了C++中SharedContext::attach方法的典型用法代码示例。如果您正苦于以下问题:C++ SharedContext::attach方法的具体用法?C++ SharedContext::attach怎么用?C++ SharedContext::attach使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SharedContext
的用法示例。
在下文中一共展示了SharedContext::attach方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testParallelRecord
void testParallelRecord() {
SharedContext ctx; Solver& solver = *ctx.master();
builder.startProgram(ctx, ProgramBuilder::EqOptions().noEq().noScc())
.setAtomName(1, "a").setAtomName(2, "b").setAtomName(3, "c").setAtomName(4, "d")
.startRule(CHOICERULE).addHead(1).addHead(2).addHead(3).addHead(4).endRule()
;
CPPUNIT_ASSERT_EQUAL(true, builder.endProgram());
ctx.setSolvers(2);
ctx.addEnumerator(new RecordEnumerator(0));
ctx.enumerator()->enumerate(0);
ctx.endInit();
Solver solver2;
ctx.attach(solver2);
SymbolTable& index = ctx.symTab();
solver.assume(index[1].lit) && solver.propagate();
solver.assume(index[2].lit) && solver.propagate();
solver.assume(index[3].lit) && solver.propagate();
solver.assume(index[4].lit) && solver.propagate();
CPPUNIT_ASSERT_EQUAL(uint32(0), solver.numFreeVars());
ctx.enumerator()->backtrackFromModel(solver);
solver.undoUntil(0);
CPPUNIT_ASSERT_EQUAL(true, ctx.enumerator()->update(solver2, false));
solver2.assume(index[1].lit) && solver2.propagate();
solver2.assume(index[2].lit) && solver2.propagate();
solver2.assume(index[3].lit) && solver2.propagate();
CPPUNIT_ASSERT(solver2.isFalse(index[4].lit) && solver2.propagate());
CPPUNIT_ASSERT_EQUAL(uint32(0), solver2.numFreeVars());
ctx.enumerator()->backtrackFromModel(solver2);
solver.undoUntil(0);
CPPUNIT_ASSERT_EQUAL(true, ctx.enumerator()->update(solver, false));
solver.assume(index[1].lit) && solver.propagate();
solver.assume(index[2].lit) && solver.propagate();
CPPUNIT_ASSERT(solver.isFalse(index[3].lit));
ctx.detach(solver2);
ctx.detach(solver);
solver2.undoUntil(0);
ctx.attach(solver2);
solver2.assume(index[1].lit) && solver2.propagate();
solver2.assume(index[2].lit) && solver2.propagate();
solver2.assume(index[3].lit) && solver2.propagate();
CPPUNIT_ASSERT(solver2.value(index[4].lit.var()) == value_free);
}
示例2: testParallelUpdate
void testParallelUpdate() {
SharedContext ctx; Solver& solver = *ctx.master();
builder.startProgram(ctx, ProgramBuilder::EqOptions().noEq().noScc())
.setAtomName(1, "a").setAtomName(2, "b").setAtomName(3, "c")
.startRule(CHOICERULE).addHead(1).addHead(2).addHead(3).endRule()
.startRule(OPTIMIZERULE).addToBody(2, true).endRule()
;
CPPUNIT_ASSERT_EQUAL(true, builder.endProgram());
MinimizeBuilder minBuilder;
builder.addMinimize(minBuilder);
ctx.setSolvers(2);
ctx.addEnumerator(new RecordEnumerator(0));
ctx.enumerator()->enumerate(0);
ctx.enumerator()->setMinimize(minBuilder.build(ctx));
ctx.endInit();
Solver solver2;
ctx.attach(solver2);
SymbolTable& index = ctx.symTab();
// a
solver.assume(index[1].lit);
solver.pushRootLevel(1);
solver.propagate();
// ~a
solver2.assume(~index[1].lit);
solver2.pushRootLevel(1);
solver2.propagate();
// M1: ~b, c
solver.assume(~index[2].lit);
solver.propagate();
solver.assume(index[3].lit);
solver.propagate();
CPPUNIT_ASSERT_EQUAL(uint32(0), solver.numFreeVars());
ctx.enumerator()->backtrackFromModel(solver);
solver.undoUntil(0);
// M2: ~b, ~c
solver2.assume(~index[2].lit);
solver2.propagate();
solver2.assume(~index[3].lit);
solver2.propagate();
// M2 is NOT VALID!
CPPUNIT_ASSERT_EQUAL(false, ctx.enumerator()->update(solver2, true));
}