Commit 1b76707a authored by Michele Volpato's avatar Michele Volpato

working on old example for deterministic tictactoe, problem with placeholder and output generation

parent 66757b6f
......@@ -52,7 +52,8 @@ class CompleteTicTacToeTester(AbstractTester):
model.move(action)
if output not in model.outputs():
self._logger.info("Found a counterexample: "
+ str(ce) + " output: "+str(output))
+ str(ce) + " output: "+str(output)+
" not in " + str(model.outputs()))
self._teacher.reset()
model.reset()
......
......@@ -45,7 +45,7 @@ import helpers.bisimulation as bi
import csv
logging.basicConfig(level=logging.INFO)
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
HOST = 'localhost'
......
......@@ -43,7 +43,7 @@ class TicTacToeOracle(AbstractOracle):
if len(outputs) > 0:
return True
else:
# Check trace, if it has more outputs or more imputs in a row,
# Check trace, if it has more outputs or more inputs in a row,
# then return True
if trace == ():
return False
......
......@@ -58,23 +58,23 @@ class TicTacToeOutputPurpose(Purpose):
if (trace != None and len(trace) > 0 and trace[-1] not in inputs):
return set(['delta'])
else:
if (outputs != None and len(outputs) > 0):
return outputs
else:
#if (outputs != None and len(outputs) > 0):
# return outputs
#else:
# In this SUL we have many outputs (>4000)
# for this reason we use a placeholder
# We also need a way to compare a set of outputs with the
# placeholder
return 'PLACEHOLDER'
return set(['PLACEHOLDER'])
def isIncluded(self, set1, set2):
if set2 == 'PLACEHOLDER':
if 'PLACEHOLDER' in set2:
return True
else:
if set1 == 'PLACEHOLDER':
if 'PLACEHOLDER' in set1:
return False
else:
return set1.issubset(set2)
def allOutputs(self):
return set(itertools.product('XO_', repeat=9))
return set(map(''.join, itertools.product('XO_', repeat=9)))
......@@ -42,7 +42,7 @@ class TicTacToeTeacher(AbstractTeacher):
self._socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self._socket.connect((host, port))
self._outputs = set(itertools.product('XO_', repeat=9))
self._outputs = set(map(''.join, itertools.product('XO_', repeat=9)))
# counter for inputs:
self._count = 0
......
......@@ -318,7 +318,7 @@ class LearningAlgorithm:
def getHypothesis(self, chaos=False):
# If table is not closed, ERROR
if self._table.isNotGloballyClosed():
self._logger.error("Tried to get hypotheses with table not closed")
self._logger.warning("Trying to create a model from a not closed table")
return None, None
# Get equivalence classes
rows = self._table.getEquivalenceClasses(chaos)
......@@ -330,7 +330,7 @@ class LearningAlgorithm:
# assign to each equivalence class a state number
# start with equivalence class of empty trace to 0
# TODO: is () always the representative of an equivalence class?
# NO
# NO, we might have more than one row representing (). TODO: FIX
rowForEmpty = ()
# search for the representative for ()
for row in rows:
......@@ -338,6 +338,8 @@ class LearningAlgorithm:
# private. Change to public, or add a public version
if self._table._moreSpecificRow(row, rowForEmpty, chaos):
rowForEmpty = row
self._logger.debug("Creating " + ("HPlus" if chaos else "HMinus")
+ ": Row representing (): " + str(row))
break
assignments = {rowForEmpty:0}
......@@ -351,7 +353,7 @@ class LearningAlgorithm:
for row in rows:
enabledOuptuts = self._table.getOutputs(row)
allLabels = self._getAllLabels(row, enabledOuptuts)
self._logger.debug("All labels: "+ str(allLabels))
for label in allLabels:
# create row and search it in the table
extension = row + (label,)
......@@ -408,6 +410,8 @@ class LearningAlgorithm:
if self._outputPurpose != None:
enabledOutputs = self._outputPurpose.getEnabled(row)
allLabels = enabledInputs.union(enabledOutputs)
self._logger.debug("enabledInputs: "+ str(enabledInputs))
self._logger.debug("enabledOutputs: "+ str(enabledOutputs))
return allLabels
# Generate DOT files for hypotheses. hyp = hMinus|hPlus|both
......
......@@ -753,7 +753,7 @@ class Table:
outputs1 = self._entries[th.flatten(row1,self._quiescence)][0]
outputs2 = self._entries[th.flatten(row2,self._quiescence)][0]
# If they enable the same inputs, check each entry.
# Check each entry.
for column in self._columns:
entry1 = th.flatten(row1 + column, self._quiescence)
entry2 = th.flatten(row2 + column, self._quiescence)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment