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