Intermediate variables and AddMultiplicationEquality

1,655 views
Skip to first unread message

Jack

unread,
Feb 11, 2020, 4:13:58 AM2/11/20
to or-tools-discuss
Hello,
I am also new to OR tools and have to deal with a nonlinear constraint (term x*y).

x = model.NewIntVar(0, 5, 'x')
y = model.NewIntVar(0, 8, 'y')

# Create the conmstraints
model.Add(y+2*x-x*y<30)

I found that this can be solved using intermediate boolean variables and AddMultiplicationEquality.
Don't really understand how to do this. So I have to loop through all x and y and sum it up via AddMultiplicationEquality?
Can you help me out?

Thanks,
Jack

Jack

unread,
Feb 11, 2020, 4:23:41 AM2/11/20
to or-tools-discuss
Forgot to add [CP-SAT, Python]

Xiang Chen

unread,
Feb 11, 2020, 4:35:08 AM2/11/20
to or-tools...@googlegroups.com
You have to create an intermediate integer variable:

xy = model.NewIntVar(0, 8*5, 'xy')
model.AddMultiplicationEquality(xy, [x, y])

--
You received this message because you are subscribed to the Google Groups "or-tools-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/or-tools-discuss/c0908d18-ffd8-4aa3-9cf9-6230daa10189%40googlegroups.com.

Jack

unread,
Feb 11, 2020, 5:41:08 AM2/11/20
to or-tools-discuss
Solved! Thanks a lot :)


On Tuesday, February 11, 2020 at 10:35:08 AM UTC+1, Xiang Chen wrote:
You have to create an intermediate integer variable:

xy = model.NewIntVar(0, 8*5, 'xy')
model.AddMultiplicationEquality(xy, [x, y])

El mar., 11 feb. 2020 10:23, Jack <jakob....@gmail.com> escribió:
Forgot to add [CP-SAT, Python]

On Tuesday, February 11, 2020 at 10:13:58 AM UTC+1, Jack wrote:
Hello,
I am also new to OR tools and have to deal with a nonlinear constraint (term x*y).

x = model.NewIntVar(0, 5, 'x')
y = model.NewIntVar(0, 8, 'y')

# Create the conmstraints
model.Add(y+2*x-x*y<30)

I found that this can be solved using intermediate boolean variables and AddMultiplicationEquality.
Don't really understand how to do this. So I have to loop through all x and y and sum it up via AddMultiplicationEquality?
Can you help me out?

Thanks,
Jack

--
You received this message because you are subscribed to the Google Groups "or-tools-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages