use of fr.lip6.move.gal.Not in project ITSTools by lip6.
the class TransitionsAbstractor method abstractStatements.
/**
* Abstract the Statements by removing those whose Support do not intersect with the specified Support toKeep.
*
* @param actions
* @param toKeep
*/
private static void abstractStatements(Transition transition, Support toKeep) {
EList<Statement> statements = transition.getActions();
List<Statement> statementsToDelete = new ArrayList<Statement>();
Logger log = Logger.getLogger("fr.lip6.move.gal");
for (Statement statement : statements) {
Support support = new Support();
SupportAnalyzer.computeSupport(statement, support);
if (!toKeep.intersects(support)) {
statementsToDelete.add(statement);
}
}
statements.removeAll(statementsToDelete);
log.fine("Abstracting GAL, removed " + statementsToDelete.size() + " statement(s) " + "from transition " + transition.getName());
}
use of fr.lip6.move.gal.Not in project ITSTools by lip6.
the class ITSPropertyCheckerAdapter method check.
@Override
public IResult check(Specification gal, Property property) {
if (property.getBody() instanceof SafetyProp) {
SafetyProp sbody = (SafetyProp) property.getBody();
// diagnose constant cases
if (sbody instanceof ReachableProp) {
if (sbody.getPredicate() instanceof True) {
return new CheckResult(true, true, new String[0]);
} else if (sbody.getPredicate() instanceof False) {
return new CheckResult(false, false, null);
}
} else if (sbody instanceof NeverProp) {
if (sbody.getPredicate() instanceof True) {
return new CheckResult(false, true, new String[0]);
} else if (sbody.getPredicate() instanceof False) {
return new CheckResult(true, false, null);
}
} else if (sbody instanceof InvariantProp) {
if (sbody.getPredicate() instanceof True) {
return new CheckResult(true, false, null);
} else if (sbody.getPredicate() instanceof False) {
return new CheckResult(false, true, new String[0]);
}
}
// get trace info and pass it as argument to ITS trace checker
BufferedReader in = null;
String[] results = new String[0];
launcher.setModel(gal);
launcher.setTrace("");
// diagnose
if (sbody instanceof ReachableProp) {
// could not find trace to state satisfying
launcher.setProperty(SerializationUtil.getText(sbody.getPredicate(), true));
} else if (sbody instanceof NeverProp) {
// could not find trace to state satisfying
launcher.setProperty("!(" + SerializationUtil.getText(sbody.getPredicate(), true) + ")");
} else if (sbody instanceof InvariantProp) {
// could not find counter example trace
launcher.setProperty("!(" + SerializationUtil.getText(sbody.getPredicate(), true) + ")");
}
IStatus status = launcher.run();
if (!status.isOK()) {
throw new RuntimeException("ITS tools raised an exception when treating model property " + property.getName());
}
try {
in = new BufferedReader(launcher.getResult());
String line;
while ((line = in.readLine()) != null) {
getLog().fine("read : " + line);
if (line.contains("This shortest transition sequence")) {
line = in.readLine();
results = line.split(", ");
// we got our results, stop parsing its-reach output
in.close();
return new CheckResult(true, true, results);
}
}
in.close();
// Not feasible !
return new CheckResult(false, false, null);
} catch (IOException ie) {
throw new RuntimeException("CEGAR procedure failed for " + property.getName() + " could not parse trace of its-tools.");
}
} else {
String msg = "Only safety properties are handled in CEGAR solution currently. Cannot handle " + property.getName();
Logger.getLogger("fr.lip6.move.gal").warning(msg);
throw new RuntimeException(msg);
}
}
use of fr.lip6.move.gal.Not in project ITSTools by lip6.
the class ExportToGAL method export.
/**
* Export a model to GAL formatted file
* @param model The model to export
* @param filePath The path of the destination file
* @param monitor A monitor to follow the export progression
* @throws ExtensionException Something wrong has happened.
*/
public final void export(IGraph model, String filePath, IProgressMonitor monitor) throws ExtensionException {
// Filename checks
if (filePath.equalsIgnoreCase("") || filePath == null) {
// $NON-NLS-1$
throw new ExtensionException("The filename is not correct. Please provide a valid filename");
}
int totalWork = model.getNodes().size() + model.getArcs().size();
monitor.beginTask("Export to GAL", totalWork);
String name = "model";
final GalFactory gf = GalFactory.eINSTANCE;
GALTypeDeclaration gal = gf.createGALTypeDeclaration();
gal.setName(name);
// now optional to specify transient
// Transient tr = gf.createTransient();
// False f = gf.createFalse();
// tr.setValue(f);
// gal.setTransient(tr);
Map<IVariable, ConstParameter> evarMap = new HashMap<IVariable, ConstParameter>();
Map<INode, Variable> varMap = new HashMap<INode, Variable>();
// nodes : each place gives rise to a variable
for (INode node : model.getNodes()) {
if ("place".equals(node.getNodeFormalism().getName())) {
Variable var = gf.createVariable();
var.setName(node.getAttribute("name").getValue());
var.setValue(toIntExpression(node.getAttribute("marking").getValue(), gal, evarMap));
gal.getVariables().add(var);
varMap.put(node, var);
}
}
// transition clocks
boolean isTimed = false;
for (INode node : model.getNodes()) {
if ("transition".equals(node.getNodeFormalism().getName())) {
IntExpression eft = eft(node, gal, evarMap);
IntExpression lft = lft(node, gal, evarMap);
if (hasClock(eft, lft)) {
isTimed = true;
Variable var = gf.createVariable();
var.setName(node.getAttribute("label").getValue() + ".clock");
var.setValue(constant(0));
gal.getVariables().add(var);
varMap.put(node, var);
}
if (isZero(lft)) {
// urgent ! It does not produce a clock variable, but it still means overall we must constrain time elapse.
isTimed = true;
}
}
}
// prepare the creation of the reset disabled transition
Label labReset = GF2.createLabel("reset");
Transition reset = gf.createTransition();
reset.setName("reset");
reset.setLabel(labReset);
reset.setGuard(gf.createTrue());
// prepare the creation of the elapse disabled transition
Label labElapse = GF2.createLabel("elapse");
Transition elapse = gf.createTransition();
elapse.setName("elapse");
elapse.setLabel(labElapse);
elapse.setGuard(gf.createTrue());
BooleanExpression canElapse = gf.createTrue();
List<Statement> elapseAct = new ArrayList<Statement>();
for (INode node : model.getNodes()) {
if ("transition".equals(node.getNodeFormalism().getName())) {
Transition t = gf.createTransition();
t.setName(node.getAttribute("label").getValue());
if ("public".equals(node.getAttribute("visibility").getValue())) {
Label lab = gf.createLabel();
lab.setName(node.getAttribute("label").getValue());
t.setLabel(lab);
}
// build elapse effect
IntExpression eft = eft(node, gal, evarMap);
IntExpression lft = lft(node, gal, evarMap);
BooleanExpression guard = computeGuard(node, gf, varMap, gal, evarMap);
if (!(eft instanceof Constant) || ((Constant) eft).getValue() != 0) {
BooleanExpression comp = GF2.createComparison(GF2.createVariableRef(varMap.get(node)), ComparisonOperators.GE, eft);
// createComparison(node, ComparisonOperators.GE, eft, gf, varMap);
// and clock >= eft to guard condition
t.setGuard(GF2.and(guard, comp));
} else {
t.setGuard(guard);
}
// build actions : first action is reset, then take tokens, then put tokens
for (IArc arc : node.getIncomingArcs()) {
String arcType = arc.getArcFormalism().getName();
if ("reset".equals(arcType)) {
// p= 0
t.getActions().add(GF2.createAssignVarConst(varMap.get(arc.getSource()), 0));
}
}
// build actions : then take tokens
for (IArc arc : node.getIncomingArcs()) {
String arcType = arc.getArcFormalism().getName();
if ("arc".equals(arcType)) {
// p -= valuation
IntExpression val;
IAttribute iaval = arc.getAttribute("valuation");
if (iaval != null) {
val = toIntExpression(iaval.getValue(), gal, evarMap);
} else {
val = constant(1);
}
Statement ass = decrementVar(arc.getSource(), val, gf, varMap);
t.getActions().add(ass);
}
}
// build actions : then put tokens
for (IArc arc : node.getOutgoingArcs()) {
String arcType = arc.getArcFormalism().getName();
if ("arc".equals(arcType)) {
IntExpression value;
IAttribute iaval = arc.getAttribute("valuation");
if (iaval != null) {
value = toIntExpression(iaval.getValue(), gal, evarMap);
} else {
value = constant(1);
}
// p= 0
Statement ass = incrementVar(arc.getTarget(), value, gf, varMap);
t.getActions().add(ass);
}
}
// handle time constraints : reset this clock after firing
if (isTimed) {
if (hasClock(eft, lft)) {
// p= 0
Statement ass = GF2.createAssignVarConst(varMap.get(node), 0);
t.getActions().add(ass);
// also add a term to resetDisabled
Ite ite = gf.createIte();
Not notGuard = gf.createNot();
BooleanExpression g = computeGuard(node, gf, varMap, gal, evarMap);
notGuard.setValue(g);
ite.setCond(notGuard);
Statement ass2 = GF2.createAssignVarConst(varMap.get(node), 0);
ite.getIfTrue().add(ass2);
reset.getActions().add(ite);
}
// reset other disabled transition clocks
// call(reset)
SelfCall call = gf.createSelfCall();
call.setLabel(labReset);
t.getActions().add(call);
if (isZero(eft) && isInf(lft)) {
// [0,inf[
// nop
} else if (isZero(eft) && isZero(lft)) {
// [0,0]
// no clock, abort elapse if enabled
Ite ite = gf.createIte();
BooleanExpression guardd = computeGuard(node, gf, varMap, gal, evarMap);
ite.setCond(guardd);
ite.getIfTrue().add(gf.createAbort());
elapse.getActions().add(ite);
// New condition on can elapse : transition is not enabled
Not not = gf.createNot();
not.setValue(EcoreUtil.copy(guardd));
if (EcoreUtil.equals(canElapse, gf.createTrue())) {
canElapse = not;
} else {
And and = gf.createAnd();
and.setLeft(canElapse);
and.setRight(not);
canElapse = and;
}
// no transition elapse effects, since no clock
} else if (isInf(lft)) {
// [a,inf[
// increment clock variable up to a.
Ite ite = gf.createIte();
And and = gf.createAnd();
and.setLeft(computeGuard(node, gf, varMap, gal, evarMap));
BooleanExpression comp = createComparison(node, ComparisonOperators.LT, eft, gf, varMap);
and.setRight(comp);
// condition is : enabled && clock < eft(t)
ite.setCond(and);
// effect if true is :
// clock= clock+1
Statement ass = incrementVar(node, constant(1), gf, varMap);
ite.getIfTrue().add(ass);
elapse.getActions().add(ite);
// No particular canelapse guard, since lft is infinite
// New effect if firing elapse : increment clock if enabled and less than a
elapseAct.add(EcoreUtil.copy(ite));
} else {
// [a,b]
// general case
// ite(enabled, ite(clock < lft, clock++, abort ), nop )
Ite ite = gf.createIte();
BooleanExpression guardd = computeGuard(node, gf, varMap, gal, evarMap);
ite.setCond(guardd);
Ite ite2 = gf.createIte();
BooleanExpression comp = createComparison(node, ComparisonOperators.LT, lft, gf, varMap);
// condition is : clock < lft(t)
ite2.setCond(comp);
// effect if true is :
// clock= clock+1
Statement ass = incrementVar(node, constant(1), gf, varMap);
ite2.getIfTrue().add(ass);
// effect if false is abort !
ite2.getIfFalse().add(gf.createAbort());
ite.getIfTrue().add(ite2);
elapse.getActions().add(ite);
// canelapse guard : ! enabled || clock < lft(t)
Not not = gf.createNot();
not.setValue(EcoreUtil.copy(guardd));
Or or = gf.createOr();
or.setLeft(not);
or.setRight(EcoreUtil.copy(comp));
if (EcoreUtil.equals(canElapse, gf.createTrue())) {
canElapse = or;
} else {
And and = gf.createAnd();
and.setLeft(canElapse);
and.setRight(or);
canElapse = and;
}
// elapse Effect : if (enabled) { clock++ }
Ite ite3 = gf.createIte();
ite3.setCond(EcoreUtil.copy(guardd));
ite3.getIfTrue().add(EcoreUtil.copy(ass));
elapseAct.add(ite3);
}
}
gal.getTransitions().add(t);
}
}
if (isTimed) {
if (isEssentialStates) {
Label lab = gf.createLabel();
lab.setName("succ");
boolean first = true;
for (Transition t : gal.getTransitions()) {
if (t.getLabel() == null) {
if (first) {
first = !first;
t.setLabel(lab);
} else {
t.setLabel(EcoreUtil.copy(lab));
}
}
}
Transition elEffect = gf.createTransition();
elEffect.setName("elapseEffect");
Label elEffLab = gf.createLabel();
elEffLab.setName("elapseEffect");
elEffect.setLabel(elEffLab);
elEffect.setGuard(canElapse);
elEffect.getActions().addAll(elapseAct);
gal.getTransitions().add(elEffect);
Transition id = gf.createTransition();
id.setName("id");
id.setGuard(gf.createTrue());
id.setLabel(EcoreUtil.copy(elEffLab));
gal.getTransitions().add(id);
Transition trel = gf.createTransition();
trel.setName("nextState");
trel.setGuard(gf.createTrue());
trel.setGuard(gf.createTrue());
Fixpoint fix = gf.createFixpoint();
SelfCall callEl = gf.createSelfCall();
callEl.setLabel(elEffLab);
fix.getActions().add(callEl);
trel.getActions().add(fix);
SelfCall call = gf.createSelfCall();
call.setLabel(lab);
trel.getActions().add(call);
gal.getTransitions().add(trel);
gal.getTransitions().add(reset);
} else {
gal.getTransitions().add(elapse);
gal.getTransitions().add(reset);
}
}
try {
Simplifier.simplify(gal);
Specification spec = gf.createSpecification();
spec.getTypes().add(gal);
SerializationUtil.systemToFile(spec, filePath);
} catch (FileNotFoundException fe) {
Logger.getLogger("fr.lip6.move.coloane.core").warning("Echec lors de la création du fichier : Nom de fichier invalide");
throw new ExtensionException("Invalid filename !");
} catch (IOException ioe) {
Logger.getLogger("fr.lip6.move.coloane.core").warning("Erreur lors de l'écriture dans le fichier");
throw new ExtensionException("Write error :" + ioe.getMessage());
} catch (Exception e) {
e.printStackTrace();
throw new ExtensionException("Unexpected exception when building GAL file :" + e.getMessage());
}
monitor.done();
}
use of fr.lip6.move.gal.Not in project ITSTools by lip6.
the class ExportToCompositeITS method export.
/**
* Export a model to ITS XML formatted file
* @param model The model to export
* @param filePath The path of the destination file
* @param monitor A monitor to follow the export progression
* @throws ExtensionException Something wrong has happened.
*/
public final void export(IGraph model, String filePath, IProgressMonitor monitor) throws ExtensionException {
FileOutputStream writer;
// Filename checks
if (filePath == null || "".equals(filePath)) {
// $NON-NLS-1$
throw new ExtensionException("The filename is not correct. Please provide a valid filename");
}
int totalWork = model.getNodes().size() + model.getArcs().size();
monitor.beginTask("Export to ITS", totalWork);
try {
// File creation
// $NON-NLS-1$
writer = new FileOutputStream(new File(filePath));
BufferedWriter sb = new BufferedWriter(new OutputStreamWriter(writer));
// Translation
// write header
sb.append("<?xml version='1.0' encoding='UTF-8'?>\n");
// TODO : add a schema reference
sb.append("<model>\n");
// First export nodes: should be only instances and synchronizations
for (INode node : model.getNodes()) {
sb.append("<");
sb.append(node.getNodeFormalism().getName());
sb.append(" ");
// Add the id
sb.append("id='" + Integer.toString(node.getId()) + "' ");
for (IAttribute a : node.getAttributes()) {
sb.append(a.getName());
sb.append("='");
sb.append(a.getValue());
sb.append("' ");
}
sb.append("/>\n");
}
// Now export the arcs
for (IArc arc : model.getArcs()) {
sb.append("<");
sb.append(arc.getArcFormalism().getName());
sb.append(" ");
INode src = arc.getSource();
INode dest = arc.getTarget();
// check the arc is in the right direction
if (!"instance".equals(src.getNodeFormalism().getName())) {
// swap src and dest if not
INode tmp = src;
src = dest;
dest = tmp;
}
// now print source and dest id
sb.append(" instance='" + src.getId() + "' ");
sb.append(" synchronization='" + dest.getId() + "' ");
// add the labels (and any other attributes ??)
for (IAttribute a : arc.getAttributes()) {
sb.append(a.getName());
sb.append("='");
sb.append(a.getValue());
sb.append("' ");
}
sb.append("/>\n");
}
// Now export the size if it exists (scalar and circular set)
IAttribute sizeatt = model.getAttribute("size");
if (sizeatt != null && sizeatt.getValue() != null) {
sb.append("<size size='");
sb.append(sizeatt.getValue());
sb.append("' ");
sb.append("/>\n");
}
sb.append("</model>\n");
sb.newLine();
// End of writing : clean & close
sb.flush();
writer.flush();
sb.close();
writer.close();
} catch (FileNotFoundException fe) {
Logger.getLogger("fr.lip6.move.coloane.core").warning("Echec lors de la création du fichier : Nom de fichier invalide");
throw new ExtensionException("Invalid filename !");
} catch (IOException ioe) {
Logger.getLogger("fr.lip6.move.coloane.core").warning("Erreur lors de l'écriture dans le fichier");
throw new ExtensionException("Write error :" + ioe.getMessage());
}
monitor.done();
}
use of fr.lip6.move.gal.Not in project ITSTools by lip6.
the class ImportFromImpl method importFrom.
/**
* Import a Romeo State class graph or Zone based graph file into a Graph object
* @param filePath The location of the file to be imported
* @param formalism The formalism (since CAMI file does not define the model formalism)
* @param monitor A monitor to follow the operation progress
* @return The resulting model {@link IGraph}
* @throws ExtensionException Something went wrong
*/
public final IGraph importFrom(String filePath, IFormalism formalism, IProgressMonitor monitor) throws ExtensionException {
IGraph model = null;
// //$NON-NLS-1$
LOGGER.finer("Creation du fichier...");
IPath path = new Path(filePath);
IFileStore file = EFS.getLocalFileSystem().getStore(path);
model = ModelLoader.loadFromXML(file.toURI(), formalism);
return model;
}
Aggregations