From 0ece4b72db22139db51e8f5f37c25f24c84f3e43 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Thu, 17 Apr 2025 10:50:57 +0200 Subject: Small rework of optimal vs maxsols I wanted to make the "optimal" and "maxsolutions" options mutually exclusive, but in the end I decided there is value in keeping both (e.g. for specifying a limit to the number of solutions when asking for "all" optimal"). Now optimal cannot be negative anymore, for the same reason of maxsolutions. The interface user (shell, UI) will have to take care of handling this in a way that makes sense for the user. Usually this means setting the maximum number of solutions to UINT_MAX (or a similar very high number) when the user wants "all optimal". --- cpp/examples/solve_h48h3k2.cpp | 2 +- cpp/nissy.cpp | 16 ++++++++++++---- cpp/nissy.h | 4 ++-- 3 files changed, 15 insertions(+), 7 deletions(-) (limited to 'cpp') diff --git a/cpp/examples/solve_h48h3k2.cpp b/cpp/examples/solve_h48h3k2.cpp index 7f06376..f7ba235 100644 --- a/cpp/examples/solve_h48h3k2.cpp +++ b/cpp/examples/solve_h48h3k2.cpp @@ -68,7 +68,7 @@ int main() { // Solve auto solve_result = h48h3k2.solve(c, nissy::nissflag::NORMAL, - 0, maxmoves, 1, -1, 8); + 0, maxmoves, 1, 20, 8); // Write the result if (!solve_result.err.ok()) { diff --git a/cpp/nissy.cpp b/cpp/nissy.cpp index 944944b..92b10bd 100644 --- a/cpp/nissy.cpp +++ b/cpp/nissy.cpp @@ -21,8 +21,8 @@ extern "C" { long long nissy_gendata(const char *, unsigned long long, char *); long long nissy_checkdata(unsigned long long, const char *); long long nissy_solve(const char *, const char *, unsigned, unsigned, - unsigned, unsigned, int, int, unsigned long long, const char *, - unsigned, char *, long long *); + unsigned, unsigned, unsigned, unsigned, unsigned long long, + const char *, unsigned, char *, long long *); long long nissy_countmoves(const char *); long long nissy_setlogger(void (*)(const char *, void *), void *); } @@ -182,11 +182,19 @@ namespace nissy { solver::solve_result solver::solve(const cube& cube, nissflag niss, unsigned minmoves, - unsigned maxmoves, unsigned maxsols, int optimal, int threads) + unsigned maxmoves, unsigned maxsols, unsigned optimal, + unsigned threads) { + solver::solve_result result; + + if (maxsols == 0) { + result.solutions = {}; + result.err = error::OK; + return result; + } + const size_t len = 3 * (maxmoves+1) * maxsols; std::vector csols(len); - solver::solve_result result; auto err = nissy_solve(cube.to_string().c_str(), name.c_str(), niss.value, minmoves, maxmoves, maxsols, diff --git a/cpp/nissy.h b/cpp/nissy.h index db8ba5f..4b9c1c9 100644 --- a/cpp/nissy.h +++ b/cpp/nissy.h @@ -91,8 +91,8 @@ namespace nissy { error check_data(); void unload_data(); solve_result solve(const cube&, nissflag, unsigned minmoves, - unsigned maxmoves, unsigned maxsols, int optimal, - int threads); + unsigned maxmoves, unsigned maxsols, unsigned optimal, + unsigned threads); static std::variant get(const std::string&); private: -- cgit v1.3