diff --git a/testcases/models/high_fidelity_models/single-zone/SingleZoneDamperControl.fmu b/testcases/models/high_fidelity_models/single-zone/SingleZoneDamperControl.fmu index 1c5f668c..493438bd 100644 Binary files a/testcases/models/high_fidelity_models/single-zone/SingleZoneDamperControl.fmu and b/testcases/models/high_fidelity_models/single-zone/SingleZoneDamperControl.fmu differ diff --git a/testcases/models/high_fidelity_models/single-zone/SingleZoneDamperControlBaseline.fmu b/testcases/models/high_fidelity_models/single-zone/SingleZoneDamperControlBaseline.fmu index 09386503..c5454e62 100644 Binary files a/testcases/models/high_fidelity_models/single-zone/SingleZoneDamperControlBaseline.fmu and b/testcases/models/high_fidelity_models/single-zone/SingleZoneDamperControlBaseline.fmu differ diff --git a/testcases/models/high_fidelity_models/single-zone/SingleZoneVAV.mo b/testcases/models/high_fidelity_models/single-zone/SingleZoneVAV.mo index c21484ef..bdfb8cf4 100644 --- a/testcases/models/high_fidelity_models/single-zone/SingleZoneVAV.mo +++ b/testcases/models/high_fidelity_models/single-zone/SingleZoneVAV.mo @@ -18,6 +18,7 @@ package SingleZoneVAV "Cooling setpoint during on"; parameter Modelica.SIunits.Temperature TCooOff=303.15 "Cooling setpoint during off"; + parameter Real mSenFac = 1 "Thermal mass scalor in the zone"; BaseClasses.Control.ChillerDXHeatingEconomizerController con( minAirFlo=0.1, @@ -41,7 +42,9 @@ package SingleZoneVAV BaseClasses.Room zon( redeclare package MediumA = MediumA, mAir_flow_nominal=0.75, - lat=weaDat.lat) "Thermal envelope of single zone" + lat=weaDat.lat, + roo(mSenFac=mSenFac)) + "Thermal envelope of single zone" annotation (Placement(transformation(extent={{40,-20},{80,20}}))); Buildings.BoundaryConditions.WeatherData.ReaderTMY3 weaDat( computeWetBulbTemperature=false, filNam= @@ -298,6 +301,7 @@ First implementation. "Cooling setpoint during on"; parameter Modelica.SIunits.Temperature TCooOff=303.15 "Cooling setpoint during off"; + parameter Real mSenFac = 1 "Thermal mass scalor in the zone"; BaseClasses.Control.ChillerDXHeatingEconomizerController con( minAirFlo=0.1, @@ -321,7 +325,8 @@ First implementation. BaseClasses.Room zon( redeclare package MediumA = MediumA, mAir_flow_nominal=0.75, - lat=weaDat.lat) "Thermal envelope of single zone" + lat=weaDat.lat, + roo(mSenFac=mSenFac)) "Thermal envelope of single zone" annotation (Placement(transformation(extent={{40,-20},{80,20}}))); Buildings.BoundaryConditions.WeatherData.ReaderTMY3 weaDat( computeWetBulbTemperature=false, filNam= @@ -576,6 +581,7 @@ First implementation. "Cooling setpoint during on"; parameter Modelica.SIunits.Temperature TCooOff=303.15 "Cooling setpoint during off"; + parameter Real mSenFac = 1 "Thermal mass scalor in the zone"; BaseClasses.Control.ChillerDXHeatingEconomizerController con( minAirFlo=0.1, @@ -598,7 +604,8 @@ First implementation. BaseClasses.Room zon( redeclare package MediumA = MediumA, mAir_flow_nominal=0.75, - lat=weaDat.lat) "Thermal envelope of single zone" + lat=weaDat.lat, + roo(mSenFac=mSenFac)) "Thermal envelope of single zone" annotation (Placement(transformation(extent={{40,-20},{80,20}}))); Buildings.BoundaryConditions.WeatherData.ReaderTMY3 weaDat( computeWetBulbTemperature=false, filNam= @@ -866,6 +873,7 @@ First implementation. "Cooling setpoint during on"; parameter Modelica.SIunits.Temperature TCooOff=303.15 "Cooling setpoint during off"; + parameter Real mSenFac = 4 "Thermal mass scalor in the zone"; BaseClasses.Control.ChillerDXHeatingEconomizerController con( minAirFlo=0.1, @@ -889,7 +897,7 @@ First implementation. redeclare package MediumA = MediumA, mAir_flow_nominal=0.75, lat=weaDat.lat, - roo(mSenFac=4)) "Thermal envelope of single zone" + roo(mSenFac=mSenFac)) "Thermal envelope of single zone" annotation (Placement(transformation(extent={{40,-20},{80,20}}))); Buildings.BoundaryConditions.WeatherData.ReaderTMY3 weaDat( computeWetBulbTemperature=false, filNam= @@ -1145,8 +1153,7 @@ First implementation. extends Modelica.Icons.BasesPackage; model Room "Room model for test case" extends Buildings.Air.Systems.SingleZone.VAV.Examples.BaseClasses.Room( - roo(use_C_flow=true, - mSenFac=4, nPorts=6), + roo(use_C_flow=true, nPorts=6), sinInf(use_C_in=true), TRooAir(unit="K")); Modelica.Blocks.Math.Gain gaiCO2Gen(k=2) diff --git a/testcases/models/high_fidelity_models/single-zone/compile_fmu.bat b/testcases/models/high_fidelity_models/single-zone/compile_fmu.bat index 5e0de162..92525b9f 100644 --- a/testcases/models/high_fidelity_models/single-zone/compile_fmu.bat +++ b/testcases/models/high_fidelity_models/single-zone/compile_fmu.bat @@ -7,4 +7,4 @@ docker run^ -v %CD%:/mnt/shared^ -i^ -t^ - mpcdrl /bin/bash -c "cd /mnt/shared && python2 /mnt/shared/compile_fmu.py" + yangyangfu/mpcdrl:cpu_py3 /bin/bash -c "cd /mnt/shared && python2 /mnt/shared/compile_fmu.py" diff --git a/testcases/mpc/single-zone-fan-power/average-sample/SingleZoneDamperControl.fmu b/testcases/mpc/single-zone-fan-power/average-sample/SingleZoneDamperControl.fmu index 7bb90e67..493438bd 100644 Binary files a/testcases/mpc/single-zone-fan-power/average-sample/SingleZoneDamperControl.fmu and b/testcases/mpc/single-zone-fan-power/average-sample/SingleZoneDamperControl.fmu differ diff --git a/testcases/mpc/single-zone-fan-power/average-sample/SingleZoneDamperControlBaseline.fmu b/testcases/mpc/single-zone-fan-power/average-sample/SingleZoneDamperControlBaseline.fmu index 6f4b8742..c5454e62 100644 Binary files a/testcases/mpc/single-zone-fan-power/average-sample/SingleZoneDamperControlBaseline.fmu and b/testcases/mpc/single-zone-fan-power/average-sample/SingleZoneDamperControlBaseline.fmu differ diff --git a/testcases/mpc/single-zone-fan-power/average-sample/TZone.json b/testcases/mpc/single-zone-fan-power/average-sample/TZone.json deleted file mode 100644 index 4b5bfdbf..00000000 --- a/testcases/mpc/single-zone-fan-power/average-sample/TZone.json +++ /dev/null @@ -1 +0,0 @@ -{"alpha": [2.044875402545769, -1.3416833469911322, 0.19815318342890995, 0.06385773304883345], "beta": 0.07826740460068192, "gamma": 0.03454395083553603} \ No newline at end of file diff --git a/testcases/mpc/single-zone-fan-power/average-sample/TZone.pdf b/testcases/mpc/single-zone-fan-power/average-sample/TZone.pdf deleted file mode 100644 index d6ee5a5b..00000000 Binary files a/testcases/mpc/single-zone-fan-power/average-sample/TZone.pdf and /dev/null differ diff --git a/testcases/mpc/single-zone-fan-power/average-sample/TZone_ANN.pdf b/testcases/mpc/single-zone-fan-power/average-sample/TZone_ANN.pdf deleted file mode 100644 index 6e78fe23..00000000 Binary files a/testcases/mpc/single-zone-fan-power/average-sample/TZone_ANN.pdf and /dev/null differ diff --git a/testcases/mpc/single-zone-fan-power/average-sample/generate_training_data.bat b/testcases/mpc/single-zone-fan-power/average-sample/generate_training_data.bat index 22af6128..68698a6f 100644 --- a/testcases/mpc/single-zone-fan-power/average-sample/generate_training_data.bat +++ b/testcases/mpc/single-zone-fan-power/average-sample/generate_training_data.bat @@ -7,6 +7,5 @@ docker run --name fmuc^ -v %CD%:/mnt/shared^ -i^ -t^ - mpcdrl /bin/bash -c^ - "source activate base && export PYTHONPATH=$PYFMI_PY3_CONDA_PATH:$PYTHONPATH && cd /mnt/shared && python /mnt/shared/generate_training_data.py" + yangyangfu/mpcdrl:cpu_py3 /bin/bash -c "source activate base && export PYTHONPATH=$PYFMI_PY3_CONDA_PATH:$PYTHONPATH && cd /mnt/shared && python /mnt/shared/generate_training_data.py" diff --git a/testcases/mpc/single-zone-fan-power/average-sample/mass_1/TZone_ANN.pdf b/testcases/mpc/single-zone-fan-power/average-sample/mass_1/TZone_ANN.pdf new file mode 100644 index 00000000..e13373d4 Binary files /dev/null and b/testcases/mpc/single-zone-fan-power/average-sample/mass_1/TZone_ANN.pdf differ diff --git a/testcases/mpc/single-zone-fan-power/average-sample/TZone_ARX.pdf b/testcases/mpc/single-zone-fan-power/average-sample/mass_1/TZone_ARX.pdf similarity index 100% rename from testcases/mpc/single-zone-fan-power/average-sample/TZone_ARX.pdf rename to testcases/mpc/single-zone-fan-power/average-sample/mass_1/TZone_ARX.pdf diff --git a/testcases/mpc/single-zone-fan-power/average-sample/fan-power-fit.pdf b/testcases/mpc/single-zone-fan-power/average-sample/mass_1/fan-power-fit.pdf similarity index 100% rename from testcases/mpc/single-zone-fan-power/average-sample/fan-power-fit.pdf rename to testcases/mpc/single-zone-fan-power/average-sample/mass_1/fan-power-fit.pdf diff --git a/testcases/mpc/single-zone-fan-power/average-sample/fan-power-fit.png b/testcases/mpc/single-zone-fan-power/average-sample/mass_1/fan-power-fit.png similarity index 100% rename from testcases/mpc/single-zone-fan-power/average-sample/fan-power-fit.png rename to testcases/mpc/single-zone-fan-power/average-sample/mass_1/fan-power-fit.png diff --git a/testcases/mpc/single-zone-fan-power/average-sample/mass_1/mpc-vs-rbc.pdf b/testcases/mpc/single-zone-fan-power/average-sample/mass_1/mpc-vs-rbc.pdf new file mode 100644 index 00000000..ac57b502 Binary files /dev/null and b/testcases/mpc/single-zone-fan-power/average-sample/mass_1/mpc-vs-rbc.pdf differ diff --git a/testcases/mpc/single-zone-fan-power/average-sample/mass_1/mpc-vs-rbc.png b/testcases/mpc/single-zone-fan-power/average-sample/mass_1/mpc-vs-rbc.png new file mode 100644 index 00000000..9ab2fdad Binary files /dev/null and b/testcases/mpc/single-zone-fan-power/average-sample/mass_1/mpc-vs-rbc.png differ diff --git a/testcases/mpc/single-zone-fan-power/average-sample/Power.json b/testcases/mpc/single-zone-fan-power/average-sample/mass_1/power.json similarity index 100% rename from testcases/mpc/single-zone-fan-power/average-sample/Power.json rename to testcases/mpc/single-zone-fan-power/average-sample/mass_1/power.json diff --git a/testcases/mpc/single-zone-fan-power/average-sample/Power.pdf b/testcases/mpc/single-zone-fan-power/average-sample/mass_1/power.pdf similarity index 100% rename from testcases/mpc/single-zone-fan-power/average-sample/Power.pdf rename to testcases/mpc/single-zone-fan-power/average-sample/mass_1/power.pdf diff --git a/testcases/mpc/single-zone-fan-power/average-sample/power_accuracy.json b/testcases/mpc/single-zone-fan-power/average-sample/mass_1/power_accuracy.json similarity index 100% rename from testcases/mpc/single-zone-fan-power/average-sample/power_accuracy.json rename to testcases/mpc/single-zone-fan-power/average-sample/mass_1/power_accuracy.json diff --git a/testcases/mpc/single-zone-fan-power/average-sample/train_data.csv b/testcases/mpc/single-zone-fan-power/average-sample/mass_1/train_data.csv similarity index 100% rename from testcases/mpc/single-zone-fan-power/average-sample/train_data.csv rename to testcases/mpc/single-zone-fan-power/average-sample/mass_1/train_data.csv diff --git a/testcases/mpc/single-zone-fan-power/average-sample/mass_1/u_opt.json b/testcases/mpc/single-zone-fan-power/average-sample/mass_1/u_opt.json new file mode 100644 index 00000000..5c17ee6c --- /dev/null +++ b/testcases/mpc/single-zone-fan-power/average-sample/mass_1/u_opt.json @@ -0,0 +1 @@ +{"u_opt": [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.3277056498430354e-06, 1.327705492153554e-06, 1.3277055568648882e-06, 1.3277057359093578e-06, 1.3277056746199185e-06, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0003263616264076512, 0.138533925895964, 0.01759423360508048, 0.14496103231804572, 0.04725454451816511, 0.15745173072085428, 0.20737632860332553, 0.21324080643226367, 0.25836045002900093, 0.2407595632070505, 0.2528065379336276, 0.25178069636498357, 0.254274230328989, 0.2513201185499676, 0.24414642105638754, 0.2416500310900496, 0.25265387803219086, 0.27007611697458217, 0.2763547886365778, 0.28193952718695475, 0.2848652759461326, 0.28706203565242766, 0.29220591607588525, 0.2771791460090229, 0.2654461989873237, 0.2415701671705485, 0.24942472408185204, 0.2311680347123846, 0.21165863854070974, 0.2042485915644999, 0.18247716481784665, 0.18625493547239896, 0.15993410054635093, 0.1645616757844748, 0.133311869563894, 0.14203142574249966, 0.10399468972973266, 0.12095868785500105, 0.02742963118933019, 0.12212345916837006, 6.054617769640774e-07, 6.054663221737953e-07, 6.054662190471545e-07, 6.054670576651635e-07, 6.054669042170742e-07, 6.054679567198795e-07, 6.054682144861341e-07, 6.05468310339923e-07, 6.054684894453952e-07, 6.054685955415739e-07, 6.054688643150739e-07, 6.054690995612775e-07, 6.054692315506187e-07, 7.015058667442581e-07, 8.330543720261566e-07, 1.024279689491869e-06, 1.3277035917640602e-06, 1.3277038219416137e-06, 1.3277040658782946e-06, 1.3277041585808821e-06, 1.3277042330839202e-06, 1.3277044113600225e-06, 1.3277046898842367e-06, 1.327704926409636e-06, 1.3277050242226248e-06, 1.3277051629260038e-06, 1.3277052508696341e-06, 1.3277054354191525e-06, 1.3277056589509e-06, 1.3277059183248122e-06, 1.3277061752057901e-06, 1.3277063444705265e-06, 1.3277065169366341e-06, 1.3277065640577932e-06, 1.3277066405711276e-06, 1.3277064052045981e-06, 1.3277061142951058e-06, 1.327705876921508e-06, 1.3277057366487146e-06, 1.3277056386791217e-06, 1.3277054622227876e-06, 1.3277053367925517e-06, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.00013694809236450438, 0.07026894119567449, 0.08248875350446513, 0.11342394118238436, 0.1502972774106752, 0.18963923731061613, 0.2582575362663237, 0.27097008205202217, 0.25674954662879235, 0.2532377639850705, 0.27149956736548025, 0.2693300595466178, 0.24780571588003822, 0.2322224485888647, 0.24271590192556342, 0.2657718123019659, 0.28789099302199883, 0.2877349502743065, 0.3010869258061118, 0.30613353588785713, 0.3063779728170225, 0.304454541751753, 0.2933354554564181, 0.2989512199216796, 0.2897939323306467, 0.2778834033775731, 0.270414396590098, 0.2582685461842307, 0.24859224322170906, 0.23070754403526914, 0.21904439643045195, 0.20182807958508056, 0.1965265935049393, 0.17975694551249866, 0.1749782626678738, 0.15377481035364796, 0.14843854562655498, 0.12956305812316551, 0.12259583221545615, 0.03957934473685031, 0.11010490711446298, 6.054534835395817e-07, 6.054661059959658e-07, 6.054664277569824e-07, 6.054672667039907e-07, 6.054670337578685e-07, 6.054679644561209e-07, 6.054681063777997e-07, 6.054682615589055e-07, 6.054684726510096e-07, 6.054685932377175e-07, 6.054687503666805e-07, 6.054689815680152e-07, 6.054692113196137e-07, 7.015058007670422e-07, 8.330542134960957e-07, 1.0242792557884247e-06, 1.3277027339248775e-06, 1.3277031649557988e-06, 1.3277036732349166e-06, 1.32770418333357e-06, 1.3277044589913283e-06, 1.327704716588451e-06, 1.327704864565878e-06, 1.327705057466724e-06, 1.3277053609957634e-06, 1.3277056351658751e-06, 1.3277059283354305e-06, 1.3277061309652377e-06, 1.327706281862938e-06, 1.327706321779482e-06, 1.3277063664544849e-06, 1.3277062343515491e-06, 1.3277061019710521e-06, 1.3277060754976997e-06, 1.327706180940575e-06, 1.3277062870252217e-06, 1.3277062395685547e-06, 1.327706252882495e-06, 1.3277062145917447e-06, 1.3277061435388112e-06, 1.3277061058266491e-06, 1.3277059346807728e-06, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.10925125174167084, 0.0, 0.20290245863291573, 0.03555450106600073, 0.2348549545822638, 0.2223342006339331, 0.22518091200997503, 0.2597915937696326, 0.24810167563665708, 0.26534816119520677, 0.2440237656367432, 0.2086796032056004, 0.2224213226848712, 0.2523030431680375, 0.2867001250252168, 0.22175589964714945, 0.2776747075319299, 0.29194451153450623, 0.3311943462156756, 0.3205661575603746, 0.2871183215866214, 0.3271625279990781, 0.290806387107716, 0.3339846593922811, 0.30557965524339925, 0.2992308244979552, 0.2929759691916903, 0.28251907312313884, 0.28202490432051164, 0.2545301664721498, 0.2479071509788449, 0.21952446217332147, 0.22359081857221133, 0.19817950421348823, 0.20084479527881793, 0.17392058382742823, 0.1671754212541605, 0.1476078167449786, 0.13304449272605315, 0.0781915936353482, 0.1001738529501372, 0.009750237441656866, 6.054656585591289e-07, 6.054653441321537e-07, 6.05465977079538e-07, 6.054661466454139e-07, 6.054671904586602e-07, 6.054673972368996e-07, 6.054676905074124e-07, 6.05468050328438e-07, 6.054682372866758e-07, 6.054684816696756e-07, 6.054686788102053e-07, 6.054689063433052e-07, 7.015055424322064e-07, 8.33054122767426e-07, 1.0242794721569634e-06, 1.3277032296959707e-06, 1.327703479004211e-06, 1.327703842444928e-06, 1.3277037882166695e-06, 1.3277036789211903e-06, 1.3277038372243962e-06, 1.3277042639292285e-06, 1.3277048258811697e-06, 1.327705078624941e-06, 1.3277056461912973e-06, 1.327706118863273e-06, 1.327706621067787e-06, 1.3277073510804733e-06, 1.3277078213916506e-06, 1.3277082679366575e-06, 1.3277079564545832e-06, 1.327707592300812e-06, 1.327707682138247e-06, 1.3277080030643952e-06, 1.3277081714571603e-06, 1.3277080474573437e-06, 1.3277075304340654e-06, 1.3277070440492517e-06, 1.3277067829987864e-06, 1.327706706257766e-06, 1.3277066147727046e-06, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.06178201542349781, 0.04465966653764826, 0.19023154473918363, 0.10188080241306764, 0.209855949926334, 0.22381477270418715, 0.24193336825049291, 0.25823952619402096, 0.26491641936162263, 0.2691759573146101, 0.27211949684433373, 0.26723719118882666, 0.27444849048715836, 0.26301582445710153, 0.2928094205772092, 0.3011281179755101, 0.3255669786099145, 0.3280315535873107, 0.3362498427923963, 0.33753257863484765, 0.333024534609868, 0.3290659033104626, 0.3254903281458587, 0.31827123334383794, 0.3053369137456137, 0.2974632493622384, 0.28442793205919115, 0.2755246193056102, 0.2624834220360525, 0.2514349749354657, 0.24271805722967568, 0.22731860115240227, 0.216039152563258, 0.199822890275489, 0.18782245392570426, 0.1771763721595072, 0.16177557416772503, 0.1514295436636288, 0.09330906332735606, 0.11818751827598635, 0.031137938599285937, 6.054656535802578e-07, 6.05464963743268e-07, 6.054654951741011e-07, 6.054650663813803e-07, 6.054661517471177e-07, 6.054670584577742e-07, 6.054676508225083e-07, 6.054678473408657e-07, 6.054681503013917e-07, 6.054684411612837e-07, 6.054686899986482e-07, 6.054689184793733e-07, 7.015053416026211e-07, 8.330536902789483e-07, 1.0242783127622945e-06, 1.3277003825526199e-06, 1.32770097714504e-06, 1.327701713257236e-06, 1.3277028940218273e-06, 1.327703603969552e-06, 1.3277039053045317e-06, 1.3277038277520098e-06, 1.327703821985872e-06, 1.3277043450061135e-06, 1.3277048782511365e-06, 1.327705483362454e-06, 1.3277063420670108e-06, 1.3277070308799185e-06, 1.3277075945919136e-06, 1.3277077607967817e-06, 1.327707810498588e-06, 1.327708286739573e-06, 1.3277078840227833e-06, 1.3277076800124178e-06, 1.327707236039014e-06, 1.3277067601873946e-06, 1.3277062731903984e-06, 1.3277057827807814e-06, 1.3277054421547682e-06, 1.3277051801738744e-06, 1.3277047793951706e-06, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.1488795767345419, 0.0, 0.2270334418549576, 0.0825253898619449, 0.2642492759003745, 0.25141989845761964, 0.2630969400907931, 0.24921791725035783, 0.26435716709984125, 0.2632304756013476, 0.26348145610363644, 0.2732119829889985, 0.2784623823117661, 0.28354694322279894, 0.314452666289528, 0.3362740665923971, 0.3542399688865687, 0.3709375208963375, 0.38933540779923254, 0.40286051865479, 0.38299978478398744, 0.38778581088461056, 0.39324864673094656, 0.3894364168645298, 0.3901582406158525, 0.3584134559509478, 0.34675186290974747, 0.3149651744843559, 0.3217824414300978, 0.30313101901796047, 0.2725407560637179, 0.26305317315930143, 0.23171729245792405, 0.2311345157159269, 0.20085783490192313, 0.19711360521950136, 0.18330902242063862, 0.17187745902333923, 0.15462169715497823, 0.1418880253896818, 0.10879012358248821, 0.11117613846290815, 0.04653063871119158, 6.054660408447926e-07, 6.054643623156107e-07, 6.054643561212126e-07, 6.054640432930146e-07, 6.054650894183244e-07, 6.054660852549695e-07, 6.054665702286775e-07, 6.054667649504727e-07, 6.05467109390871e-07, 6.054673985776846e-07, 6.054677862668315e-07, 6.054681529008099e-07, 7.015045363255035e-07, 8.330526674929271e-07, 1.0242769902951034e-06, 1.327698907323616e-06, 1.3276992660696707e-06, 1.327699827770941e-06, 1.327700562490694e-06, 1.3277009911645259e-06, 1.3277017800863733e-06, 1.3277024087196225e-06, 1.3277030751708853e-06, 1.327703799675147e-06, 1.3277040338662887e-06, 1.3277042559438644e-06, 1.3277039658065815e-06, 1.3277037561674716e-06, 1.327703846295586e-06, 1.3277042523991556e-06, 1.3277046297250235e-06, 1.327704597346642e-06, 1.3277047185098744e-06, 1.327704736577376e-06, 1.3277047715332357e-06, 1.3277049029460306e-06, 1.3277048244645418e-06, 1.3277047427419975e-06, 1.3277045133916182e-06, 1.327704261028493e-06, 1.3277038992632725e-06, 3.6770705787966765e-06, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.07043443202292966, 0.0, 0.13067479989536115, 0.08965403089012215, 0.17615540726544007, 0.19930080857575022, 0.19903922288551093, 0.2307581710433604, 0.23425764011143582, 0.25359494940024163, 0.265545540133589, 0.2717028495472349, 0.2641141618863499, 0.2602121713006853, 0.26195321805303184, 0.2932744981652493, 0.31903603571886574, 0.34328306193778524, 0.36325381584669497, 0.3798449997198745, 0.4027702311296514, 0.41332678927845157, 0.41597028005161574, 0.40332297627399644, 0.3781405003695135, 0.35627635224122933, 0.33151230595733855, 0.3394847440563084, 0.33184268183022403, 0.31724887090507053, 0.3112226795667096, 0.29093101772576657, 0.28517069870201533, 0.26596895665126075, 0.25736783894977305, 0.2639174550505875, 0.24504374532730638, 0.23593633550650783, 0.21706591280174004, 0.2133656240755601, 0.20250009948087916, 0.1799435476368652, 0.17055195193841305, 0.09473772483492471, 0.1308928662572361, 0.04066749857170728, 6.054630308885735e-07, 6.054580787905307e-07, 6.054594396931147e-07, 6.054546106380981e-07, 6.054612304448551e-07, 6.054631373478703e-07, 6.054631148855249e-07, 6.054638784617081e-07, 6.054646194970701e-07, 6.054653247165416e-07, 6.054661393748289e-07, 6.05466492168114e-07, 7.015025567598579e-07, 8.330502324376986e-07, 1.0242732652320286e-06, 1.3276928866908924e-06, 1.327693385468034e-06, 1.327694615411022e-06, 1.3276958191064485e-06, 1.3276960877669831e-06, 1.3276970040201138e-06, 1.327697677999307e-06, 1.3276986539271154e-06, 1.327699686920252e-06, 1.32770033575346e-06, 1.3277006971226981e-06, 1.3277009196648574e-06, 1.327701334204113e-06, 1.327701545377468e-06, 1.327701803704703e-06, 1.3277018912159767e-06, 1.327701873500721e-06, 1.3277017977516084e-06, 1.3277016564460108e-06, 1.3277017722329452e-06, 1.3277019723238185e-06, 1.3277022056397278e-06, 1.3277024124953566e-06, 1.3277024916130581e-06, 1.3277025698383804e-06, 1.3277023829821364e-06, 1.3277072129716708e-06, 1.3277884807707821e-06, 1.3277912884888587e-06, 0.0, 0.0, 0.0, 1.3268817955721848e-06, 0.040796321736447455, 0.06870434186079515, 0.07416263442905607, 0.10311956488065935, 0.11043909696261675, 0.20877750367145081, 0.2067175659895849, 0.22652571931015844, 0.24181552078749907, 0.2502732974337473, 0.2622935319577056, 0.26683574618576084, 0.2680683809004666, 0.26579287776162774, 0.2421814014393582, 0.2416905939397098, 0.29526191398990326, 0.3083506147538597, 0.34769276839017577, 0.3555473752723141, 0.38777359456908755, 0.3529781491524373, 0.37897638295598224, 0.4045429427404347, 0.41672687835379035, 0.4338224274341678, 0.40259762603927896, 0.4147521110255497, 0.3902091129695385, 0.375562703623117, 0.37643110806193697, 0.35706251681003126, 0.363539312775302, 0.32648972523719444, 0.31428720098405305, 0.3148081646479939, 0.29309969783035167, 0.2929600155618391, 0.2652032160209468, 0.26244653881929053, 0.24311364004399938, 0.22195785387566505, 0.21158664741130975, 0.19408988766339313, 0.1816252174127754, 0.1063071829826631, 0.13961624734899372, 0.053824713914056126, 6.054639848761077e-07, 6.0545798896525e-07, 6.054590948735565e-07, 6.05457832497608e-07, 6.054620998279455e-07, 6.054639110278973e-07, 6.054642349097634e-07, 6.054649431555628e-07, 6.05465227643285e-07, 6.054657913416231e-07, 6.054662743236329e-07, 6.054665737212667e-07, 7.015025687607588e-07, 8.330500624279797e-07, 1.0242737962242682e-06, 1.3276944924737857e-06, 1.3276955587069894e-06, 1.327696463620749e-06, 1.3276972552437912e-06, 1.3276980981263728e-06], "t_opt": [18316800.0, 18317700.0, 18318600.0, 18319500.0, 18320400.0, 18321300.0, 18322200.0, 18323100.0, 18324000.0, 18324900.0, 18325800.0, 18326700.0, 18327600.0, 18328500.0, 18329400.0, 18330300.0, 18331200.0, 18332100.0, 18333000.0, 18333900.0, 18334800.0, 18335700.0, 18336600.0, 18337500.0, 18338400.0, 18339300.0, 18340200.0, 18341100.0, 18342000.0, 18342900.0, 18343800.0, 18344700.0, 18345600.0, 18346500.0, 18347400.0, 18348300.0, 18349200.0, 18350100.0, 18351000.0, 18351900.0, 18352800.0, 18353700.0, 18354600.0, 18355500.0, 18356400.0, 18357300.0, 18358200.0, 18359100.0, 18360000.0, 18360900.0, 18361800.0, 18362700.0, 18363600.0, 18364500.0, 18365400.0, 18366300.0, 18367200.0, 18368100.0, 18369000.0, 18369900.0, 18370800.0, 18371700.0, 18372600.0, 18373500.0, 18374400.0, 18375300.0, 18376200.0, 18377100.0, 18378000.0, 18378900.0, 18379800.0, 18380700.0, 18381600.0, 18382500.0, 18383400.0, 18384300.0, 18385200.0, 18386100.0, 18387000.0, 18387900.0, 18388800.0, 18389700.0, 18390600.0, 18391500.0, 18392400.0, 18393300.0, 18394200.0, 18395100.0, 18396000.0, 18396900.0, 18397800.0, 18398700.0, 18399600.0, 18400500.0, 18401400.0, 18402300.0, 18403200.0, 18404100.0, 18405000.0, 18405900.0, 18406800.0, 18407700.0, 18408600.0, 18409500.0, 18410400.0, 18411300.0, 18412200.0, 18413100.0, 18414000.0, 18414900.0, 18415800.0, 18416700.0, 18417600.0, 18418500.0, 18419400.0, 18420300.0, 18421200.0, 18422100.0, 18423000.0, 18423900.0, 18424800.0, 18425700.0, 18426600.0, 18427500.0, 18428400.0, 18429300.0, 18430200.0, 18431100.0, 18432000.0, 18432900.0, 18433800.0, 18434700.0, 18435600.0, 18436500.0, 18437400.0, 18438300.0, 18439200.0, 18440100.0, 18441000.0, 18441900.0, 18442800.0, 18443700.0, 18444600.0, 18445500.0, 18446400.0, 18447300.0, 18448200.0, 18449100.0, 18450000.0, 18450900.0, 18451800.0, 18452700.0, 18453600.0, 18454500.0, 18455400.0, 18456300.0, 18457200.0, 18458100.0, 18459000.0, 18459900.0, 18460800.0, 18461700.0, 18462600.0, 18463500.0, 18464400.0, 18465300.0, 18466200.0, 18467100.0, 18468000.0, 18468900.0, 18469800.0, 18470700.0, 18471600.0, 18472500.0, 18473400.0, 18474300.0, 18475200.0, 18476100.0, 18477000.0, 18477900.0, 18478800.0, 18479700.0, 18480600.0, 18481500.0, 18482400.0, 18483300.0, 18484200.0, 18485100.0, 18486000.0, 18486900.0, 18487800.0, 18488700.0, 18489600.0, 18490500.0, 18491400.0, 18492300.0, 18493200.0, 18494100.0, 18495000.0, 18495900.0, 18496800.0, 18497700.0, 18498600.0, 18499500.0, 18500400.0, 18501300.0, 18502200.0, 18503100.0, 18504000.0, 18504900.0, 18505800.0, 18506700.0, 18507600.0, 18508500.0, 18509400.0, 18510300.0, 18511200.0, 18512100.0, 18513000.0, 18513900.0, 18514800.0, 18515700.0, 18516600.0, 18517500.0, 18518400.0, 18519300.0, 18520200.0, 18521100.0, 18522000.0, 18522900.0, 18523800.0, 18524700.0, 18525600.0, 18526500.0, 18527400.0, 18528300.0, 18529200.0, 18530100.0, 18531000.0, 18531900.0, 18532800.0, 18533700.0, 18534600.0, 18535500.0, 18536400.0, 18537300.0, 18538200.0, 18539100.0, 18540000.0, 18540900.0, 18541800.0, 18542700.0, 18543600.0, 18544500.0, 18545400.0, 18546300.0, 18547200.0, 18548100.0, 18549000.0, 18549900.0, 18550800.0, 18551700.0, 18552600.0, 18553500.0, 18554400.0, 18555300.0, 18556200.0, 18557100.0, 18558000.0, 18558900.0, 18559800.0, 18560700.0, 18561600.0, 18562500.0, 18563400.0, 18564300.0, 18565200.0, 18566100.0, 18567000.0, 18567900.0, 18568800.0, 18569700.0, 18570600.0, 18571500.0, 18572400.0, 18573300.0, 18574200.0, 18575100.0, 18576000.0, 18576900.0, 18577800.0, 18578700.0, 18579600.0, 18580500.0, 18581400.0, 18582300.0, 18583200.0, 18584100.0, 18585000.0, 18585900.0, 18586800.0, 18587700.0, 18588600.0, 18589500.0, 18590400.0, 18591300.0, 18592200.0, 18593100.0, 18594000.0, 18594900.0, 18595800.0, 18596700.0, 18597600.0, 18598500.0, 18599400.0, 18600300.0, 18601200.0, 18602100.0, 18603000.0, 18603900.0, 18604800.0, 18605700.0, 18606600.0, 18607500.0, 18608400.0, 18609300.0, 18610200.0, 18611100.0, 18612000.0, 18612900.0, 18613800.0, 18614700.0, 18615600.0, 18616500.0, 18617400.0, 18618300.0, 18619200.0, 18620100.0, 18621000.0, 18621900.0, 18622800.0, 18623700.0, 18624600.0, 18625500.0, 18626400.0, 18627300.0, 18628200.0, 18629100.0, 18630000.0, 18630900.0, 18631800.0, 18632700.0, 18633600.0, 18634500.0, 18635400.0, 18636300.0, 18637200.0, 18638100.0, 18639000.0, 18639900.0, 18640800.0, 18641700.0, 18642600.0, 18643500.0, 18644400.0, 18645300.0, 18646200.0, 18647100.0, 18648000.0, 18648900.0, 18649800.0, 18650700.0, 18651600.0, 18652500.0, 18653400.0, 18654300.0, 18655200.0, 18656100.0, 18657000.0, 18657900.0, 18658800.0, 18659700.0, 18660600.0, 18661500.0, 18662400.0, 18663300.0, 18664200.0, 18665100.0, 18666000.0, 18666900.0, 18667800.0, 18668700.0, 18669600.0, 18670500.0, 18671400.0, 18672300.0, 18673200.0, 18674100.0, 18675000.0, 18675900.0, 18676800.0, 18677700.0, 18678600.0, 18679500.0, 18680400.0, 18681300.0, 18682200.0, 18683100.0, 18684000.0, 18684900.0, 18685800.0, 18686700.0, 18687600.0, 18688500.0, 18689400.0, 18690300.0, 18691200.0, 18692100.0, 18693000.0, 18693900.0, 18694800.0, 18695700.0, 18696600.0, 18697500.0, 18698400.0, 18699300.0, 18700200.0, 18701100.0, 18702000.0, 18702900.0, 18703800.0, 18704700.0, 18705600.0, 18706500.0, 18707400.0, 18708300.0, 18709200.0, 18710100.0, 18711000.0, 18711900.0, 18712800.0, 18713700.0, 18714600.0, 18715500.0, 18716400.0, 18717300.0, 18718200.0, 18719100.0, 18720000.0, 18720900.0, 18721800.0, 18722700.0, 18723600.0, 18724500.0, 18725400.0, 18726300.0, 18727200.0, 18728100.0, 18729000.0, 18729900.0, 18730800.0, 18731700.0, 18732600.0, 18733500.0, 18734400.0, 18735300.0, 18736200.0, 18737100.0, 18738000.0, 18738900.0, 18739800.0, 18740700.0, 18741600.0, 18742500.0, 18743400.0, 18744300.0, 18745200.0, 18746100.0, 18747000.0, 18747900.0, 18748800.0, 18749700.0, 18750600.0, 18751500.0, 18752400.0, 18753300.0, 18754200.0, 18755100.0, 18756000.0, 18756900.0, 18757800.0, 18758700.0, 18759600.0, 18760500.0, 18761400.0, 18762300.0, 18763200.0, 18764100.0, 18765000.0, 18765900.0, 18766800.0, 18767700.0, 18768600.0, 18769500.0, 18770400.0, 18771300.0, 18772200.0, 18773100.0, 18774000.0, 18774900.0, 18775800.0, 18776700.0, 18777600.0, 18778500.0, 18779400.0, 18780300.0, 18781200.0, 18782100.0, 18783000.0, 18783900.0, 18784800.0, 18785700.0, 18786600.0, 18787500.0, 18788400.0, 18789300.0, 18790200.0, 18791100.0, 18792000.0, 18792900.0, 18793800.0, 18794700.0, 18795600.0, 18796500.0, 18797400.0, 18798300.0, 18799200.0, 18800100.0, 18801000.0, 18801900.0, 18802800.0, 18803700.0, 18804600.0, 18805500.0, 18806400.0, 18807300.0, 18808200.0, 18809100.0, 18810000.0, 18810900.0, 18811800.0, 18812700.0, 18813600.0, 18814500.0, 18815400.0, 18816300.0, 18817200.0, 18818100.0, 18819000.0, 18819900.0, 18820800.0, 18821700.0, 18822600.0, 18823500.0, 18824400.0, 18825300.0, 18826200.0, 18827100.0, 18828000.0, 18828900.0, 18829800.0, 18830700.0, 18831600.0, 18832500.0, 18833400.0, 18834300.0, 18835200.0, 18836100.0, 18837000.0, 18837900.0, 18838800.0, 18839700.0, 18840600.0, 18841500.0, 18842400.0, 18843300.0, 18844200.0, 18845100.0, 18846000.0, 18846900.0, 18847800.0, 18848700.0, 18849600.0, 18850500.0, 18851400.0, 18852300.0, 18853200.0, 18854100.0, 18855000.0, 18855900.0, 18856800.0, 18857700.0, 18858600.0, 18859500.0, 18860400.0, 18861300.0, 18862200.0, 18863100.0, 18864000.0, 18864900.0, 18865800.0, 18866700.0, 18867600.0, 18868500.0, 18869400.0, 18870300.0, 18871200.0, 18872100.0, 18873000.0, 18873900.0, 18874800.0, 18875700.0, 18876600.0, 18877500.0, 18878400.0, 18879300.0, 18880200.0, 18881100.0, 18882000.0, 18882900.0, 18883800.0, 18884700.0, 18885600.0, 18886500.0, 18887400.0, 18888300.0, 18889200.0, 18890100.0, 18891000.0, 18891900.0, 18892800.0, 18893700.0, 18894600.0, 18895500.0, 18896400.0, 18897300.0, 18898200.0, 18899100.0, 18900000.0, 18900900.0, 18901800.0, 18902700.0, 18903600.0, 18904500.0, 18905400.0, 18906300.0, 18907200.0, 18908100.0, 18909000.0, 18909900.0, 18910800.0, 18911700.0, 18912600.0, 18913500.0, 18914400.0, 18915300.0, 18916200.0, 18917100.0, 18918000.0, 18918900.0, 18919800.0, 18920700.0]} \ No newline at end of file diff --git a/testcases/mpc/single-zone-fan-power/average-sample/mass_1/zone_ann.pkl b/testcases/mpc/single-zone-fan-power/average-sample/mass_1/zone_ann.pkl new file mode 100644 index 00000000..217a6ad6 Binary files /dev/null and b/testcases/mpc/single-zone-fan-power/average-sample/mass_1/zone_ann.pkl differ diff --git a/testcases/mpc/single-zone-fan-power/average-sample/mass_1/zone_ann_accuracy.json b/testcases/mpc/single-zone-fan-power/average-sample/mass_1/zone_ann_accuracy.json new file mode 100644 index 00000000..3e32121d --- /dev/null +++ b/testcases/mpc/single-zone-fan-power/average-sample/mass_1/zone_ann_accuracy.json @@ -0,0 +1 @@ +{"test": {"error_mean": -0.18797262123778807, "mse": 0.4348028561307629, "nrmse": 0.032246986700762856, "r2": 0.961475206123683}, "train": {"error_mean": -0.003588103621155987, "mse": 0.23796288904618743, "nrmse": 0.023374465434156635, "r2": 0.9697037667041808}} \ No newline at end of file diff --git a/testcases/mpc/single-zone-fan-power/average-sample/zone_arx.json b/testcases/mpc/single-zone-fan-power/average-sample/mass_1/zone_arx.json similarity index 100% rename from testcases/mpc/single-zone-fan-power/average-sample/zone_arx.json rename to testcases/mpc/single-zone-fan-power/average-sample/mass_1/zone_arx.json diff --git a/testcases/mpc/single-zone-fan-power/average-sample/zone_arx_accuracy.json b/testcases/mpc/single-zone-fan-power/average-sample/mass_1/zone_arx_accuracy.json similarity index 100% rename from testcases/mpc/single-zone-fan-power/average-sample/zone_arx_accuracy.json rename to testcases/mpc/single-zone-fan-power/average-sample/mass_1/zone_arx_accuracy.json diff --git a/testcases/mpc/single-zone-fan-power/average-sample/model.py b/testcases/mpc/single-zone-fan-power/average-sample/model.py index 022b8718..e89452e5 100644 --- a/testcases/mpc/single-zone-fan-power/average-sample/model.py +++ b/testcases/mpc/single-zone-fan-power/average-sample/model.py @@ -67,7 +67,6 @@ def autocorrection(self,Tz_his_meas, Tz_his_pred): correction = np.mean(np.array(Tz_his_meas)-np.array(Tz_his_pred)) return float(correction) - def predict(self,Tz_his_meas, Tz_his_pred, To_his_meas, mz, Tsa): """This is to provide a complete prediction with autocorrection term diff --git a/testcases/mpc/single-zone-fan-power/average-sample/mpc-vs-rbc-pre.pdf b/testcases/mpc/single-zone-fan-power/average-sample/mpc-vs-rbc-pre.pdf deleted file mode 100644 index 4d2cdce0..00000000 Binary files a/testcases/mpc/single-zone-fan-power/average-sample/mpc-vs-rbc-pre.pdf and /dev/null differ diff --git a/testcases/mpc/single-zone-fan-power/average-sample/mpc-vs-rbc.pdf b/testcases/mpc/single-zone-fan-power/average-sample/mpc-vs-rbc.pdf deleted file mode 100644 index 6b014873..00000000 Binary files a/testcases/mpc/single-zone-fan-power/average-sample/mpc-vs-rbc.pdf and /dev/null differ diff --git a/testcases/mpc/single-zone-fan-power/average-sample/mpc-vs-rbc.png b/testcases/mpc/single-zone-fan-power/average-sample/mpc-vs-rbc.png deleted file mode 100644 index e4cfaaaa..00000000 Binary files a/testcases/mpc/single-zone-fan-power/average-sample/mpc-vs-rbc.png and /dev/null differ diff --git a/testcases/mpc/single-zone-fan-power/average-sample/mpc.py b/testcases/mpc/single-zone-fan-power/average-sample/mpc.py index e92cbe9a..c92778eb 100644 --- a/testcases/mpc/single-zone-fan-power/average-sample/mpc.py +++ b/testcases/mpc/single-zone-fan-power/average-sample/mpc.py @@ -6,299 +6,307 @@ # ipopt #from pyomo.environ import * -from FuncDesigner import * -from openopt import NSP -from openopt import NLP -from openopt import GLP -import joblib +import casadi as ca +import model +import joblib + +class ObjectiveCallback(ca.Callback): + def __init__(self,name, PH, dt, w, power_model, predictor, opts={}): + ca.Callback.__init__(self) + self.PH = PH + self.dt = dt + self.w = w # weights for energy cost and temperature violation term [w1, w2] + self.power_model = power_model + self.predictor = predictor + self.construct(name,opts) -class mpc_case(): - def __init__(self,PH,CH,time,dt,parameters_zone, parameters_power,measurement,states,predictor): + # Number of inputs and outputs + def get_n_in(self): return 1 + def get_n_out(self): return 1 - self.PH=PH # prediction horizon - self.CH=CH # control horizon - self.dt = dt # time step - self.time = time # current time index + # Array of inputs and outputs + def get_sparsity_in(self,i): + return ca.Sparsity.dense(2*self.PH,1) + def get_sparsity_out(self,i): + return ca.Sparsity.dense(1,1) - self.parameters_zone = parameters_zone # parameters for zone dynamic mpc model, dictionary - self.parameters_power = parameters_power # parameters for system power dynamic mpc model, dictionary - self.measurement = measurement # measurement at current time step, dictionary - self.predictor = predictor # price and outdoor air temperature for the future horizons - self.zone_model = joblib.load('ann.pkl') + # Initialize the object + def init(self): + print('initializing object') - self.states = states # dictionary - self.P_his_t = [] - self.Tz_his_t = [] + def power_polynomial(self,mz): + params = self.power_model + f_P = model.FanPower(n=len(params['alpha'])) + f_P.params = params + PFan = f_P.predict(mz) - self.number_zone = 1 - self.occ_start = 6 # occupancy starts - self.occ_end = 19 # occupancy ends + return PFan - # initialize optimiztion - #self.optimization_model=self.get_optimization_model() # pyomo object - self.optimum= {} - self.u_start = [0.5]*PH - self.u_lb = [0.0]*PH - self.u_ub = [1.0]*PH - - - def obj(self,u_ph): - #u_ph = u_ph.inputs - # MPC model predictor settings - alpha_power = np.array(self.parameters_power['alpha']) - #beta_power = np.array(self.parameters_power['beta']) - #gamma_power = np.array(self.parameters_power['gamma']) - - alpha_zone = np.array(self.parameters_zone['alpha']) - beta_zone = np.array(self.parameters_zone['beta']) - gamma_zone = np.array(self.parameters_zone['gamma']) - l = 4 + def eval(self,arg): + """evaluate objective - # zone temperature bounds - need check with the high-fidelty model - T_upper = np.array([30.0 for i in range(24)]) - T_upper[self.occ_start:self.occ_end] = 26.0 - T_lower = np.array([12.0 for i in range(24)]) - T_lower[self.occ_start:self.occ_end] = 22.0 - - overshoot = [] - undershoot = [] + """ + # get control inputs: U = {u(t+1), u(t+2), ... u(t+PH)} + # u = [mz, \epsilon] + U = arg[0] # loop over the prediction horizon i = 0 P_pred_ph = [] - Tz_pred_ph = [] - - # get current state - has to copy original states due to mutable object list and dictionary - P_his = self.states['P_his_t'][:] # current state of historical power [P(t) to P(t-l)] - Tz_his = self.states['Tz_his_t'][:] # current zone temperatur states for zone temperture prediction model - - # initialize the cost function - penalty = [] # temperature violation penalty for each zone - alpha_up = 0.01 - alpha_low = 0.01 - time = self.time + eps_ph = [] while i < self.PH: - - mz = u_ph[i]*0.75 # control inputs - Toa = self.predictor['Toa'][i] # predicted outdoor air temperature + # get u for current step + u = U[i*2:2*i+2] + mz = u[0]*0.75 # control inputs + eps = u[1] # temperature slack ### ==================================================================== ### Power Predictor ### ===================================================================== # predict total power at current step - #P_pred = self.total_power(alpha_power, beta_power, gamma_power, l, P_his, mz, Toa) - P_pred = self.total_power(alpha_power, mz) - # update historical power measurement for next prediction - # reverst the historical data to enable FILO: [t, t-1, ...,t-l] - P_his = self.FILO(P_his,P_pred) - - # Save step-wise power + P_pred = self.power_polynomial(mz) + # Save step-wise power prediction P_pred_ph.append(P_pred) # save all step-wise power for cost calculation - ### ================================================================= - ### Zone Temperatre Predicction - ### ============================================================ - Ts = 273.15+13 # used as constant in this model - #Tz_pred = self.zone_temperature(alpha_zone, beta_zone, gamma_zone, l, Tz_his, mz, Ts, Toa) - Tz_pred = self.zone_temperature(Tz_his, mz, Toa) - # update historical zone temperature measurement for next prediction - # reverse the historical data to enable FILO - Tz_his = self.FILO(Tz_his,Tz_pred) - - # save step-wise temperature - Tz_pred_ph.append(Tz_pred) # save all step-wise power for cost calculation - - # get overshoot and undershoot for each step - # current time step - t = int(time+i*self.dt) - t = int((t % 86400)/3600) # hour index 0~23 + ### ===================================== + # Temperature violation + ### ====================================== + eps_ph.append(eps) - # this is to be revised for multi-zone - for k in range(self.number_zone): - overshoot.append(np.array([float((Tz_pred -273.15) - T_upper[t]), 0.0]).max()) - undershoot.append(np.array([float(T_lower[t] - (Tz_pred-273.15)), 0.0]).max()) - ### =========================================================== ### Update for next step ### ========================================================== # update clock + i += 1 - i+=1 - - # calculate total cost based on predicted energy prices + # energy cost: calculate total cost based on predicted energy prices price_ph = self.predictor['price'] + energy_cost = np.sum(np.array(price_ph)*np.array(P_pred_ph))*self.dt/3600./1000. # zone temperature bounds penalty - penalty = alpha_up*sum(np.array(overshoot)) + alpha_low*sum(np.array(undershoot)) + penalty = np.sum(np.array(eps_ph)**2) - ener_cost = float(np.sum(np.array(price_ph)*np.array(P_pred_ph)))*self.dt/3600./1000. + # objective for a minimization problem + f = self.w[0]*energy_cost + self.w[1]*penalty - #print mz, np.array(Tz_pred_ph)-273.15, ener_cost, penalty + return [f] - # objective for a minimization problem - f = ener_cost + penalty - #f = ener_cost - #f=penalty - # constraints - unconstrained - #g=[0.0]*self.PH - #for i in range(self.PH): - # g[i] = 0.1 - u_ph[i] +class ZoneTemperatureCallback(ca.Callback): + def __init__(self,name, PH, zone_model, states, predictor, opts={}): + ca.Callback.__init__(self) + self.PH = PH + self.zone_model = zone_model # params={'alpha':{}} + self.states = states + self.predictor = predictor + self.instantiate_zone_arx_model() + self.construct(name,opts) - # simulation status - #fail = 0 - #print f, g - return f + # Number of inputs and outputs + def get_n_in(self): return 1 + def get_n_out(self): return 1 - def optimize(self): + # Array of inputs and outputs + def get_sparsity_in(self,i): + return ca.Sparsity.dense(2*self.PH,1) + def get_sparsity_out(self,i): + return ca.Sparsity.dense(self.PH,1) + + # Initialize the object + def init(self): + print('initializing object') + + def instantiate_zone_arx_model(self): + """Instantiate a zone arx model """ - MPC optimizer: call optimizer to solve a minimization problem + self.Lz = len(self.zone_model['alpha']) + self.Lo = len(self.zone_model['beta']) + self.f_Tz = model.Zone(Lz=self.Lz, Lo=self.Lo) + self.f_Tz.params = self.zone_model + + def zone_arx(self,Tz_his_meas, To_his_meas, mz): + Tsa = 13 + return self.f_Tz.model(Tz_his_meas, To_his_meas, mz, Tsa) + + def eval(self,arg): + """evaluate temperature + """ - - self.optimum={} - - # get optimization model - model = self.get_optimization_model() - - # solve optimization - xtol=1e-3 - ftol=1e-6 - solver='de' # GLP - #solver = "interalg" # GLP - #solver='ralg' # NLP - #solver='ipopt'# NLP - r = model.solve(solver,xtol=xtol,ftol=ftol) - x_opt, f_opt = r.xf, r.ff - d1 = r.evals - d2 = r.elapsed - nbr_iters = d1['iter'] - nbr_fevals = d1['f'] - solve_time = d2['solver_time'] + # get control inputs: U = {u(t+1), u(t+2), ... u(t+PH)} + # u = [mz, \epsilon] + U = arg[0] + + # loop over the prediction horizon + i = 0 + Tz_pred_ph = [] + + # get states at current step t + Tz_his_meas = self.states['Tz_his_meas'] # [Tz(t-l), ..., Tz(t-1), Tz(t)] + To_his_meas = self.states['To_his_meas'] # [Tz(t-l), ..., Tz(t-1), Tz(t)] + Tz_his_pred = self.states['Tz_his_pred'] # [Tz(t-l), ..., Tz(t-1), Tz(t)] + + # get autocorrection term + e = self.f_Tz.autocorrection(Tz_his_meas, Tz_his_pred) + + while i < self.PH: + # get u for current step + u = U[i*2:2*i+2] + mz = u[0]*0.75 # control inputs + + ### ==================================================================== + ### Zone temperature prediction + ### ===================================================================== + # predict total power at current step + Tz_pred = self.zone_arx(Tz_his_meas, To_his_meas, mz) + e + + ### =========================================================== + ### Update for next step + ### ========================================================== + # update states for zone recursive regression model + # update future measurement + # future zone temperature measurements + Tz_his_meas = LIFO(Tz_his_meas,Tz_pred) + + # future oa temperature measurement + To_pred = self.predictor['Toa'][i] + To_his_meas = LIFO(To_his_meas,To_pred) + + # save step-wise temperature + Tz_pred_ph.append(Tz_pred) # save all step-wise power for cost calculation + + # update clock + i += 1 + + # return predicted zone temperature over prediction horizon + + return [Tz_pred_ph] + + +def LIFO(array,x): + # lAST IN FIRST OUT: + a = np.append(array,x) + + return list(a[1:]) + +class mpc_case(): + def __init__(self,PH,CH,time,dt,zone_model, power_model,measurement,states,predictor): + + self.PH=PH # prediction horizon + self.CH=CH # control horizon + self.dt = dt # time step + self.time = time # current time index + + #self.parameters_zone = parameters_zone # parameters for zone dynamic mpc model, dictionary + #self.parameters_power = parameters_power # parameters for system power dynamic mpc model, dictionary + self.measurement = measurement # measurement at current time step, dictionary + self.predictor = predictor # price and outdoor air temperature for the future horizons + ## load MPC models + # should be decided beforehand: if ARX, {'alpha':[], 'beta':[], 'gamma':[]}; if ANN, {'model_name':'xx.pkl'} + self.zone_model = zone_model if 'model_name' not in zone_model else joblib.load(zone_model['model_name']) + self.power_model = power_model if 'model_name' not in power_model else joblib.load(power_model['model_name']) - self.optimum['objective'] = f_opt - self.optimum['variable'] = x_opt - - disp = True - if disp: - print (' ') - print ('Solver: OpenOpt solver ' + solver) - print (' ') - print ('Number of iterations: ' + str(nbr_iters)) - print ('Number of function evaluations: ' + str(nbr_fevals)) - print (' ') - print ('Execution time: ' + str(solve_time)) - print (' ') + self.states = states # dictionary - return self.optimum + # some building control settings + self.number_zone = 1 + self.occ_start = 6 # occupancy starts + self.occ_end = 19 # occupancy ends - def openopt_model_glp(self): - """This is to formulate a global optimization problem + # some mpc settings + self.n = 2 # number of control variable for each step + self.w = [1, 0.01] # weights between energy cost and temperature violation + self.u_lb = [0.]*self.n + self.u_ub = [1.,0.01] + # initialize optimiztion + self.u_start = self.u_lb*self.PH + #self.optimization_model=self.get_optimization_model() # pyomo object + self.optimum= {} + + def optimize(self): + """MPC optimization problem in casadi interface """ - # create oovar of size PH - #u = oovar(size=self.PH) - # might not work becasue u is a oovar object, not list - objective = lambda u: self.obj([u[i] for i in range(self.PH)]) - #startPoint = 0.5*np.array(self.PH) - # bounds - lb = self.u_lb - ub = self.u_ub + # instantiate objective function + f = ObjectiveCallback('f', + PH = self.PH, + dt = self.dt, + w = self.w, + power_model = self.power_model, + predictor = self.predictor, + opts={"enable_fd":True}) + + # instantiate nonlinear constraints zone temperature + Tz = ZoneTemperatureCallback('Tz', + PH = self.PH, + zone_model = self.zone_model, + states = self.states, + predictor =self.predictor, + opts={"enable_fd":True}) + # define casadi variables + u = ca.MX.sym("U",self.n*self.PH) + + # define objective function + obj = f(u) + # define constraint function + Tz_pred = Tz(u) # predicted T of size PH + + ### define nonlinear temperature constraints + # zone temperature bounds - need check with the high-fidelty model + T_upper = np.array([30.0 for i in range(24)]) + T_upper[self.occ_start:self.occ_end] = 26.0 + T_lower = np.array([12.0 for i in range(24)]) + T_lower[self.occ_start:self.occ_end] = 22.0 - return GLP(objective, lb=lb, ub=ub, maxIter = 5e5) + # get overshoot and undershoot for each step + # current time step + time = self.time - def openopt_model_nlp(self): - """This is to formulate a nolinear programming problem in openopt: minimization - """ - objective = lambda u: self.obj([u[i] for i in range(self.PH)]) - # objective gradient - optional - df = None - # start point - start = self.u_start - # constraints if any - c = None # nonlinear inequality - dc = None # derivative of c - h = None # nonlinear equality - dh = None # derivative of h - A = None # linear inequality - b = None - Aeq = None # linear equality - beq = None # linear equality - - # bounds - lb = self.u_lb - ub = self.u_ub - - # tolerance control - # required constraints tolerance, default for NLP is 1e-6 - contol = 1e-6 - - # If you use solver algencan, NB! - it ignores xtol and ftol; using maxTime, maxCPUTime, maxIter, maxFunEvals, fEnough is recommended. - # Note that in algencan gtol means norm of projected gradient of the Augmented Lagrangian - # so it should be something like 1e-3...1e-5 - gtol = 1e-6 # (default gtol = 1e-6) - - # see https://github.com/troyshu/openopt/blob/d15e81999ef09d3c9c8cb2fbb83388e9d3f97a98/openopt/oo.py#L390. - return NLP(objective, start, df=df, c=c, dc=dc, h=h, dh=dh, A=A, b=b, Aeq=Aeq, beq=beq, - lb=lb, ub=ub, gtol=gtol, contol=contol, maxIter = 50000, maxFunEvals = 20000, name = 'NLP for: '+str(self.time)) - - def get_optimization_model(self): - return self.openopt_model_glp() - #return self.openopt_model_nlp() - - def FILO(self,lis,x): - lis.pop() # remove the last element - lis.reverse() - lis.append(x) - lis.reverse() - - return lis - - def zone_temperature(self,Tz_his, mz, Toa): - ann = self.zone_model - x=list(Tz_his) - x.append(mz) - x.append(Toa) - x = np.array(x).reshape(1,-1) - y=float(ann.predict(x)) + g = [] + lbg = [] + ubg = [] + for k in range(self.PH): + # future time + t = int(time+k*self.dt) + t = int((t % 86400)/3600) # hour index 0~23 + + # inequality constraints + eps = u[self.n*k+1] + g += [Tz_pred[k]+eps, Tz_pred[k]-eps] + # get upper and lower T bound + lbg += [T_lower[t], 0.] + ubg += [ca.inf, T_upper[t]] + + # formulate an optimziation problem using nlp solver + prob = {'f':obj, 'x': u, 'g': ca.vertcat(*g)} + nlp_optimize = ca.nlpsol('solver', 'ipopt', prob) + + # set initial guess + u0 = self.u_start + + # set lower upper bound for u + lbx = self.u_lb*self.PH + ubx = self.u_ub*self.PH + + # solve the optimization problem + solution = nlp_optimize(x0=u0, lbx=lbx, ubx=ubx, lbg=lbg, ubg=ubg) - return np.maximum(273.15+14,np.minimum(y,273.15+35)) - - def total_power(self,alpha, mz): - """Predicte power at next step - - :param alpha: coefficients from curve-fitting - :type alpha: np array (l,) - :param beta: coefficient from curve-fitting - :type beta: scalor - :param gamma: coefficient from curve-fitting - :type gamma: scalor - :param l: historical step - :type l: scalor - :param Tz_his: historical zone temperature array - :type Tz_his: np array (l,) - :param mz: zone air mass flowrate at time t - :type mz: scalor - :param Ts: discharge air temperaure at time t - :type Ts: scalor - :param Toa: outdoor air dry bulb temperature at time t - :type Toa: scalor - - :return: predicted zone temperature at time t - :rtype: scalor - """ - # check dimensions + # get and save the results + u_opt = solution['x'] + f_opt = solution['f'] + self.optimum['objective'] = f_opt + self.optimum['variable'] = u_opt - alpha=np.array(alpha).reshape(-1) - #beta=np.array(beta).reshape(-1) - if mz>=1e-03: - P = alpha[0]+alpha[1]*mz+alpha[2]*mz**2 #+ beta[0]+ beta[1]*Toa+beta[2]*Toa**2 - else: - P = 0 - return float(abs(P)) + print(solution) + + # save the function for external calls + self.f = f + self.Tz = Tz + return self.optimum + def set_time(self, time): self.time = time @@ -341,8 +349,8 @@ def set_predictor(self, predictor): self.predictor = predictor def get_u_start(self,optimum_prev): - fut = optimum_prev[1:] - start = np.append(fut,(self.u_lb[-1]+self.u_ub[-1])/2.) + fut = optimum_prev[self.n:] + start = np.append(fut, [0.5,0.]) return start def set_u_start(self,prev): diff --git a/testcases/mpc/single-zone-fan-power/average-sample/mpc_final_run.bat b/testcases/mpc/single-zone-fan-power/average-sample/mpc_final_run.bat index 19ef7284..dd305644 100644 --- a/testcases/mpc/single-zone-fan-power/average-sample/mpc_final_run.bat +++ b/testcases/mpc/single-zone-fan-power/average-sample/mpc_final_run.bat @@ -7,6 +7,5 @@ docker run --name fmuc^ -v %CD%:/mnt/shared^ -i^ -t^ - mpcdrl /bin/bash -c^ - "source activate base && export PYTHONPATH=$PYFMI_PY3_CONDA_PATH:$PYTHONPATH && cd /mnt/shared && python /mnt/shared/mpc_final_run.py" + yangyangfu/mpcdrl:cpu_py3 /bin/bash -c "source activate base && export PYTHONPATH=$PYFMI_PY3_CONDA_PATH:$PYTHONPATH && cd /mnt/shared && python /mnt/shared/mpc_final_run.py" diff --git a/testcases/mpc/single-zone-fan-power/average-sample/mpc_final_run.py b/testcases/mpc/single-zone-fan-power/average-sample/mpc_final_run.py index a4809ea1..ccf6c18f 100644 --- a/testcases/mpc/single-zone-fan-power/average-sample/mpc_final_run.py +++ b/testcases/mpc/single-zone-fan-power/average-sample/mpc_final_run.py @@ -26,7 +26,7 @@ ## fmu settings options = baseline.simulate_options() -options['ncp'] = 5000. +options['ncp'] = 5000 options['initialize'] = True ## construct optimal input for fmu @@ -44,13 +44,14 @@ t_opt = opt['t_opt'] u_opt = opt['u_opt'] - +u_opt = np.maximum(np.array(u_opt),0) +print(u_opt) ### 1- Load virtual building model mpc = load_fmu('SingleZoneDamperControl.fmu') ## fmu settings options = mpc.simulate_options() -options['ncp'] = 5000. +options['ncp'] = 5000 options['initialize'] = True ## construct optimal input for fmu diff --git a/testcases/mpc/single-zone-fan-power/average-sample/test_mpc.bat b/testcases/mpc/single-zone-fan-power/average-sample/test_mpc.bat index f849a870..599e8435 100644 --- a/testcases/mpc/single-zone-fan-power/average-sample/test_mpc.bat +++ b/testcases/mpc/single-zone-fan-power/average-sample/test_mpc.bat @@ -7,5 +7,4 @@ docker run^ -v %CD%:/mnt/shared^ -i^ -t^ - mpcdrl /bin/bash -c^ - "source activate base && export PYTHONPATH=$PYFMI_PY3_CONDA_PATH:$PYTHONPATH && cd /mnt/shared && python /mnt/shared/test_mpc.py" + yangyangfu/mpcdrl:cpu_py3 /bin/bash -c "source activate base && export PYTHONPATH=$PYFMI_PY3_CONDA_PATH:$PYTHONPATH && cd /mnt/shared && python /mnt/shared/test_mpc.py" diff --git a/testcases/mpc/single-zone-fan-power/average-sample/test_mpc.py b/testcases/mpc/single-zone-fan-power/average-sample/test_mpc.py index 1dde547c..186cf3bb 100644 --- a/testcases/mpc/single-zone-fan-power/average-sample/test_mpc.py +++ b/testcases/mpc/single-zone-fan-power/average-sample/test_mpc.py @@ -32,33 +32,33 @@ def interpolate_dataframe(df,new_index): df_out[col_name] = np.interp(new_index, df.index, col) return df_out -def FILO(a_list,x): - """First in last out: +def LIFO(a_list,x): + """Last in first out: x: scalor """ - a_list.pop() # remove the last element - a_list.reverse() a_list.append(x) - a_list.reverse() - return a_list + return a_list[1:] -def get_states(states,measurement): +def get_states(states,measurement,Tz_pred): # read list - Tz_his = states['Tz_his_t'] - P_his = states['P_his_t'] + Tz_his = states['Tz_his_meas'] + To_his = states['To_his_meas'] + Tz_his_pred = states['Tz_his_pred'] - # read scalor - Tz = measurement['TRoo'].values[0] - P = measurement['PTot'].values[0] + # read scalor: to degC for ARX model + Tz = measurement['TRoo'].values[0] - 273.15 + To = measurement['TOut'].values[0] - 273.15 + + # new list - avoid immutable lists + new_Tz_his = LIFO(Tz_his,Tz) + new_To_his = LIFO(To_his,To) + new_Tz_his_pred = LIFO(Tz_his_pred,Tz_pred) - # new list - new_Tz_his = FILO(Tz_his,Tz) - new_P_his = FILO(P_his,P) - # new dic - states['Tz_his_t'] = new_Tz_his - states['P_his_t']= new_P_his + states['Tz_his_meas'] = new_Tz_his + states['To_his_meas'] = new_To_his + states['Tz_his_pred'] = new_Tz_his_pred return states @@ -66,8 +66,8 @@ def get_price(time,dt,PH): price_tou = [0.0640, 0.0640, 0.0640, 0.0640, 0.0640, 0.0640, 0.0640, 0.0640, 0.1391, 0.1391, 0.1391, 0.1391, - 0.3548, 0.3548, 0.3548, 0.3548, - 0.3548, 0.3548, 0.1391, 0.1391, + 0.3548*10, 0.3548*10, 0.3548*10, 0.3548*10, + 0.3548*10, 0.3548*10, 0.1391, 0.1391, 0.1391, 0.1391, 0.1391, 0.0640] #- assume hourly TOU pricing t_ph = np.arange(time,time+dt*PH,dt) @@ -84,7 +84,7 @@ def read_temperature(weather_file,dt): dat = read_epw(weather_file) - tem_sol_h = dat[0][['temp_air']]+273.15 + tem_sol_h = dat[0][['temp_air']] index_h = np.arange(0,3600.*len(tem_sol_h),3600.) tem_sol_h.index = index_h @@ -107,7 +107,7 @@ def get_Toa(time,dt,PH,Toa_year): ## fmu settings options = hvac.simulate_options() -options['ncp'] = 500. +options['ncp'] = 500 options['initialize'] = True # Warm up FMU simulation settings @@ -116,37 +116,49 @@ def get_Toa(time,dt,PH,Toa_year): ### 2- Initialize MPC case dt = 15*60. -PH = 8 +PH = 4 CH = 1 -with open('TZone.json') as f: +with open('zone_arx.json') as f: parameters_zone = json.load(f) -with open('Power.json') as f: +with open('power.json') as f: parameters_power = json.load(f) -# measurement at current time +# initialize measurement measurement_names=['TRoo','TOut','PTot','uFan','hvac.fanSup.m_flow_in'] -measurement_ini = {} +res = hvac.simulate(start_time = ts, + final_time = ts, + options=options) +options['initialize'] = False +measurement_ini = get_measurement(res,measurement_names) + +# read one-year weather file +weather_file = 'USA_CA_Riverside.Muni.AP.722869_TMY3.epw' +Toa_year = read_temperature(weather_file,dt) + +### =========================== # states at current time for MPC model - this should be customized based on mpc design lag_Tz = 4 # 4-step lag - should be identified for MPC model -lag_PTot = 4 # 4-step lag - should be idetified for mpc model -Tz_ini = 273.15+20 +lag_To = 4 # 4-step lag +Tz_ini = measurement_ini['TRoo'].values[0] - 273.15 P_ini = 0.0 -states_ini = {'Tz_his_t':[Tz_ini]*lag_Tz, - 'P_his_t':[P_ini]*lag_PTot} # initial states used for MPC models +To_his_meas_init = get_Toa(ts-(lag_To-1)*dt,dt,lag_To,Toa_year) -## predictors -predictor = {} +states_ini = {'Tz_his_meas':[Tz_ini]*lag_Tz, + 'To_his_meas':To_his_meas_init, + 'Tz_his_pred':[Tz_ini]*lag_Tz} # initial states used for MPC models +### ========================================== +### predictors +predictor = {} # energy prices -predictor['price'] = get_price(ts,dt,PH) +predictor['price'] = get_price(ts+dt,dt,PH) # outdoor air temperature -weather_file = 'USA_CA_Riverside.Muni.AP.722869_TMY3.epw' -Toa_year = read_temperature(weather_file,dt) -predictor['Toa'] = get_Toa(ts,dt,PH,Toa_year) +predictor['Toa'] = get_Toa(ts+dt,dt,PH,Toa_year) +### ================================== ### 3- MPC Control Loop -uFan_ini = 0.1 +uFan_ini = 0. # initialize fan speed for warmup setup uFan = uFan_ini states = states_ini @@ -156,14 +168,15 @@ def get_Toa(time,dt,PH,Toa_year): CH=CH, time=ts, dt=dt, - parameters_zone = parameters_zone, - parameters_power = parameters_power, + zone_model = parameters_zone, + power_model = parameters_power, measurement = measurement, states = states, predictor = predictor) # initialize all results u_opt=[] t_opt=[] +warmup = True while ts=te_warm: # activate mpc after warmup + print("\nstate 1") + print(case.states) + if not warmup: # activate mpc after warmup # update mpc case case.set_time(ts) case.set_measurement(measurement) - case.set_states(states) - print("\nstate 1") - print(case.states) + case.set_states(states) case.set_predictor(predictor) # call optimizer optimum = case.optimize() @@ -185,22 +198,26 @@ def get_Toa(time,dt,PH,Toa_year): # get objective and design variables f_opt_ph = optimum['objective'] u_opt_ph = optimum['variable'] - + # get the control action for the control horizon - u_opt_ch = u_opt_ph[0] + u_opt_ch = u_opt_ph[0:case.n] # overwrite fan speed - uFan = u_opt_ch + uFan = np.maximum(float(u_opt_ch[0]),0) # update start points for optimizer using previous optimum value case.set_u_start(u_opt_ph) + + # update predictions after MPC predictor is called otherwise use measurement + Tz_pred = float(case.Tz(u_opt_ph)[0]) + ### advance building simulation by one step - u_traj = np.transpose(np.vstack(([ts,te],[uFan,uFan]))) - input_object = ("uFan",u_traj) + #u_traj = np.transpose(np.vstack(([ts,te],[uFan,uFan]))) + #input_object = ("uFan",u_traj) + hvac.set("uFan",uFan) res = hvac.simulate(start_time = ts, final_time = te, - options = options, - input = input_object) + options = options) # update clock ts = te @@ -208,24 +225,29 @@ def get_Toa(time,dt,PH,Toa_year): # get measurement measurement = get_measurement(res,measurement_names) print(measurement) - # update MPC model inputs - print ("\nstate 2") - print (case.states) - print ("\nstate 3") - print (states) - states = get_states(states,measurement) + + # update MPC model states + # if not warmup then measurement else from mpc + if warmup: + Tz_pred = measurement['TRoo'].values[0] - 273.15 + + states = get_states(states,measurement, Tz_pred) print ("\nstate 4") print (states) + # online MPC model calibration if applied - NOT IMPLEMENTED # update parameter_zones and parameters_power - NOT IMPLEMENTED # update predictor - predictor['price'] = get_price(ts,dt,PH) - predictor['Toa'] = get_Toa(ts,dt,PH,Toa_year) + predictor['price'] = get_price(ts+dt,dt,PH) + predictor['Toa'] = get_Toa(ts+dt,dt,PH,Toa_year) # update fmu settings options['initialize'] = False + # update warmup flag for next step + warmup = ts