Integrating Answer Set Programming with Object-oriented Languages
Jakob Rath and Christoph Redl
jakob.rath@student.tuwien.ac.at, redl@kr.tuwien.ac.at
January 16, 2017
Rath J., Redl C. (TU Vienna) HEX-Programs January 16, 2017 1 / 22
Integrating Answer Set Programming with Object-oriented Languages - - PowerPoint PPT Presentation
Integrating Answer Set Programming with Object-oriented Languages Jakob Rath and Christoph Redl jakob.rath@student.tuwien.ac.at, redl@kr.tuwien.ac.at January 16, 2017 Rath J., Redl C. (TU Vienna) HEX-Programs January 16, 2017 1 / 22
jakob.rath@student.tuwien.ac.at, redl@kr.tuwien.ac.at
Rath J., Redl C. (TU Vienna) HEX-Programs January 16, 2017 1 / 22
Motivation
Rath J., Redl C. (TU Vienna) HEX-Programs January 16, 2017 2 / 22
Motivation
Rath J., Redl C. (TU Vienna) HEX-Programs January 16, 2017 3 / 22
Motivation
Rath J., Redl C. (TU Vienna) HEX-Programs January 16, 2017 3 / 22
Motivation
Rath J., Redl C. (TU Vienna) HEX-Programs January 16, 2017 3 / 22
Motivation
Rath J., Redl C. (TU Vienna) HEX-Programs January 16, 2017 3 / 22
Motivation
Rath J., Redl C. (TU Vienna) HEX-Programs January 16, 2017 4 / 22
Motivation
1
2
3
Rath J., Redl C. (TU Vienna) HEX-Programs January 16, 2017 4 / 22
Motivation
1
2
3
Rath J., Redl C. (TU Vienna) HEX-Programs January 16, 2017 4 / 22
Motivation
Rath J., Redl C. (TU Vienna) HEX-Programs January 16, 2017 5 / 22
Motivation
Rath J., Redl C. (TU Vienna) HEX-Programs January 16, 2017 5 / 22
General Approach
Rath J., Redl C. (TU Vienna) HEX-Programs January 16, 2017 6 / 22
General Approach
Rath J., Redl C. (TU Vienna) HEX-Programs January 16, 2017 7 / 22
General Approach
Rath J., Redl C. (TU Vienna) HEX-Programs January 16, 2017 7 / 22
General Approach
Rath J., Redl C. (TU Vienna) HEX-Programs January 16, 2017 7 / 22
General Approach
Rath J., Redl C. (TU Vienna) HEX-Programs January 16, 2017 7 / 22
General Approach
1 Parameters v1, . . . , vn are converted to facts according to input specification ι. 2 These facts along with the ASP program P are passed to the ASP solver. 3 The answer sets are mapped to objects O according to output specification ω.
Rath J., Redl C. (TU Vienna) HEX-Programs January 16, 2017 8 / 22
General Approach
1 Parameters v1, . . . , vn are converted to facts according to input specification ι. 2 These facts along with the ASP program P are passed to the ASP solver. 3 The answer sets are mapped to objects O according to output specification ω.
Rath J., Redl C. (TU Vienna) HEX-Programs January 16, 2017 8 / 22
General Approach
1 Parameters v1, . . . , vn are converted to facts according to input specification ι. 2 These facts along with the ASP program P are passed to the ASP solver. 3 The answer sets are mapped to objects O according to output specification ω.
Rath J., Redl C. (TU Vienna) HEX-Programs January 16, 2017 8 / 22
General Approach
1 Parameters v1, . . . , vn are converted to facts according to input specification ι. 2 These facts along with the ASP program P are passed to the ASP solver. 3 The answer sets are mapped to objects O according to output specification ω.
Rath J., Redl C. (TU Vienna) HEX-Programs January 16, 2017 8 / 22
General Approach
Rath J., Redl C. (TU Vienna) HEX-Programs January 16, 2017 9 / 22
General Approach
1 Data is organized in classes, which consist of named attributes and methods.
Rath J., Redl C. (TU Vienna) HEX-Programs January 16, 2017 9 / 22
General Approach
1 Data is organized in classes, which consist of named attributes and methods. 2 The language must provide the classes str and int.
Rath J., Redl C. (TU Vienna) HEX-Programs January 16, 2017 9 / 22
General Approach
1 Data is organized in classes, which consist of named attributes and methods. 2 The language must provide the classes str and int. 3 We presuppose the following collection types:
Rath J., Redl C. (TU Vienna) HEX-Programs January 16, 2017 9 / 22
Input and Output Specification Language
Rath J., Redl C. (TU Vienna) HEX-Programs January 16, 2017 10 / 22
Input and Output Specification Language
Rath J., Redl C. (TU Vienna) HEX-Programs January 16, 2017 11 / 22
Input and Output Specification Language
Rath J., Redl C. (TU Vienna) HEX-Programs January 16, 2017 11 / 22
Input and Output Specification Language
Rath J., Redl C. (TU Vienna) HEX-Programs January 16, 2017 12 / 22
Input and Output Specification Language
Rath J., Redl C. (TU Vienna) HEX-Programs January 16, 2017 13 / 22
Input and Output Specification Language
Rath J., Redl C. (TU Vienna) HEX-Programs January 16, 2017 13 / 22
Input and Output Specification Language
Rath J., Redl C. (TU Vienna) HEX-Programs January 16, 2017 14 / 22
Input and Output Specification Language
Rath J., Redl C. (TU Vienna) HEX-Programs January 16, 2017 15 / 22
Implementation and Applications
Rath J., Redl C. (TU Vienna) HEX-Programs January 16, 2017 16 / 22
Implementation and Applications
User Code ASP Program Input Arguments Input Mapper
PY-ASPIOFacade
Output Mapper Facts ASP Solver Answer Sets User Application
PY-ASPIO Library
ASP Solver
Rath J., Redl C. (TU Vienna) HEX-Programs January 16, 2017 17 / 22
Implementation and Applications
from c o l l e c t i o n s import namedtuple import aspio # Define classes and create sample data Node = namedtuple ( ’Node ’ , [ ’ label ’ ] ) ColoredNode = namedtuple ( ’ ColoredNode ’ , [ ’ label ’ , ’ color ’ ] ) Edge = namedtuple ( ’Edge ’ , [ ’ f i r s t ’ , ’ second ’ ] ) a , b , c = Node( ’a ’ ) , Node( ’b ’ ) , Node( ’ c ’ ) nodes = {a , b , c} edges = {Edge(a , b ) , Edge(a , c ) , Edge(b , c)} # Register class names with aspio aspio . r e g i s t e r d i c t ( globals ( ) ) # Load ASP program and input / output s p e c i f i c a t i o n s from f i l e prog = aspio . Program ( filename= ’ coloring . dl ’ ) # I t e r a t e
a l l answer sets for r e s u l t in prog . solve ( nodes , edges ) : print ( r e s u l t . colored nodes ) Rath J., Redl C. (TU Vienna) HEX-Programs January 16, 2017 18 / 22
Implementation and Applications
Rath J., Redl C. (TU Vienna) HEX-Programs January 16, 2017 19 / 22
Implementation and Applications
Rath J., Redl C. (TU Vienna) HEX-Programs January 16, 2017 19 / 22
Implementation and Applications
Rath J., Redl C. (TU Vienna) HEX-Programs January 16, 2017 19 / 22
Implementation and Applications
Rath J., Redl C. (TU Vienna) HEX-Programs January 16, 2017 19 / 22
Implementation and Applications
Rath J., Redl C. (TU Vienna) HEX-Programs January 16, 2017 19 / 22
Conclusion
Rath J., Redl C. (TU Vienna) HEX-Programs January 16, 2017 20 / 22
Conclusion
Rath J., Redl C. (TU Vienna) HEX-Programs January 16, 2017 21 / 22
Conclusion
Rath J., Redl C. (TU Vienna) HEX-Programs January 16, 2017 21 / 22
Conclusion
Rath J., Redl C. (TU Vienna) HEX-Programs January 16, 2017 21 / 22
Conclusion
Rath J., Redl C. (TU Vienna) HEX-Programs January 16, 2017 22 / 22
Conclusion
Rath J., Redl C. (TU Vienna) HEX-Programs January 16, 2017 23 / 22