Skip to content

Commit b13c04f

Browse files
committed
Export variable and constraints names in LP files and add new lp-debug io_api
1 parent 9227a2f commit b13c04f

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

linopy/io.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,15 @@ def print_variable_anonymous(var):
7878
def print_constraint_anonymous(cons):
7979
return f"c{cons}"
8080

81-
return print_variable_anonymous, print_constraint_anonynous
81+
return print_variable_anonymous, print_constraint_anonymous
8282
else:
8383

8484
def print_variable(var):
8585
name, coord = m.variables.get_label_position(var)
8686
name = clean_name(name)
8787
return f"{name}{print_coord(coord)}"
8888

89-
def print_constraint(constraints, cons):
89+
def print_constraint(cons):
9090
name, coord = m.constraints.get_label_position(cons)
9191
name = clean_name(name)
9292
return f"{name}{print_coord(coord)}"
@@ -709,6 +709,8 @@ def to_file(
709709

710710
if io_api == "lp":
711711
to_lp_file(m, fn, integer_label, slice_size=slice_size, progress=progress)
712+
elif io_api == "lp-debug":
713+
to_lp_file(m, fn, integer_label, slice_size=slice_size, progress=progress, anonymously=False)
712714
elif io_api == "lp-polars":
713715
to_lp_file_polars(
714716
m, fn, integer_label, slice_size=slice_size, progress=progress
@@ -726,7 +728,7 @@ def to_file(
726728
h.writeModel(str(fn))
727729
else:
728730
raise ValueError(
729-
f"Invalid io_api '{io_api}'. Choose from 'lp', 'lp-polars' or 'mps'."
731+
f"Invalid io_api '{io_api}'. Choose from 'lp', 'lp-debug', 'lp-polars' or 'mps'."
730732
)
731733

732734
return fn

linopy/solvers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"mindopt",
4444
]
4545

46-
FILE_IO_APIS = ["lp", "lp-polars", "mps"]
46+
FILE_IO_APIS = ["lp", "lp-debug", "lp-polars", "mps"]
4747
IO_APIS = FILE_IO_APIS + ["direct"]
4848

4949
available_solvers = []

test/test_io.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,16 @@ def test_to_file_lp(model, tmp_path):
126126
gurobipy.read(str(fn))
127127

128128

129+
@pytest.mark.skipif("gurobi" not in available_solvers, reason="Gurobipy not installed")
130+
def test_to_file_lp_debug(model, tmp_path):
131+
import gurobipy
132+
133+
fn = tmp_path / "test.lp"
134+
model.to_file(fn, io_api='lp-debug')
135+
136+
gurobipy.read(str(fn))
137+
138+
129139
@pytest.mark.skipif("gurobi" not in available_solvers, reason="Gurobipy not installed")
130140
def test_to_file_lp_None(model):
131141
import gurobipy

0 commit comments

Comments
 (0)