Exemple #1
0
def main(MAXEVALS=MAXEVALS, current_batch=current_batch, number_of_batches=number_of_batches):
    print("Benchmarking solver %s, %s" % (str(solver), time.asctime(), ))
    t0 = time.clock()
    if 11 < 3:
        # simple Pythonic use case, never leaves a problem unfree()ed, ctrl-C "safe"
        print('Pythonic usecase ...'); sys.stdout.flush()
        found_problems, addressed_problems = 0, 0
        for problem in Benchmark(suite_name, suite_options, 
                                 observer_name, observer_options):
            found_problems += 1
            # use problem only under some conditions, mainly for testing
            if 11 < 3 and not ('f11' in problem.id and 'i03' in problem.id):
                continue
            coco_optimize(problem, MAXEVALS)
            addressed_problems += 1
        print("%s done (%d of %d problems benchmarked), %s (%f s)." 
                % (suite_name, addressed_problems, found_problems,
                   time.asctime(), (time.clock()-t0)/60**0))
    
    elif 1 < 3:
        # usecase with batches
        print('Batch usecase ...'); sys.stdout.flush()
        bm = Benchmark(suite_name, suite_options, observer_name, observer_options)  
        addressed_problems = []
        for problem_index in bm.problem_indices: # bm.next_problem_index(problem_index) is also available
            if (problem_index + current_batch - 1) % number_of_batches:
                continue
            problem = bm.get_problem(problem_index)
            # print("%4d: " % problem_index, end="")
            coco_optimize(problem, MAXEVALS)
            problem.free()  # preferably free would not be necessary, but how?
            addressed_problems += [problem_index]
        print("%s done (%d of %d problems benchmarked%s), %s (%f min)." % 
               (suite_name, len(addressed_problems), len(bm),
                 ((" in batch %d of %d" % (current_batch, number_of_batches))
                   if number_of_batches > 1 else ""), time.asctime(), (time.clock()-t0)/60))

    elif 1 < 3:
        # generic example with batches, similarly possible in all languages
        print('Generic usecase with batches...'); sys.stdout.flush()
        bm = Benchmark(suite_name, suite_options, observer_name, observer_options)  
        found_problems, addressed_problems = 0, 0
        problem_index = -1  # first index is not necessarily 0!
        while True:
            problem_index = bm.next_problem_index(problem_index)
            if problem_index < 0: 
                break 
            found_problems += 1
            if (problem_index + current_batch - 1) % number_of_batches:
                continue
            problem = bm.get_problem(problem_index) 
            # use problem only under some conditions, mainly for testing
            if 1 or ('d20' in problem.id and 'i01' in problem.id):
                print("%4d: " % problem_index, end="")
                coco_optimize(problem, MAXEVALS)
                addressed_problems += 1
            problem.free()  # preferably free would not be necessary
        print("%s done (%d of %d problems benchmarked%s), %s (%f min)." % 
               (suite_name, addressed_problems, found_problems,
                 ((" in batch %d of %d" % (current_batch, number_of_batches))
                   if number_of_batches > 1 else ""), time.asctime(), (time.clock()-t0)/60, ))
Exemple #2
0
        for problem in Benchmark(suite_name, suite_options, 
                                 observer_name, observer_options):
            found_problems += 1
            # use problem only under some conditions, mainly for testing
            if 11 < 3 and not ('f11' in problem.id and 'i03' in problem.id):
                continue
            coco_optimize(problem, MAXEVALS)
            addressed_problems += 1
        print("%s done (%d of %d problems benchmarked), %s (%f s)." 
                % (suite_name, addressed_problems, found_problems,
                   time.asctime(), (time.clock()-t0)/60**0))
    
    elif 1 < 3:
        # usecase with batches
        print('Batch usecase ...'); sys.stdout.flush()
        bm = Benchmark(suite_name, suite_options, observer_name, observer_options)  
        addressed_problems = []
        for problem_index in bm.problem_indices: # bm.next_problem_index(problem_index) is also available
            if (problem_index + current_batch - 1) % number_of_batches:
                continue
            problem = bm.get_problem(problem_index)
            # print("%4d: " % problem_index, end="")
            coco_optimize(problem, MAXEVALS)
            problem.free()  # preferably free would not be necessary, but how?
            addressed_problems += [problem_index]
        print("%s done (%d of %d problems benchmarked%s), %s (%f min)." % 
               (suite_name, len(addressed_problems), len(bm),
                 ((" in batch %d of %d" % (current_batch, number_of_batches))
                   if number_of_batches > 1 else ""), time.asctime(), (time.clock()-t0)/60))

    elif 1 < 3: