diff --git a/doc/release_notes.rst b/doc/release_notes.rst index 6fa44dc1..a899f116 100644 --- a/doc/release_notes.rst +++ b/doc/release_notes.rst @@ -6,6 +6,8 @@ Upcoming Version **Bug Fixes** +* Fix the parsing of solutions returned by the CBC solver when solving from a file to not + assume that variables start with `x`. * Fix the retrieval of solutions from the SCIP solver, and do not turn off presolve. Version 0.5.2 diff --git a/linopy/solvers.py b/linopy/solvers.py index 144f76db..7574029a 100644 --- a/linopy/solvers.py +++ b/linopy/solvers.py @@ -453,6 +453,11 @@ def solve_problem_from_file( status = Status(SolverStatus.warning, TerminationCondition.unknown) status.legacy_status = data + # Use HiGHS to parse the problem file and find the set of variable names, needed to parse solution + h = highspy.Highs() + h.readModel(path_to_string(problem_fn)) + variables = {v.name for v in h.getVariables()} + def get_solver_solution() -> Solution: objective = float(data[len("Optimal - objective value ") :]) @@ -467,7 +472,7 @@ def get_solver_solution() -> Solution: usecols=[1, 2, 3], index_col=0, ) - variables_b = df.index.str[0] == "x" + variables_b = df.index.isin(variables) sol = df[variables_b][2] dual = df[~variables_b][3]