Consider a simple ILP which consist of an objective function and constraints on the variables:
min x1 + x2
s.t.
x1 + x2 >= 50
x1 >= 0
x2 >= 0
To enforce your condition you can add 2 variables y
and z
and 2 constraints:
y >= x1 + x2
y == 100 * j
for some j >= 1
and change your objective function in min y
.
In code:
Original formulation
x1 = pulp.LpVariable('x1',lowBound=0,cat=pulp.LpContinuous)
x2 = pulp.LpVariable('x2',lowBound=0,cat=pulp.LpContinuous)
prob1 = pulp.LpProblem('example1',pulp.LpMinimize)
# obj
prob1+= 5*x1 + 10*x2
# constraints
prob1+= x1 + x2 >= 50
prob1.solve()
print(pulp.value(prob1.objective)) #250
Converted one
y = pulp.LpVariable('y',lowBound=0, cat=pulp.LpContinuous)
z = pulp.LpVariable('z',lowBound=1, cat=pulp.LpInteger)
prob2 = pulp.LpProblem('example2',pulp.LpMinimize)
# obj
prob2+= y
# constraints
prob2+= y >= 5*x1 + 10*x2
prob2+= y == 100 * z
prob2+= x1 + x2 >= 50
prob2.solve()
print(pulp.value(prob2.objective)) #300