Skip to content

Commit 9aa1832

Browse files
committed
add m.remove_sos_constraints
1 parent 7367e18 commit 9aa1832

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

linopy/model.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,29 @@ def remove_constraints(self, name: str | list[str]) -> None:
816816
logger.debug(f"Removed constraint: {name}")
817817
self.constraints.remove(name)
818818

819+
def remove_sos_constraints(self, variable: Variable) -> None:
820+
"""
821+
Remove all sos constraints from a given variable.
822+
823+
Parameters
824+
----------
825+
variable : Variable
826+
Variable instance from which to remove all sos constraints.
827+
Can be retrieved from `m.variables.sos`.
828+
829+
Returns
830+
-------
831+
None.
832+
"""
833+
sos_type = variable.attrs.get("sos_type")
834+
sos_dim = variable.attrs.get("sos_dim")
835+
836+
del variable.attrs["sos_type"], variable.attrs["sos_dim"]
837+
838+
logger.debug(
839+
f"Removed sos{sos_type} constraint on {sos_dim} from {variable.name}"
840+
)
841+
819842
def remove_objective(self) -> None:
820843
"""
821844
Remove the objective's linear expression from the model.

0 commit comments

Comments
 (0)