Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #109768 > unrolled thread
| Started by | meInvent bbird <jobmattcon@gmail.com> |
|---|---|
| First post | 2016-06-09 17:58 -0700 |
| Last post | 2016-06-10 22:55 -0700 |
| Articles | 16 — 6 participants |
Back to article view | Back to comp.lang.python
how to solve memory meInvent bbird <jobmattcon@gmail.com> - 2016-06-09 17:58 -0700
Re: how to solve memory Michael Torrie <torriem@gmail.com> - 2016-06-09 19:12 -0600
Re: how to solve memory meInvent bbird <jobmattcon@gmail.com> - 2016-06-09 21:59 -0700
Re: how to solve memory Steven D'Aprano <steve@pearwood.info> - 2016-06-11 00:07 +1000
Almost crashing computer, was Re: how to solve memory Peter Otten <__peter__@web.de> - 2016-06-10 16:41 +0200
Re: how to solve memory meInvent bbird <jobmattcon@gmail.com> - 2016-06-10 08:00 -0700
Re: how to solve memory meInvent bbird <jobmattcon@gmail.com> - 2016-06-10 08:23 -0700
Re: how to solve memory meInvent bbird <jobmattcon@gmail.com> - 2016-06-10 16:23 -0700
Re: how to solve memory John Gordon <gordon@panix.com> - 2016-06-10 14:46 +0000
Re: how to solve memory meInvent bbird <jobmattcon@gmail.com> - 2016-06-10 08:08 -0700
Re: how to solve memory John Gordon <gordon@panix.com> - 2016-06-10 16:26 +0000
Re: how to solve memory meInvent bbird <jobmattcon@gmail.com> - 2016-06-10 16:31 -0700
Re: how to solve memory MRAB <python@mrabarnett.plus.com> - 2016-06-11 01:33 +0100
Re: how to solve memory meInvent bbird <jobmattcon@gmail.com> - 2016-06-10 21:43 -0700
Re: how to solve memory meInvent bbird <jobmattcon@gmail.com> - 2016-06-10 22:18 -0700
Re: how to solve memory meInvent bbird <jobmattcon@gmail.com> - 2016-06-10 22:55 -0700
| From | meInvent bbird <jobmattcon@gmail.com> |
|---|---|
| Date | 2016-06-09 17:58 -0700 |
| Subject | how to solve memory |
| Message-ID | <4f853aa2-cc00-480b-9fd7-79b05cbd4889@googlegroups.com> |
https://drive.google.com/file/d/0Bxs_ao6uuBDULVNsRjZSVjdPYlE/view?usp=sharing
M1 = {}
M2 = {}
M3 = {}
M4 = {}
M5 = {}
V6 = {}
M1['00']=0
M1['01']=2
M1['02']=1
M1['10']=1
M1['11']=1
M1['12']=1
M1['20']=1
M1['21']=1
M1['22']=2
M2['00']=0
M2['01']=1
M2['02']=1
M2['10']=1
M2['11']=1
M2['12']=1
M2['20']=1
M2['21']=1
M2['22']=1
M3['00']=2
M3['01']=2
M3['02']=2
M3['10']=0
M3['11']=2
M3['12']=1
M3['20']=0
M3['21']=1
M3['22']=2
M4['00']=1
M4['01']=2
M4['02']=1
M4['10']=2
M4['11']=2
M4['12']=2
M4['20']=0
M4['21']=1
M4['22']=2
M5['00']=0
M5['01']=1
M5['02']=1
M5['10']=0
M5['11']=2
M5['12']=1
M5['20']=0
M5['21']=1
M5['22']=1
V6['00']=1
V6['01']=1
V6['02']=2
V6['10']=1
V6['11']=2
V6['12']=1
V6['20']=1
V6['21']=2
V6['22']=2
MM = {}
MM[0] = M1
MM[1] = M2
MM[2] = M3
MM[3] = M4
MM[4] = M5
MM[5] = V6
m = 3
b = [str(i)+str(j)+str(k) for i in range(m) for j in range(m) for k in range(m)]
import itertools
deep = 3
final = []
mylist = [MM[i] for i in range(0,7-1)]
b = [str(i)+str(j)+str(k) for i in range(m) for j in range(m) for k in range(m)]
def DFS(b, deep, maxx, sourceoperators, path):
initlist = []
if deep > 0:
print("deep=", deep)
for aa,bb in itertools.combinations(sourceoperators, 2):
print(aa,bb)
if deep == maxx:
finalresult = []
op1xy = [aa[b[i][0:1]+b[i][1:2]] for i in range(len(b))]
op1yz = [aa[b[i][1:2]+b[i][2:3]] for i in range(len(b))]
op1xz = [aa[b[i][0:1]+b[i][2:3]] for i in range(len(b))]
op2xy = [bb[b[i][0:1]+b[i][1:2]] for i in range(len(b))]
op2yz = [bb[b[i][1:2]+b[i][2:3]] for i in range(len(b))]
op2xz = [bb[b[i][0:1]+b[i][2:3]] for i in range(len(b))]
if sum(op1xy) == 54:
path.append([(deep, aa, "xy")])
if sum(op1yz) == 54:
path.append([(deep, aa, "yz")])
if sum(op1xz) == 54:
path.append([(deep, aa, "xz")])
if sum(op2xy) == 54:
path.append([(deep, bb, "xy")])
if sum(op2yz) == 54:
path.append([(deep, bb, "yz")])
if sum(op2xz) == 54:
path.append([(deep, bb, "xz")])
initlist.append(op1xy)
initlist.append(op1yz)
initlist.append(op1xz)
initlist.append(op2xy)
initlist.append(op2yz)
initlist.append(op2xz)
else:
level = []
for j in range(len(b)):
op1xy = [aa[b[j][i]] for i in range(len(b[j]))]
op2xy = [bb[b[j][i]] for i in range(len(b[j]))]
if sum(op1xy) == 54:
path.append([(deep, aa, "xy")])
if sum(op2xy) == 54:
path.append([(deep, bb, "xy")])
level.append(op1xy)
level.append(op2xy)
initlist.append(op1xy)
initlist.append(op2xy)
if deep == maxx:
b = []
#print(len(list(itertools.combinations(initlist, 2))))
for aaa,bbb in itertools.combinations(initlist, 2):
b.append([str(i)+str(j) for i,j in zip(aaa, bbb)])
path = DFS(b, deep-1, maxx, sourceoperators, path)
else:
#print(len(list(itertools.combinations(initlist, 2))))
for aaa,bbb in itertools.combinations(initlist, 2):
b.append([str(i)+str(j) for i,j in zip(aaa, bbb)])
path = DFS(b, deep-1, maxx, sourceoperators, path)
return path
path = []
mresult = DFS(b, 2, 2, mylist, path)
[toc] | [next] | [standalone]
| From | Michael Torrie <torriem@gmail.com> |
|---|---|
| Date | 2016-06-09 19:12 -0600 |
| Message-ID | <mailman.129.1465521179.2306.python-list@python.org> |
| In reply to | #109768 |
On 06/09/2016 06:58 PM, meInvent bbird wrote: > <snip> Do you have a question for the list? If so, please state what it is, and describe what you are doing and what isn't working. If you can boil it down to a dozen lines of run-able, self-contained code that illustrates the problem, that is helpful too.
[toc] | [prev] | [next] | [standalone]
| From | meInvent bbird <jobmattcon@gmail.com> |
|---|---|
| Date | 2016-06-09 21:59 -0700 |
| Message-ID | <fc5bcd84-31f5-4007-b0b7-9cbde651b027@googlegroups.com> |
| In reply to | #109770 |
On Friday, June 10, 2016 at 9:13:13 AM UTC+8, Michael Torrie wrote: > On 06/09/2016 06:58 PM, meInvent bbird wrote: > > <snip> > > Do you have a question for the list? If so, please state what it is, and > describe what you are doing and what isn't working. If you can boil it > down to a dozen lines of run-able, self-contained code that illustrates > the problem, that is helpful too. there are six operator, and a logic table initial in b variable aa[b[j][i]] [aa[b[i][0:1]+b[i][2:3] are just like vlookup to find output of each operator acting on first column and second column, second column and third column , first column and third column and searching a output columns which is result sum is 27*2 and record the path if succeed, it record the path and output any path which has result is 27*2 described before op1(op2(op3(op1(op2(),),op1(op2(),))), op1(op2(),)) there are two cases, first cases b are logic table later case are for six operators acting on the result column from previous result before recursive call
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve@pearwood.info> |
|---|---|
| Date | 2016-06-11 00:07 +1000 |
| Message-ID | <575ac991$0$1583$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #109768 |
On Fri, 10 Jun 2016 10:58 am, meInvent bbird wrote:
[snip unreadable code]
I just ran your code, and it almost crashed my computer. I think it is quite
rude to post code without an explanation of what the problem is.
I'm afraid that your code is virtually unreadable to me. It is too verbose,
the indentation is awful (single space indents is impossible for me to
track by eye) and it makes too much work out of simple operations. And none
of the variable names mean anything.
I've started to simplify and clean the code, and got to the following, which
I hope you will agree is easier to read and more compact:
import itertools
M1 = {'00': 0, '01': 2, '02': 1, '10': 1, '11': 1,
'12': 1, '20': 1, '21': 1, '22': 2}
M2 = {'00': 0, '01': 1, '02': 1, '10': 1, '11': 1,
'12': 1, '20': 1, '21': 1, '22': 1}
M3 = {'00': 2, '01': 2, '02': 2, '10': 0, '11': 2,
'12': 1, '20': 0, '21': 1, '22': 2}
M4 = {'00': 1, '01': 2, '02': 1, '10': 2, '11': 2,
'12': 2, '20': 0, '21': 1, '22': 2}
M5 = {'00': 0, '01': 1, '02': 1, '10': 0, '11': 2,
'12': 1, '20': 0, '21': 1, '22': 1}
# Why V instead of M?
V6 = {'00': 1, '01': 1, '02': 2, '10': 1, '11': 2,
'12': 1, '20': 1, '21': 2, '22': 2}
MM = {0: M1, 1: M2, 2: M3, 3: M4, 4: M5, 5: V6}
m = 3
b = [str(i)+str(j)+str(k) for i in range(m)
for j in range(m) for k in range(m)]
mylist = [MM[i] for i in range(6)]
def DFS(b, deep, maxx, sourceoperators, path):
initlist = []
if deep > 0:
print("deep=", deep)
for aa,bb in itertools.combinations(sourceoperators, 2):
print(aa,bb)
if deep == maxx:
finalresult = []
op1xy = [aa[b[i][0:1]] for i in range(len(b))]
op1yz = [aa[b[i][1:2]] for i in range(len(b))]
op1xz = [aa[b[i][0]+b[i][2]] for i in range(len(b))]
op2xy = [bb[b[i][0:1]] for i in range(len(b))]
op2yz = [bb[b[i][1:2]] for i in range(len(b))]
op2xz = [bb[b[i][0]+b[i][2]] for i in range(len(b))]
if sum(op1xy) == 54:
path.append([(deep, aa, "xy")])
if sum(op1yz) == 54:
path.append([(deep, aa, "yz")])
if sum(op1xz) == 54:
path.append([(deep, aa, "xz")])
if sum(op2xy) == 54:
path.append([(deep, bb, "xy")])
if sum(op2yz) == 54:
path.append([(deep, bb, "yz")])
if sum(op2xz) == 54:
path.append([(deep, bb, "xz")])
initlist.extend([op1xy, op1yz, op1xz, op2xy, op2yz, op2xz])
else:
level = []
for j in range(len(b)):
op1xy = [aa[b[j][i]] for i in range(len(b[j]))]
op2xy = [bb[b[j][i]] for i in range(len(b[j]))]
if sum(op1xy) == 54:
path.append([(deep, aa, "xy")])
if sum(op2xy) == 54:
path.append([(deep, bb, "xy")])
level.extend([op1xy, op2xy])
initlist.extend([op1xy, op2xy])
if deep == maxx:
b = []
for aaa,bbb in itertools.combinations(initlist, 2):
b.append([str(i)+str(j) for i,j in zip(aaa, bbb)])
path = DFS(b, deep-1, maxx, sourceoperators, path)
return path
path = []
mresult = DFS(b, 2, 2, mylist, path)
Unfortunate, in cleaning up your code, I have changed something, because my
version and your version do not do the same thing.
After nearly crashing my computer running your version, I am not going to
spend the time trying to debug this. If you want our help, I suggest that
you clean up the code. Currently it is an incomprehensible mess to me. Even
after the cleanup, I have no idea what this piece of code is supposed to do
or what it is calculating.
Can you explain the purpose of the code? What is it calculating? Can you
show the expected results? What does "DFS" mean? Why do you have M1 - M5
but then a mysterious V6?
I can see you are calculating *something* to do with permutations of 0 1 2,
but I don't understand what.
I think I can see one problem: DFS is a recursive function, but it never
ends the recursion. It ALWAYS calls DFS(... deep-1, ...) even if deep is
zero. So I expect that you will have an infinite loop that just recurses
over and over, until you run out of memory or hit the recursion limit.
--
Steven
[toc] | [prev] | [next] | [standalone]
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Date | 2016-06-10 16:41 +0200 |
| Subject | Almost crashing computer, was Re: how to solve memory |
| Message-ID | <mailman.140.1465569713.2306.python-list@python.org> |
| In reply to | #109788 |
Steven D'Aprano wrote:
> I just ran your code, and it almost crashed my computer.
When you suspect that a script may consume a lot of memory (the subject
might have been a hint)
ulimit (bash internal)
helps you prevent that your linux machine becomes unresponsive.
$ ulimit -v 200000
$ python3 tmp2.py > /dev/null
Traceback (most recent call last):
File "tmp2.py", line 134, in <module>
mresult = DFS(b, 2, 2, mylist, path)
File "tmp2.py", line 125, in DFS
path = DFS(b, deep-1, maxx, sourceoperators, path)
File "tmp2.py", line 129, in DFS
b.append([str(i)+str(j) for i,j in zip(aaa, bbb)])
File "tmp2.py", line 129, in <listcomp>
b.append([str(i)+str(j) for i,j in zip(aaa, bbb)])
MemoryError
[toc] | [prev] | [next] | [standalone]
| From | meInvent bbird <jobmattcon@gmail.com> |
|---|---|
| Date | 2016-06-10 08:00 -0700 |
| Message-ID | <7cc811f2-b90d-401d-beae-041b1fdff1af@googlegroups.com> |
| In reply to | #109788 |
i put final part of code inside one more space
and add constraint deep > 0
but still memory error
and print the deep number to see, it do not run infinity again
V6 is just my superstitution, because V is disable 6 is separation
i run your version directly, it has key = '0' error
M1 = {}
M2 = {}
M3 = {}
M4 = {}
M5 = {}
V6 = {}
M1['00']=0
M1['01']=1
M1['02']=2
M1['10']=1
M1['11']=1
M1['12']=2
M1['20']=2
M1['21']=2
M1['22']=2
M2['00']=0
M2['01']=0
M2['02']=2
M2['10']=0
M2['11']=1
M2['12']=2
M2['20']=2
M2['21']=2
M2['22']=2
M3['00']=0
M3['01']=0
M3['02']=0
M3['10']=0
M3['11']=1
M3['12']=2
M3['20']=0
M3['21']=2
M3['22']=2
M4['00']=0
M4['01']=1
M4['02']=0
M4['10']=1
M4['11']=1
M4['12']=1
M4['20']=0
M4['21']=1
M4['22']=2
M5['00']=0
M5['01']=0
M5['02']=0
M5['10']=0
M5['11']=1
M5['12']=2
M5['20']=0
M5['21']=2
M5['22']=2
V6['00']=2
V6['01']=2
V6['02']=2
V6['10']=1
V6['11']=2
V6['12']=2
V6['20']=0
V6['21']=1
V6['22']=2
MM = {}
MM[0] = M1
MM[1] = M2
MM[2] = M3
MM[3] = M4
MM[4] = M5
MM[5] = V6
m = 3
b = [str(i)+str(j)+str(k) for i in range(m) for j in range(m) for k in range(m)]
import itertools
deep = 3
final = []
mylist = [MM[i] for i in range(0,7-1)]
b = [str(i)+str(j)+str(k) for i in range(m) for j in range(m) for k in range(m)]
def DFS(b, deep, maxx, sourceoperators, path):
initlist = []
if deep > 0:
print("deep=", deep)
for aa,bb in itertools.combinations(sourceoperators, 2):
print(aa,bb)
if deep == maxx:
finalresult = []
op1xy = [aa[b[i][0:1]+b[i][1:2]] for i in range(len(b))]
op1yz = [aa[b[i][1:2]+b[i][2:3]] for i in range(len(b))]
op1xz = [aa[b[i][0:1]+b[i][2:3]] for i in range(len(b))]
op2xy = [bb[b[i][0:1]+b[i][1:2]] for i in range(len(b))]
op2yz = [bb[b[i][1:2]+b[i][2:3]] for i in range(len(b))]
op2xz = [bb[b[i][0:1]+b[i][2:3]] for i in range(len(b))]
if sum(op1xy) == 54:
path.append([(deep, aa, "xy")])
if sum(op1yz) == 54:
path.append([(deep, aa, "yz")])
if sum(op1xz) == 54:
path.append([(deep, aa, "xz")])
if sum(op2xy) == 54:
path.append([(deep, bb, "xy")])
if sum(op2yz) == 54:
path.append([(deep, bb, "yz")])
if sum(op2xz) == 54:
path.append([(deep, bb, "xz")])
initlist.append(op1xy)
initlist.append(op1yz)
initlist.append(op1xz)
initlist.append(op2xy)
initlist.append(op2yz)
initlist.append(op2xz)
else:
level = []
for j in range(len(b)):
op1xy = [aa[b[j][i]] for i in range(len(b[j]))]
op2xy = [bb[b[j][i]] for i in range(len(b[j]))]
if sum(op1xy) == 54:
path.append([(deep, aa, "xy")])
if sum(op2xy) == 54:
path.append([(deep, bb, "xy")])
level.append(op1xy)
level.append(op2xy)
initlist.append(op1xy)
initlist.append(op2xy)
if deep == maxx:
if deep > 0:
b = []
for aaa,bbb in itertools.combinations(initlist, 2):
b.append([str(i)+str(j) for i,j in zip(aaa, bbb)])
print("deep=")
print(deep)
path = DFS(b, deep-1, maxx, sourceoperators, path)
else:
if deep > 0:
for aaa,bbb in itertools.combinations(initlist, 2):
b.append([str(i)+str(j) for i,j in zip(aaa, bbb)])
print("deep=")
print(deep)
path = DFS(b, deep-1, maxx, sourceoperators, path)
return path
path = []
mresult = DFS(b, 2, 2, mylist, path)
On Friday, June 10, 2016 at 10:08:44 PM UTC+8, Steven D'Aprano wrote:
> On Fri, 10 Jun 2016 10:58 am, meInvent bbird wrote:
>
> [snip unreadable code]
>
> I just ran your code, and it almost crashed my computer. I think it is quite
> rude to post code without an explanation of what the problem is.
>
>
> I'm afraid that your code is virtually unreadable to me. It is too verbose,
> the indentation is awful (single space indents is impossible for me to
> track by eye) and it makes too much work out of simple operations. And none
> of the variable names mean anything.
>
> I've started to simplify and clean the code, and got to the following, which
> I hope you will agree is easier to read and more compact:
>
>
>
> import itertools
> M1 = {'00': 0, '01': 2, '02': 1, '10': 1, '11': 1,
> '12': 1, '20': 1, '21': 1, '22': 2}
> M2 = {'00': 0, '01': 1, '02': 1, '10': 1, '11': 1,
> '12': 1, '20': 1, '21': 1, '22': 1}
> M3 = {'00': 2, '01': 2, '02': 2, '10': 0, '11': 2,
> '12': 1, '20': 0, '21': 1, '22': 2}
> M4 = {'00': 1, '01': 2, '02': 1, '10': 2, '11': 2,
> '12': 2, '20': 0, '21': 1, '22': 2}
> M5 = {'00': 0, '01': 1, '02': 1, '10': 0, '11': 2,
> '12': 1, '20': 0, '21': 1, '22': 1}
> # Why V instead of M?
> V6 = {'00': 1, '01': 1, '02': 2, '10': 1, '11': 2,
> '12': 1, '20': 1, '21': 2, '22': 2}
>
> MM = {0: M1, 1: M2, 2: M3, 3: M4, 4: M5, 5: V6}
> m = 3
> b = [str(i)+str(j)+str(k) for i in range(m)
> for j in range(m) for k in range(m)]
> mylist = [MM[i] for i in range(6)]
>
> def DFS(b, deep, maxx, sourceoperators, path):
> initlist = []
> if deep > 0:
> print("deep=", deep)
> for aa,bb in itertools.combinations(sourceoperators, 2):
> print(aa,bb)
> if deep == maxx:
> finalresult = []
> op1xy = [aa[b[i][0:1]] for i in range(len(b))]
> op1yz = [aa[b[i][1:2]] for i in range(len(b))]
> op1xz = [aa[b[i][0]+b[i][2]] for i in range(len(b))]
> op2xy = [bb[b[i][0:1]] for i in range(len(b))]
> op2yz = [bb[b[i][1:2]] for i in range(len(b))]
> op2xz = [bb[b[i][0]+b[i][2]] for i in range(len(b))]
> if sum(op1xy) == 54:
> path.append([(deep, aa, "xy")])
> if sum(op1yz) == 54:
> path.append([(deep, aa, "yz")])
> if sum(op1xz) == 54:
> path.append([(deep, aa, "xz")])
> if sum(op2xy) == 54:
> path.append([(deep, bb, "xy")])
> if sum(op2yz) == 54:
> path.append([(deep, bb, "yz")])
> if sum(op2xz) == 54:
> path.append([(deep, bb, "xz")])
> initlist.extend([op1xy, op1yz, op1xz, op2xy, op2yz, op2xz])
> else:
> level = []
> for j in range(len(b)):
> op1xy = [aa[b[j][i]] for i in range(len(b[j]))]
> op2xy = [bb[b[j][i]] for i in range(len(b[j]))]
> if sum(op1xy) == 54:
> path.append([(deep, aa, "xy")])
> if sum(op2xy) == 54:
> path.append([(deep, bb, "xy")])
> level.extend([op1xy, op2xy])
> initlist.extend([op1xy, op2xy])
> if deep == maxx:
> b = []
> for aaa,bbb in itertools.combinations(initlist, 2):
> b.append([str(i)+str(j) for i,j in zip(aaa, bbb)])
> path = DFS(b, deep-1, maxx, sourceoperators, path)
> return path
>
> path = []
> mresult = DFS(b, 2, 2, mylist, path)
>
>
>
> Unfortunate, in cleaning up your code, I have changed something, because my
> version and your version do not do the same thing.
>
> After nearly crashing my computer running your version, I am not going to
> spend the time trying to debug this. If you want our help, I suggest that
> you clean up the code. Currently it is an incomprehensible mess to me. Even
> after the cleanup, I have no idea what this piece of code is supposed to do
> or what it is calculating.
>
> Can you explain the purpose of the code? What is it calculating? Can you
> show the expected results? What does "DFS" mean? Why do you have M1 - M5
> but then a mysterious V6?
>
> I can see you are calculating *something* to do with permutations of 0 1 2,
> but I don't understand what.
>
> I think I can see one problem: DFS is a recursive function, but it never
> ends the recursion. It ALWAYS calls DFS(... deep-1, ...) even if deep is
> zero. So I expect that you will have an infinite loop that just recurses
> over and over, until you run out of memory or hit the recursion limit.
>
>
>
> --
> Steven
[toc] | [prev] | [next] | [standalone]
| From | meInvent bbird <jobmattcon@gmail.com> |
|---|---|
| Date | 2016-06-10 08:23 -0700 |
| Message-ID | <d4fd7f57-ce95-42fe-8c27-f5ff98e224fb@googlegroups.com> |
| In reply to | #109788 |
On Friday, June 10, 2016 at 10:08:44 PM UTC+8, Steven D'Aprano wrote:
> On Fri, 10 Jun 2016 10:58 am, meInvent bbird wrote:
>
> [snip unreadable code]
>
> I just ran your code, and it almost crashed my computer. I think it is quite
> rude to post code without an explanation of what the problem is.
>
>
> I'm afraid that your code is virtually unreadable to me. It is too verbose,
> the indentation is awful (single space indents is impossible for me to
> track by eye) and it makes too much work out of simple operations. And none
> of the variable names mean anything.
>
> I've started to simplify and clean the code, and got to the following, which
> I hope you will agree is easier to read and more compact:
>
>
>
> import itertools
> M1 = {'00': 0, '01': 2, '02': 1, '10': 1, '11': 1,
> '12': 1, '20': 1, '21': 1, '22': 2}
> M2 = {'00': 0, '01': 1, '02': 1, '10': 1, '11': 1,
> '12': 1, '20': 1, '21': 1, '22': 1}
> M3 = {'00': 2, '01': 2, '02': 2, '10': 0, '11': 2,
> '12': 1, '20': 0, '21': 1, '22': 2}
> M4 = {'00': 1, '01': 2, '02': 1, '10': 2, '11': 2,
> '12': 2, '20': 0, '21': 1, '22': 2}
> M5 = {'00': 0, '01': 1, '02': 1, '10': 0, '11': 2,
> '12': 1, '20': 0, '21': 1, '22': 1}
> # Why V instead of M?
> V6 = {'00': 1, '01': 1, '02': 2, '10': 1, '11': 2,
> '12': 1, '20': 1, '21': 2, '22': 2}
>
> MM = {0: M1, 1: M2, 2: M3, 3: M4, 4: M5, 5: V6}
> m = 3
> b = [str(i)+str(j)+str(k) for i in range(m)
> for j in range(m) for k in range(m)]
> mylist = [MM[i] for i in range(6)]
>
> def DFS(b, deep, maxx, sourceoperators, path):
> initlist = []
> if deep > 0:
> print("deep=", deep)
> for aa,bb in itertools.combinations(sourceoperators, 2):
> print(aa,bb)
> if deep == maxx:
> finalresult = []
> op1xy = [aa[b[i][0:1]] for i in range(len(b))]
> op1yz = [aa[b[i][1:2]] for i in range(len(b))]
> op1xz = [aa[b[i][0]+b[i][2]] for i in range(len(b))]
> op2xy = [bb[b[i][0:1]] for i in range(len(b))]
> op2yz = [bb[b[i][1:2]] for i in range(len(b))]
> op2xz = [bb[b[i][0]+b[i][2]] for i in range(len(b))]
> if sum(op1xy) == 54:
> path.append([(deep, aa, "xy")])
> if sum(op1yz) == 54:
> path.append([(deep, aa, "yz")])
> if sum(op1xz) == 54:
> path.append([(deep, aa, "xz")])
> if sum(op2xy) == 54:
> path.append([(deep, bb, "xy")])
> if sum(op2yz) == 54:
> path.append([(deep, bb, "yz")])
> if sum(op2xz) == 54:
> path.append([(deep, bb, "xz")])
> initlist.extend([op1xy, op1yz, op1xz, op2xy, op2yz, op2xz])
> else:
> level = []
> for j in range(len(b)):
> op1xy = [aa[b[j][i]] for i in range(len(b[j]))]
> op2xy = [bb[b[j][i]] for i in range(len(b[j]))]
> if sum(op1xy) == 54:
> path.append([(deep, aa, "xy")])
> if sum(op2xy) == 54:
> path.append([(deep, bb, "xy")])
> level.extend([op1xy, op2xy])
> initlist.extend([op1xy, op2xy])
> if deep == maxx:
> b = []
> for aaa,bbb in itertools.combinations(initlist, 2):
> b.append([str(i)+str(j) for i,j in zip(aaa, bbb)])
> path = DFS(b, deep-1, maxx, sourceoperators, path)
> return path
>
> path = []
> mresult = DFS(b, 2, 2, mylist, path)
>
>
>
> Unfortunate, in cleaning up your code, I have changed something, because my
> version and your version do not do the same thing.
>
> After nearly crashing my computer running your version, I am not going to
> spend the time trying to debug this. If you want our help, I suggest that
> you clean up the code. Currently it is an incomprehensible mess to me. Even
> after the cleanup, I have no idea what this piece of code is supposed to do
> or what it is calculating.
>
> Can you explain the purpose of the code? What is it calculating? Can you
> show the expected results? What does "DFS" mean? Why do you have M1 - M5
> but then a mysterious V6?
>
> I can see you are calculating *something* to do with permutations of 0 1 2,
> but I don't understand what.
>
> I think I can see one problem: DFS is a recursive function, but it never
> ends the recursion. It ALWAYS calls DFS(... deep-1, ...) even if deep is
> zero. So I expect that you will have an infinite loop that just recurses
> over and over, until you run out of memory or hit the recursion limit.
>
>
>
> --
> Steven
i recorded a video to show what i am searching for
https://drive.google.com/file/d/0Bxs_ao6uuBDUbjFxbjJReXZoNHc/view?usp=sharing
something i hide because i invented some math, hope your mercy.
[toc] | [prev] | [next] | [standalone]
| From | meInvent bbird <jobmattcon@gmail.com> |
|---|---|
| Date | 2016-06-10 16:23 -0700 |
| Message-ID | <28a63efe-9096-4914-8cce-2dc1861d3776@googlegroups.com> |
| In reply to | #109788 |
i put final part of code inside one more space
and add constraint deep > 0
but still memory error
and print the deep number to see, it do not run infinity again
V6 is just my superstitution, because V is disable 6 is separation
i run your version directly, it has key = '0' error
M1 = {}
M2 = {}
M3 = {}
M4 = {}
M5 = {}
V6 = {}
M1['00']=0
M1['01']=1
M1['02']=1
M1['10']=2
M1['11']=2
M1['12']=1
M1['20']=1
M1['21']=1
M1['22']=1
M2['00']=0
M2['01']=1
M2['02']=1
M2['10']=1
M2['11']=2
M2['12']=2
M2['20']=1
M2['21']=1
M2['22']=1
M3['00']=0
M3['01']=1
M3['02']=1
M3['10']=0
M3['11']=1
M3['12']=2
M3['20']=0
M3['21']=2
M3['22']=2
M4['00']=0
M4['01']=1
M4['02']=0
M4['10']=1
M4['11']=2
M4['12']=2
M4['20']=0
M4['21']=1
M4['22']=1
M5['00']=0
M5['01']=1
M5['02']=1
M5['10']=2
M5['11']=1
M5['12']=2
M5['20']=0
M5['21']=2
M5['22']=1
V6['00']=1
V6['01']=1
V6['02']=2
V6['10']=1
V6['11']=1
V6['12']=1
V6['20']=2
V6['21']=2
V6['22']=2
MM = {}
MM[0] = M1
MM[1] = M2
MM[2] = M3
MM[3] = M4
MM[4] = M5
MM[5] = V6
m = 3
b = [str(i)+str(j)+str(k) for i in range(m) for j in range(m) for k in range(m)]
import itertools
deep = 3
final = []
mylist = [MM[i] for i in range(0,7-1)]
b = [str(i)+str(j)+str(k) for i in range(m) for j in range(m) for k in range(m)]
def DFS(b, deep, maxx, sourceoperators, path):
initlist = []
if deep > 0:
print("deep=", deep)
for aa,bb in itertools.combinations(sourceoperators, 2):
print(aa,bb)
if deep == maxx:
finalresult = []
op1xy = [aa[b[i][0:1]+b[i][1:2]] for i in range(len(b))]
op1yz = [aa[b[i][1:2]+b[i][2:3]] for i in range(len(b))]
op1xz = [aa[b[i][0:1]+b[i][2:3]] for i in range(len(b))]
op2xy = [bb[b[i][0:1]+b[i][1:2]] for i in range(len(b))]
op2yz = [bb[b[i][1:2]+b[i][2:3]] for i in range(len(b))]
op2xz = [bb[b[i][0:1]+b[i][2:3]] for i in range(len(b))]
if sum(op1xy) == 54:
path.append([(deep, aa, "xy")])
if sum(op1yz) == 54:
path.append([(deep, aa, "yz")])
if sum(op1xz) == 54:
path.append([(deep, aa, "xz")])
if sum(op2xy) == 54:
path.append([(deep, bb, "xy")])
if sum(op2yz) == 54:
path.append([(deep, bb, "yz")])
if sum(op2xz) == 54:
path.append([(deep, bb, "xz")])
initlist.append(op1xy)
initlist.append(op1yz)
initlist.append(op1xz)
initlist.append(op2xy)
initlist.append(op2yz)
initlist.append(op2xz)
else:
level = []
for j in range(len(b)):
op1xy = [aa[b[j][i]] for i in range(len(b[j]))]
op2xy = [bb[b[j][i]] for i in range(len(b[j]))]
if sum(op1xy) == 54:
path.append([(deep, aa, "xy")])
if sum(op2xy) == 54:
path.append([(deep, bb, "xy")])
level.append(op1xy)
level.append(op2xy)
initlist.append(op1xy)
initlist.append(op2xy)
if deep == maxx:
if deep > 0:
b = []
for aaa,bbb in itertools.combinations(initlist, 2):
b.append([str(i)+str(j) for i,j in zip(aaa, bbb)])
print("deep=")
print(deep)
path2 = DFS(b, deep-1, maxx, sourceoperators, path)
path.append(path2)
else:
if deep > 0:
for aaa,bbb in itertools.combinations(initlist, 2):
b.append([str(i)+str(j) for i,j in zip(aaa, bbb)])
print("deep=")
print(deep)
path2 = DFS(b, deep-1, maxx, sourceoperators, path)
path.append(path2)
return path
path = []
mresult = DFS(b, 2, 2, mylist, path)
On Friday, June 10, 2016 at 10:08:44 PM UTC+8, Steven D'Aprano wrote:
> On Fri, 10 Jun 2016 10:58 am, meInvent bbird wrote:
>
> [snip unreadable code]
>
> I just ran your code, and it almost crashed my computer. I think it is quite
> rude to post code without an explanation of what the problem is.
>
>
> I'm afraid that your code is virtually unreadable to me. It is too verbose,
> the indentation is awful (single space indents is impossible for me to
> track by eye) and it makes too much work out of simple operations. And none
> of the variable names mean anything.
>
> I've started to simplify and clean the code, and got to the following, which
> I hope you will agree is easier to read and more compact:
>
>
>
> import itertools
> M1 = {'00': 0, '01': 2, '02': 1, '10': 1, '11': 1,
> '12': 1, '20': 1, '21': 1, '22': 2}
> M2 = {'00': 0, '01': 1, '02': 1, '10': 1, '11': 1,
> '12': 1, '20': 1, '21': 1, '22': 1}
> M3 = {'00': 2, '01': 2, '02': 2, '10': 0, '11': 2,
> '12': 1, '20': 0, '21': 1, '22': 2}
> M4 = {'00': 1, '01': 2, '02': 1, '10': 2, '11': 2,
> '12': 2, '20': 0, '21': 1, '22': 2}
> M5 = {'00': 0, '01': 1, '02': 1, '10': 0, '11': 2,
> '12': 1, '20': 0, '21': 1, '22': 1}
> # Why V instead of M?
> V6 = {'00': 1, '01': 1, '02': 2, '10': 1, '11': 2,
> '12': 1, '20': 1, '21': 2, '22': 2}
>
> MM = {0: M1, 1: M2, 2: M3, 3: M4, 4: M5, 5: V6}
> m = 3
> b = [str(i)+str(j)+str(k) for i in range(m)
> for j in range(m) for k in range(m)]
> mylist = [MM[i] for i in range(6)]
>
> def DFS(b, deep, maxx, sourceoperators, path):
> initlist = []
> if deep > 0:
> print("deep=", deep)
> for aa,bb in itertools.combinations(sourceoperators, 2):
> print(aa,bb)
> if deep == maxx:
> finalresult = []
> op1xy = [aa[b[i][0:1]] for i in range(len(b))]
> op1yz = [aa[b[i][1:2]] for i in range(len(b))]
> op1xz = [aa[b[i][0]+b[i][2]] for i in range(len(b))]
> op2xy = [bb[b[i][0:1]] for i in range(len(b))]
> op2yz = [bb[b[i][1:2]] for i in range(len(b))]
> op2xz = [bb[b[i][0]+b[i][2]] for i in range(len(b))]
> if sum(op1xy) == 54:
> path.append([(deep, aa, "xy")])
> if sum(op1yz) == 54:
> path.append([(deep, aa, "yz")])
> if sum(op1xz) == 54:
> path.append([(deep, aa, "xz")])
> if sum(op2xy) == 54:
> path.append([(deep, bb, "xy")])
> if sum(op2yz) == 54:
> path.append([(deep, bb, "yz")])
> if sum(op2xz) == 54:
> path.append([(deep, bb, "xz")])
> initlist.extend([op1xy, op1yz, op1xz, op2xy, op2yz, op2xz])
> else:
> level = []
> for j in range(len(b)):
> op1xy = [aa[b[j][i]] for i in range(len(b[j]))]
> op2xy = [bb[b[j][i]] for i in range(len(b[j]))]
> if sum(op1xy) == 54:
> path.append([(deep, aa, "xy")])
> if sum(op2xy) == 54:
> path.append([(deep, bb, "xy")])
> level.extend([op1xy, op2xy])
> initlist.extend([op1xy, op2xy])
> if deep == maxx:
> b = []
> for aaa,bbb in itertools.combinations(initlist, 2):
> b.append([str(i)+str(j) for i,j in zip(aaa, bbb)])
> path = DFS(b, deep-1, maxx, sourceoperators, path)
> return path
>
> path = []
> mresult = DFS(b, 2, 2, mylist, path)
>
>
>
> Unfortunate, in cleaning up your code, I have changed something, because my
> version and your version do not do the same thing.
>
> After nearly crashing my computer running your version, I am not going to
> spend the time trying to debug this. If you want our help, I suggest that
> you clean up the code. Currently it is an incomprehensible mess to me. Even
> after the cleanup, I have no idea what this piece of code is supposed to do
> or what it is calculating.
>
> Can you explain the purpose of the code? What is it calculating? Can you
> show the expected results? What does "DFS" mean? Why do you have M1 - M5
> but then a mysterious V6?
>
> I can see you are calculating *something* to do with permutations of 0 1 2,
> but I don't understand what.
>
> I think I can see one problem: DFS is a recursive function, but it never
> ends the recursion. It ALWAYS calls DFS(... deep-1, ...) even if deep is
> zero. So I expect that you will have an infinite loop that just recurses
> over and over, until you run out of memory or hit the recursion limit.
>
>
>
> --
> Steven
[toc] | [prev] | [next] | [standalone]
| From | John Gordon <gordon@panix.com> |
|---|---|
| Date | 2016-06-10 14:46 +0000 |
| Message-ID | <njejs6$ri3$1@reader1.panix.com> |
| In reply to | #109768 |
In <4f853aa2-cc00-480b-9fd7-79b05cbd4889@googlegroups.com> meInvent bbird <jobmattcon@gmail.com> writes:
> https://drive.google.com/file/d/0Bxs_ao6uuBDULVNsRjZSVjdPYlE/view?usp=sharing
I already responded to your earlier post about this program. Did you
read it?
--
John Gordon A is for Amy, who fell down the stairs
gordon@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"
[toc] | [prev] | [next] | [standalone]
| From | meInvent bbird <jobmattcon@gmail.com> |
|---|---|
| Date | 2016-06-10 08:08 -0700 |
| Message-ID | <8a1c372e-bd6c-4923-8ae1-8f129ec749e4@googlegroups.com> |
| In reply to | #109791 |
On Friday, June 10, 2016 at 10:46:43 PM UTC+8, John Gordon wrote: > In <4f853aa2-cc00-480b-9fd7-79b05cbd4889@googlegroups.com> meInvent bbird <jobmattcon@gmail.com> writes: > > > https://drive.google.com/file/d/0Bxs_ao6uuBDULVNsRjZSVjdPYlE/view?usp=sharing > > I already responded to your earlier post about this program. Did you > read it? > > -- > John Gordon A is for Amy, who fell down the stairs > gordon@panix.com B is for Basil, assaulted by bears > -- Edward Gorey, "The Gashlycrumb Tinies" sorry i missed your reply post, i find post by me and search your name, no this name is your name changed in previous post? could you post the link here? is it an email or google group post?
[toc] | [prev] | [next] | [standalone]
| From | John Gordon <gordon@panix.com> |
|---|---|
| Date | 2016-06-10 16:26 +0000 |
| Message-ID | <njepo0$83e$1@reader1.panix.com> |
| In reply to | #109794 |
In <8a1c372e-bd6c-4923-8ae1-8f129ec749e4@googlegroups.com> meInvent bbird <jobmattcon@gmail.com> writes:
> > I already responded to your earlier post about this program. Did you
> > read it?
> sorry i missed your reply post,
> i find post by me and search your name, no this name
> is your name changed in previous post?
My comment was that the recursive calls weren't indented in the
"if deep > 0" block, therefore DFS was being called infinitely with smaller
and smaller values of deep. But it appears you have fixed that issue.
--
John Gordon A is for Amy, who fell down the stairs
gordon@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"
[toc] | [prev] | [next] | [standalone]
| From | meInvent bbird <jobmattcon@gmail.com> |
|---|---|
| Date | 2016-06-10 16:31 -0700 |
| Message-ID | <b2dfb3cb-bc3b-4d97-a3ce-ffa80e0c51f6@googlegroups.com> |
| In reply to | #109797 |
it is quite ridiculous,
this time i am sure that i put correct indentation
and add a else statement to make sure recursive call inside the
if statement , it still memory error,
where is the memory error?
is itertools.combinations so big for the list?
if deep == maxx:
if deep > 0:
b = []
for aaa,bbb in itertools.combinations(initlist, 2):
b.append([str(i)+str(j) for i,j in zip(aaa, bbb)])
print("deep=")
print(deep)
path2 = DFS(b, deep-1, maxx, sourceoperators, path)
path.append(path2)
else:
print ""
else:
if deep > 0:
for aaa,bbb in itertools.combinations(initlist, 2):
b.append([str(i)+str(j) for i,j in zip(aaa, bbb)])
print("deep=")
print(deep)
path2 = DFS(b, deep-1, maxx, sourceoperators, path)
path.append(path2)
else:
print ""
return path
On Saturday, June 11, 2016 at 12:26:55 AM UTC+8, John Gordon wrote:
> In <8a1c372e-bd6c-4923-8ae1-8f129ec749e4@googlegroups.com> meInvent bbird <jobmattcon@gmail.com> writes:
>
> > > I already responded to your earlier post about this program. Did you
> > > read it?
>
> > sorry i missed your reply post,
> > i find post by me and search your name, no this name
> > is your name changed in previous post?
>
> My comment was that the recursive calls weren't indented in the
> "if deep > 0" block, therefore DFS was being called infinitely with smaller
> and smaller values of deep. But it appears you have fixed that issue.
>
> --
> John Gordon A is for Amy, who fell down the stairs
> gordon@panix.com B is for Basil, assaulted by bears
> -- Edward Gorey, "The Gashlycrumb Tinies"
[toc] | [prev] | [next] | [standalone]
| From | MRAB <python@mrabarnett.plus.com> |
|---|---|
| Date | 2016-06-11 01:33 +0100 |
| Message-ID | <mailman.145.1465605243.2306.python-list@python.org> |
| In reply to | #109803 |
On 2016-06-11 00:31, meInvent bbird wrote: > it is quite ridiculous, > this time i am sure that i put correct indentation > and add a else statement to make sure recursive call inside the > if statement , it still memory error, > > where is the memory error? > > is itertools.combinations so big for the list? > [snip] How long is initlist? When I ran the code, it said over 100_000 items. How many combinations would there be? Over 10_000_000_000. That's how long the list 'b' would be. You'll need 10s of gigabytes of memory and a lot of patience!
[toc] | [prev] | [next] | [standalone]
| From | meInvent bbird <jobmattcon@gmail.com> |
|---|---|
| Date | 2016-06-10 21:43 -0700 |
| Message-ID | <fe43c0c9-5525-4d82-96d3-e585aedfb666@googlegroups.com> |
| In reply to | #109805 |
this time i remove redundant which not add full column sum already has beeb 27*2
but it always has syntax error, indentation error,
where is wrong?
def DFS(b, deep, maxx, sourceoperators, path):
initlist = []
if deep > 0:
print("deep=", deep)
for aa,bb in itertools.combinations(sourceoperators, 2):
print(aa,bb)
if deep == maxx:
finalresult = []
op1xy = [aa[b[i][0:1]+b[i][1:2]] for i in range(len(b))]
op1yz = [aa[b[i][1:2]+b[i][2:3]] for i in range(len(b))]
op1xz = [aa[b[i][0:1]+b[i][2:3]] for i in range(len(b))]
op2xy = [bb[b[i][0:1]+b[i][1:2]] for i in range(len(b))]
op2yz = [bb[b[i][1:2]+b[i][2:3]] for i in range(len(b))]
op2xz = [bb[b[i][0:1]+b[i][2:3]] for i in range(len(b))]
if sum(op1xy) == 54:
path.append([(deep, aa, b, "xy")])
else:
initlist.append(op1xy)
if sum(op1yz) == 54:
path.append([(deep, aa, b, "yz")])
else:
initlist.append(op1yz)
if sum(op1xz) == 54:
path.append([(deep, aa, b, "xz")])
else:
initlist.append(op1xz)
if sum(op2xy) == 54:
path.append([(deep, bb, b, "xy")])
else:
initlist.append(op2xy)
if sum(op2yz) == 54:
path.append([(deep, bb, b, "yz")])
else:
initlist.append(op2yz)
if sum(op2xz) == 54:
path.append([(deep, bb, b, "xz")])
else:
initlist.append(op2xz)
else:
level = []
for j in range(len(b)):
op1xy = [aa[b[j][i]] for i in range(len(b[j]))]
op2xy = [bb[b[j][i]] for i in range(len(b[j]))]
if sum(op1xy) == 54:
path.append([(deep, aa, b[j], "xy")])
else:
initlist.append(op1xy)
if sum(op2xy) == 54:
path.append([(deep, bb, b[j], "xy")])
else:
initlist.append(op2xy)
level.append(op1xy)
level.append(op2xy)
print("initlist=")
print(len(initlist)
if deep == maxx:
if deep > 0:
b = []
for aaa,bbb in itertools.combinations(initlist, 2):
b.append([str(i)+str(j) for i,j in zip(aaa, bbb)])
print("deep=")
print(deep)
path2 = DFS(b, deep-1, maxx, sourceoperators, path)
path.append(path2)
else:
print("")
print("path=")
print(len(path))
else:
if deep > 0:
for aaa,bbb in itertools.combinations(initlist, 2):
b.append([str(i)+str(j) for i,j in zip(aaa, bbb)])
print("deep=")
print(deep)
path2 = DFS(b, deep-1, maxx, sourceoperators, path)
path.append(path2)
else:
print("")
print("path=")
print(len(path))
return path
On Saturday, June 11, 2016 at 8:34:16 AM UTC+8, MRAB wrote:
> On 2016-06-11 00:31, meInvent bbird wrote:
> > it is quite ridiculous,
> > this time i am sure that i put correct indentation
> > and add a else statement to make sure recursive call inside the
> > if statement , it still memory error,
> >
> > where is the memory error?
> >
> > is itertools.combinations so big for the list?
> >
> [snip]
>
> How long is initlist?
>
> When I ran the code, it said over 100_000 items.
>
> How many combinations would there be?
>
> Over 10_000_000_000.
>
> That's how long the list 'b' would be.
>
> You'll need 10s of gigabytes of memory and a lot of patience!
[toc] | [prev] | [next] | [standalone]
| From | meInvent bbird <jobmattcon@gmail.com> |
|---|---|
| Date | 2016-06-10 22:18 -0700 |
| Message-ID | <f4453805-e2c3-44f6-9294-52f2ca0a01f1@googlegroups.com> |
| In reply to | #109805 |
i use a version having better indentation,
and then remove redundant which if sum column == 54 , do not add this column
into initlist
and add deep > 0 before recursive call
and print number of initlist is 118,XXX
but it is still running, where it run , and why run a very long time
def DFS(b, deep, maxx, sourceoperators, path):
initlist = []
if deep > 0:
print("deep=", deep)
for aa,bb in itertools.combinations(sourceoperators, 2):
print(aa,bb)
if deep == maxx:
finalresult = []
op1xy = [aa[b[i][0:1]+b[i][1:2]] for i in range(len(b))]
op1yz = [aa[b[i][1:2]+b[i][2:3]] for i in range(len(b))]
op1xz = [aa[b[i][0:1]+b[i][2:3]] for i in range(len(b))]
op2xy = [bb[b[i][0:1]+b[i][1:2]] for i in range(len(b))]
op2yz = [bb[b[i][1:2]+b[i][2:3]] for i in range(len(b))]
op2xz = [bb[b[i][0:1]+b[i][2:3]] for i in range(len(b))]
if sum(op1xy) == 54:
path.append([(deep, aa, "xy")])
else:
initlist.append(op1xy)
if sum(op1yz) == 54:
path.append([(deep, aa, "yz")])
else:
initlist.append(op1yz)
if sum(op1xz) == 54:
path.append([(deep, aa, "xz")])
else:
initlist.append(op1xz)
if sum(op2xy) == 54:
path.append([(deep, bb, "xy")])
else:
initlist.append(op2xy)
if sum(op2yz) == 54:
path.append([(deep, bb, "yz")])
else:
initlist.append(op2yz)
if sum(op2xz) == 54:
path.append([(deep, bb, "xz")])
else:
initlist.append(op2xz)
else:
level = []
for j in range(len(b)):
op1xy = [aa[b[j][i]] for i in range(len(b[j]))]
op2xy = [bb[b[j][i]] for i in range(len(b[j]))]
if sum(op1xy) == 54:
path.append([(deep, aa, "xy")])
else:
initlist.append(op1xy)
if sum(op2xy) == 54:
path.append([(deep, bb, "xy")])
else:
initlist.append(op2xy)
level.extend([op1xy, op2xy])
if deep == maxx:
b = []
print("initlist=")
print(len(initlist))
for aaa,bbb in itertools.combinations(initlist, 2):
b.append([str(i)+str(j) for i,j in zip(aaa, bbb)])
if deep > 0:
path2 = DFS(b, deep-1, maxx, sourceoperators, path)
path.append(path2)
return path
path = []
mresult = DFS(b, 2, 2, mylist, path)
On Saturday, June 11, 2016 at 8:34:16 AM UTC+8, MRAB wrote:
> On 2016-06-11 00:31, meInvent bbird wrote:
> > it is quite ridiculous,
> > this time i am sure that i put correct indentation
> > and add a else statement to make sure recursive call inside the
> > if statement , it still memory error,
> >
> > where is the memory error?
> >
> > is itertools.combinations so big for the list?
> >
> [snip]
>
> How long is initlist?
>
> When I ran the code, it said over 100_000 items.
>
> How many combinations would there be?
>
> Over 10_000_000_000.
>
> That's how long the list 'b' would be.
>
> You'll need 10s of gigabytes of memory and a lot of patience!
[toc] | [prev] | [next] | [standalone]
| From | meInvent bbird <jobmattcon@gmail.com> |
|---|---|
| Date | 2016-06-10 22:55 -0700 |
| Message-ID | <2f9dc62c-7999-410e-9448-01cfcb62a273@googlegroups.com> |
| In reply to | #109805 |
i use sage cloud to run, it killed my program
i checked total memory is large, how much memory it need, 8GB*10, 80GB?
top - 05:55:16 up 10:05, 1 user, load average: 0.35, 0.63, 0.56
Tasks: 13 total, 1 running, 12 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.5 us, 0.4 sy, 0.0 ni, 99.1 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem: 26755056 total, 6317696 used, 20437360 free, 611836 buffers
KiB Swap: 67108860 total, 468688 used, 66640172 free. 1223512 cached Mem
def DFS(b, deep, maxx, sourceoperators, path):
initlist = []
if deep > 0:
print("deep=", deep)
for aa,bb in itertools.combinations(sourceoperators, 2):
print(aa,bb)
if deep == maxx:
finalresult = []
op1xy = [aa[b[i][0:1]+b[i][1:2]] for i in range(len(b))]
op1yz = [aa[b[i][1:2]+b[i][2:3]] for i in range(len(b))]
op1xz = [aa[b[i][0:1]+b[i][2:3]] for i in range(len(b))]
op2xy = [bb[b[i][0:1]+b[i][1:2]] for i in range(len(b))]
op2yz = [bb[b[i][1:2]+b[i][2:3]] for i in range(len(b))]
op2xz = [bb[b[i][0:1]+b[i][2:3]] for i in range(len(b))]
if sum(op1xy) == 54:
path.append([(deep, aa, b, "xy")])
else:
initlist.append(op1xy)
if sum(op1yz) == 54:
path.append([(deep, aa, b, "yz")])
else:
initlist.append(op1yz)
if sum(op1xz) == 54:
path.append([(deep, aa, b, "xz")])
else:
initlist.append(op1xz)
if sum(op2xy) == 54:
path.append([(deep, bb, b, "xy")])
else:
initlist.append(op2xy)
if sum(op2yz) == 54:
path.append([(deep, bb, b, "yz")])
else:
initlist.append(op2yz)
if sum(op2xz) == 54:
path.append([(deep, bb, b, "xz")])
else:
initlist.append(op2xz)
else:
level = []
for j in range(len(b)):
op1xy = [aa[b[j][i]] for i in range(len(b[j]))]
op2xy = [bb[b[j][i]] for i in range(len(b[j]))]
if sum(op1xy) == 54:
path.append([(deep, aa, b[j], "xy")])
else:
initlist.append(op1xy)
if sum(op2xy) == 54:
path.append([(deep, bb, b[j], "xy")])
else:
initlist.append(op2xy)
level.extend([op1xy, op2xy])
if deep == maxx:
b = []
print("initlist=")
print(len(initlist))
for aaa,bbb in itertools.combinations(initlist, 2):
b.append([str(i)+str(j) for i,j in zip(aaa, bbb)])
if deep > 0:
path2 = DFS(b, deep-1, maxx, sourceoperators, path)
path.append(path2)
return path
path = []
mresult = DFS(b, 2, 2, mylist, path)
On Saturday, June 11, 2016 at 8:34:16 AM UTC+8, MRAB wrote:
> On 2016-06-11 00:31, meInvent bbird wrote:
> > it is quite ridiculous,
> > this time i am sure that i put correct indentation
> > and add a else statement to make sure recursive call inside the
> > if statement , it still memory error,
> >
> > where is the memory error?
> >
> > is itertools.combinations so big for the list?
> >
> [snip]
>
> How long is initlist?
>
> When I ran the code, it said over 100_000 items.
>
> How many combinations would there be?
>
> Over 10_000_000_000.
>
> That's how long the list 'b' would be.
>
> You'll need 10s of gigabytes of memory and a lot of patience!
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web