corsasport.co.uk
 

Corsa Sport » Message Board » Off Day » Geek Day » One for the programmers on here (or Ian)


New Topic

New Poll
  Subscribe | Add to Favourites

You are not logged in and may not post or reply to messages. Please log in or create a new account or mail us about fixing an existing one - register@corsasport.co.uk

There are also many more features available when you are logged in such as private messages, buddy list, location services, post search and more.


Author One for the programmers on here (or Ian)
Sam
Moderator
Premium Member


Registered: 24th Dec 99
Location: West Midlands
User status: Offline
6th Jul 12 at 21:00   View User's Profile U2U Member Reply With Quote

I guess this is probably partly/mostly a mathematical question? But here goes my following example scenario...

You are creating a program that offers you a list of ways to get from one train station to another.

Let's say you want to travel to Worcester Shrub Hill from Birmingham New Street.

The 3 ways I personally know of doing this journey are:

- Birmingham New Street direct to Worcester Shrub Hill
- Birmingham New Street > Smethwick Galton Bridge > Worcester Shrub Hill
- Birmingham New Street > Droitwich Spa > Worcester Shrub Hill

How would you create such a program and make it 'know' that it can go to different points via other points?
John
Member

Registered: 30th Jun 03
User status: Offline
6th Jul 12 at 21:06   View User's Profile U2U Member Reply With Quote

I'm not a programmer but I'd want a database that contained the station with links to the stations that connected.

You'd then need to traverse the database in the most efficient way to compare all the links.
AndyKent
Member

Registered: 3rd Sep 05
User status: Offline
6th Jul 12 at 21:19   View User's Profile U2U Member Reply With Quote

Interesting question, be interested to know the answer.

I suspect I could build something with a limited number of stations but it'd probably be grossly inefficient and rely on processing power rather than intelligence.
Dom
Member

Registered: 13th Sep 03
User status: Offline
6th Jul 12 at 21:39   View User's Profile U2U Member Reply With Quote

As John said but personally i'd opt for someone else's API
John
Member

Registered: 30th Jun 03
User status: Offline
6th Jul 12 at 21:56   View User's Profile U2U Member Reply With Quote

Actually, is this not just the travelling salesman problem?
Ian
Site Administrator

Avatar

Registered: 28th Aug 99
Location: Liverpool
User status: Offline
7th Jul 12 at 03:25   View Garage View User's Profile U2U Member Reply With Quote

Usually Dijkstra's algorithm, computationally quite expensive with a relational database as you need as many recursive joins as there are probably nodes in your route.

In essence, you have a table of stations, then another table which station id 1 and station id 2 and the distance/time/whatever

You keep querying the distances table and sum up all the distances, and order the result set by the sum so that the top results are your path candidates.

You'll get lots of wacky solutions which are very long which you discard.

I'd probably combine it with some sort of knowledge of where the stations physically were and bound on that so you're not talking about Liverpool stations if your start and finish destinations are both in Birmingham for example. OS Code Point would help you there assume you also have postcodes for the stations.

The other problem is that if you don't have the database it will very time consuming to create. Number of rows is the number of stations, squared, minus any prohibited combinations - trains which don't stop or different lines which don't give access to the same stations.

[Edited on 07-07-2012 by Ian]
AndyKent
Member

Registered: 3rd Sep 05
User status: Offline
7th Jul 12 at 07:06   View User's Profile U2U Member Reply With Quote

Here we to - http://algo2.iti.kit.edu/documents/routeplanning/weaOverview.pdf
Sam
Moderator
Premium Member


Registered: 24th Dec 99
Location: West Midlands
User status: Offline
7th Jul 12 at 11:46   View User's Profile U2U Member Reply With Quote

So what would happen if say for example you wanted to travel from Birmingham New Street to Liverpool Lime Street if there was no direct route?
Chris
Premium Member

Avatar

Registered: 21st Sep 99
User status: Offline
8th Jul 12 at 19:29   View Garage View User's Profile U2U Member Reply With Quote

There is a direct route i used it the other day departs 1 and :36

www.thetrainline.com kinda does just what you are asking, even give you ticket prices.

[Edited on 08-07-2012 by Chris]
Ian
Site Administrator

Avatar

Registered: 28th Aug 99
Location: Liverpool
User status: Offline
8th Jul 12 at 19:40   View Garage View User's Profile U2U Member Reply With Quote

quote:
Originally posted by Sam
So what would happen if say for example you wanted to travel from Birmingham New Street to Liverpool Lime Street if there was no direct route?


When the route is found, the number of nodes / travel time per node is summed and that is your route.

In your original example you are also displaying the runners up to the direct route, BNS to Liverpool the runners up (ie. not direct) are the top of the node/station count / distance / time whatever your weight is in the data.

 
New Topic

New Poll

  Related Threads Author Forum Replies Views Last Post
Does anyone know Java???? SteveW Geek Day 24 1937
9th Jun 03 at 11:50
by Mikorsa16v
 
Joke Happy_2008 General Chat 4 1192
15th Oct 03 at 19:25
by chris_uk
 
are there any good pic programmers on here? cdcool1 General Chat 10 671
7th Mar 04 at 09:58
by Adam-D
 
Any programmers out there? Cosmo Geek Day 16 1853
28th Oct 05 at 16:46
by James
 

Corsa Sport » Message Board » Off Day » Geek Day » One for the programmers on here (or Ian) 29 database queries in 0.0111051 seconds