def _evaluate_invariants(self, state): dbm_op_seq = DBMOperationSequence() # Get invariant operations inv_operations = [] for inst_name, loc in state.location_state.items(): state.activate_instance_scope(inst_name) for inv in loc.invariants: constr_operation = self._make_constraint_operation_from_ast( constr_ast=inv.ast, state=state) inv_operations.append(constr_operation) # Apply invariant operations dbm_op_seq.extend(inv_operations) for inv in inv_operations: # print(inv) inv.apply(state.dbm_state) # Close DBM if any invariants were applied if len(inv_operations) > 0: close_operation = dbm_op_gen.generate_close() dbm_op_seq.append(close_operation) close_operation.apply(state.dbm_state) return {"dbm_op_seq": dbm_op_seq}
def _evaluate_locations(self, state): all_pot_trans = self._get_all_potential_transitions(state=state) all_urgent_or_committed_trans = list( filter(lambda trans: trans.urgent or trans.committed, all_pot_trans)) dbm_op_seq = DBMOperationSequence() if len(all_urgent_or_committed_trans) == 0: df_operation = dbm_op_gen.generate_delay_future() df_operation.apply(state.dbm_state) dbm_op_seq.append(df_operation) inv_res = self._evaluate_invariants(state) dbm_op_seq.extend(inv_res["dbm_op_seq"]) return {"dbm_op_seq": dbm_op_seq}
def _evaluate_guards(self, transition: Transition): dbm_op_seq = DBMOperationSequence() state = transition.target_state # Get guard operations grd_operations = [] var_guard_res = True for inst_name, edge in transition.triggered_edges.items(): if edge is None: continue state.activate_instance_scope(inst_name) has_edge_scope = inst_name in transition.edge_scopes if has_edge_scope: state.add_local_scope(name="edge", scope=transition.edge_scopes[inst_name]) for guard in edge.clock_guards: # if isinstance(guard, ClockGuard): # TODO: Remove distinguishing clock and variables guards in separate lists, as it affects the order constr_operation = self._make_constraint_operation_from_ast( constr_ast=guard.ast, state=state) grd_operations.append(constr_operation) for guard in edge.variable_guards: ret = self.c_evaluator.eval_ast(ast=guard.ast["expr"], state=state) var_guard_res = var_guard_res and ret if has_edge_scope: state.remove_local_scope() # Apply guards dbm_op_seq.extend(grd_operations) for guard in grd_operations: guard.apply(state.dbm_state) # Close DBM if any guards were applied if len(grd_operations) > 0: close_operation = dbm_op_gen.generate_close() dbm_op_seq.append(close_operation) close_operation.apply(state.dbm_state) return {"dbm_op_seq": dbm_op_seq, "var_guard_res": var_guard_res}