[GRASS-SVN] r66576 - grass-addons/grass7/raster/r.futures/r.futures.pga

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Oct 22 06:39:18 PDT 2015


Author: wenzeslaus
Date: 2015-10-22 06:39:18 -0700 (Thu, 22 Oct 2015)
New Revision: 66576

Modified:
   grass-addons/grass7/raster/r.futures/r.futures.pga/main.cpp
Log:
r.futures.pga: carry on the cells we have developed over the limit

The counting mechanism was in the original code but the value was not stored
in between the steps. This would probably work if the variable would be static
and we would do only one region.
    
The next step would be to warn at the end if there are some regions which
are developed too much, i.e. the value is not zero.



Modified: grass-addons/grass7/raster/r.futures/r.futures.pga/main.cpp
===================================================================
--- grass-addons/grass7/raster/r.futures/r.futures.pga/main.cpp	2015-10-22 12:20:30 UTC (rev 66575)
+++ grass-addons/grass7/raster/r.futures/r.futures.pga/main.cpp	2015-10-22 13:39:18 UTC (rev 66576)
@@ -277,6 +277,11 @@
     char *controlFileAll;
     int devDemand[MAX_YEARS];
     int devDemands[MAXNUM_COUNTY][MAX_YEARS];
+    /// This keeps the number of cells in demand which we satisfied
+    /// in one step but it was more than we should have satisfied.
+    /// To corrent for this, we keep it to the next step and we use
+    /// it to lower the current demand.
+    int overflowDevDemands[MAXNUM_COUNTY];
     /// number of simulation steps
     int nSteps;
 } t_Params;
@@ -1531,7 +1536,8 @@
     double dProb;
     t_Cell *pThis;
 
-    nExtra = 0;
+    // get number of demanded cells already satisfied in the previous step
+    nExtra = pParams->overflowDevDemands[regionID];
 
     nStep = step;
 
@@ -1633,6 +1639,8 @@
         }
         G_debug(1, "Converted %d sites", nDone);
         nExtra += (nDone - nToConvert);
+        // save overflow for the next time
+        pParams->overflowDevDemands[regionID] = nExtra;
         G_debug(1, "%d extra sites knocked off next timestep", nExtra);
     }
 }
@@ -2112,6 +2120,10 @@
         readDevPotParams(&sParams, opt.devpotParamsFile->answer);
 
     readDevDemand(&sParams);
+    // initialize the overflow demands to zero
+    for (int i = 0; i < sParams.num_Regions; i++) {
+        sParams.overflowDevDemands[i] = 0;
+    }
     /* allocate memory */
     if (buildLandscape(&sLandscape, &sParams)) {
         /* read data */



More information about the grass-commit mailing list