Debian Codegraph @

test/regress/cli/regress1/sygus/node-discrete.sy

raw
1 ; EXPECT: feasible
2 ; COMMAND-LINE: --sygus-out=status --lang=sygus2 --no-check-synth-sol --arrays-exp
3 (set-logic ALL)
4
5 (declare-datatype Packet ((P1) (P2)))
6
7 (declare-datatype Node ((A) (B) (C)))
8
9 (declare-datatype SPair ((mkPair (pnode Node) (ppacket Packet))))
10
11 (declare-datatype State ((mkState (rcv (Array SPair Bool)))))
12 (declare-datatype StateList ((consSL (headSL State) (tailSL StateList)) (nilSL)))
13
14 ; C is destination of P1 and P2
15 (define-fun h_State ((s State)) Real
16 (+
17 (ite (select (rcv s) (mkPair C P1)) 1.0 0.0)
18 (ite (select (rcv s) (mkPair C P2)) 1.0 0.0)
19 )
20 )
21
22 ; reliability
23 (define-fun rel () Real 0.7)
24
25 ; new chance of feasible
26 (define-fun updateReal ((addP Real) (currP Real)) Real
27 (+ currP (* (- 1.0 currP) addP))
28 )
29
30 ; Actions and how they are interpreted
31
32 (declare-datatype Action (
33 (sleep)
34 (pushPck (push_dst Node) (push_pck Packet))
35 (pullPck (pull_src Node) (pull_pck Packet))
36 ))
37 (declare-datatype ActionList ((consAL (headA Action) (tailA ActionList)) (nilAL)))
38
39 ;; returns true if action is valid for actor in state s
40 (define-fun preconditionAction ((actor Node) (a Action) (s State)) Bool
41 (let ((rcv (rcv s)))
42 (ite ((_ is pullPck) a)
43 (let ((pck (pull_pck a)))
44 ; don't pull if already recieved the packet
45 (not (select rcv (mkPair actor pck)))
46 )
47 true
48 )
49 )
50 )
51
52 ; which action fires in state s?
53 (define-fun-rec actionListToAction ((actor Node) (al ActionList) (s State)) Action
54 (ite ((_ is consAL) al)
55 (let ((a (headA al)))
56 (ite (preconditionAction actor a s)
57 a
58 (actionListToAction actor (tailA al) s)
59 )
60 )
61 sleep
62 )
63 )
64
65 (declare-datatype PState ((mkPState (states StateList) (prob (Array State Real)))))
66
67 (define-fun-rec h_PState_rec ((pssl StateList) (pspb (Array State Real))) Real
68 (ite ((_ is consSL) pssl)
69 (let ((s (headSL pssl)))
70 (+ (* (select pspb s) (h_State s)) (h_PState_rec (tailSL pssl) pspb))
71 )
72 0.0)
73 )
74 (define-fun h_PState ((ps PState)) Real
75 (h_PState_rec (states ps) (prob ps))
76 )
77
78 (define-fun nilPState () PState
79 (mkPState nilSL ((as const (Array State Real)) 0.0))
80 )
81 (define-fun-rec appendStateToPState ((s State) (r Real) (p PState)) PState
82 (let ((pstates (states p)))
83 (let ((pprob (prob p)))
84 (let ((pr (select pprob s)))
85 (mkPState
86 ; add to list if not there already
87 (ite (= pr 0.0)
88 (consSL s pstates)
89 pstates
90 )
91 (store
92 pprob
93 s (+ r pr)
94 )
95 )
96 )))
97 )
98
99
100 (define-fun transNode ((actor Node) (a Action) (r Real) (s State) (psp PState)) PState
101 (let ((prevRcv (rcv s)))
102 (ite ((_ is pushPck) a)
103 (let ((dst (push_dst a)))
104 (let ((pck (push_pck a)))
105 (let ((dst_pair (mkPair dst pck)))
106 (let ((src_pair (mkPair actor pck)))
107 (let ((chSuccess (ite (select prevRcv src_pair) rel 0.0)))
108 ; feasible and failure
109 (appendStateToPState
110 (mkState (store prevRcv dst_pair true))
111 (* r chSuccess)
112 (appendStateToPState
113 s
114 (* r (- 1.0 chSuccess))
115 psp
116 ))
117 )))))
118 (ite ((_ is pullPck) a)
119 (let ((src (pull_src a)))
120 (let ((pck (pull_pck a)))
121 (let ((dst_pair (mkPair actor pck)))
122 (let ((src_pair (mkPair src pck)))
123 (let ((chSuccess (ite (select prevRcv src_pair) rel 0.0)))
124 ; feasible and failure
125 (appendStateToPState
126 (mkState (store prevRcv dst_pair true))
127 (* r chSuccess)
128 (appendStateToPState
129 s
130 (* r (- 1.0 chSuccess))
131 psp
132 ))
133 )))))
134 (appendStateToPState
135 s
136 r
137 psp)
138 ))
139 )
140 )
141
142 (define-fun-rec transNodeListRec ((actor Node) (al ActionList) (ps PState) (pssl StateList) (psp PState)) PState
143 ; if more states to consider in s
144 (ite ((_ is consSL) pssl)
145 (let ((s (headSL pssl)))
146 (let ((r (select (prob ps) s)))
147 (transNode actor (actionListToAction actor al s) r s
148 (transNodeListRec actor al ps (tailSL pssl) psp))
149 ))
150 psp)
151 )
152
153 (define-fun-rec transNodeList ((actor Node) (al ActionList) (ps PState) (psp PState)) PState
154 (transNodeListRec actor al ps (states ps) psp)
155 )
156
157 (define-fun trans ((aa ActionList) (ab ActionList) (ac ActionList) (ps PState)) PState
158 ;(transNodeList A aa ps
159 ;(transNodeList B ab ps
160 (transNodeList C ac ps
161 nilPState);))
162 )
163
164 (synth-fun actionA () ActionList
165 ((GAL ActionList) (GA Action) (GN Node) (GP Packet))
166 (
167 (GAL ActionList (nilAL))
168 (GA Action ((pushPck GN GP) (pullPck GN GP)))
169 (GN Node (B C))
170 (GP Packet (P1 P2))
171 )
172 )
173 (synth-fun actionB () ActionList
174 ((GAL ActionList) (GA Action) (GN Node) (GP Packet))
175 (
176 (GAL ActionList (nilAL))
177 (GA Action ((pushPck GN GP) (pullPck GN GP)))
178 (GN Node (A C))
179 (GP Packet (P1 P2))
180 )
181 )
182 (synth-fun actionC () ActionList
183 ((GAL ActionList) (GA Action) (GN Node) (GP Packet))
184 (
185 (GAL ActionList ((consAL GA GAL) nilAL))
186 (GA Action ((pushPck GN GP) (pullPck GN GP)))
187 (GN Node (A B))
188 (GP Packet (P1 P2))
189 )
190 )
191
192
193 ; A and B initially have packets P1 and P2
194 (define-fun init-state () State
195 (mkState
196 (store
197 (store
198 ((as const (Array SPair Bool)) false)
199 (mkPair B P2) true
200 )
201 (mkPair A P1) true
202 )
203 )
204 )
205
206 (define-fun init-pstate () PState
207 (appendStateToPState init-state 1.0 nilPState)
208 )
209
210 ; expected value of packets is greater than 1.0 after 2 time steps.
211 (constraint
212 (< 1.0 (h_PState
213 (trans actionA actionB actionC (trans actionA actionB actionC init-pstate))
214 ))
215 )
216 (check-synth)