Commit b965fd52 authored by Michele's avatar Michele

added complete tester, still need to be run with more than 5 loops of learning

parent ac77db53
# Copyright (c) 2015 Michele Volpato
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
from testing.basetesting import AbstractTester
import logging
import itertools
# Complete tester.
class CompleteTicTacToeTester(AbstractTester):
def __init__(self, teacher, logger=None):
# The tester will run test using the teacher
self._teacher = teacher
# upper bound: 9! (possible plays, also invalid ones)
# according to wikipedia
self._all_games = set(itertools.permutations(['0','1','2','3','4','5','6','7','8']))
self._logger = logger or logging.getLogger(__name__)
# Search a counterexample to teacher ioco model
def findCounterexample(self, model):
self._teacher.reset()
model.reset()
ce = ()
i = 0
for i in self._all_games:
ce = ()
# Next game
self._teacher.reset()
model.reset()
# play this game, if we receive END, then go to next game.
for action in i:
ce = ce + (action,)
output = self._processInputs((action,))
model.move(action)
if output not in model.outputs():
self._logger.info("Found a counterexample: "
+ str(ce) + " output: "+str(output))
self._teacher.reset()
model.reset()
# return counterexample trace and output obtained by
# testing
return ce, output
elif 'END' in output:
continue
else:
model.move(output)
ce = ce + (output,)
return None, None
def _processInputs(self, consecutiveInputs):
if consecutiveInputs != ():
output = self._teacher.oneOutput(consecutiveInputs)
if output == None:
return None
return output
return self._teacher.output()
......@@ -71,7 +71,7 @@ print("Starting learning...")
#print(T1.oneOutput(('1')))
L = LearningAlgorithm(T1, O1, printPath=path, maxLoops=4,
L = LearningAlgorithm(T1, O1, printPath=path, maxLoops=10,
tablePreciseness=100000, logger=logger, tester=tester, outputPurpose=outputExpert,
inputPurpose=inputExpert)
minus, plus = L.run()
......
......@@ -69,7 +69,7 @@ class TicTacToeTeacher(AbstractTeacher):
# Provide output from current state
def output(self):
ready = select.select([self._socket], [], [], 1) # 1 second timeout, for quiescence
ready = select.select([self._socket], [], [], 0.3) # second timeout, for quiescence
output = 'delta'
if ready[0]:
output = self._socket.recv(1024).decode("utf-8")
......
......@@ -105,7 +105,7 @@ class InputOutputLTS(AbstractIOLTS):
keys = self._transitions.keys()
possibleOutputs = set()
for state,label in keys:
if state != givenState or label not in self._outputs:
if state != givenState or label in self._inputs:
continue
possibleOutputs.add(label)
if len(possibleOutputs) == 0:
......
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