Exemplo n.º 1
0
        /**
         * Calculate the acceptance signature for the union of two states.
         * @param da_state_1 index of the state in the first automaton
         * @param da_state_2 index of the state in the second automaton
         * @return A shared_ptr Rabin acceptance signature
         */
        public RabinSignature calculateAcceptance(int da_state_1, int da_state_2)
        {
            RabinSignature signature_p = new RabinSignature(_acc_size_1 + _acc_size_2);
            RabinSignature signature   = signature_p;

            for (int i = 0; i < _acc_size_1; i++)
            {
                if (_acc_1.isStateInAcceptance_L(i, da_state_1))
                {
                    signature.setL(i, true);
                }
                if (_acc_1.isStateInAcceptance_U(i, da_state_1))
                {
                    signature.setU(i, true);
                }
            }

            for (int j = 0; j < _acc_size_2; j++)
            {
                if (_acc_2.isStateInAcceptance_L(j, da_state_2))
                {
                    signature.setL(j + _acc_size_1, true);
                }
                if (_acc_2.isStateInAcceptance_U(j, da_state_2))
                {
                    signature.setU(j + _acc_size_1, true);
                }
            }

            return(signature_p);
        }
Exemplo n.º 2
0
 /** Constructor
  * @param other another RabinSignature
  */
 public RabinSignature(RabinSignature other)
 {
     //_L(other._L), _U(other._U), _size(other._size)
     this._L    = new BitSet(other._L);
     this._U    = new BitSet(other._U);
     this._size = other._size;
 }
Exemplo n.º 3
0
        public override RabinSignature generateAcceptance()
        {
            RabinSignature s = new RabinSignature(getNodeMax());

            generateAcceptance(s);
            return(s);
        }
Exemplo n.º 4
0
 /** Merge this acceptance signature with other signature,
  *  for each tuple element calculate the maximum of the
  *  colors according to the order
  * RABIN_WHITE < RABIN_GREEN < RABIN_RED */
 public void maxMerge(RabinSignature other)
 {
     for (int i = 0; i < _size; i++)
     {
         if (getColor(i) < other.getColor(i))
         {
             setColor(i, other.getColor(i));
         }
     }
 }
Exemplo n.º 5
0
 /** Set L and U for this state according to RabinSignature */
 public void setSignature(RabinSignature signature)
 {
     for (int i = 0; i < signature.size(); i++)
     {
         if (signature.getL().get(i))
         {
             addTo_L(i);
         }
         if (signature.getU().get(i))
         {
             addTo_U(i);
         }
     }
 }
Exemplo n.º 6
0
        //typedef std::vector<algo_state_t> intermediate_state_vector_t;

        /**
         * Calculate Acceptance for RabinAcceptance conditon
         */
        private bool calculate_acceptance(List <StateInterface> state_vector, int cycle_point, RabinSignature prefix_signature, RabinSignature cycle_signature)
        {
            int states = state_vector.Count;

            state_vector[cycle_point].generateAcceptance(cycle_signature); // start
            for (int i = cycle_point + 1; i < states; i++)
            {
                cycle_signature.maxMerge(state_vector[i].generateAcceptance());
            }

            if (prefix_signature != null)
            {
                prefix_signature = cycle_signature;
                for (int i = 1; i < cycle_point; i++)
                {
                    prefix_signature.maxMerge(state_vector[i].generateAcceptance());
                }
            }

            if (prefix_signature != null)
            {
                // check if prefix can be ommited
                RabinSignature p0_signature = new RabinSignature(prefix_signature.getSize());
                state_vector[0].generateAcceptance(p0_signature);

                for (int j = 0; j < prefix_signature.getSize(); j++)
                {
                    if (prefix_signature.getColor(j) <= cycle_signature.getColor(j) ||
                        prefix_signature.getColor(j) <= p0_signature.getColor(j))
                    {
                        // acceptance pair j is ok
                        ;
                    }
                    else
                    {
                        return(false);
                    }
                }
                // all acceptance pairs are ok, return true
                return(true);
            }

            return(false);
        }
Exemplo n.º 7
0
 public override void generateAcceptance(RabinSignature acceptance)
 {
     acceptance.setSize(getNodeMax());
     for (int i = 0; i < getNodeMax(); i++)
     {
         SafraTreeNode stn = this[i];
         if (stn == null)
         {
             acceptance.setColor(i, RabinColor.RABIN_RED);
         }
         else
         {
             if (stn.hasFinalFlag())
             {
                 acceptance.setColor(i, RabinColor.RABIN_GREEN);
             }
             else
             {
                 acceptance.setColor(i, RabinColor.RABIN_WHITE);
             }
         }
     }
 }
Exemplo n.º 8
0
 /** Merge this acceptance signature with other signature,
  *  for each tuple element calculate the maximum of the
  *  colors according to the order
  * RABIN_WHITE < RABIN_GREEN < RABIN_RED */
 public void maxMerge(RabinSignature other)
 {
     for (int i = 0; i < _size; i++)
     {
     if (getColor(i) < other.getColor(i))
     {
         setColor(i, other.getColor(i));
     }
     }
 }
Exemplo n.º 9
0
 /** Copy acceptance signature for this state
  * @param acceptance (<b>out</b>) acceptance signature for the state in the result automaton
  */
 public override void generateAcceptance(RabinSignature acceptance)
 {
     acceptance = signature;
 }
Exemplo n.º 10
0
 /** Constructor.
  * @param da_state_1_ index of the state in the first automaton
  * @param da_state_2_ index of the state in the second automaton
  * @param acceptance_calculator UnionAcceptanceCalculator
  */
 //template <typename AcceptanceCalc>
 public UnionState(int da_state_1_, int da_state_2_, UnionAcceptanceCalculator acceptance_calculator)
 {
     da_state_1 = da_state_1_;
     da_state_2 = da_state_2_;
     signature  = acceptance_calculator.calculateAcceptance(da_state_1, da_state_2);
 }
Exemplo n.º 11
0
 /** Constructor. The acceptance signature is initialized from the tree.
  * @param tree the Tree
  */
 public TreeWithAcceptance(StateInterface tree)
 {
     _tree = tree;
     //_signature(*tree);
     _signature = new RabinSignature(tree);
 }
Exemplo n.º 12
0
 /**
  * Generate the appropriate acceptance signature for Rabin Acceptance for this object
  * @param acceptance the acceptance signature to which the signature for this state is copied
  */
 public void generateAcceptance(RabinSignature acceptance)
 {
     acceptance = _signature;
 }
Exemplo n.º 13
0
 public override RabinSignature generateAcceptance()
 {
     RabinSignature s = new RabinSignature(getNodeMax());
     generateAcceptance(s);
     return s;
 }
Exemplo n.º 14
0
 /** Constructor
  * @param other another RabinSignature
  */
 public RabinSignature(RabinSignature other)
 {
     //_L(other._L), _U(other._U), _size(other._size)
     this._L = new BitSet(other._L);
     this._U = new BitSet(other._U);
     this._size = other._size;
 }
Exemplo n.º 15
0
 /** Set L and U for this state according to RabinSignature */
 public void setSignature(RabinSignature signature)
 {
     for (int i=0;i<signature.size();i++) {
     if (signature.getL().get(i)) {
       addTo_L(i);
     }
     if (signature.getU().get(i)) {
       addTo_U(i);
     }
       }
 }
Exemplo n.º 16
0
        //typedef std::vector<algo_state_t> intermediate_state_vector_t;
        /**
         * Calculate Acceptance for RabinAcceptance conditon
         */
        private bool calculate_acceptance(List<StateInterface> state_vector, int cycle_point, RabinSignature prefix_signature, RabinSignature cycle_signature)
        {
            int states = state_vector.Count;

            state_vector[cycle_point].generateAcceptance(cycle_signature); // start
            for (int i = cycle_point + 1; i < states; i++)
            {
                cycle_signature.maxMerge(state_vector[i].generateAcceptance());
            }

            if (prefix_signature != null)
            {
                prefix_signature = cycle_signature;
                for (int i = 1; i < cycle_point; i++)
                {
                    prefix_signature.maxMerge(state_vector[i].generateAcceptance());
                }
            }

            if (prefix_signature != null)
            {
                // check if prefix can be ommited
                RabinSignature p0_signature = new RabinSignature(prefix_signature.getSize());
                state_vector[0].generateAcceptance(p0_signature);

                for (int j = 0; j < prefix_signature.getSize(); j++)
                {
                    if (prefix_signature.getColor(j) <= cycle_signature.getColor(j) ||
                        prefix_signature.getColor(j) <= p0_signature.getColor(j))
                    {
                        // acceptance pair j is ok
                        ;
                    }
                    else
                    {
                        return false;
                    }
                }
                // all acceptance pairs are ok, return true
                return true;
            }

            return false;
        }
Exemplo n.º 17
0
 public abstract void generateAcceptance(RabinSignature acceptance);
Exemplo n.º 18
0
 public abstract void generateAcceptance(RabinSignature acceptance);
Exemplo n.º 19
0
        /** Calculate the prefix and the cycle state */
        prefix_and_cycle_state_t calculate_prefix_and_cycle_state(List <StateInterface> state_vector, int cycle_point)
        {
            //TreeWithAcceptance prefix_state, cycle_state;
            TreeWithAcceptance prefix_state = null;
            TreeWithAcceptance cycle_state  = null;
            int states = state_vector.Count; //.size();

            int smallest = cycle_point;

            for (int i = cycle_point + 1; i < states; i++)
            {
                if (state_vector[i] < state_vector[smallest])
                {
                    smallest = i;
                }
            }

#if STUTTERED_VERBOSE
            std::cerr << "Smallest: " << smallest << std::endl;
#endif

            cycle_state = new TreeWithAcceptance(state_vector[smallest]);
            if (!(cycle_point == 0 || cycle_point == 1))
            {
                prefix_state = new TreeWithAcceptance(state_vector[smallest]);
            }

            RabinSignature signature_prefix = null; //(typename Acceptance::signature_type*)NULL;
            if (prefix_state != null)
            {
                signature_prefix = prefix_state.getSignature();
            }
            RabinSignature signature_cycle = cycle_state.getSignature();


            bool omit_prefix = calculate_acceptance(state_vector, cycle_point, signature_prefix, signature_cycle);

            if (omit_prefix)
            {
                //prefix_state.reset();
            }

            //  if (_detailed_states) {
            //    std::ostringstream prefix_description;
            //    std::ostringstream cycle_description;

            //if (prefix_state) {
            //  prefix_description << "<TABLE><TR><TD>Prefix</TD><TD>Cycle (" << (smallest-cycle_point) <<")</TD></TR>"
            //             << "<TR><TD>";

            //  prefix_description << "<TABLE><TR>";
            //  for (unsigned int i=1;i<cycle_point;i++) {
            //    prefix_description << "<TD>" << state_vector[i]->toHTML() << "</TD>";
            //  }
            //  prefix_description << "</TR></TABLE></TD>";
            //}

            //cycle_description << "<TD><TABLE><TR>";
            //for (unsigned int i=cycle_point; i<state_vector.size();i++) {
            //  cycle_description << "<TD>";
            //  cycle_description << state_vector[i]->toHTML();
            //  cycle_description << "</TD>";
            //}
            //cycle_description << "</TR></TABLE></TD>";


            //if (prefix_state) {
            //  prefix_description << cycle_description.str();
            //  prefix_description << "</TR></TABLE>";

            //  prefix_state->setDescription(prefix_description.str());
            //}

            //cycle_description << "</TR></TABLE>";
            //cycle_state->setDescription("<TABLE><TR><TD>Cycle ("+
            //                boost::lexical_cast<std::string>(smallest-cycle_point) +
            //                ")</TD></TR><TR>" + cycle_description.str());
            //  }

            return(new prefix_and_cycle_state_t(prefix_state, cycle_state));
        }
Exemplo n.º 20
0
 public override void generateAcceptance(RabinSignature acceptance)
 {
     acceptance.setSize(getNodeMax());
     for (int i = 0; i < getNodeMax(); i++)
     {
         SafraTreeNode stn = this[i];
         if (stn == null)
         {
             acceptance.setColor(i, RabinColor.RABIN_RED);
         }
         else
         {
             if (stn.hasFinalFlag())
             {
                 acceptance.setColor(i, RabinColor.RABIN_GREEN);
             }
             else
             {
                 acceptance.setColor(i, RabinColor.RABIN_WHITE);
             }
         }
     }
 }