Skip to content

Commit 79b8ebf

Browse files
committed
Add Philipp's functions
1 parent a40ff71 commit 79b8ebf

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

src/OpenGames/Engine/Diagnostics.hs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,20 @@ module OpenGames.Engine.Diagnostics
1616
generateOutputStr,
1717
generateIsEq,
1818
showDiagnosticInfoL,
19+
nextState,
20+
nextContinuation,
21+
equilibriumMap,
22+
toEquilibrium,
23+
generateEquilibrium
1924
)
2025
where
2126

2227
import OpenGames.Engine.OpticClass
2328
import OpenGames.Engine.TLL
2429

30+
import qualified Control.Monad.Trans.State.Strict as ST hiding (state)
31+
import qualified Control.Monad.Trans as ST (lift)
32+
2533
--------------------------------------------------------
2634
-- Diagnosticinformation and processesing of information
2735
-- for standard game-theoretic analysis
@@ -113,6 +121,24 @@ data Concat = Concat
113121
instance Apply Concat String (String -> String) where
114122
apply _ x = \y -> x ++ "\n NEWGAME: \n" ++ y
115123

124+
-- for apply output of equilibrium function
125+
data Equilibrium = Equilibrium
126+
127+
instance Apply Equilibrium [DiagnosticInfoBayesian x y] Bool where
128+
apply _ x = equilibriumMap x
129+
130+
data And = And
131+
132+
instance Apply And Bool (Bool -> Bool) where
133+
apply _ x = \y -> y && x
134+
135+
-- map diagnostics to equilibrium
136+
toEquilibrium :: DiagnosticInfoBayesian x y -> Bool
137+
toEquilibrium = equilibrium
138+
139+
equilibriumMap :: [DiagnosticInfoBayesian x y] -> Bool
140+
equilibriumMap = and . fmap toEquilibrium
141+
116142
---------------------
117143
-- main functionality
118144

@@ -148,3 +174,31 @@ generateIsEq ::
148174
generateIsEq hlist =
149175
putStrLn $
150176
"----Analytics begin----" ++ (foldrL Concat "" $ mapL @_ @_ @(ConstMap String xs) PrintIsEq hlist) ++ "----Analytics end----\n"
177+
178+
-- give equilibrium value for further use
179+
generateEquilibrium :: forall xs.
180+
( MapL Equilibrium xs (ConstMap Bool xs)
181+
, FoldrL And Bool (ConstMap Bool xs)
182+
) => List xs -> Bool
183+
generateEquilibrium hlist = foldrL And True $ mapL @_ @_ @(ConstMap Bool xs) Equilibrium hlist
184+
185+
186+
---------------------------------------
187+
-- Helper functionality for play output
188+
189+
-- Transform the optic into the next state given some input
190+
nextState ::
191+
StochasticStatefulOptic s t a b ->
192+
s ->
193+
Stochastic a
194+
nextState (StochasticStatefulOptic v _) x = do
195+
(z, a) <- v x
196+
pure a
197+
198+
nextContinuation
199+
:: StochasticStatefulOptic s t a ()
200+
-> s
201+
-> ST.StateT Vector Stochastic t
202+
nextContinuation (StochasticStatefulOptic v u) x = do
203+
(z,a) <- ST.lift (v x)
204+
u z ()

0 commit comments

Comments
 (0)