aboutsummaryrefslogtreecommitdiff
path: root/cpp
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2025-04-29 10:08:04 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2025-04-29 10:08:04 +0200
commit8d3fc9f5f9c0593fcae9c451efe6c89c64dcbe84 (patch)
tree8c0182f9bf94aaa8afe5126988e07af82c4409fd /cpp
parentcdf46d85efe7fa54e8c302a255214341c567b4af (diff)
downloadnissy-core-8d3fc9f5f9c0593fcae9c451efe6c89c64dcbe84.tar.gz
nissy-core-8d3fc9f5f9c0593fcae9c451efe6c89c64dcbe84.zip
Added stop / pause / resume solve to API
Diffstat (limited to 'cpp')
-rw-r--r--cpp/examples/solve_h48h3k2.cpp2
-rw-r--r--cpp/nissy.cpp13
-rw-r--r--cpp/nissy.h12
3 files changed, 22 insertions, 5 deletions
diff --git a/cpp/examples/solve_h48h3k2.cpp b/cpp/examples/solve_h48h3k2.cpp
index f7ba235..f0d6f2f 100644
--- a/cpp/examples/solve_h48h3k2.cpp
+++ b/cpp/examples/solve_h48h3k2.cpp
@@ -68,7 +68,7 @@ int main() {
68 68
69 // Solve 69 // Solve
70 auto solve_result = h48h3k2.solve(c, nissy::nissflag::NORMAL, 70 auto solve_result = h48h3k2.solve(c, nissy::nissflag::NORMAL,
71 0, maxmoves, 1, 20, 8); 71 0, maxmoves, 1, 20, 8, NULL, NULL);
72 72
73 // Write the result 73 // Write the result
74 if (!solve_result.err.ok()) { 74 if (!solve_result.err.ok()) {
diff --git a/cpp/nissy.cpp b/cpp/nissy.cpp
index 118a072..2faea6f 100644
--- a/cpp/nissy.cpp
+++ b/cpp/nissy.cpp
@@ -20,7 +20,8 @@ extern "C" {
20 long long nissy_checkdata(unsigned long long, const unsigned char *); 20 long long nissy_checkdata(unsigned long long, const unsigned char *);
21 long long nissy_solve(const char *, const char *, unsigned, unsigned, 21 long long nissy_solve(const char *, const char *, unsigned, unsigned,
22 unsigned, unsigned, unsigned, unsigned, unsigned long long, 22 unsigned, unsigned, unsigned, unsigned, unsigned long long,
23 const unsigned char *, unsigned, char *, long long *); 23 const unsigned char *, unsigned, char *, long long *,
24 int (*)(void *), void *);
24 long long nissy_countmoves(const char *); 25 long long nissy_countmoves(const char *);
25 long long nissy_setlogger(void (*)(const char *, void *), void *); 26 long long nissy_setlogger(void (*)(const char *, void *), void *);
26} 27}
@@ -47,6 +48,10 @@ namespace nissy {
47 const error error::OPTIONS{-80}; 48 const error error::OPTIONS{-80};
48 const error error::UNKNOWN{-999}; 49 const error error::UNKNOWN{-999};
49 50
51 const status status::run{0};
52 const status status::stop{1};
53 const status status::pause{2};
54
50 namespace size { 55 namespace size {
51 constexpr size_t CUBE = 22; 56 constexpr size_t CUBE = 22;
52 constexpr size_t TRANSFORMATION = 12; 57 constexpr size_t TRANSFORMATION = 12;
@@ -154,7 +159,8 @@ namespace nissy {
154 solver::solve_result 159 solver::solve_result
155 solver::solve(const cube& cube, nissflag niss, unsigned minmoves, 160 solver::solve(const cube& cube, nissflag niss, unsigned minmoves,
156 unsigned maxmoves, unsigned maxsols, unsigned optimal, 161 unsigned maxmoves, unsigned maxsols, unsigned optimal,
157 unsigned threads) 162 unsigned threads, int (*poll_status)(void *),
163 void *poll_status_data)
158 { 164 {
159 solver::solve_result result; 165 solver::solve_result result;
160 166
@@ -171,7 +177,8 @@ namespace nissy {
171 name.c_str(), niss.value, minmoves, maxmoves, maxsols, 177 name.c_str(), niss.value, minmoves, maxmoves, maxsols,
172 optimal, threads, data.size(), 178 optimal, threads, data.size(),
173 reinterpret_cast<const unsigned char *>(data.data()), len, 179 reinterpret_cast<const unsigned char *>(data.data()), len,
174 csols.data(), result.stats.data()); 180 csols.data(), result.stats.data(), poll_status,
181 poll_status_data);
175 result.err = error{err}; 182 result.err = error{err};
176 183
177 if (err < 0) 184 if (err < 0)
diff --git a/cpp/nissy.h b/cpp/nissy.h
index 4fa98ad..41d3876 100644
--- a/cpp/nissy.h
+++ b/cpp/nissy.h
@@ -46,6 +46,15 @@ namespace nissy {
46 static const error UNKNOWN; 46 static const error UNKNOWN;
47 }; 47 };
48 48
49 class status {
50 public:
51 int value;
52
53 static const status run;
54 static const status stop;
55 static const status pause;
56 };
57
49 class cube { 58 class cube {
50 public: 59 public:
51 cube(); 60 cube();
@@ -86,7 +95,8 @@ namespace nissy {
86 void unload_data(); 95 void unload_data();
87 solve_result solve(const cube&, nissflag, unsigned minmoves, 96 solve_result solve(const cube&, nissflag, unsigned minmoves,
88 unsigned maxmoves, unsigned maxsols, unsigned optimal, 97 unsigned maxmoves, unsigned maxsols, unsigned optimal,
89 unsigned threads); 98 unsigned threads, int (*poll_status)(void *),
99 void *poll_status_data);
90 100
91 static std::variant<solver, error> get(const std::string&); 101 static std::variant<solver, error> get(const std::string&);
92 private: 102 private:

Generated with cgit - Back to sebastiano.tronto.net