Package dk.brics.automaton

Examples of dk.brics.automaton.State


public class AutomatonOperation {


    public static Automaton makeAcceptAllOfLength(int length, int[] alphabet) {
        Automaton auto = new Automaton();
        State start = new State();
        State tmp = start;
        State last = start;

        for (int i = 0; i < length; i++) {
            last = new State();
            for (int k : alphabet) {
                tmp.addTransition(new Transition(FiniteAutomaton.getCharFromInt(k), last));
            }
            tmp = last;

        }
        last.setAccept(true);
        auto.setInitialState(start);
        return auto;
    }
View Full Code Here


    a.setInitialState(makeState());
    return a;
  }
 
  private State makeState() {
    State s = new State();
    if(contents != null) s.setAccept(true);
    for(Character c : next.keySet()) {
      State nextState = next.get(c).makeState();
      Transition t = new Transition(c, nextState);
      s.addTransition(t);
    }   
    return s;
  }
View Full Code Here

        String ret = tmp.toCVC3FormulaString(x);
        return ret;
    }

    public static Formula createFormula(Automaton A, int n) {
        State root = A.getInitialState();
        if (n==0) {
            if (root.isAccept()) {
                return new TrueFormula();
            } else {
                return new FalseFormula();
            }
        } else {
View Full Code Here

        IdentityHashMap<State, Formula> ret = new IdentityHashMap<State, Formula>();
        Formula collect = null;

        List<Transition> transitions = root.getSortedTransitions(false);
        for (Transition transition : transitions) {
            State next = transition.getDest();
            AndFormula tmp1 = new AndFormula(new RelConstant(i,transition.getMin(),">="), new RelConstant(i,transition.getMax(),"<="));
            Formula tmp2 = ret.get(next);
            if (tmp2 != null) {
                OrFormula tmp3 = new OrFormula(tmp2,tmp1);
                ret.put(next, tmp3);
            } else {
                ret.put(next,tmp1);
            }
        }
        if (i < n) {
            for (State next : ret.keySet()) {
                Formula suffix = createFormula(next, i + 1, n);
                if (suffix != null) {
                    Formula tmp4 = new AndFormula(ret.get(next), suffix);
                    if (collect == null) {
                        collect = tmp4;
                    } else {
                        collect = new OrFormula(collect, tmp4);
                    }
                }
            }
        } else {
            for (State next : ret.keySet()) {
                if (next.isAccept()) {
                    if (collect == null) {
                        collect = ret.get(next);
                    } else {
                        collect = new OrFormula(collect, ret.get(next));
                    }
View Full Code Here

    /**
     * Constructs automaton accepting strings with zero or more characters from this set.
     */
    public Automaton toAutomaton() {
        Automaton a = new Automaton();
        State s = a.getInitialState();
        s.setAccept(true);
        for (Interval v : intervals) {
            s.addTransition(new Transition(v.getMin(), v.getMax(), s));
        }
        return a;
    }
View Full Code Here

            a = new Automaton();

            // construct automaton states
            Map<MLFAState, State> statemap = new HashMap<MLFAState, State>();
            for (MLFAState q : reachable) {
                State ss = new State();
                statemap.put(q, ss);
                if (q == s) {
                    a.setInitialState(ss);
                }
                if (q == f) {
                    ss.setAccept(true);
                }
            }

            // add transitions
            final Set<StatePair> epsilons = new HashSet<StatePair>();
            for (MLFAState q : reachable) {
                for (MLFAEdge e : q.getEdges()) {
                    if (reachable.contains(e.getDestination())) {
                        final State qq = statemap.get(q);
                        final State pp = statemap.get(e.getDestination());
                        Automaton b = e.getTransition().visitBy(new TransitionVisitor<Automaton>() {

                            public Automaton visitAutomatonTransition(AutomatonTransition t) {
                                return t.getAutomaton().clone();
                            }
View Full Code Here

    private Set<State> findPostSet(Automaton b, Map<State, Set<State>> special_prevs) {
        Set<State> post = new HashSet<State>();
        TreeSet<State> pending = new TreeSet<State>();
        pending.addAll(b.getAcceptStates());
        while (!pending.isEmpty()) {
            State p = pending.first();
            pending.remove(p);
            post.add(p);
            Set<State> prevset = special_prevs.get(p);
            if (prevset != null) {
                for (State q : prevset) {
View Full Code Here

    private void findPrevs(Automaton b, Map<State, Set<State>> normal_prevs, Map<State, Set<State>> special_prevs) {
        for (State s : b.getStates()) {
            for (Transition t : s.getTransitions()) {
                char min = t.getMin();
                char max = t.getMax();
                State dest = t.getDest();
                if (min <= '\u0020') {
                    Set<State> prevset = special_prevs.get(dest);
                    if (prevset == null) {
                        prevset = new HashSet<State>();
                        special_prevs.put(dest, prevset);
View Full Code Here

        for (State s : b.getStates()) {
            Set<Transition> transitions = s.getTransitions();
            for (Transition t : new ArrayList<Transition>(transitions)) {
                char min = t.getMin();
                char max = t.getMax();
                State dest = t.getDest();
                if (min != Character.MIN_VALUE || max != Character.MAX_VALUE) {
                    transitions.remove(t);
                    for (int c = min; c <= max; c++) {
                      String up = String.valueOf((char)c).toUpperCase();
                      if (up.length() == 1) {
                        transitions.add(new Transition(Character.toUpperCase((char) c), dest));
                      } else {
                        // YES some characters translate to more than one character when turned upper case
                        // for example the German character "�" becomes "SS"
                        State lastState = s;
                        for (int i=0; i<up.length()-1; i++) {
                          char ch = up.charAt(i);
                          State state = new State();
                          lastState.addTransition(new Transition(ch, state));
                          lastState = state;
                        }
                        lastState.addTransition(new Transition(up.charAt(up.length()-1), dest));
                      }
View Full Code Here

     * @return resulting automaton
     */
    @Override
    public Automaton op(Automaton a) {
        Automaton b = a.clone();
        State accept = new State();
        accept.setAccept(true);
        Set<StatePair> epsilons = new HashSet<StatePair>();
        for (State s : b.getStates()) {
            epsilons.add(new StatePair(s, accept));
        }
        b.addEpsilons(epsilons);
View Full Code Here

TOP

Related Classes of dk.brics.automaton.State

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.