Commit c30fa82c authored by Michele's avatar Michele

removed input enabledness assumption of modelin RandomTester

parent d2eb3621
......@@ -37,6 +37,7 @@ from tictacoracle import TicTacToeOracle
from tictacpurpose import InputPurpose, OutputPurpose
from learning.learning import LearningAlgorithm
from testing.randomtesting import RandomTester
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
......@@ -54,7 +55,7 @@ inputExpert = InputPurpose()
T1 = TicTacToeTeacher(HOST, PORT)
O1 = TicTacToeOracle()
tester = None
tester = RandomTester(T1, 100, 10)
currentdir = os.path.dirname(os.path.abspath(
inspect.getfile(inspect.currentframe())))
......
......@@ -57,30 +57,6 @@ class TicTacToeTeacher(AbstractTeacher):
logger = logging.getLogger(__name__)
# Reply to a membership/output query
# trace is a list of inputs and or outputs
@d.deprecated
def process(self, trace):
pass
# reset SUL
# reset = self.reset()
# if not reset:
# logger.error("Cannot reset.")
# return False
#
# output = None
# if len(trace) == 0:
# # Get output for the empty trace
# ready = select.select([self._socket], [], [], 1) # 1 second timeout, for quiescence
# output = 'delta'
# if ready[0]:
# output = self._socket.recv(1024).decode("utf-8")
# for action in trace:
# # TODO finish here, maybe not needed
# print(ddd)
# return None
# return output
# Provide a sequence of inputs (possibly one or even zero) end get an output
# Tic Tac Toe is a mealy machine like game, there is alternation of input and
# output. This must be defined in inputExpert
......@@ -89,8 +65,6 @@ class TicTacToeTeacher(AbstractTeacher):
self._socket.sendall(bytes(str(actions[i]), 'UTF-8'))
output = self.output()
print(actions)
print(output)
return output
# Provide output from current state
......
......@@ -366,7 +366,7 @@ if __name__ == "__main__":
HOST = 'localhost'
PORT = 29000 # Arbitrary non-privileged port
logging.basicConfig(level=logging.DEBUG)
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
......
......@@ -301,13 +301,12 @@ class LearningAlgorithm:
consistentCheck = self._table.isNotGloballyConsistent()
while closingRows or consistentCheck:
while closingRows:
self._logger.info("Closing table")
self._logger.info("Table is not closed")
self._logger.debug(closingRows)
self._table.promote(closingRows)
# After promoting one should check if some one letter
# extensions should also be added
if self._table.addOneLetterExtensions(closingRows):
self._logger.info("something changed")
self._table.addOneLetterExtensions(closingRows)
if self._logger.isEnabledFor(logging.DEBUG):
self._table.printTable(prefix="_c_")
self.updateTable()
......@@ -315,10 +314,9 @@ class LearningAlgorithm:
consistentCheck = self._table.isNotGloballyConsistent()
# Table is closed, check for consistency
if consistentCheck:
self._logger.info("Consistency check")
self._logger.info("Table is not consistent")
self._logger.debug(consistentCheck)
if self._table.addColumn(consistentCheck, force=True):
self._logger.info("something changed")
self._table.addColumn(consistentCheck, force=True)
if self._logger.isEnabledFor(logging.DEBUG):
self._table.printTable(prefix="_i_")
# TODO: is an update needed here? in theory, when I encounter
......@@ -452,14 +450,11 @@ class LearningAlgorithm:
newSuffixes = self._table.isNotQuiescenceReducible()
while (newSuffixes or not self._table.isStable()):
if newSuffixes:
self._logger.info("Quiescence reducible")
self._logger.info("Table is not quiescence reducible")
self._logger.debug(newSuffixes)
if self._logger.isEnabledFor(logging.DEBUG):
self._table.printTable(prefix="_Q_")
if self._table.addColumn(newSuffixes, force=True):
self._logger.info("somethig changed")
if self._logger.isEnabledFor(logging.DEBUG):
self._table.printTable(prefix="_Qafter_")
self._table.printTable(prefix="_Q_")
self.updateTable()
self.stabilizeTable()
newSuffixes = self._table.isNotQuiescenceReducible()
......
......@@ -23,10 +23,11 @@ from abc import ABCMeta, abstractmethod
class AbstractTeacher(metaclass=ABCMeta):
# Reply to a membership/output query
@abstractmethod
def process(self, trace):
pass
# Deprecated
# # Reply to a membership/output query
# @abstractmethod
# def process(self, trace):
# pass
# Provide a sequence of inputs (possibly one or even zero) end get an output
@abstractmethod
......
......@@ -50,15 +50,19 @@ class RandomTester(AbstractTester):
if reset != 0:
# do not Reset
typeAction = random.sample(set(['input', 'output']),1)[0]
# there might be no inputs, but we assume the model is
# non-blocking, thus there is always an output (or quiescence)
if len(model.inputs()) ==0:
typeAction = 'output'
if typeAction == 'input':
# provide an input
# do not assume input enabledness
input = random.sample(model.inputs(),1)[0]
ce = ce + (input,)
model.move(input) # should be deterministic
my_input = random.sample(model.inputs(),1)[0]
ce = ce + (my_input,)
model.move(my_input) # should be deterministic
# add input to consecutiveInputs
consecutiveInputs = consecutiveInputs + (input,)
consecutiveInputs = consecutiveInputs + (my_input,)
# and continue with next step
# providing input costs an action
i += 1
......
......@@ -79,14 +79,14 @@ class TestTableReader:
outputPurpose=outputExpert,
inputPurpose=inputExpert)
table._loadTable(path)
#table._loadTable(path)
path = os.path.join(parentdir, "learning")
table.printTable(path=path, prefix='TEST')
#path = os.path.join(parentdir, "learning")
#table.printTable(path=path, prefix='TEST')
moreSpecific = lambda x: lambda y: table._moreSpecificRow(y, x, False)
listOfRows = list(filter(moreSpecific(('a', 'x', 'y', 'a', 'delta') + ('a',)), table._rowsInS))
#moreSpecific = lambda x: lambda y: table._moreSpecificRow(y, x, False)
#listOfRows = list(filter(moreSpecific(('a', 'x', 'y', 'a', 'delta') + ('a',)), table._rowsInS))
print(listOfRows)
print(table.isNotGloballyClosed())
assert_equal(listOfRows == [], False)
#print(listOfRows)
#print(table.isNotGloballyClosed())
#assert_equal(listOfRows == [], False)
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