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

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Jun 13 04:34:56 PDT 2014


Author: mic
Date: 2014-06-13 04:34:56 -0700 (Fri, 13 Jun 2014)
New Revision: 60819

Modified:
   grass-addons/grass7/raster/r.agent/libagent/anthill.py
   grass-addons/grass7/raster/r.agent/libagent/playground.py
   grass-addons/grass7/raster/r.agent/tests/test_playground.py
Log:
get sane default values

Modified: grass-addons/grass7/raster/r.agent/libagent/anthill.py
===================================================================
--- grass-addons/grass7/raster/r.agent/libagent/anthill.py	2014-06-13 11:23:26 UTC (rev 60818)
+++ grass-addons/grass7/raster/r.agent/libagent/anthill.py	2014-06-13 11:34:56 UTC (rev 60819)
@@ -73,9 +73,9 @@
         self.randomweight = 1
         self.costweight = 1
         ## maximum number of ants on the playground
-        self.maxants = 100
+        self.maxants = self.playground.gettotalcount()
         ## the ants ttl will be set by user or based on playground size
-        self.antslife = 0
+        self.antslife = self.playground.getdiagonalcount()
         self.decisionbase = "standard"
         self.evaluationbase = "standard"
         self.numberofpaths = 0
@@ -102,7 +102,7 @@
         Let the agents do their job. The actual main loop in such a world.
         """
         while rounds > 0:
-            #grass.info(len(self.agents))
+#            grass.info(len(self.agents))
             if len(self.agents) <= self.maxants:
                 # as there is still space on the pg, produce another ant
                 self.bear()

Modified: grass-addons/grass7/raster/r.agent/libagent/playground.py
===================================================================
--- grass-addons/grass7/raster/r.agent/libagent/playground.py	2014-06-13 11:23:26 UTC (rev 60818)
+++ grass-addons/grass7/raster/r.agent/libagent/playground.py	2014-06-13 11:34:56 UTC (rev 60819)
@@ -72,6 +72,20 @@
         """
         return self.region
 
+    def gettotalcount(self):
+        """
+        Return the number of cells in the playground
+        @return int total cells count
+        """
+        return self.region["rows"]*self.region["cols"]
+
+    def getdiagonalcount(self):
+        """
+        Return the number of cells in the diagonal
+        @return int diagonal cells count
+        """
+        return sqrt(self.region["rows"]*self.region["cols"])
+
     def getbound(self, bound):
         """
         Return the requested bound, takes: 'n', 's', 'w', or 'e'

Modified: grass-addons/grass7/raster/r.agent/tests/test_playground.py
===================================================================
--- grass-addons/grass7/raster/r.agent/tests/test_playground.py	2014-06-13 11:23:26 UTC (rev 60818)
+++ grass-addons/grass7/raster/r.agent/tests/test_playground.py	2014-06-13 11:34:56 UTC (rev 60819)
@@ -24,6 +24,14 @@
         self.assertIsNotNone(self.pg.getregion())
         self.assertIs(self.pg.getregion(),self.pg.region)
 
+    def gettotalcount(self):
+        #not tested for its just a wrapper
+        pass
+
+    def getdiagonalcount(self):
+        #not tested for its just a wrapper
+        pass
+
     def test_getbound(self):
         n = self.pg.region["n"]
         s = self.pg.region["s"]



More information about the grass-commit mailing list