Go Back  PPRuNe Forums > Aircrew Forums > Rotorheads
Reload this Page >

Route optimization

Rotorheads A haven for helicopter professionals to discuss the things that affect them

Route optimization

Old 30th Sep 2020, 08:18
  #1 (permalink)  
Thread Starter
 
Join Date: Sep 2020
Location: Stockholm
Posts: 3
Route optimization

Does anyone know of a good computor program for route optimazation?

I would like to import a lot of coordinates into the computer that can optimize the route to the shortest legnth, then export it as an KML and/or GPX- file.
babbaz is offline  
Old 30th Sep 2020, 10:39
  #2 (permalink)  
 
Join Date: Sep 2002
Location: Great South East, tired and retired
Posts: 3,015
Yeah, choppers have such a huge range that we need to fly great circles instead of Rhumb lines.
Ascend Charlie is offline  
Old 30th Sep 2020, 10:44
  #3 (permalink)  
Thread Starter
 
Join Date: Sep 2020
Location: Stockholm
Posts: 3
Thank you for the reply, that really helped me a lot!!
babbaz is offline  
Old 30th Sep 2020, 13:47
  #4 (permalink)  
 
Join Date: Dec 2006
Location: yes
Posts: 257
You are asking to solve a well-known problem in computer science referred to as the “travelling salesman”, or the “shortest path algorithm”. It’s complicated to say the least, as books have been written about it. Most software programs available optimize the results using road-routing (for delivery trucks), which I assume you don’t want. The backend programming access to Goggle Maps can solve this also, but AFAIK, only programmatically. Try searching for an Excel spreadsheet that performs shortest path. I found a few links that looked promising. However, the spreadsheet probably won’t use the lat/long but will rather need the distances between all points.
JimEli is offline  
Old 30th Sep 2020, 16:16
  #5 (permalink)  
swh

Eidolon
 
Join Date: May 2001
Location: Some hole
Posts: 1,984
Not difficult to do, could probably write that in 20 lines of code.



Many people have also implemented Dijkstra's algorithm in excel also, you could possibly find a spreadsheet for it online.
swh is offline  
Old 30th Sep 2020, 16:50
  #6 (permalink)  
 
Join Date: Sep 2003
Location: Redding CA, or on a fire somewhere
Posts: 1,795
Originally Posted by babbaz View Post
Does anyone know of a good computor program for route optimazation?

I would like to import a lot of coordinates into the computer that can optimize the route to the shortest legnth, then export it as an KML and/or GPX- file.
This works for airports:

AirNav: Fuel Stop Planner
Gordy is offline  
Old 30th Sep 2020, 17:33
  #7 (permalink)  
 
Join Date: Jun 2010
Location: Nanaimo, B.C.
Age: 63
Posts: 44
The problem here is that one quickly realizes that often the minimum time route is not the same as the minimum fuel route. Computing minimum fuel routes requires the input of aircraft performance. Having worked on algorithms to do this back in the 80's for airlines I can assure you that it is not trivial.

An example: what if the minimum distance route requires a climb to 10000' over a mountain? Would you want to choose that route over a longer distance valley route?

Still, there are many cases where the minimum distance route (usually but not always the minimum time route as well) is good enough.
dash34 is offline  
Old 1st Oct 2020, 03:23
  #8 (permalink)  
 
Join Date: Mar 2005
Location: N/A
Posts: 3,459
what if the minimum distance route requires a climb to 10000' over a mountain
Had this scenario presented by the CP during a IMC test, the shortest route had a high LSALT and with the OAT given would have been unable to remain above the terrain should an engine failure occur, the only option was to follow an airway that went down a valley which added considerable track miles. Had icing been a consideration the same would have applied.
megan is offline  
Old 1st Oct 2020, 05:45
  #9 (permalink)  
Thread Starter
 
Join Date: Sep 2020
Location: Stockholm
Posts: 3
A comon thing here were i work and fly is that our customers who wants to fly and inspect forest (government people who inspect that the land owners have cut the forest in the correct way) might send me a bunch of objects (gps positions) they want to go to. It's usually a cluster of positions that could have a couple of hundred of meters between them and sometimes kilometers between them. Today we have a system for optimization, but it's old, verry slow and complicated.
babbaz is offline  
Old 1st Oct 2020, 21:03
  #10 (permalink)  
 
Join Date: Apr 2000
Location: EGDC
Posts: 8,137
Mark the positions on a map and eyeball it? Or is that just too old-school?
crab@SAAvn.co.uk is offline  
Old 2nd Oct 2020, 10:38
  #11 (permalink)  
RMK
 
Join Date: Aug 2008
Location: London
Posts: 211
ForeFlight, Garmin Pilot and SkyDemon can all do that.
RMK is offline  
Old 2nd Oct 2020, 20:42
  #12 (permalink)  
 
Join Date: Dec 2006
Location: yes
Posts: 257
Originally Posted by swh View Post
Not difficult to do, could probably write that in 20 lines of code.
Many people have also implemented Dijkstra's algorithm in excel also, you could possibly find a spreadsheet for it online.
“Travelling Salesman Problem” (TSP) is not a trivial problem. In computer science it is termed “NP-Hard”. For example, the Dantzig49 variant of TSP requires a tour be constructed of 48 cities, one each in every continental US state plus Washington, DC. There are (n-1!)/2 possible tours to a TSP, so Dantzig49 has 6,206,957,796,268,036,335,431,144,523,686,687,519,260,743,17 7,338,880,000,000,000 possible tours (~6.2 novemdecillion). We'll wait here for the 20 lines (AFAIK, Dijsktra doesn't necessarily solve the problem).

Last edited by JimEli; 2nd Oct 2020 at 22:11.
JimEli is offline  
Old 3rd Oct 2020, 04:13
  #13 (permalink)  
 
Join Date: Oct 2020
Location: USA
Posts: 3
I've thrown together some code to do this, enter a list of lat/long and it will find the shortest route. It is only really effective for less than 6 locations as it is using a brute force algorithm and the number of possible routes gets very large. Let me know if you are interested in checking it out.
Waypoint Short is offline  
Old 7th Oct 2020, 11:41
  #14 (permalink)  
swh

Eidolon
 
Join Date: May 2001
Location: Some hole
Posts: 1,984
I have written a few lines of code that solves the problem would be easy to extend to solve for the shortest time rather than shortest distance, I could just use a TAS and wind to get an average groundspeed for each track. The code solves the shortest distance matrix, it does not know what the weights are in the matrix, they can be time or distance, or fuel.

# read the CSV with waypoints
waypoints=df.read_csv("sweden.csv")
# extract the colums with lat and long
latlon= waypoints[['Latitude','Longitude']].values
# number of waypoints
points=latlon.shape[0]
# create an empty square matrix to hold the distances between each waypoint
dist_matrix = np.zeros((points,points))
# calculate the great circle distance between all waypoints in nautical miles
for i in range(0, points):
for j in range(0, points):
dist_matrix[i,j]=great_circle(latlon[i],latlon[j]).nautical
# solve the shortest path through the waypoints
path = solve_tsp(dist_matrix,endpoints = (0,0))

It is robust enough to calculate all the shortest path for 1916 Swedish cities in this CSV, https://github.com/sphrak/svenska-st...ska-stader.csv. It also outputs the route in PNG, KML, GPX, and CSV format



Full code here, its written in Python 3.8, it will run on a Mac, PC, or Unix Machine.


import pandas as df
import numpy as np
import matplotlib.pyplot as plt
from geopy.distance import great_circle
from mpl_toolkits.basemap import Basemap
from tsp_solver.greedy import solve_tsp
import simplekml, gpxpy, gpxpy.gpx, csv
# read the CSV with waypoints
waypoints=df.read_csv("sweden.csv")
# extract the colums with lat and long
latlon= waypoints[['Latitude','Longitude']].values
# number of waypoints
points=latlon.shape[0]
# create an empty square matrix to hold the distances between each waypoint
dist_matrix = np.zeros((points,points))
# calculate the great circle distance between all waypoints in nautical miles
for i in range(0, points):
for j in range(0, points):
dist_matrix[i,j]=great_circle(latlon[i],latlon[j]).nautical
# solve the shortest path through the waypoints
path = solve_tsp(dist_matrix,endpoints = (0,0))

#
# Plot the result
#
fig = plt.figure(figsize=(300, 300), edgecolor='w')
plt.plot( latlon[path,1], latlon[path,0], 'k-' )
plt.show()
m = Basemap(projection='tmerc',
lon_0=16., lat_0=62.,
resolution='l',
llcrnrlon=10, llcrnrlat=55, # LL = lower left
urcrnrlon=23, urcrnrlat=67) #UR = upper right
m.shadedrelief()
m.drawcoastlines()
m.drawcountries()
m.drawstates()
m.etopo(scale=0.5, alpha=0.5)
#
# Draw the tracks
#
for i in range(0,len(path)-1):
m.drawgreatcircle(latlon[path[i],1],
latlon[path[i],0],
latlon[path[i+1],1],
latlon[path[i+1],0]
,color='r')
plt.savefig('output.png')
#
# Write GPX File
#
gpx = gpxpy.gpx.GPX()
gpx_track = gpxpy.gpx.GPXTrack()
gpx.tracks.append(gpx_track)
gpx_segment = gpxpy.gpx.GPXTrackSegment()
gpx_track.segments.append(gpx_segment)
for i in range(0,len(path)-1):
gpx_segment.points.append(gpxpy.gpx.GPXTrackPoint(latlon[path[i],0], latlon[path[i],1]))
with open('output.gpx', 'w') as f:
f.write(gpx.to_xml())
#
# Write KML File
#
kml = simplekml.Kml()
for i in range(0,len(path)-1):
kml.newpoint(name=str(i), coords=[(latlon[path[i],1], latlon[path[i],0])])
for i in range(0, points-1):
linestring = kml.newlinestring(name="Sector "+str(i))
linestring.coords = [
(latlon[path[i],1], latlon[path[i],0],50),
(latlon[path[i+1],1], latlon[path[i+1],0],50)]
linestring.altitudemode = simplekml.AltitudeMode.relativetoground
kml.save("output.kml")
#
# Write CSV File
#
with open('output.csv', 'w', newline='') as file:
writer = csv.writer(file)
writer.writerow(["Track", "from_Lat","from_long", "to_Lat", "to_Long"])
for i in range(0,len(path)-1):
writer.writerow([i, latlon[path,0], latlon[path,1],latlon[path[i+1],0], latlon[path[i+1],1]])
swh is offline  
Old 7th Oct 2020, 13:59
  #15 (permalink)  
 
Join Date: Dec 2006
Location: yes
Posts: 257
Originally Posted by swh View Post
I have written a few lines of code that solves the problem would be easy to extend to solve for the shortest time rather than shortest distance, I could just use a TAS and wind to get an average groundspeed for each track. The code solves the shortest distance matrix, it does not know what the weights are in the matrix, they can be time or distance, or fuel.
...
Since solving the actual routing of the TSP is performed in several hundred lines of imported code, you could have at least mentioned attribution.
JimEli is offline  
Old 7th Oct 2020, 16:05
  #16 (permalink)  
swh

Eidolon
 
Join Date: May 2001
Location: Some hole
Posts: 1,984
Originally Posted by JimEli View Post
Since solving the actual routing of the TSP is performed in several hundred lines of imported code, you could have at least mentioned attribution.
I wrote the python code above that reads in the waypoints from a CSV file, calculates the great circle distance between those waypoints, calculates the minimum cost through the waypoint network, and outputs that minimum cost path as PNG, CSV, KML, GPX. I used existing python libraries as the code works, however in order to know which libraries to use, I needed how to solve the problem, how to get the data in the correct format to use the libraries, and how to use the results.

I never claimed to have invented python, or its multitude of libraries, or the compiled libraries, the compilers, assembler language, operating system, or even the computer itself. The greedy.py solver is less than 200 lines of code (not including spaces or comments). It is not a complicated algorithm, nor is 2 -opt. I could write a 2-opt solver (https://en.wikipedia.org/wiki/2-opt) in less than 20 lines (which would be better solver for larger datasets). You made a very silly comment, like saying someone didn't write stdio.h math.h numpy or pandas or their associated compiled libraries so that any code that uses them is invalid. Everyone can see the libraries used.

You are basically accusing me of plagiarism, would you like to enlighten us all where such a start to end solution has been presented before for everyone to see ?

What did you actually do apart from pontificate and preach how difficult a problem it is ?

BTW, This is my solution to the US 48 states problem using the same code (starting and ending in Washington), you know the one you said had "6,206,957,796,268,036,335,431,144,523,686,687,519,260,743,1 7 7,338,880,000,000,000 possible tours (~6.2 novemdecillion)" which I solved in under 10 seconds.

Did you really come up with that number of tours, or did you just lift if off another web page to make yourself sound intelligent ?



Last edited by swh; 7th Oct 2020 at 16:22.
swh is offline  
Old 8th Oct 2020, 00:29
  #17 (permalink)  
 
Join Date: Dec 2006
Location: yes
Posts: 257
Prone to flying off the handle? Because you just went all Fox-One on me. Try switching to 100% Ox before total GLOC. Nobody’s claiming plagiarism. I just pointed out that you called an imported, specialized library to do all the heavy lifting and create the TSP solution. Sort of like claiming you can multiply, but then using a calculator. You're the one that boasted. You also should have noted, that the imported algorithm, “does not guarantee to find the optimal solution.” I’ll ignore the remainder of your pointless drivel, however reference your comment about my post, you could have followed my link to the source of the comment. I did that so anyone but a disgruntled pelican could clearly see it wasn’t mine. And regarding enlightening, “us all where such a start to end solution has been presented before for everyone to see?” A few progenitors are,

https://jupyter.brynmawr.edu/service...15/TSPv3.ipynb

and,

Travelling Salesman Problem Ross Scrivener

and the Concorde TSP Solver, widely regarded as the fastest true TSP solver in existence (BTW, its also an iPhone app),

https://en.wikipedia.org/wiki/Concorde_TSP_Solver
JimEli is offline  
Old 8th Oct 2020, 15:03
  #18 (permalink)  
swh

Eidolon
 
Join Date: May 2001
Location: Some hole
Posts: 1,984
Originally Posted by JimEli View Post
Prone to flying off the handle? Because you just went all Fox-One on me. Try switching to 100% Ox before total GLOC.
You are being a prat.

Originally Posted by JimEli View Post
Nobody’s claiming plagiarism. I just pointed out that you called an imported, specialized library to do all the heavy lifting and create the TSP solution.
You said I failed to attribute the code of others, what I posted is my original work. All the modules used are clearly listed at the top of the code. No different to the Concorde you mentioned, it actually uses QSOpt to do the solving, that does detract from them knowing how to use QSOpt and getting the data in a format to to use it.

Originally Posted by JimEli View Post
Sort of like claiming you can multiply, but then using a calculator. You're the one that boasted.
All I said was "Not difficult to do, could probably write that in 20 lines of code", I never claimed I would build the computer, operating system, compilers and everything from scratch in 20 lines. I did exactly what I said I could do, produced the results, meanwhile you blew more hot air.

Originally Posted by JimEli View Post
You also should have noted, that the imported algorithm, “does not guarantee to find the optimal solution.” I’ll ignore the remainder of your pointless drivel, however reference your comment about my post, you could have followed my link to the source of the comment.
My pointless drivel ? What have you actually contributed to this thread except from what you have copied without quoting from other websites ?

There is a big difference between the optimal solution and an optimised route, one is an academic exercise, the other a practical exercise. The OP was after a way to read a series of waypoints, determine an optimized route, and generate GPX and/or KLM files, which is exactly what my code does. The greedy algorithm is actually the best choice for this practical problem due to its speed and it optimises from the start of the trip, which means during the sortie they can pull off from the optimised route and do a fuel stop or crew swap and it will then recommence an optimised route again. Other algorithms optimize the entire route, and if you deviate from that route it needs to recalculate it all over again.

Originally Posted by Jimsli View Post
I did that so anyone but a disgruntled pelican could clearly see it wasn’t mine.
Everyone can see your true colors, plagiarizing content from others and then throwing personal insults when exposed.

Originally Posted by Jimsli View Post
And regarding enlightening, “us all where such a start to end solution has been presented before for everyone to see?” A few progenitors are,

https://jupyter.brynmawr.edu/service...15/TSPv3.ipynb

and,

Travelling Salesman Problem Ross Scrivener

and the Concorde TSP Solver, widely regarded as the fastest true TSP solver in existence (BTW, its also an iPhone app),

https://en.wikipedia.org/wiki/Concorde_TSP_Solver
None of those can do what my code does, i.e. read a CSV file of LAT/LON, calculate tracks on a WGS84 ellipsoid, calculate a optimised route, and output a KML/GPX/CSV file.
swh is offline  
Old 8th Oct 2020, 23:20
  #19 (permalink)  
 
Join Date: Apr 2010
Location: USA
Posts: 595
Possibly of interest...

https://www.quantamagazine.org/compu...cord-20201008/

aa777888 is online now  
Old 12th Oct 2020, 18:55
  #20 (permalink)  
 
Join Date: Jun 2010
Location: Nanaimo, B.C.
Age: 63
Posts: 44
https://www.quantamagazine.org/compu...2f932-45608622
dash34 is offline  

Thread Tools
Search this Thread

Contact Us - Archive - Advertising - Cookie Policy - Privacy Statement - Terms of Service - Do Not Sell My Personal Information -

Copyright 2018 MH Sub I, LLC dba Internet Brands. All rights reserved. Use of this site indicates your consent to the Terms of Use.