python now works, jl can leave
This commit is contained in:
@@ -3,23 +3,31 @@ from polycube_encoder import PolyCubeEncdoder
|
||||
import json
|
||||
|
||||
def main(maxlength:int):
|
||||
polycubes = set([PolyCube([(0, 0, 0)], [(0, 0, 0)])])
|
||||
initial_cube = PolyCube([(0, 0, 0)], [(0, 0, 0)])
|
||||
n_size = [0]*maxlength
|
||||
todo = [PolyCube([(0, 0, 0)], [(0, 0, 0)])]
|
||||
todo = [initial_cube]
|
||||
polycubes = [initial_cube.oriented_offsets[0]]
|
||||
n_size[0] = 1
|
||||
|
||||
while len(todo) != 0:
|
||||
polycube = todo.pop()
|
||||
children = polycube.generate_children(maxlength)
|
||||
for child in children:
|
||||
if child in polycubes:
|
||||
continue
|
||||
if child_exists_in(child, polycubes):
|
||||
continue
|
||||
todo.append(child)
|
||||
polycubes.add(child)
|
||||
polycubes.append(child.oriented_offsets[0])
|
||||
n_size[len(child.cubes)-1] += 1
|
||||
with open("out.json", "w") as f:
|
||||
f.write(json.dumps(polycubes, cls=PolyCubeEncdoder))
|
||||
with open("count.json", "w") as f:
|
||||
f.write(json.dumps(n_size))
|
||||
|
||||
def child_exists_in(child: PolyCube, polycubes: list):
|
||||
for orientation in child.oriented_offsets:
|
||||
if orientation in polycubes:
|
||||
return True
|
||||
return False
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(4)
|
||||
main(7)
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
from tuple_tools import reorient_tuple, generate_neighbors
|
||||
from tuple_tools import reorient_tuple, generate_neighbors, subtract
|
||||
from itertools import combinations, chain
|
||||
|
||||
class PolyCube:
|
||||
|
||||
#cubes set{tuple}
|
||||
#orientations list{set{tuple{}}}
|
||||
#last_additions set{tuple}
|
||||
#cubes set{tuple}
|
||||
#oriented_offsets list{list{tuple{}}}
|
||||
#last_additions set{tuple}
|
||||
|
||||
def __init__(self, cubes_list, last_additions = []) -> None:
|
||||
self.cubes = set(cubes_list)
|
||||
@@ -15,11 +15,21 @@ class PolyCube:
|
||||
def _compute_reorientations(self):
|
||||
n_cubes = len(self.cubes)
|
||||
n_orientations = 24
|
||||
orientations = [set()]*n_orientations
|
||||
orientations = [[]]*n_orientations
|
||||
oriented_offsets = [[]]*n_orientations
|
||||
for i in range(n_orientations):
|
||||
for cube in self.cubes:
|
||||
orientations[i].add(reorient_tuple(cube, i))
|
||||
self.orientations = orientations
|
||||
if n_cubes == 1:
|
||||
oriented_offsets[i] = []
|
||||
else:
|
||||
orientations[i] = []
|
||||
for cube in self.cubes:
|
||||
orientations[i].append(reorient_tuple(cube, i))
|
||||
orientations[i].sort()
|
||||
oriented_offsets[i] = [(0, 0, 0)]*(n_cubes-1)
|
||||
last_cube = orientations[i][0]
|
||||
for j in range(n_cubes-1):
|
||||
oriented_offsets[i][j] = subtract(*last_cube, *orientations[i][j+1])
|
||||
self.oriented_offsets = oriented_offsets
|
||||
|
||||
def generate_children(self, max_length:int):
|
||||
max_growth = max_length - len(self.cubes)
|
||||
|
||||
Reference in New Issue
Block a user