/** * 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); }
/** * 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; }
/** * 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; }
/** * 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); }