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

📄 reteutil.c

📁 NASA 开发使用的一个专家系统
💻 C
📖 第 1 页 / 共 2 页
字号:
   /*******************************************************/   /*      "C" Language Integrated Production System      */   /*                                                     */   /*             CLIPS Version 6.05  04/09/97            */   /*                                                     */   /*                 RETE UTILITY MODULE                 */   /*******************************************************//*************************************************************//* Purpose: Provides a set of utility functions useful to    *//*   other modules.                                          *//*                                                           *//* Principal Programmer(s):                                  *//*      Gary D. Riley                                        *//*                                                           *//* Contributing Programmer(s):                               *//*                                                           *//* Revision History:                                         *//*                                                           *//*************************************************************/#define _RETEUTIL_SOURCE_#include <stdio.h>#define _CLIPS_STDIO_#include "setup.h"#if DEFRULE_CONSTRUCT#include "clipsmem.h"#include "router.h"#include "retract.h" #include "drive.h" #include "incrrset.h"#include "pattern.h"#include "match.h"#include "moduldef.h"#include "reteutil.h"/***************************************//* LOCAL INTERNAL FUNCTION DEFINITIONS *//***************************************/#if ANSI_COMPILER   static VOID                    TraceErrorToRuleDriver(struct joinNode *,char *);#else   static VOID                    TraceErrorToRuleDriver();#endif/****************************************//* GLOBAL INTERNAL VARIABLE DEFINITIONS *//****************************************/   globle struct partialMatch   *GlobalLHSBinds = NULL;   globle struct partialMatch   *GlobalRHSBinds = NULL;   globle struct joinNode       *GlobalJoin = NULL;   /***********************************************************//* PrintPartialMatch: Prints out the list of fact indices  *//*   and/or instance names associated with a partial match *//*   or rule instantiation.                                *//***********************************************************/globle VOID PrintPartialMatch(logicalName,list)  char *logicalName;  struct partialMatch *list;  {   struct patternEntity *matchingItem;   short int i;   for (i = 0; i < (int) list->bcount;)     {      if (get_nth_pm_match(list,i)->matchingItem != NULL)        {         matchingItem = get_nth_pm_match(list,i)->matchingItem;         if (matchingItem != NULL) (*matchingItem->theInfo->base.shortPrintFunction)(logicalName,matchingItem);        }      i++;      if (i < (int) list->bcount) PrintCLIPS(logicalName,",");     }  }/**********************************************//* CopyPartialMatch:  Copies a partial match. *//**********************************************/globle struct partialMatch *CopyPartialMatch(list,addActivationSlot,addDependencySlot)  struct partialMatch *list;  int addActivationSlot;  int addDependencySlot;  {   struct partialMatch *linker;   short int i;   linker = get_var_struct(partialMatch,sizeof(struct genericMatch) *                                        (list->bcount + addActivationSlot + addDependencySlot - 1));   linker->next = NULL;   linker->betaMemory = CLIPS_TRUE;   linker->busy = CLIPS_FALSE;   linker->activationf = addActivationSlot;   linker->dependentsf = addDependencySlot;   linker->notOriginf = CLIPS_FALSE;   linker->counterf = CLIPS_FALSE;   linker->bcount = list->bcount;   for (i = 0; i < (int) linker->bcount; i++) linker->binds[i] = list->binds[i];   if (addActivationSlot) linker->binds[i++].gm.theValue = NULL;   if (addDependencySlot) linker->binds[i].gm.theValue = NULL;   return(linker);  }/****************************************************//* MergePartialMatches: Merges two partial matches. *//****************************************************/globle struct partialMatch *MergePartialMatches(list1,list2,addActivationSlot,addDependencySlot)  struct partialMatch *list1, *list2;  int addActivationSlot;  int addDependencySlot;  {   struct partialMatch *linker;   short int i, j;   linker = get_var_struct(partialMatch,                           sizeof(struct genericMatch) *                            (list1->bcount + list2->bcount + addActivationSlot + addDependencySlot - 1));   linker->next = NULL;   linker->betaMemory = CLIPS_TRUE;   linker->busy = CLIPS_FALSE;   linker->activationf = addActivationSlot;   linker->dependentsf = addDependencySlot;   linker->notOriginf = CLIPS_FALSE;   linker->counterf = CLIPS_FALSE;   linker->bcount = list1->bcount + list2->bcount;   for (i = 0; i < (int) list1->bcount; i++)     { linker->binds[i] = list1->binds[i]; }   for (i = (short) list1->bcount, j = 0; i < (short) linker->bcount; i++, j++)     { linker->binds[i] = list2->binds[j]; }   if (addActivationSlot) linker->binds[i++].gm.theValue = NULL;   if (addDependencySlot) linker->binds[i].gm.theValue = NULL;   return(linker);  }  /*******************************************************************//* InitializePatternHeader: Initializes a pattern header structure *//*   (used by the fact and instance pattern matchers).             *//*******************************************************************/globle VOID InitializePatternHeader(theHeader)  struct patternNodeHeader *theHeader;  {   theHeader->entryJoin = NULL;   theHeader->alphaMemory = NULL;    theHeader->endOfQueue = NULL;   theHeader->singlefieldNode = CLIPS_FALSE;   theHeader->multifieldNode = CLIPS_FALSE;   theHeader->stopNode = CLIPS_FALSE;#if INCREMENTAL_RESET && (! RUN_TIME)   theHeader->initialize = GetIncrementalReset();#else   theHeader->initialize = CLIPS_FALSE;#endif   theHeader->marked = CLIPS_FALSE;   theHeader->beginSlot = CLIPS_FALSE;   theHeader->endSlot = CLIPS_FALSE;  }  /******************************************************************//* CreateAlphaMatch: Given a pointer to an entity (such as a fact *//*   or instance) which matched a pattern, this function creates  *//*   a partial match suitable for storing in the alpha memory of  *//*   the pattern network. Note that the multifield markers which  *//*   are passed as a calling argument are copied (thus the caller *//*   is still responsible for freeing these data structures).     *//******************************************************************/globle struct partialMatch *CreateAlphaMatch(theEntity,markers,theHeader)  VOID *theEntity;  struct multifieldMarker *markers;  struct patternNodeHeader *theHeader;  {   struct partialMatch *theMatch;   struct alphaMatch *afbtemp;      /*==================================================*/   /* Create the alpha match and intialize its values. */   /*==================================================*/      theMatch = get_struct(partialMatch);   theMatch->next = NULL;   theMatch->betaMemory = CLIPS_FALSE;   theMatch->busy = CLIPS_FALSE;   theMatch->activationf = CLIPS_FALSE;   theMatch->dependentsf = CLIPS_FALSE;   theMatch->notOriginf = CLIPS_FALSE;   theMatch->counterf = CLIPS_FALSE;   theMatch->dependentsf = CLIPS_FALSE;   theMatch->bcount = 1;   afbtemp = get_struct(alphaMatch);   afbtemp->next = NULL;   afbtemp->matchingItem = (struct patternEntity *) theEntity;      if (markers != NULL)     { afbtemp->markers = CopyMultifieldMarkers(markers); }   else     { afbtemp->markers = NULL; }        theMatch->binds[0].gm.theMatch = afbtemp;      /*====================================*/   /* Store the alpha match in the alpha */   /* memory of the pattern node.        */   /*====================================*/      if (theHeader->endOfQueue == NULL)     {       theHeader->alphaMemory = theMatch;      theHeader->endOfQueue = theMatch;     }   else     {      theHeader->endOfQueue->next = theMatch;      theHeader->endOfQueue = theMatch;     }   /*===================================================*/   /* Return a pointer to the newly create alpha match. */   /*===================================================*/      return(theMatch);  }/*********************************************************//* AddSingleMatch: Combines an alpha match and a partial *//*   match into a new partial match.                     *//*********************************************************/globle struct partialMatch *AddSingleMatch(list,afb,addActivationSlot,addDependencySlot)  struct partialMatch *list;  struct alphaMatch *afb;  int addActivationSlot;  int addDependencySlot;  {   struct partialMatch *linker;   short int i;   linker = get_var_struct(partialMatch,sizeof(struct genericMatch) *                                         (list->bcount + addActivationSlot +                                         addDependencySlot));   linker->next = NULL;   linker->betaMemory = CLIPS_TRUE;   linker->busy = CLIPS_FALSE;   linker->activationf = addActivationSlot;   linker->dependentsf = addDependencySlot;   linker->notOriginf = CLIPS_FALSE;   linker->counterf = CLIPS_FALSE;   linker->bcount = list->bcount + 1;   for (i = 0; i < (int) list->bcount; i++)     { linker->binds[i] = list->binds[i]; }   set_nth_pm_match(linker,i++,afb);      if (addActivationSlot) linker->binds[i++].gm.theValue = NULL;   if (addDependencySlot) linker->binds[i].gm.theValue = NULL;   return(linker);  }  /*******************************************//* CopyMultifieldMarkers: Copies a list of *//*   multifieldMarker data structures.     *//*******************************************/struct multifieldMarker *CopyMultifieldMarkers(theMarkers)  struct multifieldMarker *theMarkers;  {   struct multifieldMarker *head = NULL, *lastMark = NULL, *newMark;

⌨️ 快捷键说明

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