def apply_condition(self, condition: Condition) -> None: """ Apply the condition to this transition :param condition: Condition should be already formatted! i.e. format should be like A = B + C :return: None """ if condition.get_state() == ConditionState.IS_NOT_ZERO: logger.warn( "Can not apply NOT_ZERO condition: {}".format(condition)) return condition_left = condition.get_left_side() condition_right = condition.get_right_side() # XXX: Expect formatted condition assert len(condition_left) == 1 var = condition_left.get_first() self.__left.replace_var_by_side(var, condition_right) self.__right.replace_var_by_side(var, condition_right)
def _use_and_append_zero_cond(self, condition: Condition) -> None: self.__apply_condition(condition) self.dump_system("System after apply condition {}".format(condition), with_main_conds=False) for nzcondition in self._conds_non_zero: if nzcondition.update_with(condition): self.dump_system( "Conditions after apply condition {}".format(condition), with_trans=False) if not nzcondition.is_correct(): func = inspect.currentframe().f_back.f_code raise ConditionException( "[{}:{}] Contradiction detected '{}'".format( func.co_name, func.co_firstlineno, nzcondition)) new_zero_conds = [] useless_econds = [] for econdition in self._conds_equals: if econdition.update_with(condition): self.dump_system( "[_use_and_append_zero_cond] Conditions after apply condition {}" .format(condition), with_trans=False) if not econdition.is_correct(): func = inspect.currentframe().f_back.f_code raise ConditionException( "[{}:{}] Contradiction detected '{}'".format( func.co_name, func.co_firstlineno, econdition)) if econdition.get_state() == ConditionState.IS_ZERO: # condition was converted new_zero_conds.append(econdition) if econdition.is_useless(): useless_econds.append(econdition) logger.debug("useless: Condition {} true ".format(econdition)) else: logger.debug("useless: Condition {} false ".format(econdition)) if condition.get_state() == ConditionState.IS_EQUAL: self._conds_equals.append(condition) else: self._conds_zero.append(condition) self.dump_system("Added condition {}".format(condition), with_trans=False) # remove useless condition if len(useless_econds): for ucondition in useless_econds: self._conds_equals.remove(ucondition) logger.info( "_use_and_append_zero_cond: remove useless condition from _conds_equals '{}'" .format(ucondition)) self.dump_system("Clear _conds_equals", with_trans=False) # remove and apply new zero conditions if len(new_zero_conds) > 0: for zcondition in new_zero_conds: self._conds_equals.remove(zcondition) logger.info( "_use_and_append_zero_cond: remove new zero condition from _conds_equals '{}'" .format(zcondition)) self.dump_system("Clear _conds_equals 2", with_trans=False) for zcondition in new_zero_conds: self._use_and_append_zero_cond(zcondition)