Programming in hybrid constraint languages - PowerPoint PPT Presentation

1 / 33
About This Presentation
Title:

Programming in hybrid constraint languages

Description:

Programming in hybrid constraint languages M2 – PowerPoint PPT presentation

Number of Views:259
Avg rating:3.0/5.0
Slides: 34
Provided by: Mud69
Category:

less

Transcript and Presenter's Notes

Title: Programming in hybrid constraint languages


1
Programming in hybrid constraint languages
  • ????? M2
  • ?? ??

2
The relations between the cc languages
  • cc
    cc
  • Default cc Timed cc Default cc
    Timed cc
  • cc defaults cc time

  • Timed default cc
  • Hybrid cc Timed Default cc
  • cc defaults cc defaults
  • cont.time discrete time
    Hybrid cc

3
Hybrid cc
  • ????????????????????????????????
  • ???????????????
  • Example ??????????????
  • ????????????????????????
  • ?????????????????????????
  • ?????????????

4
The cc Programming Language
  • ??store?Agent(tell,ask)???????????????
  • Example program x10,x0,if xgt0 then x-10

5
Hybrid cc the language and its use
  • c tell the constraint c
  • if d then A if d holds,reduce to A
  • if d else A reduce to A unless d holds
  • A,B Parallel Composition
  • new V in A V is local to A
  • hence A execute A at every instant
  • after now

6
Hcc Example1
x10,x'0, henceif xgt0 then x''-10,
if x0 then x' -0.5x'
7
Hcc Example2
  • Prey Predator(in Hcc)
  • py8, //prey
  • pd2, //predator
  • pd0.2,
  • always py0.08py 0.04pypd //prey growth
  • always
  • cont(pd)
  • if(pdgt0.5py) then
  • pd-0.1pd0.02pypd
  • else
  • pd-0.06pd0.02pypd
  • ,
  • sample(pd), sample(py)

8
PreyPredator
FigurePreyPredator
9
Computational model
  • ?????????????
  • 1. Point Phase(???????????)
  • 2. Interval Phase(???????????)
  • ? 1 , 2??????????

10
The Control Constructs and Execution of hcc
  • Hcc?????

1. Point Phase????? 2. Point Phase????????????? 3.
Interval Phase??? 4. ??????????????????(4th
order Runge-Kutta?) 5. ???????????????????????????
??? ?????? 6. ??????Point Phase??? ????1
6?????
11
Execution of hcc
  • Example
  • X 0,hencex1,if(x2) then y1
  • In the interval phase following x0,x evolves
    continuously
  • according to x1,through the interval(0,2) until
    x2 is about to
  • become true.
  • At this point the set of constraints may
    change,so the next point
  • phase is started.

12
Continuous Constraints
  • ContConstr Term RelOp Term
    cont(LVariable) lcont(LVariable)
  • RelOp gt lt
  • Term LVariableExpr Constant
    Term BinOp Term
  • UnOp(Term)
    dot(Term,Num) Term (Term)
  • LVariableExpr Lvariable Uvariable.LVariable
    Expr
  • BinOp - ? /
  • UnOp - log exp prev
  • Lvariables are strings which start with a
    lowercase character.
  • Constants are floating point numbers.
  • exp(x) is the exponential function ex.
  • Term denotes the derivative of Term.
  • dot(Term , n) denotes the nth derivative of
    Term(n is a natural number) .

13
Ask Constraints(for Continuous Constraints)
  • AContConstr Term ARelOp Term
  • ARelOp gt lt lt gt !

14
Non-arithmetic Constraints
  • Dconstr UVariableExpr
    UVarExpr Dexpr
  • UVariableExpr UVariable
    UVariableExpr.UVariableExpr
  • Dexpr UVariableExpr
    prev(UVariableExpr) String

  • (VarList)HccAgent

  • (VarList)VarListHccAgent

  • UVariableExpr(VarList) VarListHccAgent
  • VarList Uvariable Lvariable
    VarList,VarLIst
  • Uvariable is a string starting with an
    uppercase character.
  • HccAgent is hcc Agent.

15
Closure Class definition
  • Closure definition X (A,x) Agent
  • Class definition X (m,n)A,m Agent

16
Closure definition
  • X (A,x)Agent
  • Example
  • P (n,m,Q)
  • if n gt 0 then
  • new m1 in Q(n-1,m1,Q), m m1n
  • else
  • m 1
  • ,
  • Fact (n,m) P(n,m,P),
  • Fact(10,m)

17
Class Definition
  • X (m,n)A,m Agent
  • Example
  • Planet (initvx,initvy,initpx,initpy,m)px,py,mas
    s
  • px initpx, py initpy, px initvx,
    py initvy,
  • always
  • massm,
  • pxsum(F.x,Force(F),F.Targe
    t Self),
  • pysum(F.x,Force(F),F.Targe
    t Self)

18
Boolean Constraints
  • BoolConstr Atom StrConstr ContConstr
  • Bool BoolConstr
    (BoolConstr)
  • ABoolConstr Atom StrConstr AContConstr
  • ABool ABoolConstr
  • ABoolConstr
    ABoolConstr
  • (ABoolConstr)

19
Reduction Rules
  • Tell lt(G, c),s,next, default ? ltG,s U c,next,
    default
  • s- d
  • Ask
  • lt(G,if d then A),s,next, defaultgt ?
    lt(G,A),s,next, defaultgt
  • else lt(G,if d else A),s,next,elsegt ?
    ltG,s,next,(else, if d else A)gt

G denotes a set of Hybrid cc program
fragments. s denotes the store.
next the set of program fragments to be run
in the next phase. default a
set of suspended else statements. s - c
denotes entailment checking.
20
Reduction rules(for Hence)
  • The rule for hence A differs in point and
    interval phases
  • Hence Point lt(G,hence A), s, next ,
    defaultgt ?
  • ltG , s, ltnext ,
    hence Agt, defaultgt
  • Hence Interval lt(G, hence A), s, next ,
    defaultgt ?
  • lt(G, A), s, (next
    , A , hence A), defaultgt
  • G denotes a set of Hybrid cc program
    fragments.
  • s denotes the store.
  • next the set of program fragments to be
    run in the next phase.
  • default a set of suspended else statements.
  • s - c denotes entailment checking.

21
The algorithm for interpreter
  • 1. Run the reduction rules on the current
    ltG,s,next defaultgt,
  • till no further reductions can take place.
  • 2. If s is inconsistent , return 0 (false).
  • 3. If default is empty , return 1 (true).
  • 4. Remove one statement from default if c
    else A.
  • If s - c , go to step 3.
  • 5. Add A to G. Run the interpreter on the
    current state.
  • If the result is 1 and s -/ c , return 1.
  • 6. Undo the effects of the previous step by
    backtracking.
  • Run the interpreter on the current state.
  • If the result is 1 and s -/ c , return 1.
    Otherwise return 0.

22
  • A Hybrid cc program A is run as follows.
  • 1. Run interpreter with G A , and empty s,
    next and default
  • in the point phase. If the result is 0,
    abort.
  • 2. Run the interval phase with G next , as
    returned by the point
  • phase.
  • s , next and default are again empty. If the
    result is 0, abort.
  • Record all the tells , and also the ask
    constraints that were checked
  • during the phase.
  • 3. Integrate the arithmetic constraints that were
    told in the previous
  • step,until one of the ask constraints changes
    status(i.e.goes from
  • false to true or unknown, etc.). Go to step 1
    with G next.

23
Nonlinear equations
  • Indexicals
  • Interval splitting
  • The Newton-Raphson method
  • The Simplex method
  • ???4???????????????????????

24
Indexicals
  • ??f(x,y)0?xg(y)????????
  • Example
  • x y 0, x ? 0,3, and y ? -1, -2.
  • Then the indexical x -y is used to set to 1,
    2.

25
Interval splitting
  • ??a,b???????????
  • a1smallest number 0?f(a1,b) and a?a1.
  • Hence,if 0?f(a,(ab)/2),then
    a1?a,(ab)/2,
  • otherwise a1?(ab)/2,b
  • b1??????
  • Example x21 and x ?-8 , 8.
  • It follows that 0 ?-8 , 0.
  • 0 ?/ -8 , -100. a1 is determined to be in
    -100 , 0.
  • Eventually, a1 is determined to be 1.

26
The Newton-Raphson method
  • ???f(x)0??????????
  • Interval?????????????
  • ?????f(x)?????f(x)0???x?????
  • ???????????x0????f(x)????????
  • ???????y-f(x0)f(x0)(x-x0)??????????
  • ?????X?????x1?y0?????x1x0-f(x0)/f(x0)
  • ???????
  • ??x1??f(x)?????x??????x2?????????
  • ??????????f(x)0???????i?????????
  • xi1xi-f(xi)/f(xi)?????????e???????
  • xi1-xilte??????xi1???????

27
Splitting Newton-Raphson method
  • Splitting?Newton-Raphson method???????(clp
    Newton)?
  • Example
  • x21 and x?I-8, 8
  • 1. Split I recursively until I is split down to
    -2,-1.
  • 2. Applying the N-R method-1,-1 is produced.
  • 3. Similarly,1,1 is produced.
  • 4. Only 1 and 1 are solutions to the equation.

28
The Control Constructs and Execution of hcc
  • Hcc?????

1. Point Phase????? 2. Point Phase????????????? 3.
Interval Phase??? 4. ??????????????????(4th
order Runge-Kutta?) 5. ???????????????????????????
??? ?????? 6. ??????Point Phase??? ????1
6?????
29
Runge-Kutta algorithm
4?????????
30
Runge-Kutta algorithm
1. A????????? k1??? 2. B?(xih/2,yik1/2)???
?????k2??? 3. C?(xih/2,yik2/2)???
?????k3??? 4. D?(xih,yik3)???? ????k4??? 5.
k1 k4???????? ?????????yi????
?????yi1???? k1h(xi,yi),k2hf(xih/2,yik1/2),
k3hf(xih/2,yik2/2), k4hf(tih,xik3)
yi1yi(k12k22k3k4)/6
31
Program Example
  • ball.hcc
  • / A simple example of a ball bouncing on the
    floor.
  • /
  • y 10, y' 0, // initial
    conditions
  • hence
  • if y gt 0 then y'' -10, // free fall
  • if y 0 then // bounce
  • if (prev(y') gt -0.000001) then always y'
    0 // end of bouncing
  • else y' -0.5 prev(y')
  • ,
  • sample(y)

32
??????(5??)
33
????
  • B.Carlson and V.Gupta.Hybrid cc with interval
    constraints.
  • V.Gupta,R.Jagadeesan,V.A.Saraswat,and D.Bobrow.
  • Programming in hybrid concurrent constraint
    languages.In Panos
  • Antsakis,Wolf Kohn,Anil Nerode,and Sankar
    Sastry,editors,Hybrid
  • Systems ?,volume999 of Lecture Notes in
    Computer Science,1995
  • V.Gupta,R.Jagadeesan,V.Saraswat,and D.Bobrow.
  • Programming in hybrid constraint languages
Write a Comment
User Comments (0)
About PowerShow.com