Click or drag to resize

EvaluatorT Class

Inheritance Hierarchy
SystemObject
  AGI.FoundationEvaluatorT
    More...

Namespace:  AGI.Foundation
Assembly:  AGI.Foundation.Core (in AGI.Foundation.Core.dll) Version: 24.1.418.0 (24.1.418.0)
Syntax
public abstract class Evaluator<T> : IEvaluator<T>, 
	IEvaluator, IAvailability, IThreadAware, ICloneWithContext, IDisposable, 
	IIsTimeVarying

Type Parameters

T
The type returned by the evaluator.

The EvaluatorT type exposes the following members.

Constructors
Properties
  NameDescription
Public propertyAvailabilityIntervals
Gets a TimeIntervalCollection over which data is available. If the availability interval is infinite, this returns Infinite.
Public propertyGroup
Gets the group that contains this evaluator.
Public propertyIsThreadSafe
Gets a value indicating whether the methods on this instance are safe to call from multiple threads simultaneously.
Public propertyIsTimeVarying
Gets a value indicating whether or not the value of this evaluator changes with time. If , the evaluator is assumed to return the same value for any input JulianDate.
Top
Methods
  NameDescription
Public methodClone
Clones this object using the specified context.
Public methodDispose
Releases any resources associated with this instance.
Protected methodDispose(Boolean)
Releases any resources associated with this instance.
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Public methodEvaluate(JulianDate)
Evaluates the function.
Public methodEvaluate(TimeInterval, Duration)
Evaluates this evaluator at a specified fixed step over the specified interval.
Public methodEvaluate(JulianDate, JulianDate, Duration)
Evaluates this evaluator at a specified fixed step over the specified interval.
Public methodEvaluate(TimeInterval, Duration, ITrackCalculationProgress)
Evaluates this evaluator at a specified fixed step over the specified interval.
Public methodEvaluate(JulianDate, JulianDate, Duration, ITrackCalculationProgress)
Evaluates this evaluator at a specified fixed step over the specified interval.
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetAvailabilityIntervals
Gets the intervals over which data is available.
Public methodGetCachingWrapper
Gets a version of this evaluator that caches the previously computed value so that if it is evaluated twice at the same date the computation is done only once.
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodIsAvailable
Determines if valid data is available for the given JulianDate.
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Public methodCode exampleUpdateEvaluatorReferences
Updates the evaluator references held by this object using the reference-to-reference mapping in the specified CopyContext.
Top
Examples

This is an example class which organizes user input to create an evaluator to perform a simple vector computation. The user provides a coefficient and a vector, and the evaluator multiplies the vector's magnitude by the coefficient.

C#
public class ExampleComputation
{
    /// <summary>
    /// Here is a coefficient which the user specifies for the computation.
    /// </summary>
    public double UserCoefficient = 1.0;

    /// <summary>
    /// Here is a vector which the user can modify to analyze different vectors which may vary with time.
    /// </summary>
    public Vector UserVector = new VectorFixed(Axes.Root, new Cartesian(4.2, 0.0, -1.3));

    /// <summary>
    /// This method takes the user's data above and creates an IEvaluator to perform the calculation.
    /// Notice that a <see cref="VectorEvaluator"/> is required for the calculation.  The <see cref="EvaluatorGroup"/>
    /// provides a way to reuse an identical <see cref="VectorEvaluator"/> if it already exists or creates a new
    /// instance if it does not.
    /// </summary>
    /// <param name="group">The repository of existing evaluators.</param>
    /// <returns>A generic evaluator which can be used to compute the desired vector operation.</returns>
    public IEvaluator<double> GetEvaluator(EvaluatorGroup group)
    {
        if (group == null)
            throw new ArgumentNullException("group");

        // Use the Evaluator group to optimize the behavior of the Evaluators used in this one.
        return group.CreateEvaluator<IEvaluator<double>>(CreateEvaluator);
    }

    private IEvaluator<double> CreateEvaluator(EvaluatorGroup group)
    {
        // By using the GetEvaluator methods on other components, its easy to make
        // new Evaluators based on existing Evaluators.
        VectorEvaluator componentEvaluator = UserVector.GetEvaluator(group);

        return new MyEvaluator(group, UserCoefficient, componentEvaluator);
    }

    /// <summary>
    /// Here the implementation of the evaluator is defined and encapsulated.
    /// </summary>
    private sealed class MyEvaluator : Evaluator<double>
    {
        /// <summary>
        /// A constructor takes parameters from the GetEvaluator method, ensuring that it only uses
        /// objects which cannot be changed from outside the evaluator.  If such an object is needed
        /// as a parameter, it should be copied to a new instance.
        /// </summary>
        /// <param name="group">The group that contains this evaluator.</param>
        /// <param name="coefficient">A scalar coefficient.</param>
        /// <param name="vectorEvaluator">A vector evaluator to include in a simple computation.</param>
        public MyEvaluator(EvaluatorGroup group, double coefficient, VectorEvaluator vectorEvaluator)
            : base(group)
        {
            m_coefficient = coefficient;
            m_vectorEvaluator = vectorEvaluator;
        }

        /// <summary>
        /// This constructor provides a way to copy this instance of the evaluator to other threads.  
        /// This is called by the Clone method.
        /// </summary>
        /// <param name="existingInstance">An existing instance.</param>
        /// <param name="context">The context in which to make a copy.</param>
        private MyEvaluator(MyEvaluator existingInstance, CopyContext context)
            : base(existingInstance, context)
        {
            m_coefficient = existingInstance.m_coefficient;
            m_vectorEvaluator = existingInstance.m_vectorEvaluator;
            UpdateEvaluatorReferences(context);
        }

        /// <summary>
        /// This method is used by <see cref="EvaluatorGroup"/> to update the evaluator references held
        /// by this evaluator.  If two evaluators share a third, the two evaluators will be updated to
        /// refer to a caching wrapper for that third evaluator.  
        /// </summary>
        /// <param name="context">The context that specifies the reference mapping.</param>
        public override void UpdateEvaluatorReferences(CopyContext context)
        {
            // Call UpdateReference on any Evaluators used in this one
            m_vectorEvaluator = context.UpdateReference(m_vectorEvaluator);
        }

        /// <summary>
        /// Copy this evaluator.
        /// </summary>
        /// <param name="context">The context in which to make a copy.</param>
        /// <returns>A copy of this instance.</returns>
        public override object Clone(CopyContext context)
        {
            return new MyEvaluator(this, context);
        }

        /// <summary>
        /// This property provides a way of determining if multiple threads can call this instance
        /// simultaneously or whether it needs to be copied.
        /// </summary>
        public override bool IsThreadSafe
        {
            // Check whether the vector evaluator used in the calculation is threadsafe.
            // If any Evaluators used in this one are not threadsafe, this one is not threadsafe.
            get { return m_vectorEvaluator.IsThreadSafe; }
        }

        /// <summary>
        /// This property determines if this Evaluator result
        /// changes depending on the time at which it is evaluated.
        /// </summary>
        public override bool IsTimeVarying
        {
            get { return m_vectorEvaluator.IsTimeVarying; }
        }

        /// <summary>
        /// This method provides a way to check whether there are any times where the evaluator cannot
        /// provide a value.
        /// </summary>
        /// <param name="date">A date to check.</param>
        /// <returns>True if a value can be computed for the given date.</returns>
        public override bool IsAvailable(JulianDate date)
        {
            return m_vectorEvaluator.IsAvailable(date);
        }

        /// <summary>
        /// This provides a collection of time intervals when this evaluator can produce a value.
        /// This should consist of an intersection of the AvailabilityIntervals of any Evaluators used
        /// in this one.  In general, this will be an infinite span of time unless there is only a 
        /// limited set of data.  For instance, if the ephemeris source used in an Evaluator is only
        /// available for a range of dates, the valid timespan will be represented by the 
        /// AvailabilityIntervals.
        /// </summary>
        /// <param name="consideredIntervals">The intervals for which to consider availability.</param>
        public override TimeIntervalCollection GetAvailabilityIntervals(TimeIntervalCollection consideredIntervals)
        {
            return m_vectorEvaluator.GetAvailabilityIntervals(consideredIntervals);
        }

        /// <summary>
        /// This is the actual calculation which we want to produce.  Given a particular date, calculate
        /// the value of the result.  After this evaluator is created, the result produced by
        /// the evaluator should not change even if the user changes <see cref="UserCoefficient"/> 
        /// or <see cref="UserVector"/>.
        /// </summary>
        /// <param name="date">The time at which to calculate the desired value.</param>
        /// <returns>The resulting value.</returns>
        public override double Evaluate(JulianDate date)
        {
            // Evaluate the vector's magnitude
            double vectorMagnitude = m_vectorEvaluator.Evaluate(date).Magnitude;
            // Multiply that magnitude by the user specified coefficient
            return m_coefficient * vectorMagnitude;
        }

        /// <summary>
        /// Return a <see cref="CachingEvaluator{T}"/> which caches the value produced by this one.  
        /// This allows the <see cref="EvaluatorGroup"/> to optimize performance when one evaluator 
        /// is called multiple times at a particular <see cref="JulianDate"/>.
        /// </summary>
        /// <returns>An evaluator which caches the value of this one.</returns>
        public override IEvaluator GetCachingWrapper()
        {
            return new CachingEvaluator<double>(this);
        }

        /// <summary>
        /// Releases any resources associated with this instance.
        /// </summary>
        /// <param name="disposing">
        /// <see langword="true"/> to release both managed and unmanaged resources;
        /// <see langword="false"/> to release only unmanaged resources.
        /// </param>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                m_vectorEvaluator.Dispose();
            }
        }

        private readonly double m_coefficient;
        private VectorEvaluator m_vectorEvaluator;
    }

    /// <summary>
    /// Here is an example of how to perform the computation.
    /// </summary>
    public static void Example()
    {
        // Create the computation
        ExampleComputation computation = new ExampleComputation();
        // Provide user data to the computation
        computation.UserCoefficient = 42.0;
        computation.UserVector = new VectorFixed(Axes.Root, new Cartesian(3.14, 15, -9.2));
        // Since this is a very simple computation, a group does not already exist.  
        // So, create a new one.
        EvaluatorGroup newGroup = new EvaluatorGroup();
        // Get the evaluator for the computation using the group.
        IEvaluator<double> evaluator = computation.GetEvaluator(newGroup);
        // Then call the Evaluate method to calculate the value at the specified time.
        double valueOne = evaluator.Evaluate(TimeConstants.J2000);
        // What happens if we change the value of the coefficient?
        computation.UserCoefficient = -2.1;
        // Evaluating the same evaluator will produce the same value even though the coefficient has changed!
        double valueTwo = evaluator.Evaluate(TimeConstants.J2000);
        // To perform the computation with the current user values, get a new evaluator from the GetEvaluator method.
        // Note that, since we have not changed the vector parameter, the use of the same EvaluatorGroup will
        // ensure that the same VectorEvaluator is reused in the computation rather than creating a new one.
        IEvaluator<double> newEvaluator = computation.GetEvaluator(newGroup);
        double newValue = newEvaluator.Evaluate(TimeConstants.J2000);
        Console.WriteLine("The first calculation is:  " + valueOne);
        Console.WriteLine("The second calculation is: " + valueTwo);
        Console.WriteLine("The new value is:          " + newValue);
    }
}
See Also
Inheritance Hierarchy
SystemObject
  AGI.FoundationEvaluatorT
    AGI.Foundation.AccessAccessEvaluator
    AGI.Foundation.AccessEvaluatorDelayedByLinkT
    AGI.Foundation.CelestialForceEvaluator
    AGI.Foundation.CelestialTorqueEvaluator
    AGI.Foundation.Communications.AntennasBeamformerWeightsEvaluator
    AGI.Foundation.Communications.AntennasDirectionsEvaluator
    AGI.Foundation.CommunicationsSignalEvaluator
    AGI.FoundationConstantEvaluatorT
    AGI.Foundation.GeometryInternationalTerrestrialReferenceFrameEvaluator
    AGI.Foundation.GeometryLinkDelayEvaluator
    AGI.Foundation.GeometryReferenceFrameEvaluator
    AGI.Foundation.Geometry.ShapesDynamicSensorFieldOfViewEvaluator
    AGI.Foundation.InfrastructureCachingEvaluatorT
    AGI.Foundation.PlatformsSensorProjectionEvaluator