def __init__(self): # action space: Continuous Do setpoints | range-> -1~1 (applicable variation of DO, need to be checked with the other Envs. self.action_space = spaces.Box( np.array([-1.0]), np.array([1.0]), dtype=np.float32) # -1~1 으로 DO setpoint change # state space: Continuous, components | normalized self.observation_space = spaces.Box(low=0.9 * np.ones([14]), high=np.ones([14]), dtype=np.float32) # SBR parameters self.Spar = [0.24, 0.67, 0.08, 0.08, 0.06] # (ref. BSM1 report Tbl. 2) # Ya Yh fp ixb ixp self.Kpar = [ 4.0, 10.0, 0.2, 0.5, 0.3, 0.8, 0.8, 3.0, 0.1, 0.5, 1.0, 0.05, 0.4, 0.05 ] # (ref. BSM1 report Tbl. 3) # muhath Ks Koh Kno bh tag etah kh Kx muhata Knh ba Koa Ka self.DO_control_par = [ 5.0, 0.00035, 0.02 / 24, 2, 0, 240, 12, 2, 5, 0.005, DO_set(15) ] self.biomass_setpoint = 2700 self.Qeff = 0.66 self.x_1 = np.array([ 1.32000000e+00, 3.00000000e+01, 3.81606587e+01, 6.94658685e+02, 1.07772100e+02, 1.22613841e+03, 7.88460027e+01, 2.57616136e+02, 1.01108024e+00, 6.24510635e+00, 1.78877937e+01, 3.95743344e+00, 5.70432163e+00, 5.50185509e+00 ])
def __init__(self): # action space: Continuous Do setpoints | range-> -1~1 (applicable variation of DO, need to be checked with the other Envs. self.action_space = spaces.Box( np.array([-1]), np.array([1]), dtype=np.float32) # -0.05~0.05 으로 DO setpoint change # state space: Continuous, components | normalized self.observation_space = spaces.Box( low=np.array([0, 0, 0, -1, -1]), high=np.ones([5]) * 1.0, # low=np.array([0, 0,0,0,0,0,0]), high=np.ones([7])*1.0, # dtype=np.float32) # 7가지 ASM components를 state로 선정함. # SBR parameters self.Spar = [0.24, 0.67, 0.08, 0.08, 0.06] # (ref. BSM1 report Tbl. 2) # BSM report에 따름 # Ya Yh fp ixb ixp self.Kpar = [ 4.0, 10.0, 0.2, 0.5, 0.3, 0.8, 0.8, 3.0, 0.1, 0.5, 1.0, 0.05, 0.4, 0.05 ] # (ref. BSM1 report Tbl. 3) # BSM report에 따름 # muhath Ks Koh Kno bh tag etah kh Kx muhata Knh ba Koa Ka self.DO_control_par = [ 5.0, 0.00035, 0.02 / 24, 2, 0, 240, 12, 2, 5, 0.005, DO_set(15) ] # DO controller의 control parameter self.biomass_setpoint = 2700 # settling 시 reactor에 남겨지는 biomass 총량 값. => 이 값에 맞도록 Qw를 빼냄. self.Qeff = 0.66 self.u_t_t = np.array(np.zeros([1, 466])) # 먼지잘 모르겠음. """ List of variables : 0: time, 2=Ss, 6=Xbh, 7=Xba, 9=So, 10=Sno, 11=Snh (ref. BSM1 report Tbl. 1) """ self.state_idx = [ 0, 8, 10 ] # 각 변수에 따른 위치값 #self.state_idx = [0, 2, 5, 6, 8, 9, 10] #각 변수에 따른 위치값 # self.x_1 = np.array( [0.5, 8., 30] ) # Normalization을 위한 초기 값.self.x_1 = np.array([0.5, 5, 3000., 200., 8., 30., 30]) # Normalization을 위한 초기 값. self.x_2 = np.zeros([1, len(self.state_idx)]) self.x_2 = np.zeros([1, len(self.state_idx)]) self.t_t = [] # DeepRL code와 결합시켜 plotting하기 위한 변수, time trajectory self.x_t = [] # DeepRL code와 결합시켜 plotting하기 위한 변수, state trajectory self.state_t = []
def __init__(self): # action space: Continuous Do setpoints | range-> -1~1 (applicable variation of DO, need to be checked with the other Envs. self.action_space = spaces.Box( np.array([-0.05]), np.array([0.05]), dtype=np.float32) # -0.05~0.05 으로 DO setpoint change # state space: Continuous, components | normalized self.observation_space = spaces.Box(low=np.array( [0, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9]), high=np.ones([7]) * 1.3, dtype=np.float32) # SBR parameters self.Spar = [0.24, 0.67, 0.08, 0.08, 0.06] # (ref. BSM1 report Tbl. 2) # Ya Yh fp ixb ixp self.Kpar = [ 4.0, 10.0, 0.2, 0.5, 0.3, 0.8, 0.8, 3.0, 0.1, 0.5, 1.0, 0.05, 0.4, 0.05 ] # (ref. BSM1 report Tbl. 3) # muhath Ks Koh Kno bh tag etah kh Kx muhata Knh ba Koa Ka self.DO_control_par = [ 5.0, 0.00035, 0.02 / 24, 2, 0, 240, 12, 2, 5, 0.005, DO_set(15) ] self.biomass_setpoint = 2700 self.Qeff = 0.66 self.u_t_t = np.array(np.zeros([1, 466])) """ List of variables : 0: time, 2=Ss, 6=Xbh, 7=Xba, 9=So, 10=Sno, 11=Snh (ref. BSM1 report Tbl. 1) """ self.state_idx = [0, 1, 5, 6, 8, 9, 10] self.x_1 = np.array([0.5, 30, 2599., 168., 2., 13., 0.005]) self.x_2 = np.zeros([1, len(self.state_idx)])
WV = 1.32 # m^3, Working Volume t_ratio = [ 4.2 / 100, 8.3 / 100, 37.5 / 100, 31.2 / 100, 2.1 / 100, 8.3 / 100, 2.1 / 100, 6.3 / 100 ] t_delta = 0.002 / 24 # phase time t_cycle = 12 / 24 # hour -> day, 12hr t_memory1, t_memory2, t_memory3, t_memory4, t_memory5, t_memory8 = batch_time( t_cycle, t_ratio, t_delta) #Oxygen concentration at saturation : 15deg So_sat = DO_set(15) # DO control prarameters DO_control_par = [5.0, 0.00035, 0.02 / 24, 2, 0, 240, 12, 2, 5, 0.005, So_sat] # Kc, taui, delt, So_set, Kla_min, Kla_max, DKla_max, So_low, So_high, DO saturation dt = DO_control_par[2] #DO control setpoints DO_setpoints = [0, 0, 2, 0, 2, 0, 0, 2] kla0 = 0 class SbrEnv2(gym.Env): """custom Environment that follows gym interface"""
def run_step(self, batch_type, t, u, x_in, influent_mixed): # Batch type assignment # | This part was developed for assigning the batch type during time # | It is not considered as the MVs which the DeepRL operated. # | However, it should be altered as MV for next step. # | 0: Filling phase | 1: Reaction phase | 2: Settling phase & 3: Draw phase & 4: idle phase global So, Kla, kla, dcv, ie, e, t_t, x_t, Qw, eff_component if (t_memory1[0] <= t) & (t < t_memory1[-1]): batch_type = 0 elif (t_memory1[-1] <= t) & (t < t_memory2[-1]): batch_type = 1 elif (t_memory2[-1] <= t) & (t < t_memory3[-1]): batch_type = 1 elif (t_memory3[-1] <= t) & (t < t_memory4[-1]): batch_type = 1 elif (t_memory4[-1] <= t) & (t < t_memory5[-1]): batch_type = 1 else: batch_type = 2 # Simplified, It includes Settling, Draw, and idle phases # Actually it should be divided into each phase. # Initialize if t == 0: # | initialize DO conc. So.append(x_in[8]) # | initialize Kla Kla.append(0) #kla x_t = np.array(x0) # Call: time range # | Controller time interval: t_start ~ t_end(t_start + t_delta) t_start = t # start time to run the SBR system (ODE) t_end = t + t_delta # end time when the SBR running has finished (ODE) # | derivative time interval: ~dt (t_delta/10) t_range = np.linspace(t_start, t_end, (t_end - t_start) / dt) # Call: Simulate the SBR system/each phases have been divided # | 1. Filling phase if batch_type == 0: # Filling phase? x_out, t_range, Kla, So, dcv, ie, e = self.Sim_filling( x_in, t_range, u, influent_mixed, Kla, So, dcv, ie, e) Qw = 0 eff_component = [] # | 2. Reaction phase if batch_type == 1: # reaction phase? x_out, t_range, Kla, So, dcv, ie, e = self.Sim_rxn( x_in, t_range, u, Kla, So, dcv, ie, e) Qw = 0 eff_component = [] # | 3. Settling, drawing phases # | if batch_type == 2: # settling phase? x_out1, t_range1, Qw, PE, SP, EQI, eff_component, So = self.Sim_Settling_Drawing( x_in, t, t_ratio[5], t_ratio[6], t_delta, self.Qeff, self.biomass_setpoint, So) x_in = x_out1[-1] x_out2, t_range2, Kla, So, dcv, ie, e = self.Sim_idle( x_in, t_range1, t_ratio[7], u, Kla, So, dcv, ie, e) x_out = np.vstack([x_out1, x_out2[1:]]) t_range1 = t_range1.tolist() t_range2 = t_range2.tolist() t_range = t_range1 + t_range2[1:] t_range = np.array(t_range) t_end = t_range[-1] """========================================================================================= # | 3. Settling phase if batch_type == 2: # settling phase? self.sim_settling() # | 4. Drawing phase if batch_type == 3: # drawing phase? self.sim_drawing() # | 5. Idle phase if batch_type == 4: # idle phase? x_out = integrate.odeint(self.Idle_dxdt, x, t_range, args=(self.Spar, self.Kpar, self.DO_control_par, Kla[-1],)) =========================================================================================""" # Update: update batch_type, time, and initial value for next step # | 1. batch_type # Simplified # | 2. time t = t_end # | update the temporal trajectories t_instant = t_range.tolist() if t == 0: t_t = t_t + t_instant else: t_t = t_t + t_instant[1:] # change np array to list if t == 0: x_t = np.array(x_out) else: x_t = np.vstack([x_t, x_out[1:]]) # | 3. initial value # It will be updated in the section of STEP reward = sbr_reward(DO_set(15), Kla, batch_type, Qin, Qw, eff_component) return batch_type, t, x_out, reward
1 5 (2.1) No Yes Yes No Rxn (AER) 1 6 (8.3) No No No No STL 2 7 (2.1) No No No Yes DRW 3 8 (6.3) No Yes No No IDL 4 (ref. Pons et al. Tbl. 1) """ DO_control_par = [ 5.0, 0.00035, 0.02 / 24, 2, 0, 240, 12, 2, 5, 0.005, DO_set(15) ] # PID tuning # | PID parameters: optimized parameters, (hand tuning) Kc = 5 tauI = 0.00035 tauD = 0.005 class SbrEnv4(gym.Env): """custom Environment that follows gym interface""" metadata = {'render.modes': ['human']} def __init__(self): # action space: Continuous Do setpoints | range-> -1~1 (applicable variation of DO, need to be checked with the other Envs.