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

svn_grass at osgeo.org svn_grass at osgeo.org
Sat May 25 14:47:15 PDT 2013


Author: mic
Date: 2013-05-25 14:47:15 -0700 (Sat, 25 May 2013)
New Revision: 56417

Modified:
   grass-addons/grass7/raster/r.agent/libagent/anthill.py
   grass-addons/grass7/raster/r.agent/r.agent.aco
Log:
support multiple output per run

Modified: grass-addons/grass7/raster/r.agent/libagent/anthill.py
===================================================================
--- grass-addons/grass7/raster/r.agent/libagent/anthill.py	2013-05-25 19:59:06 UTC (rev 56416)
+++ grass-addons/grass7/raster/r.agent/libagent/anthill.py	2013-05-25 21:47:15 UTC (rev 56417)
@@ -41,6 +41,8 @@
         self.addlayertopg(Anthill.COST)
         ## allow overwriting the cost map
         self.overwritepenalty = False
+        # TODO probably delete all these stuff here related to output..
+        self.addsequencenumber = False
         ## and finally the markings from the agents
         self.addlayertopg(Anthill.RESULT)
         ## allow overwriting the main map (if it exists)
@@ -97,7 +99,6 @@
         Let the agents do their job. The actual main loop in such a world.
         """
         while rounds > 0:
-#            grass.info(rounds)
             if len(self.agents) < self.maxants:
 #                grass.info(len(self.agents))
                 # as there is still space on the pg, produce another ant

Modified: grass-addons/grass7/raster/r.agent/r.agent.aco
===================================================================
--- grass-addons/grass7/raster/r.agent/r.agent.aco	2013-05-25 19:59:06 UTC (rev 56416)
+++ grass-addons/grass7/raster/r.agent/r.agent.aco	2013-05-25 21:47:15 UTC (rev 56417)
@@ -35,6 +35,10 @@
 #% description: Allow overwriting existing pheromone maps
 #%end
 #%flag
+#% key: s
+#% description: Produce a sequence of pheromone maps (by appending a number)
+#%end
+#%flag
 #% key: c
 #% description: Overwrite existing cost map (only used with penalty conversion)
 #%end
@@ -267,6 +271,9 @@
     """
     Organize the agents and the pheromone on the playground.
     """
+    if world.addsequencenumber:
+        outputmapbasename = \
+            world.playground.grassmapnames[anthill.Anthill.RESULT].split("@")
     if 0 < outrounds < rounds:
         # calculate when to write output
         mainloops = rounds / outrounds
@@ -275,7 +282,13 @@
         # produce output only at the end
         mainloops = 1
         nextwrite = rounds
-    while mainloops > 0:
+    run = 0
+    while run < mainloops:
+        print(run)
+        if outputmapbasename:
+            outputmapname = outputmapbasename[0] + str(run) + "@" + \
+                            outputmapbasename[1]
+        print(outputmapname)
 #        grass.info(mainloops)
         # loop and write out the contents at the end
         world.letantsdance(nextwrite)
@@ -288,13 +301,13 @@
                     world.playground.layers[anthill.Anthill.RESULT][0])):
                 world.playground.layers["copy"][i][j] = \
                         world.playground.layers[anthill.Anthill.RESULT][i][j]
-        world.playground.writelayer("copy", False,  
+        world.playground.writelayer("copy", outputmapname,
                                             world.overwritepheormone)
         #TODO world.playground.writelayer(anthill.Anthill.RESULT, False,
         #TODO                                    world.overwritepheormone)
 #        print "nrofpaths:", world.nrop
         # count down outer
-        mainloops -= 1
+        run += 1
 #    print "nrofrounds", nrofrounds
 
 def main():
@@ -305,6 +318,10 @@
             options['inputmap'], options['outputmap'], flags['p'])
 
 #        world.playground.setboundsfromlayer("costs")
+        if not options['outrounds']:
+            options['outrounds'] = 0
+        elif flags['s'] and options['outrounds'] > 0:
+            world.addsequencenumber = True
 
         if options['maxpheromone']:
             world.maxpheromone = int(options['maxpheromone'])
@@ -335,10 +352,7 @@
         #if arglist[0] == "stability":
             #TODO ask silvia..
 
-
 #        world.checkvalues()
-        if not options['outrounds']:
-            options['outrounds'] = 0
     except error.DataError:
         grass.fatal("Failed to parse args..")
         sys.exit(1)



More information about the grass-commit mailing list