[GRASS-SVN] r56354 - in grass-addons/grass7/raster/r.agent: . libagent tests

svn_grass at osgeo.org svn_grass at osgeo.org
Tue May 21 08:47:25 PDT 2013


Author: mic
Date: 2013-05-21 08:47:24 -0700 (Tue, 21 May 2013)
New Revision: 56354

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/r.agent.aco
   grass-addons/grass7/raster/r.agent/tests/test_ant.py
   grass-addons/grass7/raster/r.agent/tests/test_anthill.py
Log:
evaluate sites info

Modified: grass-addons/grass7/raster/r.agent/libagent/ant.py
===================================================================
--- grass-addons/grass7/raster/r.agent/libagent/ant.py	2013-05-21 15:42:02 UTC (rev 56353)
+++ grass-addons/grass7/raster/r.agent/libagent/ant.py	2013-05-21 15:47:24 UTC (rev 56354)
@@ -53,7 +53,7 @@
         @return boolean whether such a position was found
         """
         for p in positions[:]:
-            if self.world.getpenalty(p) < 0:
+            if self.world.getsitevalue(p) < 0:
                 # this is what we are looking for!
                 if p[0] == self.home[0] and p[1] == self.home[1]:
                     # ok, unfortunately we have only found the home position..

Modified: grass-addons/grass7/raster/r.agent/libagent/anthill.py
===================================================================
--- grass-addons/grass7/raster/r.agent/libagent/anthill.py	2013-05-21 15:42:02 UTC (rev 56353)
+++ grass-addons/grass7/raster/r.agent/libagent/anthill.py	2013-05-21 15:47:24 UTC (rev 56354)
@@ -155,3 +155,11 @@
         """
         return self.playground.getcellvalue(Anthill.COST, position)
 
+    def getsitevalue(self, position):
+        """
+        Return the value at a certain position in the sites layer
+        @param position the position in question
+        @return the value of interest
+        """
+        return self.playground.getcellvalue(Anthill.SITE, position)
+

Modified: grass-addons/grass7/raster/r.agent/r.agent.aco
===================================================================
--- grass-addons/grass7/raster/r.agent/r.agent.aco	2013-05-21 15:42:02 UTC (rev 56353)
+++ grass-addons/grass7/raster/r.agent/r.agent.aco	2013-05-21 15:47:24 UTC (rev 56354)
@@ -231,7 +231,7 @@
             site = site + '@' + grass.gisenv()['MAPSET']
         # set sitemap and site list
         world.sites = world.playground.parsevectorlayer(anthill.Anthill.SITE,
-                                                        site, True)
+                                                        site, -1, True)
         if not world.sites:
             raise error.DataError("r.agent.aco:",
                                     "There were no sites in" + site)

Modified: grass-addons/grass7/raster/r.agent/tests/test_ant.py
===================================================================
--- grass-addons/grass7/raster/r.agent/tests/test_ant.py	2013-05-21 15:42:02 UTC (rev 56353)
+++ grass-addons/grass7/raster/r.agent/tests/test_ant.py	2013-05-21 15:47:24 UTC (rev 56354)
@@ -16,16 +16,16 @@
         positions = [[0,0],[1,1]]
         self.laststeps = [1,1]
         # An empty test
-        self.pg.layers[anthill.Anthill.COST][0][0] = 0
-        self.pg.layers[anthill.Anthill.COST][1][1] = 0
+        self.pg.layers[anthill.Anthill.SITE][0][0] = 0
+        self.pg.layers[anthill.Anthill.SITE][1][1] = 0
         self.assertFalse(self.agent.check(positions))
         self.assertIsNone(self.agent.nextstep[0])
         # set the value of interest but at the homeplace
-        self.pg.layers[anthill.Anthill.COST][1][1] = -1
+        self.pg.layers[anthill.Anthill.SITE][1][1] = -1
         self.assertFalse(self.agent.check(positions))
         self.assertIsNone(self.agent.nextstep[0])
         # and this time at a good position
-        self.pg.layers[anthill.Anthill.COST][0][0] = -1
+        self.pg.layers[anthill.Anthill.SITE][0][0] = -1
         self.assertTrue(self.agent.check(positions))
         self.assertIsNotNone(self.agent.nextstep[0])
         self.assertEqual(1, self.agent.nextstep[0])

Modified: grass-addons/grass7/raster/r.agent/tests/test_anthill.py
===================================================================
--- grass-addons/grass7/raster/r.agent/tests/test_anthill.py	2013-05-21 15:42:02 UTC (rev 56353)
+++ grass-addons/grass7/raster/r.agent/tests/test_anthill.py	2013-05-21 15:47:24 UTC (rev 56354)
@@ -87,6 +87,12 @@
         self.world.playground.layers[anthill.Anthill.COST][0][0] = 9
         self.assertEqual(9, self.world.getpenalty([0,0]))
 
+    def test_getpenalty(self):
+        self.assertNotEqual(9,
+            self.world.playground.layers[anthill.Anthill.SITE][0][0])
+        self.world.playground.layers[anthill.Anthill.SITE][0][0] = 9
+        self.assertEqual(9, self.world.getsitevalue([0,0]))
+
     def volatilize(self):
         # gets tested in Playground, except for setting the values..
         pass



More information about the grass-commit mailing list