Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
guidotack committed Oct 5, 2015
2 parents 52bafdb + aa8347e commit e543fde
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 13 deletions.
38 changes: 25 additions & 13 deletions lib/optimize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -829,16 +829,12 @@ namespace MiniZinc {
Id* ident = c->args()[0]->isa<Id>() ? c->args()[0]->cast<Id>() : c->args()[1]->cast<Id>();
Expression* arg = c->args()[0]->isa<Id>() ? c->args()[1] : c->args()[0];
bool canRemove = false;
if (ident->decl()->e()==NULL) {
ident->decl()->e(c->args()[0]->isa<IntLit>() ? c->args()[0] : c->args()[1]);
canRemove = true;
}
TypeInst* ti = ident->decl()->ti();
switch (ident->type().bt()) {
case Type::BT_BOOL:
if (ti->domain() == NULL) {
ti->domain(constants().boollit(eval_bool(env,arg)));
ti->setComputedDomain(true);
ti->setComputedDomain(false);
canRemove = true;
} else {
if (eval_bool(env,ti->domain())==eval_bool(env,arg)) {
Expand All @@ -854,13 +850,13 @@ namespace MiniZinc {
IntVal d = eval_int(env,arg);
if (ti->domain() == NULL) {
ti->domain(new SetLit(Location().introduce(), IntSetVal::a(d,d)));
ti->setComputedDomain(true);
ti->setComputedDomain(false);
canRemove = true;
} else {
IntSetVal* isv = eval_intset(env,ti->domain());
if (isv->contains(d)) {
ident->decl()->ti()->domain(new SetLit(Location().introduce(), IntSetVal::a(d,d)));
ident->decl()->ti()->setComputedDomain(true);
ident->decl()->ti()->setComputedDomain(false);
canRemove = true;
} else {
env.flat()->fail(env);
Expand All @@ -873,13 +869,13 @@ namespace MiniZinc {
{
if (ti->domain() == NULL) {
ti->domain(new BinOp(Location().introduce(), arg, BOT_DOTDOT, arg));
ti->setComputedDomain(true);
ti->setComputedDomain(false);
canRemove = true;
} else {
FloatVal value = eval_float(env,arg);
if (LinearTraits<FloatLit>::domain_contains(ti->domain()->cast<BinOp>(), value)) {
ti->domain(new BinOp(Location().introduce(), arg, BOT_DOTDOT, arg));
ti->setComputedDomain(true);
ti->setComputedDomain(false);
canRemove = true;
} else {
env.flat()->fail(env);
Expand All @@ -891,7 +887,14 @@ namespace MiniZinc {
default:
break;
}

if (ident->decl()->e()==NULL) {
ident->decl()->e(c->args()[0]->isa<Id>() ? c->args()[1] : c->args()[0]);
ti->setComputedDomain(true);
canRemove = true;
}

if (ident->decl()->e()->isa<Call>())
constraintQueue.push_back((*env.flat())[env.vo.find(ident->decl())]);
pushDependentConstraints(env, ident, constraintQueue);
if (canRemove) {
CollectDecls cd(env.vo,deletedVarDecls,ii);
Expand Down Expand Up @@ -1011,8 +1014,19 @@ namespace MiniZinc {
}
case OptimizeRegistry::CS_REWRITE:
{
CollectDecls cd(env.vo,deletedVarDecls,ii);

std::vector<VarDecl*> tdv;
CollectDecls cd(env.vo,tdv,ii);
topDown(cd,c);

CollectOccurrencesE ce(env.vo,ii);
topDown(ce,rewrite);

for (unsigned int i=0; i<tdv.size(); i++) {
if (env.vo.occurrences(tdv[i])==0)
deletedVarDecls.push_back(tdv[i]);
}

assert(rewrite != NULL);
if (ConstraintI* ci = ii->dyn_cast<ConstraintI>()) {
ci->e(rewrite);
Expand All @@ -1028,8 +1042,6 @@ namespace MiniZinc {
}
pushVarDecl(env, vdi, env.vo.find(vdi->e()), vardeclQueue);
}
CollectOccurrencesE ce(env.vo,ii);
topDown(ce,rewrite);
return true;
}
}
Expand Down
24 changes: 24 additions & 0 deletions tests/unit/evaluation/minizinc/regression/test_bug54.mzn
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
% RUNS ON mzn20_fd

function var int:mydiv(var int: x, var int: y) =
let {constraint y != 0 } in
safediv(x, y)
;

function var int: safediv(var int: x, var int: y) :: promise_total =
let {
var 0..ub(x): q;
var 0..ub(y)-1: r;
constraint q*y + r = x;
constraint r < y;
} in q;

var int: x;
var int: y;
var int: z;

constraint x = 7;
constraint y = 1;
constraint z = mydiv(x,y);

solve satisfy;
4 changes: 4 additions & 0 deletions tests/unit/evaluation/minizinc/regression/test_bug54.ozn
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
output ["x = ",show(x),";\n","y = ",show(y),";\n","z = ",show(z),";\n"];
int: x;
int: y;
int: z;

0 comments on commit e543fde

Please sign in to comment.