How to add divisibility constraint in GNU mathprog

95 Views Asked by At

I want to add a constraint that a variable should be divisible by a particular integer. I tried using mod operator but it cannot be used with variables:

s.t. c1 x1 mod 10 = 0

I get the following error:

operand preceding mod has invalid type

How to resolve it?

1

There are 1 best solutions below

0
Erwin Kalvelagen On

This is actually surprisingly easy.

Your constraint:

 x mod 10 = 0

is equivalent to

 x = 10 * n where n is an integer

So the recipe is: add an integer variable n and add the linear constraint:

 x = 10 * n