[gecode-users] Help to express a constraint

Christian Schulte cschulte at kth.se
Tue Jun 3 09:55:45 CEST 2014


Hi Philippe,

I am sorry but at this point in time you first need to understand:
 - the difference between a C++ integer and a Gecode integer variable
 - the difference between an expression (a la expr) and a constraint (a la
rel)
 - the original constructor in your model is supposed to create constraints
and is only executed once and then solved by search, so your use of a C++
if-statement strikes me as maybe not what you intend.

Your code snippets seem to confuse these concepts which are not really
Gecode specific but general for modeling with constraints. You might to
consider first training modeling (you might consider the case studies
included in Modeling and Programming with Gecode plus the intro).

Best
Christian

--
Christian Schulte, Professor of Computer Science, KTH,
www.ict.kth.se/~cschulte/


-----Original Message-----
From: users-bounces at gecode.org [mailto:users-bounces at gecode.org] On Behalf
Of Philippe
Sent: Monday, June 02, 2014 10:35 PM
To: users at gecode.org
Subject: Re: [gecode-users] Help to express a constraint

Hello Christian,

Thanks for your answer. 
1) I realized during the WE that i don't really understand the difference
between an "rel" and a "expr" (not from a pure C++ point of view).

2) The example that i have provided point on some confusion :
I have written status(t,m) which is correct but
status(succ(t,m)) is incorrect, the correct form is status(succ(t,m),m).
Thus,  element(Status, Succ(t,m)) is syntactically correct but wrong.

3) I've found a similar solution than yours (after hard work!). With however
a big difference (probably because i'm perverted by years of imperative
programming) : 
I have written :

if (Status(t, m) != 3)
{
  BoolVar not_inprogress =
  expr(*this, element(Status.row(m), Succ(t,m)) != 3);
  BoolVar toa_of_succ =
  expr(*this, element(Time.row(m), Succ(t, m)) > ETOA[m] + 10);
  rel(*this, not_inprogress >> toa_of_succ); }

Thus, the (Status(t, m) != 3) is not part of the constraint, what are the
implications of doing this ? (that's more a constraint programming question
than a question related to gecode, i admit).


4) Is it a good point to be able to express things like that (and i could
may be try to propose some patches) :

Example 1 :
==========

expr1.1 : expr(*this, element(Status.row(m), Succ(t,m)) != 3) 

compile, but :

expr1.2 : expr(*this, Status(Succ(t,m), m) != 3);

don't, however, the first form seems to me more elegant.

Example 2 :
===========

expr2.1 :
IntVar task(*this, t, t);
expr(*this, Succ(t,m) != task);

compile, but :

expr2.2 : expr(*this, Succ(t,m) != t) 

don't. Here again, the second form seems more elegant.

Best,
Philippe



_______________________________________________
Gecode users mailing list
users at gecode.org
https://www.gecode.org/mailman/listinfo/gecode-users




More information about the users mailing list