forked from azardilis/Chromar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple.hs
More file actions
29 lines (21 loc) · 778 Bytes
/
simple.hs
File metadata and controls
29 lines (21 loc) · 778 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS_GHC -fno-warn-name-shadowing #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}
import Chromar
-- Agent declarations
data Agent = A { x :: Int } deriving (Eq, Show)
$(return [])
-- Rules
r1, r2 :: [(Agent, Int)] -> Time -> [Rxn Agent]
r1 = [rule| A{x=x}, A{x=y} --> A{x='x+1'}, A{x='y-1'} @'1.0' ['y > 0'] |]
r2 = [rule| A{x=x} --> A{x='x'}, A{x='0'} @'1.0' |]
na, nx :: Er Agent Int
na = [er| select A{x=x}; aggregate (count . 'count + 1') '0' |]
nx = [er| select A{x=x}; aggregate (count . 'count + x') '0' |]
s :: Multiset Agent
s = ms [A{x=5}, A{x=5}]
model :: Model Agent
model = Model{ rules = [r1, r2], initState = s }
main :: IO ()
main = let nsteps = 100 in run model nsteps (erZip na nx)