/* * The MIT License * * Copyright 2020 The OpenNARS authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ #include "NAR.h" long currentTime = 1; static bool initialized = false; void NAR_INIT() { assert(pow(TRUTH_PROJECTION_DECAY_INITIAL,EVENT_BELIEF_DISTANCE) >= MIN_CONFIDENCE, "Bad params, increase projection decay or decrease event belief distance!"); Memory_INIT(); //clear data structures Event_INIT(); //reset base id counter Narsese_INIT(); currentTime = 1; //reset time initialized = true; } void NAR_Cycles(int cycles) { assert(initialized, "NAR not initialized yet, call NAR_INIT first!"); for(int i=0; iterm).success) { goto Continue; } if(isImplication) { Term subject = Term_ExtractSubterm(&term, 1); int op_k = Narsese_getOperationID(&subject); for(int j=0; jprecondition_beliefs[op_k].itemsAmount; j++) { Implication *imp = &c->precondition_beliefs[op_k].array[j]; if(!Variable_Unify(&term, &imp->term).success) { continue; } if(Truth_Expectation(imp->truth) >= Truth_Expectation(best_truth)) { best_truth = imp->truth; best_term = imp->term; answerCreationTime = imp->creationTime; } } } else if(isEvent) { if(c->belief_spike.type != EVENT_TYPE_DELETED) { Truth potential_best_truth = Truth_Projection(c->belief_spike.truth, c->belief_spike.occurrenceTime, currentTime); if(Truth_Expectation(potential_best_truth) >= Truth_Expectation(best_truth_projected)) { best_truth_projected = potential_best_truth; best_truth = c->belief_spike.truth; best_term = c->belief_spike.term; answerOccurrenceTime = c->belief_spike.occurrenceTime; answerCreationTime = c->belief_spike.creationTime; } } if(c->predicted_belief.type != EVENT_TYPE_DELETED) { Truth potential_best_truth = Truth_Projection(c->predicted_belief.truth, c->predicted_belief.occurrenceTime, currentTime); if(Truth_Expectation(potential_best_truth) >= Truth_Expectation(best_truth_projected)) { best_truth_projected = potential_best_truth; best_truth = c->predicted_belief.truth; best_term = c->predicted_belief.term; answerOccurrenceTime = c->predicted_belief.occurrenceTime; answerCreationTime = c->predicted_belief.creationTime; } } } else { if(c->belief.type != EVENT_TYPE_DELETED && Truth_Expectation(c->belief.truth) >= Truth_Expectation(best_truth)) { best_truth = c->belief.truth; best_term = c->belief.term; answerCreationTime = c->belief.creationTime; } } Continue:; } fputs("Answer: ", stdout); if(best_truth.confidence == 1.0) { puts("None."); } else { Narsese_PrintTerm(&best_term); if(answerOccurrenceTime == OCCURRENCE_ETERNAL) { printf(". creationTime=%ld ", answerCreationTime); } else { printf(". :|: occurrenceTime=%ld creationTime=%ld ", answerOccurrenceTime, answerCreationTime); } Truth_Print(&best_truth); } fflush(stdout); } //input beliefs and goals else { NAR_AddInput(term, punctuation == '!' ? EVENT_TYPE_GOAL : EVENT_TYPE_BELIEF, tv, !isEvent, isUserKnowledge); } }