[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [pygame] Does anyone have a python implementation of A*?



Magnus Lie Hetland wrote:

> Fredrik Aronsson <d98aron@dtek.chalmers.se>:
> > Me and a friend implemented dijkstra shortest path both in Python and in C
> > for a school project. (A difficult VRP problem). The C implementation was
> > about 100 times faster than the Python one. This type of
> > algorithms with heavy calculations and nested loops seems to be a lot
> > faster in C.
> > Just a hint...
> 
> I've been thinking about some shortest-path algorithms in Numeric. I
> guess that would speed things up considerably -- and you'll probably
> have Numeric installed if you're running PyGame anyway, so...
> 
> (And I don't think a Python implementation of Dijkstra's algorithm
> would have to be _that_ much slower than a C implementation. I guess
> it depends on what "Python weaknesses" you're able to eliminate :)
 
Switched from the for-loop over new nodes to list comprehensions. Got
over a 100x speedup! What took just over a second before, now takes
around .08 seconds. I had thought it would help, but I didn't think it
would this much. Goes to show you're point a bit I think. :)

-- 

John Eikenberry
[jae@zhar.net - http://zhar.net]
______________________________________________________________
"They who can give up essential liberty to purchase a little temporary
 safety, deserve neither liberty nor safety."
                                          --B. Franklin
____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org