Hello everybody!
I am solving a MILP example (details are as follows).
from docplex.mp.model import Model
from docplex.mp.relax_linear import LinearRelaxer
n_xvars=2 # number of 'x' variables
n_yvars=2 # number of 'y' variables
#-----Model-----#
my_MILP=Model(name='MILP example')
x_vars={i+1:my_MILP.continuous_var(name='x_{}'.format(i+1),lb=-20,ub=20) for i in range(n_xvars)}
y_vars={i+1:my_MILP.integer_var(name='y_{}'.format(i+1),lb=-20,ub=20) for i in range(n_yvars)}
# Adding constraints
my_MILP.add_constraint(x_vars[1]+4*x_vars[2]>=-5)
my_MILP.add_constraint(x_vars[1]-y_vars[2]<=5)
my_MILP.add_constraint(x_vars[1]+3*y_vars[1]-10*y_vars[2]<=10)
my_MILP.add_constraint(x_vars[1]+2*x_vars[2]-3*y_vars[1]+4*y_vars[2]<=2)
# Defining objective function and solving
obj=x_vars[1]+5*x_vars[2]+6*y_vars[1]-2*y_vars[2]
my_MILP.minimize(obj)
my_MILP.print_information()
print(my_MILP.export_as_lp_string())
# Solving and solution
my_MILP.solve()
my_MILP.print_solution()
Then, I want to convert this model into an LP Relax model. For this, I wrote the following code:
my_MILP_relax = LinearRelaxer.make_relaxed_model(my_MILP)
my_MILP_relax.print_information()
print(my_MILP_relax.export_as_lp_string())
my_MILP_relax.solve()
#knap_relax.display()
my_MILP_relax.print_solution()
Then, I want to print the set of 'y' variables. When I write the following code:
for i in range( n_yvars):
print(y_vars[i+1].solution_value)
It is printing the values of MILP model. However, I want to print the values of a set of y_vars for the LP Relax model.
I request the community please help me to get those values.
Thanks,
Samiullah