diff --git a/flexmeasures/data/models/planning/linear_optimization.py b/flexmeasures/data/models/planning/linear_optimization.py index f0d79f866..f7385d455 100644 --- a/flexmeasures/data/models/planning/linear_optimization.py +++ b/flexmeasures/data/models/planning/linear_optimization.py @@ -339,9 +339,16 @@ def cost_function(m): model.costs = Objective(rule=cost_function, sense=minimize) # Solve - results = SolverFactory(current_app.config.get("FLEXMEASURES_LP_SOLVER")).solve( - model - ) + solver_name = current_app.config.get("FLEXMEASURES_LP_SOLVER") + opt = SolverFactory(solver_name) + + if "highs" in solver_name.lower(): + try: + results = opt.solve(model) + except RuntimeError: + results = opt.solve(model, load_solutions=False) + else: + results = opt.solve(model) planned_costs = value(model.costs) planned_power_per_device = []