Agents can be configured by using the arg in
the XML run files. Any such tags are passed to the
init()
method through a
MicaProperties object. An example of a complex
snippet of a MicaRunner XML file that shows an agent that takes multiple
parameters is shown in figure Figure 4.3.
These can be accessed through the methods of the
MicaProperties
class. Note that multiple
parameters with different values are allowed; in this case to load
different files into MicaBot.
<agent class="unsw.cse.framescript.mica.MicaBot"> <arg param="file" value="scripts/system_mica.frs"/> <arg param="file" value="scripts/numbers.frs"/> <arg param="topic" value="all"/> <arg param="init" value="init"/> <debug level="information"/> </agent>
Figure 4.3. A MicaRunner XML file snippet with complex arguments
Also note that the MicaRunner file supports a
home element so that you can choose the directory
that MICA is installed in. This is if you want to run agents in another
directory. The MICA home directory is used for several purposes, namely
to load data from config/type
folder related to
types (the LearnerAgent also uses the
config/learntask
folder to load learning tasks).
The data
folder from the mica home directory is
also used to store temporary objects, like blackboard data files, or
learnt concepts.
The current implementation of MICA uses types that are read in
at the beginning of the blackboard's execution. Future versions are
likely to allow types and inheritance to be defined dynamically. But
for now, on startup, any xml files in the type directory (normally
config/type
) are read in to define the hierarchy.
Figure 4.4 shows a typical type definition file,
for the problem of defining a hierarchy of shapes.
<typedesc> <mobdecl name="object"/> <mobdecl name="shape"> <parent name="object"/> </mobdecl> <mobdecl name="polygon"> <parent name="shape"/> </mobdecl> <mobdecl name="rectangle"> <parent name="shape"/> </mobdecl> <mobdecl name="circle"> <parent name="shape"/> </mobdecl> <mobdecl name="square"> <parent name="rectangle"/> <parent name="polygon"/> </mobdecl> </typedesc>
Figure 4.4. shapes.xml
As can be seen, each type declaration consists of a description
of a mob, and then its parents. For example,
circle
inherits from
shape
, and square
inherits from both rectangle
and
polygon
. If a type is to be defined as
transient, simply add the attribute
persistence="transient"
to the declaration. For
example, to make all the types in the above example transient, define
the object type as <mobdecl name="object"
persistence="transient" />
.
The MICA query system takes advantages of the storage mechanism used by MICA. MICA uses HSQLDB as a database store in which it places all of the MICA objects. MICA's query language takes advantage of the HSQL interface. Without going in to too much detail, MICA objects reside in a SQL table with three columns: the name of the object, the type of the object and the object itself.
To use the MICA Query language, normal SQL has been enhanced
with the following functions that are applicable to mobs. They closely
mirror the methods that are available to the
unsw.cse.mica.data.Mob
class.
typeof(mob, 'type')
allows you to
check the type of an object. This mthod returns a
boolean.
hasslot(mob, 'slotName')
allows
you to check whether a mob has a particular slot or not.
getslot1(mob, 'slotName')
gets
the first value of a slot. It returns a string. There are two
further versions of this method,
getslot1asint
and
getslot1asdbl
to get the first value in
a slot as an integer and double respectively.
getslotn(mob,'slotName',pos)
is a
useful method for getting arbitrary information from a
multi-valued slot.
contains(mob, 'slotName',
'value')
allows you to check whether a mob has a
particular value stored somewhere in a multi-valued slot.
In order to use the system, consider the following examples that actually occur in the MICA codebase.
To get all mobs from the blackboard, you can use:
select * from mobs
To get all mobs of a particular type from the blackboard (including subtypes) you could use:
select * from mobs where typeof(mob, 'sharedPadObject')
This would retrieve all sharedPadObjects (sharedPadLines, sharedPadRectangles, etc) from the blackboard.
To get Mobs in a particular order, you can use the "order by" command, for example
select * from mobs where typeOf(mob, 'sharedPadObject') order by getSlot1(mob, 'creationTime')
"asc" and "desc" could be appended to get things in ascending or descending order, respectively.
If we wanted the most recent sharedPadObject, this could be achieved as follows:
select top 1 * from mobs where typeof(mob, 'sharedPadObject') order by getslot1(mob, 'creationTime') desc
If we wanted to find a mob with particular properties, this could be tested, for example, as follows:
select * from mobs where contains(mob, 'creator', 'myAgentName')
The same thing could be accomplished using
select * from mobs where getslot1(mob, 'creator') = 'myAgentName'
(assuming, of course, that the 'creator' slot is single-valued).