The Interval Constraint Solver For integer and real variables.

Slides:



Advertisements
Similar presentations
The simplex algorithm The simplex algorithm is the classical method for solving linear programs. Its running time is not polynomial in the worst case.
Advertisements

MATH 224 – Discrete Mathematics
1 Chapter 7: Controlling Search. 2 Controlling Search u Estimating Efficiency of a CLP Program u Rule Ordering u Literal Ordering u Adding Redundant Constraints.
1 Constraint Satisfaction Problems A Quick Overview (based on AIMA book slides)
1 Chapter 8: Modelling with Finite Domain Constraints Where we examine how modelling and controlling search interact with finite domain constraints.
© Imperial College London Eplex: Harnessing Mathematical Programming Solvers for Constraint Logic Programming Kish Shen and Joachim Schimpf IC-Parc.
Hybridisation Solver Cooperation in ECLiPSe. 2 Introduction  Motivation  Sending Constraints to Different Solvers  Probing  Column Generation  Motivation.
Introduction to Algorithms
Chapter 6 Linear Programming: The Simplex Method
EE 553 Integer Programming
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
Introduction to C Programming
/425 Declarative Methods - J. Eisner1 Constraint Programming.
Constraint Reasoning u Motivation u ECLiPSe - IC u ECLiPSe – propia u ECLiPSe - eplex.
Constraint Logic Programming Ryan Kinworthy. Overview Introduction Logic Programming LP as a constraint programming language Constraint Logic Programming.
1 Optimisation Although Constraint Logic Programming is somehow focussed in constraint satisfaction (closer to a “logical” view), constraint optimisation.
Introduction to Computers and Programming Lecture 4: Mathematical Operators New York University.
Approximation Algorithms
12 April 2013Lecture 2: Intervals, Interval Arithmetic and Interval Functions1 Intervals, Interval Arithmetic and Interval Functions Jorge Cruz DI/FCT/UNL.
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
ECE122 L3: Expression Evaluation February 6, 2007 ECE 122 Engineering Problem Solving with Java Lecture 3 Expression Evaluation and Program Interaction.
CS180 Recitation 3. Lecture: Overflow byte b; b = 127; b += 1; System.out.println("b is" + b); b is -128 byte b; b = 128; //will not compile! b went out.
Sandia is a multiprogram laboratory operated by Sandia Corporation, a Lockheed Martin Company, for the United States Department of Energy under contract.
1 Foundations of Interval Computation Trong Wu Phone: Department of Computer Science Southern Illinois University Edwardsville.
Dr Eleni Mangina – COURSE: LOGIC PROGRAMMING (during a joint degree with Fudan University in Software Engineering) DEPT. OF COMPUTER SCIENCE UCD LOGIC.
Introduction to C Programming
Constraint Logic Programming (CLP) Luis Tari March 10, 2005.
Intro to Robots Conditionals and Recursion. Intro to Robots Modulus Two integer division operators - / and %. When dividing an integer by an integer we.
Solver & Optimization Problems n An optimization problem is a problem in which we wish to determine the best values for decision variables that will maximize.
Non-Linear Simultaneous Equations
Fundamentals of Python: From First Programs Through Data Structures
1 Constraint Programming: An Introduction Adapted by Cristian OLIVA from Peter Stuckey (1998) Ho Chi Minh City.
12 Feb 2009MATH 1314 College Algebra Ch Quadratic Functions Objectives –Recognize characteristics of parabolas –Graph parabolas –Determine a quadratic.
Computer Science 1000 Spreadsheets II Permission to redistribute these slides is strictly prohibited without permission.
3208 Unit 2 Limits and Continuity
Linear Inequalities Foundation Part I. An INEQUALITY shows a relationship between two variables, usually x & y Examples –y > 2x + 1 –y < x – 3 –3x 2 +
3.1 Quadratic Functions Objectives
Math 002 College Algebra Final Exam Review.
1 Decision Procedures for Linear Arithmetic Presented By Omer Katz 01/04/14 Based on slides by Ofer Strichman.
1 Chapter 1 Analysis Basics. 2 Chapter Outline What is analysis? What to count and consider Mathematical background Rates of growth Tournament method.
8. Linear Programming (Simplex Method) Objectives: 1.Simplex Method- Standard Maximum problem 2. (i) Greedy Rule (ii) Ratio Test (iii) Pivot Operation.
Chapter 6 Linear Programming: The Simplex Method Section 2 The Simplex Method: Maximization with Problem Constraints of the Form ≤
Topic III The Simplex Method Setting up the Method Tabular Form Chapter(s): 4.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Set Domain Solvers. 2 ic_sets - the set constraint solver  Load the ic_sets library by using :- lib(ic_sets). at the beginning of your code, or type.
C++ Programming Language Lecture 2 Problem Analysis and Solution Representation By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
CP Summer School Modelling for Constraint Programming Barbara Smith 2. Implied Constraints, Optimization, Dominance Rules.
CMP 131 Introduction to Computer Programming Violetta Cavalli-Sforza Week 5, Lecture 1 (Monday)
Linear Program Set Cover. Given a universe U of n elements, a collection of subsets of U, S = {S 1,…, S k }, and a cost function c: S → Q +. Find a minimum.
CHAPTER 7 Systems of Equations & Inequalities. 7.1 Systems of Linear Equations in 2 Variables Objectives –Decide whether an ordered pair is a solutions.
Resource Allocation in Hospital Networks Based on Green Cognitive Radios 王冉茵
The Hashemite University Computer Engineering Department
WEEK 6 Day 1. Progress report Thursday the 11 th.
Logic Programming Lecture 9: Constraint logic programming.
1 Simplex algorithm. 2 The Aim of Linear Programming A Linear Programming model seeks to maximize or minimize a linear function, subject to a set of linear.
Chapter 2 1. Chapter Summary Sets The Language of Sets - Sec 2.1 – Lecture 8 Set Operations and Set Identities - Sec 2.2 – Lecture 9 Functions and sequences.
OPERATORS IN C CHAPTER 3. Expressions can be built up from literals, variables and operators. The operators define how the variables and literals in the.
Types CSCE 314 Spring 2016.
CSC Modeling with FD Constraints
Building Java Programs
Perturbation method, lexicographic method
Symbolic Solver.
Learning Resource Services
Building Java Programs
Building Java Programs Chapter 2
Building Java Programs
Part II General Integer Programming
Building Java Programs Chapter 2
Consistency algorithms
Presentation transcript:

The Interval Constraint Solver For integer and real variables

Outline  Introduction & general overview  Integer constraint solving  Global constraints  Reified constraints  Real interval arithmetic  Real constraint solving

Usage  Load the interval constraint library by using :- lib(ic). at the beginning of your code, or type lib(ic). at the top-level ECLiPSe prompt.

Functionality The IC library implements  variables with integer or real domains  basic equality, inequality and disequality constraints over linear and non-linear arithmetic expressions  some “global” constraints for integer variables  reified constraints  search and optimisation facilities

Interval variables  IC variables have a domain attached integer intervals : X{1..9} integer intervals with holes: Y{[2,5..7]} real intervals: Z{ } infinite intervals: W{ Inf} infinite integer intervals: V{-1.0Inf..3}

Interval variables Vars :: Domain e.g. X :: 1..9X #:: 1..9 Y :: [2,5..7]Y #:: [2,5..7] Z :: Z $:: W :: InfW $:: Inf V :: -1.0Inf..3V #:: -1.0Inf..3  Attaches an initial domain to a variable or intersects its old domain with the new one.  Type of bounds gives type of variable for :: ( 1.0Inf is considered type-neutral)  #:: always imposes integrality  $:: never imposes integrality

The basic set of constraints  X #>= Y, Y #= = Y, Y $=< Z Non-strict inequalities.  X #> Y, Y # Y, Y $< Z Strict inequalities.  X #= Y, Y #\= Z, X $= Y, Y $\= Z Equality and disequality.  X,Y,Z can be expressions + - * / ^ abs sqr exp ln sin cos min max sum...  “ # ” constraints impose integrality, “ $ ” constraints do not

Propagation behaviour  Constraints are active: ?- [X, Y] :: 1..5, X #>= Y + 1. X = X{2.. 5}, Y = Y{1.. 4} Delayed goals: ic : (-(X{2.. 5}) + Y{1.. 4} =< -1) Yes ?- [X, Y] :: 1..5, X #>= Y + 1, Y #>= 3. X = X{[4, 5]}, Y = Y{[3, 4]} Delayed goals: ic : (-(X{[4, 5]}) + Y{[3, 4]} =< -1) Yes ?- [X, Y] :: 1..5, X #>= Y + 1, Y #>= 4. X = 5, Y = 4 Yes

Basic search support  indomain(?Var) Instantiates Var to a value from its domain. Tries values from smallest to largest on backtracking. If X :: 1..3 then indomain(X) is the same as X=1 ; X=2 ; X=3  labeling(+VarList) Invokes indomain/1 on each variable in the list.  More sophisticated search covered in a later session

Exploring the search space  Trying values from the domain ?- X :: X = X{1.. 3} Yes ?- X :: 1..3, indomain(X). X = 1 More? (;) X = 2 More? (;) X = 3 Yes ?- X :: 1..2, Y :: 1..3, labeling([X,Y]). X = 1, Y = 1 More? (;) X = 1, Y = 2 More? (;) X = 1, Y = 3 More? (;) X = 2, Y = 1 More? (;) X = 2, Y = 2 More? (;) X = 2, Y = 3 Yes

Standard example sendmore(Digits) :- Digits = [S,E,N,D,M,O,R,Y], Digits :: 0..9, alldifferent(Digits), S #\= 0, M #\= 0, 1000*S + 100*E + 10*N + D *M + 100*O + 10*R + E #= 10000*M *O + 100*N + 10*E + Y, labeling(Digits). SEND + MORE = MONEY

SEND + MORE = MONEY Standard example ?- sendmore(Digits). Digits = [9, 5, 6, 7, 1, 0, 8, 2] More? (;) No = 10652

Other built-in constraints  alldifferent(+List) All elements of the list are constrained to be pairwise different.  integers(+List) All elements of the list are constrained to be integral.  reals(+List) All elements of the list are constrained to be real. (Note this doesn’t mean they can’t also be integral: this is equivalent to List :: -1.0Inf..1.0Inf.)

Modelling  Built-in constraints X #> Y  Abstraction before(task(Si,Di), task(Sj,Dj)) :- Si+Di #=< Sj.  Conjunction between(X,Y,Z) :- X #< Y, Y #< Z.  Disjunction (but see later...) neighbour(X,Y) :- ( X #= Y+1 ; Y #= X+1 ).  Iteration not_among(X, L) :- ( foreach(Y,L),param(X) do X #\= Y ).  Recursion not_among(X, []). not_among(X, [Y|Ys]) :- X #\= Y, not_among(X, Ys).

An arithmetic puzzle Is there a positive number which  when divided by 3 gives a remainder of 1;  when divided by 4 gives a remainder of 2;  when divided by 5 gives a remainder of 3; and  when divided by 6 gives a remainder of 4? (express the constraints with multiplications rather than divisions) model(X) :- X #> 0, X #= A*3 + 1, X #= B*4 + 2, X #= C*5 + 3, X #= D*6 + 4.

An arithmetic puzzle model(X) :- X #> 0, X #= A*3 + 1, X #= B*4 + 2, X #= C*5 + 3, X #= D* ?- model(X). X = X{ Inf} Delayed goals: ic:(-3*A{ Inf} + X{ Inf} =:= 1) ic:(-4*B{ Inf} + X{ Inf} =:= 2) ic:(-5*C{ Inf} + X{ Inf} =:= 3) ic:(X{ Inf} - 6*D{9..1.0Inf} =:= 4) Yes

An arithmetic puzzle ?- model(X). X = X{ Inf} Delayed goals: ic:(-3*A{ Inf} + X{ Inf} =:= 1) ic:(-4*B{ Inf} + X{ Inf} =:= 2) ic:(-5*C{ Inf} + X{ Inf} =:= 3) ic:(X{ Inf} - 6*D{9..1.0Inf} =:= 4) Yes ?- model(X), labeling([X]). X = 58 More? (;) X = 118 More? (;) X = 178 More? (;)...

N-ary constraints in lib(ic)  S #= sum(List) Sum of N variables or sub-expressions.  X #= min(List) Smallest of N variables or sub-expressions.  X #= max(List) Largest of N variables or sub-expressions.  alldifferent(List) All elements of the list are pairwise different.

Change to list variable affects maximum: ?- X :: 2..5, Y :: 3..4, Z :: 1..7, M #= max([X, Y, Z]), Y#>3. X = X{[2..5]}, Y = 4, Z = Z{[1..7]}, M = M{[4..7]} There is 1 delayed goal. Behaviour example  Initial setup ?- X :: 2..5, Y :: 3..4, Z :: 1..7, M #= max([X, Y, Z]). X = X{[2..5]}, Y = Y{[3, 4]}, Z = Z{[1..7]}, M = M{[3..7]} There is 1 delayed goal.  Change to maximum affects list variables: ?- X :: 2..5, Y :: 3..4, Z :: 1..7, M #= max([X, Y, Z]), M#<5. X = X{[2..4]}, Y = Y{[3, 4]}, Z = Z{[1..4]}, M = M{[3, 4]} There is 1 delayed goal.

Global constraints  Constraints involving many variables  Do more “global” reasoning  Based on IC primitives :- lib(ic).  Available in the libraries :- lib(ic_global). :- lib(ic_cumulative). :- lib(ic_edge_finder). :- lib(ic_edge_finder3).

Different constraint behaviours lib(ic) implementation of alldifferent/1 ?- [A,B,C]::1..3, D::1..5, ic:alldifferent([A,B,C,D]). A = A{1.. 3} B = B{1.. 3} C = C{1.. 3} D = D{1.. 5} Delayed goals: outof(A{1.. 3}, [], [B{1.. 3}, C{1.. 3}, D{1.. 5}]) outof(B{1.. 3}, [A{1.. 3}], [C{1.. 3}, D{1.. 5}]) outof(C{1.. 3}, [B{1.. 3}, A{1.. 3}], [D{1.. 5}]) outof(D{1.. 5}, [C{1.. 3}, B{1.. 3}, A{1.. 3}], []) Yes

Different constraint behaviours  lib(ic_global) implementation ?- [A,B,C] :: 1..3, D::1..5, ic_global:alldifferent([A,B,C,D]). A = A{1.. 3} B = B{1.. 3} C = C{1.. 3} D = D{[4, 5]} Delayed goals: alldifferent([A{1.. 3}, B{1.. 3}, C{1.. 3}], 1) Yes

Why is it better?  Global view enables more reasoning: D C B A Primitive constraints see only e.g A 54321D #\= alldifferent

More constraints in lib(ic_global) ( I ) alldifferent(+List, ++Capacity) declarative: No value in List occurs more than Capacity times. behaviour: Changes in the list variables affect other list variables. element(?Index, ++List, ?Value) declarative: The Index 'th element of List is equal to Value. behaviour: Changes to either Index or Value may affect the other variable.

The element/3 constraint  Defines a mapping from one variable to another: ?- element(I, [1,3,6,3,2], V). I = I{1.. 5} V = V{[1.. 3, 6]} Delayed goals: element(I{1..5}, [1, 3, 6, 3, 2], V{[1..3, 6]}) Yes ?- element(I, [1,3,6,3,2], V), V #\= 3. I = I{[1, 3, 5]} V = V{[1, 2, 6]} Delayed goals: element(I{[1, 3, 5]}, [1, 3, 6, 3, 2], V{[1, 2, 6]}) Yes

More constraints in lib(ic_global) ( II ) ordered(++Rel, +List) declarative: List is an ordered list. behaviour: Changes in the list variables affect other list variables. ordered_sum(+List, ?Sum) declarative: List is an ordered list and the sum of its elements is Sum. behaviour: Changes in the list variables affect Sum and other list variables, and vice-versa. sorted(?List, ?SortedList) declarative: SortedList is a sorted permutation of List. behaviour: Change of bounds in one list may affect the other. sorted(?List, ?SortedList, ?Positions) declarative: SortedList is a sorted permutation of List, and Positions describes how the elements are permuted. behaviour: Change of bounds in any list may affect others.

Benefits of “global view” again  Separate constraints for order and sum: ?- length(L, 3), L :: 0..20, ordered(=<, L), sum(L)#=10. L = [_1709{[0..10]}, _1722{[0..10]}, _1735{[0..10]}]  Combined constraint: ?- length(L, 3), L :: 0..20, ordered_sum(L, 10). L = [_1694{[0..3]}, _1707{[0..5]}, _1720{[4..10]}]  More inferences are possible! Remember that constraints operate locally

More constraints in lib(ic_global) ( III ) atmost(++N, +List, ++Value) declarative: At most N elements of List have value Value. behaviour: Changes in the list variables affect other list variables. occurrences(++Value, +List, ?N) declarative: Value occurs N times in List. behaviour: Changes in the list variables affect N and vice versa. lexico_le(+List1, +List2) declarative: List1 is lexicographically less than or equal to List2. behaviour: Change of bounds in one list may affect the other.

Scheduling constraints cumulative(+Starts, +Durations, +ResourceUsages, ++ResourceLimit) disjunctive(+Starts, +Durations) Same as cumulative(Starts, Durations, [1,...,1], 1) cumulative([S1,S2,S3,S4], [1,4,2,2], [1,1,3,2], 4)

Scheduling constraints - implementations  The declarative constraints cumulative(+Starts, +Durations, +ResourceUsages, ++ResourceLimit) disjunctive(+Starts, +Durations)  Three implementation variants lib(ic_cumulative) - linear algorithm on each change lib(ic_edge_finder) - quadratic algorithm lib(ic_edge_finder3) - cubic algorithm  More work, more propagation Edge-finder detects failures earlier Edge-finder gives more bound propagation

Reified constraints

Basic IC constraints revisited  X #= Y  X #>= Y  X #< Y  X #\= Y  etc. #=(X, Y) #>=(X, Y) #<(X, Y) #\=(X, Y) etc. #=(X, Y, B) #>=(X, Y, B) #<(X, Y, B) #\=(X, Y, B) etc. Boolean variables B indicate truth of constraint

Reified constraints X #> Y#>(X, Y, B) X #= Y#=(X, Y, B)  B=1 if the constraint is satisfied (entailed)  B=0 if the constraint is false (disentailed)  B{0..1} while unknown B can be set to  1 to enforce the constraint  0 to enforce its negation

Disjunctive constraints via reified constraints no_overlap(S1, D1, S2, D2) :- #>=(S2, S1+D1, B), #<(S1, S2+D2, B) B=1 B=0 2 Fail (B=0/\B=1) B{0..1}

Constraint connectives  neg C Negation of constraint C  C1 and C2 C1 and C2  C1 or C2 C1 or C2  C1 => C2 C1 implies C2 E.g. X #= 0 => Y #> 0

Embedding reified constraints  Constraints can appear in other expressions Evaluate to their reified boolean Sometimes the easiest way to reify a constraint  B #= (X #>= Y + 2)  1 #= (X1 #< Y1 + (X2 #=< Y2))  This is how the constraint connectives ( and, or, etc.) are actually implemented

Disjunctive constraints via reified constraints ( II ) Note that the following are all equivalent:  #>=(S2, S1+D1, B), #<(S1, S2+D2, B)  (S2 #>= S1+D1) #= (S1 #< S2+D2)  S2 #>= S1+D1 or S1 #>= S2+D2

Interval Arithmetic and Constraints

Interval Arithmetic  Real values often can’t be represented exactly by floating point numbers  Calculations introduce rounding errors Problems:  Is the result really a solution?  Were solutions missed?

Interval Arithmetic Solution:  Represent each real value by a pair of floating point bounds  Arithmetic performed on intervals, with appropriate rounding  A ground interval expresses that the exact real value lies somewhere between its bounds

Two kinds of intervals:  “Ground” interval Approximates a single (ground) real value Bounds never change  “Variable” interval Approximates the domain of a real variable Bounds can be updated Interval Arithmetic

Problem:  Arithmetic comparison now only partial  E.g. is 0.12__0.16 = 0.13__0.15? > ? < ? Solution:  Leave incomparable comparisons as delayed goals  Presence of delayed goals indicates that the solution is a “candidate” only  User decides if delayed goals indicate a problem

The bounded real data type  Written lwb__upb, where lwb and upb are the lower and upper floating point bounds, respectively (e.g. 0.12__0.16)  Not usually entered directly: normally occur as result of computation  breal/1 tests whether a term is a bounded real  breal/2 converts other numeric types to bounded reals  breal_min/2, breal_max/2 and breal_bounds/3 can be used to obtain the floating point bounds of a bounded real

The bounded real data type ?- X is sqrt(breal(2)). X = __ Yes ?- Y is float(1) / 10, X is Y + Y + Y + Y + Y + Y + Y + Y + Y + Y. X = Y = 0.1 Yes ?- Y is breal(1) / 10, X is Y + Y + Y + Y + Y + Y + Y + Y + Y + Y. X = __ Y = __ Yes

Working with Bounded Reals  Take care with arithmetic comparisons if arguments might be bounded reals E.g. X > 0, X =:= 0, etc. will leave delayed goals behind if X spans 0  Decide what should happen and design tests appropriately E.g. X > 0, not X = 0 are equivalent for most numeric types, but do different things for bounded reals

IC for real variables  IC’s general constraints ( $=/2, $=</2, etc.) work for: real variables integer variables a mix of both  Propagation is performed using safe arithmetic  Integrality preserved where possible

Propagation behaviour ( I )  For integers, just like integer constraints: ?- [X, Y] :: 1..5, X $>= Y + 1. X = X{2.. 5}, Y = Y{1.. 4} Delayed goals: ic : (-(X{2.. 5}) + Y{1.. 4} =< -1) Yes ?- [X, Y] :: 1..5, X $>= Y + 1, Y $>= 3. X = X{[4, 5]}, Y = Y{[3, 4]} Delayed goals: ic : (-(X{[4, 5]}) + Y{[3, 4]} =< -1) Yes ?- [X, Y] :: 1..5, X $>= Y + 1, Y $>= 4. X = 5, Y = 4 Yes

Propagation behaviour ( II )  For reals, uses safe arithmetic: ?- [X, Y] :: , X $>= Y + 1. X = X{ } Y = Y{ } Delayed goals: ic : (-(X{ }) + Y{ } =< -1) Yes ?- [X, Y] :: , X $>= Y + 1, Y $>= 3. X = X{ } Y = Y{ } Delayed goals: ic : (-(X{ }) + Y{ } =< -1) Yes

Propagation behaviour ( III )  Variables don’t usually end up ground: ?- [X, Y] :: , X $>= Y + 1, Y $>= 4. X = X{ } Y = Y{ } Delayed goals: ic : (-(X{ }) + Y{ } =< -1 Yes

Solving real constraints  IC provides two methods for solving real constraints  locate/2,3 good when there are a finite number of discrete solutions Works by splitting domains  squash/3 good for refining bounds on a continuous feasible region Works by trying to prove parts of domains infeasible

Using locate  Find the intersection of two circles ?- 4 $= X^2 + Y^2, 4 $= (X - 1)^2 + (Y - 1)^2). X = X{ } Y = Y{ } There are 12 delayed goals. Yes

Using locate ?- 4 $= X^2 + Y^2, 4 $= (X - 1)^2 + (Y – 1)^2, locate([X, Y], 1e-5). X = X{ } Y = Y{ } There are 12 delayed goals. More ? ; X = X{ } Y = Y{ } There are 12 delayed goals. Yes

Using squash  Find the intersection of two discs and a half-plane ?- 4 $>= X^2 + Y^2, 4 $>= (X - 1)^2 + (Y – 1)^2, Y $>= X. Y = Y{ } X = X{ } There are 13 delayed goals. Yes

Using squash ?- 4 $>= X^2 + Y^2, 4 $>= (X - 1)^2 + (Y – 1)^2, Y $>= X, squash([X, Y], 1e-5, lin). X = X{ } Y = Y{ } There are 13 delayed goals. Yes

IC Example (modelling, abstraction) A C B 7 George is contemplating buying a farm which is a very strange shape, comprising a large triangular lake with a square field on each side.  The area of the lake is exactly seven acres.  The area of each field is an exact whole number of acres. What is the smallest possible total area of the three fields?

IC Example - Model farm(F, A, B, C) :- [A, B, C] :: Inf, % The 3 sides of the lake triangle_area(A, B, C, 7), % The lake area is 7 [F, FA, FB, FC] :: Inf, % The square areas are integral square_area(A, FA), square_area(B, FB), square_area(C, FC), F #= FA+FB+FC, % Avoid symmetric solutions FA $>= FB, FB $>= FC. A C B 7

IC Example - Abstraction triangle_area(A, B, C, Area) :- S $>= 0, S $= (A+B+C)/2, Area $= sqrt(S*(S-A)*(S-B)*(S-C)). square_area(A, Area) :- Area $= sqr(A). A C B 7

IC Example - Search solve(F, A, B, C) :- farm(F, A, B, C), % the model indomain(F), % ensure that solution is minimal locate([A, B, C], 0.01). ?- solve(F, A, B, C). F = 50 A = A{ } B = B{ } C = C{ } There are 23 delayed goals. More? A C B 7

A PERT problem (1)  Schedule a project in minimal time respect precedence constraints (some jobs can only start after certain others are finished)  Data NameDurAfter Amasonry7- Bcarpentry3A Croof1B Dinstallations8A E front2D,C Fwindows1D,C Ggarden1D,C Hceiling2F Jpainting1H Kmoving in1E,G,J

A PERT problem (2) Get the file Tutorial/Exercises/fd3.pl  understand the data structure given  write the model / constraint setup code  run the setup code and observe propagation  add code to make a simple list of start times  add code to label the start times  use min_max/2 to prove optimality  print a table of task names and start times

More search support  Refer to later session  deleteff(-Var, +List, -RestList) pick element with smallest domain from List.  deleteffc(-Var, +List, -RestList) pick element with smallest domain which is involved in the largest number of constraints.  deletemin(-Var, +List, -RestList) pick element with lowest value in its domain.

Exercises  Try the SEND+MORE=MONEY problem for yourself  Try the exercises from “Getting Started with Interval Constraints” in the tutorial manual (section 8.9 in my copy, on page 84 (+10))  Try the first search exercise  Look at “Working with Real Numbers and Variables” (chapter 9) in the tutorial manual