h48

A prototype for an optimal Rubik's cube solver, work in progress.
git clone https://git.tronto.net/h48
Download | Log | Files | Refs | README | LICENSE

expected_distributions.h (3308B)


      1 uint64_t expected_cocsep[21] = {
      2 	[0] = 1,
      3 	[1] = 6,
      4 	[2] = 63,
      5 	[3] = 468,
      6 	[4] = 3068,
      7 	[5] = 15438,
      8 	[6] = 53814,
      9 	[7] = 71352,
     10 	[8] = 8784,
     11 	[9] = 96
     12 };
     13 
     14 uint64_t expected_h48[12][9][21] = {
     15 	[0] = {
     16 		[2] = {
     17 			[0] = 5473562,
     18 			[1] = 34776317,
     19 			[2] = 68566704,
     20 			[3] = 8750867,
     21 		},
     22 		[4] = {
     23 			[0] = 1,
     24 			[1] = 1,
     25 			[2] = 4,
     26 			[3] = 34,
     27 			[4] = 331,
     28 			[5] = 3612,
     29 			[6] = 41605,
     30 			[7] = 474128,
     31 			[8] = 4953846,
     32 			[9] = 34776317,
     33 			[10] = 68566704,
     34 			[11] = 8749194,
     35 			[12] = 1673,
     36 		},
     37 	},
     38 	[1] = {
     39 		[2] = {
     40 			[0] = 6012079,
     41 			[1] = 45822302,
     42 			[2] = 142018732,
     43 			[3] = 41281787,
     44 		},
     45 	},
     46 	[2] = {
     47 		[2] = {
     48 			[0] = 6391286,
     49 			[1] = 55494785,
     50 			[2] = 252389935,
     51 			[3] = 155993794,
     52 		},
     53 	},
     54 	[3] = {
     55 		[2] = {
     56 			[0] = 6686828,
     57 			[1] = 63867852,
     58 			[2] = 392789689,
     59 			[3] = 477195231,
     60 		},
     61 
     62 	},
     63 	[4] = {
     64 		[2] = {
     65 			[0] = 77147213,
     66 			[1] = 543379415,
     67 			[2] = 1139570251,
     68 			[3] = 120982321,
     69 		},
     70 	},
     71 	[5] = {
     72 		[2] = {
     73 			[0] = 82471284,
     74 			[1] = 687850732,
     75 			[2] = 2345840746,
     76 			[3] = 645995638,
     77 		},
     78 	},
     79 	[6] = {
     80 		[2] = {
     81 			[0] = 85941099,
     82 			[1] = 804752968,
     83 			[2] = 4077248182,
     84 			[3] = 2556374551,
     85 		},
     86 	},
     87 	[7] = {
     88 		[2] = {
     89 			[0] = 88529761,
     90 			[1] = 897323475,
     91 			[2] = 6126260791,
     92 			[3] = 7936519573,
     93 		},
     94 	},
     95 	[8] = {
     96 		[2] = {
     97 			[0] = 1051579940,
     98 			[1] = 8136021316,
     99 			[2] = 19024479822,
    100 			[3] = 18851861220,
    101 		},
    102 	},
    103 	[9] = {
    104 		[2] = {
    105 			[0] = 1102038189,
    106 			[1] = 9888265242,
    107 			[2] = 38299375805,
    108 			[3] = 10904855164,
    109 		},
    110 	},
    111 	[10] = {
    112 		[2] = {
    113 			[0] = 1133240039,
    114 			[1] = 11196285614,
    115 			[2] = 64164702961,
    116 			[3] = 43894840186,
    117 		},
    118 	},
    119 	[11] = {
    120 		[2] = {
    121 			[0] = 1150763161,
    122 			[1] = 12045845660,
    123 			[2] = 91163433330,
    124 			[3] = 136418095449,
    125 		},
    126 	},
    127 };
    128 
    129 static bool
    130 distribution_equal(const uint64_t *expected, const uint64_t *actual, int n)
    131 {
    132 	bool equal;
    133 	int i;
    134 
    135 	for (i = 0, equal = true; i <= n; i++) {
    136 		if (expected[i] != actual[i]) {
    137 			equal = false;
    138 			printf("Wrong value for %d: expected %" PRIu64
    139 			    ", actual %" PRIu64 "\n",
    140 			    i, expected[i], actual[i]);
    141 		}
    142 	}
    143 
    144 	return equal;
    145 }
    146 
    147 static bool
    148 check_cocsep(uint64_t data_size, const void *data)
    149 {
    150 	tableinfo_t info;
    151 
    152 	readtableinfo(data_size, data, &info);
    153 	return distribution_equal(
    154 	    expected_cocsep, info.distribution, info.maxvalue);
    155 }
    156 
    157 static bool
    158 unknown_h48(uint8_t h, uint8_t k)
    159 {
    160 	if (k != 2 && k != 4)
    161 		return true;
    162 
    163 	if (k == 4 && h != 0)
    164 		return true;
    165 
    166 	return k == 2 && h > 7;
    167 }
    168 
    169 STATIC bool
    170 check_distribution(const char *solver, uint64_t data_size, const void *data)
    171 {
    172 	tableinfo_t info = {0};
    173 
    174 	if (!strncmp(solver, "h48", 3)) {
    175 		readtableinfo(data_size, data, &info);
    176 		if (!distribution_equal(
    177 		    expected_cocsep, info.distribution, info.maxvalue)) {
    178 			printf("ERROR! cocsep distribution is incorrect\n");
    179 			return false;
    180 		}
    181 		printf("cocsep distribution is correct\n");
    182 
    183 		readtableinfo_n(data_size, data, 2, &info);
    184 		if (unknown_h48(info.h48h, info.bits))
    185 			goto check_distribution_unknown;
    186 
    187 		if (!distribution_equal(expected_h48[info.h48h][info.bits],
    188 		    info.distribution, info.maxvalue)) {
    189 			printf("ERROR! h48 distribution is incorrect\n");
    190 			return false;
    191 		}
    192 
    193 		printf("h48 distribution is correct\n");
    194 		return true;
    195 	}
    196 
    197 check_distribution_unknown:
    198 	printf("Distribution unknown, not checked\n");
    199 	return true;
    200 }