Skip to content

Commit

Permalink
removing duplicate tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ChouaneLouis committed May 16, 2024
1 parent 4255eff commit ec5632b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 297 deletions.
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[project]
name = "andromede_modeling_prototype"
name = "andromede"
version = "0.0.1"
license = {text="MPL-2.0"}
dependencies = [
"ortools"
]
dynamic = ["description"]

[tool.setuptools.packages.find]
# All the following settings are optional:
Expand Down
296 changes: 0 additions & 296 deletions tests/functional/test_andromede.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,166 +46,6 @@
)


def test_network() -> None:
network = Network("test")
assert network.id == "test"
assert list(network.nodes) == []
assert list(network.components) == []
assert list(network.all_components) == []
assert list(network.connections) == []

with pytest.raises(KeyError):
network.get_node("N")

N1 = Node(model=NODE_BALANCE_MODEL, id="N1")
N2 = Node(model=NODE_BALANCE_MODEL, id="N2")
network.add_node(N1)
network.add_node(N2)
assert list(network.nodes) == [N1, N2]
assert network.get_node(N1.id) == N1
assert network.get_component("N1") == Node(model=NODE_BALANCE_MODEL, id="N1")
with pytest.raises(KeyError):
network.get_component("unknown")


def test_basic_balance() -> None:
"""
Balance on one node with one fixed demand and one generation, on 1 timestep.
"""

database = DataBase()
database.add_data("D", "demand", ConstantData(100))

database.add_data("G", "p_max", ConstantData(100))
database.add_data("G", "cost", ConstantData(30))

node = Node(model=NODE_BALANCE_MODEL, id="N")
demand = create_component(
model=DEMAND_MODEL,
id="D",
)

gen = create_component(
model=GENERATOR_MODEL,
id="G",
)

network = Network("test")
network.add_node(node)
network.add_component(demand)
network.add_component(gen)
network.connect(PortRef(demand, "balance_port"), PortRef(node, "balance_port"))
network.connect(PortRef(gen, "balance_port"), PortRef(node, "balance_port"))

scenarios = 1
problem = build_problem(network, database, TimeBlock(1, [0]), scenarios)
status = problem.solver.Solve()

assert status == problem.solver.OPTIMAL
assert problem.solver.Objective().Value() == 3000


def test_link() -> None:
"""
Balance on one node with one fixed demand and one generation, on 1 timestep.
"""

database = DataBase()
database.add_data("D", "demand", ConstantData(100))

database.add_data("G", "p_max", ConstantData(100))
database.add_data("G", "cost", ConstantData(35))

database.add_data("L", "f_max", ConstantData(150))

node1 = Node(model=NODE_BALANCE_MODEL, id="1")
node2 = Node(model=NODE_BALANCE_MODEL, id="2")
demand = create_component(
model=DEMAND_MODEL,
id="D",
)
gen = create_component(
model=GENERATOR_MODEL,
id="G",
)
link = create_component(
model=LINK_MODEL,
id="L",
)

network = Network("test")
network.add_node(node1)
network.add_node(node2)
network.add_component(demand)
network.add_component(gen)
network.add_component(link)
network.connect(PortRef(demand, "balance_port"), PortRef(node1, "balance_port"))
network.connect(PortRef(gen, "balance_port"), PortRef(node2, "balance_port"))
network.connect(PortRef(link, "balance_port_from"), PortRef(node1, "balance_port"))
network.connect(PortRef(link, "balance_port_to"), PortRef(node2, "balance_port"))

scenarios = 1
problem = build_problem(network, database, TimeBlock(1, [0]), scenarios)
status = problem.solver.Solve()

assert status == problem.solver.OPTIMAL
assert problem.solver.Objective().Value() == 3500

for variable in problem.solver.variables():
if "balance_port_from" in variable.name():
assert variable.solution_value() == 100
if "balance_port_to" in variable.name():
assert variable.solution_value() == -100


def test_stacking_generation() -> None:
"""
Balance on one node with one fixed demand and 2 generations with different costs, on 1 timestep.
"""

database = DataBase()
database.add_data("D", "demand", ConstantData(150))

database.add_data("G1", "p_max", ConstantData(100))
database.add_data("G1", "cost", ConstantData(30))

database.add_data("G2", "p_max", ConstantData(100))
database.add_data("G2", "cost", ConstantData(50))

node1 = Node(model=NODE_BALANCE_MODEL, id="1")

demand = create_component(
model=DEMAND_MODEL,
id="D",
)

gen1 = create_component(
model=GENERATOR_MODEL,
id="G1",
)

gen2 = create_component(
model=GENERATOR_MODEL,
id="G2",
)

network = Network("test")
network.add_node(node1)
network.add_component(demand)
network.add_component(gen1)
network.add_component(gen2)
network.connect(PortRef(demand, "balance_port"), PortRef(node1, "balance_port"))
network.connect(PortRef(gen1, "balance_port"), PortRef(node1, "balance_port"))
network.connect(PortRef(gen2, "balance_port"), PortRef(node1, "balance_port"))

scenarios = 1
problem = build_problem(network, database, TimeBlock(1, [0]), scenarios)
status = problem.solver.Solve()

assert status == problem.solver.OPTIMAL
assert problem.solver.Objective().Value() == 30 * 100 + 50 * 50


def test_timeseries() -> None:
"""
Basic case with 2 timesteps, where the demand is 100 on first timestep and 50 on second timestep.
Expand Down Expand Up @@ -327,142 +167,6 @@ def test_variable_bound() -> None:
assert status == problem.solver.INFEASIBLE # Infeasible


def test_spillage() -> None:
"""
Balance on one node with one fixed demand and 1 generation higher than demand and 1 timestep .
"""

database = DataBase()
database.add_data("D", "demand", ConstantData(150))
database.add_data("S", "cost", ConstantData(10))

database.add_data("G1", "p_max", ConstantData(300))
database.add_data("G1", "p_min", ConstantData(200))
database.add_data("G1", "cost", ConstantData(30))

node = Node(model=NODE_BALANCE_MODEL, id="1")
spillage = create_component(model=SPILLAGE_MODEL, id="S")
demand = create_component(model=DEMAND_MODEL, id="D")

gen1 = create_component(
model=GENERATOR_MODEL_WITH_PMIN,
id="G1",
)

network = Network("test")
network.add_node(node)
network.add_component(demand)
network.add_component(gen1)
network.add_component(spillage)
network.connect(PortRef(demand, "balance_port"), PortRef(node, "balance_port"))
network.connect(PortRef(gen1, "balance_port"), PortRef(node, "balance_port"))
network.connect(PortRef(spillage, "balance_port"), PortRef(node, "balance_port"))

problem = build_problem(network, database, TimeBlock(0, [1]), 1)
status = problem.solver.Solve()

assert status == problem.solver.OPTIMAL
assert problem.solver.Objective().Value() == 30 * 200 + 50 * 10


def test_min_up_down_times() -> None:
"""
Model on 3 time steps with one thermal generation and one demand on a single node.
- Demand is the following time series : [500 MW, 0, 0]
- Thermal generation is characterized with:
- P_min = 100 MW
- P_max = 500 MW
- Min up/down time = 3
- Generation cost = 100€ / MWh
- Unsupplied energy = 3000 €/MWh
- Spillage = 10 €/MWh
The optimal solution consists is turning on the thermal plant, which must then stay on for the 3 timesteps and producing [500, 100, 100] to satisfy P_min constraints.
The optimal cost is then :
500 x 100 (prod step 1)
+ 100 x 100 (prod step 2)
+ 100 x 100 (prod step 3)
+ 100 x 10 (spillage step 2)
+ 100 x 10 (spillage step 3)
= 72 000
"""

database = DataBase()

database.add_data("G", "p_max", ConstantData(500))
database.add_data("G", "p_min", ConstantData(100))
database.add_data("G", "cost", ConstantData(100))
database.add_data("G", "d_min_up", ConstantData(3))
database.add_data("G", "d_min_down", ConstantData(3))
database.add_data("G", "nb_units_max", ConstantData(1))
database.add_data("G", "nb_failures", ConstantData(0))

database.add_data("U", "cost", ConstantData(3000))
database.add_data("S", "cost", ConstantData(10))

demand_data = TimeScenarioSeriesData(
{
TimeScenarioIndex(0, 0): 500,
TimeScenarioIndex(1, 0): 0,
TimeScenarioIndex(2, 0): 0,
}
)
database.add_data("D", "demand", demand_data)

time_block = TimeBlock(1, [0, 1, 2])
scenarios = 1

node = Node(model=NODE_BALANCE_MODEL, id="1")
demand = create_component(model=DEMAND_MODEL, id="D")

gen = create_component(model=THERMAL_CLUSTER_MODEL_HD, id="G")

spillage = create_component(model=SPILLAGE_MODEL, id="S")

unsupplied_energy = create_component(model=UNSUPPLIED_ENERGY_MODEL, id="U")

network = Network("test")
network.add_node(node)
network.add_component(demand)
network.add_component(gen)
network.add_component(spillage)
network.add_component(unsupplied_energy)
network.connect(PortRef(demand, "balance_port"), PortRef(node, "balance_port"))
network.connect(PortRef(gen, "balance_port"), PortRef(node, "balance_port"))
network.connect(PortRef(spillage, "balance_port"), PortRef(node, "balance_port"))
network.connect(
PortRef(unsupplied_energy, "balance_port"), PortRef(node, "balance_port")
)

problem = build_problem(
network,
database,
time_block,
scenarios,
border_management=BlockBorderManagement.CYCLE,
)
status = problem.solver.Solve()

assert status == problem.solver.OPTIMAL
assert problem.solver.Objective().Value() == pytest.approx(72000, abs=0.01)

output = OutputValues(problem)
expected_output = OutputValues()
expected_output.component("G").var("generation").value = [[500.0, 100.0, 100.0]]
expected_output.component("G").var("nb_on").value = [[1.0, 1.0, 1.0]]
expected_output.component("G").var("nb_start").value = [[-0.0, 0.0, 0.0]]
expected_output.component("G").var("nb_stop").value = [[0.0, 0.0, 0.0]]

expected_output.component("S").var("spillage").value = [[0.0, 100.0, 100.0]]
expected_output.component("U").var("unsupplied_energy").value = [[0.0, 0.0, 0.0]]

# TODO this test should pass with the next port implementation
# assert output == expected_output, f"Output differs from expected: {output}"

print(f"Variables values: {output}")


def generate_data(
efficiency: float, horizon: int, scenarios: int
) -> TimeScenarioSeriesData:
Expand Down

0 comments on commit ec5632b

Please sign in to comment.