aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nissy.c63
-rw-r--r--src/nissy.h6
-rw-r--r--src/solvers/h48/gendata_cocsep.h12
-rw-r--r--src/solvers/h48/gendata_h48.h24
-rw-r--r--tools/000_gendata/gendata.c (renamed from tools/100_gendata/gendata.c)0
5 files changed, 104 insertions, 1 deletions
diff --git a/src/nissy.c b/src/nissy.c
index 318cff1..27e2835 100644
--- a/src/nissy.c
+++ b/src/nissy.c
@@ -13,6 +13,9 @@
13 13
14int parse_h48_options(const char *, uint8_t *, uint8_t *, uint8_t *); 14int parse_h48_options(const char *, uint8_t *, uint8_t *, uint8_t *);
15STATIC int64_t write_result(cube_t, char [static 22]); 15STATIC int64_t write_result(cube_t, char [static 22]);
16STATIC bool distribution_equal(
17 const uint64_t [static 21], const uint64_t [static 21], uint8_t);
18STATIC bool checkdata(const void *, const tableinfo_t *);
16 19
17/* TODO: add option to get DR, maybe C-only, E-only, eo... */ 20/* TODO: add option to get DR, maybe C-only, E-only, eo... */
18#define GETCUBE_OPTIONS(S, F) { .option = S, .fix = F } 21#define GETCUBE_OPTIONS(S, F) { .option = S, .fix = F }
@@ -62,6 +65,49 @@ parse_h48_options_error:
62 return -1; 65 return -1;
63} 66}
64 67
68STATIC bool
69checkdata(const void *buf, const tableinfo_t *info)
70{
71 uint64_t distr[21];
72
73 if (!strncmp(info->solver, "cocsep", 6)) {
74 getdistribution_cocsep(
75 (uint32_t *)((char *)buf + INFOSIZE), distr);
76 } else if (!strncmp(info->solver, "h48", 3)) {
77 getdistribution_h48((uint8_t *)buf + INFOSIZE, distr,
78 info->h48h, info->bits);
79 } else {
80 LOG("checkdata: unknown solver %s\n", info->solver);
81 return false;
82 }
83
84 return distribution_equal(info->distribution, distr, info->maxvalue);
85}
86
87STATIC bool
88distribution_equal(
89 const uint64_t expected[static 21],
90 const uint64_t actual[static 21],
91 uint8_t maxvalue
92)
93{
94 int wrong;
95 uint8_t i;
96
97 for (i = 0, wrong = 0; i <= MAX(maxvalue, 20); i++) {
98 if (expected[i] != actual[i]) {
99 wrong++;
100 LOG("Value %" PRIu8 ": expected %" PRIu64 ", found %"
101 PRIu64 "\n", i, expected[i], actual[i]);
102 }
103 }
104
105 if (wrong > 0)
106 LOG("chekdata: %d wrong values\n", wrong);
107
108 return wrong > 0;
109}
110
65STATIC int64_t 111STATIC int64_t
66write_result(cube_t cube, char result[static 22]) 112write_result(cube_t cube, char result[static 22])
67{ 113{
@@ -275,6 +321,23 @@ nissy_gendata(
275} 321}
276 322
277int64_t 323int64_t
324nissy_checkdata(
325 const char *solver,
326 const char *options,
327 const void *data
328)
329{
330 char *buf;
331 tableinfo_t info;
332
333 for (buf = (char *)data; readtableinfo(buf, &info); buf += info.next)
334 if (!checkdata(buf, &info))
335 return 1;
336
337 return 0;
338}
339
340int64_t
278nissy_solve( 341nissy_solve(
279 const char cube[static 22], 342 const char cube[static 22],
280 const char *solver, 343 const char *solver,
diff --git a/src/nissy.h b/src/nissy.h
index 336130c..e8c35c3 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
89int64_t nissy_checkdata(
90 const char *solver,
91 const char *options,
92 const void *data
93);
94
89/* Print information on a data table via the provided callback writer */ 95/* Print information on a data table via the provided callback writer */
90int64_t nissy_datainfo( 96int64_t nissy_datainfo(
91 const void *table, 97 const void *table,
diff --git a/src/solvers/h48/gendata_cocsep.h b/src/solvers/h48/gendata_cocsep.h
index 2189145..262793b 100644
--- a/src/solvers/h48/gendata_cocsep.h
+++ b/src/solvers/h48/gendata_cocsep.h
@@ -25,6 +25,7 @@ STATIC_INLINE void set_visited(uint8_t *, int64_t);
25 25
26STATIC size_t gendata_cocsep(void *, uint64_t *, cube_t *); 26STATIC size_t gendata_cocsep(void *, uint64_t *, cube_t *);
27STATIC uint32_t gendata_cocsep_dfs(cocsep_dfs_arg_t *); 27STATIC uint32_t gendata_cocsep_dfs(cocsep_dfs_arg_t *);
28STATIC void getdistribution_cocsep(const uint32_t *, uint64_t [static 21]);
28 29
29STATIC_INLINE int8_t get_h48_cdata(cube_t, uint32_t *, uint32_t *); 30STATIC_INLINE int8_t get_h48_cdata(cube_t, uint32_t *, uint32_t *);
30 31
@@ -157,6 +158,17 @@ gendata_cocsep_dfs(cocsep_dfs_arg_t *arg)
157 return cc; 158 return cc;
158} 159}
159 160
161STATIC void
162getdistribution_cocsep(const uint32_t *table, uint64_t distr[static 21])
163{
164 size_t i;
165
166 memset(distr, 0, 21 * sizeof(uint64_t));
167
168 for (i = 0; i < COCSEP_TABLESIZE; i++)
169 distr[CBOUND(table[i])]++;
170}
171
160STATIC_INLINE bool 172STATIC_INLINE bool
161get_visited(const uint8_t *a, int64_t i) 173get_visited(const uint8_t *a, int64_t i)
162{ 174{
diff --git a/src/solvers/h48/gendata_h48.h b/src/solvers/h48/gendata_h48.h
index 3445570..6e7b0ca 100644
--- a/src/solvers/h48/gendata_h48.h
+++ b/src/solvers/h48/gendata_h48.h
@@ -104,13 +104,16 @@ STATIC size_t gendata_h48k2_realcoord(gendata_h48_arg_t *);
104STATIC void gendata_h48k2_dfs(h48k2_dfs_arg_t *arg); 104STATIC void gendata_h48k2_dfs(h48k2_dfs_arg_t *arg);
105STATIC void * gendata_h48k2_runthread(void *); 105STATIC void * gendata_h48k2_runthread(void *);
106STATIC tableinfo_t makeinfo_h48k2(gendata_h48_arg_t *, uint8_t); 106STATIC tableinfo_t makeinfo_h48k2(gendata_h48_arg_t *, uint8_t);
107STATIC void getdistribution_h48(
108 const uint8_t *, uint64_t [static 21], uint8_t, uint8_t);
107 109
108STATIC uint32_t *get_cocsepdata_ptr(const void *); 110STATIC uint32_t *get_cocsepdata_ptr(const void *);
109STATIC uint8_t *get_h48data_ptr(const void *); 111STATIC uint8_t *get_h48data_ptr(const void *);
110 112
111STATIC_INLINE uint8_t get_h48_pval(const uint8_t *, int64_t, uint8_t); 113STATIC_INLINE uint8_t get_h48_pval(const uint8_t *, int64_t, uint8_t);
112STATIC_INLINE void set_h48_pval(uint8_t *, int64_t, uint8_t, uint8_t); 114STATIC_INLINE void set_h48_pval(uint8_t *, int64_t, uint8_t, uint8_t);
113STATIC_INLINE uint8_t get_h48_bound(cube_t, uint32_t, uint8_t, uint8_t, uint8_t *); 115STATIC_INLINE uint8_t get_h48_bound(
116 cube_t, uint32_t, uint8_t, uint8_t, uint8_t *);
114 117
115STATIC uint64_t 118STATIC uint64_t
116gendata_h48short(gendata_h48short_arg_t *arg) 119gendata_h48short(gendata_h48short_arg_t *arg)
@@ -662,6 +665,25 @@ makeinfo_h48k2(gendata_h48_arg_t *arg, uint8_t base)
662 return info; 665 return info;
663} 666}
664 667
668STATIC void
669getdistribution_h48(
670 const uint8_t *table,
671 uint64_t distr[static 21],
672 uint8_t h,
673 uint8_t k
674) {
675 uint8_t val;
676 int64_t i, h48max;
677
678 memset(distr, 0, 21 * sizeof(uint64_t));
679
680 h48max = H48_COORDMAX(h);
681 for (i = 0; i < h48max; i++) {
682 val = get_h48_pval(table, i, k);
683 distr[val]++;
684 }
685}
686
665STATIC uint32_t * 687STATIC uint32_t *
666get_cocsepdata_ptr(const void *data) 688get_cocsepdata_ptr(const void *data)
667{ 689{
diff --git a/tools/100_gendata/gendata.c b/tools/000_gendata/gendata.c
index 78f81ab..78f81ab 100644
--- a/tools/100_gendata/gendata.c
+++ b/tools/000_gendata/gendata.c

Generated with cgit - Back to sebastiano.tronto.net