Skip to content

Commit

Permalink
test fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Manish-Khanra committed Nov 20, 2024
1 parent 7ebb00f commit d159f00
Showing 1 changed file with 0 additions and 48 deletions.
48 changes: 0 additions & 48 deletions tests/test_building.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,54 +644,6 @@ def test_building_battery_discharge_constraint_simple(
assert "discharge_battery_to_market_constraint" in constraints


def test_building_flexibility_infeasible_solution(
forecast,
index,
building_components_heatpump,
default_objective,
default_flexibility_measure,
):
"""
Test the determine_optimal_operation_with_flex method with an infeasible solution.
"""
# Initialize the Building instance with flexibility enabled
building_components_heatpump["heat_pump"]["flexibility_enabled"] = True

building = Building(
id="building_flex_infeasible_test",
unit_operator="operator_hp",
index=index,
bidding_strategies={},
components=building_components_heatpump,
objective=default_objective,
flexibility_measure=default_flexibility_measure,
forecaster=forecast,
)

# Add contradictory constraints to make the model infeasible
@building.model.Constraint(building.model.time_steps)
def infeasible_constraint_lower(m, t):
"""Force total_power_input to be at least 10."""
return m.total_power_input[t] >= 10

@building.model.Constraint(building.model.time_steps)
def infeasible_constraint_upper(m, t):
"""Force total_power_input to be at most 5."""
return m.total_power_input[t] <= 5

# Call the determine_optimal_operation_with_flex method
try:
building.determine_optimal_operation_with_flex()
except RuntimeError as e:
# Ensure the solver reported infeasibility
assert "A feasible solution was not found" in str(e)

# Explicitly check that outputs were not computed due to infeasibility
assert (
building.flex_power_requirement is None
), "Flexibility outputs should not be set for infeasible models."


def test_building_infeasible_model(
forecast,
index,
Expand Down

0 comments on commit d159f00

Please sign in to comment.