# [gecode-users] Using Linear Constraints

Max chaosangel at gmx.de
Mon Dec 1 17:24:13 CET 2008

```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

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

```