New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Recursion bug in deepcopy #47293
Comments
With the following code: class Edge:
def __init__(self, V1, V2):
self.vertexes=[V1, V2]
V1.edges.append(self)
V2.edges.append(self) Where the references are cyclic(this is for a research project into |
Whoops, sorry, correction, when there are 100 vertexes and 500 edges. |
This should have been fixed at 2.2, as long as you change your classes |
Same problem, even with new-style classes. Here, I'll show the function class Vertex(object):
def __init__(self, type):
self.type = type
self.color=-1
self.edges=[]
class Edge(object):
def __init__(self, V1, V2):
self.vertexes=[V1, V2]
V1.edges.append(self)
V2.edges.append(self)
def generate(graph={'V':[], 'E':[]}, seed=777, vertexes=5, edges=25):
#generates a graph similar to the KEGG pathway database format.
# Purpose is for testing algorithms on a smaller scale "predicatible" graph
# For that reason, the "random" selections are seeded with a known
number. This is to be able
# to measure efficacy, in that on the same graph, if algorithm A
performs in half the time, its
# not a characteristic of the graph, but the algorithm.
r=random.Random(seed)
p=[0, 0, 0, 0]
c=0
#generate vertices, with a regularly incremented set of numbers, to
appear like the KEGG pathway database does.
while c!=vertexes:
#This is ugly, could be done easier in a loop. Fix later.
p[3]+=1
if p[3]>9:
p[3]=0
p[2]+=1
if p[2]>9:
p[2]=0
p[1]+=1
if p[1]>9:
p[1]=0
p[0]+=1
#we copy the set of numbers, due to the way python passes lists by
reference, instead of by copy.
v=Vertex(p[:])
graph['V'].append(v)
c+=1
v=graph['V']
if len(v)!=vertexes:
print "Not enough vertices, aborting."
return graph
c=0
#randomly choose two vertices. Could even, randomly, be the same vertex.
# Then, connect an edge between them. Just creating the edge by
implication,
# with the vertices passed, connects them all together.
while c!=edges:
v1=r.choice(v)
v2=r.choice(v)
graph['E'].append(Edge(v1, v2))
c+=1
if len(graph['E']) !=edges:
print "Not enough edges, aborting."
return graph And here is how I use it:
Thanks for the prompt response, this isn't critical in nature, just -Zeroth |
Your graph is simply too deep for Python to handle it. The copy module If you want, you can carefully increase the limit by using the function >>> sys.setrecursionlimit(2000) |
Two weeks passed, closing it manually (see |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: