Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
AVANZINI Martin
ecoimp
Commits
4a37c023
Commit
4a37c023
authored
May 11, 2020
by
AVANZINI Martin
Browse files
templates templates templates
parent
8de9c4c9
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
examples/2drobot.imp
deleted
100644 → 0
View file @
8de9c4c9
# 2D Robot
# Chatterjee et al., Cost Analysis of Nondeterministic Programs
#
# **2D Robot** We consider a robot walking in a plane. Suppose
# that the robot is initially located below the line y = x and
# we want it to cross this line, i.e. the program continues until
# the robot crosses the line. At each iteration, the robot prob-
# abilistically chooses one of the following 9 directions and
# moves in that direction: {0: North, 1: South, 2: East, 3: West, 4:
# Northeast, 5: Southeast, 6: Northwest, 7: Southwest, 8: Stay}.
# Moreover, the robot’s step size is a uniformly random vari-
# able between 1 and 3. At the end of each iteration, a cost is
# incurred, which is dependent on the distance between the
# robot and the line y = x.
# Note: use approximation `tick(x-y)` instead of `tick(0.707 * (x-y))`
def f():
var x, y, r, a, b
x = a
y = b
while y <= x:
prob(1,4):
r = unif(1,3)
y = y + r
else:
prob(1,7):
r = unif(1,3)
y = y - r
else:
prob(1,6):
r = unif(1,3)
x = x + r
else:
prob(1,5):
r = unif(1,3)
x = x - r
else:
prob(1,4):
r = unif(1,3)
x = x + r
r = unif(1,3)
y = y + r
else:
prob(1,3):
r = unif(1,3)
x = x + r
r = unif(1,3)
y = y - r
else:
prob(1,2):
r = unif(1,3)
x = x - r
r = unif(1,3)
y = y + r
else:
prob(1,1):
r = unif(1,3)
x = x - r
r = unif(1,3)
y = y - r
else:
skip
# tick(0.707 * (x-y))
tick(x-y)
results
View file @
4a37c023
This diff is collapsed.
Click to expand it.
src/Data/PWhile/CostExpression.hs
View file @
4a37c023
...
...
@@ -34,6 +34,7 @@ mulN :: Norm -> Norm -> Norm
mulN
(
Norm
_
1
)
n
@
Norm
{}
=
n
mulN
n
@
Norm
{}
(
Norm
_
1
)
=
n
mulN
(
Norm
g1
e1
)
(
Norm
g2
e2
)
=
norm
(
g1
.&&
g2
)
(
e1
*
e2
)
-- mulN (Norm g1 e1) (Norm g2 e2) = norm (g1 .&& g2) (e1 * e2)
prodN
::
[
Norm
]
->
Norm
prodN
=
foldl
mulN
oneN
...
...
src/PWhile/InferEt.hs
View file @
4a37c023
...
...
@@ -12,7 +12,7 @@ module PWhile.InferEt
,
showResult
)
where
import
Data.List
(
nub
)
import
Control.Applicative
import
Control.Monad.Except
import
qualified
Control.Monad.State
as
St
...
...
@@ -167,7 +167,7 @@ varGNorms = filter (not . C.isConstGN) . C.gNorms
type
NormTemplate
=
P
.
Polynomial
C
.
Norm
Int
templateToNorms
::
NormTemplate
->
[
C
.
Norm
]
templateToNorms
p
=
templateToNorms
p
=
nub
$
filter
(
not
.
zeroN
)
[
C
.
prodN
[
C
.
expN
n
k
|
(
n
,
k
)
<-
P
.
toPowers
m
]
|
(
_
,
m
)
<-
P
.
toMonos
p
]
where
zeroN
(
C
.
Norm
_
e
)
=
e
==
0
...
...
@@ -317,7 +317,8 @@ extractRanking body i c g f = fmap templateToNorms $ do
<|>
template
"shift-avg"
(
refine
shiftAvg
lin
)
<|>
template
"conditions"
(
refine
conds
lin
)
<|>
template
"shift-max"
(
refine
shiftMax
lin
)
<|>
template
"mixed"
(
pure
(
grdNorm
*
grdNorm
+
lin
))
<|>
template
"mixed-lin"
(
pure
(
grdNorm
*
lin
+
lin
))
<|>
template
"mixed-square"
(
pure
(
grdNorm
*
grdNorm
+
lin
))
<|>
template
"square"
(
pure
(
lin
*
lin
+
lin
))
where
refine
m
r
=
do
...
...
@@ -411,6 +412,7 @@ et Ect (Seq c1 c2) f
et
t
(
Seq
c1
c2
)
f
=
etM
t
c1
=<<
etM
t
c2
f
et
t
d
@
(
While
_
i
b
c
)
f
=
logBlk
"While.step"
$
do
logData
"Problem"
d
logData
"f"
f
g
<-
case
t
of
{
Evt
->
return
C
.
zero
;
Ect
->
logBlk
"Expected Cost Body"
$
et
Ect
c
C
.
zero
}
ns
<-
logResult
"Norms"
$
extractRanking
c
i
b
g
f
hs
<-
traverse
(
et
Evt
c
.
C
.
fromNorm
)
ns
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment