## linearizing a constraint optmodel

how to linearize the following constraint to be able to solve it with optmodel
con Con1 {i in Item ,j in Cust}: (limit[i,'A1'] -x[i,'A1']) * x[i,'A2']=0;
where x is the decision variable.

4 REPLIES 4

## Re: linearizing a constraint optmodel

What kind of variable is x?

Also, the constraint is declared over i and j but does not depend on j. The effect is that you get multiple copies of the same equation. You can use the EXPAND statement to see this.

## Re: linearizing a constraint optmodel

X is an integer variable "quantity". the constraint depends on Both i and j.  where j is the customer A,B,C. for customer A I have two offers for customer A; A1& A2, where customer can only leverage the discounted price A2 if he takes a minimum of quantity x with price A1.

I used expand and the function is working fine.

The thing is that I need an integer variable, and I receive this error" The NLP solver does not allow integer variables" when x is defined as integer.  while, when x is not an integer it works fine but with lots of decimals

## Re: linearizing a constraint optmodel

But the equation for your constraint does not contain j anywhere.  So for the same i but different j, the constraint declaration will generate the same equation.  If you did not see duplicates when you used EXPAND, then I suspect the code you ran is somehow different than what you posted.

In any case, I think I understand what you want to accomplish.  So let me describe the model generically and you can modify it as needed to use in your optimization problem.  Suppose x and y are variables, with 0 <= x <= u, where u is some constant, and y >= 0.  You want to model the logical implication "if x > 0 then y >= c," where c is some constant.  Then you can introduce a binary variable z and the following constraints:

x <= u * z

and

y >= c * z.

If x > 0, the first constraint forces z = 1.  If z = 1, the second constraint forces y >= c.  So together they enforce the desired implication: if x > 0 then y >= c.

## Re: linearizing a constraint optmodel

Thank you Rob,

Discussion stats
• 4 replies
• 959 views
• 1 like
• 2 in conversation