Skip to content

FemalesWithChildrenByChildAgeCSfilter only sees the last child #499

Description

@amorison

The FemalesWithChildrenByChildAgeCSfilter filter is incorrectly implemented. The offending bit is this loop, gathering children ages:

Set<Person> childrenInBU = person.getBenefitUnit().getChildren();
int[] ages = new int[childrenInBU.size()];
if (childrenInBU != null) {
    int arrayPosition = 0;
    for (Person child : childrenInBU) {
        ages[arrayPosition] = child.getDemAge();
    }
}

arrayPosition is never incremented, meaning ages will only see one child (and if there are more than one children, this means the minimum age being seen will also be 0 rather than the age of that child).

The semantic of that filter is also slightly unclear. Looking at the implementation (and especially an older implementation that's been commented out), this seems to be intended to check that all children are in the given age range. The way it's used in experiment/SimPathsObserver.java, however, seems to need to check that any child (rather than all children) is in the given age range (for which leveraging BenefitUnit::getIndicatorChildren is probably the way to go).

Note: the check childrenInBU != null is unnecessary since BenefitUnit::getChildren never returns a null. It's also too late anyway since childrenInBU.size() called before would fail on a null.

Once the semantic is clarified, I'm happy to make a PR (I also have a performance improvement for BenefitUnit::getIndicatorChildren I can throw in).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions