Exemplo n.º 1
0
 // Does this get used?
 // If not, don't include it.  Passing a reference causes otherProfile to change when Profile changes
 /// <summary>
 /// Create a new Profile from a copy of an existing profile
 /// This constructor create a deep copy of the Profile passed in as a reference
 /// </summary>
 /// <param name="otherProfile"></param>
 public HSFProfile(HSFProfile <T> otherProfile)
 {
     foreach (var item in otherProfile.data)
     {
         data[item.Key] = item.Value;
     }
 }
Exemplo n.º 2
0
        public static HSFProfile <T> operator +(HSFProfile <T> p1, HSFProfile <T> p2)
        {
            if (p1.Empty())
            {
                return(p2);
            }

            if (p2.Empty())
            {
                return(p1);
            }

            HSFProfile <T> p3 = new HSFProfile <T>();

            IEnumerable <double> p1Keys      = p1.data.Keys;
            IEnumerable <double> p2Keys      = p2.data.Keys;
            IEnumerable <double> uniqueTimes = p1Keys.Union(p2Keys).Distinct();

            foreach (double time in uniqueTimes)
            {
                p3[time] = (dynamic)p1[time] + (dynamic)p2[time];
            }

            return(p3);
        }
Exemplo n.º 3
0
        // Operators

        public static HSFProfile <T> MergeProfiles(HSFProfile <T> p1, HSFProfile <T> p2) //Morgan made this static
        {
            HSFProfile <T> p3 = new HSFProfile <T>();

            p3.data = (SortedDictionary <double, T>)(p1.data.Union(p2.data));
            p3.RemoveDuplicates();

            return(p3);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Adds a new data points to an existing profile from some other existing profile
 /// </summary>
 /// <param name="otherProfile">The existing profile which is merged with this profile</param>
 public void Add(HSFProfile <T> otherProfile)
 {
     if (!otherProfile.Empty())
     {
         foreach (var item in otherProfile.data)
         {
             Add(item);
         }
     }
 }
Exemplo n.º 5
0
        public static HSFProfile <T> operator *(HSFProfile <T> p1, dynamic someNumber)
        {
            HSFProfile <T> pOut = new HSFProfile <T>();

            foreach (KeyValuePair <double, T> item in p1.data)
            {
                pOut[item.Key] *= someNumber;
            }

            return(pOut);
        }
Exemplo n.º 6
0
        public static HSFProfile <T> operator -(HSFProfile <T> p1)
        {
            HSFProfile <T> pOut = new HSFProfile <T>();

            foreach (KeyValuePair <double, T> item in p1.data)
            {
                pOut[item.Key] = -(dynamic)p1[item.Key];
            }

            return(pOut);
        }
Exemplo n.º 7
0
        public static HSFProfile <T> operator /(dynamic someNumber, HSFProfile <T> p1)
        {
            HSFProfile <T> pOut = new HSFProfile <T>();

            foreach (KeyValuePair <double, T> item in p1.data)
            {
                pOut.Add(item.Key, someNumber / item.Value);
            }

            return(pOut);
        }
Exemplo n.º 8
0
        // override object.Equals
        public override bool Equals(object obj)
        {
            if (obj == null || GetType() != obj.GetType())
            {
                return(false);
            }

            // TODO: write your implementation of Equals() here
            HSFProfile <T> p = obj as HSFProfile <T>;

            return(data == p.data);
        }
Exemplo n.º 9
0
        //TODO: (morgan ask mehiel) THis should be templated
        public HSFProfile <double> limitIntegrateToProf(double start, double end, double saveFreq, double lowerBound, double upperBound, ref bool exceeded_lower, ref bool exceeded_upper, double iv, double ic)
        {
            HSFProfile <double> prof = new HSFProfile <double>();
            double last = ic;
            double result;
            double time;

            for (time = start + saveFreq; time < end; time += saveFreq)
            {
                Double.TryParse(Integrate(time - saveFreq, time, iv).ToString(), out result); //Morgan isn't sure about this
                result += last;
                if (result.CompareTo(upperBound) >= 0)
                {
                    result         = upperBound;
                    exceeded_upper = true;
                }
                if (result < lowerBound)
                {
                    result         = lowerBound;
                    exceeded_lower = true;
                }
                if (result != last)
                {
                    prof[time] = result;
                }
                last = result;
            }
            Double.TryParse(Integrate(time -= saveFreq, end, iv).ToString(), out result); //Morgan isn't sure about this
            result += last;
            if (result > upperBound)
            {
                result         = upperBound;
                exceeded_upper = true;
            }
            if (result < lowerBound)
            {
                result         = lowerBound;
                exceeded_lower = true;
            }
            if (result != last)
            {
                prof[end] = result;
            }

            if (prof.Empty())
            {
                prof[start] = ic;
            }
            return(prof);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Override the object equals method
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            if (obj == null || GetType() != obj.GetType())
            {
                return(false);
            }

            // TODO: write your implementation of Equals() here
            HSFProfile <T> p        = obj as HSFProfile <T>;
            bool           areEqual = true;

            foreach (var item in data.Zip(p.data, Tuple.Create))
            {
                areEqual &= item.Item1.Key == item.Item2.Key;
                areEqual &= (dynamic)item.Item1.Value == item.Item2.Value;
            }
            return(areEqual);
        }
Exemplo n.º 11
0
        public static HSFProfile <T> operator /(HSFProfile <T> p1, dynamic someNumber)
        {
            HSFProfile <T> pOut = new HSFProfile <T>();

            return(pOut = p1 * (1.0 / someNumber));
        }
Exemplo n.º 12
0
        public static HSFProfile <T> operator *(dynamic someNumber, HSFProfile <T> p1)
        {
            HSFProfile <T> pOut = new HSFProfile <T>();

            return(pOut = p1 * someNumber);
        }
Exemplo n.º 13
0
        public static HSFProfile <T> operator -(HSFProfile <T> p1, HSFProfile <T> p2)
        {
            HSFProfile <T> pOut = new HSFProfile <T>();

            return(pOut = p1 + (-p2));
        }