Skip to content

Commit

Permalink
Hack symmetry into ptbsearch
Browse files Browse the repository at this point in the history
Transparent catalysts and minimum interaction generation have been
removed. Usgae is now:

ptb2 inputfile catalystsfile maxgen catalysts-1 mingen xcoord ycoord

The new parameters xcoord and ycoord define a 180 degree rotation such
that cell (0, 0) maps to cell (xcoord, ycoord).

At the start, and at every moment a catalyst is added, the pattern is
overlaid with the image of the pattern after the rotation, thus creating
symmetry at all times.

Because of this any catalysts that are 180 rotations of each other
should be avoided in the catalysts file as they will just be redundant.

Also 'survive' has been changed so that it only outputs patterns that
last for a long time without breaking and without becoming p2.
  • Loading branch information
ceebo committed Sep 30, 2015
1 parent ba6415a commit b64959d
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 22 deletions.
4 changes: 2 additions & 2 deletions analyze.c
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ int i,damaged, lastsfor;
if ( matchLifeList(&tmp, perturb, transl) == perturb->ncells &&
matchLifeList(&tmp, &spread1, transl) == perturb->ncells ) {
if (damaged) lastsfor++;
if (lastsfor>=10) return 1;
if (lastsfor>=8) return 1;
} else {
damaged = 1;
lastsfor = 0;
Expand All @@ -586,6 +586,7 @@ void setupPerturbors(LifeList *perturbs, Cell *placed, int nplaced,
mergeLifeLists(justPerturbs, perturbs+placed[i].value,
placed[i].position);
}
resymmetrise(justPerturbs);
mergeLifeLists(reaction, justPerturbs, 0);

}
Expand All @@ -611,7 +612,6 @@ int placeNewPerturbor(LifeList *seed, LifeList *perturbs,
copyLifeList(seed, &cells);

setupPerturbors(perturbs, placed, nplaced, &perturbcells, &cells);

naligns=0;
for (i=0; i<finalGen; i++) {

Expand Down
4 changes: 4 additions & 0 deletions gen.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
/* All code copyright Paul Callahan 1996-1997 */

#define FLIP_X 1
#define FLIP_Y 1
#define SYMM (1 + (FLIP_X || FLIP_Y))

#define INCY (1<<15)
#define INCX (1)
#define CENTER (1<<14)
Expand Down
40 changes: 40 additions & 0 deletions lifelist.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,46 @@ void mergeLifeLists(LifeList *cells1, LifeList *cells2, int transl) {
copyList(cells1->neighborhoods, cells1->ncells, cells1->cellList, 0);
}

/*
extern int max_x, max_y;
void setSymmetryDimensions(int LifeList *cells) {
int i, x, y,n = cells->ncells;
max_x = max_y = 0;
for (i = 0; i < n; i++) {
unpack(cells->cellList[i].position, &x, &y);
if (x > max_x) max_x = x;
if (y > max_y) max_y = y;
}
}
*/

void resymmetrise(LifeList *cells) {

if (!FLIP_X && !FLIP_Y)
return;

int i, n = cells->ncells;

resizeIfNeeded(cells, 2 * n);

for (i = 0; i < n; i++) {
int pos = cells->cellList[i].position;
if (FLIP_X) pos = flip_x(pos);
if (FLIP_Y) pos = flip_y(pos);
cells->cellList[i+n].position = pos;
cells->cellList[i+n].value = cells->cellList[i].value;
}

cells->ncells = 2 * n;

makeRowMajor(cells);
}

void mergeLifeListsMin(LifeList *cells1, LifeList *cells2, int transl) {

/* note: destroys neighborhood values */
Expand Down
7 changes: 5 additions & 2 deletions ptb2.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ LifeList tmp;
extern Cell *convolution, *scratch1, *scratch2, *oldAlignments;
void makeWorkSpace(int n);

extern int max_x, max_y;

main(int argc, char *argv[]) {
int i, nconv, nol;
Expand All @@ -35,8 +36,10 @@ int maxgen1;
if (argc>3) sscanf(argv[3], "%d", &maxgenall);
if (argc>4) sscanf(argv[4], "%d", &depth);
if (argc>5) sscanf(argv[5], "%d", &mingen);
if (argc>6) sscanf(argv[6], "%d", &maxvanish);
if (argc>7) sscanf(argv[7], "%d", &maxgen1); else maxgen1 = maxgenall;
if (argc>6) sscanf(argv[6], "%d", &max_x);
if (argc>7) sscanf(argv[7], "%d", &max_y);
maxgen1 = maxgenall;
resymmetrise(&orig);

perturbEnum(&orig, ptb, nptb,
0, depth, mingen, maxgen1, maxgenall, maxvanish);
Expand Down
8 changes: 5 additions & 3 deletions ptbsearch2.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ int iperturb, thisgen;
setupPerturbors(perturbs, perturbPlace, depth,
&justPerturbs, reaction+depth);


for (thisgen=0; thisgen<mingen; thisgen++) generate(reaction+depth);

for (; thisgen<maxgencurr; thisgen++) {
Expand All @@ -82,12 +81,15 @@ int iperturb, thisgen;
mergeLifeLists(&justPerturbs, perturbs+perturbPlace[j].value,
perturbPlace[j].position);
}
resymmetrise(&justPerturbs);

mergeLifeLists(&tmp, perturbs+iperturb, aligns[i].position);
resymmetrise(&tmp);

oldcount=justPerturbs.ncells;
mergeLifeLists(&justPerturbs, perturbs+iperturb,
aligns[i].position);
resymmetrise(&justPerturbs);

// if (iperturb==8) printf("chose a block %d %d\n", perturbs[iperturb].ncells, countGreaterThan(perturbs[iperturb].cellList, perturbs[iperturb].ncells, 1) );

Expand All @@ -96,8 +98,8 @@ int iperturb, thisgen;
perturbs[iperturb].ncells) tvanish--;

if (tvanish>=0 &&
oldcount+perturbs[iperturb].ncells == justPerturbs.ncells &&
survives(&tmp, &justPerturbs, 0, 15)) {
oldcount+SYMM*perturbs[iperturb].ncells == justPerturbs.ncells &&
survives(&tmp, &justPerturbs, 0, 10)) {

if (depth >= maxDepth) {
if (restored(&tmp, &justPerturbs, 0, 50)) {
Expand Down
12 changes: 12 additions & 0 deletions rmo.c
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,18 @@ int pack(int x, int y) {

}

int max_x, max_y;

int flip_x(int pack_value) {
int x = (pack_value & (INCY-1)) - CENTER;
return pack_value + max_x - 2 * x;
}

int flip_y(int pack_value) {
int y = pack_value / INCY - CENTER;
return pack_value + (max_y - 2 * y) * INCY;
}

int packtrans(int x, int y) {

return pack(x,y)-CENTER*INCY-CENTER;
Expand Down
32 changes: 17 additions & 15 deletions survive.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ main(int argc, char *argv[]) {
int x,y;
int match;
int pos;
int count[240];
int count[64];
int least= 0;
int fail;
int damaged;
Expand All @@ -34,8 +34,6 @@ main(int argc, char *argv[]) {

while(gets(nextpat)) {

for (i=0; i<240; i++) { count[i] = i; }

getpat(nextpat, &cells);
copyLifeList(&cells, &matchcells);

Expand All @@ -54,20 +52,24 @@ main(int argc, char *argv[]) {

// printf("%d %d %d %d\n", i, fail, damaged, restored);

count[i%240] = cells.ncells;
count[i&63] = cells.ncells;

if (cells.ncells == 0) break;

if (i >= 64) {

match = 1;

for (j = 2; j < 64; j+=2) {
if (count[(i-j)&63] != cells.ncells) {
match = 0;
break;
}
}

match = 1;
for (j=0; j<180; j++) {
if (count[j] != count[j+60]) {
match = 0;
break;
}
if (match) break;
}

if (match) break;

if ( matchLifeList(&cells, &matchcells, 0) < matchcells.ncells) {
fail++;
restored=0;
Expand All @@ -83,15 +85,15 @@ main(int argc, char *argv[]) {
}

if (fail>150) break;

}

if (damaged) {
if (i > 400) {
fflush(stdout);
removeLifeList(&outcells, &matchcells, 0);
makeString(outcells.cellList, outcells.ncells, outpat);

printf("%s %d %d %d %d %s\n", nextpat, damaged, fail, i-fail, prodcells, outpat);
printf("%s %d %d %d %d %s %d\n", nextpat, damaged, fail, i-fail, prodcells, outpat);
}

}
Expand Down

0 comments on commit b64959d

Please sign in to comment.