Embedding ASP in mobile systems: discussion and preliminary - - PowerPoint PPT Presentation

embedding asp in mobile systems discussion and
SMART_READER_LITE
LIVE PREVIEW

Embedding ASP in mobile systems: discussion and preliminary - - PowerPoint PPT Presentation

Introduction The embASP Framework An embASP Specialization DLVfit Related Work Conclusions References Embedding ASP in mobile systems: discussion and preliminary implementation Francesco Calimeri Davide Fusc` a Stefano Germano Simona Perri


slide-1
SLIDE 1

Introduction The embASP Framework An embASP Specialization DLVfit Related Work Conclusions References

Embedding ASP in mobile systems: discussion and preliminary implementation

Francesco Calimeri Davide Fusc` a Stefano Germano Simona Perri Jessica Zangari

Department of Mathematics and Computer Science, University of Calabria, Italy

Workshop on Answer Set Programming and Other Computing Paradigms, 2015

Calimeri, Fusc` a, Germano, Perri, Zangari DeMaCS Embedding ASP in mobile systems

slide-2
SLIDE 2

Introduction The embASP Framework An embASP Specialization DLVfit Related Work Conclusions References

Table of Contents

1

Introduction

2

The embASP Framework

3

An embASP Specialization

4

DLVfit

5

Related Work

6

Conclusions

7

References

Calimeri, Fusc` a, Germano, Perri, Zangari DeMaCS Embedding ASP in mobile systems

slide-3
SLIDE 3

Introduction The embASP Framework An embASP Specialization DLVfit Related Work Conclusions References

Motivation

Ease the use of ASP [GL91, Bar03] in industrial-level and enterprise applications [CR13, LR15] Popularity of “smart”/wearable devices is constantly increasing ICT industry is moving towards the mobile scenario Lack of works about ASP systems natively running on mobile devices

Calimeri, Fusc` a, Germano, Perri, Zangari DeMaCS Embedding ASP in mobile systems

slide-4
SLIDE 4

Introduction The embASP Framework An embASP Specialization DLVfit Related Work Conclusions References

Contribution

embASP: a general framework for the integration of ASP in a mobile setting DLVfit: as a proof of concept, a first ASP-based Android application (actually, a health-app) Freely available at https://www.mat.unical.it/calimeri/projects/embasp/

Calimeri, Fusc` a, Germano, Perri, Zangari DeMaCS Embedding ASP in mobile systems

slide-5
SLIDE 5

Introduction The embASP Framework An embASP Specialization DLVfit Related Work Conclusions References

The embASP Framework

Abstract Architecture

ASPHANDLER SOLVER HANDLER ASP SOLVER

Java Native Interface (JNI)

DLV Android Service

Calimeri, Fusc` a, Germano, Perri, Zangari DeMaCS Embedding ASP in mobile systems

slide-6
SLIDE 6

Introduction The embASP Framework An embASP Specialization DLVfit Related Work Conclusions References

The embASP Framework

Framework implementation

ASP HANDLER SOLVER HANDLER ASP SOLVER

ASPHandler ASPHandler_Solver1 ASPHandler_SolverN

...

ASPService ASPService_Solver1 ASPService_SolverN

...

AnswerSetCallback AnswerSets AnswerSets_Solver1 AnswerSets_SolverN

...

AnswerSet Client Mapper Solver1 SolverN

Calimeri, Fusc` a, Germano, Perri, Zangari DeMaCS Embedding ASP in mobile systems

slide-7
SLIDE 7

Introduction The embASP Framework An embASP Specialization DLVfit Related Work Conclusions References

The embASP Framework

ASPHandler

ASP HANDLER

ASPHandler ASPHandler_Solver1 ASPHandler_SolverN

...

AnswerSetCallback AnswerSets AnswerSets_Solver1 AnswerSets_SolverN

...

AnswerSet Client Mapper

Provides the methods to manipulate input and

  • utput of the solvers

(simple strings, files, Java Objects) Manages settings of all

  • ptions for the actual

ASP solvers Features proper methods for making the reasoning start

Calimeri, Fusc` a, Germano, Perri, Zangari DeMaCS Embedding ASP in mobile systems

slide-8
SLIDE 8

Introduction The embASP Framework An embASP Specialization DLVfit Related Work Conclusions References

The embASP Framework

ASPHandler and Solver Handler interaction

ASP HANDLER SOLVER HANDLER

ASPHandler ASPHandler_Solver1 ASPHandler_SolverN

...

ASPService ASPService_Solver1 ASPService_SolverN

...

AnswerSetCallback AnswerSets AnswerSets_Solver1 AnswerSets_SolverN

...

AnswerSet Client Mapper

The Solver Handler layer manages invocations to the actual ASP solver(s) and gathers the results Asynchronous invocation (by implementing the AnswerSetCallback) Answer Sets are captured and parsed by the AnswerSets class

Calimeri, Fusc` a, Germano, Perri, Zangari DeMaCS Embedding ASP in mobile systems

slide-9
SLIDE 9

Introduction The embASP Framework An embASP Specialization DLVfit Related Work Conclusions References

The embASP Framework

ASPHandler, Solver Handler and ASPSolver interaction

ASP HANDLER SOLVER HANDLER ASP SOLVER

ASPHandler ASPHandler_Solver1 ASPHandler_SolverN

...

ASPService ASPService_Solver1 ASPService_SolverN

...

AnswerSetCallback AnswerSets AnswerSets_Solver1 AnswerSets_SolverN

...

AnswerSet Client Mapper Solver1 SolverN

NOT bounded to a single solver Different solvers can be managed directly within the framework

Calimeri, Fusc` a, Germano, Perri, Zangari DeMaCS Embedding ASP in mobile systems

slide-10
SLIDE 10

Introduction The embASP Framework An embASP Specialization DLVfit Related Work Conclusions References

The embASP Framework

ASPHandler, Solver Handler and ASPSolver interaction

ASP HANDLER SOLVER HANDLER ASP SOLVER

ASPHandler ASPHandler_Solver1 ASPHandler_SolverN

...

ASPService ASPService_Solver1 ASPService_SolverN

...

AnswerSetCallback AnswerSets AnswerSets_Solver1 AnswerSets_SolverN

...

AnswerSet Client Mapper Solver1 SolverN

To add an other solver:

Extend ASPHandler Start a proper ASPService Specialize AnswerSets to deal with the specific

  • utput of the solver

Calimeri, Fusc` a, Germano, Perri, Zangari DeMaCS Embedding ASP in mobile systems

slide-11
SLIDE 11

Introduction The embASP Framework An embASP Specialization DLVfit Related Work Conclusions References

The embASP Framework

The Mapper

Intended to automatically convert

the input for the solver from plain Java Objects into Strings the output of the solvers from Strings into Java Objects

The process is guided by proper annotations:

@Predicate(string name) @Term(integer position)

@Predicate("edge") public class Edge { @Term (0) private String node1; @Term (1) private String node2; ... } Edge e1 = new Edge("n1","n2"); Edge e2 = new Edge("n1","n3"); edge("n1","n3"). edge("n2","n3").

Calimeri, Fusc` a, Germano, Perri, Zangari DeMaCS Embedding ASP in mobile systems

slide-12
SLIDE 12

Introduction The embASP Framework An embASP Specialization DLVfit Related Work Conclusions References

An embASP Specialization

for Android and DLV

Lstart,asCallbackP:PAnswerSetCallbackv LaddOption,optionsP:PStringv LaddRawInput,programP:PStringv LaddFileInput,filePathP:PStringv LaddInput,objP:PObjectv LaddInput,objectsP:PSet<Object>vPSet<Object> LaddFilter,objP:PClassv LaddFilter,predicateP:PStringv ASPHandler

  • outputStringP:Pstring
  • weightMapP:Pmap<IntegerVPInteger>

LgetAnswerObjects,vP:PSet<Object> AnswerSet LregisterClass,classP:PClassv LgetClass,predicateP:PStringvP:PClass LgetString,objP:PObjectvP:PString LgetObject,stringP:PStringvP:PObject ASPMapper Lcallback,answerSetsP:PSet<AnswerSet>v AnswerSetCallback LhandleActionSolve,v ASPService Lstart,asCallbackP:PAnswerSetCallbackv LaddFilter,predicateP:PStringv LaddFilter,objP:PClassv DLVHandler LhandleActionSolve,v DLVService Client

  • answerSetListP:PList<AnswerSet>

Lparse,v AnswerSets Lparse,v DLVAnswerSets

Calimeri, Fusc` a, Germano, Perri, Zangari DeMaCS Embedding ASP in mobile systems

slide-13
SLIDE 13

Introduction The embASP Framework An embASP Specialization DLVfit Related Work Conclusions References

The embASP Specialization

Technical Details

Android [Anda]

The most used mobile operating system worldwide, due also to its open source nature The development model is currently based on the Java programming language

Calimeri, Fusc` a, Germano, Perri, Zangari DeMaCS Embedding ASP in mobile systems

slide-14
SLIDE 14

Introduction The embASP Framework An embASP Specialization DLVfit Related Work Conclusions References

The embASP Specialization

Technical Details

Android [Anda]

The most used mobile operating system worldwide, due also to its open source nature The development model is currently based on the Java programming language

JNI (Java Native Interface) [JNI] and Android NDK (Native Development Kit) [Andb]

The use of JNI grants the access to the API provided by the Android NDK, and to the exposed DLV functionalities directly from the Java code of an Android application The NDK allows developers to implement parts of an Android application as “native-code” languages, such as C and C++ These technologies represent the general and standard way to realize the porting of a C++ software in an Android context

Calimeri, Fusc` a, Germano, Perri, Zangari DeMaCS Embedding ASP in mobile systems

slide-15
SLIDE 15

Introduction The embASP Framework An embASP Specialization DLVfit Related Work Conclusions References

The embASP Specialization

Technical Details

Android [Anda]

The most used mobile operating system worldwide, due also to its open source nature The development model is currently based on the Java programming language

JNI (Java Native Interface) [JNI] and Android NDK (Native Development Kit) [Andb]

The use of JNI grants the access to the API provided by the Android NDK, and to the exposed DLV functionalities directly from the Java code of an Android application The NDK allows developers to implement parts of an Android application as “native-code” languages, such as C and C++ These technologies represent the general and standard way to realize the porting of a C++ software in an Android context

DLV [LPF+06]

Calimeri, Fusc` a, Germano, Perri, Zangari DeMaCS Embedding ASP in mobile systems

slide-16
SLIDE 16

Introduction The embASP Framework An embASP Specialization DLVfit Related Work Conclusions References

DLVfit

A first full native ASP-based Android App

Calimeri, Fusc` a, Germano, Perri, Zangari DeMaCS Embedding ASP in mobile systems

slide-17
SLIDE 17

Introduction The embASP Framework An embASP Specialization DLVfit Related Work Conclusions References

DLVfit

Features

The user expresses her own health goals and preferences in a customizable way, along many composable dimensions By means of the Google Activity Recognition APIs [Goo], in the background the app constantly detects the current user activity and stores proper information At any time, the user might ask for a suggestion about a workout plan for the rest of the day: this task is carried on by the reasoning module, that prepares a (set of) proper workout plans

Calimeri, Fusc` a, Germano, Perri, Zangari DeMaCS Embedding ASP in mobile systems

slide-18
SLIDE 18

Introduction The embASP Framework An embASP Specialization DLVfit Related Work Conclusions References

DLVfit

Asking for a workout plan

Calimeri, Fusc` a, Germano, Perri, Zangari DeMaCS Embedding ASP in mobile systems

slide-19
SLIDE 19

Introduction The embASP Framework An embASP Specialization DLVfit Related Work Conclusions References

DLVfit

Expressing priorities

Calimeri, Fusc` a, Germano, Perri, Zangari DeMaCS Embedding ASP in mobile systems

slide-20
SLIDE 20

Introduction The embASP Framework An embASP Specialization DLVfit Related Work Conclusions References

DLVfit

Expressing preferences over different workout levels

Calimeri, Fusc` a, Germano, Perri, Zangari DeMaCS Embedding ASP in mobile systems

slide-21
SLIDE 21

Introduction The embASP Framework An embASP Specialization DLVfit Related Work Conclusions References

DLVfit

ASP Reasoning Module

The app builds dynamically a proper ASP program complying with the very personal goals and preferences previously expressed A classic Guess/Check/Optimize paradigm is used:

Guess: Compute how much time should be spent on each exercise Check: Find only admissible workout plans Optimize: Try to satisfy the user’s preferences to the largest possible extent

Calimeri, Fusc` a, Germano, Perri, Zangari DeMaCS Embedding ASP in mobile systems

slide-22
SLIDE 22

Introduction The embASP Framework An embASP Specialization DLVfit Related Work Conclusions References

DLVfit

ASP program: relevants concepts

calories burnt per activity(A, C)

the calories burnt (C), in each unit of time, per each Activity (A)

remaining calories to burn(R)

the calories that remain to burnt in the current day

how long(A, D)

the amount of the time that can be spent for each activity

max time(T)

the duration of the workout

surplus(C)

the maximum surplus of calories to burn of the suggested workouts

  • ptimize(T, W, P)

the specific optimization operation(s) that the user wants to perform

Calimeri, Fusc` a, Germano, Perri, Zangari DeMaCS Embedding ASP in mobile systems

slide-23
SLIDE 23

Introduction The embASP Framework An embASP Specialization DLVfit Related Work Conclusions References

DLVfit

An example of Input I (Basic Concepts)

calories_burnt_per_activity("ON_BICYCLE", 5). calories_burnt_per_activity("WALKING", 2). calories_burnt_per_activity("RUNNING", 11). remaining_calories_to_burn(200). how_long("ON_BICYCLE", 10). how_long("ON_BICYCLE", 20). how_long("WALKING", 10). how_long("WALKING", 20). how_long("RUNNING", 10). how_long("RUNNING", 20). max_time(20). surplus(100).

Calimeri, Fusc` a, Germano, Perri, Zangari DeMaCS Embedding ASP in mobile systems

slide-24
SLIDE 24

Introduction The embASP Framework An embASP Specialization DLVfit Related Work Conclusions References

DLVfit

An example of Input II (Custom Optimizations)

  • ptimize("RUNNING", 1, 3).
  • ptimize("WALKING", 2, 3).
  • ptimize("ON BICYCLE", 3, 3).

maximize the number of favourite activities to perform

  • ptimize(time,0,2).

minimize total time spent exercising

  • ptimize(activities, 0, 1).

minimize total number of activities to perform

Calimeri, Fusc` a, Germano, Perri, Zangari DeMaCS Embedding ASP in mobile systems

slide-25
SLIDE 25

Introduction The embASP Framework An embASP Specialization DLVfit Related Work Conclusions References

DLVfit

Logic rules composing the ASP program

activity_to_do (A, HL) | not_activity_to_do (A, HL) :- how_long(A, HL). :- activity_to_do (A, HL1), activity_to_do (A, HL2), HL1 != HL2. :- remaining_calories_to_burn (RC), total_calories_activity_to_do (CB), RC > CB. :- remaining_calories_to_burn (RC), total_calories_activity_to_do (CB), CB > RCsurplus , RCsurplus = RC + surplus. :- max_time(MTS), total_time_activity_to_do (TS), MTS < TS. :∼ optimize(time , _, P), activity_to_do (_, HL). [HL:P] :∼ optimize(activities , _, P), #int(HM), HM = #count{A, HL : activity_to_do (A, HL )}. [HM:P] :∼ optimize(A, W, P), activity_to_do (A, _). [W:P]

Calimeri, Fusc` a, Germano, Perri, Zangari DeMaCS Embedding ASP in mobile systems

slide-26
SLIDE 26

Introduction The embASP Framework An embASP Specialization DLVfit Related Work Conclusions References

DLVfit

Advantages of the approach

Wide range of customization possibilities thanks to the modelling capabilities and the declarative nature of ASP Flexibility and possibility to build the ASP program(s) at runtime and to customize the modules ease the developer’s job of make the app comply to the user’s desiderata

Calimeri, Fusc` a, Germano, Perri, Zangari DeMaCS Embedding ASP in mobile systems

slide-27
SLIDE 27

Introduction The embASP Framework An embASP Specialization DLVfit Related Work Conclusions References

Related Work

Clingo4 and Java Wrapper

Clingo4 [GKKS14] Enables a form of control over the computational tasks of the embedded ASP solver Clingo with scripting languages lua and python The main purpose is the support of dynamic and incremental reasoning Java Wrapper [Ric03] Acts like a versatile wrapper wherewith the Java developers can interact with the ASP solver (DLV)

Differently, embASP makes use of Java Annotations, allowing an easy mapping of input/output to Java Objects

Calimeri, Fusc` a, Germano, Perri, Zangari DeMaCS Embedding ASP in mobile systems

slide-28
SLIDE 28

Introduction The embASP Framework An embASP Specialization DLVfit Related Work Conclusions References

Related Work

JDLV

JDLV [FGLR12] Based on JASP, an hybrid language that allows a bilateral interaction between ASP and Java Uses JPA annotations to define how Java classes map to relations, similarly to ORM frameworks

Differently, embASP exploits custom annotations, almost effortless to define, in order to deal with the mapping

Calimeri, Fusc` a, Germano, Perri, Zangari DeMaCS Embedding ASP in mobile systems

slide-29
SLIDE 29

Introduction The embASP Framework An embASP Specialization DLVfit Related Work Conclusions References

Related Work

HealthyLife

HealthyLife [DLL13] Prototype system which makes use of ASP-based Stream Reasoning (ASR) in a mobile health app According to a cloud computing paradigm uses internet connections in order to communicate with the reasoning service The focus of HealthyLife is primarily to detect users daily activities and try to deal with ambiguities when recognizing situations, while DLVfit delegates this task to Android Recognition API: its primary goal is to experiment with the usage of ASP on mobile devices

Calimeri, Fusc` a, Germano, Perri, Zangari DeMaCS Embedding ASP in mobile systems

slide-30
SLIDE 30

Introduction The embASP Framework An embASP Specialization DLVfit Related Work Conclusions References

Related Work

Cloud-based Approach

Pro

Grants great computational power to low-end devices No need for actually porting a system to the final user’s device Performance is not an issue

Calimeri, Fusc` a, Germano, Perri, Zangari DeMaCS Embedding ASP in mobile systems

slide-31
SLIDE 31

Introduction The embASP Framework An embASP Specialization DLVfit Related Work Conclusions References

Related Work

Cloud-based Approach

Pro

Grants great computational power to low-end devices No need for actually porting a system to the final user’s device Performance is not an issue

Cons

Needs a proper application hosting architecture

set-up might be tricky if not hard costs might be an issue

Might need a stable and fast internet connection

Calimeri, Fusc` a, Germano, Perri, Zangari DeMaCS Embedding ASP in mobile systems

slide-32
SLIDE 32

Introduction The embASP Framework An embASP Specialization DLVfit Related Work Conclusions References

Conclusions

embASP

A general framework for embedding the reasoning capabilities

  • f ASP into external systems

A specialization for the mobile setting, tailored for making use

  • f DLV within Android apps

DLVfit

First mobile app natively running an ASP system Android health app that shows the effectiveness of the framework

Future Work

Test the framework over different platforms and solvers Evaluate the performances of our porting with detailed benchmarks over several version of Android and multiple devices Further investigate the potential of ASP on mobile systems by means of new applications

Calimeri, Fusc` a, Germano, Perri, Zangari DeMaCS Embedding ASP in mobile systems

slide-33
SLIDE 33

Introduction The embASP Framework An embASP Specialization DLVfit Related Work Conclusions References

Thank you for your attention.

Calimeri, Fusc` a, Germano, Perri, Zangari DeMaCS Embedding ASP in mobile systems

slide-34
SLIDE 34

Introduction The embASP Framework An embASP Specialization DLVfit Related Work Conclusions References

References I

Android. http://www.android.com. Android Native Development Kit. https://developer.android.com/tools/sdk/ndk. Chitta Baral. Knowledge Representation, Reasoning and Declarative Problem Solving. Cambridge University Press, 2003. Gerhard Brewka, Thomas Eiter, and Miroslaw Truszczynski. Answer set programming at a glance.

  • Commun. ACM, 54(12):92–103, 2011.

Francesco Calimeri and Francesco Ricca. On the application of the answer set programming system dlv in industry: a report from the field. Book Reviews, 2013(03), 2013.

Calimeri, Fusc` a, Germano, Perri, Zangari DeMaCS Embedding ASP in mobile systems

slide-35
SLIDE 35

Introduction The embASP Framework An embASP Specialization DLVfit Related Work Conclusions References

References II

Thang M Do, Seng W Loke, and Fei Liu. Healthylife: An activity recognition system with smartphone using logic-based stream reasoning. In Mobile and Ubiquitous Systems: Computing, Networking, and Services, pages 188–199. Springer, 2013. Thomas Eiter, Wolfgang Faber, Nicola Leone, and Gerald Pfeifer. Declarative problem-solving using the dlv system. In Logic-based artificial intelligence, pages 79–103. Springer, 2000. Thomas Eiter, Giovambattista Ianni, and Thomas Krennwallner. Answer Set Programming: A Primer. In Reasoning Web. Semantic Technologies for Information Systems, 5th International Summer School - Tutorial Lectures, pages 40–110, Brixen-Bressanone, Italy, August-September 2009. Onofrio Febbraro, Giovanni Grasso, Nicola Leone, and Francesco Ricca. JASP: a framework for integrating Answer Set Programming with Java. In Proc. of KR2012. AAAI Press, 2012.

Calimeri, Fusc` a, Germano, Perri, Zangari DeMaCS Embedding ASP in mobile systems

slide-36
SLIDE 36

Introduction The embASP Framework An embASP Specialization DLVfit Related Work Conclusions References

References III

Martin Gebser, Roland Kaminski, Benjamin Kaufmann, and Torsten Schaub. Clingo= asp+ control: Preliminary report. arXiv preprint arXiv:1405.3694, 2014. Michael Gelfond and Vladimir Lifschitz. Classical Negation in Logic Programs and Disjunctive Databases. New Generation Computing, 9:365–385, 1991. Google Activity Recognition API. https://developer.android.com/reference/com/google/android/gms/ location/ActivityRecognition.html. Java Native Interface. http://docs.oracle.com/javase/8/docs/technotes/guides/jni. Nicola Leone, Gerald Pfeifer, Wolfgang Faber, Thomas Eiter, Georg Gottlob, Simona Perri, and Francesco Scarcello. The DLV System for Knowledge Representation and Reasoning. ACM Transactions on Computational Logic, 7(3):499–562, July 2006.

Calimeri, Fusc` a, Germano, Perri, Zangari DeMaCS Embedding ASP in mobile systems

slide-37
SLIDE 37

Introduction The embASP Framework An embASP Specialization DLVfit Related Work Conclusions References

References IV

Nicola Leone and Francesco Ricca. Answer set programming: A tour from the basics to advanced development tools and industrial applications. In RR2015, to appear, LNCS, 2015. Victor W. Marek and Miros law Truszczy´ nski. Stable Models and an Alternative Logic Programming Paradigm. In Krzysztof R. Apt, V. Wiktor Marek, Miros law Truszczy´ nski, and David S. Warren, editors, The Logic Programming Paradigm – A 25-Year Perspective, pages 375–398. Springer Verlag, 1999. Ilkka Niemel¨ a. Logic Programming with Stable Model Semantics as Constraint Programming Paradigm. Annals of Mathematics and Artificial Intelligence, 25(3–4):241–273, 1999. Francesco Ricca. The dlv java wrapper. In APPIA-GULP-PRODE, pages 263–274. Citeseer, 2003.

Calimeri, Fusc` a, Germano, Perri, Zangari DeMaCS Embedding ASP in mobile systems