
January 1st, 2013, 10:51 AM
|
|
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=[]
def readGraph(self,f):
s=f.readline()
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):
s=f.readline()
a=s.split()
u=int(a[0]); v=int(a[1]);
self.addEdge(u,v)
def addEdge(self,u,v):
if ([u,v] in self.lofedges):
return
(self.edges[u]).add(v)
(self.edges[v]).add(u)
(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?
|