protected internal virtual void Minimize()
 {
     MakeInitialBlocks();
     while (HasActivePair())
     {
         Pair <ExactAutomatonMinimizer.ExactBlock <TransducerGraph.Arc>, object> activePair = GetActivePair();
         ExactAutomatonMinimizer.ExactBlock <TransducerGraph.Arc> activeBlock = activePair.First();
         object symbol = activePair.Second();
         ICollection <object> inverseImages = GetInverseImages(activeBlock, symbol);
         IDictionary <ExactAutomatonMinimizer.ExactBlock <TransducerGraph.Arc>, ICollection <object> > inverseImagesByBlock = SortIntoBlocks(inverseImages);
         foreach (ExactAutomatonMinimizer.ExactBlock <TransducerGraph.Arc> block in inverseImagesByBlock.Keys)
         {
             if (block == null)
             {
                 throw new Exception("block was null");
             }
             ICollection members = inverseImagesByBlock[block];
             if (members.Count == 0 || members.Count == block.GetMembers().Count)
             {
                 continue;
             }
             if (members.Count > block.GetMembers().Count - members.Count)
             {
                 members = Difference(block.GetMembers(), members);
             }
             RemoveAll(block.GetMembers(), members);
             MakeBlock(members);
         }
     }
 }
        protected internal virtual ICollection <object> GetInverseImages(ExactAutomatonMinimizer.ExactBlock <TransducerGraph.Arc> block, object symbol)
        {
            IList <object> inverseImages = new List <object>();

            foreach (TransducerGraph.Arc member in block.GetMembers())
            {
                ICollection <TransducerGraph.Arc> arcs = null;
                if (member != SinkNode)
                {
                    arcs = GetUnminimizedFA().GetArcsByTargetAndInput(member, symbol);
                }
                else
                {
                    arcs = GetUnminimizedFA().GetArcsByInput(symbol);
                    if (!sparseMode)
                    {
                        arcs = Difference(GetUnminimizedFA().GetArcs(), arcs);
                    }
                }
                if (arcs == null)
                {
                    continue;
                }
                foreach (TransducerGraph.Arc arc in arcs)
                {
                    object source = arc.GetSourceNode();
                    inverseImages.Add(source);
                }
            }
            return(inverseImages);
        }
 protected internal virtual ExactAutomatonMinimizer.ExactBlock <TransducerGraph.Arc> GetBlock(object o)
 {
     ExactAutomatonMinimizer.ExactBlock <TransducerGraph.Arc> result = memberToBlock[o];
     if (result == null)
     {
         throw new Exception("memberToBlock had null block");
     }
     return(result);
 }
        //  protected Collection inverseImages(Collection block, Object symbol) {
        //    List inverseImages = new ArrayList();
        //    for (Iterator nodeI = block.iterator(); nodeI.hasNext();) {
        //      Object node = nodeI.next();
        //      inverseImages.addAll(getUnminimizedFA().getInboundArcs(node, symbol));
        //    }
        //    return inverseImages;
        //  }
        protected internal virtual IDictionary <ExactAutomatonMinimizer.ExactBlock <TransducerGraph.Arc>, ICollection <Y> > SortIntoBlocks <Y>(ICollection <Y> nodes)
        {
            IDictionary <ExactAutomatonMinimizer.ExactBlock <TransducerGraph.Arc>, ICollection <Y> > blockToMembers = Generics.NewHashMap();

            // IdentityHashMap();
            foreach (Y o in nodes)
            {
                ExactAutomatonMinimizer.ExactBlock <TransducerGraph.Arc> block = GetBlock(o);
                if (block == null)
                {
                    throw new Exception("got null block");
                }
                Maps.PutIntoValueHashSet(blockToMembers, block, o);
            }
            return(blockToMembers);
        }
 protected internal virtual void MakeBlock(ICollection <TransducerGraph.Arc> members)
 {
     ExactAutomatonMinimizer.ExactBlock <TransducerGraph.Arc> block = new ExactAutomatonMinimizer.ExactBlock <TransducerGraph.Arc>(Generics.NewHashSet(members));
     foreach (TransducerGraph.Arc member in block.GetMembers())
     {
         if (member != SinkNode)
         {
             memberToBlock[member] = block;
         }
     }
     foreach (object o in GetSymbols())
     {
         TransducerGraph.Arc symbol = (TransducerGraph.Arc)o;
         AddActivePair(new Pair <ExactAutomatonMinimizer.ExactBlock <TransducerGraph.Arc>, TransducerGraph.Arc>(block, symbol));
     }
 }