[GRASS-SVN] r56265 - in grass-addons/grass7/raster/r.agent: . libagent tests
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed May 15 07:26:28 PDT 2013
Author: mic
Date: 2013-05-15 07:26:26 -0700 (Wed, 15 May 2013)
New Revision: 56265
Modified:
grass-addons/grass7/raster/r.agent/libagent/ant.py
grass-addons/grass7/raster/r.agent/libagent/anthill.py
grass-addons/grass7/raster/r.agent/libagent/world.py
grass-addons/grass7/raster/r.agent/r.agent.aco
grass-addons/grass7/raster/r.agent/tests/test_ant.py
grass-addons/grass7/raster/r.agent/tests/test_anthill.py
Log:
move inner loop to world and add ant work
Modified: grass-addons/grass7/raster/r.agent/libagent/ant.py
===================================================================
--- grass-addons/grass7/raster/r.agent/libagent/ant.py 2013-05-15 14:25:44 UTC (rev 56264)
+++ grass-addons/grass7/raster/r.agent/libagent/ant.py 2013-05-15 14:26:26 UTC (rev 56265)
@@ -33,6 +33,13 @@
self.goal = []
self.penalty = 0.0
- def walk(self):
+ def work(self):
+ """
+ Wander around searching for fields of interest, mark the
+ road back home.
+ @return boolean whether still alive
+ """
+ # we are all only getting older..
+ if self.age() == False:
+ return False
pass
-
Modified: grass-addons/grass7/raster/r.agent/libagent/anthill.py
===================================================================
--- grass-addons/grass7/raster/r.agent/libagent/anthill.py 2013-05-15 14:25:44 UTC (rev 56264)
+++ grass-addons/grass7/raster/r.agent/libagent/anthill.py 2013-05-15 14:26:26 UTC (rev 56265)
@@ -11,6 +11,7 @@
import error, world, ant
+#from grass.script import core as grass
from sys import maxsize
from math import sqrt
from math import exp
@@ -73,6 +74,16 @@
#TODO self.decisionbase = "default"
#TODO self.rememberbase = "default"
+ def bear(self):
+ """
+ Set a new agent into the world
+ @param int number of cycles the agent has to live
+ @param list coordinates to put the agent on, none for a random position
+ @return agent the newly created agent
+ """
+ position = self.sites[randint(0, len(self.sites)-1)]
+ return super(Anthill, self).bear(self.antslife, position)
+
def volatilize(self):
"""
Let the pheromone evaporate over time.
@@ -80,3 +91,21 @@
self.playground.decaycellvalues(Anthill.RESULT, self.volatilizationtime,
self.minpheromone)
+ def letantsdance(self, rounds):
+ """
+ Let the agents do their job. The actual main loop in such a world.
+ """
+ while rounds > 0:
+# grass.info(rounds)
+ if len(self.agents) < self.maxants:
+# grass.info(len(self.agents))
+ # as there is still space on the pg, produce another ant
+ self.bear()
+ for ant in self.agents:
+ # let all the ants take action
+ ant.work()
+ # let the pheromone evaporate
+ self.volatilize()
+ # count down
+ rounds -= 1
+
Modified: grass-addons/grass7/raster/r.agent/libagent/world.py
===================================================================
--- grass-addons/grass7/raster/r.agent/libagent/world.py 2013-05-15 14:25:44 UTC (rev 56264)
+++ grass-addons/grass7/raster/r.agent/libagent/world.py 2013-05-15 14:26:26 UTC (rev 56265)
@@ -88,7 +88,8 @@
"""
Set a new agent into the world
@param int number of cycles the agent has to live
- @param list coordinates to put the agent or none for a random position
+ @param list coordinates to put the agent on, none for a random position
+ @param agenttype the typ of agent to be spawned
@return agent the newly created agent
"""
position = self.findposition(position)
Modified: grass-addons/grass7/raster/r.agent/r.agent.aco
===================================================================
--- grass-addons/grass7/raster/r.agent/r.agent.aco 2013-05-15 14:25:44 UTC (rev 56264)
+++ grass-addons/grass7/raster/r.agent/r.agent.aco 2013-05-15 14:26:26 UTC (rev 56265)
@@ -273,27 +273,11 @@
mainloops = 1
nextwrite = rounds
while mainloops > 0:
- grass.info(mainloops)
+# grass.info(mainloops)
# loop and write out the contents at the end
- loops = nextwrite
- while loops > 0:
- grass.info(loops)
- # loop without producing output
- if len(world.agents) < world.maxants:
- grass.info(len(world.agents))
- # as there is still space on the pg, produce another ant
- # at a random site..
- position = world.sites[randint(0, len(world.sites)-1)]
- world.bear(world.antslife, position)
- for ant in world.agents:
- # let all the ants take action
- ant.walk()
- # let the pheromone evaporate
- world.volatilize()
- # count down inner
- loops -= 1
+ world.letantsdance(nextwrite)
# export the value maps
- world.writeout()
+# world.writeout()
# print "nrofpaths:", world.nrop
# count down outer
mainloops -= 1
Modified: grass-addons/grass7/raster/r.agent/tests/test_ant.py
===================================================================
--- grass-addons/grass7/raster/r.agent/tests/test_ant.py 2013-05-15 14:25:44 UTC (rev 56264)
+++ grass-addons/grass7/raster/r.agent/tests/test_ant.py 2013-05-15 14:26:26 UTC (rev 56265)
@@ -27,5 +27,8 @@
def test_walk(self):
pass
+ def test_work(self):
+ pass
+
# def tearDown(self):
Modified: grass-addons/grass7/raster/r.agent/tests/test_anthill.py
===================================================================
--- grass-addons/grass7/raster/r.agent/tests/test_anthill.py 2013-05-15 14:25:44 UTC (rev 56264)
+++ grass-addons/grass7/raster/r.agent/tests/test_anthill.py 2013-05-15 14:26:26 UTC (rev 56265)
@@ -25,7 +25,6 @@
pass
def test_bear(self):
- # gets tested in World
pass
def test_move(self):
@@ -40,6 +39,9 @@
# gets tested in World
pass
+ def test_letantsdance(self):
+ pass
+
def volatilize(self):
pass
More information about the grass-commit
mailing list