-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloopover2
More file actions
77 lines (66 loc) · 2.3 KB
/
Copy pathloopover2
File metadata and controls
77 lines (66 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#! /usr/bin/python3
#import pyximport; pyximport.install(pyimport=True)
from datetime import datetime
timeStart = datetime.today()
import copy
from multiprocessing import Pool
import multiprocessing
import itertools
import defs2
import tracemalloc
#import os
if __name__ == "__main__":
pool = Pool(multiprocessing.cpu_count())
#pool = Pool(1)
checkMem = False
#boards = {((1,2,3,4,5),(6,7,8,9,10),(11,12,13,14,15),(16,17,18,19,20),(21,22,23,24,25))}
#boards = {((1,2,3,4),(5,6,7,8),(9,10,11,12),(13,14,15,16))}
boards = {((1,2,3),(4,5,6),(7,8,9))}
#boards = {((1,2),(3,4))}
#boards = {((1,2,3,4,5),(6,7,8,9,10))}
found = True
number = 0
depth = 0
newBoards = copy.deepcopy(boards)
oldBoards = set()
def splitBoards(newBoards):
return (set().union(*[newBoardsS[0] for newBoardsS in newBoards]),sum([countS[1] for countS in newBoards]))
if checkMem:
tracemalloc.start()
timeLast = datetime.today()
print("Init took: "+str(datetime.today()-timeStart))
while found:
newBoards, newCount = splitBoards(pool.map(defs2.getNewPositions, newBoards, int(len(newBoards)/multiprocessing.cpu_count())+1))
newBoards = newBoards - boards
boards.update(newBoards)
oldBoards = copy.deepcopy(newBoards)
number += newCount
depth += 1
if not bool(newBoards):
found = False
print("Number of combos tested: " + str(number))
print("Number of combos unique: " + str(len(boards)))
print("Depth: " + str(depth))
tmpTime = datetime.today()-timeLast
print("Took: "+str(tmpTime))
print("Boards per seccond: "+str(newCount/(tmpTime).total_seconds()))
timeLast = datetime.today()
tmpTime = datetime.today()-timeStart
print("Total: "+str(tmpTime))
print("Overall boards per seccond: "+str(number/(tmpTime).total_seconds()))
print()
pool.close()
print("Number of combos tested:"+str(number))
print("Number of unique combos:"+str(len(boards)))
print("Depth:"+str(depth-1))
tmpTime = datetime.today()-timeStart
print("Total Time:"+str(str(tmpTime)))
print("Overall boards per seccond: "+str(number/(tmpTime).total_seconds()))
print("Total size of boards: "+str(boards.__sizeof__())+" bytes")
if checkMem:
snapshot = tracemalloc.take_snapshot()
defs2.display_top(snapshot)
file_object = open("tmp", "w")
def writeTheThing(theThing):
file_object.write(str(theThing))
list(map(writeTheThing,oldBoards))