Some Practical Applications of Con- straints planning, - - PDF document

some practical applications of con straints planning
SMART_READER_LITE
LIVE PREVIEW

Some Practical Applications of Con- straints planning, - - PDF document

Some Practical Applications of Con- straints planning, scheduling, timetabling (see Outline ILOG solver esp ecially) conguration what is a constraint electrical circuit analysis, synthesis, and di-


slide-1
SLIDE 1 Outline
  • what
is a constraint
  • the
constraint logic p rogramming frame- w
  • rk
  • decla
rative and p ro cedural readings
  • f
CLP p rograms
  • the
CLP(R) language and its implementa- tion 1 Some Practical Applications
  • f
Con- straints
  • planning,
scheduling, timetabling (see ILOG solver esp ecially)
  • conguration
  • electrical
circuit analysis, synthesis, and di- agnosis
  • nancial:
  • ptions
trading, nancial plan- ning
  • cutting
sto ck p roblems
  • natural
language p ro cessing
  • restriction
site mapping (genetics applica- tion)
  • generating
test data fo r communications p roto cols 2 Denition
  • f
a Constraint What is a constraint? Info rmally , a constraint is a relation that w e w
  • uld
lik e to b e satised. Examples:
  • t
w
  • columns
in a table b e
  • f
equal widths
  • ne
windo w
  • n
a screen b e ab
  • ve
another windo w
  • a
resisto r in a circuit simulation should
  • b
ey Ohm's La w Advantages: decla rative, high-level, natural fo r many applications, Disadvantages: easier to state than to satisfy , debugging and usabilit y issues, complex inter- actions with state and
  • bject
identit y 3 Constraints in Constraint Logic Program- ming The CLP and logic p rogramming communit y uses the follo wing mo re fo rmal denition
  • f
constraint. The fo rm and meaning
  • f
a constraint is sp ec- ied b y a domain D , including syntax fo r the constraints, p ermissible values fo r the va ri- ables, and meanings
  • f
the symb
  • ls
in the con- straint. Example: Y
  • Y
< 1 means dierent things fo r integers, reals,
  • r
complex numb ers. Denition: a p rimitive constraint consists
  • f
a constraint relation symb
  • l
from D with the co rrect numb er
  • f
a rguments. Each a rgument is constructed from va riables and the constants and functions
  • f
D . 4
slide-2
SLIDE 2 Domains and Constraints Example domain: the real numb ers with the standa rd a rithmetic functions and relations. The domain is R, the function symb
  • ls
a re +, ,
  • and
=, and the constraint relation symb
  • ls
a re =, <, , , and >. Some
  • ther
domains: integers, b
  • leans,
trees (nite
  • r
innite). Denition: a constraint is
  • f
the fo rm c 1 ^ : : : ^ c n where n
  • and
c 1 ; : : : c n a re p rim- itive constraints. (Note: the UI p eople no rmally do not mak e a distinction b et w een constraints and p rimitive constraints, and also rega rd fo r example + as a constraint itself, rather than a function sym- b
  • l.)
5 V aluations and Satisabilit y Denition: a valuation
  • fo
r a set V
  • f
va riables is an assignment
  • f
values from the domain to those va riables. F
  • r
va riables V = fX 1 ; : : : X n g
  • ma
y b e written fX 1 ! d 1 ; : : : X n ! d n g. Let va rs(e) b e the va riables
  • ccuring
in an ex- p ression e, and va rs(C ) b e the va riables
  • ccur-
ing in a constraint C . If
  • is
a valuation fo r V where va rs (C )
  • V
then it is a solution
  • f
C if
  • (C
) holds in the constraint domain. A constraint C is satisable if it has a solution. Otherwise it is unsatisable. Tw
  • constraints
a re equivalent, written C 1 $ C 2 if they have the same set
  • f
solutions. 6 Solver Prop erties Constraint solvers accept a constraint as input. (Rememb er these can b e comp
  • sed
  • f
multiple p rimitive constraints.) Output is:
  • true
(constraints a re satisable)
  • false
(constraints a re unsatisable)
  • unkno
wn Denition: a solver is complete if fo r every constraint in D the solver's
  • utput
is either true
  • r
false. W e will not b e interested in unsound solvers (which might
  • utput
true fo r unsatisable con- straints
  • r
false fo r satisable constraints). W e p refer that solvers b e complete, but fo r some domains this is not p ractical
  • r
even p
  • s-
sible. 7 Mini-Exercises Consider the domain
  • f
the reals. Supp
  • se
w e have a solver that alw a ys
  • utputs
unkno wn. Is this solver sound? Complete? Supp
  • se
w e have a solver that alw a ys
  • utputs
true. Is this solver sound? Complete? Let C 1 b e the constraint X
  • 10
^ X + 5 = Y . Is C 1 satisable? Give a valuation that is a solution fo r C 1 , and a valuation that is not a solution. Is C 1 equivalent to X
  • 10
^ Y
  • 5?
8
slide-3
SLIDE 3 The CLP Scheme CLP(D ) is a language framew
  • rk,
where D is the domain
  • f
the constraints. Example CLP languages:
  • Prolog
  • CHIP
  • Prolog
I I I { domain is rationals, b
  • leans,
and trees
  • CLP
(*) { domain is regula r sets
  • CLP(R)
{ domain is reals (plus trees, i.e. the data t yp es that Prolog uses) 9 CLP(R) { Domain and Solver CLP(R) can solve a rbitra ry collections
  • f
linea r equalit y and inequalit y constraints. It can also solve
  • ther
kinds
  • f
constraints
  • ver
the reals if it can nd the answ er using
  • ne-
step deductions (rst nd this va riable using
  • ne
constraint, then nd another va riable using another constraint, etc | but no simultaneous equations). 10 CLP(R) Examples Sample goals (just using p rimitive constraints { no user-dened rules): ?- X=Y+1, Y=10. X=11, Y=10 ?- 2*A+B=7, 3*A+B=9. A=2, B=3 ? X>=2*Y, Y>=5, X<=10. X=10, Y=5. ?- X*X*X + X = 10. maybe (The last goal do es have a solution X=2. The \ma yb e" answ er means the constraints a re to
  • ha
rd fo r CLP(R) to solve.) 11 CLP(R) Examples CLP(R) p rograms a re collections
  • f
facts and rules. Sample rule: /* centigrade-fahrenheit relation */ cf(C,F) :- F = 1.8*C + 32. Sample Goals: ?- cf(100,A). A=212.0 ?- cf(A,B), A>100, B<200. no. ?- cf(X,X). X=-40.0 12
slide-4
SLIDE 4 F
  • rmal
Denitions
  • CLP
Constituents A user dened constraint is
  • f
the fo rm p(t 1 ; : : : t n where p is an n-a ry p redicate and t 1 ; : : : t n a re exp ressions from the constraint do- main. A literal is either a p rimitive constraint
  • r
a user-dened constraint. A goal G is a sequence
  • f
literals. G has the fo rm L 1 ; L 2 ; : : : L m where m
  • 0.
If m = the goal is empt y and is rep resented b y 2 A rule R is
  • f
the fo rm A : B where A is a user-dened constraint and B is a goal. A is the head
  • f
the rule and B is the b
  • dy
. (Read this as B implies A.) A fact is a rule with the empt y goal as the b
  • dy
A : 2 and is just written as A: (Read this as A is true.) 13 A constraint logic p rogram P is a sequence
  • f
rules. The denition
  • f
a p redicate p in a p rogram P is the sequence
  • f
rules app ea ring in P which have a head involving p redicate p. (Mo re fo r- mally \involving p redicate p" means that the head
  • f
those rules can b e unied with p, in
  • ther
w
  • rds,
w e can solve a tree equalit y con- straint b et w een them.) Evaluation in CLP Languages { Info rmal Discussion Given an initial goal, a CLP interp reter rewrites any user-dened constraints in the goal using their denitions. This ma y yield mo re user dened constraints, which a re then rewritten. Primitive constraints a re k ept in a constraint sto re. W e continue until there a re
  • nly
p rimitive con- straints, which a re solved b y the system. Ho w ever, if the constraint sto re contains an unsatisable set
  • f
constraints, w e can stop rewriting immediately . W e ma y have multiple rules fo r a given user- dened constraint. W e try these in
  • rder,
backtracking if
  • ne
fails. 14 Rewriting { Mo re F
  • rmal
Denition Let a goal G b e
  • f
the fo rm L 1 ; : : : L i1 ; L i ; L i+1 ; : : : L m where L i is the user-dened constraint p(t 1 ; : : : ; t n ) and rule R is
  • f
the fo rm p(s 1 ; : : : ; s n ) : B . A rewriting
  • f
G at L i b y R using
  • is
the goal L 1 ; : : : L i1 ; t 1 = (s 1 ); : : : ; t n = (s n ); (B ); L i+1 ; : : : L m where
  • is
a renaming such that the va riables in (R ) do not app ea r in G. 15
slide-5
SLIDE 5 Example Rewriting Consider the goal cf(100,A), B=A+100. Let's rewrite this using the rule cf(C,F) :- F = 1.8*C + 32. W e can use the empt y renaming, since there a re no va riables in common b et w een the goal and the rule. The new goal is 100 = C ; A = F ; F = 1:8
  • C
+ 32; B = A + 100 16 Mini-Exercise Rewrite the goal cf(F,F) using the cf rule: cf(C,F) :- F = 1.8*C + 32. 17 Evaluation in CLP Languages { Mo re F
  • r-
mal T reatment The state
  • f
the computation at any p
  • int
consists
  • f
the current goal G and the con- straint sto re C . Rememb er that G is a con- junction
  • f
literals, and the constraint sto re holds p rimitive constraints. F
  • rmally
, a state is a pair written hG j C i. A derivation step involves p ro cessing a con- straint from G. A derivation step is written as hG 1 j C 1 i ) hG 2 j C 2 i. 18 Evaluation (continued) Supp
  • se
G 1 = L 1 ; : : : L m fo r literals L 1 ; : : : L m . Case 1. L 1 is a p rimitive constraint. Then the next state is hG 2 j C 2 i, where C 2 = C 1 ^ L 1 . If solv(C 2 ) 6 false G 2 = L 2 ; : : : L m . If solv(C 2 )
  • false
G 2 = 2. Case 2. L 1 is a user dened constraint. Then C 2 = C 1 , and G 2 is a rewriting
  • f
G 1 at L 1 b y some rule R in the p rogram. If there is no rule dening the p redicate
  • f
L 1 then C 2 is false and G 2 is the empt y goal. 19
slide-6
SLIDE 6 Success and F ailure A success state is a state h2 j C i where solv(C ) 6 false. A fail state is a state h2 j C i where solv(C )
  • false.
A derivation hG j C i ) : : : ) hG n j C n i is successful if hG n j C n i is a success state. The constraints resulting from simplifying C n with resp ect to the va riables in the
  • riginal
goal G a re the answ er to hG j C i. If hG n j C n i is a failed state then the derivation is failed. 20 Answ er to Example Rewriting Ea rlier w e rewrote the goal cf(100,A), B=A+100 using the rule cf(C,F) :- F = 1.8*C + 32. The new goal is 100 = C ; A = F ; F = 1:8
  • C
+ 32; B = A + 100 The answ er is A = 212; B = 312 21 Example Derivation CLP(R) p rogram: cf(C,F) :- /* rule R1 */ F = 1.8*C + 32. double(X,Y) := Y=2*X. /* rule R2 */ Consider the goal cf(A,B), double(A,200). hcf(A; B ); double (A; 200) j true i ) using R1: hA = C ; B = F ; F = 1:8
  • C
+ 32; double (A; 200) j true i ) 22 hB = F ; F = 1:8
  • C
+ 32; double (A; 200) j A = C i ) hF = 1:8
  • C
+ 32; double (A; 200) j A = C ; B = F i ) hdouble (A; 200) j A = C ; B = F ; F = 1:8
  • C
+ 32i ) using R2: hA = X ; 200 = Y ; Y = 2
  • X
j A = C ; B = F ; F = 1:8
  • C
+ 32i )
slide-7
SLIDE 7 h200 = Y ; Y = 2
  • X
j A = C ; B = F ; F = 1:8
  • C
+ 32; A = X i ) hY = 2
  • X
j A = C ; B = F ; F = 1:8
  • C
+ 32; A = X ; 200 = Y i, ) h2 j A = C ; B = F ; F = 1:8
  • C
+ 32; A = X ; 200 = Y ; Y = 2
  • X
i Simplifying with resp ect to the va riables in G (namely A; B ) w e get the answ er A = 100; B = 212 Innite Derivations Consider the follo wing rules dening the natu- ral numb ers: natural(N) :- natural(N-1). /* Rule R1 */ natural(1). /* rule R2 */ Given the goal natural(3)
  • ne
derivation is hnatural(3) j true i ) (using R1) hN = 3; natural (N
  • 1)
j truei ) hnatural(N
  • 1)
j N = 3i ) (using R1) 23 hN
  • 1
= N ; natural(N
  • 1)
j N = 3i ) hnatural(N
  • 1)
j N = 3; N
  • 1
= N i ) (using R1) hN
  • 1
= N 00 ; natural (N 00
  • 1)
j N = 3; N
  • 1
= N i ) hnatural(N 00
  • 1)
j N = 3; N
  • 1
= N ; N
  • 1
= N 00 i ) (using R1) hN 00
  • 1
= N 000 ; natural (N 000
  • 1)
j N = 3; N
  • 1
= N ; N
  • 1
= N 00 ; N 00
  • 1
= N 000 i ) . . . A Dierent Derivation Another derivation fo r the goal natural(3) is hnatural(3) j true i ) (using R1) hN = 3; natural (N
  • 1)
j truei ) hnatural(N
  • 1)
j N = 3i ) (using R1) hN
  • 1
= N ; natural(N
  • 1)
j N = 3i ) hnatural(N
  • 1)
j N = 3; N
  • 1
= N i 24
slide-8
SLIDE 8 ) (using R2) hN
  • 1
= 1 j N = 3; N
  • 1
= N i ) h2 j N = 3; N
  • 1
= N ; N
  • 1
= 1i (a success state) Choices in CLP(R) 1. When a goal contains mo re than
  • ne
literal, which literal to select? 2. When mo re than
  • ne
rule matches the se- lected literal, which rule to select? Theo rem: fo r a derivation that is successful, cho
  • sing
dierent literals still gives the same result. (Intuition: fo r a successful derivation w e have to p ro cess each literal so
  • ner
  • r
later.) Our CLP(R) implementation alw a ys selects the leftmost literal. 25 The choice
  • f
rule is mo re interesting. W e can get dierent answ ers fo r the same goal given dierent rule choices. (In
  • ther
w
  • rds,
there can b e mo re than
  • ne
successful deriva- tion.) Also some rule choices ma y result in innite derivations | so it matters which
  • rder
w e try them in. Denition: a derivation tree fo r a goal G and p rogram P is a tree with states as no des. The ro
  • t
  • f
the tree is hG j true i. The children
  • f
each state hG i j C i i a re those states that can b e reached in a single derivation step. A state with t w
  • r
mo re children is a choice- p
  • int.
(This happ ens
  • nly
fo r user-dened constraints that have multiple matching rules.) CLP(R) rst selects the rule that
  • ccurs
rst in the p rogram text. If this derivation fails, it selects the next rule, and so fo rth. T
  • imple-
ment this it k eeps a stack
  • f
backtrack p
  • ints,
and uses depth-rst sea rch. The
  • rder
  • f
rules in the p rogram can mak e a dierence!
slide-9
SLIDE 9 Mini-Exercises W rite CLP(R) rules to dene the \max" rela- tion. Here a re some sample goals: ?- max(10,20,X). X=20 ?- max(10,20,30). no What a re the answ ers fo r the follo wing goals? If there is mo re than
  • ne
answ er give all
  • f
them. Sho w the derivation tree (skipping some details
  • f
p ro cessing the p rimitive constraints if y
  • u
wish). ?- max(1,2,A). ?- max(X,Y,20). 26 T ree Constraints Besides the domain
  • f
the real numb ers, CLP(R) has another domain: trees. These al- lo w us to mo del data structures such as lists, reco rds, and trees. Denitions: a tree constructo r is a symb
  • l
b e- ginning with a lo w er-case letter. A tree is ei- ther a constant,
  • r
a tree constructo r together with an
  • rdered
list
  • f
  • ne
  • r
mo re trees, which a re its children. A term is either a constant, a va riable,
  • r
a tree constructo r together with an
  • rdered
list
  • f
  • ne
  • r
mo re trees, which a re its children. The
  • nly
relation among trees w e will use is equalit y . In CLP(R) atoms sta rt with lo w er-case letters, and va riables with capital letters. 27 (Prolog fans: trees a re the data structures that Prolog uses. Unication is the algo rithm used to solve equalit y constraints
  • ver
trees.) Examples
  • f
trees: fred X point(10,20) point(X,Y) line(point(X1,Y1),point(X2,Y2)) node(3,emptynode,node(4,emptynode, empty node) ) There is sp ecial syntax fo r lists: [ ] /* the empty list */ [1,2,3] [1 | [2,3]] /* the same as [1,2, */ [a, b, [c], [d] ] /* sublists OK */ Examples
  • f
tree constraints: A = point(10,20) has solution A=point(10,20) point(X,X) = point(10,Y) has solution X=Y=10 point(X,X) = point(10,20) has no solution [A,B,C] = [1,2,3] has solution A=1, B=2, C=3 [X|Xs] = [1,2,3] has solution X=1, Xs=[2,3] [X|Xs] = [100] has solution X=100, Xs=[]
slide-10
SLIDE 10 T ree Constraint Solver T
  • solve
e 1 = e 2 If e 1 is a va riable v , then succeed, and return the substitution v = e 2 If e 2 is a va riable v , then succeed, and return the substitution v = e 1 If e 1 and e 2 a re constants, if they a re the same succeed; if they a re dierent fail. If
  • nly
  • ne
  • f
e 1 and e 2 is a constant, fail. Otherwise b
  • th
e 1 and e 2 consist
  • f
a tree con- structo r with an
  • rdered
list
  • f
children. If e 1 and e 2 have dierent constructo rs
  • r
dier- ent numb ers
  • f
children, then fail. Otherwise e 1 = p(s 1 ; : : : ; s n ) and e 2 = p(t 1 ; : : : ; t n ). Recur- sively solve the constraints s 1 = t 1 ; : : : s n = t n . Succeed if all
  • f
them can b e solved, and re- turn the combined subsitution. Otherwise fail. 28 Some Simple Recursive CLP(R) Programs /* LENGTH OF LIST */ length([],0). length([H|T],N) :- N > 0, length(T,N-1). /* compare this with a scheme program: (define (length x) (if (null? x) (+ 1 (length (cdr x))))) */ /* SUM OF THE ELEMENTS IN A LIST */ sum([],0). sum([X|Xs],X+S) :- sum(Xs,S). 29 /* FACTORIAL */ factorial(0, 1). factorial(N, N * F) :- N > , fact(N
  • 1,
F). Mini-Exercises What a re the
  • utputs
fo r the follo wing goals? Sho w the derivation tree (skipping some details
  • f
p ro cessing the p rimitive constraints if y
  • u
wish). ?- length([a,b,c],N). ?- length([X|Xs],N). ?- length(L,2). 30
slide-11
SLIDE 11 Greatest Common Diviso r /* GREATEST COMMON DIVISOR (USING EUCLID'S ALGORITHM) */ gcd(A,B,G) :- A < B, gcd(A,B-A,G). gcd(A,B,G) :- A > B, gcd(A-B,B,G). gcd(A,A,A). 31 Quickso rt quicksort([],[]). quicksort([X|Xs],Sorted) :- partition(X,Xs,Smalls,Bigs), quicksort(Smalls,SortedSmalls), quicksort(Bigs,SortedBigs), append(SortedSmalls,[X|SortedBig s],So rted) . partition(Pivot,[],[],[]). partition(Pivot,[X|Xs],[X|Ys],Zs) :- X <= Pivot, partition(Pivot,Xs,Ys,Zs). partition(Pivot,[X|Xs],Ys,[X|Zs]) :- X > Pivot, partition(Pivot,Xs,Ys,Zs). append([],X,X). append([X|Xs],Ys,[X|Zs]) :- append(Xs,Ys,Zs). 32 Electrical Circuit Example resistor(lead(I1,V1),lead(I2,V2),O hms) :- I1+I2=0, V2-V1=I1*Ohms. battery(lead(I1,V1),lead(I2,V2),Vo lts) :- V1 = V2+Volts, I1+I2=0. electrical_ground(lead(0,0)). ammeter(lead(I1,V),lead(I2,V),I1) :- I1+I2=0. voltmeter(lead(0,V1),lead(0,V2),Vo lts) :- V1-V2=Volts. 33 /* rule to connect a list
  • f
leads together (makes all the voltages the same, and the sum
  • f
the currents be */ connect(Leads) :- same_voltages(Leads), currents_sum(Leads,0). same_voltages([]). same_voltages([L]). same_voltages([lead(I1,V),lead(I2, V)|Mo re]) :- same_voltages([lead(I2,V)|More] ). currents_sum([],0). currents_sum([lead(I1,V1)|More],I1 +Sum) :- currents_sum(More,Sum).
slide-12
SLIDE 12 /* RULES TO BUILD THE SAMPLE CIRCUITS */ /* simple battery-resistor circuit */
  • ne_resistor(Volts,Ohms,Amps)
:- battery(B1,B2,Volts), resistor(R1,R2,Ohms), ammeter(A1,A2,Amps), electrical_ground(G), connect([B2,A1]), connect([A2,R1]), connect([R2,B1,G]). /* same circuit, but no ground */
  • ne_noground(Volts,Ohms,Amps)
:- battery(B1,B2,Volts), resistor(R1,R2,Ohms), ammeter(A1,A2,Amps), connect([B2,A1]), connect([A2,R1]), connect([R2,B1]). /* voltage divider */ divider(Volts,Ohms1,Ohms2,Amps,VCe nter) :- battery(B1,B2,Volts), resistor(R1,R2,Ohms1), resistor(S1,S2,Ohms2), ammeter(A1,A2,Amps), voltmeter(V1,V2,VCenter), electrical_ground(G), connect([B2,A1]), connect([A2,R1]), connect([R2,S1,V1]), connect([S2,V2,B1,G]). divider_noground(Volts,Ohms1,Ohms2 ,Amps ,VCen ter) :- battery(B1,B2,Volts), resistor(R1,R2,Ohms1), resistor(S1,S2,Ohms2), ammeter(A1,A2,Amps), voltmeter(V1,V2,VCenter), connect([B2,A1]), connect([A2,R1]), connect([R2,S1,V1]), connect([S2,V2,B1]). /* Wheatstone bridge */ wheat(Volts,WOhms,XOhms,YOhms,ZOhm s,Amp s) :- battery(B1,B2,Volts), resistor(W1,W2,WOhms), resistor(X1,X2,XOhms), resistor(Y1,Y2,YOhms), resistor(Z1,Z2,ZOhms), ammeter(A1,A2,Amps), electrical_ground(G), connect([B2,W1,X1]), connect([B1,Y2,Z2,G]), connect([W2,Y1,A1]), connect([X2,Z1,A2]). wheat_noground(Volts,WOhms,XOhms,Y Ohms, ZOhms ,Amps ) :- battery(B1,B2,Volts), resistor(W1,W2,WOhms), resistor(X1,X2,XOhms), resistor(Y1,Y2,YOhms), resistor(Z1,Z2,ZOhms), ammeter(A1,A2,Amps), connect([B2,W1,X1]), connect([B1,Y2,Z2]), connect([W2,Y1,A1]), connect([X2,Z1,A2]). ladder(T1,T2,Ohms,1) :- /*
  • ne
rung */ resistor(T1,A,Ohms), resistor(T2,B,Ohms), resistor(R1,R2,Ohms), connect([A,R1]), connect([B,R2]). ladder(T1,T2,Ohms,N) :- N>1, ladder(X1,X2,Ohms,N-1), resistor(T1,A,Ohms), resistor(T2,B,Ohms), resistor(R1,R2,Ohms), connect([A,R1,X1]), connect([B,R2,X2]). /* SAMPLE GOALS */ go1 :-
  • ne_resistor(100,50,A),
dump([A]). go2 :-
  • ne_noground(100,50,A),
dump([A]). go3 :- divider(100,30,20,Amps,VCenter), dump([Amps,VCenter]). go4 :- divider_noground(100,30,20,Amps, VCent er),
slide-13
SLIDE 13 dump([Amps,VCenter]). go5(XOhms) :- wheat(100,100,XOhms,50,30,Amps), dump([XOhms,Amps]). go6(XOhms) :- wheat_noground(100,100,XOhms,50, 30,Am ps), dump([XOhms,Amps]). go7(N) :- ladder(T1,T2,10,N), battery(B1,B2,100), ammeter(A1,A2,Amps), electrical_ground(G), connect([B2,A1]), connect([A2,T1]), connect([T2,B1,G]), dump([Amps]). CLP(R) Implementation Constraint Logic Abstract Machine (CLAM) | derived from W a rren Abstract Machine (W AM) The Engine The engine is a structure sha ring Prolog inter- p reter (see Figure 2, page 360) Distinguish b et w een constraints that can b e handled in the engine (e.g. nonsolver va riable = numb er) and those that must b e passed to the interface. Constraints that can b e handled in the engine a re sho wn in gure 3, page 361. 34 The Interface Simplify input constraint b y evaluating a rith- metic exp ressions. If constraint is ground, test it. If there is
  • ne
non-solver va riable, set up a binding. Otherwise put constraint into a canonical fo rm and invok e solver. Solver solver mo dules:
  • equalit
y solver
  • inequalit
y solver
  • nonlinea
r handler 35 Equalit y Solver Equalit y solver uses va riant
  • f
Gaussian elimi- nation. Rep resent nonpa rametric va riables in terms
  • f
pa rametric va riables and constants. Central data structure: a tableau (2d a rra y). Each ro w rep resents some nonpa rametric va riable as a linea r combination
  • f
pa rametric va riables. Equalit y solver is invok ed b y the interface with a new equalit y , from the inequalit y solver with an implicit equalit y ,
  • r
with a dela y ed con- straint from the nonlinea r handler. 36
slide-14
SLIDE 14 Inequalit y Solver and Nonlinea r Handler Inequalit y Solver: adapted from rst phase
  • f
t w
  • -phase
Simplex algo rithm. Simplex augmentations:
  • unconstrainted
va riables and slack va riables
  • symb
  • lic
entries denoting innitesimal val- ues
  • negative
  • r
p
  • sitive
co ecients fo r basic unconstrained va riables Solver detects implicit equalities (could scrap equalit y solver and just do it all with Simplex ...) Nonlinea r handler: dela y nonlinea r constraints until they b ecome linea r 37