def test_solve_2a():
    '''

    Run 'solve_2' on  
        initial_state : 'workbenches/wb_09_i.txt'
        goal_state : 'workbenches/wb_09_g1.txt'
    
 
    Computation takes about a tenth of a second on my aging PC
   
    '''
    initial_state = load_state('workbenches/wb_08_i.txt')    

    goal_state  = load_state('workbenches/wb_08_g1.txt')
    ap_2 = AssemblyProblem_2(initial_state, goal_state)
    display_state(initial_state, "INITIAL: ")
    display_state(goal_state, "Goal: ")
    
    t0 = time.time()
    
    La = solve_2(initial_state, goal_state)
    
    t1 = time.time()
    
    print ('Search solve_2 took {0} seconds'.format(t1-t0))
def test_solve_2():
    '''
    Test function  'my_solver.solve_2'
    '''

    initial_state = load_state('workbenches/wb_05_i.txt')
    goal_state_no = load_state('workbenches/wb_01_i.txt')

    goal_state_yes = load_state('workbenches/wb_05_g.txt')

    display_state(initial_state, 'Initial state')

    display_state(goal_state_no, 'Goal state "no"')

    La_no = solve_2(initial_state, goal_state_no)
    print('\n\n')

    display_state(goal_state_yes, 'Goal state "yes"')
    t0 = time.time()
    La_yes = solve_2(initial_state, goal_state_yes)
    t1 = time.time()
    print('Search solve_1 took {0} seconds'.format(t1 - t0))
    #    print(La_yes)

    test_passed = (  #1  
        La_no == 'no solution' and (  #2
            La_yes == [(((5, 5, 5), ), ((1, 1, 3, 1, 0), (0, 1, 0, 1, 1)), 1),
                       (((1, 1, 3, 1, 0), (0, 1, 0, 1, 1), (0, 5, 5, 5, 0)),
                        ((1, 2), ), -2)]
            or La_yes == [(((1, 1, 3, 1, 0), (0, 1, 0, 1, 1)), ((1, 2), ), -2),
                          (((5, 5, 5), ), ((0, 0, 1, 2, 0), (1, 1, 3, 1, 0),
                                           (0, 1, 0, 1, 1)), 1)])  #2
    )  #1

    return test_passed
def test_solve_3a():
    '''
    Test function  'my_solver.solve_3'
    '''

    print('\n First test example \n')
    initial_state = load_state('workbenches/wb_06_i.txt')        
    goal_state_no = load_state('workbenches/wb_01_i.txt')        
    
    display_state(initial_state,'Initial state')

    goal_state_yes = load_state('workbenches/wb_06_g1.txt')    

    display_state(goal_state_no,'\nUneachable Goal State')    
    display_state(goal_state_yes,'\nReachable Goal State')

    
    t0 = time.time()
    La = solve_3(initial_state, goal_state_no)
    ok_2 = La=='no solution'
    t1 = time.time()
    
    print ('Unreachable Search solve_3 took {0} seconds'.format(t1-t0))
    print('\n\n')
    
    t0 = time.time()
    La = solve_3(initial_state, goal_state_yes)    
    ok_1 = La!='no solution'
    t1 = time.time()
    print ('Reachable Search solve_3 took {0} seconds'.format(t1-t0))
    print('\n\n')
    
    test_passed = ok_1 and ok_2
    
    return test_passed
Пример #4
0
def test_solve_1():
    '''
    Test function  'my_solver.solve_1'
    '''

    initial_state = load_state('workbenches/wb_05_i.txt')
    goal_state_no = load_state('workbenches/wb_01_i.txt')

    goal_state_yes = load_state('workbenches/wb_05_g.txt')

    display_state(initial_state, 'Initial state')

    display_state(goal_state_no, '\nUnreachable goal state')

    La_no = solve_1(initial_state, goal_state_no)
    print('\n\n')

    display_state(goal_state_yes, '\nReachable goal state')
    La_yes = solve_1(initial_state, goal_state_yes)
    #    print(La_yes)

    test_passed = (  #1  
        La_no == 'no solution' and (  #2
            La_yes == [(((5, 5, 5), ), ((1, 1, 3, 1, 0), (0, 1, 0, 1, 1)), 1),
                       (((1, 1, 3, 1, 0), (0, 1, 0, 1, 1), (0, 5, 5, 5, 0)),
                        ((1, 2), ), -2)]
            or La_yes == [(((1, 1, 3, 1, 0), (0, 1, 0, 1, 1)), ((1, 2), ), -2),
                          (((5, 5, 5), ), ((0, 0, 1, 2, 0), (1, 1, 3, 1, 0),
                                           (0, 1, 0, 1, 1)), 1)])  #2
    )  #1

    return test_passed
Пример #5
0
def test_solve2():
    initial_state = load_state('workbenches/wb_05_i.txt')

    goal_state_yes = load_state('workbenches/wb_05_g.txt')

    La_yes = solve_2(initial_state, goal_state_yes)

    print(La_yes)
Пример #6
0
def test_solve_3a():
    '''
    Test function  'my_solver.solve_3'
    '''

    print('\n First test example \n')
    initial_state = load_state('workbenches/wb_06_i.txt')
    goal_state = load_state('workbenches/wb_01_i.txt')

    display_state(initial_state, 'Initial state')

    goal_state = load_state('workbenches/wb_06_g.txt')
    display_state(goal_state, '\nGoal state')
    La = solve_3(initial_state, goal_state)
Пример #7
0
def test_solve_4():
    '''
    Test function  'my_solver.solve_4'
    '''

    print('\n First test example \n')
    initial_state = load_state('workbenches/wb_06_i.txt')
    goal_state = load_state('workbenches/wb_06_g.txt')

    display_state(initial_state, 'Initial state')
    display_state(goal_state, '\nGoal state')

    La = solve_4(initial_state, goal_state)

    print('\n\n This problem is solvable \n')
def test_action_result_broad():   #USER ADDED
    '''
    Load some parts, choose first actions and see results. Visually inspect 
    
    '''
    initial_state = load_state('workbenches/wb_06_i.txt')        
    ap = AssemblyProblem_3(initial_state)
    actions = ap.actions(initial_state)
    display_state(initial_state, "INITIAL: ")
    print("Num Actions: ", len(actions))
    
    for i in range(0, len(actions)):
        if i >-10: #can limit how many to show, here
            if len(actions[i])==3:
                pa, pu, offset = actions[i]
                pa_ = TetrisPart(pa)
                pu_ = TetrisPart(pu)
                print("\n\nACTION #", i)
                print("Part Above:")
                pa_.display()
                print("Part Under:")
                pu_.display()
                print("Offset: ", offset)
                
            elif len(actions[i])==2:
                part, r = actions[i]
                p = TetrisPart(part)
                print("\n\nACTION #", i)
                print("Part: ")
                p.display()
                print("Rotation: ", r*90)
            new_state = ap.result(initial_state, actions[i])
            display_state(new_state, "Result:")
def test_solve_rand_2():
    '''
    Generate a problem
    
    '''
    initial_state = load_state('workbenches/wb_09_i.txt')
    ap_2 = AssemblyProblem_1(initial_state)

    goal_state = gen_prob(ap_2, num_op=2)
    t0 = time.time()
    La = solve_2(initial_state, goal_state)
    t1 = time.time()

    #    sum = 0
    #    for i in range(0,5):
    #        t0 = time.time()
    #        La = solve_2(initial_state, goal_state)
    #        t1 = time.time()
    #        sum = sum + (t1-t0)
    #        print(sum)
    #
    #
    #    print ('Search solve_2 took {0} seconds'.format(sum/5))

    print('Search solve_rand2 took {0} seconds'.format(t1 - t0))
    print(La)
def test_solve_4():
    '''
    Test function  'my_solver.solve_4'
    '''

    print('\n First test example \n')
    initial_state = load_state('workbenches/wb_06_i.txt')
    goal_state = load_state('workbenches/wb_06_g.txt')

    display_state(initial_state, 'Initial state')
    display_state(goal_state, '\nGoal state')
    t0 = time.time()
    La = solve_4(initial_state, goal_state)
    t1 = time.time()
    print('Search solve_1 took {0} seconds'.format(t1 - t0))
    print('\n\n This problem is solvable \n')
    print(La)
def test_solve_3b():
    '''
    Test function  'my_solver.solve_3'
    '''

    print('\n First test example \n')
    initial_state = load_state('workbenches/wb_06_i.txt')
    goal_state = load_state('workbenches/wb_06_g.txt')

    display_state(initial_state, 'Initial state')
    display_state(goal_state, '\nGoal state')
    t0 = time.time()
    La = solve_3(initial_state, goal_state)
    t1 = time.time()
    print('Search solve_1 took {0} seconds'.format(t1 - t0))
    print(La)

    return False  #test_passed
Пример #12
0
def test3():

    initial_state = load_state('workbenches/wb_09_i.txt')
    c = initial_state[0]
    print(initial_state)
    print(c)
    d = TetrisPart(c)
    d.rotate90()
    print(d.get_frozen())
    display_state((d.get_frozen(), c))
Пример #13
0
def test_solve_rand_2():
    '''
    Generate a problem
    
    '''
    initial_state = load_state('workbenches/wb_09_i.txt')
    ap_2 = AssemblyProblem_2(initial_state)

    goal_state = gen_prob(ap_2, num_op=2)

    La = solve_2(initial_state, goal_state)
def test_solve_3b():
    '''
    Test function  'my_solver.solve_3'
    '''

    initial_state = load_state('workbenches/wb_06_i.txt')        
    goal_state = load_state('workbenches/wb_06_g3.txt')        
    
    display_state(initial_state,'Initial state')
    display_state(goal_state,'\nGoal state')
    
    t0 = time.time()
    La = solve_3(initial_state,goal_state) 
    t1 = time.time()
    
    #print(La)
    print ('Solve_3 took {0} seconds'.format(t1-t0))
    print('\n\n')
    
    return t1-t0 #test_passed
Пример #15
0
def test_solve_1a():
    '''

    Run 'solve_1' on  
        initial_state : 'workbenches/wb_09_i.txt'
        goal_state : 'workbenches/wb_09_g1.txt'
    
    Computation takes about 20 minutes on my aging PC
    
    '''
    initial_state = load_state('workbenches/wb_09_i.txt')

    goal_state = load_state('workbenches/wb_09_g1.txt')

    t0 = time.time()

    La = solve_1(initial_state, goal_state)

    t1 = time.time()

    print('Search solve_1 took {0} seconds'.format(t1 - t0))
def test_solve_rand_2():
    '''
    Generate a problem
    
    '''
    initial_state = load_state('workbenches/wb_09_i.txt')        
    ap_2 = AssemblyProblem_2(initial_state)
    print("\n\nNumber of Actions: ", len(ap_2.actions(initial_state)))

    goal_state = gen_prob(ap_2, num_op=3)
    
    La = solve_2(initial_state, goal_state)
def test_solve_2a():
    '''

    Run 'solve_2' on  
        initial_state : 'workbenches/wb_09_i.txt'
        goal_state : 'workbenches/wb_09_g1.txt'
    
 
    Computation takes about a tenth of a second on my aging PC
   
    '''
    initial_state = load_state('workbenches/wb_09_i.txt')

    goal_state = load_state('workbenches/wb_09_g1.txt')

    sum = 0
    for i in range(0, 5):
        t0 = time.time()
        La = solve_2(initial_state, goal_state)
        t1 = time.time()
        sum = sum + (t1 - t0)
        print(sum)

    print('Search solve_2 took {0} seconds'.format(sum / 5))
def test_action_result_deep():   #USER ADDED
    '''
    Load some parts, and keep building randomly until only one part exists.
    '''
    
    initial_state = load_state('workbenches/wb_08_i.txt')        
    ap = AssemblyProblem_3(initial_state)
    
    state = initial_state
    display_state(state, "INITIAL: ")
    assert(state == initial_state)
    i = 1
    
    while len(make_state_canonical(state)) is not 1:
        
        actions = ap.actions(state)
        action = random.choice(actions)
        
        if len(action)==3:
            pa, pu, offset = action
            pa_ = TetrisPart(pa)
            pu_ = TetrisPart(pu)
            print("\n\nACTION #", i, ", DROP")
            print("Part Above:")
            pa_.display()
            print("Part Under:")
            pu_.display()
            print("Offset: ", offset)
        elif len(action)==2:
            p, r = action
            part = TetrisPart(p)
            print("\n\nACTION #",i, ", ROTATION")
            print("Part:")
            part.display()
            print("Rotate: ", r*90)
        
        new_state = ap.result(state, action)
        assert(new_state != state)
        display_state(new_state, "Result: ")
        state = new_state
        i +=1
        
    print("\n\nFully Built.")
    test_passed = len(state) == 1
    print("Test Action and Result Passed: ", test_passed)
Пример #19
0
def test_solve_rand_1():
    '''
    Generate a problem and attempt to solve it
    
    '''
    initial_state = load_state('workbenches/wb_09_i.txt')
    ap_1 = AssemblyProblem_1(initial_state)

    # num_op=3 is fine
    goal_state = gen_prob(ap_1, num_op=4)

    t0 = time.time()

    La = solve_1(initial_state, goal_state)

    t1 = time.time()

    print('Search solve_1 took {0} seconds'.format(t1 - t0))
def test_solve_rand_3(): #USER ADDED
    '''
    Generate a problem and attempt to solve it
    
    '''
    initial_state = load_state('workbenches/wb_06_i.txt')        
    ap_3 = AssemblyProblem_3(initial_state)
    print("\n\nNumber of Actions: ", len(ap_3.actions(initial_state)))
    
    # num_op=3 is fine
    goal_state = gen_prob(ap_3, num_op=3)
    
    t0 = time.time()

    La = solve_3(initial_state, goal_state)

    t1 = time.time()
    
    print ('Search solve_1 took {0} seconds'.format(t1-t0))
def test_solve_rand_2a(): #USER ADDED
    '''
    Generate a random goal using ap1 
    
    '''
    initial_state = load_state('workbenches/wb_08_i.txt')        
    ap_1 = AssemblyProblem_1(initial_state)
    goal_state = gen_prob(ap_1, num_op=6)
    
    ap_2 = AssemblyProblem_2(initial_state, goal=goal_state)
    print("\n\nNumber of Actions: ", len(ap_2.actions(initial_state)))
    
    
    t0 = time.time()

    La = solve_2(initial_state, goal_state)

    t1 = time.time()
    
    print ('Search solve_1 took {0} seconds'.format(t1-t0))
Пример #22
0
def test_solve_rand_2():
    '''
    Generate a problem
    
    '''
    initial_state = load_state('workbenches/wb_09_i.txt')
    ap_2 = AssemblyProblem_2(initial_state)

    ap_1 = AssemblyProblem_1(initial_state)

    goal_state = gen_prob(ap_1, num_op=4)

    t0 = time.time()

    La = solve_2(initial_state, goal_state)
    print(La)

    t1 = time.time()

    print('Search solve_1 took {0} seconds'.format(t1 - t0))
def test_solve_rand_4a(): #USER ADDED
    '''
    Generate a random goal using ap3
    
    '''
    initial_state = load_state('workbenches/wb_06_i.txt')        
    ap_3 = AssemblyProblem_3(initial_state)
    goal_state = gen_prob(ap_3, num_op=3)
    
    ap_4 = AssemblyProblem_4(initial_state, goal=goal_state)
    print("\n\nNumber of Actions: ", len(ap_4.actions(initial_state)))
    display_state(initial_state, message="Initial:")
    print(ap_4.actions(initial_state))
    
    
    t0 = time.time()

    La = solve_4(initial_state, goal_state)

    t1 = time.time()
    
    print ('Search solve_1 took {0} seconds'.format(t1-t0))