Jump to content

Weather routing: Difference between revisions

m
syntax highlighting fixup automation
m (→‎{{header|Phix}}: syntax coloured, made p2js compatible)
m (syntax highlighting fixup automation)
Line 15:
{{trans|Julia}}
This runs in only 37 seconds which is surprisingly quick compared to Julia. However, I've just noticed that I'm using an out of date version of Julia (1.0.4) so hopefully the latest version will be able to close the gap.
<langsyntaxhighlight lang="go">package main
 
import (
Line 467:
fmt.Println("The route taking the least time found was:\n", tp.path, "\nwhich has duration",
int(tp.duration/60), "hours,", int(math.Round(math.Mod(tp.duration, 60))), "minutes.")
}</langsyntaxhighlight>
 
{{out}}
Line 478:
=={{header|Julia}}==
Brute force optimization search, practical for shorter path lengths, but would require a better algorithm for paths over twice this size.
<langsyntaxhighlight lang="julia">module SailingPolars
 
using DelimitedFiles
Line 861:
println("The route taking the least time found was:\n ", tp.path,
"\nwhich has duration $(div(tp.duration, 60)) hours, $(rem(tp.duration, 60)) minutes.")
</syntaxhighlight>
</lang>
The polar CSV file used for this solution, named polar.csv, is as follows. Note that this is a very detailed
polar, chosen to stress the testing of the code. Most polar files are far smaller,
Line 921:
The Go version runs in about 44 seconds on my computer. This Nim version, compiled in release mode (which includes runtime checks), runs in 22 seconds (18 seconds if link time optimization is activated). When compiled without checks (“danger” mode), it runs in 15.5 seconds.
 
<langsyntaxhighlight Nimlang="nim">import hashes, math, parsecsv, sequtils, sets, strutils, sugar
 
type
Line 1,237:
echo "The route taking the least time found was:"
echo tp.path
echo "which has duration ", int(tp.duration / 60), " hours ", toInt(tp.duration mod 60), " minutes."</langsyntaxhighlight>
 
{{out}}
Line 1,246:
=={{header|Phix}}==
{{trans|Go}}
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\Weather_Routing.exw
Line 1,590:
<span style="color: #0000FF;">{}</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">wait_key</span><span style="color: #0000FF;">()</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 1,605:
 
As you'd expect, this takes many times longer than Julia to run (about 24.5 minutes versus 3 minutes 20 seconds) but gets there in the end :)
<langsyntaxhighlight lang="ecmascript">import "io" for File
 
/*
Line 2,026:
var tp = minimumTimeRoute.call(routeProb, sp, false)
System.print("The route taking the least time found was:\n %(tp.path) \nwhich has duration " +
"%((tp.duration/60).truncate) hours, %((tp.duration%60).round) minutes.")</langsyntaxhighlight>
 
{{out}}
10,327

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.