Beispiel #1
0
 def run(self, q: Instance) -> Solution:
     H = b(q.tasks, start=1)
     l = Schedule(q.no_tasks, [
         i[0] for i in c(H,
                         key=lambda x: (x[1].due_date + 10 * x[1].duration[
                             0] + 5 * x[1].duration[1]) / (x[1].weight))
     ])
     return Solution(self.v(q, Solution(0.0, l)).value, l)
Beispiel #2
0
    def run2(in_data: Instance) -> Solution:  # 80.5, 61.86
        tasks = [(i + 1, t) for i, t in enumerate(in_data.tasks)]
        tasks.sort(key=lambda x: x[1].due_date / x[1].weight)

        schedule = Schedule(in_data.no_tasks, [t[0] for t in tasks])
        solution = Solution(score=-1, schedule=schedule)

        evl = Evaluator136811().evaluate(in_data, solution)

        return Solution(score=evl.value, schedule=schedule)
Beispiel #3
0
 def run(self, AUHkREgCmDcPaow: Instance) -> Solution:
     AUHkREgCmDcPaot = AUHkREgCmDcPaoz(AUHkREgCmDcPaow.tasks, start=1)
     AUHkREgCmDcPaos = Schedule(AUHkREgCmDcPaow.no_tasks, [
         i[0] for i in AUHkREgCmDcPaoO(
             AUHkREgCmDcPaoz(AUHkREgCmDcPaow.tasks, start=1),
             key=lambda x: (x[1].due_date + AUHkREgCmDcPaow.no_tasks / 100 *
                            AUHkREgCmDcPaoT(x[1].duration)) /
             (AUHkREgCmDcPaow.no_tasks / 1000 * x[1].weight))
     ])
     return Solution(
         AUHkREgCmDcPaoV(AUHkREgCmDcPaow, Solution(0.0,
                                                   AUHkREgCmDcPaos)).value,
         AUHkREgCmDcPaos)
Beispiel #4
0
    def evaluate_my_algorithm(self):
        _, evals, algs = self.__index_setup()
        eval: Evaluator = evals[INDEX][0]()
        alg: Algorithm = algs[INDEX][0]()
        print(alg.__class__.__name__)
        relative_losses_sum = 0.0
        relative_losses_count = 0
        my_relative_losses_sum = 0.0
        my_relative_losses_count = 0
        not_found = set([])
        print('\t'.join(['n', 'dummy_solution', 'algorithm_solution', 'time']))
        for index in INDICES:
            for n in range(50, 501, 50):
                try:
                    instance = Instance.load(self.get_instance_path(index, n))
                    seq_output = eval.validate_schedule(instance, Solution.get_dummy_solution(n))
                    alg_output = eval.validate_algorithm(instance, alg)
                    assert alg_output.correct
                    relative_loss = (seq_output.value - alg_output.value) / seq_output.value
                    # print(seq_output.value, alg_output.value)
                    if index == INDEX:
                        my_relative_losses_sum += relative_loss
                        my_relative_losses_count += 1
                        print('\t'.join(map(lambda x: str(round(x, 2)),
                                            [n, seq_output.value, alg_output.value, 100 * relative_loss, alg_output.time])))
                        # print("\\\\\n\\hline")
                    relative_losses_sum += relative_loss
                    relative_losses_count += 1
                    # print(round(alg_output.value, 2))
                except FileNotFoundError:
                    not_found.add(index)

        log.info(f'Not found instances of: {not_found}')
        log.info(f'Mean relative improvement on own instances: {round(100 * my_relative_losses_sum / my_relative_losses_count, 2)}')
        log.info(f'Mean relative improvement: {round(100 * relative_losses_sum / relative_losses_count, 2)}')
Beispiel #5
0
    def run(self, in_data: Instance) -> Solution:
        n = in_data.no_tasks
        m = in_data.no_machines

        schedule = []
        end_tasks = []
        machine_time = m * [0]
        tasks = [i for i in zip(range(1, n + 1), in_data.tasks)]
        result = []

        best = tasks
        for a in range(1, 14, 2):
            for b in range(5):
                tmp = sorted(tasks,
                             key=lambda task: -priority(
                                 a, b, task[1].weight, task[1].due_date))
                if score(tmp) < score(best):
                    best = tmp

        schedule = best
        D = score(schedule)
        schedule = [task[0] for task in schedule]

        return Solution(score=D,
                        schedule=Schedule(no_tasks=n, schedule=schedule))
Beispiel #6
0
    def run(self, in_data: Instance) -> Solution:
        tasks = [
            Task(i, in_data.tasks[i].duration, in_data.tasks[i].due_date,
                 in_data.tasks[i].weight) for i in range(len(in_data.tasks))
        ]
        machine_times = [0 for _ in range(in_data.no_machines)]
        average_weight = self.get_average_weight(tasks)
        schedule = []
        total_latency = 0
        weights_sum = 0
        for task in tasks:
            weights_sum += task.weight

        for i in range(in_data.no_tasks):
            selected_task = self.chose_next_element(tasks, machine_times,
                                                    average_weight)
            self.remove_selected_task(tasks, selected_task)
            schedule.append(selected_task + 1)
            machine_times = self.update_machine_times(
                machine_times, in_data.tasks[selected_task])
            total_latency += max(
                0, machine_times[in_data.no_machines - 1] -
                in_data.tasks[selected_task].due_date
            ) * in_data.tasks[selected_task].weight
        return Solution(total_latency / weights_sum,
                        schedule=Schedule(in_data.no_tasks, schedule))
Beispiel #7
0
 def run(self, in_data: Instance) -> Solution:
     scheduler = Scheduler(in_data.tasks)
     scheduler.init_sort()
     scheduled_jobs = scheduler.schedule2()
     schedule = list(map(lambda x: x.number + 1, scheduled_jobs))
     score = getScore(in_data, schedule)
     #exit()
     return Solution(score, Schedule(in_data.no_tasks, schedule))
Beispiel #8
0
    def run(self, in_data: Instance) -> Solution:
        """ 
        0. Reduce searched tasks by tasks with weight less than some parameters ( weight, due date)
        1. Sort available tasks by due date and then weight
        2. for every task find one with best score
        3. add this to solution
        4. 
        """
        tasks_with_id = list(enumerate(in_data.tasks, 1))

        tasks_with_id.sort(key=lambda t: (t[1].due_date, -t[1].weight))

        # sort out tasks with high due_date and low weight or with no weight
        less_important_tasks = list(
            filter(
                lambda task: task[1].weight <
                (in_data.no_tasks / (0.05 * in_data.no_tasks)), tasks_with_id))

        # take all tasks with weight != 0 which have higher weight and due date isn't high
        tasks_to_proceed = list(
            filter(
                lambda task: task[1].weight >=
                (in_data.no_tasks / (0.05 * in_data.no_tasks)), tasks_with_id))

        schedule_by_id = []
        solution = 0
        clock = 0
        while len(tasks_to_proceed) > 0:
            # find best fitting
            id_in_list, best_task_id = find_best_task_by_due_date_duration(
                tasks_to_proceed, clock)
            # add to solution  new values

            schedule_by_id.append(best_task_id)
            # increase clock and remove chosen task from available
            clock += sum(tasks_to_proceed[id_in_list][1].duration)
            tasks_to_proceed.pop(id_in_list)

        add_rest_tasks_to_schedule(less_important_tasks, schedule_by_id,
                                   solution, clock)

        schedule = Schedule(in_data.no_tasks, schedule_by_id)
        solution = Evaluator126828().evaluate(in_data,
                                              Solution(0.0, schedule)).value
        return Solution(solution, schedule=schedule)
Beispiel #9
0
    def run(self, in_data: Instance) -> Solution:
        jobs = [{
            'index':
            i,
            'weight':
            job.weight,
            'due_date':
            job.due_date,
            'durations': (job.duration[0], job.duration[1], job.duration[2])
        } for i, job in enumerate(in_data.tasks, start=1)]

        avg_p = sum([sum(j['durations']) for j in jobs]) / in_data.no_tasks / 3
        timestamps = [0, 0, 0]
        schedule = []

        def modified_weight(job):
            t_0 = timestamps[0] + job['durations'][0]
            t_1 = max(t_0 + job['durations'][1],
                      timestamps[1] + job['durations'][1])
            t_2 = max(t_1 + job['durations'][2],
                      timestamps[2] + job['durations'][2])
            return max(0, avg_p + t_2 - job['due_date']) * (
                job['weight'] / sum(job['durations']))

        while len(jobs) > 0:
            j = max(jobs, key=modified_weight)
            timestamps[0] += j['durations'][0]
            timestamps[1] = max(timestamps[1] + j['durations'][1],
                                timestamps[0] + j['durations'][1])
            timestamps[1] = max(timestamps[2] + j['durations'][2],
                                timestamps[1] + j['durations'][2])
            jobs = list(filter(lambda x: x['index'] != j['index'], jobs))
            schedule.append(j['index'])
            if len(jobs) > 0:
                avg_p = max(
                    [sum([j['durations'][x] for j in jobs])
                     for x in range(3)]) / len(jobs)

        schedule = Schedule(in_data.no_tasks, schedule)
        sol = Solution(0.0, schedule)
        score = Evaluator132211().evaluate(in_data, sol).value
        sol = Solution(score, schedule)
        return sol
Beispiel #10
0
 def run(self, in_data: Instance) -> Solution:
 
     n = in_data.no_tasks
     no_machines = in_data.no_machines
     tasks_list = in_data.tasks
     
     
     tasks_list = [[i+1,x,0] for i,x in enumerate(tasks_list)] 
     
     
     
     tasks_list.sort(key = lambda t: (t[1].duration[0]+t[1].duration[1]+t[1].duration[2])*t[1].due_date/t[1].weight)
     
    
     maximum = -1
     time1 = 0
     time2 = 0
     time3 = 0 
     c1 = 0
     c2 = 0
     c3 = 0
     mianownik = 0
     licznik = 0
                 
         
     #wyliczanie wyniku
     for x in tasks_list:
         task_number = x[0]
         task_info = x[1]
         p1 = task_info.duration[0]
         p2 = task_info.duration[1]
         p3 = task_info.duration[2]
         due_date = task_info.due_date
         weight = task_info.weight
                     
         time1 += p1
         c1 = time1
         
         time2 = max(c1, c2) 
         time2 += p2
         c2 = time2
         
         time3 = max(c2, c3)
         time3 += p3 
         c3 = time3
         
         Dj = max(0, c3 - due_date)
         mianownik += weight
         licznik += weight*Dj
     
     score = licznik/mianownik
     
     schedule = Schedule(no_tasks = n, schedule = [index_tasksinfo[0] for index_tasksinfo in tasks_list])
     
     return Solution(score = score, schedule = schedule)
Beispiel #11
0
    def run3(
            in_data: Instance) -> Solution:  # 55.96, 20.12  |  80.14, 59.81  |
        tasks = [(i + 1, t) for i, t in enumerate(in_data.tasks)]
        simple = [(i, Algorithm136811.make_simple_task(t)) for i, t in tasks]
        group1 = [
            task for task in simple
            if task[1].duration[0] <= task[1].duration[1]
        ]
        group2 = [
            task for task in simple
            if task[1].duration[0] > task[1].duration[1]
        ]

        group1.sort(key=lambda x: x[1].duration[0])
        group2.sort(key=lambda x: x[1].duration[1], reverse=True)
        group1.sort(key=lambda x: x[1].due_date / x[1].weight)
        group2.sort(key=lambda x: x[1].due_date / x[1].weight)
        i1, i2 = 0, 0
        schedule = []
        while i1 < len(group1) and i2 < len(group2):
            if group1[i1][1].due_date <= group2[i2][1].due_date:
                schedule.append(group1[i1][0])
                i1 += 1
            else:
                schedule.append(group2[i2][0])
                i2 += 1
        while i1 < len(group1):
            schedule.append(group1[i1][0])
            i1 += 1
        while i2 < len(group2):
            schedule.append(group2[i2][0])
            i2 += 1

        # schedule = [t[0] for t in group1]
        # schedule.extend([t[0] for t in group2])
        schedule = Schedule(in_data.no_tasks, schedule)
        solution = Solution(-1, schedule=schedule)

        evl = Evaluator136811().evaluate(in_data, solution)
        return Solution(score=evl.value, schedule=schedule)
Beispiel #12
0
    def run(self, instance: Instance):
        algorithm = self.duration_by_weight_look_ahead

        for i, task in enumerate(instance.tasks):
            instance.tasks[i] = ScheduleTask(task.duration,
                                             task.due_date,
                                             task.weight,
                                             no=i + 1)
        schedule = algorithm(instance)
        score = self.mwt(instance, schedule)
        # evaluator = Evaluator136834()
        # score = evaluator.mwt(instance, schedule)
        return Solution(score, schedule)
Beispiel #13
0
 def validate_all_instances(self):
     eval: Evaluator = self.__index_setup()[1][INDEX][0]()
     results = []
     not_found = set([])
     for index in INDICES:
         for n in range(50, 501, 50):
             try:
                 instance = Instance.load(self.get_instance_path(index, n))
                 evaluator_output = eval.validate_schedule(instance, Solution.get_dummy_solution(n))
                 results.append(evaluator_output.value)
             except FileNotFoundError:
                 not_found.add(index)
     print("\n".join([str(round(value, 2)) for value in results]))
     log.info(f"Not found: {not_found}")
Beispiel #14
0
    def run(self, in_data: Instance) -> Solution:
        n=in_data.no_tasks
        m=in_data.no_machines

        schedule = []
        end_tasks = []
        machine_zeit=m*[0]
        dead=[0]*(n+10)
        post_heap=[0]*(n+10)
        convoys_to_nothingness=[]

        tasks=in_data.tasks
        pos=range(1, n+1)
        all_tasks = [i for i in zip(pos, tasks)]
        maximal=max([sum([x.duration[y] for x in tasks]) for y in range(m)])
        global bottlenecks
        bottlenecks=[sum([x.duration[y] for x in tasks])/maximal for y in range(m)]

        partial=sorted(all_tasks, key=velvet_decoder)

        batches=math.ceil(math.log(n))
        schedule=[]

        for i, x in partial:
            if len(convoys_to_nothingness)!=0 or dead[i]==1:
                if dead[i]==0 and post_heap[i]==0 and maxer(x, machine_zeit)>=x.due_date:
                    post_heap[i]=1
                    h_push(convoys_to_nothingness, [i, x])
                i, x=h_pop(convoys_to_nothingness, machine_zeit)

            task_zeit=0
            for ij in range(m):
                task_zeit=max(machine_zeit[ij], task_zeit)
                task_zeit+=x.duration[ij]
                machine_zeit[ij]=task_zeit
            schedule.append([i, x])
            dead[i]=1

            for j, y in partial:
                if dead[j]==0 and post_heap[j]==0 and maxer(y, machine_zeit)>=y.due_date:
                    post_heap[j]=1
                    h_push(convoys_to_nothingness, (j, y))

        score=evaluat(schedule)
        schedule = [task[0] for task in schedule]

        return Solution(score=score, schedule=Schedule(no_tasks=n, schedule=schedule))
Beispiel #15
0
 def run(self, in_data: Instance) -> Solution:
     n = in_data.no_tasks
     schedule = Schedule(n, simple_wedd_sort(in_data))
     obj = objective(in_data, schedule)
     return Solution(obj, schedule=schedule)
Beispiel #16
0
 def run(p,in_data:Instance)->Solution:
  jobs=[Job(counter+1,task.duration,task.due_date,task.weight)for counter,task in enumerate(in_data.tasks)]
  jobs.sort(key=lambda x:(sum(x.duration)*float(x.due_date/x.weight)))
  J=Schedule(in_data.no_tasks,[v.id for v in jobs])
  s=Evaluator127183().evaluate(in_data,Solution(0.0,J)).value
  return Solution(s,J)