示例#1
0
 private bool IncludeTransition(Transition other)
 {
     if (!Includes.Add(other))
     {
         return(false);
     }
     other.IncludedBy.Add(this);
     //propagate "up"
     foreach (var incBy in IncludedBy)
     {
         incBy.IncludeTransition(other);
     }
     return(true);
 }
示例#2
0
        private TransitionSet BuildTransitionSet(IEnumerable <IGate> terms, IEnumerable <IVariableCondition> rvclist)
        {
            var tset = new TransitionSet();

            var result          = Gate.Constant(false);
            var staticvariables = new HashSet <int>();

            foreach (var term in terms)
            {
                // populate a dictionary per variable factor
                var dict = new Dictionary <int, ConditionPair>();

                // right sides first
                foreach (var right in rvclist)
                {
                    dict.Add(right.Variable.Index, new ConditionPair {
                        Right = right
                    });
                }

                foreach (var left in term.GetVariableConditions())
                {
                    ConditionPair cp;
                    if (dict.TryGetValue(left.Variable.Index, out cp))
                    {
                        // right side exists
                        cp.Left = left;
                    }
                    else
                    {
                        dict.Add(left.Variable.Index, new ConditionPair {
                            Left = left
                        });
                    }
                }

                // evaluate new term
                var newterm = Gate.Constant(true);
                foreach (var p in dict.Values)
                {
                    if (null == p.Left)
                    {
                        // right side factor not present on left side, move static condition
                        newterm = Gate.ComposeAND(newterm, p.Right.Decompose());
                    }
                    else if (null == p.Right)
                    {
                        // static condition
                        newterm = Gate.ComposeAND(newterm, p.Left.Decompose());
                    }
                    else if (p.Left.StateIndex == p.Right.StateIndex)
                    {
                        // no state change: static condition
                        //newterm = Gate.ComposeAND(newterm, p.Left.Decompose());

                        throw new CompilerException(ErrorCode.BadCondition,
                                                    "variable consition " + p.Left + " used on both sides of a transition.");
                    }
                    else
                    {
                        newterm = Gate.ComposeAND(newterm, p.Left.Decompose());

                        // add transition
                        var x = new Transition(p.Left)
                        {
                            PreStateIndexes = new[] { p.Left.StateIndex },
                            NewStateIndexes = new[] { p.Right.StateIndex }
                        };

                        tset.Add(x);
                    }
                }

                result = Gate.ComposeOR(result, newterm);
            }

            _lgate = result;

            return(tset);
        }
示例#3
0
        private TransitionSet BuildTransitionSet(IEnumerable<IGate> terms, IEnumerable<IVariableCondition> rvclist)
        {
            var tset = new TransitionSet();

            var result = Gate.Constant(false);
            var staticvariables = new HashSet<int>();

            foreach (var term in terms)
            {
                // populate a dictionary per variable factor
                var dict = new Dictionary<int, ConditionPair>();

                // right sides first
                foreach (var right in rvclist)
                {
                    dict.Add(right.Variable.Index, new ConditionPair { Right = right });
                }

                foreach (var left in term.GetVariableConditions())
                {
                    ConditionPair cp;
                    if(dict.TryGetValue(left.Variable.Index, out cp))
                    {
                        // right side exists
                        cp.Left = left;
                    }
                    else
                    {
                        dict.Add(left.Variable.Index, new ConditionPair { Left = left });
                    }
                }

                // evaluate new term
                var newterm = Gate.Constant(true);
                foreach(var p in dict.Values)
                {
                    if(null == p.Left)
                    {
                        // right side factor not present on left side, move static condition
                        newterm = Gate.ComposeAND(newterm, p.Right.Decompose());
                    }
                    else if(null == p.Right)
                    {
                        // static condition
                        newterm = Gate.ComposeAND(newterm, p.Left.Decompose());
                    }
                    else if(p.Left.StateIndex == p.Right.StateIndex)
                    {
                        // no state change: static condition
                        //newterm = Gate.ComposeAND(newterm, p.Left.Decompose());

                        throw new CompilerException(ErrorCode.BadCondition,
                            "variable consition " + p.Left + " used on both sides of a transition.");
                    }
                    else
                    {
                        newterm = Gate.ComposeAND(newterm, p.Left.Decompose());

                        // add transition
                        var x = new Transition(p.Left)
                        {
                            PreStateIndexes = new[] { p.Left.StateIndex },
                            NewStateIndexes = new[] { p.Right.StateIndex }
                        };

                        tset.Add(x);
                    }
                }

                result = Gate.ComposeOR(result, newterm);
            }

            _lgate = result;

            return tset;
        }