Commit b89999da authored by apvrille's avatar apvrille
Browse files

Update on Test sequences generation

parent 81212c81
......@@ -687,7 +687,7 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe
}
public void makeRefusalGraph(RG inputGraph) {
JFrameRefusalGraph jfm = new JFrameRefusalGraph(frame, this, "Refusal Graph Construction", inputGraph);
JFrameRefusalGraph jfm = new JFrameRefusalGraph(frame, this, "Test Sequences Construction", inputGraph);
//jfm.setSize(900, 700);
GraphicLib.centerOnParent(jfm, 900, 700);
jfm.setVisible(true);
......
......@@ -42,7 +42,7 @@
package ui.graph;
import myutil.Conversion;
import myutil.GraphAlgorithms;
import myutil.*;
import myutil.TraceManager;
import java.io.BufferedReader;
......@@ -1371,6 +1371,64 @@ public class AUTGraph implements myutil.Graph {
}
public AUTGraph makeTestSequencesFromRefusalGraph() {
ArrayList<AUTState> newStates = new ArrayList<AUTState>();
ArrayList<AUTTransition> newTransitions = new ArrayList<AUTTransition>();
AUTState firstState = new AUTState(0);
newStates.add(firstState);
// Take all termination states of the refusal graph and get the shortest path
// from the first state to this termination state
// Add this path as a new path of the new graph
computeStates();
DijkstraState[] allPaths = GraphAlgorithms.ShortestPathFrom(this, 0);
for(AUTState state: states) {
if (state.isTerminationState()) {
int[] path = allPaths[state.id].path;
if (path != null) {
AUTState currentStateN = firstState;
// We create a corresponding path in the new graph.
String s = "";
for(int j=0; j<path.length; j++) {
s += path[j] + " ";
}
TraceManager.addDev("path=" + s);
for(int i=1; i<path.length; i++) {
AUTState currentState = states.get(path[i-1]);
AUTState nextState = states.get(path[i]);
AUTTransition tr = currentState.getTransitionTo(nextState.id);
TraceManager.addDev("Looking for transition");
if (tr != null) {
// We need to create the destination state
AUTState newDest = new AUTState(newStates.size());
newStates.add(newDest);
AUTTransition newTr = new AUTTransition(currentStateN.id, tr.transition, newDest.id);
newTransitions.add(newTr);
TraceManager.addDev("Adding transition:" + newTr);
currentStateN = newDest;
} else {
TraceManager.addDev(" -> null transitions");
}
}
}
}
}
// Making the graph
AUTGraph testGraph = new AUTGraph(newStates, newTransitions);
return testGraph;
}
private void printConfiguration(AUTPartition _part, AUTSplitter _w) {
TraceManager.addDev("P={" + _part.toString() + "}");
TraceManager.addDev("W={" + _w.toString() + "}");
......
......@@ -84,6 +84,19 @@ public class AUTState implements Comparable<AUTState> {
return outTransitions.size();
}
public boolean isTerminationState() {
return (outTransitions.size() == 0);
}
public AUTTransition getTransitionTo(int destination) {
for(AUTTransition tr: outTransitions) {
if (tr.destination == destination) {
return tr;
}
}
return null;
}
public boolean hasTransitionTo(int destination) {
for(AUTTransition aut1 : outTransitions) {
if (aut1.destination == destination) {
......
......@@ -95,4 +95,26 @@ public class RG {
return ret;
}
public RG generateTestSequences() {
if (graph == null) {
if (data == null){
return null;
}
graph = new AUTGraph();
graph.buildGraph(data);
}
TraceManager.addDev("Making Test sequences");
AUTGraph testSequencesGraph = graph.makeTestSequencesFromRefusalGraph();
//TraceManager.addDev("Null graph?");
if (testSequencesGraph == null) {
TraceManager.addDev("Null graph...");
return null;
}
RG ret = new RG(name+"_Test");
ret.graph = testSequencesGraph;
return ret;
}
}
......@@ -193,7 +193,7 @@ public class JDiagramTree extends javax.swing.JTree implements ActionListener, M
jmiShow.addActionListener(this);
jmiMinimize = new JMenuItem("Minimize");
jmiMinimize.addActionListener(this);
jmiRefusalGraph = new JMenuItem("Make Refusal Graph");
jmiRefusalGraph = new JMenuItem("Make Test Sequences");
jmiRefusalGraph.addActionListener(this);
jmiRemove = new JMenuItem("Remove from tree");
jmiRemove.addActionListener(this);
......
......@@ -74,6 +74,7 @@ public class JFrameRefusalGraph extends javax.swing.JFrame implements ActionList
private MainGUI mgui;
private RG rg;
private RG newRG;
private RG newRGTS;
protected Thread t;
......@@ -123,7 +124,7 @@ public class JFrameRefusalGraph extends javax.swing.JFrame implements ActionList
jta.setEditable(false);
jta.setMargin(new Insets(10, 10, 10, 10));
jta.setTabSize(3);
jta.append("Select actions and then, click on 'start' to start minimization\n");
jta.append("Select actions and then, click on 'start' to generate test sequences\n");
Font f = new Font("Courrier", Font.BOLD, 12);
jta.setFont(f);
JScrollPane jsp = new JScrollPane(jta, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
......@@ -226,6 +227,13 @@ public class JFrameRefusalGraph extends javax.swing.JFrame implements ActionList
newRG.nbOfTransitions = newRG.graph.getTransitions().size();
mgui.addRG(newRG);
jta.append("\nRefusal Graph: " + newRG.nbOfStates + " states, " + newRG.nbOfTransitions + " transitions\n");
jta.append("Generating test sequences\n");
newRGTS = newRG.generateTestSequences();
newRGTS.nbOfStates = newRGTS.graph.getNbOfStates();
newRGTS.nbOfTransitions = newRGTS.graph.getTransitions().size();
mgui.addRG(newRGTS);
jta.append("\nTest sequences: " + newRGTS.nbOfStates + " states, " + newRGTS.nbOfTransitions + " transitions\n");
} else {
jta.append("\nCould not build Refusal Graph\n");
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment