Search in sources :

Example 1 with Combinations

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;
    }
}
Also used : Unify(nars.term.subst.Unify) Combinations(jcog.math.Combinations) Ellipsis(nars.derive.match.Ellipsis) Term(nars.term.Term) ShuffledSubterms(nars.subterm.ShuffledSubterms)

Aggregations

Combinations (jcog.math.Combinations)1 Ellipsis (nars.derive.match.Ellipsis)1 ShuffledSubterms (nars.subterm.ShuffledSubterms)1 Term (nars.term.Term)1 Unify (nars.term.subst.Unify)1