Core Team

  • Francesco Calimeri
  • Davide FuscĂ 
  • Stefano Germano
  • Simona Perri
  • Jessica Zangari

Contacts

For further information, contact embasp@mat.unical.it.

License

The framework is released under The MIT License (MIT).

The framework specializations for DLV (such as the one for DLV on Android) embeds the DLV system itself, which is free for academic and non-commercial educational use, as well as for use by non-profit organisations. For further information about DLV please refer to the DLVSystem Ltd. home page.

Download

Latest release version

You can download the last stable release version of EmbASP here.

Development Version GitHub

You can find the current development version here.

Application Showcase

DLVfit is a health and fitness app that monitors the user activity during the day and suggests some workout plans that depend on her age, weight, gender and goals. The app periodically stores some information about the user activities (running, walking, etc.) and infers the current amount of calories burned so far. When the user asks for a workout plan, DLVfit proposes a set of exercises that would allow the user to reach her daily goal, taking into account also to her preferences. The suggested workout plans are computed in the background by DLV via EmbASP.

The ASP program used within DLVfit can be found in the repository. Basically, the program guesses for possible fitness exercises to do in order to burn the remaing calories. Each answer set represent a possible workout plan, in which is ensured that the user's requirements about the calories to burn and the time to spend in the workout are respected. Moreover, also user's preferences are taken into account by means of weak constraints.

Release

You can download the latest version of DLVfit here.

The app should work on most devices equipped with Android 4.x/5.x.
The list of compatible devices include (but it is not limited to):

  • Samsung Galaxy S2 - Android 4.3, API 16
  • HTC One - Android 4.3, API 18
  • HTC One XL - Android 4.2.2, API 17
  • HTC One XL - Android 4.1.1, API 16
  • Samsung Galaxy Note 2 - Android 4.2.2, API 17
  • Google Nexus 7 - Android 4.4.4, API 19
  • Samsung S4 - Android 4.4.4, API 19
  • Samnsung S3 - Android 4.3, API 18
  • Sony Xperia S - Android 4.1.1, API 16
  • Google Nexus 7 - Android 4.3, API 18
  • Sony Xperia Go - Android 4.0
  • Sony Xperia Z3 - Android 5.0
  • Sony Xperia Z3 - Android 5.1
  • Galaxy S6 - Android 5.0
  • Nexus 6 - Android 5.0
Developers
  • Dario Campisano
  • The EmbASP Team

GuessAndCheckers is a native mobile application that works as an helper for users that play "live" games of the (Italian) checkers (i.e., by means of physical board and pieces). The app, that runs on Android, can help a player at any time: by means of the device camera a picture of the board is taken, and the information about the current status of the game is properly inferred thanks to OpenCV, an open source computer vision and machine learning software; an ASP-based artificial intelligence module then suggests the move.

Thanks to EmbASP and the use of ASP, GuessAndCheckers features a fully-declarative approach that made easy to develop and improve several different strategies, also experimenting with many combinations thereof.
The source code of this application along with the Android Application Package (APK) are available online.

Release

You can download the latest version of GuessAndCheckers here.

Developers
  • Vincenzo Arieta
  • The EmbASP Team

DLVEdu is an educational Android App for children, that integrates well-established mobile technologies, such as voice or drawn text recognition, with the modeling capabilities of ASP. In particular, it is able to guide the child throughout the learning tasks, by proposing a series of educational games, and developing a personalized educational path. The games are divided into four macro-areas: Logic, Numeric-Mathematical, Memory, and Verbal Language. The usage of ASP allows the application to adapt to the game experiences fulfilled by the user, her formative gap, and the obtained improvements.

The application continuously profiles the user by recording mistakes and successes, and dynamically builds and updates a customized educational path along the different games. The application features a "Parent Area", that allows parents to monitor child's achievements and to express some preferences, such as explicit filters of some games or educational areas.

Developers
  • Mattia Lanzillotta
  • Mirko Pontoriero
  • The EmbASP Team

Getting Started

How to import the framework on Android Studio

In order to use the framework in your applications you can import it as module on Android Studio.

  1. Import the framework module:
    1. Download the framework last released module.
    2. Extract the downloaded file.
    3. In the project view, right-click on your project New > Module.
    4. Select Import Existing Project.
    5. Select the extracted directory.
  2. Set the dependency:
    1. In the Android Studio menu: File > Project Structure.
    2. Select your project module (by default called app).
    3. In the Dependencies Tab add as Module Dependency the previously imported framework.

Setting up the execution

In the following, we detail the actual usage of the framework by means of a running example. In particular we show how to use the framework to develop a simple mobile app that make use of ASP in order to solve the 3-Colouring problem. This problem asks for a valid assignment of colours to the nodes of a graph: given a graph as set of nodes and edges between them, it is "3-colourable" if to each node can be assigned one among three available colours, in such a way that any two nodes directly linked by an edge cannot have the same colour.

The framework can be invoked adding logic programs as strings and as files:


        ASPHandler handler = new DLVHandler();
        handler.addRawInput("col(N,red) | col(N,green) | col(N,blue) :- node(N).");
        handler.addRawInput(":- col(N1,C1), col(N2,C1), edge(N1,N2).");
        handler.addFileInput("my_edb_file.asp");
        handler.setFilter("col");
        handler.start(theContext, myAnswerSetCallback);
                        

First, we create a new instance of an ASPHandler subclass. Then, the program is added as string input, while "my_edb_file.asp" is a file of input facts, added by its path. In addition, a filter option is set on the predicate "col".

Finally, we start the execution of the solver giving as parameter the Android Context (needed to start the Service) and an object which must be an instance of a class implementing AnswerSetCallback.

The framework allows also to add input using objects:


        Edge edge1 = new Edge("node_1","node_2");
        Edge edge2 = new Edge("node_1","node_3");
        handler.addInput(edge1);
        handler.addInput(edge2);
                        

In order to use this feature, the added objects' classes must be implemented as JavaBeans and properly annotated. Basically, the class Edge can be annotated in this way :


        @Predicate("edge")
        public class Edge {
        @Term(0)
        private String node1;
        @Term(1)
        private String node2;
        .....
        }
                        

Gathering results

Once the solver has been started with the given input, the framework offers different ways to gather its result. First, the user has to write a class implementing AnswerSetCallback, and override the abstract method callback(AnswerSets answerSets). The answer sets found by the solver are contained in an AnswerSets object and one can use this object to analyse each AnswerSet returned by the reasoner. Moreover the user can get an AnswerSet as set of objects, previously annotated using the specific annotations.


            public void callback(AnswerSets answerSets) {
                List<AnswerSet> answerSetList=answerSets.getAnswerSetsList();
                for(AnswerSet answerSet:answerSetList){
                    Set<Object> objSet=answerSet.getAnswerObjects();	
                    ....
                }
            }
                        

In our example of 3-colouring, in order to get back the colours assignment in the form of objects, one can implement a class representing the "col" predicate. In this case, this class will be used to convert the "col" facts in the answer sets as instances of this class; this class can be implemented as follows:


        @Predicate("col")
        public class Col {
        @Term(0)
        private String node;
        @Term(1)
        private String colour;
        .....
        }
                        
In order to notify the framework of the existence of the Col class, the user has to register it, calling the registerClass(Class<?> cl) method of the Singleton class ASPMapper, that notify this class to the ASPMapper. The registration is automatic if the input or the fillter are added using Class objects. The framework in a transparent way will map the answer sets into objects taking care of the parsing of the output string returned by the solver. From this point on, the user can manage the answer sets using plain Java objects as she wish.

Architecture Description

The framework consists of three different layers:

  • The first layer acts like a facade to the user of the framework. It contains all functions needed in order to manage input and output of the ASP solver.
  • The second layer acts as a middleware between the facade and the actual solver, providing the native functions that allow to invoke the solver.
  • The third layer is the actual ASP solver. It also contains the functions to run and make use of it.
Abstract Architecture
Abstract Architecture of the framework. Overshadowed components are related to the specialization for DLV on Android.

The figure shows how the layers interact. It is worth noting that, as for the implementation herein presented, ASPHandler and Solver Handler are totally written in Java, and communicate by means of function calls; in addition, even if the framework can be easily extended in order to handle other ASP solvers, it comes equipped with DLV as default ASP Solver layer. Given that DLV is implemented in C++, the JNI was used in order to let the upper layers communicate with the ASP Solver layer. Basically, the execution works as follows: ASPHandler (asynchronously) calls the Solver Handler, providing it with the logic program and the proper options for the solver; then, Solver Handler starts the ASP Solver, invoking the native functions of the solver with the needed parameters, and then collecting the reasoning results. Eventually, it publishes the results collected by ASPHandler and turn them back to the user via a callback function; this mechanism is better detailed below. The Solver Handler layer is needed in order to handle an Android Service, i.e., a native application component that can perform long-running operations in the background; this allows the application that makes use of EmbASP can asynchronously perform other operations while waiting for the answer from the ASP solver. Furthermore, the use of an Android Service makes the solver type and invocation details transparent to the framework. It is noteworthy that the stratified architecture has been designed in order to be general enough to facilitate the replacement of the ASP Solver layer. Moreover, it can be adapted, with minor changes, to any other Java compliant environment, even much different from Android.

Detailed Description

The framework is composed by an hierarchy of classes that interact as shown in the figure.

Class Diagram
Class Diagram of the framework

The abstract class ASPHandler contains the methods to add input in different ways; in particular, the input can be in the form of simple string, files or Java Objects. It contains also a method to set options for the solver. Since the filter option is a very common one, the framework provides a direct way to add it. Indeed, as for the input, the user can set a filter as string using the predicates names, or as a class object representing classes that are annotated as explained hereafter. In addiction, since it acts like an interface to the users, it also contains the method to let the solver starts the reasoning, so this is the class that has to be extended in order to use the framework with an other solver. However, it comes already equipped with an implementation of this class, that uses DLV as solver, the DLVHandler class. In addition, each concrete class that extends ASPHandler should start a proper ASPService.

The abstract class ASPService manages the invocation of the solver and takes care of the results of its computation. The framework provides a concrete implementation of this class, DLVService, which invokes the DLV solver. The source code of DLV has been built using the Android NDK and the DLV code has been optimized for this particular use case, and is linked to the Java code using the JNI as required by the NDK. The following figure depicts an abstract class diagram of an implementation of EmbASP enhanced with two generic solvers.
Class Diagram
Abstract Class Diagram of the framework with two generic solvers

In order to get back the results obtained by the solver, that is invoked asynchronously, it is needed a callback function, which is automatically called when the computation is terminated. This callback function can be specified implementing the AnswerSetCallback interface.

The answer sets are represented by the class AnswerSets that can be extended in order to parse the specific output of different ASP solvers. While, the concept of answer set is captured by the AnswerSet class.

The framework provides also a mapper able to convert the output string of the solver into Java Objects. This conversion is guided by the annotations of the Java Objects mapped. Indeed, to exploit this functionality, the user has to provides classes with specific annotations and those classes must be implemented as JavaBeans. Basically, there are two types of annotations:

  • @Predicate(String name) specify the predicate name and the target of this annotation must be a class.
  • @Term(Integer position) specify the term position in the atoms (whose predicate name is specified with @Predicate annotation) and the target of this annotation must be a field of a class.

Moreover, the mapping is done also in the other way around, from objects to strings, so that the input can be also specified as plain Java objects.