Perceptor

From Agent Factory

Jump to: navigation, search

Contents

Editorial History

18/11/2008 (Version 1): Initial Version of Page

Overview

A Perceptor is a Java class that implements a software sensor for an AFAPL2 agent. That is, perceptors represent the interface through which an agent builds a model of its environment. This model takes the form of a set of beliefs about that environment, where a Belief is a well-formed formula of an extended first-order logic of Commitment. The AFAPL2 Interpreter invokes the agents perceptors at the start of each iteration of its execution cycle, resulting in a initial model of the current state of the environment for that iteration. This model is then augmented via Temporal Beliefs, Belief Rules, and other beliefs that have been added as a result of mental Actions.

A practical example of a perceptor can be found in the Example Alive Application that is provided as part of the Netbeans Plugin. For a more detailed discussion of perceptors, please read the AFAPL2 Programmers Guide.

Writing a Perceptor

A perceptor is a Java class that extends the com.agentfactory.logic.agent.Perceptor abstract base class, and that implements the perceive() method. The example below is taken from the Alive Application, a simple example that is packaged as part of the Netbeans Plugin.

 package perceptor;
 
 import com.agentfactory.logic.agent.Perceptor;
 
 public class Alive extends Perceptor {
 
   public void perceive() {
     adoptBelief("BELIEF(state(alive))");
   }
 }

This example uses the adoptBelief(...) method to add the belief that the agents "state" is "alive" to its belief set.

What support fields / methods are provided?

To support the implementation of the perceive(...) method, a number of helper methods have been provided by the Perceptor base class, these include:

  • getModuleByName(String name): Returns a reference to the Module of the given name.
  • getModuleByClass(String className): Returns a reference to the first Module found with the given class name (this is the String returned by the Class.getName() method).
  • getModulesByClass(String className): Returns an array of references to the all the Modules with the given class name (this is the String returned by the Class.getName() method).
  • adoptBelief(String belief): Adopts the given Belief at the start of the next iteration of the agent interpreter cycle.
  • retractBelief(String belief): Retracts the given Temporal Belief immediately.
  • getService(String id): Returns a reference to the specified Platform Service.
  • getConfiguration(): Returns a reference to a Map containing the current configuration of the actuator.

Finally, the base class also provides a reference to the agent object that the actuator is associated with.

Specifying a Perceptor in AFAPL2

Creating the Java class is only part of the story. For an agent to use the perceptor, it must be declared within the corresponding agent program. Here, we will focus on the AFAPL2 language, but perceptors may also be used in AFAPL or any other logical language that is implemented using Agent Factory.

AFAPL2 programs are written in text files that have a ".afapl2" extension. In this file, perceptors are declared via a PERCEPTOR statement of the form:

 PERCEPTOR alive {
     CLASS perceptor.Alive;
 }

Basically, this statement declares that the agent will have a perceptor called "alive" whose implementation is realised via the perceptor.Alive Java class. The name of the perceptor is kept distinct from the class that implements the perceptor because AFAPL2 supports configurable perceptors (i.e. configurations can be passed into a perceptor, allowing the same implementation to be reused for multiple cases).

Adding a Configuration to a Perceptor

We can implement more configurable perceptors that allow us to configure the state as follows by making use of the configuration feature that is built into AFAPL2. To do this, we need to follow two basic steps:

1. Update the Perceptor Declaration to pass a configuration:

This is done by augmenting the CLASS parameter of the PERCEPTOR statement:

 PERCEPTOR alive {
     CLASS perceptor.Alive {
         state=alive;
     }
 }

2. Modify the Perceptor implementation to make use of the perceptor:

This is done by invoking the getConfiguration() method:

package perceptor;

import com.agentfactory.logic.agent.Perceptor;

public class Alive extends Perceptor {

  public void perceive() {
    adoptBelief("BELIEF(state(" + getConfiguration().get("state") + "))");
  }
}

Now, we can create a second perceptor, say called "dead" that uses the same implementation:

 PERCEPTOR dead {
     CLASS perceptor.Alive {
         state=dead;
     }
 }

For a detailed treatment of perceptors, please read the AFAPL2 Programmers Guide.