From 76adfe8d1f1b72ddcd11625b136a71b3ded23930 Mon Sep 17 00:00:00 2001 From: ARCJ137442 <61109168+ARCJ137442@users.noreply.github.com> Date: Mon, 23 Sep 2024 02:47:47 +0800 Subject: [PATCH 1/3] Update Decision.c, Decision.h, NAR.c: Privatize the global variable currentTime in `NAR.c` and supplement the parameter `currentTime` of `Decision_ConsiderNegativeOutcomes` to eliminate the cyclic dependency of `NAR` -> `Cycle` -> `Decision` --- src/Decision.c | 4 ++-- src/Decision.h | 1 - src/NAR.c | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Decision.c b/src/Decision.c index c7d0235c..8ae0c475 100755 --- a/src/Decision.c +++ b/src/Decision.c @@ -284,7 +284,7 @@ static Decision Decision_MotorBabbling() return decision; } -static Decision Decision_ConsiderNegativeOutcomes(Decision decision) +static Decision Decision_ConsiderNegativeOutcomes(Decision decision, long currentTime) { Event OpGoalImmediateOutcomes = {0}; //1. discount decision based on negative outcomes via revision @@ -386,7 +386,7 @@ static Decision Decision_ConsiderImplication(long currentTime, Event *goal, Impl i++; } } - return Decision_ConsiderNegativeOutcomes(decision); + return Decision_ConsiderNegativeOutcomes(decision, currentTime); } Decision Decision_BestCandidate(Concept *goalconcept, Event *goal, long currentTime) diff --git a/src/Decision.h b/src/Decision.h index 292eba8f..2eb1edf6 100755 --- a/src/Decision.h +++ b/src/Decision.h @@ -51,7 +51,6 @@ #include #include #include "Memory.h" -#include "NAR.h" #include "Config.h" //Parameters// diff --git a/src/NAR.c b/src/NAR.c index 6352b413..66530787 100755 --- a/src/NAR.c +++ b/src/NAR.c @@ -24,7 +24,7 @@ #include "NAR.h" -long currentTime = 1; +static long currentTime = 1; //This needs to be private to encourage the design of "pass in parameters rather than using global variables" static bool initialized = false; static int op_k = 0; double QUESTION_PRIMING = QUESTION_PRIMING_INITIAL; From 78fedc18a95f22eec226b3c9777499682f31e002 Mon Sep 17 00:00:00 2001 From: ARCJ137442 <61109168+ARCJ137442@users.noreply.github.com> Date: Mon, 23 Sep 2024 02:59:37 +0800 Subject: [PATCH 2/3] Update Cycle.c: Further removes the dependency on the global variable `currentTime` in `NAR.c` and resolves compile-time errors --- src/Cycle.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Cycle.c b/src/Cycle.c index b762d1bb..e2900214 100755 --- a/src/Cycle.c +++ b/src/Cycle.c @@ -154,7 +154,7 @@ void Cycle_PopEvents(Event *selectionArray, double *selectionPriority, int *sele //{Event (a &/ b)!, Event a.} |- Event b! Truth_Deduction //if Truth_Expectation(a) >= ANTICIPATION_THRESHOLD else //{Event (a &/ b)!} |- Event a! Truth_StructuralDeduction -bool Cycle_GoalSequenceDecomposition(Event *selectedGoal, double selectedGoalPriority, int layer) +bool Cycle_GoalSequenceDecomposition(Event *selectedGoal, double selectedGoalPriority, int layer, long currentTime) { //1. Extract potential subgoals if(!Narsese_copulaEquals(selectedGoal->term.atoms[0], SEQUENCE)) //left-nested sequence @@ -276,7 +276,7 @@ static void Cycle_ProcessAndInferGoalEvents(long currentTime, int layer) Event *goal = &selectedGoals[i]; IN_DEBUG( fputs("selected goal ", stdout); Narsese_PrintTerm(&goal->term); puts(""); ) //if goal is a sequence, overwrite with first deduced non-fulfilled element - if(Cycle_GoalSequenceDecomposition(goal, selectedGoalsPriority[i], layer)) //the goal was a sequence which leaded to a subgoal derivation + if(Cycle_GoalSequenceDecomposition(goal, selectedGoalsPriority[i], layer, currentTime)) //the goal was a sequence which leaded to a subgoal derivation { continue; } @@ -340,7 +340,7 @@ static void Cycle_ProcessAndInferGoalEvents(long currentTime, int layer) } //Reinforce temporal implication link between a's and b's concept (via temporal induction) -static Implication Cycle_ReinforceLink(Event *a, Event *b) +static Implication Cycle_ReinforceLink(Event *a, Event *b, long currentTime) { if(a->type != EVENT_TYPE_BELIEF || b->type != EVENT_TYPE_BELIEF) { @@ -416,7 +416,7 @@ void Cycle_ProcessBeliefEvents(long currentTime) //so now derive it if(success5) { - Cycle_ReinforceLink(&seq_op_cur, &postcondition); //<(A &/ op) =/> B> + Cycle_ReinforceLink(&seq_op_cur, &postcondition, currentTime); //<(A &/ op) =/> B> } } } @@ -445,10 +445,10 @@ void Cycle_ProcessBeliefEvents(long currentTime) { if(!op_id && !op_id2) { - Cycle_ReinforceLink(&c->belief_spike, &postcondition); // B>, B> + Cycle_ReinforceLink(&c->belief_spike, &postcondition, currentTime); // B>, B> if(c->belief_spike.occurrenceTime == postcondition.occurrenceTime) { - Cycle_ReinforceLink(&postcondition, &c->belief_spike); // A> + Cycle_ReinforceLink(&postcondition, &c->belief_spike, currentTime); // A> } } int sequence_len = 0; From c0a8cddd3ac5e6babbd2f87a3a585b8dfadd5f54 Mon Sep 17 00:00:00 2001 From: ARCJ137442 <61109168+ARCJ137442@users.noreply.github.com> Date: Mon, 23 Sep 2024 03:08:44 +0800 Subject: [PATCH 3/3] Update NAR.h: fix compile-time error for global variable `currentTime` The global variable `currentTime` is now completely private for NAR in `NAR.c` --- src/NAR.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/NAR.h b/src/NAR.h index cec1acd2..9c26d6b4 100755 --- a/src/NAR.h +++ b/src/NAR.h @@ -41,7 +41,6 @@ //Parameters// //----------// #define NAR_DEFAULT_TRUTH ((Truth) { .frequency = NAR_DEFAULT_FREQUENCY, .confidence = NAR_DEFAULT_CONFIDENCE }) -extern long currentTime; extern double QUESTION_PRIMING; //Callback function types//