Search in sources :

Example 1 with ShuffledSubterms

use of nars.subterm.ShuffledSubterms 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)

Example 2 with ShuffledSubterms

use of nars.subterm.ShuffledSubterms in project narchy by automenta.

the class CommutivePermutations method mutate.

@Override
public void mutate(Unify f, Termutator[] chain, int current) {
    int start = f.now();
    ShuffledSubterms p = new ShuffledSubterms(x, f.random);
    while (p.hasNextThenNext()) {
        if (p.unifyLinear(y, f)) {
            if (!f.tryMutate(chain, current))
                break;
        }
        if (!f.revertLive(start))
            break;
    }
}
Also used : ShuffledSubterms(nars.subterm.ShuffledSubterms)

Aggregations

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