-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrun_optimization.py
More file actions
148 lines (121 loc) · 5.95 KB
/
run_optimization.py
File metadata and controls
148 lines (121 loc) · 5.95 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
'''
The actual optimization function and script to run one iteration
'''
from config import config
from cost_dict import *
from data_loader import process_data_pipeline
from siting_model import run_datacenter_optimization
from results_visualization import visualize_optimization_results
from components.storage import *
from components.plant import *
def main():
# Define the file paths
file_paths = {
'state_shapefile': '/Users/maria/Documents/Research/deloitte-proj/deloitte-data/cb_2022_us_state_20m/cb_2022_us_state_20m.shp',
'county_csv': 'CountyMaps/county_data.csv',
'supply_data': '/Users/maria/Documents/Research/deloitte-proj/telecom-data/supply_data_lat_lon_water_clim.csv',
'merged_cf': '/Users/maria/Documents/Research/deloitte-proj/deloitte-data/merged_hourly_solar_wind_cf.csv',
'demand_data': 'fake_demand.csv',
'county2zone': 'CountyMaps/county2zone.csv',
'hierarchy': 'CountyMaps/hierarchy.csv',
'electric_prices': '/Users/maria/Documents/Research/deloitte-proj/deloitte-data/electric_prices.csv',
'water_risk': '/Users/maria/Documents/Research/deloitte-proj/deloitte-data/water_risk.gpkg',
'county_shapefile': '/Users/maria/Documents/Research/deloitte-proj/deloitte-data/cb_2018_us_county_5m/cb_2018_us_county_5m.shp'
}
# Process the data
print("\nStep 1: Processing energy data...")
processor, model_dictionaries = process_data_pipeline(
file_paths=file_paths,
pue_climate_dict=pue_climate_region_5,
wue_climate_dict=wue_climate_region_5,
trans_mult_dict=trans_mult_dict,
telecom_cost_dict=telecom_cost,
min_capacity=200, # Minimum total renewable capacity (MW)
state_filter=None, # Set to specific state if desired (e.g., 'TX' for Texas)
max_water_risk=5.0 # Maximum acceptable water risk
)
# Apply load multiplier to energy and water loads
if config['load_multiplier'] != 1.0:
print(f"Applying load multiplier: {config['load_multiplier']}")
# Multiply energy load
if 'energy_load' in model_dictionaries:
model_dictionaries['energy_load'] = {
(h, loc): value * config['load_multiplier']
for (h, loc), value in model_dictionaries['energy_load'].items()
}
# Multiply water load
if 'water_load' in model_dictionaries:
model_dictionaries['water_load'] = {
(h, loc): value * config['load_multiplier']
for (h, loc), value in model_dictionaries['water_load'].items()
}
# Run the Optimization
print("\nStep 2: Running optimization model...")
try:
opt_model, solution = run_datacenter_optimization(
model_dictionaries=model_dictionaries,
config=config,
cost_params=cost_params,
trans_rating = trans_rating,
trans_cost = trans_cost,
solver_name='gurobi',
processor=processor,
storage_system = StorageTemplates.create_lithium_ion("lithium-battery"),
plant_systems = {'smr': PlantTemplates.create_smr_plant("my_smr", 1000),
# 'gas': PlantTemplates.create_gas_turbine("my_gas_turbine", 1000)}
}
# You can add solver options here:
# MIPGap=0.01, # 1% optimality gap
# TimeLimit=3600 # 1 hour time limit
)
# 8. ANALYZE RESULTS
print("\nStep 3: Analyzing results...")
analyze_results(solution, model_dictionaries, opt_model)
except Exception as e:
print(f"Error during optimization: {e}")
print("Trying with different solver or check your data...")
print("\n📈 STEP 3: CREATING VISUALIZATIONS")
print("-" * 40)
try:
viz_results = visualize_optimization_results(
model=opt_model.model,
cost_params=cost_params,
supply_data=processor.processed_data['supply_data'],
output_dir="optimization_output",
county_shapefile_path=file_paths['county_shapefile']
)
max_load = max(model_dictionaries['energy_load'].values())
print(f" Data Center Max Load: {max_load:.1f} MW")
print(f"✅ Visualizations complete!")
print(f" Generated plots and analysis in 'optimization_output/' directory")
# Print detailed summary
#print_detailed_summary(viz_results, solution)
except Exception as e:
print(f"❌ Error in visualization: {e}")
print("Optimization completed successfully, but visualization failed")
def analyze_results(solution, model_dictionaries, opt_model):
"""Analyze and print detailed results."""
if not solution['selected_locations']:
print("No feasible solution found!")
return
#selected_loc = solution['selected_locations'][0] # Assuming single location
selected_locs = solution['selected_locations']
print(f"\nDETAILED ANALYSIS FOR LOCATION {selected_locs}")
print("-" * 50)
# Location characteristics
if 'location_coordinates' in model_dictionaries:
coords = model_dictionaries['location_coordinates'].get(selected_locs, (None, None))
print(f"Coordinates: {coords[0]:.4f}, {coords[1]:.4f}")
# Renewable capacity at location
solar_cap = model_dictionaries['solar_capacity'].get(selected_locs, 0)
wind_cap = model_dictionaries['wind_capacity'].get(selected_locs, 0)
geo_cap = model_dictionaries.get('geo_capacity', {}).get(selected_locs, 0)
max_load = max(model_dictionaries['energy_load'].values())
print(f"Available Capacity:")
print(f" Solar: {solar_cap:.1f} MW")
print(f" Wind: {wind_cap:.1f} MW")
print(f" Geothermal: {geo_cap:.1f} MW")
print(f" Total: {solar_cap + wind_cap + geo_cap:.1f} MW")
print(f" Data Center Max Load: {max_load:.1f} MW")
if __name__ == "__main__":
main()