Skip to content
Snippets Groups Projects
Commit ee531881 authored by hansen's avatar hansen
Browse files

optimized deterministic check

parent 62a0cd45
Branches
No related tags found
No related merge requests found
package de.tlc4b.ltl; package de.tlc4b.ltl;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import de.be4.classicalb.core.parser.node.APredicateParseUnit; import de.be4.classicalb.core.parser.node.APredicateParseUnit;
...@@ -183,20 +185,55 @@ public class LTLFormulaPrinter extends DepthFirstAdapter { ...@@ -183,20 +185,55 @@ public class LTLFormulaPrinter extends DepthFirstAdapter {
@Override @Override
public void caseADetLtl(ADetLtl node) { public void caseADetLtl(ADetLtl node) {
List<PActions> copy = new ArrayList<PActions>(node.getArgs()); List<PActions> copy = new ArrayList<PActions>(node.getArgs());
for (int i = 0; i < copy.size(); i++) { LinkedHashMap<String, Node> operations = ltlFormulaVisitor
AOpActions action1 = (AOpActions) copy.get(i); .getMachineContext().getOperations();
for (int j = i + 1; j < copy.size(); j++) { if (copy.size() > 1) {
if (!(i == 0 && j == 1)) { tlaPrinter.moduleStringAppend("(");
for (int i = 0; i < copy.size() - 1; i++) {
if (i != 0) {
tlaPrinter.moduleStringAppend(" /\\ "); tlaPrinter.moduleStringAppend(" /\\ ");
} }
tlaPrinter.moduleStringAppend("\\neg(ENABLED("); AOpActions action1 = (AOpActions) copy.get(i);
tlaPrinter.moduleStringAppend(action1.getOperation().getText()); String action1Name = action1.getOperation().getText();
tlaPrinter.moduleStringAppend(") /\\ ENABLED("); Node op1 = operations.get(action1Name);
tlaPrinter.moduleStringAppend("(ENABLED(");
tlaPrinter.printOperationCall(op1);
tlaPrinter.moduleStringAppend(") => \\neg(");
for (int j = i + 1; j < copy.size(); j++) {
AOpActions action2 = (AOpActions) copy.get(j); AOpActions action2 = (AOpActions) copy.get(j);
tlaPrinter.moduleStringAppend(action2.getOperation().getText()); String action2Name = action2.getOperation().getText();
Node op2 = operations.get(action2Name);
if (j != i + 1) {
tlaPrinter.moduleStringAppend(" \\/ ");
}
tlaPrinter.moduleStringAppend("ENABLED(");
tlaPrinter.printOperationCall(op2);
tlaPrinter.moduleStringAppend(")");
}
tlaPrinter.moduleStringAppend("))"); tlaPrinter.moduleStringAppend("))");
} }
tlaPrinter.moduleStringAppend(")");
} else { // only the single operation should be enabled
AOpActions action1 = (AOpActions) copy.get(0);
String action1Name = action1.getOperation().getText();
Node op1 = operations.get(action1Name);
tlaPrinter.moduleStringAppend("(ENABLED(");
tlaPrinter.printOperationCall(op1);
tlaPrinter.moduleStringAppend(") => \\neg(");
ArrayList<Node> remainingOperations = new ArrayList<Node>(operations.values());
remainingOperations.remove(op1);
for (int i = 0; i < remainingOperations.size(); i++) {
if (i != 0) {
tlaPrinter.moduleStringAppend(" \\/ ");
}
Node op2 = remainingOperations.get(i);
tlaPrinter.moduleStringAppend("ENABLED(");
tlaPrinter.printOperationCall(op2);
tlaPrinter.moduleStringAppend(")");
}
tlaPrinter.moduleStringAppend("))");
} }
} }
@Override @Override
......
...@@ -310,4 +310,8 @@ public class LTLFormulaVisitor extends DepthFirstAdapter { ...@@ -310,4 +310,8 @@ public class LTLFormulaVisitor extends DepthFirstAdapter {
outAAndLtl(node); outAAndLtl(node);
} }
protected MachineContext getMachineContext(){
return this.machineContext;
}
} }
...@@ -523,7 +523,7 @@ public class TLAPrinter extends DepthFirstAdapter { ...@@ -523,7 +523,7 @@ public class TLAPrinter extends DepthFirstAdapter {
moduleStringAppend("\n"); moduleStringAppend("\n");
} }
private void printOperationCall(Node operation) { public void printOperationCall(Node operation) {
AOperation op = (AOperation) operation; AOperation op = (AOperation) operation;
List<PExpression> newList = new ArrayList<PExpression>(); List<PExpression> newList = new ArrayList<PExpression>();
newList.addAll(op.getParameters()); newList.addAll(op.getParameters());
...@@ -2914,5 +2914,4 @@ public class TLAPrinter extends DepthFirstAdapter { ...@@ -2914,5 +2914,4 @@ public class TLAPrinter extends DepthFirstAdapter {
public TLAModule getTLAModule(){ public TLAModule getTLAModule(){
return this.tlaModule; return this.tlaModule;
} }
} }
...@@ -182,10 +182,20 @@ public class LtlFormulaTest { ...@@ -182,10 +182,20 @@ public class LtlFormulaTest {
String machine = "MACHINE test\n" String machine = "MACHINE test\n"
+ "OPERATIONS foo = skip; bar = skip; bazz = skip\n" + "OPERATIONS foo = skip; bar = skip; bazz = skip\n"
+ "END"; + "END";
String expected = "\\neg(ENABLED(foo) /\\ ENABLED(bar)) /\\ \\neg(ENABLED(foo) /\\ ENABLED(bazz)) /\\ \\neg(ENABLED(bar) /\\ ENABLED(bazz))"; String expected = "((ENABLED(foo) => \\neg(ENABLED(bar) \\/ ENABLED(bazz))) /\\ (ENABLED(bar) => \\neg(ENABLED(bazz))))";
compareLTLFormula(expected, machine, "deterministic(foo,bar,bazz)"); compareLTLFormula(expected, machine, "deterministic(foo,bar,bazz)");
} }
@Test
public void testDeterministicOnly() throws Exception {
String machine = "MACHINE test\n"
+ "OPERATIONS foo = skip; bar = skip; bazz = skip\n"
+ "END";
String expected = "(ENABLED(foo) => \\neg(ENABLED(bar) \\/ ENABLED(bazz)))";
compareLTLFormula(expected, machine, "deterministic(foo)");
}
@Test @Test
public void testDeadlock() throws Exception { public void testDeadlock() throws Exception {
String machine = "MACHINE test\n" String machine = "MACHINE test\n"
......
MACHINE CounterLTL MACHINE CounterLTL
DEFINITIONS DEFINITIONS
ASSERT_LTL_1 == "F {x = 10}" ASSERT_LTL_1 == "F {x = 10}";
ASSERT_LTL_2 == "G(not(deadlock))";
ASSERT_LTL_3 == "G(deterministic(Inc,Reset))";
VARIABLES x VARIABLES x
INVARIANT INVARIANT
x : 1..10 x : 1..10
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment