[GRASS-SVN] r56378 - in grass-addons/grass7/raster/r.agent: libagent tests
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu May 23 07:34:45 PDT 2013
Author: mic
Date: 2013-05-23 07:34:45 -0700 (Thu, 23 May 2013)
New Revision: 56378
Modified:
grass-addons/grass7/raster/r.agent/libagent/ant.py
grass-addons/grass7/raster/r.agent/tests/test_ant.py
Log:
improve logic flow
Modified: grass-addons/grass7/raster/r.agent/libagent/ant.py
===================================================================
--- grass-addons/grass7/raster/r.agent/libagent/ant.py 2013-05-23 11:56:31 UTC (rev 56377)
+++ grass-addons/grass7/raster/r.agent/libagent/ant.py 2013-05-23 14:34:45 UTC (rev 56378)
@@ -28,10 +28,10 @@
self.home = self.position[:]
self.laststeps = []
self.visitedsteps = []
- self.done = False
self.nextstep = [None,None,None,0]
self.goal = []
self.penalty = 0.0
+ self.walk = self.walkaround
if self.world.decisionbase == "standard":
# TODO: for now like 'else'..
self.decide = self.randomposition
@@ -68,11 +68,10 @@
# str(self.world.numberofpaths))
# add one to the counter
#self.world.nrop += 1
- self.done = True
+ self.walk = self.walkhome
# now, head back home..
self.nextstep = self.laststeps.pop()
return True
- # TODO instead of work and walk reset work, which initially points to walkaround, to to headhome here!
return False
def choose(self):
@@ -86,28 +85,32 @@
if not self.evaluate(positions):
self.nextstep = self.decide(positions)
- def walk(self):
+ def walkhome(self):
"""
Do all the things necessary for performing a regualar step when
- walking around or going back home.
+ walking back home.
"""
- if self.done:
- self.position = self.nextstep
- if len(self.laststeps) > 1:
- # walk only up to the gates of the hometown
- self.nextstep = self.laststeps.pop()
- self.penalty += self.nextstep[3] + \
- self.world.getpenalty(self.nextstep)
- else:
- # retire after work.
- self.snuffit()
- self.world.setpathpheromone(self.position)
+ self.position = self.nextstep
+ if len(self.laststeps) > 1:
+ # walk only up to the gates of the hometown
+ self.nextstep = self.laststeps.pop()
+ self.penalty += self.nextstep[3] + \
+ self.world.getpenalty(self.nextstep)
else:
- self.laststeps.append(self.position)
- self.position = self.nextstep
- self.nextstep = [None,None,None,0]
- self.world.setsteppheromone(self.position)
+ # retire after work.
+ self.snuffit()
+ self.world.setpathpheromone(self.position)
+ def walkaround(self):
+ """
+ Do all the things necessary for performing a regualar step when
+ walking around.
+ """
+ self.laststeps.append(self.position)
+ self.position = self.nextstep
+ self.nextstep = [None,None,None,0]
+ self.world.setsteppheromone(self.position)
+
def work(self):
"""
Wander around searching for fields of interest, mark the
Modified: grass-addons/grass7/raster/r.agent/tests/test_ant.py
===================================================================
--- grass-addons/grass7/raster/r.agent/tests/test_ant.py 2013-05-23 11:56:31 UTC (rev 56377)
+++ grass-addons/grass7/raster/r.agent/tests/test_ant.py 2013-05-23 14:34:45 UTC (rev 56378)
@@ -35,8 +35,11 @@
# possible other methods which are directly testable
pass
- def test_walk(self):
+ def test_walkhome(self):
#TODO walking home
+ pass
+
+ def test_walkaround(self):
self.agent.position = [0,0]
self.agent.nextstep = [1,1]
self.agent.walk()
More information about the grass-commit
mailing list