static void GeneralAfaExamples() { // Directly specify the augmented finite automaton using arcs #region Pattern 1: A followed immediately by B: AB Afa <Payload, Empty> pat1 = new Afa <Payload, Empty>(); pat1.AddSingleElementArc(0, 1, (ts, ev, reg) => ev.Field1 == "A"); pat1.AddSingleElementArc(1, 2, (ts, ev, reg) => ev.Field1 == "B"); RunPatternQuery("Pattern 1: A followed immediately by B: AB", pat1, source1); #endregion #region Pattern 2: A followed by B (with events in between): A(.*)B Afa <Payload, Empty> pat2 = new Afa <Payload, Empty>(); pat2.AddSingleElementArc(0, 1, (ts, ev, reg) => ev.Field1 == "A"); pat2.AddSingleElementArc(1, 1, (ts, ev, reg) => true); pat2.AddSingleElementArc(1, 2, (ts, ev, reg) => ev.Field1 == "B"); RunPatternQuery("Pattern 2: A followed by B (with events in between): A(.*)B", pat2, source1); #endregion #region Pattern 3: A followed by first occurrence of B within 100 time units Afa <Payload, long> pat3 = new Afa <Payload, long>(); pat3.AddSingleElementArc(0, 1, (ts, ev, reg) => ev.Field1 == "A", (ts, ev, reg) => ts); pat3.AddSingleElementArc(1, 1, (ts, ev, reg) => ev.Field1 != "B" && ts < reg + 100); pat3.AddSingleElementArc(1, 2, (ts, ev, reg) => ev.Field1 == "B" && ts < reg + 100); RunPatternQuery("Pattern 3: A followed by first occurrence of B within 100 time units", pat3, source1); #endregion #region Pattern 4: A followed by no occurrences B within 100 time units Afa <Payload, long> pat4 = new Afa <Payload, long>(); pat4.AddSingleElementArc(0, 1, (ts, ev, reg) => ev.Field1 == "A", (ts, ev, reg) => ts); pat4.AddSingleElementArc(1, 1, (ts, ev, reg) => ev.Field1 != "B" && ts < reg + 100); pat4.AddSingleElementArc(1, 2, (ts, ev, reg) => ts >= reg + 100); RunPatternQuery("Pattern 4: A followed by no occurrences B within 100 time units", pat4, source1); #endregion #region Pattern 5: Sequence of A's followed by sequence of B's of same number Afa <Payload, int> pat5 = new Afa <Payload, int>(); pat5.AddSingleElementArc(0, 0, (ts, ev, reg) => ev.Field1 == "A", (ts, ev, reg) => reg + 1); pat5.AddSingleElementArc(0, 1, (ts, ev, reg) => ev.Field1 == "A", (ts, ev, reg) => reg + 1); pat5.AddSingleElementArc(1, 1, (ts, ev, reg) => ev.Field1 == "B" && reg > 1, (ts, ev, reg) => reg - 1); pat5.AddSingleElementArc(1, 2, (ts, ev, reg) => ev.Field1 == "B" && reg == 1, (ts, ev, reg) => reg - 1); RunPatternQuery("Pattern 5: Sequence of A's followed by sequence of B's of same number", pat5, source1); #endregion }
private static void GeneralAfaSamples() { #region Pattern 1: A followed immediately by B: AB var pat1 = new Afa <Payload, Empty, bool>(); pat1.AddSingleElementArc(0, 1, (ts, ev, reg) => ev.Field1 == "A"); pat1.AddSingleElementArc(1, 2, (ts, ev, reg) => ev.Field1 == "B"); RunPatternQuery("Pattern 1: A followed immediately by B: AB", pat1, source); #endregion #region Pattern 2: A followed by B (with events in between): A(.*)B var pat2 = new Afa <Payload, Empty, bool>(); pat2.AddSingleElementArc(0, 1, (ts, ev, reg) => ev.Field1 == "A"); pat2.AddSingleElementArc(1, 1, (ts, ev, reg) => true); pat2.AddSingleElementArc(1, 2, (ts, ev, reg) => ev.Field1 == "B"); RunPatternQuery("Pattern 2: A followed by B (with events in between): A(.*)B", pat2, source); #endregion #region Pattern 3: A followed by first occurrence of B within 100 time units var pat3 = new Afa <Payload, long, bool>(); pat3.AddSingleElementArc(0, 1, (ts, ev, reg) => ev.Field1 == "A", (ts, ev, reg) => ts); pat3.AddSingleElementArc(1, 1, (ts, ev, reg) => ev.Field1 != "B" && ts < reg + 100); pat3.AddSingleElementArc(1, 2, (ts, ev, reg) => ev.Field1 == "B" && ts < reg + 100); RunPatternQuery("Pattern 3: A followed by first occurrence of B within 100 time units", pat3, source); #endregion #region Pattern 4: A followed by no occurrences of B within 20 time units var pat4 = new Afa <Payload, long, bool>(); pat4.AddSingleElementArc(0, 1, (ts, ev, reg) => ev.Field1 == "A", (ts, ev, reg) => ts); pat4.AddSingleElementArc(1, 1, (ts, ev, reg) => ev.Field1 != "B" && ts < reg + 20); pat4.AddSingleElementArc(1, 2, (ts, ev, reg) => ts >= reg + 20); RunPatternQuery("Pattern 4: A followed by no occurrences of B within 20 time units", pat4, source); #endregion #region Pattern 5: Sequence of A's followed by sequence of B's of same number var pat5 = new Afa <Payload, int, bool>(); pat5.AddSingleElementArc(0, 0, (ts, ev, reg) => ev.Field1 == "A", (ts, ev, reg) => reg + 1); pat5.AddSingleElementArc(0, 1, (ts, ev, reg) => ev.Field1 == "A", (ts, ev, reg) => reg + 1); pat5.AddSingleElementArc(1, 1, (ts, ev, reg) => ev.Field1 == "B" && reg > 1, (ts, ev, reg) => reg - 1); pat5.AddSingleElementArc(1, 2, (ts, ev, reg) => ev.Field1 == "B" && reg == 1, (ts, ev, reg) => reg - 1); RunPatternQuery("Pattern 5: Sequence of A's followed by sequence of B's of same number", pat5, source); #endregion }