mirror of
https://github.com/ANL-CEEESA/MIPLearn.git
synced 2025-12-08 18:38:51 -06:00
62 lines
2.2 KiB
Python
62 lines
2.2 KiB
Python
# MIPLearn: Extensible Framework for Learning-Enhanced Mixed-Integer Optimization
|
|
# Copyright (C) 2020-2022, UChicago Argonne, LLC. All rights reserved.
|
|
# Released under the modified BSD license. See COPYING.md for more details.
|
|
|
|
import numpy as np
|
|
from scipy.stats import uniform, randint
|
|
|
|
from miplearn.problems.uc import (
|
|
UnitCommitmentData,
|
|
build_uc_model_gurobipy,
|
|
UnitCommitmentGenerator,
|
|
)
|
|
|
|
|
|
def test_generator() -> None:
|
|
np.random.seed(42)
|
|
gen = UnitCommitmentGenerator(
|
|
n_units=randint(low=3, high=4),
|
|
n_periods=randint(low=4, high=5),
|
|
max_power=uniform(loc=50, scale=450),
|
|
min_power=uniform(loc=0.25, scale=0.5),
|
|
cost_startup=uniform(loc=1, scale=1),
|
|
cost_prod=uniform(loc=1, scale=1),
|
|
cost_prod_quad=uniform(loc=1, scale=1),
|
|
cost_fixed=uniform(loc=1, scale=1),
|
|
min_uptime=randint(low=1, high=8),
|
|
min_downtime=randint(low=1, high=8),
|
|
)
|
|
data = gen.generate(1)
|
|
assert data[0].demand.tolist() == [430.3, 511.29, 484.91, 860.61]
|
|
assert data[0].min_power.tolist() == [120.05, 156.73, 124.44]
|
|
assert data[0].max_power.tolist() == [218.54, 477.82, 379.4]
|
|
assert data[0].min_uptime.tolist() == [3, 3, 5]
|
|
assert data[0].min_downtime.tolist() == [4, 3, 6]
|
|
assert data[0].cost_startup.tolist() == [1.06, 1.72, 1.94]
|
|
assert data[0].cost_prod.tolist() == [1.0, 1.99, 1.62]
|
|
assert data[0].cost_prod_quad.tolist() == [1.6117, 1.0071, 1.0231]
|
|
assert data[0].cost_fixed.tolist() == [1.52, 1.4, 1.05]
|
|
|
|
|
|
def test_uc() -> None:
|
|
data = UnitCommitmentData(
|
|
demand=np.array([10, 12, 15, 10, 8, 5]),
|
|
min_power=np.array([5, 5, 10]),
|
|
max_power=np.array([10, 8, 20]),
|
|
min_uptime=np.array([4, 3, 2]),
|
|
min_downtime=np.array([4, 3, 2]),
|
|
cost_startup=np.array([100, 120, 200]),
|
|
cost_prod=np.array([1.0, 1.25, 1.5]),
|
|
cost_fixed=np.array([10, 12, 9]),
|
|
cost_prod_quad=np.array([0, 0, 0]),
|
|
)
|
|
model = build_uc_model_gurobipy(data)
|
|
model.optimize()
|
|
assert model.inner.objVal == 154.5
|
|
|
|
|
|
if __name__ == "__main__":
|
|
data = UnitCommitmentGenerator().generate(1)[0]
|
|
model = build_uc_model_gurobipy(data)
|
|
model.optimize()
|