How to constrain an integer variable using a binary variable?

25 views
Skip to first unread message

firas...@gmail.com

unread,
Apr 23, 2019, 8:23:54 AM4/23/19
to AMPL Modeling Language
Hello everyone!!

I have a set of integer variables Xpdt that represents the number of units produced of product p using die d at time t. (To be determined by the solver)
Example: X111 represents the number of units produced of product 1 using die 1 at time period 1.

Each die can make one type of products per time period. (i.e. if X111 > 0, then X211 = 0 & X311 = 0)

The question is: How can I code the above condition?

The logic I have is as follows: (I hope my handwriting is readable)

IMG_20190423_121357.jpg




















Based on the logic shown in the picture above, I thought of creating a binary variable s[d,t] which will have a value of 1 if False & a value of 0 if True. Then, I will penalize s in the objective function.

I have wrote the below code in AMPL, but I am getting a message that says: Logical constraint is not an indicator constraint.

subject to c1{d in 1..Dies, t in 1..Time}:
s[d,t] = 1 ==>
(if
sum{p in 1..Parts}x[p,d,t] <= x[1,d,t] or
sum{p in 1..Parts}x[p,d,t] <= x[2,d,t] or
sum{p in 1..Parts}x[p,d,t] <= x[3,d,t] then 1) >= 1;

subject to c2{d in 1..Dies, t in 1..Time}:
s[d,t] = 0 ==>
(if
sum{p in 1..Parts}x[p,d,t] <= x[1,d,t] or
sum{p in 1..Parts}x[p,d,t] <= x[2,d,t] or
sum{p in 1..Parts}x[p,d,t] <= x[3,d,t] then 1) >= 1;


Any help in solving this issue would be highly appreciated!!

AMPL Google Group

unread,
Apr 23, 2019, 6:18:10 PM4/23/19
to Ampl Modeling Language
There is a standard way to do this. For each X[p,d,t] define also a binary variable Z[p,d,t]. Then the constraints are

Z[p,d,t] = 0 ==> X[p,d,t] = 0
sum {p in 1..Parts} Z[p,d,t] <= 1

You'll have to add "subject to" and the appropriate indexing to each constraint. The first one is a valid indicator constraint accepted by CPLEX, Gurobi, or Xpress.

--
Robert Fourer
am...@googlegroups.com
{#HS:834846086-41884#}

Firas Abdo

unread,
Apr 25, 2019, 7:46:45 AM4/25/19
to am...@googlegroups.com
Your efforts are highly appreciated Mr. Robert !!!

--
You received this message because you are subscribed to a topic in the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ampl/U86AtseSY0I/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ampl+uns...@googlegroups.com.
To post to this group, send email to am...@googlegroups.com.
Visit this group at https://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages