1 Constraint Programming Maurizio Gabbrielli Universita’ di Bologna Slides by: K. Marriott.

Slides:



Advertisements
Similar presentations
Type Inference David Walker COS 320. Criticisms of Typed Languages Types overly constrain functions & data polymorphism makes typed constructs useful.
Advertisements

1 Chapter 4:Constraint Logic Programs Where we learn about the only programming concept rules, and how programs execute.
SMT Solvers (an extension of SAT) Kenneth Roe. Slide thanks to C. Barrett & S. A. Seshia, ICCAD 2009 Tutorial 2 Boolean Satisfiability (SAT) ⋁ ⋀ ¬ ⋁ ⋀
1 Constraint Satisfaction Problems A Quick Overview (based on AIMA book slides)
1 Finite Constraint Domains. 2 u Constraint satisfaction problems (CSP) u A backtracking solver u Node and arc consistency u Bounds consistency u Generalized.
Dana Nau: Lecture slides for Automated Planning Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike License:
1 Constraint operations: Simplification, Optimization and Implication.
1 Chapter 2: Simplification, Optimization and Implication Where we learn more fun things we can do with constraints.
Situation Calculus for Action Descriptions We talked about STRIPS representations for actions. Another common representation is called the Situation Calculus.
Chapter 1 Section 3 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
ML: a quasi-functional language with strong typing Conventional syntax: - val x = 5; (*user input *) val x = 5: int (*system response*) - fun len lis =
Algebra Problems… Solutions Algebra Problems… Solutions © 2007 Herbert I. Gross Set 22 By Herbert I. Gross and Richard A. Medeiros next.
CPSC 322, Lecture 19Slide 1 Propositional Logic Intro, Syntax Computer Science cpsc322, Lecture 19 (Textbook Chpt ) February, 23, 2009.
Constraint Logic Programming Ryan Kinworthy. Overview Introduction Logic Programming LP as a constraint programming language Constraint Logic Programming.
ML: a quasi-functional language with strong typing Conventional syntax: - val x = 5; (*user input *) val x = 5: int (*system response*) - fun len lis =
Catriel Beeri Pls/Winter 2004/5 type reconstruction 1 Type Reconstruction & Parametric Polymorphism  Introduction  Unification and type reconstruction.
1 Chapter 1: Constraints What are they, what do they do and what can I use them for.
Search in the semantic domain. Some definitions atomic formula: smallest formula possible (no sub- formulas) literal: atomic formula or negation of an.
Type Inference David Walker COS 441. Criticisms of Typed Languages Types overly constrain functions & data polymorphism makes typed constructs useful.
Last time Proof-system search ( ` ) Interpretation search ( ² ) Quantifiers Equality Decision procedures Induction Cross-cutting aspectsMain search strategy.
Type Inference David Walker CS 510, Fall Criticisms of Typed Languages Types overly constrain functions & data polymorphism makes typed constructs.
Sebastian Bitzer Seminar Constraint Logic Programming University of Osnabrueck November 11 th 2002 The Simplex Algorithm.
Linear Systems The definition of a linear equation given in Chapter 1 can be extended to more variables; any equation of the form for real numbers.
Introduction Information in science, business, and mathematics is often organized into rows and columns to form rectangular arrays called “matrices” (plural.
SAT Solver Math Foundations of Computer Science. 2 Boolean Expressions  A Boolean expression is a Boolean function  Any Boolean function can be written.
1 Constraint Programming: An Introduction Adapted by Cristian OLIVA from Peter Stuckey (1998) Ho Chi Minh City.
Systems of Linear Equation and Matrices
CSE583: Programming Languages David Notkin 22 February David Notkin 22.
SAT and SMT solvers Ayrat Khalimov (based on Georg Hofferek‘s slides) AKDV 2014.
AITI Lecture 20 Trees, Binary Search Trees Adapted from MIT Course 1.00 Spring 2003 Lecture 28 and Tutorial Note 10 (Teachers: Please do not erase the.
Chapter 4.1 Solving Systems of Linear Equations in two variables.
1 Automatic Refinement and Vacuity Detection for Symbolic Trajectory Evaluation Orna Grumberg Technion Haifa, Israel Joint work with Rachel Tzoref.
Variables Tutorial 3c variable A variable is any symbol that can be replaced with a number to solve a math problem. An open sentence has at least one.
INTRODUCTION TO ARTIFICIAL INTELLIGENCE COS302 MICHAEL L. LITTMAN FALL 2001 Satisfiability.
Slide Copyright © 2012 Pearson Education, Inc.
Copyright © Cengage Learning. All rights reserved. 4 Quadratic Functions.
Week 10Complexity of Algorithms1 Hard Computational Problems Some computational problems are hard Despite a numerous attempts we do not know any efficient.
Equations, Inequalities, and Mathematical Models 1.2 Linear Equations
1 © 2010 Pearson Education, Inc. All rights reserved © 2010 Pearson Education, Inc. All rights reserved Chapter 1 Equations and Inequalities.
Daniel Kroening and Ofer Strichman 1 Decision Procedures An Algorithmic Point of View BDDs.
LDK R Logics for Data and Knowledge Representation PL of Classes.
Propositional Calculus CS 270: Mathematical Foundations of Computer Science Jeremy Johnson.
LDK R Logics for Data and Knowledge Representation Propositional Logic: Reasoning First version by Alessandro Agostini and Fausto Giunchiglia Second version.
Chapter 1 Section 3. Objectives 1 Copyright © 2012, 2008, 2004 Pearson Education, Inc. Evaluate algebraic expressions, given values for the variables.
1.6. DEFINITIONS  An equation is a statement that two expressions are equal.  Usually contains 1 or more variables  A variable is a symbol that represents.
1 Chapter 3: Finite Constraint Domains Where we meet the simplest and yet most difficult constraints, and some clever and not so clever ways to solve them.
1 Knowledge Based Systems (CM0377) Lecture 6 (last modified 20th February 2002)
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
Daniel Kroening and Ofer Strichman Decision Procedures An Algorithmic Point of View Deciding Combined Theories.
Types and Programming Languages Lecture 14 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Daniel Kroening and Ofer Strichman 1 Decision Procedures An Algorithmic Point of View Basic Concepts and Background.
Solving Equations with Variable on Both Sides Objective: Students will solve equations with variables on both sides. Section 3.4.
Metalogic Soundness and Completeness. Two Notions of Logical Consequence Validity: If the premises are true, then the conclusion must be true. Provability:
Dana Nau: Lecture slides for Automated Planning Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike License:
Identities, Contradictions and Conditional Equations.
Solving Equations With Variables on Both Sides Section 2-4.
1 Chapter 1: Constraints What are they, what do they do and what can I use them for.
CS5205: Foundation in Programming Languages Type Reconstruction
Chapter 2: Simplification, Optimization and Implication
What are they, what do they do and what can I use them for.
P & NP.
Chapter 7 Rational Expressions
Optimization Problems
Chapter 2: Simplification, Optimization and Implication
ML: a quasi-functional language with strong typing
Propositional Calculus: Boolean Algebra and Simplification
CSCI1600: Embedded and Real Time Software
Chapter 3: Finite Constraint Domains
Chapter 1 Section 3.
2 Equations, Inequalities, and Applications.
Presentation transcript:

1 Constraint Programming Maurizio Gabbrielli Universita’ di Bologna Slides by: K. Marriott

2 Overview u Constraints (what they are) u Constraint solvers u Finite constraints domains: CSP u Constraint Logic Programming u Modeling with Constraints u Practical problems

3 Overview: part 2 u Concurrent constraint programming (ccp) u Timed extensions of ccp (tccp) u A proof system for (timed) ccp u Expressive power u Constraint Handling Rules (CHR)

4 Constraints u What are constraints? u Modelling problems u Constraint solving u Tree constraints u Other constraint domains u Properties of constraint solving

5 Constraints Variable: a place holder for values Function Symbol: mapping of values to values Relation Symbol: relation between values

6 Constraints Primitive Constraint: constraint relation with arguments Constraint: conjunction of primitive constraints (full FOL formula in some cases)

7 Satisfiability Valuation: an assignment of values (of a suitable domain) to variables Solution: valuation which satisfies constraint

8 Satisfiability Satisfiable: constraint has a solution Unsatisfiable: constraint does not have a solution satisfiable unsatisfiable

9 Constraints as Syntax u Constraints are strings of symbols u Brackets don't matter (don't use them) u Order does matter (!, so not really FOL) u Some algorithms will depend on order

10 Equivalent Constraints Two different constraints can represent the same information Two constraints are equivalent if they have the same set of solutions

11 Modelling with constraints u Constraints describe idealized behaviour of objects in the real world

12 Modelling with constraints start foundations interior walls exterior walls chimney roof doors tiles windows

13 Constraint Satisfaction u Given a constraint C two questions u satisfaction: does it have a solution? u solution: give me a solution, if it has one? u The first is more basic u A constraint solver answers the satisfaction problem

14 Constraint Satisfaction u How do we answer the question? u Simple approach try all valuations.

15 Constraint Satisfaction u The enumeration method wont work for Reals (why not?) u A smarter version will be used for finite domain constraints u How do we solve Real constraints u Remember Gauss-Jordan elimination from high school

16 Gauss-Jordan elimination u Choose an equation c from C u Rewrite c into the form x = e u Replace x everywhere else in C by e u Continue until u all equations are in the form x = e u or an equation is equivalent to d = 0 (d != 0) u Return true in the first case else false

17 Gauss-Jordan Example 1 Replace X by 2Y+Z-1 Replace Y by -1 Return false

18 Gauss-Jordan Example 2 Replace X by 2Y+Z-1 Replace Y by -1 Solved form : constraints in this form are satisfiable

19 Solved Form u Non-parametric variable: appears on the left of one equation. u Parametric variable: appears on the right of any number of equations. u Solution: choose parameter values and determine non-parameters

20 Tree Constraints u Tree constraints represent structured data u Tree constructor: character string u cons, node, null, widget, f u Constant: constructor or number u Tree: u A constant is a tree u A constructor with a list of > 0 trees is a tree u Drawn with constructor above children

21 Tree Examples order(part(77665, widget(red, moose)), quantity(17), date(3, feb, 1994)) cons(red,cons(blue,con s(red,cons(…))))

22 Tree Constraints u Height of a tree: u a constant has height 1 u a tree with children t1, …, tn has height one more than the maximum of trees t1,…,tn u Finite tree: has finite height u Examples: height 4 and height

23 Terms u A term is a tree with variables replacing subtrees u Term: u A constant is a term u A variable is a term u A constructor with a list of > 0 terms is a term u Drawn with constructor above children u Term equation: s = t (s,t terms)

24 Term Examples order(part(77665, widget(C, moose)), Q, date(3, feb, Y)) cons(red,cons(B,cons(r ed,L)))

25 Tree Constraint Solving u Assign trees to variables so that the terms are identical u cons(R, cons(B, nil)) = cons(red, L) u Similar to Gauss-Jordan u Starts with a set of term equations C and an empty set of term equations S u Continues until C is empty or it returns false

26 Tree Constraint Solving u unify u unify(C) u Remove equation c from C u case x=x: do nothing u case f(s1,..,sn)=g(t1,..,tn): return false u case f(s1,..,sn)=f(t1,..,tn): u add s1=t1,.., sn=tn to C u case t=x (x variable): add x=t to C u case x=t (x variable): add x=t to S u substitute t for x everywhere else in C and S

27 Tree Solving Example CS Like Gauss-Jordan, variables are parameters or non-parameters. A solution results from setting parameters (I.e T) to any value.

28 One extra case u Is there a solution to X = f(X) ? u NO! u if the height of X in the solution is n u then f(X) has height n+1 u Occurs check: u before substituting t for x u check that x does not occur in t

29 Other Constraint Domains u There are many u Boolean constraints u Sequence constraints u Blocks world u Many more, usually related to some well understood mathematical structure

30 Boolean Constraints Used to model circuits, register allocation problems, etc. An exclusive or gate Boolean constraint describing the xor circuit

31 Boolean Constraints Constraint modelling the circuit with faulty variables Constraint modelling that only one gate is faulty Observed behaviour: Solution:

32 Boolean Solver let m be the number of primitive constraints in C for i := 1 to n do generate a random valuation over the variables in C if the valuation satisfies C then return true endif endfor return unknown

33 Boolean Constraints u Something new? u The Boolean solver can return unknown u It is incomplete (doesnt answer all questions) u It is polynomial time, where a complete solver is exponential (unless P = NP) u Still such solvers can be useful!

34 Blocks World Constraints Objects in the blocks world can be on the floor or on another object. Physics restricts which positions are stable. Primitive constraints are e.g. red(X), on(X,Y), not_sphere(Y). floor Constraints don't have to be mathematical

35 Blocks World Constraints A solution to a Blocks World constraint is a picture with an annotation of which variable is which block Y X Z

36 Solver Definition u A constraint solver is a function solv which takes a constraint C and returns true, false or unknown depending on whether the constraint is satisfiable u if solv(C) = true then C is satisfiable u if solv(C) = false then C is unsatisfiable

37 Properties of Solvers u We desire solvers to have certain properties u well-behaved: u set based: answer depends only on set of primitive constraints u monotonic: is solver fails for C1 it also fails for C1 /\ C2 u variable name independent: the solver gives the same answer regardless of names of vars

38 Properties of Solvers u The most restrictive property we can ask u complete: A solver is complete if it always answers true or false. (never unknown)

39 Constraints Summary u Constraints are pieces of syntax used to model real world behaviour u A constraint solver determines if a constraint has a solution u Real arithmetic and tree constraints u Properties of solver we expect (well- behavedness)