- * This function prints the zone as a guard, not a CDD or DBM.
+ * This function prints the zone as an expression, not a CDD or DBM.
*
*
* Since left.getInvariant() is equal to right.getInvariant(),
@@ -52,7 +52,7 @@ public void setNode(GraphNode node) {
public String prettyPrint() {
return String.format("(%s %s) [ %s ]",
left.getLocation(), right.getLocation(),
- left.getInvariant().getGuard().prettyPrint());
+ left.getInvariant().getExpression().prettyPrint());
}
@Override
diff --git a/src/logic/Transition.java b/src/logic/Transition.java
index 02f7c31c..9a6e4d4a 100644
--- a/src/logic/Transition.java
+++ b/src/logic/Transition.java
@@ -58,7 +58,7 @@ public List getEdges() {
return move.getEdges();
}
- public Guard getGuards(List relevantClocks ) {
+ public Expression getGuards(List relevantClocks ) {
return move.getGuards( relevantClocks);
}
diff --git a/src/models/AndExpression.java b/src/models/AndExpression.java
new file mode 100644
index 00000000..c9e2b2e2
--- /dev/null
+++ b/src/models/AndExpression.java
@@ -0,0 +1,126 @@
+package models;
+
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+
+import java.util.*;
+import java.util.stream.Collectors;
+
+public class AndExpression extends Expression {
+ private List expressions;
+
+ public AndExpression(List expressions) {
+ this.expressions = expressions;
+
+ /* If any of the expressions are AndExpressions themselves,
+ * then we can decompose their expressions to be contained in this */
+ List worklist = this.expressions
+ .stream()
+ .filter(expr -> expr instanceof AndExpression)
+ .map(expr -> (AndExpression) expr)
+ .collect(Collectors.toList());
+ while (!worklist.isEmpty()) {
+ AndExpression current = worklist.get(0);
+ worklist.remove(0);
+
+ for (Expression expression : current.expressions) {
+ if (expression instanceof AndExpression) {
+ worklist.add((AndExpression) expression);
+ }
+ this.expressions.add(expression);
+ }
+
+ this.expressions.remove(current);
+ }
+
+ /* If the AndExpression contains a FalseExpression,
+ * then remove all expressions and just have a single
+ * FalseExpression as it will always be false. */
+ boolean hasFalseExpr = this.expressions.stream().anyMatch(expr -> expr instanceof FalseExpression);
+ if (hasFalseExpr) {
+ /* We just know that there is at least one FalseExpression for this
+ * reason we clear all expressions as it handle multiple FalseExpression
+ * then we just add a FalseExpression to account for all of them.
+ * If we left it empty then it would be interpreted as a tautology. */
+ this.expressions.clear();
+ this.expressions.add(new FalseExpression());
+ }
+
+ // Remove all true expressions
+ this.expressions = this.expressions.stream().filter(expr -> !(expr instanceof TrueExpression)).collect(Collectors.toList());
+
+ // If empty then it is a tautology
+ if (this.expressions.size() == 0) {
+ this.expressions.add(new TrueExpression());
+ }
+ }
+
+ public AndExpression(List... expressions) {
+ this(Lists.newArrayList(Iterables.concat(expressions)));
+ }
+
+ public AndExpression(Expression... expressions) {
+ this(Arrays.asList(expressions));
+ }
+
+ public AndExpression(AndExpression copy, List newClocks, List oldClocks, List newBVs, List oldBVs) {
+ // As this is the copy-constructor we need to create new instances of the expressions
+ this(copy.expressions.stream().map(expr ->
+ expr.copy(newClocks, oldClocks, newBVs, oldBVs)
+ ).collect(Collectors.toList()));
+ }
+
+ public List getExpressions() {
+ return expressions;
+ }
+
+ @Override
+ int getMaxConstant(Clock clock) {
+ int max = 0;
+ for (Expression expression : expressions) {
+ max = Math.max(max, expression.getMaxConstant(clock));
+ }
+ return max;
+ }
+
+ @Override
+ Expression copy(List newClocks, List oldClocks, List newBVs, List oldBVs) {
+ return new AndExpression(
+ this, newClocks, oldClocks, newBVs, oldBVs
+ );
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (!(obj instanceof AndExpression)) {
+ return false;
+ }
+
+ AndExpression other = (AndExpression) obj;
+ return Arrays.equals(expressions.toArray(), other.expressions.toArray());
+ }
+
+ @Override
+ public String toString() {
+ if (expressions.size() == 1) {
+ return expressions.get(0).toString();
+ }
+
+ return "(" +
+ expressions.stream().map(Expression::toString).collect(Collectors.joining(" && "))
+ + ")";
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(expressions);
+ }
+
+ @Override
+ public String prettyPrint() {
+ return Expression.compositePrettyPrint(expressions, "&&");
+ }
+}
diff --git a/src/models/AndGuard.java b/src/models/AndGuard.java
deleted file mode 100644
index e7544d5a..00000000
--- a/src/models/AndGuard.java
+++ /dev/null
@@ -1,126 +0,0 @@
-package models;
-
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
-
-import java.util.*;
-import java.util.stream.Collectors;
-
-public class AndGuard extends Guard {
- private List guards;
-
- public AndGuard(List guards) {
- this.guards = guards;
-
- /* If any of the guards are AndGuards themselves,
- * then we can decompose their guards to be contained in this */
- List worklist = this.guards
- .stream()
- .filter(guard -> guard instanceof AndGuard)
- .map(guard -> (AndGuard) guard)
- .collect(Collectors.toList());
- while (!worklist.isEmpty()) {
- AndGuard current = worklist.get(0);
- worklist.remove(0);
-
- for (Guard guard : current.guards) {
- if (guard instanceof AndGuard) {
- worklist.add((AndGuard) guard);
- }
- this.guards.add(guard);
- }
-
- this.guards.remove(current);
- }
-
- /* If the AndGuard contains a FalseGuard,
- * then remove all guards and just have a single
- * FalseGuard as it will always be false. */
- boolean hasFalseGuard = this.guards.stream().anyMatch(guard -> guard instanceof FalseGuard);
- if (hasFalseGuard) {
- /* We just know that there is at least one FalseGuard for this
- * reason we clear all guard as it handle multiple FalseGuards
- * then we just add a FalseGuard to account for all of them.
- * If we left it empty then it would be interpreted as a tautology. */
- this.guards.clear();
- this.guards.add(new FalseGuard());
- }
-
- // Remove all ture guards
- this.guards = this.guards.stream().filter(guard -> !(guard instanceof TrueGuard)).collect(Collectors.toList());
-
- // If empty then it is a tautology
- if (this.guards.size() == 0) {
- this.guards.add(new TrueGuard());
- }
- }
-
- public AndGuard(List... guards) {
- this(Lists.newArrayList(Iterables.concat(guards)));
- }
-
- public AndGuard(Guard... guards) {
- this(Arrays.asList(guards));
- }
-
- public AndGuard(AndGuard copy, List newClocks, List oldClocks, List newBVs, List oldBVs) {
- // As this is the copy-constructor we need to create new instances of the guards
- this(copy.guards.stream().map(guard ->
- guard.copy(newClocks, oldClocks, newBVs, oldBVs)
- ).collect(Collectors.toList()));
- }
-
- public List getGuards() {
- return guards;
- }
-
- @Override
- int getMaxConstant(Clock clock) {
- int max = 0;
- for (Guard guard : guards) {
- max = Math.max(max, guard.getMaxConstant(clock));
- }
- return max;
- }
-
- @Override
- Guard copy(List newClocks, List oldClocks, List newBVs, List oldBVs) {
- return new AndGuard(
- this, newClocks, oldClocks, newBVs, oldBVs
- );
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!(obj instanceof AndGuard)) {
- return false;
- }
-
- AndGuard other = (AndGuard) obj;
- return Arrays.equals(guards.toArray(), other.guards.toArray());
- }
-
- @Override
- public String toString() {
- if (guards.size() == 1) {
- return guards.get(0).toString();
- }
-
- return "(" +
- guards.stream().map(Guard::toString).collect(Collectors.joining(" && "))
- + ")";
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(guards);
- }
-
- @Override
- public String prettyPrint() {
- return Guard.compositePrettyPrint(guards, "&&");
- }
-}
diff --git a/src/models/Automaton.java b/src/models/Automaton.java
index 7be83c7b..6bb1074f 100644
--- a/src/models/Automaton.java
+++ b/src/models/Automaton.java
@@ -182,7 +182,7 @@ public HashMap getMaxBoundsForAllClocks() {
private List getEdgesFromLocation(Location loc) {
if (loc.isUniversal()) {
return actions.stream()
- .map(action -> new Edge(loc, loc, action, inputAct.contains(action), new TrueGuard(), new ArrayList<>()))
+ .map(action -> new Edge(loc, loc, action, inputAct.contains(action), new TrueExpression(), new ArrayList<>()))
.collect(Collectors.toList());
}
return edges.stream().filter(edge -> edge.getSource().equals(loc)).collect(Collectors.toList());
@@ -263,7 +263,7 @@ public void makeInputEnabled() {
}
if (resCDD.isNotFalse()) {
- Edge newEdge = new Edge(loc, loc, input, true, resCDD.getGuard(getClocks()), new ArrayList<>());
+ Edge newEdge = new Edge(loc, loc, input, true, resCDD.getExpression(getClocks()), new ArrayList<>());
getEdges().add(newEdge);
}
}
@@ -278,10 +278,10 @@ public void addTargetInvariantToEdges() {
boolean initialisedCdd = CDD.tryInit(clocks, BVs);
for (Edge edge : getEdges()) {
- CDD targetCDD = new CDD(edge.getTarget().getInvariantGuard());
+ CDD targetCDD = new CDD(edge.getTarget().getInvariant());
CDD past = targetCDD.transitionBack(edge);
if (!past.equiv(CDD.cddTrue()))
- edge.setGuard(past.conjunction(edge.getGuardCDD()).getGuard(getClocks()));
+ edge.setGuard(past.conjunction(edge.getGuardCDD()).getExpression(getClocks()));
}
if (initialisedCdd) {
diff --git a/src/models/BoolGuard.java b/src/models/BoolExpression.java
similarity index 67%
rename from src/models/BoolGuard.java
rename to src/models/BoolExpression.java
index b2524173..c6619047 100644
--- a/src/models/BoolGuard.java
+++ b/src/models/BoolExpression.java
@@ -2,27 +2,27 @@
import java.util.*;
-public class BoolGuard extends Guard {
+public class BoolExpression extends Expression {
private final BoolVar var;
private final Relation relation;
private final boolean value;
- public BoolGuard(BoolVar var, Relation relation, boolean value) {
+ public BoolExpression(BoolVar var, Relation relation, boolean value) {
// These are the only relation types allowed
if (relation != Relation.EQUAL && relation != Relation.NOT_EQUAL) {
- throw new IllegalArgumentException("The relation of the clock guard is invalid");
+ throw new IllegalArgumentException("The relation of the clock expression is invalid");
}
this.var = var;
this.relation = relation;
this.value = value;
}
- public BoolGuard(BoolVar var, String comparator, boolean value)
+ public BoolExpression(BoolVar var, String comparator, boolean value)
throws NoSuchElementException {
this(var, Relation.fromString(comparator), value);
}
- public BoolGuard(BoolGuard copy, List newBVs, List oldBVs)
+ public BoolExpression(BoolExpression copy, List newBVs, List oldBVs)
throws IndexOutOfBoundsException, NoSuchElementException {
this(newBVs.get(oldBVs.indexOf(copy.getVar())), copy.relation, copy.value);
}
@@ -35,14 +35,14 @@ public boolean getValue() {
return value;
}
- public BoolGuard negate() {
+ public BoolExpression negate() {
switch (relation) {
case EQUAL:
- return new BoolGuard(var, Relation.NOT_EQUAL, value);
+ return new BoolExpression(var, Relation.NOT_EQUAL, value);
case NOT_EQUAL:
- return new BoolGuard(var, Relation.EQUAL, value);
+ return new BoolExpression(var, Relation.EQUAL, value);
}
- throw new IllegalStateException("The relation of the boolean guard is invalid");
+ throw new IllegalStateException("The relation of the boolean expression is invalid");
}
@Override
@@ -51,8 +51,8 @@ int getMaxConstant(Clock clock) {
}
@Override
- Guard copy(List newClocks, List oldClocks, List newBVs, List oldBVs) {
- return new BoolGuard(
+ Expression copy(List newClocks, List oldClocks, List newBVs, List oldBVs) {
+ return new BoolExpression(
this, newBVs, oldBVs
);
}
@@ -62,11 +62,11 @@ public boolean equals(Object obj) {
if (this == obj) {
return true;
}
- if (!(obj instanceof BoolGuard)) {
+ if (!(obj instanceof BoolExpression)) {
return false;
}
- BoolGuard other = (BoolGuard) obj;
+ BoolExpression other = (BoolExpression) obj;
return var.equals(other.var) &&
relation == other.relation &&
diff --git a/src/models/CDD.java b/src/models/CDD.java
index ad31ad33..03db7f75 100644
--- a/src/models/CDD.java
+++ b/src/models/CDD.java
@@ -13,7 +13,7 @@
public class CDD {
private long pointer;
- private Guard guard;
+ private Expression expression;
private boolean isGuardDirty;
private CddExtractionResult extraction;
@@ -42,35 +42,35 @@ public CDD(long pointer) {
setDirty();
}
- public CDD(Guard guard)
+ public CDD(Expression expression)
throws IllegalArgumentException {
CDD cdd;
- if (guard instanceof FalseGuard) {
+ if (expression instanceof FalseExpression) {
cdd = cddFalse();
- } else if (guard instanceof TrueGuard) {
+ } else if (expression instanceof TrueExpression) {
cdd = cddTrue();
- } else if (guard instanceof ClockGuard) {
+ } else if (expression instanceof ClockExpression) {
Zone zone = new Zone(numClocks, true);
zone.init();
- zone.buildConstraintsForGuard((ClockGuard) guard, clocks);
+ zone.buildConstraintsForGuard((ClockExpression) expression, clocks);
cdd = CDD.createFromDbm(zone.getDbm(), numClocks);
- } else if (guard instanceof BoolGuard) {
- cdd = create((BoolGuard) guard);
- } else if (guard instanceof AndGuard) {
+ } else if (expression instanceof BoolExpression) {
+ cdd = create((BoolExpression) expression);
+ } else if (expression instanceof AndExpression) {
cdd = cddTrue();
- for (Guard g : ((AndGuard) guard).getGuards()) {
+ for (Expression g : ((AndExpression) expression).getExpressions()) {
cdd = cdd.conjunction(new CDD(g));
}
- } else if (guard instanceof OrGuard) {
+ } else if (expression instanceof OrExpression) {
cdd = cddFalse();
- for (Guard g : ((OrGuard) guard).getGuards()) {
+ for (Expression g : ((OrExpression) expression).getExpressions()) {
cdd = cdd.disjunction(new CDD(g));
}
} else {
throw new IllegalArgumentException("Guard instance is not supported");
}
this.pointer = cdd.pointer;
- this.guard = guard;
+ this.expression = expression;
}
private void setDirty() {
@@ -78,35 +78,35 @@ private void setDirty() {
isExtractionDirty = true;
}
- public Guard getGuard(List relevantClocks) {
+ public Expression getExpression(List relevantClocks) {
if (isGuardDirty) {
- guard = isBDD() ? toBoolGuards() : toClockGuards(relevantClocks);
+ expression = isBDD() ? toBoolExpression() : toClockGuards(relevantClocks);
isGuardDirty = false;
}
- return guard;
+ return expression;
}
- public Guard getGuard() {
- return getGuard(clocks);
+ public Expression getExpression() {
+ return getExpression(clocks);
}
- private Guard toClockGuards(List relevantClocks)
+ private Expression toClockGuards(List relevantClocks)
throws IllegalArgumentException {
if (isBDD()) {
throw new IllegalArgumentException("CDD is a BDD");
}
if (isFalse()) {
- return new FalseGuard();
+ return new FalseExpression();
}
if (isTrue()) {
- return new TrueGuard();
+ return new TrueExpression();
}
CDD copy = hardCopy();
- List orParts = new ArrayList<>();
+ List orParts = new ArrayList<>();
while (!copy.isTerminal()) {
copy.reduce().removeNegative();
CddExtractionResult extraction = copy.extract();
@@ -115,63 +115,63 @@ private Guard toClockGuards(List relevantClocks)
Zone zone = new Zone(extraction.getDbm());
CDD bdd = extraction.getBddPart();
- List andParts = new ArrayList<>();
+ List andParts = new ArrayList<>();
// Adds normal guards and diagonal constraints
andParts.add(
- zone.buildGuardsFromZone(clocks, relevantClocks)
+ zone.buildExpressionFromZone(clocks, relevantClocks)
);
// Adds boolean constraints (var == val)
andParts.add(
- bdd.toBoolGuards()
+ bdd.toBoolExpression()
);
// Removes all TrueGuards
andParts = andParts.stream()
- .filter(guard -> !(guard instanceof TrueGuard))
+ .filter(guard -> !(guard instanceof TrueExpression))
.collect(Collectors.toList());
orParts.add(
- new AndGuard(andParts)
+ new AndExpression(andParts)
);
}
- return new OrGuard(orParts);
+ return new OrExpression(orParts);
}
- private Guard toBoolGuards()
+ private Expression toBoolExpression()
throws IllegalArgumentException {
if (!isBDD()) {
throw new IllegalArgumentException("CDD is not a BDD");
}
if (isFalse()) {
- return new FalseGuard();
+ return new FalseExpression();
}
if (isTrue()) {
- return new TrueGuard();
+ return new TrueExpression();
}
long ptr = getPointer();
BDDArrays arrays = new BDDArrays(CDDLib.bddToArray(ptr, numBools));
- List orParts = new ArrayList<>();
+ List orParts = new ArrayList<>();
for (int i = 0; i < arrays.traceCount; i++) {
- List andParts = new ArrayList<>();
+ List andParts = new ArrayList<>();
for (int j = 0; j < arrays.booleanCount; j++) {
int index = arrays.getVariables().get(i).get(j);
if (index >= 0) {
BoolVar var = BVs.get(index - bddStartLevel);
boolean val = arrays.getValues().get(i).get(j) == 1;
- BoolGuard bg = new BoolGuard(var, Relation.EQUAL, val);
+ BoolExpression bg = new BoolExpression(var, Relation.EQUAL, val);
andParts.add(bg);
}
}
- orParts.add(new AndGuard(andParts));
+ orParts.add(new AndExpression(andParts));
}
- return new OrGuard(orParts);
+ return new OrExpression(orParts);
}
public long getPointer() {
@@ -633,7 +633,7 @@ public CDD transitionBack(Move e) {
@Override
public String toString() {
- return getGuard().toString();
+ return getExpression().toString();
}
@Override
@@ -663,14 +663,14 @@ public static CDD create(List updates) {
}
if (up instanceof BoolUpdate) {
BoolUpdate u = (BoolUpdate) up;
- BoolGuard bg = new BoolGuard(u.getBV(), Relation.EQUAL, u.getValue());
+ BoolExpression bg = new BoolExpression(u.getBV(), Relation.EQUAL, u.getValue());
res = res.conjunction(CDD.create(bg));
}
}
return res.removeNegative().reduce();
}
- public static CDD create(BoolGuard guard) {
+ public static CDD create(BoolExpression guard) {
if (guard.getValue()) {
return createBddNode(bddStartLevel + indexOf(guard.getVar()));
}
diff --git a/src/models/ClockGuard.java b/src/models/ClockExpression.java
similarity index 79%
rename from src/models/ClockGuard.java
rename to src/models/ClockExpression.java
index 8fd8a395..ea9f209f 100644
--- a/src/models/ClockGuard.java
+++ b/src/models/ClockExpression.java
@@ -3,14 +3,14 @@
import java.util.List;
import java.util.Objects;
-public class ClockGuard extends Guard {
+public class ClockExpression extends Expression {
private final Clock clock, diagonalClock;
private final int bound;
private final Relation relation;
- public ClockGuard(Clock main, Clock secondary, int bound, Relation relation) throws IllegalArgumentException {
+ public ClockExpression(Clock main, Clock secondary, int bound, Relation relation) throws IllegalArgumentException {
if (main == null) {
- throw new IllegalArgumentException("The main clock of the clock guard cannot be null");
+ throw new IllegalArgumentException("The main clock of the clock expression cannot be null");
}
// These are the only relation types allowed
if (relation != Relation.LESS_THAN &&
@@ -18,7 +18,7 @@ public ClockGuard(Clock main, Clock secondary, int bound, Relation relation) thr
relation != Relation.EQUAL &&
relation != Relation.GREATER_EQUAL &&
relation != Relation.GREATER_THAN) {
- throw new IllegalArgumentException("The relation of the clock guard is invalid");
+ throw new IllegalArgumentException("The relation of the clock expression is invalid");
}
this.clock = main;
this.diagonalClock = secondary;
@@ -26,11 +26,11 @@ public ClockGuard(Clock main, Clock secondary, int bound, Relation relation) thr
this.bound = bound;
}
- public ClockGuard(Clock clock_i, int bound, Relation relation) throws IllegalArgumentException {
+ public ClockExpression(Clock clock_i, int bound, Relation relation) throws IllegalArgumentException {
this(clock_i, null, bound, relation);
}
- public ClockGuard(ClockGuard orig, List newClocks, List oldClocks) throws IndexOutOfBoundsException, IllegalArgumentException {
+ public ClockExpression(ClockExpression orig, List newClocks, List oldClocks) throws IndexOutOfBoundsException, IllegalArgumentException {
this(newClocks.get(oldClocks.indexOf(orig.clock)), orig.diagonalClock == null ? null : newClocks.get(oldClocks.indexOf(orig.diagonalClock)), orig.getBound(), orig.getRelation());
}
@@ -60,7 +60,7 @@ public int getLowerBound() throws IllegalStateException {
return 0;
}
}
- throw new IllegalStateException("The relation of the clock guard is invalid");
+ throw new IllegalStateException("The relation of the clock expression is invalid");
}
public int getUpperBound() throws IllegalStateException {
@@ -75,10 +75,10 @@ public int getUpperBound() throws IllegalStateException {
return Integer.MAX_VALUE;
}
}
- throw new IllegalStateException("The relation of the clock guard is invalid");
+ throw new IllegalStateException("The relation of the clock expression is invalid");
}
- // Returns a bound of a guard in the automaton
+ // Returns a bound of an expression in the automaton
public int getBound() {
return bound;
}
@@ -100,8 +100,8 @@ int getMaxConstant(Clock clock)
}
@Override
- Guard copy(List newClocks, List oldClocks, List newBVs, List oldBVs) {
- return new ClockGuard(this, newClocks, oldClocks);
+ Expression copy(List newClocks, List oldClocks, List newBVs, List oldBVs) {
+ return new ClockExpression(this, newClocks, oldClocks);
}
@Override
@@ -109,11 +109,11 @@ public boolean equals(Object obj) {
if (this == obj) {
return true;
}
- if (!(obj instanceof ClockGuard)) {
+ if (!(obj instanceof ClockExpression)) {
return false;
}
- ClockGuard other = (ClockGuard) obj;
+ ClockExpression other = (ClockExpression) obj;
if (bound != other.bound ||
relation != other.relation ||
diff --git a/src/models/Edge.java b/src/models/Edge.java
index 64e70dfa..524b3658 100644
--- a/src/models/Edge.java
+++ b/src/models/Edge.java
@@ -10,7 +10,7 @@ public class Edge {
private Location source, target;
private Channel chan;
private boolean isInput;
- private Guard guard;
+ private Expression expression;
private List updates;
public void setSource(Location source) {
@@ -33,16 +33,16 @@ public void setInput(boolean input) {
isInput = input;
}
- public void setGuard(Guard guard) {
- this.guard = guard;
+ public void setGuard(Expression expression) {
+ this.expression = expression;
}
- public Edge(Location source, Location target, Channel chan, boolean isInput, Guard guards, List updates) {
+ public Edge(Location source, Location target, Channel chan, boolean isInput, Expression guards, List updates) {
this.source = source;
this.target = target;
this.chan = chan;
this.isInput = isInput;
- this.guard = guards;
+ this.expression = guards;
this.updates = updates;
}
@@ -52,7 +52,7 @@ public Edge(Edge copy, List newClocks, List newBVs, Location sou
targetR,
copy.chan,
copy.isInput,
- copy.guard.copy(newClocks, oldClocks, newBVs, oldBVs),
+ copy.expression.copy(newClocks, oldClocks, newBVs, oldBVs),
copy.updates
.stream()
.map(update -> update.copy(
@@ -67,11 +67,11 @@ public Edge(Edge copy, List newClocks, List newBVs, List
}
public CDD getGuardCDD() {
- return new CDD(guard);
+ return new CDD(expression);
}
public int getMaxConstant(Clock clock) {
- return guard.getMaxConstant(clock);
+ return expression.getMaxConstant(clock);
}
// Used in determinism check to verify if two edges have exactly the same updates
@@ -97,8 +97,8 @@ public boolean isInput() {
return isInput;
}
- public Guard getGuard() {
- return guard;
+ public Expression getGuard() {
+ return expression;
}
public List getUpdates() {
@@ -120,14 +120,14 @@ public boolean equals(Object obj) {
if (chan == null && edge.chan != null) {
return false;
}
- if (guard == null && edge.guard != null) {
+ if (expression == null && edge.expression != null) {
return false;
}
return isInput == edge.isInput &&
source != null && source.equals(edge.source) &&
target != null && target.equals(edge.target) &&
chan != null && chan.equals(edge.chan) &&
- guard != null && guard.equals(edge.guard) &&
+ expression != null && expression.equals(edge.expression) &&
hasEqualUpdates(edge);
}
@@ -137,13 +137,13 @@ public String toString() {
source + " - " +
chan.getName() +
(isInput ? "?" : "!") + " - " +
- guard + " - " +
+ expression + " - " +
Arrays.toString(this.updates.toArray()) + " - " +
target + ")\n";
}
@Override
public int hashCode() {
- return Objects.hash(source, target, chan, isInput, guard, updates);
+ return Objects.hash(source, target, chan, isInput, expression, updates);
}
}
diff --git a/src/models/Guard.java b/src/models/Expression.java
similarity index 57%
rename from src/models/Guard.java
rename to src/models/Expression.java
index e2eda37f..58d526dc 100644
--- a/src/models/Guard.java
+++ b/src/models/Expression.java
@@ -3,11 +3,11 @@
import java.util.List;
import java.util.stream.Collectors;
-public abstract class Guard {
+public abstract class Expression {
abstract int getMaxConstant(Clock clock);
- abstract Guard copy(List newClocks, List oldClocks, List newBVs, List oldBVs);
+ abstract Expression copy(List newClocks, List oldClocks, List newBVs, List oldBVs);
@Override
public abstract boolean equals(Object o);
@@ -22,16 +22,16 @@ public String prettyPrint() {
return toString();
}
- static String compositePrettyPrint(List guards, String connector) {
- return guards.stream()
- .limit(guards.size()-1)
+ static String compositePrettyPrint(List expressions, String connector) {
+ return expressions.stream()
+ .limit(expressions.size()-1)
.map(g -> {
- if (g instanceof OrGuard || g instanceof AndGuard)
+ if (g instanceof OrExpression || g instanceof AndExpression)
return String.format("(%s) %s ", g.prettyPrint(), connector);
else
return String.format("%s %s ", g.prettyPrint(), connector);
})
.collect(Collectors.joining())
- + guards.get(guards.size()-1).prettyPrint();
+ + expressions.get(expressions.size()-1).prettyPrint();
}
}
diff --git a/src/models/FalseGuard.java b/src/models/FalseExpression.java
similarity index 61%
rename from src/models/FalseGuard.java
rename to src/models/FalseExpression.java
index 7068139e..16b595c1 100644
--- a/src/models/FalseGuard.java
+++ b/src/models/FalseExpression.java
@@ -3,7 +3,7 @@
import java.util.List;
import java.util.Objects;
-public class FalseGuard extends Guard {
+public class FalseExpression extends Expression {
@Override
int getMaxConstant(Clock clock) {
@@ -11,13 +11,13 @@ int getMaxConstant(Clock clock) {
}
@Override
- Guard copy(List newClocks, List oldClocks, List newBVs, List oldBVs) {
- return new FalseGuard();
+ Expression copy(List newClocks, List oldClocks, List newBVs, List oldBVs) {
+ return new FalseExpression();
}
@Override
public boolean equals(Object o) {
- return o instanceof FalseGuard;
+ return o instanceof FalseExpression;
}
@Override
diff --git a/src/models/Federation.java b/src/models/Federation.java
index ab4ed634..9f097a12 100644
--- a/src/models/Federation.java
+++ b/src/models/Federation.java
@@ -48,12 +48,12 @@ public Federation copy() {
return new Federation(zones);
}
- public Guard toGuards(List clocks) {
- List turnedBackIntoGuards = new ArrayList<>();
+ public Expression toGuards(List clocks) {
+ List turnedBackIntoExpressions = new ArrayList<>();
for (Zone zone : getZones()) {
- turnedBackIntoGuards.add(zone.buildGuardsFromZone(clocks, clocks));
+ turnedBackIntoExpressions.add(zone.buildExpressionFromZone(clocks, clocks));
}
- return new OrGuard(turnedBackIntoGuards);
+ return new OrExpression(turnedBackIntoExpressions);
}
public boolean isUnrestrained(List clocks) {
diff --git a/src/models/Location.java b/src/models/Location.java
index 2b5e68d0..e92776d9 100644
--- a/src/models/Location.java
+++ b/src/models/Location.java
@@ -10,7 +10,7 @@
* {@link Location} is a class used by both {@link Automaton} and {@link TransitionSystem} to decribe a location.
* It is named and has coordinates describing the position where it should be drawn in the GUI.
* A {@link Location} can be marked as initial, urgent, universal, and inconsistent.
- * In order to reduce the conversions between {@link Guard} and {@link CDD}
+ * In order to reduce the conversions between {@link Expression} and {@link CDD}
* the invariant is stored as both and only updated when required.
* For {@link Pruning} it also stores the inconsistent part of its invariant.
*
@@ -21,15 +21,15 @@
* The invariant of a composed location is lazily created as the conjunction of its children's invariants.
* In this context lazily created means that the locally stored invariant value in this location is only
* updated when a change in this composed location warrants an update to it.
- * This can be warranted when {@link #setInvariantGuard(Guard)} is invoked.
+ * This can be warranted when {@link #setInvariant(Expression)} is invoked.
*
*
* A {@link Location} can also be a simple location, which is a location with exactly one child.
* A simple location is used when the {@link CDD CDD invariant} of this location
- * is not directly created from the {@link Guard Guard invariant}.
+ * is not directly created from the {@link Expression Invariant}.
* Instead the {@link CDD CDD invariant} of this location will always be the {@link CDD CDD invariant} of its child,
- * whilst the {@link Guard Guard invariant} of this location can be different from the {@link CDD CDD invariant}.
- * For this reason a simple location can have a {@link Guard Guard invariant} and {@link CDD CDD invariant}
+ * whilst the {@link Expression Invariant} of this location can be different from the {@link CDD CDD invariant}.
+ * For this reason a simple location can have a {@link Expression Invariant} and {@link CDD CDD invariant}
* which is out of sync.
* Deprecation warning:simple locations are planned to be deprecated and one should instead create
* composed locations which have a more predictable specification
@@ -38,7 +38,7 @@
* State overview:
*
name
*
x and y coordinates
- *
invariant both as {@link Guard} and {@link CDD}
+ *
invariant both as {@link Expression} and {@link CDD}
*
inconsistent part for {@link Pruning}
*
whether it is initial, urgent, universal, inconsistent
*
@@ -49,7 +49,7 @@ public final class Location {
private String name;
private int x, y;
- private Guard invariantGuard;
+ private Expression invariantExpression;
private CDD invariantCdd;
private CDD inconsistentPart;
@@ -63,7 +63,7 @@ public final class Location {
private Location(
String name,
- Guard invariantGuard,
+ Expression invariantExpression,
CDD invariantCdd,
CDD inconsistentPart,
boolean isInitial,
@@ -79,7 +79,7 @@ private Location(
}
this.name = name;
- this.invariantGuard = invariantGuard;
+ this.invariantExpression = invariantExpression;
this.invariantCdd = invariantCdd;
this.inconsistentPart = inconsistentPart;
this.isInitial = isInitial;
@@ -93,7 +93,7 @@ private Location(
public static Location create(
String name,
- Guard invariant,
+ Expression invariant,
boolean isInitial,
boolean isUrgent,
boolean isUniversal,
@@ -118,7 +118,7 @@ public static Location create(
public static Location create(
String name,
- Guard invariant,
+ Expression invariant,
boolean isInitial,
boolean isUrgent,
boolean isUniversal,
@@ -145,7 +145,7 @@ public static Location createComposition(List children) {
int x = 0;
int y = 0;
- List guards = new ArrayList<>();
+ List expressions = new ArrayList<>();
for (Location location : children) {
nameBuilder.append(location.getName());
isInitial = isInitial && location.isInitial();
@@ -154,7 +154,7 @@ public static Location createComposition(List children) {
isInconsistent = isInconsistent || location.isInconsistent();
x += location.getX();
y += location.getY();
- guards.add(location.getInvariantGuard());
+ expressions.add(location.getInvariant());
}
int amount = children.size();
@@ -162,7 +162,7 @@ public static Location createComposition(List children) {
y /= amount;
String name = nameBuilder.toString();
- Guard invariant = new AndGuard(guards);
+ Expression invariant = new AndExpression(expressions);
return new Location(
name,
invariant,
@@ -187,7 +187,7 @@ public static Location createUniversalLocation(
) {
return new Location(
name,
- new TrueGuard(),
+ new TrueExpression(),
null,
null,
isInitial,
@@ -213,7 +213,7 @@ public static Location createInconsistentLocation(
) {
return new Location(
name,
- new FalseGuard(),
+ new FalseExpression(),
null,
null,
isInitial,
@@ -236,7 +236,7 @@ public static Location createSimple(Location child) {
return new Location(
child.getName(),
- child.getInvariantGuard(),
+ child.getInvariant(),
null,
child.getInconsistentPart(),
child.isInitial(),
@@ -252,7 +252,7 @@ public static Location createSimple(Location child) {
public Location copy() {
return new Location(
getName(),
- getInvariantGuard(),
+ getInvariant(),
null,
getInconsistentPart(),
isInitial(),
@@ -273,7 +273,7 @@ public Location copy(
) {
return new Location(
getName(),
- getInvariantGuard().copy(
+ getInvariant().copy(
newClocks, oldClocks, newBVs, oldBVs
),
null,
@@ -301,7 +301,7 @@ public List getChildren() {
}
public void removeInvariants() {
- invariantGuard = new TrueGuard();
+ invariantExpression = new TrueExpression();
invariantCdd = CDD.cddTrue();
}
@@ -341,17 +341,17 @@ public void setY(int y) {
this.y = y;
}
- public Guard getInvariantGuard() {
- if (invariantGuard == null) {
- invariantGuard = getInvariantCdd().getGuard();
+ public Expression getInvariant() {
+ if (invariantExpression == null) {
+ invariantExpression = getInvariantCdd().getExpression();
}
- return invariantGuard;
+ return invariantExpression;
}
public CDD getInvariantCdd() {
if (isSimple()) {
- return new CDD(children.get(0).getInvariantGuard());
+ return new CDD(children.get(0).getInvariant());
}
if (invariantCdd == null) {
@@ -365,15 +365,15 @@ public CDD getInvariantCdd() {
this.invariantCdd = this.invariantCdd.conjunction(location.getInvariantCdd());
}
} else {
- invariantCdd = new CDD(getInvariantGuard());
+ invariantCdd = new CDD(getInvariant());
}
}
return invariantCdd;
}
- public void setInvariantGuard(Guard invariantAsGuard) {
- this.invariantGuard = invariantAsGuard;
+ public void setInvariant(Expression invariantAsExpression) {
+ this.invariantExpression = invariantAsExpression;
this.invariantCdd = null;
}
@@ -390,7 +390,7 @@ public void setInconsistentPart(CDD inconsistentPart) {
}
public int getMaxConstant(Clock clock) {
- return getInvariantGuard().getMaxConstant(clock);
+ return getInvariant().getMaxConstant(clock);
}
@Override
@@ -431,6 +431,6 @@ public int hashCode() {
return Objects.hash(children);
}
- return Objects.hash(name, getInvariantGuard(), isInitial, isUrgent, isUniversal, isInconsistent);
+ return Objects.hash(name, getInvariant(), isInitial, isUrgent, isUniversal, isInconsistent);
}
}
diff --git a/src/models/Move.java b/src/models/Move.java
index 8e855dea..704ca8de 100644
--- a/src/models/Move.java
+++ b/src/models/Move.java
@@ -56,8 +56,8 @@ public CDD getGuardCDD() {
return (guardCDD);
}
- public Guard getGuards(List relevantClocks) {
- return guardCDD.getGuard(relevantClocks);
+ public Expression getGuards(List relevantClocks) {
+ return guardCDD.getExpression(relevantClocks);
}
public void setGuards(CDD guardCDD) {
diff --git a/src/models/OrExpression.java b/src/models/OrExpression.java
new file mode 100644
index 00000000..dd2c59ce
--- /dev/null
+++ b/src/models/OrExpression.java
@@ -0,0 +1,127 @@
+package models;
+
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+
+import java.util.*;
+import java.util.stream.Collectors;
+
+public class OrExpression extends Expression {
+
+ private List expressions;
+
+ public OrExpression(List expressions) {
+ this.expressions = expressions;
+
+ /* If any of the expressions are OrExpressions themselves,
+ * then we can decompose their expressions to be contained in this */
+ List worklist = this.expressions
+ .stream()
+ .filter(expression -> expression instanceof OrExpression)
+ .map(expression -> (OrExpression) expression)
+ .collect(Collectors.toList());
+ while (!worklist.isEmpty()) {
+ OrExpression current = worklist.get(0);
+ worklist.remove(0);
+
+ for (Expression expression : current.expressions) {
+ if (expression instanceof OrExpression) {
+ worklist.add((OrExpression) expression);
+ }
+ this.expressions.add(expression);
+ }
+
+ this.expressions.remove(current);
+ }
+
+ // Remove all expressions if there is a true expression
+ boolean hasTrueExpression = this.expressions.stream().anyMatch(expression -> expression instanceof TrueExpression);
+ if (hasTrueExpression) {
+ /* If there are one or more TrueExpressions then we just need a single TrueExpression.
+ * It would be possible to just clear it and let the last predicate,
+ * ensure that the empty OrExpression is a tautology.
+ * However, this is more robust towards changes */
+ this.expressions.clear();
+ this.expressions.add(new TrueExpression());
+ }
+
+ // Remove all false expressions
+ this.expressions = this.expressions.stream().filter(expression -> !(expression instanceof FalseExpression)).collect(Collectors.toList());
+
+ // If there are no expressions then it is a tautology
+ if (this.expressions.size() == 0) {
+ this.expressions.add(new TrueExpression());
+ }
+ }
+
+ public OrExpression(List... expressions) {
+ this(Lists.newArrayList(Iterables.concat(expressions)));
+ }
+
+ public OrExpression(Expression... expressions) {
+ this(Arrays.asList(expressions));
+ }
+
+ public OrExpression(OrExpression copy, List newClocks, List oldClocks, List newBVs, List oldBVs) {
+ // As this is the copy-constructor we need to create new instances of the expressions
+ this(copy.expressions.stream().map(expression ->
+ expression.copy(newClocks, oldClocks, newBVs, oldBVs)
+ ).collect(Collectors.toList()));
+ }
+
+ public List getExpressions() {
+ return expressions;
+ }
+
+ @Override
+ int getMaxConstant(Clock clock) {
+ int max = 0;
+ for (Expression expression : expressions) {
+ max = Math.max(max, expression.getMaxConstant(clock));
+ }
+ return max;
+ }
+
+ @Override
+ Expression copy(List newClocks, List oldClocks, List newBVs, List oldBVs) {
+ return new OrExpression(
+ this, newClocks, oldClocks, newBVs, oldBVs
+ );
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (!(obj instanceof OrExpression)) {
+ return false;
+ }
+
+ OrExpression other = (OrExpression) obj;
+ return Arrays.equals(expressions.toArray(), other.expressions.toArray());
+ }
+
+ @Override
+ public String toString() {
+ if (expressions.size() == 1) {
+ return expressions.get(0).toString();
+ }
+
+ return "(" +
+ expressions.stream()
+ .map(Expression::toString)
+ .collect(Collectors.joining(" or "))
+ + ")";
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(false);
+ }
+
+ @Override
+ public String prettyPrint() {
+ return Expression.compositePrettyPrint(expressions, "||");
+ }
+}
diff --git a/src/models/OrGuard.java b/src/models/OrGuard.java
deleted file mode 100644
index fb97f472..00000000
--- a/src/models/OrGuard.java
+++ /dev/null
@@ -1,127 +0,0 @@
-package models;
-
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
-
-import java.util.*;
-import java.util.stream.Collectors;
-
-public class OrGuard extends Guard {
-
- private List guards;
-
- public OrGuard(List guards) {
- this.guards = guards;
-
- /* If any of the guards are OrGuards themselves,
- * then we can decompose their guards to be contained in this */
- List worklist = this.guards
- .stream()
- .filter(guard -> guard instanceof OrGuard)
- .map(guard -> (OrGuard) guard)
- .collect(Collectors.toList());
- while (!worklist.isEmpty()) {
- OrGuard current = worklist.get(0);
- worklist.remove(0);
-
- for (Guard guard : current.guards) {
- if (guard instanceof OrGuard) {
- worklist.add((OrGuard) guard);
- }
- this.guards.add(guard);
- }
-
- this.guards.remove(current);
- }
-
- // Remove all guards if there is a true guard
- boolean hasTrueGuard = this.guards.stream().anyMatch(guard -> guard instanceof TrueGuard);
- if (hasTrueGuard) {
- /* If there are one or more TrueGuards then we just need a single TrueGuard.
- * It would be possible to just clear it and let the last predicate,
- * ensure that the empty OrGuard is a tautology.
- * However, this is more robust towards changes */
- this.guards.clear();
- this.guards.add(new TrueGuard());
- }
-
- // Remove all false guards
- this.guards = this.guards.stream().filter(guard -> !(guard instanceof FalseGuard)).collect(Collectors.toList());
-
- // If there are no guards then it is a tautology
- if (this.guards.size() == 0) {
- this.guards.add(new TrueGuard());
- }
- }
-
- public OrGuard(List... guards) {
- this(Lists.newArrayList(Iterables.concat(guards)));
- }
-
- public OrGuard(Guard... guards) {
- this(Arrays.asList(guards));
- }
-
- public OrGuard(OrGuard copy, List newClocks, List oldClocks, List newBVs, List oldBVs) {
- // As this is the copy-constructor we need to create new instances of the guards
- this(copy.guards.stream().map(guard ->
- guard.copy(newClocks, oldClocks, newBVs, oldBVs)
- ).collect(Collectors.toList()));
- }
-
- public List getGuards() {
- return guards;
- }
-
- @Override
- int getMaxConstant(Clock clock) {
- int max = 0;
- for (Guard guard : guards) {
- max = Math.max(max, guard.getMaxConstant(clock));
- }
- return max;
- }
-
- @Override
- Guard copy(List newClocks, List oldClocks, List newBVs, List oldBVs) {
- return new OrGuard(
- this, newClocks, oldClocks, newBVs, oldBVs
- );
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!(obj instanceof OrGuard)) {
- return false;
- }
-
- OrGuard other = (OrGuard) obj;
- return Arrays.equals(guards.toArray(), other.guards.toArray());
- }
-
- @Override
- public String toString() {
- if (guards.size() == 1) {
- return guards.get(0).toString();
- }
-
- return "(" +
- guards.stream()
- .map(Guard::toString)
- .collect(Collectors.joining(" or "))
- + ")";
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(false);
- }
-
- @Override
- public String prettyPrint() {
- return Guard.compositePrettyPrint(guards, "||");
- }
-}
diff --git a/src/models/TrueGuard.java b/src/models/TrueExpression.java
similarity index 61%
rename from src/models/TrueGuard.java
rename to src/models/TrueExpression.java
index 46e996e9..2d59a4fc 100644
--- a/src/models/TrueGuard.java
+++ b/src/models/TrueExpression.java
@@ -3,7 +3,7 @@
import java.util.List;
import java.util.Objects;
-public class TrueGuard extends Guard{
+public class TrueExpression extends Expression {
@Override
int getMaxConstant(Clock clock) {
@@ -11,13 +11,13 @@ int getMaxConstant(Clock clock) {
}
@Override
- Guard copy(List newClocks, List oldClocks, List newBVs, List oldBVs) {
- return new TrueGuard();
+ Expression copy(List newClocks, List oldClocks, List newBVs, List oldBVs) {
+ return new TrueExpression();
}
@Override
public boolean equals(Object o) {
- return o instanceof TrueGuard;
+ return o instanceof TrueExpression;
}
@Override
diff --git a/src/models/Zone.java b/src/models/Zone.java
index 7e2de49f..74faa318 100644
--- a/src/models/Zone.java
+++ b/src/models/Zone.java
@@ -50,7 +50,7 @@ public int getDimension() {
return dimension;
}
- public void buildConstraintsForGuard(ClockGuard guard, List clocks) {
+ public void buildConstraintsForGuard(ClockExpression guard, List clocks) {
if (guard.isDiagonal()) {
buildConstraintsForDiagonalConstraint(guard, clocks);
} else {
@@ -58,7 +58,7 @@ public void buildConstraintsForGuard(ClockGuard guard, List clocks) {
}
}
- public void buildConstraintsForNormalGuard(ClockGuard guard, List clocks) {
+ public void buildConstraintsForNormalGuard(ClockExpression guard, List clocks) {
int index = getIndexOfClock(guard.getClock(), clocks);
Relation relation = guard.getRelation();
@@ -89,7 +89,7 @@ public void buildConstraintsForNormalGuard(ClockGuard guard, List clocks)
}
}
- public void buildConstraintsForDiagonalConstraint(ClockGuard guard, List clocks)
+ public void buildConstraintsForDiagonalConstraint(ClockExpression guard, List clocks)
throws IllegalArgumentException {
Relation relation = guard.getRelation();
Clock clock_i = guard.getClock();
@@ -182,15 +182,15 @@ private static boolean containsClock(Clock clock, List clocks) {
return clocks.contains(clock);
}
- public Guard buildGuardsFromZone(List clocks, List relevantClocks) {
- List guards = new ArrayList<>();
- guards.addAll(buildNormalGuardsFromZone(clocks, relevantClocks));
- guards.addAll(buildDiagonalConstraintsFromZone(clocks, relevantClocks));
- return new AndGuard(guards);
+ public Expression buildExpressionFromZone(List clocks, List relevantClocks) {
+ List expressions = new ArrayList<>();
+ expressions.addAll(buildNormalGuardsFromZone(clocks, relevantClocks));
+ expressions.addAll(buildDiagonalConstraintsFromZone(clocks, relevantClocks));
+ return new AndExpression(expressions);
}
- public List buildNormalGuardsFromZone(List clocks, List relevantClocks) {
- List guards = new ArrayList<>();
+ public List buildNormalGuardsFromZone(List clocks, List relevantClocks) {
+ List guards = new ArrayList<>();
for (int i = 1; i < dimension; i++) {
Clock clock = clocks.get(i - 1);
@@ -205,7 +205,7 @@ public List buildNormalGuardsFromZone(List clocks, List buildNormalGuardsFromZone(List clocks, List buildNormalGuardsFromZone(List clocks, List buildNormalGuardsFromZone(List clocks, List buildDiagonalConstraintsFromZone(List clocks, List relevantClocks) {
- List guards = new ArrayList<>();
+ public List buildDiagonalConstraintsFromZone(List clocks, List relevantClocks) {
+ List guards = new ArrayList<>();
for (int i = 1; i < dimension; i++) {
for (int j = 1; j < dimension; j++) {
@@ -264,11 +264,11 @@ public List buildDiagonalConstraintsFromZone(List clocks, Lis
if (DBMLib.dbm_rawIsStrict(currentValue)) {
guards.add(
- new ClockGuard(clock_j, clock_i, DBMLib.raw2bound(currentValue), Relation.LESS_THAN)
+ new ClockExpression(clock_j, clock_i, DBMLib.raw2bound(currentValue), Relation.LESS_THAN)
);
} else {
guards.add(
- new ClockGuard(clock_j, clock_i, DBMLib.raw2bound(currentValue), Relation.LESS_EQUAL)
+ new ClockExpression(clock_j, clock_i, DBMLib.raw2bound(currentValue), Relation.LESS_EQUAL)
);
}
diff --git a/src/parser/ExpressionParser.java b/src/parser/ExpressionParser.java
new file mode 100644
index 00000000..c81e24ea
--- /dev/null
+++ b/src/parser/ExpressionParser.java
@@ -0,0 +1,106 @@
+package parser;
+
+import ExpressionGrammar.ExpressionGrammarParser;
+import ExpressionGrammar.ExpressionGrammarLexer;
+import ExpressionGrammar.ExpressionGrammarBaseVisitor;
+import exceptions.BooleanVariableNotFoundException;
+import exceptions.ClockNotFoundException;
+import models.*;
+import org.antlr.v4.runtime.CharStream;
+import org.antlr.v4.runtime.CharStreams;
+import org.antlr.v4.runtime.CommonTokenStream;
+import org.antlr.v4.runtime.TokenStream;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class ExpressionParser {
+
+ private static List clocks;
+ private static List BVs;
+
+ private static Clock findClock(String clockName) {
+ for (Clock clock : clocks)
+ if (clock.getOriginalName().equals(clockName)) return clock;
+
+ throw new ClockNotFoundException("Clock: " + clockName + " was not found");
+ }
+
+ private static BoolVar findBV(String name) {
+ for (BoolVar bv : BVs)
+ if (bv.getOriginalName().equals(name))
+ return bv;
+
+ throw new BooleanVariableNotFoundException("Boolean variable: " + name + " was not found");
+ }
+
+ public static Expression parse(String expressionString, List clockList, List BVList) {
+ clocks = clockList;
+ BVs = BVList;
+ CharStream charStream = CharStreams.fromString(expressionString);
+ ExpressionGrammarLexer lexer = new ExpressionGrammarLexer(charStream);
+ lexer.addErrorListener(new ErrorListener());
+ TokenStream tokens = new CommonTokenStream(lexer);
+ ExpressionGrammarParser parser = new ExpressionGrammarParser(tokens);
+ parser.addErrorListener(new ErrorListener());
+
+ ExpressionVisitor expressionVisitor = new ExpressionVisitor();
+ return expressionVisitor.visit(parser.contstraint());
+ }
+
+ private static class ExpressionVisitor extends ExpressionGrammarBaseVisitor{
+
+ @Override
+ public Expression visitOr(ExpressionGrammarParser.OrContext ctx) {
+ List orExpressions = new ArrayList<>();
+ for(ExpressionGrammarParser.OrExpressionContext orExpression: ctx.orExpression()){
+ orExpressions.add(visit(orExpression));
+ }
+
+ return new OrExpression(orExpressions);
+ }
+
+ public Expression visitAnd(ExpressionGrammarParser.AndContext ctx) {
+ List expressions = new ArrayList<>();
+ for (ExpressionGrammarParser.ExpressionContext expression: ctx.expression()) {
+ expressions.add(visit(expression));
+ }
+ return new AndExpression(expressions);
+ }
+
+ @Override
+ public Expression visitExpression(ExpressionGrammarParser.ExpressionContext ctx) {
+ if(ctx.BOOLEAN() != null) {
+ boolean value = Boolean.parseBoolean(ctx.BOOLEAN().getText());
+ return value ? new TrueExpression() : new FalseExpression();
+ }else if(ctx.contstraint() != null){
+ return visit(ctx.contstraint());
+ }
+ return visitChildren(ctx);
+ }
+
+ @Override
+ public Expression visitClockExpr(ExpressionGrammarParser.ClockExprContext ctx) {
+ int value = Integer.parseInt(ctx.INT().getText());
+ String operator = ctx.OPERATOR().getText();
+ Clock clock_i = findClock(ctx.VARIABLE(0).getText());
+ Relation relation = Relation.fromString(operator);
+
+ if(ctx.VARIABLE().size() > 1){
+ Clock clock_j = findClock(ctx.VARIABLE(1).getText());
+ return new ClockExpression(clock_i, clock_j, value, relation);
+ }else {
+ return new ClockExpression(clock_i, value, relation);
+ }
+ }
+
+ @Override
+ public Expression visitBoolExpr(ExpressionGrammarParser.BoolExprContext ctx) {
+ boolean value = Boolean.parseBoolean(ctx.BOOLEAN().getText());
+ String operator = ctx.OPERATOR().getText();
+ BoolVar bv = findBV(ctx.VARIABLE().getText());
+
+ return new BoolExpression(bv, operator, value);
+ }
+ }
+}
diff --git a/src/parser/GuardParser.java b/src/parser/GuardParser.java
deleted file mode 100644
index 944ffb89..00000000
--- a/src/parser/GuardParser.java
+++ /dev/null
@@ -1,106 +0,0 @@
-package parser;
-
-import GuardGrammar.GuardGrammarParser;
-import GuardGrammar.GuardGrammarLexer;
-import GuardGrammar.GuardGrammarBaseVisitor;
-import exceptions.BooleanVariableNotFoundException;
-import exceptions.ClockNotFoundException;
-import models.*;
-import org.antlr.v4.runtime.CharStream;
-import org.antlr.v4.runtime.CharStreams;
-import org.antlr.v4.runtime.CommonTokenStream;
-import org.antlr.v4.runtime.TokenStream;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class GuardParser {
-
- private static List clocks;
- private static List BVs;
-
- private static Clock findClock(String clockName) {
- for (Clock clock : clocks)
- if (clock.getOriginalName().equals(clockName)) return clock;
-
- throw new ClockNotFoundException("Clock: " + clockName + " was not found");
- }
-
- private static BoolVar findBV(String name) {
- for (BoolVar bv : BVs)
- if (bv.getOriginalName().equals(name))
- return bv;
-
- throw new BooleanVariableNotFoundException("Boolean variable: " + name + " was not found");
- }
-
- public static Guard parse(String guardString, List clockList, List BVList) {
- clocks = clockList;
- BVs = BVList;
- CharStream charStream = CharStreams.fromString(guardString);
- GuardGrammarLexer lexer = new GuardGrammarLexer(charStream);
- lexer.addErrorListener(new ErrorListener());
- TokenStream tokens = new CommonTokenStream(lexer);
- GuardGrammarParser parser = new GuardGrammarParser(tokens);
- parser.addErrorListener(new ErrorListener());
-
- GuardVisitor guardVisitor = new GuardVisitor();
- return guardVisitor.visit(parser.guard());
- }
-
- private static class GuardVisitor extends GuardGrammarBaseVisitor{
-
- @Override
- public Guard visitOr(GuardGrammarParser.OrContext ctx) {
- List orGuards = new ArrayList<>();
- for(GuardGrammarParser.OrExpressionContext orExpression: ctx.orExpression()){
- orGuards.add(visit(orExpression));
- }
-
- return new OrGuard(orGuards);
- }
-
- public Guard visitAnd(GuardGrammarParser.AndContext ctx) {
- List guards = new ArrayList<>();
- for (GuardGrammarParser.ExpressionContext expression: ctx.expression()) {
- guards.add(visit(expression));
- }
- return new AndGuard(guards);
- }
-
- @Override
- public Guard visitExpression(GuardGrammarParser.ExpressionContext ctx) {
- if(ctx.BOOLEAN() != null) {
- boolean value = Boolean.parseBoolean(ctx.BOOLEAN().getText());
- return value ? new TrueGuard() : new FalseGuard();
- }else if(ctx.guard() != null){
- return visit(ctx.guard());
- }
- return visitChildren(ctx);
- }
-
- @Override
- public Guard visitClockExpr(GuardGrammarParser.ClockExprContext ctx) {
- int value = Integer.parseInt(ctx.INT().getText());
- String operator = ctx.OPERATOR().getText();
- Clock clock_i = findClock(ctx.VARIABLE(0).getText());
- Relation relation = Relation.fromString(operator);
-
- if(ctx.VARIABLE().size() > 1){
- Clock clock_j = findClock(ctx.VARIABLE(1).getText());
- return new ClockGuard(clock_i, clock_j, value, relation);
- }else {
- return new ClockGuard(clock_i, value, relation);
- }
- }
-
- @Override
- public Guard visitBoolExpr(GuardGrammarParser.BoolExprContext ctx) {
- boolean value = Boolean.parseBoolean(ctx.BOOLEAN().getText());
- String operator = ctx.OPERATOR().getText();
- BoolVar bv = findBV(ctx.VARIABLE().getText());
-
- return new BoolGuard(bv, operator, value);
- }
- }
-}
diff --git a/src/parser/JSONParser.java b/src/parser/JSONParser.java
index 293b878b..56be1238 100644
--- a/src/parser/JSONParser.java
+++ b/src/parser/JSONParser.java
@@ -220,8 +220,8 @@ private static List addLocations(JSONArray locationList) {
boolean isNotUrgent = "NORMAL".equals(jsonObject.get("urgency").toString());
- Guard invariant = ("".equals(jsonObject.get("invariant").toString()) ? new TrueGuard() :
- GuardParser.parse(jsonObject.get("invariant").toString(), componentClocks, BVs));
+ Expression invariant = ("".equals(jsonObject.get("invariant").toString()) ? new TrueExpression() :
+ ExpressionParser.parse(jsonObject.get("invariant").toString(), componentClocks, BVs));
Location loc = Location.create(jsonObject.get("id").toString(), invariant, isInitial, !isNotUrgent,
isUniversal, isInconsistent);
@@ -251,16 +251,16 @@ private static List addEdges(JSONArray edgeList, List locations)
for (Object obj : edgeList) {
JSONObject jsonObject = (JSONObject) obj;
- Guard guards;
+ Expression guards;
List clockUpdates = new ArrayList<>();
List boolUpdates = new ArrayList<>();
List updates;
if (!jsonObject.get("guard").toString().equals("")) {
- guards = GuardParser.parse((String) jsonObject.get("guard"), componentClocks, BVs);
+ guards = ExpressionParser.parse((String) jsonObject.get("guard"), componentClocks, BVs);
} else
- guards = new TrueGuard();
+ guards = new TrueExpression();
if (!jsonObject.get("update").toString().equals(""))
updates = UpdateParser.parse((String) jsonObject.get("update"), componentClocks, BVs);
diff --git a/src/parser/XMLFileWriter.java b/src/parser/XMLFileWriter.java
index 3d764ffb..e4af18dc 100644
--- a/src/parser/XMLFileWriter.java
+++ b/src/parser/XMLFileWriter.java
@@ -140,7 +140,7 @@ public static Element processAutomaton(String filename, Automaton automaton )
Element invarLabel = new Element("label");
invarLabel.setAttribute("kind", "invariant");
- String guardString = l.getInvariantGuard().toString();
+ String guardString = l.getInvariant().toString();
/* int j=0;
for (List list: l.getInvariant()) {
int i = 0;
diff --git a/src/parser/XMLParser.java b/src/parser/XMLParser.java
index e075c475..cd1db7c4 100644
--- a/src/parser/XMLParser.java
+++ b/src/parser/XMLParser.java
@@ -167,7 +167,7 @@ private static List setLocations(Element el, List clocks, List<
String locName = loc.getAttributeValue("id");
boolean isInitial = locName.equals(initId);
List labels = loc.getChildren("label");
- Guard invariants = new TrueGuard();
+ Expression invariants = new TrueExpression();
int x=0,y=0;
boolean xyDefined = false;
@@ -181,9 +181,9 @@ private static List setLocations(Element el, List clocks, List<
for (Element label : labels) {
if (label.getAttributeValue("kind").equals("invariant")) {
if (!label.getText().isEmpty())
- invariants = GuardParser.parse(label.getText(), clocks, BVs);
+ invariants = ExpressionParser.parse(label.getText(), clocks, BVs);
else
- invariants = new TrueGuard();
+ invariants = new TrueExpression();
}
}
@@ -238,7 +238,7 @@ private static List setEdges(Element el, List clocks, List
Location target = findLocations(locations, edge.getChild("target").getAttributeValue("ref"));
List labels = edge.getChildren("label");
- Guard guards = new TrueGuard();
+ Expression guards = new TrueExpression();
List updates = new ArrayList<>();
Channel chan = null;
@@ -249,7 +249,7 @@ private static List setEdges(Element el, List clocks, List
switch (kind) {
case "guard":
if (!text.isEmpty()) {
- guards = GuardParser.parse(text, clocks, BVs);
+ guards = ExpressionParser.parse(text, clocks, BVs);
}
break;
case "synchronisation":
diff --git a/test/cdd/CDDTest.java b/test/cdd/CDDTest.java
index 44ff5529..952ac346 100644
--- a/test/cdd/CDDTest.java
+++ b/test/cdd/CDDTest.java
@@ -41,21 +41,21 @@ public void testConjunctionSameTypeWithOverlap() throws CddNotRunningException,
CDD cdd2 = CDD.createInterval(2,1,4,true,6, true);
CDD cdd3 = cdd1.conjunction(cdd2);
- Log.debug(cdd2.getGuard(clocks));
+ Log.debug(cdd2.getExpression(clocks));
- Guard g1 = new ClockGuard(b,a,3,Relation.LESS_EQUAL );
- Guard g2 = new ClockGuard(a,b,5,Relation.LESS_EQUAL );
+ Expression g1 = new ClockExpression(b,a,3,Relation.LESS_EQUAL );
+ Expression g2 = new ClockExpression(a,b,5,Relation.LESS_EQUAL );
- Guard g3 = new ClockGuard(b,a,4,Relation.LESS_EQUAL );
- Guard g4 = new ClockGuard(a,b,6,Relation.LESS_EQUAL );
+ Expression g3 = new ClockExpression(b,a,4,Relation.LESS_EQUAL );
+ Expression g4 = new ClockExpression(a,b,6,Relation.LESS_EQUAL );
- List guardList = new ArrayList<>();
- guardList.add(g1);
- guardList.add(g2);
- guardList.add(g3);
- guardList.add(g4);
+ List expressionList = new ArrayList<>();
+ expressionList.add(g1);
+ expressionList.add(g2);
+ expressionList.add(g3);
+ expressionList.add(g4);
- Log.debug(new CDD(new AndGuard(guardList)).getGuard(clocks));
+ Log.debug(new CDD(new AndExpression(expressionList)).getExpression(clocks));
// TODO: Make sense of how exactly the interval works, and make a good asser statement
cdd1.free();
@@ -281,21 +281,21 @@ public void guardToCDDTest() throws CddNotRunningException, CddAlreadyRunningExc
CDD.addClocks(clocks);
- Guard e2_g1 = new ClockGuard(x, null, 3, Relation.GREATER_EQUAL);
+ Expression e2_g1 = new ClockExpression(x, null, 3, Relation.GREATER_EQUAL);
//Guard e2_g3 = new ClockGuard(x, null, 999, Relation.LESS_THAN);
- Guard e2_g2 = new ClockGuard(y, null, 5, Relation.LESS_EQUAL);
+ Expression e2_g2 = new ClockExpression(y, null, 5, Relation.LESS_EQUAL);
- List g1 = new ArrayList<>();
+ List g1 = new ArrayList<>();
// g1.add(new AndGuard(e2_g1, e2_g3));
g1.add(e2_g1);
g1.add(e2_g2);
- CDD res = new CDD(new OrGuard(g1));
+ CDD res = new CDD(new OrExpression(g1));
//res.printDot();
CDD exp = CDD.cddTrue();
exp = exp.conjunction(CDD.createInterval(1, 0, 3, true, CDD_INF/2, false));
exp = exp.disjunction(CDD.createInterval(2, 0, 0,true, 5,true));
- Log.debug(exp.removeNegative().reduce().getGuard(clocks));
- Log.debug(res.removeNegative().reduce().getGuard(clocks));
+ Log.debug(exp.removeNegative().reduce().getExpression(clocks));
+ Log.debug(res.removeNegative().reduce().getExpression(clocks));
//exp.printDot();
exp = exp.removeNegative().reduce();
res = res.removeNegative().reduce();
diff --git a/test/dbm/DBMTest.java b/test/dbm/DBMTest.java
index 31acf902..abd465c6 100644
--- a/test/dbm/DBMTest.java
+++ b/test/dbm/DBMTest.java
@@ -18,7 +18,7 @@
public class DBMTest {
private static final int DBM_INF = 2147483646;
private static State state1, state2, state3, state4, state5;
- private static Guard g1, g2, g3, g4, g5, g6, g7, g8;
+ private static Expression g1, g2, g3, g4, g5, g6, g7, g8;
private static List clockList = new ArrayList<>();
private static Clock x,y,z;
@@ -30,7 +30,7 @@ public void afterEachTest(){
@BeforeClass
public static void setUpBeforeClass() {
- Location l1 = Location.create("L0", new TrueGuard(), false, false, false, false, 0, 0);
+ Location l1 = Location.create("L0", new TrueExpression(), false, false, false, false, 0, 0);
Location sl1 = l1.copy();
x = new Clock("x", "AUT");
@@ -63,13 +63,13 @@ public static void setUpBeforeClass() {
// GUARDS---------------------
- g1 = new ClockGuard(x, 5, Relation.GREATER_EQUAL);
- g2 = new ClockGuard(x, 1, Relation.GREATER_EQUAL);
- g3 = new ClockGuard(x, 7, Relation.LESS_EQUAL);
- g4 = new ClockGuard(x, 14, Relation.LESS_EQUAL);
+ g1 = new ClockExpression(x, 5, Relation.GREATER_EQUAL);
+ g2 = new ClockExpression(x, 1, Relation.GREATER_EQUAL);
+ g3 = new ClockExpression(x, 7, Relation.LESS_EQUAL);
+ g4 = new ClockExpression(x, 14, Relation.LESS_EQUAL);
- g5 = new ClockGuard(x, 505, Relation.GREATER_EQUAL);
- g6 = new ClockGuard(y, 8, Relation.GREATER_EQUAL);
+ g5 = new ClockExpression(x, 505, Relation.GREATER_EQUAL);
+ g6 = new ClockExpression(y, 8, Relation.GREATER_EQUAL);
CDD.done();
}
@@ -115,11 +115,11 @@ public void testExtrapolate() {
map.put(x,12);
map.put(y,10);
- Guard g2 = new ClockGuard(x,null, 20,Relation.LESS_EQUAL);
- Guard g3 = new ClockGuard(y,null, 2,Relation.LESS_EQUAL);
- Guard initialZone = new AndGuard(g2,g3);
+ Expression g2 = new ClockExpression(x,null, 20,Relation.LESS_EQUAL);
+ Expression g3 = new ClockExpression(y,null, 2,Relation.LESS_EQUAL);
+ Expression initialZone = new AndExpression(g2,g3);
- Location l1 = Location.create("L1",new TrueGuard(),true,false,false,false, 0, 0);
+ Location l1 = Location.create("L1",new TrueExpression(),true,false,false,false, 0, 0);
State state1 = new State(l1.copy(), new CDD(initialZone));
//state1.delay();
Log.trace(state1);
diff --git a/test/features/BoolTest.java b/test/features/BoolTest.java
index 82b2645e..5bc2293d 100644
--- a/test/features/BoolTest.java
+++ b/test/features/BoolTest.java
@@ -74,20 +74,20 @@ public void testBoolArray() {
BoolVar c = new BoolVar("c", "aut", true);
List BVs = new ArrayList<>();
BVs.add(a); BVs.add(b); BVs.add(c);
- BoolGuard bg_a_false = new BoolGuard(a, "==",false);
- BoolGuard bg_b_false = new BoolGuard(b, "==",false);
- BoolGuard bg_a_true = new BoolGuard(a, "==",true);
- BoolGuard bg_b_true = new BoolGuard(b, "==",true);
- BoolGuard bg_c_true = new BoolGuard(c, "==",true);
- BoolGuard bg_c_false = new BoolGuard(c, "==",false);
- List l1 = new ArrayList<>(List.of(bg_a_true,bg_b_false,bg_c_false));
+ BoolExpression bg_a_false = new BoolExpression(a, "==",false);
+ BoolExpression bg_b_false = new BoolExpression(b, "==",false);
+ BoolExpression bg_a_true = new BoolExpression(a, "==",true);
+ BoolExpression bg_b_true = new BoolExpression(b, "==",true);
+ BoolExpression bg_c_true = new BoolExpression(c, "==",true);
+ BoolExpression bg_c_false = new BoolExpression(c, "==",false);
+ List l1 = new ArrayList<>(List.of(bg_a_true,bg_b_false,bg_c_false));
// List l2 = new ArrayList<>(List.of(bg_a_true,bg_b_true,bg_c_false));
// List l3 = new ArrayList<>(List.of(bg_a_false,bg_b_true,bg_c_false));
- List> list = new ArrayList();
+ List> list = new ArrayList();
list.add(l1); //list.add(l2); list.add(l3);
CDD.init(CDD.maxSize,CDD.cs,CDD.stackSize);
CDD.addBooleans(BVs);
- CDD cdd =new CDD(new AndGuard(l1));
+ CDD cdd =new CDD(new AndExpression(l1));
BDDArrays bddArr = new BDDArrays(CDDLib.bddToArray(cdd.getPointer(),BVs.size()));
Log.debug(bddArr.getValues());
Log.debug(bddArr.getVariables());
@@ -107,19 +107,19 @@ public void testBooleanSimplification() {
BoolVar c = new BoolVar("c", "aut", true);
List BVs = new ArrayList<>();
BVs.add(a); BVs.add(b); BVs.add(c);
- BoolGuard bg_a_false = new BoolGuard(a, "==",false);
- BoolGuard bg_b_false = new BoolGuard(b, "==",false);
- BoolGuard bg_a_true = new BoolGuard(a, "==",true);
- BoolGuard bg_b_true = new BoolGuard(b, "==",true);
- BoolGuard bg_c_true = new BoolGuard(c, "==",true);
- BoolGuard bg_c_false = new BoolGuard(c, "==",false);
- Guard l1 = new AndGuard(bg_a_true,bg_b_false,bg_c_false);
- Guard l2 = new AndGuard(bg_a_true,bg_b_true,bg_c_false);
- Guard l3 = new AndGuard(bg_a_false,bg_b_true,bg_c_false);
+ BoolExpression bg_a_false = new BoolExpression(a, "==",false);
+ BoolExpression bg_b_false = new BoolExpression(b, "==",false);
+ BoolExpression bg_a_true = new BoolExpression(a, "==",true);
+ BoolExpression bg_b_true = new BoolExpression(b, "==",true);
+ BoolExpression bg_c_true = new BoolExpression(c, "==",true);
+ BoolExpression bg_c_false = new BoolExpression(c, "==",false);
+ Expression l1 = new AndExpression(bg_a_true,bg_b_false,bg_c_false);
+ Expression l2 = new AndExpression(bg_a_true,bg_b_true,bg_c_false);
+ Expression l3 = new AndExpression(bg_a_false,bg_b_true,bg_c_false);
CDD.init(CDD.maxSize,CDD.cs,CDD.stackSize);
CDD.addBooleans(BVs);
- Log.debug("or guard " + new OrGuard(l1,l2,l3));
- CDD cdd =new CDD(new OrGuard(l1,l2,l3));
+ Log.debug("or guard " + new OrExpression(l1,l2,l3));
+ CDD cdd =new CDD(new OrExpression(l1,l2,l3));
cdd.printDot();
Log.debug( l1 + " " + l2 + " " + l3 + " " + cdd);
//assert(cdd.toString().equals("[[(a==true), (b==false), (c==false)], [(a==true), (b==true), (c==false)], [(a==false), (b==true), (c==false)]]"));
@@ -136,30 +136,30 @@ public void testTwoEdgesWithDifferentBool() {
BVs.add(a); BVs.add(b);
List noUpdate = new ArrayList<>();
- List> noguard = new ArrayList<>();
- List emptyBoolGuards = new ArrayList<>();
+ List> noguard = new ArrayList<>();
+ List emptyBoolExpressions = new ArrayList<>();
BoolUpdate[] emptyBoolUpdates = new BoolUpdate[]{};
- ClockGuard g1 = new ClockGuard(x, 10, Relation.LESS_EQUAL);
- ClockGuard g2 = new ClockGuard(x, 5, Relation.GREATER_EQUAL);
- ClockGuard g3 = new ClockGuard(y, 3, Relation.LESS_EQUAL);
- ClockGuard g4 = new ClockGuard(y, 2, Relation.GREATER_EQUAL);
+ ClockExpression g1 = new ClockExpression(x, 10, Relation.LESS_EQUAL);
+ ClockExpression g2 = new ClockExpression(x, 5, Relation.GREATER_EQUAL);
+ ClockExpression g3 = new ClockExpression(y, 3, Relation.LESS_EQUAL);
+ ClockExpression g4 = new ClockExpression(y, 2, Relation.GREATER_EQUAL);
- ClockGuard g5= new ClockGuard(x, 6, Relation.LESS_EQUAL);
- ClockGuard g6 = new ClockGuard(x, 1, Relation.GREATER_EQUAL);
- ClockGuard g7 = new ClockGuard(y, 7, Relation.LESS_EQUAL);
- ClockGuard g8 = new ClockGuard(y, 6, Relation.GREATER_EQUAL);
+ ClockExpression g5= new ClockExpression(x, 6, Relation.LESS_EQUAL);
+ ClockExpression g6 = new ClockExpression(x, 1, Relation.GREATER_EQUAL);
+ ClockExpression g7 = new ClockExpression(y, 7, Relation.LESS_EQUAL);
+ ClockExpression g8 = new ClockExpression(y, 6, Relation.GREATER_EQUAL);
- BoolGuard bg1 = new BoolGuard(a, "==",false);
- BoolGuard bg2 = new BoolGuard(b, "==",false);
- List boolGuards1 = new ArrayList<>();
- List boolGuards2 = new ArrayList<>();
+ BoolExpression bg1 = new BoolExpression(a, "==",false);
+ BoolExpression bg2 = new BoolExpression(b, "==",false);
+ List boolGuards1 = new ArrayList<>();
+ List boolGuards2 = new ArrayList<>();
boolGuards1.add(bg1);
boolGuards2.add(bg2);
- List> guards1 = new ArrayList<>();
- List inner = new ArrayList<>();
+ List> guards1 = new ArrayList<>();
+ List inner = new ArrayList<>();
inner.add(g1);
inner.add(g2);
inner.add(g3);
@@ -167,8 +167,8 @@ public void testTwoEdgesWithDifferentBool() {
inner.addAll(boolGuards1);
guards1.add(inner);
- List> guards2 = new ArrayList<>();
- List inner1 = new ArrayList<>();
+ List> guards2 = new ArrayList<>();
+ List inner1 = new ArrayList<>();
inner1.add(g5);
inner1.add(g6);
inner1.add(g7);
@@ -176,13 +176,13 @@ public void testTwoEdgesWithDifferentBool() {
inner1.addAll(boolGuards2);
guards2.add(inner1);
- Location l0 = Location.create("L0", new TrueGuard(), true, false, false, false, 0, 0);
- Location l1 = Location.create("L1", new TrueGuard(), false, false, false, false, 0, 0);
+ Location l0 = Location.create("L0", new TrueExpression(), true, false, false, false, 0, 0);
+ Location l1 = Location.create("L1", new TrueExpression(), false, false, false, false, 0, 0);
Channel i1 = new Channel("i1");
- Edge e0 = new Edge(l0, l1, i1, true, new AndGuard(inner), noUpdate);
- Edge e1 = new Edge(l0, l1, i1, true, new AndGuard(inner1), noUpdate);
+ Edge e0 = new Edge(l0, l1, i1, true, new AndExpression(inner), noUpdate);
+ Edge e1 = new Edge(l0, l1, i1, true, new AndExpression(inner1), noUpdate);
List locations = new ArrayList<>();
locations.add(l0);
@@ -203,8 +203,8 @@ public void testTwoEdgesWithDifferentBool() {
CDD.init(CDD.maxSize,CDD.cs,CDD.stackSize);
CDD.addClocks(clocks);
CDD.addBooleans(BVs);
- CDD origin1 = new CDD(new AndGuard(inner));
- CDD origin2 = new CDD(new AndGuard(inner1));
+ CDD origin1 = new CDD(new AndExpression(inner));
+ CDD origin2 = new CDD(new AndExpression(inner1));
CDD bothOrigins = origin1.disjunction(origin2);
Automaton aut = new Automaton("Automaton", locations, edges, clocks, bools,false);
@@ -234,27 +234,27 @@ public void testOverlappingZonesWithDifferentBool() {
bools.add(b);
List noUpdate = new ArrayList<>();
- List> noguard = new ArrayList<>();
+ List> noguard = new ArrayList<>();
- ClockGuard g1 = new ClockGuard(x, 10, Relation.LESS_EQUAL);
- ClockGuard g2 = new ClockGuard(x, 5, Relation.GREATER_EQUAL);
- ClockGuard g3 = new ClockGuard(y, 3, Relation.LESS_EQUAL);
- ClockGuard g4 = new ClockGuard(y, 2, Relation.GREATER_EQUAL);
+ ClockExpression g1 = new ClockExpression(x, 10, Relation.LESS_EQUAL);
+ ClockExpression g2 = new ClockExpression(x, 5, Relation.GREATER_EQUAL);
+ ClockExpression g3 = new ClockExpression(y, 3, Relation.LESS_EQUAL);
+ ClockExpression g4 = new ClockExpression(y, 2, Relation.GREATER_EQUAL);
- ClockGuard g5= new ClockGuard(x, 6, Relation.LESS_EQUAL);
- ClockGuard g6 = new ClockGuard(x, 1, Relation.GREATER_EQUAL);
- ClockGuard g7 = new ClockGuard(y, 7, Relation.LESS_EQUAL);
- ClockGuard g8 = new ClockGuard(y, 6, Relation.GREATER_EQUAL);
+ ClockExpression g5= new ClockExpression(x, 6, Relation.LESS_EQUAL);
+ ClockExpression g6 = new ClockExpression(x, 1, Relation.GREATER_EQUAL);
+ ClockExpression g7 = new ClockExpression(y, 7, Relation.LESS_EQUAL);
+ ClockExpression g8 = new ClockExpression(y, 6, Relation.GREATER_EQUAL);
- BoolGuard bg_a_false = new BoolGuard(a, "==",false);
- BoolGuard bg_b_false = new BoolGuard(b, "==",false);
- BoolGuard bg_a_true = new BoolGuard(a, "==",true);
- BoolGuard bg_b_true = new BoolGuard(b, "==",true);
+ BoolExpression bg_a_false = new BoolExpression(a, "==",false);
+ BoolExpression bg_b_false = new BoolExpression(b, "==",false);
+ BoolExpression bg_a_true = new BoolExpression(a, "==",true);
+ BoolExpression bg_b_true = new BoolExpression(b, "==",true);
- List boolGuards1 = new ArrayList<>();
- List