Jump to content


Dijkstra Pathfinding with Python


  • Please log in to reply
17 replies to this topic

#1 asnowcappedromance

asnowcappedromance

    Initiate

  • Members
  • PipPip
  • 158 posts
  • Joined: 18-October 09
  • Location:Vancouver, B.C.
  • Name:Manuel Tausch

Posted 01 December 2011 - 11:31 PM

hey guys,

I thought it's time to test my python skills and decided to give the Dijkstra Pathfinding Algorythm a shot.
Some credits actually go to Sam Hancock who inspired me to do this project, I gladly took a peek at his approach before I tackled the problem,
also I have to thank my friend Michael Davis who always throws in some kickass workflow tips.

After a couple hours of work I was able to solve the (too me a big) mystery - as I never dealt with such stuff before it got quite interesting.
The biggest problem I ran into was calculating the distances between connected points (the "neighbours") in Python,
it gets really messy as there is no such thing as an edge in Houdini compared to other packages (I'm not complaining, only a little) -
so I decided to go back to VOPs and use the neighbourCount and neighbour nodes which provided a really fast and flexible workaround.

During my little ride I actually solved the travelling salesman problem (TSP) accidentally, see the attached image  :lol:

Anyway, I'm attaching the scenefile for everyone who's interested,

cheers,

Manu

Attached Thumbnails

  • TravellingSalesMan.jpg
  • Dijkstra_Pathfinding.jpg

Attached Files


Edited by asnowcappedromance, 01 December 2011 - 11:32 PM.


Manuel Tausch
senior FX TD - Rhythm & Hues

#2 Ole

Ole

    Peon

  • Members
  • Pip
  • 53 posts
  • Joined: 10-November 07
  • Location:Oslo, Norway
  • Name:Ole G.

Posted 02 December 2011 - 06:08 AM

View Postasnowcappedromance, on 01 December 2011 - 11:31 PM, said:

hey guys,

I thought it's time to test my python skills and decided to give the Dijkstra Pathfinding Algorythm a shot.
Some credits actually go to Sam Hancock who inspired me to do this project, I gladly took a peek at his approach before I tackled the problem,
also I have to thank my friend Michael Davis who always throws in some kickass workflow tips.

After a couple hours of work I was able to solve the (too me a big) mystery - as I never dealt with such stuff before it got quite interesting.
The biggest problem I ran into was calculating the distances between connected points (the "neighbours") in Python,
it gets really messy as there is no such thing as an edge in Houdini compared to other packages (I'm not complaining, only a little) -
so I decided to go back to VOPs and use the neighbourCount and neighbour nodes which provided a really fast and flexible workaround.

During my little ride I actually solved the travelling salesman problem (TSP) accidentally, see the attached image :lol:

Anyway, I'm attaching the scenefile for everyone who's interested,

cheers,

Manu

Thank you for sharing!
Gimpville.no

#3 asnowcappedromance

asnowcappedromance

    Initiate

  • Members
  • PipPip
  • 158 posts
  • Joined: 18-October 09
  • Location:Vancouver, B.C.
  • Name:Manuel Tausch

Posted 02 December 2011 - 09:34 AM

terribly sorry, forgot to attach the otl file, without it the scene is useless. My bad!
Here you go!

One thing that I'd like to add is the following link:
http://eoinbailey.co...ted-explanation
It's a detailed explanation of the algorithm, it helped me a lot to get what's going on under the hood.

Attached Files



Manuel Tausch
senior FX TD - Rhythm & Hues

#4 kursad

kursad

    Peon

  • Members
  • Pip
  • 72 posts
  • Joined: 13-May 10
  • Name:kursad kursad

Posted 06 December 2011 - 07:04 PM

View Postasnowcappedromance, on 02 December 2011 - 09:34 AM, said:

terribly sorry, forgot to attach the otl file, without it the scene is useless. My bad!
Here you go!

One thing that I'd like to add is the following link:
http://eoinbailey.co...ted-explanation
It's a detailed explanation of the algorithm, it helped me a lot to get what's going on under the hood.

Hey thanks for the file. I was actually working on a similar problem. So this is great.

As a side note, the group SOP provides a way to select the connected points. It might provide a much more concise way to get a decent list of connected edges. I have been looking into ways to build the list of connected edges and this was one of the ways I came up with, although it is not as sexy as using vop and python that is for sure :)

#5 asnowcappedromance

asnowcappedromance

    Initiate

  • Members
  • PipPip
  • 158 posts
  • Joined: 18-October 09
  • Location:Vancouver, B.C.
  • Name:Manuel Tausch

Posted 06 December 2011 - 09:53 PM

I'm glad you like the setup!
It's far from perfect though, haven't had any time to polish it up, going on vacation tomorrow :)
Yeah, I know about the group SOP but it's slow as hell and using VOPs is 10x faster that's for sure and if you're worried about this approach
being concise, believe me it is. Also, VOPs would allow you to use point clouds which is even faster, so if you would limit the search to a certain
radius you could speed it up even more. The python operator kills the speed though, the Dijkstra method is far too slow as is computes every single shortest
path for the whole geometry.

cheers,

Manu

Manuel Tausch
senior FX TD - Rhythm & Hues

#6 kursad

kursad

    Peon

  • Members
  • Pip
  • 72 posts
  • Joined: 13-May 10
  • Name:kursad kursad

Posted 08 December 2011 - 04:02 PM

View Postasnowcappedromance, on 06 December 2011 - 09:53 PM, said:

I'm glad you like the setup!
It's far from perfect though, haven't had any time to polish it up, going on vacation tomorrow :)
Yeah, I know about the group SOP but it's slow as hell and using VOPs is 10x faster that's for sure and if you're worried about this approach
being concise, believe me it is. Also, VOPs would allow you to use point clouds which is even faster, so if you would limit the search to a certain
radius you could speed it up even more. The python operator kills the speed though, the Dijkstra method is far too slow as is computes every single shortest
path for the whole geometry.

cheers,

Manu


Manu, thanks for the heads up. I have not tried the group sop but I just knew that it could create the connection groups.

I have not used the neighbors nodes before and your example explains it very well. Thanks again

#7 vi_rus

vi_rus

    Initiate

  • Members
  • PipPip
  • 115 posts
  • Joined: 05-June 09
  • Location:Moscow, Russia
  • Name:Sergei Bolisov

Posted 30 January 2012 - 12:20 PM

It's really nice realization of Dijkstra algorithm! But python is too slow for this purposes... So I decided to rewrite python code with hdk. Check out what I did)

View on Vimeo.


Posted Image
Posted Image

#8 asnowcappedromance

asnowcappedromance

    Initiate

  • Members
  • PipPip
  • 158 posts
  • Joined: 18-October 09
  • Location:Vancouver, B.C.
  • Name:Manuel Tausch

Posted 31 January 2012 - 08:33 PM

that is indeed very impressive!!
You're totally right, Python is not the best approach to do it, I think I should learn how to write c++ :)

Manuel Tausch
senior FX TD - Rhythm & Hues

#9 Jason

Jason

    King Tapir

  • Administrators
  • 3,708 posts
  • Joined: 08-November 00
  • Name:Jason Iversen

Posted 31 January 2012 - 09:50 PM

This is nice and useful project! Thank you!

There is also the inlinecpp module if you don't want to dig into the gory internals of the HDK, perhaps?
jason iversen
++odforce guy, and supervisor @ r+h, jiversen-at-rhythm
odforce g+ page: https://plus.google.com/103473736257525043693

#10 vi_rus

vi_rus

    Initiate

  • Members
  • PipPip
  • 115 posts
  • Joined: 05-June 09
  • Location:Moscow, Russia
  • Name:Sergei Bolisov

Posted 01 February 2012 - 03:16 AM

I can share source code, if it'll helps you at c++ learning)
Posted Image
Posted Image

#11 asnowcappedromance

asnowcappedromance

    Initiate

  • Members
  • PipPip
  • 158 posts
  • Joined: 18-October 09
  • Location:Vancouver, B.C.
  • Name:Manuel Tausch

Posted 01 February 2012 - 02:39 PM

View Postvi_rus, on 01 February 2012 - 03:16 AM, said:

I can share source code, if it'll helps you at c++ learning)

much appreciated Sergei, I sent you a pm!

Oh and thanks for that link, Jason, I'll have a look at that!

cheers!

Manuel Tausch
senior FX TD - Rhythm & Hues

#12 hyperforce

hyperforce

    Peon

  • Members
  • Pip
  • 34 posts
  • Joined: 07-November 10
  • Location:Heeze, Netherlands
  • Name:Erwin Heyms

Posted 25 March 2012 - 01:04 PM

Hi Asnowcappedromance,

I have to say great work on implementing Dijkstra's algorithm.

I have a question.

I'm currently working on my specialization/graduation (graduation year) college program at IGAD-NHTV.

My project is to find a way to create a generator that can build functional and playable multiplayer levels that can be exported to a game engine.
I've been looking at different methods to make the generator construct logical corridors throughout my levels and a
path-finding solution seems to be the most promising.
I am however no programmer and know nothing when it comes to python script.

Would I be allowed to use your solution in my research and potentially my graduation project?
You will of course be referenced and credited for the method and OTL if I succeed in implementing it into a working solution.

Edited by hyperforce, 25 March 2012 - 01:06 PM.

My Procedural FPS level generator:
http://forums.odforc...vel-generation/

Email: erwinheyms@gmail.com




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users