Exemplo n.º 1
0
def get_all_truth_values_in_astVector(smt_Object, maxDepth, maxAssert):
    """
        Get truth values for all the leaves and sub-trees in the astVector
    """
    print("####### Breaking up assertions into nodes..")
    ast = smt_Object.get_orig_ast()
    for assertion in ast:
        assertion_tree_depth = get_tree_depth(assertion,
                                              maxDepth,
                                              optimization=False)
        if assertion_tree_depth > 99999:
            print(
                colored(
                    "\t\tTree depth is higher than the max recursion limit. Abort",
                    "red",
                    attrs=["bold"]))
            continue
        # Now we get truth values of nodes in the assertion
        recursively_break_down_an_assertion_into_nodes(assertion, smt_Object,
                                                       maxDepth)

    print("####### Evaluating truth values for all nodes..")
    # Evaluate truth values of nodes in this assertion
    model = smt_Object.get_model()
    for node in smt_Object.get_all_nodes():
        if model.eval(node, model_completion=True) == True:
            smt_Object.append_true_node(node)
        if model.eval(node, model_completion=True) == False:
            smt_Object.append_false_node(node)
        """
Exemplo n.º 2
0
def recursively_break_down_an_assertion_into_nodes(assertion, smt_Object,
                                                   maxDepth):
    """
        Recusively evaluate a tree and append it in the respective
        true or false lists
    """
    # TODO:  Put a limit on how deep we want to go. Should be less than max python recursion limit
    #  Problem:
    #  Exception while computing tree depthargument 1: <class 'RecursionError'>: maximum recursion depth exceeded
    #  Fatal Python error: Cannot recover from stack overflow.
    if is_and(assertion) or is_or(assertion):
        tree_depth = get_tree_depth(assertion, maxDepth)
        if tree_depth < maxDepth:
            # Depth bound met
            smt_Object.append_to_all_nodes(assertion)
        children = assertion.children()
        for i, child in enumerate(children):
            if is_and(child) or is_or(child):
                recursively_break_down_an_assertion_into_nodes(
                    child, smt_Object, maxDepth)
            else:
                # depth is already zero here
                smt_Object.append_to_all_nodes(child)
    else:
        # depth is already zero here
        smt_Object.append_to_all_nodes(assertion)
Exemplo n.º 3
0
def get_max_depth(file_path):
    max_depth = 0
    ast = parse_smt2_file(file_path)
    for assertion in ast:
        assertion_depth = get_tree_depth(assertion, 64, optimization=False)
        if assertion_depth > max_depth:
            max_depth = assertion_depth
    return max_depth