I am developing the python code for Marking Optimization Problem by using python CPLEX library. Here is the mathematical equations.
Here is the python code (I give comments for each of the codes with the respective mathematical equations by #)
import cplex
from docplex.mp.model import Model
import numpy as np
mdl = Model(name='Marking Optimization')
inf = cplex.infinity
n = 2
A = np.array([1,2])
p = np.array([40,100])
c = np.array([20,100])
v = 3
w = 5
m = np.array([1,3])
y = mdl.integer_var(lb = 0, ub=inf, name='y')
z = np.empty((n,), dtype= object)
for i in range(n):
z[i] = mdl.integer_var(lb = 0, ub=inf, name='z' + str(i + 1))
#constraint 15
mdl.add_constraint(1 >= y*(n+1)*(2*v + 2*w))
#constraint 16
for i in range(n):
mdl.add_constraint(1 >= y*1/m[i]*(p[i] + c[i] + 2*w))
#constraint 17
for i in range(n):
mdl.add_constraint(m[i] - z[i] >= y*(p[i] + 3*v + 4*w))
#constraint 18
for i in range(len(A)):
mdl.add_constraint((1 + z[i] >= y*((n+1 -2*(len(A)))*(2*v + 2*w) + (2*w+v+c[i]))))
#constraint 19A
for i in range(n):
mdl.add_constraint(0 <= z[i])
#constraint 19B
for i in range(n):
mdl.add_constraint(z[i] <= m[i] -1)
#equation 14
mdl.maximize(y)
mdl.print_information()
solver = mdl.solve() #(log_output=True)
if solver is not None:
mdl.print_solution()
else:
print("Solver is error")
When I run the program, the result is not as expected. The correct answer should be y = 0.014285, z1 = 0 and z2 = 1. However the result from the code is 0 as below screenshot.
Could anyone tell me, what is wrong here and what should I do, please? Thank you in advance!