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

📄 ruledef.c

📁 clips源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
   /*******************************************************/   /*      "C" Language Integrated Production System      */   /*                                                     */   /*             CLIPS Version 6.30  10/19/06            */   /*                                                     */   /*                   DEFRULE MODULE                    */   /*******************************************************//*************************************************************//* Purpose: Defines basic defrule primitive functions such   *//*   as allocating and deallocating, traversing, and finding *//*   defrule data structures.                                *//*                                                           *//* Principal Programmer(s):                                  *//*      Gary D. Riley                                        *//*                                                           *//* Contributing Programmer(s):                               *//*      Brian L. Donnell                                     *//*                                                           *//* Revision History:                                         *//*      6.24: Removed CONFLICT_RESOLUTION_STRATEGIES         *//*            compilation flag.                              *//*                                                           *//*            Renamed BOOLEAN macro type to intBool.         *//*                                                           *//*            Corrected code to remove run-time program      *//*            compiler warnings.                             *//*                                                           *//*      6.30: Added support for hashed alpha memories.       *//*                                                           *//*            Added additional developer statistics to help  *//*            analyze join network performance.              *//*                                                           *//*            Added salience groups to improve performance   *//*            with large numbers of activations of different *//*            saliences.                                     *//*                                                           *//*************************************************************/#define _RULEDEF_SOURCE_#include "setup.h"#if DEFRULE_CONSTRUCT#include <stdio.h>#define _STDIO_INCLUDED_#include "agenda.h"#include "drive.h"#include "engine.h"#include "envrnmnt.h"#include "memalloc.h"#include "pattern.h"#include "retract.h"#include "reteutil.h"#include "rulebsc.h"#include "rulecom.h"#include "rulepsr.h"#include "ruledlt.h"#if BLOAD || BLOAD_AND_BSAVE || BLOAD_ONLY#include "bload.h"#include "rulebin.h"#endif#if CONSTRUCT_COMPILER && (! RUN_TIME)#include "rulecmp.h"#endif#include "ruledef.h"/***************************************//* LOCAL INTERNAL FUNCTION DEFINITIONS *//***************************************/   static void                   *AllocateModule(void *);   static void                    ReturnModule(void *,void *);   static void                    InitializeDefruleModules(void *);   static void                    DeallocateDefruleData(void *);   static void                    DestroyDefruleAction(void *,struct constructHeader *,void *);#if RUN_TIME      static void                    AddBetaMemoriesToRule(void *,struct joinNode *);#endif/**********************************************************//* InitializeDefrules: Initializes the defrule construct. *//**********************************************************/globle void InitializeDefrules(  void *theEnv)  {      unsigned long i;   AllocateEnvironmentData(theEnv,DEFRULE_DATA,sizeof(struct defruleData),DeallocateDefruleData);   InitializeEngine(theEnv);   InitializeAgenda(theEnv);   InitializePatterns(theEnv);   InitializeDefruleModules(theEnv);   AddReservedPatternSymbol(theEnv,"and",NULL);   AddReservedPatternSymbol(theEnv,"not",NULL);   AddReservedPatternSymbol(theEnv,"or",NULL);   AddReservedPatternSymbol(theEnv,"test",NULL);   AddReservedPatternSymbol(theEnv,"logical",NULL);   AddReservedPatternSymbol(theEnv,"exists",NULL);   AddReservedPatternSymbol(theEnv,"forall",NULL);   DefruleBasicCommands(theEnv);   DefruleCommands(theEnv);   DefruleData(theEnv)->DefruleConstruct =      AddConstruct(theEnv,"defrule","defrules",                   ParseDefrule,EnvFindDefrule,                   GetConstructNamePointer,GetConstructPPForm,                   GetConstructModuleItem,EnvGetNextDefrule,SetNextConstruct,                   EnvIsDefruleDeletable,EnvUndefrule,ReturnDefrule);   DefruleData(theEnv)->AlphaMemoryTable = (ALPHA_MEMORY_HASH **)                  gm3(theEnv,sizeof (ALPHA_MEMORY_HASH *) * ALPHA_MEMORY_HASH_SIZE);   for (i = 0; i < ALPHA_MEMORY_HASH_SIZE; i++) DefruleData(theEnv)->AlphaMemoryTable[i] = NULL;   DefruleData(theEnv)->BetaMemoryResizingFlag = TRUE;      DefruleData(theEnv)->RightPrimeJoins = NULL;   DefruleData(theEnv)->LeftPrimeJoins = NULL;     }  /**************************************************//* DeallocateDefruleData: Deallocates environment *//*    data for the defrule construct.             *//**************************************************/static void DeallocateDefruleData(  void *theEnv)  {   struct defruleModule *theModuleItem;   void *theModule;   struct activation *theActivation, *tmpActivation;   struct salienceGroup *theGroup, *tmpGroup;#if BLOAD || BLOAD_AND_BSAVE   if (Bloaded(theEnv))     { return; }#endif      DoForAllConstructs(theEnv,DestroyDefruleAction,DefruleData(theEnv)->DefruleModuleIndex,FALSE,NULL);   for (theModule = EnvGetNextDefmodule(theEnv,NULL);        theModule != NULL;        theModule = EnvGetNextDefmodule(theEnv,theModule))     {      theModuleItem = (struct defruleModule *)                      GetModuleItem(theEnv,(struct defmodule *) theModule,                                    DefruleData(theEnv)->DefruleModuleIndex);                                          theActivation = theModuleItem->agenda;      while (theActivation != NULL)        {         tmpActivation = theActivation->next;                  rtn_struct(theEnv,activation,theActivation);                  theActivation = tmpActivation;        }              theGroup = theModuleItem->groupings;      while (theGroup != NULL)        {         tmpGroup = theGroup->next;                  rtn_struct(theEnv,salienceGroup,theGroup);                  theGroup = tmpGroup;        }        #if ! RUN_TIME                                          rtn_struct(theEnv,defruleModule,theModuleItem);#endif     }           rm3(theEnv,DefruleData(theEnv)->AlphaMemoryTable,sizeof (ALPHA_MEMORY_HASH *) * ALPHA_MEMORY_HASH_SIZE);  }  /********************************************************//* DestroyDefruleAction: Action used to remove defrules *//*   as a result of DestroyEnvironment.                 *//********************************************************/#if IBM_TBC#pragma argsused#endifstatic void DestroyDefruleAction(  void *theEnv,  struct constructHeader *theConstruct,  void *buffer)  {#if MAC_MCW || IBM_MCW || MAC_XCD#pragma unused(buffer)#endif   struct defrule *theDefrule = (struct defrule *) theConstruct;      DestroyDefrule(theEnv,theDefrule);  }/*****************************************************//* InitializeDefruleModules: Initializes the defrule *//*   construct for use with the defmodule construct. *//*****************************************************/static void InitializeDefruleModules(  void *theEnv)  {   DefruleData(theEnv)->DefruleModuleIndex = RegisterModuleItem(theEnv,"defrule",                                    AllocateModule,                                    ReturnModule,#if BLOAD_AND_BSAVE || BLOAD || BLOAD_ONLY                                    BloadDefruleModuleReference,#else                                    NULL,#endif#if CONSTRUCT_COMPILER && (! RUN_TIME)                                    DefruleCModuleReference,#else                                    NULL,#endif                                    EnvFindDefrule);  }

⌨️ 快捷键说明

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