Skip to content

Commit

Permalink
Merge branch 'master' into filter-infs
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianHofmann committed Oct 31, 2024
2 parents 474a401 + 3d0275d commit 44fd9b3
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions linopy/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,19 @@ def sanitize_infinities(self) -> None:
labels = con.labels.where(~valid_infinity_values, -1)
con._data = assign_multiindex_safe(con.data, labels=labels)

def sanitize_infinities(self) -> None:
"""
Replace infinite values in the constraints with a large value.
"""
for name in self:
constraint = self[name]
valid_infinity_values = (
(constraint.sign == LESS_EQUAL) & (constraint.rhs == np.inf)
) | ((constraint.sign == GREATER_EQUAL) & (constraint.rhs == -np.inf))
self[name].data["labels"] = self[name].labels.where(
~valid_infinity_values, -1
)

def get_name_by_label(self, label: Union[int, float]) -> str:
"""
Get the constraint name of the constraint containing the passed label.
Expand Down

0 comments on commit 44fd9b3

Please sign in to comment.