-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfinal_step5_multi_scenario_optimization.py
36 lines (25 loc) · 1.26 KB
/
final_step5_multi_scenario_optimization.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#Optimize for the worst case scenario
'''
After having identified the worst case scenarios (those with the maximum death outcomes) we are going to optimize for them.
'''
if __name__ == '__main__':
# read the worst-case scenarios
selected = pd.read_csv("intermediate outputs/step4 - prim results - worst case scenarios.csv")
scenarios = [Scenario(f"{index}", **row) for index, row in selected.iterrows()]
# create the model
dike_model, planning_steps = get_model_for_problem_formulation(6)
ema_logging.log_to_stderr(ema_logging.INFO)
# run the optimization code
def optimize(scenario, nfe, model, epsilons):
with MultiprocessingEvaluator(model) as evaluator:
results = evaluator.optimize(nfe=nfe, searchover='levers',
epsilons=epsilons,
reference=scenario)
return results
#save the results
results = []
for scenario in scenarios:
epsilons = [0.1, ] * len(dike_model.outcomes)
res = optimize(scenario, 100000, dike_model, epsilons)
res.to_csv("intermediate outputs/step5 - multi scenario optimization results/step5 - " + str(scenario.name) + " optimization results.csv")
results.append(res)