Solved

Using modulo operator in constraint programming

  • 16 July 2020
  • 4 replies
  • 61 views

When I want to use the modulo function in my linear model, I get the following error: “Constraint programming constraints cannot be used in combination with real valued variables, only with integer valued variables, element valued variables and activities.”. In my constraint I calculate the modulo of (x_{zht}*(t-1), Z) where Z is a parameter and I have used the function Ord to calculate the first part of the modulo, so x_{zht}*(Ord(t)-1).

Also, I have tried making the indices a subset of Integers and label it as numeric, but then the model does not give any solution anymore (even when I turn the modulo constraint off). How can I make the constraints containing the modulo function in my linear model work?

icon

Best answer by Marcel Hunting 16 July 2020, 11:02

Hi @Anne2. You cannot use the modulo function in a linear programming problem. (Constraint programming is a different optimization technology that supports the modulo function but it does not support continuous aka real valued variables; hence the error message.)

There is way the reformulate the modulo function as follows. Assume r = mod(x,Z). Then you can reformulate this as:

 

x = y*Z + r
r <= Z - eps
r >= 0
y integer

 

Here eps is a parameter representing a positive value close to 0, e.g., 1e-4. If Z is integer then eps can be 1.

You need a new integer variable y. If your model was a LP before then it becomes a MIP.

View original

4 replies

Userlevel 3

Hi @Anne2. You cannot use the modulo function in a linear programming problem. (Constraint programming is a different optimization technology that supports the modulo function but it does not support continuous aka real valued variables; hence the error message.)

There is way the reformulate the modulo function as follows. Assume r = mod(x,Z). Then you can reformulate this as:

 

x = y*Z + r
r <= Z - eps
r >= 0
y integer

 

Here eps is a parameter representing a positive value close to 0, e.g., 1e-4. If Z is integer then eps can be 1.

You need a new integer variable y. If your model was a LP before then it becomes a MIP.

Hi, thanks a lot! For that constraint it worked. But, I also have another constraint that contains two modulo functions and I have rewritten them both in the way described above. But, the model then does not give an error nor a solution. Is there maybe something else I have to change when two modulo functions are included in a constraint?

Userlevel 3

Can you show the definition of that constraint? Or better: would it be possible to add your AIMMS project here, preferably after adding it to a zip file, or send it to our support by email if your project contains sensitive information?

Dear Marcel,

I have sent the project to the support. Thank you in advance!

 

Reply


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

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