aboutsummaryrefslogtreecommitdiff
path: root/src/solvers
diff options
context:
space:
mode:
Diffstat (limited to 'src/solvers')
-rw-r--r--src/solvers/coord/gendata.h17
-rw-r--r--src/solvers/dispatch.h8
-rw-r--r--src/solvers/solutions_types_macros.h2
-rw-r--r--src/solvers/solvers.h1
-rw-r--r--src/solvers/twostep/twostep.h98
5 files changed, 121 insertions, 5 deletions
diff --git a/src/solvers/coord/gendata.h b/src/solvers/coord/gendata.h
index 0acf9c0..a48263c 100644
--- a/src/solvers/coord/gendata.h
+++ b/src/solvers/coord/gendata.h
@@ -27,16 +27,25 @@ gendata_coord_dispatch(
27 unsigned char *buf 27 unsigned char *buf
28) 28)
29{ 29{
30 size_t r;
30 coord_t *coord; 31 coord_t *coord;
31 multicoord_t *mcoord; 32 multicoord_t *mcoord;
32 33
33 parse_coord_and_trans(coordstr, &coord, &mcoord, NULL); 34 parse_coord_and_trans(coordstr, &coord, &mcoord, NULL);
34 35
35 if (coord != NULL) 36 if (coord != NULL) {
36 return gendata_coord(coord, buf); 37 if (bufsize < gendata_coord(coord, NULL))
38 return NISSY_ERROR_BUFFER_SIZE;
39 r = gendata_coord(coord, buf);
40 return r == 0 ? NISSY_ERROR_UNKNOWN : (long long)r;
41 }
37 42
38 if (mcoord != NULL) 43 if (mcoord != NULL) {
39 return gendata_multicoord(mcoord, buf); 44 if (bufsize < gendata_multicoord(mcoord, NULL))
45 return NISSY_ERROR_BUFFER_SIZE;
46 r = gendata_multicoord(mcoord, buf);
47 return r == 0 ? NISSY_ERROR_UNKNOWN : (long long)r;
48 }
40 49
41 LOG("Error: could not parse coordinate '%s'\n", coordstr); 50 LOG("Error: could not parse coordinate '%s'\n", coordstr);
42 return NISSY_ERROR_INVALID_SOLVER; 51 return NISSY_ERROR_INVALID_SOLVER;
diff --git a/src/solvers/dispatch.h b/src/solvers/dispatch.h
index d484736..89a0771 100644
--- a/src/solvers/dispatch.h
+++ b/src/solvers/dispatch.h
@@ -41,6 +41,13 @@ solver_dispatch_t solver_dispatchers[] = {
41 .solve = solve_multicoord_dispatch, 41 .solve = solve_multicoord_dispatch,
42}, 42},
43{ 43{
44 .prefix = "twostep",
45 .dataid = dataid_twostep,
46 .gendata = gendata_twostep,
47 .checkdata = checkdata_twostep,
48 .solve = solve_twostep,
49},
50{
44 .prefix = NULL 51 .prefix = NULL
45} 52}
46}; 53};
@@ -70,6 +77,7 @@ const char *solver_aliases[][2] = {
70 { "htr-drfb", "coord_HTR_BU" }, 77 { "htr-drfb", "coord_HTR_BU" },
71 { "corners", "coord_CORNERS_UF" }, 78 { "corners", "coord_CORNERS_UF" },
72 { "cornersx", "coord_CORNERSX_UF" }, 79 { "cornersx", "coord_CORNERSX_UF" },
80 { "quick", "twostep" },
73 { NULL, NULL } 81 { NULL, NULL }
74}; 82};
75 83
diff --git a/src/solvers/solutions_types_macros.h b/src/solvers/solutions_types_macros.h
index 8454a21..6cde681 100644
--- a/src/solvers/solutions_types_macros.h
+++ b/src/solvers/solutions_types_macros.h
@@ -1,7 +1,7 @@
1#ifndef SOLVERS_SOLUTIONS_TYPES_MACROS_H 1#ifndef SOLVERS_SOLUTIONS_TYPES_MACROS_H
2#define SOLVERS_SOLUTIONS_TYPES_MACROS_H 2#define SOLVERS_SOLUTIONS_TYPES_MACROS_H
3 3
4#define SOLUTION_MAXLEN 20 4#define SOLUTION_MAXLEN 25
5 5
6typedef struct { 6typedef struct {
7 uint8_t nmoves; 7 uint8_t nmoves;
diff --git a/src/solvers/solvers.h b/src/solvers/solvers.h
index 78180aa..fab6e27 100644
--- a/src/solvers/solvers.h
+++ b/src/solvers/solvers.h
@@ -7,6 +7,7 @@
7#include "tables.h" 7#include "tables.h"
8#include "distribution.h" 8#include "distribution.h"
9#include "coord/coord.h" 9#include "coord/coord.h"
10#include "twostep/twostep.h"
10#include "h48/h48.h" 11#include "h48/h48.h"
11#include "dispatch.h" 12#include "dispatch.h"
12 13
diff --git a/src/solvers/twostep/twostep.h b/src/solvers/twostep/twostep.h
new file mode 100644
index 0000000..afb49da
--- /dev/null
+++ b/src/solvers/twostep/twostep.h
@@ -0,0 +1,98 @@
1#ifndef SRC_SOLVERS_TWOSTEP_TWOSTEP_H
2#define SRC_SOLVERS_TWOSTEP_TWOSTEP_H
3
4#include "../coord/coord.h"
5
6STATIC long long dataid_twostep(const char *, char [SIZE(NISSY_SIZE_DATAID)]);
7STATIC long long gendata_twostep(
8 const char *, unsigned long long, unsigned char *);
9STATIC long long checkdata_twostep(
10 const char *, unsigned long long, const unsigned char *);
11STATIC long long solve_twostep(oriented_cube_t, const char *, unsigned,
12 unsigned, unsigned, unsigned, unsigned, unsigned, unsigned long long,
13 const unsigned char *, unsigned, char *,
14 long long [SIZE(NISSY_SIZE_SOLVE_STATS)], int (*)(void *), void *);
15
16STATIC long long
17dataid_twostep(const char *s, char dataid[SIZE(NISSY_SIZE_DATAID)])
18{
19 strcpy(dataid, "DR_DRFIN");
20 return NISSY_OK;
21}
22
23STATIC long long
24gendata_twostep(
25 const char *s,
26 unsigned long long bufsize,
27 unsigned char *buf
28)
29{
30 size_t r, s1, s2;
31
32 s1 = gendata_coord(&coordinate_dr, NULL);
33 s1 = DIV_ROUND_UP(s1, 8); /* Preserve 8-byte alignment */
34 s2 = gendata_multicoord(&multicoordinate_drfin, NULL);
35
36 if (buf == NULL)
37 goto gendata_twostep_return_size;
38
39 if (bufsize < s1 + s2)
40 return NISSY_ERROR_BUFFER_SIZE;
41
42 r = gendata_coord(&coordinate_dr, buf);
43 if (r == 0)
44 return NISSY_ERROR_UNKNOWN;
45
46 r = gendata_multicoord(&multicoordinate_drfin, buf + s1);
47 if (r != NISSY_OK)
48 return NISSY_ERROR_UNKNOWN;
49
50gendata_twostep_return_size:
51 return s1 + s2;
52}
53
54STATIC long long
55checkdata_twostep(
56 const char *s,
57 unsigned long long bufsize,
58 const unsigned char *buf
59)
60{
61 long long r;
62
63 LOG("[checkdata] Checking double table for two step solver\n");
64
65 r = checkdata_coord(&coordinate_dr, bufsize, buf);
66 if (r != NISSY_OK)
67 return r;
68
69 r = checkdata_multicoord(&multicoordinate_drfin, bufsize, buf);
70 if (r != NISSY_OK)
71 return r;
72
73 return NISSY_OK;
74}
75
76STATIC long long
77solve_twostep(
78 oriented_cube_t oc,
79 const char *coord_and_trans,
80 unsigned nissflag,
81 unsigned minmoves,
82 unsigned maxmoves,
83 unsigned maxsolutions,
84 unsigned optimal,
85 unsigned threads,
86 unsigned long long data_size,
87 const unsigned char *data,
88 unsigned solutions_size,
89 char *sols,
90 long long stats[SIZE(NISSY_SIZE_SOLVE_STATS)],
91 int (*poll_status)(void *),
92 void *poll_status_data
93)
94{
95//TODO
96}
97
98#endif /* SRC_SOLVERS_TWOSTEP_TWOSTEP_H */

Generated with cgit - Back to sebastiano.tronto.net