Skip to content

Commit

Permalink
Merge pull request #11 from pedro-andrade-inpe/master
Browse files Browse the repository at this point in the history
update to beta-5
  • Loading branch information
pedro-andrade-inpe committed Nov 30, 2016
2 parents 2d7ca9c + f1b1610 commit 98ef5da
Show file tree
Hide file tree
Showing 17 changed files with 85 additions and 13 deletions.
2 changes: 1 addition & 1 deletion description.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = "0.6.5"
version = "0.7.3"
license = "GPL"
package = "sysdyn"
depends = "terrame (>= 2.0), sci (>= 0.3)"
Expand Down
Binary file modified images/limited-growth.bmp
Binary file not shown.
Binary file added images/yeast.bmp
Binary file not shown.
12 changes: 12 additions & 0 deletions images/yeast.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

Random{seed = 12345}

import("sysdyn")

y = Yeast{}

y:run()

y.chart:save("yeast.bmp")
clean()

Binary file modified log/Daisyworld-chart-1.bmp
Binary file not shown.
Binary file modified log/Daisyworld-chart-2.bmp
Binary file not shown.
Binary file modified log/Daisyworld-chart-3.bmp
Binary file not shown.
Binary file modified log/Daisyworld-chart-4.bmp
Binary file not shown.
Binary file added log/Yeast-chart-1.bmp
Binary file not shown.
Binary file modified log/predator-prey-1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified log/predator-prey-2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions lua/RandomWalk.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ RandomWalk = Model{
value = 0,
prob = Choice{0, 0.3, 0.5, 0.7, 0.95, 1, default = 0.5},
finalTime = Choice{min = 10, default = 100},
random = true,
execute = function(model)
if Random():number(0, 1) <= model.prob then
model.value = model.value + 1
Expand Down
29 changes: 20 additions & 9 deletions lua/SIR.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,23 @@
-- @arg data.infected The initial indected population. The default value is 2.
-- @arg data.recovered The initial recovered population. The default value is 0.
-- @arg data.duration The duration of the disease in days. The default value is 2.
-- @arg data.contacts The number of contacts each infected has each time step. The default value is 6.
-- @arg data.finalTime The final simulation time, in days. The default value is 30.
-- @arg data.probability The probability of a susceptible person getting infected after
-- a contact with an infected one.
-- a contact with an infected one. The default value is 0.25.
-- @arg data.maximum A threshold of infected people that activates a public policy. The
-- policy asks people to start leaving their houses, which cuts the contacts
-- between people by half.
-- @image sir.bmp
-- @output maxInfected The maximum number of infected individuals along the simulation.
-- @output finalInfected A table with number of infected individuals in each simulation step.
SIR = Model{
susceptible = 9998,
infected = 2,
recovered = 0,
duration = 2,
finalTime = 30,
contacts = 6,
maximum = math.huge,
probability = 0.25,
init = function(model)
Expand All @@ -26,20 +30,27 @@ SIR = Model{
color = {"green", "red", "blue"}
}

model.contacts = 6
model.maxInfected = model.infected
model.finalInfected = {model.infected}

model.timer = Timer{
Event{action = function()
local proportion = model.susceptible /
(model.susceptible + model.infected + model.recovered)
local proportion = model.susceptible /
(model.susceptible + model.infected + model.recovered)

local newInfected = model.infected * model.contacts * model.probability * proportion
local newInfected = model.infected * model.contacts * model.probability * proportion

local newRecovered = model.infected / model.duration
local newRecovered = model.infected / model.duration

model.susceptible = model.susceptible - newInfected
model.recovered = model.recovered + newRecovered
model.infected = model.infected + newInfected - newRecovered
model.susceptible = model.susceptible - newInfected
model.recovered = model.recovered + newRecovered
model.infected = model.infected + newInfected - newRecovered

if model.maxInfected < model.infected then
model.maxInfected = model.infected
end

table.insert(model.finalInfected, model.infected)
end},
Event{action = function()
if model.infected >= model.maximum then
Expand Down
35 changes: 35 additions & 0 deletions lua/Yeast.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
--- A yeast growth model.
-- @arg data.cells The initial number of cells. The default value is 9.6.
-- @arg data.capacity The total capacity of the environment. The default value is 665.
-- @arg data.rate The growth rate of the cells. The default value is 1.1.
-- @arg data.finalTime The final simulation time. The default value is 9.
-- @output finalCells A vector with the quantity of cells in each time step.
-- @image yeast.bmp
Yeast = Model{
cells = 9.6,
capacity = 665.0,
rate = Choice{min = 0, max = 3.5, default = 1.1},
finalTime = 9,
init = function(model)
model.chart = Chart{
target = model,
select = {"cells"}
}

model.finalCells = {[0] = model.cells}

model.timer = Timer{
Event{action = function()
model.cells = model.cells + model.cells * model.rate * (1 - model.cells / model.capacity)

if model.cells > model.capacity then
model.cells = model.capacity
end

table.insert(model.finalCells, model.cells)
end},
Event{action = model.chart}
}
end
}

2 changes: 1 addition & 1 deletion tests/Daisyworld.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

return{
Daisyworld = function(unitTest)
local model = Daisyworld{}
local model = Daisyworld{finalTime = 40}

model:run()

Expand Down
4 changes: 2 additions & 2 deletions tests/PredatorPrey.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

return{
PredatorPrey = function(unitTest)
local p = PredatorPrey{}
local p = PredatorPrey{finalTime = 200}
p:run()

unitTest:assertEquals(p.predator, 41, 0.1)
unitTest:assertEquals(p.predator, 65.6, 0.1)
unitTest:assertSnapshot(p.chart1, "predator-prey-1.png", 0.1)
unitTest:assertSnapshot(p.chart2, "predator-prey-2.png", 0.1)
end,
Expand Down
13 changes: 13 additions & 0 deletions tests/Yeast.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-- Test file for Yeast.lua
-- Author: Gilberto Camara and Pedro R. Andrade

return{
Yeast = function(unitTest)
local model = Yeast{}

model:run()

unitTest:assertSnapshot(model.chart, "Yeast-chart-1.bmp", 0.05)
end,
}

0 comments on commit 98ef5da

Please sign in to comment.