Пример #1
0
def solve_4(initial, goal):
    '''
    Solve a problem of type AssemblyProblem_4
    
    The implementation has to 
    - use an instance of the class AssemblyProblem_4
    - make a call to an appropriate functions of the 'generic_search" library
    
    @return
        - the string 'no solution' if the problem is not solvable
        - otherwise return the sequence of actions to go from state
        'initial' to state 'goal'
    
    '''
    print('\n++  busy searching in solve_4() ...  ++\n')
    assembly_problem = AssemblyProblem_4(initial, goal)                                         #initiating assembly problem 1 with initial workbench and goal
    
    search_function = generic_search.astar_graph_search(assembly_problem,assembly_problem.h)    #using A star search to solve the find a solution
    search_function2 = generic_search.breadth_first_graph_search(assembly_problem)
    search_function3 = generic_search.uniform_cost_search(assembly_problem)
    search_function4 = generic_search.iterative_deepening_search(assembly_problem)
    
    if search_function == None:                                     #if search does not output anything string 'no solution' will be returned from this function
        return 'no solution'
    else:
        return search_function.solution()#,search_function2.solution(), search_function3.solution(), search_function4.solution()                           #otherwise the solution will be returned 
Пример #2
0
def solve_3(initial, goal):
    '''
    Solve a problem of type AssemblyProblem_3
    
    The implementation has to 
    - use an instance of the class AssemblyProblem_3
    - make a call to an appropriate functions of the 'generic_search" library
    
    @return
        - the string 'no solution' if the problem is not solvable
        - otherwise return the sequence of actions to go from state
        'initial' to state 'goal'
    
    '''
    print('\n++  busy searching in solve_3() ...  ++\n')
    assembly_problem = AssemblyProblem_3(initial, goal)
    sol_ts = gs.iterative_deepening_search(assembly_problem)
    if (sol_ts == None):
        return "no solution"
    return sol_ts.solution()