コード例 #1
0
    def do_fast_estimation(self, custom_cond, common_cond_nz):
        nz_sides = [cond.get_left_side() for cond in common_cond_nz]

        count_simple = 0
        for trans in self.__transitions:
            tr_left = trans.get_left_side()
            tr_right = trans.get_right_side()

            # print "Let see on %s" % str(trans)
            # print "List of non zero sides {\n\t%s\n}" % "\n\t".join(map(str, nz_sides))

            if tr_left in nz_sides and tr_right not in nz_sides:
                custom_cond.append_condition(
                    Condition.create_non_zero_condition(tr_right.copy()))
                nz_sides.append(tr_right)
                if tr_right.has_only_one_unknown():
                    trans.set_simple()
                    count_simple += 1
            elif tr_left not in nz_sides and tr_right in nz_sides:
                custom_cond.append_condition(
                    Condition.create_non_zero_condition(tr_left.copy()))
                nz_sides.append(tr_left)
                if tr_left.has_only_one_unknown():
                    trans.set_simple()
                    count_simple += 1

            if not tr_left.contains_unknown() and (
                    not tr_right.contains_unknown()):
                trans.set_simple()
                count_simple += 1

        return count_simple == len(self.__transitions)
コード例 #2
0
ファイル: transition.py プロジェクト: oguzey-cv/DiffAnalysis
    def do_fast_estimation(self, custom_cond, common_cond_nz):
        nz_sides = [cond.get_left_side() for cond in common_cond_nz]

        count_simple = 0
        for trans in self.__transitions:
            tr_left = trans.get_left_side()
            tr_right = trans.get_right_side()

            # print "Let see on %s" % str(trans)
            # print "List of non zero sides {\n\t%s\n}" % "\n\t".join(map(str, nz_sides))

            if tr_left in nz_sides and tr_right not in nz_sides:
                custom_cond.append_condition(
                    Condition.create_non_zero_condition(tr_right.copy()))
                nz_sides.append(tr_right)
                if tr_right.has_only_one_unknown():
                    trans.set_simple()
                    count_simple += 1
            elif tr_left not in nz_sides and tr_right in nz_sides:
                custom_cond.append_condition(
                    Condition.create_non_zero_condition(tr_left.copy()))
                nz_sides.append(tr_left)
                if tr_left.has_only_one_unknown():
                    trans.set_simple()
                    count_simple += 1

            if not tr_left.contains_unknown() and (
                    not tr_right.contains_unknown()):
                trans.set_simple()
                count_simple += 1

        return count_simple == len(self.__transitions)
コード例 #3
0
    def estimate(system, custom_cond, common_in, common_out, comcon_nz,
                 res_list, call_as_fork):
        count_triviality = 0
        count_with_unknowns = 0
        print "#" * 50 + "start estimation" + "#" * 50
        print "This call of function is %s FORK" % (""
                                                    if call_as_fork else "NOT")
        print "Start estimate function with "
        print "system \n%s" % str(system)
        print "and custom_conditions %s\n" % str(custom_cond)

        transitions = system.get_transitions()

        for x in xrange(len(transitions) - 1, -1, -1):
            if custom_cond.exist_contradiction(comcon_nz):
                print "ESTIMATE: CONDITIONS HAVE CONTADICTIONS"
                print "custom_conditions %s\n" % str(custom_cond)
                print "common_in ", str(common_in)
                print "common_out ", str(common_out)
                SystemTransition.__write_result(system, custom_cond, common_in,
                                                common_out, count_triviality,
                                                count_with_unknowns, res_list,
                                                call_as_fork, True)
                return None

            transition = transitions[x]
            print "\nAnalyse transition ", str(transition)
            left = transition.get_left_side()
            right = transition.get_right_side()
            assert len(left) > 0 and len(right) > 0

            # 2 sides does not have unknowns
            if not left.contains_unknown() and not right.contains_unknown():
                count_triviality += 1
                print "Transition is triviality"
                continue

            is_left_non_zero = custom_cond.is_side_non_zero(left)
            is_right_non_zero = custom_cond.is_side_non_zero(right)

            if is_left_non_zero and is_right_non_zero:
                print "Both sides of transition are NOT ZERO"
                # do nothing, just increase counter
                count_with_unknowns += 1
                continue
            elif is_left_non_zero and not is_right_non_zero:
                print "Left side '%s' is NON ZERO. Rigth is undefined" % str(
                    left)
                # fixed left side: not fork
                nz = Condition.create_non_zero_condition(right.copy())
                print "Create non zero condition " + str(nz)
                try:
                    custom_cond.append_condition(nz)
                except ConditionExeption:
                    print "#" * 30 + "UNEXPECTED CONDITION EXEPTION" + "#" * 30
                    SystemTransition.__write_result(system, custom_cond,
                                                    common_in, common_out,
                                                    count_triviality,
                                                    count_with_unknowns,
                                                    res_list, call_as_fork,
                                                    True)
                    return
                print "Updated custom condition is " + str(custom_cond)
                count_with_unknowns += 1
                continue
            elif not is_left_non_zero and is_right_non_zero:
                print "Right side '%s' is NON ZERO. Left undefined" % str(
                    right)
                # fixed right side: not fork
                nz = Condition.create_non_zero_condition(left.copy())
                print "Create non zero condition " + str(nz)
                try:
                    custom_cond.append_condition(nz)
                except ConditionExeption:
                    print "#" * 30 + "UNEXPECTED CONDITION EXEPTION" + "#" * 30
                    SystemTransition.__write_result(system, custom_cond,
                                                    common_in, common_out,
                                                    count_triviality,
                                                    count_with_unknowns,
                                                    res_list, call_as_fork,
                                                    True)
                    return
                print "Updated custom condition is " + str(custom_cond)
                count_with_unknowns += 1
                continue
            else:
                new_res_list = []
                res_list.append(new_res_list)
                res_list = new_res_list
                fork = False
                # both sides not zero
                # check that they does not contain unkwowns
                if not left.contains_unknown() or not right.contains_unknown():
                    print 'Left or right sides does not contains UNKNOWN'
                    # need divide in two cases: zero and not zero
                    # zero case
                else:
                    print "Left and right contains UNKNOWN and sides in undefined"
                    print "IT IS FOOORKKK!!!!!"
                    fork = True
                    res_list.append("fork")

                print "Creating new components for zero case"
                new_custom_c = custom_cond.copy()
                left_zc = Condition.create_zero_condition(left.copy())
                right_zc = Condition.create_zero_condition(right.copy())
                print "New zero conditions %s and %s" % (str(left_zc),
                                                         str(right_zc))
                new_system = system.copy()
                print "New system copy \n" + str(new_system)
                try:
                    new_custom_c.append_condition(left_zc)
                    new_custom_c.append_condition(right_zc)
                    new_system.simplify_with_custom_conditions(new_custom_c)
                    print "system after simplify \n" + str(new_system)
                    print "Updated custom conditions " + str(new_custom_c)
                    if new_custom_c.exist_contradiction(comcon_nz):
                        print "ESTIMATE: CONDITIONS HAVE CONTADICTIONS2"
                        print "custom_conditions %s\n" % str(custom_cond)
                        print "common_in ", str(common_in)
                        print "common_out ", str(common_out)
                        SystemTransition.__write_result(
                            new_system, custom_cond, common_in, common_out,
                            count_triviality, count_with_unknowns, res_list,
                            call_as_fork, True)
                        return
                    print "Goto recursion"

                except ConditionExeption:
                    print "#" * 30 + "Catche ConditionExeption. System FAIL." + "#" * 30
                    SystemTransition.__write_result(new_system, custom_cond,
                                                    common_in, common_out,
                                                    count_triviality,
                                                    count_with_unknowns,
                                                    res_list, call_as_fork,
                                                    True)
                else:
                    if not fork:
                        SystemTransition.estimate(new_system, new_custom_c,
                                                  common_in, common_out,
                                                  comcon_nz, res_list, False)
                    else:
                        # fork
                        SystemTransition.estimate(new_system, new_custom_c,
                                                  common_in, common_out,
                                                  comcon_nz, res_list, True)

                # none zero case
                left_nzc = Condition.create_non_zero_condition(left.copy())
                right_nzc = Condition.create_non_zero_condition(right.copy())
                print "New non zero conditions %s and %s" % (str(left_nzc),
                                                             str(right_nzc))
                try:
                    custom_cond.append_condition(left_nzc)
                    custom_cond.append_condition(right_nzc)
                    print "Updated custom conditions " + str(custom_cond)
                    count_with_unknowns += 1
                except ConditionExeption:
                    print "#" * 30 + "Catche ConditionExeption. System FAIL." + "#" * 30
                    SystemTransition.__write_result(system, custom_cond,
                                                    common_in, common_out,
                                                    count_triviality,
                                                    count_with_unknowns,
                                                    res_list, call_as_fork,
                                                    True)
                    return

                continue

        SystemTransition.__write_result(system, custom_cond, common_in,
                                        common_out, count_triviality,
                                        count_with_unknowns, res_list,
                                        call_as_fork, False)
コード例 #4
0
ファイル: transition.py プロジェクト: oguzey-cv/DiffAnalysis
    def estimate(system, custom_cond, common_in, common_out, comcon_nz, res_list, call_as_fork):
        count_triviality = 0
        count_with_unknowns = 0
        print "#"*50 + "start estimation" + "#"*50
        print "This call of function is %s FORK" % ("" if call_as_fork else "NOT")
        print "Start estimate function with "
        print "system \n%s" % str(system)
        print "and custom_conditions %s\n" % str(custom_cond)

        transitions = system.get_transitions()

        for x in xrange(len(transitions) - 1, -1, -1):
            if custom_cond.exist_contradiction(comcon_nz):
                print "ESTIMATE: CONDITIONS HAVE CONTADICTIONS"
                print "custom_conditions %s\n" % str(custom_cond)
                print "common_in ", str(common_in)
                print "common_out ", str(common_out)
                SystemTransition.__write_result(
                        system, custom_cond, common_in, common_out, count_triviality,
                        count_with_unknowns, res_list, call_as_fork, True)
                return None

            transition = transitions[x]
            print "\nAnalyse transition ", str(transition)
            left = transition.get_left_side()
            right = transition.get_right_side()
            assert len(left) > 0 and len(right) > 0

            # 2 sides does not have unknowns
            if not left.contains_unknown() and not right.contains_unknown():
                count_triviality += 1
                print "Transition is triviality"
                continue

            is_left_non_zero = custom_cond.is_side_non_zero(left)
            is_right_non_zero = custom_cond.is_side_non_zero(right)

            if is_left_non_zero and is_right_non_zero:
                print "Both sides of transition are NOT ZERO"
                # do nothing, just increase counter
                count_with_unknowns += 1
                continue
            elif is_left_non_zero and not is_right_non_zero:
                print "Left side '%s' is NON ZERO. Rigth is undefined" % str(left)
                # fixed left side: not fork
                nz = Condition.create_non_zero_condition(right.copy())
                print "Create non zero condition " + str(nz)
                try:
                    custom_cond.append_condition(nz)
                except ConditionExeption:
                    print "#"*30 + "UNEXPECTED CONDITION EXEPTION" + "#"*30
                    SystemTransition.__write_result(
                        system, custom_cond, common_in, common_out, count_triviality,
                        count_with_unknowns, res_list, call_as_fork, True)
                    return
                print "Updated custom condition is " + str(custom_cond)
                count_with_unknowns += 1
                continue
            elif not is_left_non_zero and is_right_non_zero:
                print "Right side '%s' is NON ZERO. Left undefined" % str(right)
                # fixed right side: not fork
                nz = Condition.create_non_zero_condition(left.copy())
                print "Create non zero condition " + str(nz)
                try:
                    custom_cond.append_condition(nz)
                except ConditionExeption:
                    print "#"*30 + "UNEXPECTED CONDITION EXEPTION" + "#"*30
                    SystemTransition.__write_result(
                        system, custom_cond, common_in, common_out, count_triviality,
                        count_with_unknowns, res_list, call_as_fork, True)
                    return
                print "Updated custom condition is " + str(custom_cond)
                count_with_unknowns += 1
                continue
            else:
                new_res_list = []
                res_list.append(new_res_list)
                res_list = new_res_list
                fork = False
                # both sides not zero
                # check that they does not contain unkwowns
                if not left.contains_unknown() or not right.contains_unknown():
                    print 'Left or right sides does not contains UNKNOWN'
                    # need divide in two cases: zero and not zero
                    # zero case
                else:
                    print "Left and right contains UNKNOWN and sides in undefined"
                    print "IT IS FOOORKKK!!!!!"
                    fork = True
                    res_list.append("fork")

                print "Creating new components for zero case"
                new_custom_c = custom_cond.copy()
                left_zc = Condition.create_zero_condition(left.copy())
                right_zc = Condition.create_zero_condition(right.copy())
                print "New zero conditions %s and %s" % (str(left_zc), str(right_zc))
                new_system = system.copy()
                print "New system copy \n" + str(new_system)
                try:
                    new_custom_c.append_condition(left_zc)
                    new_custom_c.append_condition(right_zc)
                    new_system.simplify_with_custom_conditions(new_custom_c)
                    print "system after simplify \n" + str(new_system)
                    print "Updated custom conditions " + str(new_custom_c)
                    if new_custom_c.exist_contradiction(comcon_nz):
                        print "ESTIMATE: CONDITIONS HAVE CONTADICTIONS2"
                        print "custom_conditions %s\n" % str(custom_cond)
                        print "common_in ", str(common_in)
                        print "common_out ", str(common_out)
                        SystemTransition.__write_result(
                                new_system, custom_cond, common_in, common_out, count_triviality,
                                count_with_unknowns, res_list, call_as_fork, True)
                        return
                    print "Goto recursion"

                except ConditionExeption:
                    print "#"*30 + "Catche ConditionExeption. System FAIL." + "#"*30
                    SystemTransition.__write_result(
                        new_system, custom_cond, common_in, common_out, count_triviality,
                        count_with_unknowns, res_list, call_as_fork, True)
                else:
                    if not fork:
                        SystemTransition.estimate(
                            new_system, new_custom_c, common_in, common_out,
                            comcon_nz, res_list, False)
                    else:
                        # fork
                        SystemTransition.estimate(
                            new_system, new_custom_c, common_in, common_out,
                            comcon_nz, res_list, True)

                # none zero case
                left_nzc = Condition.create_non_zero_condition(left.copy())
                right_nzc = Condition.create_non_zero_condition(right.copy())
                print "New non zero conditions %s and %s" % (str(left_nzc), str(right_nzc))
                try:
                    custom_cond.append_condition(left_nzc)
                    custom_cond.append_condition(right_nzc)
                    print "Updated custom conditions " + str(custom_cond)
                    count_with_unknowns += 1
                except ConditionExeption:
                    print "#"*30 + "Catche ConditionExeption. System FAIL." + "#"*30
                    SystemTransition.__write_result(
                        system, custom_cond, common_in, common_out, count_triviality,
                        count_with_unknowns, res_list, call_as_fork, True)
                    return

                continue

        SystemTransition.__write_result(system, custom_cond, common_in,
                                        common_out, count_triviality, count_with_unknowns,
                                        res_list, call_as_fork, False)