示例#1
0
 def test_solve_dinner(self):
     planner = Planner()
     self.assertEqual(
         planner.solve('dinner/dinner.pddl', 'dinner/pb1.pddl'), [
             Action('cook', [], [['clean']], [], [['dinner']], []),
             Action('wrap', [], [['quiet']], [], [['present']], []),
             Action('carry', [], [['garbage']], [], [],
                    [['garbage'], ['clean']])
         ])
	def get_best_plan_with_keys_recursive(self,graph, keys):

		if keys == 0:
			planner = Planner()
			planner.graph = graph
			path = planner.solve(self.actual_position, [self.target])
			return path, self.keys_available - keys

		best_plan = None
		best_plan_dist = 999999
		best_keys_num = 9999999
		removed_walls = []

		for node, walls in self.walls.items():
			aux = None
			for i,w in enumerate(walls):

				if walls[Orientation.up] == 1 and i == Orientation.up:
					aux = (node[0]+1,node[1], Orientation.up)
				elif walls[Orientation.left] == 1 and i == Orientation.left:
					aux = (node[0],node[1]-1, Orientation.left)
				elif walls[Orientation.down] == 1 and i == Orientation.down:
					aux = (node[0]-1,node[1], Orientation.down)
				elif walls[Orientation.right] == 1 and i == Orientation.right:
					aux = (node[0],node[1]+1, Orientation.right)

				if aux in graph.nodes:
					graph.add_edge( (node[0],node[1],i),aux)

					path, keys_used = self.get_best_plan_with_keys_recursive(graph,keys - 1)

					graph.disconect( (node[0],node[1],i),aux)

					if(len(path) < best_plan_dist ):
						best_plan_dist = len(path)
						best_keys_num = keys_used
						best_plan = path
					if( len(path) == best_plan_dist and keys_used < best_keys_num ):
						best_plan_dist = len(path)
						best_keys_num = keys_used
						best_plan = path

		return best_plan, best_keys_num
	def plan_action(self):
		planner = Planner()

		if self.current_state == RobotState.searching:
			planner.graph = self.graph
			path = planner.solve(self.actual_position, [self.target])

		elif self.current_state == RobotState.returning:
			planner.graph = self.original_graph
			path,keys_used = self.best_plan(self.original_graph, self.keys_available)

		self.current_plan = path

		if len(path) <= 1:
			return Action.nothing
		else:
			next_state = path[1]
			turn = next_state[2] - self.actual_position[2]

			if( not (next_state in self.graph.edges[self.actual_position]) and
					( abs(next_state[0] - self.actual_position[0]) +
						abs(next_state[1] - self.actual_position[1]) == 1 ) and turn == 0):

				if self.waiting_for_door == False:
					print "Waiting For Door!"
					self.waiting_for_door = True
					return Action.open_door
				else:
					self.keys_available -= 1
					print 'USING KEY ! left: ',self.keys_available
					self.waiting_for_door = False

			if turn == 0:
				return Action.move
			elif turn==-1:
				return Action.turn_right
			elif turn==1:
				return Action.turn_left
			elif turn == 3:
				return Action.turn_right
			elif turn == -3:
				return Action.turn_left
示例#4
0
	def plan_action(self):
		planner = Planner()
		planner.graph = self.graph
		path = planner.solve(self.location, self.goal)
		self.current_plan = path

		if len(path) <= 1:
			return False
		else:
			next_state = path[1]
			turn = next_state[2] - self.location[2]
			if turn == 0:
				return Action.move
			elif turn==-1:  
				return Action.turn_right
			elif turn==1:
				return Action.turn_left
			elif turn == 3:
				return Action.turn_right
			elif turn == -3:
				return Action.turn_left
示例#5
0
def mainCallBack(block_n, domain_c):
    global plan_act
    start_time = time.time()
    outputtext.delete(1.0, tk.END)  # clear the output text text widget
    print(block_n, domain_c)
    if domain_c == 'Blocks-world':
        domain = 'plan_files/domain_bw.pddl'
        if block_n == '2':
            problem = 'plan_files/p2_bw.pddl'
        elif block_n == '3':
            problem = 'plan_files/p3_bw.pddl'
        elif block_n == '4':
            problem = 'plan_files/p4_1_bw.pddl'
        elif block_n == '5':
            problem = 'plan_files/p5_2_bw.pddl'
        elif block_n == '6':
            problem = 'plan_files/p6_bw.pddl'  # 2 minutes
            outputtext.insert(tk.END,
                              'This one might take some time...' + '\n')
        else:
            entNumRo.configure(state='normal')
            cbDomain.configure(state='readonly')
            outputtext.delete(1.0, tk.END)  # clear the output text text widget
            outputtext.insert(tk.END,
                              'Please insert a number of blocks!' + '\n')
            raise Exception
    elif domain_c == 'BoxBall-world':
        domain = 'plan_files/domain_gripper.pddl'
        if block_n == '2':
            problem = 'plan_files/p2_gripper.pddl'
        elif block_n == '3':
            problem = 'plan_files/p3_gripper.pddl'
        elif block_n == '4':
            problem = 'plan_files/p4_gripper.pddl'
        elif block_n == '5':
            problem = 'plan_files/p5_gripper.pddl'  # 459 sec - 8min
            outputtext.insert(tk.END,
                              'This one might take some time...' + '\n')
        else:
            entNumRo.configure(state='normal')
            cbDomain.configure(state='readonly')
            outputtext.delete(1.0, tk.END)  # clear the output text text widget
            outputtext.insert(tk.END,
                              'Please insert a number of blocks!' + '\n')
            raise Exception
    elif domain_c == 'Tower-world':
        domain = 'plan_files/domain_hanoi.pddl'
        if block_n == '2':
            problem = 'plan_files/p2_hanoi.pddl'
        elif block_n == '3':
            problem = 'plan_files/p3_hanoi.pddl'
        elif block_n == '4':
            problem = 'plan_files/p4_hanoi.pddl'
        elif block_n == '5':
            problem = 'plan_files/p5_hanoi.pddl'  # 3 seconds
        elif block_n == '6':
            problem = 'plan_files/p6_hanoi.pddl'  # 1 minute
            outputtext.insert(tk.END,
                              'This one might take some time...' + '\n')
        else:
            entNumRo.configure(state='normal')
            cbDomain.configure(state='readonly')
            outputtext.delete(1.0, tk.END)  # clear the output text text widget
            outputtext.insert(tk.END,
                              'Please insert a number of blocks!' + '\n')
            raise Exception
    else:
        entNumRo.configure(state='normal')
        cbDomain.configure(state='readonly')
        outputtext.delete(1.0, tk.END)  # clear the output text text widget
        outputtext.insert(tk.END, 'Please insert the domain!' + '\n')
        raise Exception
    plan_act = []
    planner = Planner()
    outputtext.insert(tk.END, 'Getting the solution!' + '\n')
    plan = planner.solve(domain, problem)

    print('Time taken: ' + str(time.time() - start_time) + 's')
    if plan:
        df = []
        start_act = [datetime.datetime(2020, 1, 28, 12, 45, 00)]
        a = []
        for act in plan:
            a.append(((str(act).split('\n'))[0]).split()[1])
            a.append(((str(act).split('\n'))[1]).split(':')[1])
        print('Length of plan:', len(a))
        aa = []
        for k in range(int(len(a) / 2)):
            ai = a[k * 2] + a[(k * 2) + 1]
            aa.append(ai)
        if aa[0][0] == 'p':
            time_act = (np.random.normal(1.044, 0.317))
        elif aa[0][0] == 'd':
            time_act = (np.random.normal(1.042, 0.502))
        elif aa[0][0] == 'm':
            time_act = (np.random.normal(2.036, 0.548))
        elif aa[0][0] == 'u':
            time_act = (np.random.normal(0.504, 0.048))
        elif aa[0][0] == 's':
            time_act = 0.802
        else:
            time_act = 2
        end_act = [start_act[0] + datetime.timedelta(seconds=(time_act * 60))]
        test = random.randrange(len(aa))
        for i in range(len(aa)):
            name_act = (aa[i])
            if name_act[0] == 'p':
                time_act2 = (np.random.normal(1.044, 0.317))
            elif name_act[0] == 'd':
                time_act2 = (np.random.normal(1.042, 0.502))
            elif name_act[0] == 'm':
                time_act2 = (np.random.normal(2.036, 0.548))
            elif name_act[0] == 'u':
                time_act2 = (np.random.normal(0.504, 0.048))
            elif name_act[0] == 's':
                time_act2 = 0.802
            else:
                time_act2 = 2
            start_act.append(end_act[i])
            end_act.append(start_act[i + 1] +
                           datetime.timedelta(seconds=(time_act2 * 60)))
            count = 0
            if i == test or i == int(test / 2) or i == int(test * 2):
                count = count + 1
                end_act[i] = end_act[i] + datetime.timedelta(seconds=0.336)
                df.append(
                    dict(Task=name_act,
                         Start=str(start_act[i]),
                         Finish=str(end_act[i]),
                         Resource=resources[1]))
            else:
                if count == 1:
                    start_act[i] = start_act[i] + datetime.timedelta(
                        seconds=0.336)
                    df.append(
                        dict(Task=name_act,
                             Start=str(start_act[i]),
                             Finish=str(end_act[i]),
                             Resource=resources[0]))
                else:
                    df.append(
                        dict(Task=name_act,
                             Start=str(start_act[i]),
                             Finish=str(end_act[i]),
                             Resource=resources[0]))
            plan_act.append(name_act)
        r = lambda: random.randint(0, 255)
        colors = ['#%02X%02X%02X' % (r(), r(), r())]
        for i in range(1, len(aa) + 1):
            colors.append('#%02X%02X%02X' % (r(), r(), r()))
        fig = ff.create_gantt(df,
                              index_col='Resource',
                              colors=colors,
                              title='Daily Schedule',
                              show_colorbar=True,
                              bar_width=0.8,
                              showgrid_x=True,
                              showgrid_y=True)
        plot(fig,
             filename='other/%s%s.html' % (domain_c, block_n),
             auto_open=False)
        outputtext.delete(1.0, tk.END)  # clear the output text text widget
        for x in plan_act:
            outputtext.insert(tk.END, x + '\n')
        outputtext.insert(
            tk.END,
            'Total Task Time: ' + str(end_act[len(aa)] - start_act[0]) + '\n')
        entNumRo.configure(state='normal')
        cbDomain.configure(state='readonly')
    else:
        print('No plan was found')
        entNumRo.configure(state='normal')
        cbDomain.configure(state='readonly')
示例#6
0
                   'WED2': {'v': 2, 'u': 2},
                   'PrFm': {'v': 2, 'u': 2}
                   }

    source = AdUnisHSR()
    username, password = utils.parse_user_credentials('auth.cfg')
    response = source.signin(username, password)

    filters = [
                restrictions.InTimeRange(time(7, 0), time(18, 00)),
                restrictions.MinChance(30),
                restrictions.FreeTime(3, range(5), time(12), time(23)),
                # restrictions.FreeTime(1, range(5), time(6), time(23))
                ]

    planner = Planner(module_spec.keys(), source)
    solutions = planner.solve(filters)

    for solution in solutions:
        planner.verify(module_spec, solution)

    # Print max. 10 timetables
    nr_timetables_to_print = len(solutions) if len(solutions) < 10 else 10
    for i in range(0, nr_timetables_to_print):
        lectures = []
        for val in solutions[i].values():
            lectures += val
        # printer.verify(lectures)
        printTimeTable(lectures)
        print('\n')
示例#7
0
            'u': 2
        }
    }

    source = AdUnisHSR()
    username, password = utils.parse_user_credentials('auth.cfg')
    response = source.signin(username, password)

    filters = [
        restrictions.InTimeRange(time(7, 0), time(18, 00)),
        restrictions.MinChance(30),
        restrictions.FreeTime(3, range(5), time(12), time(23)),
        # restrictions.FreeTime(1, range(5), time(6), time(23))
    ]

    planner = Planner(module_spec.keys(), source)
    solutions = planner.solve(filters)

    for solution in solutions:
        planner.verify(module_spec, solution)

    # Print max. 10 timetables
    nr_timetables_to_print = len(solutions) if len(solutions) < 10 else 10
    for i in range(0, nr_timetables_to_print):
        lectures = []
        for val in solutions[i].values():
            lectures += val
        # printer.verify(lectures)
        printTimeTable(lectures)
        print('\n')