예제 #1
0
def test_dt_backtracking():
    """
    test a bit more of the decision tree.
    tries all possible children, at least for strategies,
    then goes with the "best" one.
    """
    if 0:
        plt.figure(1).clf()
        fig, ax = plt.subplots(num=1)

    af = test_basic_setup()
    af.log.setLevel(logging.INFO)

    af.cdt.post_check = False

    af.root = front.DTChooseSite(af)
    af.current = af.root

    if 0:

        def cb():
            print("tried...")
            af.plot_summary()
            fig.canvas.draw()
    else:

        def cb():
            pass

    af.current.best_child()
    af.current.best_child(cb=cb)
    af.current.best_child()
    # This is leaving things in a weird place
    # maybe fixed now?
    af.current.best_child(cb=cb)
예제 #2
0
def test_no_lookahead():
    af = test_basic_setup(front.AdvancingTriangles)
    af.log.setLevel(logging.INFO)
    af.cdt.post_check = False

    af.current = af.root = front.DTChooseSite(af)

    def cb():
        af.plot_summary(label_nodes=False)
        try:
            af.current.site.plot()
        except:  # AttributeError:
            pass

    while 1:
        if not af.current.children:
            break  # we're done?

        for child_i in range(len(af.current.children)):
            if af.current.try_child(child_i):
                # Accept the first child which returns true
                break
        else:
            assert False  # none of the children worked out
    return af
예제 #3
0
def test_singlestep_lookahead():
    af = test_basic_setup()

    af.log.setLevel(logging.INFO)
    af.cdt.post_check = False
    af.current = af.root = front.DTChooseSite(af)

    while 1:
        if not af.current.children:
            break  # we're done?

        if not af.current.best_child():  # cb=cb
            assert False

    return af
예제 #4
0
plt.plot(P[:, 0], P[:, 1], 'go')
plt.axis('equal')

##

# This often has scale issues at the end
# af.loop(1000)

##

# try invoking the search tree approach
import logging

af.log.setLevel(logging.INFO)

af.current = af.root = front.DTChooseSite(af)

##


# can this be rewritten so that af.current holds enough state to always
# know the next thing to do?
def advance_greedy(af):
    """
    based on the state of af.current, take the next step.
    returns True indicating more work to do, or False to 
    indicate completion or stuck
    """
    # active_child refers to the last child of this node which was
    # attempted.  it is None/-1 if no children have been attempted.
    # it is len(children) if all children have been attempted and