//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; //typedef TreeWithAcceptance<algo_state_t, typename Acceptance::signature_type> stuttered_state_t; //typedef typename stuttered_state_t::ptr stuttered_state_ptr_t; //typedef std::pair<stuttered_state_ptr_t, da_state_t*> unprocessed_value_t; //typedef std::stack<unprocessed_value_t> unprocessed_stack_t; /** Convert the NBA to the DA */ public void convert() { APSet ap_set = _da_result.getAPSet(); if (_algo.checkEmpty()) { _da_result.constructEmpty(); return; } _algo.prepareAcceptance(_da_result.acceptance()); TreeWithAcceptance s_start = new TreeWithAcceptance(_algo.getStartState()); DA_State start_state = _da_result.newState(); s_start.generateAcceptance(start_state.acceptance()); if (_detailed_states) { //start_state->setDescription(s_start->toHTML()); start_state.setDescription("hahahahah"); } _state_mapper.add(s_start, start_state); _da_result.setStartState(start_state); Stack <KeyValuePair <TreeWithAcceptance, DA_State> > unprocessed; _unprocessed.Push(new KeyValuePair <TreeWithAcceptance, DA_State>(s_start, start_state)); bool all_insensitive = _stutter_information.isCompletelyInsensitive(); BitSet partial_insensitive = _stutter_information.getPartiallyInsensitiveSymbols(); while (_unprocessed.Count > 0) { KeyValuePair <TreeWithAcceptance, DA_State> top = _unprocessed.Pop(); //_unprocessed.pop(); TreeWithAcceptance from = top.Key; DA_State da_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); if (da_from.edges().get(elem) == null) { // the edge was not yet calculated... if (!all_insensitive && partial_insensitive.get(it_elem) == null) { // can't stutter for this symbol, do normal step SafraTree next_tree = _algo.delta(from.getTree() as SafraTree, elem).getState(); TreeWithAcceptance next_state = new TreeWithAcceptance(next_tree); add_transition(da_from, next_state, elem); continue; } // normal stuttering... calc_delta(from, da_from, elem); if (_limit != 0 && _da_result.size() > _limit) { //THROW_EXCEPTION(LimitReachedException, ""); throw new Exception("LimitReachedException"); } } } } }
/** 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 SafraTree, 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; } } }
/** 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; } } }