I use if()
sentences to control some transition, but it does not work. How can I solve these problems? I use the EasyFSM library to implement the simulation based on Finite State Machine.
I attach my own code. This is only the part of my code that has the problem I want to solve.
I think that there is no syntax error, but when I run the program there is no transition (the f.ProcessFSM(~)
does not work) and there are only IDLE
states (it is the first state of the FSM.)
How can I solve this problem?
FSM f = new FSM("C://Users//losin//Desktop//file//PMC.xml", new FSMAction() {
@Override
public boolean action(String curState, String message, String nextState, Object args) {
return true;
}
});
for(int j=0; j <10 ; j++) {
list.add(f.getCurrentState().toString());
if(f.getCurrentState().toString()=="IDLE") {
double rnd1 = Math.random();
if(list.contains("PROCESS_COMPLIETED")==true) {
if(rnd1 < 0.05) {
f.ProcessFSM("FAIL");
} else if(rnd1 < 0.15) {
f.ProcessFSM("CLEAN");
} else {
f.ProcessFSM("LOAD");
}
} else {
if(rnd1 < 0.05) {
f.ProcessFSM("FAIL");
} else {
f.ProcessFSM("LOAD");
}
}
} else if(f.getCurrentState().toString()=="PREPARE") {
f.ProcessFSM("PROCESS_START");
} else if(f.getCurrentState().toString()=="PROCESS") {
double rnd2 = Math.random();
if(rnd2 < 0.05) {
f.ProcessFSM("FAIL");
} else {
f.ProcessFSM("COMPLETE");
}
} else if(f.getCurrentState().toString()=="PROCESS_COMPLETED") {
f.ProcessFSM("UNLOAD");
} else if(f.getCurrentState().toString()=="FAILURE") {
f.ProcessFSM("FIX");
} else {
f.ProcessFSM("CLEAN_END");
}
}
CSVUtils.writeLine(writer, list);
writer.flush();
writer.close();