aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nissy.c47
-rw-r--r--src/nissy.h6
-rw-r--r--src/solvers/tables.h6
-rw-r--r--tools/001_gendata_h48h0k4/gendata_h48h0k4.c22
-rw-r--r--tools/002_gendata_h48h0k2/gendata_h48h0k2.c21
-rw-r--r--tools/020_solve_small/solve_small.c16
-rwxr-xr-xtools/run_tool.sh2
-rw-r--r--tools/tool.h10
8 files changed, 88 insertions, 42 deletions
diff --git a/src/nissy.c b/src/nissy.c
index de95e94..2d6af4b 100644
--- a/src/nissy.c
+++ b/src/nissy.c
@@ -196,6 +196,53 @@ nissy_datasize(
196} 196}
197 197
198int64_t 198int64_t
199nissy_datainfo(
200 const void *table,
201 void (*write)(const char *, ...)
202)
203{
204 uint8_t i;
205 tableinfo_t info;
206
207 readtableinfo(table, &info);
208
209 write("\n---------\n\n");
210 write("Table information for '%s'\n", info.solver);
211 write("\n");
212 write("Size: %" PRIu64 " bytes\n", info.fullsize);
213 write("Entries: %" PRIu64 " (%" PRIu8 " bits per entry)",
214 info.entries, info.bits);
215 write("\n");
216
217 switch (info.type) {
218 case TABLETYPE_PRUNING:
219 write("\n");
220 if (info.base != 0)
221 write(" (base value = %" PRIu8 ")", info.base);
222 write(":\nValue\tPositions\n");
223 for (i = 0; i <= info.maxvalue; i++) {
224 write("%" PRIu8 "\t%" PRIu64 "\n",
225 i, info.distribution[i]);
226 }
227 break;
228 case TABLETYPE_SPECIAL:
229 write("This is an ad-hoc table\n");
230 break;
231 default:
232 LOG("datainfo: unknown table type\n");
233 return 1;
234 }
235
236 if (info.next != 0) {
237 return nissy_datainfo((char *)table + info.next, write);
238 }
239
240 write("\n---------\n");
241
242 return 0;
243}
244
245int64_t
199nissy_gendata( 246nissy_gendata(
200 const char *solver, 247 const char *solver,
201 const char *options, 248 const char *options,
diff --git a/src/nissy.h b/src/nissy.h
index 346b99a..336130c 100644
--- a/src/nissy.h
+++ b/src/nissy.h
@@ -86,6 +86,12 @@ int64_t nissy_gendata(
86 void *generated_data 86 void *generated_data
87); 87);
88 88
89/* Print information on a data table via the provided callback writer */
90int64_t nissy_datainfo(
91 const void *table,
92 void (*write)(const char *, ...)
93);
94
89/* Returns the number of solutions found, or -1 in case of error */ 95/* Returns the number of solutions found, or -1 in case of error */
90int64_t nissy_solve( 96int64_t nissy_solve(
91 const char cube[static 22], 97 const char cube[static 22],
diff --git a/src/solvers/tables.h b/src/solvers/tables.h
index 44363fe..988de52 100644
--- a/src/solvers/tables.h
+++ b/src/solvers/tables.h
@@ -4,6 +4,9 @@
4#define INFO_SOLVER_STRLEN 100 4#define INFO_SOLVER_STRLEN 100
5#define INFO_DISTRIBUTION_LEN 21 5#define INFO_DISTRIBUTION_LEN 21
6 6
7#define TABLETYPE_PRUNING 0
8#define TABLETYPE_SPECIAL 1
9
7#define INFO_OFFSET_SOLVER 0 10#define INFO_OFFSET_SOLVER 0
8#define INFO_OFFSET_TYPE INFO_SOLVER_STRLEN 11#define INFO_OFFSET_TYPE INFO_SOLVER_STRLEN
9#define INFO_OFFSET_INFOSIZE (INFO_OFFSET_TYPE + sizeof(uint64_t)) 12#define INFO_OFFSET_INFOSIZE (INFO_OFFSET_TYPE + sizeof(uint64_t))
@@ -17,9 +20,6 @@
17#define INFO_OFFSET_NEXT (INFO_OFFSET_MAXVALUE + sizeof(uint8_t)) 20#define INFO_OFFSET_NEXT (INFO_OFFSET_MAXVALUE + sizeof(uint8_t))
18#define INFO_OFFSET_DISTRIBUTION (INFO_OFFSET_NEXT + sizeof(uint64_t)) 21#define INFO_OFFSET_DISTRIBUTION (INFO_OFFSET_NEXT + sizeof(uint64_t))
19 22
20const uint64_t TABLETYPE_PRUNING = 0;
21const uint64_t TABLETYPE_SPECIAL = 1;
22
23typedef struct { 23typedef struct {
24 char solver[INFO_SOLVER_STRLEN]; 24 char solver[INFO_SOLVER_STRLEN];
25 uint64_t type; 25 uint64_t type;
diff --git a/tools/001_gendata_h48h0k4/gendata_h48h0k4.c b/tools/001_gendata_h48h0k4/gendata_h48h0k4.c
index 0e3deb1..a9993b8 100644
--- a/tools/001_gendata_h48h0k4/gendata_h48h0k4.c
+++ b/tools/001_gendata_h48h0k4/gendata_h48h0k4.c
@@ -27,8 +27,6 @@ uint32_t expected[21] = {
27char *buf; 27char *buf;
28 28
29void run(void) { 29void run(void) {
30 uint32_t *h48info, x;
31 int i;
32 int64_t s; 30 int64_t s;
33 31
34 s = nissy_gendata("h48", OPTIONS, buf); 32 s = nissy_gendata("h48", OPTIONS, buf);
@@ -36,20 +34,12 @@ void run(void) {
36 if (s == -1) { 34 if (s == -1) {
37 printf("Error generating table\n"); 35 printf("Error generating table\n");
38 } else { 36 } else {
39 printf("Table is probably ok\n"); 37 nissy_datainfo(buf, write_stdout);
40/* 38 printf("\n");
41TODO: adapt to new tables 39 printf("Succesfully generated %" PRId64 " bytes. "
42 printf("Succesfully generated %" PRId64 " bytes. Table:\n", s); 40 "See above for details on the tables.\n", s);
43 h48info = (uint32_t *)buf + 1 + (ETABLESIZE(HVALUE) + COCSEPSIZE) / 4; 41
44 for (i = 0; i < MAXDEPTH+1 && h48info[i+1]; i++) { 42 /* TODO: check that the table is correct */
45 x = h48info[i+1];
46 printf("%d:\t%" PRIu32, i, x);
47 if (x != expected[i])
48 printf(" <--- Error! Expected: %" PRIu32,
49 expected[i]);
50 printf("\n");
51 }
52*/
53 } 43 }
54} 44}
55 45
diff --git a/tools/002_gendata_h48h0k2/gendata_h48h0k2.c b/tools/002_gendata_h48h0k2/gendata_h48h0k2.c
index 2754f80..271d339 100644
--- a/tools/002_gendata_h48h0k2/gendata_h48h0k2.c
+++ b/tools/002_gendata_h48h0k2/gendata_h48h0k2.c
@@ -5,9 +5,6 @@
5#define OPTIONS "0;2;20" 5#define OPTIONS "0;2;20"
6#define LONGOPTIONS "h = 0, k = 2, max depth = 20" 6#define LONGOPTIONS "h = 0, k = 2, max depth = 20"
7 7
8#define COCSEPSIZE 1119792
9#define ETABLESIZE(h) (((3393 * 495 * 70) >> 2) << (size_t)(h))
10
11uint32_t expected[21] = { 8uint32_t expected[21] = {
12 /* Base value is 8 */ 9 /* Base value is 8 */
13 [0] = 5473562, 10 [0] = 5473562,
@@ -19,8 +16,6 @@ uint32_t expected[21] = {
19char *buf; 16char *buf;
20 17
21void run(void) { 18void run(void) {
22 uint32_t *h48info, x;
23 int i;
24 int64_t s; 19 int64_t s;
25 20
26 s = nissy_gendata("h48", OPTIONS, buf); 21 s = nissy_gendata("h48", OPTIONS, buf);
@@ -28,16 +23,12 @@ void run(void) {
28 if (s == -1) { 23 if (s == -1) {
29 printf("Error generating table\n"); 24 printf("Error generating table\n");
30 } else { 25 } else {
31 printf("Succesfully generated %" PRId64 " bytes. Table:\n", s); 26 nissy_datainfo(buf, write_stdout);
32 h48info = (uint32_t *)buf + 1 + (ETABLESIZE(HVALUE) + COCSEPSIZE) / 4; 27 printf("\n");
33 for (i = 0; i < 4; i++) { 28 printf("Succesfully generated %" PRId64 " bytes. "
34 x = h48info[i+1]; 29 "See above for details on the tables.\n", s);
35 printf("%d:\t%" PRIu32, i, x); 30
36 if (x != expected[i]) 31 /* TODO: check that the table is correct */
37 printf(" <--- Error! Expected: %" PRIu32,
38 expected[i]);
39 printf("\n");
40 }
41 } 32 }
42} 33}
43 34
diff --git a/tools/020_solve_small/solve_small.c b/tools/020_solve_small/solve_small.c
index dee2b55..4d07728 100644
--- a/tools/020_solve_small/solve_small.c
+++ b/tools/020_solve_small/solve_small.c
@@ -20,20 +20,22 @@ void run(void) {
20 20
21 printf("Solved the following scrambles:\n\n"); 21 printf("Solved the following scrambles:\n\n");
22 for (i = 0; scrambles[i] != NULL; i++) { 22 for (i = 0; scrambles[i] != NULL; i++) {
23 printf("%s\n", scrambles[i]); 23 printf("%d. %s\n", i+1, scrambles[i]);
24 fprintf(stderr, "Solving scramble %s\n", scrambles[i]); 24 fprintf(stderr, "Solving scramble %s\n", scrambles[i]);
25 if (nissy_frommoves(scrambles[i], cube) == -1) { 25 if (nissy_frommoves(scrambles[i], cube) == -1) {
26 fprintf(stderr, "Invalid scramble, " 26 fprintf(stderr, "Invalid scramble\n");
27 "continuing with next scramble\n"); 27 printf("Invalid\n");
28 continue; 28 continue;
29 } 29 }
30 n = nissy_solve( 30 n = nissy_solve(
31 cube, "h48", options, "", 0, 20, 1, -1, buf, sol); 31 cube, "h48", options, "", 0, 20, 1, -1, buf, sol);
32 if (n == 0) 32 if (n == 0) {
33 fprintf(stderr, "No solution found, " 33 printf("No solution\n");
34 "continuing with next scramble\n"); 34 fprintf(stderr, "No solution found\n");
35 } else {
36 printf("Solutions:\n%s\n", sol);
37 }
35 } 38 }
36 printf("\n");
37} 39}
38 40
39int main(void) { 41int main(void) {
diff --git a/tools/run_tool.sh b/tools/run_tool.sh
index 2462b2d..cec7630 100755
--- a/tools/run_tool.sh
+++ b/tools/run_tool.sh
@@ -16,7 +16,7 @@ for t in tools/*; do
16 fi 16 fi
17 toolname="$(basename "$t" .c)" 17 toolname="$(basename "$t" .c)"
18 $CC -o $BIN $t/*.c $CUBEOBJ || exit 1; 18 $CC -o $BIN $t/*.c $CUBEOBJ || exit 1;
19 $BIN | tee "tools/results/$toolname-$d.txt" 19 $BIN | tee "tools/results/$toolname-$d.txt" "tools/results/last.out"
20 break 20 break
21done 21done
22 22
diff --git a/tools/tool.h b/tools/tool.h
index d75342d..7995621 100644
--- a/tools/tool.h
+++ b/tools/tool.h
@@ -18,6 +18,16 @@ log_stderr(const char *str, ...)
18 va_end(args); 18 va_end(args);
19} 19}
20 20
21static void
22write_stdout(const char *str, ...)
23{
24 va_list args;
25
26 va_start(args, str);
27 vfprintf(stdout, str, args);
28 va_end(args);
29}
30
21static double 31static double
22timerun(void (*run)(void), char *name) 32timerun(void (*run)(void), char *name)
23{ 33{

Generated with cgit - Back to sebastiano.tronto.net