示例#1
0
def run(solver_object, budget=budget,
        max_runs=max_runs,
        current_batch=current_batch,
        number_of_batches=number_of_batches):
    """Initialize suite and observer, then benchmark solver by calling
    `batch_loop(SOLVER, suite, observer, budget,...`.
    """
    ##############################################################################
    solver = solver_object.ibea
    suite_name = "bbob-biobj"
    suite_instance = "year:2016"
    suite_options = "dimensions: 2,3,5"  # "dimensions: 2,3,5,10,20 "  # if 40 is not desired
    observer_name = suite_name
    observer_options = (
        ' result_folder: %s_on_%s_budget%04dxD '
        % (str(solver_object), suite_name, budget) +
        ' algorithm_name: %s ' % solver.__name__ +
        ' algorithm_info: "Indicator-based Evolutionary Algorithm (epsilon)" ')
    observer = Observer(observer_name, observer_options)
    suite = Suite(suite_name, suite_instance, suite_options)
    print("Benchmarking solver '%s' with budget=%d*dimension on %s suite, %s"
          % (' '.join(str(solver).split()[:2]), budget,
             suite.name, time.asctime()))
    if number_of_batches > 1:
        print('Batch usecase, make sure you run *all* %d batches.\n' %
              number_of_batches)
    t0 = time.clock()
    batch_loop(solver, suite, observer, budget, max_runs,
               current_batch, number_of_batches)
    print(", %s (%s total elapsed time)." % (time.asctime(), ascetime(time.clock() - t0)))
示例#2
0
def main(budget=budget,
         max_runs=max_runs,
         current_batch=current_batch,
         number_of_batches=number_of_batches):
    """Initialize suite and observer, then benchmark solver by calling
    ``batch_loop(SOLVER, suite, observer, budget,...``
    """
    suite = Suite(suite_name, suite_instance, suite_options)

    observer_name = default_observers()[suite_name]
    # observer_name = another observer if so desired
    observer_options.update_gracefully(default_observer_options())
    observer = Observer(observer_name, observer_options.as_string)

    print("Benchmarking solver '%s' with budget=%d*dimension on %s suite, %s" %
          (' '.join(
              str(SOLVER).split()[:2]), budget, suite.name, time.asctime()))
    if number_of_batches > 1:
        print('Batch usecase, make sure you run *all* %d batches.\n' %
              number_of_batches)
    t0 = time.clock()
    batch_loop(SOLVER, suite, observer, budget, max_runs, current_batch,
               number_of_batches)
    print(", %s (%s total elapsed time)." %
          (time.asctime(), ascetime(time.clock() - t0)))
    print('Data written to folder', observer.result_folder)
    print('To post-process the data call \n'
          '    python -m cocopp %s \n'
          'from a system shell or \n'
          '    cocopp.main("%s") \n'
          'from a python shell' % (2 * (observer.result_folder, )))
示例#3
0
def main(problem_subset,
         budget,
         max_runs=max_runs,
         current_batch=current_batch,
         number_of_batches=number_of_batches):
    """Initialize suite and observer, then benchmark solver by calling
    ``batch_loop(SOLVER, suite, observer, budget,...``
    """
    observer_name = default_observers()[suite_name]
    observer_options.update_gracefully(default_observer_options())

    observer = Observer(observer_name, observer_options.as_string)
    suite = Suite(suite_name, suite_instance, suite_options)

    print("Benchmarking solver '%s' with budget=%d*dimension on %s suite, %s" %
          (' '.join(
              str(SOLVER).split()[:2]), budget, suite.name, time.asctime()))
    if number_of_batches > 1:
        print('Batch usecase, make sure you run *all* %d batches.\n' %
              number_of_batches)
    t0 = time.clock()
    batch_loop(SOLVER,
               suite,
               observer,
               budget,
               max_runs,
               current_batch,
               number_of_batches,
               problem_subset=problem_subset)
    print(", %s (%s total elapsed time)." %
          (time.asctime(), ascetime(time.clock() - t0)))
def main(budget=budget,
         max_runs=max_runs,
         current_batch=current_batch,
         number_of_batches=number_of_batches):
    """Initialize suite and observer, then benchmark solver by calling
    ``batch_loop(SOLVER, suite, observer, budget,...``
    """
    suite = Suite(suite_name, suite_instance, suite_options)

    observer_name = default_observers()[suite_name]
    # observer_name = another observer if so desired
    # observer_options.update_gracefully(default_observer_options())
    observer = Observer(observer_name, observer_options.as_string)
    """

    print("Benchmarking solver '%s' with budget=%d*dimension on %s suite, %s"
          % (' '.join(str(SOLVER).split()[:2]), budget,
             suite.name, time.asctime()))
    if number_of_batches > 1:
        print('Batch usecase, make sure you run *all* %d batches.\n' %
              number_of_batches)
    t0 = time.clock()
    """
    batch_loop(SOLVER, suite, observer, budget, max_runs, current_batch,
               number_of_batches)
    """
示例#5
0
    def run(self, budget=100, current_batch=1, number_of_batches=15):
        # type: (int, int, int) -> None

        suite = Suite(self._suite_name, self._suite_instance,
                      self._suite_options)

        observer_name = default_observers()[self._suite_name]

        observer_options = self._build_observer_options(budget)
        observer = Observer(observer_name, observer_options.as_string)

        for problem_index, problem in enumerate(tqdm(suite)):
            if (problem_index % number_of_batches) != current_batch - 1:
                continue

            observer.observe(problem)

            max_evals = budget * problem.dimension
            self._solver(problem,
                         problem.lower_bounds,
                         problem.upper_bounds,
                         max_evals - problem.evaluations_constraints,
                         verbose=False)
def log_reconstruct(input_path, output_path, algorithm_name, algorithm_info,
                    functions, instances, dimensions):
    """Reconstructs the .info, .dat and .tdat files produced by the logger from the .adat files in the input_path.

       Takes into account only the given functions, instances and dimensions. If any .info, .dat and .tdat files of
       the same names already exist in the output_path, the new data is appended to them.
    """
    suite_name = 'bbob-biobj'

    print('Reading archive information...')
    archive_info = ArchiveInfo(input_path, functions, instances, dimensions,
                               False)

    function_string = archive_info.get_function_string()
    instance_string = archive_info.get_instance_string()
    dimension_string = archive_info.get_dimension_string()
    file_name_set = archive_info.get_file_name_set()

    print('Initializing the suite and observer...')
    suite_instance = 'instances: {}'.format(instance_string)
    suite_options = 'dimensions: {} function_indices: {}'.format(
        dimension_string, function_string)
    suite = Suite(suite_name, suite_instance, suite_options)
    observer_options = 'result_folder: {} algorithm_name: {} algorithm_info: "{}" log_nondominated: read'. \
        format(output_path, algorithm_name, algorithm_info)
    observer = Observer(suite_name, observer_options)

    print('Reconstructing...')
    for input_file in file_name_set:

        (_suite_name, function, _instance,
         dimension) = parse_archive_file_name(input_file)

        with open(input_file, 'r') as f_in:
            print(input_file)

            problem = None
            objective_vector = None
            evaluation_found = False
            instance = None
            count_not_updated = 0
            evaluation = 0

            for line in f_in:

                if len(line.split()) < 3:
                    continue

                elif line[0] == '%' and 'instance' in line:
                    instance = int(get_key_value(line[1:], 'instance'))
                    if instance in instances:
                        if problem is not None:
                            if not evaluation_found:
                                raise PreprocessingWarning(
                                    'Missing the line `% evaluations = ` in the previous '
                                    'problem. This problem is file = {}, instance = {}'
                                    .format(input_file, instance))
                            if count_not_updated > 0:
                                print(
                                    '{} solutions did not update the archive'.
                                    format(count_not_updated))
                            problem.free()
                        problem = suite.get_problem_by_function_dimension_instance(
                            function, dimension, instance, observer)
                        evaluation_found = False

                elif line[0] != '%' and instance in instances:
                    try:
                        split = line.split()
                        evaluation = int(split[0])
                        objective_vector = np.array(split[1:3])
                        updated = problem.logger_biobj_feed_solution(
                            evaluation, objective_vector)
                        if updated == 0:
                            count_not_updated += 1
                    except ValueError as error:
                        print('Problem in file {}, line {}, skipping line\n{}'.
                              format(input_file, line, error))
                        continue

                elif line[0] == '%' and 'evaluations' in line:
                    old_evaluation = evaluation
                    evaluation = int(get_key_value(line[1:], 'evaluations'))
                    evaluation_found = True
                    if (
                            evaluation > old_evaluation
                    ) and problem is not None and objective_vector is not None:
                        problem.logger_biobj_feed_solution(
                            evaluation, objective_vector)

            if problem is not None:
                if not evaluation_found:
                    print(
                        'Missing the line `% evaluations = ` in this or the previous problem. This is file = {}, '
                        'instance = {}'.format(input_file, instance))
                if count_not_updated > 0:
                    print('{} solutions did not update the archive'.format(
                        count_not_updated))
                problem.free()

            f_in.close()
示例#7
0
    """ 
        suite: dataset
        observer: output
        solver: optimisation of function
        dimension, current_batch, number_of_batches: choose data
        max_run: max times of run
    """
    for fun_index, fun in enumerate(suite):
        if (fun_index + current_batch - 1) % number_of_batches:
            continue
        if fun.dimension > dimension:
            continue
        fun.observe_with(observer)
        solver(fun, fun.lower_bounds, fun.upper_bounds, budget)

    # cocopp.main(observer.result_folder)  # re-run folders look like "...-001" etc
    # webbrowser.open("file://" + os.getcwd() + "/ppdata/index.html")


if __name__ == '__main__':
    """add parameters here """
    suite = Suite('bbob-biobj', 'year:2018', '')
    observer = Observer(
        "bbob-biobj",
        "result_folder: %s_on_%s" % (solver.__name__, "bbob2018"))
    solver = random_search
    dimension = 5
    budget = 100
    main(budget, suite, observer, solver, dimension, max_runs, current_batch,
         number_of_batches)