MRC-CSO-SPHSU / LoneParentsModel.jl

An initial implementation of an ABM for social and child care
0 stars 5 forks source link

Potential simplification #60

Closed AtiyahElsheikh closed 2 years ago

AtiyahElsheikh commented 2 years ago

Some pieces of code is subject to simplification.

For instance:

            setDead!(person) 
            resetHouse!(person)
            isSingle(person) ?
                nothing :  
                resolvePartnership!(partner(person),person)

the last two statements can be moved to the function setDead!()

Also, the Person constructor can be improved so that the client does not take care setting up kinship relationship. My current, Person inner cor looks as

function Person(pos, info, kinship)
        person = new(getIDCOUNTER(),pos,info,kinship)
        if !undefined(pos)
            addOccupant!(pos, person)
        end

        kinship.father != nothing ? addChild!(kinship.father,person) : nothing
        kinship.mother != nothing ? addChild!(kinship.mother,person) : nothing  
        if kinship.partner != nothing
            resetPartner!(kinship.partner)
            partner.partner = person 
        end 
        if length(kinship.children) > 0
            for child in kinship.children
                setAsParentChild!(person,child)
            end
        end 

        person  
    end 

instead of

function Person(pos, info, kinship)
        person = new(getIDCOUNTER(),pos,info,kinship)
        if !undefined(pos)
            addOccupant!(pos, person)
        end
        person  
    end 

This also simplifies the implementation of DoBirths

p.s. : will also modify the ?to if

mhinsch commented 2 years ago

The important thing to keep in mind, though, is that the agent building blocks need to be able to function independently. setDead! for example is currently delegated to BasicInfo which of course knows nothing about relationships etc. The way to go would then be to implement setDead!(::Person) which does all the things you mention and in turn calls setDead!(::BasicInfo) (setDeat would then have to be taken out of the delegation list in person.jl).