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

📄 agenda.c

📁 NASA 开发使用的一个专家系统
💻 C
📖 第 1 页 / 共 3 页
字号:
   /*******************************************************/   /*      "C" Language Integrated Production System      */   /*                                                     */   /*             CLIPS Version 6.05  04/09/97            */   /*                                                     */   /*                    AGENDA MODULE                    */   /*******************************************************//*************************************************************//* Purpose:                                                  *//*   Provides functionality for examining, manipulating,     *//*   adding, and removing activations from the agenda.       *//*                                                           *//* Principal Programmer(s):                                  *//*      Gary D. Riley                                        *//*                                                           *//* Contributing Programmer(s):                               *//*      Brian L. Donnell                                     *//*                                                           *//* Revision History:                                         *//*                                                           *//*************************************************************/#define _AGENDA_SOURCE_#include <stdio.h>#define _CLIPS_STDIO_#include <string.h>#include "setup.h"#if DEFRULE_CONSTRUCT#include "constant.h"#include "clipsmem.h"#include "sysdep.h"#include "router.h"#include "strngrtr.h"#include "reteutil.h"#include "retract.h"#include "extnfunc.h"#include "argacces.h"#include "crstrtgy.h"#include "watch.h"#include "moduldef.h"#include "engine.h"#include "rulebsc.h"#include "ruledef.h"#include "modulutl.h"#include "agenda.h"/***************************************//* LOCAL INTERNAL FUNCTION DEFINITIONS *//***************************************/#if ANSI_COMPILER   static VOID                    PrintActivation(char *,VOID *);   static VOID                    AgendaClearFunction(VOID);#if DYNAMIC_SALIENCE   static char                   *SalienceEvaluationName(int);   static int                     EvaluateSalience(VOID *);#endif#else   static VOID                    PrintActivation();   static VOID                    AgendaClearFunction();#if DYNAMIC_SALIENCE   static char                   *SalienceEvaluationName();   static int                     EvaluateSalience();#endif#endif   /****************************************//* GLOBAL INTERNAL VARIABLE DEFINITIONS *//****************************************/#if DEBUGGING_FUNCTIONS   globle BOOLEAN              WatchActivations = OFF;#endif/***************************************//* LOCAL INTERNAL VARIABLE DEFINITIONS *//***************************************/   static long int             NumberOfActivations = 0;   static unsigned long int    CurrentTimetag = 0;   static int                  AgendaChanged = CLIPS_FALSE;#if DYNAMIC_SALIENCE   static BOOLEAN              SalienceEvaluation = WHEN_DEFINED;#endif/************************************************************//* InitializeAgenda: Initializes the activations watch item *//*   and the CLIPS commands for manipulating the agenda.    *//************************************************************/globle VOID InitializeAgenda()  {   AddClearFunction("agenda",AgendaClearFunction,0);#if DEBUGGING_FUNCTIONS   AddWatchItem("activations",1,&WatchActivations,40,DefruleWatchAccess,DefruleWatchPrint);#endif#if ! RUN_TIME   DefineFunction2("refresh", 'v', PTIF RefreshCommand, "RefreshCommand", "11w");#if DYNAMIC_SALIENCE   DefineFunction2("refresh-agenda",'v',                   PTIF RefreshAgendaCommand,"RefreshAgendaCommand", "01w");   DefineFunction2("get-salience-evaluation",'w',                   PTIF GetSalienceEvaluationCommand,                   "GetSalienceEvaluationCommand", "00");   DefineFunction2("set-salience-evaluation",'w',                   PTIF SetSalienceEvaluationCommand,                   "SetSalienceEvaluationCommand",                   "11w");#endif#if DEBUGGING_FUNCTIONS      DefineFunction2("agenda", 'v', PTIF AgendaCommand, "AgendaCommand", "01w");#endif#endif  }/*****************************************************************//* AddActivation: Creates a rule activation to be added to the   *//*   Agenda and links the activation with its associated partial *//*   match. The function PlaceActivation is then called to place *//*   the activation on the Agenda. Typically called when all     *//*   patterns on the LHS of a rule have been satisfied.          *//*****************************************************************/globle VOID AddActivation(vTheRule,vBinds)  VOID *vTheRule;  VOID *vBinds;  {   struct activation *newActivation;   struct defrule *theRule = (struct defrule *) vTheRule;   struct partialMatch *binds = (struct partialMatch *) vBinds;   struct defruleModule *theModuleItem;      /*=======================================*/   /* Focus on the module if the activation */   /* is from an auto-focus rule.           */   /*=======================================*/      if (theRule->autoFocus)     { Focus((VOID *) theRule->header.whichModule->theModule); }        /*=======================================================*/   /* Create the activation. The activation stores pointers */   /* to its associated partial match and defrule. The      */   /* activation is given a time tag, its salience is       */   /* evaluated, and it is assigned a random number for use */   /* with the random conflict resolution strategy.         */   /*=======================================================*/   newActivation = get_struct(activation);   newActivation->theRule = theRule;   newActivation->basis = binds;   newActivation->timetag = CurrentTimetag++;#if DYNAMIC_SALIENCE   newActivation->salience = EvaluateSalience(theRule);#else   newActivation->salience = theRule->salience;#endif#if CONFLICT_RESOLUTION_STRATEGIES   newActivation->sortedBasis = NULL;   newActivation->randomID = genrand();#endif   newActivation->prev = NULL;   newActivation->next = NULL;   NumberOfActivations++;   /*=======================================================*/   /* Point the partial match to the activation to complete */   /* the link between the join network and the agenda.     */   /*=======================================================*/   binds->binds[binds->bcount].gm.theValue = (VOID *) newActivation;   /*====================================================*/   /* If activations are being watch, display a message. */   /*====================================================*/#if DEBUGGING_FUNCTIONS   if (newActivation->theRule->watchActivation)     {      PrintCLIPS(WTRACE,"==> Activation ");      PrintActivation(WTRACE,(VOID *) newActivation);      PrintCLIPS(WTRACE,"\n");     }#endif    /*=====================================*/    /* Place the activation on the agenda. */    /*=====================================*/    theModuleItem = (struct defruleModule *) theRule->header.whichModule;    PlaceActivation(&(theModuleItem->agenda),newActivation);   }/***************************************************************//* ClearRuleFromAgenda: Clears the agenda of a specified rule. *//***************************************************************/globle VOID ClearRuleFromAgenda(vTheRule)  VOID *vTheRule;  {   struct defrule *theRule = (struct defrule *) vTheRule;   struct defrule *tempRule;   struct activation *agendaPtr, *agendaNext;   /*============================================*/   /* Get a pointer to the agenda for the module */   /* in which the rule is contained.            */   /*============================================*/      agendaPtr = ((struct defruleModule *) theRule->header.whichModule)->agenda;   /*==============================================*/   /* Loop through every activation on the agenda. */   /*==============================================*/   while (agendaPtr != NULL)     {      agendaNext = agendaPtr->next;            /*========================================================*/      /* Check each disjunct of the rule against the activation */      /* to determine if the activation points to the rule. If  */      /* it does, then remove the activation from the agenda.   */      /*========================================================*/            for (tempRule = theRule;            tempRule != NULL;           tempRule = tempRule->disjunct)        {         if (agendaPtr->theRule == tempRule)           {             RemoveActivation(agendaPtr,CLIPS_TRUE,CLIPS_TRUE);            break;           }        }              agendaPtr = agendaNext;     }  }/********************************************************************//* GetNextActivation: Returns an activation from the Agenda. If its *//*   argument is NULL, then the first activation on the Agenda      *//*   is returned. If its argument is not NULL, the next activation  *//*   after the argument is returned.                                *//********************************************************************/globle VOID *GetNextActivation(actPtr)  VOID *actPtr;  {   struct defruleModule *theModuleItem;      if (actPtr == NULL)     {      theModuleItem = (struct defruleModule *) GetModuleItem(NULL,DefruleModuleIndex);      if (theModuleItem == NULL) return(NULL);      return((VOID *) theModuleItem->agenda);     }   else     { return((VOID *) (((struct activation *) actPtr)->next)); }  }/**********************************************************************************//* GetActivationName: Returns the name of the rule associated with an activation. *//**********************************************************************************/globle char *GetActivationName(actPtr)  VOID *actPtr;  { return(ValueToString(((struct activation *) actPtr)->theRule->header.name)); }/********************************************************************//* SetActivationSalience: Sets the salience value of an activation. *//********************************************************************/globle int SetActivationSalience(actPtr,value)  VOID *actPtr;  int value;  {   int temp;   temp = ((struct activation *) actPtr)->salience;   ((struct activation *) actPtr)->salience = value;   return(temp);  }/**********************************************************************************//* GetActivationPPForm: Returns the pretty print representation of an activation. *//**********************************************************************************/globle VOID GetActivationPPForm(buffer,bufferLength,theActivation)  char *buffer;  int bufferLength;  VOID *theActivation;  {   OpenStringDestination("ActPPForm",buffer,bufferLength);   PrintActivation("ActPPForm",(VOID *) theActivation);   CloseStringDestination("ActPPForm");  }/********************************************//* MoveActivationToTop: Moves the specified *//*   activation to the top of the agenda.   *//********************************************/globle BOOLEAN MoveActivationToTop(vtheActivation)  VOID *vtheActivation;  {   struct activation *prevPtr;   struct activation *theActivation = (struct activation *) vtheActivation;   struct defruleModule *theModuleItem;   /*====================================*/   /* Determine the module of the agenda */    /* in which the activation is stored. */   /*====================================*/      theModuleItem = (struct defruleModule *) theActivation->theRule->header.whichModule;         /*============================================*/   /* If the activation is already at the top of */   /* the agenda, then nothing needs to be done. */   /*============================================*/      if (theActivation == theModuleItem->agenda) return(CLIPS_FALSE);   /*=================================================*/   /* Update the pointers of the activation preceding */   /* and following the activation being moved.       */   /*=================================================*/      prevPtr = theActivation->prev;   prevPtr->next = theActivation->next;   if (theActivation->next != NULL) theActivation->next->prev = prevPtr;   /*=======================================================*/   /* Move the activation and then update its pointers, the */   /* pointers of the activation following it, and the      */   /* module pointer to the top activation on the agenda.   */   /*=======================================================*/      theActivation->next = theModuleItem->agenda;   theModuleItem->agenda->prev = theActivation;   theActivation->prev = NULL;   theModuleItem->agenda = theActivation;   /*=============================*/   /* Mark the agenda as changed. */   /*=============================*/      AgendaChanged = CLIPS_TRUE;      return(CLIPS_TRUE);  }/******************************************************//* DeleteActivation: Removes the specified activation *//*   from the agenda.                                 *//******************************************************/globle BOOLEAN DeleteActivation(theActivation)  VOID *theActivation;  {   if (theActivation == NULL) RemoveAllActivations();   else RemoveActivation((struct activation *) theActivation,CLIPS_TRUE,CLIPS_TRUE);   return(CLIPS_TRUE);  }  /*******************************************************//* DetachActivation: Detaches the specified activation *//*   from the list of activations on the Agenda.       *//*******************************************************/globle BOOLEAN DetachActivation(vTheActivation)  VOID *vTheActivation;  {   struct defruleModule *theModuleItem;   struct activation *theActivation = (struct activation *) vTheActivation;      /*============================*/   /* A NULL pointer is invalid. */   /*============================*/      if (theActivation == NULL) CLIPSSystemError("AGENDA",1);      /*====================================*/   /* Determine the module of the agenda */ 

⌨️ 快捷键说明

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