diff --git a/README.md b/README.md index 4be05a7..5ec5f3b 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/lpm.jl b/lpm.jl index 1bd173a..67ba7e4 100644 --- a/lpm.jl +++ b/lpm.jl @@ -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 @@ -16,4 +16,3 @@ using SocioEconomicsX.Specification.Simulate using SocioEconomicsX.Utilities include("mainHelpers.jl") - diff --git a/mainHelpers.jl b/mainHelpers.jl index 8c33b9a..3dc02c2 100644 --- a/mainHelpers.jl +++ b/mainHelpers.jl @@ -11,7 +11,7 @@ mutable struct Model end function createDemography!(datapars, pars) - ukTowns = createTowns(pars) + ukTowns = create_inhabited_towns(pars) ukHouses = Vector{PersonHouse}() diff --git a/mainMAHelpers.jl b/mainMAHelpers.jl index ddfe54e..fe0e110 100644 --- a/mainMAHelpers.jl +++ b/mainMAHelpers.jl @@ -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 diff --git a/src/malpm/Models.jl b/src/malpm/Models.jl index dbed54d..4715762 100644 --- a/src/malpm/Models.jl +++ b/src/malpm/Models.jl @@ -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) @@ -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 @@ -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 \ No newline at end of file diff --git a/src/malpm/demography/SimSetup.jl b/src/malpm/demography/SimSetup.jl index aab3019..4528b21 100644 --- a/src/malpm/demography/SimSetup.jl +++ b/src/malpm/demography/SimSetup.jl @@ -27,7 +27,6 @@ is provided here @return dictionary of required simulation parameters """ - function setupCommon!(sim::AbstractABMSimulator) verbose(sim) ? setVerbose!() : unsetVerbose!() @@ -57,7 +56,6 @@ end function setup!(sim::AbstractABMSimulator,example::LPMUKDemographyOpt) - #attach_agent_step!(sim,agestepAlivePerson!) setupCommon!(sim) diff --git a/src/malpm/demography/Simulate.jl b/src/malpm/demography/Simulate.jl index 6898d77..3c68e69 100644 --- a/src/malpm/demography/Simulate.jl +++ b/src/malpm/demography/Simulate.jl @@ -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