diff --git a/pyDMPC/ControlFramework/Experiment.py b/pyDMPC/ControlFramework/Experiment.py index 87089a1..cfb169e 100644 --- a/pyDMPC/ControlFramework/Experiment.py +++ b/pyDMPC/ControlFramework/Experiment.py @@ -21,7 +21,7 @@ def main(): start_time = time.time() sys.execute() #time.sleep(max(0, min_samp_inter - time.time() + start_time)) - + System.Bexmoc.close_mod() System.Bexmoc.close_cont_sys() print("Success") diff --git a/pyDMPC/ControlFramework/Init.py b/pyDMPC/ControlFramework/Init.py index 8d565c6..8e211dc 100644 --- a/pyDMPC/ControlFramework/Init.py +++ b/pyDMPC/ControlFramework/Init.py @@ -14,7 +14,7 @@ contr_sys_typ = "Modelica" ads_id = '5.59.199.202.1.1' ads_port = 851 -name_fmu = r'ModelicaModels_ControlledSystems_ControlledSystemBoundaries.fmu' +name_fmu = 'ModelicaModels_ControlledSystems_ControlledSystemBoundaries.fmu' orig_fmu_path = glob_res_path + '\\' + name_fmu dest_fmu_path = glob_res_path + '\\' + name_wkdir + '\\' + name_fmu time_incr = 120 @@ -71,7 +71,7 @@ par_neigh.append(None) input_names.append(["coolerTemperature.T"]) input_variables.append([r"variation.table[1,2]"]) -inputs.append(range(280,325,5)) +inputs.append([i for i in range(280,325,1)]) output_names.append(["supplyAirTemperature.T"]) set_points.append([303]) state_var_names.append(["heaterInitials[1].y"]) @@ -79,18 +79,18 @@ start.append(0.) stop.append(3600) incr.append(10.) -opt_time.append(0) -samp_time.append(10) +opt_time.append(600) +samp_time.append(60) lib_paths.append(glob_lib_paths) res_path.append(glob_res_path + "\\" + name_wkdir) dym_path.append(glob_dym_path) -mod_path.append(r'D:\dymola\heater') +mod_path.append(f'{glob_res_path}\\heater') command_names.append(["valveHeater"]) command_variables.append(["decisionVariables.table[1,2]"]) -commands.append(range(0,105,5)) +commands.append([[0,0], [10,10], [30,30], [60,60], [80,80], [100,100]]) traj_points.append([]) traj_var.append([]) -cost_fac.append([0.5, 0.0, 1.0]) +cost_fac.append([0.1, 0.0, 1.0]) sys_id.append(1) name.append("Cooler") @@ -100,7 +100,7 @@ par_neigh.append(None) input_names.append(["preHeaterTemperature.T"]) input_variables.append([r"variation.table[1,2]"]) -inputs.append(range(280,325,5)) +inputs.append([i for i in range(280,325,1)]) output_names.append(["supplyAirTemperature.T"]) set_points.append([303]) state_var_names.append(["coolerInitials[1].y"]) @@ -108,15 +108,15 @@ start.append(0.) stop.append(3600.) incr.append(10.) -opt_time.append(0) -samp_time.append(10) +opt_time.append(600) +samp_time.append(60) lib_paths.append(glob_lib_paths) res_path.append(glob_res_path + "\\" + name_wkdir) dym_path.append(glob_dym_path) -mod_path.append(r'D:\dymola\cooler') +mod_path.append(f'{glob_res_path}\\cooler') command_names.append(["valveCooler"]) command_variables.append(["decisionVariables.table[1,2]"]) -commands.append(range(0,105,5)) +commands.append([[0,0], [2,2], [4,4], [6,6], [8,8], [10,10], [12,12], [14,14], [16,16], [18,18], [20,20], [22,22]]) traj_points.append([]) traj_var.append([]) -cost_fac.append([0.5, 1.0, 0]) +cost_fac.append([0.0, 1.0, 0]) diff --git a/pyDMPC/ControlFramework/Modeling.py b/pyDMPC/ControlFramework/Modeling.py index fb3ce14..b4eee5f 100644 --- a/pyDMPC/ControlFramework/Modeling.py +++ b/pyDMPC/ControlFramework/Modeling.py @@ -195,19 +195,28 @@ def translate(self): def simulate(self): ModelicaMod.dymola.cd(self.paths.res_path) + + command_variables = [f"decisionVariables.table[{i+1},2]" + for i in range(1)] + + time_variables = [f"decisionVariables.table[{i+1},1]" + for i in range(1)] + + times = [i*600 for i in range(1)] if self.states.input_variables[0] == "external": initialNames = (self.states.command_variables + - self.states.model_state_var_names) - initialValues = (self.states.commands + self.states.state_vars) + self.states.model_state_var_names + time_variables) + initialValues = (self.states.commands + self.states.state_vars + times) else: initialValues = (self.states.commands + self.states.inputs + - self.states.state_vars) + self.states.state_vars + times) - initialNames = (self.states.command_variables + + initialNames = (command_variables + self.states.input_variables + - self.states.model_state_var_names) + self.states.model_state_var_names + time_variables) print(initialNames) + print(initialValues) for k in range(3): @@ -267,17 +276,19 @@ def load_mod(self): def write_inputs(self): import numpy as np - commands = [com*np.ones(60) for com in self.states.commands] - inputs = [inp*np.ones(60) for inp in self.states.inputs] + commands_1 = self.states.commands[0]*np.ones(10) + commands_2 = self.states.commands[1]*np.ones(50) + commands = commands_1.tolist() + commands_2.tolist() + inputs = self.states.inputs[0]*np.ones(60) + inputs = inputs.tolist() - inputs = np.stack((commands + inputs), axis=1) + inputs = np.stack(([commands] + [inputs]), axis=1) self.scal_inputs = self.scaler.transform(inputs) def predict(self): self.write_inputs() self.states.outputs = [self.model.predict(self.scal_inputs)] - #print(f"MLP outputs: {self.states.outputs}") class LinMod(Model): diff --git a/pyDMPC/ControlFramework/Subsystem.py b/pyDMPC/ControlFramework/Subsystem.py index 0b955df..33c2e75 100644 --- a/pyDMPC/ControlFramework/Subsystem.py +++ b/pyDMPC/ControlFramework/Subsystem.py @@ -122,7 +122,6 @@ def predict(self, inputs, commands): if self.model.states.state_var_names != []: for i,nam in enumerate(self.model.states.state_var_names): - #print("State variable names: " + str(nam)) state_vars.append(System.Bexmoc.read_cont_sys(nam)) if inputs != "external": @@ -150,8 +149,6 @@ def interp_minimize(self, interp): from scipy import interpolate as it import time - #print('minimizing') - opt_costs = [] opt_outputs = [] opt_command = [] @@ -159,7 +156,6 @@ def interp_minimize(self, interp): states = self.get_state_vars() if states != []: self.model.states.state_vars = states[0] - #print(f"States: {self.model.states.state_vars}") if self.model.states.input_variables[0] != "external": if self.inputs == []: @@ -180,14 +176,12 @@ def interp_minimize(self, interp): costs = [] for com in self.commands: - results = self.predict(inp, [com]) + results = self.predict(inp, com) outputs.append(results) costs.append(self.calc_cost(com, results[-1][-1])) min_ind = costs.index(min(costs)) - #print("index: " + str(min_ind)) - opt_costs.append(costs[min_ind]) temp = outputs[min_ind] opt_outputs.append(temp[0][-1]) @@ -200,6 +194,7 @@ def interp_minimize(self, interp): for pts in self.traj_points: traj_costs.append((pts - set_point)**2) + self.traj_points.insert(self.traj_points[0] - 1.) traj_costs.insert(traj_costs[0] * 5) self.traj_points.append(self.traj_points[-1] + 1) @@ -221,7 +216,6 @@ def interp_minimize(self, interp): if len(inputs) >= 2: if interp: - self.coup_vars_send = opt_outputs self.command_send = it.interp1d(inputs, opt_command, fill_value = (100,100), bounds_error = False) @@ -233,75 +227,74 @@ def interp_minimize(self, interp): self.coup_vars_send = opt_outputs[0] self.command_send = opt_command[0] + print(f"self.cost_send: {self.cost_send}") + time.sleep(2) + print(f"Command: {self.command_send}") + def calc_cost(self, command, outputs): import scipy.interpolate + import numpy as np - cost = self.cost_fac[0] * command + cost = self.cost_fac[0] * sum(command) if self.cost_rec != [] and self.cost_rec != [[]]: for c in self.cost_rec: if type(c) is scipy.interpolate.interpolate.interp1d: cost += self.cost_fac[1] * c(outputs) - #print(f"Interp. cost: {c(outputs)}") elif type(c) is list: - cost += self.cost_fac[1] * c[0] + idx = self.find_nearest(np.asarray(self.inputs), outputs) + cost += self.cost_fac[1] * c[idx] else: cost += self.cost_fac[1] * c - if self.model.states.set_points != []: cost += (self.cost_fac[2] * (outputs - self.model.states.set_points[0])**2) return cost + + def find_nearest(self, a, a0): + import numpy as np + "Element in nd array `a` closest to the scalar value `a0`" + idx = np.abs(a - a0).argmin() + + return idx def interp(self, iter_real): import scipy.interpolate - import time + import numpy as np if iter_real == "iter" and self.coup_vars_rec != []: inp = self.coup_vars_rec else: inp = self.model.states.inputs - #print(f"{self.name}: {inp}") + idx = self.find_nearest(np.asarray(self.inputs), inp[0]) if self.command_send != []: if (type(self.command_send) is scipy.interpolate.interpolate.interp1d): self.fin_command = self.command_send(inp[0]) else: - self.fin_command = self.command_send[0] + self.fin_command = self.command_send[idx] if self.coup_vars_send != []: if type(self.coup_vars_send) is scipy.interpolate.interpolate.interp1d: self.fin_coup_vars = self.coup_vars_send(inp[0]) else: - self.fin_coup_vars = self.coup_vars_send - - #print(f"{self.name}: {self.fin_command}") - #time.sleep(2) + self.fin_coup_vars = self.coup_vars_send[idx] def get_inputs(self): - cur_time = Time.Time.get_time() - #print("Time: " + str(cur_time)) - #print("Sample time: " + str(self.model.times.samp_time)) - inputs = [] - #print("Input variables: "+ str(self.model.states.input_variables)) if self.model.states.input_variables is not None: for nam in self.model.states.input_names: - #print("check") inputs.append(System.Bexmoc.read_cont_sys(nam)) - #print("Inputs" + str(inputs)) self.model.states.inputs = inputs def get_state_vars(self): - cur_time = Time.Time.get_time() - states = [] if self.model.states.state_var_names is not None: @@ -316,7 +309,9 @@ def send_commands(self): if (cur_time - self.last_write) > self.model.times.samp_time: self.last_write = cur_time + + print(self.fin_command[0]) if self.model.states.command_names is not None: for nam in self.model.states.command_names: - System.Bexmoc.write_cont_sys(nam, self.fin_command) + System.Bexmoc.write_cont_sys(nam, self.fin_command[0]) diff --git a/pyDMPC/ControlFramework/System.py b/pyDMPC/ControlFramework/System.py index e2a6555..de156f0 100644 --- a/pyDMPC/ControlFramework/System.py +++ b/pyDMPC/ControlFramework/System.py @@ -234,10 +234,10 @@ def initialize(self): def execute(self): for i in range(len(self.subsystems)): - self.subsystems[i].optimize(interp=True) + self.subsystems[i].optimize(interp=False) if self.subsystems[i].par_neigh is not None: for j in self.subsystems[i].par_neigh: - self.subsystems[j].optimize(interp=True) + self.subsystems[j].optimize(interp=False) self.broadcast([i] + self.subsystems[i].par_neigh) else: #print(f"Broadcasting: {i}") @@ -253,8 +253,7 @@ def execute(self): cur_time = Time.Time.get_time() Bexmoc.proceed(cur_time, Time.Time.time_incr) - tim = Time.Time.set_time() - #print("Time: " + str(tim)) + Time.Time.set_time() def iterate(self): import time @@ -292,10 +291,13 @@ def iterate(self): #print(f"Coupling: {sub.coup_vars_rec[0]}") if (self.subsystems[1].inputs[0] < self.subsystems[1].model.states.set_points[0]): - sub.inputs = [min(sub.coup_vars_rec[0], sub.model.states.set_points[0] - 0.5), sub.model.states.set_points[0]] + sub.inputs = [min(sub.coup_vars_rec[0], + sub.model.states.set_points[0] - 0.5), + sub.model.states.set_points[0]] else: sub.inputs = [max(sub.coup_vars_rec[1], - sub.model.states.set_points[0] + 0.5), sub.model.states.set_points[0]] + sub.model.states.set_points[0] + 0.5), + sub.model.states.set_points[0]] sub.inputs.sort() print(f"{sub.name}: {sub.inputs}") diff --git a/pyDMPC/ModelicaModels/ModelicaModels/ControlledSystems/ControlledSystemBoundaries.mo b/pyDMPC/ModelicaModels/ModelicaModels/ControlledSystems/ControlledSystemBoundaries.mo index 4f50e2d..227f8d5 100644 --- a/pyDMPC/ModelicaModels/ModelicaModels/ControlledSystems/ControlledSystemBoundaries.mo +++ b/pyDMPC/ModelicaModels/ModelicaModels/ControlledSystems/ControlledSystemBoundaries.mo @@ -82,169 +82,16 @@ model ControlledSystemBoundaries AixLib.Fluid.Sensors.RelativeHumidity outgoingAirOutletHumidity(redeclare package Medium = MediumAir) "Relative humidity after HRC" annotation (Placement(transformation(extent={{-256,48},{-236,68}}))); - Modelica.Blocks.Interfaces.RealOutput outgoingAirOutletHumidityOutput - "Relative humidity in port medium" annotation (Placement(transformation( - extent={{-10,-10},{10,10}}, - rotation=90, - origin={-230,202}))); - Modelica.Blocks.Interfaces.RealOutput outdoorHumidityOutput - "Connector of Real output signal" annotation (Placement(transformation( - extent={{-10,-10},{10,10}}, - rotation=90, - origin={-346,198}))); - Modelica.Blocks.Interfaces.RealOutput outgoingAirOutletTemperatureCOutput - annotation (Placement(transformation( - extent={{-10,-10},{10,10}}, - rotation=90, - origin={-210,202}))); - Modelica.Blocks.Interfaces.RealOutput outdoorTemperatureOutput - "Connector of Real output signal" annotation (Placement(transformation( - extent={{-10,-10},{10,10}}, - rotation=90, - origin={-360,198}))); - Modelica.Blocks.Interfaces.RealOutput hRCHumidityOutput - "Relative humidity in port medium" annotation (Placement(transformation( - extent={{-10,-10},{10,10}}, - rotation=90, - origin={-106,118}))); - Modelica.Blocks.Interfaces.RealOutput hRCTemperatureCOutput annotation ( - Placement(transformation( - extent={{-10,-10},{10,10}}, - rotation=90, - origin={-90,118}))); - Modelica.Blocks.Interfaces.RealOutput preHeaterHumidityOutput - "Relative humidity in port medium" annotation (Placement(transformation( - extent={{-10,-10},{10,10}}, - rotation=90, - origin={-2,76}))); - Modelica.Blocks.Interfaces.RealOutput preHeaterTemperatureCOutput - "Temperature in port medium" annotation (Placement(transformation( - extent={{-10,-10},{10,10}}, - rotation=90, - origin={12,76}))); - Modelica.Blocks.Interfaces.RealOutput coolerHumidityOutput - "Relative humidity in port medium" annotation (Placement(transformation( - extent={{-10,-10},{10,10}}, - rotation=90, - origin={58,82}))); - Modelica.Blocks.Interfaces.RealOutput coolerTemperatureCOutput annotation ( - Placement(transformation( - extent={{-10,-10},{10,10}}, - rotation=90, - origin={72,82}))); - Modelica.Blocks.Interfaces.RealOutput heaterHumidityOutput - "Relative humidity in port medium" annotation (Placement(transformation( - extent={{-10,-10},{10,10}}, - rotation=90, - origin={144,74}))); - Modelica.Blocks.Interfaces.RealOutput heaterTemperatureCOutput annotation ( - Placement(transformation( - extent={{-10,-10},{10,10}}, - rotation=90, - origin={160,74}))); - Modelica.Blocks.Interfaces.RealOutput supplyHumidityOutput - "Relative humidity in port medium" annotation (Placement(transformation( - extent={{-10,-10},{10,10}}, - rotation=90, - origin={276,76}))); - Modelica.Blocks.Interfaces.RealOutput supplyAirTemperatureCOutput annotation ( - Placement(transformation( - extent={{-10,-10},{10,10}}, - rotation=90, - origin={294,76}))); - Modelica.Blocks.Interfaces.RealOutput roomTemperatureOutput - "Connector of Real output signal" annotation (Placement(transformation( - extent={{-10,-10},{10,10}}, - rotation=90, - origin={212,178}))); - Modelica.Blocks.Interfaces.RealOutput roomHumidityOutput - "Connector of Real output signal" annotation (Placement(transformation( - extent={{-10,-10},{10,10}}, - rotation=90, - origin={190,176}))); - Modelica.Blocks.Interfaces.RealOutput coolingCircuitOutput - "Connector of Real output signal" annotation (Placement(transformation( - extent={{-10,-10},{10,10}}, - rotation=90, - origin={32,142}))); - Modelica.Blocks.Interfaces.RealOutput highTemperatureCircuitOutput - "Connector of Real output signal" annotation (Placement(transformation( - extent={{-10,-10},{10,10}}, - rotation=90, - origin={-54,154}))); - Modelica.Blocks.Interfaces.RealOutput coolerReturnTemperatureOutput - "Water return temperature in Celsius" annotation (Placement(transformation( - extent={{-10,-10},{10,10}}, - rotation=270, - origin={78,-62}))); - Modelica.Blocks.Interfaces.RealOutput preHeaterReturnTemperatureOutput - "Water return temperature in Celsius" annotation (Placement(transformation( - extent={{-10,-10},{10,10}}, - rotation=270, - origin={-12,-66}))); - Modelica.Blocks.Interfaces.RealOutput heaterReturnTemperatureOutput - "Water return temperature in Celsius" annotation (Placement(transformation( - extent={{-10,-10},{10,10}}, - rotation=270, - origin={142,-68}))); Modelica.Blocks.Sources.RealExpression realExpression[4](y=inOutlets.hex.ele[ :].mas.T) annotation (Placement(transformation(extent={{-200,-142},{-180,-122}}))); - Modelica.Blocks.Interfaces.RealOutput inOutletsOutgoingHexele1masT - "Value of Real output" - annotation (Placement(transformation(extent={{-160,-126},{-140,-106}}))); - Modelica.Blocks.Interfaces.RealOutput inOutletsOutgoingHexele2masT - "Value of Real output" - annotation (Placement(transformation(extent={{-160,-136},{-140,-116}}))); - Modelica.Blocks.Interfaces.RealOutput inOutletsOutgoingHexele3masT - "Value of Real output" - annotation (Placement(transformation(extent={{-160,-146},{-140,-126}}))); - Modelica.Blocks.Interfaces.RealOutput inOutletsOutgoingHexele4masT - "Value of Real output" - annotation (Placement(transformation(extent={{-160,-156},{-140,-136}}))); Modelica.Blocks.Sources.RealExpression realExpression2[4](y=preHeater.hex.ele[ :].mas.T) annotation (Placement(transformation(extent={{-78,-186},{-58,-166}}))); - Modelica.Blocks.Interfaces.RealOutput preHeaterhexele1masT - "Value of Real output" - annotation (Placement(transformation(extent={{-38,-170},{-18,-150}}))); - Modelica.Blocks.Interfaces.RealOutput preHeaterhexele2masT - "Value of Real output" - annotation (Placement(transformation(extent={{-38,-180},{-18,-160}}))); - Modelica.Blocks.Interfaces.RealOutput preHeaterhexele3masT - "Value of Real output" - annotation (Placement(transformation(extent={{-38,-190},{-18,-170}}))); - Modelica.Blocks.Interfaces.RealOutput preHeaterhexele4masT - "Value of Real output" - annotation (Placement(transformation(extent={{-38,-200},{-18,-180}}))); - Modelica.Blocks.Sources.RealExpression realExpression3[4](y=cooler.hex.ele[:].mas.T) + Modelica.Blocks.Sources.RealExpression coolerInitials[4](y=cooler.hex.ele[:].mas.T) annotation (Placement(transformation(extent={{8,-188},{28,-168}}))); - Modelica.Blocks.Interfaces.RealOutput coolerhexele1masT - "Value of Real output" - annotation (Placement(transformation(extent={{48,-172},{68,-152}}))); - Modelica.Blocks.Interfaces.RealOutput coolerhexele2masT - "Value of Real output" - annotation (Placement(transformation(extent={{48,-182},{68,-162}}))); - Modelica.Blocks.Interfaces.RealOutput coolerhexele3masT - "Value of Real output" - annotation (Placement(transformation(extent={{48,-192},{68,-172}}))); - Modelica.Blocks.Interfaces.RealOutput coolerhexele4masT - "Value of Real output" - annotation (Placement(transformation(extent={{48,-202},{68,-182}}))); - Modelica.Blocks.Sources.RealExpression realExpression4[4](y=heater.hex.ele[:].mas.T) + Modelica.Blocks.Sources.RealExpression heaterInitials[4](y=heater.hex.ele[:].mas.T) annotation (Placement(transformation(extent={{96,-186},{116,-166}}))); - Modelica.Blocks.Interfaces.RealOutput heaterhexele1masT - "Value of Real output" - annotation (Placement(transformation(extent={{136,-170},{156,-150}}))); - Modelica.Blocks.Interfaces.RealOutput heaterhexele2masT - "Value of Real output" - annotation (Placement(transformation(extent={{136,-180},{156,-160}}))); - Modelica.Blocks.Interfaces.RealOutput heaterhexele3masT - "Value of Real output" - annotation (Placement(transformation(extent={{136,-190},{156,-170}}))); - Modelica.Blocks.Interfaces.RealOutput heaterhexele4masT - "Value of Real output" - annotation (Placement(transformation(extent={{136,-200},{156,-180}}))); AixLib.Fluid.Sensors.RelativeHumidity outdoorHumidityMeas(redeclare package Medium = MediumAir) "Relative humidity outside" annotation (Placement(transformation(extent={{-254,-16},{-274,4}}))); @@ -288,98 +135,11 @@ equation annotation (Line(points={{295,30},{310,30}}, color={0,0,127})); connect(heaterTemperature.T, heaterTemperatureC.Kelvin) annotation (Line(points={{161,32},{170,32}}, color={0,0,127})); - connect(outgoingAirOutletHumidity.phi, outgoingAirOutletHumidityOutput) - annotation (Line(points={{-235,58},{-230,58},{-230,202}}, color={0,0,127})); - connect(outgoingAirOutletTemperatureC.Celsius, - outgoingAirOutletTemperatureCOutput) annotation (Line(points={{-175,50},{ - -152,50},{-152,122},{-210,122},{-210,202}}, color={0,0,127})); - connect(outdoorTemperature.y, outdoorTemperatureOutput) annotation (Line( - points={{-362.6,120},{-360,120},{-360,198}}, color={0,0,127})); - connect(hRCHumidity.phi, hRCHumidityOutput) annotation (Line(points={{-105,34}, - {-106,34},{-106,118}}, color={0,0,127})); - connect(hRCTemperatureC.Celsius, hRCTemperatureCOutput) annotation (Line( - points={{-49,30},{-38,30},{-38,98},{-90,98},{-90,118}}, color={0,0,127})); - connect(preHeaterHumidity.phi, preHeaterHumidityOutput) - annotation (Line(points={{-17,30},{-2,30},{-2,76}}, color={0,0,127})); - connect(coolerHumidity.phi, coolerHumidityOutput) - annotation (Line(points={{59,34},{58,34},{58,82}}, color={0,0,127})); - connect(coolerTemperatureC.Celsius, coolerTemperatureCOutput) annotation ( - Line(points={{109,32},{114,32},{114,52},{72,52},{72,82}}, color={0,0,127})); - connect(heaterHumidity.phi, heaterHumidityOutput) - annotation (Line(points={{139,34},{144,34},{144,74}}, color={0,0,127})); - connect(preHeaterTemperatureC.Celsius, preHeaterTemperatureCOutput) - annotation (Line(points={{35,30},{38,30},{38,52},{12,52},{12,76}}, color={0, - 0,127})); - connect(heaterTemperatureC.Celsius, heaterTemperatureCOutput) annotation ( - Line(points={{193,32},{198,32},{198,54},{160,54},{160,74}}, color={0,0, - 127})); - connect(supplyHumidity.phi, supplyHumidityOutput) - annotation (Line(points={{271,30},{276,30},{276,76}}, color={0,0,127})); - connect(supplyAirTemperatureC.Celsius, supplyAirTemperatureCOutput) - annotation (Line(points={{333,30},{348,30},{348,54},{294,54},{294,76}}, - color={0,0,127})); - connect(roomTemperature.y, roomTemperatureOutput) annotation (Line(points={{ - 140.7,132},{132,132},{132,150},{212,150},{212,178}}, color={0,0,127})); - connect(roomHumidity.y, roomHumidityOutput) annotation (Line(points={{140.7, - 183},{126,183},{126,156},{190,156},{190,176}}, color={0,0,127})); - connect(cooler.returnTemperature, coolerReturnTemperatureOutput) annotation ( - Line(points={{43.5714,-5.10769},{78,-5.10769},{78,-62}}, - color={0,0,127})); - connect(preHeater.returnTemperature, preHeaterReturnTemperatureOutput) - annotation (Line(points={{-36.4286,6.10769},{-12,6.10769},{-12,-66}}, - color={0,0,127})); - connect(heater.returnTemperature, heaterReturnTemperatureOutput) annotation ( - Line(points={{123.571,-0.505882},{142,-0.505882},{142,-68}}, - color={0,0,127})); - connect(realExpression[1].y, inOutletsOutgoingHexele1masT) annotation (Line( - points={{-179,-132},{-168,-132},{-168,-116},{-150,-116}}, color={0,0, - 127})); - connect(realExpression[2].y, inOutletsOutgoingHexele2masT) annotation (Line( - points={{-179,-132},{-168,-132},{-168,-126},{-150,-126}}, color={0,0, - 127})); - connect(realExpression[3].y, inOutletsOutgoingHexele3masT) annotation (Line( - points={{-179,-132},{-170,-132},{-170,-136},{-150,-136}}, color={0,0, - 127})); - connect(realExpression[4].y, inOutletsOutgoingHexele4masT) annotation (Line( - points={{-179,-132},{-168,-132},{-168,-146},{-150,-146}}, color={0,0, - 127})); - connect(realExpression2[1].y, preHeaterhexele1masT) annotation (Line(points={ - {-57,-176},{-46,-176},{-46,-160},{-28,-160}}, color={0,0,127})); - connect(realExpression2[2].y, preHeaterhexele2masT) annotation (Line(points={ - {-57,-176},{-46,-176},{-46,-170},{-28,-170}}, color={0,0,127})); - connect(realExpression2[3].y, preHeaterhexele3masT) annotation (Line(points={ - {-57,-176},{-48,-176},{-48,-180},{-28,-180}}, color={0,0,127})); - connect(realExpression2[4].y, preHeaterhexele4masT) annotation (Line(points={ - {-57,-176},{-46,-176},{-46,-190},{-28,-190}}, color={0,0,127})); - connect(realExpression3[1].y, coolerhexele1masT) annotation (Line(points={{29, - -178},{40,-178},{40,-162},{58,-162}}, color={0,0,127})); - connect(realExpression3[2].y, coolerhexele2masT) annotation (Line(points={{29, - -178},{40,-178},{40,-172},{58,-172}}, color={0,0,127})); - connect(realExpression3[3].y, coolerhexele3masT) annotation (Line(points={{29, - -178},{38,-178},{38,-182},{58,-182}}, color={0,0,127})); - connect(realExpression3[4].y, coolerhexele4masT) annotation (Line(points={{29, - -178},{40,-178},{40,-192},{58,-192}}, color={0,0,127})); - connect(realExpression4[1].y, heaterhexele1masT) annotation (Line(points={{ - 117,-176},{128,-176},{128,-160},{146,-160}}, color={0,0,127})); - connect(realExpression4[2].y, heaterhexele2masT) annotation (Line(points={{ - 117,-176},{128,-176},{128,-170},{146,-170}}, color={0,0,127})); - connect(realExpression4[3].y, heaterhexele3masT) annotation (Line(points={{ - 117,-176},{126,-176},{126,-180},{146,-180}}, color={0,0,127})); - connect(realExpression4[4].y, heaterhexele4masT) annotation (Line(points={{ - 117,-176},{128,-176},{128,-190},{146,-190}}, color={0,0,127})); - connect(preHeater.waterInflowTemperature, highTemperatureCircuitOutput) - annotation (Line(points={{-44.2857,11.9231},{-36,11.9231},{-36,116},{-54, - 116},{-54,154}}, color={0,0,127})); - connect(cooler.waterInflowTemperature, coolingCircuitOutput) annotation (Line( - points={{35.7143,-10.9231},{56,-10.9231},{56,68},{32,68},{32,142}}, - color={0,0,127})); connect(outdoorHumidity.y, toTotAir.XiDry) annotation (Line(points={{-362.6, 76},{-350,76},{-350,-6},{-374,-6},{-374,-44},{-363,-44}}, color={0,0, 127})); connect(outdoorHumidityMeas.port, freshAirSource.ports[2]) annotation (Line( points={{-264,-16},{-264,-40},{-282,-40}}, color={0,127,255})); - connect(outdoorHumidityMeas.phi, outdoorHumidityOutput) annotation (Line( - points={{-275,-6},{-346,-6},{-346,198}}, color={0,0,127})); connect(outgoingAirOutletTemperature.port, inOutlets.portExhaustAirOut) annotation (Line(points={{-214,40},{-214,36},{-180.812,36},{-180.812, 29.5765}}, color={0,127,255})); diff --git a/pyDMPC/Utilities/mlp_train_modelica.py b/pyDMPC/Utilities/mlp_train_modelica.py index 8e640c2..bf377bf 100644 --- a/pyDMPC/Utilities/mlp_train_modelica.py +++ b/pyDMPC/Utilities/mlp_train_modelica.py @@ -8,7 +8,7 @@ def main(): - module = "heater" + module = "cooler" path = "D:\dymola" command = [] # The manipulated variable in the model T_cur = [] # The current inflow temperature @@ -45,7 +45,7 @@ def main(): if t < 100: command.append(0) elif t%120 == 0: - command.append(random.uniform(0.0,100.0)) + command.append(random.uniform(0.0,10.0)) else: command.append(command[-1])