constraint logic programming in clp(b oolean n aturals r...
TRANSCRIPT
page 1Constraint Interval Arithmetic
BNRComputing Research Laboratory
National Research Council
Constraint Logic Programmingin CLP(Boolean Naturals Reals)
André Vellino
Computing Research LaboratoryBell-Northern Research
Ottawa
November 1993
page 2Constraint Interval Arithmetic
BNRComputing Research Laboratory
National Research Council
Outline of the Talk
• What is Logic Programming?
• History and Motivation for CLP(BNR)
• Constraint Interval Arithmetic
• Applications and Plans for the Future
page 3Constraint Interval Arithmetic
BNRComputing Research Laboratory
National Research Council
What is Logic Programming?(a) The expression of computer programs in an efficientlyprovable subset of first-order predicate calculus;
(b) A non-deterministic, relational and recursive language thatincorporates unification and a depth-first search algorithm;
(c) A language with no types, no assignment statements nocontrol constructs and no data-structures;
(d) A paradigm for which the equation:
Algorithms + Data Structures = Programs
is replaced by:
Knowledge + Question = Answer(s)
page 4Constraint Interval Arithmetic
BNRComputing Research Laboratory
National Research Council
Prolog Programs
Answers found_in(ottawa, ontario). found_in(montreal, quebec). found_in(toronto, ontario). found_in(ontario, canada). found_in(quebec, canada). found_in(boston, mass). found_in(mass, usa). found_in(canada, north_america). found_in(usa, north_america). found_in(ottawa, canada). found_in(ottawa, north_america). found_in(montreal, canada). found_in(montreal, north_america). found_in(toronto, canada). found_in(toronto, north_america). found_in(ontario, north_america). found_in(quebec, north_america). found_in(boston, usa). found_in(boston, north_america). found_in(mass, north_america).
Knowledgelocated_in(ottawa,ontario).located_in(montreal,quebec).located_in(toronto,ontario).located_in(ontario,canada).located_in(quebec,canada).located_in(boston,mass).located_in(mass,usa).located_in(canada,north_america).located_in(usa,north_america).
found_in(A,B) :- located_in(A,B).found_in(X,Z) :- located_in(X,Y), found_in(Y,Z).
+Question?- found_in(Containee, Container).
=
page 5Constraint Interval Arithmetic
BNRComputing Research Laboratory
National Research Council
Call Processing in Prolog
idling
calling
talking
ringing
dialansweroriginate
originate offhookanswer
release onhook
react(idling, dial, calling, originate ).react(idling, originate , ringing, none).react(ringing, offhook , talking, answer ).react(calling, answer , talking, none).react(talking, onhook , idling, release ).react(talking, release , idling, none).
react(_, onhook , idling, release ).react(_, release , idling, none).
page 6Constraint Interval Arithmetic
BNRComputing Research Laboratory
National Research Council
Outline of the Talk
• What is Logic Programming?
• History and Motivation for CLP(BNR)
• Constraint Interval Arithmetic
• Applications and Plans for the Future
page 7Constraint Interval Arithmetic
BNRComputing Research Laboratory
National Research Council
A Brief History ofCLP(BNR)
XMS-Prolog interpreter 1985-1987
Constraint Interval Arithmetic talk by John Cleary 1987
BNR-Prolog interpreter for Macintosh 1988
Panels UI toolkit 1989
Dassault Electronique develop InterLog 1990
BNR-Prolog compiler for Sun Workstations 1991
Constraints on Integers and Boolean CLP(BNR)-1992
Ports to DEC, HP 300-400, HP 700-1993
page 8Constraint Interval Arithmetic
BNRComputing Research Laboratory
National Research Council
Related Systems
• CHIP -- Constraint Handling in Prolog (ECRC)
• CHARME / Decision Power
• CLP(R) IBM -- Yorktown Heights
• Prolog-III -- Marseille
• ILOG-Solver -- C++ library
• InterLog -- Dassault Electronique
• Screamer -- Non-determinsitic Common-LISP
•
page 9Constraint Interval Arithmetic
BNRComputing Research Laboratory
National Research Council
Why Constraints?Software Development:
FasterSimpler programs;
Correctness easier to ascertain;More maintainable;Eliminates many difficult algorithm design problems;
One implementation can be used for different purposes;
Real World Modelling:
Can use uncertain or fuzzy data and tolerancesCan make effective use of redundant informationCan use approximation information without error
Sensitivity analysis is trivial
page 10Constraint Interval Arithmetic
BNRComputing Research Laboratory
National Research Council
Applications of CLP(BNR)• manufacturing specifications (Dassault Electronique);
• temporal reasoning (BNR);
• analysis of gear ratios (Ford);
• hardware configuration (BNR)
• FPGA-gate allocation (BNR);
• hardware timing analysis (BNR);
• Others ... operations research;performance modeling (Carleton U.);x-ray crystallography
page 11Constraint Interval Arithmetic
BNRComputing Research Laboratory
National Research Council
Theoretical Motivations
• Commutative
• Persistence
• Monotone
p(X) & q(X) q(X) & p(X)
P & ....& Q & P
"Ask a vaguer question get a vaguer answer"
P & ....& Q
("Ask a more precise question get a more precise answer")
page 12Constraint Interval Arithmetic
BNRComputing Research Laboratory
National Research Council
Impure Logic Programs
• Side-effects
• Filters
• Arithmetic
Input/Output, Database Updates
var(X) (monotone but not persistent)nonvar(X) (does not commute)
page 13Constraint Interval Arithmetic
BNRComputing Research Laboratory
National Research Council
Prolog Arithmetic
?- X is 2 *3.X = 6
?- 4 is X * X.NO
?- X is 2 * 3, Y is X * 2.X=6 Y=12
?- Y is X * 2, X is 2 * 3.NO
Functional
Not Relational
Not Logical(not commutative)
page 14Constraint Interval Arithmetic
BNRComputing Research Laboratory
National Research Council
Conventional Arithmetic
Round off errors in floating point arithmetic causesprograms to produce incorrect results. e.g. 1.21 is 1.1 * 1.1 is false. (A + B) * C = (A * C) + (B * C) is not always true
Thus, it is never safe to combine programs that dosymbolic algebra with programs that evaluate themnumerically.
page 15Constraint Interval Arithmetic
BNRComputing Research Laboratory
National Research Council
Constraint Arithmetic on Intervals
Intervals Correctness of Arithmetic Precision problems Mixing of symbolic and numeric methods
Constraints Commutativity of operations Interchangability of unknowns
page 16Constraint Interval Arithmetic
BNRComputing Research Laboratory
National Research Council
Outline of the Talk
• What is Logic Programming?
• History and Motivation for CLP(BNR)
• Constraint Interval Arithmetic
• Applications and Plans for the Future
page 17Constraint Interval Arithmetic
BNRComputing Research Laboratory
National Research Council
CLP(BNR)
A system which takes a set of relations over
Booleans Naturals and Reals, a set of initial bounds
on all the quantities and derives a set of posteriori
bounds on all the quantities using a local propagation,
arc-consistency based, fixed-point iteration.
page 18Constraint Interval Arithmetic
BNRComputing Research Laboratory
National Research Council
Interval ArithmeticAn interval represents a real number that lies between twofloating point bounds.
This overcomes the problem of incorrect arithmetic, becauseround off errors can be accommodated.
X [2.5, 3.5]Y [2.6, 4.2]X+Y [5.0999,7.70001]
page 19Constraint Interval Arithmetic
BNRComputing Research Laboratory
National Research Council
Interval Constraint Network
X
Y
Z
X + 3 == U
U
Y * U == V
V + X == Z V
Z == Y * (X + 3) + X X + 3 == UY * U == VV + X == Z
Source Code Constraint Network
page 20Constraint Interval Arithmetic
BNRComputing Research Laboratory
National Research Council
Equality is Intersection?- X:real(2,4),Y:real(3,5), X == Y.X = [3,4], Y = [3,4]
?- X:real(2,4),Y:real(3,5), X == Y, X >= 3.5, Y =< 3.7.X = [3.5,3.7], Y = [3.5,3.7]
X Y
page 21Constraint Interval Arithmetic
BNRComputing Research Laboratory
National Research Council
InequalityX =< Y
page 22Constraint Interval Arithmetic
BNRComputing Research Laboratory
National Research Council
Relational Addition
?- X:real(3, 7), Y:real(2, 8), Z:real(4, 6), X + Y == Z.X = [3, 4]Y = [2, 3]Z = [5, 6]
Evaluating a relational expression on intervalsmay narrow them all.
Interpretation: ∀x ∈ X, ∃ y ∈Y, ∃ z ∈ Z such that x + y = z
∀ y ∈Y, ∃x ∈ X, ∃ z ∈ Z such that x + y = z
∀ z ∈ Z ∃x ∈ X, ∃ y ∈Y, such that x + y = z
page 23Constraint Interval Arithmetic
BNRComputing Research Laboratory
National Research Council
Limitations of Local Propagation
?- [X,Y,Z]: real(-1,1), X + Y + Z == 0, X + Y + Z == 1.
Some constraint networks are not congenial to thenarrowing of intervals. For example the question
succeeds even though the two equations are inconsistent.
The inconsistency is detected numerically only whenfurther narrowing is attempted.
page 24Constraint Interval Arithmetic
BNRComputing Research Laboratory
National Research Council
Redundant Constraints
Sometimes redundant constraints can help, e.g.
?- [X,Y,Z]: real(-1,1), T : real, X + Y + Z == T, T == 0, T == 1.
is false.
page 25Constraint Interval Arithmetic
BNRComputing Research Laboratory
National Research Council
Searching for Solutions
?- [X,Y]:real, Y >= 3, Y =< 4,Y == X * X.
X = [-2, 2]
To narrow for more precise solutions,we need to search the solution spacealgorithmically (e.g. divide and conquer)
-2.0 -1.0 1.0 2.0
2.0
4.0
-2.0
Y
?- [X,Y]:real, Y >= 3, Y =< 4,Y == X * X, X >= 0 ; X =< 0.
X = [1.7320, 2.0001]X = [-2.0001, -1.7320]
page 26Constraint Interval Arithmetic
BNRComputing Research Laboratory
National Research Council
Searching for SolutionsSince interval arithmetic is integrated in a Prolog systemit is possible to write your own relaxation algorithm.
For example, you can recursively constrain a giveninterval to be alternately less than or greater than itsmidpoint and thus 'scan' the interval for solutions.
e.g.
?- X:real(0, 1), 0 == 35 * X ** 256 - 14 * X ** 17 + X, solve(X).
X = [0.0, 0.0] ;X = [0.84794,0.84795] ;X = [0.99584,0.99585]
page 27Constraint Interval Arithmetic
BNRComputing Research Laboratory
National Research Council
Integers and Booleans?- I:integer, Y:real(3.5,8.26), I**2==Y. ?- [I:integer, Y : real(3.5, 8.26), I**2 == Y]
where [I : integer(-2, 2), Y: 4].
?- B:boolean, 1 == (B and (C or ~D)) . ?- [1 : boolean, 1 == (1 and (C or ~ D))] where [C : boolean, D : boolean].
?- [A,B]:boolean, [X,Y]:real, J:integer,((X**2 + 2.5*J =< log(Y)) and A) == ~ B.
Disjunctive Scheduling Constraints
(Start1 + Dur1 =< Start2) xor (Start2 + Dur2 =< Start1) == 1
page 28Constraint Interval Arithmetic
BNRComputing Research Laboratory
National Research Council
Formal Properties
• Commutative
• Persistent
• Monotone
"Once P implies henceforth P"
"Ask a more precise question get a more precise answer"
"The order of constraints doesn't matter"
page 29Constraint Interval Arithmetic
BNRComputing Research Laboratory
National Research Council
Outline of the Talk
• What is Logic Programming?
• History and Motivation for CLP(BNR)
• Constraint Interval Arithmetic
• Applications and Plans for the Future
page 30Constraint Interval Arithmetic
BNRComputing Research Laboratory
National Research Council
Configuration in CLP(BNR)
Problem
Configuration of Northern Telecom DMS switching equipment. Different shelves can contain line cards subject to capacity constraints;
Shelves have requirement and exclusion constraints.
Problem: how to distribute components to minimize number of shelves
page 31Constraint Interval Arithmetic
BNRComputing Research Laboratory
National Research Council
Problem Specificationbin_types( [blue,red,green]).commodities( [glass, plastic, steel, wood, copper]).
requires(wood,plastic).excludes(glass, copper).excludes(copper,plastic).
capacity( red, wood, 1 ).capacity( green, wood, 2 ).
capacity(red, steel,0).capacity(red,plastic,0).capacity(blue,wood,0).capacity(blue,plastic,0).capacity(green,glass,0).capacity(green,steel,0).
capacity( red, 3).capacity( blue, 1).capacity( green, 4).
page 32Constraint Interval Arithmetic
BNRComputing Research Laboratory
National Research Council
Automatic Translation into CLP(BNR)bin([Blue, Green, Red],[Glass,Plastic,Steel,Wood,Copper],Total) :-
% declarations[Blue,Green,Red] : boolean,[Glass,Plastic,Steel,Wood,Copper] : integer(0,_),BinSize:integer(1,4),
% global constraintsRed + Green + Blue == 1,BinSize == Red*3 + Green*4 + Blue*1, Total is (Glass + Plastic + Steel + Wood + Copper),BinSize >= Total,
% requires/excludes constraintsGlass exclusive Copper, Copper exclusive Plastic, if (Wood >= 1) then (Plastic >= 1), if Green then (Glass + Steel == 0), if Green then (Wood =< 2), if Blue then ((Wood + Plastic) == 0), if Red then ((Steel + Wood) == 0), if Red then (Wood =< 1).
X exclusive Y :- X * Y == 0.if A then B :- A =< B.
page 33Constraint Interval Arithmetic
BNRComputing Research Laboratory
National Research Council
FPGA Gate Arrays
Problem: layout the functional components of a gate array so that:
(a) only one register can be enabled on the data bus(b) each function has only 4 inputs(c) arithmetic and compare functions must be routed locally(d) minimize data-bus traffic to/from registers....
Solution space large (10!)3-5 orders of magnitude faster than Test & Generate algorithmTypical configuration constraint problemDrawback: no explanation facility
page 34Constraint Interval Arithmetic
BNRComputing Research Laboratory
National Research Council
Hardware Timing AnalysisProblem: to determine the “timing correctness” of a circuit without simulating its functional behaviour
Answer: represent circuit component delays, rising and falling edges of clock etc. as intervals
represent composite delays as arithmetic functions ofcomponent delays
set up circuits as sets of simultaneous arithmetic relations
constitutes a formal verification (monotonic)
Results: 5 pages of CLP(BNR), 3400 gates in circuit linear (average) performance without correlated delays 120s (HP700) quadratic (average) performance with correlated delays
page 35Constraint Interval Arithmetic
BNRComputing Research Laboratory
National Research Council
Comparison w/ Other CLPs
• can express & solve systems of non-linear constraints• sound arithmetic ∴ o.k. to do symbolic manipulation• not very useful for under-constrained linear systems• allows for disjunctive scheduling with Booleans• finite-domain problems expressible with integer-intervals
CLP(BNR)
CHIP--restricted to integers and finite domains
CLP(R) -- restricted to linear equations, limited by floating point errors
Prolog-III -- restricted to linear equations and rational numbers
ILOG-Solver -- C++ library w/ clumsy non-determinism and control
Screamer -- Non-determinsitic Common-LISP
page 36Constraint Interval Arithmetic
BNRComputing Research Laboratory
National Research Council
Future Plans:Constraint Programming Research with Carleton University
• Continue CLP(BNR) research as applied to: resource-allocation,scheduling,network configuration problems;
• 5 Professors (& ~10 Grad students) involved: Majumdar, Woodside, Pagurek, Chinneck and Karam;
• 5 Applied Projects:Performance Analysis and Engineering;Task and Resource Allocation for Concurrent Software;Network Diagnosis;Configuration Management;Task Management for Multiprocessor Systems;
• 2 Research Projects:Global Optimization;Flexible Scheduling.