/* * Main authors: * Kevin Leo * Andrea Rendl * Guido Tack */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include #include #include #include #include #include #include "aux_brancher.hh" #include using namespace std; using namespace Gecode; namespace MiniZinc { GecodeSolverFactory::GecodeSolverFactory() { SolverConfig sc("org.minizinc.gecode_presolver", GECODE_VERSION); sc.name("Presolver"); sc.mznlib("-Ggecode_presolver"); sc.mznlibVersion(1); sc.supportsMzn(false); sc.description("Internal Gecode presolver plugin"); sc.tags({"cp", "float", "api", "set", "gecode_presolver", "__internal__"}); sc.stdFlags({"-a", "-n"}); SolverConfigs::registerBuiltinSolver(sc); } SolverInstanceBase::Options* GecodeSolverFactory::createOptions() { return new GecodeOptions; } SolverInstanceBase* GecodeSolverFactory::doCreateSI(Env& env, std::ostream& log, SolverInstanceBase::Options* opt) { return new GecodeSolverInstance(env, log, opt); } string GecodeSolverFactory::getDescription(SolverInstanceBase::Options* /*opt*/) { string v = "Gecode solver plugin, compiled " __DATE__ ", using: Gecode version " + string(GECODE_VERSION); return v; } string GecodeSolverFactory::getVersion(SolverInstanceBase::Options* /*opt*/) { return string(GECODE_VERSION); } bool GecodeSolverFactory::processOption(SolverInstanceBase::Options* opt, int& i, std::vector& argv, const std::string& workingDir) { auto& _opt = static_cast(*opt); if (string(argv[i]) == "--allow-unbounded-vars") { _opt.allowUnboundedVars = true; } else if (string(argv[i]) == "--only-range-domains") { _opt.onlyRangeDomains = true; } else if (string(argv[i]) == "--sac") { _opt.sac = true; } else if (string(argv[i]) == "--shave") { _opt.shave = true; } else if (string(argv[i]) == "--pre-passes") { if (++i == argv.size()) { return false; } int passes = atoi(argv[i].c_str()); if (passes >= 0) { _opt.prePasses = passes; } } else if (string(argv[i]) == "-a" || string(argv[i]) == "--all-solutions") { _opt.allSolutions = true; } else if (string(argv[i]) == "-n") { if (++i == argv.size()) { return false; } int n = atoi(argv[i].c_str()); if (n >= 0) { _opt.nSolutions = n; } } else if (string(argv[i]) == "--node") { if (++i == argv.size()) { return false; } int nodes = atoi(argv[i].c_str()); if (nodes >= 0) { _opt.nodes = nodes; } } else if (string(argv[i]) == "--c_d") { if (++i == argv.size()) { return false; } int c_d = atoi(argv[i].c_str()); if (c_d >= 0) { _opt.c_d = static_cast(c_d); } } else if (string(argv[i]) == "--a_d") { if (++i == argv.size()) { return false; } int a_d = atoi(argv[i].c_str()); if (a_d >= 0) { _opt.a_d = static_cast(a_d); } } else if (string(argv[i]) == "--fail") { if (++i == argv.size()) { return false; } int fails = atoi(argv[i].c_str()); if (fails >= 0) { _opt.fails = fails; } } else if (argv[i] == "--solver-time-limit" || argv[i] == "-t") { if (++i == argv.size()) { return false; } int time = atoi(argv[i].c_str()); if (time >= 0) { _opt.time = time; } } else if (string(argv[i]) == "-v" || string(argv[i]) == "--verbose-solving") { _opt.verbose = true; } else if (string(argv[i]) == "-s" || string(argv[i]) == "--solver-statistics") { _opt.statistics = true; } else { return false; } return true; } void GecodeSolverFactory::printHelp(ostream& os) { os << "Gecode solver plugin options:" << std::endl << " --allow-unbounded-vars" << std::endl << " give unbounded variables maximum bounds (this may lead to incorrect behaviour)" << std::endl << " --only-range-domains" << std::endl << " only tighten bounds" << std::endl << " --sac" << std ::endl << " singleton arc consistency" << std::endl << " --shave" << std::endl << " shave domains" << std::endl << " --pre-passes " << std::endl << " n passes of sac/shaving, 0 for fixed point" << std::endl << " --c_d " << std::endl << " recomputation commit distance" << std::endl << " --a_d " << std::endl << " recomputation adaption distance" << std::endl << " --node " << std::endl << " node cutoff (0 = none, solution mode)" << std::endl << " --fail " << std::endl << " failure cutoff (0 = none, solution mode)" << std::endl << " --time " << std::endl << " time (in ms) cutoff (0 = none, solution mode)" << std::endl << " -a, --all-solutions" << std::endl << " print intermediate solutions" << std::endl << " -n " << std::endl << " number of solutions" << std::endl << std::endl; } class GecodeEngine { public: virtual FznSpace* next() = 0; virtual bool stopped() = 0; virtual ~GecodeEngine() {} virtual Gecode::Search::Statistics statistics() = 0; }; template