Skip to content

Commit af55952

Browse files
Merge branch 'master' into vincenzo
2 parents 9f8b2c0 + 2c81ae5 commit af55952

File tree

3 files changed

+27
-16
lines changed

3 files changed

+27
-16
lines changed

automata/automaton0005

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
q0 q1 q2 q3 q4 q5 q6 q7 q8
2+
q0
3+
q8
4+
q0 q1 '
5+
q1 q2 y
6+
q2 q3 :
7+
q3 q4 =
8+
q4 q5 1
9+
q5 q6 ;
10+
q6 q7 $
11+
q7 q8 '

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

+14-14
Original file line numberDiff line numberDiff line change
@@ -1241,10 +1241,11 @@ public void hopcroftremoveUnreachableStates(){
12411241
HashSet<State> newStates = (HashSet<State>) this.getInitialStates().clone();
12421242
HashSet<Transition> transitionstoRemove = new HashSet<>();
12431243
HashSet<State> temp;
1244+
final HashSet<State> emptySet = new HashSet<>(Collections.<State>emptySet());
12441245

12451246

12461247
do{
1247-
temp = new HashSet<>(Collections.<State>emptySet());
1248+
temp = (HashSet<State>) emptySet.clone();
12481249
for(State s : newStates){
12491250
for(String a : getAlphabet(this)){
12501251
State to = getOutgoingStatefromTransitionSymbol(s, a);
@@ -1346,20 +1347,18 @@ public void hopcroftMinimize(){
13461347

13471348
HashSet<State> A = new HashSet<>();
13481349
HashSet<State> X;
1349-
LinkedList<HashSet<State>> listYs;
1350-
Random r=new Random();
1350+
List<HashSet<State>> listYs;
1351+
Random r = new Random();
13511352

13521353
while(!W.isEmpty()){
13531354
//choose and remove a set A from W
1354-
do{
1355-
for(HashSet<State> s : W){
1356-
int insert=r.nextInt(2);
1357-
if(insert > 0)
1358-
A = s;
1359-
else break;
1360-
}
1361-
W.remove(A);
1362-
}while(A.isEmpty());
1355+
1356+
for(HashSet<State> s : W){
1357+
A = s;
1358+
if(r.nextInt(2) == 0)
1359+
break;
1360+
}
1361+
W.remove(A);
13631362

13641363
for(String c : getAlphabet(this)){
13651364
// select a X set for which a transition in c leads to a state in A
@@ -1414,7 +1413,6 @@ private void constructMinimumAutomatonFromPartition(HashSet<HashSet<State>> P) {
14141413
isInitialState = isInitialState || s.isInitialState();
14151414
isFinalState = isFinalState || s.isFinalState();
14161415

1417-
14181416
}
14191417

14201418
State mergedMacroState = new State(macroStatename, isInitialState, isFinalState);
@@ -1440,7 +1438,9 @@ private void constructMinimumAutomatonFromPartition(HashSet<HashSet<State>> P) {
14401438
this.states = new HashSet<State>(automatonStateBinding.values());
14411439
this.delta = newDelta;
14421440

1443-
this.adjacencyList = this.computeAdjacencyList();
1441+
for(State s : states){
1442+
updateAdjacencyList(s);
1443+
}
14441444
}
14451445

14461446
/**

src/it/univr/fsm/main/Main.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ public static void main(String[] args) {
6969
System.out.println("a:");
7070
System.out.println(a);
7171
a.hopcroftMinimize();
72-
System.out.println(a);
73-
*/
72+
System.out.println(a);*/
73+
7474

7575
Automaton a3 = Automaton.loadAutomata("/Users/andreaperazzoli/Desktop/SPY/java-fsm-library/automata/" + "automaton0003");
7676
System.out.println("a3:");

0 commit comments

Comments
 (0)