Search in sources :

Example 1 with Truthlet

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;
    });
}
Also used : DurService(nars.control.DurService) LongFunction(java.util.function.LongFunction) Predicate(java.util.function.Predicate) ITask(nars.task.ITask) ActiveQuestionTask(nars.task.ActiveQuestionTask) Truthlet(nars.task.signal.Truthlet) Consumer(java.util.function.Consumer) Nullable(org.jetbrains.annotations.Nullable) TruthletTask(nars.task.signal.TruthletTask) Truth(nars.truth.Truth) BiConsumer(java.util.function.BiConsumer) BELIEF(nars.Op.BELIEF) NotNull(org.jetbrains.annotations.NotNull) Term(nars.term.Term) GOAL(nars.Op.GOAL) Truthlet(nars.task.signal.Truthlet) TruthletTask(nars.task.signal.TruthletTask)

Aggregations

BiConsumer (java.util.function.BiConsumer)1 Consumer (java.util.function.Consumer)1 LongFunction (java.util.function.LongFunction)1 Predicate (java.util.function.Predicate)1 BELIEF (nars.Op.BELIEF)1 GOAL (nars.Op.GOAL)1 DurService (nars.control.DurService)1 ActiveQuestionTask (nars.task.ActiveQuestionTask)1 ITask (nars.task.ITask)1 Truthlet (nars.task.signal.Truthlet)1 TruthletTask (nars.task.signal.TruthletTask)1 Term (nars.term.Term)1 Truth (nars.truth.Truth)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1