Constraint Logic Programming (CLP) Luis Tari March 10, 2005.

Slides:



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

CICLOPS 2001 Finite Domain Constraints in SICStus Prolog Mats Carlsson Swedish Institute of Computer Science
Modelling with Finite Domains u Domains and Labelling u Complex Constraints u Labelling u Different Problem Modellings u Efficiency u Using SICStus Prolog.
Course Summary What have we learned and what are we expected to know?
Logic Programming Lecture 9: Constraint logic programming.
1 CMSC 471 Fall 2002 Class #6 – Wednesday, September 18.
Introduction. IC-Parc2 ECLiPSe Components Constraint Logic Programming system, consisting of  A runtime core Data-driven computation, backtracking, garbage.
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:
ICS-271:Notes 5: 1 Lecture 5: Constraint Satisfaction Problems ICS 271 Fall 2008.
1 Chapter 8: Modelling with Finite Domain Constraints Where we examine how modelling and controlling search interact with finite domain constraints.
DMOR Branch and bound. Integer programming Modelling logical constraints and making them linear: – Conjuction – Disjunction – Implication – Logical constraints.
Iterative Deepening A* & Constraint Satisfaction Problems Lecture Module 6.
Counting the bits Analysis of Algorithms Will it run on a larger problem? When will it fail?
Answer Set Programming Overview Dr. Rogelio Dávila Pérez Profesor-Investigador División de Posgrado Universidad Autónoma de Guadalajara
CPSC 422, Lecture 21Slide 1 Intelligent Systems (AI-2) Computer Science cpsc422, Lecture 21 Mar, 4, 2015 Slide credit: some slides adapted from Stuart.
Constraint Processing and Programming Introductory Exemple Javier Larrosa.
Branch & Bound Algorithms
/425 Declarative Methods - J. Eisner1 Constraint Programming.
Best-First Search: Agendas
CS 330 Programming Languages 12 / 12 / 2006 Instructor: Michael Eckmann.
For Friday Read “lectures” 1-5 of Learn Prolog Now: prolog-now/
Modular Answer Set Programming. Introduction One common answer set programming (ASP) methodology is to: Encode the problem Enumerate possible solutions.
Programming with Constraints Jia-Huai You. Subject of Study Constraint Programming (CP) studies the computational models, languages, and systems for solving.
1 Optimisation Although Constraint Logic Programming is somehow focussed in constraint satisfaction (closer to a “logical” view), constraint optimisation.
16/23/2015 9:48 AM6/23/2015 9:48 AM6/23/2015 9:48 AMRecursion Recursion Recursion is when a function calls itself to implement an algorithm. Really a paradigm.
Search in the semantic domain. Some definitions atomic formula: smallest formula possible (no sub- formulas) literal: atomic formula or negation of an.
1 Predicates and quantifiers Chapter 8 Formal Specification using Z.
Last time Proof-system search ( ` ) Interpretation search ( ² ) Quantifiers Equality Decision procedures Induction Cross-cutting aspectsMain search strategy.
Constraint Satisfaction Problem Solving Chapter 5.
Branch and Bound Algorithm for Solving Integer Linear Programming
Constraint Programming An Appetizer Christian Schulte Laboratory of Electronics and Computer Systems Institute of Microelectronics.
Dr Eleni Mangina – COURSE: LOGIC PROGRAMMING (during a joint degree with Fudan University in Software Engineering) DEPT. OF COMPUTER SCIENCE UCD LOGIC.
How to Play Sudoku & Win Integer Programming Formulation of a Popular Game Sven LeyfferSven Leyffer, Argonne, Feb. 15, 2005 (windoze powerpoint sumi painting.
1 Constraint Programming: An Introduction Adapted by Cristian OLIVA from Peter Stuckey (1998) Ho Chi Minh City.
CP Summer School Modelling for Constraint Programming Barbara Smith 1.Definitions, Viewpoints, Constraints 2.Implied Constraints, Optimization,
1 Constraint Satisfaction and Backtrack Search 22c:31 Algorithms.
CONSTRAINT PROGRAMMING Computer Science Seminar April 9 th, 2004 Kerem Kacel.
Types of IP Models All-integer linear programs Mixed integer linear programs (MILP) Binary integer linear programs, mixed or all integer: some or all of.
Constraint Satisfaction Problems (CSPs) CPSC 322 – CSP 1 Poole & Mackworth textbook: Sections § Lecturer: Alan Mackworth September 28, 2012.
Modelling for Constraint Programming Barbara Smith CP 2010 Doctoral Programme.
Lecture 9: Constraint logic programming
Constraint Satisfaction Read Chapter 5. Model Finite set of variables: X1,…Xn Variable Xi has values in domain Di. Constraints C1…Cm. A constraint specifies.
Constraint Satisfaction CPSC 386 Artificial Intelligence Ellen Walker Hiram College.
Exact and heuristics algorithms
1 Outline:  Optimization of Timed Systems  TA-Modeling of Scheduling Tasks  Transformation of TA into Mixed-Integer Programs  Tree Search for TA using.
Advanced Algorithm Design and Analysis (Lecture 14) SW5 fall 2004 Simonas Šaltenis E1-215b
Integer Programming Li Xiaolei. Introduction to Integer Programming An IP in which all variables are required to be integers is called a pure integer.
Branch-and-Cut Valid inequality: an inequality satisfied by all feasible solutions Cut: a valid inequality that is not part of the current formulation.
Chapter 5 Constraint Satisfaction Problems
1 Lic Presentation Memory Aware Task Assignment and Scheduling for Multiprocessor Embedded Systems Radoslaw Szymanek / Embedded System Design
Divide and Conquer Optimization problem: z = max{cx : x  S}
Constraints and Search Toby Walsh Cork Constraint Computation Centre (4C) Logic & AR Summer School, 2002.
Chapter 2) CSP solving-An overview Overview of CSP solving techniques: problem reduction, search and solution synthesis Analyses of the characteristics.
CPSC 422, Lecture 21Slide 1 Intelligent Systems (AI-2) Computer Science cpsc422, Lecture 21 Oct, 30, 2015 Slide credit: some slides adapted from Stuart.
Problem Reduction So far we have considered search strategies for OR graph. In OR graph, several arcs indicate a variety of ways in which the original.
Arc consistency AC5, AC2001, MAC. AC5 A generic arc-consistency algorithm and its specializations AIJ 57 (2-3) October 1992 P. Van Hentenryck, Y. Deville,
Branch and Bound Algorithms Present by Tina Yang Qianmei Feng.
Logic: Proof procedures, soundness and correctness CPSC 322 – Logic 2 Textbook §5.2 March 7, 2011.
CSCE350 Algorithms and Data Structure Lecture 21 Jianjun Hu Department of Computer Science and Engineering University of South Carolina
For Friday No reading Prolog Handout 2. Homework.
Logical Agents Chapter 7. Outline Knowledge-based agents Propositional (Boolean) logic Equivalence, validity, satisfiability Inference rules and theorem.
Introduction to Integer Programming Integer programming models Thursday, April 4 Handouts: Lecture Notes.
Logic Programming Lecture 9: Constraint logic programming.
1 Chapter 5 Branch-and-bound Framework and Its Applications.
Automatic Test Generation
CSC Modeling with FD Constraints
Semantic and Declarative Technologies AIT Budapest
Constraint Satisfaction
Chapter 1. Formulations.
Presentation transcript:

Constraint Logic Programming (CLP) Luis Tari March 10, 2005

Why CLP? “Generate-and-test” approach is a common methodology for logic programming. –Generate possible solutions –Test and eliminate non-solutions Disadvantages of “generate-and-test” approach: –Passive use of constraints to test potential values –Inefficient for combinatorial search problems CLP languages use the global search paradigm. –Actively pruning the search space –Recursively dividing a problem into subproblems until its subproblems are simple enough to be solved

Why CLP and AnsProlog? AnsProlog is inefficient in dealing with numerical values, due to –Implementation of the current solvers –“generate-and-test” paradigm Goal of CLP is to pick numerical values from pre-defined domains for certain variables so that the given constraints on the variables are all satisfied. Idea: use CLP to define and reason with numerical constraints and assignments

List Notation in Prolog Example of list notation –[eggs, tea, milk, steak, spinach, toothpaste] Head of a list –First element of a list –eggs Tail of a list –The remaining list apart from the head –[tea, milk, steak, spinach, toothpaste] [H|T] –H = eggs –T = [tea, milk, steak, spinach, toothpaste]

An example of List Use the predicate append to define appending two lists into one. append([X|XL],YL,[X|ZL]) :- append(XL,YL,ZL). append([],YL,YL). ?- append([1],[2],X). X = [1,2]

CLP with Sicstus Prolog To invoke the CLP library: | ?- :- use_module(library(clpfd)). A constraint is called as if it is a Prolog predicate. | ?- X in 1..5, Y in 2..8, X+Y #= T. X in 1..5, Y in 2..8, T in The above constraint says that given X,Y, assign values for T so that the constraint is satisfiable. | ?- X in 1..5, T in 3..13, X+Y #= T. X in 1..5, T in 3..13, Y in

Typical Steps of a CLP Program Step 1. Declare the domains of the variables Step 2. Post the problem constraints Step 3. Look for a feasible solution via backtrack search, or look for an optimal solution via branch-and-bound search

Constraint Satisfaction Problem Let’s consider the Send More Money puzzle. The variables are the letters S, E, N, D, M, O, R and Y. Each letter represents a digit between 0 and 9. Assign a value to each digit, such that SEND + MORE equals MONEY.

Send More Money Example using CLP | ?- mm([S,E,N,D,M,O,R,Y], []). D = 7, E = 5, M = 1, N = 6, O = 0, R = 8, S = 9, Y = 2

Reified Constraints To reflect its truth value into a 0/1 variable B, so that: –The constraint is posted if B is set to 1 –The negation of the constraint is posted if B is set to 0 –B is set to 1 if the constraint becomes entailed –B is set to 0 if the constraint becomes disentailed. A reified constraint is written as: | ?- Constraint # B.

An example using reified constraint Define exactly(X,L,N) so that it is true if X occurs exactly N times in the list L. If the constraint “element X is the same as element Y” becomes entailed, then assign B to be 1 else 0.

Other Constraints Arithmetic constraints –| ?- X in 1..2, Y in 3..5, X#= B. B = 1, X in 1..2, Y in 3..5 –If the constraint “value in X is <= value in Y” becomes entailed, then assign B to be 1 else 0. Propositional constraints –X #= 4 #\/ Y #= 6 –Disjunction of the two equality constraints Many more….

Defining Search Variants labeling(:Options, +Variables) –Where Variables is a list of domain variables or integers and Options is a list of search options. | ?- constraints(Variables), labeling([], Variables). %same as [leftmost,step,up,all] –leftmost : the leftmost variable is selected –step : makes a binary choice between X#=B and X#\=B, where B is the lower or upper bound of X. –up : the domain is explored in ascending order –all : all solutions are enumerated by backtracking

An Example - Cumulative Scheduling There are 7 tasks where each task has a fixed duration and a fixed amount of used resource. Goal: find a schedule that minimizes the completion time for the schedule while not exceeding the capacity 13 of the resource.

Cumulative Scheduling (2) :- use_module(library(clpfd)). :- use_module(library(lists), [append/3]). schedule(Ss, End) :- length(Ss, 7), Ds=[16,6,13,7,5,18,4], Rs=[2,9,3,7,10,1,11], domain(Ss, 1, 30), domain([End], 1, 50), after(Ss, Ds, End), cumulative(Ss, Ds, Rs, 13), append(Ss, [End], Vars), labeling([minimize(End)], Vars). after([], [], _). after([S|Ss], [D|Ds], E) :- E #>= S+D, after(Ss, Ds, E). Constraining the tasks such that for each task j has a start time Ss j, a duration Ds j, and a resource Rs j, so that the total resource consumption does not exceed 13 at any time. Find an assignment that minimizes the domain variable of Vars

Cumulative Scheduling (3) Ds = [16,6,13,7, 5,18,4] Rs = [2,9, 3,7,10, 1,11] Capacity = 13 | ?- schedule(Ss, End). Ss = [1,17,10,10,5,5,1], End = 23

References Sicstus Prolog Manual Version 3.12, Chapter 34 on Constraint Logic Programming over Finite Domains P. Van Hentenryck, H. Simonis, M. Dincbas, Constraint satisfaction using constraint logic programming, Journal of Artif. Intell., 58(1-3), pages , 1992.