Browse Source

4x4x4 fix tsai

master
Daniel Walton 2 years ago
parent
commit
0bc12b61ca
2 changed files with 181 additions and 30 deletions
  1. +152
    -13
      rubikscubennnsolver/RubiksCube444.py
  2. +29
    -17
      rubikscubennnsolver/RubiksCube555.py

+ 152
- 13
rubikscubennnsolver/RubiksCube444.py View File

@@ -12,6 +12,7 @@ from rubikscubennnsolver.RubiksCube444Misc import (
from rubikscubennnsolver.LookupTable import (
LookupTable,
LookupTableIDA,
LookupTableAStar,
NoSteps,
NoIDASolution,
)
@@ -581,6 +582,7 @@ class LookupTable444TsaiPhase2Edges(LookupTable):
linecount=2704156)

def state(self):
'''
centers_cost = self.parent.lt_tsai_phase2_centers.steps_cost()
min_edges_cost = None
min_edges_state = None
@@ -599,6 +601,12 @@ class LookupTable444TsaiPhase2Edges(LookupTable):
min_edges_state = edges_state

return min_edges_state
'''

edges_state = self.parent.tsai_phase2_orient_edges_state(set())
#edges_cost = self.steps_cost(edges_state)

return edges_state


class LookupTableIDA444TsaiPhase2(LookupTableIDA):
@@ -607,20 +615,21 @@ class LookupTableIDA444TsaiPhase2(LookupTableIDA):
LookupTableIDA.__init__(
self,
parent,
'lookup-table-4x4x4-step60-dummy.txt',
'TBD',
#'lookup-table-4x4x4-step60-dummy.txt',
'lookup-table-4x4x4-step60.txt',
'UDDUUUUUUDDUDUDLLUULLDUDDUUFFDDFFUUDDUDRRUURRDUDDUUFFDDFFUUDUDDUUUUUUDDU',
moves_4x4x4,
("Fw", "Fw'", "Bw", "Bw'",
"Uw", "Uw'", "Dw", "Dw'"), # illegal_moves

# prune tables
(parent.lt_tsai_phase2_centers,),
#(parent.lt_tsai_phase2_centers,
# parent.lt_tsai_phase2_edges),
linecount=0)
#(parent.lt_tsai_phase2_centers,),
(parent.lt_tsai_phase2_centers,
parent.lt_tsai_phase2_edges),
linecount=2520544)

def state(self):
babel = {
babel = {
'L' : 'L',
'F' : 'F',
'R' : 'R',
@@ -720,7 +729,7 @@ class LookupTableIDA444TsaiPhase2(LookupTableIDA):
result = ''.join(result)
return result

def ida_search_complete(self, state, steps_to_here):
def experimental_ida_search_complete(self, state, steps_to_here):

# Are UD and FB staged?
for side in (self.parent.sideU, self.parent.sideD):
@@ -1158,6 +1167,95 @@ class LookupTable444EdgesSliceBackward(LookupTable):
raise Exception("This should never be called")



class BidirIDA444ULFRBDCentersStage(LookupTableIDA):
"""
lookup-table-4x4x4-step10-ULFRBD-centers-stage.txt
==================================================
1 steps has 7 entries (0 percent, 0.00x previous step)
2 steps has 135 entries (0 percent, 19.29x previous step)
3 steps has 2,286 entries (0 percent, 16.93x previous step)
4 steps has 36,728 entries (0 percent, 16.07x previous step)
5 steps has 562,932 entries (6 percent, 15.33x previous step)
6 steps has 8,047,054 entries (93 percent, 14.29x previous step)

Total: 8,649,142 entries
"""

def __init__(self, parent):
LookupTableIDA.__init__(
self,
parent,
'lookup-table-4x4x4-step10-ULFRBD-centers-stage.txt',
'UUUULLLLFFFFLLLLFFFFUUUU',
moves_4x4x4,
(), # illegal_moves

# prune tables
(parent.lt_UD_centers_stage,
parent.lt_LR_centers_stage,
parent.lt_FB_centers_stage),
linecount=8649142,
max_depth=6)

def state(self):
parent_state = self.parent.state

result = [
# Upper
parent_state[6],
parent_state[7],
parent_state[10],
parent_state[11],

# Left
parent_state[22],
parent_state[23],
parent_state[26],
parent_state[27],

# Front
parent_state[38],
parent_state[39],
parent_state[42],
parent_state[43],

# Right
parent_state[54],
parent_state[55],
parent_state[58],
parent_state[59],

# Back
parent_state[70],
parent_state[71],
parent_state[74],
parent_state[75],

# Down
parent_state[86],
parent_state[87],
parent_state[90],
parent_state[91]
]

tmp_result = []
for x in result:
if x in ('L', 'F', 'U'):
tmp_result.append(x)
elif x == 'R':
tmp_result.append('L')
elif x == 'B':
tmp_result.append('F')
elif x == 'D':
tmp_result.append('U')

result = ''.join(tmp_result)

return result



class RubiksCube444(RubiksCube):

def __init__(self, state, order, colormap=None, avoid_pll=True, debug=False):
@@ -1289,6 +1387,14 @@ class RubiksCube444(RubiksCube):
# Stage LR centers
self.lt_LR_centers_stage = LookupTable444LRCentersStage(self)

elif self.cpu_mode == 'exp':

self.lt_UD_centers_stage = LookupTable444UDCentersStage(self)
self.lt_LR_centers_stage = LookupTable444LRCentersStage(self)
self.lt_FB_centers_stage = LookupTable444FBCentersStage(self)

self.lt_ULFRBD_centers_stage = BidirIDA444ULFRBDCentersStage(self)

else:
raise Exception("We should not be here, cpu_mode %s" % self.cpu_mode)

@@ -1306,10 +1412,13 @@ class RubiksCube444(RubiksCube):
# - solve LR centers to one of 12 states
# - stage UD and FB centers
self.lt_tsai_phase2_centers = LookupTable444TsaiPhase2Centers(self)
# self.lt_tsai_phase2_edges = LookupTable444TsaiPhase2Edges(self)
self.lt_tsai_phase2_edges = LookupTable444TsaiPhase2Edges(self)

self.lt_tsai_phase2 = LookupTableIDA444TsaiPhase2(self)

elif self.cpu_mode == 'exp':
pass

else:
raise Exception("We should not be here, cpu_mode %s" % self.cpu_mode)

@@ -1330,6 +1439,9 @@ class RubiksCube444(RubiksCube):

self.lt_tsai_phase3 = LookupTableIDA444TsaiPhase3(self)

elif self.cpu_mode == 'exp':
pass

else:
raise Exception("We should not be here, cpu_mode %s" % self.cpu_mode)

@@ -1453,10 +1565,8 @@ class RubiksCube444(RubiksCube):
self.lt_ULFRBD_centers_stage.avoid_oll = True
self.lt_ULFRBD_centers_stage.solve()
log.info("%s: End of Phase1, %d steps in" % (self, self.get_solution_len_minus_rotates(self.solution)))
log.info("")

self.print_cube()
sys.exit(0) # dwalton
log.info("")

log.info("%s: Start of Phase2, %d steps in" % (self, self.get_solution_len_minus_rotates(self.solution)))
self.lt_ULFRBD_centers_solve.solve()
@@ -1464,6 +1574,16 @@ class RubiksCube444(RubiksCube):
log.info("%s: End of Phase2, %d steps in" % (self, self.get_solution_len_minus_rotates(self.solution)))
log.info("")

elif self.cpu_mode == 'exp':

log.info("%s: Start of Phase1" % self)
self.lt_ULFRBD_centers_stage.avoid_oll = True
self.lt_ULFRBD_centers_stage.solve()
log.info("%s: End of Phase1, %d steps in" % (self, self.get_solution_len_minus_rotates(self.solution)))
self.print_cube()
log.info("")
sys.exit(0) # dwalton

# The tsai will solve the centers and pair the edges
elif self.cpu_mode == 'tsai':

@@ -1471,6 +1591,7 @@ class RubiksCube444(RubiksCube):
original_state = self.state[:]
original_solution = self.solution[:]

'''
# Collect phase1 options
phase1_options = []
phase1_options_states = []
@@ -1518,7 +1639,7 @@ class RubiksCube444(RubiksCube):
min_solution = None
min_state = None

for init_max_ida_threshold in range(8, 99):
for init_max_ida_threshold in range(7, 99):
for (upper_side_name, front_side_name, transform, tmp_state, tmp_solution) in phase1_options:
self.state = tmp_state[:]
self.solution = tmp_solution[:]
@@ -1570,6 +1691,24 @@ class RubiksCube444(RubiksCube):

log.info("%s: End of Phase1/2, %d steps in" % (self, self.get_solution_len_minus_rotates(self.solution)))
log.info("")
'''

log.info("%s: Start of Phase1, %d steps in" % (self, self.get_solution_len_minus_rotates(self.solution)))
self.lt_LR_centers_stage.solve()
self.print_cube()
log.info("%s: End of Phase1, %d steps in" % (self, self.get_solution_len_minus_rotates(self.solution)))

# Test the prune table
#self.lt_tsai_phase2_edges.solve()
#self.lt_tsai_phase2_centers.solve()
#self.tsai_phase2_orient_edges_print()
#self.print_cube()
#sys.exit(0)

log.info("%s: Start of Phase2, %d steps in" % (self, self.get_solution_len_minus_rotates(self.solution)))
self.lt_tsai_phase2.solve()
self.print_cube()
log.info("%s: End of Phase2, %d steps in" % (self, self.get_solution_len_minus_rotates(self.solution)))

# Testing the phase3 prune tables
#self.lt_tsai_phase3_edges_solve.solve()


+ 29
- 17
rubikscubennnsolver/RubiksCube555.py View File

@@ -434,14 +434,22 @@ class LookupTable555FBXCenterStage(LookupTable):
# Convert to hex
return self.hex_format % int(result, 2)

# dwalton exp
#class LookupTableIDA555AllCenterStage(LookupTableAStar):

class LookupTableIDA555AllCenterStage(LookupTableIDA):
"""
lookup-table-5x5x5-step100-ALL-centers-stage.txt
================================================
1 steps has 7 entries (0 percent, 0.00x previous step)
2 steps has 147 entries (0 percent, 21.00x previous step)
3 steps has 3,054 entries (0 percent, 20.78x previous step)
4 steps has 65,520 entries (4 percent, 21.45x previous step)
5 steps has 1,467,630 entries (95 percent, 22.40x previous step)

Total: 1,536,358 entries
"""

def __init__(self, parent):
LookupTableAStar.__init__(
LookupTableIDA.__init__(
self,
parent,
'lookup-table-5x5x5-step100-ALL-centers-stage.txt',
@@ -461,7 +469,7 @@ class LookupTableIDA555AllCenterStage(LookupTableIDA):
def state(self):
parent_state = self.parent.state

result = [
tmp_result = [
# Upper
parent_state[7], parent_state[8], parent_state[9],
parent_state[12], parent_state[13], parent_state[14],
@@ -493,11 +501,18 @@ class LookupTableIDA555AllCenterStage(LookupTableIDA):
parent_state[142], parent_state[143], parent_state[144]
]

result = ['1' if x in ('U', 'D') else '0' for x in result]
result = ''.join(result)
# dwalton fix this
result = []

# Convert to hex
return self.hex_format % int(result, 2)
for x in tmp_result:
if x in ('U', 'D'):
result.append('U')
elif x in ('L', 'R'):
result.append('L')
elif x in ('F', 'B'):
result.append('F')

return ''.join(result)


class LookupTable555CpuMinUDTCenterStage(LookupTable):
@@ -1330,7 +1345,8 @@ class RubiksCube555(RubiksCube):
return
self.lt_init_called = True

# dwalton experiment
# experiment
'''
self.lt_UD_T_centers_stage = LookupTable555UDTCenterStage(self)
self.lt_UD_X_centers_stage = LookupTable555UDXCenterStage(self)
self.lt_LR_T_centers_stage = LookupTable555LRTCenterStage(self)
@@ -1338,8 +1354,8 @@ class RubiksCube555(RubiksCube):
self.lt_FB_T_centers_stage = LookupTable555FBTCenterStage(self)
self.lt_FB_X_centers_stage = LookupTable555FBXCenterStage(self)
self.lt_ALL_enters_stage = LookupTableIDA555AllCenterStage(self)

'''

if self.cpu_mode == 'min':
self.lt_UD_T_centers_stage = LookupTable555CpuMinUDTCenterStage(self)
self.lt_UD_X_centers_stage = LookupTable555CpuMinUDXCenterStage(self)
@@ -1352,7 +1368,6 @@ class RubiksCube555(RubiksCube):
self.lt_LR_centers_stage_x_center_only = LookupTable555LRXCentersStage(self)
self.lt_LR_centers_stage_t_center_only = LookupTable555LRTCentersStage(self)
self.lt_LR_centers_stage = LookupTableIDA555LRCentersStage(self)
'''

self.lt_UL_centers_solve = LookupTableULCentersSolve(self)
self.lt_UF_centers_solve = LookupTableUFCentersSolve(self)
@@ -1440,12 +1455,10 @@ class RubiksCube555(RubiksCube):
#self.lt_LR_X_centers_stage.solve()
#self.lt_FB_T_centers_stage.solve()
#self.lt_FB_X_centers_stage.solve()
self.lt_ALL_enters_stage.solve()
# dwalton exp
self.print_cube()
sys.exit()
#self.lt_ALL_enters_stage.solve()
#self.print_cube()
#sys.exit()

'''
# Stage UD centers
self.group_centers_stage_UD()

@@ -1455,7 +1468,6 @@ class RubiksCube555(RubiksCube):

self.lt_LR_centers_stage.solve()
log.info("ULFRBD centers staged, %d steps in" % self.get_solution_len_minus_rotates(self.solution))
'''

# All centers are staged so solve them
self.lt_ULFRB_centers_solve.solve()


Loading…
Cancel
Save