This DLVHEX plugin provides an implementation of the ActHEX language.
The plugin allows external action execution, via the introduction of action atoms, that can appear in rules' head. Intuitively, acthex programs extend hex programs allowing rules like:
#robot[move,D]{b, T}[2 : 1] :- direction(D), time(T).You can access via SVN the current source of the ActionPlugin here. For putting ActHEX programs at work, you will need DLVHEX installed in your system (you can svn co a fresh copy of the sources from here. In turn, DLVHEX will need a series of packages (usually available in most Linux distributions), and a binary of the DLV system. Once the ActionPlugin and DLVHEX are compiled and installed, you will be able to execute your ActHEX programs simply typing dlvhex myprogram from command line. ActionAddons libraries already developed can be found in the Download section
For any issue, you might want to contact our research group at here.
In the next section we introduce the principle of action addons and action atoms and gives a short hands-on example.
#robot[move,left]{b,2}[3:1]
where move stands for a parameter string denoting the type of action,
left stands for a string denoting the direction of the action, b
represents that brave reasoning will be used to determine whether the
action will be executed or not, 2 denotes the action
precedence, 3 and 1 are the action weight and
level.
Input parameters can freely represent constants and predicate names: action functions have full access to the answer set that triggered execution, thus enabling access to relational inferred knowledge.
We wanted to keep the interface between dlvhex, plugin and action addon as lean as possible. The only necessary interaction is registering the action addon and its atoms to the action plugin.
To this end, we provide a base class which the addon author has to subclass. As a running example, we will use the aforementioned Robot-atom. To begin with, the following header file from dlvhex needs to be included:
#include "dlvhex/ActionAddonAtom.h
#include "dlvhex/Error.h"If action atom was installed correctly, this header should be available.
class ROBOTatom : public ActionAddonAtom {
class RobotAddon : public ActionAddonInterface { public:
At the current stage of dlvhex, only the function ActionAddonInterface::getAtoms() needs to be defined inside this class:
virtual void getAtoms(AtomFunctionMap& a) { boost::shared_ptr<ActionAddonAtom> rdf(new ROBOTatom); a["robot"] = robot; }
Here, a ActionAddon-Atom object is related to a string in a map - as soon as
dlvhex encounters an action atom (in this case: #robot)
during the evaluation of answer sets of the program, it finds the corresponding atom
object (and hence its ActionAddonAtom::execute()
function) in this map. Of course, a addon can comprise several
different ActionAddon-Atoms, which are all registered here:
boost::shared_ptr<ActionAddonAtom> assert(new assert_atom); boost::shared_ptr<ActionAddonAtom> retract(new retract_atom); a["assert"] = assert; a["retract"] = retract;
The above registers the two action atoms #assert and #retract:
ROBOTActionAddon theROBOTactionaddon;
Eventually, we need to import the action addon to action plugin. This is achieved by the dynamic linking mechanism of shared libraries. The author needs to define this function,
extern "C" ROBOTactionaddon* PLUGINIMPORTFUNCTION() { theROBOTactionaddon.setActionAddonName(PACKAGE_TARNAME); theROBOTactionaddon.setVersion(ROBOTACTIONADDON_MAJOR, ROBOTACTIONADDON_MINOR, ROBOTACTIONADDON_MICRO); return new ROBOTactionaddon(); }
replacing the type ROBOTActionAddon by her own action addon class. For each found library, action plugin will call this function and receive a pointer to the action addon object, thus being able to call its ActionAddonInterface::getAtoms() function.
The macros used here for setting the version number have their origin in
configure.ac, which is needed to produce the
configure-script .
Of course they can also be hardcoded here, but the method with the
macros from configure.ac is certainly more practical!
After downloading and extracting the toolkit skeleton, the user can customize the top-level configure.ac to her own needs regarding dependencies on other packages. This file contains invocations of the Autoconf macros that test the system features your package needs or can use. There are two source-directory in this template. One is src and other is include, where Makefile.am sets the name of the library and its sourcefiles. The user has to take care of referencing them in the top-level Makefile.am. Calling ./bootstrap in the top-level directory creates the configure file. Subsequently calling ./configure and make install installs the shared library. If no further arguments are given to configure, the addon will be installed into the system-wide plugin-directory (specified by the package configuration file lib/pkgconfig/dlvhex.pc of the devel-package). To install the addon into ~/.dlvhex/plugins, run ./configure --enable-userinstall.
Some sample action addons can be found in Download Section.
last edited 2010-02-10