The real question is how to represent a graph data structure in ruby (some example code might help me understand).
I currently have an idea to represent a graph. that is every Node
has an array
of neighbourNodes
which are object_id
of node objects. Is there any better solution? Can i achieve this with some library easily. I have looked at GRATR
and RGL
. both are outdated (atleast i think so.) Anyway any working example on tuby 2.0.0 will help me a lot.
I have Busstops
which compose Routes
. Routes
is a sequence of Busstops
. How would I represent the graph for all the Routes
. I want to use Dijkstra's Algorith to find a shortest path between two busstops (which may or may not lie on the same Route
. Which means you have to change a bus on the way)).
This question is really vague, so you should expect to receive vague answers. Here's mine:
It's All Data
When you're looking to do something visually, it all starts with data
Your busstops
have routes
-- this means nothing to Rails or your graphing system. What will mean something is numbers & data; specifically geolocational data (for the bus stops & other geolocational data)
We've never done anything with maps or routes; so I don't know how you'd plot a route, and find the nearest bus stop. I do know, however, that in order to get that working, you'll definitely need to pull the correct data from your database
How I'd Approach It
I'd start by getting all the data you'll need stored in the database:
Once you have all these values in place, you'll then be able to get some sort of process sorted to show the data on the graph
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With