Skip to content

Commit

Permalink
Merge pull request #15 from MRC-CSO-SPHSU/develop
Browse files Browse the repository at this point in the history
Version 0.2.6
  • Loading branch information
AtiyahElsheikh authored Dec 28, 2022
2 parents 25c45de + 14d10c8 commit 1b45727
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 59 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ Releases

- **V0.2.0 (5.12.2022)** : Unified API of CreateX and Initialize functions (compatible with SE V0.2)

- V0.2.1 (7.12) : - (MALPM only) New Simulation Interface for 3 functions, doBirths!, doDeaths!, doDivorces, Improved API for parameter accessory functions, compatible with SE* Version 0.2.1
- V0.2.2 (8.12) : - (MALPM only) doMarriages (SE* V0.2.2)
- V0.2.3 (9.12) : - (MALPM only) adoptions, workTransitions, socialTransitions, ageTransitions (SE* V0.2.3)
- V0.2.4 (14.12) : - (MALPM only) adjusting to SimpleABM types of MA Version 0.4, improved model data structure

- V0.2.1 (7.12) : (MALPM only) New Simulation Interface for 3 functions, doBirths!, doDeaths!, doDivorces, Improved API for parameter accessory functions, compatible with SE* Version 0.2.1
- V0.2.2 (8.12) : (MALPM only) doMarriages (SE* V0.2.2)
- V0.2.3 (9.12) : (MALPM only) adoptions, workTransitions, socialTransitions, ageTransitions (SE* V0.2.3)
- V0.2.4 (14.12) : (MALPM only) adjusting to SimpleABM types of MA Version 0.4, improved model data structure
- V0.2.5 (21.12) : (MALPM only) exploits some tuned simulation functions from SE* V0.2.5 and improved performance (3x faster)
- V0.2.6 (27.12) : (MALPM only) Improved implementation of allocation algorithms (no temporary arrays), tuned do marriage algorithm (memoization can be avoided) & Improved runtime performance (3x faster & 4x less memory allocation and storage w.r.t. V0.2.5)
3 changes: 1 addition & 2 deletions lpm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ include("libspath.jl")
using SocioEconomicsX: SEVERSION
using SocioEconomicsX: SEPATH, SESRCPATH

@assert SEVERSION == v"0.2.4"
@assert SEVERSION == v"0.2.6"

using SocioEconomicsX.ParamTypes

Expand All @@ -16,4 +16,3 @@ using SocioEconomicsX.Specification.Simulate
using SocioEconomicsX.Utilities

include("mainHelpers.jl")

2 changes: 1 addition & 1 deletion mainHelpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ mutable struct Model
end

function createDemography!(datapars, pars)
ukTowns = createTowns(pars)
ukTowns = create_inhabited_towns(pars)

ukHouses = Vector{PersonHouse}()

Expand Down
2 changes: 1 addition & 1 deletion mainMAHelpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ addToLoadPath!("../MultiAgents.jl")

using SocioEconomics: SEVERSION, SEPATH, SESRCPATH

@assert SEVERSION == v"0.2.4"
@assert SEVERSION == v"0.2.6"

using SocioEconomics.ParamTypes

Expand Down
19 changes: 12 additions & 7 deletions src/malpm/Models.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,28 @@ This module is within the MALPM module

module Models

using SocioEconomics.XAgents: Town, PersonHouse, Person, alive
using SocioEconomics.XAgents: Town, PersonHouse, PersonTown, Person, alive
using SocioEconomics.ParamTypes: DemographyPars, MapPars, DemographyData
using MultiAgents: AbstractMABM, SimpleABM
using MultiAgents: AbstractMABM, SimpleABM
using MultiAgents: add_agent!, kill_agent_at_opt!

import SocioEconomics.API.ParamFunc: populationParameters, birthParameters, divorceParameters,
marriageParameters, workParameters, allParameters
import SocioEconomics.API.ModelFunc: allPeople, alivePeople, dataOf, houses, towns
marriageParameters, workParameters, allParameters, mapParameters
import SocioEconomics.API.ModelFunc: allPeople, alivePeople, dataOf, houses, towns, add_person!, add_house!, remove_person!

import MultiAgents: allagents

export MAModel

mutable struct MAModel <: AbstractMABM
towns :: SimpleABM{Town}
struct MAModel <: AbstractMABM
towns :: SimpleABM{PersonTown}
houses :: SimpleABM{PersonHouse}
pop :: SimpleABM{Person}
parameters :: DemographyPars
data :: DemographyData

function MAModel(model,pars,data)
ukTowns = SimpleABM{Town}(model.towns)
ukTowns = SimpleABM{PersonTown}(model.towns)
ukHouses = SimpleABM{PersonHouse}(model.houses)
ukPopulation = SimpleABM{Person}(model.pop)
new(ukTowns,ukHouses,ukPopulation,pars,data)
Expand All @@ -42,6 +43,9 @@ houses(model::MAModel) = allagents(model.houses)
towns(model::MAModel) = allagents(model.towns)
#dataOf(model) = model.pop.data
dataOf(model) = model.data
add_person!(model, person) = add_agent!(model.pop, person)
remove_person!(model, personidx::Int) = kill_agent_at_opt!(personidx, model.pop)
add_house!(model, house) = add_agent!(model.houses, house)


allParameters(model::MAModel) = model.parameters
Expand All @@ -50,5 +54,6 @@ birthParameters(model::MAModel) = model.parameters.birthpars
divorceParameters(model::MAModel) = model.parameters.divorcepars
marriageParameters(model::MAModel) = model.parameters.marriagepars
workParameters(model::MAModel) = model.parameters.workpars
mapParameters(model::MAModel) = model.parameters.mappars

end # module Models
2 changes: 0 additions & 2 deletions src/malpm/demography/SimSetup.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ is provided here
@return dictionary of required simulation parameters
"""


function setupCommon!(sim::AbstractABMSimulator)

verbose(sim) ? setVerbose!() : unsetVerbose!()
Expand Down Expand Up @@ -57,7 +56,6 @@ end


function setup!(sim::AbstractABMSimulator,example::LPMUKDemographyOpt)

#attach_agent_step!(sim,agestepAlivePerson!)
setupCommon!(sim)

Expand Down
73 changes: 32 additions & 41 deletions src/malpm/demography/Simulate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,64 +9,55 @@ using MultiAgents: add_agent!, currstep
using MALPM.Demography.Population: removeDead!
using MALPM.Demography: DemographyExample, LPMUKDemography, LPMUKDemographyOpt
using SocioEconomics
import SocioEconomics.Specification.SimulateNew: doDeaths!, doBirths!,
using SocioEconomics.API.Traits: FullPopulation, NoReturn
import SocioEconomics.Specification.SimulateNew: dodeaths!, dobirths!,
dodivorces!, domarriages!,
doAgeTransitions!, doWorkTransitions!, doSocialTransitions!,
doDivorces!, doMarriages!, doAssignGuardians!
doAssignGuardians!

"""
dead people could be indicies in the population and in such a
case it is assumed that these indices are ordered
"""
function removeDeads!(deadpeople,pop,::LPMUKDemography)
for deadperson in Iterators.reverse(deadpeople)
removeDead!(deadperson,pop)
end

nothing
end

removeDeads!(deadpeople,pop,::LPMUKDemographyOpt) = nothing

function doDeaths!(model::AbstractMABM, sim::AbstractABMSimulator, example::DemographyExample)
#(deadpeople, deadsind) = doDeaths!(model,currstep(sim))
(; deadsind) = doDeaths!(model,currstep(sim))

#len = length(model.pop.agentsList)
#@info deadsind len

function doDeaths!(model::AbstractMABM, sim::AbstractABMSimulator, ::LPMUKDemography)
# (; deadsind) = dodeaths!(model,currstep(sim))
# ToDo separate step?
# removeDeads!(deads,model.pop,example)
removeDeads!(deadsind,model.pop,example)

# for ind in Iterators.reverse(deadsind)
# removeDead!(ind,model.pop)
# end
dodeaths!(model, currstep(sim))
nothing
end # function doDeaths!

function doBirths!(model::AbstractMABM, sim::AbstractABMSimulator, example::DemographyExample)

newbabies = doBirths!(model, currstep(sim))

# false ? population.variables[:numBirths] += length(newbabies) : nothing # Temporarily this way till realized

for baby in newbabies
add_agent!(model.pop,baby)
end
function doDeaths!(model, sim, ::LPMUKDemographyOpt)
dodeaths!(model,currstep(sim),FullPopulation(),NoReturn())
nothing
end # function doDeaths!

_dobirths!(model,sim,::LPMUKDemography) = dobirths!(model, currstep(sim))
_dobirths!(model,sim,::LPMUKDemographyOpt) =
dobirths!(model, currstep(sim),FullPopulation(),NoReturn())

function doBirths!(model, sim, example)
#(;babies) = _dobirths!(model, sim, example)
# TODO separate step?
# for baby in babies
# add_agent!(model.pop,baby)
#end
_dobirths!(model, sim, example)
nothing
end

_dodivorces!(model,sim,::LPMUKDemography) = dodivorces!(model, currstep(sim))
_dodivorces!(model,sim,::LPMUKDemographyOpt) = dodivorces!(model, currstep(sim),FullPopulation(), NoReturn())

function doDivorces!(model::AbstractMABM, sim::AbstractABMSimulator, example::DemographyExample)

doDivorces!(model, currstep(sim))

function doDivorces!(model, sim, example)
_dodivorces!(model, sim, example)
nothing
end

_domarriages!(model,sim,::LPMUKDemography) = domarriages!(model, currstep(sim))
_domarriages!(model,sim,::LPMUKDemographyOpt) = domarriages!(model, currstep(sim),FullPopulation(), NoReturn())

function doMarriages!(model::AbstractMABM, sim::AbstractABMSimulator, example::DemographyExample)

doMarriages!(model, currstep(sim))

_domarriages!(model, sim,example)
nothing
end

Expand Down

0 comments on commit 1b45727

Please sign in to comment.