130 likes | 269 Views
Action Rules (AR). Early Implementation methods Complex abstract machines (e.g., CHIP) Special purpose constructs Indexicals, delay constructs, attribute variables General purpose language (CHR) Motivation of AR
E N D
Action Rules (AR) • Early Implementation methods • Complex abstract machines (e.g., CHIP) • Special purpose constructs • Indexicals, delay constructs, attribute variables • General purpose language (CHR) • Motivation of AR • A powerful , flexible, and efficient language for implementing propagation-based constraint solvers by Neng-Fa Zhou
Suspension & Domain Variables • Suspension variables • susp_attach_term(X,T) • Attach term T to X • susp_attached_term(X,T) • The attached term to X is T • Domain variables • fd_var(V),fd_first(V,N),fd_last(V,N),fd_size(V,N),fd_true(V,E),fd_set_false(V,E),fd_next(V,E,NextE),fd_prev(V,E,PrevE) by Neng-Fa Zhou
Syntax and Semantics of AR • Syntax Agent, Condition, {Event} => Action • Operational semantics • An agent (sub-goal) C will be suspended if: • C matches Agent, • Condition is met, and • Event is not empty • C is activated whenever an event in Event is posted • Action is executed when C is activated and Condition is met • C is suspended again after Action is executed • The next rule is tried if Condition fails • Cfails if Action fails by Neng-Fa Zhou
Posting Events: post(E) • event(X,O) • X – suspension variable • O – event object • Events for programming propagators • ins(X) – X is instantiated • bound(X) – The bound of the domain of X is updated • dom(X,E) – E is excluded from the domain of X by Neng-Fa Zhou
Example 1An Echoing Agent echo_agent(X), {event(X,Message)} => write(Message),nl. by Neng-Fa Zhou
Example 2freeze(X,G) freeze(X,G), var(X), {ins(X)} => true. freeze(X,G) => call(G). by Neng-Fa Zhou
Propagators for aX=bY+c • Forward checking 'aX=bY+c_forward'(A,X,B,Y,C),var(X),var(Y), {ins(X),ins(Y)} => true. 'aX=bY+c_forward'(A,X,B,Y,C),var(X) => T is B*Y+C,Ex is T//A, A*Ex=:=T. 'aX=bY+c_forward'(A,X,B,Y,C) => T is A*X-C, Ey is T//B, B*Ey=:=T. When either X or Y is instantiated, instantiate the other variable. by Neng-Fa Zhou
Propagators for aX=bY+c • Interval consistency 'aX in bY+c_interval'(A,X,B,Y,C),var(X),var(Y), {bound(Y)} => 'aX in bY+c_reduce_domain'(A,X,B,Y,C). 'aX in bY+c_interval'(A,X,B,Y,C) => true. Whenever the bound of Y’s domain is updated, reduce X’s domain to achieve interval consistency. by Neng-Fa Zhou
Propagators for aX=bY+c • Arc consistency 'aX in bY+c_arc'(A,X,B,Y,C),var(X),var(Y), {dom(Y,Ey)} => T is B*Ey+C, Ex is T//A, (A*Ex=:=T -> exclude(X,Ex);true). 'aX in bY+c_arc'(A,X,B,Y,C) => true. Whenever an element Ey is excluded from Y’s domain, exclude Ey’s counterpart Ex from X’s domain. by Neng-Fa Zhou
Propagator for A1*X1+...+An*Xn+C = 0 'A1*X1+...+An*Xn+C=0'(C,A1,A2,...,An,X1,X2,..,Xn), n_vars_gt(n,2), {ins(X1),bound(X1),...,ins(Xn),bound(Xn)} => reduce domains of X1,..,Xn to achieve ic. 'A1*X1+...+An*Xn+C=0'(C,A1,A2,...,An,X1,X2,..,Xn) => nary_to_binary(NewC,B1,B2,Y1,Y2), call_binary_propagator(NewC,B1,Y1,B2,Y2). When the constraint has more than 2 variables, achieve interval consistency. When the constraint is binary archive arc consistency. by Neng-Fa Zhou
Performance EvaluationCLP(FD) BP: 6.4, Eclipse (EP) 5.5 #46, Sicstus (SP) 3.10, Gnu-Prolog (GP) 1.2.16) by Neng-Fa Zhou
Performance EvaluationCLP(SET) by Neng-Fa Zhou
Papers • N.F. Zhou: Programming Finite-Domain Constraint Propagators in Action Rules, submitted to TPLP, 2004. • N.F. Zhou: Implementing Constraint Solvers in B-Prolog, IFIP World Congress, Intelligent Information Processing, pp.249-260, 2002. • N.F. Zhou: A High-Level Intermediate Language and the Algorithms for Compiling Finite-Domain Constraints, Proc. Joint International Conference and Symposium on Logic Programming, pp.70-84, 1998. • N.F. Zhouand J.Schimpf: Implementation of Propagation Rules for Set Constraints Revisited, unpublished manuscript, 2002. by Neng-Fa Zhou