dlvhex



The Action Plugin and Action Addon Framework



  • DLVHEX with Action Atoms: The Project
    1. Introduction
    2. Installation
    3. Action Atom Function
    4. How to write your own action addon
    5. Building the Action Addons
    6. Examples
  • The Team
  • Download
    1. Action Plugin
    2. Action Addons
    3. Action Addon Template
  • Publications


  • DLV-HEX with Action Atoms: The Project


    Introduction

    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).

    the above can be seen as a rule for scheduling a movement of a given robot indirection D with execution order T. Action atoms are executed according to execution schedules. The latter in turn depend on answer sets, which in their generalized form, can contain action atoms. The order of execution within a schedule can be specified using a precedence attribute (which in the above rule is set by the variable T); also actions can be associated with weights and priority levels (the values 2 and 1 above). Weights and levels are used for computing a cost function which helps in selecting preferred actions, as defined here. Action atoms allow to specify whether they have to be eAction atoms allow to specify whether they have to be executed bravely (the b switch above), cautiously or preferred cautiously, respectively meaning that an action atom a can get executed if it appears in at least one, all, or all best cost answer sets.

    Specific action can be programmed the action addon framework. An action addon is a shared library that provides all the facilities for realising custom action executions.

    If you designed a nice action addon, tell us.

    Installation

    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.

    The Action Atom Function

    Formally, an action atom is executed depending on the following parameters:
    • Input list
    • Action option
    • Action precedence
    • Action weight
    • Action level
    For instance, the action atom to control a toy robot has this form:

     #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.

    Types of Input Parameters

    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.

    How to write your own action addon

    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:

    If action atom was installed correctly, this header should be available.

    The Action Atom Function

    We have to subclass ActionAddonAtom to create our own ROBOTatom class:

         class ROBOTatom : public ActionAddonAtom
         {
    

    Registering the Atoms

    So far, we described the implementation of a specific action atom. In order to integrate one or more atoms in the interface framework, the addon author needs to subclass ActionAddonInterface:

         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:

    Importing the Action Addon

    To make the action addon available, we need to instantiate it. The simplest way to do this is to define a global variable:

         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!

    Building the Action Addons

    We provide a template toolkit for building action addons based on the GNU Autotools (http://sourceware.org/autobook/) environment. This means that you will need the respective tools installed on your system - which is usually no problem, since they are provided as packages by all major linux distributions. For instance in Debian, you need the packages libtool, automake1.9, and autoconf.

    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.

    Examples

  • An Example of Observe-Think-Act Cycle with ActHex Programs
  • An Example of Update to a Web Source After Reasoning Under ASP Semantics



  • Team


  • Selen Basol
  • Ozan Erdem
  • Michael Fink
  • Giovambattista Ianni



  • Download


  • Action Plugin download

  • Action Addons
    1. Robot Action Addon: info download
    2. KBMod Action Addon: info download
    3. GCal Action Addon: info download

  • A template for building your Action Addons download



  • Publications



    [1] S. Basol, O. Erdem, M. Fink, G. Ianni, "Hex Programs with Action Atoms", Twenty-sixth International Conference on Logic Programming (ICLP 2010), submitted. [PDF]



    last edited 2010-02-10