Why m.objective_value does not work properly when reading from MPS file?

14 Views Asked by At

I have this code, where I have two models one writen there and one in a mps file. They are the same. However the objective value for the two models is different. The objective value for m is 0.0 and the value for m2 is 23.0. Why is that?

from mip import *
m = Model()
m2 = Model()
# Load the model from the MPS file
m.read("random2.mps")
# Example: Adding variables and objective function (modify this part as needed).
x1 = m2.add_var(var_type=INTEGER, lb=0)
x2 = m2.add_var(var_type=INTEGER, lb=0)
m2.objective = maximize(x1 + 5 * x2)
# Add constraints (modify this part as needed).
m2 += -4 * x1 + 3 * x2 <= 6
m2 += 3 * x1 + 2 * x2 <= 18
# Optimize the model
m.optimize()
m2.optimize()
if m.status == OptimizationStatus.OPTIMAL:
    # Access the objective value
    objective_value = m.objective_value
    print("Optimal Objective Value m:", objective_value)
if m2.status == OptimizationStatus.OPTIMAL:
    # Access the objective value
    objective_value = m2.objective_value
    print("Optimal Objective Value m2:", objective_value)
0

There are 0 best solutions below