- Added a more generic tuplesdo.py

This commit is contained in:
ccremers 2005-01-20 15:47:23 +00:00
parent 094267cd03
commit c354401d16
4 changed files with 56 additions and 25 deletions

View File

@ -22,6 +22,8 @@
# To verify combos of protocols starting with s and t
#
import tuples
# ***********************
# PARAMETERS
# ***********************
@ -47,7 +49,7 @@ ScytherArgs = ScytherDefaults + " " + ScytherMethods + " " + ScytherBounds
CommandPrefix = ScytherProgram + " " + ScytherArgs
# Some default settings for Agents, untrusted e with sk(e) and k(a,e) etc.
IncludeProtocols = 'spdl-defaults.inc'
IncludeProtocols = '../spdl/spdl-defaults.inc'
# Some protocols are causing troubles: this is a hard-coded filter to exclude
# the problem children. Unfair, yes. Practical, yes.
@ -304,7 +306,7 @@ def DescribeContext (filep, protocols, claim):
#
# Determines:
# ProtocolCount
# Protocol[0..count-1]
# ProtocolFileList[0..count-1]
#
# Furthermore, TempFileList is created.
@ -321,7 +323,7 @@ else:
# Read stdin into list and count, send to file
loop = 1
ProtocolCount = 0
Protocol = []
ProtocolFileList = []
outp = open(TempFileList, 'w')
while loop:
line = sys.stdin.readline()
@ -330,7 +332,7 @@ while loop:
cleanline = string.strip(line)
if cleanline != '' and cleanline[0] != '#' and cleanline not in SkipList:
# not a blank line, not forbidden
Protocol.append(cleanline)
ProtocolFileList.append(cleanline)
ProtocolCount = ProtocolCount + 1
outp.write(line)
else:
@ -348,8 +350,8 @@ print "Evaluating tuples of", TupleWidth, "for", ProtocolCount, "protocols, usin
i = 0
safetxt = " " * 20
while i < ProtocolCount:
ShowProgress (i, ProtocolCount,Protocol[i]+safetxt)
ScytherEval1 ( Protocol[i] )
ShowProgress (i, ProtocolCount,ProtocolFileList[i]+safetxt)
ScytherEval1 ( ProtocolFileList[i] )
i = i + 1
ClearProgress(ProtocolCount, safetxt)
print "Evaluated single results."

21
test/tuple.py Executable file
View File

@ -0,0 +1,21 @@
# Tuple module
#
# tuplesDo generates all unordered sets (in a list) of size n of the
# elements of the list l. The resulting lists (of length n) are passed
# to the function f.
def tuplesDo (f,l,n):
def tuplesDoRecurse (l,r):
if r and (len(r) == n):
f(r)
else:
if l and (n > 0):
# Larger size: we have options
# Option 1: include first
tuplesDoRecurse (l[1:], r + [l[0]])
# Option 2: exclude first
tuplesDoRecurse (l[1:], r)
tuplesDoRecurse (l,[])

View File

@ -20,6 +20,7 @@
#
import sys
import string
import tuplesdo
# Retrieve the tuple width
tuplesize = int(sys.argv[1])
@ -39,26 +40,12 @@ while loop:
# end of the input
loop = 0
def tupleUnit (x):
print x + "\t",
def tuplesPrint (l, n):
def f (resultlist):
print " ".join(resultlist)
def tuplesPrint (l, n, r):
if r and (len(r) == n):
count = 0
for x in r:
if count > 0:
print "\t",
print x,
count = count+1
print
else:
if l and (n > 0):
# Larger size: we have options
# Option 1: include first
tuplesPrint (l[1:], n, r + [l[0]])
# Option 2: exclude first
tuplesPrint (l[1:], n, r)
tuplesdo.tuplesDo (f, l, n)
# Generate tuples...
tuplesPrint (list, tuplesize, [])
tuplesPrint (list, tuplesize)
# Thanks for your attention

21
test/tuplesdo.py Executable file
View File

@ -0,0 +1,21 @@
# Tuple module
#
# tuplesDo generates all unordered sets (in a list) of size n of the
# elements of the list l. The resulting lists (of length n) are passed
# to the function f.
def tuplesDo (f,l,n):
def tuplesDoRecurse (l,r):
if r and (len(r) == n):
f(r)
else:
if l and (n > 0):
# Larger size: we have options
# Option 1: include first
tuplesDoRecurse (l[1:], r + [l[0]])
# Option 2: exclude first
tuplesDoRecurse (l[1:], r)
tuplesDoRecurse (l,[])