⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 factmngr.c

📁 一套美国国家宇航局人工智能中心NASA的专家系统工具源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
   /* Return TRUE to indicate that fact slot */   /* values were successfully copied.       */   /*========================================*/      return(CLIPS_TRUE);  }  /*********************************************//* CreateFactBySize: Allocates a fact data   *//*   structure based on the number of slots. *//*********************************************/globle struct fact *CreateFactBySize(size)  int size;  {   struct fact *theFact;   int newSize;   if (size <= 0) newSize = 1;   else newSize = size;   theFact = get_var_struct2(fact,sizeof(struct field) * (newSize - 1));       theFact->depth = (unsigned) CurrentEvaluationDepth;   theFact->garbage = CLIPS_FALSE;   theFact->factIndex = 0L;   theFact->factHeader.busyCount = 0;   theFact->factHeader.theInfo = &FactInfo;#if LOGICAL_DEPENDENCIES   theFact->factHeader.dependents = NULL;#endif   theFact->whichDeftemplate = NULL;   theFact->nextFact = NULL;   theFact->previousFact = NULL;   theFact->list = NULL;      theFact->theProposition.multifieldLength = size;   theFact->theProposition.depth = (short) CurrentEvaluationDepth;   theFact->theProposition.busyCount = 0;   return(theFact);  }/*********************************************//* ReturnFact: Returns a fact data structure *//*   to the pool of free memory.             *//*********************************************/globle VOID ReturnFact(theFact)  struct fact *theFact;  {   struct multifield *theSegment;   int newSize, i;      theSegment = &theFact->theProposition;      for (i = 0; i < (int) theSegment->multifieldLength; i++)     {      if (theSegment->theFields[i].type == MULTIFIELD)        { ReturnMultifield(theSegment->theFields[i].value); }     }      if (theFact->theProposition.multifieldLength == 0) newSize = 1;   else newSize = theFact->theProposition.multifieldLength;      rtn_var_struct2(fact,sizeof(struct field) * (newSize - 1),theFact);  }/*************************************************************//* FactInstall: Increments the fact, deftemplate, and atomic *//*   data value busy counts associated with the fact.        *//*************************************************************/globle VOID FactInstall(newFact)  struct fact *newFact;  {   struct multifield *theSegment;   int i;      NumberOfFacts++;   newFact->whichDeftemplate->busyCount++;   theSegment = &newFact->theProposition;         for (i = 0 ; i < (int) theSegment->multifieldLength ; i++)     {       AtomInstall(theSegment->theFields[i].type,theSegment->theFields[i].value);     }        newFact->factHeader.busyCount++;   }/***************************************************************//* FactDeinstall: Decrements the fact, deftemplate, and atomic *//*   data value busy counts associated with the fact.          *//***************************************************************/globle VOID FactDeinstall(newFact)  struct fact *newFact;  {   struct multifield *theSegment;   int i;      NumberOfFacts--;   theSegment = &newFact->theProposition;   newFact->whichDeftemplate->busyCount--;      for (i = 0 ; i < (int) theSegment->multifieldLength ; i++)     {       AtomDeinstall(theSegment->theFields[i].type,theSegment->theFields[i].value);     }        newFact->factHeader.busyCount--;   }/*********************************************//* IncrementFactCount: Increments the number *//*   of references to a specified fact.      *//*********************************************/globle VOID IncrementFactCount(factPtr)  VOID *factPtr;  {   ((struct fact *) factPtr)->factHeader.busyCount++;  }/*********************************************//* DecrementFactCount: Decrements the number *//*   of references to a specified fact.      *//*********************************************/globle VOID DecrementFactCount(factPtr)  VOID *factPtr;  {   ((struct fact *) factPtr)->factHeader.busyCount--;  }/************************************************************//* GetNextFact: If passed a NULL pointer, returns the first *//*   fact in the fact-list. Otherwise returns the next fact *//*   following the fact passed as an argument.              *//************************************************************/globle VOID *GetNextFact(factPtr)  VOID *factPtr;  {   if (factPtr == NULL)     { return((VOID *) FactList); }   if (((struct fact *) factPtr)->garbage) return(NULL);   return((VOID *) ((struct fact *) factPtr)->nextFact);  }/**************************************************//* GetNextFactInScope: Returns the next fact that *//*   is in scope of the current module. Works in  *//*   a similar fashion to GetNextFact, but skips  *//*   facts that are out of scope.                 *//**************************************************/globle VOID *GetNextFactInScope(vTheFact)  VOID *vTheFact;  {             static long lastModuleIndex = -1;   struct fact *theFact = (struct fact *) vTheFact;      /*=======================================================*/   /* If fact passed as an argument is a NULL pointer, then */   /* we're just beginning a traversal of the fact list. If */   /* the module index has changed since that last time the */   /* fact list was traversed by this routine, then         */   /* determine all of the deftemplates that are in scope   */   /* of the current module.                                */   /*=======================================================*/      if (theFact == NULL)     {       theFact = FactList;      if (lastModuleIndex != ModuleChangeIndex)        {         UpdateDeftemplateScope();         lastModuleIndex = ModuleChangeIndex;        }     }        /*==================================================*/   /* Otherwise, if the fact passed as an argument has */   /* been retracted, then there's no way to determine */   /* the next fact, so return a NULL pointer.         */   /*==================================================*/      else if (((struct fact *) theFact)->garbage)      { return(NULL); }        /*==================================================*/   /* Otherwise, start the search for the next fact in */   /* scope with the fact immediately following the    */   /* fact passed as an argument.                      */   /*==================================================*/      else     { theFact = theFact->nextFact; }        /*================================================*/   /* Continue traversing the fact-list until a fact */   /* is found that's associated with a deftemplate  */   /* that's in scope.                               */   /*================================================*/                             while (theFact != NULL)     {      if (theFact->whichDeftemplate->inScope) return((VOID *) theFact);              theFact = theFact->nextFact;     }        return(NULL);  }/*******************************************//* GetFactPPForm: Returns the pretty print *//*   representation of a fact.             *//*******************************************/globle VOID GetFactPPForm(buffer,bufferLength,theFact)  char *buffer;  int bufferLength;  VOID *theFact;  {   OpenStringDestination("FactPPForm",buffer,bufferLength);   PrintFactWithIdentifier("FactPPForm",(struct fact *) theFact);   CloseStringDestination("FactPPForm");  }/***********************************//* FactIndex: C access routine for *//*   the fact-index function.      *//***********************************/globle long int FactIndex(factPtr)  VOID *factPtr;  {   return(((struct fact *) factPtr)->factIndex);  }/**************************************//* AssertString: C access routine for *//*   the assert-string function.      *//**************************************/globle VOID *AssertString(theString)  char *theString;  {   struct fact *theFact;   if ((theFact = StringToFact(theString)) == NULL) return(NULL);   return((VOID *) Assert((VOID *) theFact));  }/******************************************************//* GetFactListChanged: Returns the flag indicating    *//*   whether a change to the fact-list has been made. *//******************************************************/globle int GetFactListChanged()  { return(ChangeToFactList); }/********************************************************//* SetFactListChanged: Sets the flag indicating whether *//*   a change to the fact-list has been made.           *//********************************************************/globle VOID SetFactListChanged(value)  int value;  {   ChangeToFactList = value;  }/****************************************//* GetNumberOfFacts: Returns the number *//* of facts in the fact-list.           *//****************************************/globle long int GetNumberOfFacts()  { return(NumberOfFacts); }/***********************************************************//* ResetFacts: Reset function for facts. Sets the starting *//*   fact index to zero and removes all facts.             *//***********************************************************/static VOID ResetFacts()  {   /*====================================*/   /* Initialize the fact index to zero. */   /*====================================*/   NextFactIndex = 0L;   /*======================================*/   /* Remove all facts from the fact list. */   /*======================================*/   RemoveAllFacts();  }  /************************************************************//* ClearFactsReady: Clear ready function for facts. Returns *//*   TRUE if facts were successfully removed and the clear  *//*   command can continue, otherwise FALSE.                 *//************************************************************/static int ClearFactsReady()  {   /*====================================*/   /* Initialize the fact index to zero. */   /*====================================*/   NextFactIndex = 0L;   /*======================================*/   /* Remove all facts from the fact list. */   /*======================================*/   RemoveAllFacts();      /*==============================================*/   /* If for some reason there are any facts still */   /* remaining, don't continue with the clear.    */   /*==============================================*/                       if (GetNextFact(NULL) != NULL) return(CLIPS_FALSE);      /*=============================*/   /* Return TRUE to indicate the */   /* clear command can continue. */   /*=============================*/      return(CLIPS_TRUE);  }/***************************************************//* FindIndexedFact: Returns a pointer to a fact in *//*   the fact list with the specified fact index.  *//***************************************************/globle struct fact *FindIndexedFact(factIndexSought)  long int factIndexSought;  {   struct fact *theFact;   for (theFact = (struct fact *) GetNextFact(NULL);        theFact != NULL;        theFact = (struct fact *) GetNextFact(theFact))     {      if (theFact->factIndex == factIndexSought)        { return(theFact); }     }   return(NULL);  }  #endif /* DEFTEMPLATE_CONSTRUCT && DEFRULE_CONSTRUCT */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -