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
     }
 }
        private StringBuilder ProcessHHoutput(HH hh, double convFactor)
        {
            StringBuilder hhResults = new StringBuilder();

            foreach (List <Person> tu in hh.GetTUs(coParTU.name))
            {
                if (!IsOutputElig(hh, tu))
                {
                    continue;
                }

                StringBuilder tuRow = new StringBuilder();


                List <ParVarIL> orderedValues = outList.OrderBy(p => int.Parse(p.Value.description.par.order)).Select(p => p.Value).ToList();    // try to output in UI order
                foreach (ParVarIL parOut in orderedValues)
                {
                    double value = parOut.GetValue(hh, tu);
                    // if value is "VOID", check if you need to replace the value
                    if (value == FunStore.UNITLOOP_VOID)
                    {
                        if (doReplaceUnitLoopVoidBy)
                        {
                            value = replaceUnitLoopVoidBy;
                        }
                        if (!suppressVoidMessage)
                        {
                            // old exec behaviour:
                            //                      std::string handling = "Zero is used as default value for the not defined variables.";
                            //						if(RepVoidBy) handling = CEMUtilities::DoubleToStr(RepVoidBy) + " is used as default value for the incomelist.";
                            //						if(!CEMError::NonCritErr("Use of not yet calculated variable(s) "+VoidVar+"in incomelist '"+* iti+"'.", this, "", "", handling)) return 0;
                            string msg = $"{description.Get()}: VOID value found in '{parOut.GetName()}' for hhid '{infoStore.GetIDHH(hh)}'";
                            if (doReplaceUnitLoopVoidBy)
                            {
                                msg += " and replaced by " + value;
                            }
                            infoStore.communicator.ReportError(new Communicator.ErrorInfo()
                            {
                                isWarning = true, message = msg, runTimeErrorId = description.funID
                            });
                        }
                    }
                    // if the value was not void, check if you need to apply an exchange rate
                    else if (doExchangeConversion && parOut.isMonetary)
                    {
                        value *= convFactor;
                    }
                    // print value
                    tuRow.Append(value.ToString(formatDecimals));
                    tuRow.Append("\t");
                }
                foreach (TUInfo tuInfoGroup in tuInfoGroups) // see PrepareUnitInfoPar for description of TUInfo.getInfos
                {
                    List <Person> altTU = hh.GetAlternativeTU(tuInfoGroup.tuName, tu, description);

                    // get the status of the DefOutput-TU's head (usually one person-TU) in the UnitInfo-TU
                    Person headInAltTU = // note: head of DefOutput-TU must be member of altTU, otherwise GetAlternativeTU is buggy
                                         (from p in altTU where p.indexInHH == tu[0].indexInHH select p).First();
                    foreach (Func <HH, List <Person>, Person, double> getInfo in tuInfoGroup.getInfos.Values)
                    {
                        tuRow.Append(getInfo(hh, altTU, headInAltTU)).Append("\t");
                    }
                }
                foreach (int indexStringVar in infoStore.operandAdmin.indexStringVars.Values)
                {
                    string value = hh.personStringVarList[tu[0].indexInHH][indexStringVar];
                    // print value
                    tuRow.Append(EncodeStringForOutput(value));
                    tuRow.Append("\t");
                }
                if (tuRow.Length > 0)
                {
                    tuRow.Length--;                       // trim trailing tab
                }
                hhResults.AppendLine(tuRow.ToString());
            }
            return(hhResults);
        }
        private static void PrintParDetails(ParBase par)
        {
            RandColor.WriteLine(par.description.Get(), GetSwapColor());
            RandColor.WriteLine($"xml-value: {par.xmlValue}", GetSwapColor());

            if (infoStore.hhAdmin == null)
            {
                return;
            }
            HH            dummyHH = infoStore.hhAdmin.GetFirstHH();
            List <Person> dummyTU = new List <Person>()
            {
                new Person(0)
            };

            if (par.GetType() == typeof(ParBool))
            {
                RandColor.WriteLine($"value: {(par as ParBool).GetBoolValue()}", GetSwapColor());
            }
            else if (par.GetType() == typeof(ParCateg))
            {
                RandColor.WriteLine($"value: {(par as ParCateg).GetCateg()}", GetSwapColor());
            }
            else if (par.GetType() == typeof(ParNumber))
            {
                RandColor.WriteLine($"value: {(par as ParNumber).GetValue()}", GetSwapColor());
            }
            else if (par.GetType() == typeof(ParTU))
            {
                string tuName = (par as ParTU).name;
                dummyHH.GetTUs(tuName); // that's to "use" the TU, i.e. to create it for the HH
                RandColor.WriteLine($"TU {tuName} has {dummyHH.hhTUs[tuName].Count} unit(s) in 1st HH", GetSwapColor());
            }
            else if (par.GetType() == typeof(ParVar))
            {
                RandColor.WriteLine($"value: {(par as ParVar).GetValue(dummyHH, dummyTU)}", GetSwapColor());
            }
            else if (par.GetType() == typeof(ParOutVar)) // there is actually nothing to check, out-vars just care for registration
            {
                RandColor.WriteLine($"index: {(par as ParOutVar).index}", GetSwapColor());
            }
            else if (par.GetType() == typeof(ParIL))
            {
                RandColor.WriteLine($"value: {(par as ParIL).GetValue(dummyHH, dummyTU)}", GetSwapColor());
            }
            else if (par.GetType() == typeof(ParVarIL))
            {
                RandColor.WriteLine($"value: {(par as ParVarIL).GetValue(dummyHH, dummyTU)}", GetSwapColor());
            }
            else if (par.GetType() == typeof(ParFormula))
            {
                RandColor.WriteLine($"value: {(par as ParFormula).GetValue(dummyHH, dummyTU)}", GetSwapColor());
            }
            else if (par.GetType() == typeof(ParCond))
            {
                RandColor.WriteLine($"ParCond not yet handled", ConsoleColor.DarkMagenta);
            }
            else
            {
                RandColor.WriteLine($"unknow type: {par.GetType()}", GetSwapColor());
            }
        }