def json_parse_and_read_plan(domain_file, problem_file):
    start_time = time.time()
    os.system((
        "./scripts/FD/fast-downward.py {} {} --search \"lazy_greedy([ff()], preferred=[ff()])\""
    ).format(domain_file, problem_file))
    with open('books.json') as book_parse:
        data = json.load(book_parse)

    next_state = problem.State(0, 0, "EAST")

    sas_file = open("sas_plan", "r")
    for line in sas_file:
        word = line.strip('(').split()

        if word[0] == "move":
            from_location = word[2]
            print from_location
            to_location = word[1][0:len(word[1]) - 5]
            print to_location
            if from_location == "tbot3_init_loc":
                init_state = problem.get_initial_state()
                if to_location[0:1] == 'b':
                    curr_loc = data["books"][to_location]["load_loc"][0]
                    curr_state = problem.State(curr_loc[0], curr_loc[1],
                                               "EAST")
                elif to_location[0:1] == 't':
                    curr_loc = data["bins"][to_location]["load_loc"][0]
                    curr_state = problem.State(curr_loc[0], curr_loc[1],
                                               "EAST")
                action_list = gbfs(init_state, curr_state)
                action_list.pop(0)
                if action_list:
                    next_state = curr_state
                    problem.execute_move_action(action_list)
                    print(action_list)
            else:
                init_state = next_state
                if to_location[0:1] == 'b':
                    curr_loc = data["books"][to_location]["load_loc"][0]
                    curr_state = problem.State(curr_loc[0], curr_loc[1],
                                               "EAST")
                elif to_location[0:1] == 't':
                    curr_loc = data["bins"][to_location]["load_loc"][0]
                    curr_state = problem.State(curr_loc[0], curr_loc[1],
                                               "EAST")
                action_list = gbfs(init_state, curr_state)
                action_list.pop(0)
                if action_list:
                    next_state = curr_state
                    problem.execute_move_action(action_list)
                    print(action_list)
        elif word[0] == "place":
            book_name = word[1]
            bin_name = word[6][0:len(word[6]) - 1]
            problem.execute_place_action(book_name, bin_name, next_state)
        elif word[0] == "pick":
            book_name = word[1]
            problem.execute_pick_action(book_name, next_state)
    end_time = time.time()
Beispiel #2
0
 def build_goal_states(self, locations):
     """
     Creates a State representations for given list of locations
     
     """
     states = []
     for location in locations:
         states.append(problem.State(location[0], location[1], "EAST"))
         states.append(problem.State(location[0], location[1], "WEST"))
         states.append(problem.State(location[0], location[1], "NORTH"))
         states.append(problem.State(location[0], location[1], "SOUTH"))
     return states
def main():
    s = problem.State()
    inputVar(s)
    inputRules(s)
    inputForbidden(s)
    s.inputConstraints()
    s.inputHeuristic()

    print("\nDictionary: " + str(s.dt))
    print("Variables: " + str(s.variables))
    print("Rules: " + str(s.rules))
    print("Rule Conditions: " + str(s.rule_conditions))
    print("Rule costs: " + str(s.rule_cost))
    print("Forbidden States: " + str(s.forbidden))
    print("Constraints: " + str(s.constraints))
    print("Heuristic function: " + str(s.heuristic))

    s.inputStartState()
    s.inputGoalState()

    print("\nStart: " + str(s.dt))
    print("Goal: " + str(s.goal))
    print()

    f = search.Search(s)
    print(f.aSearch())
Beispiel #4
0
def get_possible_states(curr_state, action):
    rospy.wait_for_service('get_successor')
    try:
        get_successor = rospy.ServiceProxy('get_successor', GetSuccessor)
        response = get_successor(curr_state.x, curr_state.y,
                                 curr_state.orientation, curr_state.battery)
        states = collections.OrderedDict()
        possible_state = []
        if action not in response.action:
            print "Action not applicable in this state"
            return False
        for i in range(len(response.action)):
            if response.action[i] == action:
                return problem.State(response.x[i], response.y[i],
                                     response.direction[i],
                                     response.battery[i])

    except rospy.ServiceException, e:
        print "Service call failed get_possible_states: %s" % e
Beispiel #5
0
def p_problem(p):
    '''problem : LPAREN DEFINE_KEY problem_structure_def_lst RPAREN'''
    prob, dom = None, None
    init, goal = tuple(), tuple()
    objects = dict()
    for d in p[3]:
        if 'PROBLEM_KEY' in d:
            prob = d[1]
        elif 'DOMAIN_KEY' in d:
            dom = d[1]
        elif 'OBJECTS_KEY' in d:
            objects = d[1]
        elif 'INIT_KEY' in d:
            init = d[1]
        elif 'GOAL_KEY' in d:
            goal = d[1]

    # add objects to 'objects' attributes of the State class
    problem.State.objects = objects

    p[0] = problem.Problem(prob, dom, problem.State(init), goal)
Beispiel #6
0
        possible_state = []
        if action not in response.action:
            print "Action not applicable in this state"
            return False
        for i in range(len(response.action)):
            if response.action[i] == action:
                return problem.State(response.x[i], response.y[i],
                                     response.direction[i],
                                     response.battery[i])

    except rospy.ServiceException, e:
        print "Service call failed get_possible_states: %s" % e


if __name__ == "__main__":
    state_to_check = problem.State(1.0, 1.5, 'EAST', 5)
    action_to_check = 'REFUEL'

    initial_state = get_current_state()
    print "INITIAL STATE: " + str(initial_state)

    is_goal = is_terminal_state(state_to_check)
    print "IS TERMINAL STATE = " + str(is_goal)

    all_actions = get_all_actions()
    print "ALL ACTIONS: " + str(all_actions)

    possible_actions = get_possible_actions(state_to_check)
    print "POSSIBLE ACTIONS: " + str(possible_actions)

    goal_state = get_terminal_state()
Beispiel #7
0
 print("move_list:", moves_list)
 if (flag == 1 and moves_list[0] == "MOVE"):
     init_state_var = moves_list[1]
     goal_state_var = moves_list[2]
     if "INIT" in init_state_var and "BOOK" in goal_state_var:
         init_state = problem.get_initial_state()
         # print("initial state of robot:",init_state)
         l = [
             int(s) for s in goal_state_var.split('_')
             if s.isdigit()
         ]
         book_name = "book_" + str(l[0])
         # print(book_name)
         book_state = obj_dict["books"][book_name]["load_loc"][
             0]
         goal_state = problem.State(book_state[0],
                                    book_state[1], "EAST")
         print(type(goal_state))
         actions = astar(init_state, goal_state)
         print("actions 1st:", actions)
         problem.execute_move_action(actions)
     elif "BOOK" in init_state_var and "TROLLY" in goal_state_var:
         m = [
             int(s) for s in init_state_var.split('_')
             if s.isdigit()
         ]
     book_name = "book_" + str(m[0])
     book_state = obj_dict["books"][book_name]["load_loc"][0]
     init_state = problem.State(book_state[0], book_state[1],
                                "EAST")
 # print("initial state of robot:",init_state)
 n = [int(s) for s in goal_state_var.split('_') if s.isdigit()]
Beispiel #8
0
 def build_goal_states(self, locations):
     states = []
     for location in locations:
         states.append(problem.State(location[0], location[1], "EAST"))
     return states