| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- import time
- from pprint import pprint
- import numpy as np
- import pandas as pd
- from .model.DHU_2 import DHU_2
- from ._opt.algorithm.sim_config import simulate_config as sim_opt_config
- from ._opt.algorithm.main import main as main_opt
- from ._opt.boundary.sim_config import simulate_config as sim_config_bound
- from ._opt.boundary.main import main as main_bound
- from ._opt.algorithm.model.model import SystemModel
- def main(*args,config=None):
-
- args = [_.reset_index(drop=True) for _ in args]
-
- var_cur = {
- 'coil_1_ToutA': args[0],
- 'coil_1_HoutA': args[1],
- 'HzP' : args[2],
- 'HzR' : args[3],
- 'coil_1_TinW' : args[4],
- 'coil_2_TinW' : args[5],
- 'coil_3_TinW' : args[6],
- 'coil_1_Val' : args[7],
- 'coil_2_Val' : args[8],
- 'coil_3_Val' : args[9],
- 'wheel_1_TinR': args[10],
- 'wheel_2_TinR': args[11],
- 'mixed_1_TinM': args[12],
- 'mixed_1_HinM': args[13],
- 'mixed_2_TinM': args[14],
- 'mixed_2_HinM': args[15],
- }
- var_cur = {k:v.set_axis([k],axis=1) for k,v in var_cur.items()}
- var_opt_name = ['coil_2_Val','wheel_1_TinR','wheel_2_TinR']
- var_sys_name = [_ for _ in var_cur.keys() if _ not in var_opt_name]
- var_opt_cur = {k:v for k,v in var_cur.items() if k in var_opt_name}
- var_sys_cur = {k:v for k,v in var_cur.items() if k in var_sys_name}
- var_opt_var = {
- 'coil_2_Val': main_bound(
- None,None,None,
- var_opt_cur['coil_2_Val'],
- config = sim_config_bound(
- opt_var = ['coil_2_Val'],
- syn_opt = False,
- var_type = True,
- lb_static = 100,
- ub_static = 100,
- var_precis = 1
- )
- ),
- 'wheel_1_TinR': main_bound(
- None,None,None,
- var_opt_cur['wheel_1_TinR'],
- config = sim_config_bound(
- opt_var = ['wheel_1_TinR'],
- syn_opt = False,
- var_type = True,
- lb_static = 50,
- ub_static = 120,
- var_precis = 1
- )
- ),
- 'wheel_2_TinR': main_bound(
- None,None,None,
- var_opt_cur['wheel_2_TinR'],
- config = sim_config_bound(
- opt_var = ['wheel_2_TinR'],
- syn_opt = False,
- var_type = True,
- lb_static = 50,
- ub_static = 120,
- var_precis = 1
- )
- ),
- }
-
- # 获取优化结果
- opt_config = sim_opt_config(
- target = 'Fs',
- dir_min = True,
- var_opt = var_opt_name,
- var_sys = var_sys_name,
- diag_model = False,
- algorithm = 'soea_DE_best_1_L_templet',
- NIND = 5000,
- MAXGEN = 200,
- constrains = [
- 'coil_3_DoutA-[coil_3_DoutA]<0',
- # 'steamcoil_1_Fs-220<0',
- # 'steamcoil_2_Fs-100<0',
- # '40-steamcoil_1_Fs<0',
- # '30-steamcoil_2_Fs<0',
- ],
- allow_neg_opt = False,
- )
-
- system = AirSystem()
- opt_output = main_opt(
- *list(var_opt_var.values()),
- *list(var_sys_cur.values()),
- system_model = system,
- config = opt_config
- )
- sys_output = system.predict(
- pd.concat([*opt_output[3:],*list(var_sys_cur.values())],axis=1),
- )
-
- show_data = None
- # show_data = get_show_data(opt_res=opt_output[2])
- # print(show_data)
-
- return [
- sys_output.loc[:,['coil_2_ToutA']],
- opt_output[3:][1],
- opt_output[3:][2],
- show_data
- ]
- class AirSystem(SystemModel):
- def __init__(self):
- super().__init__()
- # self.model = DHU_2().load_from_platform()
- path = r'C:\Users\zhangshenhao\Documents\WorkSpace\zsh_project\004_溧阳宁德\除湿机模型\model.pkl'
- self.model = DHU_2().load(path)
-
- def predict(self,data:pd.DataFrame) -> pd.DataFrame:
- time_start = time.time()
- self.PENALTY = {}
- self.index = data.index
- sys_out = self.model.predict_system(data)
- time_end = time.time()
- past_time = round(time_end-time_start,2)
- self.PAST_TIME.append(past_time)
- print(f'第{len(self.PAST_TIME)}次调用系统模型,本次调用时长为:{past_time}秒 \n')
- return sys_out
- def get_show_data(opt_res:pd.DataFrame) -> pd.DataFrame:
- var_names = {
- 'coil_3_DoutA' : '送风露点(℃)',
- 'coil_2_Q' : '中表冷冷量(kW)',
- 'coil_3_Q' : '后表冷冷量(kW)',
- 'steamcoil_1_Q' : '前再生热量(kW)',
- 'steamcoil_2_Q' : '后再生热量(kW)',
- 'wheel_1_E_diff' : '前转轮焓升(kJ/kg)',
- 'wheel_2_E_diff' : '后转轮焓升(kJ/kg)',
- 'summary_cost_cooling': '耗冷费用折算(元/h)',
- 'summary_cost_heating': '耗热费用折算(元/h)',
- 'summary_cost_total' : '冷热费用合计(元/h)',
- }
- res = (
- opt_res
- .loc[list(var_names.keys()),['Before','After']]
- .assign(指标=list(var_names.values()))
- .rename(columns={'Before':'优化前状态','After':'优化后状态'})
- .loc[:,['指标','优化前状态','优化后状态']]
- )
- return res
|