The purpose of this tutorial is to teachyou how to create a functional Domain class from scratch using the Grid World domain as an example. Though building a custom domain will have many differences, the code contained in this domain can be adapted for any discrete grid based domain.
To begin, we'll simply create a basic class with includes, constant definitions, and a blank main that we'll complete later in the tutorial.
package domain.fourrooms; import java.util.List; import java.util.Map; import oomdptb.oomdp.Action; import oomdptb.oomdp.Attribute; import oomdptb.oomdp.Domain; import oomdptb.oomdp.DomainGenerator; import oomdptb.oomdp.ObjectClass; import oomdptb.oomdp.ObjectInstance; import oomdptb.oomdp.PropositionalFunction; import oomdptb.oomdp.State; import oomdptb.oomdp.explorer.TerminalExplorer; import oomdptb.oomdp.explorer.VisualExplorer; import oomdptb.oomdp.visualizer.Visualizer; public class FourRoomsDomain implements DomainGenerator { //Constants public static final String ATTX = "x"; public static final String ATTY = "y"; public static final String CLASSAGENT = "agent"; public static final String CLASSGOAL = "goal"; public static final String ACTIONNORTH = "north"; public static final String ACTIONSOUTH = "south"; public static final String ACTIONEAST = "east"; public static final String ACTIONWEST = "west"; public static final String PFATGOAL = "atGoal"; public static final int MAXX = 12; public static final int MAXY = 12; public static int[][] MAP; public static Domain DOMAIN = null; public static void main(String[] args) { //We'll fill this in later } }
Because most functions in the OOMDP library take string references to the names of the individual elements as parameters, it is very helpful to define these names as constants beforehand. Specifically, we are defining constants for the following elements:
ATTX/ATTY
These are the coordinates that will be used to define the positions of the agent and goal objects.
CLASSAGENT/CLASSGOAL
These are the names of the classes that will be used to define our agent and goal location.
ACTIONNORTH/ACTIONSOUTH/ACTIONEAST/ACTIONWEST
These are the name of the four actions (one for each cardinal direction) that the agent can execute.
PFATGOAL
This is the name of the propositional function that determines whether the agent is inside the goal.
MAXX/MAXY
These constants are unrelated to the previous constants and instead define the dimensions of the 2D grid.
MAP
This two dimensional array will define where the impassable walls will be locate in the domain.
DOMAIN
This is simply a reference to the Domain object that will be instantiated and returned by the generateDomain() method.