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

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Mar 11 13:04:56 PDT 2013


Author: mic
Date: 2013-03-11 13:04:56 -0700 (Mon, 11 Mar 2013)
New Revision: 55322

Modified:
   grass-addons/grass7/raster/r.agent/aco.py
   grass-addons/grass7/raster/r.agent/libagent/anthill.py
Log:
populate controllers

Modified: grass-addons/grass7/raster/r.agent/aco.py
===================================================================
--- grass-addons/grass7/raster/r.agent/aco.py	2013-03-11 19:54:03 UTC (rev 55321)
+++ grass-addons/grass7/raster/r.agent/aco.py	2013-03-11 20:04:56 UTC (rev 55322)
@@ -10,8 +10,7 @@
               for details.
 """
 
-from libagent import error
-from libagent import anthill
+from libagent import error, grassland, anthill
 
 from sys import maxsize
 from math import sqrt
@@ -22,11 +21,30 @@
 rounds = 0
 outrounds = 0
 
-# take out a subscription to a world
-world = anthill.Anthill()
+# take out a subscription for a playground to a world
+world = anthill.Anthill(grassland.Grassland())
 
-def set_maps(site, cost, result):
-    pass
+def setmaps(site, cost, wastecosts, inphero, outphero, wastephero):
+    """
+    Set the user maps in place
+    """
+    if site:
+        # set sitemap and site list
+        world.sites = world.playground.parsevectorlayer(anthill.Anthill.SITE,
+                                                        site, True)
+    else:
+        raise error.DataError("aco:", "The site map is mandatory.")
+    if cost:
+        # set cost/penalty layer
+        world.playground.setgrasslayer(anthill.Anthill.COST, cost, True)
+        world.overwritepenalty = wastecosts
+    if inphero == outphero:
+        if not wastephero:
+            raise error.DataError("aco:", "May not overwrite the output map.")
+    if inphero:
+        world.playground.setgrasslayer(anthill.Anthill.RESULT, inphero, True)
+    world.playground.grassmapnames[anthill.Anthill.RESULT] = outphero
+    world.overwritepheormone = wastephero
 
 def letantsdance(self):
     """

Modified: grass-addons/grass7/raster/r.agent/libagent/anthill.py
===================================================================
--- grass-addons/grass7/raster/r.agent/libagent/anthill.py	2013-03-11 19:54:03 UTC (rev 55321)
+++ grass-addons/grass7/raster/r.agent/libagent/anthill.py	2013-03-11 20:04:56 UTC (rev 55322)
@@ -9,9 +9,7 @@
               for details.
 """
 
-import error
-import world
-import ant
+import error, world, ant
 
 from sys import maxsize
 from math import sqrt
@@ -28,13 +26,16 @@
     COST = "penaltymap"
     RESULT = "pheromap"
 
-    def __init__(self):
+    def __init__(self, pg=False):
         """
         Create a world based on the natural laws of the Ant Colony Optimization
         algorithm (plus adaptions honouring the complexity of the raster case).
         """
         # get all attributes from the basic world
-        super(Anthill, self).__init__(ant.Ant)
+        if pg:
+            super(Anthill, self).__init__(ant.Ant, pg)
+        else:
+            super(Anthill, self).__init__(ant.Ant)
         # add the main layers
         ## one containing the points of interest
         self.addlayertopg(Anthill.SITE)



More information about the grass-commit mailing list