admin管理员组

文章数量:1289528

I am using Pyomo with the HiGHS solver to optimize a model. The problem I am facing is that, after solving the model and loading the solution using model.solutions.load_from(opt_results), the values do not always remain consistent throughout the process.

With CBC, the solution was always stable across all steps. However, with HiGHS, the values printed immediately after solving (print_results(model)) do not always match the values accessed later inside add_iteration_result(model).

Here is the relevant part of my code:

# Optimizer launch
opt_results = pyomo.SolverFactory('appsi_highs').solve(model, load_solutions=False, timelimit=3000)
# opt_results.write()  # (no solution, hence cannot write results)

# Creating results dictionary to export
optimizer_results = SC.SolverResults(
    opt_results.Solver[0].Termination_condition, cap_cons,
    opt_results.Solver[0].Termination_message, opt_results.Solver[0].system_time, capacity_factor
)

# Case 1: Feasible solution found
if opt_results.solver.termination_condition == TerminationCondition.optimal:
    
    # Loading solutions because it is optimal
    model.solutions.load_from(opt_results)
    completed = True

    # Print and plot results
    Export.print_results(model)

    # Save iteration result
    ITERATION = Export.add_iteration_result(model, TIME, SECTORS, I, ITERATION)
    
    # Create result
    result = Export.create_feasible_result(SC, ITERATION, Cost, K, Cmax, HEC, m, optimizer_results, model)

I previously used CBC with the same code:

opt_results = pyomo.SolverFactory('cbc').solve(model)
opt_results.write()

With CBC, the solution was always consistent across the entire process. With HiGHS, sometimes the values retrieved later do not match those initially printed.

It seems like model.solutions.load_from(opt_results) does not persist the solution properly when using HiGHS.

Has anyone else encountered this issue? Is there a better way to ensure HiGHS' solution is correctly loaded into the model?

本文标签: optimizationPyomoHiGHS Solution values sometimes change after loading the resultsStack Overflow