Browse Source

4x4x4 fix tsai

Daniel Walton 1 year 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 (
12 12
 from rubikscubennnsolver.LookupTable import (
13 13
     LookupTable,
14 14
     LookupTableIDA,
15
+    LookupTableAStar,
15 16
     NoSteps,
16 17
     NoIDASolution,
17 18
 )
@@ -581,6 +582,7 @@ class LookupTable444TsaiPhase2Edges(LookupTable):
581 582
             linecount=2704156)
582 583
 
583 584
     def state(self):
585
+        '''
584 586
         centers_cost = self.parent.lt_tsai_phase2_centers.steps_cost()
585 587
         min_edges_cost = None
586 588
         min_edges_state = None
@@ -599,6 +601,12 @@ class LookupTable444TsaiPhase2Edges(LookupTable):
599 601
                         min_edges_state = edges_state
600 602
 
601 603
         return min_edges_state
604
+        '''
605
+
606
+        edges_state = self.parent.tsai_phase2_orient_edges_state(set())
607
+        #edges_cost = self.steps_cost(edges_state)
608
+
609
+        return edges_state
602 610
 
603 611
 
604 612
 class LookupTableIDA444TsaiPhase2(LookupTableIDA):
@@ -607,20 +615,21 @@ class LookupTableIDA444TsaiPhase2(LookupTableIDA):
607 615
         LookupTableIDA.__init__(
608 616
             self,
609 617
             parent,
610
-            'lookup-table-4x4x4-step60-dummy.txt',
611
-            'TBD',
618
+            #'lookup-table-4x4x4-step60-dummy.txt',
619
+            'lookup-table-4x4x4-step60.txt',
620
+            'UDDUUUUUUDDUDUDLLUULLDUDDUUFFDDFFUUDDUDRRUURRDUDDUUFFDDFFUUDUDDUUUUUUDDU',
612 621
             moves_4x4x4,
613 622
             ("Fw", "Fw'", "Bw", "Bw'",
614 623
              "Uw", "Uw'", "Dw", "Dw'"), # illegal_moves
615 624
 
616 625
             # prune tables
617
-            (parent.lt_tsai_phase2_centers,),
618
-            #(parent.lt_tsai_phase2_centers,
619
-            # parent.lt_tsai_phase2_edges),
620
-            linecount=0)
626
+            #(parent.lt_tsai_phase2_centers,),
627
+            (parent.lt_tsai_phase2_centers,
628
+             parent.lt_tsai_phase2_edges),
629
+            linecount=2520544)
621 630
 
622 631
     def state(self):
623
-        babel = { 
632
+        babel = {
624 633
             'L' : 'L',
625 634
             'F' : 'F',
626 635
             'R' : 'R',
@@ -720,7 +729,7 @@ class LookupTableIDA444TsaiPhase2(LookupTableIDA):
720 729
         result = ''.join(result)
721 730
         return result
722 731
 
723
-    def ida_search_complete(self, state, steps_to_here):
732
+    def experimental_ida_search_complete(self, state, steps_to_here):
724 733
 
725 734
         # Are UD and FB staged?
726 735
         for side in (self.parent.sideU, self.parent.sideD):
@@ -1158,6 +1167,95 @@ class LookupTable444EdgesSliceBackward(LookupTable):
1158 1167
         raise Exception("This should never be called")
1159 1168
 
1160 1169
 
1170
+
1171
+class BidirIDA444ULFRBDCentersStage(LookupTableIDA):
1172
+    """
1173
+    lookup-table-4x4x4-step10-ULFRBD-centers-stage.txt
1174
+    ==================================================
1175
+    1 steps has 7 entries (0 percent, 0.00x previous step)
1176
+    2 steps has 135 entries (0 percent, 19.29x previous step)
1177
+    3 steps has 2,286 entries (0 percent, 16.93x previous step)
1178
+    4 steps has 36,728 entries (0 percent, 16.07x previous step)
1179
+    5 steps has 562,932 entries (6 percent, 15.33x previous step)
1180
+    6 steps has 8,047,054 entries (93 percent, 14.29x previous step)
1181
+
1182
+    Total: 8,649,142 entries
1183
+    """
1184
+
1185
+    def __init__(self, parent):
1186
+        LookupTableIDA.__init__(
1187
+            self,
1188
+            parent,
1189
+            'lookup-table-4x4x4-step10-ULFRBD-centers-stage.txt',
1190
+            'UUUULLLLFFFFLLLLFFFFUUUU',
1191
+            moves_4x4x4,
1192
+            (), # illegal_moves
1193
+
1194
+            # prune tables
1195
+            (parent.lt_UD_centers_stage,
1196
+             parent.lt_LR_centers_stage,
1197
+             parent.lt_FB_centers_stage),
1198
+            linecount=8649142,
1199
+            max_depth=6)
1200
+
1201
+    def state(self):
1202
+        parent_state = self.parent.state
1203
+
1204
+        result = [
1205
+            # Upper
1206
+            parent_state[6],
1207
+            parent_state[7],
1208
+            parent_state[10],
1209
+            parent_state[11],
1210
+
1211
+            # Left
1212
+            parent_state[22],
1213
+            parent_state[23],
1214
+            parent_state[26],
1215
+            parent_state[27],
1216
+
1217
+            # Front
1218
+            parent_state[38],
1219
+            parent_state[39],
1220
+            parent_state[42],
1221
+            parent_state[43],
1222
+
1223
+            # Right
1224
+            parent_state[54],
1225
+            parent_state[55],
1226
+            parent_state[58],
1227
+            parent_state[59],
1228
+
1229
+            # Back
1230
+            parent_state[70],
1231
+            parent_state[71],
1232
+            parent_state[74],
1233
+            parent_state[75],
1234
+
1235
+            # Down
1236
+            parent_state[86],
1237
+            parent_state[87],
1238
+            parent_state[90],
1239
+            parent_state[91]
1240
+        ]
1241
+
1242
+        tmp_result = []
1243
+        for x in result:
1244
+            if x in ('L', 'F', 'U'):
1245
+                tmp_result.append(x)
1246
+            elif x == 'R':
1247
+                tmp_result.append('L')
1248
+            elif x == 'B':
1249
+                tmp_result.append('F')
1250
+            elif x == 'D':
1251
+                tmp_result.append('U')
1252
+
1253
+        result = ''.join(tmp_result)
1254
+
1255
+        return result
1256
+
1257
+
1258
+
1161 1259
 class RubiksCube444(RubiksCube):
1162 1260
 
1163 1261
     def __init__(self, state, order, colormap=None, avoid_pll=True, debug=False):
@@ -1289,6 +1387,14 @@ class RubiksCube444(RubiksCube):
1289 1387
             # Stage LR centers
1290 1388
             self.lt_LR_centers_stage = LookupTable444LRCentersStage(self)
1291 1389
 
1390
+        elif self.cpu_mode == 'exp':
1391
+
1392
+            self.lt_UD_centers_stage = LookupTable444UDCentersStage(self)
1393
+            self.lt_LR_centers_stage = LookupTable444LRCentersStage(self)
1394
+            self.lt_FB_centers_stage = LookupTable444FBCentersStage(self)
1395
+
1396
+            self.lt_ULFRBD_centers_stage = BidirIDA444ULFRBDCentersStage(self)
1397
+
1292 1398
         else:
1293 1399
             raise Exception("We should not be here, cpu_mode %s" % self.cpu_mode)
1294 1400
 
@@ -1306,10 +1412,13 @@ class RubiksCube444(RubiksCube):
1306 1412
             # - solve LR centers to one of 12 states
1307 1413
             # - stage UD and FB centers
1308 1414
             self.lt_tsai_phase2_centers = LookupTable444TsaiPhase2Centers(self)
1309
-            # self.lt_tsai_phase2_edges = LookupTable444TsaiPhase2Edges(self)
1415
+            self.lt_tsai_phase2_edges = LookupTable444TsaiPhase2Edges(self)
1310 1416
 
1311 1417
             self.lt_tsai_phase2 = LookupTableIDA444TsaiPhase2(self)
1312 1418
 
1419
+        elif self.cpu_mode == 'exp':
1420
+            pass
1421
+
1313 1422
         else:
1314 1423
             raise Exception("We should not be here, cpu_mode %s" % self.cpu_mode)
1315 1424
 
@@ -1330,6 +1439,9 @@ class RubiksCube444(RubiksCube):
1330 1439
 
1331 1440
             self.lt_tsai_phase3 = LookupTableIDA444TsaiPhase3(self)
1332 1441
 
1442
+        elif self.cpu_mode == 'exp':
1443
+            pass
1444
+
1333 1445
         else:
1334 1446
             raise Exception("We should not be here, cpu_mode %s" % self.cpu_mode)
1335 1447
 
@@ -1453,10 +1565,8 @@ class RubiksCube444(RubiksCube):
1453 1565
             self.lt_ULFRBD_centers_stage.avoid_oll = True
1454 1566
             self.lt_ULFRBD_centers_stage.solve()
1455 1567
             log.info("%s: End of Phase1, %d steps in" % (self, self.get_solution_len_minus_rotates(self.solution)))
1456
-            log.info("")
1457
-
1458 1568
             self.print_cube()
1459
-            sys.exit(0) # dwalton
1569
+            log.info("")
1460 1570
 
1461 1571
             log.info("%s: Start of Phase2, %d steps in" % (self, self.get_solution_len_minus_rotates(self.solution)))
1462 1572
             self.lt_ULFRBD_centers_solve.solve()
@@ -1464,6 +1574,16 @@ class RubiksCube444(RubiksCube):
1464 1574
             log.info("%s: End of Phase2, %d steps in" % (self, self.get_solution_len_minus_rotates(self.solution)))
1465 1575
             log.info("")
1466 1576
 
1577
+        elif self.cpu_mode == 'exp':
1578
+
1579
+            log.info("%s: Start of Phase1" % self)
1580
+            self.lt_ULFRBD_centers_stage.avoid_oll = True
1581
+            self.lt_ULFRBD_centers_stage.solve()
1582
+            log.info("%s: End of Phase1, %d steps in" % (self, self.get_solution_len_minus_rotates(self.solution)))
1583
+            self.print_cube()
1584
+            log.info("")
1585
+            sys.exit(0) # dwalton
1586
+
1467 1587
         # The tsai will solve the centers and pair the edges
1468 1588
         elif self.cpu_mode == 'tsai':
1469 1589
 
@@ -1471,6 +1591,7 @@ class RubiksCube444(RubiksCube):
1471 1591
             original_state = self.state[:]
1472 1592
             original_solution = self.solution[:]
1473 1593
 
1594
+            '''
1474 1595
             # Collect phase1 options
1475 1596
             phase1_options = []
1476 1597
             phase1_options_states = []
@@ -1518,7 +1639,7 @@ class RubiksCube444(RubiksCube):
1518 1639
             min_solution = None
1519 1640
             min_state = None
1520 1641
 
1521
-            for init_max_ida_threshold in range(8, 99):
1642
+            for init_max_ida_threshold in range(7, 99):
1522 1643
                 for (upper_side_name, front_side_name, transform, tmp_state, tmp_solution) in phase1_options:
1523 1644
                     self.state = tmp_state[:]
1524 1645
                     self.solution = tmp_solution[:]
@@ -1570,6 +1691,24 @@ class RubiksCube444(RubiksCube):
1570 1691
 
1571 1692
             log.info("%s: End of Phase1/2, %d steps in" % (self, self.get_solution_len_minus_rotates(self.solution)))
1572 1693
             log.info("")
1694
+            '''
1695
+
1696
+            log.info("%s: Start of Phase1, %d steps in" % (self, self.get_solution_len_minus_rotates(self.solution)))
1697
+            self.lt_LR_centers_stage.solve()
1698
+            self.print_cube()
1699
+            log.info("%s: End of Phase1, %d steps in" % (self, self.get_solution_len_minus_rotates(self.solution)))
1700
+
1701
+            # Test the prune table
1702
+            #self.lt_tsai_phase2_edges.solve()
1703
+            #self.lt_tsai_phase2_centers.solve()
1704
+            #self.tsai_phase2_orient_edges_print()
1705
+            #self.print_cube()
1706
+            #sys.exit(0)
1707
+
1708
+            log.info("%s: Start of Phase2, %d steps in" % (self, self.get_solution_len_minus_rotates(self.solution)))
1709
+            self.lt_tsai_phase2.solve()
1710
+            self.print_cube()
1711
+            log.info("%s: End of Phase2, %d steps in" % (self, self.get_solution_len_minus_rotates(self.solution)))
1573 1712
 
1574 1713
             # Testing the phase3 prune tables
1575 1714
             #self.lt_tsai_phase3_edges_solve.solve()

+ 29
- 17
rubikscubennnsolver/RubiksCube555.py View File

@@ -434,14 +434,22 @@ class LookupTable555FBXCenterStage(LookupTable):
434 434
         # Convert to hex
435 435
         return self.hex_format % int(result, 2)
436 436
 
437
-# dwalton exp
438
-#class LookupTableIDA555AllCenterStage(LookupTableAStar):
437
+
439 438
 class LookupTableIDA555AllCenterStage(LookupTableIDA):
440 439
     """
440
+    lookup-table-5x5x5-step100-ALL-centers-stage.txt
441
+    ================================================
442
+    1 steps has 7 entries (0 percent, 0.00x previous step)
443
+    2 steps has 147 entries (0 percent, 21.00x previous step)
444
+    3 steps has 3,054 entries (0 percent, 20.78x previous step)
445
+    4 steps has 65,520 entries (4 percent, 21.45x previous step)
446
+    5 steps has 1,467,630 entries (95 percent, 22.40x previous step)
447
+
448
+    Total: 1,536,358 entries
441 449
     """
442 450
 
443 451
     def __init__(self, parent):
444
-        LookupTableAStar.__init__(
452
+        LookupTableIDA.__init__(
445 453
             self,
446 454
             parent,
447 455
             'lookup-table-5x5x5-step100-ALL-centers-stage.txt',
@@ -461,7 +469,7 @@ class LookupTableIDA555AllCenterStage(LookupTableIDA):
461 469
     def state(self):
462 470
         parent_state = self.parent.state
463 471
 
464
-        result = [
472
+        tmp_result = [
465 473
             # Upper
466 474
             parent_state[7], parent_state[8], parent_state[9],
467 475
             parent_state[12], parent_state[13], parent_state[14],
@@ -493,11 +501,18 @@ class LookupTableIDA555AllCenterStage(LookupTableIDA):
493 501
             parent_state[142], parent_state[143], parent_state[144]
494 502
         ]
495 503
 
496
-        result = ['1' if x in ('U', 'D') else '0' for x in result]
497
-        result = ''.join(result)
504
+        # dwalton fix this
505
+        result = []
498 506
 
499
-        # Convert to hex
500
-        return self.hex_format % int(result, 2)
507
+        for x in tmp_result:
508
+            if x in ('U', 'D'):
509
+                result.append('U')
510
+            elif x in ('L', 'R'):
511
+                result.append('L')
512
+            elif x in ('F', 'B'):
513
+                result.append('F')
514
+
515
+        return ''.join(result)
501 516
 
502 517
 
503 518
 class LookupTable555CpuMinUDTCenterStage(LookupTable):
@@ -1330,7 +1345,8 @@ class RubiksCube555(RubiksCube):
1330 1345
             return
1331 1346
         self.lt_init_called = True
1332 1347
 
1333
-        # dwalton experiment
1348
+        # experiment
1349
+        '''
1334 1350
         self.lt_UD_T_centers_stage = LookupTable555UDTCenterStage(self)
1335 1351
         self.lt_UD_X_centers_stage = LookupTable555UDXCenterStage(self)
1336 1352
         self.lt_LR_T_centers_stage = LookupTable555LRTCenterStage(self)
@@ -1338,8 +1354,8 @@ class RubiksCube555(RubiksCube):
1338 1354
         self.lt_FB_T_centers_stage = LookupTable555FBTCenterStage(self)
1339 1355
         self.lt_FB_X_centers_stage = LookupTable555FBXCenterStage(self)
1340 1356
         self.lt_ALL_enters_stage = LookupTableIDA555AllCenterStage(self)
1341
-
1342 1357
         '''
1358
+
1343 1359
         if self.cpu_mode == 'min':
1344 1360
             self.lt_UD_T_centers_stage = LookupTable555CpuMinUDTCenterStage(self)
1345 1361
             self.lt_UD_X_centers_stage = LookupTable555CpuMinUDXCenterStage(self)
@@ -1352,7 +1368,6 @@ class RubiksCube555(RubiksCube):
1352 1368
         self.lt_LR_centers_stage_x_center_only = LookupTable555LRXCentersStage(self)
1353 1369
         self.lt_LR_centers_stage_t_center_only = LookupTable555LRTCentersStage(self)
1354 1370
         self.lt_LR_centers_stage = LookupTableIDA555LRCentersStage(self)
1355
-        '''
1356 1371
 
1357 1372
         self.lt_UL_centers_solve = LookupTableULCentersSolve(self)
1358 1373
         self.lt_UF_centers_solve = LookupTableUFCentersSolve(self)
@@ -1440,12 +1455,10 @@ class RubiksCube555(RubiksCube):
1440 1455
         #self.lt_LR_X_centers_stage.solve()
1441 1456
         #self.lt_FB_T_centers_stage.solve()
1442 1457
         #self.lt_FB_X_centers_stage.solve()
1443
-        self.lt_ALL_enters_stage.solve()
1444
-        # dwalton exp
1445
-        self.print_cube()
1446
-        sys.exit()
1458
+        #self.lt_ALL_enters_stage.solve()
1459
+        #self.print_cube()
1460
+        #sys.exit()
1447 1461
 
1448
-        '''
1449 1462
         # Stage UD centers
1450 1463
         self.group_centers_stage_UD()
1451 1464
 
@@ -1455,7 +1468,6 @@ class RubiksCube555(RubiksCube):
1455 1468
 
1456 1469
         self.lt_LR_centers_stage.solve()
1457 1470
         log.info("ULFRBD centers staged, %d steps in" % self.get_solution_len_minus_rotates(self.solution))
1458
-        '''
1459 1471
 
1460 1472
         # All centers are staged so solve them
1461 1473
         self.lt_ULFRB_centers_solve.solve()