use of nars.task.NALTask in project narchy by automenta.
the class PrologCore method answer.
private void answer(Task question, Solution answer) {
try {
Term yt = nterm(answer.goal);
Task y = Task.tryTask(yt, BELIEF, $.t(1f, answerConf.floatValue()), (term, truth) -> {
NALTask t = new NALTask(term, BELIEF, truth, nar.time(), ETERNAL, ETERNAL, nar.time.nextStampArray());
t.pri(nar.priDefault(BELIEF));
t.log("Prolog Answer");
return t;
});
if (y != null) {
logger.info("answer {}\t{}", question, y);
in.input(y);
}
} catch (Exception e) {
logger.error("answer {} {} {}", question, answer, e);
}
}
use of nars.task.NALTask in project narchy by automenta.
the class IO method readTask.
@NotNull
public static NALTask readTask(DataInput in) throws IOException {
Term preterm = readTerm(in);
final Term term = preterm.normalize();
if (term == null)
throw new IOException("un-normalizable task term");
byte punc = in.readByte();
Truth truth = hasTruth(punc) ? readTruth(in) : null;
long start = in.readLong();
long end = in.readLong();
long[] evi = readEvidence(in);
float pri = in.readFloat();
long cre = in.readLong();
NALTask mm = new NALTask(term, punc, truth, cre, start, end, evi);
mm.priSet(pri);
return mm;
}
use of nars.task.NALTask in project narchy by automenta.
the class NAgent method alwaysWant.
@Deprecated
public NALTask alwaysWant(Termed x, float conf) {
NALTask t = new NALTask(x.term(), GOAL, $.t(1f, conf), now, ETERNAL, ETERNAL, Stamp.UNSTAMPED);
always.add(t);
return t;
}
use of nars.task.NALTask in project narchy by automenta.
the class NAgent method alwaysQuestion.
@Deprecated
public NALTask alwaysQuestion(Termed x) {
NALTask t = new NALTask(x.term(), QUESTION, null, now, ETERNAL, ETERNAL, // Stamp.UNSTAMPED
nar().time.nextStampArray()) {
@Override
public boolean isInput() {
return false;
}
};
always.add(t);
return t;
}
use of nars.task.NALTask in project narchy by automenta.
the class RTreeBeliefTable method mergeOrDelete.
private boolean mergeOrDelete(Space<TaskRegion> treeRW, Top2<Leaf<TaskRegion>> l, FloatFunction<Task> taskStrength, float inputStrength, FloatFunction<TaskRegion> weakestTasks, Consumer<Tasked> added, NAR nar) {
TaskRegion a, b;
Leaf<TaskRegion> la = l.a;
short sa = la.size;
if (sa > 2) {
Top2<TaskRegion> w = new Top2<>(weakestTasks);
la.forEach(w::add);
a = w.a;
b = w.b;
} else if (sa == 2) {
a = la.get(0);
b = la.get(1);
} else {
a = la.get(0);
Leaf<TaskRegion> lb = l.b;
if (lb != null) {
int sb = lb.size();
if (sb > 1) {
Top<TaskRegion> w = new Top<>(weakestTasks);
lb.forEach(w);
b = w.the;
} else if (sb == 1) {
b = lb.get(0);
} else {
// ??
b = null;
}
} else {
b = null;
}
}
assert (a != null);
Task at = a.task();
float aPri = at.pri();
treeRW.remove(at);
if (b != null) {
Task bt = b.task();
if (bt.isDeleted()) {
treeRW.remove(bt);
return true;
} else {
at.meta("@", bt);
}
if (// already deleted
aPri != aPri)
return true;
Task c = // HACK
(this instanceof Simple || (at.term().equals(bt.term()))) ? Revision.mergeTemporal(nar, at, bt) : // TODO remove this when the mergeTemporal fully supports CONJ and Temporal
Revision.merge(at, bt, nar.time(), c2wSafe(nar.confMin.floatValue()), nar);
if (c != null && !c.equals(a) && !c.equals(b)) {
boolean allowMerge;
if (inputStrength != inputStrength) {
allowMerge = true;
} else {
float strengthRemoved = taskStrength.floatValueOf(at) + taskStrength.floatValueOf(bt);
float strengthAdded = taskStrength.floatValueOf(c) + inputStrength;
allowMerge = strengthAdded >= strengthRemoved;
}
if (allowMerge) {
treeRW.remove(bt);
// forward
((NALTask) at).delete(c);
// forward
((NALTask) bt).delete(c);
if (treeRW.add(c))
added.accept(c);
return true;
} else {
// merge result is not strong enough
c.delete();
}
}
}
// TODO do this outside of the locked section
if (Param.ETERNALIZE_EVICTED_TEMPORAL_TASKS)
eternalize(at, added, nar);
at.delete();
return true;
}
Aggregations