Пример #1
0
def run():
    f = open('./config.yml')
    config = yaml.load(f)
    roi_shape = config['roi_shape']
    dead_zone = config['dead_zone']
    cube_resolution = config['cube_resolution']
    laser_num = config['laser_num']
    lidar_num = config['lidar_num']
    beam_angle = config['beam_angle']
    max_itrs = config['max_itrs']
    numb_bees = config['numb_bees']
    lower_bound = config['lower_bound'] * lidar_num
    upper_bound = config['upper_bound'] * lidar_num
    estimate_solve_time = config['estimate_solve_time']
    save_result_to_json = config['save_result_to_json']

    assert (len(beam_angle) == laser_num
            ), "Please check the number of beams' angles of pitch"
    eval.logConfig(config=config)

    VSR_solver = eval.Evaluator(roi_shape=roi_shape,
                                dead_zone=dead_zone,
                                cube_resolution=cube_resolution,
                                laser_num=laser_num,
                                lidar_num=lidar_num,
                                pitch_angle=beam_angle)
    # creates model
    if estimate_solve_time:
        eval.estimateTime(config=config, VSR_solver=VSR_solver, Hive=Hive)

    now = time.time()
    model = Hive.BeeHive(lower=lower_bound,
                         upper=upper_bound,
                         fun=VSR_solver.solve,
                         numb_bees=numb_bees,
                         max_itrs=max_itrs,
                         verbose=True)
    cost = model.run()
    total_time = time.time() - now
    print("Total time consume: ", total_time)
    print("Solution: ", model.solution)
    # prints out best solution
    print("Fitness Value ABC: {0}".format(model.best))

    if save_result_to_json:
        eval.saveResults(config=config,
                         model=model,
                         total_time=total_time,
                         cost=cost)
    # plots convergence
    Utilities.ConvergencePlot(cost)
def run():

    ndim = int(10)
    model = Hive.BeeHive(
        lower=[-5.12] * ndim,
        upper=[5.12] * ndim,
        fun=evaluator,
        numb_bees=50,
        max_itrs=100,
    )

    cost = model.run()

    Utilities.ConvergencePlot(cost)

    print("Fitness Value ABC: {0}".format(model.best))
Пример #3
0
def run():

    # Crea el modelo
    ndim = int(2)
    model = Hive.BeeHive(lower     = [0 for i in range(ndim)],
                         upper     = [10 for i in range(ndim)],
                         fun       = Rosenbrock ,
                         numb_bees =  50       ,
                         max_itrs  =  60       ,)

    # Corre el modelo
    cost = model.run()

    # Grafica de convergencia
    Utilities.ConvergencePlot(cost)

    # Prints
    print("Fitness Value ABC: {0}".format(model.best))
    print("Solution: {0}".format(cost["solution"]))
Пример #4
0
def run():

    # creates model
    ndim = int(2)
    model = Hive.BeeHive(
        lower=[0] * ndim,
        upper=[10] * ndim,
        fun=evaluator,
        numb_bees=10,
        max_itrs=50,
    )

    # runs model
    cost = model.run()

    # plots convergence
    Utilities.ConvergencePlot(cost)

    # prints out best solution
    print("Fitness Value ABC: {0}".format(model.best))
Пример #5
0
    def runAlgos(runs,
                 lower,
                 upper,
                 d,
                 numb_bees,
                 fun,
                 name,
                 means=True,
                 bests=False,
                 draw=True):
        print("\n\n-----------------------\nRunning algorithms using ", name,
              " for fitness")

        with concurrent.futures.ThreadPoolExecutor() as executor:

            future1 = executor.submit(
                convertResult,
                lower,
                upper,
                d,
                fun,
                numb_bees,
                runs,
                0,
                "ABC",
                name,
            )
            future2 = executor.submit(
                convertResult,
                lower,
                upper,
                d,
                fun,
                numb_bees,
                runs,
                1,
                "sABC",
                name,
            )
            future3 = executor.submit(
                convertResult,
                lower,
                upper,
                d,
                fun,
                numb_bees,
                runs,
                2,
                "qABC",
                name,
            )
            # future4 = executor.submit(convertResult,lower, upper, d, fun, numb_bees, runs, 3, "qsABC", name,)
            future5 = executor.submit(
                convertResult,
                lower,
                upper,
                d,
                fun,
                numb_bees,
                runs,
                4,
                "iqABC",
                name,
            )
            future6 = executor.submit(
                convertResult,
                lower,
                upper,
                d,
                fun,
                numb_bees,
                runs,
                5,
                "iqsABC",
                name,
            )
            cost1, ends1, avg1 = future1.result()
            cost2, ends2, avg2 = future2.result()
            cost3, _, _ = future3.result()
            # cost4, _, _ = future4.result()
            cost5, ends5, avg5 = future5.result()
            cost6, ends6, avg6 = future6.result()

            ends5 = np.array(ends5)
            ends6 = np.array(ends6)
            if len(ends5) >= 20:
                stat, p = wilcoxon(ends5, ends6)
                print('Alg %s Statistics=%.3f, p=%.3f' % (name, stat, p))
                f = open(filename, "a")
                resultString = "iqsabc"
                if avg5 < avg6: resultString = "iqabc"
                if p >= 0.05: resultString = "-"
                f.write('Zres&%s&%s&%f&p=%.4f\\\\\n' % (name, resultString,
                                                        (avg5 - avg6), p))
                f.close()
            if len(ends1) >= 20:
                stat, p = wilcoxon(ends1, ends2)
                print('Alg %s Statistics=%.3f, p=%.3f' % (name, stat, p))
                f = open(filename, "a")
                resultString = "sabc"
                if avg1 < avg2: resultString = "abc"
                if p >= 0.05: resultString = "-"
                f.write('Yres&%s&%s&%f&p=%.4f\\\\\n' % (name, resultString,
                                                        (avg1 - avg2), p))
                f.close()
            if draw:
                Utilities.ConvergencePlots(
                    name, [cost1, cost2, cost3, cost5, cost6],
                    ['blue', 'magenta', 'green', 'red', 'black'],
                    ['ABC', 'sABC', 'qABC', 'iqABC', 'iqsABC'],
                    means=means,
                    bests=bests,
                    right=int(3000))
                pass