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

📄 constrnt.c

📁 NASA 开发使用的一个专家系统
💻 C
📖 第 1 页 / 共 2 页
字号:
/**********************************************//* ConstraintCompare: Compares two constraint *//*   records and returns TRUE if they are     *//*   identical, otherwise FALSE.              *//**********************************************/static int ConstraintCompare(constraint1,constraint2)  struct constraintRecord *constraint1, *constraint2;  {   struct expr *tmpPtr1, *tmpPtr2;      if ((constraint1->anyAllowed != constraint2->anyAllowed) ||       (constraint1->symbolsAllowed != constraint2->symbolsAllowed) ||       (constraint1->stringsAllowed != constraint2->stringsAllowed) ||       (constraint1->floatsAllowed != constraint2->floatsAllowed) ||       (constraint1->integersAllowed != constraint2->integersAllowed) ||       (constraint1->instanceNamesAllowed != constraint2->instanceNamesAllowed) ||       (constraint1->instanceAddressesAllowed != constraint2->instanceAddressesAllowed) ||       (constraint1->externalAddressesAllowed != constraint2->externalAddressesAllowed) ||       (constraint1->multifieldsAllowed != constraint2->multifieldsAllowed) ||       (constraint1->singlefieldsAllowed != constraint2->singlefieldsAllowed) ||        (constraint1->factAddressesAllowed != constraint2->factAddressesAllowed) ||       (constraint1->anyRestriction != constraint2->anyRestriction) ||       (constraint1->symbolRestriction != constraint2->symbolRestriction) ||       (constraint1->stringRestriction != constraint2->stringRestriction) ||       (constraint1->floatRestriction != constraint2->floatRestriction) ||       (constraint1->integerRestriction != constraint2->integerRestriction) ||       (constraint1->instanceNameRestriction != constraint2->instanceNameRestriction))     { return(CLIPS_FALSE); }   for (tmpPtr1 = constraint1->restrictionList, tmpPtr2 = constraint2->restrictionList;        (tmpPtr1 != NULL) && (tmpPtr2 != NULL);         tmpPtr1 = tmpPtr1->nextArg, tmpPtr2 = tmpPtr2->nextArg)     {       if ((tmpPtr1->type != tmpPtr2->type) || (tmpPtr1->value != tmpPtr2->value))        { return(CLIPS_FALSE); }     }   if (tmpPtr1 != tmpPtr2) return(CLIPS_FALSE);   for (tmpPtr1 = constraint1->minValue, tmpPtr2 = constraint2->minValue;        (tmpPtr1 != NULL) && (tmpPtr2 != NULL);         tmpPtr1 = tmpPtr1->nextArg, tmpPtr2 = tmpPtr2->nextArg)     {       if ((tmpPtr1->type != tmpPtr2->type) || (tmpPtr1->value != tmpPtr2->value))        { return(CLIPS_FALSE); }     }   if (tmpPtr1 != tmpPtr2) return(CLIPS_FALSE);         for (tmpPtr1 = constraint1->maxValue, tmpPtr2 = constraint2->maxValue;        (tmpPtr1 != NULL) && (tmpPtr2 != NULL);         tmpPtr1 = tmpPtr1->nextArg, tmpPtr2 = tmpPtr2->nextArg)     {       if ((tmpPtr1->type != tmpPtr2->type) || (tmpPtr1->value != tmpPtr2->value))        { return(CLIPS_FALSE); }     }   if (tmpPtr1 != tmpPtr2) return(CLIPS_FALSE);           for (tmpPtr1 = constraint1->minFields, tmpPtr2 = constraint2->minFields;        (tmpPtr1 != NULL) && (tmpPtr2 != NULL);         tmpPtr1 = tmpPtr1->nextArg, tmpPtr2 = tmpPtr2->nextArg)     {       if ((tmpPtr1->type != tmpPtr2->type) || (tmpPtr1->value != tmpPtr2->value))        { return(CLIPS_FALSE); }     }   if (tmpPtr1 != tmpPtr2) return(CLIPS_FALSE);         for (tmpPtr1 = constraint1->maxFields, tmpPtr2 = constraint2->maxFields;        (tmpPtr1 != NULL) && (tmpPtr2 != NULL);         tmpPtr1 = tmpPtr1->nextArg, tmpPtr2 = tmpPtr2->nextArg)     {       if ((tmpPtr1->type != tmpPtr2->type) || (tmpPtr1->value != tmpPtr2->value))        { return(CLIPS_FALSE); }     }   if (tmpPtr1 != tmpPtr2) return(CLIPS_FALSE);   if (((constraint1->multifield == NULL) && (constraint2->multifield != NULL)) ||       ((constraint1->multifield != NULL) && (constraint2->multifield == NULL)))     { return(CLIPS_FALSE); }   else if (constraint1->multifield == constraint2->multifield)     { return(CLIPS_TRUE); }        return(ConstraintCompare(constraint1->multifield,constraint2->multifield));  }  /************************************//* AddConstraint: Adds a constraint *//*   to the constraint hash table.  *//************************************/globle struct constraintRecord *AddConstraint(theConstraint)  struct constraintRecord *theConstraint;  {   struct constraintRecord *tmpPtr;   int hashValue;   if (theConstraint == NULL) return(NULL);      hashValue = HashConstraint(theConstraint);   for (tmpPtr = ConstraintHashtable[hashValue];        tmpPtr != NULL;        tmpPtr = tmpPtr->next)     {      if (ConstraintCompare(theConstraint,tmpPtr))         {         tmpPtr->count++;         ReturnConstraintRecord(theConstraint);         return(tmpPtr);        }     }        InstallConstraintRecord(theConstraint);   theConstraint->count = 1;   theConstraint->bucket = hashValue;   theConstraint->next = ConstraintHashtable[hashValue];   ConstraintHashtable[hashValue] = theConstraint;   return(theConstraint);  }/*************************************************//* InstallConstraintRecord: Increments the count *//*   values of all occurrences of primitive data *//*   types found in a constraint record.         *//*************************************************/static VOID InstallConstraintRecord(constraints)  CONSTRAINT_RECORD *constraints;  {       struct expr *tempExpr;      tempExpr = AddHashedExpression(constraints->restrictionList);   ReturnExpression(constraints->restrictionList);   constraints->restrictionList = tempExpr;      tempExpr = AddHashedExpression(constraints->maxValue);   ReturnExpression(constraints->maxValue);   constraints->maxValue = tempExpr;      tempExpr = AddHashedExpression(constraints->minValue);   ReturnExpression(constraints->minValue);   constraints->minValue = tempExpr;      tempExpr = AddHashedExpression(constraints->minFields);   ReturnExpression(constraints->minFields);   constraints->minFields = tempExpr;      tempExpr = AddHashedExpression(constraints->maxFields);   ReturnExpression(constraints->maxFields);   constraints->maxFields = tempExpr;      if (constraints->multifield != NULL)       { InstallConstraintRecord(constraints->multifield); }  }#endif /* (! RUN_TIME) && (! BLOAD_ONLY) */  /**********************************************//* SDCCommand: CLIPS access routine for the   *//*   set-dynamic-constraint-checking command. *//**********************************************/globle int SDCCommand()  {   int oldValue;   DATA_OBJECT arg_ptr;   oldValue = GetDynamicConstraintChecking();   if (ArgCountCheck("set-dynamic-constraint-checking",EXACTLY,1) == -1)     { return(oldValue); }   RtnUnknown(1,&arg_ptr);   if ((arg_ptr.value == CLIPSFalseSymbol) && (arg_ptr.type == SYMBOL))     { SetDynamicConstraintChecking(CLIPS_FALSE); }   else     { SetDynamicConstraintChecking(CLIPS_TRUE); }   return(oldValue);  }/**********************************************//* GDCCommand: CLIPS access routine for the   *//*   get-dynamic-constraint-checking command. *//**********************************************/globle int GDCCommand()  {   int oldValue;   oldValue = GetDynamicConstraintChecking();   if (ArgCountCheck("get-dynamic-constraint-checking",EXACTLY,0) == -1)     { return(oldValue); }   return(oldValue);  }  /*********************************************//* SSCCommand: CLIPS access routine for the  *//*   set-static-constraint-checking command. *//*********************************************/globle int SSCCommand()  {   int oldValue;   DATA_OBJECT arg_ptr;   oldValue = GetStaticConstraintChecking();   if (ArgCountCheck("set-static-constraint-checking",EXACTLY,1) == -1)     { return(oldValue); }   RtnUnknown(1,&arg_ptr);   if ((arg_ptr.value == CLIPSFalseSymbol) && (arg_ptr.type == SYMBOL))     { SetStaticConstraintChecking(CLIPS_FALSE); }   else     { SetStaticConstraintChecking(CLIPS_TRUE); }   return(oldValue);  }/*********************************************//* GSCCommand: CLIPS access routine for the  *//*   get-static-constraint-checking command. *//*********************************************/globle int GSCCommand()  {   int oldValue;   oldValue = GetStaticConstraintChecking();   if (ArgCountCheck("get-static-constraint-checking",EXACTLY,0) == -1)     { return(oldValue); }   return(oldValue);  }  /******************************************************//* SetDynamicConstraintChecking: C access routine for *//*   the set-dynamic-constraint-checking command.     *//******************************************************/globle BOOLEAN SetDynamicConstraintChecking(value)  int value;  {   int ov;   ov = DynamicConstraintChecking;   DynamicConstraintChecking = value;   return(ov);  }/******************************************************//* GetDynamicConstraintChecking: C access routine for *//*   the get-dynamic-constraint-checking command.     *//******************************************************/globle BOOLEAN GetDynamicConstraintChecking()  { return(DynamicConstraintChecking); }  /*****************************************************//* SetStaticConstraintChecking: C access routine for *//*   the set-static-constraint-checking command.     *//*****************************************************/globle BOOLEAN SetStaticConstraintChecking(value)  int value;  {   int ov;   ov = StaticConstraintChecking;   StaticConstraintChecking = value;   return(ov);  }/*****************************************************//* GetStaticConstraintChecking: C access routine for *//*   the get-static-constraint-checking command.     *//*****************************************************/globle BOOLEAN GetStaticConstraintChecking()  { return(StaticConstraintChecking); }    

⌨️ 快捷键说明

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