Exemplo n.º 1
0
class Controller:
    def __init__(self):
        self.swarm = Swarm()
        self.problem = Problem()

    def loadParameters(self):
        self.problem.LoadData()
        for i in range(0, 50):
            self.swarm.v.append(Particle(self.problem))
            for k in range(0, len(self.problem.getA())):
                self.swarm.v[i].data.append(randint(0, 1))
                self.swarm.v[i].velocity.append(0)
            self.swarm.v[i].evaluate()
            self.swarm.noOfParticles += 1

    def iterate(self):
        gBest = self.swarm.getBest()[0]
        for i in range(0, self.swarm.noOfParticles):
            lBest = self.swarm.getBestNeighbourhood(i)
            self.swarm.v[i].bestPosition = gBest.data
            self.swarm.v[i].update(lBest)

    def run(self):

        for i in range(0, 100):
            self.iterate()

        print(self.swarm.getBest()[0].data)
Exemplo n.º 2
0
 def restart(self):
     '''Music Generation'''
     self.filename = self.get_random_song()
     if self.filename is None: self.filename = "background_music.wav"
     pg.mixer.music.load(self.filename)
     self.length = pg.mixer.Sound(self.filename).get_length() * 30
     self.input_data = read(self.filename)
     self.audio = self.input_data[1]
     '''Terrain / Background / Enemies / Swarm / Player Reset'''
     self.terrain = Terrain_Generation.Terrain(1000, 500)
     self.terrain.prev_values = []
     self.current_background = 0
     self.background = Background.Background("background.jpg")
     self.enemies = []
     self.enemy_spawn_tick = 0
     self.player.dead = True
     self.player.lives = 3
     self.displayScore = self.player.score
     self.uploaded_data = False
     self.start_time = time.time()
     self.swarm = Swarm.Swarm()
     self.swarms = [Swarm.Swarm()]
     self.swarm_timing = 0
     self.average = [(i, 37) for i in range(0, 1000, 10)]
     self.options = False
     self.personalise = False
     self.account_menu = False
     pg.mouse.set_visible(True)
     self.scroll_tick = 0
Exemplo n.º 3
0
def main3():
    prob = Problem()
    pop = Swarm(prob)
    ctrl = Controller()
    res = ctrl.runAlg()
    fitnessOptim = res.fitness
    individualOptim = res.position
    print('Result: The detectet minimum point is (%3.2f %3.2f) \n with function\'s value %3.2f'% \
          (individualOptim[0],individualOptim[1], fitnessOptim) )
Exemplo n.º 4
0
    def runAlg(self):
        self.edges, self.nodes = self.loadParameters()
        self.pop = Swarm(self.noParticles, self.edges, self.nodes)

        # we establish the particles' neighbors
        neighborhoods = self.pop.selectNeighbours(self.sizeNeighbourhood)

        for i in range(100):
            self.iteration(neighborhoods)

        #print the best individual
        best = 0
        for i in range(1, len(self.pop)):
            if (self.pop[i].fitness < self.pop[best].fitness):
                best = i

        result = self.pop[best]
        fitnessOptim = self.pop[best].fitness
        e1, e2 = [], []
        n1, n2 = set(), set()
        for i in range(0, len(result.pozition)):
            if result.pozition[i] == 0:
                e1.append(self.edges[i])
                n1.add(self.edges[i][0])
                n1.add(self.edges[i][0])
            else:
                e2.append(self.edges[i])
                n2.add(self.edges[i][0])
                n2.add(self.edges[i][1])

        print(e1)
        print(e2)

        print("Fitness", fitnessOptim)
        individualOptim = self.pop.population[best].pozition
        print("Individual", individualOptim)
Exemplo n.º 5
0
@author: Walter
'''

from Swarm import *

if __name__ == '__main__':

    def Rastrigin(X):
        val = 0.0
        for d in range(30):
            val += X[0, d]**2 + 10 - 10 * np.cos(2 * np.pi * X[0, d])
        return val

    bounds = []
    bests = []
    swarm = Swarm(20, 30)
    swarm.setParam(2.0, 2.0, 0.8, Rastrigin)
    ws = []
    for i in range(30):
        ws.append([-5.12, 5.12])
    swarm.initParticles(ws)

    runPlan = [250]
    for r in runPlan:
        for t in range(r):
            swarm.update()
            #print swarm.globalbestFitness

            bounds.append(swarm.bound)
            bests.append(swarm.globalbestFitness)
Exemplo n.º 6
0
 def __init__(self):
     self.swarm = Swarm()
     self.problem = Problem()
def genColour(x):
    x = x / radius * x_range[1]
    # print(x)
    h = getH(x)
    if h > 1:
        h = 1
    if h < -1:
        h = -1
    colour = [int(124 + 124 * h), 0, int(124 + 124 * -h)]
    return colour


# swarm = Swarm.Swarm(10, getH, -CLAMPVAL[0], CLAMPVAL[0])
swarm = Swarm.Swarm(10,
                    getH,
                    x_range[0],
                    x_range[1],
                    dimensions=2,
                    maximizing=False)


def drawSwarm():
    if swarm.dimensions == 2:
        posList = swarm.getParticlesPos()
        for [x, y], vel in posList:
            x = int((x / x_range[1]) * CENTER[0] + CENTER[0])
            y = int(CENTER[1] - (y / x_range[1]) * CENTER[1])

            pygame.draw.circle(screen, white, [x, y], 5, 1)
            # vel = [0.36*vel[0], 0.36*vel[1]]
            # pygame.draw.lines(screen, yellow, False, [pos, vel], 1)
Exemplo n.º 8
0
class Window(QtGui.QMainWindow):

    #---------------------------------------------#
    #define class variables
    msPtX = 20
    msPtY = 20

    swarm = Swarm.Swarm(100, 50)

    # obs = Obstacle.Obstacle(75, 500, 300)
    # obs2 = Obstacle.Obstacle(40, 100, 450)
    # obs3 = Obstacle.Obstacle(40, 300, 450)
    # obs4 = Obstacle.Obstacle(40, 500, 450)
    # obs5 = Obstacle.Obstacle(40, 100, 250)
    # obs6 = Obstacle.Obstacle(40, 300, 250)
    # obs7 = Obstacle.Obstacle(40, 500, 250)
    # obsList = [obs, obs2, obs3, obs4, obs5, obs6, obs7]
    obsList = []
    for i in range(0, 100):
        x = random.uniform(50, 950)
        y = random.uniform(50, 950)
        obsList.append(Obstacle.Obstacle(20, x, y))

    #---------------------------------------------#
    #define what to do on initialization
    def __init__(self):
        super(Window, self).__init__()
        self.setGeometry(100, 200, 1000, 1000)
        self.setWindowTitle("Final Form")
        self.timer = QtCore.QTimer()
        self.timer.timeout.connect(self.update)
        self.timer.start(2)
        self.show()

    #---------------------------------------------#
    #grab coordinates of mouse click
    def mousePressEvent(self, QMouseEvent):
        mousePoint = (str(QMouseEvent.pos())[20:])
        mousePoint = mousePoint.rsplit(", ")
        msPtX = mousePoint[0]
        noEndP = mousePoint[1].rsplit(")")
        msPtY = noEndP[0]
        self.msPtX = int(msPtX)
        self.msPtY = int(msPtY)

    #---------------------------------------------#
    #movement to mouse coordinates after mouse click
    def moveToMouse(self):
        self.swarm.updateBotList(self.msPtX, self.msPtY)
        for element in self.swarm.botList:
            element.move(self.msPtX, self.msPtY, self.swarm.botList,
                         self.obsList)

    #---------------------------------------------#
    #paint event being looped to simulate animation
    def paintEvent(self, event):
        paint = QPainter()
        paint.begin(self)
        paint.setRenderHint(QPainter.Antialiasing)
        #set background
        paint.setBrush(Qt.white)
        paint.drawRect(event.rect())
        #set circle
        paint.setPen(Qt.black)
        paint.setBrush(Qt.green)
        #draw circle
        # rad = 15
        # center = QPoint(self.bot.xPos, self.bot.yPos)
        # paint.drawEllipse(center, rad, rad)

        #draw a swarm of bots
        for element in self.swarm.botList:
            center = QPoint(element.xPos, element.yPos)
            paint.drawEllipse(center, element.size, element.size)

        #create object to draw
        paint.setBrush(Qt.blue)
        for element in self.obsList:
            obsCenter = QPoint(element.xPos, element.yPos)
            paint.drawEllipse(obsCenter, element.size, element.size)

        self.moveToMouse()

        paint.end()
Exemplo n.º 9
0
            for j in range(0,25): #try it 99 more times
                swarm = Swarm.Swarm(num_rockets=rockets[i], num_iterations=iterations[i], num_steps=10, algorithm=alg, dimensions=dims, numSparks=sparks, func=func, benchmarks=2500)                
                swarm.run()
                print("Completed trial {} for {} and {} with best of {}".format(j, functions[func], algorithms[alg], swarm.gbest))
                outputLine += str(swarm.gbest) + ","
            f.write(outputLine[0:-1] + "\n") # take off last comma



'''
#swarm = Swarm.Swarm(num_rockets=rockets[0], num_iterations=iterations[0], num_steps=10, algorithm=1, dimensions=dims, numSparks=sparks, func=2, benchmarks=2500)
dims = 2
sparks = 3
swarm = Swarm.Swarm(num_rockets=4,
                    num_iterations=10,
                    num_steps=10,
                    algorithm=Recursive,
                    dimensions=dims,
                    numSparks=sparks,
                    func=2,
                    benchmarks=250)
print(swarm.get_num_func_evals())
swarm.run()
print("gbest History: ", swarm.gbest)
print(swarm.newthing)

if dims == 2:
    swarm.plot_history()

#'''
Exemplo n.º 10
0
def initZombies(x):
    global zombies
    global swarm
    swarm = Swarm.Swarm((Util.WINDOW_WIDTH, Util.WINDOW_HEIGHT))
    for i in range(0, x):
        zombies.append(Zombie.Zombie(hero, swarm))
Exemplo n.º 11
0
 def init_swarm(self, args):
     """Initialize the swarm"""
     self.swarm = Swarm.Swarm(self.transport, args)
Exemplo n.º 12
0
if __name__ == '__main__':

    def Griewank(X):
        val = 0.0
        for d in range(30):
            val += X[0, d]**2
        val /= 4000.0
        val2 = 0.0
        for d in range(30):
            val2 *= np.cos(X[0, d] / np.sqrt(float(d))) + 1
        return val - val2

    bounds = []
    bests = []
    swarm = Swarm(20, 30)
    swarm.setParam(2.0, 2.0, 0.8, Griewank)
    ws = []
    for i in range(30):
        ws.append([-600.0, 600.0])
    swarm.initParticles(ws)

    runPlan = [250]
    for r in runPlan:
        for t in range(r):
            swarm.update()
            #print swarm.globalbestFitness

            bounds.append(swarm.bound)
            bests.append(swarm.globalbestFitness)
Exemplo n.º 13
0
'''
from Swarm import *
import matplotlib.pyplot as plt

if __name__ == '__main__':
    
    def DeJongF4(X):
        val = 0.0
        for d in range(30):
            val += (d+1) * ( X[0,d]**4 )
        return val
    
    bounds = []
    bests = []
    pos = []
    swarm = Swarm(20, 30)
    swarm.setParam(20.0, 20.0, 0.8, DeJongF4)
    ws = []
    for i in range(30):
        ws.append([-20.0, 20.0]) 
    swarm.initParticles(ws)
    
    runPlan = [250]
    for r in runPlan:
        for t in range(r):
            swarm.update()
            
            bounds.append(swarm.bound)
            bests.append(swarm.globalbestFitness)
            pos.append(swarm.particles[0].pos[0,0]);
            
Exemplo n.º 14
0
class Controller:
    def __init__(self, filename):
        self.filename = filename

    def iteration(self, neighbors):
        bestNeighbors = []
        #determine the best neighbor for each particle
        for i in range(len(self.pop)):
            bestNeighbors.append(neighbors[self.pop[i]][0])
            for j in range(1, len(neighbors[self.pop[i]])):
                if (bestNeighbors[i].fitness >
                        neighbors[self.pop[i]][j].fitness):
                    bestNeighbors[i] = neighbors[self.pop[i]][j]

        #update the velocity for each particle
        for i in range(len(self.pop.population)):
            for j in range(len(self.pop[i].velocity)):
                newVelocity = self.w * self.pop.population[i].velocity[j]
                newVelocity = newVelocity + self.c1 * random() * (
                    bestNeighbors[i].pozition[j] -
                    self.pop.population[i].pozition[j])
                newVelocity = newVelocity + self.c2 * random() * (
                    self.pop.population[i].bestPozition[j] -
                    self.pop.population[i].pozition[j])
                self.pop.population[i].velocity[j] = newVelocity

        #update the pozition for each particle
        for i in range(len(self.pop.population)):
            self.pop.updateParticle(i)

    def runAlg(self):
        self.edges, self.nodes = self.loadParameters()
        self.pop = Swarm(self.noParticles, self.edges, self.nodes)

        # we establish the particles' neighbors
        neighborhoods = self.pop.selectNeighbours(self.sizeNeighbourhood)

        for i in range(100):
            self.iteration(neighborhoods)

        #print the best individual
        best = 0
        for i in range(1, len(self.pop)):
            if (self.pop[i].fitness < self.pop[best].fitness):
                best = i

        result = self.pop[best]
        fitnessOptim = self.pop[best].fitness
        e1, e2 = [], []
        n1, n2 = set(), set()
        for i in range(0, len(result.pozition)):
            if result.pozition[i] == 0:
                e1.append(self.edges[i])
                n1.add(self.edges[i][0])
                n1.add(self.edges[i][0])
            else:
                e2.append(self.edges[i])
                n2.add(self.edges[i][0])
                n2.add(self.edges[i][1])

        print(e1)
        print(e2)

        print("Fitness", fitnessOptim)
        individualOptim = self.pop.population[best].pozition
        print("Individual", individualOptim)

    def loadParameters(self):
        f = open(self.filename, "r")
        line = f.readline().strip()
        nodes = set()
        edges = []
        while line != "":
            pair = line.split(" ")
            nodes.add(int(pair[0]))
            nodes.add(int(pair[1]))
            edges.append([int(pair[0]), int(pair[1])])
            line = f.readline().strip()
        f.close()
        self.noParticles = 100
        self.sizeNeighbourhood = 20
        self.w = 1.0
        self.c1 = 1.0
        self.c2 = 2.5
        return edges, nodes
Exemplo n.º 15
0
Arquivo: C4.py Projeto: dqyi11/PSO_sim
if __name__ == '__main__':
    
    def Griewank(X):
        val = 0.0
        for d in range(30):
            val += X[0,d]**2 
        val /= 4000.0
        val2 = 0.0
        for d in range(30):
            val2 *= np.cos(X[0,d]/np.sqrt(float(d))) + 1
        return val - val2
    
    bounds = []
    bests = []
    swarm = Swarm(20, 30)
    swarm.setParam(2.0, 2.0, 0.8, Griewank)
    ws = []
    for i in range(30):
        ws.append([-600.0, 600.0]) 
    swarm.initParticles(ws)
    
    runPlan = [250]
    for r in runPlan:
        for t in range(r):
            swarm.update()
            #print swarm.globalbestFitness
            
            bounds.append(swarm.bound)
            bests.append(swarm.globalbestFitness)
            
Exemplo n.º 16
0
 def __init__(self, pop=Swarm(problem=Problem()), _prob=Problem()):
     self.population = pop
     self.problem = _prob
Exemplo n.º 17
0
    class LPPDemo(Demo):
        def __init__(self, swarm, size=(800, 600)):
            Demo.__init__(self, swarm=swarm, size=size)
            self.vert = SFVert(self.window, .8)

        def draw(self, taxi):
            self.window.clear()
            for c in Centroid.centroids:
                self.window.draw(c.triFan)
            for c in Centroid.centroids:
                self.window.draw(c.linesStrip)
            self.vert.setScale(self.view.size.x / self.window.size.x * 3)
            for c in Centroid.centroids:
                self.vert.draw(c)
            self.window.display()
            self.processEvents()

    swarm = Swarm(48)
    demo = LPPDemo(swarm)
    taxi = Taxi(swarm)
    Centroid.centroids = ConnectedSubset(taxi)
    for c in Centroid.centroids:
        c.triFan = SFCentroidTriFan(c)
        c.linesStrip = SFCentroidOutline(c)

    demo.draw(taxi)
    while demo.is_open:
        demo.draw(taxi)
        sleep(.25)
Exemplo n.º 18
0
			col= sf.Color.BLACK
			for i in range(len(verts)):
				self[i].color=col
				self[i].position=verts[i]
			self[0].color=sf.Color.GREEN

	class LPPDemo(Demo):
		def draw(self, taxi):
			self.window.clear()
			for c in Centroid.centroids:	self.window.draw(c.triFan)
			for c in Centroid.centroids:	self.window.draw(c.linesStrip)
			self.window.display()
			self.processEvents()


	swarm= Swarm(32)
	demo= LPPDemo(swarm)
	taxi=Taxi(swarm)

	Centroid.centroids= LongestPolyPath(taxi)
	for c in Centroid.centroids:
		c.triFan=SFCentroidTriFan(c)
		c.linesStrip=SFCentroidOutline(c)

	demo.draw(taxi)
	while demo.is_open:
		demo.draw(taxi)
		sleep(.25)


Exemplo n.º 19
0
os.mkdir(working_dir)

###########################
# setup nodes
print("Preparing devices...")

multiparametric_space = dict()
swarm_keys = []

for parameter in data['settings']['parameter_space'].items():
    swarm_keys.append(parameter[0])
    multiparametric_space[parameter[0]] = list(map(float, parameter[1]))

swarm = Swarm(multiparametric_space,
              int(data['settings']['max_values']),
              swarm_keys,
              dir_name=working_dir)
swarm.type = int(data['settings']['optimum_type'])
swarm.start()

for node in data['nodes']:
    particle = import_particle(node, swarm, working_dir, data, write=False)
    time.sleep(2)
    swarm.add_particle(particle)

########################################

print("Setup done.")

xml.write_xml(data, working_dir)
Exemplo n.º 20
0
def main(out_port, in_port):

    # LOAD PARAMS FROM CONFIG
    load_config()

    # DEFINE BOUNDING BOX(ES)
    cube_min = array([10, 50, 7, 0, 0])
    edge_length = 40  # 35
    cube = Swarm.Cube(cube_min, edge_length)
    cube2 = Swarm.Cube(array([10 + edge_length, 50, 7, 0, 0]), edge_length)
    cube3 = Swarm.Cube(array([10 + 2 * edge_length, 50, 7, 0, 0]), edge_length)

    # MAKE SWARM OBJECTS
    # TODO make the 'follow' implicit
    # format:       swarm,                    channel
    swarm_data = [
        (Swarm.Swarm(13, cube, 6), 3),
        # (Swarm.Swarm(7, cube, follow=7), 1),
        # (Swarm.Swarm(15, cube3, follow=12), 2),
        # (Swarm.Swarm(4, cube2, follow=7), 9)
    ]
    swarms = list(map(lambda x: x[0], swarm_data))

    # SET UP MIDI
    midiout = rtmidi.MidiOut()
    midiout.open_port(out_port)

    interps = list()
    i1 = PolyInterpreter(0, midiout, swarm_data[0])
    start_interp(i1,
                 tempo=120,
                 scale=Scales.satie,
                 preset="piano",
                 instrument="")
    interps.append(i1)

    # i2 = PolyInterpreter(1, midiout, swarm_data[1])
    # start_interp(i2, tempo=130, scale=Scales.chrom, preset="piano", instrument="")
    # interps.append(i2)
    # #
    # i3 = PolyInterpreter(2, midiout, swarm_data[2])
    # start_interp(i3, tempo=90, scale=Scales.satie, preset="synth", instrument="fantasia")
    # interps.append(i3)

    # start up the midi in stream
    # in_stream = None
    if Parameters.SP.ATTRACTOR_MODE == 2:
        in_stream = InStream(interps, in_port)
        ren_att = True
    else:
        in_stream = None
        ren_att = False

    config = pyglet.gl.Config(sample_buffers=1, samples=4)

    # resolution
    import os
    if os.name != 'nt':
        w = 1200
        h = 900
    else:
        w = 1920
        h = 1080

    # creates the window and sets its properties
    Window(swarms,
           interps,
           ren_att,
           config=config,
           width=w,
           height=h,
           caption='Murmurations',
           resizable=True)

    # start the application
    pyglet.app.run()

    # CLEAN UP
    for interp in interps:
        interp.done = True  # kill it.
        interp.join()
    del midiout
    if in_stream:
        in_stream.done = True
        in_stream.join()
    print("Exiting")
Exemplo n.º 21
0
    # h = -(x**2 + y**2)+1
    return h


def genColour(x, Q=2, H=10, A=1):
    h = getH(x, Q, H, A)
    if h > 1:
        h = 1
    if h < -1:
        h = -1
    colour = [int(124 + 124 * -h), 0, int(124 + 124 * h)]
    return colour


# swarm = Swarm.Swarm(10, getH, -CLAMPVAL[0], CLAMPVAL[0])
swarm = Swarm.Swarm(1, getH, CENTER[0], CENTER[0], dimensions=1)

while not done:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            done = True

        if event.type == pygame.MOUSEBUTTONDOWN:
            pos = pygame.mouse.get_pos()
            print(getH(CENTER[0] - pos[0]))

        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_RIGHT:
                swarm.runStep(0.5, 0.8, 0.9, 1.0)
                for pos, vel in swarm.getParticlesPos():
                    print(pos, vel)
Exemplo n.º 22
0
@author: Walter
'''

from Swarm import *

if __name__ == '__main__':

    def Rosenbrock(X):
        val = 0.0
        for d in range(30 - 1):
            val += 100 * (X[0, d + 1] - X[0, d]**2)**2 + (X[0, d] - 1)**2
        return val

    bounds = []
    bests = []
    swarm = Swarm(20, 30)
    swarm.setParam(2.0, 2.0, 0.8, Rosenbrock)
    ws = []
    for i in range(30):
        ws.append([-100.0, 100.0])
    swarm.initParticles(ws)

    runPlan = [250]
    for r in runPlan:
        for t in range(r):
            swarm.update()
            #print swarm.globalbestFitness

            bounds.append(swarm.bound)
            bests.append(swarm.globalbestFitness)
Exemplo n.º 23
0
Arquivo: C3.py Projeto: dqyi11/PSO_sim
@author: Walter
'''

from Swarm import *

if __name__ == '__main__':
    
    def Rastrigin(X):
        val = 0.0
        for d in range(30):
            val += X[0,d]**2 + 10 - 10 * np.cos(2 * np.pi * X[0,d])
        return val
    
    bounds = []
    bests = []
    swarm = Swarm(20, 30)
    swarm.setParam(2.0, 2.0, 0.8, Rastrigin)
    ws = []
    for i in range(30):
        ws.append([-5.12, 5.12]) 
    swarm.initParticles(ws)
    
    runPlan = [250]
    for r in runPlan:
        for t in range(r):
            swarm.update()
            #print swarm.globalbestFitness
            
            bounds.append(swarm.bound)
            bests.append(swarm.globalbestFitness)
            
Exemplo n.º 24
0
        # x = x / CLAMPVAL[0]
        # y = y / CLAMPVAL[1]
    else:
        raise ValueError(
            "\nPosition Vector of length {} not implemented!\n".format(dim))

    #h = math.sin(math.sqrt(x**2 + yx**2))
    h = -((1 / Q)**(w(x, y) / H) * A * math.cos(w(x, y)))
    # h = -(x**2 + y**2)+1

    return h


# Particle.Particle(getH, 0, 10, 10)
particles = 10
swarm = Swarm.Swarm(particles, getH, -10, 10, dimensions=2)
iteration = 0
n_iterations = 500
target_error = 1e-3

target = min([getH([x, y]) for x in range(-10, 10) for y in range(-10, 10)])

print("Iteration: 0")
print("Target: {}".format(target))
print("Current Best: {}\n".format(swarm.gBest))

while iteration < n_iterations:
    swarm.runStep(0.5, 0.8, 0.9, 1)

    if (abs(swarm.gBest - target) < target_error):
        break
Exemplo n.º 25
0
Arquivo: C2.py Projeto: dqyi11/PSO_sim
@author: Walter
'''

from Swarm import *

if __name__ == '__main__':
    
    def Rosenbrock(X):
        val = 0.0
        for d in range(30-1):
            val += 100 * ( X[0,d+1] - X[0,d]**2 )**2 + (X[0,d]-1)**2
        return val
    
    bounds = []
    bests = []
    swarm = Swarm(20, 30)
    swarm.setParam(2.0, 2.0, 0.8, Rosenbrock)
    ws = []
    for i in range(30):
        ws.append([-100.0, 100.0]) 
    swarm.initParticles(ws)
    
    runPlan = [250]
    for r in runPlan:
        for t in range(r):
            swarm.update()
            #print swarm.globalbestFitness
            
            bounds.append(swarm.bound)
            bests.append(swarm.globalbestFitness)