/** * Compares two states 'less-than' using the * coloring, uses the bisimulation * equivalence relation to determine * equality. */ //bool operator()(int state_x, int state_y) public bool comp(int state_x, int state_y) { int cx = _coloring.state2color(state_x); int cy = _coloring.state2color(state_y); if (cx < cy) { return(true); } else if (cx > cy) { return(false); } //for (APSet::element_iterator label= _dra.getAPSet().all_elements_begin();label!=_dra.getAPSet().all_elements_end();++label) for (int label = _dra.getAPSet().all_elements_begin(); label != _dra.getAPSet().all_elements_end(); ++label) { DA_State to_x = _dra[state_x].edges().get(new APElement(label)); DA_State to_y = _dra[state_y].edges().get(new APElement(label)); int ctx = _coloring.state2color(to_x.getName()); int cty = _coloring.state2color(to_y.getName()); if (ctx < cty) { return(true); } else if (ctx > cty) { return(false); } } // we get here only if x and y are equal with this // coloring -> return false return(false); }
/** * 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); }