Example #1
0
globle int FocusCommand(
  void *theEnv)
  {
   DATA_OBJECT argPtr;
   char *argument;
   struct defmodule *theModule;
   int argCount, i;

   /*=====================================================*/
   /* Check for the correct number and type of arguments. */
   /*=====================================================*/

   if ((argCount = EnvArgCountCheck(theEnv,"focus",AT_LEAST,1)) == -1)
     { return(FALSE); }

   /*===========================================*/
   /* Focus on the specified defrule module(s). */
   /*===========================================*/

   for (i = argCount; i > 0; i--)
     {
      if (EnvArgTypeCheck(theEnv,"focus",i,SYMBOL,&argPtr) == FALSE)
        { return(FALSE); }

      argument = DOToString(argPtr);
      theModule = (struct defmodule *) EnvFindDefmodule(theEnv,argument);

      if (theModule == NULL)
        {
         CantFindItemErrorMessage(theEnv,"defmodule",argument);
         return(FALSE);
        }

      EnvFocus(theEnv,(void *) theModule);
     }

   /*===================================================*/
   /* Return TRUE to indicate success of focus command. */
   /*===================================================*/

   return(TRUE);
  }
Example #2
0
static struct activation *NextActivationToFire(
  void *theEnv)
  {
   struct activation *theActivation;
   struct defmodule *theModule;

   /*====================================*/
   /* If there is no current focus, then */
   /* focus on the MAIN module.          */
   /*====================================*/

   if (EngineData(theEnv)->CurrentFocus == NULL)
     {
      theModule = (struct defmodule *) EnvFindDefmodule(theEnv,"MAIN");
      EnvFocus(theEnv,theModule);
     }

   /*===========================================================*/
   /* Determine the top activation on the agenda of the current */
   /* focus. If the current focus has no activations on its     */
   /* agenda, then pop the focus off the focus stack until      */
   /* a focus that has an activation on its agenda is found.    */
   /*===========================================================*/

   theActivation = EngineData(theEnv)->CurrentFocus->theDefruleModule->agenda;
   while ((theActivation == NULL) && (EngineData(theEnv)->CurrentFocus != NULL))
     {
      if (EngineData(theEnv)->CurrentFocus != NULL) EnvPopFocus(theEnv);
      if (EngineData(theEnv)->CurrentFocus != NULL) theActivation = EngineData(theEnv)->CurrentFocus->theDefruleModule->agenda;
     }

   /*=========================================*/
   /* Return the next activation to be fired. */
   /*=========================================*/

   return(theActivation);
  }
Example #3
0
globle void AddActivation(
    void *theEnv,
    void *vTheRule,
    void *vBinds)
{
    struct activation *newActivation;
    struct defrule *theRule = (struct defrule *) vTheRule;
    struct partialMatch *binds = (struct partialMatch *) vBinds;
    struct defruleModule *theModuleItem;
    struct salienceGroup *theGroup;

    /*=======================================*/
    /* Focus on the module if the activation */
    /* is from an auto-focus rule.           */
    /*=======================================*/

    if (theRule->autoFocus)
    {
        EnvFocus(theEnv,(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(theEnv,activation);
    newActivation->theRule = theRule;
    newActivation->basis = binds;
    newActivation->timetag = AgendaData(theEnv)->CurrentTimetag++;
    newActivation->salience = EvaluateSalience(theEnv,theRule);

    newActivation->randomID = genrand();
    newActivation->prev = NULL;
    newActivation->next = NULL;

    AgendaData(theEnv)->NumberOfActivations++;

    /*=======================================================*/
    /* Point the partial match to the activation to complete */
    /* the link between the join network and the agenda.     */
    /*=======================================================*/

    binds->marker = (void *) newActivation;

    /*====================================================*/
    /* If activations are being watch, display a message. */
    /*====================================================*/

#if DEBUGGING_FUNCTIONS
    if (newActivation->theRule->watchActivation)
    {
        EnvPrintRouter(theEnv,WTRACE,(char*)"==> Activation ");
        PrintActivation(theEnv,WTRACE,(void *) newActivation);
        EnvPrintRouter(theEnv,WTRACE,(char*)"\n");
    }
#endif

    /*=====================================*/
    /* Place the activation on the agenda. */
    /*=====================================*/

    theModuleItem = (struct defruleModule *) theRule->header.whichModule;

    theGroup = ReuseOrCreateSalienceGroup(theEnv,theModuleItem,newActivation->salience);

    PlaceActivation(theEnv,&(theModuleItem->agenda),newActivation,theGroup);
}