?? rulecom.c
字號:
/*******************************************************/ /* "C" Language Integrated Production System */ /* */ /* CLIPS Version 6.30 10/19/06 */ /* */ /* RULE COMMANDS MODULE */ /*******************************************************//*************************************************************//* Purpose: Provides the matches command. Also provides the *//* the developer commands show-joins and rule-complexity. *//* Also provides the initialization routine which *//* registers rule commands found in other modules. *//* *//* Principal Programmer(s): *//* Gary D. Riley *//* *//* Contributing Programmer(s): *//* *//* Revision History: *//* *//* 6.24: Removed CONFLICT_RESOLUTION_STRATEGIES *//* INCREMENTAL_RESET, and LOGICAL_DEPENDENCIES *//* compilation flags. *//* *//* Renamed BOOLEAN macro type to intBool. *//* *//* 6.30: Added support for hashed alpha memories. *//* *//* Added matches-count function. *//* *//* Added get-join-hashing and set-join-hashing *//* functions. *//* *//*************************************************************/#define _RULECOM_SOURCE_#include <stdio.h>#define _STDIO_INCLUDED_#include <string.h>#include "setup.h"#if DEFRULE_CONSTRUCT#include "argacces.h"#include "constant.h"#include "constrct.h"#include "crstrtgy.h"#include "engine.h"#include "envrnmnt.h"#include "evaluatn.h"#include "extnfunc.h"#include "incrrset.h"#include "lgcldpnd.h"#include "memalloc.h"#include "pattern.h"#include "reteutil.h"#include "router.h"#include "ruledlt.h"#include "sysdep.h"#include "watch.h"#if BLOAD || BLOAD_AND_BSAVE || BLOAD_ONLY#include "rulebin.h"#endif#include "rulecom.h"/***************************************//* LOCAL INTERNAL FUNCTION DEFINITIONS *//***************************************/#if DEVELOPER static void ShowJoins(void *,void *);#endif static int ListAlphaMatches(void *,struct joinNode *,int); static int ListBetaMatches(void *,struct joinNode *,int); static int ListBetaJoinActivity(void *,struct joinNode *,int,long long *,int); static void PrintMatchesMemory(void *,struct joinNode *,struct betaMemory *,int,int); /****************************************************************//* DefruleCommands: Initializes defrule commands and functions. *//****************************************************************/globle void DefruleCommands( void *theEnv) {#if ! RUN_TIME EnvDefineFunction2(theEnv,"run",'v', PTIEF RunCommand,"RunCommand", "*1i"); EnvDefineFunction2(theEnv,"halt",'v', PTIEF HaltCommand,"HaltCommand","00"); EnvDefineFunction2(theEnv,"focus",'b', PTIEF FocusCommand,"FocusCommand", "1*w"); EnvDefineFunction2(theEnv,"clear-focus-stack",'v',PTIEF ClearFocusStackCommand, "ClearFocusStackCommand","00"); EnvDefineFunction2(theEnv,"get-focus-stack",'m',PTIEF GetFocusStackFunction, "GetFocusStackFunction","00"); EnvDefineFunction2(theEnv,"pop-focus",'w',PTIEF PopFocusFunction, "PopFocusFunction","00"); EnvDefineFunction2(theEnv,"get-focus",'w',PTIEF GetFocusFunction, "GetFocusFunction","00");#if DEBUGGING_FUNCTIONS EnvDefineFunction2(theEnv,"set-break",'v', PTIEF SetBreakCommand, "SetBreakCommand","11w"); EnvDefineFunction2(theEnv,"remove-break",'v', PTIEF RemoveBreakCommand, "RemoveBreakCommand", "*1w"); EnvDefineFunction2(theEnv,"show-breaks",'v', PTIEF ShowBreaksCommand, "ShowBreaksCommand", "01w"); EnvDefineFunction2(theEnv,"matches",'v',PTIEF MatchesCommand,"MatchesCommand","11w"); EnvDefineFunction2(theEnv,"join-activity",'g',PTIEF JoinActivityCommand,"JoinActivityCommand","11w"); EnvDefineFunction2(theEnv,"matches-count",'v',PTIEF MatchesCountCommand,"MatchesCountCommand","11w"); EnvDefineFunction2(theEnv,"list-focus-stack",'v', PTIEF ListFocusStackCommand, "ListFocusStackCommand", "00"); EnvDefineFunction2(theEnv,"dependencies", 'v', PTIEF DependenciesCommand, "DependenciesCommand", "11h"); EnvDefineFunction2(theEnv,"dependents", 'v', PTIEF DependentsCommand, "DependentsCommand", "11h"); EnvDefineFunction2(theEnv,"timetag", 'g', PTIEF TimetagFunction, "TimetagFunction", "11h");#endif /* DEBUGGING_FUNCTIONS */ EnvDefineFunction2(theEnv,"get-incremental-reset",'b', GetIncrementalResetCommand,"GetIncrementalResetCommand","00"); EnvDefineFunction2(theEnv,"set-incremental-reset",'b', SetIncrementalResetCommand,"SetIncrementalResetCommand","11"); EnvDefineFunction2(theEnv,"get-beta-memory-resizing",'b', GetBetaMemoryResizingCommand,"GetBetaMemoryResizingCommand","00"); EnvDefineFunction2(theEnv,"set-beta-memory-resizing",'b', SetBetaMemoryResizingCommand,"SetBetaMemoryResizingCommand","11"); EnvDefineFunction2(theEnv,"get-strategy", 'w', PTIEF GetStrategyCommand, "GetStrategyCommand", "00"); EnvDefineFunction2(theEnv,"set-strategy", 'w', PTIEF SetStrategyCommand, "SetStrategyCommand", "11w");#if DEVELOPER && (! BLOAD_ONLY) EnvDefineFunction2(theEnv,"rule-complexity",'l', PTIEF RuleComplexityCommand,"RuleComplexityCommand", "11w"); EnvDefineFunction2(theEnv,"show-joins", 'v', PTIEF ShowJoinsCommand, "ShowJoinsCommand", "11w"); EnvDefineFunction2(theEnv,"show-aht", 'v', PTIEF ShowAlphaHashTable, "ShowAlphaHashTable", "00");#if DEBUGGING_FUNCTIONS AddWatchItem(theEnv,"rule-analysis",0,&DefruleData(theEnv)->WatchRuleAnalysis,0,NULL,NULL);#endif#endif /* DEVELOPER && (! BLOAD_ONLY) */#else#if MAC_MCW || IBM_MCW || MAC_XCD#pragma unused(theEnv)#endif#endif /* ! RUN_TIME */ }/***********************************************//* EnvGetBetaMemoryResizing: C access routine *//* for the get-beta-memory-resizing command. *//***********************************************/globle intBool EnvGetBetaMemoryResizing( void *theEnv) { return(DefruleData(theEnv)->BetaMemoryResizingFlag); }/***********************************************//* EnvSetBetaMemoryResizing: C access routine *//* for the set-beta-memory-resizing command. *//***********************************************/globle intBool EnvSetBetaMemoryResizing( void *theEnv, int value) { int ov; ov = DefruleData(theEnv)->BetaMemoryResizingFlag; DefruleData(theEnv)->BetaMemoryResizingFlag = value; return(ov); }/****************************************************//* SetBetaMemoryResizingCommand: H/L access routine *//* for the set-beta-memory-resizing command. *//****************************************************/globle int SetBetaMemoryResizingCommand( void *theEnv) { int oldValue; DATA_OBJECT argPtr; oldValue = EnvGetBetaMemoryResizing(theEnv); /*============================================*/ /* Check for the correct number of arguments. */ /*============================================*/ if (EnvArgCountCheck(theEnv,"set-beta-memory-resizing",EXACTLY,1) == -1) { return(oldValue); } /*=================================================*/ /* The symbol FALSE disables beta memory resizing. */ /* Any other value enables beta memory resizing. */ /*=================================================*/ EnvRtnUnknown(theEnv,1,&argPtr); if ((argPtr.value == EnvFalseSymbol(theEnv)) && (argPtr.type == SYMBOL)) { EnvSetBetaMemoryResizing(theEnv,FALSE); } else { EnvSetBetaMemoryResizing(theEnv,TRUE); } /*=======================*/ /* Return the old value. */ /*=======================*/ return(oldValue); }/****************************************************//* GetBetaMemoryResizingCommand: H/L access routine *//* for the get-beta-memory-resizing command. *//****************************************************/globle int GetBetaMemoryResizingCommand( void *theEnv) { int oldValue; oldValue = EnvGetBetaMemoryResizing(theEnv); if (EnvArgCountCheck(theEnv,"get-beta-memory-resizing",EXACTLY,0) == -1) { return(oldValue); } return(oldValue); }#if DEBUGGING_FUNCTIONS/****************************************//* MatchesCommand: H/L access routine *//* for the matches command. *//****************************************/globle void MatchesCommand( void *theEnv) { char *ruleName; void *rulePtr; ruleName = GetConstructName(theEnv,"matches","rule name"); if (ruleName == NULL) return; rulePtr = EnvFindDefrule(theEnv,ruleName); if (rulePtr == NULL) { CantFindItemErrorMessage(theEnv,"defrule",ruleName); return; } EnvMatches(theEnv,rulePtr); }/********************************//* EnvMatches: C access routine *//* for the matches command. *//********************************/globle intBool EnvMatches( void *theEnv, void *theRule) { struct defrule *rulePtr, *tmpPtr; struct joinNode *lastJoin; ACTIVATION *agendaPtr; int flag; /*=================================================*/ /* Loop through each of the disjuncts for the rule */ /*=================================================*/ for (rulePtr = (struct defrule *) theRule, tmpPtr = rulePtr; rulePtr != NULL; rulePtr = rulePtr->disjunct) { /*======================================*/ /* Determine the last join in the rule. */ /*======================================*/ lastJoin = rulePtr->lastJoin; /*========================================*/ /* List the alpha memory partial matches. */ /*========================================*/ ListAlphaMatches(theEnv,lastJoin->lastLevel,0); /*=======================================*/ /* List the beta memory partial matches. */ /*=======================================*/ ListBetaMatches(theEnv,lastJoin,1); } /*===================*/ /* List activations. */ /*===================*/ rulePtr = tmpPtr; EnvPrintRouter(theEnv,WDISPLAY,"Activations\n"); flag = 1; for (agendaPtr = (struct activation *) EnvGetNextActivation(theEnv,NULL); agendaPtr != NULL; agendaPtr = (struct activation *) EnvGetNextActivation(theEnv,agendaPtr)) { if (GetHaltExecution(theEnv) == TRUE) return(TRUE); if (((struct activation *) agendaPtr)->theRule->header.name == rulePtr->header.name) { flag = 0; PrintPartialMatch(theEnv,WDISPLAY,GetActivationBasis(agendaPtr)); EnvPrintRouter(theEnv,WDISPLAY,"\n"); } } if (flag) EnvPrintRouter(theEnv,WDISPLAY," None\n"); return(TRUE); }/*********************//* ListAlphaMatches: *//*********************/static int ListAlphaMatches( void *theEnv, struct joinNode *theJoin, int priorPatterns) { struct alphaMemoryHash *listOfHashNodes; struct partialMatch *listOfMatches; int flag; if (theJoin == NULL) { return(priorPatterns); } if (theJoin->rightSideEntryStructure == NULL) { priorPatterns++; EnvPrintRouter(theEnv,WDISPLAY,"Matches for Pattern ");
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -