forked from OpenDrift/opendrift
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfind_optimal_locations.py
More file actions
278 lines (237 loc) · 10.7 KB
/
Copy pathfind_optimal_locations.py
File metadata and controls
278 lines (237 loc) · 10.7 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
#!/usr/bin/env python3
"""
Find Optimal Launch Locations for Gaza Delivery
==============================================
This script expands the search beyond your CSV coordinates to find locations
and configurations that achieve higher success rates, accepting 3km variance
from the central target point.
"""
from gaza_reverse_optimizer import GazaReverseOptimizer
from gaza_advanced_backend import ContainerSpecs, RopeSystem, EnvironmentalConditions
import math
def generate_expanded_coordinates(center_lat, center_lon, target_lat, target_lon, tolerance_km=3.0):
"""Generate a comprehensive grid of launch candidates."""
# Calculate direction from target to current search center
lat_diff = center_lat - target_lat
lon_diff = center_lon - target_lon
# Create grid around successful directions with expanded range
coordinates = []
# Grid parameters
lat_step = 0.02 # ~2km steps
lon_step = 0.02
grid_radius = 0.15 # ~15km radius
# Create systematic grid
for lat_offset in [-0.15, -0.1, -0.05, 0, 0.05, 0.1, 0.15]:
for lon_offset in [-0.15, -0.1, -0.05, 0, 0.05, 0.1, 0.15]:
new_lat = center_lat + lat_offset
new_lon = center_lon + lon_offset
# Check if point is reasonable (not on land, reasonable distance)
distance_km = calculate_distance(new_lat, new_lon, target_lat, target_lon)
if 15 <= distance_km <= 50: # Reasonable launch distances
coordinates.append((new_lat, new_lon))
# Add your original CSV coordinates for comparison
csv_coordinates = [
(31.3, 33.95), # offshore_15
(31.3, 34.0), # offshore_16
(31.35, 34.0), # offshore_20
(31.25, 33.95), # offshore_11
(31.25, 34.0), # offshore_12
]
# Combine and deduplicate
all_coordinates = coordinates + csv_coordinates
unique_coordinates = list(set(all_coordinates))
return unique_coordinates
def calculate_distance(lat1, lon1, lat2, lon2):
"""Calculate distance in km between two points."""
R = 6371 # Earth's radius in km
dlat = math.radians(lat2 - lat1)
dlon = math.radians(lon2 - lon1)
a = (math.sin(dlat/2) * math.sin(dlat/2) +
math.cos(math.radians(lat1)) * math.cos(math.radians(lat2)) *
math.sin(dlon/2) * math.sin(dlon/2))
c = 2 * math.atan2(math.sqrt(a), math.sqrt(1-a))
return R * c
def test_container_configurations():
"""Test different container and rope configurations for optimal performance."""
configurations = {
# Lightweight bottles with minimal rope
'light_bottle_short': {
'container': ContainerSpecs(
container_type='bottle',
volume=1.5,
mass=0.8, # Very light
density=533,
drag_coefficient=0.5
),
'rope': RopeSystem(
length=1.0, # Minimal rope
rope_type='nylon',
anchor_weight=0.1,
anchor_type='weight'
)
},
# Standard 2L bottle optimized
'bottle_2L_optimized': {
'container': ContainerSpecs(
container_type='bottle',
volume=2.0,
mass=1.2, # Slightly heavier for stability
density=600,
drag_coefficient=0.6
),
'rope': RopeSystem(
length=3.0, # Medium rope for stability
rope_type='polypropylene',
anchor_weight=0.3,
anchor_type='weight'
)
},
# Heavy bottle for wind resistance
'heavy_bottle_stable': {
'container': ContainerSpecs(
container_type='bottle',
volume=2.5,
mass=2.0, # Heavy for wind resistance
density=800,
drag_coefficient=0.7
),
'rope': RopeSystem(
length=5.0, # Longer rope for current effect
rope_type='nylon',
anchor_weight=0.5,
anchor_type='sandbag'
)
},
# Jerry can optimized
'jerry_optimized': {
'container': ContainerSpecs(
container_type='jerry_can',
volume=3.0, # Smaller jerry can
mass=2.0,
density=667,
drag_coefficient=0.75
),
'rope': RopeSystem(
length=4.0,
rope_type='polypropylene',
anchor_weight=0.4,
anchor_type='weight'
)
}
}
return configurations
def main():
print("🚀 Comprehensive Gaza Delivery Optimization")
print("Finding optimal locations and configurations for higher success rates")
print("=" * 80)
# Target with 3km tolerance as requested
target_lat, target_lon = 31.2794, 34.2542 # Almawasi Central Beach
tolerance_km = 3.0
print(f"🎯 Target: {target_lat:.4f}°N, {target_lon:.4f}°E")
print(f"📏 Accepting deliveries within {tolerance_km}km of target")
print(f"🔍 Expanding search beyond your CSV coordinates")
print()
# Generate expanded coordinate grid
base_lat, base_lon = 31.3, 34.0 # Center of your CSV coordinates
candidate_coordinates = generate_expanded_coordinates(
base_lat, base_lon, target_lat, target_lon, tolerance_km
)
print(f"📍 Testing {len(candidate_coordinates)} launch coordinates")
print(f" (Including your 5 CSV coordinates plus {len(candidate_coordinates)-5} new candidates)")
print()
# Test different environmental conditions
environments = {
'optimal_summer': EnvironmentalConditions(
season='summer',
launch_time='dawn',
wind_factor=0.8, # Reduced wind
current_factor=1.2 # Enhanced current
),
'strong_current': EnvironmentalConditions(
season='summer',
launch_time='dawn',
wind_factor=0.6,
current_factor=1.5 # Very strong eastward current
),
'light_wind': EnvironmentalConditions(
season='spring',
launch_time='dawn',
wind_factor=0.5,
current_factor=1.3
)
}
# Get container configurations
configurations = test_container_configurations()
optimizer = GazaReverseOptimizer()
best_results = []
# Test each combination
for env_name, environment in environments.items():
print(f"\n🌊 TESTING ENVIRONMENT: {env_name.upper().replace('_', ' ')}")
print(f" Season: {environment.season}, Launch: {environment.launch_time}")
print(f" Wind factor: {environment.wind_factor}, Current factor: {environment.current_factor}")
print("-" * 70)
for config_name, config in configurations.items():
container = config['container']
rope = config['rope']
print(f"\n🔬 Testing {config_name.replace('_', ' ').title()}")
print(f" Container: {container.volume}L {container.container_type}, {container.mass}kg")
print(f" Rope: {rope.length}m {rope.rope_type}, {rope.anchor_weight}kg anchor")
def progress_update(message):
if "Analyzing" in message or "Best" in message:
print(f" {message}")
# Run optimization with expanded tolerance
result = optimizer.optimize_launch_point(
target_lat, target_lon, container, rope, environment,
progress_callback=progress_update,
target_success_rate=0.6, # More realistic target
candidate_coordinates=candidate_coordinates,
success_radius_km=tolerance_km # Accept 3km variance
)
if result.optimal_point.success_probability > 0:
best_results.append({
'environment': env_name,
'configuration': config_name,
'result': result,
'container': container,
'rope': rope
})
print(f" ✅ Success Rate: {result.optimal_point.success_probability:.1%}")
print(f" 📍 Best Launch: {result.optimal_point.lat:.4f}°N, {result.optimal_point.lon:.4f}°E")
print(f" 📏 Distance to Target: {result.optimal_point.distance_km:.1f}km")
# Sort results by success rate
best_results.sort(key=lambda x: x['result'].optimal_point.success_probability, reverse=True)
print("\n" + "=" * 80)
print("🏆 TOP PERFORMING CONFIGURATIONS")
print("=" * 80)
for i, entry in enumerate(best_results[:5]): # Top 5
result = entry['result']
env = entry['environment']
config = entry['configuration']
container = entry['container']
rope = entry['rope']
print(f"\n#{i+1}. {config.replace('_', ' ').title()} in {env.replace('_', ' ').title()}")
print(f" 🎯 Success Rate: {result.optimal_point.success_probability:.1%}")
print(f" 📍 Launch Point: {result.optimal_point.lat:.4f}°N, {result.optimal_point.lon:.4f}°E")
print(f" 📏 Distance: {result.optimal_point.distance_km:.1f}km to target")
print(f" 📦 Container: {container.volume}L {container.container_type}, {container.mass}kg")
print(f" 🪢 Rope: {rope.length}m {rope.rope_type}, {rope.anchor_weight}kg anchor")
# Create animation for top 3 results
if i < 3:
animation_file = f"optimal_{i+1}_{config}_{result.optimal_point.success_probability:.0%}.gif"
optimizer.create_trajectory_animation(result, animation_file)
print(f" 🎬 Animation: {animation_file}")
# Summary
if best_results:
best = best_results[0]
print(f"\n🎉 BEST CONFIGURATION FOUND:")
print(f" Success Rate: {best['result'].optimal_point.success_probability:.1%}")
print(f" Launch Point: {best['result'].optimal_point.lat:.4f}°N, {best['result'].optimal_point.lon:.4f}°E")
print(f" Configuration: {best['configuration'].replace('_', ' ').title()}")
print(f" Environment: {best['environment'].replace('_', ' ').title()}")
# Calculate improvement over CSV coordinates
improvement = best['result'].optimal_point.success_probability - 0.28 # vs your 28% max
print(f" 📈 Improvement: +{improvement:.1%} over your CSV coordinates")
else:
print("\n⚠️ No successful configurations found. Need to adjust physics parameters.")
if __name__ == "__main__":
main()