Skip to content

Commit

Permalink
Add distinction between different data types when checking 'sense'
Browse files Browse the repository at this point in the history
  • Loading branch information
ClaraBuettner committed Dec 18, 2023
1 parent 1d3d4c9 commit 064ce77
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions pypsa/optimization/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,13 +381,20 @@ def optimize_mga(
objective + fixed_cost <= (1 + slack) * optimal_cost, name="budget"
)

# parse optimization sense
if sense.startswith("min") or sense > 0:
sense = 1
elif sense.startswith("max") or sense < 0:
sense = -1
if isinstance(sense, str):
if sense.startswith("min"):
sense = 1
elif sense.startswith("max"):
sense = -1
else:
raise ValueError(f"Could not parse optimization sense {sense}")
else:
raise ValueError(f"Could not parse optimization sense {sense}")
if sense > 0:
sense = 1
elif sense < 0:
sense = -1
else:
raise ValueError(f"Could not parse optimization sense {sense}")

# build alternate objective
objective = []
Expand Down

0 comments on commit 064ce77

Please sign in to comment.