Example 1

[1]:
import numpy as np
import hyveopt as h2
from shilps.datasets import generate_solar_irradiance

Create system components templates

[4]:
plant_template = h2.PlantTemplate(
    name="myplant",
    location=("22°10'17.66\"S", "70° 5'23.50\"W") # ~ Tocopilla, Chile.
)

electrolizer_efficiency = h2.Gain(
    breakpoints = [0.0, 0.1, 0.4, 0.7, 1],
    slopes = [0.,2., 0.5, 0.2],
    intercepts = [0.0, -0.1, 0.5, 0.8]
)

plant_template.add(h2.TemplateElectrolizer(
    name="electrolizer",
    pnom_kW=h2.Range(0., 200.),
    gain=electrolizer_efficiency,
    inv_cost_per_kw=1500.
    )
)

plant_template.add(h2.TemplateESS(
    name="battery",
    pnom_kW=h2.Range(0., 200.),
    soc_nom_kWh=h2.Range(0., 100.),
    inv_cost_per_kw=300.
))

plant_template.add(h2.TemplatePVSystem(
    name="pv_system",
    snom_KVA=h2.Range(0., 200.),
    solar_irradiance=h2.TSParameter(tsname="si_pv_system", default=0.0),
    inv_cost_per_kw=1500.
))


Planning horizon definition and time series data generation

[5]:

insample_start = '2025-01-01' planning_horizon_start = '2025-01-01' planning_horizon_end = '2025-01-02' freq = '1h' scenarios = list(range(1, 4)) # Define time configuration time_config = h2.TimeConfig( start=planning_horizon_start, end=planning_horizon_end, freq=freq ) tsdata = h2.DataTimeSeries( tsnames=plant_template.tsnames(), scenarios=scenarios, time_config=time_config) for scenario in scenarios: # Generate solar irradiance data solar_series = generate_solar_irradiance( start_date=time_config.start, end_date=time_config.end, frequency=time_config.freq, column_dimension=1 ) # Add data to time series data tsdata[scenario].loc[:, "solar_irradiance_pv1"] = solar_series

Create and solve sizing model

[6]:
model = h2.HydrogenPlantDesign(plant_template, time_config, tsdata)

ret = model.check_constraints(model.x)

model.optimize()
model.display_variables()
gen     nevals  avg             min                                     max
0       300     -14.2568        (np.float64(-37.049834657776245),)      (np.float64(-6.400403606924987),)
1       181     -11.2196        (np.float64(-35.1124400260609),)        (np.float64(-6.400403606924987),)
2       163     -10.0903        (np.float64(-29.733630415577338),)      (np.float64(-6.400403606924987),)
3       175     -8.95495        (np.float64(-26.14615432248884),)       (np.float64(-4.669807719374384),)
4       176     -8.2904         (np.float64(-26.908103670004298),)      (np.float64(-5.137030699993553),)
5       192     -7.50766        (np.float64(-30.40538001871077),)       (np.float64(-4.585239648039815),)
6       178     -6.82837        (np.float64(-25.006919665419275),)      (np.float64(-3.6520816772347806),)
7       183     -6.33379        (np.float64(-31.127589928600244),)      (np.float64(-2.3499866941002576),)
8       182     -5.79749        (np.float64(-21.316647591434233),)      (np.float64(-2.3499866941002576),)
9       194     -5.42077        (np.float64(-29.620298226979727),)      (np.float64(-2.3499866941002576),)
10      163     -4.86271        (np.float64(-30.675712466660535),)      (np.float64(-1.538306585990291),)
11      170     -4.41034        (np.float64(-23.335768196695224),)      (np.float64(-1.538306585990291),)
12      214     -3.77383        (np.float64(-21.73248137675386),)       (np.float64(-1.1358958855328538),)
13      190     -3.49369        (np.float64(-30.250573120400368),)      (np.float64(-0.9719171431486425),)
14      185     -3.11407        (np.float64(-29.306763929026026),)      (np.float64(-0.9719171431486425),)
15      184     -2.57984        (np.float64(-31.74589384538956),)       (np.float64(-0.9719171431486425),)
16      201     -2.37726        (np.float64(-26.661554921622187),)      (np.float64(-0.05283649411353819),)
17      195     -2.19856        (np.float64(-27.20444214705944),)       (np.float64(-0.05283649411353819),)
18      181     -1.77483        (np.float64(-27.926151638601432),)      (np.float64(-0.05283649411353819),)
19      189     -1.8508725689889949     (np.float64(-27.848863628585683),)      (Individual(12.54271916),)
20      176     -1.6095947662888124     (np.float64(-29.413865036357414),)      (Individual(12.54271916),)
21      172     -1.54571                (np.float64(-28.430304935058597),)      (np.float64(-0.05283649411353819),)
22      175     -0.7407094429089411     (np.float64(-27.196052811510302),)      (Individual(12.39170907),)
23      170     -0.9629627516149749     (np.float64(-29.00099313993263),)       (Individual(12.39170907),)
24      170     -0.3990138063044213     (np.float64(-30.325095229917984),)      (Individual(12.91519982),)
25      165     0.047922468259401184    (np.float64(-29.0),)                    (Individual(13.39170907),)
26      181     0.8100040398187571      (np.float64(-29.062925984794443),)      (Individual(13.39170907),)
27      184     3.0630442132737965      (np.float64(-29.420524555607116),)      (Individual(14.29029143),)
28      163     6.578725612363231       (np.float64(-30.484703595350265),)      (Individual(14.29029143),)
29      163     8.942953503672927       (np.float64(-29.529732488525262),)      (Individual(15.39170907),)
30      170     9.311720754573882       (np.float64(-30.0),)                    (Individual(15.39170907),)
31      181     9.789417276665402       (np.float64(-31.019718738980494),)      (Individual(15.39170907),)
32      182     10.046461830683567      (np.float64(-29.892880847742962),)      (Individual(15.45071159),)
33      170     11.380133402577446      (np.float64(-31.132522564451264),)      (Individual(16.39170907),)
34      176     11.377959543292713      (np.float64(-28.433066451283842),)      (Individual(16.52888411),)
35      165     11.222756785516406      (np.float64(-29.57558353121365),)       (Individual(16.52888411),)
36      155     12.48359388637221       (np.float64(-30.0),)                    (Individual(17.45071159),)
37      174     11.8225920057278        (np.float64(-30.18310158011449),)       (Individual(18.39170907),)
38      169     12.574400143978439      (np.float64(-28.625922995315378),)      (Individual(18.39170907),)
39      166     13.898148831915671      (np.float64(-26.310362221526454),)      (Individual(18.39170907),)
40      193     12.417065575089008      (np.float64(-28.816074947614332),)      (Individual(18.45071159),)
41      197     13.100644048280397      (np.float64(-27.747901232468262),)      (Individual(18.45071159),)
42      182     12.056640351961642      (np.float64(-30.627066700558778),)      (Individual(18.45071159),)
43      169     14.527736021428552      (np.float64(-28.641604630457305),)      (Individual(19.31353655),)
44      182     14.08085628344299       (np.float64(-29.672623323138854),)      (Individual(19.45071159),)
45      183     14.185691989073781      (np.float64(-29.13804452027184),)       (Individual(19.45071159),)
46      190     13.481273359063845      (np.float64(-32.355466209089634),)      (Individual(19.45071159),)
47      187     13.777883979013938      (np.float64(-28.0),)                    (Individual(19.45071159),)
48      185     14.560692919896473      (np.float64(-26.839637184411554),)      (Individual(19.45071159),)
49      198     13.717769210169475      (np.float64(-29.420524555607116),)      (Individual(20.2064174),)
50      184     13.718368151016284      (np.float64(-28.98298554466531),)       (Individual(20.2064174),)
51      155     14.885261654196778      (np.float64(-27.894247466054317),)      (Individual(20.2064174),)
52      168     15.63285403819514       (np.float64(-28.098209652546885),)      (Individual(20.2064174),)
53      162     16.27202097782293       (np.float64(-28.548489478718825),)      (Individual(20.2064174),)
54      178     15.447755261980705      (np.float64(-28.50030562188424),)       (Individual(20.2064174),)
55      183     15.771217385513971      (np.float64(-29.349034980881235),)      (Individual(20.2064174),)
56      178     15.327903568929223      (np.float64(-29.218123989231152),)      (Individual(20.2064174),)
57      170     15.840513707553013      (np.float64(-27.868656892763667),)      (Individual(20.2064174),)
58      173     14.997795192435214      (np.float64(-29.016809816669653),)      (Individual(20.2064174),)
59      184     15.321793607534753      (np.float64(-27.0),)                    (Individual(20.2064174),)
60      173     15.986518817709591      (np.float64(-27.0),)                    (Individual(20.2064174),)
61      180     15.789480759624036      (np.float64(-29.430744118419042),)      (Individual(20.2064174),)
62      171     15.99979957733594       (np.float64(-29.4069061767527),)        (Individual(20.2064174),)
63      185     15.693465762766989      (np.float64(-29.977681704683395),)      (Individual(20.2064174),)
64      190     17.133281022442695      (np.float64(-29.868656892763667),)      (Individual(20.2064174),)
65      166     16.70698599585068       (np.float64(-31.384394830435344),)      (Individual(20.2064174),)
66      202     15.276888757033085      (np.float64(-28.885898825019567),)      (Individual(20.2064174),)
67      184     16.39706147063292       (np.float64(-26.041378483030424),)      (Individual(20.2064174),)
68      167     15.777157248285388      (np.float64(-31.50571272608788),)       (Individual(20.2064174),)
69      192     15.586448539017619      (np.float64(-27.62715516876611),)       (Individual(20.2064174),)
70      175     14.282874466630279      (np.float64(-30.50030562188424),)       (Individual(20.2064174),)
71      193     14.889824326986194      (np.float64(-27.984820001028975),)      (Individual(20.2064174),)
72      164     15.524394127965227      (np.float64(-29.423967559807924),)      (Individual(20.2064174),)
73      195     15.140192539204897      (np.float64(-28.965679891296695),)      (Individual(20.2064174),)
74      192     15.504621528787778      (np.float64(-27.747901232468262),)      (Individual(20.2064174),)
75      196     16.402088104975608      (np.float64(-29.137997592551308),)      (Individual(20.2064174),)
76      181     15.646764605535843      (np.float64(-29.596285261062537),)      (Individual(20.2064174),)
77      186     14.719840925279119      (np.float64(-28.81440925029369),)       (Individual(20.2064174),)
78      185     15.12467685101024       (np.float64(-27.90585481718537),)       (Individual(20.2064174),)
79      182     15.251717541722359      (np.float64(-27.672623323138854),)      (Individual(20.2064174),)
80      179     16.56551522575386       (np.float64(-29.12098313721662),)       (Individual(20.2064174),)
81      163     16.917145344881913      (np.float64(-28.021871590470568),)      (Individual(20.2064174),)
82      173     15.354695520184269      (np.float64(-29.12150487971027),)       (Individual(20.2064174),)
83      187     15.366260664240324      (np.float64(-28.716667157955122),)      (Individual(20.2064174),)
84      185     15.725928551173107      (np.float64(-28.201945213744487),)      (Individual(20.2064174),)
85      184     14.963546164494431      (np.float64(-29.759903045854962),)      (Individual(20.2064174),)
86      171     15.079081688887678      (np.float64(-29.37896052199045),)       (Individual(20.2064174),)
87      187     16.1884038342693        (np.float64(-28.596285261062537),)      (Individual(20.2064174),)
88      154     15.531034814389134      (np.float64(-31.839637184411554),)      (Individual(20.2064174),)
89      193     15.099320570594049      (np.float64(-28.827682298745387),)      (Individual(20.2064174),)
90      178     15.682603009802936      (np.float64(-28.04385240973668),)       (Individual(20.2064174),)
91      184     14.443454276242344      (np.float64(-29.51226050755041),)       (Individual(20.2064174),)
92      163     15.406766086955573      (np.float64(-28.32172523667017),)       (Individual(20.2064174),)
93      184     15.70473762606089       (np.float64(-30.728622765637432),)      (Individual(20.2064174),)
94      174     14.758743366911977      (np.float64(-28.080126396679844),)      (Individual(20.2064174),)
95      176     15.673778782682838      (np.float64(-25.837875453267422),)      (Individual(20.2064174),)
96      191     15.817237982945501      (np.float64(-26.672623323138854),)      (Individual(20.2064174),)
97      167     16.59541187601737       (np.float64(-27.297924852922783),)      (Individual(20.2064174),)
98      179     16.007766361839696      (np.float64(-27.529667221008353),)      (Individual(20.2064174),)
99      178     15.635593899031079      (np.float64(-28.672623323138854),)      (Individual(20.2064174),)
100     183     16.326321312395013      (np.float64(-26.85993850698008),)       (Individual(20.2064174),)
Best individual:  [0.         0.         0.         0.         0.         0.
 0.         0.         0.         0.         0.         0.
 0.40327918 0.22907906 0.67575091 0.         0.6553646  0.
 0.         0.         0.         0.         0.         0.
 0.         0.         0.         0.86200241 1.         1.
 0.40371474 0.9198736  1.         1.         1.         0.25209877
 1.         0.95767896 0.93137163 0.85585016 0.57441367 0.92443067
 0.92182748 0.62751934 1.         1.         0.95862152 0.32737668
 0.68963778 1.         1.         0.        ]
Best fitness:  20.20641739649888
|Index |Variable       |Lower Bound |Upper Bound |Current Value
0      cap_el[0]        0.00         -            0.0
1      cap_pv[0]        0.00         -            0.0
2      pg[0,0]          0.00         -            0.0
3      pg[1,0]          0.00         -            0.0
4      pg[2,0]          0.00         -            0.0
5      pg[3,0]          0.00         -            0.0
6      pg[4,0]          0.00         -            0.0
7      pg[5,0]          0.00         -            0.0
8      pg[6,0]          0.00         -            0.0
9      pg[7,0]          0.00         -            0.0
10     pg[8,0]          0.00         -            0.0
11     pg[9,0]          0.00         -            0.0
12     pg[10,0]         0.00         -            0.4032791837204919
13     pg[11,0]         0.00         -            0.2290790581786939
14     pg[12,0]         0.00         -            0.6757509065348477
15     pg[13,0]         0.00         -            0.0
16     pg[14,0]         0.00         -            0.6553645974907741
17     pg[15,0]         0.00         -            0.0
18     pg[16,0]         0.00         -            0.0
19     pg[17,0]         0.00         -            0.0
20     pg[18,0]         0.00         -            0.0
21     pg[19,0]         0.00         -            0.0
22     pg[20,0]         0.00         -            0.0
23     pg[21,0]         0.00         -            0.0
24     pg[22,0]         0.00         -            0.0
25     pg[23,0]         0.00         -            0.0
26     pg[24,0]         0.00         -            0.0
27     y[0,0]           0.00         -            0.8620024074486927
28     y[1,0]           0.00         -            1.0
29     y[2,0]           0.00         -            1.0
30     y[3,0]           0.00         -            0.403714738937464
31     y[4,0]           0.00         -            0.9198736033201538
32     y[5,0]           0.00         -            1.0
33     y[6,0]           0.00         -            1.0
34     y[7,0]           0.00         -            1.0
35     y[8,0]           0.00         -            0.25209876753173877
36     y[9,0]           0.00         -            1.0
37     y[10,0]          0.00         -            0.9576789637539306
38     y[11,0]          0.00         -            0.9313716259297596
39     y[12,0]          0.00         -            0.8558501572429695
40     y[13,0]          0.00         -            0.5744136705919701
41     y[14,0]          0.00         -            0.924430672302241
42     y[15,0]          0.00         -            0.9218274815600159
43     y[16,0]          0.00         -            0.6275193355756751
44     y[17,0]          0.00         -            1.0
45     y[18,0]          0.00         -            1.0
46     y[19,0]          0.00         -            0.9586215169695768
47     y[20,0]          0.00         -            0.32737667686114547
48     y[21,0]          0.00         -            0.689637778473545
49     y[22,0]          0.00         -            1.0
50     y[23,0]          0.00         -            1.0
51     y[24,0]          0.00         -            0.0