Weather routing: Difference between revisions

m
Line 52:
function getpolardata(filename)
 
Read a sailing polar CSV file and return a SurfaceParametersSailingPolar struct forcontaing the file data.
 
A sailing polar file is a CSV file, with ';' used as the comma separator instead of a comma.
Line 91:
 
"""
polard2cartesuanpolard2cartesian(r, deg)
 
Convert polar coordinates in degrees to cartesian x, y coordinates
Line 248:
 
timeinterval: the seconds duration for each TimeSlice
timeframe: a vector of sequntialsequential timeslices for the ocean region
obstacleindices: the Cartesian indices in each timeslice for
obstacles, such as land or shoals, where the ship may not go
Line 257:
"""
mutable struct RoutingProblem
timeinterval::Float64 # secondsminutes between timeframe slices
timeframe::Vector{TimeSlice}
obstacleindices::Vector{Point2{Int}}
Line 301:
function minimumtimeroute(rp::RoutingProblem, sp::SailingPolar, verbose=false)
timedpaths = [TimedPath(0.0, [rp.start])]
completed, mintime, minpath = false, 10_000_0001000.0, TimedPath(10_000_0001000.0, [])
for (i, timeframe) in enumerate(rp.timeframe)1:1000
newpaths = TimedPath[]
verbose && println("Checking ", length(timedpaths), " paths of length ",
Line 312:
else
p1 = tpath.path[end]
forslice p2= in surroundrp.timeframe[div(Int([p1[1]round(tpath.duration)), p1[2]],10) timeframe, rp.obstacleindices)%
length(rp.timeframe) + 1]
for p2 in surround([p1[1], p1[2]], slice, rp.obstacleindices)
!rp.allowrepeatvisits && p2 in tpath.path && continue
gp1, gp2 = timeframeslice[p1[1], p1[2]], timeframeslice[p2[1], p2[2]]
lat1, lon1, lat2, lon2 = gp1.pt[1], gp1.pt[2], gp2.pt[1], gp2.pt[2]
t = sailsegmenttime(sp, gp1.sp, lat1, lon1, lat2, lon2)
Line 372 ⟶ 374:
 
# Vary wind speeds over time.
function mutatetimeslices!(gridpointsslices)
for (i, xslice) in enumerate(gridpointsslices), x in slice
x.sp = SurfaceParameters(x.sp.winddeg, x.sp.windkts * (1 + 0.002 * i),
x.sp.currentdeg, x.sp.currentkts)
end
end
Line 384 ⟶ 386:
const pmat = [Position(19.78 - 1/60 + i/60, -155.0 - 5/60 + j/60) for i in 0:8, j in 0:8]
const gpoints = map(pt -> GridPoint(pt, surfacebylongitude(lon(pt))), pmat)
const slices = [deepcopy(gpoints) for _ in 1:200]
mutatetimeslices!(gpointsslices)
 
const routeprob = RoutingProblem(60010.0, fill(gpoints, 200)slices, forbidden, 1, startpos, endpos, false)
const filename = "polar.csv"
const sp = getpolardata(filename)
Line 445 ⟶ 448:
<pre>
The route taking the least time found was:
Point{2,Int64}[[1, 4], [1, 5], [2, 6], [3, 7], [4, 7], [5, 7], [6, 7], [7, 7], [8, 6], [98, 5], [9, 4]]
which has duration 4.0 hours, 3943.72104601694747697879668707344 minutes.
</pre>
4,105

edits