Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 1st, 2013, 10:51 AM
Osvaldos88 Osvaldos88 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 1 Osvaldos88 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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?

Reply With Quote
  #2  
Old January 1st, 2013, 12:58 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,350 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 7 h 38 m 45 sec
Reputation Power: 383
1) Please provide sample input.
2) Leading white space is a key element of python syntax. Please follow and read the link at my signature to preserve your program indentation.
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Help in programming

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

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


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap