Skip to content

Commit

Permalink
Hopcroft algorithm: checks isDeterministic before determinization, de…
Browse files Browse the repository at this point in the history
…merge after hopcroft minimization #7
  • Loading branch information
VincenzoArceri committed Dec 11, 2016
1 parent af55952 commit 540adc6
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/it/univr/fsm/machine/Automaton.java
Original file line number Diff line number Diff line change
Expand Up @@ -979,10 +979,10 @@ public Automaton determinize() {
HashSet<Transition> dGamma = new HashSet<Transition>();
HashSet<State> newStates = new HashSet<State>();

dStates.put(epsilonClosure(initialState), false);
dStates.put(epsilonClosure(this.getInitialState()), false);
HashSet<State> T;

State newInitialState = new State(createName(epsilonClosure(initialState)), true, isPartitionFinalState(epsilonClosure(initialState)));
State newInitialState = new State(createName(epsilonClosure(this.getInitialState())), true, isPartitionFinalState(epsilonClosure(this.getInitialState())));

newStates.add(newInitialState);

Expand Down Expand Up @@ -1202,7 +1202,7 @@ public Automaton removeUnreachableStates() {
*/
public void minimize() {

this.reverse();
/*this.reverse();
Automaton a = this.determinize();
a = a.removeUnreachableStates();
a.reverse();
Expand All @@ -1212,6 +1212,13 @@ public void minimize() {
this.initialState = a.initialState;
this.delta = a.delta;
this.states = a.states;
this.adjacencyList = this.computeAdjacencyList();*/
this.hopcroftMinimize();

Automaton a = this.deMerge(++initChar);
this.initialState = a.initialState;
this.states = a.states;
this.delta = a.delta;
this.adjacencyList = this.computeAdjacencyList();
}

Expand Down Expand Up @@ -1333,7 +1340,13 @@ private HashSet<State> setSubtraction(HashSet<State> first, HashSet<State> secon
}

public void hopcroftMinimize(){
this.determinize();
if (!isDeterministic(this)) {
Automaton a = this.determinize();
this.initialState = a.initialState;
this.delta = a.delta;
this.states = a.states;
}

this.hopcroftremoveUnreachableStates();

// the partition P
Expand Down

0 comments on commit 540adc6

Please sign in to comment.