Example #1
0
        /// <summary>
        /// Indicates, for each time interval in a given Tnum, whether the Tbool
        /// is ever true during that interval.
        /// </summary>
        public Tbool EverPer(Tnum intervals)
        {
            // If the interval Tnum is eternally unknown, return unknown
            if (intervals.IntervalValues.Count == 1 &&
                !intervals.FirstValue.IsKnown)
            {
                return(new Tbool(intervals.FirstValue));
            }

            Tbool result = new Tbool();

            IList <DateTime> tPoints = intervals.TimePoints();

            // Check each time interval to see if condition is true
            for (int i = 0; i < tPoints.Count - 1; i++)
            {
                Hval isEverTrue = this.IsEverTrue(tPoints[i], tPoints[i + 1]).FirstValue;
                result.AddState(tPoints[i], isEverTrue);
            }

            // This doesn't use .Lean because the output of EverPer() is often
            // the input to a function that counts the number of discrete
            // intervals.  If you want a "lean" result, append .Lean when using
            // this function.
            return(result);
        }
Example #2
0
        /// <summary>
        /// Identifies intervals where a Tvar is Hstate.Null.
        /// </summary>
        public static Tbool IsNull(Tvar tvar)
        {
            Tbool result = new Tbool();

            foreach (KeyValuePair <DateTime, Hval> slice in tvar.IntervalValues)
            {
                result.AddState(slice.Key, slice.Value.State == Hstate.Null);
            }

            return(result.Lean);
        }
Example #3
0
        /// <summary>
        /// Identifies intervals where a Tvar is Stub, Uncertain, or Unstated.
        /// </summary>
        public static Tbool HasUnknownState(Tvar tvar)
        {
            Tbool result = new Tbool();

            foreach (KeyValuePair <DateTime, Hval> slice in tvar.IntervalValues)
            {
                result.AddState(slice.Key, slice.Value.IsStub || slice.Value.IsUncertain || slice.Value.IsUnstated);
            }

            return(result.Lean);
        }
Example #4
0
        /// <summary>
        /// Private temporal AND function
        /// </summary>
        private static Tbool And(Tbool t1, Tbool t2)
        {
            // Short circuit: If any input is eternally false, return false
            if (t1.IsFalse || t2.IsFalse) return new Tbool(false);

            // Else, apply the AND function to the inputs
            Tbool result = new Tbool();
            foreach(KeyValuePair<DateTime,List<Hval>> slice in TimePointValues(t1,t2))
            {    
                result.AddState(slice.Key, CoreAnd(slice.Value));
            }
            return result.Lean;
        }
Example #5
0
        /// <summary>
        /// Returns a Tbool that's true up to a specified DateTime, and false
        /// at and after it.
        /// </summary>
        public static Tbool IsBefore(Tdate dt)
        {
            // Handle unknowns
            if (!dt.FirstValue.IsKnown)
            {
                return(new Tbool(dt.FirstValue));
            }

            // Create boolean
            Tbool result = new Tbool();

            if (dt == DawnOf)
            {
                result.AddState(DawnOf, false);
            }
            else
            {
                result.AddState(DawnOf, true);
                result.AddState(dt.ToDateTime, false);
            }
            return(result);
        }
Example #6
0
        /// <summary>
        /// Private temporal AND function
        /// </summary>
        private static Tbool And(Tbool t1, Tbool t2)
        {
            // Short circuit: If any input is eternally false, return false
            if (t1.IsFalse || t2.IsFalse)
            {
                return(new Tbool(false));
            }

            // Else, apply the AND function to the inputs
            Tbool result = new Tbool();

            foreach (KeyValuePair <DateTime, List <Hval> > slice in TimePointValues(t1, t2))
            {
                result.AddState(slice.Key, CoreAnd(slice.Value));
            }
            return(result.Lean);
        }
Example #7
0
        /// <summary>
        /// Indicates, for each time interval in a given Tnum, whether the Tbool
        /// is always true during that interval.
        /// </summary>
        public Tbool AlwaysPer(Tnum intervals)
        {
            // If the interval Tnum is eternally unknown, return unknown
            if (intervals.IntervalValues.Count == 1 &&
                !intervals.FirstValue.IsKnown)
            {
                return(new Tbool(intervals.FirstValue));
            }

            Tbool result = new Tbool();

            IList <DateTime> tPoints = intervals.TimePoints();

            // Foreach interval in intervals
            for (int i = 0; i < tPoints.Count - 1; i++)
            {
                Hval isAlwaysTrue = this.IsAlwaysTrue(tPoints[i], tPoints[i + 1]).FirstValue;
                result.AddState(tPoints[i], isAlwaysTrue);
            }

            // Doesn't use .Lean.  See explanation in EverPer() above.
            return(result);
        }
Example #8
0
        /// <summary>
        /// Asserts a given fact (of the proper Tvar type)
        /// </summary>
        private static void AssertFact(Factoid f)
        {
            // Instantiate relevant Things
            Thing t1 = f.Arg1.ToString() != "" ? Facts.AddThing(f.Arg1.ToString()) : null;
            Thing t2 = f.Arg2.ToString() != "" ? Facts.AddThing(f.Arg2.ToString()) : null;
            Thing t3 = f.Arg3.ToString() != "" ? Facts.AddThing(f.Arg3.ToString()) : null;

            // Sometimes I have my doubts about static typing...
            if (f.FactType == "Tbool")
            {
                Tbool val = new Tbool();
                foreach (TemporalValue v in f.Timeline)
                {
                    val.AddState(v.Date, new Hval(v.Value));
                }
                Facts.Assert(t1, f.Relationship, t2, t3, val);
            }
            else if (f.FactType == "Tnum")
            {
                Tnum val = new Tnum();
                foreach (TemporalValue v in f.Timeline)
                {
                    val.AddState(v.Date, new Hval(v.Value));
                }
                Facts.Assert(t1, f.Relationship, t2, t3, val);
            }
            else if (f.FactType == "Tstr")
            {
                Tstr val = new Tstr();
                foreach (TemporalValue v in f.Timeline)
                {
                    val.AddState(v.Date, new Hval(v.Value));
                }
                Facts.Assert(t1, f.Relationship, t2, t3, val);
            }
            else if (f.FactType == "Tdate")
            {
                Tdate val = new Tdate();
                foreach (TemporalValue v in f.Timeline)
                {
                    val.AddState(v.Date, new Hval(v.Value));
                }
                Facts.Assert(t1, f.Relationship, t2, t3, val);
            }
            else if (f.FactType == "Tset")
            {
                Tset val = new Tset();
                foreach (TemporalValue v in f.Timeline)
                {
                    val.AddState(v.Date, new Hval(v.Value));
                }
                Facts.Assert(t1, f.Relationship, t2, t3, val);
            }
        }
Example #9
0
        /// <summary>
        /// Returns a Tbool that's true up to a specified DateTime, and false
        /// at and after it.
        /// </summary>
        public static Tbool IsBefore(Tdate dt)
        {
            // Handle unknowns
            if (!dt.FirstValue.IsKnown)
            {
                return new Tbool(dt.FirstValue);
            }

            // Create boolean
            Tbool result = new Tbool();

            if (dt == DawnOf)
            {
                result.AddState(DawnOf, false);
            }
            else
            {
                result.AddState(DawnOf, true);
                result.AddState(dt.ToDateTime, false);
            }
            return result;
        }