Skip to main content
Solved

If statement in constraint

  • July 5, 2019
  • 4 replies
  • 2239 views

Dear all,

In my model, I work with multiple factories. Each factory has a minimum lotsize requirement, meaning that IF a product run is initiated, it must be at least xxx big. I tried to put it in as follows:

  • I have a parameter MinimumSKULotsize(f), which specifies the minimum lotsize per factory;
  • I have a binary variable ProductInFactory(f,p,t), where 1 indicates a production run of that product at that factory in that time unit, and 0 does not.
  • I have a variable ProductionAllocation(p,f,t) which indicates how much of each product is allocated to which factory at which time unit.
I tried to add the constraints:

SKULotsizeConstraint0 with index (f,p,t) | ProductInFactory(f,p,t) = 0 and definition
ProductionAllocation(f,p,t) = 0

SKULotsizeConstraint1 with index (f,p,t) | ProductInFactory(f,p,t) = 1 and definition
ProductionAllocation(f,p,t) >= MinSKULotsize(f)

However, I am getting the warning: Warning: The index domain contains the variable "ProductInFactory". The use of a variable in an index domain is not allowed.

Before this, I tried to do it with an if-statement, but then I was also met with several errors. My question is: how could I correctly apply such a constraint in this situation?

Kind regards,

Koen

Best answer by deannezhang

Koen,

Domain condition can only contain parameters. Variables cannot be used as domain condition. You need to linearize your constraint:

if ProductInFactory(f,p,t) = 0 then ProductionAllocation(f,p,t) = 0
if ProductInFactory(f,p,t) = 1 then ProductionAllocation(f,p,t) >= MinSKULotsize(f)

trying yourself first, if not people here can help

4 replies

deannezhang
AIMMS Champ
Forum|alt.badge.img+3
  • AIMMS Champ
  • 61 replies
  • Answer
  • July 8, 2019
Koen,

Domain condition can only contain parameters. Variables cannot be used as domain condition. You need to linearize your constraint:

if ProductInFactory(f,p,t) = 0 then ProductionAllocation(f,p,t) = 0
if ProductInFactory(f,p,t) = 1 then ProductionAllocation(f,p,t) >= MinSKULotsize(f)

trying yourself first, if not people here can help

Jess Es
Forum|alt.badge.img+6
  • Grand Master
  • 121 replies
  • July 25, 2019
Hi @KoenV did this answer your question? If so would you please mark "best answer" so others can find it easily? Thanks 🙂

  • Newcomer
  • 1 reply
  • June 27, 2020

Koen,

Domain condition can only contain parameters. Variables cannot be used as domain condition. You need to linearize your constraint:

if ProductInFactory(f,p,t) = 0 then ProductionAllocation(f,p,t) = 0
if ProductInFactory(f,p,t) = 1 then ProductionAllocation(f,p,t) >= MinSKULotsize(f)

trying yourself first, if not people here can help

hello.. how to write the constraint like this in the model? should I write it in the constraint or in the variable?

In my model there is a binary variable x_jm(i,m,k,t) means that route selection from i to m using ship k in t time. And there is a positive variable UF(k) which is the Utilisation Factor of ship k. There are some ships in index k, not all of them to be selected/used. So once ship k (let’s say ship k1 and k2) are selected then those ships must have utilistation factor UF(k) above 0.7.

I put the constraint like below picture but there is a warning.

 

 

Could somebody help me how to write it in the model?

Thanks.

 

Regards,

Ardhana

 


Marcel Hunting
AIMMSian
Forum|alt.badge.img+4
  • AIMMSian
  • 258 replies
  • July 2, 2020

HI @ardhanaa. You cannot formulate this in one constraint or variable definition. You can reformulate it by using the following constraints:

sum[(i,m,t), x_jm(i,m,k,t)] >= b(k)
sum[(i,m,t), x_jm(i,m,k,t)] <= M * b(k)
UF(k) >= 0.7 * b(k)
UF(k) <= N * b(k)

Here b(k) is a (new) binary variable, and M and N are upper bounds on sum[(i,m,t), x_jm(i,m,k,t)] and UF(k) respectively.



Didn't find what you were looking for? Try searching on our documentation pages:

AIMMS Developer & PRO | AIMMS How-To | AIMMS SC Navigator