Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

#1
January 1st, 2013, 10:51 AM
 Osvaldos88
Registered User

Join Date: Jan 2013
Posts: 1
Time spent in forums: 15 m 3 sec
Reputation Power: 0
Help in programming

Hi I'm a student in informatic, first year. For a course I need to implement a program in python that solves the problem of disjoint paths in Graph.

My prof gives a part of the code that I should complete, this:

class Graph:

def __init__(self):
self.n=0
self.m=0
self.lofedges=[]
self.edges=[]

a=s.split()
self.n=int(a[0]); m=int(a[1]);
self.edges=[set([]) for i in range(self.n)]
for i in range(m):
a=s.split()
u=int(a[0]); v=int(a[1]);

if ([u,v] in self.lofedges):
return
(self.lofedges).append([u,v])
(self.lofedges).append([v,u])
self.m=self.m+1

def isEdge(self,u,v):
return (u in self.edges[v])

def removeEdge(self,u,v):
if ([u,v] in self.lofedges):
(self.edges[u]).remove(v)
(self.edges[v]).remove(u)
(self.lofedges).remove([u,v])
(self.lofedges).remove([v,u])
self.m=self.m-1;

def allPairs(self):
print "not implemented"

def removePath(self,u,v):
print "not implemented"

I should complete allpairs and removepath, but I think it's too hard to do it and understand how my prof have made the algorithm.
So anyone can help make a simple version af this algorithm, easier to understand?

#2
January 1st, 2013, 12:58 PM
 b49P23TIvg
Contributing User

Join Date: Aug 2011
Posts: 3,350
Time spent in forums: 1 Month 2 Weeks 3 Days 7 h 38 m 45 sec
Reputation Power: 383
3) Please demonstrate that you made an effort to understand the program.

Looks like each edge is bi-directional. No "1 way streets".

ps. Hey! The "quote post" trick works to recover the spaces! Thank you again.
__________________
[code]Code tags[/code] are essential for python code!

Last edited by b49P23TIvg : January 1st, 2013 at 01:06 PM.

 Viewing: Dev Shed Forums > Programming Languages > Python Programming > Help in programming