Skip to content

Commit

Permalink
Fixed the problem with the double-probe hack by checking if the start
Browse files Browse the repository at this point in the history
state is "default" (i.e., identity perms and zero orientations).  This
suffices for now.  Eventually we want to consider making this support
more general start states (either by inverting and conjugating by the
start state before the second probe, or by normalizing the start state
when we read the puzdef and pre/post-multiplying by the start state on
every input/output operation).  We can also consider reducing the pruning
table by inversions which would give a 2X improvement in memory efficiency
but we'd have to change the double-probe to an inversion reduction (so
one lookup instead of two) which likely would be faster anyway.
  • Loading branch information
rokicki committed Oct 9, 2024
1 parent 7d2a33a commit 04cbe33
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
16 changes: 16 additions & 0 deletions src/cpp/puzdef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,3 +283,19 @@ void domove(const puzdef &pd, setval p, int mv) {
void domove(const puzdef &pd, setval p, int mv, setval pt) {
domove(pd, p, pd.moves[mv].pos, pt);
}
int puzdef::defaultstart() const {
const uchar *a = solved.dat;
for (int i = 0; i < (int)setdefs.size(); i++) {
const setdef &sd = setdefs[i];
int n = sd.size;
for (int i = 0; i < n; i++)
if (i != a[i])
return 0;
a += n;
for (int i = 0; i < n; i++)
if (a[i] != 0)
return 0;
a += n;
}
return 1;
}
4 changes: 3 additions & 1 deletion src/cpp/puzdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,14 @@ struct puzdef {
ull checksum;
ull optionssum;
vector<illegal_t> illegal;
char haveillegal, wildo, dense, uniq, caninvert;
char haveillegal, wildo, dense, uniq, caninvert, doubleprobe;
int comparepos(const setval a, const setval b) const {
return memcmp(a.dat, b.dat, totsize);
}
int canpackdense() const { return dense; }
int invertible() const { return caninvert; }
int invertiblelookups() const { return doubleprobe; }
int defaultstart() const;
void assignpos(setval a, const setval b) const {
memcpy(a.dat, b.dat, totsize);
}
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/readksolve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ puzdef readdef(istream *f) {
if (distinguishall) {
pz.solved = pz.id;
}
pz.caninvert = pz.uniq && !pz.wildo;
pz.doubleprobe = pz.uniq && !pz.wildo && pz.defaultstart();
pz.checksum = checksum;
curline.clear();
return pz;
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/solve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ int microthread::innerfetch(const puzdef &pd, prunetable &pt) {
* default (identity perm and zero orientations). We need to fix this
* soon.
*/
} else if (0 && pd.invertible() && v < 2 + pt.baseval && invflag == 0) {
} else if (pd.invertiblelookups() && v < 2 + pt.baseval && invflag == 0) {
invflag = 1;
pd.inv(posns[sp], *invtmp);
return 3;
Expand Down

0 comments on commit 04cbe33

Please sign in to comment.