93be33a6c2 Add complete predicate REVERT: 4f10c82056 Merge branch 'MiniZinc:master' into feature/on_restart REVERT: 0848ce7ec7 Add changelog for 2.5.5 REVERT: 44e2f770d5 Add test for insertion of ArrayLits into CSE REVERT: 8a68d3dea8 Don't insert par expressions into CSE map unless they're an ArrayLit REVERT: 6bf6f1180f Increase version number of development build REVERT: dcaac92a74 Make min/max on array of opt vars return non-optional var. This is consistent with other functions on optional arrays like sum, product, exists, forall. REVERT: 32aa288884 Update changelog REVERT: a4edf0669f Fix flattening of all-par set literals REVERT: 8c1c9605f6 Fix chain compressor, needs to ignore par constants REVERT: 0cad1c6306 Use file_path on include paths to ensure separator consistency REVERT: 05ad7d1931 Update changelog REVERT: 22f5e2557b Define HAVE_CONFIG_H only for UNIX REVERT: 81c7778d55 Define HAVE_CONFIG_H for CBC REVERT: 1f56608e10 mzn-test: don't check symmetry breaking constraints REVERT: 1a9767457e mzn-test: fix parsing %%%mzn-stat: ... output REVERT: a41533fd54 MIP: report CPU time in %%%mzn-stat: solveTime= REVERT: 9d490acd52 Updated docs on OR-Tools v8 installation REVERT: c513f6599f Add changelog for 2.5.4 REVERT: b2eef2772b Follow ids to declarations when flattening par arrays. Fixes #448. REVERT: c5c846d426 Check if result of flattening rhs of a vardecl is par. REVERT: c496052767 Escape strings when pretty printing include items REVERT: 9e379c995e Canonicalise file names before adding include items into "already seen" list REVERT: d5d5d0d88c Use generic flattening inside generators. Fixes #451. REVERT: dc8630a6e9 Small fix to multi-pass library change: use original include path if it is absolute REVERT: 79c6092bd8 Strip library paths from includes in multi-pass compilation. Fixes #455. REVERT: 897875d6d7 Compile infinite domains with holes into constraints. Fixes #457. REVERT: b4e700dc67 Don't create copies of global declarations when creating par versions of functions REVERT: 0e8cc42bb1 Fix typechecker to coerce bool to int in the objective. REVERT: e05523b344 Add test for dzn output of arrays REVERT: 1e0269000e Don't evaluate output_only arrays when generating dzn output. REVERT: 57018c31d6 Fix matrix transposition in lex2 globals REVERT: 2617c0c829 Fix output variables in lex_chain tests REVERT: ef1a250c98 another efort to fix tests REVERT: c00e199dfd Fix test globals_lex_chain.mzn REVERT: b5c997d045 Fix code analysis REVERT: 3352cf0bd5 SCIP constraint handler for lex_chain_..._orbitope REVERT: 4e71a2cc97 Globals lex_chain_..., including lex_chain_..._orbitope REVERT: d807428baf Move test specifcation into the correct folder REVERT: 5be74bc74d MIP decompositions for lex_less_(bool, int, float) REVERT: 36a554ba40 Don't modify infinte domain of optional variables. Fixes #456. REVERT: f9e5306d75 Run clang-format REVERT: 4b57667608 Fix comment reference to relevant test case REVERT: 648f2ab36d Fix equality of indirection annotations REVERT: ef7be5fd78 MIP decompositions for lex_lesseq_(bool=int, float) REVERT: 6511b14e73 Propagate cv flag correctly. REVERT: 6f27ecf1c0 Never insert par expressions into the CSE map. REVERT: 7414f3ca0f Fix cplex id in example configuration REVERT: 7ad7cec506 Update strictly_decreasing with documentation and opt version REVERT: 8029f6e957 Support undefined enums in type checker. REVERT: 79e0f0f546 Revert using mzn_in_symmetry_breaking_constraint() for SCIP's orbisack REVERT: e88efda76c Fix format REVERT: 4802031dc1 Added test mzn_in_symmetry_breaking_constraint() REVERT: e21cc2515a More format fixes 02 ... REVERT: 5bbd67c130 More format fixes... REVERT: d5f9b777ea Format fixes REVERT: 43757a09a0 Remove MIP-specific fzn_less(eq)_bool(_reif).mzn REVERT: c93b5736a3 SCIP: orbisack constraint handler 'fzn_lex_lesseq__orbisack' REVERT: 4516bb4e2c mzn-test.py: add OR-Tools as checker REVERT: e2176f017d Add fix and test for crash with empty enum. REVERT: ac7db35951 Fix documentation bugs. REVERT: 47ba245832 Fix the incorrect renaming of key in model output interface REVERT: 925796ed20 Fail on empty var domains in agenda REVERT: 1ec19d7025 Fix error messages in CMake FindGurobi, FindCPlex REVERT: 6d169475c1 mzn-test.py: Use -i for intermediate solutions REVERT: df2f3e423a Allow coercion of JSON lists to enum definitions REVERT: 2b0b8165e5 Fix clang-tidy errors REVERT: 6597bc1920 Change the CI build image location REVERT: 360c988452 Remove illegal duplicate keys in .gitlab-ci.yml REVERT: 6a5d69c64b Add missing par opt versions of coercion functions REVERT: 63014e3d8f Don't propagate annotations into annotation calls. Avoids infinite recursion. REVERT: 54b19428ab Don't use GRB_INT_PAR_NONCONVEX if it's undefined REVERT: a5bb56c47d Added piecewise_linear for non-continuous intervals git-subtree-dir: software/minizinc git-subtree-split: 93be33a6c254e54be7cd38abb7ebd6a6022f0c46
199 lines
5.9 KiB
C++
199 lines
5.9 KiB
C++
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
|
|
|
/*
|
|
* Main authors:
|
|
* Kevin Leo <kevin.leo@monash.edu>
|
|
*/
|
|
|
|
/* 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 <minizinc/MIPdomains.hh>
|
|
#include <minizinc/astexception.hh>
|
|
#include <minizinc/astiterator.hh>
|
|
#include <minizinc/builtins.hh>
|
|
#include <minizinc/copy.hh>
|
|
#include <minizinc/eval_par.hh>
|
|
#include <minizinc/flatten.hh>
|
|
#include <minizinc/flatten_internal.hh>
|
|
#include <minizinc/hash.hh>
|
|
#include <minizinc/optimize.hh>
|
|
#include <minizinc/parser.hh>
|
|
#include <minizinc/passes/compile_pass.hh>
|
|
#include <minizinc/prettyprinter.hh>
|
|
#include <minizinc/timer.hh>
|
|
#include <minizinc/typecheck.hh>
|
|
|
|
#include <fstream>
|
|
#include <utility>
|
|
|
|
namespace MiniZinc {
|
|
|
|
using std::string;
|
|
using std::vector;
|
|
|
|
Env* change_library(Env& e, vector<string>& includePaths, const string& globals_dir,
|
|
CompilePassFlags& compflags, bool verbose = false) {
|
|
GCLock lock;
|
|
CopyMap cm;
|
|
Model* m = e.envi().originalModel != nullptr ? e.envi().originalModel : e.envi().model;
|
|
auto* new_mod = new Model();
|
|
new_mod->setFilename(m->filename());
|
|
new_mod->setFilepath(m->filepath());
|
|
|
|
vector<string> new_includePaths;
|
|
|
|
if (std::find(includePaths.begin(), includePaths.end(), globals_dir) == includePaths.end()) {
|
|
new_includePaths.push_back(globals_dir);
|
|
}
|
|
new_includePaths.insert(new_includePaths.end(), includePaths.begin(), includePaths.end());
|
|
|
|
// Collect include items
|
|
vector<ASTString> include_names;
|
|
for (Item* item : *m) {
|
|
if (auto* inc = item->dynamicCast<IncludeI>()) {
|
|
include_names.push_back(inc->m()->filepath());
|
|
} else {
|
|
new_mod->addItem(copy(e.envi(), cm, item));
|
|
}
|
|
}
|
|
|
|
std::stringstream ss;
|
|
for (auto& name : include_names) {
|
|
ss << "include \"" << Printer::escapeStringLit(name) << "\";";
|
|
}
|
|
|
|
vector<SyntaxError> syntax_errors;
|
|
Env* fenv = new Env(new_mod);
|
|
// Model* inc_mod = parse(*fenv, include_names, {}, new_includePaths, true, true, verbose,
|
|
// std::cerr);
|
|
std::ostringstream dummy_file;
|
|
dummy_file << m->filepath() << "_Dummy.mzn";
|
|
Model* inc_mod = parse_from_string(*fenv, ss.str(), dummy_file.str(), new_includePaths, false,
|
|
false, true, verbose, std::cerr, syntax_errors);
|
|
if (inc_mod == nullptr) {
|
|
for (const SyntaxError& se : syntax_errors) {
|
|
std::cerr << std::endl;
|
|
std::cerr << se.what() << ": " << se.msg() << std::endl;
|
|
std::cerr << se.loc() << std::endl;
|
|
}
|
|
return nullptr;
|
|
}
|
|
auto* new_inc = new IncludeI(Location().introduce(), string("MultiPassDummy.mzn"));
|
|
new_inc->m(inc_mod);
|
|
inc_mod->setParent(new_mod);
|
|
new_mod->addItem(new_inc);
|
|
|
|
return fenv;
|
|
}
|
|
|
|
CompilePass::CompilePass(Env* e, FlatteningOptions& opts, CompilePassFlags& cflags,
|
|
string globals_library, vector<string> include_paths, bool change_lib,
|
|
bool ignore_unknown)
|
|
: _env(e),
|
|
_fopts(opts),
|
|
_compflags(cflags),
|
|
_library(std::move(globals_library)),
|
|
_includePaths(std::move(include_paths)),
|
|
_changeLibrary(change_lib),
|
|
_ignoreUnknownIds(ignore_unknown) {}
|
|
|
|
Env* CompilePass::run(Env* store, std::ostream& log) {
|
|
Timer lasttime;
|
|
if (_compflags.verbose) {
|
|
log << "\n\tCompilePass: Flatten with \'" << _library << "\' library ...\n";
|
|
}
|
|
|
|
Env* new_env;
|
|
if (_changeLibrary) {
|
|
new_env = change_library(*_env, _includePaths, _library, _compflags, _compflags.verbose);
|
|
if (new_env == nullptr) {
|
|
return nullptr;
|
|
}
|
|
new_env->envi().copyPathMapsAndState(store->envi());
|
|
} else {
|
|
new_env = _env;
|
|
}
|
|
new_env->envi().ignoreUnknownIds = _ignoreUnknownIds;
|
|
|
|
vector<TypeError> typeErrors;
|
|
MiniZinc::typecheck(*new_env, new_env->model(), typeErrors,
|
|
_compflags.modelCheckOnly || _compflags.modelInterfaceOnly,
|
|
_compflags.allowMultiAssign);
|
|
if (!typeErrors.empty()) {
|
|
std::ostringstream errstream;
|
|
for (auto& typeError : typeErrors) {
|
|
errstream << typeError.what() << ": " << typeError.msg() << std::endl;
|
|
errstream << typeError.loc() << std::endl;
|
|
}
|
|
throw Error(errstream.str());
|
|
}
|
|
|
|
register_builtins(*new_env);
|
|
|
|
try {
|
|
flatten(*new_env, _fopts);
|
|
} catch (LocationException& e) {
|
|
if (_compflags.verbose) {
|
|
log << std::endl;
|
|
}
|
|
std::ostringstream errstream;
|
|
errstream << e.what() << ": " << std::endl;
|
|
new_env->dumpErrorStack(errstream);
|
|
errstream << " " << e.msg() << std::endl;
|
|
throw Error(errstream.str());
|
|
}
|
|
|
|
if (!_compflags.noMIPdomains) {
|
|
if (_compflags.verbose) {
|
|
log << "MIP domains ...";
|
|
}
|
|
mip_domains(*new_env, _compflags.statistics);
|
|
if (_compflags.verbose) {
|
|
log << " done (" << lasttime.stoptime() << ")" << std::endl;
|
|
}
|
|
}
|
|
|
|
if (_compflags.optimize) {
|
|
if (_compflags.verbose) {
|
|
log << "Optimizing ...";
|
|
}
|
|
optimize(*new_env, _compflags.chainCompression);
|
|
if (_compflags.verbose) {
|
|
log << " done (" << lasttime.stoptime() << ")" << std::endl;
|
|
}
|
|
}
|
|
|
|
for (const auto& i : new_env->warnings()) {
|
|
log << (_compflags.werror ? "\n ERROR: " : "\n WARNING: ") << i;
|
|
}
|
|
if (_compflags.werror && !new_env->warnings().empty()) {
|
|
throw Error("errors encountered");
|
|
}
|
|
new_env->clearWarnings();
|
|
|
|
if (!_compflags.newfzn) {
|
|
if (_compflags.verbose) {
|
|
log << "Converting to old FlatZinc ...";
|
|
}
|
|
oldflatzinc(*new_env);
|
|
if (_compflags.verbose) {
|
|
log << " done (" << lasttime.stoptime() << ")" << std::endl;
|
|
}
|
|
} else {
|
|
new_env->flat()->compact();
|
|
new_env->output()->compact();
|
|
}
|
|
|
|
if (_compflags.verbose) {
|
|
log << " done (" << lasttime.stoptime() << ")" << std::endl;
|
|
}
|
|
|
|
return new_env;
|
|
}
|
|
|
|
CompilePass::~CompilePass(){};
|
|
|
|
} // namespace MiniZinc
|