2

I am using eplex and ic library and trying to solve a problem. I see that the eplex and ic provide explicit support for addition,multiplication and subtraction but there is no support for modulo or division.

More precisely, I have this code :

    FirstResult #=  (Result[I] mod Val), % Here it gives error because Result[I] is not instantiated.
    NewVal is Val+1,
    SecondResult #= (Result[I] mod NewVal)

and mod requires its two arguments to be ground but Result[I] is not instantiated, rather it has range of values. So my question is how such constraints which involve mod operation can be delayed.

jschimpf
  • 4,904
  • 11
  • 24
learner
  • 21
  • 1

1 Answers1

1

You can normally reformulate

R #= X mod Y

as

0 #=< R, R #=< Y-1,      %  R is between 0 and Y-1
X #= _*Y + R,            %  X is some multiple of Y, plus a remainder R

This assumes you are using library(ic) and you don't have any special requirements for the behaviour with negative arguments.

For library(eplex), which uses a MILP solver, you can do almost the same (as long as Y is an integer parameter), but you have to be a bit more explicit about integrality:

0 $=< R, R $=< Y-1,
integers([K,R]),
X $= K*Y + R,
jschimpf
  • 4,904
  • 11
  • 24