use of nars.derive.mutate.Termutator in project narchy by automenta.
the class TermutatorTest method assertTermutatorProducesUniqueResults.
String assertTermutatorProducesUniqueResults(@NotNull Termutator t, int num) {
// assertEquals(num, t.getEstimatedPermutations());
// record the order
Set<String> s = new LinkedHashSet();
final int[] actual = { 0 };
// int blocked = 0;
final int[] duplicates = { 0 };
unifier.setTTL(TTL);
// unifier.freeCount.set( Integer.MAX_VALUE ); //MOCK
t.mutate(unifier, new Termutator[] { t, new Termutator() {
@Override
public void mutate(@NotNull Unify f, Termutator[] chain, int current) {
// use treemap for sorted keys
TreeMap t = new TreeMap();
f.xy.map.forEach(t::put);
if (s.add(t.toString())) {
actual[0]++;
} else {
duplicates[0]++;
}
}
} }, 0);
String res = s.toString();
System.out.println(res);
assertEquals(num, s.size());
assertEquals(num, actual[0]);
assertEquals(0, duplicates[0]);
return res;
}
use of nars.derive.mutate.Termutator in project narchy by automenta.
the class Unify method tryMatches.
// /**
// * computes a lazy set with the new free variables added by the incoming term, to continue
// * from a previous partial unification if necessary.
// */
// Set<Term> freeVariables(@NotNull Term x) {
// Set<Term> prevFree = free.get();
// Set<Term> nextFree = x.varsUnique(type, prevFree != null ? prevFree : Collections.emptySet());
// return concat(prevFree, nextFree);
// }
void tryMatches() {
int ts = termutes.size();
if (ts > 0) {
// TODO use Termutator[] not List
Termutator[] t = termutes.toArray(new Termutator[ts]);
termutes.clear();
// shuffle the ordering of the termutes themselves
if (ts > 1)
Util.shuffle(t, random);
// start combinatorial recurse
tryMutate(t, -1);
} else {
// tryMatch(false); //go directly to conclusion
tryMatch();
}
// if (matched.size()>1)
// System.out.println(matched);
// matched.clear();
}
Aggregations