def choose_goals(data, agents, goals_per_agent=5): """ Chooses goals based on preferences, by creating goals stochastically and rating them according to action costs """ data = "world" domain = "domain.pddl" for _ in range(goals_per_agent): random_goals(agents) all_plans = [] while len(goals) > 0: agent = agents[0] create(data, [agent]) print("Wait") time.sleep(2) calculating = [ subprocess.Popen([ "metricff//Metric-FF-v2.1//ff", '-o', os.path.join(data, domain), '-f', os.path.join(data, agent + ".pddl"), '-s', '3', '>', os.path.join(data, agent + ".soln") ]) ] too_long = 10 thinking_time = time.clock() while not finished_thinking(calculating): time.sleep(0.1) thinking_timelast = time.clock() if thinking_time + too_long < thinking_timelast: calculating[0].kill() break translation, quest = questTranslation.interpret(data) if quest == []: quest = ['Cluster'] all_plans.append((goals[0], quest)) goals.pop(0) for agent in agents: scores = [] preference = preferences[agent] for plan in all_plans: scores.append((plan[0], rate_plan(plan[1][0], preference))) best = sorted(scores)[-1] goals.append(best[0])
def main(): data = "world/bge" domain = "domain.pddl" agents = sorted(["peyj","generalkehck","jade","secundo","governor","issam"]) #agents = sorted(["generalkehck"]) write_domains(data, domain, agents, worldManagementbge.preferences) worldManagementbge.create(data,agents,genesis=True) too_long = 10000 run = True calculating = [] opened_files = [] while run: for agent in agents: opened_files.append(open(os.path.join(data,agent+".soln"),"w")) #calculating.append(subprocess.Popen([os.path.join("metricff","Metric-FF-v2.1","ff"), '-o', os.path.join(data,agent,"domain"+agent+".pddl"), '-f', os.path.join(data,agent,agent+".pddl"), '-s', '3'],stdout=opened_files[-1])) thinking_time = time.perf_counter() print('Thinking') while not finished_thinking(calculating): time.sleep(0.5) print("..", end=".") thinking_time = time.perf_counter() if thinking_time > too_long: break for opened_file in opened_files: opened_file.close() print("Done") translations, _, formalplans = questTranslation.interpret(data) print(formalplans) motivations = [questClassification.classify(formalplan) for formalplan in formalplans] for translation,motivation in zip(translations,motivations): print(translation,motivation) print("---------------------------------") #action = input() if True: run = False else: worldManagementbge.update(data, action, agents)
def main(): data = "world" domain = "domain.pddl" agents = ["Jafar", "Aladdin", "Jasmine", "Genie", "Dragon"] worldManagement.create(data, agents, genesis=True) too_long = 20 run = True while run: calculating = [ subprocess.Popen([ "metricff//Metric-FF-v2.1//ff", '-o', os.path.join(data, domain), '-f', os.path.join(data, agent + ".pddl"), '-s', '3', '>', os.path.join(data, agent + ".soln") ]) for agent in agents ] thinking_time = time.clock() while not finished_thinking(calculating): time.sleep(0.1) thinking_time = time.clock() if thinking_time > too_long: break translations, formalplans = questTranslation.interpret(data) motivations = [ questClassification.classify(formalplan) for formalplan in formalplans ] for translation, motivation in zip(translations, motivations): print(translation, motivation) action = input() if action == "exit": run = False else: worldManagement.update(data, action, agents)
def main(): data = "world" domain = "domain.pddl" agents = ["baker","blacksmith"] worldManagement.create(data,agents,genesis=True) pyperplan = os.path.join("pyperplan","pyperplan.py") too_long = 20 run = True while run: calculating = [subprocess.Popen(["C:\\Python34\python.exe", pyperplan, os.path.join(data,domain), os.path.join(data,agent+".pddl")]) for agent in agents] thinking_time = time.clock() while not finished_thinking(calculating): time.sleep(0.1) thinking_time = time.clock() if thinking_time > too_long: break translations, formalplans = questTranslation.interpret(data) motivations = [questClassification.classify(formalplan) for formalplan in formalplans] for translation,motivation in zip(translations,motivations): print(translation,motivation) action = input() if action == "exit": run = False else: worldManagement.update(data, action, agents)
def choose_goals(data, agents, quests_per_agent=3, attempts_per_agent=12, verbose=True): """ Chooses goals based on preferences, by creating goals stochastically and rating them according to action costs """ #data = "world/bge/" domain = "domain.pddl" for _ in range(attempts_per_agent): if attempts_per_agent < 2: goals[:] = [] random_goals(agents) if attempts_per_agent < 2: return good_goals = [] scores = [] for agent in agents: all_plans = [] while len(all_plans) < attempts_per_agent: #print(goals[0]) #agent = agents[0] create(data, [agent]) if verbose: print("Wait") #time.sleep(2) calculating = [questPlanning.plan_quest(agent)] too_long = 180 # 3 minutes thinking_time = time.perf_counter() thinking_timelast = thinking_time while not finished_thinking(calculating): time.sleep(0.5) thinking_timelast += 0.5 if thinking_time + too_long < thinking_timelast: calculating[0].kill() print("Took too long!") break translation, quest, NPCNames = questTranslation.interpret(data) if quest == []: quest = ['Cluster'] score = rate_plan(quest) if verbose: print(quest) print(score) all_plans.append((score, goals[0], quest)) goals.pop(0) # Maybe make it choose the longest quest in case of equal scores? if len(all_plans) == attempts_per_agent: all_plans = sorted(all_plans) good_goals.append(all_plans[0][1]) scores.append(all_plans[0][0]) if verbose: print(good_goals[-1], all_plans[0][0]) if verbose: print("Should be empty now:") print(goals) goals.extend(good_goals) if verbose: print("---------------------------------") print("Quests chosen by the agents :") print(goals) print(scores)
def choose_goals(data,agents, quests_per_agent = 1, attempts_per_agent = 4, verbose = True): """ Chooses goals based on preferences, by creating goals stochastically and rating them according to action costs """ data = "world" domain = "domain.pddl" for _ in range(attempts_per_agent): if attempts_per_agent < 2: goals[:] = [] random_goals(agents) if attempts_per_agent < 2: return good_goals = [] for agent in agents: all_plans = [] while len(all_plans) < attempts_per_agent: #print(goals[0]) #agent = agents[0] create(data, [agent]) if verbose: print("Wait") time.sleep(2) with open(os.path.join(data,agent+".soln"), "w") as openedfile: calculating = [subprocess.Popen([os.path.join("metricff","Metric-FF-v2.1","ff"), '-o', os.path.join(data,"domain"+agent+".pddl"), '-f', os.path.join(data,agent+".pddl"), '-s', '3'],stdout=openedfile)] too_long = 300 # 5 minutes thinking_time = time.clock() thinking_timelast = thinking_time while not finished_thinking(calculating): time.sleep(0.5) thinking_timelast += 0.5 if thinking_time + too_long < thinking_timelast: calculating[0].kill() print("Took too long!") break translation, quest = questTranslation.interpret(data) if quest == []: quest = ['Cluster'] score = rate_plan(quest) if verbose: print(quest) print(score) all_plans.append((score, goals[0], quest)) goals.pop(0) if len(all_plans) == attempts_per_agent: all_plans = sorted(all_plans) good_goals.append(all_plans[0][1]) if verbose: print(good_goals[-1],all_plans[0][0]) if verbose: print("Should be empty now:") print(goals) goals.extend(good_goals) if verbose: print(goals)
def main(): data = "world" domain = "domain.pddl" agents = sorted([ "baker", "king", "lumberjack", "blacksmith", "merchant", "guard", "daughter" ]) write_domains(data, domain, agents, worldManagement.preferences) worldManagement.create(data, agents, genesis=True) too_long = 10000 run = True calculating = [] opened_files = [] while run: for agent in agents: opened_files.append(open(os.path.join(data, agent + ".soln"), "w")) calculating.append( subprocess.Popen([ os.path.join("metricff", "Metric-FF-v2.1", "ff"), '-o', os.path.join(data, agent, "domain" + agent + ".pddl"), '-f', os.path.join(data, agent, agent + ".pddl"), '-s', '3' ], stdout=opened_files[-1])) thinking_time = time.perf_counter() print('Thinking') while not finished_thinking(calculating): time.sleep(0.5) print("..", end=".") thinking_time = time.perf_counter() if thinking_time > too_long: break for opened_file in opened_files: opened_file.close() print("Done") translations, _, formalplans = questTranslation.interpret(data) print(formalplans) motivations = [ questClassification.classify(formalplan) for formalplan in formalplans ] for translation, motivation in zip(translations, motivations): print(translation, motivation) action = input() if action == "exit": run = False else: worldManagement.update(data, action, agents)
def main(): data = "world" domain = "domain.pddl" #agents = sorted(["baker", "king", "lumberjack", "blacksmith", "merchant", "guard", "daughter"]) agents = sorted(["Jafar", "Aladdin", "Jasmine", "Genie", "Dragon"]) motivation_count = dict() motivations = [ "Knowledge", "Comfort", "Reputation", "Serenity", "Protection", "Conquest", "Wealth", "Ability", "Equipment" ] for motiv in motivations: motivation_count[motiv] = 0 motivation_count["Not found"] = 0 print(motivation_count) emptyOrComplete = 0 quest_log = open("quest_log.txt", "w") too_long = 600 # 10 minutes run = 1000 while run > 0: write_domains(data, domain, agents, worldManagementAladdin2.preferences) worldManagementAladdin2.create(data, agents, attempts_per_agent=4, genesis=True, verbose=False) calculating = [] opened_files = [] for agent in agents: calculating.append(questPlanning.plan_quest(agent)) #opened_files.append(open(os.path.join(data,agent+".soln"),"w")) #calculating.append(subprocess.Popen([os.path.join("metricff","Metric-FF-v2.1","ff"), '-o', os.path.join(data,"domain"+agent+".pddl"), '-f', os.path.join(data,agent+".pddl"), '-s', '3'],stdout=opened_files[-1])) thinking_time = time.clock() thinking_timelast = thinking_time print('Thinking') while not finished_thinking(calculating): time.sleep(0.5) print(".", end=".") sys.stdout.flush() thinking_timelast += 0.5 #print(thinking_timelast) if thinking_time + too_long < thinking_timelast: print(thinking_time) print("Took too long!") for stillcalculating in calculating: if stillcalculating.poll() == None: stillcalculating.kill() break for opened_file in opened_files: opened_file.close() print("Done") translations, formalplans = questTranslation.interpret(data) #print(formalplans) motivations = [ questClassification.classify_fuzzy(formalplan) for formalplan in formalplans ] for formalplan, motivation in zip(formalplans, motivations): #print(translation,motivation) if len(formalplan) < 1: emptyOrComplete += 1 else: print(" ".join(formalplan) + " " + motivation[0]) quest_log.write(" ".join(formalplan)) quest_log.write(" m:" + motivation[0]) quest_log.write("\n\n") motivation_count[motivation[0]] += 1 """ for formalplan in formalplans: #print(formalplan) if len(formalplan) < 1: emptyOrComplete += 1 else: print(" ".join(formalplan)) quest_log.write(" ".join(formalplan)) quest_log.write("\n\n") """ print(motivation_count) print(emptyOrComplete) run -= 1 quest_log.close()