From f5d6650e9bbb61c2f8874211aec595ee81683bbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Radek=20Hu=C5=A1ek?= <PitelVonSacek@gmail.com> Date: Wed, 9 Dec 2015 21:08:00 +0100 Subject: [PATCH] Alternative way to generate next forbidden mapping The new way avoids using modulo operation and is nicer to optimized Mapping structures. --- compileTimeOptions.h | 9 +++++++++ group-connectivity.h | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/compileTimeOptions.h b/compileTimeOptions.h index 32422af..865d26f 100644 --- a/compileTimeOptions.h +++ b/compileTimeOptions.h @@ -32,6 +32,15 @@ #endif +#ifndef USE_NEXT_FORB +#define USE_NEXT_FORB 1 +#endif +#if USE_NEXT_FORB +#pragma message "USE_NEXT_FORB ON" +#else +#pragma message "USE_NEXT_FORB off" +#endif + #ifndef MAX_EDGES #define MAX_EDGES 48 diff --git a/group-connectivity.h b/group-connectivity.h index 8c2f672..1ad4100 100644 --- a/group-connectivity.h +++ b/group-connectivity.h @@ -76,7 +76,8 @@ struct Tester : public AbstractTester { } } } - + +#if !USE_NEXT_FORB Mapping& unpack(size_t index, Mapping& ret) { size_t m = Ring::size - 1; @@ -87,6 +88,7 @@ struct Tester : public AbstractTester { return ret; } +#endif Mapping& cannonize(Mapping& map) { for (const auto &i : nonClassEdges) { @@ -121,15 +123,44 @@ struct Tester : public AbstractTester { #endif } +#if USE_NEXT_FORB + bool nextForb(Mapping& forb) { + for (size_t i = 0; i < edges; i++) { + T v = forb[i] + 1; + if (v >= Ring::size) { + forb.assign(i, 1); + } else { + forb.assign(i, v); + return true; + } + } + + return false; + } +#endif virtual bool run() { Mapping forb(edges); +#if USE_NEXT_FORB + for (size_t i = 0; i < edges; i++) + forb.assign(i, 1); + + do { + Mapping copy(forb); +#if SAVE_MEMORY + classes[pack(cannonize(copy))] = true; +#else + classes[pack(cannonize(copy))]++; +#endif + } while (nextForb(forb)); +#else // ! USE_NEXT_FORB for (size_t i = 0; i < numForb; i++) #if SAVE_MEMORY classes[pack(cannonize(unpack(i, forb)))] = true; #else classes[pack(cannonize(unpack(i, forb)))]++; +#endif #endif for (const auto &c : classes) if (!c) return (isConnected = false); -- GitLab