Ejemplo n.º 1
0
        public override bool Equals(object obj)
        {
            LabelAlgebra <SYMBOL> algebra = obj as LabelAlgebra <SYMBOL>;

            if (obj != null)
            {
                return(this.pa.Equals(algebra.pa));
            }
            return(false);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Compose transducers T1 and T2, resulting in transducer equivalent to applying T2 after T1.
        /// </summary>
        public static SST <SYMBOL> Compose(SST <SYMBOL> tau1, SST <SYMBOL> tau2)
        {
            if (tau1.Algebra != tau2.Algebra)
            {
                throw SSTException.IncompatibleAlphabets();
            }

            LabelAlgebra <SYMBOL> algebra = tau1.Algebra;
            var stack       = new Stack <Tuple <int, int> >();
            var finalStates = new List <int>();
            var moves       = new List <Move <Label <SYMBOL> > >();
            var stateDict   = new Dictionary <Tuple <int, int>, int>();
            int id          = 0;

            var init = new Tuple <int, int>(tau1.InitialState, tau2.InitialState);

            stateDict[init] = id++;
            stack.Push(init);

            while (stack.Count > 0)
            {
                Tuple <int, int> sourcePair = stack.Pop();
                int state1 = sourcePair.Item1;
                int state2 = sourcePair.Item2;

                foreach (Move <Label <SYMBOL> > move1 in tau1.GetMovesFrom(state1))
                {
                    foreach (Move <Label <SYMBOL> > move2 in tau2.GetMovesFrom(state2))
                    {
                        Label <SYMBOL> newLabel = algebra.Combine(move1.Label, move2.Label);
                        if (!algebra.IsSatisfiable(newLabel))
                        {
                            continue;
                        }

                        var targetPair = new Tuple <int, int>(move1.TargetState, move2.TargetState);
                        int targetState;
                        if (!stateDict.TryGetValue(targetPair, out targetState))
                        {
                            stateDict[targetPair] = targetState = id++;
                            stack.Push(targetPair);
                            if (tau1.IsFinalState(move1.TargetState) && tau2.IsFinalState(move2.TargetState))
                            {
                                finalStates.Add(targetState);
                            }
                        }
                        moves.Add(new Move <Label <SYMBOL> >(stateDict[sourcePair], targetState, newLabel));
                    }
                }
            }

            return(new SST <SYMBOL>(0, finalStates, moves));
        }