/// <summary> /// Constraint that defines whether a sequence of events is valid. /// </summary> /// <param name="es">The events.</param> /// <returns>A Zen value for if the sequence is valid.</returns> private static Zen <bool> IsValidSequence(Zen <IList <Event> > es) { var areTimesAscending = Utilities.PairwiseInvariant(es, (x, y) => x.GetTimeStamp() < y.GetTimeStamp()); var validPriorities = es.All(e => e.GetPriorityClass() <= 1); var validTypes = es.All(e => e.GetEventType() <= 2); var validStorms0 = AreStartEndStormsValid(es, false, 0); var validStorms1 = AreStartEndStormsValid(es, false, 1); var validGaps = Utilities.PairwiseInvariant(es, (x, y) => Or(y.GetTimeStamp() - x.GetTimeStamp() < 200, y.GetTimeStamp() - x.GetTimeStamp() > 400)); var timesBounded = es.All(e => e.GetTimeStamp() <= 2000); return(And(areTimesAscending, timesBounded, validGaps, validPriorities, validTypes, validStorms0, validStorms1)); }
/// <summary> /// Constraint that defines whether a sequence of events is valid. /// </summary> /// <param name="es">The events.</param> /// <returns>A Zen value for if the sequence is valid.</returns> internal static Zen <bool> IsValidSequence(Zen <IList <Event> > es) { var areTimesAscending = PairwiseInvariant(es, (x, y) => x.GetTimeStamp() < y.GetTimeStamp()); var areTimeGapsValid = PairwiseInvariant(es, (x, y) => y.GetTimeStamp() - x.GetTimeStamp() <= maxEventTimeGap); var arePrioritiesValid = es.All(e => e.GetPriorityClass() <= 1); var hasPollingEvents = True(); for (int i = 0; i < numPollingIntervals; i++) { var et = Event.EventTypeAsInt(EventType.PollingIntervalEvent); var value = (ushort)(pollingInterval * i); var hasPollingEvent = es.Any(e => And(e.GetTimeStamp() == value, e.GetEventType() == et)); hasPollingEvents = And(hasPollingEvent, hasPollingEvents); } return(And(areTimesAscending, areTimeGapsValid, arePrioritiesValid, hasPollingEvents)); }