Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plot histogram for variable counter #3

Open
lemmy opened this issue Oct 6, 2021 · 0 comments
Open

Plot histogram for variable counter #3

lemmy opened this issue Oct 6, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@lemmy
Copy link
Contributor

lemmy commented Oct 6, 2021

IOnline histogram for variable counter

diff --git a/MCEWD998.cfg b/MCEWD998.cfg
index d998f17..75f0f3d 100644
--- a/MCEWD998.cfg
+++ b/MCEWD998.cfg
@@ -1,6 +1,9 @@
 CONSTANT N = 3
+CONSTANT Init <- StatsInit
 SPECIFICATION Spec
+CONSTRAINT Stats
 CONSTRAINT StateConstraint
\ No newline at end of file
+CONSTRAINT Plot
\ No newline at end of file
diff --git a/MCEWD998.tla b/MCEWD998.tla
index 4ce9ddd..8540b60 100644
--- a/MCEWD998.tla
+++ b/MCEWD998.tla
@@ -1,5 +1,38 @@
 ------------------------------- MODULE MCEWD998 -------------------------------
-EXTENDS EWD998
+EXTENDS EWD998, CSV, TLC, FiniteSets, Sequences, IOUtils
+
+-----------------------------------------------------------------------------
+
+StatsInit ==
+    (* Just a single initial state. *)
+    /\ active \in [Node -> {TRUE}]
+    /\ pending = [i \in Node |-> 0]
+    (* Rule 0 *)
+    /\ color \in [Node -> {"black"}]
+    /\ counter = [i \in Node |-> 0]
+    /\ pending = [i \in Node |-> 0]
+    /\ token = [pos |-> 0, q |-> 0, color |-> "black"]
+
+
+CSVFile ==
+    "MCEWD998.csv"
+
+ASSUME
+    (* Write CSV header at startup *)
+    CSVRecords(CSVFile) = 0 => CSVWrite("n#counter", <<>>, CSVFile)
+
+Stats ==
+    \* Cfg: CONSTRAINT Stats
+    \A n \in Node: CSVWrite("%1$s#%2$s", <<n, counter[n]>>, CSVFile)
+
+Plot ==
+    \* Cfg: CONSTRAINT Plot
+    \* level 2 and not 1 because all initial states are generated at startup.
+    TLCGet("level") = 2 =>
+        IOExec(<<
+            "/usr/bin/env", "Rscript",
+            "MCEWD998.R", CSVFile>>).exitValue = 0
+-----------------------------------------------------------------------------
 
 (***************************************************************************)
 (* Bound the otherwise infinite state space that TLC has to check.         *)

MCEWD998.R

#!/usr/bin/env Rscript
args = commandArgs(trailingOnly=TRUE)

svg("MCEWD998.svg")

d <-
  read.csv(
    header = TRUE, sep = '#', 
       file = args[1])

hist(d$counter, 
     main='EWD840!counter', 
     xlab ='Number of Messages', 
     xlim = c(min(d$counter), max(d$counter)))

dev.off()
@lemmy lemmy added the enhancement New feature or request label Oct 6, 2021
@lemmy lemmy changed the title Plot histogram for variable counter with R Plot histogram for variable counter Dec 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

No branches or pull requests

1 participant