diff --git a/description.lua b/description.lua
index 20ee996..d93d768 100644
--- a/description.lua
+++ b/description.lua
@@ -1,8 +1,8 @@
-version = "0.1"
+version = "0.2"
package = "logo"
license = "GPL"
title = "Simple spatial ABM"
-depends = "terrame (>= 1.5)"
+depends = "terrame (>= 1.6)"
authors = "Pedro R. Andrade"
contact = "pedro.andrade@inpe.br"
content = "Implements ABM paradigm for spatial models with at most one agent per cell."
diff --git a/doc/files/LogoAgent.html b/doc/files/LogoAgent.html
index 912f90d..6bf0657 100644
--- a/doc/files/LogoAgent.html
+++ b/doc/files/LogoAgent.html
@@ -88,6 +88,8 @@
+
+
@@ -111,6 +113,9 @@ Types
+ LogoAgent
+
+
LogoModel
@@ -136,8 +141,6 @@ Types
-
-
@@ -161,9 +164,6 @@ Functions
- LogoAgent
-
-
@@ -210,6 +210,51 @@ LogoAgent
+
+
+
+
+Basic Agent for Logo models.
+
+
+
+
+
+ Arguments
+
+
+ -
+ execute: A function that gets the agent itself as argument and is called every time step.
+
+
+
+ -
+ init: A function that gets the agent itself as argument and will be executed when the agent is initialized.
+
+
+
+
+
+
+
+
+
+
+
+Usage
+import("logo")
+
+LogoAgent{}
+
+
+
+
+
+
+
+
+
Functions
@@ -291,7 +336,19 @@ Arguments
Usage
-agent:breed()
+import("logo")
+
+Breed = LogoModel{
+ quantity = 10,
+ dim = 10,
+ finalTime = 10,
+ changes = function(agent)
+ agent:breed()
+ agent:relocate()
+ end
+}
+
+Breed:execute()
@@ -336,7 +393,18 @@ Arguments
Usage
-quantity = countNeighbors(agent)
+import("logo")
+
+Count = LogoModel{
+ quantity = 3,
+ dim = 3,
+ finalTime = 2,
+ changes = function(agent)
+ print(agent:countNeighbors())
+ end
+}
+
+Count:execute()
@@ -381,7 +449,20 @@ Arguments
Usage
-neigh = emptyNeighbor(agent)
+import("logo")
+
+Empty = LogoModel{
+ quantity = 6,
+ dim = 3,
+ finalTime = 10,
+ changes = function(agent)
+ if not agent:emptyNeighbor() then
+ print("not empty")
+ end
+ end
+}
+
+Empty:execute()
@@ -426,7 +507,18 @@ Arguments
Usage
-agent:relocate()
+import("logo")
+
+Relocate = LogoModel{
+ quantity = 10,
+ dim = 10,
+ finalTime = 10,
+ changes = function(agent)
+ agent:relocate()
+ end
+}
+
+Relocate:execute()
diff --git a/doc/files/LogoModel.html b/doc/files/LogoModel.html
index 8117544..a9a2981 100644
--- a/doc/files/LogoModel.html
+++ b/doc/files/LogoModel.html
@@ -88,6 +88,8 @@
+
+
@@ -111,6 +113,11 @@ Types
+
+ LogoAgent
+
+
+
LogoModel
@@ -134,8 +141,6 @@ Types
-
-
@@ -159,11 +164,6 @@ Functions
-
- LogoAgent
-
-
-
diff --git a/doc/files/Utils.html b/doc/files/Utils.html
index e7bbf03..76fe667 100644
--- a/doc/files/Utils.html
+++ b/doc/files/Utils.html
@@ -88,6 +88,8 @@
+
+
@@ -111,6 +113,11 @@ Types
+
+ LogoAgent
+
+
+
LogoModel
@@ -136,8 +143,6 @@ Types
-
-
@@ -161,11 +166,6 @@ Functions
-
- LogoAgent
-
-
-
@@ -277,7 +277,9 @@ Arguments
Usage
-cs = getLabyrinth("room")
+import("logo")
+
+room = getLabyrinth("room")
@@ -322,7 +324,9 @@ Arguments
Usage
-cs = getSugar("room")
+import("logo")
+
+room = getSugar("default")
diff --git a/doc/files/data.html b/doc/files/data.html
index 00ae6f6..0860227 100644
--- a/doc/files/data.html
+++ b/doc/files/data.html
@@ -88,6 +88,8 @@
+
+
@@ -111,6 +113,11 @@ Types
+
+ LogoAgent
+
+
+
LogoModel
@@ -136,8 +143,6 @@ Types
-
-
@@ -161,11 +166,6 @@ Functions
-
- LogoAgent
-
-
-
diff --git a/doc/files/font.html b/doc/files/font.html
index 3b85f2a..f2a9366 100644
--- a/doc/files/font.html
+++ b/doc/files/font.html
@@ -91,6 +91,8 @@
+
+
@@ -114,6 +116,11 @@ Types
+
+ LogoAgent
+
+
+
LogoModel
@@ -139,8 +146,6 @@ Types
-
-
@@ -164,11 +169,6 @@ Functions
-
- LogoAgent
-
-
-
diff --git a/doc/files/models.html b/doc/files/models.html
index 773bf50..7c7bab3 100644
--- a/doc/files/models.html
+++ b/doc/files/models.html
@@ -88,6 +88,8 @@ Models
+
+
@@ -111,6 +113,11 @@ Types
+
+ LogoAgent
+
+
+
LogoModel
@@ -136,8 +143,6 @@ Types
-
-
@@ -161,11 +166,6 @@ Functions
-
- LogoAgent
-
-
-
@@ -262,6 +262,21 @@ Models
Model where a given Society grows, filling the whole space. Agents reproduce with 20% of probability if there is an empty neighbor.
+ Arguments
+
+
+ - chart: A boolean value indicating whether a Chart with the number of Agents along the simulation should be drawn.
+
+ - dim: The x and y dimensions of space.
+
+ - finalTime: The final simulation time.
+
+ - map: A boolean value indicating whether a Map with the spatial distribution r of Agents along the simulation should be drawn.
+
+ - quantity: The initial number of Agents in the model.
+
+
+
@@ -273,6 +288,23 @@ Models
A labyrynth, where agents move randomly from a given entrance until an exit point. There are some available labyrynths available. See the documentation of data.
+ Arguments
+
+
+ - chart: A boolean value indicating whether a Chart with the number of Agents along the simulation should be drawn.
+
+ - dim: The x and y dimensions of space.
+
+ - finalTime: The final simulation time.
+
+ - labyrinth: The spatial representation of the model. The available labyrinths are described in the data available in the package. They should be used without ".labyrinth" extension. The default pattern is "room".
+
+ - map: A boolean value indicating whether a Map with the spatial distribution r of Agents along the simulation should be drawn.
+
+ - quantity: The initial number of Agents in the model.
+
+
+
@@ -284,6 +316,21 @@ Models
A model where agents reproduce and die by age. Each Agent starts with age zero. From age 15 until 30 they have 30% of chance of reproducing if there is an empty neighbor cell. Agents have 5% of probability of dying each time step after age 20.
+ Arguments
+
+
+ - chart: A boolean value indicating whether a Chart with the number of Agents along the simulation should be drawn.
+
+ - dim: The x and y dimensions of space.
+
+ - finalTime: The final simulation time.
+
+ - map: A boolean value indicating whether a Map with the spatial distribution r of Agents along the simulation should be drawn.
+
+ - quantity: The initial number of Agents in the model.
+
+
+
@@ -299,6 +346,21 @@ Models
Model where Agents die by overpopulation. Each Agent beeds with a probability of 30% and die if there are more than three Agents in the neighborhood.
+ Arguments
+
+
+ - chart: A boolean value indicating whether a Chart with the number of Agents along the simulation should be drawn.
+
+ - dim: The x and y dimensions of space.
+
+ - finalTime: The final simulation time.
+
+ - map: A boolean value indicating whether a Map with the spatial distribution r of Agents along the simulation should be drawn.
+
+ - quantity: The initial number of Agents in the model.
+
+
+
@@ -310,6 +372,21 @@ Models
A single agent moving around randomly.
+ Arguments
+
+
+ - chart: A boolean value indicating whether a Chart with the number of Agents along the simulation should be drawn.
+
+ - dim: The x and y dimensions of space.
+
+ - finalTime: The final simulation time.
+
+ - map: A boolean value indicating whether a Map with the spatial distribution r of Agents along the simulation should be drawn.
+
+ - quantity: The initial number of Agents in the model.
+
+
+
@@ -321,6 +398,23 @@ Models
Model where a given Society grows, filling the whole space. Agents reproduce with 20% of probability if there is an empty neighbor.
+ Arguments
+
+
+ - chart: A boolean value indicating whether a Chart with the number of Agents along the simulation should be drawn.
+
+ - dim: The x and y dimensions of space.
+
+ - finalTime: The final simulation time.
+
+ - map: A boolean value indicating whether a Map with the spatial distribution r of Agents along the simulation should be drawn.
+
+ - quantity: The initial number of Agents in the model.
+
+ - sugarMap: The spatial representation of the model. The available sugarscapes are described in the data available in the package. They should be used without ".sugar" extension. The default pattern is "room".
+
+
+
diff --git a/doc/index.html b/doc/index.html
index 27f499d..5adda9a 100644
--- a/doc/index.html
+++ b/doc/index.html
@@ -90,6 +90,8 @@
+
+
@@ -113,6 +115,11 @@ Types
+
+ LogoAgent
+
+
+
LogoModel
@@ -138,8 +145,6 @@ Types
-
-
@@ -163,11 +168,6 @@ Functions
-
- LogoAgent
-
-
-
@@ -205,19 +205,19 @@
- Version: 0.1
+ Version: 0.2
License: GPL
- Release: 22 September 2015
+ Release: 15 October 2015
Authors: Pedro R. Andrade
- Depends: terrame (>= 1.5)
+ Depends: terrame (>= 1.6)
@@ -336,6 +336,8 @@
+
+
@@ -363,6 +365,11 @@ Types
+
+ LogoAgent |
+ Basic Agent for Logo models. |
+
+
@@ -392,8 +399,6 @@ Types
-
-
@@ -422,11 +427,6 @@ Functions
-
- LogoAgent |
- |
-
-
diff --git a/doc/luadoc.css b/doc/luadoc.css
index 63259d3..4f33d45 100644
--- a/doc/luadoc.css
+++ b/doc/luadoc.css
@@ -56,10 +56,8 @@ a:link { font-weight:bold; color: #004080; text-decoration: none; }
a:visited { font-weight:bold; color: #006699; text-decoration: none; }
a:link:hover { text-decoration:underline; }
hr { color:#cccccc }
-.imgBorder {
- border-width: 1px;
- border-color: Black;
-}
+img { border-width: 0px; }
+
h3 { padding-top: 1em; }
diff --git a/lua/GrowingSociety.lua b/lua/GrowingSociety.lua
index 0aa3bd1..f8c7e7d 100644
--- a/lua/GrowingSociety.lua
+++ b/lua/GrowingSociety.lua
@@ -2,13 +2,22 @@
--- Model where a given Society grows, filling
-- the whole space. Agents reproduce with 20% of
-- probability if there is an empty neighbor.
+-- @arg data.dim The x and y dimensions of space.
+-- @arg data.chart A boolean value indicating whether a Chart
+-- with the number of Agents along the simulation should
+-- be drawn.
+-- @arg data.quantity The initial number of Agents in the model.
+-- @arg data.finalTime The final simulation time.
+-- @arg data.map A boolean value indicating whether a Map
+-- with the spatial distribution r of Agents along the
+-- simulation should be drawn.
-- @image growing-society.bmp
GrowingSociety = LogoModel{
quantity = 1,
dim = 20,
chart = true,
background = "green",
- finalTime = 100,
+ finalTime = 60,
changes = function(agent)
if Random():number() < 0.2 then
agent:breed()
diff --git a/lua/Labyrinth.lua b/lua/Labyrinth.lua
index 86016d2..3058331 100644
--- a/lua/Labyrinth.lua
+++ b/lua/Labyrinth.lua
@@ -6,6 +6,19 @@ labyrinths.default = "room"
-- a given entrance until an exit point.
-- There are some available labyrynths available.
-- See the documentation of data.
+-- @arg data.dim The x and y dimensions of space.
+-- @arg data.chart A boolean value indicating whether a Chart
+-- with the number of Agents along the simulation should
+-- be drawn.
+-- @arg data.finalTime The final simulation time.
+-- @arg data.quantity The initial number of Agents in the model.
+-- @arg data.map A boolean value indicating whether a Map
+-- with the spatial distribution r of Agents along the
+-- simulation should be drawn.
+-- @arg data.labyrinth The spatial representation of the model.
+-- The available labyrinths are described in the data available in the package.
+-- They should be used without ".labyrinth" extension. The default pattern is
+-- "room".
-- @image labyrinth.bmp
Labyrinth = LogoModel{
labyrinth = Choice(labyrinths),
diff --git a/lua/LifeCycle.lua b/lua/LifeCycle.lua
index 5ff7663..a9e4392 100644
--- a/lua/LifeCycle.lua
+++ b/lua/LifeCycle.lua
@@ -4,6 +4,15 @@
-- 30 they have 30% of chance of reproducing if there
-- is an empty neighbor cell. Agents have 5% of
-- probability of dying each time step after age 20.
+-- @arg data.dim The x and y dimensions of space.
+-- @arg data.chart A boolean value indicating whether a Chart
+-- with the number of Agents along the simulation should
+-- be drawn.
+-- @arg data.quantity The initial number of Agents in the model.
+-- @arg data.finalTime The final simulation time.
+-- @arg data.map A boolean value indicating whether a Map
+-- with the spatial distribution r of Agents along the
+-- simulation should be drawn.
-- @image life-cycle.bmp
LifeCycle = LogoModel{
quantity = 10,
diff --git a/lua/LogoAgent.lua b/lua/LogoAgent.lua
index 90429d1..ccba299 100644
--- a/lua/LogoAgent.lua
+++ b/lua/LogoAgent.lua
@@ -1,9 +1,22 @@
---LogoAgent_ = {
--- type_ = "Agent",
+LogoAgent_ = {
+ type_ = "Agent",
--- Return an empty neighbor Cell. If there is no empty neighbor
-- then it returns false.
-- @arg agent An Agent.
- -- @usage neigh = emptyNeighbor(agent)
+ -- @usage import("logo")
+ --
+ -- Empty = LogoModel{
+ -- quantity = 6,
+ -- dim = 3,
+ -- finalTime = 10,
+ -- changes = function(agent)
+ -- if not agent:emptyNeighbor() then
+ -- print("not empty")
+ -- end
+ -- end
+ -- }
+ --
+ -- Empty:execute()
emptyNeighbor = function(agent)
local empty = {}
forEachNeighbor(agent:getCell(), function(_, neigh)
@@ -17,10 +30,21 @@
end
return Random():sample(empty)
- end
+ end,
--- Count the number of Agents in the neighbor cells.
-- @arg agent An Agent.
- -- @usage quantity = countNeighbors(agent)
+ -- @usage import("logo")
+ --
+ -- Count = LogoModel{
+ -- quantity = 3,
+ -- dim = 3,
+ -- finalTime = 2,
+ -- changes = function(agent)
+ -- print(agent:countNeighbors())
+ -- end
+ -- }
+ --
+ -- Count:execute()
countNeighbors = function(agent)
local count = 0
forEachNeighbor(agent:getCell(), function(_, neigh)
@@ -30,11 +54,22 @@
end)
return count
- end
+ end,
--- Walk to a random neighbor Cell. If there is no
-- empty neighbor then this function returns false.
-- @arg agent An Agent.
- -- @usage agent:relocate()
+ -- @usage import("logo")
+ --
+ -- Relocate = LogoModel{
+ -- quantity = 10,
+ -- dim = 10,
+ -- finalTime = 10,
+ -- changes = function(agent)
+ -- agent:relocate()
+ -- end
+ -- }
+ --
+ -- Relocate:execute()
relocate = function(agent)
local empty = agent:emptyNeighbor()
@@ -44,12 +79,24 @@
agent:move(empty)
return true
- end
+ end,
--- Reproduce the Agent to a random neighbor Cell.
-- If there is no empty neighbor cell then this
-- function returns nil.
-- @arg agent An Agent.
- -- @usage agent:breed()
+ -- @usage import("logo")
+ --
+ -- Breed = LogoModel{
+ -- quantity = 10,
+ -- dim = 10,
+ -- finalTime = 10,
+ -- changes = function(agent)
+ -- agent:breed()
+ -- agent:relocate()
+ -- end
+ -- }
+ --
+ -- Breed:execute()
breed = function(agent)
local empty = agent:emptyNeighbor()
@@ -61,17 +108,24 @@
newborn:move(empty)
return newborn
end
---}
+}
---[[
setmetatable(LogoAgent_, metaTableAgent_)
metaTableLogoAgent_ = {
__index = LogoAgent_
}
+--- Basic Agent for Logo models.
+-- @arg data.init A function that gets the agent itself as argument and
+-- will be executed when the agent is initialized.
+-- @arg data.execute A function that gets the agent itself as argument and
+-- is called every time step.
+-- @usage import("logo")
+--
+-- LogoAgent{}
function LogoAgent(data)
setmetatable(data, metaTableLogoAgent_)
return data
end
---]]
+
diff --git a/lua/LogoModel.lua b/lua/LogoModel.lua
index eeca62a..32b8214 100644
--- a/lua/LogoModel.lua
+++ b/lua/LogoModel.lua
@@ -81,14 +81,9 @@ function LogoModel(data)
}
end
- --instance.agent = LogoAgent{
- instance.agent = Agent{
+ instance.agent = LogoAgent{
init = init,
- execute = changes,
- emptyNeighbor = emptyNeighbor,
- breed = breed,
- countNeighbors = countNeighbors,
- relocate = relocate
+ execute = changes
}
instance.soc = Society{
diff --git a/lua/Overpopulation.lua b/lua/Overpopulation.lua
index 7b9830d..3fe0256 100644
--- a/lua/Overpopulation.lua
+++ b/lua/Overpopulation.lua
@@ -3,6 +3,15 @@
-- Each Agent beeds with a probability of 30%
-- and die if there are more than three Agents
-- in the neighborhood.
+-- @arg data.dim The x and y dimensions of space.
+-- @arg data.quantity The initial number of Agents in the model.
+-- @arg data.chart A boolean value indicating whether a Chart
+-- with the number of Agents along the simulation should
+-- be drawn.
+-- @arg data.finalTime The final simulation time.
+-- @arg data.map A boolean value indicating whether a Map
+-- with the spatial distribution r of Agents along the
+-- simulation should be drawn.
-- @image overpopulation.bmp
Overpopulation = LogoModel{
quantity = 10,
diff --git a/lua/SingleAgent.lua b/lua/SingleAgent.lua
index efde136..bd42a77 100644
--- a/lua/SingleAgent.lua
+++ b/lua/SingleAgent.lua
@@ -1,5 +1,14 @@
--- A single agent moving around randomly.
+-- @arg data.dim The x and y dimensions of space.
+-- @arg data.chart A boolean value indicating whether a Chart
+-- with the number of Agents along the simulation should
+-- be drawn.
+-- @arg data.quantity The initial number of Agents in the model.
+-- @arg data.finalTime The final simulation time.
+-- @arg data.map A boolean value indicating whether a Map
+-- with the spatial distribution r of Agents along the
+-- simulation should be drawn.
-- @image single-agent.bmp
SingleAgent = LogoModel{
quantity = 1,
diff --git a/lua/Sugarscape.lua b/lua/Sugarscape.lua
index d767baf..6ad7355 100644
--- a/lua/Sugarscape.lua
+++ b/lua/Sugarscape.lua
@@ -1,17 +1,22 @@
-local sugar = {}
-
-forEachFile(packageInfo("logo").data, function(file)
- if string.sub(file, -6) == ".sugar" then
- table.insert(sugar, string.sub(file, 1, -7))
- end
-end)
-
--- Model where a given Society grows, filling
-- the whole space. Agents reproduce with 20% of
-- probability if there is an empty neighbor.
+-- @arg data.dim The x and y dimensions of space.
+-- @arg data.quantity The initial number of Agents in the model.
+-- @arg data.chart A boolean value indicating whether a Chart
+-- with the number of Agents along the simulation should
+-- be drawn.
+-- @arg data.finalTime The final simulation time.
+-- @arg data.map A boolean value indicating whether a Map
+-- with the spatial distribution r of Agents along the
+-- simulation should be drawn.
+-- @arg data.sugarMap The spatial representation of the model.
+-- The available sugarscapes are described in the data available in the package.
+-- They should be used without ".sugar" extension. The default pattern is
+-- "room".
-- @image sugarscape.bmp
Sugarscape = LogoModel{
- sugarMap = Choice(sugar),
+ sugarMap = Choice(filesByExtension("logo", ".sugar")),
quantity = 10,
finalTime = 200,
space = function(instance)
diff --git a/lua/Utils.lua b/lua/Utils.lua
index 753953f..08cbb49 100644
--- a/lua/Utils.lua
+++ b/lua/Utils.lua
@@ -4,7 +4,9 @@ local base = getPackage("base") -- this table will be unnecessary when TerraME 1
--- Return a CellularSpace with the representation of a given labyrinth
-- data available in the package.
-- @arg pattern A string with the name of a labyrinth.
--- @usage cs = getLabyrinth("room")
+-- @usage import("logo")
+--
+-- room = getLabyrinth("room")
function getLabyrinth(pattern)
mandatoryArgument(1, "string", pattern)
local mfile = base.file(pattern..".labyrinth", "logo")
@@ -53,7 +55,9 @@ end
--- Return a CellularSpace with the representation of a given sugarscape
-- data available in the package.
-- @arg pattern A string with the name of a sugarscape.
--- @usage cs = getSugar("room")
+-- @usage import("logo")
+--
+-- room = getSugar("default")
function getSugar(pattern)
mandatoryArgument(1, "string", pattern)
diff --git a/snapshots/GrowingSociety-chart-1.bmp b/snapshots/GrowingSociety-chart-1.bmp
index 58b7872..0f78849 100644
Binary files a/snapshots/GrowingSociety-chart-1.bmp and b/snapshots/GrowingSociety-chart-1.bmp differ
diff --git a/tests/LogoAgent.lua b/tests/LogoAgent.lua
index 07f4024..518e238 100644
--- a/tests/LogoAgent.lua
+++ b/tests/LogoAgent.lua
@@ -14,5 +14,8 @@ return{
relocate = function(unitTest)
unitTest:assert(true)
end,
+ LogoAgent = function(unitTest)
+ unitTest:assert(true)
+ end
}