internal override void Run(HH hh, List <Person> tu)
        {
            if (!IsRunCondMet(hh))
            {
                return;
            }

            if (IsEligCondMet(hh, tu))
            {
                Dictionary <byte, bool> persElig = eligCond.GetTUValues(hh, tu);

                foreach (var elig in persElig)
                {
                    hh.SetPersonValue(value: elig.Value ? 1 : 0, varIndex: indexOutVar, personIndex: elig.Key);
                }

                if (coParResultVar != null)
                {
                    foreach (var elig in persElig)
                    {
                        hh.SetPersonValue(value: elig.Value ? 1 : 0, varIndex: coParResultVar.index, personIndex: elig.Key);
                    }
                }
            }
            else
            {
                hh.SetTUValue(value: 0, varIndex: indexOutVar, tu: tu, addTo: false);
                if (coParResultVar != null)
                {
                    hh.SetTUValue(value: 0, varIndex: coParResultVar.index, tu: tu);
                }
            }
        }
 protected virtual void SetOutVars(double val, HH hh, List <Person> tu)
 {
     hh.SetTUValue(value: val, varIndex: coParOutVar.Item1.index, tu: tu, addTo: coParOutVar.Item2);
     if (coParResultVar != null)
     {
         hh.SetTUValue(value: val, varIndex: coParResultVar.index, tu: tu);
     }
 }
Пример #3
0
 internal override void Run(HH hh, List <Person> tu) // note: DefVar does not have a TAX_UNIT parameter
 {                                                   // therefore tu is DUMMY_INDIVIDUAL_TU, i.e. this is called for each person
     if (!IsRunCondMet(hh))
     {
         return;                    // see note in PrepareNonCommonPar
     }
     // initialise the variables (see notes above)
     foreach (List <VarDef> condGroup in varDefs.Values)
     {
         double init = double.MaxValue;
         foreach (VarDef vd in condGroup.OrderBy(x => x.groupNo)) // make sure you preserve group order in applying conditions!
         {
             if (vd.condition != null && !vd.condition.GetPersonValue(hh, tu[0]))
             {
                 continue;
             }
             init = vd.initFormula.GetValue(hh, tu); // usually this line would be enough for assessing the init-value, the rest is just for DefVar with Conditions
         }
         if (init == double.MaxValue)
         {
             infoStore.communicator.ReportError(new Communicator.ErrorInfo()
             {
                 isWarning = true, runTimeErrorId = description.funID,
                 message   = $"{description.Get()}: is initialised with zero for idperson={infoStore.GetIDPerson(hh, tu[0].indexInHH)}, because no suitable condition was found"
             });
             init = 0;
         }
         hh.SetTUValue(init, condGroup[0].varSpec.index, tu);
     }
 }
        private void RunUnitLoop(HH hh, List <Person> tu)
        {
            // store the "running" variables (yem_unit, ils_earns_unit), and take the level into account
            foreach (StoreVar v in vars)
            {
                if (v.iteration != NOTAP)
                {
                    continue;                       // is handled below
                }
                if (hh.GetPersonValue(varIndexCurElig, tu[0].indexInHH) <= 0)
                {
                    continue;                                                         // store only for the (head of the) "currently elig" unit
                }
                List <Person> altTU  = hh.GetAlternativeTU(v.level, tu, description); // on may consider performance here, but let's first get it right
                double        levVal = v.unitLoopILPar == null?hh.GetTUValue(v.origVar.index, altTU) : v.unitLoopILPar.GetValue(hh, altTU);

                hh.SetPersonValue(levVal, v.storeVar.index, tu[0].indexInHH);
            }

            // store the "on demand" variables (e.g. yem_unit1) - they are stored the same way as for a normal loops (i.e. no level-stuff)
            foreach (StoreVar v in vars)
            {
                if (v.iteration != NOTAP && v.iteration == hh.GetPersonValue(varIndexLoopCounter, 0))
                {
                    hh.SetTUValue(hh.GetTUValue(v.origVar.index, tu), v.storeVar.index, tu);
                }
            }
        }
 private void SetCurElig(HH hh, double curIter)
 {
     foreach (List <Person> tu in hh.GetTUs(eligUnit))                // set the variable for each TU in the HH
     {
         double eligInIter = hh.GetTUValue(varIndexIsEligInIter, tu); // assess in which iteration the TU is "elig"
         hh.SetTUValue(eligInIter == curIter ? 1 : 0, varIndexIsCurElig, tu);
     }
 }
 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
     }
 }
Пример #7
0
 internal override void Run(HH hh, List <Person> tu) // note: IlArithOp does not have a TAX_UNIT parameter
 {                                                   // therefore tu is DUMMY_INDIVIDUAL_TU, i.e. this is called for each person
     if (!IsRunCondMet(hh))
     {
         return;
     }
     foreach (OutSpecification os in outSpecifications)
     {
         hh.SetTUValue(os.parFormula.GetValue(hh, tu), os.varSpec.index, tu);
     }
 }
Пример #8
0
        internal override void Run(HH hh, List <Person> tu) // note: Scale does not have a TAX_UNIT parameter
        {                                                   // therefore tu is DUMMY_INDIVIDUAL_TU, i.e. this is called for each person
            if (factorVar == 1 || !IsRunCondMet(hh))
            {
                return;
            }

            foreach (int varIndex in infoStore.operandAdmin.GetMonetaryVarIndices())
            {
                hh.SetTUValue(hh.GetTUValue(varIndex, tu) * factorVar, varIndex, tu);
            }
        }
        private void RunLoopAndFix(HH hh, List <Person> tu)
        {
            // remark: gets an "invalid" loop-counter (0/end of loop) if a loop-store is used outside a loop, but that's a developer error/decision
            double curIteration = varIndexLoopCounter == NOTAP ? NOTAP : hh.GetPersonValue(varIndexLoopCounter, 0);

            foreach (StoreVar v in vars)
            {
                if (v.iteration == NOTAP ||      // always stored (possibly overwritten): yem_loop, yem_backup, i.e. in each iteration or outside any loop
                    v.iteration == curIteration) // stored only if it is the appropriate iteration: yem_loop7
                {
                    hh.SetTUValue(hh.GetTUValue(v.origVar.index, tu), v.storeVar.index, tu);
                }
            }
        }
        // note that Restore actually does not have a TAX_UNIT, thus this is the HHAdmin.DUMMY_INDIVIDUAL_TU (see FunInSpineBase.GetTUName)
        // that means, amongst others, that the function is called for each person in the household (i.e. tu always contains one person)
        internal override void Run(HH hh, List <Person> tu)
        {
            if (!IsRunCondMet(hh))
            {
                return;
            }

            foreach (FunStore.StoreVar v in relatedStore.vars)
            {
                if (loopIteration == -1 || v.iteration == loopIteration)
                {
                    hh.SetTUValue(hh.GetTUValue(v.storeVar.index, tu), v.origVar.index, tu);
                }
            }
        }