May 29, 2018 [iDS Workshop EIT Digital] Reasoning over Stream Data Using a Rule-Based Programming Language Joaquín Arias 1 , 2 Manuel Carro 1 , 2 1 IMDEA Software Institute, 2 Technical University of Madrid madrid institute for advanced studies in software development technologies
www.software.imdea.org Motivation We want efficient automated control systems madrid institute for advanced studies in software development technologies 1 / 17
www.software.imdea.org Problems 1 The code of an automated system is very complex, it has to: • Reason with static knowledge (e.g., regulations for energy injection into the grid). • Process dynamic / stream data (e.g., energy market price or wind speed). 2 The code has to be modified due to: • New requirements (e.g., link energy production to the energy market price). • The requirements may differ (e.g., each country has it own regulations). 3 The bottleneck is on the human side rather than on the machine side [5]. madrid institute for advanced studies in software development technologies 2 / 17
www.software.imdea.org Proposal: Stream-TCLP A rule-based high level programming language (based on logic and constraints): + makes it easier to translate requirements into code. + uses constraints to prune the search during the analysis. + memorizes the analysis results to reuse them. + dynamically re-compute the results updated by new stream data. open_blades(Windmill, T) :- blades_are_closed(Windmill, T-1), 1 not risk(Windmill, T). 2 risk(Windmill, T) :- near(Windmill, Near), 3 open_blades(Near, T). 4 risk(Windmill, T) :- T1 #< T2, T2 #< T, 5 damage_detected(Windmill, T1), 6 not repaired(Windmill, T2). 7 Figure: The query ?- findall(Windmill, (current_time(T), open_blade(Windmill,T)), List) to this program returns a List with the Windmill s that can open its blades at T . madrid institute for advanced studies in software development technologies 3 / 17
www.software.imdea.org Fighting against giants? (M. Cervantes. Don Quijote de la Mancha. 1605) madrid institute for advanced studies in software development technologies 4 / 17
www.software.imdea.org Preliminary Result Modular TCLP: Is a modular design of TCLP implemented in Ciao (high performance Prolog implementation) which makes it easier to integrate tabling with different constraint solvers. http://www.cliplab.org/papers/tplp2018-tclp/ s(CASP): Extends s(ASP), a novel non-monotonic reasoner developed at the UTD, with tabling and constraints using Ciao + Modular TCLP . https://gitlab.software.imdea.org/joaquin.arias/sCASP madrid institute for advanced studies in software development technologies 5 / 17
www.software.imdea.org Modular TCLP [PPDP 2016, TPLP 2018] Modular TCLP External CLP solver Interface Tabling engine Prolog-based CLP solver WAM • Extension of Prolog which combines the benefits of CLP + tabling. • Implemented in Ciao and described in [3]. • Our design facilitates the integration of constraint solvers. • A new answer management strategy reduces execution time and space needs. • TCLP improves: declarativeness, termination properties, and performance. madrid institute for advanced studies in software development technologies 6 / 17
www.software.imdea.org Modular TCLP I: Facilitate the integration For each problem we need a specific constraint solver: • CLP(Lattice) Operates with partially ordered set of data. E.g., inventory management, bearing ⊑ gearbox ⊑ turbine. • CLP(Intervals) E.g., temporal reasoning over intervals, [T1, T2]. • CLP(Q) Solves linear (in)equations over rationals. E.g., cost management plan. gearbox turbine madrid institute for advanced studies in software development technologies 7 / 17
www.software.imdea.org Modular TCLP I: Facilitate the integration For each problem we need a specific constraint solver: • CLP(Lattice) Operates with partially ordered set of data. E.g., inventory management, bearing ⊑ gearbox ⊑ turbine. • CLP(Intervals) E.g., temporal reasoning over intervals, [T1, T2]. • CLP(Q) Solves linear (in)equations over rationals. E.g., cost management plan. :- use_package(clpq). 1 :- active_tclp. 2 store_projection(V,st(V,St)) :- clpqr_dump_constraints(V, V, St). 3 call_entail(st(V,_ ),st(V,StGen)) :- clpq_entailed(StGen). 4 answer_compare(st(V,_ ),st(V,StAns),=<) :- clpq_entailed(StAns), !. 5 answer_compare(st(F,St),st(F,StAns), >) :- clpq_meta(StAns), clpq_entailed(St). 6 apply_answer(V,st(V,St)) :- clpq_meta(St). 7 Figure: The TCLP interface of CLP(Q) [8] is a bridge to existing predicates madrid institute for advanced studies in software development technologies 7 / 17
www.software.imdea.org Modular TCLP II: Entailment Call / answer entailment check is used to detect more particular queries / answers. c 0 entails c 1 ( c 0 ⊑ c 1 ) if any solution of c 0 is also a solution of c 1 . { X > 5 } ⊑ { X > 0 } 1 The answers from a more general query / call are reused to answer more particular queries / calls avoiding re-computation. 2 Call entailment check in the presence of recursive rules may avoid loops. 3 It retains only the most general answers avoiding repetitions and redundancy. madrid institute for advanced studies in software development technologies 8 / 17
www.software.imdea.org Modular TCLP III: Answer Management Strategy 9 . 46 · 10 5 8 . 91 · 10 5 5 . 99 · 10 5 number of answers (log.) 71 , 658 37 , 548 10 6 9 , 352 10 5 4 , 371 10 4 441 242 10 3 10 2 25 10 1 Discard Remove Discard+Remove Figure: Number of answers: saved, discarded, removed and returned to the query step_bound(WindA, WindB, Steps, Limit) . madrid institute for advanced studies in software development technologies 9 / 17
www.software.imdea.org Modular TCLP IV: Declarativeness near(WindA, WindB) :- z a 1 limit(K), D #< K, 2 dist(WindA, WindB, D). 3 4 dist(X, Y, D) :- b 5 D1 #> 0, D2 #> 0, 6 D #= D1 + D2, 7 dist(X, Z, D1), 8 edge(Z, Y, D2). 9 dist(X, Y, D) :- 10 c edge(X, Y, D). 11 12 edge(a, b, D) :- 13 D #> 7, D #< 11. 14 d edge(... 15 Figure: near/2 and dist/3 find the windmills within a distance limit K . madrid institute for advanced studies in software development technologies 10 / 17
www.software.imdea.org Modular TCLP V: Termination properties & Performance z a b Prolog CLP(Q) Tabling TCLP(Q) Left recursion x x 2311 1286 Without Right recursion > 5 min. 5136 3672 2237 cycles Left recursion x x x 742 With c Right recursion x 10992 x 1776 cycles Table: Run time (ms) for dist/3 . A ‘x’ means no termination. d madrid institute for advanced studies in software development technologies 11 / 17
www.software.imdea.org However... ... Prolog and TCLP do not handle recursive rules over negation where for a given problem we may have multiple possible models. open_blades(Windmill, T) :- blades_are_closed(Windmill, T-1), 1 not risk(Windmill, T). 2 risk(Windmill, T) :- near(Windmill, Near), 3 open_blades(Near, T). 4 { open_blades(quijote,T), { not open_blades(quijote,T), not open_blades(sancho,T) } open_blades(sancho,T) } madrid institute for advanced studies in software development technologies 12 / 17
www.software.imdea.org s(CASP) [ICLP/TPLP 2018] There are two approaches to implement stable model semantics: • Answer Set Programming: however, most ASP systems perform a grounding phase which removes variables and their links / constraints. • s(ASP): is a top-down execution model which retains variables during execution and in the answer sets (developed at the University of Texas at Dallas). Our proposal, s(CASP), is a non-monotonic reasoner, which extend s(ASP) with constraints and tabling, implemented using Ciao + Modular TCLP . + The constraint can be part of the answer set. + It returns a justification tree with the rules that support the model. + The implementation design is parametric w.r.t. the constraint solver. madrid institute for advanced studies in software development technologies 13 / 17
www.software.imdea.org s(CASP) I: Performance s(CASP) ASP ASP standard incremental 479 n = 7 3,651 9,885 1,499 n = 8 54,104 174,224 5,178 n = 9 191,267 > 5 min Table: Run time (ms) needed to return the plan of minimal movements that solves the Towers of Hanoi problem with n disks. madrid institute for advanced studies in software development technologies 14 / 17
www.software.imdea.org s(CASP) I: Performance s(CASP) ASP ASP standard incremental 479 n = 7 3,651 9,885 1,499 n = 8 54,104 174,224 5,178 n = 9 191,267 > 5 min Table: Run time (ms) needed to return the plan of minimal movements that solves the Towers of Hanoi problem with n disks. • s(CASP) implements the algorithm that returns the minimal plan. • The ASP standard variant returns a plan for a given number of moves (if it exists). • The ASP incremental variant recomputes the problem, incrementing the allowed number of moves, until it finds a valid plan. madrid institute for advanced studies in software development technologies 14 / 17
Recommend
More recommend