Declaring WMEs

From ABL
Revision as of 10:14, 28 July 2006 by Dbueno (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Introduction

There are two ways to declary working memory elements. First of all, in a Java file on their own. Each class implements exactly one WME. Secondly, ABL provides a way to declare WMEs inside a abl file. We cover both options.

A working memory element (WME) is simply a field-oriented data structure used principally for stashing data. When ABL senses the environment through the Sensory Motor Architecture, information about the environment is stored in WMEs. As such, each WME must follow the JavaBeans standard. Basically, if you just create a class that extends wm.WME and only contains the following elements, you should be good to go:

  1. fields;
  2. a constructor to set those fields;
  3. and synchronised getters and setters for each field

Standalone

  1. Create a class that extends wm.WME.
  2. Add as many fields as you want.
  3. (Add accessors.)
    1. For each boolean field named languid of type T, add an accessor, public synchronized boolean isLanguid().
    2. For each field of a type other than boolean named languid, add an accessor, public synchronized T getLanguid().
    3. For each field named languid of type T, add a setter public synchronized setLanguid(T t).

Example

package utsm.sensors;

import wm.WME;

public class ObjectPositionWME extends WME {
   private String objectID;
   private double x;
   private double y;
   private double z;

   public ObjectPositionWME(String objectID, double x, double y, double z) {
      this.objectID = objectID;
      this.x = x;
      this.y = y;
      this.z = z;
   }

    public ObjectPositionWME() {}

    public synchronized String getObjectID() { return objectID; }
    public synchronized double getX() { return x; }
    public synchronized double getY() { return y; }
    public synchronized double getZ() { return z; }

    public synchronized void setObjectID(String objectID) { this.objectID = objectID; }
    public synchronized void setX(double x) { this.x = x; }
    public synchronized void setY(double y) { this.y = y; }
    public synchronized void setZ(double z) { this.z = z; }

}

Inline

ABL provides a way to declare WMEs inside a .abl file. WMEs declared within a behaving entity are defined within the behaving entity's package, making it difficult to use a WME declared in this fashion within multiple behaving entities. Thus, declaring WMEs inside a .abl file is most useful for defining WMEs that are only used within a single behaving entity. The syntax is<ref>See ABL Language Grammar for the entire ABL grammar.</ref>:

InlineWME ::= wme Identifier [ extends ( Identifier )+ ] {

    ( Field )+

}

Example

wme Strings {
    String a;
    String b;
}

wme MoreStuff extends Strings {
    String c;
}

In Context

behaving_entity Jack
{
    conflict pathplan pathplan; ...
    register action jump() with Jump; ...
    register wme AgentPositionWME with AgentPositionSensor; ...

    wme StringTestWME {
        // Empty fields crashes compiler.
        String field;
    }
...
}