Example #1
0
def main():
    """
    Main program
    """
    domain = [-5, 5]
    dim=2
    ea = SSGA(domain=domain, size=60, dim=dim, fitness=fitness_sphere)
    ea.run(maxeval=dim*10000)
    [bestsol, bestfit] = ea.getBest()
    print "Best: %f\n" %bestfit
Example #2
0
def main():
    """
    Main program
    """
    parser = OptionParser()
    parser.add_option("-f", "--function", action="store", type="int", dest="function", help="set the function to optimise", metavar="FUNCTION")
    domain = [-5, 5]
    dim=10
    ea = SSGA(domain=domain, size=60, dim=dim, fitness=fitness_sphere)
    ea.run(maxeval=dim*10000)
    [bestsol, bestfit] = ea.getBest()
    print "Best: %e\n" %bestfit
Example #3
0
def main():
    """
    Main program
    """
    args = ArgsCEC05()

    if args.hasError:
        args.print_help_exit()

    fun = args.function
    dim = args.dimension
    times = args.times

    print "Function: %d" % fun
    print "Dimension: %d" % dim
    print "Times: %d" % times
    cec2005.config(fun, dim)
    domain = cec2005.domain(fun)
    #    domain = [-5, 5]
    print "Domain: ", domain
    #    dim=10
    ea = SSGA(domain=domain, size=60, dim=dim, fitness=cec2005.evaluate)

    for x in xrange(times):
        ea.run(maxeval=dim * 10000)
        [bestsol, bestfit] = ea.getBest()
        print "BestSol: ", bestsol
        print "BestFitness: %e" % bestfit
        ea.reset()
Example #4
0
def plot_anim_ssga(minimum, maximum, dif):
    def sphere_two(x,y):
	return (x**2+y**2)

    dx = dy = dif
    x = arange(minimum, maximum, dx)
    y = arange(minimum, maximum, dy)
    X,Y = meshgrid(x, y)
    Z = sphere_two(X, Y)
    fig = plt.figure()
    ax = subplot(111)
    x, y = (np.random.rand(2, 50))*100
    #ax.plot(x, y, 'wo')
    im = imshow(Z, cmap=cm.jet)
    im.set_interpolation('bilinear')
    #show()

    domain = [-5, 5]
    dim=2
    ea = SSGA(domain=domain, size=50, dim=dim, fitness=fitness_sphere)
    ea.initPopulation(dim)
    population = ea.population()
    x = population[:,0]
    y = population[:,1]
    line, = ax.plot(x, y, 'wo')
    ea.run(maxeval=dim*10000)

    import gobject
    print 'adding idle'
    gobject.idle_add(animate)
    print 'showing'
    plt.show()