473,513 Members | 2,263 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

dijkstra algorithm by object oriented

I need that someone help me.

I need to program the dijkstra algorithm by object oriented.

I'll send my code.

#!/usr/bin/env python
# -*- encoding: latin -*-

NIL = []
INF = 9999

G = { "Vertices" : [ 0, 1, 2, 3, 4, 5, 6 ],
"Adjacentes" : { 0 : {1: 5, 2: 4},
1 : {3: 7, 5: 3},
2 : {4: 7},
3 : {2: 6},
4 : {5: 2},
5 : {6: 3},
6 : {}
}
} # definição do grafo

# 0 1 2 3 4 5 6
W = [ [0 , 5 , 4 , INF, INF, INF, INF],
[INF, 0 , INF, 7 , INF, 3 , INF],
[INF, INF, 0 , INF, 7 , INF, INF],
[INF, INF, 6 , 0 , INF, INF, INF],
[INF, INF, INF, INF, 0 , 2 , INF],
[INF, INF, INF, INF, INF, 0 , 3 ],
[INF, INF, INF, INF, INF, INF, 0 ] ]
def adjMatrix( ):
w = NIL
for i in G["Vertices"]:
w.append( [] )
for i in G["Vertices"]:
for j in G["Vertices"]:
if i == j:
w[i].append( 0 )
else:
w[i].append( INF )
for y in range(len( w )):
aux1 = G[ "Adjacentes" ][ y ].keys( )
aux2 = G[ "Adjacentes" ][ y ].values( )
for i in range( len( w ) ):
for j in range( len( aux1 ) ):
if i == aux1[ j ]:
w[ y ][ i ] = aux2[ j ]
return w

d = {}
pi = {}
Q = {}

def initialize_Single_Source( G, s ):
for v in G[ "Vertices" ]:
d[ v ] = INF
pi[ v ] = NIL
d[ s ] = 0

def relax( u, v, w ):
if d[ v ] > d[ u ] + w[ u ][ v ]:
d[ v ] = d[ u ] + w[ u ][ v ]
pi[ v ] = u

def dijkstra( G, w, s ):
initialize_Single_Source( G, s )
S = []
Q = G[ "Vertices" ]
while Q != []:
u = extract_Min( Q )
S.append( u )
for v in G[ "Adjacentes" ]:
relax(u, v, w)
print "d:",d
print "pi:",pi

def extract_Min( Q ):
m = min( Q )
Q.remove( m )
return m

dijkstra( G, adjMatrix(), 0 )
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.788 / Virus Database: 533 - Release Date: 01-11-2004

Jul 18 '05 #1
2 4180
Ricardo Batista wrote:
I need that someone help me.

I need to program the dijkstra algorithm by object oriented.

I'll send my code.


Thanks, but you haven't asked a question. Thus it sounds
as though you are simply asking for someone to make your
code work correctly. Or maybe you're asking for someone
to convert it from the style shown to an object oriented
approach.

Either way, it sounds a lot like this is a homework question
for school, so I really hope nobody is going to just do the
work for you, since you won't learn anything that way.

Please reconsider what you are trying to do and ask a
specific question, demonstrating that you have made a
reasonable attempt to solve the problem yourself first.

-Peter
Jul 18 '05 #2
Ricardo Batista wrote:
I need that someone help me.
No, you need to do your own work like everybody else.
I need to program the dijkstra algorithm by object oriented.


No, you don't, and you should tell your professor to unsubscribe from
silver-bullet OO hype and realize that OO has little to add to
mathematical problems like this.

Dijkstra must be rolling in his grave.

Dave
Jul 18 '05 #3

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

Similar topics

6
5870
by: ThanhVu Nguyen | last post by:
Hi all, I need recommendation for a very fast shortest path algorithm. The edges are all directed, positive weights. Dijkstra shortest path will solve it just fine but the if the graph is not...
10
4956
by: bpontius | last post by:
The GES Algorithm A Surprisingly Simple Algorithm for Parallel Pattern Matching "Partially because the best algorithms presented in the literature are difficult to understand and to implement,...
3
6224
by: A_StClaire_ | last post by:
implemented Dijkstra's algorithm as follows. plz pour on the negative criticism cuz I know I have a ton to learn. oh, before you flame me regarding the language, my class was told to do this in...
3
5004
by: Ook | last post by:
This is probably a bit OT, as I'm not looking for a c++ implementaiton of Dijkstra's algorithm, rather I'm just trying to understand it (is there a better place then here to ask this question?)....
1
16110
by: arlef | last post by:
Can somebody please explain and provide pseudocode for the Dijkstra algorithm? I'm trying to implement the Dijkstra shortest path algorithm. However, I'm finding it extremely difficult to...
9
4496
by: Josh Zenker | last post by:
I've been working on an implementation of Dijkstra's algorithm on and off for the past few days. I thought I was close to being finished, but clearly I've done something wrong. I'm not a very...
1
5109
Ganon11
by: Ganon11 | last post by:
Hey guys, I'm back, and with another FUN question! My latest homework asks this question: "Suppose all the edge weights in a graph are integers between 1 and |E|. How fast can Dijkstra's...
2
4638
by: shashankbs | last post by:
Given a topology and a certain node X, find the shortest path tree with X as the root. * Input: a topology file similar to the following (which is a three-node ring) ...
1
14188
by: Glenton | last post by:
Hi All Here is a very simple little class for finding a shortest route on a network, following Dijkstra's Algorithm: #!/usr/bin/env python #This is meant to solve a maze with Dijkstra's...
0
7265
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7171
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
7388
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
7547
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
5693
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,...
0
3240
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1607
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
807
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
461
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.