Skip to content

Commit

Permalink
Merge branch 'hotfix/2.1.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
guidotack committed Jan 10, 2018
2 parents d215ecb + 8bb12b9 commit bd0925a
Show file tree
Hide file tree
Showing 23 changed files with 624 additions and 220 deletions.
32 changes: 32 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,38 @@
All bug numbers refer to the issue tracker at
https://github.com/MiniZinc/libminizinc/issues

Version 2.1.7
=============

Changes:
- Improved linearisation for some element constraints.
- Improve performance of optimisation phase by using a queue instead of a
stack.
- Add --dll option for Gurobi backend to specify the Gurobi DLL to load.
- Add more defines_var annotations.

Bug fixes:
- Fix generation of variable names in output model (sometimes could contain
duplicates).
- Fix enum type inference for array literals with empty sets as their first
arguments. Fixes #180.
- Fix incorrect simplification of float domain constraints. Fixes #159.
- Fix ceil builtin for float values.
- Add superset decomposition for solvers that do not support set variables.
- Fix three bugs in the garbage collector.
- Fix a bug in flattening that would create duplicate variables when a
variable declaration referred to another one in its type-inst.
- Fix a crash in flattening of partial functions. Fixes #187.
- Add missing deopt builtins for all par types.
- Fix output for arrays of sets of enums.
- Define more functions on par opt types. Fixes #188.
- Fix type checker to accept arrays of opt set values.
- Support printing of opt enum types. Fixes #189.
- Fix evaluation of comprehensions in recursive functions.
- Fix output of Gurobi backend when used in conjunction with solns2out.
- Fix pthread linking for mzn-cbc.
- Catch type error when set literal is declared that contains another set.

Version 2.1.6
=============

Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ endif()
# The version number.
set (libminizinc_VERSION_MAJOR 2)
set (libminizinc_VERSION_MINOR 1)
set (libminizinc_VERSION_PATCH 6)
set (libminizinc_VERSION_PATCH 7)

if (ADDITIONAL_DATE_STRING)
set (libminizinc_VERSION_PATCH "${libminizinc_VERSION_PATCH}.${ADDITIONAL_DATE_STRING}")
Expand Down Expand Up @@ -556,7 +556,7 @@ if(HAS_OSICBC) # Tested version 2.9.8. Use svn to get the latest /stable snapsh

# OSICBC_LINKEXTRAS: ArchLinux needs blas, lapack, bz2
target_link_libraries(minizinc_osicbc minizinc ${OSICBC_LIBS} ${OSICBC_LINKEXTRAS})
target_link_libraries(mzn-cbc minizinc_osicbc ${OSICBC_LIBS} ${OSICBC_LINKEXTRAS})
target_link_libraries(mzn-cbc minizinc_osicbc ${OSICBC_LIBS} ${OSICBC_LINKEXTRAS} ${CMAKE_THREAD_LIBS_INIT})

INSTALL(TARGETS minizinc_osicbc mzn-cbc
RUNTIME DESTINATION bin
Expand Down
3 changes: 2 additions & 1 deletion include/minizinc/ast.hh
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,6 @@ namespace MiniZinc {
};
/// \brief A variable declaration expression
class VarDecl : public Expression {
friend class Let;
protected:
/// Type-inst of the declared variable
TypeInst* _ti;
Expand Down Expand Up @@ -860,6 +859,8 @@ namespace MiniZinc {
int payload(void) const { return _payload; }
/// Set payload
void payload(int i) { _payload = i; }
/// Put current value on trail
void trail(void);
};

class EnvI;
Expand Down
10 changes: 8 additions & 2 deletions include/minizinc/eval_par.hh
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ namespace MiniZinc {
IntVal i, KeepAlive in, std::vector<typename Eval::ArrayVal>& a) {
{
GCLock lock;
GC::mark();
e->decl(gen,id)->trail();
e->decl(gen,id)->e(IntLit::a(i));
}
CallStackItem csi(env, e->decl(gen,id)->id(), i);
Expand Down Expand Up @@ -133,14 +135,18 @@ namespace MiniZinc {
} else {
eval_comp_set<Eval>(env, eval,e,gen,id+1,in,a);
}
GC::untrail();
e->decl(gen,id)->flat(NULL);
}

template<class Eval>
void
eval_comp_array(EnvI& env, Eval& eval, Comprehension* e, int gen, int id,
IntVal i, KeepAlive in, std::vector<typename Eval::ArrayVal>& a) {
ArrayLit* al = in()->cast<ArrayLit>();
GC::mark();
e->decl(gen,id)->trail();
CallStackItem csi(env, e->decl(gen,id)->id(), i);
ArrayLit* al = in()->cast<ArrayLit>();
e->decl(gen,id)->e(al->v()[i.toInt()]);
e->rehash();
if (id == e->n_decls(gen)-1) {
Expand Down Expand Up @@ -173,7 +179,7 @@ namespace MiniZinc {
} else {
eval_comp_array<Eval>(env, eval,e,gen,id+1,in,a);
}
e->decl(gen,id)->e(NULL);
GC::untrail();
e->decl(gen,id)->flat(NULL);
}

Expand Down
7 changes: 3 additions & 4 deletions include/minizinc/flatten_internal.hh
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ namespace MiniZinc {
Model* output;
VarOccurrences vo;
VarOccurrences output_vo;
VarOccurrences output_vo_flat;
CopyMap cmap;
IdMap<KeepAlive> reverseMappers;
struct WW {
Expand Down Expand Up @@ -340,17 +341,15 @@ namespace MiniZinc {
FloatSetVal* ndomain;
switch (bot) {
case BOT_LE:
v -= 1;
// fall through
return NULL;
case BOT_LQ:
{
Ranges::Bounded<FloatVal,FloatSetRanges> b = Ranges::Bounded<FloatVal,FloatSetRanges>::maxiter(dr,v);
ndomain = FloatSetVal::ai(b);
}
break;
case BOT_GR:
v += 1;
// fall through
return NULL;
case BOT_GQ:
{
Ranges::Bounded<FloatVal,FloatSetRanges> b = Ranges::Bounded<FloatVal,FloatSetRanges>::miniter(dr,v);
Expand Down
4 changes: 2 additions & 2 deletions include/minizinc/optimize.hh
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ namespace MiniZinc {
IdMap<int> idx;

/// Add \a to the index
void add(VarDeclI* i, int idx_i);
void add_idx(VarDeclI* i, int idx_i);
/// Add \a to the index
void add(VarDecl* e, int idx_i);
void add_idx(VarDecl* e, int idx_i);
/// Find index of \a vd
int find(VarDecl* vd);
/// Remove index of \a vd
Expand Down
3 changes: 2 additions & 1 deletion include/minizinc/solns2out.hh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <ctime>
#include <memory>
#include <iomanip>
#include <unordered_map>

#include <minizinc/model.hh>
#include <minizinc/parser.hh>
Expand All @@ -44,7 +45,7 @@ namespace MiniZinc {
Model* pOutput=0;

typedef std::pair<VarDecl*, KeepAlive> DE;
ASTStringMap<DE>::t declmap;
std::unordered_map<std::string, DE> declmap;
Expression* outputExpr = NULL;
bool fNewSol2Print = false; // should be set for evalOutput to work

Expand Down
1 change: 1 addition & 0 deletions include/minizinc/values.hh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <vector>
#include <string>
#include <limits.h>
#include <cmath>

namespace MiniZinc {
class IntVal;
Expand Down
13 changes: 9 additions & 4 deletions lib/ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,14 @@ namespace MiniZinc {
for (unsigned int i=_args.size(); i--;)
cmb_hash(Expression::hash(_args[i]));
}

void
VarDecl::trail(void) {
GC::trail(&_e,e());
if (_ti->ranges().size() > 0) {
GC::trail(reinterpret_cast<Expression**>(&_ti),_ti);
}
}

void
VarDecl::rehash(void) {
Expand Down Expand Up @@ -624,10 +632,7 @@ namespace MiniZinc {
GC::mark();
for (unsigned int i=_let.size(); i--;) {
if (VarDecl* vd = _let[i]->dyn_cast<VarDecl>()) {
GC::trail(&vd->_e,vd->e());
if (vd->ti()->ranges().size() > 0) {
GC::trail(reinterpret_cast<Expression**>(&vd->_ti),vd->ti());
}
vd->trail();
vd->e(_let_orig[i]);
}
}
Expand Down
65 changes: 63 additions & 2 deletions lib/builtins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,42 @@ namespace MiniZinc {
throw EvalError(env, e->loc(), "cannot evaluate deopt on absent value");
return eval_bool(env,e);
}

FloatVal b_deopt_float(EnvI& env, Call* call) {
ASTExprVec<Expression> args = call->args();
GCLock lock;
Expression* e = eval_par(env,args[0]);
if (e==constants().absent)
throw EvalError(env, e->loc(), "cannot evaluate deopt on absent value");
return eval_float(env,e);
}

IntSetVal* b_deopt_intset(EnvI& env, Call* call) {
ASTExprVec<Expression> args = call->args();
GCLock lock;
Expression* e = eval_par(env,args[0]);
if (e==constants().absent)
throw EvalError(env, e->loc(), "cannot evaluate deopt on absent value");
return eval_intset(env,e);
}

std::string b_deopt_string(EnvI& env, Call* call) {
ASTExprVec<Expression> args = call->args();
GCLock lock;
Expression* e = eval_par(env,args[0]);
if (e==constants().absent)
throw EvalError(env, e->loc(), "cannot evaluate deopt on absent value");
return eval_string(env,e);
}

Expression* b_deopt_expr(EnvI& env, Call* call) {
ASTExprVec<Expression> args = call->args();
GCLock lock;
Expression* e = eval_par(env,args[0]);
if (e==constants().absent)
throw EvalError(env, e->loc(), "cannot evaluate deopt on absent value");
return e;
};

IntVal b_array_lb_int(EnvI& env, Call* call) {
ASTExprVec<Expression> args = call->args();
Expand Down Expand Up @@ -2211,6 +2247,8 @@ namespace MiniZinc {
std::vector<Type> t_arrayXd(1);
t_arrayXd[0] = Type::top(-1);
rb(env, m, ASTString("array1d"), t_arrayXd, b_array1d_list);
t_arrayXd[0].ot(Type::OT_OPTIONAL);
rb(env, m, ASTString("array1d"), t_arrayXd, b_array1d_list);
t_arrayXd[0] = Type::vartop(-1);
rb(env, m, ASTString("array1d"), t_arrayXd, b_array1d_list);
t_arrayXd[0] = Type::optvartop(-1);
Expand All @@ -2221,16 +2259,20 @@ namespace MiniZinc {
t_arrayXd[0] = Type::parsetint();
t_arrayXd[1] = Type::top(-1);
rb(env, m, ASTString("array1d"), t_arrayXd, b_array1d);
t_arrayXd[1].ot(Type::OT_OPTIONAL);
rb(env, m, ASTString("array1d"), t_arrayXd, b_array1d);
t_arrayXd[1] = Type::vartop(-1);
rb(env, m, ASTString("array1d"), t_arrayXd, b_array1d);
t_arrayXd[1] = Type::optvartop(-1);
rb(env, m, ASTString("array1d"), t_arrayXd, b_array1d);
}
{
std::vector<Type> t_arrayXd(2);
t_arrayXd[0] = Type::top(-1);
t_arrayXd[0] = Type::optvartop(-1);
t_arrayXd[1] = Type::top(-1);
rb(env, m, ASTString("arrayXd"), t_arrayXd, b_arrayXd);
t_arrayXd[1].ot(Type::OT_OPTIONAL);
rb(env, m, ASTString("arrayXd"), t_arrayXd, b_arrayXd);
t_arrayXd[1] = Type::vartop(-1);
rb(env, m, ASTString("arrayXd"), t_arrayXd, b_arrayXd);
t_arrayXd[1] = Type::optvartop(-1);
Expand All @@ -2242,6 +2284,8 @@ namespace MiniZinc {
t_arrayXd[1] = Type::parsetint();
t_arrayXd[2] = Type::top(-1);
rb(env, m, ASTString("array2d"), t_arrayXd, b_array2d);
t_arrayXd[2].ot(Type::OT_OPTIONAL);
rb(env, m, ASTString("array2d"), t_arrayXd, b_array2d);
t_arrayXd[2] = Type::vartop(-1);
rb(env, m, ASTString("array2d"), t_arrayXd, b_array2d);
t_arrayXd[2] = Type::optvartop(-1);
Expand All @@ -2254,6 +2298,8 @@ namespace MiniZinc {
t_arrayXd[2] = Type::parsetint();
t_arrayXd[3] = Type::top(-1);
rb(env, m, ASTString("array3d"), t_arrayXd, b_array3d);
t_arrayXd[3].ot(Type::OT_OPTIONAL);
rb(env, m, ASTString("array3d"), t_arrayXd, b_array3d);
t_arrayXd[3] = Type::vartop(-1);
rb(env, m, ASTString("array3d"), t_arrayXd, b_array3d);
t_arrayXd[3] = Type::optvartop(-1);
Expand All @@ -2267,6 +2313,8 @@ namespace MiniZinc {
t_arrayXd[3] = Type::parsetint();
t_arrayXd[4] = Type::top(-1);
rb(env, m, ASTString("array4d"), t_arrayXd, b_array4d);
t_arrayXd[4].ot(Type::OT_OPTIONAL);
rb(env, m, ASTString("array4d"), t_arrayXd, b_array4d);
t_arrayXd[4] = Type::vartop(-1);
rb(env, m, ASTString("array4d"), t_arrayXd, b_array4d);
t_arrayXd[4] = Type::optvartop(-1);
Expand All @@ -2281,6 +2329,8 @@ namespace MiniZinc {
t_arrayXd[4] = Type::parsetint();
t_arrayXd[5] = Type::top(-1);
rb(env, m, ASTString("array5d"), t_arrayXd, b_array5d);
t_arrayXd[5].ot(Type::OT_OPTIONAL);
rb(env, m, ASTString("array5d"), t_arrayXd, b_array5d);
t_arrayXd[5] = Type::vartop(-1);
rb(env, m, ASTString("array5d"), t_arrayXd, b_array5d);
t_arrayXd[5] = Type::optvartop(-1);
Expand All @@ -2296,6 +2346,8 @@ namespace MiniZinc {
t_arrayXd[5] = Type::parsetint();
t_arrayXd[6] = Type::top(-1);
rb(env, m, ASTString("array6d"), t_arrayXd, b_array6d);
t_arrayXd[6].ot(Type::OT_OPTIONAL);
rb(env, m, ASTString("array6d"), t_arrayXd, b_array6d);
t_arrayXd[6] = Type::vartop(-1);
rb(env, m, ASTString("array6d"), t_arrayXd, b_array6d);
t_arrayXd[6] = Type::optvartop(-1);
Expand Down Expand Up @@ -2635,11 +2687,20 @@ namespace MiniZinc {
std::vector<Type> t(1);
t[0] = Type::parint();
t[0].ot(Type::OT_OPTIONAL);
t[0].bt(Type::BT_TOP);
rb(env, m, ASTString("occurs"), t, b_occurs);
rb(env, m, ASTString("deopt"), t, b_deopt_expr);
t[0].bt(Type::BT_INT);
rb(env, m, ASTString("deopt"), t, b_deopt_int);
t[0].bt(Type::BT_BOOL);
rb(env, m, ASTString("occurs"), t, b_occurs);
rb(env, m, ASTString("deopt"), t, b_deopt_bool);
t[0].bt(Type::BT_FLOAT);
rb(env, m, ASTString("deopt"), t, b_deopt_float);
t[0].bt(Type::BT_STRING);
rb(env, m, ASTString("deopt"), t, b_deopt_string);
t[0].bt(Type::BT_INT);
t[0].st(Type::ST_SET);
rb(env, m, ASTString("deopt"), t, b_deopt_intset);
}
{
std::vector<Type> t(2);
Expand Down
28 changes: 16 additions & 12 deletions lib/eval_par.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,13 +313,15 @@ namespace MiniZinc {

void checkDom(EnvI& env, Id* arg, IntSetVal* dom, Expression* e) {
bool oob = false;
if (e->type().isintset()) {
IntSetVal* ev = eval_intset(env, e);
IntSetRanges ev_r(ev);
IntSetRanges dom_r(dom);
oob = !Ranges::subset(ev_r, dom_r);
} else {
oob = !dom->contains(eval_int(env,e));
if (!e->type().isopt()) {
if (e->type().isintset()) {
IntSetVal* ev = eval_intset(env, e);
IntSetRanges ev_r(ev);
IntSetRanges dom_r(dom);
oob = !Ranges::subset(ev_r, dom_r);
} else {
oob = !dom->contains(eval_int(env,e));
}
}
if (oob) {
std::ostringstream oss;
Expand All @@ -329,11 +331,13 @@ namespace MiniZinc {
}

void checkDom(EnvI& env, Id* arg, FloatVal dom_min, FloatVal dom_max, Expression* e) {
FloatVal ev = eval_float(env, e);
if (ev < dom_min || ev > dom_max) {
std::ostringstream oss;
oss << "value for argument `" << *arg << "' out of bounds";
throw EvalError(env, e->loc(), oss.str());
if (!e->type().isopt()) {
FloatVal ev = eval_float(env, e);
if (ev < dom_min || ev > dom_max) {
std::ostringstream oss;
oss << "value for argument `" << *arg << "' out of bounds";
throw EvalError(env, e->loc(), oss.str());
}
}
}

Expand Down
Loading

0 comments on commit bd0925a

Please sign in to comment.