Skip to content

Commit 540adc6

Browse files
Hopcroft algorithm: checks isDeterministic before determinization, demerge after hopcroft minimization #7
1 parent af55952 commit 540adc6

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/it/univr/fsm/machine/Automaton.java

+17-4
Original file line numberDiff line numberDiff line change
@@ -979,10 +979,10 @@ public Automaton determinize() {
979979
HashSet<Transition> dGamma = new HashSet<Transition>();
980980
HashSet<State> newStates = new HashSet<State>();
981981

982-
dStates.put(epsilonClosure(initialState), false);
982+
dStates.put(epsilonClosure(this.getInitialState()), false);
983983
HashSet<State> T;
984984

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

987987
newStates.add(newInitialState);
988988

@@ -1202,7 +1202,7 @@ public Automaton removeUnreachableStates() {
12021202
*/
12031203
public void minimize() {
12041204

1205-
this.reverse();
1205+
/*this.reverse();
12061206
Automaton a = this.determinize();
12071207
a = a.removeUnreachableStates();
12081208
a.reverse();
@@ -1212,6 +1212,13 @@ public void minimize() {
12121212
this.initialState = a.initialState;
12131213
this.delta = a.delta;
12141214
this.states = a.states;
1215+
this.adjacencyList = this.computeAdjacencyList();*/
1216+
this.hopcroftMinimize();
1217+
1218+
Automaton a = this.deMerge(++initChar);
1219+
this.initialState = a.initialState;
1220+
this.states = a.states;
1221+
this.delta = a.delta;
12151222
this.adjacencyList = this.computeAdjacencyList();
12161223
}
12171224

@@ -1333,7 +1340,13 @@ private HashSet<State> setSubtraction(HashSet<State> first, HashSet<State> secon
13331340
}
13341341

13351342
public void hopcroftMinimize(){
1336-
this.determinize();
1343+
if (!isDeterministic(this)) {
1344+
Automaton a = this.determinize();
1345+
this.initialState = a.initialState;
1346+
this.delta = a.delta;
1347+
this.states = a.states;
1348+
}
1349+
13371350
this.hopcroftremoveUnreachableStates();
13381351

13391352
// the partition P

0 commit comments

Comments
 (0)