internal override double GetValue(HH hh, List <Person> tu, Person person) { double fatherId = hh.GetPersonValue(indexFatherIdVar, person.indexInHH); for (byte i = 0; i < hh.GetPersonCount(); i++) { if (fatherId == hh.GetPersonValue(indexPersonIdVar, i)) { return(parIncome.GetValue(hh, tu, new Person(i))); } } return(0.0); }
protected void SetCounter(HH hh, double cnt) { if (hh == null) { infoStore.hhAdmin.GlobalSetVar(varIndexLoopCounter, cnt); // sequential run: set counter for all households } else // parallel run: set counter only for the currently processed household { for (int personIndex = 0; personIndex < hh.GetPersonCount(); ++personIndex) { hh.SetPersonValue(cnt, varIndexLoopCounter, personIndex); } } }
private void InitVar(HH hh, out int nElig) { nElig = 0; foreach (List <Person> tu in hh.GetTUs(eligUnit)) { bool isMet = parEligUnitCond == null ? true : FunInSpineBase.IsCondMetByTU(hh, tu, parEligUnitCond, who); if (isMet) { ++nElig; } hh.SetTUValue(isMet ? 1 : 0, varIndexIsElig, tu); // on TU-level: set isULElig_loopname hh.SetTUValue(isMet ? nElig : 0, varIndexIsEligInIter, tu); // on TU-level: set isEligInIter_loopname } for (int p = 0; p < hh.GetPersonCount(); ++p) { hh.SetPersonValue(nElig, varIndexNElig, p); // on HH-level: set nULElig_loopname } }
internal override double GetValue(HH hh, List <Person> tu, Person person) { double perId = hh.GetPersonValue(indexPersonIdVar, person.indexInHH); double parId = hh.GetPersonValue(indexPartnerIdVar, person.indexInHH); // also get the partnerID if (parId == 0) { parId = -1; // don't match 0! } for (int i = 0; i < hh.GetPersonCount(); i++) { if (hh.GetPersonValue(indexFatherIdVar, i) == perId || hh.GetPersonValue(indexMotherIdVar, i) == perId || hh.GetPersonValue(indexFatherIdVar, i) == parId || hh.GetPersonValue(indexMotherIdVar, i) == parId) { return(1.0); } } return(0.0); }
internal override double GetValue(HH hh, List <Person> tu, Person person) { GetAgeLimits(out double ageMin, out double ageMax); double personId = hh.GetPersonValue(indexPersonIdVar, person.indexInHH); double income = 0.0; for (byte i = 0; i < hh.GetPersonCount(); i++) { if (personId == hh.GetPersonValue(indexMotherIdVar, i) || personId == hh.GetPersonValue(indexFatherIdVar, i)) { double age = hh.GetPersonValue(indexAgeVar, i); if (age >= ageMin && age <= ageMax) { income += parIncome.GetValue(hh, tu, new Person(i)); } } } return(income); }
internal override double GetValue(HH hh, List <Person> tu, Person person) { GetAgeLimits(out double ageMin, out double ageMax); double headID = hh.GetPersonValue(indexPersonIdVar, person.indexInHH), partnerID = hh.GetPersonValue(indexPartnerIdVar, person.indexInHH); double n = 0.0; for (int i = 0; i < hh.GetPersonCount(); i++) { if (hh.GetPersonValue(indexPersonIdVar, i) != headID && hh.GetPersonValue(indexPersonIdVar, i) != partnerID) { if (hh.GetPersonValue(indexFatherIdVar, i) == headID || (partnerID > 0 && hh.GetPersonValue(indexFatherIdVar, i) == partnerID) || hh.GetPersonValue(indexMotherIdVar, i) == headID || (partnerID > 0 && hh.GetPersonValue(indexMotherIdVar, i) == partnerID)) { if (hh.GetPersonValue(indexAgeVar, i) >= ageMin && hh.GetPersonValue(indexAgeVar, i) <= ageMax) { ++n; } } } } return(n); }
// This is the function that composes the actual TUs internal List <List <Person> > ComposeTUs(HH hh, out bool _isStatic) { // first check if we need to initiate the local objects PrepareLocals(); List <List <Person> > tus = new List <List <Person> >(); _isStatic = isStatic; // if static, TUs can be stored and do not need to be recreated on next use // if type is INDIVIDUAL, then create a TU for each person if (tuType == DefPar.Value.TUTYPE_IND) { for (byte i = 0; i < hh.GetPersonCount(); ++i) { double headPersonID = hh.GetPersonValue(indexPersonId, i); List <Person> temp_tu = new List <Person>() { new Person(i) { tuHeadID = headPersonID, isHead = true } }; PopulateTUMembersInfo(temp_tu, hh, 0, headPersonID); // isLoneParent is not filled, but is impossible in Individual households anyway... tus.Add(temp_tu); } return(tus); } else // else type is HOUSEHOLD or SUBGROUP { // compose a dictionary of all members, to hold calculated incomes & ages Dictionary <byte, Person> headCandidates = new Dictionary <byte, Person>(); for (byte i = 0; i < hh.personVarList.Count; i++) { headCandidates.Add(i, new Person(i)); } if (tuType == DefPar.Value.TUTYPE_SUBGROUP) // if type is SUBGROUP, create TUs until you run out of HH members { while (headCandidates.Count > 0) { byte head = GetHead(hh, headCandidates); // first get the head from the unassigned HH members double headPersonID = hh.GetPersonValue(indexPersonId, head); List <Person> tu = new List <Person>(); // create a TU with all unassigned members and this head - this will be used for calculating Person attributes (e.g. isDepChild etc) List <Person> temp_tu = MakeTempTU(headCandidates, hh, head); // populate the Person attributes, except for isLoneParent (see below) PopulateTUMembersInfo(temp_tu, hh, headCandidates.ElementAt(0).Key, headPersonID); // add the head to the new TU tu.Add(temp_tu[0]); // head should always be first temp_tu.RemoveAt(0); // remove it from the temp_tu // add the rest of the members foreach (string member_type in members) { List <Person> ps = new List <Person>(); switch (member_type) { case DefPar.DefTu.MEMBER_TYPE.DEPCHILD: ps = temp_tu.Where(p => p.isDepChild).ToList(); break; case DefPar.DefTu.MEMBER_TYPE.DEPPARENT: ps = temp_tu.Where(p => p.isDepParent).ToList(); break; case DefPar.DefTu.MEMBER_TYPE.DEPRELATIVE: ps = temp_tu.Where(p => p.isDepRelative).ToList(); break; case DefPar.DefTu.MEMBER_TYPE.LOOSEDEPCHILD: ps = temp_tu.Where(p => p.isLooseDepChild).ToList(); break; case DefPar.DefTu.MEMBER_TYPE.OWNCHILD: ps = temp_tu.Where(p => p.isOwnChild).ToList(); break; case DefPar.DefTu.MEMBER_TYPE.OWNDEPCHILD: ps = temp_tu.Where(p => p.isOwnDepChild).ToList(); break; case DefPar.DefTu.MEMBER_TYPE.PARTNER: ps = temp_tu.Where(p => p.isPartner).ToList(); break; default: infoStore.communicator.ReportError(new Communicator.ErrorInfo() { isWarning = false, runTimeErrorId = description.Get(), message = $"{description.Get()}: invalid member type found '{member_type}'" }); break; } foreach (Person p in ps) { tu.Add(p); temp_tu.Remove(p); } } // then, if required, add the DepOfDep if (assignPartnerOfDependents || assignDepChOfDependents) { // in the old executable we only check remaining members in order // in EM3, should we allow members to be added in mixed order too? byte i = 0; // for each member of the TU while (i < tu.Count) { // if this person is a dependent, check if members can be attached if (tu[i].isDepChild || tu[i].isDepParent || tu[i].isDepRelative || tu[i].isLooseDepChild || tu[i].isOwnDepChild || tu[i].isDepMember) { double personId = hh.GetPersonValue(indexPersonId, tu[i].indexInHH); int j = 0; // check the unassigned members while (j < temp_tu.Count) { bool add = false; if (assignPartnerOfDependents && (personId == hh.GetPersonValue(indexPartnerId, temp_tu[j].indexInHH))) { add = true; } else if (assignDepChOfDependents && temp_tu[j].isDepChild && (personId == hh.GetPersonValue(indexFatherId, temp_tu[j].indexInHH) || personId == hh.GetPersonValue(indexMotherId, temp_tu[j].indexInHH))) { add = true; } if (add) { temp_tu[j].isDepMember = true; // flag this as a dependent member tu.Add(temp_tu[j]); // add it to the TU temp_tu.RemoveAt(j); // and remove it from the unassigned } else { j++; // advance to the next unassigned member } } } ++i; // advance to the next person in the TU } } // we need to run loneParentCond only on people already added to the TU! Dictionary <byte, bool> allLoneParent = loneParentCond.GetTUValues(hh, tu, true); for (byte i = 0; i < tu.Count; i++) { tu[i].isLoneParent = allLoneParent[tu[i].indexInHH]; } // the TU is complete, so add it to the list of TUs tus.Add(tu); // finally remove anyone that was added in this TU from the headCandidates of the next round foreach (Person p in tu) { headCandidates.Remove(p.indexInHH); } } } else { byte head = GetHead(hh, headCandidates); double headPersonID = hh.GetPersonValue(indexPersonId, head); List <Person> tu = new List <Person>(); tu.Add(new Person(head) { isHead = true, tuHeadID = headPersonID }); // head should always be first for (byte i = 0; i < hh.GetPersonCount(); ++i) // then add the rest { if (i != head) { tu.Add(new Person(i)); } } PopulateTUMembersInfo(tu, hh, tu[0].indexInHH, headPersonID); // we need to run loneParentCond only on people already added to the TU! Dictionary <byte, bool> allLoneParent = loneParentCond.GetTUValues(hh, tu, true); for (byte i = 0; i < tu.Count; i++) { tu[i].isLoneParent = allLoneParent[tu[i].indexInHH]; } tus.Add(tu); } } return(tus); }