some minor fixes
This commit is contained in:
@@ -114,11 +114,27 @@ def printstats():
|
||||
if x>5:
|
||||
break
|
||||
|
||||
def parallel_pool_init():
|
||||
global stats
|
||||
global solutions
|
||||
stats=dict()
|
||||
solutions=list()
|
||||
|
||||
|
||||
def parallel_solve(cube):
|
||||
global all_rotations
|
||||
all_rotations=generate_rotations(piece)
|
||||
pieces=set(all_rotations.copy())
|
||||
first_position=(0,0,0)
|
||||
while len(pieces)>0:
|
||||
piece=pieces.pop()
|
||||
if put_piece_in_cube(piece, cube, first_position, index):
|
||||
solve(cube, 2,):
|
||||
|
||||
|
||||
def solve(cube,index):
|
||||
#make copy of cube
|
||||
printstats()
|
||||
|
||||
global stats
|
||||
global solutions
|
||||
global all_rotations
|
||||
pieces=set(all_rotations.copy())
|
||||
|
||||
@@ -128,7 +144,8 @@ def solve(cube,index):
|
||||
if empty_pos==None:
|
||||
pprint.pprint(cube)
|
||||
draw_cube(cube)
|
||||
return True
|
||||
solutions.append(cube)
|
||||
return False
|
||||
else:
|
||||
(x,y,z)=empty_pos
|
||||
while len(pieces)>0:
|
||||
@@ -145,16 +162,13 @@ def solve(cube,index):
|
||||
return False
|
||||
|
||||
|
||||
maxindex=0
|
||||
stat_counter=0
|
||||
stats=dict()
|
||||
last_stats=dict()
|
||||
def main():
|
||||
# maxindex=0
|
||||
# stat_counter=0
|
||||
# stats=dict()
|
||||
# last_stats=dict()
|
||||
|
||||
global all_rotations
|
||||
all_rotations=generate_rotations(piece)
|
||||
print(len(all_rotations))
|
||||
solve(init_cube(),1)
|
||||
def main():
|
||||
parallel_solve(init_cube())
|
||||
|
||||
if __name__ == '__main__':
|
||||
# profile.run('main()')
|
||||
|
||||
@@ -9,6 +9,8 @@ Demonstrates plotting 3D volumetric objects with ``ax.voxels``
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
import pprint
|
||||
import random
|
||||
from matplotlib import colors as mcolors
|
||||
|
||||
# This import registers the 3D projection, but is otherwise unused.
|
||||
from mpl_toolkits.mplot3d import Axes3D # noqa: F401 unused import
|
||||
@@ -16,10 +18,36 @@ from mpl_toolkits.mplot3d import Axes3D # noqa: F401 unused import
|
||||
g_cube=np.zeros((6,6,6))
|
||||
# prepare some coordinates
|
||||
x, y, z = np.indices((6, 6, 6))
|
||||
farben=["red","blue","green","cyan","magenta","yellow"]
|
||||
g_cube[2][2][2]=1
|
||||
g_cube[3][1][1]=2
|
||||
g_cube[5][5][5]=2
|
||||
|
||||
# farben=["red","blue","green","cyan","magenta","yellow"]
|
||||
farben=[name for name in mcolors.CSS4_COLORS]
|
||||
random.shuffle(farben)
|
||||
g_cube=[[[1, 1, 1, 1, 22],
|
||||
[6, 6, 6, 6, 22],
|
||||
[2, 6, 9, 22, 22],
|
||||
[9, 9, 9, 9, 22],
|
||||
[10, 15, 15, 15, 15]],
|
||||
[[2, 11, 1, 19, 20],
|
||||
[2, 11, 13, 19, 21],
|
||||
[2, 11, 11, 19, 23],
|
||||
[2, 11, 17, 19, 24],
|
||||
[10, 14, 18, 15, 25]],
|
||||
[[3, 3, 3, 3, 20],
|
||||
[4, 13, 13, 19, 21],
|
||||
[8, 8, 8, 8, 23],
|
||||
[10, 14, 17, 17, 24],
|
||||
[10, 14, 18, 18, 25]],
|
||||
[[4, 12, 3, 20, 20],
|
||||
[4, 12, 13, 21, 21],
|
||||
[4, 12, 8, 23, 23],
|
||||
[4, 12, 17, 24, 24],
|
||||
[10, 14, 18, 25, 25]],
|
||||
[[5, 5, 5, 5, 20],
|
||||
[7, 5, 13, 16, 21],
|
||||
[7, 12, 16, 16, 23],
|
||||
[7, 7, 17, 16, 24],
|
||||
[7, 14, 18, 16, 25]]]
|
||||
|
||||
|
||||
list_of_cubes =list()
|
||||
color_counter=0
|
||||
@@ -27,8 +55,9 @@ for x_pos in range(0,len(g_cube)):
|
||||
for y_pos in range(0,len(g_cube[x_pos])):
|
||||
for z_pos in range(0,len(g_cube[x_pos][y_pos])):
|
||||
if g_cube[x_pos][y_pos][z_pos]!=0:
|
||||
print("Voxel by ({},{},{})".format(x_pos,y_pos,z_pos))
|
||||
list_of_cubes.append({"cube":(x < x_pos) & (x >= (x_pos-1) ) & (y < y_pos) & (y >= (y_pos-1) ) & (z < z_pos) & (z >= (z_pos-1) ),"farbe":farben[color_counter]})
|
||||
cur_farbe=g_cube[x_pos][y_pos][z_pos]%len(farben)
|
||||
print("Voxel by in {} for ({}>x>={}//{}>y>={}//{}>z>={}) )".format(farben[cur_farbe],x_pos,x_pos+1,y_pos,y_pos+1,z_pos,z_pos+1))
|
||||
list_of_cubes.append({"cube":(x > x_pos) & (x <= (x_pos+1) ) & (y > y_pos) & (y <= (y_pos+1) ) & (z > z_pos) & (z <= (z_pos+1) ),"farbe":farben[cur_farbe]})
|
||||
color_counter=(color_counter + 1) % len (farben)
|
||||
|
||||
voxels=list_of_cubes[0]["cube"]
|
||||
|
||||
Reference in New Issue
Block a user