Journal FortKnox's Journal: Developers! Developers! Developers! 6
Question:
Have you ever had to deal with graphs? I am assembling a structure as a hashmap. But in some instances I may want to build (at runtime) a graph from objects within this hashmap.
The words "graph theory" sends chills up my spine. But is there anyway to assemble graphs (think 3d) that are attached at any 4 points (think north, south, east, west, up, and down. They can use 1..* of the directions), and establish two points next to each other but not attached?
In other words, start at a spot. You can either go up or down. If you go up, you can go three spots north. If you go down you can go two spots north. I want to see the relationship between those two spots north (on the 'down' track) and the 2 spots north (on the 'up' track); eg - they should be 'above' and 'below' themselves. The extra spot north (on the 'up' track) should understand that nothing is 'below' it.
So, any ideas on how this could be done? Any good books on graph theory to talk me outta attempting this?
Have you ever had to deal with graphs? I am assembling a structure as a hashmap. But in some instances I may want to build (at runtime) a graph from objects within this hashmap.
The words "graph theory" sends chills up my spine. But is there anyway to assemble graphs (think 3d) that are attached at any 4 points (think north, south, east, west, up, and down. They can use 1..* of the directions), and establish two points next to each other but not attached?
In other words, start at a spot. You can either go up or down. If you go up, you can go three spots north. If you go down you can go two spots north. I want to see the relationship between those two spots north (on the 'down' track) and the 2 spots north (on the 'up' track); eg - they should be 'above' and 'below' themselves. The extra spot north (on the 'up' track) should understand that nothing is 'below' it.
So, any ideas on how this could be done? Any good books on graph theory to talk me outta attempting this?
I'm replying to myself! (Score:2)
What seems most intelligent to use (to me) would be a 3D array structure. That way, I can just use the numbers to my advantage (if something exists in the say X,Y, but has a different Z, its just up/down level different, etc...). But, in java, you can't resize arrays, so I could fall into trouble.
Instead, I should apply an x,y,z coordinate to the area. That way, I just have to check the coordinates against one another.
In fact, I don't need to assemble the structure into a
Re:I'm replying to myself! (Score:1)
Java Arrays (Score:2)
Arggh. Can't think of the book right now, I think it's Core Java Fundamentals Vol. I has an actual example of this in like Chapter II.
Doesn't help with your representation, though.
Sorry.
The best graph algorithms book out there (Score:2)
He's rewritten Parts 1-4 as an Algorithms in Java [barnesandnoble.com] book, I'm assuming part 5 will come out as a Java book soon as welll.
I'm sick now, and don't have the brain power to look over your problem, but if I think of anything I'll be sure to post it.
Good luck.
Just a thought (Score:1)
What about a BSP tree? Your description reminded me of visibility calculations in Doom.
(Disclaimer: My graph theory muscles have atrophied from disuse since college.)
More details? (Score:2)
There are any number of potential solutions, but it's hard to say which is best from your description. So, a few questions: