diff options
| author | Sebastiano Tronto <sebastiano.tronto@gmail.com> | 2021-11-20 16:08:43 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano.tronto@gmail.com> | 2021-11-20 16:08:43 +0100 |
| commit | a8c4da5b955eab2eed9ebb03ee4b1212ec6fe042 (patch) | |
| tree | 3fe233ce2883545ec42d2c3cf5661fba3818fb9d /src/cubetypes.h | |
| parent | 0df4f6f98101bb3be192ce892aa1452f2c6de1a4 (diff) | |
| download | nissy-a8c4da5b955eab2eed9ebb03ee4b1212ec6fe042.tar.gz nissy-a8c4da5b955eab2eed9ebb03ee4b1212ec6fe042.zip | |
Multithreading seems to be working now, it was easier than expected!
Diffstat (limited to 'src/cubetypes.h')
| -rw-r--r-- | src/cubetypes.h | 231 |
1 files changed, 126 insertions, 105 deletions
diff --git a/src/cubetypes.h b/src/cubetypes.h index 334662c..7eb803e 100644 --- a/src/cubetypes.h +++ b/src/cubetypes.h | |||
| @@ -3,6 +3,7 @@ | |||
| 3 | 3 | ||
| 4 | #include <stdbool.h> | 4 | #include <stdbool.h> |
| 5 | #include <inttypes.h> | 5 | #include <inttypes.h> |
| 6 | #include <pthread.h> | ||
| 6 | 7 | ||
| 7 | #define NMOVES 55 /* Actually 55, but one is NULLMOVE */ | 8 | #define NMOVES 55 /* Actually 55, but one is NULLMOVE */ |
| 8 | #define NTRANS 48 | 9 | #define NTRANS 48 |
| @@ -87,6 +88,7 @@ typedef struct prunedata PruneData; | |||
| 87 | typedef struct solveoptions SolveOptions; | 88 | typedef struct solveoptions SolveOptions; |
| 88 | typedef struct step Step; | 89 | typedef struct step Step; |
| 89 | typedef struct symdata SymData; | 90 | typedef struct symdata SymData; |
| 91 | typedef struct threaddata ThreadData; | ||
| 90 | 92 | ||
| 91 | typedef Cube (*AntiIndexer) (uint64_t); | 93 | typedef Cube (*AntiIndexer) (uint64_t); |
| 92 | typedef bool (*Checker) (Cube); | 94 | typedef bool (*Checker) (Cube); |
| @@ -104,186 +106,205 @@ typedef Trans (*TransDetector) (Cube); | |||
| 104 | struct | 106 | struct |
| 105 | alg | 107 | alg |
| 106 | { | 108 | { |
| 107 | Move * move; | 109 | Move * move; |
| 108 | bool * inv; | 110 | bool * inv; |
| 109 | int len; | 111 | int len; |
| 110 | int allocated; | 112 | int allocated; |
| 111 | }; | 113 | }; |
| 112 | 114 | ||
| 113 | struct | 115 | struct |
| 114 | alglist | 116 | alglist |
| 115 | { | 117 | { |
| 116 | AlgListNode * first; | 118 | AlgListNode * first; |
| 117 | AlgListNode * last; | 119 | AlgListNode * last; |
| 118 | int len; | 120 | int len; |
| 119 | }; | 121 | }; |
| 120 | 122 | ||
| 121 | struct | 123 | struct |
| 122 | alglistnode | 124 | alglistnode |
| 123 | { | 125 | { |
| 124 | Alg * alg; | 126 | Alg * alg; |
| 125 | AlgListNode * next; | 127 | AlgListNode * next; |
| 126 | }; | 128 | }; |
| 127 | 129 | ||
| 128 | struct | 130 | struct |
| 129 | block | 131 | block |
| 130 | { | 132 | { |
| 131 | bool edge[12]; | 133 | bool edge[12]; |
| 132 | bool corner[8]; | 134 | bool corner[8]; |
| 133 | bool center[6]; | 135 | bool center[6]; |
| 134 | }; | 136 | }; |
| 135 | 137 | ||
| 136 | struct | 138 | struct |
| 137 | command | 139 | command |
| 138 | { | 140 | { |
| 139 | char * name; | 141 | char * name; |
| 140 | char * usage; | 142 | char * usage; |
| 141 | char * description; | 143 | char * description; |
| 142 | ArgParser parse_args; | 144 | ArgParser parse_args; |
| 143 | Exec exec; | 145 | Exec exec; |
| 144 | }; | 146 | }; |
| 145 | 147 | ||
| 146 | struct | 148 | struct |
| 147 | commandargs | 149 | commandargs |
| 148 | { | 150 | { |
| 149 | bool success; | 151 | bool success; |
| 150 | Alg * scramble; | 152 | Alg * scramble; |
| 151 | SolveOptions * opts; | 153 | SolveOptions * opts; |
| 152 | Step * step; | 154 | Step * step; |
| 153 | Command * command; /* For help */ | 155 | Command * command; /* For help */ |
| 154 | }; | 156 | }; |
| 155 | 157 | ||
| 156 | struct | 158 | struct |
| 157 | coordinate | 159 | coordinate |
| 158 | { | 160 | { |
| 159 | Indexer index; | 161 | Indexer index; |
| 160 | AntiIndexer cube; | 162 | AntiIndexer cube; |
| 161 | uint64_t max; | 163 | uint64_t max; |
| 162 | int ntrans; | 164 | int ntrans; |
| 163 | Trans * trans; | 165 | Trans * trans; |
| 164 | }; | 166 | }; |
| 165 | 167 | ||
| 166 | struct | 168 | struct |
| 167 | cube | 169 | cube |
| 168 | { | 170 | { |
| 169 | int epose; | 171 | int epose; |
| 170 | int eposs; | 172 | int eposs; |
| 171 | int eposm; | 173 | int eposm; |
| 172 | int eofb; | 174 | int eofb; |
| 173 | int eorl; | 175 | int eorl; |
| 174 | int eoud; | 176 | int eoud; |
| 175 | int cp; | 177 | int cp; |
| 176 | int coud; | 178 | int coud; |
| 177 | int cofb; | 179 | int cofb; |
| 178 | int corl; | 180 | int corl; |
| 179 | int cpos; | 181 | int cpos; |
| 180 | }; | 182 | }; |
| 181 | 183 | ||
| 182 | struct | 184 | struct |
| 183 | cubearray | 185 | cubearray |
| 184 | { | 186 | { |
| 185 | int * ep; | 187 | int * ep; |
| 186 | int * eofb; | 188 | int * eofb; |
| 187 | int * eorl; | 189 | int * eorl; |
| 188 | int * eoud; | 190 | int * eoud; |
| 189 | int * cp; | 191 | int * cp; |
| 190 | int * coud; | 192 | int * coud; |
| 191 | int * corl; | 193 | int * corl; |
| 192 | int * cofb; | 194 | int * cofb; |
| 193 | int * cpos; | 195 | int * cpos; |
| 194 | }; | 196 | }; |
| 195 | 197 | ||
| 196 | struct | 198 | struct |
| 197 | cubetarget | 199 | cubetarget |
| 198 | { | 200 | { |
| 199 | Cube cube; | 201 | Cube cube; |
| 200 | int target; | 202 | int target; |
| 201 | }; | 203 | }; |
| 202 | 204 | ||
| 203 | struct | 205 | struct |
| 204 | dfsdata | 206 | dfsdata |
| 205 | { | 207 | { |
| 206 | int d; | 208 | int d; |
| 207 | int m; | 209 | int m; |
| 208 | int lb; | 210 | int lb; |
| 209 | bool niss; | 211 | bool niss; |
| 210 | Move last1; | 212 | Move last1; |
| 211 | Move last2; | 213 | Move last2; |
| 212 | AlgList * sols; | 214 | AlgList * sols; |
| 213 | Alg * current_alg; | 215 | pthread_mutex_t * sols_mutex; |
| 214 | Move sorted_moves[NMOVES]; | 216 | Alg * current_alg; |
| 215 | int move_position[NMOVES]; | 217 | Move * sorted_moves; |
| 216 | uint8_t * visited; | 218 | int * move_position; |
| 219 | uint8_t * visited; | ||
| 217 | }; | 220 | }; |
| 218 | 221 | ||
| 219 | struct | 222 | struct |
| 220 | piecefilter | 223 | piecefilter |
| 221 | { | 224 | { |
| 222 | bool epose; | 225 | bool epose; |
| 223 | bool eposs; | 226 | bool eposs; |
| 224 | bool eposm; | 227 | bool eposm; |
| 225 | bool eofb; | 228 | bool eofb; |
| 226 | bool eorl; | 229 | bool eorl; |
| 227 | bool eoud; | 230 | bool eoud; |
| 228 | bool cp; | 231 | bool cp; |
| 229 | bool coud; | 232 | bool coud; |
| 230 | bool cofb; | 233 | bool cofb; |
| 231 | bool corl; | 234 | bool corl; |
| 232 | bool cpos; | 235 | bool cpos; |
| 233 | }; | 236 | }; |
| 234 | 237 | ||
| 235 | struct | 238 | struct |
| 236 | prunedata | 239 | prunedata |
| 237 | { | 240 | { |
| 238 | char * filename; | 241 | char * filename; |
| 239 | uint8_t * ptable; | 242 | uint8_t * ptable; |
| 240 | bool generated; | 243 | bool generated; |
| 241 | uint64_t n; | 244 | uint64_t n; |
| 242 | Coordinate * coord; | 245 | Coordinate * coord; |
| 243 | Moveset moveset; | 246 | Moveset moveset; |
| 244 | }; | 247 | }; |
| 245 | 248 | ||
| 246 | struct | 249 | struct |
| 247 | solveoptions | 250 | solveoptions |
| 248 | { | 251 | { |
| 249 | int min_moves; | 252 | int min_moves; |
| 250 | int max_moves; | 253 | int max_moves; |
| 251 | int max_solutions; | 254 | int max_solutions; |
| 252 | bool optimal_only; | 255 | int nthreads; |
| 253 | bool can_niss; | 256 | bool optimal_only; |
| 254 | bool verbose; | 257 | bool can_niss; |
| 255 | bool all; | 258 | bool verbose; |
| 256 | bool print_number; | 259 | bool all; |
| 260 | bool print_number; | ||
| 257 | }; | 261 | }; |
| 258 | 262 | ||
| 259 | struct | 263 | struct |
| 260 | step | 264 | step |
| 261 | { | 265 | { |
| 262 | char * shortname; | 266 | char * shortname; |
| 263 | char * name; | 267 | char * name; |
| 264 | Estimator estimate; | 268 | Estimator estimate; |
| 265 | Checker ready; | 269 | Checker ready; |
| 266 | char * ready_msg; | 270 | char * ready_msg; |
| 267 | Validator is_valid; | 271 | Validator is_valid; |
| 268 | Moveset moveset; | 272 | Moveset moveset; |
| 269 | Trans pre_trans; | 273 | Trans pre_trans; |
| 270 | TransDetector detect; | 274 | TransDetector detect; |
| 271 | int ntables; | 275 | int ntables; |
| 272 | PruneData * tables[10]; | 276 | PruneData * tables[10]; |
| 273 | }; | 277 | }; |
| 274 | 278 | ||
| 275 | struct | 279 | struct |
| 276 | symdata | 280 | symdata |
| 277 | { | 281 | { |
| 278 | char * filename; | 282 | char * filename; |
| 279 | bool generated; | 283 | bool generated; |
| 280 | Coordinate * coord; | 284 | Coordinate * coord; |
| 281 | Coordinate * sym_coord; | 285 | Coordinate * sym_coord; |
| 282 | int ntrans; | 286 | int ntrans; |
| 283 | Trans * trans; | 287 | Trans * trans; |
| 284 | uint64_t * class; | 288 | uint64_t * class; |
| 285 | Cube * rep; | 289 | Cube * rep; |
| 286 | Trans * transtorep; | 290 | Trans * transtorep; |
| 291 | }; | ||
| 292 | |||
| 293 | struct | ||
| 294 | threaddata | ||
| 295 | { | ||
| 296 | int thid; | ||
| 297 | Cube cube; | ||
| 298 | Step * step; | ||
| 299 | int depth; | ||
| 300 | Move * sorted_moves; | ||
| 301 | int * move_position; | ||
| 302 | SolveOptions * opts; | ||
| 303 | AlgList * start; | ||
| 304 | AlgListNode ** node; | ||
| 305 | AlgList * sols; | ||
| 306 | pthread_mutex_t * start_mutex; | ||
| 307 | pthread_mutex_t * sols_mutex; | ||
| 287 | }; | 308 | }; |
| 288 | 309 | ||
| 289 | #endif | 310 | #endif |
