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

📄 objrtbld.c

📁 一套美国国家宇航局人工智能中心NASA的专家系统工具源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
      return(NULL);     }   if ((tmpNode->bottom == NULL) && (tmpNode->multifieldSlot))     {      PPBackup();      PPBackup();      SavePPBuffer(")");     }   tmpNode->derivedConstraints = 1;        return(tmpNode);  }  /********************************************************  NAME         : NewClassBitMap  DESCRIPTION  : Creates a new bitmap large enough                 to hold all ids of classes in the                 system and initializes all the bits                 to zero or one.  INPUTS       : 1) The maximum id that will be set                    in the bitmap                 2) An integer code indicating if all                    the bits are to be set to zero or one  RETURNS      : The new bitmap  SIDE EFFECTS : BitMap allocated and initialized  NOTES        : None ********************************************************/static CLASS_BITMAP *NewClassBitMap(maxid,set)  int maxid,set;  {   register CLASS_BITMAP *bmp;   int size;      if (maxid == -1)     maxid = 0;   size = (int) (sizeof(CLASS_BITMAP) +                (sizeof(char) * (maxid / BITS_PER_BYTE)));   bmp = (CLASS_BITMAP *) gm2(size);   ClearBitString((VOID *) bmp,size);   bmp->maxid = (unsigned short) maxid;   InitializeClassBitMap(bmp,set);   return(bmp);  }/***********************************************************  NAME         : InitializeClassBitMap  DESCRIPTION  : Initializes a bitmap to all zeroes or ones.  INPUTS       : 1) The bitmap                 2) An integer code indicating if all                    the bits are to be set to zero or one  RETURNS      : Nothing useful  SIDE EFFECTS : The bitmap is initialized  NOTES        : None ***********************************************************/static VOID InitializeClassBitMap(bmp,set)  CLASS_BITMAP *bmp;  int set;  {   register int i,bytes;   DEFCLASS *cls;   struct defmodule *currentModule;      bytes = bmp->maxid / BITS_PER_BYTE + 1;   while (bytes > 0)     {      bmp->map[bytes - 1] = (char) 0;      bytes--;     }   if (set)     {      currentModule = ((struct defmodule *) GetCurrentModule());      for (i = 0 ; i <= (int) bmp->maxid ; i++)        {         cls = ClassIDMap[i];         if ((cls != NULL) ? DefclassInScope(cls,currentModule) : CLIPS_FALSE)           {            if (cls->reactive && (cls->abstract == 0))              SetBitMap(bmp->map,i);           }        }     }  }  /********************************************  NAME         : DeleteIntermediateClassBitMap  DESCRIPTION  : Deallocates a bitmap  INPUTS       : The class set  RETURNS      : Nothing useful  SIDE EFFECTS : Class set deallocated  NOTES        : None ********************************************/static VOID DeleteIntermediateClassBitMap(bmp)  CLASS_BITMAP *bmp;  {   rm((VOID *) bmp,ClassBitMapSize(bmp));  }  /******************************************************  NAME         : CopyClassBitMap  DESCRIPTION  : Increments the in use count of a                 bitmap and returns the same pointer  INPUTS       : The bitmap  RETURNS      : The bitmap  SIDE EFFECTS : Increments the in use count  NOTES        : Class sets are shared by multiple                 copies of an object pattern within an                 OR CE.  The use count prevents having                 to make duplicate copies of the bitmap ******************************************************/static VOID *CopyClassBitMap(gset)  VOID *gset;  {   if (gset != NULL)     IncrementBitMapCount(gset);   return(gset);  }  /**********************************************************  NAME         : DeleteClassBitMap  DESCRIPTION  : Deallocates a bitmap,                 and decrements the busy flags of the                 classes marked in the bitmap  INPUTS       : The bitmap  RETURNS      : Nothing useful  SIDE EFFECTS : Class set deallocated and classes unmarked  NOTES        : None **********************************************************/static VOID DeleteClassBitMap(gset)  VOID *gset;  {      if (gset == NULL)     return;   DecrementBitMapCount(gset);  }/***************************************************  NAME         : MarkBitMapClassesBusy  DESCRIPTION  : Increments/Decrements busy counts                 of all classes marked in a bitmap  INPUTS       : 1) The bitmap hash node                 2) 1 or -1 (to increment or                    decrement class busy counts)  RETURNS      : Nothing useful  SIDE EFFECTS : Bitmap class busy counts updated  NOTES        : None ***************************************************/static VOID MarkBitMapClassesBusy(bmphn,offset)  BITMAP_HN *bmphn;  int offset;  {   register CLASS_BITMAP *bmp;   register unsigned short i;   register DEFCLASS *cls;   /* ====================================      If a clear is in progress, we do not      have to worry about busy counts      ==================================== */   if (ClearInProgress)     return;   bmp = (CLASS_BITMAP *) ValueToBitMap(bmphn);   for (i = 0 ; i <= bmp->maxid ; i++)     if (TestBitMap(bmp->map,i))       {        cls =  ClassIDMap[i];        cls->busy += offset;       }  }   /****************************************************  NAME         : EmptyClassBitMap  DESCRIPTION  : Determines if one or more bits                 are marked in a bitmap  INPUTS       : The bitmap  RETURNS      : CLIPS_TRUE if the set has no bits                 marked, CLIPS_FALSE otherwise  SIDE EFFECTS : None  NOTES        : None ****************************************************/static BOOLEAN EmptyClassBitMap(bmp)  CLASS_BITMAP *bmp;  {   register unsigned short bytes;      bytes = (unsigned short) (bmp->maxid / BITS_PER_BYTE + 1);   while (bytes > 0)     {      if (bmp->map[bytes - 1] != (char) 0)        return(CLIPS_FALSE);      bytes--;     }   return(CLIPS_TRUE);  }/***************************************************  NAME         : IdenticalClassBitMap  DESCRIPTION  : Determines if two bitmaps                 are identical  INPUTS       : 1) First bitmap                 2) Second bitmap  RETURNS      : CLIPS_TRUE if bitmaps are the same,                 CLIPS_FALSE otherwise  SIDE EFFECTS : None  NOTES        : None ***************************************************/static BOOLEAN IdenticalClassBitMap(cs1,cs2)  CLASS_BITMAP *cs1,*cs2;  {   register int i;      if (cs1->maxid != cs2->maxid)     return(CLIPS_FALSE);   for (i = 0 ; i < (int) (cs1->maxid / BITS_PER_BYTE + 1) ; i++)     if (cs1->map[i] != cs2->map[i])       return(CLIPS_FALSE);   return(CLIPS_TRUE);  }  /*****************************************************************  NAME         : ProcessClassRestriction  DESCRIPTION  : Examines a class restriction and forms a bitmap                 corresponding to the maximal set of classes which                 can satisfy a static analysis of the restriction  INPUTS       : 1) The bitmap to mark classes in                 2) The lhsParseNodes of the restriction                 3) A flag indicating if this is the first                    non-recursive call or not  RETURNS      : CLIPS_TRUE if all OK, CLIPS_FALSE otherwise  SIDE EFFECTS : Class bitmap set and lhsParseNodes corressponding                 to constant restrictions are removed  NOTES        : None *****************************************************************/static BOOLEAN ProcessClassRestriction(clsset,classRestrictions,recursiveCall)  CLASS_BITMAP *clsset;  struct lhsParseNode **classRestrictions;  int recursiveCall;  {   register struct lhsParseNode *chk,**oraddr;   CLASS_BITMAP *tmpset1,*tmpset2;   int constant_restriction = CLIPS_TRUE;      if (*classRestrictions == NULL)     {      if (recursiveCall)        InitializeClassBitMap(clsset,1);      return(CLIPS_TRUE);     }   /* ===============================================      Determine the corresponding class set and union      it with the current total class set.  If an AND      restriction is comprised entirely of symbols,      it can be removed      =============================================== */   tmpset1 = NewClassBitMap(((int) MaxClassID) - 1,1);   tmpset2 = NewClassBitMap(((int) MaxClassID) - 1,0);   for  (chk = *classRestrictions ; chk != NULL ; chk = chk->right)     {      if (chk->type == SYMBOL)        {         chk->value = (VOID *) LookupDefclassInScope(ValueToString(chk->value));         if (chk->value == NULL)           {            PrintErrorID("OBJRTBLD",5,CLIPS_FALSE);            PrintCLIPS(WERROR,"Undefined class in object pattern.\n");            DeleteIntermediateClassBitMap(tmpset1);            DeleteIntermediateClassBitMap(tmpset2);            return(CLIPS_FALSE);           }         if (chk->negated)           {            InitializeClassBitMap(tmpset2,1);            MarkBitMapSubclasses(tmpset2->map,(DEFCLASS *) chk->value,0);           }         else           {            InitializeClassBitMap(tmpset2,0);            MarkBitMapSubclasses(tmpset2->map,(DEFCLASS *) chk->value,1);           }         IntersectClassBitMaps(tmpset1,tmpset2);        }      else        constant_restriction = CLIPS_FALSE;     }   if (EmptyClassBitMap(tmpset1))     {      PrintErrorID("OBJRTBLD",2,CLIPS_FALSE);      PrintCLIPS(WERROR,"No objects of existing classes can satisfy ");      PrintCLIPS(WERROR,"is-a restriction in object pattern.\n");      DeleteIntermediateClassBitMap(tmpset1);      DeleteIntermediateClassBitMap(tmpset2);      return(CLIPS_FALSE);     }   if (constant_restriction)     {      chk = *classRestrictions;      *classRestrictions = chk->bottom;      chk->bottom = NULL;      ReturnLHSParseNodes(chk);      oraddr = classRestrictions;     }   else     oraddr = &(*classRestrictions)->bottom;   UnionClassBitMaps(clsset,tmpset1);   DeleteIntermediateClassBitMap(tmpset1);   DeleteIntermediateClassBitMap(tmpset2);        /* =====================================      Process the next OR class restriction      ===================================== */   return(ProcessClassRestriction(clsset,oraddr,CLIPS_FALSE));  }  /****************************************************************  NAME         : ProcessSlotRestriction  DESCRIPTION  : Determines which slots could match the slot                 pattern and determines the union of all                 constraints for the pattern  INPUTS       : 1) The class set                 2) The slot name                 3) A buffer to hold a flag indicating if                    any multifield slots are found w/ this name  RETURNS      : A union of the constraints on all the slots                 which could match the slots (NULL if no                 slots found)  SIDE EFFECTS : The class bitmap set is marked/cleared  NOTES        : None ****************************************************************/static CONSTRAINT_RECORD *ProcessSlotRestriction(clsset,slotName,multip)  CLASS_BITMAP *clsset;  SYMBOL_HN *slotName;  int *multip;  {   register DEFCLASS *cls;   register int si;   CONSTRAINT_RECORD *totalConstraints = NULL,*tmpConstraints;   register unsigned i;      *multip = CLIPS_FALSE;   for (i = 0 ; i < CLASS_TABLE_HASH_SIZE ; i++)     for (cls = ClassTable[i] ; cls != NULL ; cls = cls->nxtHash)       {        if (TestBitMap(clsset->map,cls->id))          {           si = FindInstanceTemplateSlot(cls,slotName);           if ((si !=

⌨️ 快捷键说明

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