Ejemplo n.º 1
0
def test_full_problem():
    graph = make_toy_graph()

    banned_values = set([frozenset(['h'])])
    heuristic = make_heuristic(banned_values, greed=10)

    initial_bindings = {
        'x': set(['x']),
        'y': set(['y']),
    }

    initial_expr = E.prob([E.v('y')], [E.do(E.v('x'))])

    initial_proof_state = ProofState(
        length=0,  # length of proof
        heuristic_length=0,
        bindings=initial_bindings,
        root_expr=initial_expr,
    ).normalise()

    initial_proof_state = initial_proof_state.copy(
        heuristic_length=heuristic(initial_proof_state))

    def goal_check(proof_state):
        return proof_state.heuristic_length == 0

    result = proof_search(initial_proof_state,
                          graph,
                          goal_check,
                          heuristic,
                          max_proof_length=7)
    assert result['reached_goal']
Ejemplo n.º 2
0
def test_full_problem():
    graph = make_toy_graph()

    banned_values = set([frozenset(['h'])])
    heuristic = make_heuristic(banned_values, greed=10)

    initial_bindings = {
        'x' : set(['x']),
        'y' : set(['y']),
    }

    initial_expr = E.prob([E.v('y')], [E.do(E.v('x'))])

    initial_proof_state = ProofState(
        length = 0, # length of proof
        heuristic_length = 0,
        bindings = initial_bindings,
        root_expr = initial_expr,
    ).normalise()

    initial_proof_state = initial_proof_state.copy(heuristic_length=heuristic(initial_proof_state))

    def goal_check(proof_state):
        return proof_state.heuristic_length == 0

    result = proof_search(initial_proof_state, graph, goal_check, heuristic, max_proof_length=7)
    assert result['reached_goal']
Ejemplo n.º 3
0
def main():

    if len(sys.argv) != 2:
        sys.stderr.write('usage: greediness (positive float...)\n')
        sys.exit(1)

    greed = float(sys.argv[1])

    graph = make_toy_graph()

    banned_values = set([frozenset(['h'])])
    # dial the greed parameter up high.
    # this makes the search very optimistic.
    # in general this may not find the shortest proof
    heuristic = make_heuristic(banned_values, greed)

    initial_bindings = {
        'x': frozenset(['x']),
        'y': frozenset(['y']),
    }

    initial_expr = E.prob([E.v('y')], [E.do(E.v('x'))])

    initial_proof_state = ProofState(
        length=0,  # length of proof
        heuristic_length=0,
        bindings=initial_bindings,
        root_expr=initial_expr,
        parent=None,
        comment='initial state',
    ).normalise()

    # this is a little silly
    initial_proof_state = initial_proof_state.copy(
        heuristic_length=heuristic(initial_proof_state))

    def goal_check(proof_state):
        return proof_state.heuristic_length == 0

    result = proof_search(initial_proof_state,
                          graph,
                          goal_check,
                          heuristic,
                          max_proof_length=7)
    assert result['reached_goal']
    print 'success!'

    display_proof_as_listing(result['path'])

    out_file_name = 'proof_tree.dot'
    write_proof_tree(result['path'], result['closed'], out_file_name)
Ejemplo n.º 4
0
def main():

    if len(sys.argv) != 2:
        sys.stderr.write('usage: greediness (positive float...)\n')
        sys.exit(1)

    greed = float(sys.argv[1])

    graph = make_toy_graph()

    banned_values = set([frozenset(['h'])])
    # dial the greed parameter up high.
    # this makes the search very optimistic.
    # in general this may not find the shortest proof
    heuristic = make_heuristic(banned_values, greed)

    initial_bindings = {
        'x' : frozenset(['x']),
        'y' : frozenset(['y']),
    }

    initial_expr = E.prob([E.v('y')], [E.do(E.v('x'))])

    initial_proof_state = ProofState(
        length = 0, # length of proof
        heuristic_length = 0,
        bindings = initial_bindings,
        root_expr = initial_expr,
        parent = None,
        comment = 'initial state',
    ).normalise()

    # this is a little silly
    initial_proof_state = initial_proof_state.copy(heuristic_length=heuristic(initial_proof_state))
    
    def goal_check(proof_state):
        return proof_state.heuristic_length == 0

    result = proof_search(initial_proof_state, graph, goal_check, heuristic, max_proof_length=7)
    assert result['reached_goal']
    print 'success!'

    display_proof_as_listing(result['path'])

    out_file_name = 'proof_tree.dot'
    write_proof_tree(result['path'], result['closed'], out_file_name)