Propia and CHRs Transforming Constraint Specification into Constraint Behaviour.

Slides:



Advertisements
Similar presentations
Non-Binary Constraint Satisfaction Toby Walsh Cork Constraint Computation Center.
Advertisements

Marco Gavanelli – Università di Ferrara, Italy Marco Alberti – Universidade nova de Lisboa, Portugal Evelina Lamma – Università di Ferrara, Italy.
Computer Science CPSC 322 Lecture 25 Top Down Proof Procedure (Ch 5.2.2)
Continuing Abstract Interpretation We have seen: 1.How to compile abstract syntax trees into control-flow graphs 2.Lattices, as structures that describe.
Inference Rules Universal Instantiation Existential Generalization
SLD-resolution Introduction Most general unifiers SLD-resolution
Cs7120 (Prasad)L22-MetaPgm1 Meta-Programming
Knowledge & Reasoning Logical Reasoning: to have a computer automatically perform deduction or prove theorems Knowledge Representations: modern ways of.
CLASSICAL PLANNING What is planning ?  Planning is an AI approach to control  It is deliberation about actions  Key ideas  We have a model of the.
1 CMSC 471 Fall 2002 Class #6 – Wednesday, September 18.
Lecture 3Dr. Verma1 COSC 6397 – Information Assurance Module M2 – Protocol Specification and Verification University of Houston Rakesh Verma Lecture 3.
Hybridisation Solver Cooperation in ECLiPSe. 2 Introduction  Motivation  Sending Constraints to Different Solvers  Probing  Column Generation  Motivation.
For Friday No reading Homework: –Chapter 9, exercise 4 (This is VERY short – do it while you’re running your tests) Make sure you keep variables and constants.
Answer Set Programming Overview Dr. Rogelio Dávila Pérez Profesor-Investigador División de Posgrado Universidad Autónoma de Guadalajara
13 Automated Reasoning 13.0 Introduction to Weak Methods in Theorem Proving 13.1 The General Problem Solver and Difference Tables 13.2 Resolution.
Logic CPSC 386 Artificial Intelligence Ellen Walker Hiram College.
1 Pierangelo Dell’Acqua Dept. of Science and Technology Linköping University Constraint programming 2001 November 13th 2001
1 Simulator-Model Checker for Reactive Real-Time Abstract State Machines Anatol Slissenko University Paris 12 Pavel Vasilyev University Paris 12 University.
CHORD Semantics January, F-Atoms User Defined Constraint – A::B – A[B->C], A[B=>C] – A[B(V)->C], A[B(P:T0)=>T1] Built-in Constraint – 1 : Integer,
CPSC 322, Lecture 19Slide 1 Propositional Logic Intro, Syntax Computer Science cpsc322, Lecture 19 (Textbook Chpt ) February, 23, 2009.
Constraint Reasoning u Motivation u ECLiPSe - IC u ECLiPSe – propia u ECLiPSe - eplex.
Weizmann Institute Deciding equality formulas by small domain instantiations O. Shtrichman The Weizmann Institute Joint work with A.Pnueli, Y.Rodeh, M.Siegel.
Constraint Logic Programming Ryan Kinworthy. Overview Introduction Logic Programming LP as a constraint programming language Constraint Logic Programming.
1 Automated Reasoning Introduction to Weak Methods in Theorem Proving 13.1The General Problem Solver and Difference Tables 13.2Resolution Theorem.
Inference and Resolution for Problem Solving
Proof System HY-566. Proof layer Next layer of SW is logic and proof layers. – allow the user to state any logical principles, – computer can to infer.
Search in the semantic domain. Some definitions atomic formula: smallest formula possible (no sub- formulas) literal: atomic formula or negation of an.
Last time Proof-system search ( ` ) Interpretation search ( ² ) Quantifiers Equality Decision procedures Induction Cross-cutting aspectsMain search strategy.
Describing Syntax and Semantics
Logic Programming Part 2: Semantics James Cheney CS 411.
MIT and James Orlin © Chapter 3. The simplex algorithm Putting Linear Programs into standard form Introduction to Simplex Algorithm.
On Solving Presburger and Linear Arithmetic with SAT Ofer Strichman Carnegie Mellon University.
Introduction to Logic for Artificial Intelligence Lecture 2 Erik Sandewall 2010.
Knowledge & Reasoning Logical Reasoning: to have a computer automatically perform deduction or prove theorems Knowledge Representations: modern ways of.
Propositional Logic Reasoning correctly computationally Chapter 7 or 8.
1 Constraint Programming: An Introduction Adapted by Cristian OLIVA from Peter Stuckey (1998) Ho Chi Minh City.
The Theory of NP-Completeness 1. What is NP-completeness? Consider the circuit satisfiability problem Difficult to answer the decision problem in polynomial.
Notes for Chapter 12 Logic Programming The AI War Basic Concepts of Logic Programming Prolog Review questions.
CP Summer School Modelling for Constraint Programming Barbara Smith 1.Definitions, Viewpoints, Constraints 2.Implied Constraints, Optimization,
14/10/04 AIPP Lecture 7: The Cut1 Controlling Backtracking: The Cut Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture 7 14/10/04.
30/09/04 AIPP Lecture 3: Recursion, Structures, and Lists1 Recursion, Structures, and Lists Artificial Intelligence Programming in Prolog Lecturer: Tim.
Logical Agents Logic Propositional Logic Summary
ARTIFICIAL INTELLIGENCE [INTELLIGENT AGENTS PARADIGM] Professor Janis Grundspenkis Riga Technical University Faculty of Computer Science and Information.
CSE S. Tanimoto Horn Clauses and Unification 1 Horn Clauses and Unification Propositional Logic Clauses Resolution Predicate Logic Horn Clauses.
PROLOG SYNTAX AND MEANING Ivan Bratko University of Ljubljana Faculty of Computer and Info. Sc. Ljubljana, Slovenia.
CSE 230 The -Calculus. Background Developed in 1930’s by Alonzo Church Studied in logic and computer science Test bed for procedural and functional PLs.
The AI War LISP and Prolog Basic Concepts of Logic Programming
CSE Winter 2008 Introduction to Program Verification January 31 proofs through simplification.
LDK R Logics for Data and Knowledge Representation Propositional Logic: Reasoning First version by Alessandro Agostini and Fausto Giunchiglia Second version.
For Monday Finish chapter 19 No homework. Program 4 Any questions?
A Logic of Partially Satisfied Constraints Nic Wilson Cork Constraint Computation Centre Computer Science, UCC.
Automated Reasoning Early AI explored how to automated several reasoning tasks – these were solved by what we might call weak problem solving methods as.
Ch. 13 Ch. 131 jcmt CSE 3302 Programming Languages CSE3302 Programming Languages (notes?) Dr. Carter Tiernan.
For Monday Finish chapter 19 Take-home exam due. Program 4 Any questions?
First-Order Logic and Inductive Logic Programming.
1 Georgia Tech, IIC, GVU, 2006 MAGIC Lab Rossignac Lecture 02: QUANTIFIERS Sections 1.3 and 1.4 Jarek Rossignac CS1050:
Computer Science CPSC 322 Lecture 22 Logical Consequences, Proof Procedures (Ch 5.2.2)
Logic: Proof procedures, soundness and correctness CPSC 322 – Logic 2 Textbook §5.2 March 7, 2011.
AN INTERPOLATING THEOREM PROVER K.L. McMillan Cadence Berkley Labs.
SAT Solving As implemented in - DPLL solvers: GRASP, Chaff and
Copyright 1999Paul F. Reynolds, Jr. Foundations of Logic Programming.
O A procedure: a set of axioms (rules and facts) with identical signature (predicate symbol and arity). o A logic program: a set of procedures (predicates),
Chapter 7: Beyond Definite Knowledge
Copyright © Cengage Learning. All rights reserved.
Horn Clauses and Unification
Horn Clauses and Unification
Horn Clauses and Unification
Constraint Handling Rules with Disjunction (CHRv)
Representations & Reasoning Systems (RRS) (2.2)
Unit III – Chapter 3 Path Testing.
Presentation transcript:

Propia and CHRs Transforming Constraint Specification into Constraint Behaviour

2 Motivation for Propia and CHRs  Encode constraints in readable form  Set up model without leaving choice points  Support constraint propagation NB: Never introduce choice points in constraint setup Why not? repeatedly setting up constraints on different branches partially blind searching

3 The noclash Example noclash(S,T)  (T  S+5)  (S  T) Specification: Encoding as ECLiPSe clauses: noclash(S,T) :- ic:(T >= S+5). noclash(S,T) :- ic:(S >= T). Model Setup: setup(S) :- S::1..10, constraint(noclash(S,6)).

4 The noclash constraint in ECLiPSe Prolog constraint(Goal) :- call(Goal). This program leaves a choice point ?- setup(S). yes S = 1 noclash(S,T) :- ic:(T >= S+5). noclash(S,T) :- ic:(S >= T). setup(S) :- S::1..10, constraint(noclash(S,6)).

5 noclash with Propia constraint(Goal) :- Goal infers most. S{[1, 6..10]} This program does not create any choice points ?- setup(S). yes noclash(S,T) :- ic:(T >= S+5). noclash(S,T) :- ic:(S >= T). setup(S) :- S::1..10, constraint(noclash(S,6)).

6 noclash with CHRs constraint(noclash(S,T)) ic:(T = T). constraint(noclash(S,T)) ic:(S = S+5). This program does not create any choice points ?- setup(S). yes S{1..10} noclash(S,T) :- ic:(T >= S+5). noclash(S,T) :- ic:(S >= T). setup(S) :- S::1..10, constraint(noclash(S,6)).

7 Choice Points and Efficiency Experiment sum(Products,Raw1,Raw2,Profit) :- ( foreach(Item,Products), foreach(R1,R1List), foreach(R2,R2List), foreach(P,PList) do product(Item,R1,R2,P) ), Raw1 #= sum(R1List), Raw2 #= sum(R2List), Profit #= sum(PList). product( 101,1,19,1). product( 102,2,17,2). product( 103,3,15,3). product( 104,4,13,4). product( 105,10,8,5). product( 106,16,4,4). product( 107,17,3,3). product( 108,18,2,2). product( 109,19,1,1). £1 1pin 19nuts £2 2pins 17nuts £P R1pins R2nuts Raw1 = R1 Raw2 = R2 Profit= P Products:

8 Choice Points and Efficiency product_plan(Products) :- length(Products,9), Raw1 #=< 95, Raw2 #=< 95, Profit #>= 40, sum(Products,Raw1,Raw2,Profit), labeling(Products). sum(Products,Raw1,Raw2,Profit) :- ( foreach(Item,Products), foreach(R1,R1List), foreach(R2,R2List), foreach(P,PList) do product(Item,R1,R2,P) ), Raw1 #= sum(R1List), Raw2 #= sum(R2List), Profit #= sum(PList). infers most 33 secs Time for all solutions: Time to first solution: 1 hour 95>= R1+R1+R1+R1+R1+R1+R1+R1+R1 95>= R2+R2+R2+R2+R2+R2+R2+R2+R2 40=< P +P +P +P +P +P +P +P +P

9 Propia  Annotations  Most Specific Generalisation  Algorithm

10 Propia’s infers Annotation Propia annotation says what you want to infer:  Goal infers consistent Fail as soon as inconsistency can be proven  Goal infers unique Instantiate as soon as unique solution exists  Goal infers ac Maintain finite domains covering all solutions  Goal infers most Use strongest available representation covering all solutions

11 Annotation Results p(1,1). p(1,3). p(1,4). ?- p(X,Y) infers consistent. No information extracted ?- p(X,3) infers unique. X=1 ?- p(X,Y) infers most. X=1 (assuming ic is not loaded) ?- p(X,Y) infers most. X=1,Y{[1,3,4]} (assuming ic is loaded) ?- p(X,Y) infers ac. X=1,Y{[1,3,4]} (ic must be loaded)

12 More “global” Consistency pp(X,Y,Z) :- p(X,Y), p(Y,Z). ?- pp(X,Y,Z) infers most. X=1, Y=1, Z{[1,3,4]} C1 C5 C4 C2 C3 C6 C7 C8 Problem Constraints (C1,C4,C5) infers most

13 Most Specific Generalisation The Opposite of Unification! [1,A] [1,1] [1,_] [1,1] [2,2] [X,X] “most specific generalisations”

14 Most Specific Generalisation over Finite Domains 1 2 X::{[1,2]} f(1,2) f(2,4) f(X::{1,2},Y::{2,4}) “most specific generalisations”

15 Naïve Propia Algorithm Goal infers most Find all solutions to Goal, and put them in a set Find the most specific generalisation of all the terms in the set member(X,[1,2,3]) infers most Find all solutions to member(X,[1,2,3]): {1,2,3} Find the most specific generalisation of {1,2,3}: X::{1,2,3}

16 Propia Algorithm Goal infers most Find one solution S to Goal The current most specific generalisation MSG = S Repeat Find a solution NewS to Goal which is NOT an instance of MSG Find the most specific generalisation NewMSG of MSG and NewS MSG := NewMSG until no such solution remains

17 Example - without finite domains p(1,2). p(1,3). p(2,3). p(2,4). p(X,Y) infers most MSG: 1st Iteration: p(1,2) 2nd Iteration: p(1,_) 3rd Iteration: p(_,_) No more iterations

18 Propia Algorithm for Arc Consistency p(1,2). p(1,3). p(2,3). p(2,4). This algorithm only works for predicates defined by ground facts p(X,Y) infers ac is implemented as: element(I,[1,1,2,2],X), element(I,[2,3,3,4],Y).

19 CHR - Constraints Handling Rules  CHR -- set of rewrite rules for constraints  Can be mixed with normal Prolog code H 1...,H n |.  CHR -- set of rewrite rules for constraints  Can be mixed with normal Prolog code H 1...,H n |. Constraint Store add, “tell”“ask”remove

20 Clauses, Constraints, Goals prec(X1,3,X2) X1::4..6 X2=6 Constraint Store ?- prec(X,D,X) Goal D::-inf..0 prec(X,N,Y) X=Y | ic:(N=<0) Clause HeadBody Guard prec(X,D,X)

21 Clauses, Constraints, Goals le(A,B) Constraint Store ?- le(B,C) Goal le(A,C) le(X,Y1), le(Y2,Z) ==> Y1=Y2 | le(X,Z) Clause HeadBodyGuard le(B,C)

22 Constraint Store Simplification Rule le(A,B) ?- le(B,A) Goal le(B,A) le(A,B) le(X,Y), le(Y,X) X=Y Clause HeadBody A=B

23 Weak Guard Entailment Test nc(X,Y) ==> Y<X | Y=0 ?- Y<X, nc(X,Y). X = X Y = Y

24 Definition of “less than or equal” (le) :- constraints le/2. le(X,Y), le(Y,Z) ==> le(X,Z). le(X,Y), le(Y,X) X=Y. le(X,Y) ==> X=<Y. le(X,Y) X=<Y | true. Constraint Store ?- le(1,2) Goal le(1,2) true

25 Entailment Testing Constraint Store le(A,B) ?- min(A,B,Min) Goal min(A,B,Min) le(X,Y) \ min(X,Y,Z) ==> Z=X Clause HeadBody Min=A

26 Entailment Testing – without CHR’s min1(X,Y,Z) :- ic: (Z=<X), ic: (Z=<Y), ge1(X,Y,Z). ?- ic: (X=<Y), ic: (X,Y,B). Yes B::0..1 ge1(X,Y,Z) :- ‘=<‘(X,Y,B), ge2(B,X,Y,Z). delay ge2(B,_,_,_) if var(B). ge2(0,_,Y,Z) :- Z=Y. ge2(1,X,_,Z) :- Z=X.

27 CHR-Defined Precedence prec(Time1,Duration,Time2) means that Time1 precedes Time2 by at least Duration. Note that: Time1 and Time2 may be variables or numbers Duration is a number Duration may be negative ( prec(S1,-5,S2) means that S2 precedes S1 by no more than 5)

28 Syntax and semantics for CHRs  Simplification rule: H 1...,H n |.  Propagation rule: H 1...,H n ==> |.  Simpagation rule: H 1..\..H n |.  Heads are match only - no binding of external vars.  Goals are any Prolog goals or constraints.  Constraint added to store if no rule applicable.  Simplification rule: H 1...,H n |.  Propagation rule: H 1...,H n ==> |.  Simpagation rule: H 1..\..H n |.  Heads are match only - no binding of external vars.  Goals are any Prolog goals or constraints.  Constraint added to store if no rule applicable.

29 CHRs for prec/3 %A timepoint precedes itself by a maximum duration of 0 prec(S,D,S) D=<0. ( implicit guard in the head ) %Two timepoints preceding each other by (at least) 0 are the same prec(S1,0,S2), prec(S2,0,S1) S1=S2. ( rule with two atoms in the head ) %Transitivity prec(S1,D1,S2),prec(S2,D2,S3) ==> D3 is D1+D2, prec(S1,D3,S3). ( propagation rule ) % prec(S1,D1,S2) is redundant prec(S1,D1,S2) \ prec(S1,D2,S2) D2>=D1 | true. ( simpagation rule )

30 Complete Precedence Entailment % Assume D is a number noclash(S,T)\ prec(T,D,S) D >= -5 | prec(T,0,S). noclash(S,T)\ prec(S,D,T) D >= 0 | prec(S,5,T). prec(S,D,T) ==> ic:(T>=S+D).

31 Global Consistency  Reasoning on Combinations of Constraints Propia and CHRs can apply consistency techniques to combinations of constraints  Propia for a priori combinations Propia can be applied to program-defined predicates These predicates combine sets of constraints selected in advance of program execution  CHRs for combining newly posted constraints CHR multi-headed rules can match combinations of constraints CHR multi-headed rules can match constraints newly posted during search

32 CHR Exercise Using CHR, axiomatise constraints “less than” and “minimum” Ensure logical completeness.

33 Propia and CHR Exercise Implement three constraints, 'and', 'or' and 'xor' in Propia in CHR (if you have time) The constraints are specified as follows: All boolean variables have domain [0,1]: 0 for 'false' 1 for 'true and(X,Y,Z) =def (X&Y) = Z or(X,Y,Z) =def (X or Y) = Z xor(X,Y,Z) =def ((X & -Y) or (-X & Y)) = Z

34 Testing Your Solution Suppose your constraints are called cons_and, cons_or and cons_xor Now write enter the following procedure: full_adder(I1,I2,I3,O1,O2) :- cons_xor(I1,I2,X1), cons_and(I1,I2,Y1), cons_xor(X1,I3,O1), cons_and(I3,X1,Y2), cons_or(Y1,Y2,O2). The test is : ?- full_adder(I1,I2,0,O1,1).