Beispiel #1
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 #2
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}")