temp_height, temp_gate).reshape( 1, len(temp_height) + len(temp_gate)) # Action q_values = prof_x.ac_model.predict_on_batch(input_states) # Policy action = epsi_greedy(len(action_space), q_values, epsilon_value[episode_tracker]) # Implement Action gates.update_gates(action_space[action]) implement_action(gates.current_gate, con_ponds, NODES_LIS) # Run step swmm.run_step() # Receive the reward overflow = [swmm.get(pond_name, swmm.FLOODING, swmm.SI) for pond_name in downstream_ponds] depth = [swmm.get(pond_name, swmm.DEPTH, swmm.SI) for pond_name in downstream_ponds] outflow = [swmm.get(NODES_LIS[pond_name], swmm.FLOW, swmm.SI) for pond_name in downstream_ponds] reward = reward_function(outflow, depth, overflow) reward_sim.append(reward) # Update replay memory # Heights temp_new_height = np.asarray( [swmm.get(i, swmm.DEPTH, swmm.SI) for i in nodes_list]) # Gate Positions temp_new_gate = np.asarray(gates.current_gate)
# Initializing SWMM # *********************************************************************** swmm.initialize(inp) # Step 1 # *********************************************************************** # Step Running # *********************************************************************** # Main loop: finished when the simulation time is over. while( not swmm.is_over() ): # ----------------- Run step and retrieve simulation time ----------- time.append( swmm.get_time() ) swmm.run_step() # Step 2 # --------- Retrieve & modify information during simulation --------- # Retrieve information about flow in C-5 f = swmm.get('C-5', swmm.FLOW, swmm.SI) # Stores the information in the flow vector flow.append(f) # Retrieve information about volume in V-1 v = swmm.get('V-1', swmm.VOLUME, swmm.SI) # Stores the information in the volume vector vol.append(v) # --------------------------- Control Actions ------------------------ # If the flow in C-5 is greater or equal than 2 m3/s the setting # upstream of the link is completely closed, else it is completely