diff --git a/src/clasp_facade.cpp b/src/clasp_facade.cpp index 4940dfc..6208e6c 100644 --- a/src/clasp_facade.cpp +++ b/src/clasp_facade.cpp @@ -972,6 +972,7 @@ bool ClaspFacade::read() { void ClaspFacade::prepare(EnumMode enumMode) { POTASSCO_REQUIRE(solve_.get() && !solving()); + POTASSCO_REQUIRE(!solved() || ctx.solveMode() == SharedContext::solve_multi); EnumOptions& en = config_->solve; if (solved()) { doUpdate(0, false, SIG_DFL); @@ -1020,7 +1021,8 @@ ClaspFacade::Result ClaspFacade::solve(const LitVec& a, EventHandler* handler) { } ProgramBuilder& ClaspFacade::update(bool updateConfig, void (*sigAct)(int)) { - POTASSCO_REQUIRE(config_ && program() && !solving()); + POTASSCO_REQUIRE(config_ && program() && !solving(), "Program updates not supported!"); + POTASSCO_REQUIRE(!program()->frozen() || incremental(), "Program updates not supported!"); doUpdate(program(), updateConfig, sigAct); return *program(); } diff --git a/tests/facade_test.cpp b/tests/facade_test.cpp index e73ad67..b17205a 100644 --- a/tests/facade_test.cpp +++ b/tests/facade_test.cpp @@ -203,6 +203,34 @@ TEST_CASE("Facade", "[facade]") { REQUIRE(!asp.frozen()); } + SECTION("testUpdateChecks") { + Clasp::Asp::LogicProgram& asp = libclasp.startAsp(config); + lpAdd(asp, "a :- not b. b :- not a."); + + SECTION("cannotSolveAgainInSingleSolveMode") { + REQUIRE(libclasp.solve().sat()); + REQUIRE_THROWS_AS(libclasp.prepare(), std::logic_error); + REQUIRE_THROWS_AS(libclasp.solve(), std::logic_error); + } + + SECTION("maySolveAgainInMultiSolveMode") { + libclasp.ctx.setSolveMode(Clasp::SharedContext::solve_multi); + REQUIRE(libclasp.solve().sat()); + REQUIRE_NOTHROW(libclasp.prepare()); + REQUIRE_FALSE(libclasp.solved()); + REQUIRE(libclasp.solve().sat()); + } + + SECTION("cannotUpdateInSingleShotMode") { + Clasp::Asp::LogicProgram& asp = libclasp.startAsp(config); + libclasp.keepProgram(); + lpAdd(asp, "a :- not b. b :- not a."); + REQUIRE(libclasp.solve().sat()); + REQUIRE_THROWS_AS(libclasp.update(), std::logic_error); + REQUIRE_THROWS_AS(libclasp.prepare(), std::logic_error); + } + } + SECTION("testPrepareTooStrongBound") { config.solve.numModels = 0; config.solve.optBound.assign(1, 0);