Beispiel #1
0
        // TODO: Uses non-reachable states (inefficient)
        TriangularPair <int>[] GetEquivalentPairs()
        {
            // table filling algorithm:

            var undistinguishablePairs = new HashSet <TriangularPair <int> >(); // not marked!!!

            // basis
            foreach (int p in _delta.Keys)
            {
                foreach (int q in _delta.Keys)
                {
                    if (q <= p)
                    {
                        continue;         // triangular
                    }
                    if (!IsBasisDistinguishable(p, q))
                    {
                        undistinguishablePairs.Add(new TriangularPair <int>(p, q));
                    }
                }
            }

            // induction
            while (true)
            {
                // marked pairs in this induction step
                var marked = new List <TriangularPair <int> >();

                foreach (TAlphabet successorLabel in GetLabels())
                {
                    foreach (var pair in undistinguishablePairs)
                    {
                        // Make function with input loop
                        // IsInductionDistinguishable

                        //int p = Trans[pair.Fst][successorLabel];
                        //int q = Trans[pair.Snd][successorLabel];
                        if (_delta[pair.Fst].TryGetValue(successorLabel, out var p) &&
                            _delta[pair.Snd].TryGetValue(successorLabel, out var q))
                        {
                            TriangularPair <int> successorPair = new TriangularPair <int>(p, q);

                            // For all pairs still undecided if for any successor label/input/suffix
                            // the pair goes into a pair (p, q) where the states are distinguishable
                            // for any suffix (that is already marked) we have to mark the pair.

                            // NOTE: BAD that we have to test p not equal to q (use marked table instead)
                            if (p != q && !undistinguishablePairs.Contains(successorPair)) // successor pair is marked
                            {
                                marked.Add(pair);
                            }
                        }
                    }

                    //Debug.WriteLine($"Step {step}, Input = {successorLabel}, Count = {markedPerInput.Count}: " +
                    //                markedPerInput.Select(p =>
                    //                        $"({_renamer.ToDfaStateString(p.Fst)}, {_renamer.ToDfaStateString(p.Snd)})")
                    //                    .ToSetNotation());
                }

                foreach (var pair in marked)
                {
                    undistinguishablePairs.Remove(pair); // no-op for duplicates
                }

                if (marked.Count == 0)
                {
                    break; // no more distinguishable pairs have been removed
                }
            }

            // the following pairs are equivalent
            return(undistinguishablePairs.ToArray());
        }
 public bool Equals(TriangularPair <T> other)
 {
     return(EqualityComparer <T> .Default.Equals(Fst, other.Fst) &&
            EqualityComparer <T> .Default.Equals(Snd, other.Snd));
 }