use of jcog.math.Combinations in project narchy by automenta.
the class Choose2 method mutate.
@Override
public void mutate(Unify versioneds, Termutator[] chain, int current) {
Combinations ccc = this.comb;
ccc.reset();
boolean phase = true;
int start = f.now();
ShuffledSubterms yy = this.yy;
Ellipsis xEllipsis = this.xEllipsis;
Unify f = this.f;
Term[] x = this.x;
int[] c = null;
while (ccc.hasNext() || !phase) {
c = phase ? ccc.next() : c;
phase = !phase;
byte c0 = (byte) c[0];
byte c1 = (byte) c[1];
// swap to try the reverse next iteration
ArrayUtils.reverse(c);
Term y1 = yy.sub(c0);
if (x[0].unify(y1, f)) {
Term y2 = yy.sub(c1);
if (x[1].unify(y2, f) && xEllipsis.unify(EllipsisMatch.matchExcept(yy, c0, c1), f)) {
if (!f.tryMutate(chain, current))
break;
}
}
if (!f.revertLive(start))
break;
}
}
Aggregations