We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexDiscussionExhibition › Shortest Paths
Page Index Toggle Pages: 1
Shortest Paths (Read 1413 times)
Shortest Paths
Mar 24th, 2009, 11:32pm
 
I decided to go back to an old sketch that worked out shortest paths between 2 points in a game I used to play, and try to make it nice and generic.

I found the JGraphT Library ( http://jgrapht.sourceforge.net/ ) which allows you (with a bit of effort) to create an arbitrary map of various points and routes between them.

There's many types of graphs it allows, but the one I think most people would be interested in is the "simpleWeightedGraph" which maps best on to a real-world implementation.

Here's the demo applet: http://www.hardcorepawn.com/RouteFinder/

Move the mouse to move the start point. The 3 shortest paths from the mouse to the blue square are drawn, as well as their distances.
Re: Shortest Paths
Reply #1 - Mar 27th, 2009, 5:03am
 
John, I learn something new from you every day!  Thanks for sharing.  So tell me... how did you get JgraphT to work in processing?  What is the process for adding a library like that?  I've looked at the guidelines and created the directory structure, but no go.  http://dev.processing.org/libraries/guidelines.html

There are several libraries, including JgraphT that I'd like to import.
Re: Shortest Paths
Reply #2 - Mar 27th, 2009, 5:14am
 
If you need to use a given pure Java library in a sketch, create a code folder in the sketch's folder and put the .jar file there.
Alternatively, I have read that you can just drag'n'drop the file to the PDE window where the sketch is opened...
Re: Shortest Paths
Reply #3 - Mar 27th, 2009, 5:29am
 
Wow!! These instructions should be a sticky topic in http://processing.org/discourse/yabb2/board_os_libraries_tools.html

That vastly increases the possibilities of this tool.
Re: Shortest Paths
Reply #4 - Mar 27th, 2009, 5:40am
 
I just read where John said it in another thread... I had to rename the jar so that it matched the directory name and move it to the library folder.

Quote:
If you want to add a .jar file to a single project, you put it in a "code" subfolder, e.g. Processing/MySketch/code/foo.jar

If you want the library to be available to all sketches, then the jar needs to go in: Processing/Libraries/MyLib/library/MyLib.jar (Note the directory name "MyLib" must match the jar name "MyLib.jar")
Re: Shortest Paths
Reply #5 - Mar 27th, 2009, 6:13am
 
Ah yes, if you download JGraphT you get a jgrapht-jdk1.6(or5).jar and jgrapht/lib/<lots of jars>

All I did was create a Processing/Libraries/jgrapht/library/ folder, rename jgrapht-1.5jdk.jar to jgrapht.jar and copy all the jgrapht/lib/*.jar to the library folder, and it then works and can be imported into processing via the menu.
Page Index Toggle Pages: 1