Skip to content

Commit b3e3b1f

Browse files
committed
updating optimizations for benchmark controllers
1 parent dc43f6a commit b3e3b1f

179 files changed

Lines changed: 467160 additions & 288646 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/alpha/evaluate_baseline_controllers.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
# ALPHA
2323
# options are: 'equal-filling' and 'constant-flow' (or 'uncontrolled')
24-
evaluating = 'equal-filling'
24+
evaluating = 'uncontrolled'
2525
verbose = True
2626
version = "2" # options are "1" and "2"
2727
level = "1" # options are "1" , "2", and "3"
@@ -52,8 +52,10 @@
5252

5353

5454
for parameter in tuning_values:
55-
if evaluating == "constant-flow" or evaluating == "uncontrolled":
55+
if evaluating == "constant-flow":
5656
optimal_constant_flows = np.loadtxt(str("./v" + version + "/optimal_constant_flows.txt"))
57+
elif evaluating == "uncontrolled":
58+
optimal_constant_flows = np.array([1.0,1.0,1.0,1.0,1.0,0.15,0.6,0.5,0.5,0.65])
5759
elif evaluating == "equal-filling":
5860
optimal_constant_flows = np.loadtxt(str("./v" + version + "/optimal_efd.txt"))[:-1]
5961
optimal_efd_params = np.loadtxt(str("./v" + version + "/optimal_efd.txt"))[-1]
@@ -140,7 +142,12 @@
140142
regulator_idx = [i for i in range(len(env.config['states'])) if regulator_id in env.config['states'][i]][0]
141143

142144
# assume linear scaling with opening percentage
143-
u_open_pct[idx] = Q_desired / (Cd * Ao * np.sqrt(2*g*state[regulator_idx]))
145+
if state[regulator_idx] > 0:
146+
u_open_pct[idx] = Q_desired / (Cd * Ao * np.sqrt(2*g*state[regulator_idx]))
147+
else:
148+
u_open_pct[idx] = 1.0
149+
if np.isnan(u_open_pct[idx]):
150+
print("nan value for u_open_pct")
144151
if u_open_pct[idx] > 1.0:
145152
u_open_pct[idx] = 1.0
146153
elif u_open_pct[idx] < 0.0:

baseline_controllers/alpha/optimize_parameters.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def f_efd(efd_parameters):
225225
CSO_penalty = 0
226226
for weir in CSO_flows.keys():
227227
CSO_penalty += sum(CSO_flows[weir])**2
228-
'''
228+
229229
flooding_penalty = 0
230230
for junction in flooding.keys():
231231
flooding_penalty += sum(flooding[junction])*100
@@ -243,7 +243,7 @@ def f_efd(efd_parameters):
243243
return_value = CSO_penalty + flooding_penalty - peak_filling_reward + sum(data["final_depths"]) + np.std(data['final_depths'])
244244
245245
return return_value
246-
'''
246+
247247
flooding_penalty = 0
248248
for junction in flooding.keys():
249249
#flooding_penalty += sum(flooding[junction])*100
@@ -282,7 +282,7 @@ def objective(input_data):
282282
flow_cost = 0.0
283283
for key,value in data['data_log']['flow'].items():
284284
flow_cost += sum(value)
285-
objective_cost = flow_cost + sum(data['final_depths']) + np.std(data['final_depths'])
285+
objective_cost = flow_cost #+ sum(data['final_depths']) + np.std(data['final_depths'])
286286
flood_cost = 0.0
287287
for key, value in data['data_log']['flooding'].items():
288288
flood_cost += sum(value)
@@ -311,7 +311,7 @@ def constraint(input_data):
311311
flow_cost = 0.0
312312
for key,value in data['data_log']['flow'].items():
313313
flow_cost += sum(value)
314-
objective_cost = flow_cost + sum(data['final_depths']) + np.std(data['final_depths'])
314+
objective_cost = flow_cost #+ sum(data['final_depths']) + np.std(data['final_depths'])
315315
flood_cost = 0.0
316316
for key, value in data['data_log']['flooding'].items():
317317
flood_cost += sum(value)
@@ -355,7 +355,7 @@ def objective(input_data):
355355
flow_cost = 0.0
356356
for key,value in data['data_log']['flow'].items():
357357
flow_cost += sum(value)
358-
objective_cost = flow_cost + sum(data['final_depths']) + np.std(data['final_depths'])
358+
objective_cost = flow_cost #+ sum(data['final_depths']) + np.std(data['final_depths'])
359359
flood_cost = 0.0
360360
for key, value in data['data_log']['flooding'].items():
361361
flood_cost += sum(value)
@@ -385,7 +385,7 @@ def constraint(input_data):
385385
flow_cost = 0.0
386386
for key,value in data['data_log']['flow'].items():
387387
flow_cost += sum(value)
388-
objective_cost = flow_cost + sum(data['final_depths']) + np.std(data['final_depths'])
388+
objective_cost = flow_cost #+ sum(data['final_depths']) + np.std(data['final_depths'])
389389
flood_cost = 0.0
390390
for key, value in data['data_log']['flooding'].items():
391391
flood_cost += sum(value)
@@ -421,10 +421,10 @@ def create_bo_model(data):
421421
for i in range(10):
422422
if i < 5: # orifices, set constant flow rate
423423
lower_bounds.append(0.5)
424-
upper_bounds.append(10.0)
424+
upper_bounds.append(8.0)
425425
else: # regulators, set constant opening percentage
426426
lower_bounds.append(0.0)
427-
upper_bounds.append(1.0)
427+
upper_bounds.append(0.62)
428428

429429
search_space = Box(lower_bounds, upper_bounds)
430430

@@ -485,14 +485,14 @@ def create_bo_model(data):
485485
upper_bounds.append(10.0)
486486
else: # regulators, set constant opening percentage
487487
lower_bounds.append(0.0)
488-
upper_bounds.append(1.0)
488+
upper_bounds.append(0.65)
489489
# efd gain bounds
490490
lower_bounds.append(0.0)
491491
upper_bounds.append(2.0)
492492

493493
search_space = Box(lower_bounds, upper_bounds)
494494

495-
num_initial_points = 20
495+
num_initial_points = 120
496496
initial_data = observer_efd(search_space.sample(num_initial_points))
497497

498498
initial_models = trieste.utils.map_values(create_bo_model, initial_data)
@@ -503,7 +503,7 @@ def create_bo_model(data):
503503
)
504504
rule = EfficientGlobalOptimization(eci) # type: ignore
505505

506-
num_steps = 20
506+
num_steps = 450
507507
bo = trieste.bayesian_optimizer.BayesianOptimizer(observer_efd, search_space)
508508

509509
opt_result = bo.optimize(
@@ -545,10 +545,10 @@ def create_bo_model(data):
545545
for i in range(10):
546546
if i < 5: # orifices, set constant flow rate
547547
lower_bounds.append(0.5)
548-
upper_bounds.append(10.0)
548+
upper_bounds.append(12.0)
549549
else: # regulators, set constant opening percentage
550550
lower_bounds.append(0.0)
551-
upper_bounds.append(1.0)
551+
upper_bounds.append(0.6)
552552

553553
search_space = Box(lower_bounds, upper_bounds)
554554

@@ -563,7 +563,7 @@ def create_bo_model(data):
563563
)
564564
rule = EfficientGlobalOptimization(eci) # type: ignore
565565

566-
num_steps = 1000
566+
num_steps = 500
567567
bo = trieste.bayesian_optimizer.BayesianOptimizer(observer_cf, search_space)
568568

569569
opt_result = bo.optimize(
@@ -604,17 +604,17 @@ def create_bo_model(data):
604604
for i in range(10):
605605
if i < 5: # orifices, set constant flow rate
606606
lower_bounds.append(0.5)
607-
upper_bounds.append(10.0)
607+
upper_bounds.append(12.0)
608608
else: # regulators, set constant opening percentage
609609
lower_bounds.append(0.0)
610-
upper_bounds.append(1.0)
610+
upper_bounds.append(0.6)
611611
# efd gain bounds
612612
lower_bounds.append(0.0)
613613
upper_bounds.append(2.0)
614614

615615
search_space = Box(lower_bounds, upper_bounds)
616616

617-
num_initial_points = 110
617+
num_initial_points = 150
618618
initial_data = observer_efd(search_space.sample(num_initial_points))
619619

620620
initial_models = trieste.utils.map_values(create_bo_model, initial_data)
@@ -625,7 +625,7 @@ def create_bo_model(data):
625625
)
626626
rule = EfficientGlobalOptimization(eci) # type: ignore
627627

628-
num_steps = 1200
628+
num_steps = 500
629629
bo = trieste.bayesian_optimizer.BayesianOptimizer(observer_efd, search_space)
630630

631631
opt_result = bo.optimize(
556 Bytes
Loading

0 commit comments

Comments
 (0)