Exemplo n.º 1
0
 protected internal virtual void Minimize()
 {
     MakeInitialBlocks();
     while (HasSplit())
     {
         FastExactAutomatonMinimizer.Split split = GetSplit();
         ICollection inverseImages        = GetInverseImages(split);
         IDictionary inverseImagesByBlock = SortIntoBlocks(inverseImages);
         foreach (object o in inverseImagesByBlock.Keys)
         {
             FastExactAutomatonMinimizer.Block block = (FastExactAutomatonMinimizer.Block)o;
             ICollection members = (ICollection)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);
         }
     }
 }
Exemplo n.º 2
0
        //  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 SortIntoBlocks(ICollection nodes)
        {
            IDictionary blockToMembers = new IdentityHashMap();

            foreach (object o in nodes)
            {
                FastExactAutomatonMinimizer.Block block = GetBlock(o);
                Maps.PutIntoValueHashSet(blockToMembers, block, o);
            }
            return(blockToMembers);
        }
Exemplo n.º 3
0
 protected internal virtual void MakeBlock(ICollection members)
 {
     FastExactAutomatonMinimizer.Block block = new FastExactAutomatonMinimizer.Block(new HashSet(members));
     foreach (object member in block.GetMembers())
     {
         if (member != SinkNode)
         {
             //        System.out.println("putting in memberToBlock: " + member + " " + block);
             memberToBlock[member] = block;
         }
     }
     AddSplits(block);
 }
Exemplo n.º 4
0
 protected internal virtual FastExactAutomatonMinimizer.Block GetBlock(object o)
 {
     FastExactAutomatonMinimizer.Block result = (FastExactAutomatonMinimizer.Block)memberToBlock[o];
     if (result == null)
     {
         System.Console.Out.WriteLine("No block found for: " + o);
         // debug
         System.Console.Out.WriteLine("But I do have blocks for: ");
         foreach (object o1 in memberToBlock.Keys)
         {
             System.Console.Out.WriteLine(o1);
         }
         throw new Exception("FastExactAutomatonMinimizer: no block found");
     }
     return(result);
 }
Exemplo n.º 5
0
        protected internal virtual void AddSplits(FastExactAutomatonMinimizer.Block block)
        {
            IDictionary symbolToTarget = new Hashtable();

            foreach (object member in block.GetMembers())
            {
                foreach (object o in GetInverseArcs(member))
                {
                    TransducerGraph.Arc arc = (TransducerGraph.Arc)o;
                    object symbol           = arc.GetInput();
                    object target           = arc.GetTargetNode();
                    Maps.PutIntoValueArrayList(symbolToTarget, symbol, target);
                }
            }
            foreach (object symbol_1 in symbolToTarget.Keys)
            {
                AddSplit(new FastExactAutomatonMinimizer.Split((IList)symbolToTarget[symbol_1], symbol_1, block));
            }
        }
Exemplo n.º 6
0
        protected internal virtual ICollection GetInverseImages(FastExactAutomatonMinimizer.Split split)
        {
            IList  inverseImages = new ArrayList();
            object symbol        = split.GetSymbol();

            FastExactAutomatonMinimizer.Block block = split.GetBlock();
            foreach (object member in split.GetMembers())
            {
                if (!block.GetMembers().Contains(member))
                {
                    continue;
                }
                ICollection arcs = GetInverseArcs(member, symbol);
                foreach (object arc1 in arcs)
                {
                    TransducerGraph.Arc arc = (TransducerGraph.Arc)arc1;
                    object source           = arc.GetSourceNode();
                    inverseImages.Add(source);
                }
            }
            return(inverseImages);
        }
Exemplo n.º 7
0
 public Split(ICollection members, object symbol, FastExactAutomatonMinimizer.Block block)
 {
     this.members = members;
     this.symbol  = symbol;
     this.block   = block;
 }