Esempio n. 1
0
def main(argv):
    domain_path = argv[1]
    problem_path = argv[2]
    if argv[0] == "-L":
        agent = Learner()
    else:
        agent = MyExecutor()
    print LocalSimulator().run(domain_path, problem_path, agent)
Esempio n. 2
0
def main():
    domain_path = "doms and probs/satellite_domain_multi.pddl"  #"doms and probs/rover_domain (2).pddl"# #  #  #sys.argv[2]
    problem_path = "doms and probs/satellite_problem_multi.pddl"  #"doms and probs/rover_problem (2).pddl" #  # # sys.argv[3]

    # Find the problem and the world in the problem name
    file = open(problem_path, 'r')
    policy_name = file.readline().replace("(define (problem ", "")
    while policy_name == "\n":
        policy_name = file.readline().replace("(define (problem ", "")
    policy_name = policy_name[0:policy_name.find(")")] + "_Q_Table"
    file.close()

    file = open(domain_path)
    is_deterministic = file.read().find("probabilistic") == -1
    file.close()

    file = open(problem_path)
    is_transparent = file.read().find("reveal") == -1
    file.close()

    # if (is_deterministic == False):
    # load\create the Qtable
    q = q_table.q_table()
    q.build_from_file(policy_name)
    # if sys.argv[1] == "-E":
    # execute mode
    #
    # if is_deterministic == False:
    #print LocalSimulator().run(domain_path, problem_path, Q_learner_executer.executer(q))
    # else:
    #print LocalSimulator().run(domain_path, problem_path, graph_executor.executer(q,Graph.Read("roverMqsdkJedCB9zj3HW+RaxCJQcsI6i4w3XNYU8vDEdkFo=.graphml", "graphml")))

    # elif sys.argv[1] == "-L":
    # atexit.register(q.save_to_file, policy_path=policy_name)
    # learn mode
    print LocalSimulator().run(domain_path, problem_path, learner.learner(q))
Esempio n. 3
0
# name : yuval saadati
# id: 205956634
import sys

from pddlsim.local_simulator import LocalSimulator
from my_agent import Executor
print LocalSimulator().run(str(sys.argv[2]), str(sys.argv[3]), Executor(str(sys.argv[1]), str(sys.argv[4])))
#domain_path = sys.argv[2]
#problem_path = sys.argv[3]
""" deterministic domain and problem """
# maze
domain_path = "maze_domain.pddl"
problem_path = "maze_problem.pddl"

# freecell
domain_path = "freecell_domain.pddl"
problem_path = "freecell_problem.pddl"

# satellite
domain_path = "satellite_domain.pddl"
problem_path = "satellite_problem.pddl"

# rover
""" domain_path = "rover_domain (2).pddl"
problem_path = "rover_problem (2).pddl" """
""" NOT deterministic domain and problem """
# maze
domain_path = "maze_domain_multi_effect_food.pddl"
problem_path = "t_5_5_5_food-prob0.pddl"
#problem_path = "t_5_5_5_food-prob1.pddl"
#problem_path = "t_10_10_10.pddl"

# satellite
#domain_path = "satellite_domain_multi.pddl"
#problem_path = "satellite_problem_multi.pddl"

print LocalSimulator().run(sys.argv[2], sys.argv[3], best_agent())
def run():
    print LocalSimulator().run(tools.getDomain(), tools.getProblem(),
                               MazeExecuter())
Esempio n. 6
0
perception = Perception(sim.perceive_state)
valid_actions_getter = MyValidActionsGetter(parser, perception)

root_state = perception.get_state()

states = get_all_states(root_state, valid_actions_getter, parser)
actions = [action for action in parser.actions]
goal_states = get_goal_states(parser.goals, states)

distances_from_goals = get_distances_from_goals(goal_states, states,
                                                valid_actions_getter, parser)
state_discovery_reward = defaultdict(float)
for state_index in distances_from_goals:
    state_discovery_reward[state_index] = 0
    state_distances = distances_from_goals[state_index]
    for goal_index in state_distances:
        state_discovery_reward[state_index] += 1. / state_distances[goal_index]

max_reward = len(goal_states) * max(state_discovery_reward.values())
state_recurrence_punish = min(state_discovery_reward.values())
bad_action_punish = max(state_discovery_reward.values())
lookahead = 4
known_threshold = len(states) * len(actions)

print(
    LocalSimulator(local).run(
        domain_path, problem_path,
        My_Executer(problem_path, states, actions, goal_states,
                    state_discovery_reward, max_reward,
                    state_recurrence_punish, bad_action_punish, lookahead,
                    known_threshold)))
Esempio n. 7
0
    else:
        policy_path = 'POLICYFILE'
    train_mode = 'L' in run_mode_flag

    clear_policy(policy_path)
    global_start_time = datetime.now()
    if train_mode:
        # Train mode

        iterations = 1
        moving_average_window = 1
        results_moving_average = list()
        rewards_moving_average = list()
        for current_simulation_id in range(iterations):
            iteration_start_time = datetime.now()
            simulator = LocalSimulator()
            executor = MyExecutor(policy_path=policy_path, train_mode=True)
            ret_message = simulator.run(domain_path, problem_path, executor)
            print(ret_message)

            completion_time = datetime.now()
            msg = ''
            msg += '[Iter: {}/{}]'.format(current_simulation_id + 1,
                                          iterations)
            msg += 'Global runtime: {}\t'.format(completion_time -
                                                 global_start_time)
            msg += 'iteration runtime: {}\t'.format(completion_time -
                                                    iteration_start_time)
            print(msg)
        print(
            "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
Esempio n. 8
0
        option = sys.argv[1]
        if option == '-s':
            plan_path = "simple_football_plan.xml"
            domain_path = "simple_football_domain.pddl"

        elif option == '-e':
            plan_path = "extended_football_plan.xml"
            domain_path = "extended_football_domain.pddl"
        else:
            sys.exit('Error: expected flag to be -s or -e, but flag = ' +
                     str(option))

        try:
            N = int(sys.argv[2])
        except ValueError:
            sys.exit('Error: except N to be a number, but N = ' + sys.argv[2])

        problem_path = sys.argv[3]
        if not os.path.exists(problem_path):
            sys.exit('problem_file path does not exist: ' + problem_path)

    else:
        sys.exit('Error: missing arguments expected 3 arguments, but got ',
                 str((len(sys.argv) - 1)))

    plan = PlanParser(plan_path).getPlan()

    BiuExecutor = BIUExecutor(option, N, plan)

    print LocalSimulator(local).run(domain_path, problem_path, BiuExecutor)
        while len(reversed_route) is not 0:
            item = reversed_route.pop()
            route.append(item)
        wanted_location = route[1]
        return "(move" + " " + str(my_location) + " " + str(
            wanted_location) + ")"

    def next_action(self):
        global count
        self.update()
        if self.services.goal_tracking.reached_all_goals():
            return None

        for goal in goals:
            if self.goal_reached(goal):
                count += 1
                continue
            if count >= len(goals):
                return None
            ball = goal.split(" ")[0]
            if self.near_ball(ball):
                return self.kick_ball(ball)
            else:
                return self.move_to_ball(ball)
        return None


domain_path = argv[1]
problem_path = argv[2]
print LocalSimulator().run(domain_path, problem_path, FootballExecuter())
Esempio n. 10
0
# from pddlsim.local_simulator import LocalSimulator
# from random_walker import RandomExecutor
# domain_path = "domain.pddl"
# problem_path = "problem.pddl"
# print LocalSimulator().run(domain_path, problem_path, RandomExecutor())

from pddlsim.local_simulator import LocalSimulator
from pddlsim.executors.plan_dispatch import PlanDispatcher
domain_path = "domain.pddl"
problem_path = "problem.pddl"
print LocalSimulator().run(domain_path, problem_path, PlanDispatcher())
Esempio n. 11
0
        self.steps = []
        self.plan = []

    def initialize(self, services):
        self.services = services

    def next_action(self):
        if self.services.goal_tracking.reached_all_goals():
            return None

        self.steps = self.services.valid_actions.get()
        if len(self.steps) == 0: return None
        if len(self.steps) == 1: return self.steps[0]

        if self.plan == []:
            problem_path = self.services.problem_generator.generate_problem(
                self.services.goal_tracking.uncompleted_goals[0],
                self.services.perception.get_state())
            self.plan = self.services.planner(self.services.pddl.domain_path,
                                              problem_path)
        if len(self.plan) > 0:
            return self.plan.pop(0)
        return None


from pddlsim.local_simulator import LocalSimulator

domain_path = sys.argv[1]
problem_path = sys.argv[2]
print LocalSimulator().run(domain_path, problem_path, SmartReplanner())
# name : yuval saadati
# id: 205956634
import sys

from pddlsim.executors.plan_dispatch import PlanDispatcher
from pddlsim.local_simulator import LocalSimulator
from my_agent import Executor
with open(str(sys.argv[2])) as fp:
    line = fp.readline()
    planner = False
    while line:
        if "probabilistic" in line:
            print(LocalSimulator().run(str(sys.argv[2]), str(sys.argv[3]),
                                       Executor(str(sys.argv[1]))))
            planner = True
            break
        line = fp.readline()
    if not planner:
        print(LocalSimulator().run(str(sys.argv[2]), str(sys.argv[3]),
                                   PlanDispatcher()))
Esempio n. 13
0
def learn():
    LocalSimulator().run(tools.getDomain(), tools.getProblem(), MazeLearner())
    BFS.init()
import sys

from pddlsim.local_simulator import LocalSimulator
from pddlsim.planner import local

from StochasticSmartReplanner import StochasticSmartReplanner

# domain_path = "domain.pddl"
# problem_path = "t_5_5_5_multiple.pddl"
# problem_path = "ahinoam_problem.pddl"
# problem_path = "failing_actions_example.pddl"
# domain_path = "freecell_domain.pddl"
# problem_path = "freecell_problem.pddl"
# domain_path = "rover_domain.pddl"
# problem_path = "rover_problem.pddl"
# domain_path = "satellite_domain.pddl"
# problem_path = "satellite_problem.pddl"
domain_path = sys.argv[1]
problem_path = sys.argv[2]
print(
    LocalSimulator(local).run(domain_path, problem_path,
                              StochasticSmartReplanner(problem_path)))
# name : yuval saadati
# id: 205956634
import sys

from pddlsim.local_simulator import LocalSimulator
from my_agent import Executor
print LocalSimulator().run("simple_football_domain_multi.pddl",
                           "simple_football_problem_multi.pddl", Executor())
#print LocalSimulator().run(str(sys.argv[1]), str(sys.argv[2]), Executor())
Esempio n. 16
0

class RandomExecutor(object):
    """ RandomExecutor - pick a random valid action each step
	"""
    def __init__(self):
        self.successor = None
        print "__init__"
        print self.successor

    def initialize(self, services):
        self.services = services

    def next_action(self):
        if self.services.goal_tracking.reached_all_goals():
            return None
        options = self.services.valid_actions.get()
        print options
        if len(options) == 0: return None
        if len(options) == 1: return options[0]
        return self.pick_from_many(options)

    def pick_from_many(self, options):
        chosen = random.choice(options)
        return chosen


domain_path = "domain.pddl"
problem_path = "problem.pddl"
print LocalSimulator().run(domain_path, problem_path, RandomExecutor())
        if len(at) == 0:
            return None
        person = at[0].split(" ")[0]
        location = at[0].split(" ")[3]
        query = "from " + location
        instruction = ""
        item = policy.get(person)
        if policy.get(person) is None:
            return None
        for entry in policy.get(person)[0]:
            if query.split(" ")[1] == entry.split(" ")[1]:
                instruction = entry
                break
        if instruction == "":
            return None
        current = instruction.split(" ")[1]
        next = instruction.split(" ")[4]
        if self.is_north_of(current, next):
            return "(move-north " + person + " " + current + " " + next + ")"
        if self.is_south_of(current, next):
            return "(move-south " + person + " " + current + " " + next + ")"
        if self.is_east_of(current, next):
            return "(move-east " + person + " " + current + " " + next + ")"
        if self.is_west_of(current, next):
            return "(move-west " + person + " " + current + " " + next + ")"


domain_path = argv[1]
problem_path = argv[2]
print LocalSimulator().run(domain_path, problem_path, MazeExecuter())
Esempio n. 18
0
# name : yuval saadati
# id: 205956634
import sys

from pddlsim.local_simulator import LocalSimulator
from my_agent import Executor

domain_path = "attack_domain.pddl"
problem1_path = "attack_problem1.pddl"
problem2_path = "attack_problem2.pddl"
print LocalSimulator().run(domain_path, problem2_path, Executor())
#print LocalSimulator().run(str(sys.argv[1]), str(sys.argv[2]), Executor())