/* * 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" using namespace std; using namespace Gecode; namespace MiniZinc { Gecode_SolverFactory::Gecode_SolverFactory(void) { 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* Gecode_SolverFactory::createOptions(void) { return new GecodeOptions; } SolverInstanceBase* Gecode_SolverFactory::doCreateSI(std::ostream& log, SolverInstanceBase::Options* opt) { return new GecodeSolverInstance(log, opt); } string Gecode_SolverFactory::getDescription(SolverInstanceBase::Options*) { string v = "Gecode solver plugin, compiled " __DATE__ ", using: Gecode version " + string(GECODE_VERSION); return v; } string Gecode_SolverFactory::getVersion(SolverInstanceBase::Options*) { return string(GECODE_VERSION); } bool Gecode_SolverFactory::processOption(SolverInstanceBase::Options* opt, int& i, std::vector& argv) { GecodeOptions& _opt = static_cast(*opt); if (string(argv[i]) == "--allow-unbounded-vars") { _opt.allow_unbounded_vars = true; } else if (string(argv[i]) == "--only-range-domains") { _opt.only_range_domains = 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.pre_passes = passes; } else if (string(argv[i]) == "-a" || string(argv[i]) == "--all-solutions") { _opt.all_solutions = true; } else if (string(argv[i]) == "-n") { if (++i == argv.size()) return false; int n = atoi(argv[i].c_str()); if (n >= 0) _opt.n_solutions = 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]) == "--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 Gecode_SolverFactory::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 << " --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(void) = 0; virtual bool stopped(void) = 0; virtual ~GecodeEngine(void) {} virtual Gecode::Search::Statistics statistics(void) = 0; }; template