/** * Convert an LTL formula to a DRA. * @param ltl the LTL formula * @param options which operators are allowed * @return a shared_ptr to the DRA */ private DRA ltl2dra(LTLFormula ltl, BuchiAutomata buchiAutomata, LTL2DSTAR_Options options) { APSet ap_set = ltl.getAPSet(); LTLFormula ltl_pnf = ltl.toPNF(); if (options.allow_union && ltl_pnf.getRootNode().getType() == type_t.T_OR) { LTLFormula ltl_left = ltl_pnf.getSubFormula(ltl_pnf.getRootNode().getLeft()); LTLFormula ltl_right = ltl_pnf.getSubFormula(ltl_pnf.getRootNode().getRight()); LTL2DSTAR_Options rec_opt = options; rec_opt.recursion(); DRA dra_left = ltl2dra(ltl_left, buchiAutomata, rec_opt); DRA dra_right = ltl2dra(ltl_right, buchiAutomata, rec_opt); return(DRA.calculateUnion(dra_left, dra_right, _safra_opt.union_trueloop) as DRA); } if (options.safety) { LTLSafetyAutomata lsa = new LTLSafetyAutomata(); DRA safety_dra = lsa.ltl2dra(ltl, buchiAutomata); if (safety_dra != null) { return(safety_dra); } } DRA dra = new DRA(ap_set); NBA nba = LTL2NBA.ltl2nba(ltl_pnf, buchiAutomata); if (nba == null) { throw new Exception("Couldn't create NBA from LTL formula"); } NBA2DRA nba2dra = new NBA2DRA(_safra_opt); nba2dra.convert(nba, dra); if (options.optimizeAcceptance) { dra.optimizeAcceptanceCondition(); } if (options.bisim) { DRAOptimizations dra_optimizer = new DRAOptimizations(); dra = dra_optimizer.optimizeBisimulation(dra); } return(dra); }
/** * Convert the NBA to a DRA using Safra's algorithm, using stuttering * @param nba the NBA * @param dra_result the result DRA * @param limit limit for the size of the DRA */ //template < typename NBA_t, typename DRA_t > void convert_safra_stuttered(NBA nba, DRA dra_result, int limit) //=0 { SafraAlgorithm safras_algo = new SafraAlgorithm(nba, _options); StutteredNBA2DA nba2dra_stuttered = new StutteredNBA2DA(_detailed_states, _stutter_information); nba2dra_stuttered.convert(safras_algo, dra_result, limit); }
/** * 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); }
public static DRA dba2dra(NBA nba, bool complement) { APSet ap_set = nba.getAPSet();; DRA dra_p = new DRA(ap_set); dba2dra(nba, dra_p, complement); return(dra_p); }
public static DA calculateUnion(DRA dra1, DRA dra2, bool trueloop_check, bool detailed_states) { if (dra1.isStreett() || dra2.isStreett()) { throw new Exception("Can not calculate union for Streett automata"); } return(DAUnionAlgorithm.calculateUnion(dra1, dra2, trueloop_check, detailed_states)); }
public static DA calculateUnion(DRA dra1, DRA dra2, bool trueloop_check, bool detailed_states) { if (dra1.isStreett() || dra2.isStreett()) { throw new Exception("Can not calculate union for Streett automata"); } return DAUnionAlgorithm.calculateUnion(dra1, dra2, trueloop_check, detailed_states); }
public static DRA dba2dra(NBA nba, bool complement) { APSet ap_set = nba.getAPSet(); ; DRA dra_p = new DRA(ap_set); dba2dra(nba, dra_p, complement); return dra_p; }
/** * 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; }
//bool trueloop_check=true, bool detailed_states=false public static DA calculateUnionStuttered(DRA dra1, DRA dra2, StutterSensitivenessInformation stutter_information, bool trueloop_check, bool detailed_states) { if (dra1.isStreett() || dra2.isStreett()) { throw new Exception("Can not calculate union for Streett automata"); } return DAUnionAlgorithm.calculateUnionStuttered(dra1, dra2, stutter_information, trueloop_check, detailed_states); }
//bool trueloop_check=true, bool detailed_states=false public static DA calculateUnionStuttered(DRA dra1, DRA dra2, StutterSensitivenessInformation stutter_information, bool trueloop_check, bool detailed_states) { if (dra1.isStreett() || dra2.isStreett()) { throw new Exception("Can not calculate union for Streett automata"); } return(DAUnionAlgorithm.calculateUnionStuttered(dra1, dra2, stutter_information, trueloop_check, detailed_states)); }
/** Constructor. * @param algo The Algorithm_t to use * @param da_result The result automaton * @param limit Limit the number of states in the result automaton? * @param detailed_states Generate detailed descriptions? * @param stutter_information Information about which symbols may be stuttered */ public StutteredConvertorUnion(DAUnionAlgorithm algo, DRA da_result, int limit, bool detailed_states, StutterSensitivenessInformation stutter_information) { _da_result = da_result; _limit = limit; _algo = algo; _detailed_states = detailed_states; _stutter_information = stutter_information; //added by ly _state_mapper = new StateMapper <TreeWithAcceptance, DA_State>(); _unprocessed = new Stack <KeyValuePair <TreeWithAcceptance, DA_State> >(); }
/** Constructor. * @param algo The Algorithm_t to use * @param da_result The result automaton * @param limit Limit the number of states in the result automaton? * @param detailed_states Generate detailed descriptions? * @param stutter_information Information about which symbols may be stuttered */ public StutteredConvertorUnion(DAUnionAlgorithm algo, DRA da_result, int limit, bool detailed_states, StutterSensitivenessInformation stutter_information) { _da_result = da_result; _limit = limit; _algo = algo; _detailed_states = detailed_states; _stutter_information = stutter_information; //added by ly _state_mapper = new StateMapper<TreeWithAcceptance, DA_State>(); _unprocessed = new Stack<KeyValuePair<TreeWithAcceptance, DA_State>>(); }
/** * Perform union construction */ public override void calculate(int level, int limit) { // if (_options.verbose_scheduler) { //std::cerr << "Calculate ("<< level <<"): " << typeid(*this).name() << std::endl; // } try { children[0].calculate(level + 1, limit); children[1].calculate(level + 1, limit); } catch (LimitReachedException e) { //_automaton.reset(); return; } if (children[0]._automaton == null || children[1]._automaton == null) { return; } bool union_trueloop = _sched.getLTL2DRA().getOptions().union_trueloop; if (_sched.getLTL2DRA().getOptions().stutter) { _automaton = DRA.calculateUnionStuttered(children[0]._automaton, children[1]._automaton, _stutter_information, union_trueloop, _options.detailed_states) as DRA; } else { _automaton = DRA.calculateUnion(children[0]._automaton, children[1]._automaton, union_trueloop, _options.detailed_states) as DRA; /* _automaton=DRAOperations::dra_union(*children[0]->_automaton, * children[1]->_automaton, * union_trueloop, * _options.detailed_states); */ } _comment = "Union{" + children[0]._comment + "," + children[1]._comment + "}"; if (_options.optimizeAcceptance) { _automaton.optimizeAcceptanceCondition(); } if (_options.bisim) { DRAOptimizations dra_optimizer = new DRAOptimizations(); _automaton = dra_optimizer.optimizeBisimulation(_automaton); //, false, _options.detailed_states, false } hook_after_calculate(); }
public void convert(NBA nba, DRA dra_result, int limit) //=0 { if (nba.size() == 0 || nba.getStartState() == null) { // the NBA is empty -> construct DRA that is empty dra_result.constructEmpty(); return; } if (_options.dba_check && nba.isDeterministic()) { DBA2DRA.dba2dra(nba, dra_result); return; } if (_options.stutter_closure) { if (_stutter_information != null && !_stutter_information.isCompletelyInsensitive()) { //std::cerr << //"WARNING: NBA might not be 100% stutter insensitive, applying stutter closure can create invalid results!" << //std::endl; } NBA nba_closed = NBAStutterClosure.stutter_closure(nba); if (can_stutter()) { convert_safra_stuttered(nba_closed, dra_result, limit); return; } convert_safra(nba_closed, dra_result, limit); return; } if (can_stutter()) { convert_safra_stuttered(nba, dra_result, limit); return; } convert_safra(nba, dra_result, limit); return; }
/** * Constructor, get initial size of the coloring from DRA. * @param dra the DRA * @param detailed Keep detailed information on the equivalence classes? */ public Coloring(DRA dra, bool detailed) //=false { _nr_of_colors = 0; _detailed = detailed; _coloring = new List <int>(); Ultility.resize(_coloring, dra.size()); _color2state = new List <int>(); //_coloring.resize(dra.size()); if (_detailed) { _color2states = new List <BitSet>(); } else { _color2states = null; } }
/** * Convert an NBA to a DRA using Safra's algorithm. * If limit is specified (>0), the conversion is * aborted with LimitReachedException when the number of * states exceeds the limit. * @param nba the formula * @param limit a limit on the number of states (0 for no limit) * @param detailedStates save detailed interal information (Safra trees) * in the generated states * @param stutter_information Information about the symbols that can be stuttered * @return a shared_ptr to the created DRA */ public DRA nba2dra(NBA nba, int limit, bool detailedStates, StutterSensitivenessInformation stutter_information) { DRA dra = new DRA(nba.getAPSet_cp()); NBA2DRA nba2dra = new NBA2DRA(_safra_opt, detailedStates, stutter_information); try { nba2dra.convert(nba, dra, limit); } catch (LimitReachedException e) { //dra.reset(); // rethrow to notify caller //throw; } return(dra); }
/** * Convert an NBA to a DRA using Safra's algorithm. * If limit is specified (>0), the conversion is * aborted with LimitReachedException when the number of * states exceeds the limit. * @param nba the formula * @param limit a limit on the number of states (0 for no limit) * @param detailedStates save detailed interal information (Safra trees) * in the generated states * @param stutter_information Information about the symbols that can be stuttered * @return a shared_ptr to the created DRA */ public DRA nba2dra(NBA nba, int limit, bool detailedStates, StutterSensitivenessInformation stutter_information) { DRA dra = new DRA(nba.getAPSet_cp()); NBA2DRA nba2dra = new NBA2DRA(_safra_opt, detailedStates, stutter_information); try { nba2dra.convert(nba, dra, limit); } catch (LimitReachedException e) { //dra.reset(); // rethrow to notify caller //throw; } return dra; }
/** * Convert the NBA to a DRA using Safra's algorithm * @param nba the NBA * @param dra_result the result DRA * @param limit limit for the size of the DRA */ public void convert_safra(NBA nba, DRA dra_result, int limit) //=0 { SafraAlgorithm safras_algo = new SafraAlgorithm(nba, _options); if (!_options.opt_rename) { NBA2DA nba2da = new NBA2DA(_detailed_states); nba2da.convert(safras_algo, dra_result, limit); } else { //typedef typename SafrasAlgorithm<NBA_t>::result_t result_t; //typedef typename SafrasAlgorithm<NBA_t>::state_t key_t; //<safra_t,DRA_t, StateMapperFuzzy<result_t, key_t, typename DRA_t::state_type, SafraTreeCandidateMatcher> > NBA2DA nba2da_fuzzy = new NBA2DA(_detailed_states); nba2da_fuzzy.convert(safras_algo, dra_result, limit); } }
/** Calculate the automaton for this building block, by default * calculate the automata for the children and then choose the smallest. */ public virtual void calculate(int level, int limit) { //if (_options.verbose_scheduler) { // std::cerr << "Calculate ("<< level <<"): " << typeid(*this).name() << std::endl; //} calculateChildren(level, limit); bool first = true; //for (child_vector::iterator it=children.begin();it!=children.end();++it) for (int i = 0; i < children.Count; i++) { LTL2DSTAR_Tree it = children[i]; if (it._automaton == null) { continue; } if (first) { _automaton = it._automaton; _comment = it._comment; } else { if (_automaton.size() > it._automaton.size()) { _automaton = it._automaton; _comment = it._comment; } } first = false; } hook_after_calculate(); }
/** Type of an acceptance signature */ // public KeyValuePair<BitSet, BitSet> acceptance_signature_t; /** * Constructor, fills the container with the acceptance signatures of the states. * @param dra the DRA */ public AcceptanceSignatureContainer(DRA dra) { //_acceptancesig_vector.resize(dra.size()); _acceptancesig_vector = new List <KeyValuePair <BitSet, BitSet> >(); //Ultility.resize(_acceptancesig_vector, dra.size()); _bitsets = new List <BitSet>(); for (int i = 0; i < dra.size(); i++) { BitSet b = dra.acceptance().getAcceptance_L_forState(i); BitSet bp = new BitSet(b); _bitsets.Add(bp); //push_back // _acceptancesig_vector[i].Key = bp; b = dra.acceptance().getAcceptance_U_forState(i); BitSet bp1 = new BitSet(b); _bitsets.Add(bp1); // //_acceptancesig_vector[i].Value = bp1; _acceptancesig_vector.Add(new KeyValuePair <BitSet, BitSet>(bp, bp1)); } }
/** * Generate a DRA/DSA for the LTL formula */ public DRA calculate(LTLFormula ltl, BuchiAutomata ba, LTL2DSTAR_Options ltl_opt) { LTLFormula ltl_p = (ltl.toPNF()); //if (ltl_opt.verbose_scheduler) { // std::cerr << ltl_p->toStringInfix() << std::endl; //} LTL2DSTAR_Tree_Start root = new LTL2DSTAR_Tree_Start(ltl_p, ba, ltl_opt, this); //if (ltl_opt.verbose_scheduler) { // root.printTree(std::cerr); //} root.calculate(); DRA result = root._automaton; if (result != null) { result.setComment(root._comment); //+ getTimingInformation() } return(result); }
//=0 public void convert(NBA nba, DRA dra_result, int limit) { if (nba.size() == 0 || nba.getStartState() == null) { // the NBA is empty -> construct DRA that is empty dra_result.constructEmpty(); return; } if (_options.dba_check && nba.isDeterministic()) { DBA2DRA.dba2dra(nba, dra_result); return; } if (_options.stutter_closure) { if (_stutter_information != null && !_stutter_information.isCompletelyInsensitive()) { //std::cerr << //"WARNING: NBA might not be 100% stutter insensitive, applying stutter closure can create invalid results!" << //std::endl; } NBA nba_closed = NBAStutterClosure.stutter_closure(nba); if (can_stutter()) { convert_safra_stuttered(nba_closed, dra_result, limit); return; } convert_safra(nba_closed, dra_result, limit); return; } if (can_stutter()) { convert_safra_stuttered(nba, dra_result, limit); return; } convert_safra(nba, dra_result, limit); return; }
//=0 /** * Convert an NBA to an DRA (having APElements as edge labels). * Throws LimitReachedException if a limit is set (>0) and * there are more states in the generated DRA than the limit. * @param nba the NBA * @param dra_result the DRA where the result is stored * (has to have same APSet as the nba) * @param limit a limit for the number of states (0 disables the limit). */ //template < typename NBA_t, typename DRA_t> public void convert(NBA nba, DRA dra_result) { convert(nba, dra_result, 0); }
//=0 /** * Convert the NBA to a DRA using Safra's algorithm, using stuttering * @param nba the NBA * @param dra_result the result DRA * @param limit limit for the size of the DRA */ //template < typename NBA_t, typename DRA_t > void convert_safra_stuttered(NBA nba, DRA dra_result, int limit) { SafraAlgorithm safras_algo = new SafraAlgorithm(nba, _options); StutteredNBA2DA nba2dra_stuttered = new StutteredNBA2DA(_detailed_states, _stutter_information); nba2dra_stuttered.convert(safras_algo, dra_result, limit); }
//=0 /** * Convert the NBA to a DRA using Safra's algorithm * @param nba the NBA * @param dra_result the result DRA * @param limit limit for the size of the DRA */ public void convert_safra(NBA nba, DRA dra_result, int limit) { SafraAlgorithm safras_algo = new SafraAlgorithm(nba, _options); if (!_options.opt_rename) { NBA2DA nba2da = new NBA2DA(_detailed_states); nba2da.convert(safras_algo, dra_result, limit); } else { //typedef typename SafrasAlgorithm<NBA_t>::result_t result_t; //typedef typename SafrasAlgorithm<NBA_t>::state_t key_t; //<safra_t,DRA_t, StateMapperFuzzy<result_t, key_t, typename DRA_t::state_type, SafraTreeCandidateMatcher> > NBA2DA nba2da_fuzzy = new NBA2DA(_detailed_states); nba2da_fuzzy.convert(safras_algo, dra_result, limit); } }
//trueloop_check=true,bool detailed_states=false public static DA calculateUnion(DRA dra1, DRA dra2, bool trueloop_check) { return calculateUnion(dra1, dra2, trueloop_check, false); }
public static void dba2dra(NBA nba, DRA dra_result, bool complement) { //complement=false DRA dra = dra_result; APSet ap_set = dra.getAPSet();; dra.acceptance().newAcceptancePair(); for (int i = 0; i < nba.size(); i++) { dra.newState(); if (complement) { // Final states -> U_0, all states -> L_0 if (nba[i].isFinal()) { dra.acceptance().stateIn_U(0, i); } dra.acceptance().stateIn_L(0, i); } else { // Final states -> L_0, U_0 is empty if (nba[i].isFinal()) { dra.acceptance().stateIn_L(0, i); } } } if (nba.getStartState() != null) { dra.setStartState(dra[nba.getStartState().getName()]); } DA_State sink_state = null; for (int i = 0; i < nba.size(); i++) { NBA_State nba_state = nba[i]; DA_State dra_from = dra[i]; //for (APSet::element_iterator label=ap_set->all_elements_begin();label!=ap_set->all_elements_end(); ++label) for (int label = ap_set.all_elements_begin(); label != ap_set.all_elements_end(); ++label) { BitSet to = nba_state.getEdge(new APElement(label)); int to_cardinality = 0; if (to != null) { to_cardinality = to.cardinality(); } DA_State dra_to = null; if (to == null || to_cardinality == 0) { // empty to -> go to sink state if (sink_state == null) { // we have to create the sink sink_state = dra.newState(); // if we complement, we have to add the sink to // L_0 if (complement) { sink_state.acceptance().addTo_L(0); } } dra_to = sink_state; } else if (to_cardinality == 1) { int to_index = to.nextSetBit(0); // std::cerr << "to: " << to_index << std::endl; dra_to = dra[to_index]; } else { // to_cardinality>1 ! throw new IllegalArgumentException("NBA is no DBA!"); } dra_from.edges().addEdge(new APElement(label), dra_to); } } if (sink_state != null) { // there is a sink state // make true-loop from sink state to itself //for (APSet::element_iterator label=ap_set->all_elements_begin();label!=ap_set->all_elements_end();++label) { for (int label = ap_set.all_elements_begin(); label != ap_set.all_elements_end(); ++label) { sink_state.edges().addEdge(new APElement(label), sink_state); } } }
//trueloop_check=true,bool detailed_states=false public static DA calculateUnion(DRA dra1, DRA dra2, bool trueloop_check) { return(calculateUnion(dra1, dra2, trueloop_check, false)); }
public override void Initialize(SpecificationBase spec) { ltl2ba.Node LTLHeadNode; switch (ConstraintType) { case QueryConstraintType.PROB: //create the DRA from the BA LTLHeadNode = LTL2BA.ParseLTL("!(" + this.LTLString + ")", "", new CommonToken(0, "")); NegativeDRA = BA2DRAConverter.ConvertBA2DRA(BA, LTLHeadNode); NegativeDRA.DeclarationDatabase = BA.DeclarationDatabase; //todo: builf the positve DRA too //create the DRA from the BA LTLHeadNode = LTL2BA.ParseLTL(this.LTLString, "", new CommonToken(0, "")); PositiveDRA = BA2DRAConverter.ConvertBA2DRA(PositiveBA, LTLHeadNode); PositiveDRA.DeclarationDatabase = BA.DeclarationDatabase; break; case QueryConstraintType.PMAX: //create the DRA from the BA LTLHeadNode = LTL2BA.ParseLTL(this.LTLString, "", new CommonToken(0, "")); PositiveDRA = BA2DRAConverter.ConvertBA2DRA(PositiveBA, LTLHeadNode); PositiveDRA.DeclarationDatabase = BA.DeclarationDatabase; break; case QueryConstraintType.PMIN: //create the DRA from the BA if(AlmostFair)//note add by ssz { LTLHeadNode = LTL2BA.ParseLTL(this.LTLString, "", new CommonToken(0, "")); PositiveDRA = BA2DRAConverter.ConvertBA2DRA(PositiveBA, LTLHeadNode); PositiveDRA.DeclarationDatabase = BA.DeclarationDatabase; } else { LTLHeadNode = LTL2BA.ParseLTL("!(" + this.LTLString + ")", "", new CommonToken(0, "")); NegativeDRA = BA2DRAConverter.ConvertBA2DRA(BA, LTLHeadNode); NegativeDRA.DeclarationDatabase = BA.DeclarationDatabase; } break; } if (ConstraintType == QueryConstraintType.NONE) { base.Initialize(spec); } else { //initialize model checking options ModelCheckingOptions = new ModelCheckingOptions(); List<string> LTLEngine = new List<string>(); LTLEngine.Add(Constants.ENGINE_MDP_SEARCH); #if DEBUG LTLEngine.Add(Constants.ENGINE_MDP_MEC_SEARCH); LTLEngine.Add(Constants.ENGINE_MDP_SIM_SEARCH); #endif ModelCheckingOptions.AddAddimissibleBehavior(Constants.COMPLETE_BEHAVIOR, LTLEngine); } }
/** * 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); }
/** * Convert an NBA to an DRA (having APElements as edge labels). * Throws LimitReachedException if a limit is set (>0) and * there are more states in the generated DRA than the limit. * @param nba the NBA * @param dra_result the DRA where the result is stored * (has to have same APSet as the nba) * @param limit a limit for the number of states (0 disables the limit). */ //template < typename NBA_t, typename DRA_t> public void convert(NBA nba, DRA dra_result) //=0 { convert(nba, dra_result, 0); }
/// <summary> /// Run the verification and get the result. /// </summary> /// <returns></returns> public override void RunVerification() { if (ConstraintType == QueryConstraintType.NONE) { base.RunVerification(); return; } if (IsSafety) { RunVerificationSafety(); return; } if (!IsNegateLiveness) { RunVerificationNegate(); return; } if (SelectedEngineName == Constants.ENGINE_MDP_SEARCH) { switch (ConstraintType) { case QueryConstraintType.PROB: DRA = NegativeDRA; BuildMDP(); //note this function is just used to calculate the maximal probability. Min = 1 - mdp.MaxProbability(VerificationOutput); DRA = PositiveDRA; BuildMDP(); Max = mdp.MaxProbability(VerificationOutput); break; case QueryConstraintType.PMAX: DRA = PositiveDRA; BuildMDP(); Max = mdp.MaxProbability(VerificationOutput); break; case QueryConstraintType.PMIN: if (AlmostFair) //note add by ssz { DRA = PositiveDRA; BuildMDP(); Min = mdp.MinProbability(VerificationOutput); } else { DRA = NegativeDRA; BuildMDP(); Min = 1 - mdp.MaxProbability(VerificationOutput); } break; } } else if (SelectedEngineName == Constants.ENGINE_MDP_MEC_SEARCH) { switch (ConstraintType) { case QueryConstraintType.PROB: DRA = NegativeDRA; BuildMD_ImprovedTarjan(); //note this function is just used to calculate the maximal probability. Min = 1 - mdp.MaxProbability(VerificationOutput); DRA = PositiveDRA; BuildMD_ImprovedTarjan(); Max = mdp.MaxProbability(VerificationOutput); break; case QueryConstraintType.PMAX: DRA = PositiveDRA; //BuildMDP(); BuildMD_ImprovedTarjan(); Max = mdp.MaxProbability(VerificationOutput); break; case QueryConstraintType.PMIN: if (AlmostFair) //note add by ssz { DRA = PositiveDRA; BuildMD_ImprovedTarjan(); Min = mdp.MinProbability(VerificationOutput); } else { DRA = NegativeDRA; BuildMD_ImprovedTarjan(); Min = 1 - mdp.MaxProbability(VerificationOutput); } break; } } else if (SelectedEngineName == Constants.ENGINE_MDP_SIM_SEARCH) { switch (ConstraintType) { case QueryConstraintType.PROB: DRA = NegativeDRA; BuildMDP(); //note this function is just used to calculate the maximal probability. mdp = mdp.ComputeGCPP(VerificationOutput); Min = 1 - mdp.MaxProbability(VerificationOutput); DRA = PositiveDRA; BuildMDP(); mdp = mdp.ComputeGCPP(VerificationOutput); Max = mdp.MaxProbability(VerificationOutput); break; case QueryConstraintType.PMAX: DRA = PositiveDRA; BuildMDP(); mdp = mdp.ComputeGCPP(VerificationOutput); Max = mdp.MaxProbability(VerificationOutput); break; case QueryConstraintType.PMIN: if (AlmostFair) //note add by ssz { DRA = PositiveDRA; BuildMDP(); mdp = mdp.ComputeGCPP(VerificationOutput); Min = mdp.MinProbability(VerificationOutput); } else { DRA = NegativeDRA; BuildMDP(); mdp = mdp.ComputeGCPP(VerificationOutput); Min = 1 - mdp.MaxProbability(VerificationOutput); } break; } } if (Min == 1) { VerificationOutput.VerificationResult = VerificationResultType.VALID; } else if (Max == 0) { VerificationOutput.VerificationResult = VerificationResultType.INVALID; } else { VerificationOutput.VerificationResult = VerificationResultType.WITHPROBABILITY; } }
/** Constructor */ public ColoredStateComparator(Coloring coloring, DRA dra) { _coloring = coloring; _dra = dra; }
/** * Generate a DA using the Algorithm * Throws LimitReachedException if a limit is set (>0) and * there are more states in the generated DA than the limit. * @param algo the algorithm * @param da_result the DA where the result is stored * (has to have same APSet as the nba) * @param limit a limit for the number of states (0 disables the limit). */ public void convert(DAUnionAlgorithm algo, DRA da_result, int limit) { StateMapper <StateInterface, DA_State> state_mapper = new StateMapper <StateInterface, DA_State>(); APSet ap_set = da_result.getAPSet(); if (algo.checkEmpty()) { da_result.constructEmpty(); return; } //typedef typename DA_t::state_type da_state_t; //typedef typename Algorithm_t::state_t algo_state_t; //typedef typename Algorithm_t::result_t algo_result_t; algo.prepareAcceptance(da_result.acceptance()); StateInterface start = algo.getStartState(); DA_State start_state = da_result.newState(); start.generateAcceptance(start_state.acceptance()); if (_detailed_states) { start_state.setDescription(start.toHTML()); } state_mapper.add(start, start_state); da_result.setStartState(start_state); //typedef std::pair<algo_state_t, da_state_t*> unprocessed_value; Stack <KeyValuePair <StateInterface, DA_State> > unprocessed = new Stack <KeyValuePair <StateInterface, DA_State> >(); unprocessed.Push(new KeyValuePair <StateInterface, DA_State>(start, start_state)); while (unprocessed.Count > 0) { KeyValuePair <StateInterface, DA_State> top = unprocessed.Pop(); //unprocessed.pop(); StateInterface cur = top.Key; DA_State from = top.Value; //for (APSet::element_iterator it_elem = ap_set.all_elements_begin(); it_elem != ap_set.all_elements_end(); ++it_elem) for (int it_elem = ap_set.all_elements_begin(); it_elem != ap_set.all_elements_end(); ++it_elem) { APElement elem = new APElement(it_elem); ResultStateInterface <UnionState> result = algo.delta(cur as UnionState, elem); DA_State to = state_mapper.find(result.getState()); if (to == null) { to = da_result.newState(); result.getState().generateAcceptance(to.acceptance()); if (_detailed_states) { to.setDescription(result.getState().toHTML()); } state_mapper.add(result.getState(), to); unprocessed.Push(new KeyValuePair <StateInterface, DA_State>(result.getState(), to)); } from.edges().set(elem, to); if (limit != 0 && da_result.size() > limit) { throw new LimitReachedException(""); } } } }
/** * Generate a DA using the Algorithm * Throws LimitReachedException if a limit is set (>0) and * there are more states in the generated DA than the limit. * @param algo the algorithm * @param da_result the DA where the result is stored * (has to have same APSet as the nba) * @param limit a limit for the number of states (0 disables the limit). */ public void convert(DAUnionAlgorithm algo, DRA da_result, int limit) { StateMapper<StateInterface, DA_State> state_mapper = new StateMapper<StateInterface, DA_State>(); APSet ap_set = da_result.getAPSet(); if (algo.checkEmpty()) { da_result.constructEmpty(); return; } //typedef typename DA_t::state_type da_state_t; //typedef typename Algorithm_t::state_t algo_state_t; //typedef typename Algorithm_t::result_t algo_result_t; algo.prepareAcceptance(da_result.acceptance()); StateInterface start = algo.getStartState(); DA_State start_state = da_result.newState(); start.generateAcceptance(start_state.acceptance()); if (_detailed_states) { start_state.setDescription(start.toHTML()); } state_mapper.add(start, start_state); da_result.setStartState(start_state); //typedef std::pair<algo_state_t, da_state_t*> unprocessed_value; Stack<KeyValuePair<StateInterface, DA_State>> unprocessed = new Stack<KeyValuePair<StateInterface, DA_State>>(); unprocessed.Push(new KeyValuePair<StateInterface, DA_State>(start, start_state)); while (unprocessed.Count > 0) { KeyValuePair<StateInterface, DA_State> top = unprocessed.Pop(); //unprocessed.pop(); StateInterface cur = top.Key; DA_State from = top.Value; //for (APSet::element_iterator it_elem = ap_set.all_elements_begin(); it_elem != ap_set.all_elements_end(); ++it_elem) for (int it_elem = ap_set.all_elements_begin(); it_elem != ap_set.all_elements_end(); ++it_elem) { APElement elem = new APElement(it_elem); ResultStateInterface<UnionState> result = algo.delta(cur as UnionState, elem); DA_State to = state_mapper.find(result.getState()); if (to == null) { to = da_result.newState(); result.getState().generateAcceptance(to.acceptance()); if (_detailed_states) { to.setDescription(result.getState().toHTML()); } state_mapper.add(result.getState(), to); unprocessed.Push(new KeyValuePair<StateInterface, DA_State>(result.getState(), to)); } from.edges().set(elem, to); if (limit != 0 && da_result.size() > limit) { throw new LimitReachedException(""); } } } }
/** * Generate a DA using the Algorithm * Throws LimitReachedException if a limit is set (>0) and * there are more states in the generated DA than the limit. * @param algo the algorithm * @param da_result the DA where the result is stored * (has to have same APSet as the nba) * @param limit a limit for the number of states (0 disables the limit). */ public void convert(SafraAlgorithm algo, DRA da_result, int limit) { /** The hash map from DA_State to StateInterface */ StateMapper <StateInterface, DA_State> state_mapper = new StateMapper <StateInterface, DA_State>(); APSet ap_set = da_result.getAPSet();////////////************where dose this dra have ap_set? if (algo.checkEmpty()) { da_result.constructEmpty(); return; } //typedef typename DA_t::state_type da_state_t; //typedef typename Algorithm_t::state_t algo_state_t; //typedef typename Algorithm_t::result_t algo_result_t; //* Creates new acceptance pairs according to da_result's acceptance. algo.prepareAcceptance(da_result.acceptance());////*********don't understand well StateInterface start = algo.getStartState(); DA_State start_state = da_result.newState();/////************?? what is in this newState? start.generateAcceptance(start_state.acceptance()); if (_detailed_states) { start_state.setDescription(start.toHTML()); } state_mapper.add(start, start_state); da_result.setStartState(start_state); //typedef std::pair<algo_state_t, da_state_t*> unprocessed_value; Stack <KeyValuePair <StateInterface, DA_State> > unprocessed = new Stack <KeyValuePair <StateInterface, DA_State> >(); unprocessed.Push(new KeyValuePair <StateInterface, DA_State>(start, start_state)); while (unprocessed.Count > 0) { KeyValuePair <StateInterface, DA_State> top = unprocessed.Pop(); //unprocessed.pop(); StateInterface cur = top.Key; //safratreeNode DA_State from = top.Value; //DA_state //for (APSet::element_iterator it_elem = ap_set.all_elements_begin(); it_elem != ap_set.all_elements_end(); ++it_elem) for (int it_elem = ap_set.all_elements_begin(); it_elem != ap_set.all_elements_end(); ++it_elem) ///from 0 to 2^ap_set.size { APElement elem = new APElement(it_elem); /////////set simpleBitset = it_elem ResultStateInterface <SafraTree> result = algo.delta(cur as SafraTree, elem); /////get a new safraTree through elem DA_State to = state_mapper.find(result.getState()); if (to == null)////////////////result is not in state mapper. { to = da_result.newState(); result.getState().generateAcceptance(to.acceptance()); if (_detailed_states) { to.setDescription(result.getState().toHTML()); } state_mapper.add(result.getState(), to); unprocessed.Push(new KeyValuePair <StateInterface, DA_State>(result.getState(), to)); } from.edges().set(elem, to);//////////////add this edge. if (limit != 0 && da_result.size() > limit) { throw new LimitReachedException(""); } } } }
/** * Generate a DA using the Algorithm * Throws LimitReachedException if a limit is set (>0) and * there are more states in the generated DA than the limit. * @param algo the algorithm * @param da_result the DA where the result is stored * (has to have same APSet as the nba) * @param limit a limit for the number of states (0 disables the limit). */ public void convert(SafraAlgorithm algo, DRA da_result, int limit) { /** The hash map from DA_State to StateInterface */ StateMapper<StateInterface, DA_State> state_mapper = new StateMapper<StateInterface, DA_State>(); APSet ap_set = da_result.getAPSet();////////////************where dose this dra have ap_set? if (algo.checkEmpty()) { da_result.constructEmpty(); return; } //typedef typename DA_t::state_type da_state_t; //typedef typename Algorithm_t::state_t algo_state_t; //typedef typename Algorithm_t::result_t algo_result_t; //* Creates new acceptance pairs according to da_result's acceptance. algo.prepareAcceptance(da_result.acceptance());////*********don't understand well StateInterface start = algo.getStartState(); DA_State start_state = da_result.newState();/////************?? what is in this newState? start.generateAcceptance(start_state.acceptance()); if (_detailed_states) { start_state.setDescription(start.toHTML()); } state_mapper.add(start, start_state); da_result.setStartState(start_state); //typedef std::pair<algo_state_t, da_state_t*> unprocessed_value; Stack<KeyValuePair<StateInterface, DA_State>> unprocessed = new Stack<KeyValuePair<StateInterface, DA_State>>(); unprocessed.Push(new KeyValuePair<StateInterface, DA_State>(start, start_state)); while (unprocessed.Count > 0) { KeyValuePair<StateInterface, DA_State> top = unprocessed.Pop(); //unprocessed.pop(); StateInterface cur = top.Key;//safratreeNode DA_State from = top.Value;//DA_state //for (APSet::element_iterator it_elem = ap_set.all_elements_begin(); it_elem != ap_set.all_elements_end(); ++it_elem) for (int it_elem = ap_set.all_elements_begin(); it_elem != ap_set.all_elements_end(); ++it_elem)///from 0 to 2^ap_set.size { APElement elem = new APElement(it_elem);/////////set simpleBitset = it_elem ResultStateInterface<SafraTree> result = algo.delta(cur as SafraTree, elem);/////get a new safraTree through elem DA_State to = state_mapper.find(result.getState()); if (to == null)////////////////result is not in state mapper. { to = da_result.newState(); result.getState().generateAcceptance(to.acceptance()); if (_detailed_states) { to.setDescription(result.getState().toHTML()); } state_mapper.add(result.getState(), to); unprocessed.Push(new KeyValuePair<StateInterface, DA_State>(result.getState(), to)); } from.edges().set(elem, to);//////////////add this edge. if (limit != 0 && da_result.size() > limit) { throw new LimitReachedException(""); } } } }
/** * Internal helper function to perform the conversion from NBA to DRA. * @param nba the NBA (has to be deterministic) * @param dra_result the DRA into which the converted automaton is saved * @param complement complement the DBA? */ public static void dba2dra(NBA nba, DRA dra_result) { dba2dra(nba, dra_result, false); }
/** The output format */ //enum {OUT_v2, OUT_NBA, OUT_DOT, OUT_PLUGIN} flag_output; public static DRA ConvertBA2DRA(BuchiAutomata BA, Node LTLHeadNode) { /** Flag: Convert LTL->DRA->NBA? */ //bool flag_dra2nba; /** Flag: Print the NBA afert LTL->NBA? */ //bool flag_print_ltl_nba; /** Flag: Use limiting with scheduler? */ bool flag_sched_limits; /** The limiting factor for the scheduler (alpha) */ double alpha; /** The options for Safra's algorithm */ Options_Safra opt_safra = new Options_Safra(); /** The options for LTL2DSTAR */ LTL2DSTAR_Options opt_ltl2dstar = new LTL2DSTAR_Options(); opt_ltl2dstar.opt_safra = opt_safra; // std::map<std::string, std::string> defaults; //defaults["--ltl2nba"]="--ltl2nba=spin:ltl2ba"; //defaults["--automata"]="--automata=rabin"; //defaults["--output"]="--output=automaton"; //defaults["--detailed-states"]="--detailed-states=no"; //defaults["--safra"]="--safra=all"; //defaults["--bisimulation"]="--bisimulation=yes"; //defaults["--opt-acceptance"]="--opt-acceptance=yes"; //defaults["--union"]="--union=yes"; //defaults["--alpha"]="--alpha=10.0"; //defaults["--stutter"]="--stutter=yes"; //defaults["--partial-stutter"]="--partial-stutter=no"; //// defaults["--scheck"]=""; // scheck disabled /// /// // default values... //flag_dra2nba = false; flag_sched_limits = false; alpha = 1.0; // options not yet covered //flag_print_ltl_nba = false; //flag_stat_nba = false; //if (isRabin) //{ opt_ltl2dstar.automata = automata_type.RABIN; //} //else //{ // opt_ltl2dstar.automata = automata_type.STREETT; //} opt_safra.opt_all(); opt_safra.stutter = false; opt_ltl2dstar.bisim = false; opt_safra.opt_rename = false; LTLFormula ltl = LTLPrefixParser.parse(LTLHeadNode); //APSet ap_set = ltl.getAPSet(); //Debug.Assert(ltl2nba != null); LTL2DRA ltl2dra = new LTL2DRA(opt_safra); //, ltl2nba.get() //if (opt_ltl2dstar.automata == automata_type.ORIGINAL_NBA) //{ // // We just generate the NBA for the LTL formula // // and print it // NBA nba = ltl2dra.ltl2nba(ltl); // if (nba == null) // { // throw new Exception("Can't generate NBA for LTL formula"); // } // //if (flag_output==OUT_DOT) { // // nba->print_dot(out); // //} else { // // nba->print_lbtt(out); // //} // //return 0; //} LTL2DSTAR_Scheduler ltl2dstar_sched = new LTL2DSTAR_Scheduler(ltl2dra, flag_sched_limits, alpha); //ltl2dstar_sched.flagStatNBA(flag_stat_nba); ltl2dstar_sched.flagStatNBA(false); opt_ltl2dstar.opt_safra = opt_safra; DRA dra = ltl2dstar_sched.calculate(ltl, BA, opt_ltl2dstar); //if (!dra.isCompact()) { // dra.makeCompact(); //} if (dra == null) { throw new Exception("Couldn't generate DRA!"); } //if (!dra.isCompact()) { // dra.makeCompact(); //} return(dra); }
/** * Convert an LTL formula to a DRA. * @param ltl the LTL formula * @param options which operators are allowed * @return a shared_ptr to the DRA */ private DRA ltl2dra(LTLFormula ltl, BuchiAutomata buchiAutomata, LTL2DSTAR_Options options) { APSet ap_set = ltl.getAPSet(); LTLFormula ltl_pnf = ltl.toPNF(); if (options.allow_union && ltl_pnf.getRootNode().getType() == type_t.T_OR) { LTLFormula ltl_left = ltl_pnf.getSubFormula(ltl_pnf.getRootNode().getLeft()); LTLFormula ltl_right = ltl_pnf.getSubFormula(ltl_pnf.getRootNode().getRight()); LTL2DSTAR_Options rec_opt = options; rec_opt.recursion(); DRA dra_left = ltl2dra(ltl_left, buchiAutomata, rec_opt); DRA dra_right = ltl2dra(ltl_right,buchiAutomata, rec_opt); return DRA.calculateUnion(dra_left, dra_right, _safra_opt.union_trueloop) as DRA; } if (options.safety) { LTLSafetyAutomata lsa = new LTLSafetyAutomata(); DRA safety_dra = lsa.ltl2dra(ltl, buchiAutomata); if (safety_dra != null) { return safety_dra; } } DRA dra = new DRA(ap_set); NBA nba = LTL2NBA.ltl2nba(ltl_pnf, buchiAutomata); if (nba == null) { throw new Exception("Couldn't create NBA from LTL formula"); } NBA2DRA nba2dra = new NBA2DRA(_safra_opt); nba2dra.convert(nba, dra); if (options.optimizeAcceptance) { dra.optimizeAcceptanceCondition(); } if (options.bisim) { DRAOptimizations dra_optimizer = new DRAOptimizations(); dra = dra_optimizer.optimizeBisimulation(dra); } return dra; }
/** * 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; }
/** * Constructor, get initial size of the coloring from DRA. * @param dra the DRA * @param detailed Keep detailed information on the equivalence classes? */ public Coloring(DRA dra, bool detailed) //=false { _nr_of_colors = 0; _detailed = detailed; _coloring = new List<int>(); Ultility.resize(_coloring, dra.size()); _color2state = new List<int>(); //_coloring.resize(dra.size()); if (_detailed) { _color2states = new List<BitSet>(); } else { _color2states = null; } }
public static void dba2dra(NBA nba, DRA dra_result, bool complement) { //complement=false DRA dra = dra_result; APSet ap_set = dra.getAPSet(); ; dra.acceptance().newAcceptancePair(); for (int i = 0; i < nba.size(); i++) { dra.newState(); if (complement) { // Final states -> U_0, all states -> L_0 if (nba[i].isFinal()) { dra.acceptance().stateIn_U(0, i); } dra.acceptance().stateIn_L(0, i); } else { // Final states -> L_0, U_0 is empty if (nba[i].isFinal()) { dra.acceptance().stateIn_L(0, i); } } } if (nba.getStartState() != null) { dra.setStartState(dra[nba.getStartState().getName()]); } DA_State sink_state = null; for (int i = 0; i < nba.size(); i++) { NBA_State nba_state = nba[i]; DA_State dra_from = dra[i]; //for (APSet::element_iterator label=ap_set->all_elements_begin();label!=ap_set->all_elements_end(); ++label) for (int label = ap_set.all_elements_begin(); label != ap_set.all_elements_end(); ++label) { BitSet to = nba_state.getEdge(new APElement(label)); int to_cardinality = 0; if (to != null) { to_cardinality = to.cardinality(); } DA_State dra_to = null; if (to == null || to_cardinality == 0) { // empty to -> go to sink state if (sink_state == null) { // we have to create the sink sink_state = dra.newState(); // if we complement, we have to add the sink to // L_0 if (complement) { sink_state.acceptance().addTo_L(0); } } dra_to = sink_state; } else if (to_cardinality == 1) { int to_index = to.nextSetBit(0); // std::cerr << "to: " << to_index << std::endl; dra_to = dra[to_index]; } else { // to_cardinality>1 ! throw new IllegalArgumentException("NBA is no DBA!"); } dra_from.edges().addEdge(new APElement(label), dra_to); } } if (sink_state != null) { // there is a sink state // make true-loop from sink state to itself //for (APSet::element_iterator label=ap_set->all_elements_begin();label!=ap_set->all_elements_end();++label) { for (int label = ap_set.all_elements_begin(); label != ap_set.all_elements_end(); ++label) { sink_state.edges().addEdge(new APElement(label), sink_state); } } }
/** Type of an acceptance signature */ // public KeyValuePair<BitSet, BitSet> acceptance_signature_t; /** * Constructor, fills the container with the acceptance signatures of the states. * @param dra the DRA */ public AcceptanceSignatureContainer(DRA dra) { //_acceptancesig_vector.resize(dra.size()); _acceptancesig_vector = new List<KeyValuePair<BitSet, BitSet>>(); //Ultility.resize(_acceptancesig_vector, dra.size()); _bitsets = new List<BitSet>(); for (int i = 0; i < dra.size(); i++) { BitSet b = dra.acceptance().getAcceptance_L_forState(i); BitSet bp = new BitSet(b); _bitsets.Add(bp); //push_back // _acceptancesig_vector[i].Key = bp; b = dra.acceptance().getAcceptance_U_forState(i); BitSet bp1 = new BitSet(b); _bitsets.Add(bp1); // //_acceptancesig_vector[i].Value = bp1; _acceptancesig_vector.Add(new KeyValuePair<BitSet, BitSet>(bp, bp1)); } }