From 17fbe0380bf08a771b0044be23102485182c9466 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Thu, 26 Apr 2018 15:33:01 +0200 Subject: Support compact PTA json with multiple origin states per transition --- lib/automata.py | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) (limited to 'lib/automata.py') diff --git a/lib/automata.py b/lib/automata.py index e59c1ed..5779fe1 100755 --- a/lib/automata.py +++ b/lib/automata.py @@ -67,13 +67,6 @@ class State: self.power_function = power_function self.outgoing_transitions = {} - """@classmethod - def from_json(cls, serialized_state): - if 'power' in serialized_state: - cls.power = serialized_state['power']['static'] - if 'function' in serialized_state: - cls.power_function = """ - def add_outgoing_transition(self, new_transition): self.outgoing_transitions[new_transition.name] = new_transition @@ -148,16 +141,20 @@ class PTA: arg_to_param_map = None if 'arg_to_param_map' in transition: arg_to_param_map = transition['arg_to_param_map'] - pta.add_transition(transition['origin'], transition['destination'], - transition['name'], - duration = _json_get_static(transition, 'duration'), - duration_function = duration_function, - energy = _json_get_static(transition, 'energy'), - energy_function = energy_function, - timeout = _json_get_static(transition, 'timeout'), - timeout_function = timeout_function, - arg_to_param_map = arg_to_param_map - ) + origins = transition['origin'] + if type(origins) != list: + origins = [origins] + for origin in origins: + pta.add_transition(origin, transition['destination'], + transition['name'], + duration = _json_get_static(transition, 'duration'), + duration_function = duration_function, + energy = _json_get_static(transition, 'energy'), + energy_function = energy_function, + timeout = _json_get_static(transition, 'timeout'), + timeout_function = timeout_function, + arg_to_param_map = arg_to_param_map + ) return pta -- cgit v1.2.3