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

📄 rulebin.c

📁 NASA 开发使用的一个专家系统
💻 C
📖 第 1 页 / 共 3 页
字号:
/* BsaveBinaryItem: Writes out all defrule *//*   structures to the binary file.        *//*******************************************/static VOID BsaveBinaryItem(fp)  FILE *fp;  {   unsigned long int space;   struct defrule *theDefrule;   struct defmodule *theModule;   struct defruleModule *theModuleItem;   struct bsaveDefruleModule tempDefruleModule;   /*===============================================*/   /* Write out the space required by the defrules. */   /*===============================================*/   space = (NumberOfDefrules * sizeof(struct bsaveDefrule)) +           (NumberOfJoins * sizeof(struct bsaveJoinNode)) +           (NumberOfDefruleModules * sizeof(struct bsaveDefruleModule));   GenWrite(&space,(unsigned long) sizeof(unsigned long int),fp);      /*===============================================*/   /* Write out each defrule module data structure. */   /*===============================================*/   NumberOfDefrules = 0;   for (theModule = (struct defmodule *) GetNextDefmodule(NULL);        theModule != NULL;        theModule = (struct defmodule *) GetNextDefmodule(theModule))     {      SetCurrentModule((VOID *) theModule);                  theModuleItem = (struct defruleModule *)                      GetModuleItem(NULL,FindModuleItem("defrule")->moduleIndex);      AssignBsaveDefmdlItemHdrVals(&tempDefruleModule.header,                                           &theModuleItem->header);      GenWrite(&tempDefruleModule,(unsigned long) sizeof(struct bsaveDefruleModule),fp);     }   /*========================================*/   /* Write out each defrule data structure. */   /*========================================*/   for (theModule = (struct defmodule *) GetNextDefmodule(NULL);        theModule != NULL;        theModule = (struct defmodule *) GetNextDefmodule(theModule))     {      SetCurrentModule((VOID *) theModule);         for (theDefrule = (struct defrule *) GetNextDefrule(NULL);           theDefrule != NULL;           theDefrule = (struct defrule *) GetNextDefrule(theDefrule))        { BsaveDisjuncts(fp,theDefrule); }     }   /*=============================*/   /* Write out the Rete Network. */   /*=============================*/      MarkRuleNetwork(1);   BsaveJoins(fp);      /*=============================================================*/   /* If a binary image was already loaded when the bsave command */   /* was issued, then restore the counts indicating the number   */   /* of defrules, defrule modules, and joins in the binary image */   /* (these were overwritten by the binary save).                */   /*=============================================================*/      if (Bloaded())     {      RestoreBloadCount(&NumberOfDefruleModules);      RestoreBloadCount(&NumberOfDefrules);      RestoreBloadCount(&NumberOfJoins);     }  }/************************************************************//* BsaveDisjuncts: Writes out all the disjunct defrule data *//*   structures for a specific rule to the binary file.     *//************************************************************/static VOID BsaveDisjuncts(fp,theDefrule)  FILE *fp;  struct defrule *theDefrule;  {   struct defrule *theDisjunct;   struct bsaveDefrule tempDefrule;   long int disjunctExpressionCount = 0L;   int first;      /*=========================================*/   /* Loop through each disjunct of the rule. */   /*=========================================*/      for (theDisjunct = theDefrule, first = CLIPS_TRUE;        theDisjunct != NULL;        theDisjunct = theDisjunct->disjunct, first = CLIPS_FALSE)     {      NumberOfDefrules++;            /*======================================*/      /* Set header and miscellaneous values. */      /*======================================*/            AssignBsaveConstructHeaderVals(&tempDefrule.header,                                     &theDisjunct->header);      tempDefrule.salience = theDisjunct->salience;      tempDefrule.localVarCnt = theDisjunct->localVarCnt;      tempDefrule.complexity = theDisjunct->complexity;      tempDefrule.autoFocus = theDisjunct->autoFocus;            /*=======================================*/      /* Set dynamic salience data structures. */      /*=======================================*/      #if DYNAMIC_SALIENCE      if (theDisjunct->dynamicSalience != NULL)        {         if (first)           {            tempDefrule.dynamicSalience = ExpressionCount;            disjunctExpressionCount = ExpressionCount;            ExpressionCount += ExpressionSize(theDisjunct->dynamicSalience);           }         else           { tempDefrule.dynamicSalience = disjunctExpressionCount; }        }      else#endif        { tempDefrule.dynamicSalience = -1L; }      /*==============================================*/      /* Set the index to the disjunct's RHS actions. */      /*==============================================*/            if (theDisjunct->actions != NULL)        {         tempDefrule.actions = ExpressionCount;         ExpressionCount += ExpressionSize(theDisjunct->actions);        }      else        { tempDefrule.actions = -1L; }              /*=================================*/      /* Set the index to the disjunct's */      /* logical join and last join.     */      /*=================================*/#if LOGICAL_DEPENDENCIES      tempDefrule.logicalJoin = BsaveJoinIndex(theDisjunct->logicalJoin);#else      tempDefrule.logicalJoin = -1L;#endif      tempDefrule.lastJoin = BsaveJoinIndex(theDisjunct->lastJoin);      /*=====================================*/      /* Set the index to the next disjunct. */      /*=====================================*/      if (theDisjunct->disjunct != NULL)        { tempDefrule.disjunct = NumberOfDefrules; }      else        { tempDefrule.disjunct = -1L; }      /*=================================*/      /* Write the disjunct to the file. */      /*=================================*/            GenWrite(&tempDefrule,(unsigned long) sizeof(struct bsaveDefrule),fp);     }  }  /********************************************//* BsaveJoins: Writes out all the join node *//*   data structures to the binary file.    *//********************************************/static VOID BsaveJoins(fp)  FILE *fp;  {   struct defrule *rulePtr;   struct joinNode *joinPtr;   struct defmodule *theModule;      /*===========================*/   /* Loop through each module. */   /*===========================*/     for (theModule = (struct defmodule *) GetNextDefmodule(NULL);        theModule != NULL;        theModule = (struct defmodule *) GetNextDefmodule(theModule))     {      SetCurrentModule((VOID *) theModule);      /*===========================================*/      /* Loop through each rule and its disjuncts. */      /*===========================================*/            rulePtr = (struct defrule *) GetNextDefrule(NULL);      while (rulePtr != NULL)        {         /*=========================================*/         /* Loop through each join of the disjunct. */         /*=========================================*/                  for (joinPtr = rulePtr->lastJoin;              joinPtr != NULL;              joinPtr = GetPreviousJoin(joinPtr))           { if (joinPtr->marked) BsaveJoin(fp,joinPtr); }          /*=======================================*/         /* Move on to the next rule or disjunct. */         /*=======================================*/                 if (rulePtr->disjunct != NULL) rulePtr = rulePtr->disjunct;         else rulePtr = (struct defrule *) GetNextDefrule(rulePtr);        }      }   }      /********************************************//* BsaveJoin: Writes out a single join node *//*   data structure to the binary file.     *//********************************************/static VOID BsaveJoin(fp,joinPtr)  FILE *fp;  struct joinNode *joinPtr;  {   struct bsaveJoinNode tempJoin;      joinPtr->marked = 0;   tempJoin.depth = joinPtr->depth;   tempJoin.rhsType = joinPtr->rhsType;   tempJoin.firstJoin = joinPtr->firstJoin;   tempJoin.logicalJoin = joinPtr->logicalJoin;   tempJoin.joinFromTheRight = joinPtr->joinFromTheRight;   tempJoin.patternIsNegated = joinPtr->patternIsNegated;               if (joinPtr->joinFromTheRight)     { tempJoin.rightSideEntryStructure =  BsaveJoinIndex(joinPtr->rightSideEntryStructure); }   else     { tempJoin.rightSideEntryStructure =  -1L; }                 tempJoin.lastLevel =  BsaveJoinIndex(joinPtr->lastLevel);   tempJoin.nextLevel =  BsaveJoinIndex(joinPtr->nextLevel);   tempJoin.rightMatchNode =  BsaveJoinIndex(joinPtr->rightMatchNode);   tempJoin.rightDriveNode =  BsaveJoinIndex(joinPtr->rightDriveNode);   tempJoin.networkTest = HashedExpressionIndex(joinPtr->networkTest);   if (joinPtr->ruleToActivate != NULL)     {      tempJoin.ruleToActivate =          GetDisjunctIndex(joinPtr->ruleToActivate);     }   else     { tempJoin.ruleToActivate = -1L; }   GenWrite(&tempJoin,(unsigned long) sizeof(struct bsaveJoinNode),fp);  }  /***********************************************************//* AssignBsavePatternHeaderValues: Assigns the appropriate *//*   values to a bsave pattern header record.              *//***********************************************************/globle VOID AssignBsavePatternHeaderValues(theBsaveHeader,theHeader)  struct bsavePatternNodeHeader *theBsaveHeader;  struct patternNodeHeader *theHeader;  {   theBsaveHeader->multifieldNode = theHeader->multifieldNode;   theBsaveHeader->entryJoin = BsaveJoinIndex(theHeader->entryJoin);   theBsaveHeader->singlefieldNode = theHeader->singlefieldNode;   theBsaveHeader->stopNode = theHeader->stopNode;   theBsaveHeader->beginSlot = theHeader->beginSlot;   theBsaveHeader->endSlot = theHeader->endSlot;  }  #endif /* BLOAD_AND_BSAVE *//************************************************//* BloadStorage: Loads storage requirements for *//*   the defrules used by this binary image.    *//************************************************/static VOID BloadStorage()  {   unsigned long space;      /*=================================================*/   /* Determine the number of defrule, defruleModule, */   /* and joinNode data structures to be read.        */

⌨️ 快捷键说明

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