Constraint Logic Programming

Similar documents
CONSTRAINT LOGIC PROGRAMMING. Ivan Bratko Faculty of Computer and Information Sc. University of Ljubljana Slovenia

So let us begin our quest to find the holy grail of real analysis.

Goals of the Unit. spm adolfo villafiorita - introduction to software project management

7 Relations and Functions

Priori ty

Y. Xiang, Constraint Satisfaction Problems

Essential Thinking. Introduction to Constraint Programming Example Problems IV

1 if 1 x 0 1 if 0 x 1

Random Map Generator v1.0 User s Guide

Module 11. Software Project Planning. Version 2 CSE IIT, Kharagpur

MA107 Precalculus Algebra Exam 2 Review Solutions

Introduction & Overview

Properties of Real Numbers

4/1/2017. PS. Sequences and Series FROM 9.2 AND 9.3 IN THE BOOK AS WELL AS FROM OTHER SOURCES. TODAY IS NATIONAL MANATEE APPRECIATION DAY

Higher Education Math Placement

Answer Key for California State Standards: Algebra I

Patterns in Pascal s Triangle

Optimization Modeling for Mining Engineers

Mathematics. Mathematical Practices

CCSS Mathematics Implementation Guide Grade First Nine Weeks

Discuss the size of the instance for the minimum spanning tree problem.

Math Review. for the Quantitative Reasoning Measure of the GRE revised General Test

MTH 092 College Algebra Essex County College Division of Mathematics Sample Review Questions 1 Created January 17, 2006

Undergraduate Notes in Mathematics. Arkansas Tech University Department of Mathematics

Module1. x y 800.

Project and Production Management Prof. Arun Kanda Department of Mechanical Engineering Indian Institute of Technology, Delhi

Current Standard: Mathematical Concepts and Applications Shape, Space, and Measurement- Primary

A study of cash flows in projects with fuzzy activity durations

Florida Math Correlation of the ALEKS course Florida Math 0028 to the Florida Mathematics Competencies - Upper

To draw a line. To create a construction line by specifying two points

Solve addition and subtraction word problems, and add and subtract within 10, e.g., by using objects or drawings to represent the problem.

KLMLean 2.0: A Theorem Prover for KLM Logics of Nonmonotonic Reasoning

Cost Model: Work, Span and Parallelism. 1 The RAM model for sequential computation:

CHAPTER 1. Basic Concepts on Planning and Scheduling

MARATHWADA INSTITUTE OF TECHNOLOGY, AURANGABAD

MECH 896 Professional Development for MEng Students. Homework Discussion. Scheduling Overview. Winter 2015: Lecture #5 Project Time Management

11 November

PARAMETRIC MODELING. David Rosen. December By carefully laying-out datums and geometry, then constraining them with dimensions and constraints,

1. Prove that the empty set is a subset of every set.

Lecture 26 CPM / PERT Network Diagram

SYSM 6304: Risk and Decision Analysis Lecture 5: Methods of Risk Analysis

5 INTEGER LINEAR PROGRAMMING (ILP) E. Amaldi Fondamenti di R.O. Politecnico di Milano 1

Project Planning and Scheduling

Communication Diagrams

God created the integers and the rest is the work of man. (Leopold Kronecker, in an after-dinner speech at a conference, Berlin, 1886)

Artificial Intelligence

A numerically adaptive implementation of the simplex method

Complexity Theory. IE 661: Scheduling Theory Fall 2003 Satyaki Ghosh Dastidar

Common Core Unit Summary Grades 6 to 8

Scheduling Shop Scheduling. Tim Nieberg

Big Data Analytics CSCI 4030

Math. MCC6.RP.1 Understand the concept of a ratio and use

ModuMath Basic Math Basic Math Naming Whole Numbers Basic Math The Number Line Basic Math Addition of Whole Numbers, Part I

Chapter 4. Applying Linear Functions

Basic CPM Calculations

COMPETENCY TEST SAMPLE TEST. A scientific, non-graphing calculator is required for this test. C = pd or. A = pr 2. A = 1 2 bh

Ant Colony Optimization and Constraint Programming

The Fibonacci Sequence and the Golden Ratio

Linear Programming. March 14, 2014

Software Engineering. Pert and Gantt exercises. Lecturer: Giuseppe Santucci

Lecture 3. Linear Programming. 3B1B Optimization Michaelmas 2015 A. Zisserman. Extreme solutions. Simplex method. Interior point method

Max Flow, Min Cut, and Matchings (Solution)

Prentice Hall Mathematics: Course Correlated to: Arizona Academic Standards for Mathematics (Grades 6)

Algorithm Design and Analysis Homework #1 Due: 5pm, Friday, October 4, 2013 TA === Homework submission instructions ===

. Address the following issues in your solution:

6.045: Automata, Computability, and Complexity Or, Great Ideas in Theoretical Computer Science Spring, Class 4 Nancy Lynch

PES Institute of Technology-BSC QUESTION BANK

Traffic Engineering Management Concepts

Florida Math Correlation of the ALEKS course Florida Math 0018 to the Florida Mathematics Competencies - Lower

So today we shall continue our discussion on the search engines and web crawlers. (Refer Slide Time: 01:02)

ExSched: Solving Constraint Satisfaction Problems with the Spreadsheet Paradigm

Florida Math for College Readiness

WebSphere Business Monitor

ISAT Mathematics Performance Definitions Grade 4

Integer Operations. Overview. Grade 7 Mathematics, Quarter 1, Unit 1.1. Number of Instructional Days: 15 (1 day = 45 minutes) Essential Questions

TU e. Advanced Algorithms: experimentation project. The problem: load balancing with bounded look-ahead. Input: integer m 2: number of machines

8. Project Time Management

Learning Objectives 8.2. Media Run Times 8.3. Instructor Overview 8.8 Tutor Simulation: Roman Numerals and Polynomials

A Tool for Generating Partition Schedules of Multiprocessor Systems

Copy in your notebook: Add an example of each term with the symbols used in algebra 2 if there are any.

Project Time Management

Everyday Mathematics CCSS EDITION CCSS EDITION. Content Strand: Number and Numeration

Chapter 11 Monte Carlo Simulation

Overview. Essential Questions. Precalculus, Quarter 4, Unit 4.5 Build Arithmetic and Geometric Sequences and Series

Everyday Mathematics GOALS

ALGEBRA 2/TRIGONOMETRY

Algebra 2 Chapter 1 Vocabulary. identity - A statement that equates two equivalent expressions.

Krishna Institute of Engineering & Technology, Ghaziabad Department of Computer Application MCA-213 : DATA STRUCTURES USING C

Linear Programming Notes V Problem Transformations

4. How many integers between 2004 and 4002 are perfect squares?

Discernibility Thresholds and Approximate Dependency in Analysis of Decision Tables

Algebra Unpacked Content For the new Common Core standards that will be effective in all North Carolina schools in the school year.

A.2. Exponents and Radicals. Integer Exponents. What you should learn. Exponential Notation. Why you should learn it. Properties of Exponents

A Computer Application for Scheduling in MS Project

Math 120 Final Exam Practice Problems, Form: A

10. Proximal point method

Getting to know your TI-83

Linear Programming. Solving LP Models Using MS Excel, 18

Pricing complex options using a simple Monte Carlo Simulation

3. The Junction Tree Algorithms

Transcription:

Constraint Logic Programming CLP-1

What is Constraint Logic Programming? Is a combination of» Logic programming» Optimization» Artificial Intelligence CLP-2

Components Have a set of variables» Each variable ranges over a domain of values > X in 1.. 20 X has values between 1 and 20 inclusive finite domain > [X, Y] ins 1.. 20 > X X and Y each have values between 1 and 20 inclusive If the library loaded is the CLP on real numbers then X is any real number infinite domain CLP-3

Components 2 Have constraints on subsets of the variables» Y = X + 1» Y = X + 1, 2 * Y =< 8 X» Y = X + 1, 2 * Y =< 8 X, Z = 2 * X + 3 *Y > Here we assume the base type of X, Y and Z are real numbers Note that constraints can be on single variables to restrict the range, effectively defining the domain of values» X > 0, X < 21 CLP-4

Have built-in operators» maximize ( Z )» minimize (Z + 10 * Y)» inf (Z, I)» sup ( Z Y, S) Components 3 CLP-5

Putting it together Assuming variables are in the real number domain» Try different variations of the following in CLP(R) { X >= 2, -- Specify domain of X 2 * Y = X, -- Constraint 1 on X & Y 2 * Y =< 8 X, -- Constraint 2 on X & Y Z = 2 * X + 3 * Y }, -- Constrain Z wrt X and Y inf (Z, I), -- I is the the infimum (minimum) of Z sup (Z Y, S). -- S is the supremum (maximum) of Z Y maximize (Z), -- Another constraint CLP-6

Purpose Satisfy the constraints» Find an assignment of values to the variables such that all the constraints are simultaneously true» In optimization problems find the best assignment of values > Maximize, minimize, etc. CLP-7

What is in SWIPL SWI-prolog has various libraries that can be consulted» [ library(clpr) ]. > An implementation of CLP(R) with variables being real numbers with real arithmetic» [ library(clpq) ]. > An implementation of CLP(Q) with variables being rational numbers (ratios of integers)» [ library(clpfd) ]. > An implementation of CLP(FD) with variables being in finite domains» [ library(clpqr) ]. > Combination of rationals and reals CLP-8

CLP(Q) CLP(R) comparison Try the following» :- library(clpq)» { X = 2 * Y, Y = 1 X}. Compare with what is done in CLP(R)» :- library(clpr)» { X = 2 * Y, Y = 1 X}. CLP-9

CLP(R) Exercise Try the expression in slide CLP-6, adding one expression after another until the full slide is done CLP-10

Fahrenheit <--> Celsius Consider a predicate to convert between Fahrenheit and Celsius» convert (Fahrenheit, Celsius) :- Celsius is (Fahrenheit 32) * 5 / 9. > Can only go in one direction because is requires Fahrenheit to be instantiated Using CLP we can go both ways» convert (Fahrenheit, Celsius) :- { Celsius = (Fahrenheit 32) * 5 / 9 }.» convert (Fahrenheit, Celsius) :- { Fahrenheit = Celsius* 5 / 9 + 32 }. CLP-11

PERT & CPM PERT == Program Evaluation and Review Technique CPM == Critical Path Method Both are methods used in managing the complex scheduling of tasks that occur, for example, in building projects CLP-12

CPM & PERT Graph Is a graph where» Nodes are end points for tasks > Tasks begin or end at nodes» Arcs are duration time for tasks > Have a duration time associated with them E 5 3 4 7 A 3 B 6 C 5 D 4 6 F 6 G 8 CLP-13

CPM & PERT Graph 2 A task cannot start until all its precedence tasks are completed» E.G. Task CD must wait until tasks EC, BC and FC are completed before it can start E 5 3 4 7 A 3 B 6 C 5 D 4 6 F 6 G 8 CLP-14

PERT & CPM Objectives Find the critical path of tasks such that if any task is delayed the entire project is delayed, hence resources are allocated to minimize delay Another objective is to find where there is float-time in the schedule so resources can be moved from non-critical tasks to critical tasks Float-time at E E ED can be delayed in starting by 6 time units 5 7 A D 4 8 F 6 G Critical path is AFGD 18 time units CLP-15

Scheduling Example Figure 7.1 The textbook gives the following scheduling algorithm» {Ta = 0, Ta + 2 =< Tb, Note, you have to Ta + 2 =< Tc, construct a final node F, with zero duration, Tb + 3 =< Td, and appropriate arcs to it. Tc + 5 =< Tf, Td + 4 =< Tf }, minimize(tf). B,3 D,4 A,2 C,5 F CLP-16

Figure 7.1as a CPM / PERT graph» { Start = 0, Start + 2 =< E1, E1+ 3 =< E2, E2+ 4 =< F, E1+ 5 =< F}, minimize(f). Nodes are start/stop task events. Edges are tasks, with duration. E2 B,3 D,4 S A,2 E1 C,5 F Critical path is S,E1,E2,F. Task C has a float of 2 time units. CLP-17

Showing D with delayed start time» { Start = 0, Start + 2 =< E1, E1+ 3 =< E2, E2+ 4 =< F, E1+ 5 =< F}, minimize(f), maximize(e2). E2 B,3 D,4 S A,2 E1 C,10 F CLP-18

Fibonacci Ordinary Recursion Following is a recursive definition of the Fibonacci series. For reference here are the first few terms of the series Index 0 1 2 3 4 5 6 7 8 9 10 11 12 Value 1 1 2 3 5 8 13 21 34 55 89 144 233 Fibonacci ( N ) = Fibonacci ( N 1 ) + Fibonacci ( N 2 ). fib ( 0, 1 ). fib ( 1, 1 ). fib ( N, F ) :- N1 is N 1, N2 is N 2, fib ( N1, F1 ), fib ( N2, F2 ), F is F1 + F2. Does not work for queries fib ( N, 8 ) and fib ( N, F )» Values for is operator are undefined. CLP-19

Fibonacci with CLP fib_clp(n, F) :- { N = 0, F = 1 } ; { N = 1, F = 1 } ; { N >= 2, F = F1 + F2, N1 = N 1, N2 = N 2, F1 >= N1, F2 >= N2 } With accumulators we will see another solution Add for computational needs, not logical needs. fib_clp ( N1, F1), fib_clp ( N2, F2). CLP-20

Packing blocks into boxes Constraints» All objects are rectangular in two dimensional space» Sides of rectangles are parallel to the axes» Rectangles have a height and width CLP-21

A Pictorial Solution Blocks can be rotated by 90 degrees within the box.» What needs to be done to get a solution in Prolog? CLP-22

A Pictorial Solution 2 Blocks can be rotated by 90 degrees within the box.» What needs to be done to get a solution in Prolog?» Is all of the work unique to Prolog? CLP-23

DONALD + GERALD = ROBERT Crypt arithmetic puzzles are like the following, where digits 0..9 replace the letters DONALD + GERALD ROBERT 526485 + 197485 723970 CLP-24

DONALD + GERALD = ROBERT 2 solve( [D,O,N,A,L,D], [G,E,R,A,L,D], [R,O,B,E,R,T]) :- Vars = [D,O,N,A,L,G,E,R,B,T], % All variables in the puzzle Vars ins 0..9, % They are all decimal digits all_different( Vars), % They are all different 100000*D + 10000*O + 1000*N + 100*A + 10*L + D + 100000*G + 10000*E + 1000*R + 100*A + 10*L + D #= 100000*R + 10000*O + 1000*B + 100*E + 10*R + T, % labeling( [], Vars). label(vars). % Use default labeling CLP-25

You can time predicate execution» stats ( Time ) :- statistics ( runtime, _ ), solve ( _, _, _ ), statistics ( runtime, [ _, Time ] ). CLP-26

SEND + MORE = MONEY solve( [S,E,N,D] + [M,O,R,E] = [M,O,N,E,Y] ) :- Vars = [S,E,N,D,M,O,R,Y], Vars ins 0..9, all_different(vars), 1000*S + 100*E + 10*N + D + 1000*M + 100*O + 10*R + E #= 10000*M + 1000*O + 100*N + 10*E + Y, % All variables in the puzzle % They are all decimal digits % They are all different M #\= 0, S #\= 0, /* Systematically try out values for the finite domain variables in the set Vars until all of them are ground. */ labeling( [], Vars). CLP-27

Replacement for page 194 maximize ( indomain ( X ), Y ) does not exist in swipl» Replace with the following» X in 1.. 20, Y #= X * ( 20 X ), once ( labeling ( [ max ( Y ) ], [ X, Y ] ) ).» [ X,Y ] ins 1.. 20, 2 * X + Y #=< 40, once ( labeling ( [ max ( X * Y ) ], [ X, Y ] ) ). CLP-28

Replacement for page 194 2 Compare the following with schedule1 in CLP(R)» Replace with the following» schedule1a ( A, B, C, D, F ) :- StartTimes = [ A, B, C, D, F ], StartTimes ins 0.. 20, A + 2 #=< B, A + 2 #=< C, B + 3 #=< D, C + 5 #=< F, D + 4 #=< F, once ( labeling ( [ min ( F ) ], [ A, B, C, D, F ] ) ). CLP-29

Replacement for page 194 3 Compare the following with schedule1 in CLP(R)» Replace with the following» schedule1b ( A, B, C, D, F ) :- StartTimes = [ A, B, C, D, F ], StartTimes ins 0.. 20, A + 2 #=< B, A + 2 #=< C, B + 3 #=< D, C + 5 #=< F, D + 4 #=< F, once ( labeling ( [ max( C ) ], [ A, B, C, D, F ] ) ). CLP-30

Replacement for page 194 3 Compare the following with schedule1 in CLP(R)» Replace with the following» schedule1c ( A, B, C, D, F ) :- StartTimes = [ A, B, C, D, F ], StartTimes ins 0.. 20, A + 2 #=< B, A + 2 #=< C, B + 3 #=< D, C + 5 #=< F, D + 4 #=< F, once ( labeling ( [ min ( F ), max( C ) ], [ A, B, C, D, F ] ) ). CLP-31