Commit 3d556462 authored by VIGNET Pierre's avatar VIGNET Pierre
Browse files

[lib] simulator: black

parent 728cb09e
......@@ -43,10 +43,13 @@ Guarded transition systems simulator implementation
"""
from cadbiom.models.guard_transitions.analyser.ana_visitors import TableVisitor
from cadbiom.models.guard_transitions.simulator.translators.gt_visitors import\
GenSimVisitor
from cadbiom.models.guard_transitions.simulator.simul_exceptions import\
SimulException, SimulPropViolation
from cadbiom.models.guard_transitions.simulator.translators.gt_visitors import (
GenSimVisitor,
)
from cadbiom.models.guard_transitions.simulator.simul_exceptions import (
SimulException,
SimulPropViolation,
)
from cadbiom.models.guard_transitions.simulator.input_stream import CFileInput, ActInput
from simul_aux import ChartExpVisitor
from cadbiom.models.biosignal.translators.gt_visitors import compile_cond
......@@ -57,6 +60,7 @@ class ChartSimulator(object):
wrap everything for simulation - this include the simulator model and simulator attribute to
manage simulation.
"""
def __init__(self):
# the chart model which is the source of simulator model
self.model = None
......@@ -146,7 +150,7 @@ class ChartSimulator(object):
"""
test if the simulated model has inputs
"""
return len(self.__inputs)>0
return len(self.__inputs) > 0
def get_symb_tab(self):
"""
......@@ -160,7 +164,6 @@ class ChartSimulator(object):
"""
return self.__step
def set_invariant_prop(self, prop):
"""
set invariant property to be checked.
......@@ -169,8 +172,7 @@ class ChartSimulator(object):
"""
reporter = SimReport()
try:
self.invariant_prop = compile_cond(prop, self.__model_symb_tab,
reporter)
self.invariant_prop = compile_cond(prop, self.__model_symb_tab, reporter)
except Exception as exc:
raise SimulException("Error in property " + exc.__str__())
......@@ -181,12 +183,10 @@ class ChartSimulator(object):
"""
reporter = SimReport()
try:
self.reachable_prop = compile_cond(prop, self.__model_symb_tab,
reporter)
self.reachable_prop = compile_cond(prop, self.__model_symb_tab, reporter)
except Exception as exc:
raise SimulException("Error in property " + exc.__str__())
def set_sce_file_input_stream(self, filename):
"""
Find the file containing description of a scenario
......@@ -229,7 +229,6 @@ class ChartSimulator(object):
"""
self.input_buffer = ActInput(inlist=act_input_list)
def set_cfile_input_stream(self, filename):
"""
Find the file containing input description using a language - set the input stream
......@@ -283,7 +282,7 @@ class ChartSimulator(object):
try:
self.__symb_tab[evn].set_activated(True)
except KeyError:
raise SimulException('Simul set_event: Unknown event')
raise SimulException("Simul set_event: Unknown event")
def __add_fireable_transitions(self):
"""
......@@ -292,12 +291,12 @@ class ChartSimulator(object):
self.add_fir_trans = False
expv = ChartExpVisitor(self.__symb_tab)
for trans in self.__armed_transitions:
if trans.event: # eval event
if trans.event: # eval event
ev_val = trans.event.expression.accept(expv)
else:
ev_val = True
if ev_val: # event present
if trans.condition: # eval condition
if ev_val: # event present
if trans.condition: # eval condition
cond_val = trans.condition.expression.accept(expv)
else:
cond_val = True
......@@ -337,7 +336,6 @@ class ChartSimulator(object):
for trans in self.__fireabled_transitions:
trans.activate()
def check_inv_conditions(self):
"""
evaluate invariant property in the current state
......@@ -348,8 +346,9 @@ class ChartSimulator(object):
expv = ChartExpVisitor(self.__symb_tab)
val = self.invariant_prop.accept(expv)
if not val:
raise SimulPropViolation("Invariant violation",
self.invariant_prop.__str__())
raise SimulPropViolation(
"Invariant violation", self.invariant_prop.__str__()
)
def check_reachable_property(self):
"""
......@@ -374,7 +373,7 @@ class ChartSimulator(object):
self.model.notify()
self.__step += 1
def simul_step_trace(self, trace_file = None):
def simul_step_trace(self, trace_file=None):
"""
same as simul_step but register a trace
"""
......@@ -397,7 +396,7 @@ class ChartSimulator(object):
trace_file.write("\n%")
for place in self.__places:
if place.activated and not place.is_input_place():
trace_file.write(" "+place.name)
trace_file.write(" " + place.name)
for evt in self.__events:
if evt.is_input_event() and evt.activated:
trace_file.write(evt.expression.__str__())
......@@ -418,7 +417,6 @@ class ChartSimulator(object):
for evt in self.__events:
evt.set_activated(False)
def simul_init_places(self, init_places):
"""
@param init_places: list of place names to be activated
......@@ -438,6 +436,7 @@ class ChartSimulator(object):
self.check_inv_conditions()
self.model.notify()
class SimReport(object):
"""
Simple reporter used for simulation
......
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