| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- import time
- import pandas as pd
- from ..model._base._base_device import BaseDevice
- 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 optimizer(
- model : BaseDevice,
- opt_var_boundary: dict,
- opt_var_value : pd.DataFrame,
- oth_var_value : pd.DataFrame,
- constrains : list
- ):
- var_name_opt = []
- boundary_info = {}
- for var_name,var_info in opt_var_boundary.items():
- var_name_opt.append(var_name)
- boundary_info[var_name] = main_bound(
- None,None,None,
- opt_var_value.iloc[[0],:].loc[:,[var_name]],
- config = sim_config_bound(
- opt_var = [var_name],
- syn_opt = False,
- var_type = True,
- lb_static = var_info['lb'],
- ub_static = var_info['ub'],
- var_precis = var_info.get('precis',1)
- )
- )
- var_name_oth = []
- oth_var_info = {}
- for var_name in oth_var_value.columns:
- var_name_oth.append(var_name)
- oth_var_info[var_name] = oth_var_value.iloc[[0],:].loc[:,[var_name]]
- opt_config = sim_opt_config(
- target = 'Fs',
- dir_min = True,
- var_opt = var_name_opt,
- var_sys = var_name_oth,
- diag_model = False,
- algorithm = 'soea_DE_best_1_L_templet',
- NIND = 1000,
- MAXGEN = 200,
- constrains = constrains,
- allow_neg_opt = False,
- )
-
- opt_output = main_opt(
- *list(boundary_info.values()),
- *list(oth_var_info.values()),
- system_model = AirSystem(model=model),
- config = opt_config
- )
- return opt_output
- class AirSystem(SystemModel):
- def __init__(self,model):
- super().__init__()
- self.model = model
-
- 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
|