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
13d6ab12
Commit
13d6ab12
authored
May 15, 2020
by
AVANZINI Martin
Browse files
refine strategy; thanks Michi!
parent
a6744649
Changes
4
Hide whitespace changes
Inline
Side-by-side
examples/oopsla/WFGCQS-19/queueing-network.pwhile
View file @
13d6ab12
...
...
@@ -3,7 +3,7 @@ def qn ():
l1 = 0
l2 = 0
i = 0
while i <= n:
while
[l1 >= 0 and l2 >=0]
i <= n:
n = n - 1
if l1 > 0:
l1 = l1 - 1
...
...
pwhile.cabal
View file @
13d6ab12
...
...
@@ -14,8 +14,8 @@ extra-source-files:
Flag Debug
Description: Enable debug support
Manual:
Tru
e
Default:
Tru
e
Manual:
Fals
e
Default:
Fals
e
library
hs-source-dirs: src
...
...
src/PWhile/InferEt.hs
View file @
13d6ab12
...
...
@@ -194,10 +194,15 @@ normFromBExp :: BExp -> NormTemplate
normFromBExp
b
=
sum
[
normFromExp
(
e1
-
e2
+
1
)
|
e1
:>=:
e2
<-
S
.
toList
(
literals
b
)
]
normFromCExp
::
C
.
CExp
Rational
->
NormTemplate
normFromCExp
d
=
sum
[
normFromBExp
b
+
norm
n
|
C
.
GNorm
b
k
n
<-
varGNorms
d
,
k
>
0
,
not
(
C
.
isZeroN
n
)
]
-- normFromCExp :: C.CExp Rational -> NormTemplate
-- normFromCExp d = sum [ normFromBExp b + norm n
-- | C.GNorm b k n <- varGNorms d
-- , k > 0, not (C.isZeroN n) ]
-- guardNormsFromCExp :: C.CExp Rational -> NormTemplate
-- guardNormsFromCExp d = sum [ normFromBExp d
-- | C.GNorm b k n <- varGNorms d
-- , k > 0, not (C.isZeroN n) ]
substituteM
::
(
C
.
Norm
->
SolveM
NormTemplate
)
->
NormTemplate
->
SolveM
NormTemplate
substituteM
s
=
P
.
fromPolynomialM
s
(
pure
.
P
.
coefficient
)
...
...
@@ -315,11 +320,22 @@ expectation r@(E.Rand n) f =
extractRanking
::
C
->
BExp
->
BExp
->
CExp
->
CExp
->
SolveM
[
C
.
Norm
]
extractRanking
body
i
c
g
f
=
fmap
templateToNorms
$
do
let
gNorm
=
normFromCExp
g
fNorm
=
normFromCExp
f
grdNorm
=
normFromBExp
i
+
normFromBExp
c
df
<-
substituteM
delta
fNorm
let
lin
=
normFromExp
1
+
grdNorm
+
fNorm
+
gNorm
+
sum
[
normFromBExp
c
*
df
]
let
gGNs
=
varGNorms
g
fGNs
=
varGNorms
f
-- fNorm = fNorms + fGrds
-- gNorm = gNorms + gGrds
gGrds
=
sum
[
normFromBExp
b
|
C
.
GNorm
b
_
_
<-
gGNs
]
gNs
=
sum
[
norm
n
|
C
.
GNorm
_
_
n
<-
gGNs
]
gNorms
=
gNs
+
gGrds
fGrds
=
sum
[
normFromBExp
b
|
C
.
GNorm
b
_
_
<-
fGNs
]
fNs
=
sum
[
norm
n
|
C
.
GNorm
_
_
n
<-
fGNs
]
fNorms
=
fNs
+
fGrds
grdNorm
=
normFromBExp
i
+
normFromBExp
c
-- + gGrds
df
<-
substituteM
delta
fNs
let
lin
=
normFromExp
1
+
grdNorm
+
fNorms
+
gNorms
+
sum
[
normFromBExp
c
*
df
]
-- cAdd = normFromExp 1 + grdNorm + gGrds
template
"linear"
(
pure
lin
)
-- <|> template "shift-avg" (refine shiftAvg lin)
-- <|> template "conditions" (refine conds lin)
...
...
@@ -327,6 +343,7 @@ extractRanking body i c g f = fmap templateToNorms $ do
-- <|> template "mixed" (pure (grdNorm * grdNorm + lin))
<|>
template
"shift-avg"
(
refine
shiftAvg
lin
)
<|>
template
"conditions"
(
refine
conds
lin
)
<|>
template
"mixed-iteration"
(
pure
(
grdNorm
*
grdNorm
+
grdNorm
))
<|>
template
"shift-max"
(
refine
shiftMax
lin
)
<|>
template
"mixed-lin"
(
pure
(
grdNorm
*
lin
+
lin
))
-- <|> template "mixed-square" (pure (grdNorm * grdNorm + lin))
...
...
@@ -349,7 +366,8 @@ extractRanking body i c g f = fmap templateToNorms $ do
conds
=
substituteM
s
where
s
n
=
do
evn
<-
etM
Evt
body
(
C
.
nm
1
n
)
pure
$
norm
n
+
sum
[
normFromBExp
b
|
C
.
GNorm
b
_
_
<-
varGNorms
evn
]
pure
$
norm
n
+
sum
[
normFromBExp
b
|
C
.
GNorm
b
_
_
<-
varGNorms
evn
]
delta
n
@
(
C
.
Norm
_
e
)
=
do
ns
<-
S
.
toList
.
C
.
norms
<$>
etM
Evt
body
(
C
.
nm
1
n
)
...
...
src/PWhile/Util.hs
View file @
13d6ab12
...
...
@@ -13,8 +13,9 @@ import qualified Text.PrettyPrint.ANSI.Leijen as PP
renderPretty
::
PP
.
Pretty
e
=>
e
->
String
-- TODO
renderPretty
d
=
""
-- renderPretty d = PP.displayS (PP.renderSmart 1.0 120 (PP.pretty d)) ""
-- renderPretty d = ""
-- renderPretty d = PP.displayS (PP.renderCompact (PP.pretty d)) ""
renderPretty
d
=
PP
.
displayS
(
PP
.
renderSmart
1.0
12000
(
PP
.
pretty
d
))
""
hPutPrettyLn
::
PP
.
Pretty
e
=>
IO
.
Handle
->
e
->
IO
()
hPutPrettyLn
h
=
IO
.
hPutStrLn
h
.
renderPretty
...
...
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