-- CONSTANTS (MODEL PARAMETERS) CELL_AREA = 0.25; FINAL_TIME = 10; DEMAND = 200; YEARS = FINAL_TIME -- GLOBAL VARIABLES csQ = CellularSpace{ dbType = "ADO", host = "localhost", database = "c:\\TerraME\\Database\\rondonia.mdb", user = "", password = "", layer = "celulas_500_Anari_1995", theme = "celulas_500_Anari_1995", select= {"cover_" } } -- RULES -- numero de celulas alocadas por ano: csQ:load(); CreateMooreNeighbourhood(csQ); csQ:synchronize(); for time = 1, FINAL_TIME, 1 do print("t: "..time ); -- Compute amount of cells to be changed in each time step num = DEMAND/(CELL_AREA*FINAL_TIME); -- numero de celulas a serem modificadas por ano total_num_cells_ch = DEMAND/CELL_AREA; -- numero de celulas a serem modificadas no total print (DEMAND, num, total_num_cells_ch); total_actually_ch = 0; -- Percorrer o espaco, zera e recalcula o potencial de mudanca for i, cell in pairs( csQ.cells ) do cell.pot = 0; end for i, cell in pairs( csQ.cells ) do if (cell.past.cover_ == "forest") then ForEachNeighbour(cell, 0, function(cell, neigh) if (neigh.past.cover_ == "deforested" and cell~=neigh) then cell.pot = cell.pot + 1;end end ); end end -- Order cells potential it = SpatialIterator { --serve para andar ao longo do potencial das celulas csQ, function(cell) return cell.pot > 0; end, function (c1,c2) return c1.pot > c2.pot; end } -- Demand alocation count = 0; for i, cell in pairs( it.cells ) do if (count < num) then -- print (cell.object_id, cell.pot, cell.cover_); cell.cover_ = "deforested"; count = count + 1; end end -- foreach cell --Update variables and cellular space total_actually_ch = total_actually_ch + count; print ("number of cells to change:", num); print ("number of suitable cells: ", it.count); print ("number of changed cells: ", count); csQ:synchronize(); if (time ~= FINAL_TIME) then -- check if there is a need to redistribute change in the following years if (count < num) then -- there is a need to redistribute change num = (total_num_cells_ch - total_actually_ch)/(YEARS - time); print ("new annual change rate:", num); end else csQ:save( time, "cover_sim2005", {"cover_"}); end end -- time step print ("Total de celulas alocadas:", total_actually_ch);