/// <summary>
        /// Gets Besselian elements values for specified Juluan Day.
        /// </summary>
        /// <param name="jd">Julian Day of interest.</param>
        /// <returns>Besselian elements for the given instant.</returns>
        public InstantLunarEclipseElements GetInstantBesselianElements(double jd)
        {
            //if (jd < From || jd > To)
            //    throw new ArgumentException($"Polynomial Besselian elements valid only for Julian Day in range [{From} ... {To}].", nameof(jd));

            // difference, with t0, in step units
            double t = (jd - JulianDay0) / Step;

            return(new InstantLunarEclipseElements()
            {
                JulianDay = jd,
                DeltaT = DeltaT,
                X = X.Select((x, n) => x * Pow(t, n)).Sum(),
                Y = Y.Select((y, n) => y * Pow(t, n)).Sum(),
                F1 = F1.Select((y, n) => y * Pow(t, n)).Sum(),
                F2 = F2.Select((y, n) => y * Pow(t, n)).Sum(),
                F3 = F3.Select((y, n) => y * Pow(t, n)).Sum(),
                Alpha = To360(Alpha.Select((y, n) => y * Pow(t, n)).Sum()),
                Delta = Delta.Select((y, n) => y * Pow(t, n)).Sum(),
            });
        }
Пример #2
0
        public void runBackward()
        {
            bool   birthDecision = false;
            bool   converged     = false;
            double normaliser    = 1.0;

            // variables for capturing rate of increase in fitness
            double r     = 0.0;
            double rPrev = 0.0;

            int i         = 0;
            int motherAge = ageAtMaturity;

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            // main loop
            do
            {
                motherAge = ageAtMaturity;

                // loop over each permutation of mother's age and family index to find max. fitness
                for (int arrayIndex = 0; arrayIndex < F1.Length; arrayIndex++)
                {
                    for (int familyIndex = 0; familyIndex < numFamilies; familyIndex++)
                    {
                        if (StateSpace[arrayIndex, familyIndex])
                        {
                            F2[arrayIndex][familyIndex]     = findFMax(motherAge, familyIndex, arrayIndex, ref birthDecision);
                            births[arrayIndex][familyIndex] = birthDecision;

                            // normalise the array
                            if (arrayIndex == 0 && familyIndex == 0) // only set normaliser (denominator) in first iteration
                            {
                                normaliser = F2[0][0];               // F2[0][0] is fitness when mother's age is 15 for first family structure
                            }
                            F2[arrayIndex][familyIndex] = F2[arrayIndex][familyIndex] / normaliser;
                        }
                    } // end of family index loop

                    motherAge += 1;
                } // end of mother's age loop

                // what is the population rate of increase?
                r = normaliser / F1[0][0];  // use 'normaliser' because F2[0][0] gets 'normalised' above so result == 1 always

                try
                {
                    if (i >= 75)
                    {
                        if (rPrev.ToString().Substring(0, 7) == r.ToString().Substring(0, 7))  // match current and previous pop growth rates to 4th decimal place
                        {
                            Console.WriteLine("CONVERGED");
                            converged = true;
                        }
                    }
                }
                catch (Exception e) { }

                rPrev = r;

                // write to F1 for next time step
                F1 = F2.Select(s => s.ToArray()).ToArray();

                if (logger != null)
                {
                    logger.WriteLine("Finished loop {0} in {1}; r={2}", i, stopwatch.Elapsed, r);
                }
                else
                {
                    Console.WriteLine("Finished loop {0} in {1}; r={2}", i, stopwatch.Elapsed, r);
                }

                i++;
            } while (!converged);
            // end of main loop

            stopwatch.Stop();

            finishedBackward = true;
        }