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

📄 lgcldpnd.c

📁 NASA 开发使用的一个专家系统
💻 C
📖 第 1 页 / 共 2 页
字号:
      if (theBinds->dependentsf == CLIPS_FALSE) return;      /*=======================================*/   /* Loop through each of the dependencies */   /* attached to the partial match.        */   /*=======================================*/      dlPtr = (struct dependency *) theBinds->binds[theBinds->bcount + theBinds->activationf].gm.theValue;   while (dlPtr != NULL)     {      /*===============================*/      /* Remember the next dependency. */      /*===============================*/            tempPtr = dlPtr->next;      /*==========================================================*/      /* Determine the data entity associated with the dependency */      /* structure and delete its dependency references to this   */      /* partial match.                                           */      /*==========================================================*/            theEntity = (struct patternEntity *) dlPtr->dPtr;            theList = (struct dependency *) theEntity->dependents;      theList = DetachAssociatedDependencies(theList,(VOID *) theBinds);      theEntity->dependents = (VOID *) theList;            /*==============================================================*/      /* If the data entity has lost all of its logical support, then */      /* add the dependency structure from the partial match to the   */      /* list of unsupported data entities to be deleted. Otherwise,  */      /* just delete the dependency structure.                        */      /*==============================================================*/            if (theEntity->dependents == NULL)        {         (*theEntity->theInfo->base.incrementBusyCount)(theEntity);         dlPtr->next = UnsupportedDataEntities;         UnsupportedDataEntities = dlPtr;        }      else        { rtn_struct(dependency,dlPtr); }      /*==================================*/      /* Move on to the next dependency.  */      /*==================================*/            dlPtr = tempPtr;     }   /*=====================================*/   /* The partial match no longer has any */   /* dependencies associated with it.    */   /*=====================================*/      theBinds->binds[theBinds->bcount + theBinds->activationf].gm.theValue = NULL;  }  /********************************************************************//* ForceLogicalRetractions: Deletes the data entities found on the  *//*   list of items that have lost their logical support. The delete *//*   function associated with each data entity is called to delete  *//*   that data entity. Calling the delete function may in turn      *//*   add more data entities to the list of data entities which have *//*   lost their logical support.                                    *//********************************************************************/globle VOID ForceLogicalRetractions()  {   struct dependency *tempPtr;   struct patternEntity *theEntity;   static int alreadyEntered = CLIPS_FALSE;   /*===================================================*/   /* Don't reenter this function once it's called. Any */   /* new additions to the list of items to be deleted  */   /* as a result of losing their logical support will  */   /* be handled properly.                              */   /*===================================================*/      if (alreadyEntered) return;   alreadyEntered = CLIPS_TRUE;      /*=======================================================*/   /* Continue to delete the first item on the list as long */   /* as one exists. This is done because new items may be  */   /* placed at the beginning of the list as other data     */   /* entities are deleted.                                 */   /*=======================================================*/      while (UnsupportedDataEntities != NULL)     {      /*==========================================*/      /* Determine the data entity to be deleted. */      /*==========================================*/            theEntity = (struct patternEntity *) UnsupportedDataEntities->dPtr;      /*================================================*/      /* Remove the dependency structure from the list. */      /*================================================*/            tempPtr = UnsupportedDataEntities;      UnsupportedDataEntities = UnsupportedDataEntities->next;      rtn_struct(dependency,tempPtr);            /*=========================*/      /* Delete the data entity. */      /*=========================*/            (*theEntity->theInfo->base.decrementBusyCount)(theEntity);      (*theEntity->theInfo->base.deleteFunction)(theEntity);     }        /*============================================*/   /* Deletion of items on the list is complete. */   /*============================================*/      alreadyEntered = CLIPS_FALSE;  }/****************************************************************//* Dependencies: C access routine for the dependencies command. *//****************************************************************/globle VOID Dependencies(theEntity)  struct patternEntity *theEntity;  {   struct dependency *fdPtr;      /*=========================================*/   /* If the data entity has no dependencies, */   /* then print "None" and return.           */   /*=========================================*/      if (theEntity->dependents == NULL)     {      PrintCLIPS(WDISPLAY,"None\n");      return;     }   /*============================================*/   /* Loop through the list of the data entities */   /* dependencies and print them.               */   /*============================================*/      for (fdPtr = (struct dependency *) theEntity->dependents;        fdPtr != NULL;        fdPtr = fdPtr->next)     {      PrintPartialMatch(WDISPLAY,(struct partialMatch *) fdPtr->dPtr);      PrintCLIPS(WDISPLAY,"\n");     }  }/************************************************************//* Dependents: C access routine for the dependents command. *//************************************************************/globle VOID Dependents(theEntity)  struct patternEntity *theEntity;  {   struct patternEntity *entityPtr = NULL;   struct patternParser *theParser = NULL;   struct dependency *fdPtr;   struct partialMatch *theBinds;   int found = CLIPS_FALSE;   /*=================================*/   /* Loop through every data entity. */   /*=================================*/      for (GetNextPatternEntity(&theParser,&entityPtr);        entityPtr != NULL;        GetNextPatternEntity(&theParser,&entityPtr))     {      /*====================================*/      /* Loop through every dependency link */      /* associated with the data entity.   */      /*====================================*/            for (fdPtr = (struct dependency *) entityPtr->dependents;           fdPtr != NULL;           fdPtr = fdPtr->next)        {         /*=====================================================*/         /* If the data entity which was the argument passed to */         /* the dependents command is contained in one of the   */         /* partial matches of the data entity currently being  */         /* examined, then the data entity being examined is a  */         /* dependent. Print the data entity and then move on   */         /* to the next data entity.                            */         /*=====================================================*/                  theBinds = (struct partialMatch *) fdPtr->dPtr;         if (FindEntityInPartialMatch(theEntity,theBinds) == CLIPS_TRUE)           {            if (found) PrintCLIPS(WDISPLAY,",");            (*entityPtr->theInfo->base.shortPrintFunction)(WDISPLAY,entityPtr);            found = CLIPS_TRUE;            break;           }        }     }        /*=================================================*/   /* If no dependents were found, then print "None." */   /* Otherwise print a carriage return after the     */   /* list of dependents.                             */   /*=================================================*/   if (! found) PrintCLIPS(WDISPLAY,"None\n");   else PrintCLIPS(WDISPLAY,"\n");  }  /******************************************************//* FindEntityInPartialMatch: Searches for a specified *//*   data entity in a partial match.                  *//******************************************************/static int FindEntityInPartialMatch(theEntity,thePartialMatch)  struct patternEntity *theEntity;  struct partialMatch *thePartialMatch;  {   short int i;   for (i = 0 ; i < (int) thePartialMatch->bcount; i++)     {      if (thePartialMatch->binds[i].gm.theMatch->matchingItem == theEntity)        { return(CLIPS_TRUE); }     }   return(CLIPS_FALSE);  }#if DEBUGGING_FUNCTIONS/*********************************************//* DependenciesCommand: CLIPS access routine *//*   for the dependencies command.           *//*********************************************/globle VOID DependenciesCommand()  {   DATA_OBJECT item;   VOID *ptr;   if (ArgCountCheck("dependencies",EXACTLY,1) == -1) return;   ptr = GetFactOrInstanceArgument(&item,"dependencies");      if (ptr == NULL) return;   #if DEFRULE_CONSTRUCT   Dependencies((struct patternEntity *) ptr);#else   PrintCLIPS(WDISPLAY,"None\n");#endif  }        /*******************************************//* DependentsCommand: CLIPS access routine *//*   for the dependents command.           *//*******************************************/globle VOID DependentsCommand()  {   DATA_OBJECT item;   VOID *ptr;   if (ArgCountCheck("dependents",EXACTLY,1) == -1) return;   ptr = GetFactOrInstanceArgument(&item,"dependents");      if (ptr == NULL) return;   #if DEFRULE_CONSTRUCT   Dependents((struct patternEntity *) ptr);#else   PrintCLIPS(WDISPLAY,"None\n");#endif  }        /**************************************************************//* GetFactOrInstanceArgument: Utility routine for retrieving  *//*   an argument suitable for the dependents and dependencies *//*   commands.                                                *//**************************************************************/static VOID *GetFactOrInstanceArgument(item,functionName)  DATA_OBJECT *item;  char *functionName;  {   VOID *ptr;   /*==============================*/   /* Retrieve the first argument. */   /*==============================*/      RtnUnknown(1,item);   /*==================================================*/   /* Fact and instance addresses are valid arguments. */   /*==================================================*/      if ((GetpType(item) == FACT_ADDRESS) ||       (GetpType(item) == INSTANCE_ADDRESS))     { return(GetpValue(item)); }        /*==================================================*/   /* An integer is a valid argument if it corresponds */   /* to the fact index of an existing fact.           */   /*==================================================*/   #if DEFTEMPLATE_CONSTRUCT   else if (GetpType(item) == INTEGER)     {      if ((ptr = (VOID *) FindIndexedFact(DOPToLong(item))) == NULL)        {         char tempBuffer[20];         sprintf(tempBuffer,"f-%ld",DOPToLong(item));         CantFindItemErrorMessage("fact",tempBuffer);        }      return(ptr);     }#endif   /*================================================*/   /* Instance names and symbols are valid arguments */   /* if they correspond to an existing instance.    */   /*================================================*/   #if OBJECT_SYSTEM   else if ((GetpType(item) == INSTANCE_NAME) || (GetpType(item) == SYMBOL))     {      if ((ptr = (VOID *) FindInstanceBySymbol((SYMBOL_HN *) GetpValue(item))) == NULL)        {         CantFindItemErrorMessage("instance",ValueToString(GetpValue(item)));        }      return(ptr);     }#endif   /*========================================*/   /* Any other type is an invalid argument. */   /*========================================*/      ExpectedTypeError2(functionName,1);   return(NULL);  }#endif /* DEBUGGING_FUNCTIONS */#endif /* DEFRULE_CONSTRUCT && LOGICAL_DEPENDENCIES */

⌨️ 快捷键说明

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