From 81ed4a75c20d0b84d585fb74b8e42256a93cb4a5 Mon Sep 17 00:00:00 2001
From: "Nazim@misirlou" <nazim@internet.gestell>
Date: Wed, 11 Dec 2024 15:29:14 +0100
Subject: [PATCH] nzm

---
 n-vivace-satreach-cyber/.gitignore           |  2 +
 n-vivace-satreach-cyber/c-ECApaths.py        | 35 +++++++++++--
 n-vivace-satreach-cyber/d-transitionGraph.py |  7 ++-
 n-vivace-satreach-cyber/e-sunthesis.py       | 53 ++++++++++++++++++++
 4 files changed, 91 insertions(+), 6 deletions(-)
 create mode 100644 n-vivace-satreach-cyber/e-sunthesis.py

diff --git a/n-vivace-satreach-cyber/.gitignore b/n-vivace-satreach-cyber/.gitignore
index a9404d7..ad3973e 100644
--- a/n-vivace-satreach-cyber/.gitignore
+++ b/n-vivace-satreach-cyber/.gitignore
@@ -1,5 +1,7 @@
+.~*
 *cnf
 *dat
+*csv
 __pycache__/
 __pycache__/*
 allSynth/synth*txt
diff --git a/n-vivace-satreach-cyber/c-ECApaths.py b/n-vivace-satreach-cyber/c-ECApaths.py
index 9cb6465..3b458fe 100644
--- a/n-vivace-satreach-cyber/c-ECApaths.py
+++ b/n-vivace-satreach-cyber/c-ECApaths.py
@@ -4,7 +4,7 @@ import re
 import yNaming as naming
 import random
 
-FILE_SYNTHESIS_WRITEMODE="w+" # overwrite
+FILE_SYNTHESIS_WRITEMODE="a" # append (overwrite)
 
 ECAminimals=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 
 		18, 19, 22, 23, 24, 25, 26, 27, 28, 29, 30, 32, 33, 34,
@@ -35,7 +35,16 @@ def runcmd(cmd):
         sys.exit("\nFATAL ERROR code:%d raised by script command:\n[%s"%(cmdresult,cmd))
 
 
+def extract(pattern,strToParse):
+    """ minisat output string parsing """
+    srch=re.search(pattern+"\s+:\s+(\d+)", strToParse)
+    if srch:
+        return srch.group(1)
+    else:
+        print("FATAL : could not extract%s from [%s]"%(pattern,strToParse))
+
 def analyseRes3(res3, hashx, hashy):
+    """ minisat output string parsing """
     if ("CPU time" not in res3):
         print("res3:[%s]"%res3)
         print("CPUtime not found")
@@ -55,8 +64,15 @@ def analyseRes3(res3, hashx, hashy):
         print("COULD NOT FIND TIME in string:[%s]"%partTime)
         sys.exit(-88)
     satrescode=1 if satres=="SAT" else 0
-    result="%s %d %s ; %s -> %s"\
-        %(satres[:3], satrescode, timeres.group(0), hashx, hashy)
+
+
+    srch1=extract("restarts", res3)
+    srch2=extract("conflicts", res3)
+    srch3=extract("decisions", res3)
+    srch4=extract("propagations", res3)
+    result="%3s %d %-8s ; %2s %3s %3s %4s ; %s -> %s ; "\
+        %(satres[:3], satrescode, timeres.group(0),\
+          srch1, srch2, srch3, srch4, hashx, hashy)
     # satres= SAT / UNS
     return result
 
@@ -89,6 +105,7 @@ def runECA():
     filename="allSynth/synth-ECA%d-n%d-T%d.txt"%(ECA, N, TSTEPS)
     f=open(filename, FILE_SYNTHESIS_WRITEMODE)    
     for i in range(NSAMPLE):
+        print("----%d----"%(i+1))
         output=runOne()
         f.write(output+"\n")
     f.close()
@@ -99,8 +116,16 @@ def runAllECA():
         runECA()
 
 
-#ECA=70
-#runECA()
+
+def  tstRE():
+    res3="restarts : 445"
+    srch=re.search("restarts\s+:\s+(\d+)", res3)
+    if srch:
+        print("goude:"+srch.group(1))
+    else:
+        print("ZZZ...\n[%s]"%res3.replace('\n',' '))
+
 
 runAllECA()
 
+#ECA=126 ; runECA()
diff --git a/n-vivace-satreach-cyber/d-transitionGraph.py b/n-vivace-satreach-cyber/d-transitionGraph.py
index a2f0ed1..f9d9070 100644
--- a/n-vivace-satreach-cyber/d-transitionGraph.py
+++ b/n-vivace-satreach-cyber/d-transitionGraph.py
@@ -26,4 +26,9 @@ def test():
     x=trans(x)
     print(x)
 
-test()
\ No newline at end of file
+#test()
+
+def strtst():
+    strn=r"hi\nha\nho\n!"
+    str2=strn.replace('\n',' ')
+    print(str2)
\ No newline at end of file
diff --git a/n-vivace-satreach-cyber/e-sunthesis.py b/n-vivace-satreach-cyber/e-sunthesis.py
new file mode 100644
index 0000000..b3dad29
--- /dev/null
+++ b/n-vivace-satreach-cyber/e-sunthesis.py
@@ -0,0 +1,53 @@
+# Building synthesis table
+#######
+ECAminimals=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 
+		18, 19, 22, 23, 24, 25, 26, 27, 28, 29, 30, 32, 33, 34,
+		35, 36, 37, 38, 40, 41, 42, 43, 44, 45, 46, 50, 51, 54,
+		56, 57, 58, 60, 62, 72, 73, 74, 76, 77, 78, 90, 94, 104,
+		105, 106, 108, 110, 122, 126, 128, 130, 132, 134, 136,
+		138, 140, 142, 146, 150, 152, 154, 156, 160, 162, 164,
+		168, 170, 172, 178, 184, 200, 204, 232]
+
+
+ECAtest=126
+N=13
+Tsteps=55
+
+IREACH=1 ; ITIME=2
+IRESTARTS, ICONFLICTS, IDECISIONS, IPROPAGATIONS= 4,5,6,7
+
+reached=0
+
+def processData(data):
+    NS=len(data) # number of samples
+    sumreach=0
+    sumtime=0.
+    sr,sc,sd,sp=0,0,0,0
+    for line in data:
+        linedat=line.split()
+        reach, time,  = int( linedat[IREACH] ), float( linedat[ITIME] )
+        r,c,d,p=\
+            int(linedat[IRESTARTS] ), int(linedat[ICONFLICTS] ), int(linedat[IDECISIONS] ), int(linedat[IPROPAGATIONS] )
+        sr+=r ; sc+=c ; sd+=d ; sp+=p
+        sumreach+= reach
+        sumtime+= time
+        
+    preach= float(sumreach) / float(NS)
+    detreach="(%d/%d)"%(sumreach,NS)
+    return 'reached: %.2f %10s time:%.3f R: %3d C: %d D: %d P: %d'\
+          %(preach, detreach, sumtime, sr, sc, sd, sp)
+
+def readfile(ECA):
+    filename= "allSynth/synth-ECA%d-n%d-T%d.txt"%(ECA,N,Tsteps)
+    f=open(filename)
+    dat=f.readlines()
+    #print(dat)
+    strdat=processData(dat)
+    print("%3d %d %d %s"%( ECA, N, Tsteps, strdat ))
+
+def processAll():
+    for eca in ECAminimals:
+        readfile(eca)
+
+
+processAll()
\ No newline at end of file
-- 
GitLab