473,395 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

SPA - Best way of implementation

hello,

i'm looking for a good method to create an short
path algorithm like dijkstra. well.. i hope that
i can find someone that already integrated spa's
with python.

my goal is to find ways from contact-person A to
contact-person B. but i have to save and sort
all the possible ways in a depth of about nine
max hops like this:

user A knows user K
user K knows user R
user R knows user B and C
user B knows user I
user I knows user C

now i'm looking for a way from a to c:

A -> K -> R -> C
or
A -> K -> R -> B -> I -> C
target usage:

<< FROM = 'A'
<< TO = 'C'
<< MAXHOPS = 9
<< ways = []
<< ways = find(FROM,TO,MAXHOPS)
<< print ways
[{'A','K','R','C'},{'A','K','R','B','I','C'}]


:-)
so guys.. any ideas for a short, fast and
"simple" implementation with about 20 lines of code? :-)

greetings
andy

Jul 18 '05 #1
1 1322
Here's an algorithm to find the shortest path from start to end. It is
not Dijkstra's "single source shortest paths" algorithm, and that a
crucial step of the BFS is O(|queue|) instead of O(1).

def shortest_path(start, end, adj):
seen = {start: None} # XXX use sets here instead
queue = [[start]]

while queue:
partial = queue.pop(0) # XXX this is O(|queue|)
tail = partial[-1]
for edge in adj[tail]:
if edge in seen: continue
seen[edge] = None
next_partial = partial + [edge]
if edge == end:
return next_partial
queue.append(next_partial)
edges = {'A': 'K', 'K': 'R', 'R': 'BC', 'B': 'I', 'I': 'C'}
"".join(mallek.shortest_path('A', 'C', edges))

'AKRC'

Jeff

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFAweFJJd01MZaTXX0RAsMcAJ0RaVgTZLX1BY81ETtenN qcsx6tdwCeJ2qI
Ar2qtU3D1BI/eNuCajeYUuY=
=h3ez
-----END PGP SIGNATURE-----

Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Chuck Ritzke | last post by:
I keep asking myself this question as I write class modules. What's the best/smartest/most efficient way to send a large object back and forth to a class module? For example, say I have a data...
11
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in...
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
2
by: Natan | last post by:
I have been using an implementation of that Paul Wilson`s master pages for asp.net 1.1. It`s nice, but there is a problem that generally in big sites, templates must be based on other templates, or...
14
by: Jon Rea | last post by:
I am currently cleaning up an application which was origainlly hashed together with speed of coding in mind and therefore contains quite a few "hacky" shortcuts. As part of this "revamping"...
3
by: _DD | last post by:
I believe Balena's Best Practices book suggests grouping quite a few classes into each namespace. I don't remember a number, but this has me curious about how other programmers handle this. If...
13
by: Alan Silver | last post by:
Hello, MSDN (amongst other places) is full of helpful advice on ways to do data access, but they all seem geared to wards enterprise applications. Maybe I'm in a minority, but I don't have those...
20
by: int main(void) | last post by:
Hi all, What do you people think as the best libc implementation. I'm a newbie, browsing through the open source codes of various libc implementation. I want to what is the best libc...
9
by: raylopez99 | last post by:
What's the best way of implementing a multi-node tree in C++? What I'm trying to do is traverse a tree of possible chess moves given an intial position (at the root of the tree). Since every...
21
by: Owen Zhang | last post by:
What is the best way to implement "tail -f" in C or C++ and higher performance compared to either unix shell command "tail -f" or perl File::Tail ? Any suggestion appreciated. Thanks.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.