use of nars.task.signal.Truthlet in project narchy by automenta.
the class NARIn method taskWhile.
default DurService taskWhile(Term term, byte punc, Truth tru, Predicate<Task> cond) {
// HACK
NAR n = (NAR) this;
long start = n.time();
float activeFreq = tru.freq();
float inactiveFreq = 0f;
float evi = tru.evi();
LongFunction<Truthlet> stepUntil = (toWhen) -> {
return Truthlet.step(inactiveFreq, start, activeFreq, toWhen, activeFreq, evi);
};
TruthletTask t = new TruthletTask(term, punc, stepUntil.apply(start), n);
float pri = n.priDefault(punc);
t.priMax(pri);
n.input(t);
return DurService.onWhile(n, (nn) -> {
// nn.runLater(()->{
// t.concept(nn, false).goals().print();
// System.out.println();
// });
long now = nn.time();
boolean kontinue;
Truthlet tt;
if (!cond.test(t)) {
// convert from step function to impulse function which
// stops at the current time and end the service
tt = Truthlet.impulse(start, now, activeFreq, inactiveFreq, evi);
kontinue = false;
} else {
// stretch the step function to current time
tt = stepUntil.apply(now);
kontinue = true;
}
t.priMax(pri);
t.truth(tt, true, nn);
return kontinue;
});
}
Aggregations