public Set<State<T>> move(final Set<State<T>> stateSet, final T c) { final Set<State<T>> result = new HashSet<>(); // for all the states in the set SS for (final State<T> st : stateSet) // for all the edges from state st for (final Transition<T> e : st.getTransitions()) // add the 'to' state if transition matches if (e.hasName(c)) result.add(e.getTo()); return result; }
public boolean isConnected() { final Set<State<T>> visited = new HashSet<>(); final Stack<State<T>> stack = new Stack<>(); stack.push(_initialState); visited.add(_initialState); while (!stack.isEmpty()) { final State<T> state = stack.pop(); if (!_allStates.contains(state)) return false; for (final Transition<T> t : state.getTransitions()) if (visited.add(t.getTo())) stack.push(t.getTo()); } return visited.size() == _allStates.size(); }
public boolean isConnected() { final Set<State<T>> visited = new HashSet<>(); final Stack<State<T>> stack = new Stack<>(); stack.push(_initialState); visited.add(_initialState); while (!stack.isEmpty()) { final State<T> state = stack.pop(); if (!_allStates.contains(state)) return false; for (final Transition<T> t : state.getTransitions()) if (visited.add(t.getTo())) stack.push(t.getTo()); } return visited.size() == _allStates.size(); }
public Set<State<T>> move(final Set<State<T>> stateSet, final T c) { final Set<State<T>> result = new HashSet<>(); // for all the states in the set SS for (final State<T> st : stateSet) // for all the edges from state st for (final Transition<T> e : st.getTransitions()) // add the 'to' state if transition matches if (e.hasName(c)) result.add(e.getTo()); return result; }
public TransitionGraph<T> renumber() { final Set<State<T>> processed = new HashSet<>(); final LinkedList<State<T>> workList = new LinkedList<>(); int val = 0; workList.addFirst(_initialState); while (workList.size() > 0) { final State<T> s = workList.removeFirst(); s.setName(val++); processed.add(s); for (final Transition<T> e : s.getTransitions()) if (processed.add(e.getTo())) workList.addLast(e.getTo()); } return this; }
public TransitionGraph<T> renumber() { final Set<State<T>> processed = new HashSet<>(); final LinkedList<State<T>> workList = new LinkedList<>(); int val = 0; workList.addFirst(_initialState); while (workList.size() > 0) { final State<T> s = workList.removeFirst(); s.setName(val++); processed.add(s); for (final Transition<T> e : s.getTransitions()) if (processed.add(e.getTo())) workList.addLast(e.getTo()); } return this; }
final Iterator<Transition<T>> i = st.getTransitions().iterator(); while (i.hasNext())
public boolean isDeterministic() { if (!_allStates.contains(_initialState)) throw new InternalReasonerException(); for (final State<T> s : _allStates) { final Set<T> seenSymbols = new HashSet<>(); for (final Transition<T> t : s.getTransitions()) { final T symbol = t.getName(); if (t.isEpsilon() || !seenSymbols.add(symbol)) return false; } } return true; }
final Iterator<Transition<T>> i = st.getTransitions().iterator(); while (i.hasNext())
public boolean isDeterministic() { if (!_allStates.contains(_initialState)) throw new InternalReasonerException(); for (final State<T> s : _allStates) { final Set<T> seenSymbols = new HashSet<>(); for (final Transition<T> t : s.getTransitions()) { final T symbol = t.getName(); if (t.isEpsilon() || !seenSymbols.add(symbol)) return false; } } return true; }
public Set<State<T>> epsilonClosure(final State<T> s, final Set<State<T>> init) { Set<State<T>> result = init; // s is in the epsilon closure of itself result.add(s); // for each edge from s for (final Transition<T> e : s.getTransitions()) // if this is an epsilon transition and the result // does not contain 'to' state then add the epsilon // closure of 'to' state to the result set if (e.isEpsilon() && !result.contains(e.getTo())) result = epsilonClosure(e.getTo(), result); return result; }
public Set<State<T>> epsilonClosure(final State<T> s, final Set<State<T>> init) { Set<State<T>> result = init; // s is in the epsilon closure of itself result.add(s); // for each edge from s for (final Transition<T> e : s.getTransitions()) // if this is an epsilon transition and the result // does not contain 'to' state then add the epsilon // closure of 'to' state to the result set if (e.isEpsilon() && !result.contains(e.getTo())) result = epsilonClosure(e.getTo(), result); return result; }
for (final Transition<T> t : s1.getTransitions())
private State<Role> copyState(final State<Role> oldState, final TransitionGraph<Role> newTG, final Map<State<Role>, State<Role>> newStates) { State<Role> newState = newStates.get(oldState); if (newState == null) { newState = newTG.newState(); newStates.put(oldState, newState); for (final Transition<Role> t : oldState.getTransitions()) { final State<Role> oldTo = t.getTo(); final State<Role> newFrom = copyState(oldTo, newTG, newStates); if (t.isEpsilon()) newTG.addTransition(newFrom, newState); else newTG.addTransition(newFrom, t.getName().getInverse(), newState); } } return newState; } }
private State<Role> copyState(final State<Role> oldState, final TransitionGraph<Role> newTG, final Map<State<Role>, State<Role>> newStates) { State<Role> newState = newStates.get(oldState); if (newState == null) { newState = newTG.newState(); newStates.put(oldState, newState); for (final Transition<Role> t : oldState.getTransitions()) { final State<Role> oldTo = t.getTo(); final State<Role> newFrom = copyState(oldTo, newTG, newStates); if (t.isEpsilon()) newTG.addTransition(newFrom, newState); else newTG.addTransition(newFrom, t.getName().getInverse(), newState); } } return newState; } }
private static Bool checkAllValuesClash(final KnowledgeBase kb, final ATermAppl av, final CachedNode root, final CachedNode otherRoot) { ATerm r = av.getArgument(0); if (r.getType() == ATerm.LIST) r = ((ATermList) r).getFirst(); final Role role = kb.getRole(r); if (null == role) // FIXME : null is unexpected. return Bool.UNKNOWN; if (!role.hasComplexSubRole()) { if (otherRoot.hasRNeighbor(role)) { if (_logger.isLoggable(Level.FINE)) _logger.fine(root + " has " + av + " " + otherRoot + " has " + role + " _neighbor"); return Bool.UNKNOWN; } } else { final TransitionGraph<Role> tg = role.getFSM(); for (final Transition<Role> t : tg.getInitialState().getTransitions()) if (otherRoot.hasRNeighbor(t.getName())) { if (_logger.isLoggable(Level.FINE)) _logger.fine(root + " has " + av + " " + otherRoot + " has " + t.getName() + " _neighbor"); return Bool.UNKNOWN; } } return null; }
private static Bool checkAllValuesClash(final KnowledgeBase kb, final ATermAppl av, final CachedNode root, final CachedNode otherRoot) { ATerm r = av.getArgument(0); if (r.getType() == ATerm.LIST) r = ((ATermList) r).getFirst(); final Role role = kb.getRole(r); if (null == role) // FIXME : null is unexpected. return Bool.UNKNOWN; if (!role.hasComplexSubRole()) { if (otherRoot.hasRNeighbor(role)) { if (_logger.isLoggable(Level.FINE)) _logger.fine(root + " has " + av + " " + otherRoot + " has " + role + " _neighbor"); return Bool.UNKNOWN; } } else { final TransitionGraph<Role> tg = role.getFSM(); for (final Transition<Role> t : tg.getInitialState().getTransitions()) if (otherRoot.hasRNeighbor(t.getName())) { if (_logger.isLoggable(Level.FINE)) _logger.fine(root + " has " + av + " " + otherRoot + " has " + t.getName() + " _neighbor"); return Bool.UNKNOWN; } } return null; }
for (final Transition<Role> t : st.getTransitions())
private static boolean isAllValuesSafe(final KnowledgeBase kb, final Individual parent, final Role role, final ATermAppl term) { final Role s = kb.getRole(term.getArgument(0)); if (!s.hasComplexSubRole()) { final ATermAppl c = (ATermAppl) term.getArgument(1); if (role.isSubRoleOf(s) && !parent.hasType(c)) return false; } else { final TransitionGraph<Role> tg = s.getFSM(); for (final Transition<Role> t : tg.getInitialState().getTransitions()) if (role.isSubRoleOf(t.getName())) return false; } return true; }
private static boolean isAllValuesSafe(final KnowledgeBase kb, final Individual parent, final Role role, final ATermAppl term) { final Role s = kb.getRole(term.getArgument(0)); if (!s.hasComplexSubRole()) { final ATermAppl c = (ATermAppl) term.getArgument(1); if (role.isSubRoleOf(s) && !parent.hasType(c)) return false; } else { final TransitionGraph<Role> tg = s.getFSM(); for (final Transition<Role> t : tg.getInitialState().getTransitions()) if (role.isSubRoleOf(t.getName())) return false; } return true; }