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
222 lines
9.6 KiB
C++
222 lines
9.6 KiB
C++
/*
|
|
* Main authors:
|
|
* Karsten Lehmann <karsten@satalia.com>
|
|
*/
|
|
|
|
/* 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/. */
|
|
|
|
#pragma once
|
|
|
|
#include <minizinc/plugin.hh>
|
|
#include <minizinc/solver_config.hh>
|
|
#include <minizinc/solver_instance_base.hh>
|
|
#include <minizinc/solvers/MIP/MIP_wrap.hh>
|
|
|
|
#include <xprb.h>
|
|
#include <xprs.h>
|
|
|
|
using namespace std;
|
|
|
|
class XpressPlugin : public MiniZinc::Plugin {
|
|
public:
|
|
XpressPlugin();
|
|
XpressPlugin(const std::string& dll);
|
|
// NOLINTNEXTLINE(readability-identifier-naming)
|
|
int(XPRS_CC* XPRSinit)(const char* path);
|
|
// NOLINTNEXTLINE(readability-identifier-naming)
|
|
int(XPRS_CC* XPRSfree)();
|
|
// NOLINTNEXTLINE(readability-identifier-naming)
|
|
int(XB_CC* XPRSgetversion)(char* version);
|
|
// NOLINTNEXTLINE(readability-identifier-naming)
|
|
int(XPRS_CC* XPRSgetlicerrmsg)(char* buffer, int length);
|
|
// NOLINTNEXTLINE(readability-identifier-naming)
|
|
struct xo_prob_struct*(XB_CC* XPRBgetXPRSprob)(struct Xbprob* prob);
|
|
// NOLINTNEXTLINE(readability-identifier-naming)
|
|
int(XB_CC* XPRBsetmsglevel)(struct Xbprob* prob, int level);
|
|
// NOLINTNEXTLINE(readability-identifier-naming)
|
|
int(XPRS_CC* XPRSsetlogfile)(XPRSprob prob, const char* logname);
|
|
// NOLINTNEXTLINE(readability-identifier-naming)
|
|
int(XPRS_CC* XPRSsetintcontrol)(XPRSprob prob, int _index, int _ivalue);
|
|
// NOLINTNEXTLINE(readability-identifier-naming)
|
|
int(XPRS_CC* XPRSsetdblcontrol)(XPRSprob prob, int _index, double _dvalue);
|
|
// NOLINTNEXTLINE(readability-identifier-naming)
|
|
double(XB_CC* XPRBgetsol)(struct Xbvar* var);
|
|
// NOLINTNEXTLINE(readability-identifier-naming)
|
|
int(XPRS_CC* XPRSgetintattrib)(XPRSprob prob, int _index, int* _ivalue);
|
|
// NOLINTNEXTLINE(readability-identifier-naming)
|
|
int(XPRS_CC* XPRSgetdblattrib)(XPRSprob prob, int _index, double* _dvalue);
|
|
// NOLINTNEXTLINE(readability-identifier-naming)
|
|
int(XB_CC* XPRBbegincb)(struct Xbprob* prob, struct xo_prob_struct* optprob);
|
|
// NOLINTNEXTLINE(readability-identifier-naming)
|
|
int(XB_CC* XPRBsync)(struct Xbprob* prob, int synctype);
|
|
// NOLINTNEXTLINE(readability-identifier-naming)
|
|
int(XB_CC* XPRBendcb)(struct Xbprob* prob);
|
|
// NOLINTNEXTLINE(readability-identifier-naming)
|
|
int(XB_CC* XPRBsetterm)(struct Xbctr* lct, struct Xbvar* var, double coeff);
|
|
// NOLINTNEXTLINE(readability-identifier-naming)
|
|
struct Xbvar*(XB_CC* XPRBnewvar)(struct Xbprob* prob, int type, const char* name, double bdl,
|
|
double bdu);
|
|
// NOLINTNEXTLINE(readability-identifier-naming)
|
|
struct Xbctr*(XB_CC* XPRBnewctr)(struct Xbprob* prob, const char* name, int qrtype);
|
|
// NOLINTNEXTLINE(readability-identifier-naming)
|
|
int(XB_CC* XPRBsetctrtype)(struct Xbctr* lct, int qrtype);
|
|
// NOLINTNEXTLINE(readability-identifier-naming)
|
|
int(XB_CC* XPRBexportprob)(struct Xbprob* prob, int format, const char* filename);
|
|
// NOLINTNEXTLINE(readability-identifier-naming)
|
|
int(XB_CC* XPRBgetbounds)(struct Xbvar* var, double* lbd, double* ubd);
|
|
// NOLINTNEXTLINE(readability-identifier-naming)
|
|
int(XB_CC* XPRBsetobj)(struct Xbprob* prob, struct Xbctr* ctr);
|
|
// NOLINTNEXTLINE(readability-identifier-naming)
|
|
int(XB_CC* XPRBmipoptimize)(struct Xbprob* prob, const char* alg);
|
|
// NOLINTNEXTLINE(readability-identifier-naming)
|
|
int(XB_CC* XPRBsetsense)(struct Xbprob* prob, int dir);
|
|
// NOLINTNEXTLINE(readability-identifier-naming)
|
|
int(XPRS_CC* XPRSsetcbintsol)(XPRSprob prob,
|
|
void(XPRS_CC* f_intsol)(XPRSprob prob, void* vContext), void* p);
|
|
// NOLINTNEXTLINE(readability-identifier-naming)
|
|
int(XB_CC* XPRBsetub)(struct Xbvar* var, double c);
|
|
// NOLINTNEXTLINE(readability-identifier-naming)
|
|
int(XB_CC* XPRBsetlb)(struct Xbvar* var, double c);
|
|
// NOLINTNEXTLINE(readability-identifier-naming)
|
|
int(XB_CC* XPRBsetindicator)(struct Xbctr* lct, int dir, struct Xbvar* var);
|
|
// NOLINTNEXTLINE(readability-identifier-naming)
|
|
struct Xbsol*(XB_CC* XPRBnewsol)(struct Xbprob* prob);
|
|
// NOLINTNEXTLINE(readability-identifier-naming)
|
|
int(XB_CC* XPRBsetsolvar)(struct Xbsol* sol, struct Xbvar* var, double coeff);
|
|
// NOLINTNEXTLINE(readability-identifier-naming)
|
|
int(XB_CC* XPRBaddmipsol)(struct Xbprob* prob, struct Xbsol* sol, const char* name);
|
|
// NOLINTNEXTLINE(readability-identifier-naming)
|
|
struct Xbprob*(XB_CC* XPRBnewprob)(const char* name);
|
|
// NOLINTNEXTLINE(readability-identifier-naming)
|
|
int(XB_CC* XPRBdelprob)(struct Xbprob* prob);
|
|
// NOLINTNEXTLINE(readability-identifier-naming)
|
|
int(XPRS_CC* XPRSgetcontrolinfo)(XPRSprob prob, const char* sCaName, int* iHeaderId,
|
|
int* iTypeinfo);
|
|
// NOLINTNEXTLINE(readability-identifier-naming)
|
|
int(XPRS_CC* XPRSgetintcontrol)(XPRSprob prob, int _index, int* _ivalue);
|
|
// NOLINTNEXTLINE(readability-identifier-naming)
|
|
int(XPRS_CC* XPRSgetintcontrol64)(XPRSprob prob, int _index, XPRSint64* _ivalue);
|
|
// NOLINTNEXTLINE(readability-identifier-naming)
|
|
int(XPRS_CC* XPRSgetdblcontrol)(XPRSprob prob, int _index, double* _dvalue);
|
|
// NOLINTNEXTLINE(readability-identifier-naming)
|
|
int(XPRS_CC* XPRSgetstrcontrol)(XPRSprob prob, int _index, char* _svalue);
|
|
// NOLINTNEXTLINE(readability-identifier-naming)
|
|
int(XPRS_CC* XPRSsetintcontrol64)(XPRSprob prob, int _index, XPRSint64 _ivalue);
|
|
// NOLINTNEXTLINE(readability-identifier-naming)
|
|
int(XPRS_CC* XPRSgetstringcontrol)(XPRSprob prob, int _index, char* _svalue, int _svaluesize,
|
|
int* _controlsize);
|
|
// NOLINTNEXTLINE(readability-identifier-naming)
|
|
int(XPRS_CC* XPRSsetstrcontrol)(XPRSprob prob, int _index, const char* _svalue);
|
|
|
|
private:
|
|
void loadDll();
|
|
static const std::vector<std::string>& dlls();
|
|
};
|
|
|
|
class MIPxpressWrapper : public MIPWrapper {
|
|
public:
|
|
class FactoryOptions {
|
|
public:
|
|
bool processOption(int& i, std::vector<std::string>& argv, const std::string& workingDir);
|
|
|
|
std::string xpressDll;
|
|
std::string xprsPassword;
|
|
};
|
|
|
|
class Options : public MiniZinc::SolverInstanceBase::Options {
|
|
public:
|
|
int msgLevel = 0;
|
|
int timeout = 0;
|
|
int numSolutions = 0;
|
|
std::string logFile = "";
|
|
std::string writeModelFile = "";
|
|
std::string writeModelFormat = "lp";
|
|
double absGap = 0;
|
|
double relGap = 0.0001;
|
|
bool intermediateSolutions = false;
|
|
|
|
int numThreads = 0;
|
|
int randomSeed = 0;
|
|
|
|
std::unordered_map<std::string, std::string> extraParams;
|
|
|
|
bool processOption(int& i, std::vector<std::string>& argv,
|
|
const std::string& workingDir = std::string());
|
|
static void printHelp(std::ostream& os);
|
|
};
|
|
|
|
private:
|
|
FactoryOptions& _factoryOptions;
|
|
Options* _options = nullptr;
|
|
XpressPlugin* _plugin = nullptr;
|
|
|
|
public:
|
|
void doAddVars(size_t n, double* obj, double* lb, double* ub, VarType* vt,
|
|
string* names) override;
|
|
void addRow(int nnz, int* rmatind, double* rmatval, LinConType sense, double rhs,
|
|
int mask = MaskConsType_Normal, const string& rowName = "") override;
|
|
void setObjSense(int s) override;
|
|
void solve() override;
|
|
void setVarLB(int iVar, double lb) override;
|
|
void setVarUB(int iVar, double ub) override;
|
|
void setVarBounds(int iVar, double lb, double ub) override;
|
|
void addIndicatorConstraint(int iBVar, int bVal, int nnz, int* rmatind, double* rmatval,
|
|
LinConType sense, double rhs,
|
|
const std::string& rowName = "") override;
|
|
bool addWarmStart(const std::vector<VarId>& vars, const std::vector<double>& vals) override;
|
|
|
|
int getNCols() override { return _variables.size(); }
|
|
int getNRows() override { return _nRows; }
|
|
double getInfBound() override { return XPRB_INFINITY; }
|
|
const double* getValues() override { return output.x; }
|
|
double getObjValue() override { return output.objVal; }
|
|
double getBestBound() override { return output.bestBound; }
|
|
double getCPUTime() override { return output.dCPUTime; }
|
|
Status getStatus() override { return output.status; }
|
|
string getStatusName() override { return output.statusName; }
|
|
int getNNodes() override { return output.nNodes; }
|
|
int getNOpen() override { return output.nOpenNodes; }
|
|
|
|
MIPxpressWrapper(FactoryOptions& factoryOpt, Options* opt)
|
|
: _factoryOptions(factoryOpt), _options(opt) {
|
|
openXpress();
|
|
};
|
|
~MIPxpressWrapper() override { closeXpress(); };
|
|
|
|
static std::string getDescription(FactoryOptions& factoryOpt,
|
|
MiniZinc::SolverInstanceBase::Options* opt = nullptr);
|
|
static std::string getVersion(FactoryOptions& factoryOpt,
|
|
MiniZinc::SolverInstanceBase::Options* opt = nullptr);
|
|
static std::string getId();
|
|
static std::string getName();
|
|
static std::vector<std::string> getTags();
|
|
static std::vector<std::string> getStdFlags();
|
|
static std::vector<std::string> getRequiredFlags(FactoryOptions& factoryOpt);
|
|
static std::vector<std::string> getFactoryFlags();
|
|
|
|
static std::vector<MiniZinc::SolverConfig::ExtraFlag> getExtraFlags(FactoryOptions& factoryOpt);
|
|
|
|
private:
|
|
XPRBprob _problem;
|
|
XPRBctr _xpressObj;
|
|
vector<XPRBvar> _variables;
|
|
size_t _nRows{0};
|
|
|
|
void openXpress();
|
|
void closeXpress();
|
|
|
|
void checkDLL();
|
|
|
|
void setUserSolutionCallback();
|
|
void setOptions();
|
|
void writeModelIfRequested();
|
|
static int convertConstraintType(LinConType sense);
|
|
static int convertVariableType(VarType varType);
|
|
static int convertObjectiveSense(int s);
|
|
XPRBctr addConstraint(int nnz, int* rmatind, double* rmatval, LinConType sense, double rhs,
|
|
int mask, const string& rowName);
|
|
void addDummyConstraint();
|
|
};
|