Skip to content

Commit

Permalink
- Added Transition Trigger to the statemachine simulator ui
Browse files Browse the repository at this point in the history
- Fixed bug that enabled transitions are not updated
- Fixed bug that buttons are not removed from simulator ui
 #1044
  • Loading branch information
maurpa committed Jan 17, 2022
1 parent d315ace commit d239e9d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public class StateMachineSimulationView extends ViewPart {


private static final int COL = 3;
private static final int WIDTH = 300;
private static final int WIDTH = 500;
private Button buttonExplicit;
private Button buttonLoadStateMachines;
Repository repository;
Expand Down Expand Up @@ -271,6 +271,8 @@ private void createOutputWindow(String type) {

}

private TableEditor transitionsEditors;

/**
*
* @param outputtable Table for the simulation result
Expand All @@ -290,7 +292,7 @@ private void createNewSimulationTrace(Table outputtable, GlobalState currentStat
stateitem.setText(new String[]{currentState.printState()});

for (Trans trans : currentState.getGlobalEnabledTrans()) {
final TableEditor transitionsEditors = new TableEditor(table);
transitionsEditors = new TableEditor(table);
TableItem nextitem = new TableItem(outputtable, SWT.NONE);
Button transitionButtons = new Button(outputtable, SWT.PUSH);
transitionButtons.setText(trans.prinTran());
Expand Down Expand Up @@ -323,8 +325,6 @@ public void widgetDefaultSelected(SelectionEvent e) {
}

}
swtAwtComposite.update();
swtAwtComposite.redraw();

}

Expand Down Expand Up @@ -358,6 +358,7 @@ public void widgetSelected(SelectionEvent e) {

GlobalState gs = simulator.initialSimulationComputation(sm);
simulationhistory = new PriorityQueue<String>();
simulationhistory.add("Initial State: " + gs.printState());
createNewSimulationTrace(outputtable, gs);

}
Expand Down Expand Up @@ -402,9 +403,12 @@ private void openSimulationHistoryExportShell() {
exporter.export(simulationhistory);
simulationhistory.clear();
outputtable.removeAll();
transitionsEditors.dispose();
break;
case SWT.NO:
simulationhistory.clear();
outputtable.removeAll();
transitionsEditors.dispose();
break;
case SWT.CANCEL:
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*******************************************************************************/
package de.dlr.sc.virsat.model.extension.statemachines.simulator;

import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand All @@ -33,40 +32,42 @@ public class StateMachineSimulator {
* @param d: name of gardStates
*/

private void updateMap(HashMap<String, HashMap<String, Set<String>>> map, String a, String b, String c) {
private void updateMap(HashMap<String, HashMap<String, HashMap<String, String>>> map, String a, String b, String c, String d) {
if (!map.containsKey(a)) {
HashMap<String, Set<String>> m = new HashMap<String, Set<String>>();
HashMap<String, HashMap<String, String>> m = new HashMap<String, HashMap<String, String>>();

Set<String> strSet = new HashSet<>(Arrays.asList(c));
// Add here a hAshmap with strings
HashMap<String, String> strSet = new HashMap<String, String>();
strSet.put(c, d);
m.put(b, strSet);
map.put(a, m);
} else {
if (!map.get(a).containsKey(b)) {
HashMap<String, Set<String>> m1 = new HashMap<String, Set<String>>();
HashMap<String, HashMap<String, String>> m1 = new HashMap<String, HashMap<String, String>>();

m1 = map.get(a);

Set<String> infStates = new HashSet<String>();
infStates.add(c);
HashMap<String, String> infStates = new HashMap<String, String>();
infStates.put(c, d);

m1.put(b, infStates);

map.put(a, m1);
} else {
HashMap<String, Set<String>> m1 = new HashMap<String, Set<String>>();
HashMap<String, HashMap<String, String>> m1 = new HashMap<String, HashMap<String, String>>();
m1 = map.get(a);
Set<String> infStates = new HashSet<String>();
HashMap<String, String> infStates = new HashMap<String, String>();
infStates = m1.get(b);
infStates.add(c);
infStates.put(c, d);
m1.put(b, infStates);
map.put(a, m1);

}
}
}

private HashMap<String, HashMap<String, Set<String>>> localEnabledTransitions = new HashMap<String, HashMap<String, Set<String>>>();
private HashMap<String, HashMap<String, Set<String>>> stateConstraints = new HashMap<String, HashMap<String, Set<String>>>();
private HashMap<String, HashMap<String, HashMap<String, String>>> localEnabledTransitions = new HashMap<String, HashMap<String, HashMap<String, String>>>();
private HashMap<String, HashMap<String, HashMap<String, String>>> stateConstraints = new HashMap<String, HashMap<String, HashMap<String, String>>>();
/**
* // this function must be called before running POR, it is used to compute
// enabled transitions for every local state
Expand All @@ -79,7 +80,7 @@ private void compLocalEnabledTrans(List<StateMachine> design) {

for (Transition transition : trans) {
updateMap(localEnabledTransitions, sm.getName(), transition.getStateFrom().getName(),
transition.getStateTo().getName());
transition.getStateTo().getName(), transition.getTrigger().getName());
}

}
Expand All @@ -92,7 +93,7 @@ private void compLocalEnabledTrans(List<StateMachine> design) {
private void getGlobalEnabledTrans(GlobalState gState) {
for (Map.Entry<String, String> smState : gState.smStates.entrySet()) {

Set<String> localEnabledStates = new HashSet<String>();
HashMap<String, String> localEnabledStates = new HashMap<String, String>();

if (localEnabledTransitions.containsKey(smState.getKey())
&& localEnabledTransitions.get(smState.getKey()).containsKey(smState.getValue())) {
Expand All @@ -103,14 +104,15 @@ private void getGlobalEnabledTrans(GlobalState gState) {
Set<String> strGlobalState = gState.statesToString();

if (!localEnabledStates.isEmpty()) {
for (String str : localEnabledStates) {

for (String str : localEnabledStates.keySet()) {

Set<String> conflictStates;

if (this.stateConstraints.containsKey(smState.getKey())
&& this.stateConstraints.get(smState.getKey()).containsKey(str)) {

conflictStates = this.stateConstraints.get(smState.getKey()).get(str);
conflictStates = this.stateConstraints.get(smState.getKey()).get(str).keySet();

Boolean ok = true;
for (String str1 : strGlobalState) {
Expand All @@ -121,13 +123,13 @@ private void getGlobalEnabledTrans(GlobalState gState) {
}

if (ok) {
Trans t = new Trans(smState.getKey(), smState.getValue(), str);
Trans t = new Trans(smState.getKey(), smState.getValue(), str, localEnabledStates.get(str));
gState.getGlobalEnabledTrans().add(t);

}

} else {
Trans t = new Trans(smState.getKey(), smState.getValue(), str);
Trans t = new Trans(smState.getKey(), smState.getValue(), str, localEnabledStates.get(str));
gState.getGlobalEnabledTrans().add(t);
}
}
Expand All @@ -145,10 +147,10 @@ private void compConstraints(List<StateMachine> design) {
for (AConstraint cs : cons) {
this.updateMap(stateConstraints, sm.getName(), cs.getStateConstraining().getName(),
cs.getStateInfluenced().getParentCaBeanOfClass(StateMachine.class).getName() + "."
+ cs.getStateInfluenced().getName());
+ cs.getStateInfluenced().getName(), "");
this.updateMap(stateConstraints,
cs.getStateInfluenced().getParentCaBeanOfClass(StateMachine.class).getName(),
cs.getStateInfluenced().getName(), sm.getName() + "." + cs.getStateConstraining().getName());
cs.getStateInfluenced().getName(), sm.getName() + "." + cs.getStateConstraining().getName(), "");
}
}

Expand Down Expand Up @@ -193,7 +195,7 @@ boolean isDependent(Trans t1, Trans t2) {

return this.stateConstraints.containsKey(t1.stateMachine)
&& this.stateConstraints.get(t1.stateMachine).containsKey(t1.destinationState)
&& this.stateConstraints.get(t1.stateMachine).get(t1.destinationState)
&& this.stateConstraints.get(t1.stateMachine).get(t1.destinationState).keySet()
.contains(t2.stateMachine + "." + t2.destinationState);
}

Expand All @@ -210,9 +212,9 @@ public Set<Trans> getNextTransitions(GlobalState s) {
Set<Trans> nextTrans = new HashSet<Trans>();
for (String sm : stateMachines) {
String localState = s.smStates.get(sm);
Set<String> nextStates = this.stateConstraints.get(sm).get(localState);
Set<String> nextStates = this.stateConstraints.get(sm).get(localState).keySet();
for (String str : nextStates) {
Trans t = new Trans(sm, localState, str);
Trans t = new Trans(sm, localState, str, " ");
nextTrans.add(t);
}
}
Expand Down Expand Up @@ -281,7 +283,9 @@ public GlobalState initialSimulationComputation(List<StateMachine> design) {
*/
public GlobalState nextTransition(GlobalState s, Trans t) {
s.setExecutedTran(t);
return executeTran(s, s.exeTran);
GlobalState gs = executeTran(s, s.exeTran);
this.getGlobalEnabledTrans(gs);
return gs;

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,23 @@ public class Trans {
String destinationState;
boolean isBacktracking = false;
boolean explored = false;
private String transitionTrigger;

Trans(String sm, String sState, String dState) {
Trans(String sm, String sState, String dState, String transitionTrigger) {
this.stateMachine = sm;
this.startState = sState;
this.destinationState = dState;
this.transitionTrigger = transitionTrigger;
explored = false;
}

Trans() {
this.stateMachine = "";
this.startState = "";
this.destinationState = "";


public Trans() {
}



@Override
public int hashCode() {
return super.hashCode();
Expand All @@ -49,7 +52,7 @@ public boolean equals(Object o) {
}

public String prinTran() {
String str = this.stateMachine + ": " + this.startState + " ---> " + this.destinationState;
String str = this.stateMachine + ": " + this.transitionTrigger + " " + this.startState + " -> " + this.destinationState;
return str;

}
Expand Down

0 comments on commit d239e9d

Please sign in to comment.