diff --git a/changelog.in b/changelog.in index 42e9f48129..1253a20c15 100755 --- a/changelog.in +++ b/changelog.in @@ -183,6 +183,19 @@ restart. Failing the master, for example by posting no-goods, proves that no further solution exists. FlatZinc reported an unknown result instead. +[ENTRY] +Module: search +What: bug +Rank: minor +[DESCRIPTION] +Treat the first slave search of restart-based search as incomplete when the +slave configuration function returns false. +[MORE] +The first search always counted as complete, so a restricted first slave +search that found no solution was reported as a proof that none exists. With +FlatZinc, a model using gecode_on_restart_uniform_int could be reported as +unsatisfiable when the first random value admitted no solution. + [ENTRY] Module: search What: bug diff --git a/gecode/kernel/core.hpp b/gecode/kernel/core.hpp index e365b91d10..1be8f1bc59 100755 --- a/gecode/kernel/core.hpp +++ b/gecode/kernel/core.hpp @@ -2197,9 +2197,8 @@ namespace Gecode { * of whether the search on the slave space finishes or times out. * The no-goods recorded by an incomplete search only hold in the * slave's search space, so the meta engine does not pass them to the - * master configuration function. When search starts, the result only - * determines whether no-goods are passed: the meta engine treats the - * first search on a slave space as complete. + * master configuration function. This also holds for the first + * search when search starts. * * \li A portfolio meta engine calls this function once on each asset * (that is, on each slave) and passes the number of the asset, diff --git a/gecode/search/seq/rbs.hh b/gecode/search/seq/rbs.hh index 5d7cddf12d..10627f45b1 100755 --- a/gecode/search/seq/rbs.hh +++ b/gecode/search/seq/rbs.hh @@ -118,9 +118,8 @@ namespace Gecode { namespace Search { namespace Seq { * \brief Constructor * * The value \a complete is the result of the slave configuration of the - * space explored by the first engine \a e0. It only determines whether - * the no-goods of that search hold in the master: the meta engine treats - * the first search as complete. + * space explored by the first engine \a e0, and is used as for the + * searches after later restarts. */ RBS(Space* s, RestartStop* stop0, Engine* e0, const Search::Statistics& stat, const Options& o, bool best, diff --git a/gecode/search/seq/rbs.hpp b/gecode/search/seq/rbs.hpp index b19d6f1603..ff022f47de 100755 --- a/gecode/search/seq/rbs.hpp +++ b/gecode/search/seq/rbs.hpp @@ -99,7 +99,7 @@ namespace Gecode { namespace Search { namespace Seq { bool best0, bool complete0) : e(e0), master(s), last(nullptr), co(opt.cutoff), stop(stop0), m_opt(opt.expand()), sslr(0), - complete(true), nogoods_valid(complete0), restart(false), + complete(complete0), nogoods_valid(complete0), restart(false), best(best0), m_stopped(false) { stop->limit(stat,(*co)()); } diff --git a/test/search.cpp b/test/search.cpp index 34eb49adae..332ad62c89 100644 --- a/test/search.cpp +++ b/test/search.cpp @@ -1492,6 +1492,51 @@ namespace Test { RBSRootFailure rbs_root_failure; + /// Space with solutions whose first, incomplete slave fails at the root + class FailingFirstSlave : public RestrictedFirstSlave { + public: + FailingFirstSlave(void) = default; + FailingFirstSlave(FailingFirstSlave& s) : RestrictedFirstSlave(s) {} + Gecode::Space* copy(void) override { + return new FailingFirstSlave(*this); + } + bool slave(const Gecode::MetaInfo& mi) override { + if ((mi.type() == Gecode::MetaInfo::RESTART) && + (mi.reason() == Gecode::MetaInfo::RR_INIT)) { + fail(); + return false; + } + return true; + } + }; + + /// A failed first slave search that is incomplete is not a proof + class RBSFailedFirstSlave : public Base { + template class Engine> + static bool test(unsigned int threads) { + FailingFirstSlave* m = new FailingFirstSlave; + Gecode::Search::Options o; + o.threads = threads; + o.cutoff = Gecode::Search::Cutoff::constant(1); + Gecode::RBS rbs(m,o); + delete m; + FailingFirstSlave* s = rbs.next(); + if (s == nullptr) + return false; + delete s; + return rbs.statistics().restart >= 1U; + } + public: + RBSFailedFirstSlave(void) : Base("Search::RBS::FailedFirstSlave") {} + bool run(void) override { + return test(1U) && test(2U) && + test(1U) && test(2U) && + test(1U); + } + }; + + RBSFailedFirstSlave rbs_failed_first_slave; + /// Stop after a number of failures, or after many checks as a safeguard class FailureLimit : public Gecode::Search::Stop { public: