Example #1
0
        public bool CalculateRemainingLifePiecewise(Hashtable hashAttributeValues, Hashtable hashPrevious, out double dRL)
        {
            double dLimit;
            double dRemainingLife = 0;

            dRL = dRemainingLife;

            if (!SimulationMessaging.GetDeficientLevel(this.Attribute, hashPrevious, out dLimit))
            {
                return(false);
            }
            this.RemainingLifeLimit = dLimit;

            double dValue = double.Parse(hashAttributeValues[this.Attribute].ToString());

            if (Shift)
            {
                double dAge = double.Parse(hashAttributeValues["AGE"].ToString());
                dRL = this.PiecewiseEquation.GetRemainingLife(dValue, dLimit, dAge);
            }
            else
            {
                dRL = this.PiecewiseEquation.GetRemainingLife(dValue, dLimit);
            }
            return(true);
        }
Example #2
0
        public bool CalculateRemainingLifeEquation(Hashtable hashAttributeValues, Hashtable hashPrevious, out double dRL)
        {
            double increment;
            double delta;
            double ratioAnswer    = 0;
            int    iAnswer        = -1;
            double ratioDeficient = 0;
            int    iDeficient     = -1;
            double dRemainingLife = 0;

            dRL = dRemainingLife;

            double dValue = double.Parse(hashAttributeValues[this.Attribute].ToString());

            if (!_isAgeOnly)
            {
                Solve(hashPrevious);
            }
            double dAge = 0;

            if (Shift)
            {
                dAge = double.Parse(hashAttributeValues["AGE"].ToString());
            }

            double dLimit;

            if (!SimulationMessaging.GetDeficientLevel(this.Attribute, hashPrevious, out dLimit))
            {
                return(false);
            }
            this.RemainingLifeLimit = dLimit;
            for (int i = 0; i < 98; i++)
            {
                //This eliminates ascending / descending problem.  Just looking for a number in between.
                if ((_answer[i] >= dValue && dValue > _answer[i + 1]) || (_answer[i] <= dValue && dValue < _answer[i + 1]))
                {
                    delta     = dValue - _answer[i + 1];
                    increment = _answer[i] - _answer[i + 1];
                    if (increment == 0)
                    {
                        ratioAnswer = 0;
                    }
                    else
                    {
                        ratioAnswer = 1 - (delta / increment);
                    }
                    iAnswer = i;
                }


                if ((_answer[i] >= this.RemainingLifeLimit && this.RemainingLifeLimit > _answer[i + 1]) || (_answer[i] <= this.RemainingLifeLimit && this.RemainingLifeLimit < _answer[i + 1]))
                {
                    delta     = this.RemainingLifeLimit - _answer[i + 1];
                    increment = _answer[i] - _answer[i + 1];
                    if (increment == 0)
                    {
                        ratioDeficient = 0;
                    }
                    else
                    {
                        ratioDeficient = 1 - (delta / increment);
                    }
                    iDeficient = i;
                }

                if (iAnswer >= 0 && iDeficient >= 0)
                {
                    //Then we have solve remaining life
                    dRemainingLife = ((double)iDeficient + ratioDeficient) - ((double)iAnswer + ratioAnswer);
                    dRL            = dRemainingLife;

                    if (Shift && i > 0 && dAge > 0)
                    {
                        double dApparentAge = (double)iAnswer + ratioAnswer;
                        double dAgeRatio    = dApparentAge / (dAge);
                        dRL = dRL / dAgeRatio;
                    }

                    if (dRL < 0)
                    {
                        dRL = 0;
                    }
                    return(true);
                }
            }

            if (iAnswer >= 0 && iDeficient == -1)
            {
                dRemainingLife = 99;
                dRL            = dRemainingLife;
                return(true);
            }

            if (iDeficient >= 0 && iAnswer == -1)
            {
                dRemainingLife = 0;
                dRL            = dRemainingLife;
                return(true);
            }
            dRL = 0;
            return(false);
        }