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

📄 constrnt.c

📁 NASA 开发使用的一个专家系统
💻 C
📖 第 1 页 / 共 2 页
字号:
   /*******************************************************/   /*      "C" Language Integrated Production System      */   /*                                                     */   /*             CLIPS Version 6.05  04/09/97            */   /*                                                     */   /*                 CONSTRAINT MODULE                   */   /*******************************************************//*************************************************************//* Purpose: Provides functions for creating and removing     *//*   constraint records, adding them to the contraint hash   *//*   table, and enabling and disabling static and dynamic    *//*   constraint checking.                                    *//*                                                           *//* Principal Programmer(s):                                  *//*      Gary D. Riley                                        *//*                                                           *//* Contributing Programmer(s):                               *//*      Brian Donnell                                        *//*                                                           *//* Revision History:                                         *//*                                                           *//*************************************************************/#define _CONSTRNT_SOURCE_#include <stdio.h>#define _CLIPS_STDIO_#if ANSI_COMPILER#include <stdlib.h>#endif#include "setup.h"#include "constant.h"#include "clipsmem.h"#include "router.h"#include "extnfunc.h"#include "scanner.h"#include "multifld.h"#include "constrnt.h"#include "argacces.h"/***************************************//* LOCAL INTERNAL FUNCTION DEFINITIONS *//***************************************/#if ANSI_COMPILER#if (! RUN_TIME) && (! BLOAD_ONLY)   static VOID                     InstallConstraintRecord(CONSTRAINT_RECORD *);   static int                      ConstraintCompare(struct constraintRecord *,struct constraintRecord *);#endif#if (! RUN_TIME)   static VOID                     ReturnConstraintRecord(CONSTRAINT_RECORD *);   static VOID                     DeinstallConstraintRecord(CONSTRAINT_RECORD *);#endif#else#if (! RUN_TIME) && (! BLOAD_ONLY)   static VOID                     InstallConstraintRecord();   static int                      ConstraintCompare();#endif#if (! RUN_TIME)   static VOID                     ReturnConstraintRecord();   static VOID                     DeinstallConstraintRecord();#endif#endif/****************************************//* GLOBAL INTERNAL VARIABLE DEFINITIONS *//****************************************/   globle struct constraintRecord   **ConstraintHashtable;   /***************************************//* LOCAL INTERNAL VARIABLE DEFINITIONS *//***************************************/    static BOOLEAN                     StaticConstraintChecking = CLIPS_TRUE;   static BOOLEAN                     DynamicConstraintChecking = CLIPS_FALSE;/*****************************************************//* InitializeConstraints: Initializes the constraint *//*   hash table to NULL and defines the static and   *//*   dynamic constraint access functions.            *//*****************************************************/globle VOID InitializeConstraints()   {#if (! RUN_TIME) && (! BLOAD_ONLY)    int i;        ConstraintHashtable = (struct constraintRecord **)                           gm2((int) sizeof (struct constraintRecord *) *                                     SIZE_CONSTRAINT_HASH);    if (ConstraintHashtable == NULL) ExitCLIPS(1);    for (i = 0; i < SIZE_CONSTRAINT_HASH; i++) ConstraintHashtable[i] = NULL;#endif#if (! RUN_TIME)       DefineFunction2("get-dynamic-constraint-checking",'b',GDCCommand,"GDCCommand", "00");   DefineFunction2("set-dynamic-constraint-checking",'b',SDCCommand,"SDCCommand", "11");      DefineFunction2("get-static-constraint-checking",'b',GSCCommand,"GSCCommand", "00");   DefineFunction2("set-static-constraint-checking",'b',SSCCommand,"SSCCommand", "11");#endif  }#if (! RUN_TIME)/*************************************************************//* ReturnConstraintRecord: Frees the data structures used by *//*   a constraint record. If the returnOnlyFields argument   *//*   is FALSE, then the constraint record is also freed.     *//*************************************************************/static VOID ReturnConstraintRecord(constraints)  CONSTRAINT_RECORD *constraints;  {       if (constraints == NULL) return;      if (constraints->bucket < 0)     {      ReturnExpression(constraints->restrictionList);      ReturnExpression(constraints->maxValue);      ReturnExpression(constraints->minValue);      ReturnExpression(constraints->minFields);      ReturnExpression(constraints->maxFields);     }        ReturnConstraintRecord(constraints->multifield);       rtn_struct(constraintRecord,constraints);  }/***************************************************//* DeinstallConstraintRecord: Decrements the count *//*   values of all occurrences of primitive data   *//*   types found in a constraint record.           *//***************************************************/static VOID DeinstallConstraintRecord(constraints)  CONSTRAINT_RECORD *constraints;  {      if (constraints->bucket >= 0)     {      RemoveHashedExpression(constraints->restrictionList);      RemoveHashedExpression(constraints->maxValue);      RemoveHashedExpression(constraints->minValue);      RemoveHashedExpression(constraints->minFields);      RemoveHashedExpression(constraints->maxFields);     }   else     {      ExpressionDeinstall(constraints->restrictionList);      ExpressionDeinstall(constraints->maxValue);      ExpressionDeinstall(constraints->minValue);      ExpressionDeinstall(constraints->minFields);      ExpressionDeinstall(constraints->maxFields);     }        if (constraints->multifield != NULL)                                  { DeinstallConstraintRecord(constraints->multifield); }  }/******************************************//* RemoveConstraint: Removes a constraint *//*   from the constraint hash table.      *//******************************************/globle VOID RemoveConstraint(theConstraint)  struct constraintRecord *theConstraint;  {   struct constraintRecord *tmpPtr, *prevPtr = NULL;   if (theConstraint == NULL) return;      /*========================================*/   /* If the bucket value is less than zero, */   /* then the constraint wasn't stored in   */   /* the hash table.                        */   /*========================================*/      if (theConstraint->bucket < 0)     {      ReturnConstraintRecord(theConstraint);      return;     }      /*================================*/   /* Find and remove the constraint */   /* from the contraint hash table. */   /*================================*/      tmpPtr = ConstraintHashtable[theConstraint->bucket];   while (tmpPtr != NULL)     {      if (tmpPtr == theConstraint)        {         theConstraint->count--;         if (theConstraint->count == 0)           {            if (prevPtr == NULL)               { ConstraintHashtable[theConstraint->bucket] = theConstraint->next; }            else              { prevPtr->next = theConstraint->next; }            DeinstallConstraintRecord(theConstraint);            ReturnConstraintRecord(theConstraint);           }         return;        }              prevPtr = tmpPtr;      tmpPtr = tmpPtr->next;     }        return;  }  #endif /* (! RUN_TIME) */  #if (! RUN_TIME) && (! BLOAD_ONLY)    /***********************************//* HashConstraint: Returns a hash  *//*   value for a given constraint. *//***********************************/globle int HashConstraint(theConstraint)  struct constraintRecord *theConstraint;  {   int i = 0;   unsigned int count = 0;   int hashValue;   struct expr *tmpPtr;   count +=             (theConstraint->anyAllowed * 17) +      (theConstraint->symbolsAllowed * 5) +      (theConstraint->stringsAllowed * 23) +      (theConstraint->floatsAllowed * 19) +      (theConstraint->integersAllowed * 29) +      (theConstraint->instanceNamesAllowed * 31) +      (theConstraint->instanceAddressesAllowed * 17);         count +=      (theConstraint->externalAddressesAllowed * 29) +      (theConstraint->multifieldsAllowed * 29) +      (theConstraint->factAddressesAllowed * 79) +      (theConstraint->anyRestriction * 59) +      (theConstraint->symbolRestriction * 61);   count +=      (theConstraint->stringRestriction * 3) +      (theConstraint->floatRestriction * 37) +      (theConstraint->integerRestriction * 9) +      (theConstraint->instanceNameRestriction * 7);      for (tmpPtr = theConstraint->restrictionList; tmpPtr != NULL; tmpPtr = tmpPtr->nextArg)     { count += GetAtomicHashValue(tmpPtr->type,tmpPtr->value,i++); }        for (tmpPtr = theConstraint->minValue; tmpPtr != NULL; tmpPtr = tmpPtr->nextArg)     { count += GetAtomicHashValue(tmpPtr->type,tmpPtr->value,i++); }        for (tmpPtr = theConstraint->maxValue; tmpPtr != NULL; tmpPtr = tmpPtr->nextArg)     { count += GetAtomicHashValue(tmpPtr->type,tmpPtr->value,i++); }        for (tmpPtr = theConstraint->minFields; tmpPtr != NULL; tmpPtr = tmpPtr->nextArg)     { count += GetAtomicHashValue(tmpPtr->type,tmpPtr->value,i++); }        for (tmpPtr = theConstraint->maxFields; tmpPtr != NULL; tmpPtr = tmpPtr->nextArg)     { count += GetAtomicHashValue(tmpPtr->type,tmpPtr->value,i++); }      if (theConstraint->multifield != NULL)                { count += HashConstraint(theConstraint->multifield); }        hashValue = (int) (count % SIZE_CONSTRAINT_HASH);   if (hashValue < 0) hashValue = - hashValue;   return(hashValue);  }  

⌨️ 快捷键说明

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