feat: move set_int_index to solution assignment in model.py#406
feat: move set_int_index to solution assignment in model.py#406FabianHofmann merged 10 commits intomasterfrom
Conversation
siddharth-krishna
left a comment
There was a problem hiding this comment.
Thanks Fabian, this works for me! If I understand the idea correctly, I think it's also a more elegant approach, and ensures we only call set_int_index on solutions returned from linopy.Model, which is guaranteed to have the form x1, x2, ....
Btw, here is a test file I have been using to test this issue. If it makes sense, I can add it to the tests in this PR, if you can point me to where/how to integrate them. Thanks!
#!/usr/bin/env python3
"""
Created on Tue Jan 28 09:03:35 2025.
@author: sid
"""
import sys
from pathlib import Path
from linopy import solvers
mps_problem = """
NAME sample_mip
ROWS
N obj
G c1
L c2
E c3
COLUMNS
col1 obj 5
col1 c1 2
col1 c2 4
col1 c3 1
MARK0000 'MARKER' 'INTORG'
colu2 obj 3
colu2 c1 3
colu2 c2 2
colu2 c3 1
col3 obj 7
col3 c1 4
col3 c2 3
col3 c3 1
MARK0001 'MARKER' 'INTEND'
RHS
RHS_V c1 12
RHS_V c2 15
RHS_V c3 6
BOUNDS
UP BOUND col1 4
UI BOUND colu2 3
UI BOUND col3 5
ENDATA
"""
input_file = "/tmp/sid-linopy.mps"
with open(input_file, "w") as f:
f.write(mps_problem)
s = solvers.Highs()
result = s.solve_problem(problem_fn=Path(input_file), solution_fn=Path("/tmp/sid-linopy-out.sol"))
print(result)
print(result.solution.objective)|
great, since this a new class of test (which only tackles the solver implementations) I would suggest we create a new module |
|
you can push it directly to this PR (permissions should be in place) |
|
Thanks, Fabian! I added a new test file. I also added some common virtualenv paths to the .gitignore, if you don't mind? Looks like the test is failing on some solvers: glpk, cbc Do you think it's worth investigating, or should I reduce the scope of the test to HiGHS? |
a1e56c6 to
199ad98
Compare
Follow up on #396
The internal handling of
Solutionobjects was improved for more consistency. Solution objects created from solver calls now preserve the exact index names from the input file.Checklist
doc.doc/release_notes.rstof the upcoming release is included.