diff --git a/pynars/NARS/DataStructures/_py/Link.py b/pynars/NARS/DataStructures/_py/Link.py index 53746401..6daaaf77 100644 --- a/pynars/NARS/DataStructures/_py/Link.py +++ b/pynars/NARS/DataStructures/_py/Link.py @@ -187,12 +187,6 @@ def get_index(cls, main_term: Union[Term, Statement, Compound], sub_term: Union[ return indices - @classmethod - def update_budget(cls, budget: Budget, q: float, p_belief: float): - budget.priority = min(1.0, Or(budget.priority, Or(q, p_belief))) - budget.durability = min(1.0-Config.budget_epsilon, Or(budget.durability, q)) - - @property def is_valid(self): @@ -211,6 +205,11 @@ def set_type(self, source_is_component=True, type: LinkType=None): Link.set_type(self, source_is_component, type) if not self.is_valid: self.type = None + + def reward_budget(self, reward: float): + self.budget.quality = Or(self.budget.quality, reward) + + @property def is_valid(self): return self.type in ( diff --git a/pynars/NARS/InferenceEngine/GeneralEngine/GeneralEngine.py b/pynars/NARS/InferenceEngine/GeneralEngine/GeneralEngine.py index 56eba53a..87b036f9 100644 --- a/pynars/NARS/InferenceEngine/GeneralEngine/GeneralEngine.py +++ b/pynars/NARS/InferenceEngine/GeneralEngine/GeneralEngine.py @@ -391,10 +391,13 @@ def step(self, concept: Concept): if is_valid: Global.States.record_premises(task, belief) Global.States.record_rules(rules) - tasks = self.inference(task, belief, term_belief, task_link_valid, term_link_valid, rules) - if term_link_valid is not None: # TODO: Check here whether the budget updating is the same as OpenNARS 3.0.4. - for task in tasks: TermLink.update_budget(term_link_valid.budget, task.budget.quality, belief.budget.priority if belief is not None else concept_target.budget.priority) - + derived_tasks = self.inference(task, belief, term_belief, task_link_valid, term_link_valid, rules) + if term_link_valid is not None: + # reward the termlink + for derived_task in derived_tasks: + reward: float = max(derived_task.budget.priority, task.achieving_level()) + TermLink.reward_budget(reward) + tasks_derived.extend(tasks) for term_link in term_links: concept.term_links.put_back(term_link)