Example #1
0
        public override IGate Invert()
        {
            var sc = new StateCondition(Variable);
            sc.SetPreStates(Variable.Type.GetExcluding(new int[] { StateIndex }));
            var r = sc.Decompose(ConditionMode.Pre);

            //Gate.TraceLabel(this, r, "invert");

            return r;
        }
Example #2
0
        public override ICondition Clone()
        {
            var c = new StateCondition(Variable);

            c.StateIndexes.AddRange(StateIndexes);
            c.PreWildcard = PreWildcard;
            c.PostStateIndexes.AddRange(PostStateIndexes);
            c.PostWildcard = PostWildcard;
            c.Freeze();
            return(c);
        }
Example #3
0
        public override IGate Invert()
        {
            var sc = new StateCondition(Variable);

            sc.SetPreStates(Variable.Type.GetExcluding(new int[] { StateIndex }));
            var r = sc.Decompose(ConditionMode.Pre);

            //Gate.TraceLabel(this, r, "invert");

            return(r);
        }
Example #4
0
        private ICondition ReplaceCondition(ICondition c, bool post)
        {
            if (c is StateCondition)
            {
                var sc = (StateCondition)c;

                if (_transitions.Contains(sc.Variable))
                {
                    // replace the transition condition with either its pre or post states
                    if(sc.IsTransition)
                    {
                        // transition condition
                        if (!post)
                        {
                            // replace with precondition
                            var rc = new StateCondition(sc);
                            rc.SetPreStates(sc.StateIndexes);
                            c = rc;
                        }
                        else
                        {
                            // replace with postcondition
                            var rc = new StateCondition(sc);
                            rc.SetPreStates(sc.PostStateIndexes);
                            c = rc;
                        }
                    }
                }
            }

            return c;
        }
Example #5
0
 public override ICondition Clone()
 {
     var c = new StateCondition(Variable);
     c.StateIndexes.AddRange(StateIndexes);
     c.PreWildcard = PreWildcard;
     c.PostStateIndexes.AddRange(PostStateIndexes);
     c.PostWildcard = PostWildcard;
     c.Freeze();
     return c;
 }
Example #6
0
 public StateCondition(StateCondition parent)
     : this(parent.Variable)
 {
     Parent = parent;
 }
Example #7
0
        void StateCondition(out ICondition cond)
        {
            string varname; Variable v; StateCondition scond = null; IdList pre, post;
            cond = null;

            Identifier(out varname);
            v = SM.GetVariable(varname);
            if (la.kind == 29) {
            Get();
            scond = new StateCondition(v);
            StateIdentifierList(out pre);
            scond.SetPreStates(pre);
            if (la.kind == 27) {
                Get();
                StateIdentifierList(out post);
                scond.SetPostStates(post);
            }
            Expect(30);
            }
            cond = (ICondition)scond ?? new BooleanCondition(v);
        }
Example #8
0
 public StateCondition(StateCondition parent)
     : this(parent.Variable)
 {
     Parent = parent;
 }
Example #9
0
        public void SMG_04_05_Simplyify()
        {
            var sm = new StateMachine();
            var stype = sm.AddSimpleType("S");
            stype.AddStateNames(new[] { "A", "B", "C", "D", "X" });
            var v = sm.AddVariable("v", stype);
            var u = sm.AddVariable("u", stype);

            // A + B
            var c1 = new StateCondition(v);
            c1.SetPreStates(new[] { 0, 1 });

            // D
            var c2 = new StateCondition(v);
            c2.SetPreStates(new[] { 3 });

            // A
            var c3 = new StateCondition(v);
            c2.SetPreStates(new[] { 0 });

            var c1dc = Gate.ComposeAND(Gate.Invert(c1.Decompose(ConditionMode.Pre)), Gate.Invert(c2.Decompose(ConditionMode.Pre)));

            Trace("1 === {0}", c1dc);

            return;
        }
Example #10
0
        public void SMG_03_StateCondition()
        {
            TraceFlags.ShowDepencencyAnalysis = true;

            var sm = new StateMachine();
            var stype = new SimpleStateType("State");
            stype.AddStateNames(new[] { "A", "B", "C" });
            var s = sm.AddVariable("s", stype);
            var t = sm.AddVariable("t", stype);

            var c = new StateCondition(s);
            c.SetPreStates("A,B");
            c.SetPostStates("C");

            var e1 = sm.AddEvent("e1");

            var trigger = new Trigger(e1, c);
            sm.AddTrigger(trigger);

            var gc1 = new StateCondition(s);
            gc1.SetPreStates("A");
            // gc1.SetPostStates("C");
            sm.AddGuard(gc1, GuardType.LEAVE, "g1");

            var gc2 = new StateCondition(s);
            gc2.SetPreStates("C");
            sm.AddGuard(gc2, GuardType.ENTER, "g2");

            {
                var c1 = new StateCondition(t);
                c1.SetPreStates("A");

                var c2 = new StateCondition(s);
                c2.SetPreStates("A");
            }

            sm.Calculate();

            // sm.Dump();

            var e = sm.Events.First();
            Assert.AreEqual("e1", e.Name);
            Assert.AreEqual(2, e.Triggers.Count);

            var t1 = e.Triggers[0];
            var t2 = e.Triggers[1];

            Assert.AreEqual(2, t1.Guards.Count);
            Assert.AreEqual(1, t2.Guards.Count);

            Assert.IsTrue(t1.Guards.Any(g => g.Name == "g1"));
            Assert.IsTrue(t1.Guards.Any(g => g.Name == "g2"));
            Assert.IsTrue(t2.Guards.Any(g => g.Name == "g2"));
        }