Commit ba6bd882 authored by Michele Volpato's avatar Michele Volpato

added example fig1.2 thesis

parent f298e894
# 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.
import random
seed = output = random.sample(range(99999999), 1)[0]
print(seed)
random.seed(81077353) # 81077353
import os, inspect, sys
# Include project dir in path
currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
parentdir = os.path.dirname(currentdir)
sys.path.append(parentdir)
from learning.learning import LearningAlgorithm
from teachers.ltsteachers import InputOutputTeacher
from systems.implementations import InputOutputLTS
from teachers.ltsoracles import InputOutputPowerOracle
import logging
import helpers.bisimulation as bi
from testing.randomtesting import RandomTester
from systems.iopurpose import InputPurpose, OutputPurpose
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
inputs = set(['b'])
outputs = set(['t','c'])
quiescence = 'delta'
I1=InputOutputLTS(6, inputs, outputs, quiescence)
I1.addTransition(0,'b',1)
I1.addTransition(0,'b',2)
I1.addTransition(1,'t',3)
I1.addTransition(1,'c',3)
I1.addTransition(2,'b',4)
I1.addTransition(3,'c',0)
I1.addTransition(3,'t',0)
I1.addTransition(3,'b',3)
I1.addTransition(4,'c',5)
I1.addTransition(5,'t',0)
#I1.makeInputEnabled()
T1 = InputOutputTeacher(I1)
O1 = InputOutputPowerOracle(I1)
outputExpert = OutputPurpose(set(['t','c', quiescence]))
inputExpert = InputPurpose(set(['b']))
tester = RandomTester(T1, 10000, 50)
currentdir = os.path.dirname(os.path.abspath(
inspect.getfile(inspect.currentframe())))
path = os.path.join(currentdir, "dotFiles")
print("Starting learning...")
# change printPath=None to printPath=path for dot files
L2 = LearningAlgorithm(T1, O1, printPath=path, maxLoops=4,
tablePreciseness=10000, logger=logger, tester=tester, outputPurpose=outputExpert,
inputPurpose=inputExpert)
minus, plus = L2.run()
print("Models learned. Check language equivalence...")
print("hMinus bisimilar to target: " + str(bi.bisimilar(I1,minus)))
print("hPlus bisimilar to target: " + str(bi.bisimilar(I1,plus)))
......@@ -87,8 +87,11 @@ def moveRandom(moves):
if numMoves > 0:
# System is nondeterministic.
moveNum = random.sample(range(numMoves), 1)[0]
#moveNum = 1
#moveNum = random.sample(range(numMoves), 1)[0]
# Make it less nondeterministic :) Only 2 choices
moveNum = random.sample(range(1), 1)[0]
# Uncomment next line to make it deterministic
# moveNum = 1
numMoves = 0
for j in range(9):
if ((moves & (1<<j)) != 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