def updateShape(self,shp):
     n=len(self.particles)/len(shp)
     m=0
     for i in range(len(shp)):
         sys=0
         if i<len(self.swarms):
             sys=self.swarms[i]
             sys.dest=shp[i]
             sys.particles=self.particles[m:n*(i+1)]
             
         else:
             parts=self.particles[m:n*(i+1)]
             col=defaultCol
             if self.singCol==False:
                 col=randC()
             W,c1,c2=self.swarms[-1].W,self.swarms[-1].c1,self.swarms[-1].c2
             self.swarms.append(swarm(n,parts,col,shp[i],W,c1,c2))
             sys=self.swarms[i]
             
         for p in sys.particles:
             p.fit=p.fitness(sys.dest)
             p.pBest=p.pos
             p.pBestFit=p.fit 
         gBest=sys.particles[randint(0,len(sys.particles)-1)]
         sys.gBestFit=gBest.fit
         sys.gBestPos=gBest.pos
         sys.updateGBest()
         m+=n
     self.nSwarms=len(shp)
Esempio n. 2
0
    def initialize_swarm(self):
        self.bittorrent_logger.log('Initializing the swarm of peers ...')

        # get the peer data from the recieved from the tracker
        peers_data = self.active_tracker.get_peers_data()

        if self.client_request['downloading'] != None:

            # create swarm instance from the list of peers
            self.swarm = swarm(peers_data, self.torrent)

        if self.client_request['seeding'] != None:
            # no need for peers recieved from tracker
            peers_data['peers'] = []
            # create swarm instance for seeding
            self.swarm = swarm(peers_data, self.torrent)
Esempio n. 3
0
 def test_islocationFree_onefalse_2(self):
     s = swarm.swarm(2, testvisualizer())
     s.getBirds()[0].getLocation().setX(30)
     s.getBirds()[0].getLocation().setY(40)
     s.getBirds()[1].getLocation().setX(60)
     s.getBirds()[1].getLocation().setY(80)
     self.assertFalse(s.isLocationFree([31,41]))
Esempio n. 4
0
 def test_killbird(self):
     t = testvisualizer()
     s = swarm.swarm(1, t)
     s.killBird()
     self.assertEqual(s.getNumberOfBirds(), 0)
     s.killBird()
     self.assertEqual(s.getNumberOfBirds(), 0)
Esempio n. 5
0
 def test_islocationFree_bothtrue(self):
     s = swarm.swarm(2, testvisualizer())
     s.getBirds()[0].getLocation().setX(30)
     s.getBirds()[0].getLocation().setY(40)
     s.getBirds()[1].getLocation().setX(60)
     s.getBirds()[1].getLocation().setY(80)
     self.assertTrue(s.isLocationFree([45,60]))
Esempio n. 6
0
 def test_islocationFree_onefalse_5(self):
     s = swarm.swarm(2, testvisualizer())
     s.getBirds()[0].getLocation().setX(30)
     s.getBirds()[0].getLocation().setY(40)
     s.getBirds()[1].getLocation().setX(60)
     s.getBirds()[1].getLocation().setY(80)
     #De afstand van kern tot kern is 7,07 en dit is groter als 2* de straal van de bird (2*3=6)
     self.assertTrue(s.isLocationFree([35,45]))
Esempio n. 7
0
def crawl(urls, datasource):
    with swarm(*urls) << 'datasource':
        for item in datasource.items():
            yield item

        for (datasource, urls) \
            in map_datasources(datasource.links(),
                               datasource.dataset).items():
            crawl(urls, datasource)
Esempio n. 8
0
def crawl(urls, datasource):
    with swarm(*urls) << 'datasource':
        for item in datasource.items():
            yield item

        for (datasource, urls) \
            in map_datasources(datasource.links(),
                               datasource.dataset).items():
            crawl(urls, datasource)
 def __init__(self,count,dest, bound,W,c1,c2):
     self.swarms=[]
     self.particles=[]
     self.nSwarms=len(dest)
     self.bound=bound
     self.singCol=True
     for i in range(self.nSwarms):
         parts=[]
         for n in range(count/self.nSwarms):
             pos=[i*30,n*30]
             temp=particle(randP(bound),dest[i],bound)
             self.particles.append(temp)
             parts.append(temp)
         self.swarms.append(swarm(count/self.nSwarms,parts,defaultCol,dest[i],W,c1,c2))
Esempio n. 10
0
    def getSwarms(self):
        """Return a list of all swarms in which this resource can participate

        @return: returns a list of swarm objects.
        """
        conn = httplib.HTTPConnection(self.apikey.server)
        conn.request("GET", "/resources/%s/swarms"%(self.id), None,
                     {"x-bugswarmapikey":self.apikey.configuration})
        resp = conn.getresponse()
        txt = resp.read()
        conn.close()
        if resp.status >= 400:
            logging.warning('Resource swarms response: ('+str(resp.status)+'): '+txt)
        else:
            logging.debug('Resource swarms response: ('+str(resp.status)+'): '+txt)
        items = json.loads(txt)
        swarms = []
        for item in items:
            resources = {}
            if (item.has_key("resources")):
                for res_data in item["resources"]:
                    #retrieve resource_type and convert it into an enum'd permission
                    permission = resource.PERM_NONE
                    if res_data.has_key("resource_type"):
                        if (res_data["resource_type"] == resource.TYPE_PRODUCER):
                            permission = resource.PERM_PRODUCER
                        elif (res_data["resource_type"] == resource.TYPE_CONSUMER):
                            permission = resource.PERM_CONSUMER
                        else:
                            logging.warning('unknown resource_type '+str(item["resource_type"])+
                                ', assuming maximum permissions')
                            permission = resource.PERM_PROSUMER
                    #If item is not already in the resources map, add it
                    if not resources.has_key(res_data["resource_id"]):
                        resources[res_data["resource_id"]] = resource(self.apikey, res_data["resource_id"],
                            res_data["name"] if res_data.has_key("name") else False,
                            res_data["description"] if res_data.has_key("description") else False,
                            res_data["created_at"] if res_data.has_key("created_at") else False,
                            permission)
                    #if item is already in the resources map, logically OR it's permissions
                    else:
                        resources[res_data["resource_id"]].permission = resources[res_data["resource_id"]].permission | permission
            swrm = swarm.swarm(self.apikey, item["id"],
                item["name"] if item.has_key("name") else False,
                item["description"] if item.has_key("description") else False,
                item["created_at"] if item.has_key("created_at") else False,
                item["public"] if item.has_key("public") else False,
                resources)
            swarms.append(swrm)
        return swarms
Esempio n. 11
0
def search(keyword, limit, start):
    #Here comes asynchronous "atom" definition.
    
    #1. Construction `with swarm(*args, **kwargs) << _:` sets everything inside of it to be launched asynchrounously
    #1. `search_keyword` function knows when all atoms are finished.
    #1. `search_keyword` function can stop process pool from launching another tasks, save that pool to disk and restore on request. Thats how pausing implemented.
    #1. `<< 'limit, keyword':` sets local namespace variables `limit` and `keyword` to be serialized and passed inside proccess (functions can be serialized too). See [codeblocks.py](http://mtomassoli.wordpress.com/2012/04/20/code-blocks-in-python/) namespace management.
    
    with swarm(ENGINE%(limit, start, keyword)) << 'limit, keyword':
        datasource = FreebaseDatasource()
        for item in datasource.items():
            yield item

        total = datasource.total_records()
        for start in [start for start in range(total)[::limit]][1:]:
            #This recursive call will schedule existing urls on each call. But because of `unique_url` signalset - there is no chance of redundancy
            
            #1. Calls to atomized function are ___not iterating over results___ but `yield`s are captured and magically pushed to outer world.
            #Thats because async atom cannot wait for other atoms to finish - that atoms will __guarnateed__ to be started after current atom and can lead to deadlock.
            #1. Synchronous function can be iterated inside of atom and that will lead to creation of another independent `Pool`. Thus if sync function called from atom - max 25 processes will be created if `CONCURRENCY` is `5`

            search(keyword, limit, start)
Esempio n. 12
0
    def __init__(self, stdscr):
        self.swarm = swarm.swarm()
        self.stdscr = stdscr
        self.stdscr.clear()
        curses.noecho()
        curses.cbreak()
        curses.curs_set(0)
        self.stdscr.keypad(True)
        self.stdscr.nodelay(True)
        curses.init_pair(1, curses.COLOR_YELLOW, curses.COLOR_BLACK)
        curses.init_pair(2, curses.COLOR_WHITE, curses.COLOR_BLACK)
        curses.init_pair(3, curses.COLOR_BLACK, curses.COLOR_WHITE)

        self.codelines = []
        self.load_file("../asm/back_forward2.asm")

        self.line_offset = 0

        self.regs = [{
            "robot": 0,
            "state": "disconnected",
            "ping": 0,
            "pc": 2,
            "usr a": 0,
            "usr b": 0,
            "comp_angle": 0,
            "comp_dr": 0,
            "comp_d": 0,
            "step_count": 0,
            "step_reset": 0
        } for i in range(0, len(self.swarm.swarm))]

        self.reg_order = [
            "robot", "state", "ping", "pc", "usr a", "usr b", "comp_angle",
            "comp_dr", "comp_d", "step_count", "step_reset"
        ]

        self.render()
Esempio n. 13
0
File: EXAMPLE.py Progetto: gcr/swarm
#!/usr/bin/env python2
# -*- coding: utf-8
from swarm import swarm, Task
import os

INPUT_VIDEOS = os.listdir("input")

swarm(
    tasks=[

        Task("convert_to_avi",
             cmdline="ffmpeg -i input/WORKUNIT -vcodec msmpeg4v2 output-WORKUNIT.avi",
             workunits=INPUT_VIDEOS),

        Task("convert_to_mp4",
             cmdline="ffmpeg -i input/WORKUNIT -vcodec mpeg4 output-WORKUNIT.mp4",
             workunits=INPUT_VIDEOS),

        Task("rip_sound",
             cmdline="ffmpeg -i input/WORKUNIT output-WORKUNIT.ogg",
             workunits=INPUT_VIDEOS),

        ]
    )
Esempio n. 14
0
def ttt():
    with swarm('http://www.elaana.com/vb/t30926') << _:
        yield PageText(transport.content, url=transport.url).winner(0.05)
Esempio n. 15
0
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see http://www.gnu.org/licenses.
#
# http://numenta.org/licenses/
# ----------------------------------------------------------------------

from os import listdir
from os.path import isfile, join
import re
import swarm

datapath = './data/'
datafiles = [ f for f in listdir(datapath) 
		if isfile(join(datapath,f)) and  re.search('^cleanTrafficData', f)]

print " Run Swarming Over ", len(datafiles), "data files"
print " This could take a long time"

for i in range(len(datafiles)):
	swarm.swarm(datapath + datafiles[i])
Esempio n. 16
0
canvas.create_line(1, 600, 600, 600, fill="red", width="5")

# obstacles visualization
for i in range(size):
    for j in range(size):
        if obstacles_map[i][j] == 1:
            canvas.create_rectangle(i - 1,
                                    j - 1,
                                    i,
                                    j,
                                    width=0,
                                    fill="green",
                                    tag="obs")
root.update()

swarm_1 = swarm.swarm(50, obstacles_map)

draw_point_of_interest(canvas)
while True:

    # draw_actors(canvas, swarm.get_swarm_map())
    draw_actors(canvas)

    # drawing
    root.update()
    # tm.sleep(0.01)  # 25 fps
    canvas.delete("actors")

    swarm_1.update_status()
# root.mainloop()
Esempio n. 17
0
 def test_getNumberOfBirds(self):
     s = swarm.swarm(1, testvisualizer())
     self.assertEqual(s.getNumberOfBirds(), 1)
Esempio n. 18
0
#!/usr/bin/env python2
# -*- coding: utf-8
from swarm import swarm, Task
import os

INPUT_VIDEOS = os.listdir("input")

swarm(tasks=[
    Task("convert_to_avi",
         cmdline=
         "ffmpeg -i input/WORKUNIT -vcodec msmpeg4v2 output-WORKUNIT.avi",
         workunits=INPUT_VIDEOS),
    Task("convert_to_mp4",
         cmdline="ffmpeg -i input/WORKUNIT -vcodec mpeg4 output-WORKUNIT.mp4",
         workunits=INPUT_VIDEOS),
    Task("rip_sound",
         cmdline="ffmpeg -i input/WORKUNIT output-WORKUNIT.ogg",
         workunits=INPUT_VIDEOS),
])
Esempio n. 19
0
 def test_getCentre_twoBirds_x(self):
     s = swarm.swarm(2, testvisualizer())
     x1 = s.getBirds()[0].getLocation().getX()
     x2 = s.getBirds()[1].getLocation().getX()
     self.assertEqual(s.getCentre().getX(), (x1+x2)/2)
Esempio n. 20
0
 def test_getBirds(self):
     s = swarm.swarm(1, testvisualizer())
     self.assertEqual(len(s.getBirds()), 1)
Esempio n. 21
0
 def test_getCentre_twoBirds_y(self):
     s = swarm.swarm(2, testvisualizer())
     bird2 = s.getBirds()[1]
     y1 = s.getBirds()[0].getLocation().getY()
     y2 = s.getBirds()[1].getLocation().getY()
     self.assertEqual(s.getCentre().getY(), (y1+y2)/2)
Esempio n. 22
0
 def test_islocationFree_true(self):
     s = swarm.swarm(1, testvisualizer())
     s.getBirds()[0].getLocation().setX(30)
     s.getBirds()[0].getLocation().setY(40)
     self.assertTrue(s.isLocationFree([300,400]))
Esempio n. 23
0
 def test_getCentre_threeBirds_x(self):
     s = swarm.swarm(3, testvisualizer())
     x1 = s.getBirds()[0].getLocation().getX()   
     x2 = s.getBirds()[1].getLocation().getX()
     x3 = s.getBirds()[2].getLocation().getX()
     self.assertEqual(s.getCentre().getX(), (x1+x2+x3)/3)
Esempio n. 24
0
 def test_addbird(self):
     s = swarm.swarm(1, testvisualizer())
     s.addBird()
     self.assertEqual(s.getNumberOfBirds(), 2)
Esempio n. 25
0
def ttt():
    with swarm('http://www.elaana.com/vb/t30926') << _:
        yield PageText(transport.content, url=transport.url).winner(0.05)
Esempio n. 26
0
 def test_getCentre_oneBird_y(self):
     s = swarm.swarm(1, testvisualizer())
     bird = s.getBirds()[0]
     y1 = bird.getLocation().getY()
     self.assertEqual(s.getCentre().getY(), y1)
Esempio n. 27
0
 def test_init(self):
     tv = testvisualizer()
     s = swarm.swarm(0,tv)
     testvogel = bird.bird(s,tv)
     self.assertTrue(testvogel.getLocation() != None)
Esempio n. 28
0
 def test_getCentre_threeBirds_y(self):
     s = swarm.swarm(3, testvisualizer())
     y1 = s.getBirds()[0].getLocation().getY()
     y2 = s.getBirds()[1].getLocation().getY()
     y3 = s.getBirds()[2].getLocation().getY()
     self.assertEqual(s.getCentre().getY(), (y1+y2+y3)/3)