[gecode-users] Using Linear Constraints

Christian Schulte cschulte at kth.se
Mon Dec 1 17:31:37 CET 2008


I think I already answered that: please use linear directly! Do not
decompose int several plus or minus constraints as this sacrifices
propagation.

So, in your example for 5*x+y=z, you post:
	IntArgs c(3);
	IntVarArgs xyz(3);
	c[0]= 5; xyz[0]=x;
	c[1]= 1; xyz[1]=y;
	c[2]=-1; xyz[3]=z;
	linear(home,c,xyz,IRT_EQ,0);

Cheers
Christian


--
Christian Schulte, www.ict.kth.se/~cschulte/


-----Original Message-----
From: users-bounces at gecode.org [mailto:users-bounces at gecode.org] On Behalf
Of Max
Sent: Monday, December 01, 2008 5:24 PM
To: users at gecode.org
Subject: [gecode-users] Using Linear Constraints

Hello, as already asked some time ago i still want to speed up my parser 
building the constraints using linear expressions.
Currently i'm doing the following:
I got two values (either variables or constant integers) and i want to 
for example add them:

At first, all Integer Values are converted to Variables

IntVar(this, a->getInteger(), a->getInteger());

Now, for the following operands i do:

 return plus(this, v1,v2);

Returns the linear constrained variable, thats ok, the same for minus.
If i now want to multiply two Values, i use

 return mult(this, v1,v2);
or for division

       IntVar ret(this, Gecode::Int::Limits::min, Gecode::Int::Limits::max);
       div(this, v1,v2, ret);
       return ret;
Both returning a variable.
Now i want to use linear constraints if one of my values is a constant 
integer.
I found out that plus(this, v1,v2);
translates into  linear(home, xy, IRT_EQ, z, icl, pk);
and then returns "z" as a variable.
For multiplication (constant with variable) i only found:
Minimodel::operator*
It does create a Minimodel::LinExpr.
Now i want to know how can i convert it back to variable, to set further 
operators.

For example:

(X*5)+Y

I want to create a linear expression with X*5.
Using Minimodel i do get a LinExpr.
How can i now use the function plus(this, v1,v2) to add Y as linear 
function?

Thank you for any help.
Max


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





More information about the gecode-users mailing list