use of nars.entity.Task in project opennars by opennars.
the class GeneralInferenceControl method fireTaskLink.
protected static void fireTaskLink(DerivationContext nal, int termLinks) {
final Task task = nal.currentTaskLink.getTarget();
nal.setCurrentTerm(nal.currentConcept.term);
nal.setCurrentTaskLink(nal.currentTaskLink);
nal.setCurrentBeliefLink(null);
// one of the two places where this variable is set
nal.setCurrentTask(task);
nal.memory.emotion.adjustBusy(nal.currentTaskLink.getPriority(), nal.currentTaskLink.getDurability(), nal);
if (nal.currentTaskLink.type == TermLink.TRANSFORM) {
nal.setCurrentBelief(null);
// TermLink tasklink_as_termlink = new TermLink(nal.currentTaskLink.getTerm(), TermLink.TRANSFORM, nal.getCurrentTaskLink().index);
// if(nal.currentTaskLink.novel(tasklink_as_termlink, nal.memory.time(), true)) { //then record yourself, but also here novelty counts
// to turn this into structural inference as below?
RuleTables.transformTask(nal.currentTaskLink, nal);
// }
} else {
while (termLinks > 0) {
final TermLink termLink = nal.currentConcept.selectTermLink(nal.currentTaskLink, nal.memory.time());
if (termLink == null) {
break;
}
fireTermlink(termLink, nal);
nal.currentConcept.returnTermLink(termLink);
termLinks--;
}
}
nal.memory.emit(Events.ConceptFire.class, nal);
// memory.logic.TASKLINK_FIRE.commit(currentTaskLink.budget.getPriority());
}
use of nars.entity.Task in project opennars by opennars.
the class TemporalInferenceControl method NewOperationFrame.
public static void NewOperationFrame(Memory mem, Task task) {
// can there be more than one? I don't think so..
List<Task> toRemove = new LinkedList<Task>();
float priorityGain = 0.0f;
for (Task t : mem.recent_operations) {
// when made sure, make single element and add break
if (t.getTerm().equals(task.getTerm())) {
priorityGain = BudgetFunctions.or(priorityGain, t.getPriority());
toRemove.add(t);
}
}
for (Task t : toRemove) {
mem.recent_operations.take(t);
}
// this way operations priority of previous exections
task.setPriority(BudgetFunctions.or(task.getPriority(), priorityGain));
// contributes to the current (enhancement)
mem.recent_operations.putIn(task);
mem.lastDecision = task;
Concept c = (Concept) mem.concept(task.getTerm());
if (c != null) {
if (c.seq_before == null) {
c.seq_before = new LevelBag<>(Parameters.SEQUENCE_BAG_LEVELS, Parameters.SEQUENCE_BAG_SIZE);
}
for (Task t : mem.seq_current) {
if (task.sentence.getOccurenceTime() > t.sentence.getOccurenceTime()) {
c.seq_before.putIn(t);
}
}
}
mem.seq_current.clear();
}
use of nars.entity.Task in project opennars by opennars.
the class FunctionOperator method execute.
// abstract protected int getMinArity();
// abstract protected int getMaxArity();
@Override
protected ArrayList<Task> execute(Operation operation, Term[] args, Memory m) {
// TODO make memory access optional by constructor argument
// TODO allow access to NAR instance?
int numArgs = args.length - 1;
if (numArgs < 1) {
throw new RuntimeException("Requires at least 1 arguments");
}
if (numArgs < 2) /*&& !(this instanceof Javascript)*/
{
throw new RuntimeException("Requires at least 2 arguments");
}
// last argument a variable?
Term lastTerm = args[numArgs];
boolean variable = lastTerm instanceof Variable;
if (!variable) /*&& !(this instanceof Javascript)*/
{
throw new RuntimeException("output can not be specified");
}
int numParam = numArgs - 1;
/*if(this instanceof Javascript && !variable) {
numParam++;
}*/
Term[] x = new Term[numParam];
System.arraycopy(args, 1, x, 0, numParam);
Term y;
// try {
y = function(m, x);
if (y == null) {
return null;
}
/*if(!variable && this instanceof Javascript) {
return null;
}*/
// m.emit(SynchronousFunctionOperator.class, Arrays.toString(x) + " | " + y);
/*}
catch (Exception e) {
throw e;
}*/
Variable var = new Variable("$1");
// Term actual_part = Similarity.make(var, y);
// Variable vardep=new Variable("#1");
// Term actual_dep_part = Similarity.make(vardep, y);
operation = (Operation) operation.setComponent(0, ((CompoundTerm) operation.getSubject()).setComponent(numArgs, y, m), m);
float confidence = Parameters.DEFAULT_JUDGMENT_CONFIDENCE;
if (variable) {
Sentence s = new Sentence(operation, Symbols.JUDGMENT_MARK, new TruthValue(1.0f, Parameters.DEFAULT_JUDGMENT_CONFIDENCE), new Stamp(m));
return Lists.newArrayList(new Task(s, new BudgetValue(Parameters.DEFAULT_JUDGMENT_PRIORITY, Parameters.DEFAULT_FEEDBACK_DURABILITY, truthToQuality(s.getTruth())), true));
} else {
return null;
}
}
use of nars.entity.Task in project opennars by opennars.
the class Operator method call.
/**
* The standard way to carry out an operation, which invokes the execute
* method defined for the operator, and handles feedback tasks as input
*
* @param op The operator to be executed
* @param args The arguments to be taken by the operator
* @param memory The memory on which the operation is executed
* @return true if successful, false if an error occurred
*/
public final boolean call(final Operation operation, final Term[] args, final Memory memory) {
try {
List<Task> feedback = execute(operation, args, memory);
if (feedback == null || feedback.isEmpty()) {
// null operator case
memory.executedTask(operation, new TruthValue(1f, executionConfidence));
}
reportExecution(operation, args, feedback, memory);
if (feedback != null) {
for (final Task t : feedback) {
memory.inputTask(t);
}
}
return true;
}// }
catch (Exception e) {
// reportExecution(operation, args, e, memory);
}
return false;
}
use of nars.entity.Task in project opennars by opennars.
the class Anticipate method anticipationFeedback.
public void anticipationFeedback(Term content, Task t, Memory memory) {
if (anticipationOperator) {
Operation op = (Operation) Operation.make(Product.make(Term.SELF, content), this);
TruthValue truth = new TruthValue(1.0f, Parameters.DEFAULT_JUDGMENT_CONFIDENCE);
Stamp st;
if (t == null) {
st = new Stamp(memory);
} else {
st = t.sentence.stamp.clone();
st.setOccurrenceTime(memory.time());
}
Sentence s = new Sentence(op, Symbols.JUDGMENT_MARK, truth, st);
Task newTask = new Task(s, new BudgetValue(Parameters.DEFAULT_JUDGMENT_PRIORITY * InternalExperience.INTERNAL_EXPERIENCE_PRIORITY_MUL, Parameters.DEFAULT_JUDGMENT_DURABILITY * InternalExperience.INTERNAL_EXPERIENCE_DURABILITY_MUL, BudgetFunctions.truthToQuality(truth)), true);
memory.addNewTask(newTask, "Perceived (Internal Experience: Anticipation)");
}
}
Aggregations