spyse-commit Mailing List for Smart Python Simulation Environment
Status: Alpha
Brought to you by:
leviccampbell
You can subscribe to this list here.
2006 |
Jan
|
Feb
(432) |
Mar
(5) |
Apr
(10) |
May
(9) |
Jun
(8) |
Jul
(16) |
Aug
(11) |
Sep
(48) |
Oct
(71) |
Nov
(105) |
Dec
(10) |
---|
From: <dra...@us...> - 2006-12-18 09:59:54
|
Revision: 273 http://svn.sourceforge.net/spyse/?rev=273&view=rev Author: drapmeyer Date: 2006-12-18 01:59:53 -0800 (Mon, 18 Dec 2006) Log Message: ----------- minor updates Modified Paths: -------------- spyse/demo/DangerIsland/danger.py spyse/demo/envdemo/envdemo.py Removed Paths: ------------- spyse/demo/envdemo-back.bmp Modified: spyse/demo/DangerIsland/danger.py =================================================================== --- spyse/demo/DangerIsland/danger.py 2006-12-18 09:50:58 UTC (rev 272) +++ spyse/demo/DangerIsland/danger.py 2006-12-18 09:59:53 UTC (rev 273) @@ -167,7 +167,7 @@ env.start() # contr=env.controller self.start_agent(Robot, "Robot_0", env=env.controller, location=(522, 99), rotation= 125, speed=3) - self.start_agent(Robot, "Robot_1", env=env.controller, location=(330, 330), rotation= 130, speed=4) + self.start_agent(Robot, "Robot_1", env=env.controller, location=(296, 399), rotation= 60, speed=4) self.start_agent(Robot, "Robot_2", env=env.controller, location=(705, 394), rotation= 215, speed=3) self.start_agent(DI_GameAgent, 'Viewer', env=env.controller, size=(width, height)) wxAgent.run_GUI() Modified: spyse/demo/envdemo/envdemo.py =================================================================== --- spyse/demo/envdemo/envdemo.py 2006-12-18 09:50:58 UTC (rev 272) +++ spyse/demo/envdemo/envdemo.py 2006-12-18 09:59:53 UTC (rev 273) @@ -2,44 +2,43 @@ """ Environment Demo - The Environment Demo will show an example of how to use the distributed + The environment demo shows how to use the distributed environment model. - The following arguments can be given: - arg0: if 1 -> Create a Viewer else -> nothing - arg1: number of cars to create - arg2-5: create a segmented environment with bounds xMin=args2,xMax=args3,yMin=args4,yMax=args5 - args6: Color of the car + The following arguments can be given to the program: + arg0: If 1 -> Create a Viewer else -> nothing + arg1: The number of cars to create + arg2-5: Create an environment segment with bounds xMin=arg2, xMax=arg3, yMin=arg4, yMax=arg5 + args6: Color of the cars - Possible scenarios to start this demo: + Usage examples: - Local: - Let every Spyse instance be aware of all changes in the environment. - envdemo.py --port=9001 --distribution=broadcast-retrieve --env=local 1 5 - envdemo.py --port=9002 --distribution=broadcast-retrieve --env=local 0 5 + Local: + Make every Spyse instance be aware of every change in the environment. + envdemo.py --port=9001 --distribution=broadcast-retrieve --env=local 1 5 + envdemo.py --port=9002 --distribution=broadcast-retrieve --env=local 0 5 - Central: - Store the environment at a central place. - server, no view, 0 cars: - envdemo.py --threading=normal --port=9001 --distribution=server --env=server 0 0 - client,noview, 5 cars: - envdemo.py --threading=normal --port=9002 --distribution=client --env=client 0 5 - client,view, 0 cars: - client-view: envdemo.py --threading=normal --port=9003 --distribution=client --env=client 1 0 + Central: + Store the environment at a central place. + server, no view, 0 cars: + envdemo.py --threading=normal --port=9001 --distribution=server --env=server 0 0 + client, no view, 5 cars: + envdemo.py --threading=normal --port=9002 --distribution=client --env=client 0 5 + client, view, 0 cars: + envdemo.py --threading=normal --port=9003 --distribution=client --env=client 1 0 - Segmented(or Distributed): - Divide the environment over 2 Spyse instances - Box1 xMin: 0 xMax: 150 yMin: 0 yMax: 150 Blue Cars - envdemo.py --port=9001 --env=dist ns=start 1 5 0 150 0 150 blue - Box2 xMin: 150 xMax: 300 yMin: 0 yMax: 150 Red Cars - envdemo.py --port=9002 --env=dist ns=local 1 5 150 300 0 150 red - Box3 xMin: 0 xMax: 150 yMin: 150 yMax: 300 Yellow Cars - envdemo.py --port=9003 --env=dist ns=local 1 5 0 150 150 300 yellow - Box4 xMin: 150 xMax: 300 yMin: 150 yMax: 300 Green Cars - envdemo.py --port=9004 --env=dist ns=local 1 5 150 300 150 300 green + Segmented: + Divide the environment among multiple Spyse instances + Box1 xMin: 0 xMax: 150 yMin: 0 yMax: 150 Blue Cars + envdemo.py --port=9001 --ns=start --env=dist 1 5 0 150 0 150 blue + Box2 xMin: 150 xMax: 300 yMin: 0 yMax: 150 Red Cars + envdemo.py --port=9002 --ns=local --env=dist 1 5 150 300 0 150 red + Box3 xMin: 0 xMax: 150 yMin: 150 yMax: 300 Yellow Cars + envdemo.py --port=9003 --ns=local --env=dist 1 5 0 150 150 300 yellow + Box4 xMin: 150 xMax: 300 yMin: 150 yMax: 300 Green Cars + envdemo.py --port=9004 --ns=local --env=dist 1 5 150 300 150 300 green - Last scenario can be extended to create 4 instances which cover a box - with size 300,300. + N.B. This demo seems to work properly on Windows, but not on GNU/Linux. """ __version__ = '1.0' Deleted: spyse/demo/envdemo-back.bmp =================================================================== (Binary files differ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dra...@us...> - 2006-12-18 09:51:02
|
Revision: 272 http://svn.sourceforge.net/spyse/?rev=272&view=rev Author: drapmeyer Date: 2006-12-18 01:50:58 -0800 (Mon, 18 Dec 2006) Log Message: ----------- move envdemo into subfolder Added Paths: ----------- spyse/demo/envdemo/ spyse/demo/envdemo/box1.bat spyse/demo/envdemo/box2.bat spyse/demo/envdemo/box3.bat spyse/demo/envdemo/box4.bat spyse/demo/envdemo/envdemo-back.bmp spyse/demo/envdemo/envdemo.py Removed Paths: ------------- spyse/demo/envdemo.py Added: spyse/demo/envdemo/box1.bat =================================================================== --- spyse/demo/envdemo/box1.bat (rev 0) +++ spyse/demo/envdemo/box1.bat 2006-12-18 09:50:58 UTC (rev 272) @@ -0,0 +1,2 @@ +cd C:\workspace +python spyse\demo\distenv\envdemo.py --port=9001 --env=dist --ns=start 1 5 0 150 0 150 blue Added: spyse/demo/envdemo/box2.bat =================================================================== --- spyse/demo/envdemo/box2.bat (rev 0) +++ spyse/demo/envdemo/box2.bat 2006-12-18 09:50:58 UTC (rev 272) @@ -0,0 +1,2 @@ +cd C:\workspace +python spyse\demo\distenv\envdemo.py --port=9002 --env=dist --ns=local 1 5 150 300 0 150 red Added: spyse/demo/envdemo/box3.bat =================================================================== --- spyse/demo/envdemo/box3.bat (rev 0) +++ spyse/demo/envdemo/box3.bat 2006-12-18 09:50:58 UTC (rev 272) @@ -0,0 +1,2 @@ +cd C:\workspace +python spyse\demo\distenv\envdemo.py --port=9003 --env=dist --ns=local 1 5 0 150 150 300 yellow Added: spyse/demo/envdemo/box4.bat =================================================================== --- spyse/demo/envdemo/box4.bat (rev 0) +++ spyse/demo/envdemo/box4.bat 2006-12-18 09:50:58 UTC (rev 272) @@ -0,0 +1,2 @@ +cd C:\workspace +python spyse\demo\distenv\envdemo.py --port=9004 --env=dist --ns=local 1 5 150 300 150 300 green Added: spyse/demo/envdemo/envdemo-back.bmp =================================================================== (Binary files differ) Property changes on: spyse/demo/envdemo/envdemo-back.bmp ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: spyse/demo/envdemo/envdemo.py =================================================================== --- spyse/demo/envdemo/envdemo.py (rev 0) +++ spyse/demo/envdemo/envdemo.py 2006-12-18 09:50:58 UTC (rev 272) @@ -0,0 +1,232 @@ +#!/usr/bin/env python + +""" Environment Demo + + The Environment Demo will show an example of how to use the distributed + environment model. + + The following arguments can be given: + arg0: if 1 -> Create a Viewer else -> nothing + arg1: number of cars to create + arg2-5: create a segmented environment with bounds xMin=args2,xMax=args3,yMin=args4,yMax=args5 + args6: Color of the car + + Possible scenarios to start this demo: + + Local: + Let every Spyse instance be aware of all changes in the environment. + envdemo.py --port=9001 --distribution=broadcast-retrieve --env=local 1 5 + envdemo.py --port=9002 --distribution=broadcast-retrieve --env=local 0 5 + + Central: + Store the environment at a central place. + server, no view, 0 cars: + envdemo.py --threading=normal --port=9001 --distribution=server --env=server 0 0 + client,noview, 5 cars: + envdemo.py --threading=normal --port=9002 --distribution=client --env=client 0 5 + client,view, 0 cars: + client-view: envdemo.py --threading=normal --port=9003 --distribution=client --env=client 1 0 + + Segmented(or Distributed): + Divide the environment over 2 Spyse instances + Box1 xMin: 0 xMax: 150 yMin: 0 yMax: 150 Blue Cars + envdemo.py --port=9001 --env=dist ns=start 1 5 0 150 0 150 blue + Box2 xMin: 150 xMax: 300 yMin: 0 yMax: 150 Red Cars + envdemo.py --port=9002 --env=dist ns=local 1 5 150 300 0 150 red + Box3 xMin: 0 xMax: 150 yMin: 150 yMax: 300 Yellow Cars + envdemo.py --port=9003 --env=dist ns=local 1 5 0 150 150 300 yellow + Box4 xMin: 150 xMax: 300 yMin: 150 yMax: 300 Green Cars + envdemo.py --port=9004 --env=dist ns=local 1 5 150 300 150 300 green + + Last scenario can be extended to create 4 instances which cover a box + with size 300,300. +""" +__version__ = '1.0' + +from spyse.app.app import App +from spyse.core.semant.environment import PlaneEnvironment, DistEnvironment, DistController, Entity + +from spyse.core.agents.agent import Agent +from spyse.core.behaviours.behaviours import Behaviour +from spyse.core.platform.platform import Platform +from random import randint + +from spyse.core.agents.wxagent import wxAgent +from spyse.util import vector +import wx +import threading +import random +import time + +class Car(Agent): + """ Represents a random moving Car """ + def setup(self, env, location, color): + self.color = color + self.env = env + self.env.place(self.name, 'Car', spot=location) + self.env.set_color(self.name, self.color) + self.add_behaviour(CarBehaviour(env=self.env)) + +class CarBehaviour(Behaviour): + """ A car will choose a random location on the map, move towards it + and choose a new destination when it has reached his current one """ + def setup(self, env): + self.env = env + self.dest= None + self.route = 0 + + def get_destination(self): + while True: + destx = random.randint(0,300) + desty = random.randint(0,300) + dest = vector.Vector([destx,desty,0]) + + # check if the destination lies within the model of the segmented environment + # if the environment is segmented + if isinstance(self.env, DistController): + if self.env.in_model(dest): + return dest + else: + return dest + + + def get_destination2(self): + """ Move in a square pattern """ + if(self.route == 0): + self.route = 1 + return vector.Vector([225,50,0]) + elif(self.route == 1): + self.route = 2 + return vector.Vector([225,225,0]) + elif(self.route == 2): + self.route = 3 + return vector.Vector([50,225,0]) + elif(self.route == 3): + self.route = 0 + return vector.Vector([50,50,0]) + + def action(self): + if self.dest is None: # choose a destination if one isn't present + self.dest = self.get_destination() + + s = self.env.read(self.agent.name) # get current position + if s is None: # if this fails, sleep for a while and retry later + self.sleep(0.5) + return + + dx = self.dest.x - s.x # calculate the X distance we have to travel + if dx > 5: # move to the destination in small steps + dx = random.randint(1,5) + elif dx < -5: + dx = random.randint(-5,-1) + + dy = self.dest.y - s.y # calculate the Y distance we have to travel + if dy > 5: # move to the destination in small steps + dy = random.randint(1,5) + elif dy < -5: + dy = random.randint(-5,-1) + + x = s.x+dx # calculate new x + y = s.y+dy # and y position + + if dx == 0 and dy == 0: # if we are at our destination, pick a new one + self.dest = self.get_destination() + + self.env.move(self.agent.name, x=x, y=y) # move the agent + self.sleep(0.15) # sleep + +#--------------------------------------------------------------------------------- + +class DrawEnvironmentBehaviour(Behaviour): + """ Draws the moving cars """ + def setup(self, view, size): + self.view = view + self.size = size + self.dc = None + + def action(self): + if not self.dc: + self.dc = wx.ClientDC(self.agent.frame.window) + bmp = wx.Image('spyse/demo/distenv/envdemo-back.bmp', wx.BITMAP_TYPE_BMP).ConvertToBitmap() + + pen = wx.Pen('white') + brush = wx.Brush('white') + self.dc.SetPen(pen) + self.dc.SetBrush(brush) + self.dc.DrawRectangle(0, 0, self.size[0], self.size[1]) + self.dc.DrawBitmap(bmp,-self.agent.offset[0],-self.agent.offset[1]) + + entities = self.view.entities() + for e in entities: + self.dc.SetBrush(brush) + if isinstance(e, Entity) and e.type == 'Car': + self.drawCar(e) + self.sleep(0.15) + + def drawCar(self, e): + pen = wx.Pen(e.color) + pen.SetWidth(3) + self.dc.SetPen(pen) + self.dc.DrawCircle(e.x-self.agent.offset[0], e.y-self.agent.offset[1], 5) + +class ViewerAgent(wxAgent): + """ViewerAgent will draw the cars, if the environment is segmented + the offset will be the upperleft coordinate for the box which + will be drawn by this agent. """ + def setup(self, view, size, offset): + super(ViewerAgent, self).setup((size[0]+8, size[1]+27)) + self.__view = view + self.__size = size + self.offset = offset + self.add_behaviour(DrawEnvironmentBehaviour(view=self.__view, size=self.__size)) + self.frame.SetPosition((self.offset[0],self.offset[1])) + self.frame.closed = self.closed + + def closed(self): + Platform.shutdown() + + + +#--------------------------------------------------------------------------------- + +# Application + +class MyApp(App): + def run(self, args): + width=500 + height=500 + offset=(0,0) + + if len(args) > 5: # segmented environment + x_mina=int(args[2]) + x_maxa=int(args[3]) + y_mina=int(args[4]) + y_maxa=int(args[5]) + offset = (x_mina,y_mina) + e = DistEnvironment(x_min=x_mina, x_max=x_maxa, y_min=y_mina, y_max=y_maxa) + width = x_maxa-x_mina + height = y_maxa-y_mina + carloc = [x_mina+(x_maxa-x_mina)/2,y_mina+(y_maxa-y_mina)/2, 0] + else: # Plane Environment + e = PlaneEnvironment(x_min=0, x_max=width, y_min=0, y_max=height) + carloc = [300,300,0] + ec = e.controller + ev = e.view + + car_color='red' + if len(args) > 6: + car_color = args[6] + + if len(args) >0 and args[0] == '1': + self.start_agent(ViewerAgent, 'Viewer', view=ev, size=[width, height], offset=offset) + + if len(args) >1: + amount = int(args[1]) + for i in range(amount): + self.start_agent(Car, 'Car-'+str(random.randint(0, 1000000)), env=ec, location=carloc, color=car_color) + + wxAgent.run_GUI() + + +if __name__ == "__main__": + MyApp() Deleted: spyse/demo/envdemo.py =================================================================== --- spyse/demo/envdemo.py 2006-12-14 11:20:38 UTC (rev 271) +++ spyse/demo/envdemo.py 2006-12-18 09:50:58 UTC (rev 272) @@ -1,231 +0,0 @@ -#!/usr/bin/env python - -""" Environment Demo - - The environment demo shows how to use the distributed - environment model. - - The following arguments can be given to the program: - arg0: If 1 -> Create a Viewer else -> nothing - arg1: The number of cars to create - arg2-5: Create an environment segment with bounds xMin=arg2, xMax=arg3, yMin=arg4, yMax=arg5 - args6: Color of the cars - - Usage examples: - - Local: - Make every Spyse instance be aware of every change in the environment. - envdemo.py --port=9001 --distribution=broadcast-retrieve --env=local 1 5 - envdemo.py --port=9002 --distribution=broadcast-retrieve --env=local 0 5 - - Central: - Store the environment at a central place. - server, no view, 0 cars: - envdemo.py --threading=normal --port=9001 --distribution=server --env=server 0 0 - client, no view, 5 cars: - envdemo.py --threading=normal --port=9002 --distribution=client --env=client 0 5 - client, view, 0 cars: - envdemo.py --threading=normal --port=9003 --distribution=client --env=client 1 0 - - Segmented: - Divide the environment among multiple Spyse instances - Box1 xMin: 0 xMax: 150 yMin: 0 yMax: 150 Blue Cars - envdemo.py --port=9001 --ns=start --env=dist 1 5 0 150 0 150 blue - Box2 xMin: 150 xMax: 300 yMin: 0 yMax: 150 Red Cars - envdemo.py --port=9002 --ns=local --env=dist 1 5 150 300 0 150 red - Box3 xMin: 0 xMax: 150 yMin: 150 yMax: 300 Yellow Cars - envdemo.py --port=9003 --ns=local --env=dist 1 5 0 150 150 300 yellow - Box4 xMin: 150 xMax: 300 yMin: 150 yMax: 300 Green Cars - envdemo.py --port=9004 --ns=local --env=dist 1 5 150 300 150 300 green - - N.B. This demo seems to work properly on Windows, but not on GNU/Linux. -""" -__version__ = '1.0' - -from spyse.app.app import App -from spyse.core.semant.environment import PlaneEnvironment, DistEnvironment, DistController, Entity - -from spyse.core.agents.agent import Agent -from spyse.core.behaviours.behaviours import Behaviour -from spyse.core.platform.platform import Platform -from random import randint - -from spyse.core.agents.wxagent import wxAgent -from spyse.util import vector -import wx -import threading -import random -import time - -class Car(Agent): - """ Represents a random moving Car """ - def setup(self, env, location, color): - self.color = color - self.env = env - self.env.place(self.name, 'Car', spot=location) - self.env.set_color(self.name, self.color) - self.add_behaviour(CarBehaviour(env=self.env)) - -class CarBehaviour(Behaviour): - """ A car will choose a random location on the map, move towards it - and choose a new destination when it has reached his current one """ - def setup(self, env): - self.env = env - self.dest= None - self.route = 0 - - def get_destination(self): - while True: - destx = random.randint(0,300) - desty = random.randint(0,300) - dest = vector.Vector([destx,desty,0]) - - # check if the destination lies within the model of the segmented environment - # if the environment is segmented - if isinstance(self.env, DistController): - if self.env.in_model(dest): - return dest - else: - return dest - - - def get_destination2(self): - """ Move in a square pattern """ - if(self.route == 0): - self.route = 1 - return vector.Vector([225,50,0]) - elif(self.route == 1): - self.route = 2 - return vector.Vector([225,225,0]) - elif(self.route == 2): - self.route = 3 - return vector.Vector([50,225,0]) - elif(self.route == 3): - self.route = 0 - return vector.Vector([50,50,0]) - - def action(self): - if self.dest is None: # choose a destination if one isn't present - self.dest = self.get_destination() - - s = self.env.read(self.agent.name) # get current position - if s is None: # if this fails, sleep for a while and retry later - self.sleep(0.5) - return - - dx = self.dest.x - s.x # calculate the X distance we have to travel - if dx > 5: # move to the destination in small steps - dx = random.randint(1,5) - elif dx < -5: - dx = random.randint(-5,-1) - - dy = self.dest.y - s.y # calculate the Y distance we have to travel - if dy > 5: # move to the destination in small steps - dy = random.randint(1,5) - elif dy < -5: - dy = random.randint(-5,-1) - - x = s.x+dx # calculate new x - y = s.y+dy # and y position - - if dx == 0 and dy == 0: # if we are at our destination, pick a new one - self.dest = self.get_destination() - - self.env.move(self.agent.name, x=x, y=y) # move the agent - self.sleep(0.15) # sleep - -#--------------------------------------------------------------------------------- - -class DrawEnvironmentBehaviour(Behaviour): - """ Draws the moving cars """ - def setup(self, view, size): - self.view = view - self.size = size - self.dc = None - - def action(self): - if not self.dc: - self.dc = wx.ClientDC(self.agent.frame.window) - bmp = wx.Image('envdemo-back.bmp', wx.BITMAP_TYPE_BMP).ConvertToBitmap() - - pen = wx.Pen('white') - brush = wx.Brush('white') - self.dc.SetPen(pen) - self.dc.SetBrush(brush) - self.dc.DrawRectangle(0, 0, self.size[0], self.size[1]) - self.dc.DrawBitmap(bmp,-self.agent.offset[0],-self.agent.offset[1]) - - entities = self.view.entities() - for e in entities: - self.dc.SetBrush(brush) - if isinstance(e, Entity) and e.type == 'Car': - self.drawCar(e) - self.sleep(0.15) - - def drawCar(self, e): - pen = wx.Pen(e.color) - pen.SetWidth(3) - self.dc.SetPen(pen) - self.dc.DrawCircle(e.x-self.agent.offset[0], e.y-self.agent.offset[1], 5) - -class ViewerAgent(wxAgent): - """ViewerAgent will draw the cars, if the environment is segmented - the offset will be the upperleft coordinate for the box which - will be drawn by this agent. """ - def setup(self, view, size, offset): - super(ViewerAgent, self).setup((size[0]+8, size[1]+27)) - self.__view = view - self.__size = size - self.offset = offset - self.add_behaviour(DrawEnvironmentBehaviour(view=self.__view, size=self.__size)) - self.frame.SetPosition((self.offset[0],self.offset[1])) - self.frame.closed = self.closed - - def closed(self): - Platform.shutdown() - - - -#--------------------------------------------------------------------------------- - -# Application - -class MyApp(App): - def run(self, args): - width=500 - height=500 - offset=(0,0) - - if len(args) > 5: # segmented environment - x_mina=int(args[2]) - x_maxa=int(args[3]) - y_mina=int(args[4]) - y_maxa=int(args[5]) - offset = (x_mina,y_mina) - e = DistEnvironment(x_min=x_mina, x_max=x_maxa, y_min=y_mina, y_max=y_maxa) - width = x_maxa-x_mina - height = y_maxa-y_mina - carloc = [x_mina+(x_maxa-x_mina)/2,y_mina+(y_maxa-y_mina)/2, 0] - else: # Plane Environment - e = PlaneEnvironment(x_min=0, x_max=width, y_min=0, y_max=height) - carloc = [300,300,0] - ec = e.controller - ev = e.view - - car_color='red' - if len(args) > 6: - car_color = args[6] - - if len(args) >0 and args[0] == '1': - self.start_agent(ViewerAgent, 'Viewer', view=ev, size=[width, height], offset=offset) - - if len(args) >1: - amount = int(args[1]) - for i in range(amount): - self.start_agent(Car, 'Car-'+str(random.randint(0, 1000000)), env=ec, location=carloc, color=car_color) - - wxAgent.run_GUI() - - -if __name__ == "__main__": - MyApp() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dra...@us...> - 2006-12-14 11:20:39
|
Revision: 271 http://svn.sourceforge.net/spyse/?rev=271&view=rev Author: drapmeyer Date: 2006-12-14 03:20:38 -0800 (Thu, 14 Dec 2006) Log Message: ----------- use Tkinter grid manager for a nicer user interface Modified Paths: -------------- spyse/demo/bookbuying.py Modified: spyse/demo/bookbuying.py =================================================================== --- spyse/demo/bookbuying.py 2006-12-14 09:51:16 UTC (rev 270) +++ spyse/demo/bookbuying.py 2006-12-14 11:20:38 UTC (rev 271) @@ -125,20 +125,23 @@ self.add_behaviour(sq) def create_widgets(self, frame): - frame.title(self.name + " - Buy a Book") + frame.title(self.shortname + " - Buy a Book") title_label = Label(frame) title_label["text"] = "Title" - title_label.pack() + title_label.grid(row=0, column=0, padx=5, pady=5) +# title_label.pack() #self.book_title = StringVar() #self.book_title.set("Multi-Agent Systems") # this doesn't work, a bug in Tkinter? - self.title_entry = Entry(frame, width=20, background='white')#, textvariable=self.book_title) - self.title_entry.pack() + self.title_entry = Entry(frame, width=40, background='white')#, textvariable=self.book_title) + self.title_entry.grid(row=0, column=1, padx=5, pady=5) +# self.title_entry.pack() button1 = Button(frame, command=self.buy_book) button1["text"]="Buy" - button1.pack() + button1.grid(row=0, column=2, padx=5, pady=5) +# button1.pack() class RegisterServiceBehaviour(SendBehaviour): def setup(self, service): @@ -200,24 +203,30 @@ print self.name, "selling book", self.__library def create_widgets(self, frame): - frame.title(self.name + " - Sell a Book") + frame.title(self.shortname + " - Sell a Book") + title_label = Label(frame) + title_label.grid(row=0, column=0, padx=5, pady=5) title_label["text"]="Title" - title_label.pack() - - self.book_title = Entry(frame, width=20, background='white') - self.book_title.pack() - +# title_label.pack(padx=5, pady=5) + + self.book_title = Entry(frame, width=40, background='white') + self.book_title.grid(row=0, column=1, padx=5, pady=5) +# self.book_title.pack(padx=5, pady=5) + price_label = Label(frame) + price_label.grid(row=1, column=0, padx=5, pady=5) price_label["text"]="Price" - price_label.pack() - - self.book_price = Entry(frame, width=20, background='white') - self.book_price.pack() - +# price_label.pack(padx=5, pady=5) + + self.book_price = Entry(frame, width=40, background='white') + self.book_price.grid(row=1, column=1, padx=5, pady=5) +# self.book_price.pack(padx=5, pady=5) + button1 = Button(frame, command=self.sell_book) + button1.grid(row=0, column=2, rowspan=2, padx=5, pady=5) button1["text"]="Sell" - button1.pack() +# button1.pack(padx=5, pady=5) class MyApp(App): def run(self, args): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dra...@us...> - 2006-12-14 09:51:18
|
Revision: 270 http://svn.sourceforge.net/spyse/?rev=270&view=rev Author: drapmeyer Date: 2006-12-14 01:51:16 -0800 (Thu, 14 Dec 2006) Log Message: ----------- fixed bug with adding new books Modified Paths: -------------- spyse/demo/bookbuying.py Modified: spyse/demo/bookbuying.py =================================================================== --- spyse/demo/bookbuying.py 2006-12-11 14:46:28 UTC (rev 269) +++ spyse/demo/bookbuying.py 2006-12-14 09:51:16 UTC (rev 270) @@ -194,7 +194,7 @@ return result def sell_book(self): - self.__library[self.book_title.get()] = self.book_price.get() + self.__library[self.book_title.get()] = int(self.book_price.get()) self.book_title.delete(0,END) self.book_price.delete(0,END) print self.name, "selling book", self.__library This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jd...@us...> - 2006-12-11 14:46:33
|
Revision: 269 http://svn.sourceforge.net/spyse/?rev=269&view=rev Author: jdthood Date: 2006-12-11 06:46:28 -0800 (Mon, 11 Dec 2006) Log Message: ----------- Fix up docstring Modified Paths: -------------- spyse/demo/envdemo.py Modified: spyse/demo/envdemo.py =================================================================== --- spyse/demo/envdemo.py 2006-12-05 17:33:59 UTC (rev 268) +++ spyse/demo/envdemo.py 2006-12-11 14:46:28 UTC (rev 269) @@ -2,44 +2,43 @@ """ Environment Demo - The Environment Demo will show an example of how to use the distributed + The environment demo shows how to use the distributed environment model. - The following arguments can be given: - arg0: if 1 -> Create a Viewer else -> nothing - arg1: number of cars to create - arg2-5: create a segmented environment with bounds xMin=args2,xMax=args3,yMin=args4,yMax=args5 - args6: Color of the car + The following arguments can be given to the program: + arg0: If 1 -> Create a Viewer else -> nothing + arg1: The number of cars to create + arg2-5: Create an environment segment with bounds xMin=arg2, xMax=arg3, yMin=arg4, yMax=arg5 + args6: Color of the cars - Possible scenarios to start this demo: + Usage examples: - Local: - Let every Spyse instance be aware of all changes in the environment. - envdemo.py --port=9001 --distribution=broadcast-retrieve --env=local 1 5 - envdemo.py --port=9002 --distribution=broadcast-retrieve --env=local 0 5 + Local: + Make every Spyse instance be aware of every change in the environment. + envdemo.py --port=9001 --distribution=broadcast-retrieve --env=local 1 5 + envdemo.py --port=9002 --distribution=broadcast-retrieve --env=local 0 5 - Central: - Store the environment at a central place. - server, no view, 0 cars: - envdemo.py --threading=normal --port=9001 --distribution=server --env=server 0 0 - client,noview, 5 cars: - envdemo.py --threading=normal --port=9002 --distribution=client --env=client 0 5 - client,view, 0 cars: - client-view: envdemo.py --threading=normal --port=9003 --distribution=client --env=client 1 0 + Central: + Store the environment at a central place. + server, no view, 0 cars: + envdemo.py --threading=normal --port=9001 --distribution=server --env=server 0 0 + client, no view, 5 cars: + envdemo.py --threading=normal --port=9002 --distribution=client --env=client 0 5 + client, view, 0 cars: + envdemo.py --threading=normal --port=9003 --distribution=client --env=client 1 0 - Segmented(or Distributed): - Divide the environment over 2 Spyse instances - Box1 xMin: 0 xMax: 150 yMin: 0 yMax: 150 Blue Cars - envdemo.py --port=9001 --ns=start --env=dist 1 5 0 150 0 150 blue - Box2 xMin: 150 xMax: 300 yMin: 0 yMax: 150 Red Cars - envdemo.py --port=9002 --ns=local --env=dist 1 5 150 300 0 150 red - Box3 xMin: 0 xMax: 150 yMin: 150 yMax: 300 Yellow Cars - envdemo.py --port=9003 --ns=local --env=dist 1 5 0 150 150 300 yellow - Box4 xMin: 150 xMax: 300 yMin: 150 yMax: 300 Green Cars - envdemo.py --port=9004 --ns=local --env=dist 1 5 150 300 150 300 green - - Last scenario can be extended to create 4 instances which cover a box - with size 300,300. + Segmented: + Divide the environment among multiple Spyse instances + Box1 xMin: 0 xMax: 150 yMin: 0 yMax: 150 Blue Cars + envdemo.py --port=9001 --ns=start --env=dist 1 5 0 150 0 150 blue + Box2 xMin: 150 xMax: 300 yMin: 0 yMax: 150 Red Cars + envdemo.py --port=9002 --ns=local --env=dist 1 5 150 300 0 150 red + Box3 xMin: 0 xMax: 150 yMin: 150 yMax: 300 Yellow Cars + envdemo.py --port=9003 --ns=local --env=dist 1 5 0 150 150 300 yellow + Box4 xMin: 150 xMax: 300 yMin: 150 yMax: 300 Green Cars + envdemo.py --port=9004 --ns=local --env=dist 1 5 150 300 150 300 green + + N.B. This demo seems to work properly on Windows, but not on GNU/Linux. """ __version__ = '1.0' This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dra...@us...> - 2006-12-05 17:34:04
|
Revision: 268 http://svn.sourceforge.net/spyse/?rev=268&view=rev Author: drapmeyer Date: 2006-12-05 09:33:59 -0800 (Tue, 05 Dec 2006) Log Message: ----------- update on Danger Island Modified Paths: -------------- spyse/util/trig.py Modified: spyse/util/trig.py =================================================================== --- spyse/util/trig.py 2006-12-05 17:28:45 UTC (rev 267) +++ spyse/util/trig.py 2006-12-05 17:33:59 UTC (rev 268) @@ -5,3 +5,8 @@ def rad2deg(r): return r*180/math.pi + +def sign(x): + if x < 0: return -1 + elif x > 0: return 1 + else: return 0 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dra...@us...> - 2006-12-05 17:29:03
|
Revision: 267 http://svn.sourceforge.net/spyse/?rev=267&view=rev Author: drapmeyer Date: 2006-12-05 09:28:45 -0800 (Tue, 05 Dec 2006) Log Message: ----------- update on Danger Island Modified Paths: -------------- spyse/asw/environment.py spyse/demo/DangerIsland/danger.py spyse/demo/DangerIsland/danger_env.py spyse/demo/DangerIsland/danger_gui.py Added Paths: ----------- spyse/demo/DangerIsland/Taste_env.py spyse/demo/DangerIsland/images/borkum_plain_1200x900_2.png spyse/demo/DangerIsland/roads.txt spyse/demo/DangerIsland/roads_trash.txt Modified: spyse/asw/environment.py =================================================================== --- spyse/asw/environment.py 2006-12-05 17:17:32 UTC (rev 266) +++ spyse/asw/environment.py 2006-12-05 17:28:45 UTC (rev 267) @@ -64,6 +64,10 @@ def __init__(self, model): self._model = model self.start_time=time.time() + self.setup() + + def setup(self): + pass # return a list of all key,value pairs of which value[label]==labelvalue def find_items(self,label,labelvalue): @@ -299,7 +303,7 @@ return [] return [i for i in values if self.__inside(circle, i, label)] - + def inview(self, key, type=None): # neighbours in heading direction @@ -435,10 +439,11 @@ if e['label'] == type: self.objects[entity] = e return self.objects + #@singleton class Environment(threading.Thread): def __init__(self, condition, **kwargs): -# super(self.__class__, self).__init__() + #super(self.__class__, self).__init__() super(Environment, self).__init__() self.condition = condition # a function that defines how long to run, should return Boolean @@ -446,30 +451,35 @@ for a, v in kwargs.items(): setattr(self, a, v) + self.updateProcs = [] + self.set_model() + self.set_controller() + self.setup() + + # override this to set up an environment + def setup(self): + pass + + # override this to select a model + def set_model(self): self.model = None + + # override this to select a controller + def set_controller(self): self.controller = None def run(self): - pass + while self.condition(): + for p in self.updateProcs: p() + time.sleep(0.05) class Environment2D(Environment): def __init__(self, condition, **kwargs): super(Environment2D, self).__init__(condition, **kwargs) + + def set_model(self): self.model = Model() - self.updateProcs=[] - self.selectController() - self.setup() - - # override this to register model update procedures - def setup(self): - pass - - # override this to select an alternative controller - def selectController(self): + + def set_controller(self): self.controller = Controller2D(self.model) - - def run(self): - while self.condition(): - for p in self.updateProcs: p() - time.sleep(0.01) Added: spyse/demo/DangerIsland/Taste_env.py =================================================================== --- spyse/demo/DangerIsland/Taste_env.py (rev 0) +++ spyse/demo/DangerIsland/Taste_env.py 2006-12-05 17:28:45 UTC (rev 267) @@ -0,0 +1,155 @@ +import math +import os +from spyse.asw.environment import Controller2D, Environment2D +from roads import * +import wx + +#rootdir='c:/Documents and Settings/ruizenaarmga/My Documents/LopendeProjecten/TASTE/Resource' +rootdir='c:/spyse1_0/spyse/demo/Taste_Demo' + +class TasteController(Controller2D): + + def __init__(self, *formalargs, **namedargs): + self.TimeScaleFactor=1 + Controller2D.__init__(self, *formalargs, **namedargs) + + def time(self): + return Controller2D.time(self)*self.TimeScaleFactor + + # bepaal de afstand tussen twee punten + # hemelsbreed of via de weg + def Distance(self, Pos1, Pos2, type='ViaRoad'): + From=self.IsOnRoad(Pos1) + To=self.IsOnRoad(Pos2) + S=From[2] + return S.findBestRoute(self.roadMap,S.beginloc,S.endloc,From,To) + + # geef aan of positie pos op een weg ligt en geef segmentnaam terug + # name=None: positie niet op een wegsegment + def IsOnRoad(self, pos): + name=None; min=20; projloc=pos; Smin=None + for S in self.roadMap: + found, d, proj=S.OnSegment(pos) + if not found: continue + if d<min: + name=S.name; min=d; projloc=proj; Smin=S + return (name, projloc, Smin) + +class Object: + def __init__(self): + self.time=[]; self.posx=[]; self.posy=[] + self.ti=0; self. size=0 + + def append(self, t,posx,posy): + self.time.append(float(t)); self.posx.append(float(posx)); self.posy.append(float(posy)) + self.size+=1 + + def GetCurrentPos(self, t): + N=self.size + if N<1: return (0, 0) + if N==1: return (self.posx[0], self.posy[0]) + while t>self.time[self.ti+1]: + if self.ti+1<N: + self.ti+=1 + else: + return (self.posx[ti+1], self.posy[ti+1]) + r=(t-self.time[self.ti])/(self.time[self.ti+1]-self.time[self.ti]) + dx=self.posx[self.ti+1]-self.posx[self.ti] + dy=self.posy[self.ti+1]-self.posy[self.ti] + return (self.posx[self.ti]+r*dx, self.posy[self.ti]+r*dy) + +class TasteEnvironment(Environment2D): + + def selectController(self): + self.controller = TasteController(self.model) + + def setup(self): + self.loadSensors() + self.SetupSensorEvents() + self.loadObjects() + self.loadRoadmap() + self.updateProcs.append(self.updateSensors) + self.updateProcs.append(self.updateObjects) + + def loadSensors(self): + # open file and read sensor info + S=open(rootdir+'/Trebos/SensorSpec.txt') + for line in S: + name, posx, posy, type=line.split() + self.controller.place(name, label="Sensor", location=(float(posx),float(posy)), type=type, status=0) + S.close() + self.SensorDetect=wx.Sound(rootdir+'/sounds/online.wav') + + def SetupSensorEvents(self): + self.TimeOfEvents = []; self.EventIDs=[] + f=open(rootdir+'/Trebos/EventList.txt') + for line in f: + [tstr, IDstr]=line.split() + self.TimeOfEvents.append(float(tstr)) + self.EventIDs.append('sensor'+IDstr) + f.close() + self.NextEvent=0 + + def loadObjects(self): + self.objects = {} + filelist=os.listdir(rootdir+'/Trebos/') + for fname in filelist: + fname=fname.upper() + i=fname.find('.') + if (i>6) and (fname[0:6]=='OBJECT'): + # open file and read object trajectory + f=open(rootdir+'/Trebos/'+fname) + line=f.readline(); elements=line.split(); type=elements[0] + name=fname[0:i] + O=Object(); self.objects[name]=O + for line in f: + (t, posx, posy)=line.split() + O.append(t,posx,posy) + f.close() + self.controller.place(name, label="Object", location=(O.posx[0],O.posy[0]), type=type) + + def loadRoadmap(self): + f=open(rootdir+'/Trebos/Tetovo_Roads.txt') + i=0; self.controller.roadMap=[] + for line in f: + [x1, y1, x2, y2]=line.split() + name='RoadSegment'+str(i) + beginloc=(int(float(x1)), int(float(y1))) + endloc=(int(float(x2)), int(float(y2))) + self.controller.place(name, label="Road", location=beginloc, endloc=endloc) + self.controller.roadMap.append(RoadSegment(name,beginloc,endloc)) + i+=1 + f.close() + + def GetSensorEvents(self,time): + EventList=set() + N=len(self.EventIDs); idx=self.NextEvent + while (idx<N) and (time>=self.TimeOfEvents[idx]): + if (time<self.TimeOfEvents[idx]+2): + EventList.add(self.EventIDs[idx]) + else: + self.NextEvent+=1 + idx+=1 + return EventList + + def updateSensors(self): + t=self.controller.time() + ID_list=self.GetSensorEvents(t) + for key, value in self.controller.find_items('label','Sensor'): + e = self.controller.read(key) + old_status=e['status'] + new_status=(key in ID_list) + if old_status!=new_status: + # geef een geluidsignaal dat een detectie is gedaan + #if status: self.SensorDetect.Play(wx.SOUND_ASYNC) + e['status']=new_status + self.controller.write(key, e) + + def updateObjects(self): + t=self.controller.time() + for key in self.objects: + O=self.objects[key] + e = self.controller.read(key) + e['location']=O.GetCurrentPos(t) + self.controller.write(key, e) + Modified: spyse/demo/DangerIsland/danger.py =================================================================== --- spyse/demo/DangerIsland/danger.py 2006-12-05 17:17:32 UTC (rev 266) +++ spyse/demo/DangerIsland/danger.py 2006-12-05 17:28:45 UTC (rev 267) @@ -30,19 +30,79 @@ def setup(self, env, location, rotation, speed): self.env = env self.env.place(self.name, label=self.__class__.__name__, location=location, rotation=rotation, speed=speed) - self.add_behaviour(RobotBehaviour(period=1, env=self.env)) + self.add_behaviour(RobotBehaviour(period=2, env=self.env)) class RobotBehaviour(TickerBehaviour): def setup(self, env): print "RobotBehaviour.setup" self.env = env - self.da = 12 + self.roadmap = self.env.read('Roadmap') +# self.da = 12 self.last_sensor = None - + self.current_road = None # ('Node_00', 'Node_01') # TODO: = None + def on_tick(self): + print datetime.now() self.body = self.env.read(self.agent.name) self.x, self.y = self.body['location'] + nodes = self.roadmap['nodes'] + delta = 10 + # if close to end of road segment +# if self.current_road is not None: print self.env.distance(self.agent.name, nodes[self.current_road[1]]) + if self.current_road is None or self.env.distance(self.agent.name, nodes[self.current_road[1]]) < delta: + print "checking" + # look for the closest next destination of a road segment in current direction + current_origin, current_destination = self.current_road if self.current_road is not None else (None, None) + roads = self.env.on_road(self.agent.name) + print roads + print current_origin, current_destination + + # select next road segment to travel + next_roads = [] + return_road = None + for r in roads: +# print ">>> 0" + # road that returns to origin of current segment + if r[1] == current_origin: + print ">>> 1" + return_road = r + # roads originating from current destination + elif r[0] == current_destination or current_destination is None: + print ">>> 2" + next_roads.append(r) + + nr_options = len(next_roads) + print "nr_options", nr_options + # if no adjacent road found, try to return + if nr_options == 0: + print ">>> 3" + self.current_road = return_road + # if exactly one adjacent road found, take that one + elif nr_options == 1: + print ">>> 4" + self.current_road = next_roads[0] + # if multiple adjacent roads found, consult a sensor, + # otherwise choose best match with current direction + elif nr_options > 1: + print ">>> 5" + self.current_road = self.check_sensors() + if self.current_road is None: + self.current_road = random.choice(next_roads) + # otherwise, move on and try finding roads later on + else: + print ">>> 6" + self.current_road = None + + if self.current_road is not None: + dx = nodes[self.current_road[1]][0]-self.x + dy = nodes[self.current_road[1]][1]-self.y + + if (dx != 0.0 and dy != 0.0): + rot = rad2deg(math.atan2(dy, dx)) - self.body['rotation'] + self.env.turn(self.agent.name, rot) + + def check_sensors(self): # check whether a sensor is close that has not been used, yet sensors = self.env.neighbours(self.agent.name, label='sensor') print "sensors", len(sensors) @@ -56,9 +116,17 @@ # print (dx, dy), math.sqrt(dx*dx + dy*dy) if math.sqrt(dx*dx + dy*dy) < 10: self.last_sensor = s['name'] + return self.roadmap['edges'][s['direction']] + else: + return None + else: + return None + else: + return None # print s['direction']-self.body['rotation'] - self.env.turn(self.agent.name, s['direction']-self.body['rotation']) - +# self.env.turn(self.agent.name, s['direction']-self.body['rotation']) + + def find_neighbours(self): # sense environment and select road cells cells = self.env.neighbours(self.agent.name, label='cell') # print len(cells) @@ -98,9 +166,9 @@ env = DI_Environment(condition=Platform.is_running, x_min=0, x_max=width, y_min=0, y_max=height) env.start() # contr=env.controller - self.start_agent(Robot, "Robot_0", env=env.controller, location=(512, 112), rotation= 125, speed=3) -# self.start_agent(Robot, "Robot_1", env=env.controller, location=(320, 446), rotation= 250, speed=5) -# self.start_agent(Robot, "Robot_2", env=env.controller, location=(30, 300), rotation= 30, speed=10) + self.start_agent(Robot, "Robot_0", env=env.controller, location=(522, 99), rotation= 125, speed=3) + self.start_agent(Robot, "Robot_1", env=env.controller, location=(330, 330), rotation= 130, speed=4) + self.start_agent(Robot, "Robot_2", env=env.controller, location=(705, 394), rotation= 215, speed=3) self.start_agent(DI_GameAgent, 'Viewer', env=env.controller, size=(width, height)) wxAgent.run_GUI() Modified: spyse/demo/DangerIsland/danger_env.py =================================================================== --- spyse/demo/DangerIsland/danger_env.py 2006-12-05 17:17:32 UTC (rev 266) +++ spyse/demo/DangerIsland/danger_env.py 2006-12-05 17:28:45 UTC (rev 267) @@ -1,4 +1,5 @@ -from spyse.asw.environment import Environment2D +from spyse.asw.environment import Environment2D, Controller2D +from sys import maxint import time import math import wx @@ -6,11 +7,11 @@ TYPES = { # type: (red, green, blue) - 'city': (255, 0, 0), - 'grass': ( 0, 255, 0), - 'sea': ( 0, 0, 255), - 'sand': (255, 255, 255), - 'airport': (127, 127, 127), + 'city': (255, 0, 0), + 'grass': ( 0, 255, 0), + 'sea': ( 0, 0, 255), + 'sand': (255, 255, 255), + 'airport': (127, 127, 127), 'road': ( 0, 0, 0) } @@ -19,17 +20,19 @@ def setup(self): self.xChart=1000.0; self.yChart=800.0 - self.make_cells() - #self.make_roads() + #self.make_cells() + self.make_roads() self.make_sensors() self.updateProcs.append(self.moveRobots) - self.updateProcs.append(self.update_cells) + #self.updateProcs.append(self.update_cells) self.updateProcs.append(self.update_sensors) + def set_controller(self): + self.controller = DI_Controller(self.model) # model for updating robot positions in environment def moveRobots(self): # print "move_robots" - for key, value in self.controller.find_items('label','Robot'): + for key, value in self.controller.find_items('label', 'Robot'): v = value['speed'] a = value['rotation']*(math.pi/180) x_old, y_old = value['location'] @@ -46,7 +49,7 @@ def update_sensors(self): pass - def bitmap2world(self, (xb,yb)): + def bitmap2world(self, (xb, yb)): return (xw, yw) def colour2type(self, r, g, b): @@ -88,39 +91,94 @@ xi = xi+1 def make_roads(self): - f=open('roads.txt') - i=0; self.controller.roadMap=[] - for line in f: - [x1, y1, x2, y2]=line.split() - name='RoadSegment'+str(i) - beginloc=(int(float(x1)), int(float(y1))) - endloc=(int(float(x2)), int(float(y2))) - self.controller.place(name, label="Road", location=beginloc, endloc=endloc) - self.controller.roadMap.append(RoadSegment(name,beginloc,endloc)) - i+=1 +# f=open('spyse/demo/DangerIsland/roads.txt') +# for i, line in enumerate(f): +# x1, y1, x2, y2 = line.split() +# name='RoadSegment_' + str(i) +# beginloc=(int(float(x1)), int(float(y1))) +# endloc=(int(float(x2)), int(float(y2))) +# #print name, beginloc, endloc +# self.controller.place(name, label="road", name=name, begin=beginloc, end=endloc) +# f.close() + f=open('spyse/demo/DangerIsland/roads.txt') + nodes = {} + edges = {} + for i, line in enumerate(f): + name, x, y = line.split() + if name.startswith('Node'): + nodes[name] = (int(float(x)), int(float((y)))) + elif name.startswith('Edge'): + edges[name] = (x, y) f.close() + self.controller.place("Roadmap", label="roadmap", nodes=nodes, edges=edges) - roads = [ # (name, x, y, direction) - ("Sensor_1", 520, 100, 125), - ("Sensor_2", 375, 287, 45), - ("Sensor_3", 282, 362, 300), - ("Sensor_4", 326, 464, 250), - ("Sensor_5", 585, 368, 120), - ("Sensor_6", 705, 394, 225), - ("Sensor_7", 480, 505, 200) + def make_sensors(self): + sensors = [ # (name, (x, y), state [colour], direction [road)) + ("Sensor_1", (522, 99), ( 0, 255, 0), 'Edge_00'), + ("Sensor_2", (375, 285), ( 0, 255, 0), 'Edge_62'), + ("Sensor_3", (284, 362), ( 0, 255, 0), 'Edge_36'), + ("Sensor_4", (325, 462), (255, 255, 0), 'Edge_42'), + ("Sensor_5", (585, 368), (255, 255, 0), 'Edge_61'), + ("Sensor_6", (705, 394), ( 0, 255, 0), 'Edge_77'), + ("Sensor_7", (480, 505), (255, 0, 0), None) ] for sensor in sensors: - self.controller.place(sensor[0], label="sensor", name=sensor[0], location=(sensor[1], sensor[2]), direction=sensor[3]) + self.controller.place(sensor[0], label="sensor", name=sensor[0], location=sensor[1], state=sensor[2], direction=sensor[3]) - def make_sensors(self): - sensors = [ # (name, x, y, direction) - ("Sensor_1", 520, 100, 125), - ("Sensor_2", 375, 287, 45), - ("Sensor_3", 282, 362, 300), - ("Sensor_4", 326, 464, 250), - ("Sensor_5", 585, 368, 120), - ("Sensor_6", 705, 394, 225), - ("Sensor_7", 480, 505, 200) - ] - for sensor in sensors: - self.controller.place(sensor[0], label="sensor", name=sensor[0], location=(sensor[1], sensor[2]), direction=sensor[3]) + +class DI_Controller(Controller2D): + """""" + + def __on_segment(self, point, delta, start, end): + """""" + + xp, yp = point + x0, y0 = start + x1, y1 = end + dx, dy = x1 - x0, y1 - y0 + # y = ax +/- b = dy/dx +/- delta + a = float(dy)/float(dx) + x, y = xp - x0, yp - y0 + + if dx <= 0: xmin = dx-delta; xmax = delta + else: xmin = -delta; xmax = dx+delta + + if dy <= 0: ymin = dy-delta; ymax = delta + else: ymin = -delta; ymax = dy+delta + + if (xmin < x < xmax) and (ymin < y < ymax) and (abs(a*x-y) < delta): + return True + else: + return False + + def on_road(self, key): + """""" + + #TODO: create Roadmap class with appropriate methods + self.roadmap = self.read('Roadmap') + road_nodes = self.roadmap['nodes'] + road_edges = self.roadmap['edges'] + + try: + delta = 15 #TODO: use view distance of item + item = self._model.read(key) + point = item['location'] + roads = [road for road in road_edges.values() if self.__on_segment(point, delta, road_nodes[road[0]], road_nodes[road[1]])] + return roads + except: + return [] + + def distance(self, key, point): + """""" + + if point is None: + return maxint # no maxfloat found + else: + try: + item = self._model.read(key) + x0, y0 = item['location'] + x1, y1 = point + dx, dy = x1-x0, y1-y0 + return math.sqrt(dx*dx + dy*dy) + except: + return maxint Modified: spyse/demo/DangerIsland/danger_gui.py =================================================================== --- spyse/demo/DangerIsland/danger_gui.py 2006-12-05 17:17:32 UTC (rev 266) +++ spyse/demo/DangerIsland/danger_gui.py 2006-12-05 17:28:45 UTC (rev 267) @@ -87,15 +87,34 @@ dc.SetPen(pen) dc.DrawCircle(loc[0]*self.ZoomFactor,loc[1]*self.ZoomFactor,radius*self.ZoomFactor) # dc.SelectObject(wx.NullBitmap) + + roadmap = self.env.read('Roadmap') +# print "Roadmap", roadmap + nodes = roadmap['nodes'] + edges = roadmap['edges'] + for e in edges.values(): + loc0=self.world2bitmap(nodes[e[0]]) + loc1=self.world2bitmap(nodes[e[1]]) + print loc0, loc1 + pen.SetColour(wx.Colour(63, 63, 63)) + dc.SetPen(pen) + dc.DrawLinePoint(loc0*self.ZoomFactor, loc1*self.ZoomFactor) +# pen.SetColour(wx.Colour(192, 63, 63)) +# dc.SetPen(pen) +# dc.DrawCircle(loc0[0]*self.ZoomFactor, loc0[1]*self.ZoomFactor, 3) + pen.SetColour(wx.Colour(63, 192, 63)) + dc.SetPen(pen) + dc.DrawCircle(loc1[0]*self.ZoomFactor, loc1[1]*self.ZoomFactor, 3) for key, value in self.env.find_items('label','sensor'): loc=self.world2bitmap(value['location']) - radius=6 - pen.SetColour(wx.Colour(0, 0, 0)) + state=value['state'] + radius=7 + pen.SetColour(wx.Colour(255, 255, 255)) dc.SetPen(pen) - dc.SetBrush(wx.Brush("YELLOW")) - dc.DrawCircle(loc[0]*self.ZoomFactor,loc[1]*self.ZoomFactor,radius*self.ZoomFactor) - + dc.SetBrush(wx.Brush(wx.Colour(state[0], state[1], state[2]))) + dc.DrawCircle(loc[0]*self.ZoomFactor, loc[1]*self.ZoomFactor, radius*self.ZoomFactor) + dc.SelectObject(wx.NullBitmap) def BufferImages(self): @@ -117,7 +136,7 @@ if not r.Intersects(rect): continue dc.Blit(r.x,r.y,r.width,r.height,mem,r.x+self.Xoffs,r.y+self.Yoffs) mem.SelectObject(wx.NullBitmap) - + def make_players(self): ## moving objects self.players = {} Added: spyse/demo/DangerIsland/images/borkum_plain_1200x900_2.png =================================================================== (Binary files differ) Property changes on: spyse/demo/DangerIsland/images/borkum_plain_1200x900_2.png ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: spyse/demo/DangerIsland/roads.txt =================================================================== --- spyse/demo/DangerIsland/roads.txt (rev 0) +++ spyse/demo/DangerIsland/roads.txt 2006-12-05 17:28:45 UTC (rev 267) @@ -0,0 +1,116 @@ +Node_00 522 099 +Node_01 492 144 +Edge_00 Node_00 Node_01 +Edge_01 Node_01 Node_00 +Node_02 453 194 +Edge_02 Node_01 Node_02 +Edge_03 Node_02 Node_01 +Node_03 412 245 +Edge_04 Node_02 Node_03 +Edge_05 Node_03 Node_02 +Node_04 375 285 +Edge_06 Node_03 Node_04 +Edge_07 Node_04 Node_03 +Node_05 330 330 +Edge_08 Node_04 Node_05 +Edge_09 Node_05 Node_04 +Node_06 284 362 +Edge_10 Node_05 Node_06 +Edge_11 Node_06 Node_05 +Node_07 240 382 +Edge_12 Node_06 Node_07 +Edge_13 Node_07 Node_06 +Node_08 200 412 +Edge_14 Node_07 Node_08 +Edge_15 Node_08 Node_07 +Node_09 180 433 +Edge_16 Node_08 Node_09 +Edge_17 Node_09 Node_08 +Node_10 173 459 +Edge_18 Node_09 Node_10 +Edge_19 Node_10 Node_09 +Node_11 178 490 +Edge_20 Node_10 Node_11 +Edge_21 Node_11 Node_10 +Node_12 190 512 +Edge_22 Node_11 Node_12 +Edge_23 Node_12 Node_11 +Node_13 210 515 +Edge_24 Node_12 Node_13 +Edge_25 Node_13 Node_12 +Node_14 238 503 +Edge_26 Node_13 Node_14 +Edge_27 Node_14 Node_13 +Node_15 265 506 +Edge_28 Node_14 Node_15 +Edge_29 Node_15 Node_14 +Node_16 282 500 +Edge_30 Node_15 Node_16 +Edge_31 Node_16 Node_15 +Node_17 301 479 +Edge_32 Node_16 Node_17 +Edge_33 Node_17 Node_16 +Node_18 325 462 +Edge_34 Node_17 Node_18 +Edge_35 Node_18 Node_17 +Node_19 296 399 +Edge_36 Node_06 Node_19 +Edge_37 Node_19 Node_06 +Node_20 312 434 +Edge_38 Node_19 Node_20 +Edge_39 Node_20 Node_19 +Edge_40 Node_20 Node_18 +Edge_41 Node_18 Node_20 +Node_22 348 471 +Edge_42 Node_18 Node_22 +Edge_43 Node_22 Node_18 +Node_23 375 487 +Edge_44 Node_22 Node_23 +Edge_45 Node_23 Node_22 +Node_24 400 487 +Edge_46 Node_23 Node_24 +Edge_47 Node_24 Node_23 +Node_25 417 482 +Edge_48 Node_24 Node_25 +Edge_49 Node_25 Node_24 +Node_26 450 500 +Edge_50 Node_25 Node_26 +Edge_51 Node_26 Node_25 +Node_27 480 505 +Edge_52 Node_26 Node_27 +Edge_53 Node_27 Node_26 +Node_28 500 477 +Edge_54 Node_27 Node_28 +Edge_55 Node_28 Node_27 +Node_29 518 452 +Edge_56 Node_28 Node_29 +Edge_57 Node_29 Node_28 +Node_30 559 411 +Edge_58 Node_29 Node_30 +Edge_59 Node_30 Node_29 +Node_31 585 368 +Edge_60 Node_30 Node_31 +Edge_61 Node_31 Node_30 +Node_32 397 306 +Edge_62 Node_04 Node_32 +Edge_63 Node_32 Node_04 +Node_33 415 327 +Edge_64 Node_32 Node_33 +Edge_65 Node_33 Node_32 +Node_34 438 340 +Edge_66 Node_33 Node_34 +Edge_67 Node_34 Node_33 +Node_35 464 343 +Edge_68 Node_34 Node_35 +Edge_69 Node_35 Node_34 +Node_36 522 335 +Edge_70 Node_35 Node_36 +Edge_71 Node_36 Node_35 +Edge_72 Node_36 Node_31 +Edge_73 Node_31 Node_36 +Node_37 660 370 +Edge_74 Node_31 Node_37 +Edge_75 Node_37 Node_31 +Node_38 705 394 +Edge_76 Node_37 Node_38 +Edge_77 Node_38 Node_37 Added: spyse/demo/DangerIsland/roads_trash.txt =================================================================== --- spyse/demo/DangerIsland/roads_trash.txt (rev 0) +++ spyse/demo/DangerIsland/roads_trash.txt 2006-12-05 17:28:45 UTC (rev 267) @@ -0,0 +1,40 @@ +522 099 492 144 +492 144 453 194 +453 194 412 245 +412 245 375 285 +375 285 330 330 +330 330 284 362 +284 362 240 382 +240 382 200 412 +200 412 180 433 +180 433 173 459 +173 459 178 490 +178 490 190 512 +190 512 210 515 +210 515 238 503 +238 503 265 506 +265 506 282 500 +282 500 301 479 +301 479 325 462 + +284 362 296 399 +296 399 312 434 +312 434 325 462 +325 462 348 471 +348 471 375 487 +375 487 400 487 +400 487 417 482 +417 482 450 500 +450 500 480 505 +480 505 500 477 +500 477 518 452 +518 452 559 411 +559 411 585 368 +375 285 395 307 +395 307 415 327 +415 327 438 340 +438 340 464 343 +464 343 522 335 +522 335 585 368 +585 368 660 370 +660 370 705 394 \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jd...@us...> - 2006-12-05 17:17:33
|
Revision: 266 http://svn.sourceforge.net/spyse/?rev=266&view=rev Author: jdthood Date: 2006-12-05 09:17:32 -0800 (Tue, 05 Dec 2006) Log Message: ----------- Remove a control-M Modified Paths: -------------- spyse/core/platform/platform.py Modified: spyse/core/platform/platform.py =================================================================== --- spyse/core/platform/platform.py 2006-12-05 16:58:42 UTC (rev 265) +++ spyse/core/platform/platform.py 2006-12-05 17:17:32 UTC (rev 266) @@ -65,12 +65,12 @@ spyse.core.semant.environment.dist = env spyse.core.semant.environment.daemon = cls.daemon spyse.core.semant.environment.pyroloc = pyroloc - + if nsmode == NsMode.NONE: print 'Will not use a nameserver.' cls.nameserver = None elif nsmode == NsMode.LOCAL: - print 'Will use a local nameserver.' + print 'Will use a local nameserver.' Pyro.config.PYRO_NS_HOSTNAME = 'localhost' try: nslocator = Pyro.naming.NameServerLocator() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jd...@us...> - 2006-12-05 16:58:47
|
Revision: 265 http://svn.sourceforge.net/spyse/?rev=265&view=rev Author: jdthood Date: 2006-12-05 08:58:42 -0800 (Tue, 05 Dec 2006) Log Message: ----------- Remove a control-M Modified Paths: -------------- spyse/core/mts/mts.py Modified: spyse/core/mts/mts.py =================================================================== --- spyse/core/mts/mts.py 2006-12-05 15:06:43 UTC (rev 264) +++ spyse/core/mts/mts.py 2006-12-05 16:58:42 UTC (rev 265) @@ -28,7 +28,7 @@ res = False for rec in msg.receivers: res = self.__deliver_to(new_msg, rec) - return res + return res def __deliver_to(self, new_msg, rec): new_msg.receivers = [rec] This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jd...@us...> - 2006-12-05 15:06:48
|
Revision: 264 http://svn.sourceforge.net/spyse/?rev=264&view=rev Author: jdthood Date: 2006-12-05 07:06:43 -0800 (Tue, 05 Dec 2006) Log Message: ----------- Apply Andre's changes to docstring Modified Paths: -------------- spyse/demo/envdemo.py Modified: spyse/demo/envdemo.py =================================================================== --- spyse/demo/envdemo.py 2006-11-27 09:07:57 UTC (rev 263) +++ spyse/demo/envdemo.py 2006-12-05 15:06:43 UTC (rev 264) @@ -29,10 +29,14 @@ Segmented(or Distributed): Divide the environment over 2 Spyse instances - Box1 xMin: 0 xMax: 150 yMin: 0 yMax: 150 Blue Cars - envdemo.py --port=9001 --env=dist 1 5 0 150 0 150 blue - Box2 xMin: 150 xMax: 300 yMin: 0 yMax: 150 Red Cars - envdemo.py --port=909 --env=dist 1 5 150 300 0 150 red + Box1 xMin: 0 xMax: 150 yMin: 0 yMax: 150 Blue Cars + envdemo.py --port=9001 --ns=start --env=dist 1 5 0 150 0 150 blue + Box2 xMin: 150 xMax: 300 yMin: 0 yMax: 150 Red Cars + envdemo.py --port=9002 --ns=local --env=dist 1 5 150 300 0 150 red + Box3 xMin: 0 xMax: 150 yMin: 150 yMax: 300 Yellow Cars + envdemo.py --port=9003 --ns=local --env=dist 1 5 0 150 150 300 yellow + Box4 xMin: 150 xMax: 300 yMin: 150 yMax: 300 Green Cars + envdemo.py --port=9004 --ns=local --env=dist 1 5 150 300 150 300 green Last scenario can be extended to create 4 instances which cover a box with size 300,300. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dra...@us...> - 2006-11-27 09:08:02
|
Revision: 263 http://svn.sourceforge.net/spyse/?rev=263&view=rev Author: drapmeyer Date: 2006-11-27 01:07:57 -0800 (Mon, 27 Nov 2006) Log Message: ----------- updated Danger Island with road following behaviour Modified Paths: -------------- spyse/asw/asw_gui.py spyse/asw/environment.py spyse/demo/DangerIsland/danger.py spyse/demo/DangerIsland/danger_env.py spyse/demo/DangerIsland/danger_gui.py Property Changed: ---------------- spyse/demo/ Modified: spyse/asw/asw_gui.py =================================================================== --- spyse/asw/asw_gui.py 2006-11-24 18:30:39 UTC (rev 262) +++ spyse/asw/asw_gui.py 2006-11-27 09:07:57 UTC (rev 263) @@ -417,7 +417,4 @@ pass Platform.shutdown() self.Destroy() - sys.exit() - - - + sys.exit(0) Modified: spyse/asw/environment.py =================================================================== --- spyse/asw/environment.py 2006-11-24 18:30:39 UTC (rev 262) +++ spyse/asw/environment.py 2006-11-27 09:07:57 UTC (rev 263) @@ -269,22 +269,26 @@ ## ## return list(set - false_candidates) - def __inside(self, circle, item): + def __inside(self, circle, item, label): try: - x, y, d = circle - xi,yi = item['location'] - dx=xi-x; dy=yi-y - return (dx*dx + dy*dy < d*d) + if item['label'] is not label: + return False + else: + x, y, d = circle + xi, yi = item['location'] + dx = xi-x + dy = yi-y + return (dx*dx + dy*dy < d*d) except: return False - def neighbours(self, key, type=None): + def neighbours(self, key, label=None): # Who is within distance d from agent key? try: d = 50 #TODO: use view distance of item item = self._model.read(key) - x,y=item['location'] + x, y = item['location'] circle = (x, y, d) values = self._model.values() @@ -294,7 +298,7 @@ except: return [] - return [i for i in values if self.__inside(circle, i)] + return [i for i in values if self.__inside(circle, i, label)] def inview(self, key, type=None): # neighbours in heading direction Property changes on: spyse/demo ___________________________________________________________________ Name: svn:ignore - Pyro_NS_URI + Pyro_NS_URI Thumbs.db Modified: spyse/demo/DangerIsland/danger.py =================================================================== --- spyse/demo/DangerIsland/danger.py 2006-11-24 18:30:39 UTC (rev 262) +++ spyse/demo/DangerIsland/danger.py 2006-11-27 09:07:57 UTC (rev 263) @@ -37,11 +37,30 @@ print "RobotBehaviour.setup" self.env = env self.da = 12 + self.last_sensor = None def on_tick(self): - print "tick" self.body = self.env.read(self.agent.name) - cells = self.env.neighbours(self.agent.name, type='cell') + self.x, self.y = self.body['location'] + + # check whether a sensor is close that has not been used, yet + sensors = self.env.neighbours(self.agent.name, label='sensor') + print "sensors", len(sensors) + if len(sensors) > 0: + s = sensors[0] +# print s + if s['name'] is not self.last_sensor: + sx, sy = s['location'] + dx = sx - self.x + dy = sy - self.y +# print (dx, dy), math.sqrt(dx*dx + dy*dy) + if math.sqrt(dx*dx + dy*dy) < 10: + self.last_sensor = s['name'] +# print s['direction']-self.body['rotation'] + self.env.turn(self.agent.name, s['direction']-self.body['rotation']) + + # sense environment and select road cells + cells = self.env.neighbours(self.agent.name, label='cell') # print len(cells) roads = [i for i in cells if i['type'] == 'road'] print "roads", len(roads) @@ -79,10 +98,9 @@ env = DI_Environment(condition=Platform.is_running, x_min=0, x_max=width, y_min=0, y_max=height) env.start() # contr=env.controller - a = 125 - self.start_agent(Robot, "Robot_0", env=env.controller, location=(512.0, 112.0), rotation= 0+a, speed=6) -# self.start_agent(Robot, "Robot_1", env=env.controller, location=(20, 300), rotation= 0+a, speed=10) -# self.start_agent(Robot, "Robot_2", env=env.controller, location=(30, 300), rotation= 30+a, speed=10) + self.start_agent(Robot, "Robot_0", env=env.controller, location=(512, 112), rotation= 125, speed=3) +# self.start_agent(Robot, "Robot_1", env=env.controller, location=(320, 446), rotation= 250, speed=5) +# self.start_agent(Robot, "Robot_2", env=env.controller, location=(30, 300), rotation= 30, speed=10) self.start_agent(DI_GameAgent, 'Viewer', env=env.controller, size=(width, height)) wxAgent.run_GUI() Modified: spyse/demo/DangerIsland/danger_env.py =================================================================== --- spyse/demo/DangerIsland/danger_env.py 2006-11-24 18:30:39 UTC (rev 262) +++ spyse/demo/DangerIsland/danger_env.py 2006-11-27 09:07:57 UTC (rev 263) @@ -20,6 +20,8 @@ def setup(self): self.xChart=1000.0; self.yChart=800.0 self.make_cells() + #self.make_roads() + self.make_sensors() self.updateProcs.append(self.moveRobots) self.updateProcs.append(self.update_cells) self.updateProcs.append(self.update_sensors) @@ -55,7 +57,7 @@ return min(d)[1] def make_cells(self): - img = wx.Image("spyse/demo/DangerIsland/images/borkum_plain_1200x900.png", wx.BITMAP_TYPE_PNG) + img = wx.Image("spyse/demo/DangerIsland/images/borkum_plain_1200x900_2.png", wx.BITMAP_TYPE_PNG) self.imgwidth = img.GetWidth() self.imgheight = img.GetHeight() nbytes = self.imgwidth*self.imgheight*3 @@ -84,3 +86,41 @@ yi = yi+1; y = yi*(1.5*rad) nr+=1 xi = xi+1 + + def make_roads(self): + f=open('roads.txt') + i=0; self.controller.roadMap=[] + for line in f: + [x1, y1, x2, y2]=line.split() + name='RoadSegment'+str(i) + beginloc=(int(float(x1)), int(float(y1))) + endloc=(int(float(x2)), int(float(y2))) + self.controller.place(name, label="Road", location=beginloc, endloc=endloc) + self.controller.roadMap.append(RoadSegment(name,beginloc,endloc)) + i+=1 + f.close() + + roads = [ # (name, x, y, direction) + ("Sensor_1", 520, 100, 125), + ("Sensor_2", 375, 287, 45), + ("Sensor_3", 282, 362, 300), + ("Sensor_4", 326, 464, 250), + ("Sensor_5", 585, 368, 120), + ("Sensor_6", 705, 394, 225), + ("Sensor_7", 480, 505, 200) + ] + for sensor in sensors: + self.controller.place(sensor[0], label="sensor", name=sensor[0], location=(sensor[1], sensor[2]), direction=sensor[3]) + + def make_sensors(self): + sensors = [ # (name, x, y, direction) + ("Sensor_1", 520, 100, 125), + ("Sensor_2", 375, 287, 45), + ("Sensor_3", 282, 362, 300), + ("Sensor_4", 326, 464, 250), + ("Sensor_5", 585, 368, 120), + ("Sensor_6", 705, 394, 225), + ("Sensor_7", 480, 505, 200) + ] + for sensor in sensors: + self.controller.place(sensor[0], label="sensor", name=sensor[0], location=(sensor[1], sensor[2]), direction=sensor[3]) Modified: spyse/demo/DangerIsland/danger_gui.py =================================================================== --- spyse/demo/DangerIsland/danger_gui.py 2006-11-24 18:30:39 UTC (rev 262) +++ spyse/demo/DangerIsland/danger_gui.py 2006-11-27 09:07:57 UTC (rev 263) @@ -24,7 +24,7 @@ def app_setup(self): self.xChart=1000.0; self.yChart=800.0 - self.CellsOn=False + self.CellsOn=True self.make_background() self.make_players() self.SetInitialZoom() @@ -35,7 +35,7 @@ self.CellsOn=not self.CellsOn self.draw_all() self.smooth_done() - + def smooth_draw(self,dc): bufdc=wx.BufferedDC(dc,self.bufferbmp) self.draw_background(bufdc) @@ -86,6 +86,16 @@ pen.SetColour(wx.Colour(col[0],col[1],col[2])) dc.SetPen(pen) dc.DrawCircle(loc[0]*self.ZoomFactor,loc[1]*self.ZoomFactor,radius*self.ZoomFactor) +# dc.SelectObject(wx.NullBitmap) + + for key, value in self.env.find_items('label','sensor'): + loc=self.world2bitmap(value['location']) + radius=6 + pen.SetColour(wx.Colour(0, 0, 0)) + dc.SetPen(pen) + dc.SetBrush(wx.Brush("YELLOW")) + dc.DrawCircle(loc[0]*self.ZoomFactor,loc[1]*self.ZoomFactor,radius*self.ZoomFactor) + dc.SelectObject(wx.NullBitmap) def BufferImages(self): @@ -198,7 +208,6 @@ self.__class__._timer.start() def deselect(self): - print 'deselect' sb = wx.GetApp().GetTopWindow().statusBar sb.SetStatusText('', 0) self.__class__._timer.cancel() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jd...@us...> - 2006-11-24 18:30:40
|
Revision: 262 http://svn.sourceforge.net/spyse/?rev=262&view=rev Author: jdthood Date: 2006-11-24 10:30:39 -0800 (Fri, 24 Nov 2006) Log Message: ----------- Change limit to maximum and start counting at 1. Makes output easier to check. Modified Paths: -------------- spyse/demo/communication.py spyse/demo/subscription.py Modified: spyse/demo/communication.py =================================================================== --- spyse/demo/communication.py 2006-11-24 18:13:23 UTC (rev 261) +++ spyse/demo/communication.py 2006-11-24 18:30:39 UTC (rev 262) @@ -26,11 +26,11 @@ msg.receivers.add(AID('Snoopy')) if self.__iterations > 0: content = self.agent.name + "/" + str(self.__iterations) + print 'Agent', self.agent.name, "sending message", self.__iterations else: content = None msg.content = content self.agent.send_message(msg) - print 'Agent', self.agent.name, "has sent message", self.__iterations if self.__iterations > 0: self.__iterations -= 1 # Pretend we're doing something that takes 10-100 ms Modified: spyse/demo/subscription.py =================================================================== --- spyse/demo/subscription.py 2006-11-24 18:13:23 UTC (rev 261) +++ spyse/demo/subscription.py 2006-11-24 18:30:39 UTC (rev 262) @@ -16,9 +16,9 @@ class PublisherAgent(Agent): - def setup(self, limit): - self.__count = 0 - self.__limit = limit + def setup(self, maximum): + self.__count = 1 + self.__maximum = maximum self.add_behaviour(SubscriptionParticipantBehaviour( send_response=self._send_response, send_notifications=self._send_notifications, @@ -28,11 +28,11 @@ def _send_notifications(self): notification = randint(0,99) - if self.__count >= self.__limit: + if self.__count > self.__maximum: print "\nAgent", self.name, "ceasing publication." self.die() else: - print "\nAgent", self.name, "sending notification", self.__count, "/", self.__limit, "with info:", notification + print "\nAgent", self.name, "sending notification", self.__count, "/", self.__maximum, "with info:", notification self.__count += 1 return notification @@ -49,9 +49,9 @@ class SubscriberAgent(Agent): - def setup(self, subscription, limit): - self.__count = 0 - self.__limit = limit + def setup(self, subscription, maximum): + self.__count = 1 + self.__maximum = maximum self.add_behaviour(SubscriptionInitiatorBehaviour( subscription=subscription, handle_response=self._handle_response, @@ -73,17 +73,17 @@ print "Agent", self.name, "handling refusal" def _handle_inform(self, content): - print "Agent", self.name, "handling notification", self.__count, "/", self.__limit, "with info:", content self.__count += 1 + print "Agent", self.name, "handling notification", self.__count, "/", self.__maximum, "with info:", content def _handle_failure(self): print "Agent", self.name, "handling failure" def _cancel(self): - print "Agent", self.name, "cancelling my subscription" + print "Agent", self.name, "cancelling its subscription" def _check_cancel(self): - if self.__limit and self.__count >= self.__limit: + if self.__maximum and self.__count >= self.__maximum: print "Agent", self.name, "signalling cancel" return True return False @@ -91,14 +91,14 @@ class MyApp(App): def run(self, args): - self.start_agent(PublisherAgent, 'Pub', limit=40) # To reveal bug, arrange it so that publisher ends earlier than subscribers + self.start_agent(PublisherAgent, 'Pub', maximum=40) # To reveal bug, arrange it so that publisher ends earlier than subscribers time.sleep(0.2) subscription=AID('Pub') - self.start_agent(SubscriberAgent, 'Red', subscription=subscription, limit=13) + self.start_agent(SubscriberAgent, 'Red', subscription=subscription, maximum=13) time.sleep(0.2) - self.start_agent(SubscriberAgent, 'Hot', subscription=subscription, limit=17) + self.start_agent(SubscriberAgent, 'Hot', subscription=subscription, maximum=17) time.sleep(0.2) - self.start_agent(SubscriberAgent, 'Che', subscription=subscription, limit=30) + self.start_agent(SubscriberAgent, 'Che', subscription=subscription, maximum=30) if __name__ == "__main__": MyApp() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jd...@us...> - 2006-11-24 18:13:24
|
Revision: 261 http://svn.sourceforge.net/spyse/?rev=261&view=rev Author: jdthood Date: 2006-11-24 10:13:23 -0800 (Fri, 24 Nov 2006) Log Message: ----------- Underscorify receiveGlobalMsg Modified Paths: -------------- spyse/core/mts/mts.py Modified: spyse/core/mts/mts.py =================================================================== --- spyse/core/mts/mts.py 2006-11-24 18:09:17 UTC (rev 260) +++ spyse/core/mts/mts.py 2006-11-24 18:13:23 UTC (rev 261) @@ -49,7 +49,7 @@ if rec_adr == self.pyrouri: return self.__receive(new_msg) else: - return Pyro.core.getProxyForURI(rec_adr)._receiveGlobalMsg(new_msg) + return Pyro.core.getProxyForURI(rec_adr)._receive_global_msg(new_msg) else: return self.__receive(new_msg) else: @@ -60,7 +60,7 @@ try: remote_mts = Pyro.core.getProxyForURI(mts_string) try: - return remote_mts._receiveGlobalMsg(new_msg) + return remote_mts._receive_global_msg(new_msg) except Exception, e: print 'Could not deliver message to', rec.name + ': remote mts', mts_string, "raised error:", e return False @@ -82,6 +82,6 @@ print 'MTS: Could not find receiving agent', rec.name return False - def _receiveGlobalMsg(self, msg): + def _receive_global_msg(self, msg): return self.__receive(msg) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jd...@us...> - 2006-11-24 18:09:18
|
Revision: 260 http://svn.sourceforge.net/spyse/?rev=260&view=rev Author: jdthood Date: 2006-11-24 10:09:17 -0800 (Fri, 24 Nov 2006) Log Message: ----------- Underscorify etTile Modified Paths: -------------- spyse/core/semant/environment.py Modified: spyse/core/semant/environment.py =================================================================== --- spyse/core/semant/environment.py 2006-11-24 18:05:41 UTC (rev 259) +++ spyse/core/semant/environment.py 2006-11-24 18:09:17 UTC (rev 260) @@ -225,12 +225,12 @@ # stigmergic level # -# def setTile(self, x, y, z, name, value): # Ignore z for now +# def set_tile(self, x, y, z, name, value): # Ignore z for now # tile = self.cosmos[x][y] # tile['t']= time.time() # # -# def getTile(x, y, z): # ignore z for now +# def get_tile(x, y, z): # ignore z for now # return self.cosmos[x][y] # semantic level This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jd...@us...> - 2006-11-24 18:05:43
|
Revision: 259 http://svn.sourceforge.net/spyse/?rev=259&view=rev Author: jdthood Date: 2006-11-24 10:05:41 -0800 (Fri, 24 Nov 2006) Log Message: ----------- Underscorify getNext Modified Paths: -------------- spyse/core/platform/threadpool.py Modified: spyse/core/platform/threadpool.py =================================================================== --- spyse/core/platform/threadpool.py 2006-11-24 18:04:23 UTC (rev 258) +++ spyse/core/platform/threadpool.py 2006-11-24 18:05:41 UTC (rev 259) @@ -22,7 +22,7 @@ def reschedule(self,agent): self.q.put(agent) - def getNext(self): + def get_next(self): try: return self.q.get(False) except: return None @@ -42,7 +42,7 @@ def run(self): self.running = True while self.running: - a = self.pool.getNext() + a = self.pool.get_next() if a is not None: start = time.clock() res = a.run_once() @@ -55,4 +55,4 @@ #time.sleep(0) time.sleep(0.001) - \ No newline at end of file + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jd...@us...> - 2006-11-24 18:04:24
|
Revision: 258 http://svn.sourceforge.net/spyse/?rev=258&view=rev Author: jdthood Date: 2006-11-24 10:04:23 -0800 (Fri, 24 Nov 2006) Log Message: ----------- Underscorify newMsg Modified Paths: -------------- spyse/core/mts/mts.py Modified: spyse/core/mts/mts.py =================================================================== --- spyse/core/mts/mts.py 2006-11-24 18:00:52 UTC (rev 257) +++ spyse/core/mts/mts.py 2006-11-24 18:04:23 UTC (rev 258) @@ -20,18 +20,18 @@ def send(self, sender, msg): """Send message""" - newMsg = copy.deepcopy(msg.encode_ACL()) - newMsg.sender = sender + new_msg = copy.deepcopy(msg.encode_ACL()) + new_msg.sender = sender # The send method should return True or False so the agent # knows if the message is successfully delivered res = False for rec in msg.receivers: - res = self.__deliver_to(newMsg, rec) + res = self.__deliver_to(new_msg, rec) return res - def __deliver_to(self, newMsg, rec): - newMsg.receivers = [rec] + def __deliver_to(self, new_msg, rec): + new_msg.receivers = [rec] rec_hap = rec.hap if rec_hap is None: rec_hap = self.hap @@ -47,20 +47,20 @@ if len(rec_addresses) > 0: rec_adr = rec_addresses[0] if rec_adr == self.pyrouri: - return self.__receive(newMsg) + return self.__receive(new_msg) else: - return Pyro.core.getProxyForURI(rec_adr)._receiveGlobalMsg(newMsg) + return Pyro.core.getProxyForURI(rec_adr)._receiveGlobalMsg(new_msg) else: - return self.__receive(newMsg) + return self.__receive(new_msg) else: # Remote delivery - newMsg.sender.hap = self.hap + new_msg.sender.hap = self.hap mts_string = "PYROLOC://" + rec_hap.name + "/" + rec_hap.name.replace(".","+") + "/mts" try: remote_mts = Pyro.core.getProxyForURI(mts_string) try: - return remote_mts._receiveGlobalMsg(newMsg) + return remote_mts._receiveGlobalMsg(new_msg) except Exception, e: print 'Could not deliver message to', rec.name + ': remote mts', mts_string, "raised error:", e return False This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jd...@us...> - 2006-11-24 18:00:53
|
Revision: 257 http://svn.sourceforge.net/spyse/?rev=257&view=rev Author: jdthood Date: 2006-11-24 10:00:52 -0800 (Fri, 24 Nov 2006) Log Message: ----------- Underscorify createReply Modified Paths: -------------- spyse/core/content/content.py spyse/core/platform/df.py spyse/core/protocols/contractnet.py spyse/core/protocols/request.py spyse/core/protocols/subscription.py spyse/demo/bookbuying.py spyse/ibas/status_agent.py Modified: spyse/core/content/content.py =================================================================== --- spyse/core/content/content.py 2006-11-24 17:58:57 UTC (rev 256) +++ spyse/core/content/content.py 2006-11-24 18:00:52 UTC (rev 257) @@ -80,7 +80,7 @@ """Set a conversation ID""" self.conversation_id = 'cid' + str(hash(self)) + str(time.time()) + str(randint(0,1000000)) - def createReply(self, performative=MessageTemplate.AGREE): + def create_reply(self, performative=MessageTemplate.AGREE): reply = copy.copy(self) reply.performative = performative reply.receivers = set([reply.sender]) Modified: spyse/core/platform/df.py =================================================================== --- spyse/core/platform/df.py 2006-11-24 17:58:57 UTC (rev 256) +++ spyse/core/platform/df.py 2006-11-24 18:00:52 UTC (rev 257) @@ -23,7 +23,7 @@ elif perf == ACLMessage.QUERY_REF: agents = self.agent.find_service_providers(content) - reply = msg.createReply(ACLMessage.INFORM) + reply = msg.create_reply(ACLMessage.INFORM) reply.content = agents self.agent.send_message(reply) Modified: spyse/core/protocols/contractnet.py =================================================================== --- spyse/core/protocols/contractnet.py 2006-11-24 17:58:57 UTC (rev 256) +++ spyse/core/protocols/contractnet.py 2006-11-24 18:00:52 UTC (rev 257) @@ -154,7 +154,7 @@ proposals = self.datastore['proposals'] contract = self.datastore['contract'] for p in proposals: - conclusion = p.createReply() + conclusion = p.create_reply() if p == contract: conclusion.performative = ACLMessage.ACCEPT_PROPOSAL conclusion.content = p.content @@ -408,7 +408,7 @@ if result is None: self.result = ContractNetParticipantBehaviour.default_key else: - reply = conclusion.createReply() + reply = conclusion.create_reply() if result is False: reply.performative = ACLMessage.FAILURE elif result is True: Modified: spyse/core/protocols/request.py =================================================================== --- spyse/core/protocols/request.py 2006-11-24 17:58:57 UTC (rev 256) +++ spyse/core/protocols/request.py 2006-11-24 18:00:52 UTC (rev 257) @@ -104,7 +104,7 @@ self.send_response() if message_key in self.datastore: msg = self.datastore[message_key] - reply = msg.createReply(ACLMessage.AGREE) + reply = msg.create_reply(ACLMessage.AGREE) reply.sender = self.agent.aid self.agent.send_message(reply) self.result = RESPONSE_SENT @@ -136,9 +136,9 @@ result = self.send_result() msg = self.datastore[message_key] if result is None: - reply = msg.createReply(ACLMessage.INFORM_DONE) + reply = msg.create_reply(ACLMessage.INFORM_DONE) else: - reply = msg.createReply(ACLMessage.INFORM) + reply = msg.create_reply(ACLMessage.INFORM) reply.content = result self.agent.send_message(reply) @@ -157,7 +157,7 @@ self.cancel() if message_key in self.datastore: msg = self.datastore[message_key] - reply = msg.createReply(ACLMessage.INFORM_DONE) + reply = msg.create_reply(ACLMessage.INFORM_DONE) self.agent.send_message(reply) del self.datastore[message_key] self.datastore[customer_key] = None Modified: spyse/core/protocols/subscription.py =================================================================== --- spyse/core/protocols/subscription.py 2006-11-24 17:58:57 UTC (rev 256) +++ spyse/core/protocols/subscription.py 2006-11-24 18:00:52 UTC (rev 257) @@ -94,7 +94,7 @@ self.send_response() if message_key in self.datastore: msg = self.datastore[message_key] - reply = msg.createReply(ACLMessage.AGREE) + reply = msg.create_reply(ACLMessage.AGREE) self.agent.send_message(reply) del self.datastore[message_key] self.result = RESPONSE_SENT @@ -142,7 +142,7 @@ self.cancel() if message_key in self.datastore: msg = self.datastore[message_key] - reply = msg.createReply(ACLMessage.INFORM_DONE) + reply = msg.create_reply(ACLMessage.INFORM_DONE) self.agent.send_message(reply) del self.datastore[message_key] subscribers = self.datastore[subscribers_key] Modified: spyse/demo/bookbuying.py =================================================================== --- spyse/demo/bookbuying.py 2006-11-24 17:58:57 UTC (rev 256) +++ spyse/demo/bookbuying.py 2006-11-24 18:00:52 UTC (rev 257) @@ -165,7 +165,7 @@ title = content['title'] if title == "NoWay": - proposal = call.createReply() + proposal = call.create_reply() proposal.performative = ACLMessage.REFUSE return proposal @@ -176,7 +176,7 @@ print self.name, 'making proposal', title, "at price", price content['price'] = price content['signature'] = self.name - proposal = call.createReply() + proposal = call.create_reply() proposal.performative = ACLMessage.PROPOSE print self.name, "making proposal with content", content proposal.content = content Modified: spyse/ibas/status_agent.py =================================================================== --- spyse/ibas/status_agent.py 2006-11-24 17:58:57 UTC (rev 256) +++ spyse/ibas/status_agent.py 2006-11-24 18:00:52 UTC (rev 257) @@ -21,7 +21,7 @@ if msg.performative == ACLMessage.INFORM: self.agent.num_requests[msg.sender.shortname] = msg.content elif msg.performative == ACLMessage.REQUEST: - reply = msg.createReply(ACLMessage.INFORM) + reply = msg.create_reply(ACLMessage.INFORM) top_agents = self.agent.num_requests.items() top_agents.sort(self.sort_func) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jd...@us...> - 2006-11-24 17:58:59
|
Revision: 256 http://svn.sourceforge.net/spyse/?rev=256&view=rev Author: jdthood Date: 2006-11-24 09:58:57 -0800 (Fri, 24 Nov 2006) Log Message: ----------- Eliminate some getters and setters Modified Paths: -------------- spyse/core/content/content.py Modified: spyse/core/content/content.py =================================================================== --- spyse/core/content/content.py 2006-11-24 17:58:02 UTC (rev 255) +++ spyse/core/content/content.py 2006-11-24 17:58:57 UTC (rev 256) @@ -59,24 +59,6 @@ def __init__(self, performative=None): self.performative = performative - # - # Nonstandard attribute getters and setters - # - # DEPRECATED. Use attributes directly. - # - - def setInReplyTo(self, in_reply_to): - self.in_reply_to = in_reply_to - - def getInReplyTo(self): - return getattr(self, 'in_reply_to', None) - - def setReplyBy(self, reply_by): - self.reply_by = reply_by - - def getReplyBy(self): - return getattr(self, 'reply_by', None) - def __get_dict(self): d = {} for s in self.__slots__: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jd...@us...> - 2006-11-24 17:58:04
|
Revision: 255 http://svn.sourceforge.net/spyse/?rev=255&view=rev Author: jdthood Date: 2006-11-24 09:58:02 -0800 (Fri, 24 Nov 2006) Log Message: ----------- Eliminate some getters and setters Modified Paths: -------------- spyse/core/content/content.py Modified: spyse/core/content/content.py =================================================================== --- spyse/core/content/content.py 2006-11-24 17:57:02 UTC (rev 254) +++ spyse/core/content/content.py 2006-11-24 17:58:02 UTC (rev 255) @@ -65,18 +65,6 @@ # DEPRECATED. Use attributes directly. # - def setReplyTo(self, reply_to): - self.reply_to = reply_to - - def getReplyTo(self): - return getattr(self, 'reply_to', None) - - def setReplyWith(self, reply_with): - self.reply_with = reply_with - - def getReplyWith(self): - return getattr(self, 'reply_with', None) - def setInReplyTo(self, in_reply_to): self.in_reply_to = in_reply_to This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jd...@us...> - 2006-11-24 17:57:06
|
Revision: 254 http://svn.sourceforge.net/spyse/?rev=254&view=rev Author: jdthood Date: 2006-11-24 09:57:02 -0800 (Fri, 24 Nov 2006) Log Message: ----------- Eliminate some getters and setters Modified Paths: -------------- spyse/core/content/content.py spyse/ibas/iba.py spyse/ibas/logger_agent.py spyse/ibas/status_agent.py Modified: spyse/core/content/content.py =================================================================== --- spyse/core/content/content.py 2006-11-24 17:52:23 UTC (rev 253) +++ spyse/core/content/content.py 2006-11-24 17:57:02 UTC (rev 254) @@ -65,39 +65,6 @@ # DEPRECATED. Use attributes directly. # - def setProtocol(self, protocol): - self.protocol = protocol - - def getProtocol(self): - return getattr(self, 'protocol', None) - - def setEncoding(self, encoding): - self.encoding = encoding - - def getEncoding(self): - return getattr(self, 'encoding', None) - - def setLanguage(self, language): - self.language = language - - def getLanguage(self): - return getattr(self, 'language', None) - - def setOntology(self, ontology): - self.ontology = ontology - - def getOntology(self): - return getattr(self, 'ontology', None) - - def setContent(self, content): - self.content = content - - def getContent(self): - return getattr(self, 'content', None) - - def clearContent(self): - self.content = None - def setReplyTo(self, reply_to): self.reply_to = reply_to Modified: spyse/ibas/iba.py =================================================================== --- spyse/ibas/iba.py 2006-11-24 17:52:23 UTC (rev 253) +++ spyse/ibas/iba.py 2006-11-24 17:57:02 UTC (rev 254) @@ -61,7 +61,7 @@ elif self.result != "": msg = ACLMessage(ACLMessage.INFORM) msg.receivers.add(AID('Logger Agent')) - msg.setContent(self.result) + msg.content = self.result self.agent.send_message(msg) self.agent.check_time = datetime.now() + ONE_HOUR self.result = None @@ -148,7 +148,7 @@ self.num_requests = self.num_requests + 1 msg = ACLMessage(ACLMessage.INFORM) msg.receivers.add(AID('Status Agent')) - msg.setContent(self.num_requests) + msg.content = self.num_requests self.send_message(msg) def _perform_request(self, request): Modified: spyse/ibas/logger_agent.py =================================================================== --- spyse/ibas/logger_agent.py 2006-11-24 17:52:23 UTC (rev 253) +++ spyse/ibas/logger_agent.py 2006-11-24 17:57:02 UTC (rev 254) @@ -21,7 +21,7 @@ elif msg.performative == ACLMessage.REQUEST: reply = ACLMessage(ACLMessage.INFORM) reply.receivers.add(msg.sender) - reply.setContent(self.agent.messages) + reply.content = self.agent.messages self.agent.send_message(reply) class LoggerAgent(Agent): Modified: spyse/ibas/status_agent.py =================================================================== --- spyse/ibas/status_agent.py 2006-11-24 17:52:23 UTC (rev 253) +++ spyse/ibas/status_agent.py 2006-11-24 17:57:02 UTC (rev 254) @@ -26,7 +26,7 @@ top_agents = self.agent.num_requests.items() top_agents.sort(self.sort_func) top_agents = top_agents[:50] - reply.setContent(top_agents) + reply.content = top_agents self.agent.send_message(reply) class StatusAgent(Agent): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jd...@us...> - 2006-11-24 17:52:25
|
Revision: 253 http://svn.sourceforge.net/spyse/?rev=253&view=rev Author: jdthood Date: 2006-11-24 09:52:23 -0800 (Fri, 24 Nov 2006) Log Message: ----------- underscorify encodeACL Modified Paths: -------------- spyse/core/content/codec.py spyse/core/content/content.py spyse/core/mts/mts.py spyse/core/platform/ams.py Modified: spyse/core/content/codec.py =================================================================== --- spyse/core/content/codec.py 2006-11-24 17:49:49 UTC (rev 252) +++ spyse/core/content/codec.py 2006-11-24 17:52:23 UTC (rev 253) @@ -30,7 +30,7 @@ class XMLCodec(ACLCodec): - def encodeACL(msg): + def encode_ACL(msg): domi = xml.dom.minidom.DOMImplementation() dtd = domi.createDocumentType(FIPA_MESSAGE, "FIPA ACL Message Representation in XML", "fipa.acl.rep.xml.std.dtd") dom = domi.createDocument(None, FIPA_MESSAGE, dtd) Modified: spyse/core/content/content.py =================================================================== --- spyse/core/content/content.py 2006-11-24 17:49:49 UTC (rev 252) +++ spyse/core/content/content.py 2006-11-24 17:52:23 UTC (rev 253) @@ -159,7 +159,7 @@ # Syntactic representation of ACL in bit-efficient form # <a href=http://www.fipa.org/specs/fipa00069/XC00069e.html>FIPA Spec</a> - def encodeACL(self): # FIPA ACL structure + def encode_ACL(self): # FIPA ACL structure return self def decode_ACL(self): # FIPA ACL structure Modified: spyse/core/mts/mts.py =================================================================== --- spyse/core/mts/mts.py 2006-11-24 17:49:49 UTC (rev 252) +++ spyse/core/mts/mts.py 2006-11-24 17:52:23 UTC (rev 253) @@ -20,7 +20,7 @@ def send(self, sender, msg): """Send message""" - newMsg = copy.deepcopy(msg.encodeACL()) + newMsg = copy.deepcopy(msg.encode_ACL()) newMsg.sender = sender # The send method should return True or False so the agent @@ -76,7 +76,7 @@ for rec in msg.receivers: agent = self.ams.get_agent(rec.shortname) if agent: - agent.receive_message(copy.deepcopy(msg.encodeACL())) + agent.receive_message(copy.deepcopy(msg.encode_ACL())) return True else: print 'MTS: Could not find receiving agent', rec.name Modified: spyse/core/platform/ams.py =================================================================== --- spyse/core/platform/ams.py 2006-11-24 17:49:49 UTC (rev 252) +++ spyse/core/platform/ams.py 2006-11-24 17:52:23 UTC (rev 253) @@ -741,7 +741,7 @@ print recname, 'not found' return - a.receive_message(copy.deepcopy(msg.encodeACL())) + a.receive_message(copy.deepcopy(msg.encode_ACL())) # Python-Docs-2.3.4/lib/module-copy.html # should take a look at pickling: Python-Docs-2.3.4/lib/module-pickle.html This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jd...@us...> - 2006-11-24 17:49:54
|
Revision: 252 http://svn.sourceforge.net/spyse/?rev=252&view=rev Author: jdthood Date: 2006-11-24 09:49:49 -0800 (Fri, 24 Nov 2006) Log Message: ----------- Empty more trash Removed Paths: ------------- spyse/demo/trash/dom_test.py spyse/demo/trash/xmlcodec.py Deleted: spyse/demo/trash/dom_test.py =================================================================== --- spyse/demo/trash/dom_test.py 2006-11-24 17:46:13 UTC (rev 251) +++ spyse/demo/trash/dom_test.py 2006-11-24 17:49:49 UTC (rev 252) @@ -1,455 +0,0 @@ -"""Spyse dom_test module""" - -# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/415983 -# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/220472 - -# http://pyxml.sourceforge.net/topics/howto/xml-howto.html -# http://www.leverkruid.nl/XML/index.html - -# http://xpipe.sourceforge.net/cgi-bin/doc.py?module=xml.marshal.generic - -import xml.dom.minidom - -#from xml.dom.minidom import DOMImplementation -from xml.dom import Node -from xml.dom.ext import PrettyPrint - -from spyse.core.agents.aid import AID -from spyse.core.agents.agent import Agent -from spyse.core.content.content import ACLMessage - -FIPA_MESSAGE = "fipa-message" -ACT = "act" -PERFORMATIVE = "performative" # Type of communicative acts -SENDER = "sender" # Participant in communication -RECEIVER = "receiver" # Participant in communication -REPLY_TO = "reply-to" # Participant in communication -CONTENT = "content" # Content of message -LANGUAGE = "language" # Description of content -ENCODING = "encoding" # Description of content -ONTOLOGY = "ontology" # Description of content -PROTOCOL = "protocol" # Control of conversation -CONVERSATION_ID = "conversation-id" # Control of conversation -REPLY_WITH = "reply-with" # Control of conversation -IN_REPLY_TO = "in-reply-to" # Control of conversation -REPLY_BY = "reply-by" # Control of conversation - -#================================================== - -def encodeACL(msg): - domi = xml.dom.minidom.DOMImplementation() - dtd = domi.createDocumentType(FIPA_MESSAGE, "FIPA ACL Message Representation in XML", "fipa.acl.rep.xml.std.dtd") - dom = domi.createDocument(None, FIPA_MESSAGE, dtd) - - fipa_msg = dom.getElementsByTagName(FIPA_MESSAGE).item(0) - - d = msg.performative - if d is not None: - __add_performative(dom, fipa_msg, d) - - d = msg.get_conversation_id() - if d is not None: - __add_conversation_id(dom, fipa_msg, d) - - d = msg.sender - if d is not None: - __add_sender(dom, fipa_msg, d) - - d = msg.getReceiver() - if d is not None: - __add_receiver(dom, fipa_msg, d) - - d = msg.getReplyTo() - if d is not None: - __add_reply_to(dom, fipa_msg, d) - - d = msg.getContent() - if d is not None: - __add_content(dom, fipa_msg, d) - - d = msg.getLanguage() - if d is not None: - __add_language(dom, fipa_msg, d) - - d = msg.getEncoding() - if d is not None: - __add_encoding(dom, fipa_msg, d) - - d = msg.getOntology() - if d is not None: - __add_ontology(dom, fipa_msg, d) - - d = msg.getProtocol() - if d is not None: - __add_protocol(dom, fipa_msg, d) - - d = msg.getReplyWith() - if d is not None: - __add_reply_with(dom, fipa_msg, d) - - d = msg.getInReplyTo() - if d is not None: - __add_in_reply_to(dom, fipa_msg, d) - - d = msg.getReplyBy() - if d is not None: - __add_reply_by(dom, fipa_msg, d) - -# print "\n" -# PrettyPrint(dom) -# print "\n" - - #return dom.toxml("utf-8") - return dom.toprettyxml() #TODO: replace by toxml() - -def __add_agent_identifier(dom, node, detail): - aid = dom.createElement("agent-identifier") - - # name - name = dom.createElement("name") - aid.appendChild(name) - #TODO: check whether id is used ==> refid - name.setAttribute("id", detail.name) - - # addresses - __add_addresses(dom, aid, detail.getHAP()) - - # resolvers - #__add_resolvers(dom, node, detail) - - # user-data - #__add_user_data(dom, node, detail) - - node.appendChild(aid) - -def __add_addresses(dom, node, detail): - addresses = dom.createElement("addresses") - url = dom.createElement("url") - url.setAttribute("href", detail) - addresses.appendChild(url) - node.appendChild(addresses) - -def __add_resolvers(dom, node, detail): - pass - -def __add_user_data(dom, node, detail): - pass - -def __add_performative(dom, node, detail): - node.setAttribute(ACT, detail) - -def __add_conversation_id(dom, node, detail): - node.setAttribute(CONVERSATION_ID, detail) - - conversation_id = dom.createElement(CONVERSATION_ID) - conversation_id.appendChild(dom.createTextNode(detail)) - node.appendChild(conversation_id) - -def __add_sender(dom, node, detail): - #sender = Element("sender") - #sender.nodeType = Node.ELEMENT_NODE - sender = dom.createElement("sender") - #fipa_msg.appendChild(sender) - __add_agent_identifier(dom, sender, detail) - - #sender.appendChild(dom.createTextNode('XML processing with Python')) - #return sender - node.appendChild(sender) - -def __add_receiver(dom, node, detail): - receiver = dom.createElement("receiver") - for r in detail: - aid = __add_agent_identifier(dom, receiver, r) - #receiver.appendChild(aid) - node.appendChild(receiver) - -def __add_reply_to(dom, node, detail): - reply_to = dom.createElement(REPLY_TO) - __add_agent_identifier(dom, reply_to, detail) - node.appendChild(reply_to) - -def __add_content(dom, node, detail): - content = dom.createElement(CONTENT) - content.appendChild(dom.createTextNode(detail)) - node.appendChild(content) - -def __add_language(dom, node, detail): - language = dom.createElement(LANGUAGE) - language.appendChild(dom.createTextNode(detail)) - node.appendChild(language) - -def __add_encoding(dom, node, detail): - encoding = dom.createElement(ENCODING) - encoding.appendChild(dom.createTextNode(detail)) - node.appendChild(encoding) - -def __add_ontology(dom, node, detail): - ontology = dom.createElement(ONTOLOGY) - ontology.appendChild(dom.createTextNode(detail)) - node.appendChild(ontology) - -def __add_protocol(dom, node, detail): - protocol = dom.createElement(PROTOCOL) - protocol.appendChild(dom.createTextNode(detail)) - node.appendChild(protocol) - -def __add_reply_with(dom, node, detail): - reply_with = dom.createElement(REPLY_WITH) - reply_with.appendChild(dom.createTextNode(detail)) - node.appendChild(reply_with) - -def __add_in_reply_to(dom, node, detail): - in_reply_to = dom.createElement(IN_REPLY_TO) - in_reply_to.appendChild(dom.createTextNode(detail)) - node.appendChild(in_reply_to) - -def __add_reply_by(dom, node, detail): - reply_by = dom.createElement(REPLY_BY) - reply_by.setAttribute('time', detail) - node.appendChild(reply_by) - -#================================================== - -def handleFipamessage(fipamessage, msg): -# handleSlideshowTitle(slideshow.getElementsByTagName("title")[0]) - performative = fipamessage.getAttribute(ACT) - if performative is not None: - msg.performative = performative - print ACT, performative - - sender = fipamessage.getElementsByTagName(SENDER)[0] - if sender is not None: handleSender(sender, msg) - - receiver = fipamessage.getElementsByTagName(RECEIVER)[0] - if receiver is not None: handleReceiver(receiver, msg) - - reply_to = fipamessage.getElementsByTagName(REPLY_TO)[0] - if reply_to is not None: handleReplyTo(reply_to, msg) - - content = fipamessage.getElementsByTagName(CONTENT)[0] - if content is not None: handleContent(content, msg) - - language = fipamessage.getElementsByTagName(LANGUAGE)[0] - if language is not None: handleLanguage(language, msg) - - encoding = fipamessage.getElementsByTagName(ENCODING)[0] - if encoding is not None: handleEncoding(encoding, msg) - - ontology = fipamessage.getElementsByTagName(ONTOLOGY)[0] - if ontology is not None: handleOntology(ontology, msg) - - protocol = fipamessage.getElementsByTagName(PROTOCOL)[0] - if protocol is not None: handleProtocol(protocol, msg) - - conversation_id = fipamessage.getElementsByTagName(CONVERSATION_ID)[0] - if conversation_id is not None: handleConversationId(conversation_id, msg) - - reply_with = fipamessage.getElementsByTagName(REPLY_WITH)[0] - if reply_with is not None: handleReplyWith(reply_with, msg) - - in_reply_to = fipamessage.getElementsByTagName(IN_REPLY_TO)[0] - if in_reply_to is not None: handleInReplyTo(in_reply_to, msg) - - reply_by = fipamessage.getElementsByTagName(REPLY_BY)[0] - if reply_by is not None: handleReplyBy(reply_by, msg) - -def handleSender(sender, msg): - print SENDER - aid = AID() - handleAID(sender.getElementsByTagName("agent-identifier")[0], aid) - msg.sender = aid - -def handleAID(agent, aid): - handleName(agent.getElementsByTagName("name")[0], aid) - handleAddresses(agent.getElementsByTagName("addresses")[0], aid) - #handleResolvers(agent.getElementsByTagName("resolvers")[0], aid) - #handleUserDefined(agent.getElementsByTagName("user-defined")[0], aid) - -def handleName(name, aid): - print "name" - id = name.getAttribute("id") - print "id", id - if id is None: - id = name.getAttribute("refid") - print "refid", id - aid.name = id - -def handleAddresses(addresses, aid): - print "addresses" - url = addresses.getElementsByTagName("url") - for u in url: - handleURL(u, aid) - -def handleURL(url, aid): - print "url" - href = url.getAttribute("href") - print "href", href - aid.addAddress(href) - -def handleReceiver(receiver, msg): - print RECEIVER - for r in receiver.getElementsByTagName("agent-identifier"): - aid = AID() - handleAID(r, aid) - msg.addReceiver(aid) - -def handleReplyTo(reply_to, msg): - print REPLY_TO - aid = AID() - handleAID(reply_to.getElementsByTagName("agent-identifier")[0], aid) - msg.setReplyTo(aid) - -def handleContent(content, msg): - print CONTENT - href = content.getAttribute("href") - print "href", href - value = content.firstChild.nodeValue.strip() - print value - msg.setContent(value) # TODO: href - -def handleLanguage(language, msg): - print LANGUAGE - href = language.getAttribute("href") - print "href", href - value = language.firstChild.nodeValue.strip() - print value - msg.setLanguage(value) # TODO: href - -def handleEncoding(encoding, msg): - print ENCODING - href = encoding.getAttribute("href") - print "href", href - value = encoding.firstChild.nodeValue.strip() - print value - msg.setEncoding(value) # TODO: href - -def handleOntology(ontology, msg): - print ONTOLOGY - href = ontology.getAttribute("href") - print "href", href - value = ontology.firstChild.nodeValue.strip() - print value - msg.setOntology(value) # TODO: href - -def handleProtocol(protocol, msg): - print PROTOCOL - href = protocol.getAttribute("href") - print "href", href - value = protocol.firstChild.nodeValue.strip() - print value - msg.setProtocol(value) # TODO: href - -def handleConversationId(conversation_id, msg): - print CONVERSATION_ID - href = conversation_id.getAttribute("href") - print "href", href - value = conversation_id.firstChild.nodeValue.strip() - print value - msg.set_conversation_id(value) # TODO: href - -def handleReplyWith(reply_with, msg): - print REPLY_WITH - href = reply_with.getAttribute("href") - print "href", href - value = reply_with.firstChild.nodeValue.strip() - print value - msg.setReplyWith(value) # TODO: href - -def handleInReplyTo(in_reply_to, msg): - print IN_REPLY_TO - href = in_reply_to.getAttribute("href") - print "href", href - value = in_reply_to.firstChild.nodeValue.strip() - print value - msg.setInReplyTo(value) # TODO: href - -def handleReplyBy(reply_by, msg): - print REPLY_BY - time = reply_by.getAttribute("time") - print "time", time - href = reply_by.getAttribute("href") - print "href", href - msg.setReplyBy(time) # TODO: href - -def decodeACL(emsg): - print "\n*** decoding ***\n" - msg = ACLMessage() - dom = xml.dom.minidom.parseString(emsg) - handleFipamessage(dom.getElementsByTagName(FIPA_MESSAGE)[0], msg) - return msg - -#================================================== - -a1 = Agent(AID("andre"), None) -a2 = Agent(AID("annicka"), None) -#a3 = Agent(42, None) - -msg = ACLMessage() -msg.performative = "request" -msg.set_conversation_id() -#msg.sender = "me...@py...:9000" -msg.sender = AID("meyer") -msg.addReceiver(AID("neef")) -msg.addReceiver(AID("vdvecht")) -msg.setReplyTo(AID("meyer")) -msg.setContent("42") -msg.setLanguage("FIPA ACL") -msg.setEncoding("RDF") -msg.setOntology("spyse-onto") -msg.setProtocol("contract-net") -msg.setReplyWith("propose") -msg.setInReplyTo("007") -msg.setReplyBy("23:59") - - -emsg = encodeACL(msg) -if emsg is not None: print "\n" + emsg - -def printobj(obj): - print obj - if obj is not None: - for a in vars(obj): - print '-', a, '=', getattr(obj, a) - -#================================================== -#def printobj_rec(obj, level=1): # TODO: add recursive printing of lists and dicts -# if obj is not None: -# print type(obj), obj -# try: -# for a in vars(obj): -# print (level) * ' -', a, '=', #getattr(obj, a) -# printobj_rec(getattr(obj, a), level+1) -# except: -# pass -#================================================== - -def printobj_rec(obj, level=1): -# """Prints any object with all of its attributes recursively.""" -# if obj is not None: - t = type(obj) - print t, obj - if t is list: - for i, e in zip(range(len(obj)), obj): - print (level) * ' -', i, ':', - printobj_rec(obj[i], level+1) - elif t is dict: - for i, e in obj.items(): - print (level) * ' -', i, ':', - printobj_rec(obj[i], level+1) -# elif isinstance(obj, object): - try: - for a in vars(obj): - print (level) * ' -', a, '=', #getattr(obj, a) - printobj_rec(getattr(obj, a), level+1) - except: - pass - -dmsg = decodeACL(emsg) -printobj_rec(dmsg) - -#print -#printobj_rec(type(dmsg)) - -#print dmsg.__dict__ -#print dir(dmsg) - Deleted: spyse/demo/trash/xmlcodec.py =================================================================== --- spyse/demo/trash/xmlcodec.py 2006-11-24 17:46:13 UTC (rev 251) +++ spyse/demo/trash/xmlcodec.py 2006-11-24 17:49:49 UTC (rev 252) @@ -1,379 +0,0 @@ -import xml.dom.minidom - -#from xml.dom.minidom import DOMImplementation -from xml.dom import Node -#from xml.dom.ext import PrettyPrint -import pickle - -from spyse.core.agents.aid import AID -from spyse.core.agents.agent import Agent -from spyse.core.content.content import ACLMessage - -FIPA_MESSAGE = "fipa-message" -ACT = "act" -PERFORMATIVE = "performative" # Type of communicative acts -SENDER = "sender" # Participant in communication -RECEIVER = "receiver" # Participant in communication -REPLY_TO = "reply-to" # Participant in communication -CONTENT = "content" # Content of message -LANGUAGE = "language" # Description of Content -ENCODING = "encoding" # Description of Content -ONTOLOGY = "ontology" # Description of Content -PROTOCOL = "protocol" # Control of conversation -CONVERSATION_ID = "conversation-id" # Control of conversation -REPLY_WITH = "reply-with" # Control of conversation -IN_REPLY_TO = "in-reply-to" # Control of conversation -REPLY_BY = "reply-by" # Control of conversation - -def encodeACL(msg): - domi = xml.dom.minidom.DOMImplementation() - dtd = domi.createDocumentType(FIPA_MESSAGE, "FIPA ACL Message Representation in XML", "fipa.acl.rep.xml.std.dtd") - dom = domi.createDocument(None, FIPA_MESSAGE, dtd) - - fipa_msg = dom.getElementsByTagName(FIPA_MESSAGE).item(0) - - d = msg.performative - if d is not None: - __add_performative(dom, fipa_msg, d) - - d = msg.get_conversation_id() - if d is not None: - __add_conversation_id(dom, fipa_msg, d) - - d = msg.sender - if d is not None: - __add_sender(dom, fipa_msg, d) - - d = msg.getReceiver() - if d is not None: - __add_receiver(dom, fipa_msg, d) - - d = msg.getReplyTo() - if d is not None: - __add_reply_to(dom, fipa_msg, d) - - d = msg.getContent() - if d is not None: - __add_content(dom, fipa_msg, d) - - d = msg.getLanguage() - if d is not None: - __add_language(dom, fipa_msg, d) - - d = msg.getEncoding() - if d is not None: - __add_encoding(dom, fipa_msg, d) - - d = msg.getOntology() - if d is not None: - __add_ontology(dom, fipa_msg, d) - - d = msg.getProtocol() - if d is not None: - __add_protocol(dom, fipa_msg, d) - - d = msg.getReplyWith() - if d is not None: - __add_reply_with(dom, fipa_msg, d) - - d = msg.getInReplyTo() - if d is not None: - __add_in_reply_to(dom, fipa_msg, d) - - d = msg.getReplyBy() - if d is not None: - __add_reply_by(dom, fipa_msg, d) - - #return dom.toxml("utf-8") - return dom.toprettyxml() #TODO: replace by toxml() - -def __add_agent_identifier(dom, node, detail): - aid = dom.createElement("agent-identifier") - - # name - name = dom.createElement("name") - aid.appendChild(name) - #TODO: check whether id is used ==> refid - name.setAttribute("id", detail.name) - - # addresses - #__add_addresses(dom, aid, detail.getHAP()) - - # resolvers - #__add_resolvers(dom, node, detail) - - # user-data - #__add_user_data(dom, node, detail) - - node.appendChild(aid) - -def __add_addresses(dom, node, detail): - addresses = dom.createElement("addresses") - url = dom.createElement("url") - url.setAttribute("href", detail) - addresses.appendChild(url) - node.appendChild(addresses) - -def __add_resolvers(dom, node, detail): - pass - -def __add_user_data(dom, node, detail): - pass - -def __add_performative(dom, node, detail): - node.setAttribute(ACT, detail) - -def __add_conversation_id(dom, node, detail): - node.setAttribute(CONVERSATION_ID, detail) - - conversation_id = dom.createElement(CONVERSATION_ID) - conversation_id.appendChild(dom.createTextNode(detail)) - node.appendChild(conversation_id) - -def __add_sender(dom, node, detail): - #sender = Element("sender") - #sender.nodeType = Node.ELEMENT_NODE - sender = dom.createElement("sender") - #fipa_msg.appendChild(sender) - __add_agent_identifier(dom, sender, detail) - - #sender.appendChild(dom.createTextNode('XML processing with Python')) - #return sender - node.appendChild(sender) - -def __add_receiver(dom, node, detail): - receiver = dom.createElement("receiver") - for r in detail: - aid = __add_agent_identifier(dom, receiver, r) - #receiver.appendChild(aid) - node.appendChild(receiver) - -def __add_reply_to(dom, node, detail): - reply_to = dom.createElement(REPLY_TO) - __add_agent_identifier(dom, reply_to, detail) - node.appendChild(reply_to) - -def __add_content(dom, node, detail): - content = dom.createElement(CONTENT) - - # String Pickle - s = pickle.dumps(detail) - content.appendChild(dom.createTextNode(s)) - - #content.appendChild(dom.createTextNode(detail)) - node.appendChild(content) - -def __add_language(dom, node, detail): - language = dom.createElement(LANGUAGE) - language.appendChild(dom.createTextNode(detail)) - node.appendChild(language) - -def __add_encoding(dom, node, detail): - encoding = dom.createElement(ENCODING) - encoding.appendChild(dom.createTextNode(detail)) - node.appendChild(encoding) - -def __add_ontology(dom, node, detail): - ontology = dom.createElement(ONTOLOGY) - ontology.appendChild(dom.createTextNode(detail)) - node.appendChild(ontology) - -def __add_protocol(dom, node, detail): - protocol = dom.createElement(PROTOCOL) - protocol.appendChild(dom.createTextNode(detail)) - node.appendChild(protocol) - -def __add_reply_with(dom, node, detail): - reply_with = dom.createElement(REPLY_WITH) - reply_with.appendChild(dom.createTextNode(detail)) - node.appendChild(reply_with) - -def __add_in_reply_to(dom, node, detail): - in_reply_to = dom.createElement(IN_REPLY_TO) - in_reply_to.appendChild(dom.createTextNode(detail)) - node.appendChild(in_reply_to) - -def __add_reply_by(dom, node, detail): - reply_by = dom.createElement(REPLY_BY) - reply_by.setAttribute('time', detail) - node.appendChild(reply_by) - -#================================================== - -def decodeACL(emsg): - print "\n*** decoding ***\n" - msg = ACLMessage() - dom = xml.dom.minidom.parseString(emsg) - __handleFipamessage(dom.getElementsByTagName(FIPA_MESSAGE)[0], msg) - return msg - -def __handleFipamessage(fipamessage, msg): - performative = fipamessage.getAttribute(ACT) - if performative is not None: - msg.performative = performative - print ACT, performative - - sender = fipamessage.getElementsByTagName(SENDER)[0] - if sender is not None: __handleSender(sender, msg) - - receiver = fipamessage.getElementsByTagName(RECEIVER)[0] - if receiver is not None: __handleReceiver(receiver, msg) - - reply_to = fipamessage.getElementsByTagName(REPLY_TO) - if len(reply_to) != 0: __handleReplyTo(reply_to[0], msg) - - content = fipamessage.getElementsByTagName(CONTENT) - if len(content) != 0: __handleContent(content[0], msg) - - language = fipamessage.getElementsByTagName(LANGUAGE) - if len(language) != 0: __handleLanguage(language[0], msg) - - encoding = fipamessage.getElementsByTagName(ENCODING) - if len(encoding) != 0: __handleEncoding(encoding[0], msg) - - ontology = fipamessage.getElementsByTagName(ONTOLOGY) - if len(ontology) != 0: __handleOntology(ontology[0], msg) - - protocol = fipamessage.getElementsByTagName(PROTOCOL) - if len(protocol) != 0: __handleProtocol(protocol[0], msg) - - conversation_id = fipamessage.getElementsByTagName(CONVERSATION_ID) - if len(conversation_id) != 0: __handleConversationId(conversation_id[0], msg) - - reply_with = fipamessage.getElementsByTagName(REPLY_WITH) - if len(reply_with) != 0: __handleReplyWith(reply_with[0], msg) - - in_reply_to = fipamessage.getElementsByTagName(IN_REPLY_TO) - if len(in_reply_to) != 0: __handleInReplyTo(in_reply_to[0], msg) - - reply_by = fipamessage.getElementsByTagName(REPLY_BY) - if len(reply_by) != 0: __handleReplyBy(reply_by[0], msg) - -def __handleSender(sender, msg): - print SENDER - aid = AID() - __handleAID(sender.getElementsByTagName("agent-identifier")[0], aid) - msg.sender = aid - -def __handleAID(agent, aid): - __handleName(agent.getElementsByTagName("name")[0], aid) - #__handleAddresses(agent.getElementsByTagName("addresses")[0], aid) - #__handleResolvers(agent.getElementsByTagName("resolvers")[0], aid) - #__handleUserDefined(agent.getElementsByTagName("user-defined")[0], aid) - -def __handleName(name, aid): - print "name" - id = name.getAttribute("id") - print "id", id - if id is None: - id = name.getAttribute("refid") - print "refid", id - - if type(id) is unicode: - id = str(id) - aid.name = id - -def __handleAddresses(addresses, aid): - print "addresses" - url = addresses.getElementsByTagName("url") - for u in url: - __handleURL(u, aid) - -def __handleURL(url, aid): - print "url" - href = url.getAttribute("href") - print "href", href - - if type(href) is unicode: - href = str(href) - aid.addAddress(href) - -def __handleReceiver(receiver, msg): - print RECEIVER - for r in receiver.getElementsByTagName("agent-identifier"): - aid = AID() - __handleAID(r, aid) - msg.addReceiver(aid) - -def __handleReplyTo(reply_to, msg): - print REPLY_TO - aid = AID() - __handleAID(reply_to.getElementsByTagName("agent-identifier")[0], aid) - msg.setReplyTo(aid) - -def __handleContent(content, msg): - print CONTENT - href = content.getAttribute("href") - print "href", href - value = content.firstChild.nodeValue.strip() - print value - - # String Pickle - value = pickle.loads(str(value)) - - msg.setContent(value) # TODO: href - -def __handleLanguage(language, msg): - print LANGUAGE - href = language.getAttribute("href") - print "href", href - value = language.firstChild.nodeValue.strip() - print value - msg.setLanguage(value) # TODO: href - -def __handleEncoding(encoding, msg): - print ENCODING - href = encoding.getAttribute("href") - print "href", href - value = encoding.firstChild.nodeValue.strip() - print value - msg.setEncoding(value) # TODO: href - -def __handleOntology(ontology, msg): - print ONTOLOGY - href = ontology.getAttribute("href") - print "href", href - value = ontology.firstChild.nodeValue.strip() - print value - msg.setOntology(value) # TODO: href - -def __handleProtocol(protocol, msg): - print PROTOCOL - href = protocol.getAttribute("href") - print "href", href - value = protocol.firstChild.nodeValue.strip() - print value - msg.setProtocol(value) # TODO: href - -def __handleConversationId(conversation_id, msg): - print CONVERSATION_ID - href = conversation_id.getAttribute("href") - print "href", href - value = conversation_id.firstChild.nodeValue.strip() - print value - msg.set_conversation_id(value) # TODO: href - -def __handleReplyWith(reply_with, msg): - print REPLY_WITH - href = reply_with.getAttribute("href") - print "href", href - value = reply_with.firstChild.nodeValue.strip() - print value - msg.setReplyWith(value) # TODO: href - -def __handleInReplyTo(in_reply_to, msg): - print IN_REPLY_TO - href = in_reply_to.getAttribute("href") - print "href", href - value = in_reply_to.firstChild.nodeValue.strip() - print value - msg.setInReplyTo(value) # TODO: href - -def __handleReplyBy(reply_by, msg): - print REPLY_BY - time = reply_by.getAttribute("time") - print "time", time - href = reply_by.getAttribute("href") - print "href", href - msg.setReplyBy(time) # TODO: href - This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jd...@us...> - 2006-11-24 17:46:15
|
Revision: 251 http://svn.sourceforge.net/spyse/?rev=251&view=rev Author: jdthood Date: 2006-11-24 09:46:13 -0800 (Fri, 24 Nov 2006) Log Message: ----------- Eliminate spython.py Removed Paths: ------------- spyse/demo/trash/spython.py Deleted: spyse/demo/trash/spython.py =================================================================== --- spyse/demo/trash/spython.py 2006-11-24 17:45:53 UTC (rev 250) +++ spyse/demo/trash/spython.py 2006-11-24 17:46:13 UTC (rev 251) @@ -1,360 +0,0 @@ -#!/usr/bin/env python - -"""Spyse demo OUT OF DATE""" - -# red hot chili peppers, tabasco, jalapeno, yellow, green, red, black, Chili Con Queso/Carne - -#TODO FIPA-ACL -#TODO OWL ontologies -#TODO swap semweb platform -#TODO swap/surnia reasoning -#TODO mobility -#TODO pyro/http for remote communication -#TODO bdi behaviour -#TODO Zope agent, ZPT -#TODO wxPython agent -#TODO fsm behaviour -#TODO protocols -#TODO encoding -#TODO - -import threading -import Queue -import time -import random - -INITIATED = 0 -ACTIVE = 1 -SUSPENDED = 2 -WAITING = 3 -TRANSIT = 4 - -class Behaviour(object): - def __init__(self, agent=None, args=None): - self.__agent = agent - self.__done = False - self.setup(args) - - def setup(self, args): - # Override for initialisation, instead of __init__ - pass - print 'setup of', type(self) - - def action(self): - # Override in subclasses with specific behaviour - pass - - def getAgent(self): - return self.__agent - - def set_done(self): - self.__done = True - - def done(self): - return self.__done - -class BDIBehaviour(Behaviour): - pass - -class FSMBehaviour(Behaviour): - pass - -class CounterBehaviour(Behaviour): - def __init__(self): - self.__lock = threading.Lock() - self.__value = 0 - - def increment(self): - self.__lock.acquire() # critical section - #if self.__lock.locked(): maybe not necessary ??? - self.__value = value = self.value + 1 - self.__lock.release() - return value - -counter = CounterBehaviour() - -class Agent(threading.Thread): - def __init__(self, name, ams, args=None): - self.__state = INITIATED - self.__ams = ams - self.__behaviours = [] - self.__queue = Queue.Queue() # private, not visible in subclasses, use accessors instead - threading.Thread.__init__(self) - self.setName(name) - ## make distinction between given name and system name (incl. platform key) - print 'Agent', name, 'is inited.' - self.setup(args) - - def setup(self, args): - # Override for initialisation, instead of __init__ - pass - print 'setup of', self.getName() - - def run(self, args): - while True: - # run through all behaviours, executing their action() - if self.__behaviours and len(self.__behaviours) > 0: - for b in self.__behaviours: - b.action() - if b.done(): - self.remove_behaviour(b) - else: break - - def read_message(self): - return self.__queue.get() - - def receive_message(self, msg): - self.__queue.put(msg) - - def send_message(self, msg): - self.__ams.send(msg) - - def add_behaviour(self, b): - # FIXME: Check whether subclass of Behaviour - self.__behaviours.append(b) - - def remove_behaviour(self, b): - self.__behaviours.remove(b) - -def createClass(className): - return getitem(globals(),className)() -# class Dummy: -# pass -# answer = Dummy() -# answer.__class__.__name__ = name -# return answer -# map( createClass, [ "foo", "bar", "and", "the", "like" ] ) - -#def factory(aClass, *args): # varargs tuple -# #aClass = globals()[aClassName]() -# return apply(aClass, args) # call aClass -# -class AMS(Agent): - """ Agent Management Service agent, aka White Pages""" - def __init__(self): - self.__registry = {} - Agent.__init__(self, 'AMS', None) - - def register_agent(self, agent): - name = agent.getName() - if self.__registry.get(name): - print 'An agent with the name', name, 'is already registered.' - else: - self.__registry[agent.getName()] = agent - print 'Agent', name, 'is registered.' - - def create_agent(self, cls=None, name=None, args=None): - # create an agent of class cls with name name - - agent = cls(name, self, args) - #print agent - #print agent.getName() - agent.setup(args) - self.register_agent(agent) - agent.start() - - def findAgent(self, name): - return name - - def send(self, msg): - "Send an ACL message to recipients." - # check whether on same platform - # otherwise send via pyro (other spy) or http (eg. JADE) - for rec in msg.getReceivers(): - a = self.__registry.get(rec) - if a: - a.receive_message(msg) - return True - else: - print a.getName(), 'not found' - return False - -class DF(Agent): - """ Directory Facilitator agent, aka Yellow Pages""" - def __init__(self): - self.__registry = {} - Agent.__init__(self, 'DF', None) - - def register_agent(self, agent): - self.__registry[agent.getName()] = agent - - def findAgent(self, name): - return name - -class CounterAgent(Agent): - def run(self): - for i in range(10): - # schedule all behaviours to run sequentially at random - - # pretend we're doing something that takes 10-100 ms - value = counter.increment() # increment global counter - time.sleep(random.randint(10, 100) / 1000.0) - print self.getName(), "-- task", i, "finished", value - -class QueueAgent(Agent): - def run(self): - while 1: - msg = self.read_message() - item = msg.getContent() - if item is None: - break # reached end of queue - # pretend we're doing something that takes 10-100 ms - time.sleep(random.randint(10, 100) / 1000.0) - print self.getName(), "task", item, "finished" - -class SenderBehaviour(Behaviour): - def setup(self, args): - self.__i = args - - def action(self): - #a = getAMS().findAgent("Receiver") - if self.__i > 0: - self.__i = self.__i-1 - msg = ACLMessage(ACLMessage.INFORM) - msg.addReceiver('Receiver') - msg.setContent(self.__i) - self.getAgent().send_message(msg) - print self.getAgent().getName(), "task", self.__i, "started" - # pretend we're doing something that takes 10-100 ms - time.sleep(random.randint(10, 100) / 1000.0) - else: - msg = ACLMessage(ACLMessage.INFORM) - msg.addReceiver('Receiver') - msg.setContent(None) - self.set_done() - self.getAgent().send_message(msg) - -class SenderAgent(Agent): - def setup(self, args): - self.add_behaviour(SenderBehaviour(self, 18)) - -class ReceiverBehaviour(Behaviour): - def setup(self, args): - self.__i = args - - def action(self): - msg = self.getAgent().read_message() - if msg: - item = msg.getContent() - if item is None: - self.set_done() - else: - # pretend we're doing something that takes 10-100 ms - time.sleep(random.randint(10, 100) / 1000.0) - print self.getAgent().getName(), "task", item, "finished" - -class ReceiverAgent(Agent): - def setup(self, args): - self.add_behaviour(ReceiverBehaviour(self)) - -class ZopeAgent(Agent): - """ A Zope Web UI agent """ - pass - # write stdout to zpt - # ZopeAgent provides hooks for ZPT to display agent state - # make Spyth a Zope product - # edit agents via ZMI - -class wxAgent(Agent): - """ A wxPython UI agent """ - pass - -class ACLMessage(object): - # constants identifying the FIPA performatives - ACCEPT_PROPOSAL = 0 - AGREE = 1 - CANCEL = 2 - CFP = 3 - CONFIRM = 4 - DISCONFIRM = 5 - FAILURE = 6 - INFORM = 7 - INFORM_IF = 8 - INFORM_REF = 9 - NOT_UNDERSTOOD = 10 - PROPAGATE = 21 - PROPOSE = 11 - PROXY = 20 - QUERY_IF = 12 - QUERY_REF = 13 - REFUSE = 14 - REJECT_PROPOSAL = 15 - REQUEST = 16 - REQUEST_WHEN = 17 - REQUEST_WHENEVER = 18 - SUBSCRIBE = 19 - UNKNOWN = -1 - - def __init__(self, performative): - self.__sender = None - self.__receivers = [] - self.__performative = performative - - def setSender(self, sender): - assert isinstance(sender, str), 'Trying to set a sender that is not of type str') - self.__sender = sender - - def addReceiver(self, receiver): - self.__receivers.append(receiver) - - def getReceivers(self): - return self.__receivers - - def setPerformative(self, performative): - self.__performative = performative - - def setProtocol(self, protocol): - self.__protocol = protocol - - def setEncoding(self, encoding): - self.__encoding = encoding - - def setLanguage(self, language): - self.__language = language - - def setOntology(self, ontology): - self.__ontology = ontology - - def setContent(self, content): - self.__content = content - - def getContent(self): - return self.__content - -__ams = AMS() - -def getAMS(self): - return self.__ams - -# -# Counter Test -#for i in range(10): -# Agent().start() # start an agent - -# -# Queue Test -#AGENTS = 3 -#queue = Queue.Queue(0) -#for i in range(AGENTS): -# qa = QueueAgent(queue) -# qa.start() # start a queue agent -# -#for i in range(18): -# queue.put(i) -# -#for i in range(AGENTS): -# queue.put(None) # add end-of-queue markers - -# -# Sender Test - -#qa = QueueAgent('Receiver', __ams) -__ams.create_agent(ReceiverAgent, 'Receiver') -#qa.start() # start a Queue agent - -#sa = SenderAgent('Sender', __ams) -#__ams.register_agent(sa) -#sa.start() # start a Sender agent -__ams.create_agent(SenderAgent, 'Sender') -#sa.start() - This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jd...@us...> - 2006-11-24 17:45:55
|
Revision: 250 http://svn.sourceforge.net/spyse/?rev=250&view=rev Author: jdthood Date: 2006-11-24 09:45:53 -0800 (Fri, 24 Nov 2006) Log Message: ----------- Eliminate addReceiver method Modified Paths: -------------- spyse/core/content/codec.py spyse/core/content/content.py spyse/core/mts/mts.py spyse/core/protocols/contractnet.py spyse/core/protocols/request.py spyse/core/protocols/subscription.py spyse/demo/communication.py spyse/demo/remote/client.py spyse/demo/remote/server.py spyse/demo/token_pass.py spyse/ibas/iba.py spyse/ibas/interface_agent.py spyse/ibas/logger_agent.py Modified: spyse/core/content/codec.py =================================================================== --- spyse/core/content/codec.py 2006-11-24 17:26:12 UTC (rev 249) +++ spyse/core/content/codec.py 2006-11-24 17:45:53 UTC (rev 250) @@ -285,7 +285,7 @@ for r in receiver.getElementsByTagName("agent-identifier"): aid = AID() __handleAID(r, aid) - msg.addReceiver(aid) + msg.receivers.add(aid) def __handleReplyTo(reply_to, msg): print REPLY_TO Modified: spyse/core/content/content.py =================================================================== --- spyse/core/content/content.py 2006-11-24 17:26:12 UTC (rev 249) +++ spyse/core/content/content.py 2006-11-24 17:45:53 UTC (rev 250) @@ -60,28 +60,6 @@ self.performative = performative # - # Standard attribute getters and setters - # - # DEPRECATED. Use attributes directly. - # - - def setReceiver(self, receiver): - self.clearReceiver() - if not receiver is None: - assert isinstance(receiver, AID), "Trying to set receiver that is not an AID" - self.addReceiver(receiver) - - def addReceiver(self, receiver): - assert isinstance(receiver, AID), "Trying to set receiver that is not an AID" - self.receivers.append(receiver) - - def clearReceiver(self): - self.receivers = [] - - def getReceiver(self): - return self.receivers - - # # Nonstandard attribute getters and setters # # DEPRECATED. Use attributes directly. @@ -158,7 +136,7 @@ def __init__(self, performative=None): # Set mandatory attributes self.sender = None - self.receivers = [] + self.receivers = set() MessageTemplate.__init__(self, performative); def set_conversation_id(self): @@ -168,7 +146,7 @@ def createReply(self, performative=MessageTemplate.AGREE): reply = copy.copy(self) reply.performative = performative - reply.receivers = [reply.sender] + reply.receivers = set([reply.sender]) reply.content = None reply.sender = None return reply Modified: spyse/core/mts/mts.py =================================================================== --- spyse/core/mts/mts.py 2006-11-24 17:26:12 UTC (rev 249) +++ spyse/core/mts/mts.py 2006-11-24 17:45:53 UTC (rev 250) @@ -26,7 +26,7 @@ # The send method should return True or False so the agent # knows if the message is successfully delivered res = False - for rec in msg.getReceiver(): + for rec in msg.receivers: res = self.__deliver_to(newMsg, rec) return res Modified: spyse/core/protocols/contractnet.py =================================================================== --- spyse/core/protocols/contractnet.py 2006-11-24 17:26:12 UTC (rev 249) +++ spyse/core/protocols/contractnet.py 2006-11-24 17:45:53 UTC (rev 250) @@ -65,7 +65,7 @@ # try: providers = self.datastore[ContractNetInitiatorBehaviour.providers_key] for p in providers: - msg.addReceiver(p) + msg.receivers.add(p) msg.content = self.datastore['call'] msg.set_conversation_id() self.agent.send_message(msg) Modified: spyse/core/protocols/request.py =================================================================== --- spyse/core/protocols/request.py 2006-11-24 17:26:12 UTC (rev 249) +++ spyse/core/protocols/request.py 2006-11-24 17:45:53 UTC (rev 250) @@ -266,7 +266,7 @@ def sub_action(self): msg = ACLMessage(ACLMessage.REQUEST) - msg.addReceiver(self.datastore[store_key]) + msg.receivers.add(self.datastore[store_key]) msg.content = self.datastore[request_key] msg.set_conversation_id() self.datastore[conversation_key] = msg.conversation_id @@ -394,7 +394,7 @@ def action(self): # Override action, not sub_action self.cancel() msg = ACLMessage(ACLMessage.CANCEL) - msg.addReceiver(self.datastore[subscription_key]) + msg.receivers.add(self.datastore[subscription_key]) msg.conversation_id = self.datastore[conversation_key] self.agent.send_message(msg) self.result = CANCEL_REQUESTED Modified: spyse/core/protocols/subscription.py =================================================================== --- spyse/core/protocols/subscription.py 2006-11-24 17:26:12 UTC (rev 249) +++ spyse/core/protocols/subscription.py 2006-11-24 17:45:53 UTC (rev 250) @@ -126,7 +126,7 @@ notification = self.send_notifications() msg = ACLMessage(ACLMessage.INFORM) for subscriber in self.datastore[subscribers_key]: - msg.addReceiver(subscriber) + msg.receivers.add(subscriber) msg.content = notification self.agent.send_message(msg) self.result = NOTIFIED @@ -251,7 +251,7 @@ def sub_action(self): msg = ACLMessage(ACLMessage.SUBSCRIBE) - msg.addReceiver(self.datastore[subscription_key]) + msg.receivers.add(self.datastore[subscription_key]) msg.content = self.content msg.set_conversation_id() self.agent.send_message(msg) @@ -384,7 +384,7 @@ def action(self): # Override action, not sub_action self.cancel() msg = ACLMessage(ACLMessage.CANCEL) - msg.addReceiver(self.datastore[subscription_key]) + msg.receivers.add(self.datastore[subscription_key]) self.agent.send_message(msg) self.result = CANCEL_REQUESTED Modified: spyse/demo/communication.py =================================================================== --- spyse/demo/communication.py 2006-11-24 17:26:12 UTC (rev 249) +++ spyse/demo/communication.py 2006-11-24 17:45:53 UTC (rev 250) @@ -21,9 +21,9 @@ def action(self): msg = ACLMessage(ACLMessage.INFORM) - msg.addReceiver(AID('Cooter')) - msg.addReceiver(AID('Lester')) - msg.addReceiver(AID('Snoopy')) + msg.receivers.add(AID('Cooter')) + msg.receivers.add(AID('Lester')) + msg.receivers.add(AID('Snoopy')) if self.__iterations > 0: content = self.agent.name + "/" + str(self.__iterations) else: Modified: spyse/demo/remote/client.py =================================================================== --- spyse/demo/remote/client.py 2006-11-24 17:26:12 UTC (rev 249) +++ spyse/demo/remote/client.py 2006-11-24 17:45:53 UTC (rev 250) @@ -19,7 +19,7 @@ def action(self): msg = ACLMessage(ACLMessage.INFORM) - msg.addReceiver(self.__criers[0]) + msg.receivers.add(self.__criers[0]) msg.content = self.__i self.__i += 1 print "Sending a request" Modified: spyse/demo/remote/server.py =================================================================== --- spyse/demo/remote/server.py 2006-11-24 17:26:12 UTC (rev 249) +++ spyse/demo/remote/server.py 2006-11-24 17:45:53 UTC (rev 250) @@ -23,7 +23,7 @@ return print "Received a cry request" reply = ACLMessage(ACLMessage.INFORM) - reply.addReceiver(msg.sender) + reply.receivers.add(msg.sender) reply.content = self.agent.cry(item) self.agent.send_message(reply) Modified: spyse/demo/token_pass.py =================================================================== --- spyse/demo/token_pass.py 2006-11-24 17:26:12 UTC (rev 249) +++ spyse/demo/token_pass.py 2006-11-24 17:45:53 UTC (rev 250) @@ -87,7 +87,7 @@ if perf == ACLMessage.INFORM: # if we have received a list from the DF p = content[ random.randint(0, len(content)-1)] msg = ACLMessage(ACLMessage.INFORM_REF) - msg.addReceiver(p) + msg.receivers.add(p) msg.content = self.agent.token self.agent.send_message(msg) self.agent.token=None Modified: spyse/ibas/iba.py =================================================================== --- spyse/ibas/iba.py 2006-11-24 17:26:12 UTC (rev 249) +++ spyse/ibas/iba.py 2006-11-24 17:45:53 UTC (rev 250) @@ -60,7 +60,7 @@ threading.Thread(target = self.__check, args=()).start() elif self.result != "": msg = ACLMessage(ACLMessage.INFORM) - msg.addReceiver(AID('Logger Agent')) + msg.receivers.add(AID('Logger Agent')) msg.setContent(self.result) self.agent.send_message(msg) self.agent.check_time = datetime.now() + ONE_HOUR @@ -147,7 +147,7 @@ self.move_time = datetime.now() + ONE_MINUTE self.num_requests = self.num_requests + 1 msg = ACLMessage(ACLMessage.INFORM) - msg.addReceiver(AID('Status Agent')) + msg.receivers.add(AID('Status Agent')) msg.setContent(self.num_requests) self.send_message(msg) @@ -188,4 +188,4 @@ def _send_result(self): self.last_checked = datetime.now() return self.result - \ No newline at end of file + Modified: spyse/ibas/interface_agent.py =================================================================== --- spyse/ibas/interface_agent.py 2006-11-24 17:26:12 UTC (rev 249) +++ spyse/ibas/interface_agent.py 2006-11-24 17:45:53 UTC (rev 250) @@ -41,7 +41,7 @@ def get_num_requests(self): msg = ACLMessage(ACLMessage.REQUEST) - msg.addReceiver(AID('Status Agent')) + msg.receivers.add(AID('Status Agent')) self.send_message(msg) res = self.get_message() while res is None: @@ -51,7 +51,7 @@ def get_log(self): msg = ACLMessage(ACLMessage.REQUEST) - msg.addReceiver(AID('Logger Agent')) + msg.receivers.add(AID('Logger Agent')) self.send_message(msg) res = self.get_message() while res is None: Modified: spyse/ibas/logger_agent.py =================================================================== --- spyse/ibas/logger_agent.py 2006-11-24 17:26:12 UTC (rev 249) +++ spyse/ibas/logger_agent.py 2006-11-24 17:45:53 UTC (rev 250) @@ -20,7 +20,7 @@ self.agent.messages.append(msg.sender.shortname+"#"+msg.content) elif msg.performative == ACLMessage.REQUEST: reply = ACLMessage(ACLMessage.INFORM) - reply.addReceiver(msg.sender) + reply.receivers.add(msg.sender) reply.setContent(self.agent.messages) self.agent.send_message(reply) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jd...@us...> - 2006-11-24 17:26:13
|
Revision: 249 http://svn.sourceforge.net/spyse/?rev=249&view=rev Author: jdthood Date: 2006-11-24 09:26:12 -0800 (Fri, 24 Nov 2006) Log Message: ----------- Remove traces of legacy fsm interface Modified Paths: -------------- spyse/core/behaviours/fsm.py Modified: spyse/core/behaviours/fsm.py =================================================================== --- spyse/core/behaviours/fsm.py 2006-11-24 17:25:09 UTC (rev 248) +++ spyse/core/behaviours/fsm.py 2006-11-24 17:26:12 UTC (rev 249) @@ -47,8 +47,6 @@ def __init__(self, name='', **namedargs): self._states = set() # Warning: may not include self.first_state self.first_state = None - self.__lastState = None # For legacy interface only - # For new interface, None is the last state super(FSMBehaviour, self).__init__(name, **namedargs) def get_behaviours(self): @@ -78,8 +76,6 @@ return None if target is None: self.set_done() - if target is self.__lastState: # For legacy interface - self.set_done() return target def _add_state(self, state): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |