Skip to content

Commit 9376470

Browse files
committed
final delta controllers
1 parent 92ee64d commit 9376470

54 files changed

Lines changed: 143265 additions & 134463 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

baseline_controllers/delta/compare_levels.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
# DELTA SCENARIO
1515
version = "2"
16-
control = "static-plus-rule" # "static-plus-rule" or "prop-outflow"
16+
control = "prop-outflow" # "static-plus-rule" or "prop-outflow"
1717
# set the working directory to the directory of this script
1818
os.chdir(os.path.dirname(os.path.abspath(__file__)))
1919
print(os.getcwd())

baseline_controllers/delta/compare_timeseries.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
# DELTA SCENARIO
1515
version = "2"
16-
level = "1"
16+
level = "3"
1717
# set the working directory to the directory of this script
1818
os.chdir(os.path.dirname(os.path.abspath(__file__)))
1919
print(os.getcwd())

baseline_controllers/delta/evaluate_baseline_controllers.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
# options are: 'static-plus-rule' and 'prop-outflow' (or 'uncontrolled')
2525
# static plus rule is fixed positions for the 4 weirs plus a height to open the infiltration valve at
2626
# prop outflow adds proportional feedback to weir openings to increase outflows when far below the threshold
27-
evaluating = 'static-plus-rule'
27+
evaluating = 'prop-outflow'
2828
verbose = True
2929
version = "2" # options are "1" and "2"
30-
level = "1" # options are "1" , "2", and "3"
30+
level = "3" # options are "1" , "2", and "3"
3131
#hysteresis = 0.05 # hysteresis for the infiltration valve to avoid rapid cycling between open and closed
3232
plot = True # plot True significantly increases the memory usage.
3333
# set the working directory to the directory of this script
@@ -98,12 +98,18 @@
9898

9999
states = pd.DataFrame(columns = env.config['states'])
100100
actions = pd.DataFrame(columns = env.config['action_space'])
101+
state = env.state(level=level) # get the initial state of the environment
102+
old_state = state.copy()
103+
old_old_state = old_state.copy()
101104

102105
while not done:
103106
# take control actions?
104107
if env.env.sim.current_time.minute % 5 == 0 and (env.env.sim.current_time > last_eval + datetime.timedelta(minutes=2)):
105108
last_eval = env.env.sim.current_time
106109
state = env.state(level=level)
110+
old_old_state = old_state.copy() # save the old state before updating
111+
old_state = state.copy() # save the current state as the old state for next iteration
112+
state_for_control = (state + old_state + old_old_state) / 3.0 # use the average of the current, previous, and previous previous states for control to smooth out noise in the state space
107113

108114
# first bit is the same for all 3 controllers
109115
# set the weirs
@@ -118,9 +124,9 @@
118124
u_open_pct[-1] = 0.0 # close the valve to preserve capacity in the infiltration basin
119125
'''
120126
# try proprtional valve opening between two setpoint depths
121-
if state[0] < optimal_static_settings[-2]: # below lower threshold
127+
if state_for_control[0] < optimal_static_settings[-2]: # below lower threshold
122128
u_open_pct[-1] = 0.0 # close the valve to preserve capacity in the infiltration basin
123-
elif state[0] > optimal_static_settings[-1]: # above upper threshold
129+
elif state_for_control[0] > optimal_static_settings[-1]: # above upper threshold
124130
u_open_pct[-1] = 1.0 # fully open valve above upper threshold depth in basin c
125131
else: # between the two thresholds
126132
# linearly interpolate the valve opening based on the current depth in basin C
@@ -129,7 +135,7 @@
129135
upper_threshold = optimal_static_settings[-1] # upper threshold depth
130136
range_threshold = upper_threshold - lower_threshold
131137
# calculate the current depth in the range
132-
current_depth_in_range = state[0] - lower_threshold
138+
current_depth_in_range = state_for_control[0] - lower_threshold
133139
# calculate the percentage of the way through the range
134140
percentage_in_range = current_depth_in_range / range_threshold
135141
# set the valve opening based on the percentage in range
@@ -149,10 +155,10 @@
149155
op_bound_width = operational_bounds_df.loc[name,"Upper Limit"] - operational_bounds_df.loc[name, "Lower Limit"]
150156
lower_tight_bound = operational_bounds_df.loc[name, "Lower Limit"] + 0.1 * op_bound_width
151157
upper_tight_bound = operational_bounds_df.loc[name,"Upper Limit"] - 0.25 * op_bound_width
152-
if state[idx_state[0]] < upper_tight_bound and state[idx_state[0]] > lower_tight_bound:
158+
if state_for_control[idx_state[0]] < upper_tight_bound and state_for_control[idx_state[0]] > lower_tight_bound:
153159
# only use proportional feedback on the outflow if we're safe regarding depth bounds
154160
u_open_pct[idx] += optimal_prop * flow_capacity
155-
elif state[idx_state[0]] >= upper_tight_bound and optimal_prop*flow_capacity > 0: # allow extra opening if close to exceeding upper bound
161+
elif state_for_control[idx_state[0]] >= upper_tight_bound and optimal_prop*flow_capacity > 0: # allow extra opening if close to exceeding upper bound
156162
u_open_pct[idx] += optimal_prop * flow_capacity
157163
if u_open_pct[idx] > 1.0:
158164
u_open_pct[idx] = 1.0
-4.42 KB
Loading

0 commit comments

Comments
 (0)