[GRASS-SVN] r56307 - in grass-addons/grass7/raster/r.agent: . libagent tests
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun May 19 02:18:13 PDT 2013
Author: mic
Date: 2013-05-19 02:18:13 -0700 (Sun, 19 May 2013)
New Revision: 56307
Modified:
grass-addons/grass7/raster/r.agent/libagent/agent.py
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/grassland.py
grass-addons/grass7/raster/r.agent/r.agent.aco
grass-addons/grass7/raster/r.agent/tests/test_agent.py
Log:
ants start walking, first time output is produced
Modified: grass-addons/grass7/raster/r.agent/libagent/agent.py
===================================================================
--- grass-addons/grass7/raster/r.agent/libagent/agent.py 2013-05-19 08:42:37 UTC (rev 56306)
+++ grass-addons/grass7/raster/r.agent/libagent/agent.py 2013-05-19 09:18:13 UTC (rev 56307)
@@ -8,6 +8,8 @@
License (>=v2). Read the file COPYING that comes with GRASS
for details.
"""
+#from random import choice, randint
+from random import randint
class Agent(object):
"""
@@ -44,6 +46,14 @@
#TODO not very meaningfull yet..
return self.position
+ def randomposition(self, positions):
+ """
+ Pick a random position out of a list of positions
+ @param positions list of possible positions
+ @return position the decision for a position
+ """
+ return positions[randint(0, len(positions)-1)]
+
# def move(self, nrofsteps, direction):
# not implemented yet
# """
Modified: grass-addons/grass7/raster/r.agent/libagent/ant.py
===================================================================
--- grass-addons/grass7/raster/r.agent/libagent/ant.py 2013-05-19 08:42:37 UTC (rev 56306)
+++ grass-addons/grass7/raster/r.agent/libagent/ant.py 2013-05-19 09:18:13 UTC (rev 56307)
@@ -9,7 +9,7 @@
for details.
"""
-from random import choice, randint
+from random import choice #, randint
import agent
import error
@@ -32,6 +32,11 @@
self.nextstep = [None,None,0,0,0,0]
self.goal = []
self.penalty = 0.0
+ if self.world.decisionbase == "default":
+ # TODO: for now like 'else'..
+ self.chooseposition = self.randomposition
+ else:
+ self.chooseposition = self.randomposition
def work(self):
"""
@@ -42,4 +47,7 @@
# we are all only getting older..
if self.age() == False:
return False
+ self.position = self.chooseposition(
+ self.world.getneighbourpositions(self.position))
+ self.world.setsteppheromone(self.position)
Modified: grass-addons/grass7/raster/r.agent/libagent/anthill.py
===================================================================
--- grass-addons/grass7/raster/r.agent/libagent/anthill.py 2013-05-19 08:42:37 UTC (rev 56306)
+++ grass-addons/grass7/raster/r.agent/libagent/anthill.py 2013-05-19 09:18:13 UTC (rev 56307)
@@ -71,7 +71,7 @@
self.maxants = 100
## the ants ttl will be set by user or based on playground size
self.antslife = 0
-#TODO self.decisionbase = "default"
+ self.decisionbase = "default"
#TODO self.rememberbase = "default"
def bear(self):
Modified: grass-addons/grass7/raster/r.agent/libagent/grassland.py
===================================================================
--- grass-addons/grass7/raster/r.agent/libagent/grassland.py 2013-05-19 08:42:37 UTC (rev 56306)
+++ grass-addons/grass7/raster/r.agent/libagent/grassland.py 2013-05-19 09:18:13 UTC (rev 56307)
@@ -108,10 +108,13 @@
# TODO do they all look like this??
if len(v) == 4 and v[0] == v[3]:
p = self.stringcoordinate(v[1],v[2])
+ # TODO - as with grass numpy array it seems that
+ # [0,0] is north-most west-most..
p[0] = int(round(
- ( p[0] - self.region["s"] ) / self.region["nsres"] ))
+ ( self.region["n"] - p[0] ) / self.region["nsres"] ))
p[1] = int(round(
( p[1] - self.region["w"] ) / self.region["ewres"] ))
+ grass.info(str(p[0]) + " " + str(p[1]))
vectors.append(p)
self.layers[layername][p[0]][p[1]] = value
return vectors
Modified: grass-addons/grass7/raster/r.agent/r.agent.aco
===================================================================
--- grass-addons/grass7/raster/r.agent/r.agent.aco 2013-05-19 08:42:37 UTC (rev 56306)
+++ grass-addons/grass7/raster/r.agent/r.agent.aco 2013-05-19 09:18:13 UTC (rev 56307)
@@ -277,8 +277,8 @@
# loop and write out the contents at the end
world.letantsdance(nextwrite)
# export the value maps
- world.playground.writelayer(anthill.Anthill.RESULT,
- world.overwritepheormone)
+ world.playground.writelayer(anthill.Anthill.RESULT, False,
+ world.overwritepheormone)
# print "nrofpaths:", world.nrop
# count down outer
mainloops -= 1
Modified: grass-addons/grass7/raster/r.agent/tests/test_agent.py
===================================================================
--- grass-addons/grass7/raster/r.agent/tests/test_agent.py 2013-05-19 08:42:37 UTC (rev 56306)
+++ grass-addons/grass7/raster/r.agent/tests/test_agent.py 2013-05-19 09:18:13 UTC (rev 56307)
@@ -20,6 +20,11 @@
def test_getposition(self):
self.assertTrue(self.agent.getposition() == [1,1])
+ def test_randomposition(self):
+ position = [1,2]
+ self.assertEqual(position,
+ self.agent.randomposition([position, position]))
+
# def test_move(self):
# not implemented yet
# pass
More information about the grass-commit
mailing list