MRC-CSO-SPHSU / UKSEABMLib.jl

MIT License
1 stars 1 forks source link

adoptions not consistent #30

Closed AtiyahElsheikh closed 1 year ago

AtiyahElsheikh commented 1 year ago

Most recent simulations function don't contain enough consistency checking. Apparently large potion of initial population is considered as orphans and they are subject to adoptions till their deaths.

AtiyahElsheikh commented 1 year ago
function findOtherGuardian_(person, people)
    candidates = [ p for p in people if 
        isFemale(p) && canLiveAlone(p) && !isSingle(p) && 
            (status(p) == WorkStatus.worker || status(partner(p)) == WorkStatus.worker) ]

which is responsible for identifying the guardian candidates for a non-guarded person, no candidates have been found. The last condition is not fulfilled at all leading to no candidates. This implies that work status initialization is not properly done.

Apart from this, a candidate has to be alive as well.

Initially, when removing the last condition, the function works (temporarily till identifying the error in work status initialization). Also runtime and memory performance improve (25% , 5-10% simultaneously).

AtiyahElsheikh commented 1 year ago
function assignGuardian!(person, time, model)
    guard = findFamilyGuardian_(person)
    people = allPeople(model)
    if guard == nothing
        guard = findOtherGuardian_(person, people)
    end

    # get rid of previous (possibly dead) guardians
    # this implies that relatives of a non-related former legal guardian
    # that are now excluded due to age won't get a chance again in the future
    empty!(guardians(person))
    ... 

In the above function, the last statement show that guardians of a person without guardians are still there. The code should be made consistent so that such statement shall not be needed.

AtiyahElsheikh commented 1 year ago

When performing guardians assignments as an agent-based transition (probably leading to some execution re-ordering of processes ), an assertion error is raised from the code:

function resolveDependency!(guardian, dependent)
    deps = dependents(guardian)
    idx_d = findfirst(==(dependent), deps)
    if idx_d == nothing  # an error should be returned?
        return
    end

    deleteat!(deps, idx_d)

    guards = guardians(dependent)
    idx_g = findfirst(==(guardian), guards)
    if idx_g == nothing
        error("inconsistent dependency!")
    end
    deleteat!(guards, idx_g)
end

This function is called in divorce.jl

AtiyahElsheikh commented 1 year ago

Probably it makes sense that adoptions , dependencies, work status etc. should be initialised in the initial population.

AtiyahElsheikh commented 1 year ago

This shall be re-considered when economic part of the model is progressed.