fixed import and infinite growth
This commit is contained in:
@@ -1,6 +1,19 @@
|
|||||||
|
from polycube import PolyCube
|
||||||
|
import json
|
||||||
|
|
||||||
def main():
|
def main(maxlength:int):
|
||||||
pass
|
polycubes = {}
|
||||||
|
todo = [PolyCube([(0, 0, 0)], [(0, 0, 0)])]
|
||||||
|
while len(todo) != 0:
|
||||||
|
polycube = todo.pop()
|
||||||
|
children = polycube.generate_children(maxlength)
|
||||||
|
for child in children:
|
||||||
|
if child in polycubes:
|
||||||
|
continue
|
||||||
|
todo.append(child)
|
||||||
|
polycubes[child] = 0
|
||||||
|
with open("out.json", "w") as f:
|
||||||
|
f.write(json.dumps(polycubes))
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main(4)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from python.tuple_tools import reorient_tuple, generate_neighbors
|
from tuple_tools import reorient_tuple, generate_neighbors
|
||||||
from itertools import combinations, chain
|
from itertools import combinations, chain
|
||||||
|
|
||||||
class PolyCube:
|
class PolyCube:
|
||||||
@@ -22,11 +22,12 @@ class PolyCube:
|
|||||||
self.orientations = orientations
|
self.orientations = orientations
|
||||||
|
|
||||||
def generate_children(self, max_length:int):
|
def generate_children(self, max_length:int):
|
||||||
|
max_growth = max_length - len(self.cubes)
|
||||||
growth_candidates = set([])
|
growth_candidates = set([])
|
||||||
for last_addition in self.last_additions:
|
for last_addition in self.last_additions:
|
||||||
growth_candidates = growth_candidates.union(generate_neighbors(*last_addition))
|
growth_candidates = growth_candidates.union(generate_neighbors(*last_addition))
|
||||||
growth_candidates = growth_candidates.difference(self.cubes)
|
growth_candidates = growth_candidates.difference(self.cubes)
|
||||||
realizable_growth = chain(combinations(growth_candidates, i) for i in range(1, max_length+1))
|
realizable_growth = chain(combinations(growth_candidates, i) for i in range(1, max_growth+1))
|
||||||
for addition in realizable_growth:
|
for addition in realizable_growth:
|
||||||
yield PolyCube(self.cubes.union(addition), addition)
|
yield PolyCube(self.cubes.union(addition), addition)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user