Commit d763ee5a authored by Ludovic Apvrille's avatar Ludovic Apvrille

Update on TTool package and adding probabilities to avatar transitions. Prob...

Update on TTool package and adding probabilities to avatar transitions. Prob are still not working in automatd simulation mode e.g. next breakpoint
parent d447a037
......@@ -38,7 +38,7 @@
<property name="caretWidth" class="java.lang.Integer" />
</properties>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="false" project-jdk-name="1.7" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="false" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build" />
</component>
</project>
\ No newline at end of file
......@@ -417,6 +417,7 @@ $(BASERELEASE:.tgz=.tar): $(JTTOOL_BINARY) $(TTOOL_BINARY) $(LAUNCHER_BINARY) $(
@mkdir -p $(TTOOL_TARGET)/executablecode/src
@mkdir -p $(TTOOL_TARGET)/executablecode/generated_src
@mkdir -p $(TTOOL_TARGET)/executablecode/example
@cp $(TTOOL_EXECUTABLECODE)/LICENSE* $(TTOOL_TARGET)/executablecode/
@cp $(TTOOL_EXECUTABLECODE)/Makefile $(TTOOL_TARGET)/executablecode/
@cp $(TTOOL_EXECUTABLECODE)/Makefile.defs $(TTOOL_TARGET)/executablecode/
@cp $(TTOOL_EXECUTABLECODE)/Makefile.forsoclib $(TTOOL_TARGET)/executablecode/
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -126,6 +126,28 @@ public class AvatarSyntaxChecker {
}
public static int isAValidProbabilityExpr(AvatarSpecification _as, AvatarStateMachineOwner _ab, String _expr) {
if (_expr.trim().length() == 0) {
return 0;
}
String tmp = _expr.replaceAll(" ", "").trim();
double prob = 0.5;
try {
prob = new Double(tmp).doubleValue();
} catch (Exception e) {
return -1;
}
if ((prob <0) || (prob > 1)) {
return -1;
}
return 0;
}
public static int isAValidBoolExpr(AvatarSpecification _as, AvatarStateMachineOwner _ab, String _expr) {
if (_expr.trim().length() == 0) {
return 0;
......
......@@ -98,6 +98,10 @@ public class AvatarTransition extends AvatarStateMachineElement {
public void setProbability(double _probability) {
probability = _probability;
}
public double getProbability() {
return probability;
}
public void addGuard(String _g) {
AvatarGuard guard = AvatarGuard.createFromString(this.block, _g);
......@@ -300,6 +304,7 @@ public class AvatarTransition extends AvatarStateMachineElement {
at.setComputes(getMinCompute(), getMaxCompute());
at.setDelays(getMinDelay(), getMaxDelay());
at.setProbability(getProbability());
return at;
}
......
......@@ -100,6 +100,9 @@ public class AvatarSimulationPendingTransaction {
// Lost
public boolean isLost;
// Probability of this transaction
public double probability = 0.5;
public AvatarSimulationPendingTransaction() {
......
......@@ -405,11 +405,15 @@ public class SpecConfigTTool {
* @author Fabien Tessier
*/
public static boolean checkAndCreateAVATARCodeDir(String s) throws FileException {
//TraceManager.addDev("Trying to create the dir:" + s);
File f = new File(s);
try {
if (!f.exists())
if (!f.mkdir())
if (!f.exists()) {
//TraceManager.addDev("Does not exist");
if (!f.mkdir()) {
return false;
}
}
if (!s.equals(ConfigurationTTool.AVATARExecutableCodeDirectory)) {
File make = new File(ConfigurationTTool.AVATARExecutableCodeDirectory + "Makefile");
File defs = new File(ConfigurationTTool.AVATARExecutableCodeDirectory + "Makefile.defs");
......
......@@ -1902,6 +1902,19 @@ public class AvatarDesignPanelTranslator {
if (tmp1 != null && tmp2 != null)
at.setComputes(tmp1, tmp2);
// Probability
tmp1 = asmdco.getProbability ();
if ((tmp1 != null) && (tmp1.length()>0)) {
error = AvatarSyntaxChecker.isAValidProbabilityExpr(_as, _ab, tmp1);
if (error < 0) {
this.makeError(error, tdp, _ab, tgc, "probability ", tmp1);
tmp1 = null;
}
if (tmp1 != null) {
at.setProbability(new Double(tmp1).doubleValue());
}
}
// Actions
for(String s: asmdco.getActions())
if (s.trim().length() > 0) {
......
/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille
*
*
* ludovic.apvrille AT enst.fr
*
*
* This software is a computer program whose purpose is to allow the
* edition of TURTLE analysis, design and deployment diagrams, to
* allow the generation of RT-LOTOS or Java code from this diagram,
* and at last to allow the analysis of formal validation traces
* obtained from external tools, e.g. RTL from LAAS-CNRS and CADP
* from INRIA Rhone-Alpes.
*
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
......@@ -31,14 +31,12 @@
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*/
package ui.avatarinteractivesimulation;
import ui.util.IconManager;
......@@ -50,12 +48,13 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
* Class AvatarInteractiveSimulationActions
*
* Creation: 21/01/2011
* @version 1.0 21/01/2011
* @author Ludovic APVRILLE
* @see ui.TGComponent
* Class AvatarInteractiveSimulationActions
* <p>
* Creation: 21/01/2011
*
* @author Ludovic APVRILLE
* @version 1.0 21/01/2011
* @see ui.TGComponent
*/
public class AvatarInteractiveSimulationActions extends AbstractAction {
// Actions
......@@ -107,7 +106,7 @@ public class AvatarInteractiveSimulationActions extends AbstractAction {
public static final int NB_ACTION = 36;
private static final TAction [] actions = new TAction[NB_ACTION];
private static final TAction[] actions = new TAction[NB_ACTION];
private EventListenerList listeners;
......@@ -116,13 +115,12 @@ public class AvatarInteractiveSimulationActions extends AbstractAction {
public static final String LARGE_ICON = "LargeIcon";
public AvatarInteractiveSimulationActions(int id) {
if (actions[0] == null) {
init();
}
if (actions[id] == null) {
return ;
return;
}
putValue(Action.NAME, actions[id].NAME);
......@@ -193,40 +191,40 @@ public class AvatarInteractiveSimulationActions extends AbstractAction {
actions[ACT_ADD_LATENCY] = new TAction("add-latency-command", "Add latency", IconManager.imgic75, IconManager.imgic75, "Add latency", "Add latency checkpoint", '0');
}
public String getActionCommand() {
return (String)getValue(Action.ACTION_COMMAND_KEY);
public String getActionCommand() {
return (String) getValue(Action.ACTION_COMMAND_KEY);
}
public String getShortDescription() {
return (String)getValue(Action.SHORT_DESCRIPTION);
public String getShortDescription() {
return (String) getValue(Action.SHORT_DESCRIPTION);
}
public String getLongDescription() {
return (String)getValue(Action.LONG_DESCRIPTION);
public String getLongDescription() {
return (String) getValue(Action.LONG_DESCRIPTION);
}
public void actionPerformed(ActionEvent evt) {
public void actionPerformed(ActionEvent evt) {
//System.out.println("Action performed");
if (listeners != null) {
Object[] listenerList = listeners.getListenerList();
// Recreate the ActionEvent and stuff the value of the ACTION_COMMAND_KEY
ActionEvent e = new ActionEvent(evt.getSource(), evt.getID(),
(String)getValue(Action.ACTION_COMMAND_KEY));
for (int i = 0; i <= listenerList.length-2; i += 2) {
((ActionListener)listenerList[i+1]).actionPerformed(e);
(String) getValue(Action.ACTION_COMMAND_KEY));
for (int i = 0; i <= listenerList.length - 2; i += 2) {
((ActionListener) listenerList[i + 1]).actionPerformed(e);
}
}
}
public void addActionListener(ActionListener l) {
public void addActionListener(ActionListener l) {
if (listeners == null) {
listeners = new EventListenerList();
}
listeners.add(ActionListener.class, l);
}
public void removeActionListener(ActionListener l) {
public void removeActionListener(ActionListener l) {
if (listeners == null) {
return;
}
......
......@@ -326,8 +326,36 @@ public class JFrameAvatarInteractiveSimulation extends JFrame implements Avatar
selectedComponentForTransaction2 = null;
if (ll != null) {
listPendingTransactions.setListData(ll);
int random = (int)(Math.floor((Math.random()*ll.size())));
listPendingTransactions.setSelectedIndex(random);
//int random = (int)(Math.floor((Math.random()*ll.size())));
//listPendingTransactions.setSelectedIndex(random);
// Use probabilities
double sumProb = 0.0;
for (AvatarSimulationPendingTransaction pt: ll) {
sumProb += pt.probability;
}
double rand2 = Math.random() * sumProb;
TraceManager.addDev("Nb of pending:" + ll.size() + " total prob=" + sumProb + " rand=" + rand2);
double prob = 0.0;
int index = 0;
for (AvatarSimulationPendingTransaction pt: ll) {
prob += pt.probability;
TraceManager.addDev("rand=" + rand2 + " prob=" + prob + " pt.probability=" + pt.probability);
if (rand2 < prob) {
listPendingTransactions.setSelectedIndex(index);
break;
}
index ++;
}
} else {
listPendingTransactions.setListData(new Vector<AvatarSimulationPendingTransaction>());
}
......
/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille
*
*
* ludovic.apvrille AT enst.fr
*
*
* This software is a computer program whose purpose is to allow the
* edition of TURTLE analysis, design and deployment diagrams, to
* allow the generation of RT-LOTOS or Java code from this diagram,
* and at last to allow the analysis of formal validation traces
* obtained from external tools, e.g. RTL from LAAS-CNRS and CADP
* from INRIA Rhone-Alpes.
*
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
......@@ -31,14 +31,12 @@
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*/
package ui.avatarsmd;
import myutil.GraphicLib;
......@@ -51,23 +49,24 @@ import java.awt.geom.Point2D;
import java.util.Vector;
/**
* Class AvatarSMDConnector
* Basic connector with a full arrow at the end. Used in state machine
* Creation: 06/04/2010
* @version 1.0 06/04/2010
* @author Ludovic APVRILLE
* Class AvatarSMDConnector
* Basic connector with a full arrow at the end. Used in state machine
* Creation: 06/04/2010
*
* @author Ludovic APVRILLE
* @version 1.0 06/04/2010
*/
public class AvatarSMDConnector extends TGConnectorWithCommentConnectionPoints {
public class AvatarSMDConnector extends TGConnectorWithCommentConnectionPoints {
protected int arrowLength = 10;
//protected AvatarSMDTransitionInfo myTransitionInfo;
public AvatarSMDConnector(int _x, int _y, int _minX, int _minY, int _maxX, int _maxY, boolean _pos, TGComponent _father, TDiagramPanel _tdp, TGConnectingPoint _p1, TGConnectingPoint _p2, Vector<Point> _listPoint) {
super(_x, _y, _minX, _minY, _maxX, _maxY, _pos, _father, _tdp, _p1, _p2, _listPoint);
super(_x, _y, _minX, _minY, _maxX, _maxY, _pos, _father, _tdp, _p1, _p2, _listPoint);
//nbInternalTGComponent = 1;
//tgcomponent = new TGComponent[nbInternalTGComponent];
AvatarSMDTransitionInfo tgc = new AvatarSMDTransitionInfo((_p1.getX()+_p2.getX())/2, (_p1.getY()+_p2.getY())/2, tdp.getMinX(), tdp.getMaxX(), tdp.getMinY(), tdp.getMaxY(), false, this, _tdp);
AvatarSMDTransitionInfo tgc = new AvatarSMDTransitionInfo((_p1.getX() + _p2.getX()) / 2, (_p1.getY() + _p2.getY()) / 2, tdp.getMinX(), tdp.getMaxX(), tdp.getMinY(), tdp.getMaxY(), false, this, _tdp);
tgc.setValue("");
tgc.setName("List of all parameters of an Avatar SMD transition");
tgc.setMoveWithFather(false);
......@@ -111,20 +110,22 @@ public class AvatarSMDConnector extends TGConnectorWithCommentConnectionPoints
}*/
public void setTransitionInfo(String guard, String action){
AvatarSMDTransitionInfo tgc = (AvatarSMDTransitionInfo) getInternalTGComponent(0);
if (!guard.isEmpty()){
tgc.setGuard(guard);
}
if (!action.isEmpty()){
tgc.addAction(action);
}
}
public void setTransitionTime(String minDelay, String maxDelay, String minCompute, String maxCompute){
AvatarSMDTransitionInfo tgc = (AvatarSMDTransitionInfo) getInternalTGComponent(0);
tgc.setTimes(minDelay, maxDelay, minCompute, maxCompute);
}
protected void drawLastSegment(Graphics g, int x1, int y1, int x2, int y2){
public void setTransitionInfo(String guard, String action) {
AvatarSMDTransitionInfo tgc = (AvatarSMDTransitionInfo) getInternalTGComponent(0);
if (!guard.isEmpty()) {
tgc.setGuard(guard);
}
if (!action.isEmpty()) {
tgc.addAction(action);
}
}
public void setTransitionTime(String minDelay, String maxDelay, String minCompute, String maxCompute) {
AvatarSMDTransitionInfo tgc = (AvatarSMDTransitionInfo) getInternalTGComponent(0);
tgc.setTimes(minDelay, maxDelay, minCompute, maxCompute);
}
protected void drawLastSegment(Graphics g, int x1, int y1, int x2, int y2) {
if (Point2D.distance(x1, y1, x2, y2) < GraphicLib.longueur * 1.5) {
g.drawLine(x1, y1, x2, y2);
} else {
......@@ -133,10 +134,10 @@ public class AvatarSMDConnector extends TGConnectorWithCommentConnectionPoints
}
public boolean editOndoubleClick(JFrame frame) {
AvatarSMDTransitionInfo info = getAvatarSMDTransitionInfo();
if (info == null) {
return false;
}
AvatarSMDTransitionInfo info = getAvatarSMDTransitionInfo();
if (info == null) {
return false;
}
return info.editOndoubleClick(frame);
}
......@@ -145,9 +146,9 @@ public class AvatarSMDConnector extends TGConnectorWithCommentConnectionPoints
}
public AvatarSMDTransitionInfo getAvatarSMDTransitionInfo() {
for(int i=0; i<tgcomponent.length; i++) {
for (int i = 0; i < tgcomponent.length; i++) {
if (tgcomponent[i] instanceof AvatarSMDTransitionInfo) {
return (AvatarSMDTransitionInfo)(tgcomponent[i]);
return (AvatarSMDTransitionInfo) (tgcomponent[i]);
}
}
return null;
......@@ -201,6 +202,12 @@ public class AvatarSMDConnector extends TGConnectorWithCommentConnectionPoints
return getAvatarSMDTransitionInfo().getComputeMaxDelay();
}
public String getProbability() {
return getAvatarSMDTransitionInfo().getProbability();
}
public String getFilesToInclude() {
return getAvatarSMDTransitionInfo().getFilesToInclude();
......
......@@ -64,7 +64,7 @@ import java.util.Vector;
public class JDialogAvatarTransition extends JDialogBase implements ActionListener {
private Vector<String> actions;
private String guard, afterMin, afterMax, computeMin, computeMax;
private String guard, afterMin, afterMax, computeMin, computeMax, probability;
private LinkedList<TAttribute> myAttributes;
private LinkedList<AvatarMethod> myMethods;
private Vector<String> allElements, insertElements;
......@@ -78,7 +78,7 @@ public class JDialogAvatarTransition extends JDialogBase implements ActionListen
private JPanel panel2;
// Panel1
private JTextField guardT, afterMinT, afterMaxT, computeMinT, computeMaxT;
private JTextField guardT, afterMinT, afterMaxT, computeMinT, computeMaxT, probabilityT;
private JTextArea actionsT;
private JComboBox<String> elements;
private JButton insertElement;
......@@ -89,7 +89,10 @@ public class JDialogAvatarTransition extends JDialogBase implements ActionListen
/** Creates new form */
// arrayDelay: [0] -> minDelay ; [1] -> maxDelay
public JDialogAvatarTransition(Frame _f, String _title, String _guard, String _afterMin, String _afterMax, String _computeMin, String _computeMax, Vector<String> _actions, LinkedList<TAttribute> _myAttributes, LinkedList<AvatarMethod> _myMethods, String[] _filesToInclude, String[] _codeToInclude) {
public JDialogAvatarTransition(Frame _f, String _title, String _guard, String _afterMin, String _afterMax,
String _computeMin, String _computeMax, Vector<String> _actions,
LinkedList<TAttribute> _myAttributes, LinkedList<AvatarMethod> _myMethods,
String[] _filesToInclude, String[] _codeToInclude, String _probability) {
super(_f, _title, true);
......@@ -99,6 +102,7 @@ public class JDialogAvatarTransition extends JDialogBase implements ActionListen
computeMin = _computeMin;
computeMax = _computeMax;
actions = _actions;
probability = _probability;
myAttributes = _myAttributes;
myMethods = _myMethods;
......@@ -185,7 +189,7 @@ public class JDialogAvatarTransition extends JDialogBase implements ActionListen
panel1.add(new JLabel(")"), c1);
// Compute
c1.gridwidth = 1;
/*c1.gridwidth = 1;
c1.gridheight = 1;
c1.weighty = 1.0;
c1.weightx = 1.0;
......@@ -196,8 +200,19 @@ public class JDialogAvatarTransition extends JDialogBase implements ActionListen
computeMaxT = new JTextField(computeMax, 10);
panel1.add(computeMaxT, c1);
c1.gridwidth = GridBagConstraints.REMAINDER; //end row
panel1.add(new JLabel(")"), c1);
panel1.add(new JLabel(")"), c1);*/
// probability
c1.weighty = 1.0;
c1.weightx = 1.0;
c1.gridwidth = 1;
c1.gridheight = 1;
c1.fill = GridBagConstraints.BOTH;
c1.gridheight = 1;
panel1.add(new JLabel("probability in [0...1] = "), c1);
c1.gridwidth = GridBagConstraints.REMAINDER; //end row
probabilityT = new JTextField(probability);
panel1.add(probabilityT, c1);
// actions
......@@ -359,13 +374,24 @@ public class JDialogAvatarTransition extends JDialogBase implements ActionListen
}
public String getComputeMin() {
return computeMinT.getText();
if (computeMinT == null) {
return "";
}
return computeMinT.getText();
}
public String getComputeMax() {
return computeMaxT.getText();
if (computeMaxT == null) {
return "";
}
return computeMaxT.getText();
}
public String getProbability() {
return probabilityT.getText();
}
public boolean hasBeenCancelled() {
return cancelled;
}
......
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