def test_best_pos_search_recursion(self): schedules = [[t1] * 100 + [t2] * 100 + [t3] * 100] expectations = [( 0, 300, 120 ) # 120 seems to be the result returned by the code and appears to be correct, but I'm not convinced... ] for i, schedule in enumerate(schedules): a = Agent(parameters={ "name": "1", "skill": 0.95, "task_time": 1, "move_speed": 1 }) a.schedule = schedule p_i = a.best_pos_search(tI, range(len(a.schedule) + 1)) p_j = a.best_pos_search(tJ, range(len(a.schedule) + 1)) p_k = a.best_pos_search(tK, range(len(a.schedule) + 1)) p_ijk = p_i[0], p_j[0], p_k[0] #print(p_ijk) assert p_ijk == expectations[i], "Expected {} but got {}".format( expectations[i], p_ijk)
def main(): agents, tasks = generate_painter(X, Y, 3) # We give back m tasks in a giveback phase, and each iteration we assign one task, # so for m agents we should have a giveback probability < 1/m auctioneer = Auctioneer(agents, tasks, 0.25) #1 / ( * len(agents))) schedule = auctioneer.optimize_schedule() Agent.print_schedule(X, Y, auctioneer, schedule)
def test_worst_task_idx(self): a = Agent(parameters={ "name": "1", "skill": 0.95, "task_time": 1, "move_speed": 1 }) a.schedule = [t1] * 10 + [tJ] + [t1] * 10 wt = a.worst_task_idx() assert wt == 10, "Should have been {} but was {}".format(10, wt)
def main(): agents, tasks = generate_painter(X, Y, 3) # nFeas = The number of feasible 1-moves # Given a schedule, we can move tasks equal to the number of agents. # Using the result by Osman, we set alpha = n * Nfeas, gamma = n alpha = math.factorial(X * Y) # The number of iterations is n annealer = Annealer(agents, tasks, 2500, 100, 0.1, 1) schedule = annealer.optimize_schedule() Agent.print_schedule(X, Y, annealer, schedule)
def test_best_pos_search_base_case(self): schedules = [[], [tX], [t1, t2, t3]] expectations = [(0, 0, 0), (1, 1, 1), (0, 3, 1)] for i, schedule in enumerate(schedules): a = Agent(parameters={ "name": "1", "skill": 0.95, "task_time": 1, "move_speed": 1 }) a.schedule = schedule p_i = a.best_pos_search(tI, range(len(a.schedule) + 1)) p_j = a.best_pos_search(tJ, range(len(a.schedule) + 1)) p_k = a.best_pos_search(tK, range(len(a.schedule) + 1)) p_ijk = p_i[0], p_j[0], p_k[0] assert p_ijk == expectations[i], "Expected {} but got {}".format( expectations[i], p_ijk)
def generate_painter(X, Y, num_agents): agents = [] skill_diff = 1.0 / (num_agents + 1) time_diff = 1.0 / (2 * num_agents + 1) for i in range(num_agents): agents += [ Agent( parameters={ "name": str(i), "skill": 1.0 - (i * skill_diff), "task_time": 1.0 - (i * time_diff), "move_speed": (i + 1) }) ] #print(agents[-1]) total = 0 tasks = [] half_diagonal = ((X**2 + Y**2)**0.5) / 2 for i in range(X): for j in range(Y): # p = (X^2 + Y^2) / 4 - euclidean distance from center to (i, j) # = ( (i - (X/2))^2 + (j - (X/2)^2) ^ 0.5 center_distance = ((i - X / 2)**2 + (j - Y / 2)**2)**0.5 p = half_diagonal - center_distance total += p t = Task( parameters={ "name": "({},{})".format(i, j), "i": i, "j": j, "chosen_probability": p }) tasks += [t] for task in tasks: task.parameters["chosen_probability"] /= total #for i in range(X): # for j in range(Y): # print(round(tasks[i * Y + j].chosen_probability(), 2), end=" ") # print("\n") return agents, tasks # print(generate_painter(5, 5, 3))