aboutsummaryrefslogtreecommitdiff
path: root/tools/stats_tables_h48
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2024-07-08 19:22:16 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2024-07-08 19:22:16 +0200
commitc2275e4b9625a1a19eb50d0880f70ed583d5c358 (patch)
treef1b6798f017dd62ece5b56f05d5c7201ba50ff39 /tools/stats_tables_h48
parent66c1c11ec13d362ddfb1b5f6abe8127969c0ad29 (diff)
downloadnissy-core-c2275e4b9625a1a19eb50d0880f70ed583d5c358.tar.gz
nissy-core-c2275e4b9625a1a19eb50d0880f70ed583d5c358.zip
Stats for h48 solver as tool
Diffstat (limited to 'tools/stats_tables_h48')
-rw-r--r--tools/stats_tables_h48/stats_tables_h48.c85
1 files changed, 64 insertions, 21 deletions
diff --git a/tools/stats_tables_h48/stats_tables_h48.c b/tools/stats_tables_h48/stats_tables_h48.c
index b349f63..33272c1 100644
--- a/tools/stats_tables_h48/stats_tables_h48.c
+++ b/tools/stats_tables_h48/stats_tables_h48.c
@@ -1,10 +1,13 @@
1#include <stdarg.h>
1#include <time.h> 2#include <time.h>
2#include "../timerun.h" 3#include "../timerun.h"
3#include "../../src/cube.h" 4#include "../../src/cube.h"
4 5
5#define MAXMOVES 20 6#define MAXMOVES 20
6#define NCUBES 1000 7#define NCUBES 10000
8#define LOG_EVERY (NCUBES / 20)
7 9
10const char *filename = "tables/h48h0k4";
8char *buf; 11char *buf;
9 12
10uint64_t rand64(void) { 13uint64_t rand64(void) {
@@ -16,22 +19,18 @@ uint64_t rand64(void) {
16 return ret; 19 return ret;
17} 20}
18 21
19void output(int64_t v[13][100]) { 22void log_stderr(const char *str, ...) {
20/* TODO: write to file and output only cocsepdata table stats */ 23 va_list args;
24
25 va_start(args, str);
26 vfprintf(stderr, str, args);
27 va_end(args);
21} 28}
22 29
23void run(void) { 30void run(void) {
24 uint32_t *h48info; 31 int i, j, k;
25 int i, j; 32 char sols[12], cube[22];
26 char sols[13], cube[22]; 33 int64_t ep, eo, cp, co, v[12][100] = {0};
27 int64_t s, ep, eo, cp, co, v[13][100] = {0};
28
29 s = nissy_gendata("H48stats", "", buf);
30
31 if (s == -1) {
32 printf("Error generating table\n");
33 return;
34 }
35 34
36 for (i = 0; i < NCUBES; i++) { 35 for (i = 0; i < NCUBES; i++) {
37 ep = rand64(); 36 ep = rand64();
@@ -39,13 +38,53 @@ void run(void) {
39 cp = rand64(); 38 cp = rand64();
40 co = rand64(); 39 co = rand64();
41 nissy_getcube(ep, eo, cp, co, "fix", cube); 40 nissy_getcube(ep, eo, cp, co, "fix", cube);
42 nissy_solve(cube, "H48stats", 41 nissy_solve(cube, "h48stats", "", "",
43 "", "", "", 0, MAXMOVES, 1, -1, buf, sols); 42 0, MAXMOVES, 1, -1, buf, sols);
44 for (j = 0; j < 13; j++) 43 for (j = 0; j < 12; j++)
45 v[j][(int)sols[j]]++; 44 v[j][(int)sols[j]]++;
45 if ((i+1) % LOG_EVERY == 0)
46 fprintf(stderr, "%d cubes solved...\n", i+1);
46 } 47 }
47 48
48 output(v); 49 for (j = 0; j < 12; j++) {
50 printf("Data for h=%d\n", j);
51 for (k = 0; k <= 16; k++)
52 printf("%d\t%" PRId64 "\n", k, v[j][k]);
53 printf("\n");
54 }
55}
56
57int getdata(int64_t size) {
58 int64_t s;
59 FILE *f;
60
61 buf = malloc(size);
62
63 if ((f = fopen(filename, "rb")) == NULL) {
64 fprintf(stderr, "Table file not found, generating them."
65 " This can take a while.\n");
66 s = nissy_gendata("h48stats", "", buf);
67 if (s != size) {
68 fprintf(stderr, "Error generating table");
69 if (s != -1)
70 fprintf(stderr, " (got %" PRId64 " bytes)", s);
71 fprintf(stderr, "\n");
72 return 1;
73 }
74 if ((f = fopen(filename, "wb")) == NULL) {
75 fprintf(stderr, "Could not write tables to file %s"
76 ", will be regenerated next time.\n", filename);
77 } else {
78 fwrite(buf, size, 1, f);
79 fclose(f);
80 }
81 } else {
82 fprintf(stderr, "Reading tables from file %s\n", filename);
83 fread(buf, size, 1, f);
84 fclose(f);
85 }
86
87 return 0;
49} 88}
50 89
51int main() { 90int main() {
@@ -53,17 +92,21 @@ int main() {
53 92
54 srand(time(NULL)); 93 srand(time(NULL));
55 94
56 size = nissy_datasize("H48", OPTIONS); 95 nissy_setlogger(log_stderr);
96 size = nissy_datasize("h48stats", "");
57 if (size == -1) { 97 if (size == -1) {
58 printf("h48 stats: error in datasize\n"); 98 printf("h48 stats: error in datasize\n");
59 return 1; 99 return 1;
60 } 100 }
61 101
62 buf = malloc(size); 102 if (getdata(size) != 0) {
103 printf("Error getting table, stopping\n");
104 free(buf);
105 return 1;
106 }
63 107
64 timerun(run, "h48 table stats"); 108 timerun(run, "h48 table stats");
65 109
66 free(buf); 110 free(buf);
67
68 return 0; 111 return 0;
69} 112}

Generated with cgit - Back to sebastiano.tronto.net