diff options
Diffstat (limited to '')
| -rw-r--r-- | src/cubetypes.h | 311 | ||||
| -rw-r--r-- | src/pruning.c | 44 | ||||
| -rw-r--r-- | src/solve.c | 6 |
3 files changed, 191 insertions, 170 deletions
diff --git a/src/cubetypes.h b/src/cubetypes.h index f4e682d..ccc2d34 100644 --- a/src/cubetypes.h +++ b/src/cubetypes.h | |||
| @@ -72,24 +72,25 @@ trans | |||
| 72 | 72 | ||
| 73 | /* Typedefs ******************************************************************/ | 73 | /* Typedefs ******************************************************************/ |
| 74 | 74 | ||
| 75 | typedef struct alg Alg; | 75 | typedef struct alg Alg; |
| 76 | typedef struct alglist AlgList; | 76 | typedef struct alglist AlgList; |
| 77 | typedef struct alglistnode AlgListNode; | 77 | typedef struct alglistnode AlgListNode; |
| 78 | typedef struct block Block; | 78 | typedef struct block Block; |
| 79 | typedef struct command Command; | 79 | typedef struct command Command; |
| 80 | typedef struct commandargs CommandArgs; | 80 | typedef struct commandargs CommandArgs; |
| 81 | typedef struct coordinate Coordinate; | 81 | typedef struct coordinate Coordinate; |
| 82 | typedef struct cube Cube; | 82 | typedef struct cube Cube; |
| 83 | typedef struct cubearray CubeArray; | 83 | typedef struct cubearray CubeArray; |
| 84 | typedef struct dfsdata DfsData; | 84 | typedef struct dfsdata DfsData; |
| 85 | typedef struct estimatedata EstimateData; | 85 | typedef struct estimatedata EstimateData; |
| 86 | typedef struct localinfo LocalInfo; | 86 | typedef struct localinfo LocalInfo; |
| 87 | typedef struct piecefilter PieceFilter; | 87 | typedef struct piecefilter PieceFilter; |
| 88 | typedef struct prunedata PruneData; | 88 | typedef struct prunedata PruneData; |
| 89 | typedef struct solveoptions SolveOptions; | 89 | typedef struct solveoptions SolveOptions; |
| 90 | typedef struct step Step; | 90 | typedef struct step Step; |
| 91 | typedef struct symdata SymData; | 91 | typedef struct symdata SymData; |
| 92 | typedef struct threaddata ThreadData; | 92 | typedef struct threaddatasolve ThreadDataSolve; |
| 93 | typedef struct threaddatagenpt ThreadDataGenpt; | ||
| 93 | 94 | ||
| 94 | typedef Cube (*AntiIndexer) (uint64_t); | 95 | typedef Cube (*AntiIndexer) (uint64_t); |
| 95 | typedef bool (*Checker) (Cube); | 96 | typedef bool (*Checker) (Cube); |
| @@ -108,221 +109,233 @@ typedef int (*TransFinder) (uint64_t, Trans *); | |||
| 108 | struct | 109 | struct |
| 109 | alg | 110 | alg |
| 110 | { | 111 | { |
| 111 | Move * move; | 112 | Move * move; |
| 112 | bool * inv; | 113 | bool * inv; |
| 113 | int len; | 114 | int len; |
| 114 | int allocated; | 115 | int allocated; |
| 115 | }; | 116 | }; |
| 116 | 117 | ||
| 117 | struct | 118 | struct |
| 118 | alglist | 119 | alglist |
| 119 | { | 120 | { |
| 120 | AlgListNode * first; | 121 | AlgListNode * first; |
| 121 | AlgListNode * last; | 122 | AlgListNode * last; |
| 122 | int len; | 123 | int len; |
| 123 | }; | 124 | }; |
| 124 | 125 | ||
| 125 | struct | 126 | struct |
| 126 | alglistnode | 127 | alglistnode |
| 127 | { | 128 | { |
| 128 | Alg * alg; | 129 | Alg * alg; |
| 129 | AlgListNode * next; | 130 | AlgListNode * next; |
| 130 | }; | 131 | }; |
| 131 | 132 | ||
| 132 | struct | 133 | struct |
| 133 | block | 134 | block |
| 134 | { | 135 | { |
| 135 | bool edge[12]; | 136 | bool edge[12]; |
| 136 | bool corner[8]; | 137 | bool corner[8]; |
| 137 | bool center[6]; | 138 | bool center[6]; |
| 138 | }; | 139 | }; |
| 139 | 140 | ||
| 140 | struct | 141 | struct |
| 141 | command | 142 | command |
| 142 | { | 143 | { |
| 143 | char * name; | 144 | char * name; |
| 144 | char * usage; | 145 | char * usage; |
| 145 | char * description; | 146 | char * description; |
| 146 | ArgParser parse_args; | 147 | ArgParser parse_args; |
| 147 | Exec exec; | 148 | Exec exec; |
| 148 | }; | 149 | }; |
| 149 | 150 | ||
| 150 | struct | 151 | struct |
| 151 | commandargs | 152 | commandargs |
| 152 | { | 153 | { |
| 153 | bool success; | 154 | bool success; |
| 154 | Alg * scramble; | 155 | Alg * scramble; |
| 155 | SolveOptions * opts; | 156 | SolveOptions * opts; |
| 156 | Step * step; | 157 | Step * step; |
| 157 | Command * command; /* For help */ | 158 | Command * command; /* For help */ |
| 158 | }; | 159 | }; |
| 159 | 160 | ||
| 160 | struct | 161 | struct |
| 161 | coordinate | 162 | coordinate |
| 162 | { | 163 | { |
| 163 | Indexer index; | 164 | Indexer index; |
| 164 | AntiIndexer cube; | 165 | AntiIndexer cube; |
| 165 | uint64_t max; | 166 | uint64_t max; |
| 166 | TransFinder trans; | 167 | TransFinder trans; |
| 167 | }; | 168 | }; |
| 168 | 169 | ||
| 169 | struct | 170 | struct |
| 170 | cube | 171 | cube |
| 171 | { | 172 | { |
| 172 | int epose; | 173 | int epose; |
| 173 | int eposs; | 174 | int eposs; |
| 174 | int eposm; | 175 | int eposm; |
| 175 | int eofb; | 176 | int eofb; |
| 176 | int eorl; | 177 | int eorl; |
| 177 | int eoud; | 178 | int eoud; |
| 178 | int cp; | 179 | int cp; |
| 179 | int coud; | 180 | int coud; |
| 180 | int cofb; | 181 | int cofb; |
| 181 | int corl; | 182 | int corl; |
| 182 | int cpos; | 183 | int cpos; |
| 183 | }; | 184 | }; |
| 184 | 185 | ||
| 185 | struct | 186 | struct |
| 186 | cubearray | 187 | cubearray |
| 187 | { | 188 | { |
| 188 | int * ep; | 189 | int * ep; |
| 189 | int * eofb; | 190 | int * eofb; |
| 190 | int * eorl; | 191 | int * eorl; |
| 191 | int * eoud; | 192 | int * eoud; |
| 192 | int * cp; | 193 | int * cp; |
| 193 | int * coud; | 194 | int * coud; |
| 194 | int * corl; | 195 | int * corl; |
| 195 | int * cofb; | 196 | int * cofb; |
| 196 | int * cpos; | 197 | int * cpos; |
| 197 | }; | 198 | }; |
| 198 | 199 | ||
| 199 | struct | 200 | struct |
| 200 | dfsdata | 201 | dfsdata |
| 201 | { | 202 | { |
| 202 | int d; | 203 | int d; |
| 203 | int m; | 204 | int m; |
| 204 | int lb; | 205 | int lb; |
| 205 | bool niss; | 206 | bool niss; |
| 206 | Move last1; | 207 | Move last1; |
| 207 | Move last2; | 208 | Move last2; |
| 208 | EstimateData * ed; | 209 | EstimateData * ed; |
| 209 | AlgList * sols; | 210 | AlgList * sols; |
| 210 | pthread_mutex_t * sols_mutex; | 211 | pthread_mutex_t * sols_mutex; |
| 211 | Alg * current_alg; | 212 | Alg * current_alg; |
| 212 | Move * sorted_moves; | 213 | Move * sorted_moves; |
| 213 | int * move_position; | 214 | int * move_position; |
| 214 | uint8_t * visited; | 215 | uint8_t * visited; |
| 215 | }; | 216 | }; |
| 216 | 217 | ||
| 217 | struct | 218 | struct |
| 218 | estimatedata | 219 | estimatedata |
| 219 | { | 220 | { |
| 220 | Cube cube; | 221 | Cube cube; |
| 221 | int target; | 222 | int target; |
| 222 | Move lastmove; | 223 | Move lastmove; |
| 223 | uint64_t movebitmask; | 224 | uint64_t movebitmask; |
| 224 | LocalInfo * li; | 225 | LocalInfo * li; |
| 225 | }; | 226 | }; |
| 226 | 227 | ||
| 227 | struct | 228 | struct |
| 228 | localinfo | 229 | localinfo |
| 229 | { | 230 | { |
| 230 | int corners; | 231 | int corners; |
| 231 | int normal_ud; | 232 | int normal_ud; |
| 232 | int normal_fb; | 233 | int normal_fb; |
| 233 | int normal_rl; | 234 | int normal_rl; |
| 234 | int inverse_ud; | 235 | int inverse_ud; |
| 235 | int inverse_fb; | 236 | int inverse_fb; |
| 236 | int inverse_rl; | 237 | int inverse_rl; |
| 237 | int prev_ret; | 238 | int prev_ret; |
| 238 | }; | 239 | }; |
| 239 | 240 | ||
| 240 | struct | 241 | struct |
| 241 | piecefilter | 242 | piecefilter |
| 242 | { | 243 | { |
| 243 | bool epose; | 244 | bool epose; |
| 244 | bool eposs; | 245 | bool eposs; |
| 245 | bool eposm; | 246 | bool eposm; |
| 246 | bool eofb; | 247 | bool eofb; |
| 247 | bool eorl; | 248 | bool eorl; |
| 248 | bool eoud; | 249 | bool eoud; |
| 249 | bool cp; | 250 | bool cp; |
| 250 | bool coud; | 251 | bool coud; |
| 251 | bool cofb; | 252 | bool cofb; |
| 252 | bool corl; | 253 | bool corl; |
| 253 | bool cpos; | 254 | bool cpos; |
| 254 | }; | 255 | }; |
| 255 | 256 | ||
| 256 | struct | 257 | struct |
| 257 | prunedata | 258 | prunedata |
| 258 | { | 259 | { |
| 259 | char * filename; | 260 | char * filename; |
| 260 | uint8_t * ptable; | 261 | uint8_t * ptable; |
| 261 | bool generated; | 262 | bool generated; |
| 262 | uint64_t n; | 263 | uint64_t n; |
| 263 | Coordinate * coord; | 264 | Coordinate * coord; |
| 264 | Moveset moveset; | 265 | Moveset moveset; |
| 265 | }; | 266 | }; |
| 266 | 267 | ||
| 267 | struct | 268 | struct |
| 268 | solveoptions | 269 | solveoptions |
| 269 | { | 270 | { |
| 270 | int min_moves; | 271 | int min_moves; |
| 271 | int max_moves; | 272 | int max_moves; |
| 272 | int max_solutions; | 273 | int max_solutions; |
| 273 | int nthreads; | 274 | int nthreads; |
| 274 | bool optimal_only; | 275 | bool optimal_only; |
| 275 | bool can_niss; | 276 | bool can_niss; |
| 276 | bool verbose; | 277 | bool verbose; |
| 277 | bool all; | 278 | bool all; |
| 278 | bool print_number; | 279 | bool print_number; |
| 279 | }; | 280 | }; |
| 280 | 281 | ||
| 281 | struct | 282 | struct |
| 282 | step | 283 | step |
| 283 | { | 284 | { |
| 284 | char * shortname; | 285 | char * shortname; |
| 285 | char * name; | 286 | char * name; |
| 286 | Estimator estimate; | 287 | Estimator estimate; |
| 287 | Checker ready; | 288 | Checker ready; |
| 288 | char * ready_msg; | 289 | char * ready_msg; |
| 289 | Validator is_valid; | 290 | Validator is_valid; |
| 290 | Moveset moveset; | 291 | Moveset moveset; |
| 291 | Trans pre_trans; | 292 | Trans pre_trans; |
| 292 | TransDetector detect; | 293 | TransDetector detect; |
| 293 | int ntables; | 294 | int ntables; |
| 294 | PruneData * tables[10]; | 295 | PruneData * tables[10]; |
| 295 | }; | 296 | }; |
| 296 | 297 | ||
| 297 | struct | 298 | struct |
| 298 | symdata | 299 | symdata |
| 299 | { | 300 | { |
| 300 | char * filename; | 301 | char * filename; |
| 301 | bool generated; | 302 | bool generated; |
| 302 | Coordinate * coord; | 303 | Coordinate * coord; |
| 303 | Coordinate * sym_coord; | 304 | Coordinate * sym_coord; |
| 304 | int ntrans; | 305 | int ntrans; |
| 305 | Trans * trans; | 306 | Trans * trans; |
| 306 | uint64_t * class; | 307 | uint64_t * class; |
| 307 | Cube * rep; | 308 | Cube * rep; |
| 308 | Trans * transtorep; | 309 | Trans * transtorep; |
| 309 | }; | 310 | }; |
| 310 | 311 | ||
| 311 | struct | 312 | struct |
| 312 | threaddata | 313 | threaddatasolve |
| 313 | { | 314 | { |
| 314 | int thid; | 315 | int thid; |
| 315 | Cube cube; | 316 | Cube cube; |
| 316 | Step * step; | 317 | Step * step; |
| 317 | int depth; | 318 | int depth; |
| 318 | Move * sorted_moves; | 319 | Move * sorted_moves; |
| 319 | int * move_position; | 320 | int * move_position; |
| 320 | SolveOptions * opts; | 321 | SolveOptions * opts; |
| 321 | AlgList * start; | 322 | AlgList * start; |
| 322 | AlgListNode ** node; | 323 | AlgListNode ** node; |
| 323 | AlgList * sols; | 324 | AlgList * sols; |
| 324 | pthread_mutex_t * start_mutex; | 325 | pthread_mutex_t * start_mutex; |
| 325 | pthread_mutex_t * sols_mutex; | 326 | pthread_mutex_t * sols_mutex; |
| 327 | }; | ||
| 328 | |||
| 329 | struct | ||
| 330 | threaddatagenpt | ||
| 331 | { | ||
| 332 | int thid; | ||
| 333 | PruneData * pd; | ||
| 334 | int d; | ||
| 335 | uint64_t rangemin; | ||
| 336 | uint64_t rangemax; | ||
| 337 | int nchunks; | ||
| 338 | pthread_mutex_t ** mutex; | ||
| 326 | }; | 339 | }; |
| 327 | 340 | ||
| 328 | #endif | 341 | #endif |
diff --git a/src/pruning.c b/src/pruning.c index 50299f0..8c6858d 100644 --- a/src/pruning.c +++ b/src/pruning.c | |||
| @@ -2,6 +2,7 @@ | |||
| 2 | 2 | ||
| 3 | static void genptable_bfs(PruneData *pd, int d, Move *ms); | 3 | static void genptable_bfs(PruneData *pd, int d, Move *ms); |
| 4 | static void genptable_branch(PruneData *pd,uint64_t ind,int d,Move *ms); | 4 | static void genptable_branch(PruneData *pd,uint64_t ind,int d,Move *ms); |
| 5 | static void genptable_fixnasty(PruneData *pd, int d); | ||
| 5 | static void ptable_update(PruneData *pd, Cube cube, int m); | 6 | static void ptable_update(PruneData *pd, Cube cube, int m); |
| 6 | static void ptable_update_index(PruneData *pd, uint64_t ind, int m); | 7 | static void ptable_update_index(PruneData *pd, uint64_t ind, int m); |
| 7 | static int ptableval_index(PruneData *pd, uint64_t ind); | 8 | static int ptableval_index(PruneData *pd, uint64_t ind); |
| @@ -114,6 +115,7 @@ genptable(PruneData *pd) | |||
| 114 | 0, pd->n - oldn, pd->n, pd->coord->max); | 115 | 0, pd->n - oldn, pd->n, pd->coord->max); |
| 115 | oldn = 1; | 116 | oldn = 1; |
| 116 | for (d = 0; d < 15 && pd->n < pd->coord->max; d++) { | 117 | for (d = 0; d < 15 && pd->n < pd->coord->max; d++) { |
| 118 | genptable_fixnasty(pd, d); | ||
| 117 | genptable_bfs(pd, d, ms); | 119 | genptable_bfs(pd, d, ms); |
| 118 | fprintf(stderr, "Depth %d done, generated %" | 120 | fprintf(stderr, "Depth %d done, generated %" |
| 119 | PRIu64 "\t(%" PRIu64 "/%" PRIu64 ")\n", | 121 | PRIu64 "\t(%" PRIu64 "/%" PRIu64 ")\n", |
| @@ -131,25 +133,7 @@ genptable(PruneData *pd) | |||
| 131 | static void | 133 | static void |
| 132 | genptable_bfs(PruneData *pd, int d, Move *ms) | 134 | genptable_bfs(PruneData *pd, int d, Move *ms) |
| 133 | { | 135 | { |
| 134 | int j, n; | ||
| 135 | uint64_t i; | 136 | uint64_t i; |
| 136 | Cube c, cc; | ||
| 137 | Trans t[NTRANS]; | ||
| 138 | |||
| 139 | for (i = 0; i < pd->coord->max; i++) { | ||
| 140 | if (ptableval_index(pd, i) == d) { | ||
| 141 | n = pd->coord->trans(i, t); | ||
| 142 | if (n == 1) | ||
| 143 | continue; | ||
| 144 | |||
| 145 | c = pd->coord->cube(i); | ||
| 146 | for (j = 0; j < n; j++) { | ||
| 147 | cc = apply_trans(t[j], c); | ||
| 148 | if (ptableval(pd, cc) > d) | ||
| 149 | ptable_update(pd, cc, d); | ||
| 150 | } | ||
| 151 | } | ||
| 152 | } | ||
| 153 | 137 | ||
| 154 | for (i = 0; i < pd->coord->max; i++) | 138 | for (i = 0; i < pd->coord->max; i++) |
| 155 | if (ptableval_index(pd, i) == d) | 139 | if (ptableval_index(pd, i) == d) |
| @@ -171,6 +155,30 @@ genptable_branch(PruneData *pd, uint64_t ind, int d, Move *ms) | |||
| 171 | } | 155 | } |
| 172 | } | 156 | } |
| 173 | 157 | ||
| 158 | static void | ||
| 159 | genptable_fixnasty(PruneData *pd, int d) | ||
| 160 | { | ||
| 161 | uint64_t i; | ||
| 162 | int j, n; | ||
| 163 | Cube c, cc; | ||
| 164 | Trans t[NTRANS]; | ||
| 165 | |||
| 166 | for (i = 0; i < pd->coord->max; i++) { | ||
| 167 | if (ptableval_index(pd, i) == d) { | ||
| 168 | n = pd->coord->trans(i, t); | ||
| 169 | if (n == 1) | ||
| 170 | continue; | ||
| 171 | |||
| 172 | c = pd->coord->cube(i); | ||
| 173 | for (j = 0; j < n; j++) { | ||
| 174 | cc = apply_trans(t[j], c); | ||
| 175 | if (ptableval(pd, cc) > d) | ||
| 176 | ptable_update(pd, cc, d); | ||
| 177 | } | ||
| 178 | } | ||
| 179 | } | ||
| 180 | } | ||
| 181 | |||
| 174 | void | 182 | void |
| 175 | print_ptable(PruneData *pd) | 183 | print_ptable(PruneData *pd) |
| 176 | { | 184 | { |
diff --git a/src/solve.c b/src/solve.c index 881edd6..42b4607 100644 --- a/src/solve.c +++ b/src/solve.c | |||
| @@ -156,11 +156,11 @@ instance_thread(void *arg) | |||
| 156 | { | 156 | { |
| 157 | bool b; | 157 | bool b; |
| 158 | Cube c; | 158 | Cube c; |
| 159 | ThreadData *td; | 159 | ThreadDataSolve *td; |
| 160 | AlgListNode *node; | 160 | AlgListNode *node; |
| 161 | DfsData dd; | 161 | DfsData dd; |
| 162 | 162 | ||
| 163 | td = (ThreadData *)arg; | 163 | td = (ThreadDataSolve *)arg; |
| 164 | 164 | ||
| 165 | while (1) { | 165 | while (1) { |
| 166 | b = false; | 166 | b = false; |
| @@ -215,7 +215,7 @@ multidfs(Cube c, Step *s, SolveOptions *opts, AlgList *sols, int d) | |||
| 215 | AlgList *start; | 215 | AlgList *start; |
| 216 | AlgListNode **node; | 216 | AlgListNode **node; |
| 217 | pthread_t t[opts->nthreads]; | 217 | pthread_t t[opts->nthreads]; |
| 218 | ThreadData td[opts->nthreads]; | 218 | ThreadDataSolve td[opts->nthreads]; |
| 219 | pthread_mutex_t *start_mutex, *sols_mutex; | 219 | pthread_mutex_t *start_mutex, *sols_mutex; |
| 220 | 220 | ||
| 221 | move_position = malloc(NMOVES * sizeof(int)); | 221 | move_position = malloc(NMOVES * sizeof(int)); |
