Topic: Help with calculating data from a list

Hello

I'm currently trying to write a programm that is able to calculate the length of a route from fixed points that are saved in a list .

The problem is, that I dont have any idea on how to get the data from the points into the calculator.
So far, I've managed to create a database that is filled with the content start, end and length. But I have no clue on how to get the data into the calculator.

For a short visual help on what I mean , heres a sketch up on what I'm trying to do.

http://img685.imageshack.us/img685/4272/hawprg.png

I'm pretty sure thats one stupid problem for the most of you smile

Thanks for your help !
Best regards

Last edited by Kammron (2011-06-23 05:58:19)

Re: Help with calculating data from a list

No, it's not stupid; if I'm getting it right your problem is twofold: (1) build up a graph data structure from edges, and (2) walk the graph.  Both are well known problems in computer science.  I suggest you google for them.

If you don't have too many edges, I suggest you have them basically in the structure shown in your screen mock (it would be the model in Rails).  Walking them (finding the shortest path) can be done by several different approaches. (Whichever you end up using would most likely become a class method in the model).  It is not very complicated but it's been documented at many places, see this for example: http://practicaldev.blogspot.com/2009/1 … -ruby.html  (BTW, Ruby has a graph library (http://rgl.rubyforge.org/rgl/index.html) -- but that may be an overkill.)