Weather routing: Difference between revisions
m
→{{header|Julia}}
Line 52:
function getpolardata(filename)
Read a sailing polar CSV file and return a
A sailing polar file is a CSV file, with ';' used as the comma separator instead of a comma.
Line 91:
"""
Convert polar coordinates in degrees to cartesian x, y coordinates
Line 248:
timeinterval: the seconds duration for each TimeSlice
timeframe: a vector of
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 #
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,
for
newpaths = TimedPath[]
verbose && println("Checking ", length(timedpaths), " paths of length ",
Line 312:
else
p1 = tpath.path[end]
length(rp.timeframe) + 1]
for p2 in surround([p1[1], p1[2]], slice, rp.obstacleindices)
!rp.allowrepeatvisits && p2 in tpath.path && continue
gp1, gp2 =
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!(
for (i,
x.sp = SurfaceParameters(x.sp.winddeg, x.sp.windkts * (1 + 0.002 * i),
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!(
const routeprob = RoutingProblem(
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], [
which has duration 4.0 hours,
</pre>
|