struct slName *subtractFiles(struct slName *fileList)
/* Subtract two files using subtractLists */
{
struct slName *initialList = slNameLoadReal(fileList->name);
struct slName *subtractMe = slNameLoadReal(fileList->next->name);
struct slName *diffList = subtractLists(initialList, subtractMe);
slNameFreeList(&initialList);
slNameFreeList(&subtractMe);
return diffList;
}
Пример #2
0
void removeLifeList(LifeList *cells, LifeList *removecells, int transl) {

/* note: destroys removecells neighborhood values */

    copyList(removecells->cellList, removecells->ncells,
             removecells->neighborhoods, transl);

    cells->ncells=subtractLists(removecells->neighborhoods,
                                removecells->ncells,
                                cells->cellList, cells->ncells);
}
Пример #3
0
int emptyNeighbors(LifeList *cells) {
int nnbhd;

   resizeIfNeeded(cells, cells->ncells*9);

   nnbhd= sumAllNeighbors(cells->cellList, cells->ncells, 
                                           cells->neighborhoods);
   nnbhd= subtractLists(cells->cellList, cells->ncells, 
                                cells->neighborhoods, nnbhd);

   return nnbhd;
}
Пример #4
0
AlignmentList
   firstTouch(LifeList *cells1, LifeList *cells2, int firstGen, int ngens) {
int nOld=0, nNew;
int i, lastGen;

AlignmentList list;

    lastGen=firstGen+ngens;

    assert(firstGen<=lastGen);

    list.alignments= (Cell **)calloc(sizeof(Cell *), lastGen-firstGen);
    list.firstGen= firstGen;
    list.ngens= ngens;

    list.nalignments= (int *)calloc(sizeof(int), lastGen-firstGen);

    for (i=0; i<firstGen; i++) {
        nNew= findTouching(cells1, cells2);

        makeWorkSpace(nNew+nOld); 
        nOld=combineLists(convolution, nNew, oldAlignments, nOld, scratch1);
        copyList(scratch1, nOld, oldAlignments, 0);
        setValues(oldAlignments, nOld, 1);

        generate(cells1);
        generate(cells2);
    }

    for (; i<lastGen; i++) {
        nNew= findTouching(cells1, cells2);

        nNew= subtractLists(oldAlignments, nOld, convolution, nNew);
        list.alignments[i-firstGen]=
              (Cell *)calloc(sizeof(Cell), nNew);
        list.nalignments[i-firstGen]=
               copyList(convolution, nNew, list.alignments[i-firstGen], 0); 

        makeWorkSpace(nNew+nOld); 
        nOld=combineLists(convolution, nNew, oldAlignments, nOld, scratch1);
        copyList(scratch1, nOld, oldAlignments, 0);
        setValues(oldAlignments, nOld, 1);

        generate(cells1);
        generate(cells2);
     }

     return list;
}
void sets(char *operation, struct slName *fileList)
/* sets - Do set operations on one-word-per-line files.. */
{
struct slName *finalList = NULL, *cur;
if (sameWord(operation, "intersect"))
    finalList = intersectFiles(fileList);
else if (sameWord(operation, "union"))
    finalList = unionFiles(fileList);
else if (sameWord(operation, "subtract") && (slCount(fileList) == 2))
    finalList = subtractFiles(fileList);
else if (sameWord(operation, "symetricDiff"))
    {
    struct slName *theUnion = unionFiles(fileList);
    struct slName *theIntersect = intersectFiles(fileList);
    finalList = subtractLists(theUnion, theIntersect);
    slNameFreeList(&theUnion);
    slNameFreeList(&theIntersect);
    }
else
    usage();
/* Output here */
for (cur = finalList; cur != NULL; cur = cur->next)
    printf("%s\n", cur->name);
}
Пример #6
0
int placeNewPerturbor(LifeList *seed, LifeList *perturbs,
                       Cell *placed, int nplaced, int newperturb,
                       int initialGen, int finalGen, Cell *aligns) {
  int i, j;
  int  nconv, nold, naligns, nelim;

  copyLifeList(perturbs+newperturb, &thisperturb);

  copyLifeList(&thisperturb, &spread1);
  spread(&spread1, 1);

  copyLifeList(&spread1, &spread2);
  spread(&spread2, 1);

  removeLifeList(&spread2, &spread1, 0);

  copyLifeList(seed, &cells);

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

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

    nconv=convolve(spread2.cellList, spread2.ncells,
                   cells.cellList, cells.ncells,
                   &convolution, &scratch1, &scratch2,
                   makeWorkSpace);

    makeWorkSpace(spread1.ncells*cells.ncells);
    nold=convolve(spread1.cellList, spread1.ncells,
                  cells.cellList, cells.ncells,
                  &oldAlignments, &scratch1, &scratch2,
                  makeWorkSpace);

    nconv=subtractLists(oldAlignments, nold, convolution, nconv);

    nconv=subtractLists(aligns, naligns, convolution, nconv);

    setValues(convolution, nconv, i);

    nelim=0;
    for (j=0; j<nconv; j++) {
      copyLifeList(&cells, &tmp);
      intersectLifeLists(&tmp, &spread2, convolution[j].position);

      if (interact(&tmp, &thisperturb, convolution[j].position)) {
        convolution[nelim++]=convolution[j];
      }
    }

    makeWorkSpace(nelim + naligns);
    naligns=combineLists(convolution, nelim, aligns, naligns, scratch1);
    copyList(scratch1, naligns, aligns, 0);
    
    if (i == 0) {
        setValues(oldAlignments, nold, -1);
        makeWorkSpace(nold + naligns);
        naligns=combineLists(oldAlignments, nold, aligns, naligns, scratch1);
        copyList(scratch1, naligns, aligns, 0);
    }

    generate(&cells);

    if (broken(cells.cellList, cells.ncells,
               perturbcells.cellList, perturbcells.ncells))
      break;
  }

  naligns=removeLessThan(aligns, naligns, initialGen);
  return naligns;
}