/** Constructor for getting the acceptance signature for a Tree. * @param tree the Tree, get acceptance signature from * tree.generateAcceptance(*this). */ //template <typename Tree> public RabinSignature(StateInterface tree) { //added by ly this._L = new BitSet(); this._U = new BitSet(); tree.generateAcceptance(this); _size = 0; }
/** Calculate and add transitions to the successor state. * @param from the source stuttered_state * @param da_from the source DA state * @param elem the edge label */ void calc_delta(TreeWithAcceptance from, DA_State da_from, APElement elem) { //StateMapper<SafraTree, int , ptr_hash<algo_state_t>> intermediate_state_map_t; //, PtrComparator<algo_state_t> Dictionary <StateInterface, int> state_map = new Dictionary <StateInterface, int>(); List <StateInterface> state_vector = new List <StateInterface>(); StateInterface start_tree = from.getTree(); //state_map[start_tree] = null; state_map.Add(start_tree, 0); state_vector.Add(start_tree); //push_back #if STUTTERED_VERBOSE std::cerr << "Calculate from state [" << da_from->getName() << "], " << (unsigned int ) elem << ":" << std::endl; std::cerr << start_tree->toString() << std::endl; #endif StateInterface cur_tree = start_tree; while (true) { StateInterface next_tree = _algo.delta(cur_tree as UnionState, elem).getState(); //typename intermediate_state_map_t::iterator it; //int it = state_map.find(next_tree); //if (it == state_map.end()) if (!state_map.ContainsKey(next_tree)) { // tree doesn't yet exist... // add tree //state_map[next_tree] = state_vector.size(); state_map.Add(next_tree, state_vector.Count); state_vector.Add(next_tree); //push_back cur_tree = next_tree; continue; } else { // found the cycle! int cycle_point = state_map[next_tree]; #if STUTTERED_VERBOSE std::cerr << "-----------------------\n"; for (unsigned int i = 0; i < state_vector.size(); i++) { std::cerr << "[" << i << "] "; if (cycle_point == i) { std::cerr << "* "; } std::cerr << "\n" << state_vector[i]->toString() << std::endl; } std::cerr << "-----------------------\n"; #endif prefix_and_cycle_state_t pac = calculate_prefix_and_cycle_state(state_vector, cycle_point); //DA_State da_prefix = null; DA_State da_cycle = null; if (pac.prefix_state != null && !(pac.prefix_state == pac.cycle_state)) { DA_State da_prefix = add_transition(da_from, pac.prefix_state, elem); da_cycle = add_transition(da_prefix, pac.cycle_state, elem); } else { da_cycle = add_transition(da_from, pac.cycle_state, elem); } da_cycle.edges().set(elem, da_cycle); return; } } }
/** 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); }
/** * 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(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(""); } } } }