Esempio n. 1
0
        public double IterateSpanPiecewise(Hashtable hashAttributeValues, double span, out bool bOutOfRange)
        {
            double apparentAge = 0;

            bOutOfRange = false;
            double dValue  = double.Parse(hashAttributeValues[this.Attribute].ToString());
            double dAnswer = double.NaN;
            double dAge    = 0;

            if (Shift)
            {
                dAge    = double.Parse(hashAttributeValues["AGE"].ToString());
                dAnswer = this.PiecewiseEquation.GetNextValue(dValue, dAge, span, out apparentAge).Value;
            }
            else
            {
                dAnswer = this.PiecewiseEquation.GetNextValue(dValue, span).Value;
            }

            double dMinimum;
            double dMaximum;

            if (SimulationMessaging.GetAttributeMinimum(this.Attribute, out dMinimum))
            {
                if (dMinimum > dAnswer)
                {
                    dAnswer = dMinimum;
                }
            }
            if (SimulationMessaging.GetAttributeMaximum(this.Attribute, out dMaximum))
            {
                if (dMaximum < dAnswer)
                {
                    dAnswer = dMaximum;
                }
            }
            return(dAnswer);
        }
Esempio n. 2
0
        /// <summary>
        ///
        /// Calculates the next years values AND files in the Answer array for base RemainingLife and Benefit cost.
        /// </summary>
        /// <param name="hashAttributeValues">Values for other attributes</param>
        /// <returns>Value for next year</returns>
        public double IterateOneYearEquation(Hashtable hashAttributeValues, int apparentAgeHint, out double apparentAge, out bool bOutOfRange)
        {
            double increment;
            double delta;
            double ratio;
            double dAnswer;
            double dAge = 0;

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

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

            //TODO: Does this need to be solved everytime on
            if (!_isAgeOnly)
            {
                Solve(hashAttributeValues);
            }

            //Check if 99 year value is input
            if (dValue > _answer[98] && !SimulationMessaging.GetAttributeAscending(Attribute))
            {
                bOutOfRange = false;
                return(dValue);
            }
            else if (dValue < _answer[98] && SimulationMessaging.GetAttributeAscending(Attribute))
            {
                bOutOfRange = false;
                return(dValue);
            }
            double dMinimum;
            double dMaximum;

            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]))
                {
                    if (!Shift || i == 0 || dAge == 0)
                    {
                        delta     = dValue - _answer[i + 1];
                        increment = _answer[i] - _answer[i + 1];
                        if (increment == 0)
                        {
                            return(_answer[i + 1]);
                        }
                        ratio     = 1 - (delta / increment);
                        increment = _answer[i + 1] - _answer[i + 2];
                        delta     = ratio * increment;
                        dAnswer   = _answer[i + 1] - delta;
                    }
                    else // Must be SHIFT and i not 0
                    {
                        delta     = dValue - _answer[i + 1];
                        increment = _answer[i] - _answer[i + 1];
                        double dApparentAge   = (double)i + (1 - (delta / increment)); // Determine apparent age
                        double dApparentRatio = dApparentAge / dAge;                   // Determine rate that age is changing.
                        double dNextAge       = dApparentRatio + dApparentAge;
                        int    iNextAge       = (int)Math.Floor(dNextAge);
                        double dNextRatio     = dNextAge - Math.Floor(dNextAge);
                        if (iNextAge < 99)
                        {
                            increment = _answer[iNextAge] - _answer[iNextAge + 1];
                            delta     = dNextRatio * increment;
                            dAnswer   = _answer[iNextAge] - delta;
                        }
                        else
                        {
                            dAnswer = _answer[99];
                        }
                    }
                    if (SimulationMessaging.GetAttributeMinimum(this.Attribute, out dMinimum))
                    {
                        if (dMinimum > dAnswer)
                        {
                            return(dMinimum);
                        }
                    }
                    if (SimulationMessaging.GetAttributeMaximum(this.Attribute, out dMaximum))
                    {
                        if (dMaximum < dAnswer)
                        {
                            return(dMaximum);
                        }
                    }
                    bOutOfRange = false;
                    return(dAnswer);
                }
            }

            dValue = _answer[0];
            if (SimulationMessaging.GetAttributeMinimum(this.Attribute, out dMinimum))
            {
                if (dMinimum > dValue)
                {
                    return(dMinimum);
                }
            }

            if (SimulationMessaging.GetAttributeMaximum(this.Attribute, out dMaximum))
            {
                if (dMaximum < dValue)
                {
                    return(dMaximum);
                }
            }
            return(dValue);
        }
Esempio n. 3
0
        public void Solve(Hashtable hashAttributeValue)
        {
            double dValue;
            double dMinimum;
            double dMaximum;

            _answer = new double[100];
            if (IsModule)
            {
                if (IsCRS)
                {
                    String strType     = hashAttributeValue[_attributesEquation[0].ToString()].ToString();
                    double dCRS        = Convert.ToDouble(hashAttributeValue[_attributesEquation[1].ToString()]);
                    double dThick      = Convert.ToDouble(hashAttributeValue[_attributesEquation[2].ToString()]);
                    double dESAL       = Convert.ToDouble(hashAttributeValue[_attributesEquation[3].ToString()]);
                    double dESALGrowth = Convert.ToDouble(hashAttributeValue[_attributesEquation[4].ToString()]);

                    double dRSL;
                    double dBenefit;
                    _answer[0] = dCRS;
                    for (int n = 1; n < 100; n++)
                    {
                        double dAge = (double)n;
                        dValue = SimulationMessaging.crs.CalculateCRSBenefit(false, strType, dCRS, dThick, dESAL, dESALGrowth, 1, dAge, SimulationMessaging.Method.BenefitLimit, out dBenefit, out dRSL);
                        try
                        {
                            if (SimulationMessaging.GetAttributeMaximum(this.Attribute, out dMaximum))
                            {
                                if (dValue > dMaximum)
                                {
                                    dValue = dMaximum;
                                }
                            }

                            if (SimulationMessaging.GetAttributeMinimum(this.Attribute, out dMinimum))
                            {
                                if (dValue < dMinimum)
                                {
                                    dValue = dMinimum;
                                }
                            }
                        }
                        catch
                        {
                            String strValue = SimulationMessaging.GetAttributeDefault(this.Attribute);
                            dValue = double.Parse(strValue);
                        }
                        _answer[n] = dValue;
                    }
                    return;
                }
                else if (IsOCI)
                {
                }
            }

            object[] input = new object[_attributesEquation.Count];

            int i    = 0;
            int nAge = -1;

            foreach (String str in _attributesEquation)
            {
                if (str == "AGE")
                {
                    nAge = i;
                }
                input[i] = hashAttributeValue[str];;
                i++;
            }

            for (int n = 0; n < 100; n++)
            {
                double dAge = (double)n;
                if (nAge >= 0)
                {
                    input[nAge] = dAge;
                }
                try
                {
                    object result = _calculate.RunMethod(input);
                    try
                    {
                        dValue = (double)result;
                        if (SimulationMessaging.GetAttributeMaximum(this.Attribute, out dMaximum))
                        {
                            if (dValue > dMaximum)
                            {
                                dValue = dMaximum;
                            }
                        }

                        if (SimulationMessaging.GetAttributeMinimum(this.Attribute, out dMinimum))
                        {
                            if (dValue < dMinimum)
                            {
                                dValue = dMinimum;
                            }
                        }
                    }
                    catch
                    {
                        String strValue = SimulationMessaging.GetAttributeDefault(this.Attribute);
                        dValue = double.Parse(strValue);
                    }
                    _answer[n] = dValue;
                }
                catch (Exception exc)
                {
                    SimulationMessaging.AddMessage(new SimulationMessage("Error in RunMethod.   " + _calculate.OriginalInput + " " + exc.Message));
                }
            }
            return;
        }