rulecom.c

来自「clips源代码」· C语言 代码 · 共 1,026 行 · 第 1/3 页

C
1,026
字号
      i = depth - 1;      while (theJoin != NULL)        {         if (theJoin->joinFromTheRight)           { theJoin = (struct joinNode *) theJoin->rightSideEntryStructure; }         else           {            theAlphaStorage[i] = ((struct patternNodeHeader *) theJoin->rightSideEntryStructure)->firstHash;            i--;            theJoin = theJoin->lastLevel;           }        }      /*========================================*/      /* List the alpha memory partial matches. */      /*========================================*/      for (i = 0; i < depth; i++)        {         if (GetHaltExecution(theEnv) == TRUE)           {            genfree(theEnv,theAlphaStorage,(unsigned) (depth * sizeof(struct alphaMemoryHash *)));            return(TRUE);           }         EnvPrintRouter(theEnv,WDISPLAY,"Matches for Pattern ");         PrintLongInteger(theEnv,WDISPLAY,(long int) i + 1);         EnvPrintRouter(theEnv,WDISPLAY,": ");         count = 0;         for (listOfHashNodes = theAlphaStorage[i];              listOfHashNodes != NULL;              listOfHashNodes = listOfHashNodes->nextHash)           {            listOfMatches = listOfHashNodes->alphaMemory;            while (listOfMatches != NULL)              {               if (GetHaltExecution(theEnv) == TRUE)                 {                  genfree(theEnv,theAlphaStorage,(unsigned) (depth * sizeof(struct alphaMemoryHash *)));                  return(TRUE);                 }                                count++;               listOfMatches = listOfMatches->nextInMemory;              }           }                    PrintLongInteger(theEnv,WDISPLAY,count);         EnvPrintRouter(theEnv,WDISPLAY,"\n");        }      genfree(theEnv,theAlphaStorage,(unsigned) (depth * sizeof(struct alphaMemoryHash *)));      /*========================================*/      /* Store the beta memory partial matches. */      /*========================================*/      depth = lastJoin->depth;      theStorage = (struct betaMemory **) genalloc(theEnv,(unsigned) (depth * sizeof(struct betaMemory *)));      theJoin = lastJoin;      for (i = depth - 1; i >= 0; i--)        {         /* theStorage[i] = GetBetaMemory(theEnv,theJoin); */         theStorage[i] = theJoin->leftMemory;         theJoin = theJoin->lastLevel;        }      /*=======================================*/      /* List the beta memory partial matches. */      /*=======================================*/      for (i = 1; i < depth; i++)        {         if (GetHaltExecution(theEnv) == TRUE)           {            genfree(theEnv,theStorage,(unsigned) (depth * sizeof(struct betaMemory *)));            return(TRUE);           }         count = 0;         EnvPrintRouter(theEnv,WDISPLAY,"Partial matches for CEs 1 - ");         PrintLongInteger(theEnv,WDISPLAY,(long int) i + 1);         EnvPrintRouter(theEnv,WDISPLAY,": ");         theMemory = theStorage[i];                  for (b = 0; b < theMemory->size; b++)           {            listOfMatches = theMemory->beta[b];            while (listOfMatches != NULL)              {               if (GetHaltExecution(theEnv) == TRUE)                 {                  genfree(theEnv,theStorage,(unsigned) (depth * sizeof(struct betaMemory *)));                  return(TRUE);                 }               count++;               listOfMatches = listOfMatches->nextInMemory;              }           }         count = theMemory->count;         PrintLongInteger(theEnv,WDISPLAY,count);         EnvPrintRouter(theEnv,WDISPLAY,"\n");         }      genfree(theEnv,theStorage,(unsigned) (depth * sizeof(struct betaMemory *)));     }   /*===================*/   /* List activations. */   /*===================*/   rulePtr = tmpPtr;   EnvPrintRouter(theEnv,WDISPLAY,"Activations: ");   count = 0;   for (agendaPtr = (struct activation *) EnvGetNextActivation(theEnv,NULL);        agendaPtr != NULL;        agendaPtr = (struct activation *) EnvGetNextActivation(theEnv,agendaPtr))     {      if (GetHaltExecution(theEnv) == TRUE) return(TRUE);      if (((struct activation *) agendaPtr)->theRule->header.name == rulePtr->header.name)        { count++; }     }   PrintLongInteger(theEnv,WDISPLAY,count);   EnvPrintRouter(theEnv,WDISPLAY,"\n");   return(TRUE);  }/***************************************//* TimetagFunction: H/L access routine *//*   for the timetag function.         *//***************************************/globle long long TimetagFunction(  void *theEnv)  {   DATA_OBJECT item;   void *ptr;   if (EnvArgCountCheck(theEnv,"timetag",EXACTLY,1) == -1) return(-1LL);   ptr = GetFactOrInstanceArgument(theEnv,1,&item,"timetag");   if (ptr == NULL) return(-1);   return ((struct patternEntity *) ptr)->timeTag;  }#endif /* DEBUGGING_FUNCTIONS */#if DEVELOPER/***********************************************//* RuleComplexityCommand: H/L access routine   *//*   for the rule-complexity function.         *//***********************************************/globle long RuleComplexityCommand(  void *theEnv)  {   char *ruleName;   struct defrule *rulePtr;   ruleName = GetConstructName(theEnv,"rule-complexity","rule name");   if (ruleName == NULL) return(-1);   rulePtr = (struct defrule *) EnvFindDefrule(theEnv,ruleName);   if (rulePtr == NULL)     {      CantFindItemErrorMessage(theEnv,"defrule",ruleName);      return(-1);     }   return(rulePtr->complexity);  }/******************************************//* ShowJoinsCommand: H/L access routine   *//*   for the show-joins command.          *//******************************************/globle void ShowJoinsCommand(  void *theEnv)  {   char *ruleName;   void *rulePtr;   ruleName = GetConstructName(theEnv,"show-joins","rule name");   if (ruleName == NULL) return;   rulePtr = EnvFindDefrule(theEnv,ruleName);   if (rulePtr == NULL)     {      CantFindItemErrorMessage(theEnv,"defrule",ruleName);      return;     }   ShowJoins(theEnv,rulePtr);   return;  }/*********************************//* ShowJoins: C access routine   *//*   for the show-joins command. *//*********************************/static void ShowJoins(  void *theEnv,  void *theRule)  {   struct defrule *rulePtr;   struct joinNode *theJoin;   struct joinNode *joinList[MAXIMUM_NUMBER_OF_PATTERNS];   int numberOfJoins;   char rhsType;   rulePtr = (struct defrule *) theRule;   /*=================================================*/   /* Loop through each of the disjuncts for the rule */   /*=================================================*/   while (rulePtr != NULL)     {      /*=====================================*/      /* Determine the number of join nodes. */      /*=====================================*/      numberOfJoins = -1;      theJoin = rulePtr->lastJoin;      while (theJoin != NULL)        {         if (theJoin->joinFromTheRight)           { theJoin = (struct joinNode *) theJoin->rightSideEntryStructure; }         else           {            numberOfJoins++;            joinList[numberOfJoins] = theJoin;            theJoin = theJoin->lastLevel;           }        }      /*====================*/      /* Display the joins. */      /*====================*/      while (numberOfJoins >= 0)        {         char buffer[20];                  if (joinList[numberOfJoins]->patternIsNegated)           { rhsType = 'n'; }         else if (joinList[numberOfJoins]->patternIsExists)           { rhsType = 'x'; }         else           { rhsType = ' '; }                    gensprintf(buffer,"%2d%c%c: ",(int) joinList[numberOfJoins]->depth,                                     rhsType,                                     (joinList[numberOfJoins]->logicalJoin) ? 'l' : ' ');         EnvPrintRouter(theEnv,WDISPLAY,buffer);         PrintExpression(theEnv,WDISPLAY,joinList[numberOfJoins]->networkTest);         EnvPrintRouter(theEnv,WDISPLAY,"\n");                  if (joinList[numberOfJoins]->leftHash != NULL)           {            EnvPrintRouter(theEnv,WDISPLAY,"    LH : ");            PrintExpression(theEnv,WDISPLAY,joinList[numberOfJoins]->leftHash);            EnvPrintRouter(theEnv,WDISPLAY,"\n");           }                  numberOfJoins--;        };      /*===============================*/      /* Proceed to the next disjunct. */      /*===============================*/      rulePtr = rulePtr->disjunct;      if (rulePtr != NULL) EnvPrintRouter(theEnv,WDISPLAY,"\n");     }  }/******************************************************//* ShowAlphaHashTable: Displays the number of entries *//*   in each slot of the alpha hash table.            *//******************************************************/globle void ShowAlphaHashTable(   void *theEnv)   {    int i, count;    long totalCount = 0;    struct alphaMemoryHash *theEntry;    struct partialMatch *theMatch;    char buffer[40];    for (i = 0; i < ALPHA_MEMORY_HASH_SIZE; i++)      {       for (theEntry =  DefruleData(theEnv)->AlphaMemoryTable[i], count = 0;            theEntry != NULL;            theEntry = theEntry->next)         { count++; }       if (count != 0)         {          totalCount += count;          gensprintf(buffer,"%4d: %4d ->",i,count);          EnvPrintRouter(theEnv,WDISPLAY,buffer);                    for (theEntry =  DefruleData(theEnv)->AlphaMemoryTable[i], count = 0;               theEntry != NULL;               theEntry = theEntry->next)            {             for (theMatch = theEntry->alphaMemory;                  theMatch != NULL;                  theMatch = theMatch->nextInMemory)               { count++; }                            gensprintf(buffer," %4d",count);             EnvPrintRouter(theEnv,WDISPLAY,buffer);             if (theEntry->owner->rightHash == NULL)               { EnvPrintRouter(theEnv,WDISPLAY,"*"); }            }                    EnvPrintRouter(theEnv,WDISPLAY,"\n");         }      }    gensprintf(buffer,"Total Count: %ld\n",totalCount);    EnvPrintRouter(theEnv,WDISPLAY,buffer);   }#endif /* DEVELOPER */#endif /* DEFRULE_CONSTRUCT */

⌨️ 快捷键说明

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