use of nars.NARS in project narchy by automenta.
the class SecondLevelUnificationTest method test1.
@Test
public void test1() throws Narsese.NarseseException {
// this.activeTasks = activeTasks;
NAR n = new NARS().get();
// n.log();
// n.eventTaskRemoved.on(t -> {
// //System.err.println("rm: " + t + " " + t.getLogLast());
// });
// en("all xs are opened by some y");
n.believe("<<$1 --> x> ==> (&&,<#2 --> y>,open(#2,$1))>", 1.00f, 0.90f);
// en("z is a y");
n.believe("<{z} --> y>", 1.00f, 0.90f);
// tester.mustBelieve(cycles, "<<$1 --> x> ==> <$1 --> (/,open,{z},_)>>", 1.00f, 0.42f); //en("maybe all xs are opened by z");
n.run(250);
}
use of nars.NARS in project narchy by automenta.
the class SecondLevelUnificationTest method test2.
@Test
public void test2() throws Narsese.NarseseException {
// this.activeTasks = activeTasks;
NAR n = new NARS().get();
// n.log();
// n.eventTaskRemoved.on(t -> {
// //System.err.println("rm: " + t + " " + t.getLogLast());
// });
// en("all xs are opened by some y");
n.believe("<<$1 --> x> ==> (&&,<#2 --> y>,<$1 --> #2>)>", 1.00f, 0.90f);
// en("z is a y");
n.believe("<{z} --> y>", 1.00f, 0.90f);
// tester.mustBelieve(cycles, "<<$1 --> x> ==> <$1 --> {z}>>", 1.00f, 0.42f); //en("maybe all xs are opened by z");
n.run(250);
}
use of nars.NARS in project narchy by automenta.
the class STRIPSTest method testBanana1.
@Test
public void testBanana1() throws Narsese.NarseseException {
NAR n = new NARS().tmp();
n.log();
n.input("At(A). :|:", "Level(low). :|:", "BoxAt(C). :|:", "BananasAt(B). :|:", /* Goal state: Eat(bananas) */
"Eat(bananas)!", // _Move(X, Y)_
"((At($X) &&+0 Level(low)) ==>+1 (--At($X) &&+0 At(#Y))).", // _ClimbUp(Location)_ climb up the box
"(((At(#Location) &&+0 BoxAt(#Location)) &&+0 Level(low)) ==>+1 (Level(high) &&+0 --Level(low))).", // _ClimbDown(Location)_ climb down from the box
"(((At(#Location) &&+0 BoxAt(#Location)) &&+0 Level(high)) ==>+1 (Level(low), --Level(high))).", /* Preconditions: At(X), BoxAt(X), Level(low)
Postconditions: BoxAt(Y), not BoxAt(X), At(Y), not At(X) */
"(((At($X) &&+0 BoxAt($X)) &&+0 Level(low)) ==>+1 ((((At(#Y) &&+0 BoxAt(#Y)) &&+0 --BoxAt($X)) &&+0 --At($X)))).", /* Preconditions: At(Location), BananasAt(Location), Level(high)
Postconditions: Eat(bananas) */
"(((At(#Location) &&+0 BananasAt(#Location)) &&+0 Level(high)) ==>+1 Eat(bananas)).");
n.run(1000);
}
use of nars.NARS in project narchy by automenta.
the class WorkerMultiExecTest method test1.
@Test
public void test1() {
int threads = 3;
Focus.DefaultRevaluator reval = new Focus.DefaultRevaluator();
WorkerMultiExec exe = new WorkerMultiExec(reval, threads, 16, 3);
NAR n = new NARS().exe(exe).get();
AtomicLong dutyTimeNS = new AtomicLong();
DummyCan a = new DummyCan("a", dutyTimeNS, n, (int j) -> Util.sleep(1 * j)).value(4f);
DummyCan b = new DummyCan("b", dutyTimeNS, n, (int j) -> Util.sleep(1 * j)).value(1f);
DummyCan c = new DummyCan("c", dutyTimeNS, n, (int j) -> Util.sleep(2 * j)).value(1f);
// n.onCycle(nn -> {
// Focus.Schedule s = exe.focus.schedule.read();
// System.out.println(nn.time() + " " +
// Arrays.toString(s.active) + "->" + n4(s.weight));
// });
long start = System.nanoTime();
Loop l = n.startFPS(5f);
Util.sleep(4000);
l.stop();
long totalTimeNS = (System.nanoTime() - start) * threads;
System.out.println("dutyTime=" + timeStr(dutyTimeNS.get()) + " , totalTime=" + timeStr(totalTimeNS) + ", efficiency=" + ((double) dutyTimeNS.get()) / totalTimeNS);
System.out.println(a.executed.get());
System.out.println(b.executed.get());
System.out.println(c.executed.get());
System.out.println(exe.focus);
assertEquals(3 + 1, exe.focus.choice.size());
assertEquals(expectedDuty(a) / expectedDuty(b), ((float) a.executed.get()) / b.executed.get(), 0.5f);
assertEquals(expectedDuty(a) / expectedDuty(c) / 2, ((float) a.executed.get()) / c.executed.get(), 0.5f);
}
use of nars.NARS in project narchy by automenta.
the class TermTreeTest method testCompoundInsertion.
@Test
public void testCompoundInsertion() throws Narsese.NarseseException {
TreeConceptIndex index;
NAR nar = new NARS().index(index = new TreeConceptIndex(1000)).get();
int preSize = index.size();
String[] terms = { "x", "(x)", "(xx)", "(xxx)", "(x,y)", "(x,z)", "(x --> z)", "(x <-> z)", "(x&&z)" };
HashSet<Term> input = new HashSet();
for (String s : terms) {
@NotNull Term ts = $(s);
input.add(ts);
index.get(ts, true);
}
assertEquals(terms.length + preSize, index.size());
for (Term x : input) assertNotNull(index.get(x, false));
// Set<Termed> stored = StreamSupport.stream(index.concepts.spliterator(), false).collect(Collectors.toSet());
// assertEquals(Sets.symmetricDifference(input, stored) + " = difference", input, stored);
index.concepts.prettyPrint();
index.print(System.out);
// String stringWithUnicode = "unicode\u00easomething";
// assertNull( tree.resolveOrAdd(stringWithUnicode)); //unicode not supported yet
}
Aggregations