Title: Programming in hybrid constraint languages
1Programming in hybrid constraint languages
2The 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 -
3Hybrid cc
- ????????????????????????????????
- ???????????????
- Example ??????????????
- ????????????????????????
- ?????????????????????????
- ?????????????
4The cc Programming Language
- ??store?Agent(tell,ask)???????????????
-
- Example program x10,x0,if xgt0 then x-10
5Hybrid 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
6Hcc Example1
x10,x'0, henceif xgt0 then x''-10,
if x0 then x' -0.5x'
7Hcc 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)
8PreyPredator
FigurePreyPredator
9Computational model
- ?????????????
- 1. Point Phase(???????????)
-
- 2. Interval Phase(???????????)
- ? 1 , 2??????????
10The Control Constructs and Execution of hcc
1. Point Phase????? 2. Point Phase????????????? 3.
Interval Phase??? 4. ??????????????????(4th
order Runge-Kutta?) 5. ???????????????????????????
??? ?????? 6. ??????Point Phase??? ????1
6?????
11Execution 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.
12Continuous 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) . -
13Ask Constraints(for Continuous Constraints)
- AContConstr Term ARelOp Term
- ARelOp gt lt lt gt !
14Non-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.
15Closure Class definition
- Closure definition X (A,x) Agent
- Class definition X (m,n)A,m Agent
-
16Closure 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)
17Class 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) -
-
18Boolean Constraints
-
- BoolConstr Atom StrConstr ContConstr
- Bool BoolConstr
(BoolConstr) - ABoolConstr Atom StrConstr AContConstr
- ABool ABoolConstr
- ABoolConstr
ABoolConstr - (ABoolConstr)
19Reduction 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.
20Reduction 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.
21The 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. -
23Nonlinear equations
- Indexicals
- Interval splitting
- The Newton-Raphson method
- The Simplex method
-
- ???4???????????????????????
24Indexicals
- ??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.
25Interval 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.
26The 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???????
27Splitting 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.
28The Control Constructs and Execution of hcc
1. Point Phase????? 2. Point Phase????????????? 3.
Interval Phase??? 4. ??????????????????(4th
order Runge-Kutta?) 5. ???????????????????????????
??? ?????? 6. ??????Point Phase??? ????1
6?????
29Runge-Kutta algorithm
4?????????
30Runge-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
31Program 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