Presentation is loading. Please wait.

Presentation is loading. Please wait.

Action Rules for Programming Constraint Propagators and Interactive User Interfaces Neng-Fa Zhou CUNY Brooklyn College & GC

Similar presentations


Presentation on theme: "Action Rules for Programming Constraint Propagators and Interactive User Interfaces Neng-Fa Zhou CUNY Brooklyn College & GC"— Presentation transcript:

1 Action Rules for Programming Constraint Propagators and Interactive User Interfaces Neng-Fa Zhou CUNY Brooklyn College & GC zhou@sci.brooklyn.cuny.edu www.sci.brooklyn.cuny.edu/~zhou

2 Outline of Talk 4 Motivation 4 Action Rules 4 Programming Constraint Propagators (www.sci.brooklyn.cuny.edu/~zhou/papers/arule.ps) 4 CGLIB: Constraint-based Graphics Library ( www.sci.brooklyn.cuny.edu/~zhou/papers/acmdoc01.pdf) 4 Demo of B-Prolog v.6 (www.probp.com)

3 Motivation 4 The need for a language for programming reactive systems –Constraint propagators –Event handling –Concurrency –Interactive user interfaces –Agents

4 4 Operational semantics –An agent (sub-goal) C will be suspended if: C matches Agent, ConditionSeq is met, and EventSet is not empty –C is activated whenever an event in EventSet is posted –ActionSeq is executed when C is activated and ConditionSeq is met –C is suspended again after ActionSeq is executed –The next rule is tried if ConditionSeq fails –C fails if ActionSeq fails Agent, ConditionSeq, {EventSet} => ActionSeq 4 Syntax Action Rule

5 Posting Events post(E) 4 event(X,O) –X – suspension variable –O – event object 4 Events for programming propagators –ins(X) – X is instantiated –… 4 Events for graphics programming –actionPerformed(O) – action performed on O –…

6 Example 1 An Echoing Agent echo_agent(X), {event(X,Message)} => write(Message),nl.

7 Example 2 freeze(X,G) freeze(X,G), var(X), {ins(X)} => true. freeze(X,G) => call(G).

8 Programming Constraint Propagators 4 Action rules are expressive –Propagators for maintaining node, interval, arc consistency –Propagators for global constraints 4 Action rules are efficient –B-Prolog is competitive with Ilog solver and GNU-Prolog

9 Constraint Propagation X = Y+1 (X,Y in 1..5) Algorithm Change Propagation Node consistency X=3X = 3, Y = 2 Interval consistencygeneratedX in 2..5, Y in 1..4 5 notin X X in 2..4, Y in 1..3 Arc consistency4 notin XX in [2,3,5], Y in [1,2,4]

10 Events for Programming Propagators 4 ins(X) –X is instantiated 4 minmax(X) –The bound of X is updated 4 dom(X,E) –An inner element E has been excluded from X

11 Propagators for aX=bY+c 4 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->X = Ex; true). 'aX=bY+c_forward'(A,X,B,Y,C) => T is A*X-C, Ey is T//B, (B*Ey=:=T->Y is Ey;true). When either X or Y is instantiated, instantiate the other variable.

12 Propagators for aX=bY+c 4 Interval consistency 'aX in bY+c_interval'(A,X,B,Y,C),var(X),var(Y), {minmax(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.

13 Propagators for aX=bY+c 4 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. When an element Ey is excluded from Y ’s domain, exclude Ey ’s counterpart Ex from X ’s domain.

14 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),minmax(X1),...,ins(Xn),minmax(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.

15 Performance Evaluation B-Prolog Ilog GNU-Prolog CHIP Eclipse Sicstus Mozart Oz Fast Slow 1 2 4

16 CGLIB -- A Constraint-based Graphics Library 4 Features –Use constraints to specify the layouts of objects –Use action rules to specify interactions 4 Implementation –Implemented in B-Prolog, Java, and C 4 Applications –Drawing editors, interactive user interfaces, document authoring, animation, information visualization, intelligent agents, and games.

17 An Illustrative Example go:- cgButton(B), (1) B^text #= “Hello World!”,(2) handleButtonClick(B),(3) cgShow(B).(4) handleButtonClick(B),(5) {actionPerformed(B)} (6) => (7) halt.(8)

18 Objects 4 cgButton(X) –Create a button X 4 cgButton([X1,…,Xn]) –Create a list of buttons

19 Attributes of Objects 4 Base 4 Derivative x y width height B is a button B^window B^x B^y B^width B^height B^text B^color B^font B^rightX B^bottomY B^centerX B^centerY B^leftTopPoint B^leftBottomPoint B^rightTopPoint B^rightBottomPoint B^center

20 Constraints 4 Arithmetic constraints O1^x +O1^width//2 #= O2^x O1^centerX #= O2^x 4 Positioning constraints cgLeft(O1,O2) 4 Same property constraints cgSame([O1,O2],size) cgSame([O1,O2],width,100)

21 Constraints (Cont.) 4 Grid constraints cgGrid([[_, S1,_], [S2,S3,S4], [_,S5,_]]) cgGrid([[Bc,Bdiv,Bmul,Bsub], [B7,B8, B9, Badd], [B4,B5, B6, Badd], [B1,B2, B3, Beq], [B0,B0, Bdot,Beq]],1,1),

22 Constraints (Cont.) 4 Table constraints cgTable([[Larc,Arc,Button,Lbutton], [Lcheckbox, Checkbox, Choice, Lchoice], [Lcircle,Circle,Image,Limage], [Llabel,Label,Line,Lline], [Llist,List,Oval,Loval], [Lrrectangle,Rrectangle,Rectangle,Lrectangle], [Lpolygon,Polygon,Square,Lsquare], [Lstar,Star,TextArea,Ltextarea], [Ltextfield,TextField,TextBox,Ltextbox], [Ltriangle,Triangle,_,_]],20,20),

23 Constraints (Cont.) 4 Tree constraints T=node(C0,[node(C1,[node(C3,[] node(C4,[])]), node(C2,[node(C5,[]), node(C6,[])])]), cgTree(T,top_down,10,10,centered).

24 Event Handling 4 Action rule 4 Examples Agent ConditionSeq {Event} => ActionSeq handleButtonClick(B),{actionPerformed(B)} => … handleMousePress(O),{mousePressed(O,E)} => E^x #= X, E^y #= Y, write(mouse_pressed_at(X,Y)),nl. handleKeyType(O),{keyTyped(O,E)} => E^char #= Char, write(Char).

25 Other Primitives in CGLIB 4 Packing and showing objects cgPack(O)& cgShow(O) 4 Altering and moving objects O^attr #:= Value cgScale(O,F)& cgResize(O,W,H) cgMove(O,X,Y) 4 Animation cgSleep(Time) 4 Generating Java applets cgStartRecord(FileName) & cgStopRecord

26 Demo of B-Prolog 4 B-Prolog (Version 6.0) (www.probp.com)www.probp.com –Graphical user interfaces –Animation –Information visualization –Constraint satisfaction problems –Games

27 Related Work 4 Programming Constraint Propagators Indexicals (GNU-Prolog & Sicstus) Delay constructs Attribute variables (Eclipse) Constraint handling rules 4 Graphics programming –Postscript & Latex Every detail must be specified –Java & Tcl/Tk Layout managers are helpful for certain layouts –Constraints & Constraint programming Sketchpad, ThinkLab, Amulet, SubArctic


Download ppt "Action Rules for Programming Constraint Propagators and Interactive User Interfaces Neng-Fa Zhou CUNY Brooklyn College & GC"

Similar presentations


Ads by Google