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 library 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 organizations. For further information about DLV, please refer to the DLVSystem Ltd. home page.

Download

Latest release version

To use the specialized library for DLV on Android, an AAR file has been released.
To use the specialized library for clingo on desktop, a JAR file has been released.
You can download their last stable versions 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

Connect4 is an application that allows a user to play the popular Connect Four game (also known as Four-in-a-Row) against an ASP-based artificial player.
The Connect Four game is played by two opponents on a vertical 7*6 rectangular board. At each turn, the players fill the board by dropping 1 disk into one of the column so that it falls from the top to the lowest unoccupied position in the column. The winner is the first player who gets four of her disks in a line, connected either horizontally, vertically, or diagonally.

Different AIs have been implemented, ranging from the most powerful one implementing advanced techniques for the perfect play to the simplest one relying on some classical heuristic strategies. By using EmbASP, two different versions of the same app have been built: one for Android, making use of DLV, and one for Java-enabled desktop platforms, making use of clingo.

Developers
  • Marco Anastasio
  • The EmbASP Team

Javadoc

The Javadoc documentation is available here.
For an offline usage, you can download it here.

Class Diagram

A complete UML Class Diagram is available here.

Getting Started

How to import the framework on Android Studio

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

  1. Import the framework module:
    1. Download the framework last released module.
    2. In the project view, right-click on your project New > Module.
    3. Select Import .JAR/.AAR Package.
    4. Select the directory in which the module has been downloaded.
  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.

Using EmbASP

In the following, we describe an the actual usage of the framework by means of a running example; as a use case, we will develop a simple Android application for solving Sudoku puzzles. Hereafter, we explain the crucial stepts, while the complete code is freely available here.
The framework features a annotation-guided mapping, offered by the ASPMapper component, for two-way translations between strings recognizable by ASP solvers and objects in the programming language at hand, directly employable within applications. By means of this feature, the ASP-based aspects can be separated from the Java coding: the programmer doesn't even necessarily need to be aware of ASP.
Let us think of a user that designed (or has been given) a proper logic program P to solve a sudoku puzzle and has also an initial schema. We assume that the initial schema is well-formed i.e. the complete schema solution exists and is unique. A possible program P is embedded in the complete example (here), that, coupled with a set of facts F representing the given initial schema, allows to obtain the only admissible solution.
By means of the annotation-guided mapping, the initial schema can be expressed in forms of Java objects. To this extent, we define the class Cell, aimed at representing the single cell of the sudoku schema, as follows:

    @Predicate("cell")
    public class Cell {
    
        @Term(0)
        private int row;
        
        @Term(1)
        private int column;
        
        @Term(2)
        private int value;
        
        [...]
        
    }           
                
It is worth noticing how the class has been annotated by two custom annotations, defined according to the following syntax:
  • @Predicate(string_name): the target must be a class, and defines the predicate name the class is mapped to;
  • @Term(integer_position): the target must be a field of a class annotated via @Predicate, and defines the term (and its position) in the ASP atom the field is mapped to.
Thanks to these annotations the ASPMapper class will be able to map Cell objects into strings properly recognizable from the ASP solver as logic facts of the form cell(Row,Column,Value). At this point, we can create an Android Activity Component, and start deploying our sudoku application:

    public class MainActivity extends AppCompatActivity {
	
        [...]
        private Handler handler;
    
        @Override
        protected void onCreate(Bundle bundle) {
            handler = new AndroidHandler(getApplicationContext(), DLVAndroidService.class);
            [...]
        }
        
        public void onClick(final View view){
            startReasoning();
            [...]
        }
    
        public void startReasoning() {
            InputProgram inputProgram = new InputProgram();
            for (int i = 0; i < 9; i++){
                for (int j = 0; j < 9; j++)
                    try {
                        if(sudokuMatrix[i][j]!=0) {
                            inputProgram.addObjectInput(new Cell(i, j, sudokuMatrix[i][j]));
                        }
                    } catch (Exception e) {	
                    	// Handle Exception 
                    }
            }
            handler.addProgram(inputProgram);
    
            String sudokuEncoding = getEncodingFromResources();			
            handler.addProgram(new InputProgram(sudokuEncoding));
    
            Callback callback = new MyCallback();
            handler.startAsync(callback);
        }
    }
            
The class contains an Handler instance as field, that is initialized when the Activity is created as an AndroidHandler. Required parameters include the Android Context (an Android utility, needed to start an Android Service Component) and the type of AndroidService to use, in our case a DLVAndroidService.
In addiction, in order to represent an initial sudoku schema, the class features a matrix of integers as another field where position (i,j) contains the value of cell (i,j) in the initial schema; cells initially empty are represented by positions containing zero.
The method startReasoning is in charge of actually managing the reasoning: in our case, it is invoked in response to a click event that is generated when the user asks for the solution. It is firstly created an InputProgram object that is filled with Cell objects representing the initial schema, which is then provided to the handler; then it is provided with the sudoku encoding. It could be loaded, for instance, by means of an utility function that retrieves it from the Android Resources folder, which, within Android applications, is typically meant for containing images, sounds, files and resources in general.
At this point, the reasoning process can start; since for Android we provide only the asynchronous execution mode, a callback object is in charge of fetching the output when the ASP system has done.
Finally, once the computation is over, from within the callback function the output can be retrieved directly in form of Java objects. For instance, in our case an inner class MyCallback implements the interface Callback:

    private class MyCallback implements Callback {

        @Override
        public void callback(Output o) {
            if(!(o instanceof AnswerSets))
                return;
            AnswerSets answerSets=(AnswerSets)o;
            if(answerSets.getAnswersets().isEmpty())
                return;
            AnswerSet as = answerSets.getAnswersets().get(0);
            try {
                for(Object obj:as.getAtoms()) {
                    Cell cell = (Cell) obj;
                    sudokuMatrix[cell.getRow()][cell.getColumn()] = cell.getValue();
                }
            } catch (Exception e) {
                // Handle Exception
            }
            displaySolution();
        }
    }
		

Publications

  • Francesco Calimeri, Davide Fuscà, Stefano Germano, Simona Perri and Jessica Zangari.
    Boosting the Development of ASP-based Applications in Mobile and General Scenarios
    To appear at The 15th International Conference of the Italian Association for Artificial Intelligence (AI*IA 2016).
  • Davide Fuscà, Stefano Germano, Jessica Zangari, Marco Anastasio, Francesco Calimeri and Simona Perri.
    A Framework for Easing the Development of Applications Embedding Answer Set Programming
    In Proceedings of the 18th International Symposium on Principles and Practice of Declarative Programming (PPDP 2016).
    [ paper] [slides]
  • Francesco Calimeri, Davide Fuscà, Stefano Germano, Simona Perri and Jessica Zangari.
    Embedding ASP in mobile systems: discussion and preliminary implementations
    In (online) Procedings of the 8th Workshop on Answer Set Programming and Other Computing Paradigms (ASPOCP 2015).
    [ paper] [slides]