예제 #1
0
        /**
         * Perform quotienting using bisimulation
         * @param dra the DRA to be optimized
         * @param printColoring print colorings on std::cerr?
         * @param detailedStates save detailed information on the interals in the state?
         * @param printStats print statistics on std::cerr?
         * @return shared_ptr to the quotiented DRA
         */
        public DRA optimizeBisimulation(DRA dra)
        {
            bool printColoring  = false;
            bool detailedStates = false;
            bool printStats     = false;

            //if (!dra.isCompact()) {dra.makeCompact();}

            List <int> states = new List <int>(dra.size());

            for (int i = 0; i < dra.size(); i++)
            {
                //states[i] = i;
                states.Add(i);
            }

            AcceptanceSignatureContainer  accsig_container = new AcceptanceSignatureContainer(dra);
            AcceptanceSignatureComparator accsig_comp      = new AcceptanceSignatureComparator(accsig_container);


            Coloring coloring = new Coloring(dra, detailedStates);
            // generate initial coloring by running with the
            // different acceptance signature
            Coloring new_coloring = generateColoring(states, coloring, accsig_comp);

            //delete coloring;
            coloring = new_coloring;

            int old_size          = dra.size();
            int initial_partition = coloring.countColors();

            int oldColors;

            do
            {
                oldColors = coloring.countColors();

                ColoredStateComparator cnc = new ColoredStateComparator(coloring, dra);

                Coloring new_coloring_temp = generateColoring(states, coloring, cnc);
                //delete coloring;
                coloring = new_coloring_temp;
            } while (oldColors != coloring.countColors());

            //if (printColoring) {
            //  std::cerr << *coloring << std::endl;
            //}

            DRA dra_new = generateDRAfromColoring(dra, coloring, detailedStates);
            //delete coloring;

            int new_size = dra_new.size();

            //if (printStats) {
            //  std::cerr << "Bisimulation: From (" << old_size << ") To (" << new_size << ") Initial: (" << initial_partition << ")" << std::endl;
            //}
            return(dra_new);
        }
예제 #2
0
        /** 
         * Perform quotienting using bisimulation
         * @param dra the DRA to be optimized
         * @param printColoring print colorings on std::cerr?
         * @param detailedStates save detailed information on the interals in the state?
         * @param printStats print statistics on std::cerr?
         * @return shared_ptr to the quotiented DRA
         */
        public DRA optimizeBisimulation(DRA dra)
        {
            bool printColoring = false;
            bool detailedStates = false;
            bool printStats = false;

            //if (!dra.isCompact()) {dra.makeCompact();}

            List<int> states = new List<int>(dra.size());

            for (int i = 0; i < dra.size(); i++)
            {
                //states[i] = i;
                states.Add(i);
            }

            AcceptanceSignatureContainer accsig_container = new AcceptanceSignatureContainer(dra);
            AcceptanceSignatureComparator accsig_comp = new AcceptanceSignatureComparator(accsig_container);


            Coloring coloring = new Coloring(dra, detailedStates);
            // generate initial coloring by running with the 
            // different acceptance signature
            Coloring new_coloring = generateColoring(states, coloring, accsig_comp);
            //delete coloring;
            coloring = new_coloring;

            int old_size = dra.size();
            int initial_partition = coloring.countColors();

            int oldColors;
            do
            {
                oldColors = coloring.countColors();

                ColoredStateComparator cnc = new ColoredStateComparator(coloring, dra);

                Coloring new_coloring_temp = generateColoring(states, coloring, cnc);
                //delete coloring;
                coloring = new_coloring_temp;
            } while (oldColors != coloring.countColors());

            //if (printColoring) {
            //  std::cerr << *coloring << std::endl;
            //}

            DRA dra_new = generateDRAfromColoring(dra, coloring, detailedStates);
            //delete coloring;

            int new_size = dra_new.size();

            //if (printStats) {
            //  std::cerr << "Bisimulation: From (" << old_size << ") To (" << new_size << ") Initial: (" << initial_partition << ")" << std::endl;
            //}
            return dra_new;
        }
예제 #3
0
        /**
         * Generate a new coloring based on the Comparator comp 
         * (one iteration of refinement)
         * @param states A vector of the states
         * @param coloring The current coloring
         * @param comp the Comparator
         * @return a pointer to a newly created Coloring, memory ownership
         *         passes to the caller
         */
        //template <class Comparator>
        private Coloring generateColoring(List<int> states, Coloring coloring, Comparator comp)
        {

            //std::sort(states.begin(), states.end(), comp);
            states.Sort();

            Coloring result = new Coloring(coloring.size(), coloring.getFlagDetailed());

            if (states.Count == 0)
            {
                return result;
            }

            //state_vector::reverse_iterator current = states.rbegin(), last = states.rbegin();
            int current = states[states.Count - 1];
            int last = states[states.Count - 1];

            result.setColor(current, result.newColor());

            for (int i = states.Count - 1; i >= 0; i--)//////-1 or -2?
            {
                current = states[i];
                // because states is sorted and we traverse 
                // from the end, either:
                //    *current  < *last with comp(current,last)==true
                // or *current == *last with !comp(current,last)
                if (comp.comp(current, last))
                {
                    // -> we have to start a new color
                    result.setColor(current, result.newColor());
                }
                else
                {
                    // -> more of the same, we stay with this color
                    result.setColor(current, result.currentColor());
                }

                last = current;
            }

            ////while (++current != states.rend())
            //while (++current != states[0])
            //{
            //    // because states is sorted and we traverse 
            //    // from the end, either:
            //    //    *current  < *last with comp(current,last)==true
            //    // or *current == *last with !comp(current,last)
            //    if (comp.comp(current, last))
            //    {
            //        // -> we have to start a new color
            //        result.setColor(current, result.newColor());
            //    }
            //    else
            //    {
            //        // -> more of the same, we stay with this color
            //        result.setColor(current, result.currentColor());
            //    }

            //    last = current;
            //}

            return result;
        }
예제 #4
0
 /** Constructor */
 public ColoredStateComparator(Coloring coloring, DRA dra)
 {
     _coloring = coloring;
     _dra = dra;
 }
예제 #5
0
        /**
   * Generate a new DRA from a coloring
   */
        DRA generateDRAfromColoring(DRA oldDRA, Coloring coloring, bool detailedStates)
        {
            DRA newDRA = oldDRA.createInstance(oldDRA.getAPSet()) as DRA;


            newDRA.acceptance().newAcceptancePairs(oldDRA.acceptance().size());

            for (int color = 0; color < coloring.countColors(); ++color)
            {
                newDRA.newState();
            }

            int old_start_state = oldDRA.getStartState().getName();
            int start_state_color = coloring.state2color(old_start_state);

            newDRA.setStartState(newDRA.get(start_state_color));

            APSet apset = newDRA.getAPSet();

            for (int color = 0; color < coloring.countColors(); ++color)
            {
                DA_State new_state = newDRA.get(color);

                int old_state_representative = coloring.color2state(color);

                DA_State old_state = oldDRA[old_state_representative];

                if (detailedStates)
                {
                    BitSet old_states = coloring.color2states(color);

                    // create new description...
                    if (old_states.cardinality() == 1)
                    {
                        if (old_state.hasDescription())
                        {
                            new_state.setDescription(old_state.getDescription());
                        }
                    }
                    else
                    {
                        //std::ostringstream s;
                        //s << "<TABLE BORDER=\"1\" CELLBORDER=\"0\"><TR><TD>{</TD>";
                        StringBuilder s = new StringBuilder(@"<TABLE BORDER=\""1\"" CELLBORDER=\""0\""><TR><TD>{</TD>");

                        bool first = true;
                        for (int it = BitSetIterator.start(old_states); it != BitSetIterator.end(old_states); it = BitSetIterator.increment(old_states, it))
                        {
                            if (first)
                            {
                                first = false;
                            }
                            else
                            {
                                s.Append("<TD>,</TD>");
                            }

                            s.Append("<TD>");
                            if (!oldDRA[it].hasDescription())
                            {
                                s.Append(it);
                            }
                            else
                            {
                                s.Append(oldDRA[it].getDescription());
                            }
                            s.Append("</TD>");
                        }
                        s.Append("<TD>}</TD></TR></TABLE>");

                        new_state.setDescription(s.ToString());
                        ;
                    }
                }

                // Create appropriate acceptance conditions
                int old_state_index = old_state.getName();
                for (int i = 0; i < oldDRA.acceptance().size(); ++i)
                {
                    if (oldDRA.acceptance().isStateInAcceptance_L(i, old_state_index))
                    {
                        new_state.acceptance().addTo_L(i);
                    }

                    if (oldDRA.acceptance().isStateInAcceptance_U(i, old_state_index))
                    {
                        new_state.acceptance().addTo_U(i);
                    }
                }

                //for (APSet::element_iterator label=apset.all_elements_begin();label!=apset.all_elements_end();++label) 
                for (int label = apset.all_elements_begin(); label != apset.all_elements_end(); ++label)
                {

                    DA_State old_to = old_state.edges().get(new APElement(label));

                    int to_color = coloring.state2color(old_to.getName());

                    new_state.edges().addEdge(new APElement(label), newDRA.get(to_color));
                }
            }

            return newDRA;
        }
예제 #6
0
        /**
         * Generate a new coloring based on the Comparator comp
         * (one iteration of refinement)
         * @param states A vector of the states
         * @param coloring The current coloring
         * @param comp the Comparator
         * @return a pointer to a newly created Coloring, memory ownership
         *         passes to the caller
         */
        //template <class Comparator>
        private Coloring generateColoring(List <int> states, Coloring coloring, Comparator comp)
        {
            //std::sort(states.begin(), states.end(), comp);
            states.Sort();

            Coloring result = new Coloring(coloring.size(), coloring.getFlagDetailed());

            if (states.Count == 0)
            {
                return(result);
            }

            //state_vector::reverse_iterator current = states.rbegin(), last = states.rbegin();
            int current = states[states.Count - 1];
            int last    = states[states.Count - 1];

            result.setColor(current, result.newColor());

            for (int i = states.Count - 1; i >= 0; i--)//////-1 or -2?
            {
                current = states[i];
                // because states is sorted and we traverse
                // from the end, either:
                //    *current  < *last with comp(current,last)==true
                // or *current == *last with !comp(current,last)
                if (comp.comp(current, last))
                {
                    // -> we have to start a new color
                    result.setColor(current, result.newColor());
                }
                else
                {
                    // -> more of the same, we stay with this color
                    result.setColor(current, result.currentColor());
                }

                last = current;
            }

            ////while (++current != states.rend())
            //while (++current != states[0])
            //{
            //    // because states is sorted and we traverse
            //    // from the end, either:
            //    //    *current  < *last with comp(current,last)==true
            //    // or *current == *last with !comp(current,last)
            //    if (comp.comp(current, last))
            //    {
            //        // -> we have to start a new color
            //        result.setColor(current, result.newColor());
            //    }
            //    else
            //    {
            //        // -> more of the same, we stay with this color
            //        result.setColor(current, result.currentColor());
            //    }

            //    last = current;
            //}

            return(result);
        }
예제 #7
0
 /** Constructor */
 public ColoredStateComparator(Coloring coloring, DRA dra)
 {
     _coloring = coloring;
     _dra      = dra;
 }
예제 #8
0
        /**
         * Generate a new DRA from a coloring
         */
        DRA generateDRAfromColoring(DRA oldDRA, Coloring coloring, bool detailedStates)
        {
            DRA newDRA = oldDRA.createInstance(oldDRA.getAPSet()) as DRA;


            newDRA.acceptance().newAcceptancePairs(oldDRA.acceptance().size());

            for (int color = 0; color < coloring.countColors(); ++color)
            {
                newDRA.newState();
            }

            int old_start_state   = oldDRA.getStartState().getName();
            int start_state_color = coloring.state2color(old_start_state);

            newDRA.setStartState(newDRA.get(start_state_color));

            APSet apset = newDRA.getAPSet();

            for (int color = 0; color < coloring.countColors(); ++color)
            {
                DA_State new_state = newDRA.get(color);

                int old_state_representative = coloring.color2state(color);

                DA_State old_state = oldDRA[old_state_representative];

                if (detailedStates)
                {
                    BitSet old_states = coloring.color2states(color);

                    // create new description...
                    if (old_states.cardinality() == 1)
                    {
                        if (old_state.hasDescription())
                        {
                            new_state.setDescription(old_state.getDescription());
                        }
                    }
                    else
                    {
                        //std::ostringstream s;
                        //s << "<TABLE BORDER=\"1\" CELLBORDER=\"0\"><TR><TD>{</TD>";
                        StringBuilder s = new StringBuilder(@"<TABLE BORDER=\""1\"" CELLBORDER=\""0\""><TR><TD>{</TD>");

                        bool first = true;
                        for (int it = BitSetIterator.start(old_states); it != BitSetIterator.end(old_states); it = BitSetIterator.increment(old_states, it))
                        {
                            if (first)
                            {
                                first = false;
                            }
                            else
                            {
                                s.Append("<TD>,</TD>");
                            }

                            s.Append("<TD>");
                            if (!oldDRA[it].hasDescription())
                            {
                                s.Append(it);
                            }
                            else
                            {
                                s.Append(oldDRA[it].getDescription());
                            }
                            s.Append("</TD>");
                        }
                        s.Append("<TD>}</TD></TR></TABLE>");

                        new_state.setDescription(s.ToString());
                        ;
                    }
                }

                // Create appropriate acceptance conditions
                int old_state_index = old_state.getName();
                for (int i = 0; i < oldDRA.acceptance().size(); ++i)
                {
                    if (oldDRA.acceptance().isStateInAcceptance_L(i, old_state_index))
                    {
                        new_state.acceptance().addTo_L(i);
                    }

                    if (oldDRA.acceptance().isStateInAcceptance_U(i, old_state_index))
                    {
                        new_state.acceptance().addTo_U(i);
                    }
                }

                //for (APSet::element_iterator label=apset.all_elements_begin();label!=apset.all_elements_end();++label)
                for (int label = apset.all_elements_begin(); label != apset.all_elements_end(); ++label)
                {
                    DA_State old_to = old_state.edges().get(new APElement(label));

                    int to_color = coloring.state2color(old_to.getName());

                    new_state.edges().addEdge(new APElement(label), newDRA.get(to_color));
                }
            }

            return(newDRA);
        }