From 7411385e4aef631376a5b647e9bc1b27f625a964 Mon Sep 17 00:00:00 2001 From: nagilooh Date: Thu, 24 Aug 2023 18:57:39 +0200 Subject: Add new transformation rule actions - TransformationActions can be created after creating the model - equivalence of actions can be checked --- .../store/dse/DesignSpaceExplorationAdapter.java | 3 + .../DesignSpaceExplorationAdapterImpl.java | 7 ++ .../store/dse/internal/action/ActionSymbol.java | 7 ++ .../dse/internal/action/ActivationSymbol.java | 51 ++++++++++++ .../store/dse/internal/action/AtomicAction.java | 11 +++ .../store/dse/internal/action/DeleteAction.java | 27 +++++++ .../store/dse/internal/action/InsertAction.java | 65 +++++++++++++++ .../store/dse/internal/action/NewItemSymbol.java | 40 ++++++++++ .../dse/internal/action/TransformationAction.java | 93 ++++++++++++++++++++++ 9 files changed, 304 insertions(+) create mode 100644 subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActionSymbol.java create mode 100644 subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActivationSymbol.java create mode 100644 subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/AtomicAction.java create mode 100644 subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/DeleteAction.java create mode 100644 subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/InsertAction.java create mode 100644 subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/NewItemSymbol.java create mode 100644 subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/TransformationAction.java (limited to 'subprojects/store-dse/src/main/java/tools') diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/DesignSpaceExplorationAdapter.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/DesignSpaceExplorationAdapter.java index 5aed5298..ab87ddd5 100644 --- a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/DesignSpaceExplorationAdapter.java +++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/DesignSpaceExplorationAdapter.java @@ -6,6 +6,7 @@ package tools.refinery.store.dse; import tools.refinery.store.adapter.ModelAdapter; +import tools.refinery.store.dse.internal.TransformationRule; import tools.refinery.store.map.Version; import tools.refinery.store.dse.internal.Activation; import tools.refinery.store.dse.internal.DesignSpaceExplorationBuilderImpl; @@ -65,4 +66,6 @@ public interface DesignSpaceExplorationAdapter extends ModelAdapter { public void setRandom(long seed); public List getSolutions(); + + void addTransformationRule(TransformationRule transformationRule); } diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/DesignSpaceExplorationAdapterImpl.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/DesignSpaceExplorationAdapterImpl.java index 220f0b2d..0a5cd7fc 100644 --- a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/DesignSpaceExplorationAdapterImpl.java +++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/DesignSpaceExplorationAdapterImpl.java @@ -13,6 +13,7 @@ import tools.refinery.store.map.Version; import tools.refinery.store.model.Interpretation; import tools.refinery.store.model.Model; import tools.refinery.store.query.ModelQueryAdapter; +import tools.refinery.store.query.dnf.Query; import tools.refinery.store.query.dnf.RelationalQuery; import tools.refinery.store.dse.DesignSpaceExplorationAdapter; import tools.refinery.store.dse.DesignSpaceExplorationStoreAdapter; @@ -77,6 +78,12 @@ public class DesignSpaceExplorationAdapterImpl implements DesignSpaceExploration } + @Override + public void addTransformationRule(TransformationRule rule) { + transformationRules.add(rule); + rule.prepare(model, queryEngine); + } + public List getTrajectory() { return new ArrayList<>(trajectory); } diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActionSymbol.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActionSymbol.java new file mode 100644 index 00000000..a63f60f0 --- /dev/null +++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActionSymbol.java @@ -0,0 +1,7 @@ +package tools.refinery.store.dse.internal.action; + +import tools.refinery.store.tuple.Tuple; + +public abstract class ActionSymbol implements AtomicAction { + public abstract Tuple getValue(Tuple activation); +} diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActivationSymbol.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActivationSymbol.java new file mode 100644 index 00000000..181a5020 --- /dev/null +++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActivationSymbol.java @@ -0,0 +1,51 @@ +package tools.refinery.store.dse.internal.action; + +import tools.refinery.store.model.Model; +import tools.refinery.store.tuple.Tuple; + +public class ActivationSymbol extends ActionSymbol { + + private final int index; + private Tuple value = null; + + public ActivationSymbol() { + this(0); + } + + public ActivationSymbol(int index) { + this.index = index; + } + + @Override + public void fire(Tuple activation) { + value = Tuple.of(activation.get(index)); + } + + @Override + public ActivationSymbol prepare(Model model) { + return this; + } + + @Override + public Tuple getValue(Tuple activation) { + return value; + } + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof ActivationSymbol)) { + return false; + } + return index == ((ActivationSymbol) obj).index; + } + + @Override + public int hashCode() { + int result = 17; + result = 31 * result + Integer.hashCode(index); + return result; + } +} diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/AtomicAction.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/AtomicAction.java new file mode 100644 index 00000000..19de644a --- /dev/null +++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/AtomicAction.java @@ -0,0 +1,11 @@ +package tools.refinery.store.dse.internal.action; + +import tools.refinery.store.model.Model; +import tools.refinery.store.tuple.Tuple; + +public interface AtomicAction { + + void fire(Tuple activation); + + AtomicAction prepare(Model model); +} diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/DeleteAction.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/DeleteAction.java new file mode 100644 index 00000000..589a33c4 --- /dev/null +++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/DeleteAction.java @@ -0,0 +1,27 @@ +package tools.refinery.store.dse.internal.action; + +import tools.refinery.store.dse.DesignSpaceExplorationAdapter; +import tools.refinery.store.model.Model; +import tools.refinery.store.tuple.Tuple; + +public class DeleteAction implements AtomicAction { + + private final ActionSymbol symbol; + private DesignSpaceExplorationAdapter dseAdapter; + + public DeleteAction(ActionSymbol symbol) { + this.symbol = symbol; + } + + @Override + public void fire(Tuple activation) { + dseAdapter.deleteObject(symbol.getValue(activation)); + } + + + @Override + public DeleteAction prepare(Model model) { + dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); + return this; + } +} diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/InsertAction.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/InsertAction.java new file mode 100644 index 00000000..5c02bd45 --- /dev/null +++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/InsertAction.java @@ -0,0 +1,65 @@ +package tools.refinery.store.dse.internal.action; + +import tools.refinery.store.model.Interpretation; +import tools.refinery.store.model.Model; +import tools.refinery.store.tuple.Tuple; + +import java.util.Arrays; + +public class InsertAction implements AtomicAction { + + private final Interpretation interpretation; + private final T value; + + private final ActionSymbol[] symbols; + + public InsertAction(Interpretation interpretation, T value, ActionSymbol... symbols) { + this.interpretation = interpretation; + this.value = value; + this.symbols = symbols; + + } + + @Override + public void fire(Tuple activation) { + var tuple = Tuple.of(Arrays.stream(symbols).map(symbol -> symbol.getValue(activation).get(0)) + .mapToInt(Integer::intValue).toArray()); + + interpretation.put(tuple, value); + } + + @Override + public InsertAction prepare(Model model) { + return this; + } + + public ActionSymbol[] getSymbols() { + return symbols; + } + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof InsertAction other)) { + return false; + } + if (symbols.length != other.symbols.length) { + return false; + } + if (!interpretation.equals(other.interpretation)) { + return false; + } + return value.equals(other.value); + } + + @Override + public int hashCode() { + int result = 17; + result = 31 * result + Integer.hashCode(symbols.length); + result = 31 * result + interpretation.hashCode(); + result = 31 * result + value.hashCode(); + return result; + } +} diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/NewItemSymbol.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/NewItemSymbol.java new file mode 100644 index 00000000..3c69b9a0 --- /dev/null +++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/NewItemSymbol.java @@ -0,0 +1,40 @@ +package tools.refinery.store.dse.internal.action; + +import tools.refinery.store.dse.DesignSpaceExplorationAdapter; +import tools.refinery.store.model.Model; +import tools.refinery.store.tuple.Tuple; +import tools.refinery.store.tuple.Tuple1; + +public class NewItemSymbol extends ActionSymbol { + private DesignSpaceExplorationAdapter dseAdapter; + private Tuple1 value; + + @Override + public void fire(Tuple activation) { + value = dseAdapter.createObject(); + } + + @Override + public NewItemSymbol prepare(Model model) { + dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); + return this; + } + + @Override + public Tuple1 getValue(Tuple activation) { + return value; + } + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + return obj instanceof NewItemSymbol; + } + + @Override + public int hashCode() { + return 42; + } +} diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/TransformationAction.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/TransformationAction.java new file mode 100644 index 00000000..2e58a8c4 --- /dev/null +++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/TransformationAction.java @@ -0,0 +1,93 @@ +package tools.refinery.store.dse.internal.action; + +import tools.refinery.store.model.Model; +import tools.refinery.store.tuple.Tuple; +import tools.refinery.store.tuple.Tuple2; + +import java.util.*; + +public class TransformationAction { + private final List actionSymbols = new ArrayList<>(); + private final List> insertActions = new ArrayList<>(); + private boolean configured = false; + private final Map> activationSymbolUsageMap = new LinkedHashMap<>(); + + public TransformationAction add(ActionSymbol action) { + checkConfigured(); + actionSymbols.add(action); + return this; + } + + public TransformationAction add(InsertAction action) { + checkConfigured(); + insertActions.add(action); + return this; + } + + private void checkConfigured() { + if (configured) { + throw new IllegalStateException("Action already configured."); + } + } + + public TransformationAction prepare(Model model) { + for (ActionSymbol action : actionSymbols) { + action.prepare(model); + } + for (InsertAction action : insertActions) { + action.prepare(model); + } + + for (var insertAction : insertActions) { + var actionIndex = insertActions.indexOf(insertAction); + var symbols = insertAction.getSymbols(); + for (var i = 0; i < symbols.length; i++) { + var symbolGlobalIndex = actionSymbols.indexOf(symbols[i]); + activationSymbolUsageMap.computeIfAbsent(symbolGlobalIndex, k -> new ArrayList<>()); + activationSymbolUsageMap.get(symbolGlobalIndex).add(Tuple.of(actionIndex, i)); + } + } + + configured = true; + return this; + } + + public boolean fire(Tuple activation) { + for (ActionSymbol action : actionSymbols) { + action.fire(activation); + } + for (InsertAction action : insertActions) { + action.fire(activation); + } + return true; + } + + // True if Symbols and InsertActions are inserted in same order, ActivationSymbols are equal (they have the same + // index for getting the value from the activation Tuple) and InsertActions are equal (they have the same arity + // and value to be set). + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof TransformationAction other)) { + return false; + } + if (!actionSymbols.equals(other.actionSymbols)) { + return false; + } + if (!insertActions.equals(other.insertActions)) { + return false; + } + return this.activationSymbolUsageMap.equals(other.activationSymbolUsageMap); + + } + + @Override + public int hashCode() { + var result = 17; + result = 31 * result + actionSymbols.hashCode(); + result = 31 * result + insertActions.hashCode(); + return result; + } +} -- cgit v1.2.3-70-g09d2 From 96a6ea2aabe8f04915daf2a680683352148c2fa3 Mon Sep 17 00:00:00 2001 From: nagilooh Date: Fri, 25 Aug 2023 13:09:30 +0200 Subject: Add delete action and additional tests for equals --- .../dse/internal/action/ActivationSymbol.java | 14 +- .../store/dse/internal/action/DeleteAction.java | 19 +- .../store/dse/internal/action/InsertAction.java | 17 +- .../store/dse/internal/action/NewItemSymbol.java | 12 +- .../dse/internal/action/TransformationAction.java | 17 ++ .../tools/refinery/store/dse/ActionEqualsTest.java | 246 ++++++++++++++++++++- 6 files changed, 316 insertions(+), 9 deletions(-) (limited to 'subprojects/store-dse/src/main/java/tools') diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActivationSymbol.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActivationSymbol.java index 181a5020..7598de0a 100644 --- a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActivationSymbol.java +++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActivationSymbol.java @@ -6,7 +6,7 @@ import tools.refinery.store.tuple.Tuple; public class ActivationSymbol extends ActionSymbol { private final int index; - private Tuple value = null; + private Tuple value; public ActivationSymbol() { this(0); @@ -36,16 +36,24 @@ public class ActivationSymbol extends ActionSymbol { if (obj == this) { return true; } - if (!(obj instanceof ActivationSymbol)) { + if (!(obj instanceof ActivationSymbol other)) { return false; } - return index == ((ActivationSymbol) obj).index; + + if (index != other.index) { + return false; + } + if (value == null) { + return other.value == null; + } + return value.equals(other.value); } @Override public int hashCode() { int result = 17; result = 31 * result + Integer.hashCode(index); + result = 31 * result + value.hashCode(); return result; } } diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/DeleteAction.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/DeleteAction.java index 589a33c4..c7cc4600 100644 --- a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/DeleteAction.java +++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/DeleteAction.java @@ -18,10 +18,27 @@ public class DeleteAction implements AtomicAction { dseAdapter.deleteObject(symbol.getValue(activation)); } - @Override public DeleteAction prepare(Model model) { dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); return this; } + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof DeleteAction other)) { + return false; + } + return this.symbol.getClass() == other.symbol.getClass(); + } + + @Override + public int hashCode() { + int result = 17; + result = 31 * result + symbol.getClass().hashCode(); + return result; + } } diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/InsertAction.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/InsertAction.java index 5c02bd45..7adab93b 100644 --- a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/InsertAction.java +++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/InsertAction.java @@ -51,13 +51,26 @@ public class InsertAction implements AtomicAction { if (!interpretation.equals(other.interpretation)) { return false; } - return value.equals(other.value); + if (value == null) { + if (other.value != null) { + return false; + } + } + else if (!value.equals(other.value)) { + return false; + } + for (var i = 0; i < symbols.length; i++) { + if (!symbols[i].equals(other.symbols[i])) { + return false; + } + } + return true; } @Override public int hashCode() { int result = 17; - result = 31 * result + Integer.hashCode(symbols.length); + result = 31 * result + Arrays.hashCode(symbols); result = 31 * result + interpretation.hashCode(); result = 31 * result + value.hashCode(); return result; diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/NewItemSymbol.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/NewItemSymbol.java index 3c69b9a0..acdc3cae 100644 --- a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/NewItemSymbol.java +++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/NewItemSymbol.java @@ -30,11 +30,19 @@ public class NewItemSymbol extends ActionSymbol { if (obj == this) { return true; } - return obj instanceof NewItemSymbol; + if (!(obj instanceof NewItemSymbol other)) { + return false; + } + if (value == null) { + return other.value == null; + } + return value.equals(other.value); } @Override public int hashCode() { - return 42; + int result = 17; + result = 31 * result + value.hashCode(); + return result; } } diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/TransformationAction.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/TransformationAction.java index 2e58a8c4..19ab4575 100644 --- a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/TransformationAction.java +++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/TransformationAction.java @@ -9,6 +9,7 @@ import java.util.*; public class TransformationAction { private final List actionSymbols = new ArrayList<>(); private final List> insertActions = new ArrayList<>(); + private final List deleteActions = new ArrayList<>(); private boolean configured = false; private final Map> activationSymbolUsageMap = new LinkedHashMap<>(); @@ -24,6 +25,12 @@ public class TransformationAction { return this; } + public TransformationAction add(DeleteAction action) { + checkConfigured(); + deleteActions.add(action); + return this; + } + private void checkConfigured() { if (configured) { throw new IllegalStateException("Action already configured."); @@ -37,6 +44,9 @@ public class TransformationAction { for (InsertAction action : insertActions) { action.prepare(model); } + for (DeleteAction action : deleteActions) { + action.prepare(model); + } for (var insertAction : insertActions) { var actionIndex = insertActions.indexOf(insertAction); @@ -59,6 +69,9 @@ public class TransformationAction { for (InsertAction action : insertActions) { action.fire(activation); } + for (DeleteAction action : deleteActions) { + action.fire(activation); + } return true; } @@ -79,6 +92,9 @@ public class TransformationAction { if (!insertActions.equals(other.insertActions)) { return false; } + if (!deleteActions.equals(other.deleteActions)) { + return false; + } return this.activationSymbolUsageMap.equals(other.activationSymbolUsageMap); } @@ -88,6 +104,7 @@ public class TransformationAction { var result = 17; result = 31 * result + actionSymbols.hashCode(); result = 31 * result + insertActions.hashCode(); + result = 31 * result + deleteActions.hashCode(); return result; } } diff --git a/subprojects/store-dse/src/test/java/tools/refinery/store/dse/ActionEqualsTest.java b/subprojects/store-dse/src/test/java/tools/refinery/store/dse/ActionEqualsTest.java index d54bc7d3..e29260e9 100644 --- a/subprojects/store-dse/src/test/java/tools/refinery/store/dse/ActionEqualsTest.java +++ b/subprojects/store-dse/src/test/java/tools/refinery/store/dse/ActionEqualsTest.java @@ -124,7 +124,8 @@ public class ActionEqualsTest { void actionSymbolGlobalOrderTest() { var newItemSymbol1 = new NewItemSymbol(); var activationSymbol1 = new ActivationSymbol(); - var insertAction1 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1, activationSymbol1); + var insertAction1 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1, + activationSymbol1); var action1 = new TransformationAction(); action1.add(newItemSymbol1); @@ -388,4 +389,247 @@ public class ActionEqualsTest { assertNotEquals(action1, action2); } + + @Test + void deleteActionTest() { + var newItemSymbol = new NewItemSymbol(); + var activationSymbol = new ActivationSymbol(0); + var insertAction = new InsertAction<>(model.getInterpretation(type1), false, newItemSymbol, + activationSymbol); + var deleteAction = new DeleteAction(activationSymbol); + + var action1 = new TransformationAction(); + action1.add(newItemSymbol); + action1.add(activationSymbol); + action1.add(insertAction); + action1.add(deleteAction); + action1.prepare(model); + + var action2 = new TransformationAction(); + action2.add(newItemSymbol); + action2.add(activationSymbol); + action2.add(insertAction); + action2.add(deleteAction); + action2.prepare(model); + + assertEquals(action1, action2); + } + + @Test + void deleteActionMissingTest() { + var newItemSymbol = new NewItemSymbol(); + var activationSymbol = new ActivationSymbol(0); + var insertAction = new InsertAction<>(model.getInterpretation(type1), false, newItemSymbol, + activationSymbol); + var deleteAction = new DeleteAction(activationSymbol); + + var action1 = new TransformationAction(); + action1.add(newItemSymbol); + action1.add(activationSymbol); + action1.add(insertAction); + action1.add(deleteAction); + action1.prepare(model); + + var action2 = new TransformationAction(); + action2.add(newItemSymbol); + action2.add(activationSymbol); + action2.add(insertAction); + action2.prepare(model); + + assertNotEquals(action1, action2); + } + + @Test + void deleteActionIdenticalTest() { + var newItemSymbol = new NewItemSymbol(); + var activationSymbol = new ActivationSymbol(0); + var insertAction = new InsertAction<>(model.getInterpretation(type1), false, newItemSymbol, + activationSymbol); + var deleteAction1 = new DeleteAction(activationSymbol); + var deleteAction2 = new DeleteAction(activationSymbol); + + var action1 = new TransformationAction(); + action1.add(newItemSymbol); + action1.add(activationSymbol); + action1.add(insertAction); + action1.add(deleteAction1); + action1.prepare(model); + + var action2 = new TransformationAction(); + action2.add(newItemSymbol); + action2.add(activationSymbol); + action2.add(insertAction); + action2.add(deleteAction2); + action2.prepare(model); + + assertEquals(action1, action2); + } + + @Test + void deleteActionSymbolTypeTest() { + var newItemSymbol = new NewItemSymbol(); + var activationSymbol = new ActivationSymbol(0); + var insertAction = new InsertAction<>(model.getInterpretation(type1), false, newItemSymbol, + activationSymbol); + var deleteAction1 = new DeleteAction(activationSymbol); + var deleteAction2 = new DeleteAction(newItemSymbol); + + var action1 = new TransformationAction(); + action1.add(newItemSymbol); + action1.add(activationSymbol); + action1.add(insertAction); + action1.add(deleteAction1); + action1.prepare(model); + + var action2 = new TransformationAction(); + action2.add(newItemSymbol); + action2.add(activationSymbol); + action2.add(insertAction); + action2.add(deleteAction2); + action2.prepare(model); + + assertNotEquals(action1, action2); + } + + @Test + void deleteActionOrderTest() { + var newItemSymbol = new NewItemSymbol(); + var activationSymbol = new ActivationSymbol(0); + var insertAction = new InsertAction<>(model.getInterpretation(type1), false, newItemSymbol, + activationSymbol); + var deleteAction1 = new DeleteAction(activationSymbol); + var deleteAction2 = new DeleteAction(newItemSymbol); + + var action1 = new TransformationAction(); + action1.add(newItemSymbol); + action1.add(activationSymbol); + action1.add(insertAction); + action1.add(deleteAction1); + action1.add(deleteAction2); + action1.prepare(model); + + var action2 = new TransformationAction(); + action2.add(newItemSymbol); + action2.add(activationSymbol); + action2.add(insertAction); + action2.add(deleteAction2); + action2.add(deleteAction1); + action2.prepare(model); + + assertNotEquals(action1, action2); + } + + @Test + void actionsMixedOrderTest() { + var newItemSymbol1 = new NewItemSymbol(); + var activationSymbol1 = new ActivationSymbol(); + var insertAction1 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1, + activationSymbol1); + var deleteAction1 = new DeleteAction(newItemSymbol1); + + var newItemSymbol2 = new NewItemSymbol(); + var activationSymbol2 = new ActivationSymbol(); + var insertAction2 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol2, + activationSymbol2); + var deleteAction2 = new DeleteAction(activationSymbol2); + + var action1 = new TransformationAction(); + action1.add(newItemSymbol1); + action1.add(newItemSymbol2); + action1.add(activationSymbol1); + action1.add(activationSymbol2); + action1.add(insertAction1); + action1.add(insertAction2); + action1.add(deleteAction1); + action1.add(deleteAction2); + action1.prepare(model); + + var action2 = new TransformationAction(); + action2.add(deleteAction1); + action2.add(newItemSymbol1); + action2.add(insertAction1); + action2.add(newItemSymbol2); + action2.add(deleteAction2); + action2.add(activationSymbol1); + action2.add(insertAction2); + action2.add(activationSymbol2); + action2.prepare(model); + + assertEquals(action1, action2); + } + + @Test + void twoUnpreparedActionsTest() { + var newItemSymbol1 = new NewItemSymbol(); + var activationSymbol1 = new ActivationSymbol(); + var insertAction1 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1, + activationSymbol1); + var deleteAction1 = new DeleteAction(newItemSymbol1); + + var newItemSymbol2 = new NewItemSymbol(); + var activationSymbol2 = new ActivationSymbol(); + var insertAction2 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol2, + activationSymbol2); + var deleteAction2 = new DeleteAction(activationSymbol2); + + var action1 = new TransformationAction(); + action1.add(newItemSymbol1); + action1.add(newItemSymbol2); + action1.add(activationSymbol1); + action1.add(activationSymbol2); + action1.add(insertAction1); + action1.add(insertAction2); + action1.add(deleteAction1); + action1.add(deleteAction2); + + var action2 = new TransformationAction(); + action2.add(deleteAction1); + action2.add(newItemSymbol1); + action2.add(insertAction1); + action2.add(newItemSymbol2); + action2.add(deleteAction2); + action2.add(activationSymbol1); + action2.add(insertAction2); + action2.add(activationSymbol2); + + assertEquals(action1, action2); + } + + @Test + void oneUnpreparedActionTest() { + var newItemSymbol1 = new NewItemSymbol(); + var activationSymbol1 = new ActivationSymbol(); + var insertAction1 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1, + activationSymbol1); + var deleteAction1 = new DeleteAction(newItemSymbol1); + + var newItemSymbol2 = new NewItemSymbol(); + var activationSymbol2 = new ActivationSymbol(); + var insertAction2 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol2, + activationSymbol2); + var deleteAction2 = new DeleteAction(activationSymbol2); + + var action1 = new TransformationAction(); + action1.add(newItemSymbol1); + action1.add(newItemSymbol2); + action1.add(activationSymbol1); + action1.add(activationSymbol2); + action1.add(insertAction1); + action1.add(insertAction2); + action1.add(deleteAction1); + action1.add(deleteAction2); + action1.prepare(model); + + var action2 = new TransformationAction(); + action2.add(deleteAction1); + action2.add(newItemSymbol1); + action2.add(insertAction1); + action2.add(newItemSymbol2); + action2.add(deleteAction2); + action2.add(activationSymbol1); + action2.add(insertAction2); + action2.add(activationSymbol2); + + assertNotEquals(action1, action2); + } } -- cgit v1.2.3-70-g09d2 From 0b3f95bbc05d74b37d7c769bf76f38c25e4b1b73 Mon Sep 17 00:00:00 2001 From: nagilooh Date: Fri, 25 Aug 2023 17:04:43 +0200 Subject: Move equivalence checking to new method Also: - Rename Symbol to Variable - Make fire for InsertAction with low arity faster --- .../store/dse/internal/action/ActionSymbol.java | 7 - .../store/dse/internal/action/ActionVariable.java | 7 + .../dse/internal/action/ActivationSymbol.java | 59 ----- .../dse/internal/action/ActivationVariable.java | 49 ++++ .../store/dse/internal/action/AtomicAction.java | 2 + .../store/dse/internal/action/DeleteAction.java | 25 +- .../store/dse/internal/action/InsertAction.java | 69 +++--- .../store/dse/internal/action/NewItemSymbol.java | 48 ---- .../store/dse/internal/action/NewItemVariable.java | 40 ++++ .../dse/internal/action/TransformationAction.java | 76 ++++--- .../tools/refinery/store/dse/ActionEqualsTest.java | 253 ++++++++++----------- 11 files changed, 317 insertions(+), 318 deletions(-) delete mode 100644 subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActionSymbol.java create mode 100644 subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActionVariable.java delete mode 100644 subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActivationSymbol.java create mode 100644 subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActivationVariable.java delete mode 100644 subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/NewItemSymbol.java create mode 100644 subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/NewItemVariable.java (limited to 'subprojects/store-dse/src/main/java/tools') diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActionSymbol.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActionSymbol.java deleted file mode 100644 index a63f60f0..00000000 --- a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActionSymbol.java +++ /dev/null @@ -1,7 +0,0 @@ -package tools.refinery.store.dse.internal.action; - -import tools.refinery.store.tuple.Tuple; - -public abstract class ActionSymbol implements AtomicAction { - public abstract Tuple getValue(Tuple activation); -} diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActionVariable.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActionVariable.java new file mode 100644 index 00000000..51078d15 --- /dev/null +++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActionVariable.java @@ -0,0 +1,7 @@ +package tools.refinery.store.dse.internal.action; + +import tools.refinery.store.tuple.Tuple; + +public interface ActionVariable extends AtomicAction { + Tuple getValue(); +} diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActivationSymbol.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActivationSymbol.java deleted file mode 100644 index 7598de0a..00000000 --- a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActivationSymbol.java +++ /dev/null @@ -1,59 +0,0 @@ -package tools.refinery.store.dse.internal.action; - -import tools.refinery.store.model.Model; -import tools.refinery.store.tuple.Tuple; - -public class ActivationSymbol extends ActionSymbol { - - private final int index; - private Tuple value; - - public ActivationSymbol() { - this(0); - } - - public ActivationSymbol(int index) { - this.index = index; - } - - @Override - public void fire(Tuple activation) { - value = Tuple.of(activation.get(index)); - } - - @Override - public ActivationSymbol prepare(Model model) { - return this; - } - - @Override - public Tuple getValue(Tuple activation) { - return value; - } - - @Override - public boolean equals(Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof ActivationSymbol other)) { - return false; - } - - if (index != other.index) { - return false; - } - if (value == null) { - return other.value == null; - } - return value.equals(other.value); - } - - @Override - public int hashCode() { - int result = 17; - result = 31 * result + Integer.hashCode(index); - result = 31 * result + value.hashCode(); - return result; - } -} diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActivationVariable.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActivationVariable.java new file mode 100644 index 00000000..148d4156 --- /dev/null +++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActivationVariable.java @@ -0,0 +1,49 @@ +package tools.refinery.store.dse.internal.action; + +import tools.refinery.store.model.Model; +import tools.refinery.store.tuple.Tuple; + +public class ActivationVariable implements ActionVariable { + + private final int index; + private Tuple value; + + public ActivationVariable() { + this(0); + } + + public ActivationVariable(int index) { + this.index = index; + } + + @Override + public void fire(Tuple activation) { + value = Tuple.of(activation.get(index)); + } + + @Override + public ActivationVariable prepare(Model model) { + return this; + } + + @Override + public Tuple getValue() { + return value; + } + + @Override + public boolean equalsWithSubstitution(AtomicAction other) { + if (other == null || getClass() != other.getClass()) { + return false; + } + var otherAction = (ActivationVariable) other; + + if (index != otherAction.index) { + return false; + } + if (value == null) { + return otherAction.value == null; + } + return value.equals(otherAction.value); + } +} diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/AtomicAction.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/AtomicAction.java index 19de644a..470278ae 100644 --- a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/AtomicAction.java +++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/AtomicAction.java @@ -8,4 +8,6 @@ public interface AtomicAction { void fire(Tuple activation); AtomicAction prepare(Model model); + + boolean equalsWithSubstitution(AtomicAction other); } diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/DeleteAction.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/DeleteAction.java index c7cc4600..9fa77df3 100644 --- a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/DeleteAction.java +++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/DeleteAction.java @@ -6,16 +6,16 @@ import tools.refinery.store.tuple.Tuple; public class DeleteAction implements AtomicAction { - private final ActionSymbol symbol; + private final ActionVariable variable; private DesignSpaceExplorationAdapter dseAdapter; - public DeleteAction(ActionSymbol symbol) { - this.symbol = symbol; + public DeleteAction(ActionVariable variable) { + this.variable = variable; } @Override public void fire(Tuple activation) { - dseAdapter.deleteObject(symbol.getValue(activation)); + dseAdapter.deleteObject(variable.getValue()); } @Override @@ -25,20 +25,11 @@ public class DeleteAction implements AtomicAction { } @Override - public boolean equals(Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof DeleteAction other)) { + public boolean equalsWithSubstitution(AtomicAction other) { + if (other == null || getClass() != other.getClass()) { return false; } - return this.symbol.getClass() == other.symbol.getClass(); - } - - @Override - public int hashCode() { - int result = 17; - result = 31 * result + symbol.getClass().hashCode(); - return result; + var otherAction = (DeleteAction) other; + return this.variable.getClass() == otherAction.variable.getClass(); } } diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/InsertAction.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/InsertAction.java index 7adab93b..2335abad 100644 --- a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/InsertAction.java +++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/InsertAction.java @@ -3,6 +3,7 @@ package tools.refinery.store.dse.internal.action; import tools.refinery.store.model.Interpretation; import tools.refinery.store.model.Model; import tools.refinery.store.tuple.Tuple; +import tools.refinery.store.tuple.Tuple0; import java.util.Arrays; @@ -10,21 +11,42 @@ public class InsertAction implements AtomicAction { private final Interpretation interpretation; private final T value; + private final int arity; + private final ActionVariable[] variables; - private final ActionSymbol[] symbols; - - public InsertAction(Interpretation interpretation, T value, ActionSymbol... symbols) { + public InsertAction(Interpretation interpretation, T value, ActionVariable... variables) { this.interpretation = interpretation; this.value = value; - this.symbols = symbols; - + this.variables = variables; + this.arity = interpretation.getSymbol().arity(); + if (variables.length != arity) { + throw new IllegalArgumentException("Expected " + arity + " variables, but got " + variables.length); + } } @Override public void fire(Tuple activation) { - var tuple = Tuple.of(Arrays.stream(symbols).map(symbol -> symbol.getValue(activation).get(0)) - .mapToInt(Integer::intValue).toArray()); + Tuple tuple; + if (arity == 0) { + tuple = Tuple0.INSTANCE; + } + else if (arity == 1) { + tuple = variables[0].getValue(); + } + else if (arity == 2) { + tuple = Tuple.of(variables[0].getValue().get(0), variables[1].getValue().get(0)); + } + else if (arity == 3) { + tuple = Tuple.of(variables[0].getValue().get(0), variables[1].getValue().get(0), variables[2].getValue().get(0)); + } + else { + tuple = Tuple.of(Arrays.stream(variables).map(variable -> variable.getValue().get(0)) + .mapToInt(Integer::intValue).toArray()); + } + interpretation.put(tuple, value); + } + public void put(Tuple tuple) { interpretation.put(tuple, value); } @@ -33,46 +55,35 @@ public class InsertAction implements AtomicAction { return this; } - public ActionSymbol[] getSymbols() { - return symbols; + public ActionVariable[] getVariables() { + return variables; } @Override - public boolean equals(Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof InsertAction other)) { + public boolean equalsWithSubstitution(AtomicAction other) { + if (other == null || getClass() != other.getClass()) { return false; } - if (symbols.length != other.symbols.length) { + var otherAction = (InsertAction) other; + if (variables.length != otherAction.variables.length) { return false; } - if (!interpretation.equals(other.interpretation)) { + if (!interpretation.equals(otherAction.interpretation)) { return false; } if (value == null) { - if (other.value != null) { + if (otherAction.value != null) { return false; } } - else if (!value.equals(other.value)) { + else if (!value.equals(otherAction.value)) { return false; } - for (var i = 0; i < symbols.length; i++) { - if (!symbols[i].equals(other.symbols[i])) { + for (var i = 0; i < variables.length; i++) { + if (!variables[i].equalsWithSubstitution(otherAction.variables[i])) { return false; } } return true; } - - @Override - public int hashCode() { - int result = 17; - result = 31 * result + Arrays.hashCode(symbols); - result = 31 * result + interpretation.hashCode(); - result = 31 * result + value.hashCode(); - return result; - } } diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/NewItemSymbol.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/NewItemSymbol.java deleted file mode 100644 index acdc3cae..00000000 --- a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/NewItemSymbol.java +++ /dev/null @@ -1,48 +0,0 @@ -package tools.refinery.store.dse.internal.action; - -import tools.refinery.store.dse.DesignSpaceExplorationAdapter; -import tools.refinery.store.model.Model; -import tools.refinery.store.tuple.Tuple; -import tools.refinery.store.tuple.Tuple1; - -public class NewItemSymbol extends ActionSymbol { - private DesignSpaceExplorationAdapter dseAdapter; - private Tuple1 value; - - @Override - public void fire(Tuple activation) { - value = dseAdapter.createObject(); - } - - @Override - public NewItemSymbol prepare(Model model) { - dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); - return this; - } - - @Override - public Tuple1 getValue(Tuple activation) { - return value; - } - - @Override - public boolean equals(Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof NewItemSymbol other)) { - return false; - } - if (value == null) { - return other.value == null; - } - return value.equals(other.value); - } - - @Override - public int hashCode() { - int result = 17; - result = 31 * result + value.hashCode(); - return result; - } -} diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/NewItemVariable.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/NewItemVariable.java new file mode 100644 index 00000000..65b1f544 --- /dev/null +++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/NewItemVariable.java @@ -0,0 +1,40 @@ +package tools.refinery.store.dse.internal.action; + +import tools.refinery.store.dse.DesignSpaceExplorationAdapter; +import tools.refinery.store.model.Model; +import tools.refinery.store.tuple.Tuple; +import tools.refinery.store.tuple.Tuple1; + +public class NewItemVariable implements ActionVariable { + private DesignSpaceExplorationAdapter dseAdapter; + private Tuple1 value; + + @Override + public void fire(Tuple activation) { + value = dseAdapter.createObject(); + } + + @Override + public NewItemVariable prepare(Model model) { + dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); + return this; + } + + @Override + public Tuple1 getValue() { + return value; + } + + @Override + public boolean equalsWithSubstitution(AtomicAction other) { + if (other == null || getClass() != other.getClass()) { + return false; + } + var otherAction = (NewItemVariable) other; + if (value == null) { + return otherAction.value == null; + } + return value.equals(otherAction.value); + + } +} diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/TransformationAction.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/TransformationAction.java index 19ab4575..50387f53 100644 --- a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/TransformationAction.java +++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/TransformationAction.java @@ -7,15 +7,15 @@ import tools.refinery.store.tuple.Tuple2; import java.util.*; public class TransformationAction { - private final List actionSymbols = new ArrayList<>(); + private final List actionVariables = new ArrayList<>(); private final List> insertActions = new ArrayList<>(); private final List deleteActions = new ArrayList<>(); private boolean configured = false; - private final Map> activationSymbolUsageMap = new LinkedHashMap<>(); + private final Map> actionVariableUsageMap = new LinkedHashMap<>(); - public TransformationAction add(ActionSymbol action) { + public TransformationAction add(ActionVariable action) { checkConfigured(); - actionSymbols.add(action); + actionVariables.add(action); return this; } @@ -38,7 +38,7 @@ public class TransformationAction { } public TransformationAction prepare(Model model) { - for (ActionSymbol action : actionSymbols) { + for (ActionVariable action : actionVariables) { action.prepare(model); } for (InsertAction action : insertActions) { @@ -50,11 +50,11 @@ public class TransformationAction { for (var insertAction : insertActions) { var actionIndex = insertActions.indexOf(insertAction); - var symbols = insertAction.getSymbols(); - for (var i = 0; i < symbols.length; i++) { - var symbolGlobalIndex = actionSymbols.indexOf(symbols[i]); - activationSymbolUsageMap.computeIfAbsent(symbolGlobalIndex, k -> new ArrayList<>()); - activationSymbolUsageMap.get(symbolGlobalIndex).add(Tuple.of(actionIndex, i)); + var variables = insertAction.getVariables(); + for (var i = 0; i < variables.length; i++) { + var variablelGlobalIndex = actionVariables.indexOf(variables[i]); + actionVariableUsageMap.computeIfAbsent(variablelGlobalIndex, k -> new ArrayList<>()); + actionVariableUsageMap.get(variablelGlobalIndex).add(Tuple.of(actionIndex, i)); } } @@ -63,7 +63,7 @@ public class TransformationAction { } public boolean fire(Tuple activation) { - for (ActionSymbol action : actionSymbols) { + for (ActionVariable action : actionVariables) { action.fire(activation); } for (InsertAction action : insertActions) { @@ -75,36 +75,50 @@ public class TransformationAction { return true; } - // True if Symbols and InsertActions are inserted in same order, ActivationSymbols are equal (they have the same - // index for getting the value from the activation Tuple) and InsertActions are equal (they have the same arity - // and value to be set). - @Override - public boolean equals(Object obj) { - if (obj == this) { + // Returns true if ActionVariables and InsertActions are inserted in same order, ActionVariables are equal (they + // have the same index for getting the value from the activation Tuple) and InsertActions are equal (they have + // the same arity and value to be set). + public boolean equalsWithSubstitution(TransformationAction other) { + if (other == this) { return true; } - if (!(obj instanceof TransformationAction other)) { + + if (actionVariables.size() != other.actionVariables.size()) { return false; } - if (!actionSymbols.equals(other.actionSymbols)) { + + if (insertActions.size() != other.insertActions.size()) { return false; } - if (!insertActions.equals(other.insertActions)) { + + if (deleteActions.size() != other.deleteActions.size()) { return false; } - if (!deleteActions.equals(other.deleteActions)) { - return false; + + for (var i = 0; i < actionVariables.size(); i++) { + var variable = actionVariables.get(i); + var otherVariable = other.actionVariables.get(i); + if (!variable.equalsWithSubstitution(otherVariable)) { + return false; + } } - return this.activationSymbolUsageMap.equals(other.activationSymbolUsageMap); - } + for (var i = 0; i < insertActions.size(); i++) { + var insertAction = insertActions.get(i); + var otherInsertAction = other.insertActions.get(i); + if (!insertAction.equalsWithSubstitution(otherInsertAction)) { + return false; + } + } + + for (var i = 0; i < deleteActions.size(); i++) { + var deleteAction = deleteActions.get(i); + var otherDeleteAction = other.deleteActions.get(i); + if (!deleteAction.equalsWithSubstitution(otherDeleteAction)) { + return false; + } + } + return this.actionVariableUsageMap.equals(other.actionVariableUsageMap); - @Override - public int hashCode() { - var result = 17; - result = 31 * result + actionSymbols.hashCode(); - result = 31 * result + insertActions.hashCode(); - result = 31 * result + deleteActions.hashCode(); - return result; } } diff --git a/subprojects/store-dse/src/test/java/tools/refinery/store/dse/ActionEqualsTest.java b/subprojects/store-dse/src/test/java/tools/refinery/store/dse/ActionEqualsTest.java index e29260e9..1489b413 100644 --- a/subprojects/store-dse/src/test/java/tools/refinery/store/dse/ActionEqualsTest.java +++ b/subprojects/store-dse/src/test/java/tools/refinery/store/dse/ActionEqualsTest.java @@ -14,8 +14,7 @@ import tools.refinery.store.query.view.KeyOnlyView; import tools.refinery.store.representation.Symbol; import tools.refinery.store.representation.TruthValue; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.*; public class ActionEqualsTest { @@ -55,7 +54,6 @@ public class ActionEqualsTest { .build(); - model = store.createEmptyModel(); dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); } @@ -64,40 +62,46 @@ public class ActionEqualsTest { void emptyActionEqualsTest() { var action1 = new TransformationAction(); var action2 = new TransformationAction(); - assertEquals(action1, action1); - assertEquals(action2, action2); - assertEquals(action1, action2); + + assertTrue(action1.equalsWithSubstitution(action1)); + assertTrue(action2.equalsWithSubstitution(action2)); + assertTrue(action1.equalsWithSubstitution(action2)); } @Test void actionTrivialTest() { - var newItemSymbol1 = new NewItemSymbol(); - var activationSymbol = new ActivationSymbol(); - var insertAction1 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1, + var newItemSymbol1 = new NewItemVariable(); + var activationSymbol = new ActivationVariable(); + var insertAction1 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1); + var insertAction2 = new InsertAction<>(model.getInterpretation(relation1), true, newItemSymbol1, activationSymbol); - var insertAction2 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1, + var insertAction3 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1); + var insertAction4 = new InsertAction<>(model.getInterpretation(relation1), true, newItemSymbol1, activationSymbol); var action1 = new TransformationAction(); action1.add(newItemSymbol1); action1.add(activationSymbol); action1.add(insertAction1); + action1.add(insertAction2); action1.prepare(model); var action2 = new TransformationAction(); action2.add(newItemSymbol1); action2.add(activationSymbol); - action2.add(insertAction2); + action2.add(insertAction3); + action2.add(insertAction4); action2.prepare(model); - assertEquals(action1, action2); + assertTrue(action1.equalsWithSubstitution(action2)); } @Test void actionIdenticalTest() { - var newItemSymbol1 = new NewItemSymbol(); - var activationSymbol1 = new ActivationSymbol(); - var insertAction1 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1, activationSymbol1); + var newItemSymbol1 = new NewItemVariable(); + var activationSymbol1 = new ActivationVariable(); + var insertAction1 = new InsertAction<>(model.getInterpretation(relation1), true, newItemSymbol1, + activationSymbol1); var action1 = new TransformationAction(); action1.add(newItemSymbol1); @@ -105,10 +109,9 @@ public class ActionEqualsTest { action1.add(insertAction1); action1.prepare(model); - - var newItemSymbol2 = new NewItemSymbol(); - var activationSymbol2 = new ActivationSymbol(); - var insertAction2 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol2, + var newItemSymbol2 = new NewItemVariable(); + var activationSymbol2 = new ActivationVariable(); + var insertAction2 = new InsertAction<>(model.getInterpretation(relation1), true, newItemSymbol2, activationSymbol2); var action2 = new TransformationAction(); @@ -117,14 +120,14 @@ public class ActionEqualsTest { action2.add(insertAction2); action2.prepare(model); - assertEquals(action1, action2); + assertTrue(action1.equalsWithSubstitution(action2)); } @Test void actionSymbolGlobalOrderTest() { - var newItemSymbol1 = new NewItemSymbol(); - var activationSymbol1 = new ActivationSymbol(); - var insertAction1 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1, + var newItemSymbol1 = new NewItemVariable(); + var activationSymbol1 = new ActivationVariable(); + var insertAction1 = new InsertAction<>(model.getInterpretation(relation1), true, newItemSymbol1, activationSymbol1); var action1 = new TransformationAction(); @@ -133,10 +136,9 @@ public class ActionEqualsTest { action1.add(insertAction1); action1.prepare(model); - - var newItemSymbol2 = new NewItemSymbol(); - var activationSymbol2 = new ActivationSymbol(); - var insertAction2 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol2, + var newItemSymbol2 = new NewItemVariable(); + var activationSymbol2 = new ActivationVariable(); + var insertAction2 = new InsertAction<>(model.getInterpretation(relation1), true, newItemSymbol2, activationSymbol2); var action2 = new TransformationAction(); @@ -145,43 +147,39 @@ public class ActionEqualsTest { action2.add(insertAction2); action2.prepare(model); - assertNotEquals(action1, action2); + assertFalse(action1.equalsWithSubstitution(action2)); } @Test - void actionSymbolInInsertActionOrderTest() { - var newItemSymbol1 = new NewItemSymbol(); - var activationSymbol1 = new ActivationSymbol(); - var insertAction1 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1, activationSymbol1); + void actionSymbolRepeatedInInsertActionTest() { + var newItemSymbol1 = new NewItemVariable(); + var insertAction1 = new InsertAction<>(model.getInterpretation(relation1), true, newItemSymbol1, + newItemSymbol1); var action1 = new TransformationAction(); action1.add(newItemSymbol1); - action1.add(activationSymbol1); action1.add(insertAction1); action1.prepare(model); - - var newItemSymbol2 = new NewItemSymbol(); - var activationSymbol2 = new ActivationSymbol(); - var insertAction2 = new InsertAction<>(model.getInterpretation(type1), true, activationSymbol2, + var newItemSymbol2 = new NewItemVariable(); + var insertAction2 = new InsertAction<>(model.getInterpretation(relation1), true, newItemSymbol2, newItemSymbol2); var action2 = new TransformationAction(); action2.add(newItemSymbol2); - action2.add(activationSymbol2); action2.add(insertAction2); action2.prepare(model); - assertNotEquals(action1, action2); + assertTrue(action1.equalsWithSubstitution(action2)); } @Test void identicalInsertActionInDifferentOrderTest() { - var newItemSymbol1 = new NewItemSymbol(); - var activationSymbol1 = new ActivationSymbol(); - var insertAction1 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1, + var newItemSymbol1 = new NewItemVariable(); + var activationSymbol1 = new ActivationVariable(); + var insertAction1 = new InsertAction<>(model.getInterpretation(relation1), true, newItemSymbol1, activationSymbol1); - var insertAction2 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1, + var insertAction2 = new InsertAction<>(model.getInterpretation(relation1), true, newItemSymbol1, activationSymbol1); var action1 = new TransformationAction(); @@ -198,19 +196,20 @@ public class ActionEqualsTest { action2.add(insertAction1); action2.prepare(model); - assertEquals(action1, action2); + assertTrue(action1.equalsWithSubstitution(action2)); } @Test void identicalActionAndSymbolDifferentOrderTest() { - var newItemSymbol1 = new NewItemSymbol(); - var activationSymbol1 = new ActivationSymbol(); - var insertAction1 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1, + var newItemSymbol1 = new NewItemVariable(); + var newItemSymbol2 = new NewItemVariable(); + var activationSymbol1 = new ActivationVariable(); + var activationSymbol2 = new ActivationVariable(); + + var insertAction1 = new InsertAction<>(model.getInterpretation(relation1), true, newItemSymbol1, activationSymbol1); - var newItemSymbol2 = new NewItemSymbol(); - var activationSymbol2 = new ActivationSymbol(); - var insertAction2 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol2, + var insertAction2 = new InsertAction<>(model.getInterpretation(relation1), true, newItemSymbol2, activationSymbol2); var action1 = new TransformationAction(); @@ -231,19 +230,19 @@ public class ActionEqualsTest { action2.add(insertAction1); action2.prepare(model); - assertEquals(action1, action2); + assertTrue(action1.equalsWithSubstitution(action2)); } @Test void identicalActionAndSymbolMixedOrderTest() { - var newItemSymbol1 = new NewItemSymbol(); - var activationSymbol1 = new ActivationSymbol(); - var insertAction1 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1, + var newItemSymbol1 = new NewItemVariable(); + var activationSymbol1 = new ActivationVariable(); + var insertAction1 = new InsertAction<>(model.getInterpretation(relation1), true, newItemSymbol1, activationSymbol1); - var newItemSymbol2 = new NewItemSymbol(); - var activationSymbol2 = new ActivationSymbol(); - var insertAction2 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol2, + var newItemSymbol2 = new NewItemVariable(); + var activationSymbol2 = new ActivationVariable(); + var insertAction2 = new InsertAction<>(model.getInterpretation(relation1), true, newItemSymbol2, activationSymbol2); var action1 = new TransformationAction(); @@ -264,16 +263,16 @@ public class ActionEqualsTest { action2.add(activationSymbol2); action2.prepare(model); - assertEquals(action1, action2); + assertTrue(action1.equalsWithSubstitution(action2)); } @Test void insertActionInterpretationTest() { - var newItemSymbol1 = new NewItemSymbol(); - var activationSymbol1 = new ActivationSymbol(); - var insertAction1 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1, + var newItemSymbol1 = new NewItemVariable(); + var activationSymbol1 = new ActivationVariable(); + var insertAction1 = new InsertAction<>(model.getInterpretation(relation1), true, newItemSymbol1, activationSymbol1); - var insertAction2 = new InsertAction<>(model.getInterpretation(type2), true, newItemSymbol1, + var insertAction2 = new InsertAction<>(model.getInterpretation(relation2), true, newItemSymbol1, activationSymbol1); var action1 = new TransformationAction(); @@ -288,16 +287,16 @@ public class ActionEqualsTest { action2.add(insertAction2); action2.prepare(model); - assertNotEquals(action1, action2); + assertFalse(action1.equalsWithSubstitution(action2)); } @Test void insertActionValueTest() { - var newItemSymbol1 = new NewItemSymbol(); - var activationSymbol1 = new ActivationSymbol(); - var insertAction1 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1, + var newItemSymbol1 = new NewItemVariable(); + var activationSymbol1 = new ActivationVariable(); + var insertAction1 = new InsertAction<>(model.getInterpretation(relation1), true, newItemSymbol1, activationSymbol1); - var insertAction2 = new InsertAction<>(model.getInterpretation(type1), false, newItemSymbol1, + var insertAction2 = new InsertAction<>(model.getInterpretation(relation1), false, newItemSymbol1, activationSymbol1); var action1 = new TransformationAction(); @@ -312,17 +311,17 @@ public class ActionEqualsTest { action2.add(insertAction2); action2.prepare(model); - assertNotEquals(action1, action2); + assertFalse(action1.equalsWithSubstitution(action2)); } @Test void newItemSymbolDuplicateTest() { - var newItemSymbol1 = new NewItemSymbol(); - var newItemSymbol2 = new NewItemSymbol(); - var activationSymbol1 = new ActivationSymbol(); - var insertAction1 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1, + var newItemSymbol1 = new NewItemVariable(); + var newItemSymbol2 = new NewItemVariable(); + var activationSymbol1 = new ActivationVariable(); + var insertAction1 = new InsertAction<>(model.getInterpretation(relation1), true, newItemSymbol1, activationSymbol1); - var insertAction2 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol2, + var insertAction2 = new InsertAction<>(model.getInterpretation(relation1), true, newItemSymbol2, activationSymbol1); var action1 = new TransformationAction(); @@ -337,17 +336,17 @@ public class ActionEqualsTest { action2.add(insertAction2); action2.prepare(model); - assertEquals(action1, action2); + assertTrue(action1.equalsWithSubstitution(action2)); } @Test void activationSymbolDuplicateTest() { - var newItemSymbol1 = new NewItemSymbol(); - var activationSymbol1 = new ActivationSymbol(); - var activationSymbol2 = new ActivationSymbol(); - var insertAction1 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1, + var newItemSymbol1 = new NewItemVariable(); + var activationSymbol1 = new ActivationVariable(); + var activationSymbol2 = new ActivationVariable(); + var insertAction1 = new InsertAction<>(model.getInterpretation(relation1), true, newItemSymbol1, activationSymbol1); - var insertAction2 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1, + var insertAction2 = new InsertAction<>(model.getInterpretation(relation1), true, newItemSymbol1, activationSymbol2); var action1 = new TransformationAction(); @@ -362,17 +361,17 @@ public class ActionEqualsTest { action2.add(insertAction2); action2.prepare(model); - assertEquals(action1, action2); + assertTrue(action1.equalsWithSubstitution(action2)); } @Test void activationSymbolIndexTest() { - var newItemSymbol1 = new NewItemSymbol(); - var activationSymbol1 = new ActivationSymbol(0); - var activationSymbol2 = new ActivationSymbol(1); - var insertAction1 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1, + var newItemSymbol1 = new NewItemVariable(); + var activationSymbol1 = new ActivationVariable(0); + var activationSymbol2 = new ActivationVariable(1); + var insertAction1 = new InsertAction<>(model.getInterpretation(relation1), true, newItemSymbol1, activationSymbol1); - var insertAction2 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1, + var insertAction2 = new InsertAction<>(model.getInterpretation(relation1), true, newItemSymbol1, activationSymbol2); var action1 = new TransformationAction(); @@ -387,14 +386,14 @@ public class ActionEqualsTest { action2.add(insertAction2); action2.prepare(model); - assertNotEquals(action1, action2); + assertFalse(action1.equalsWithSubstitution(action2)); } @Test void deleteActionTest() { - var newItemSymbol = new NewItemSymbol(); - var activationSymbol = new ActivationSymbol(0); - var insertAction = new InsertAction<>(model.getInterpretation(type1), false, newItemSymbol, + var newItemSymbol = new NewItemVariable(); + var activationSymbol = new ActivationVariable(0); + var insertAction = new InsertAction<>(model.getInterpretation(relation1), false, newItemSymbol, activationSymbol); var deleteAction = new DeleteAction(activationSymbol); @@ -412,14 +411,14 @@ public class ActionEqualsTest { action2.add(deleteAction); action2.prepare(model); - assertEquals(action1, action2); + assertTrue(action1.equalsWithSubstitution(action2)); } @Test void deleteActionMissingTest() { - var newItemSymbol = new NewItemSymbol(); - var activationSymbol = new ActivationSymbol(0); - var insertAction = new InsertAction<>(model.getInterpretation(type1), false, newItemSymbol, + var newItemSymbol = new NewItemVariable(); + var activationSymbol = new ActivationVariable(0); + var insertAction = new InsertAction<>(model.getInterpretation(relation1), false, newItemSymbol, activationSymbol); var deleteAction = new DeleteAction(activationSymbol); @@ -436,14 +435,14 @@ public class ActionEqualsTest { action2.add(insertAction); action2.prepare(model); - assertNotEquals(action1, action2); + assertFalse(action1.equalsWithSubstitution(action2)); } @Test void deleteActionIdenticalTest() { - var newItemSymbol = new NewItemSymbol(); - var activationSymbol = new ActivationSymbol(0); - var insertAction = new InsertAction<>(model.getInterpretation(type1), false, newItemSymbol, + var newItemSymbol = new NewItemVariable(); + var activationSymbol = new ActivationVariable(0); + var insertAction = new InsertAction<>(model.getInterpretation(relation1), false, newItemSymbol, activationSymbol); var deleteAction1 = new DeleteAction(activationSymbol); var deleteAction2 = new DeleteAction(activationSymbol); @@ -462,14 +461,14 @@ public class ActionEqualsTest { action2.add(deleteAction2); action2.prepare(model); - assertEquals(action1, action2); + assertTrue(action1.equalsWithSubstitution(action2)); } @Test void deleteActionSymbolTypeTest() { - var newItemSymbol = new NewItemSymbol(); - var activationSymbol = new ActivationSymbol(0); - var insertAction = new InsertAction<>(model.getInterpretation(type1), false, newItemSymbol, + var newItemSymbol = new NewItemVariable(); + var activationSymbol = new ActivationVariable(0); + var insertAction = new InsertAction<>(model.getInterpretation(relation1), false, newItemSymbol, activationSymbol); var deleteAction1 = new DeleteAction(activationSymbol); var deleteAction2 = new DeleteAction(newItemSymbol); @@ -488,14 +487,14 @@ public class ActionEqualsTest { action2.add(deleteAction2); action2.prepare(model); - assertNotEquals(action1, action2); + assertFalse(action1.equalsWithSubstitution(action2)); } @Test void deleteActionOrderTest() { - var newItemSymbol = new NewItemSymbol(); - var activationSymbol = new ActivationSymbol(0); - var insertAction = new InsertAction<>(model.getInterpretation(type1), false, newItemSymbol, + var newItemSymbol = new NewItemVariable(); + var activationSymbol = new ActivationVariable(0); + var insertAction = new InsertAction<>(model.getInterpretation(relation1), false, newItemSymbol, activationSymbol); var deleteAction1 = new DeleteAction(activationSymbol); var deleteAction2 = new DeleteAction(newItemSymbol); @@ -516,20 +515,20 @@ public class ActionEqualsTest { action2.add(deleteAction1); action2.prepare(model); - assertNotEquals(action1, action2); + assertFalse(action1.equalsWithSubstitution(action2)); } @Test void actionsMixedOrderTest() { - var newItemSymbol1 = new NewItemSymbol(); - var activationSymbol1 = new ActivationSymbol(); - var insertAction1 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1, + var newItemSymbol1 = new NewItemVariable(); + var activationSymbol1 = new ActivationVariable(); + var insertAction1 = new InsertAction<>(model.getInterpretation(relation1), true, newItemSymbol1, activationSymbol1); var deleteAction1 = new DeleteAction(newItemSymbol1); - var newItemSymbol2 = new NewItemSymbol(); - var activationSymbol2 = new ActivationSymbol(); - var insertAction2 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol2, + var newItemSymbol2 = new NewItemVariable(); + var activationSymbol2 = new ActivationVariable(); + var insertAction2 = new InsertAction<>(model.getInterpretation(relation1), true, newItemSymbol2, activationSymbol2); var deleteAction2 = new DeleteAction(activationSymbol2); @@ -555,20 +554,20 @@ public class ActionEqualsTest { action2.add(activationSymbol2); action2.prepare(model); - assertEquals(action1, action2); + assertTrue(action1.equalsWithSubstitution(action2)); } @Test void twoUnpreparedActionsTest() { - var newItemSymbol1 = new NewItemSymbol(); - var activationSymbol1 = new ActivationSymbol(); - var insertAction1 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1, + var newItemSymbol1 = new NewItemVariable(); + var activationSymbol1 = new ActivationVariable(); + var insertAction1 = new InsertAction<>(model.getInterpretation(relation1), true, newItemSymbol1, activationSymbol1); var deleteAction1 = new DeleteAction(newItemSymbol1); - var newItemSymbol2 = new NewItemSymbol(); - var activationSymbol2 = new ActivationSymbol(); - var insertAction2 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol2, + var newItemSymbol2 = new NewItemVariable(); + var activationSymbol2 = new ActivationVariable(); + var insertAction2 = new InsertAction<>(model.getInterpretation(relation1), true, newItemSymbol2, activationSymbol2); var deleteAction2 = new DeleteAction(activationSymbol2); @@ -592,20 +591,20 @@ public class ActionEqualsTest { action2.add(insertAction2); action2.add(activationSymbol2); - assertEquals(action1, action2); + assertTrue(action1.equalsWithSubstitution(action2)); } @Test void oneUnpreparedActionTest() { - var newItemSymbol1 = new NewItemSymbol(); - var activationSymbol1 = new ActivationSymbol(); - var insertAction1 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol1, + var newItemSymbol1 = new NewItemVariable(); + var activationSymbol1 = new ActivationVariable(); + var insertAction1 = new InsertAction<>(model.getInterpretation(relation1), true, newItemSymbol1, activationSymbol1); var deleteAction1 = new DeleteAction(newItemSymbol1); - var newItemSymbol2 = new NewItemSymbol(); - var activationSymbol2 = new ActivationSymbol(); - var insertAction2 = new InsertAction<>(model.getInterpretation(type1), true, newItemSymbol2, + var newItemSymbol2 = new NewItemVariable(); + var activationSymbol2 = new ActivationVariable(); + var insertAction2 = new InsertAction<>(model.getInterpretation(relation1), true, newItemSymbol2, activationSymbol2); var deleteAction2 = new DeleteAction(activationSymbol2); @@ -630,6 +629,6 @@ public class ActionEqualsTest { action2.add(insertAction2); action2.add(activationSymbol2); - assertNotEquals(action1, action2); + assertFalse(action1.equalsWithSubstitution(action2)); } } -- cgit v1.2.3-70-g09d2 From 3796818d5b8754cfc9cdcbf61b54af93670ef42b Mon Sep 17 00:00:00 2001 From: nagilooh Date: Fri, 25 Aug 2023 17:14:56 +0200 Subject: Add missing copyright headers --- .../store/dse/internal/action/ActionVariable.java | 5 ++++ .../dse/internal/action/ActivationVariable.java | 5 ++++ .../store/dse/internal/action/AtomicAction.java | 5 ++++ .../store/dse/internal/action/DeleteAction.java | 5 ++++ .../store/dse/internal/action/InsertAction.java | 5 ++++ .../store/dse/internal/action/NewItemVariable.java | 5 ++++ .../dse/internal/action/TransformationAction.java | 5 ++++ .../tools/refinery/store/dse/ActionEqualsTest.java | 27 +++++++++------------- 8 files changed, 46 insertions(+), 16 deletions(-) (limited to 'subprojects/store-dse/src/main/java/tools') diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActionVariable.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActionVariable.java index 51078d15..92de565d 100644 --- a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActionVariable.java +++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActionVariable.java @@ -1,3 +1,8 @@ +/* + * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors + * + * SPDX-License-Identifier: EPL-2.0 + */ package tools.refinery.store.dse.internal.action; import tools.refinery.store.tuple.Tuple; diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActivationVariable.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActivationVariable.java index 148d4156..6b4c6340 100644 --- a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActivationVariable.java +++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/ActivationVariable.java @@ -1,3 +1,8 @@ +/* + * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors + * + * SPDX-License-Identifier: EPL-2.0 + */ package tools.refinery.store.dse.internal.action; import tools.refinery.store.model.Model; diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/AtomicAction.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/AtomicAction.java index 470278ae..a8f10bca 100644 --- a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/AtomicAction.java +++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/AtomicAction.java @@ -1,3 +1,8 @@ +/* + * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors + * + * SPDX-License-Identifier: EPL-2.0 + */ package tools.refinery.store.dse.internal.action; import tools.refinery.store.model.Model; diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/DeleteAction.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/DeleteAction.java index 9fa77df3..9900390f 100644 --- a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/DeleteAction.java +++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/DeleteAction.java @@ -1,3 +1,8 @@ +/* + * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors + * + * SPDX-License-Identifier: EPL-2.0 + */ package tools.refinery.store.dse.internal.action; import tools.refinery.store.dse.DesignSpaceExplorationAdapter; diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/InsertAction.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/InsertAction.java index 2335abad..90fcc5ac 100644 --- a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/InsertAction.java +++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/InsertAction.java @@ -1,3 +1,8 @@ +/* + * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors + * + * SPDX-License-Identifier: EPL-2.0 + */ package tools.refinery.store.dse.internal.action; import tools.refinery.store.model.Interpretation; diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/NewItemVariable.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/NewItemVariable.java index 65b1f544..cbb9697e 100644 --- a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/NewItemVariable.java +++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/NewItemVariable.java @@ -1,3 +1,8 @@ +/* + * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors + * + * SPDX-License-Identifier: EPL-2.0 + */ package tools.refinery.store.dse.internal.action; import tools.refinery.store.dse.DesignSpaceExplorationAdapter; diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/TransformationAction.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/TransformationAction.java index 50387f53..adc4df9e 100644 --- a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/TransformationAction.java +++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/action/TransformationAction.java @@ -1,3 +1,8 @@ +/* + * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors + * + * SPDX-License-Identifier: EPL-2.0 + */ package tools.refinery.store.dse.internal.action; import tools.refinery.store.model.Model; diff --git a/subprojects/store-dse/src/test/java/tools/refinery/store/dse/ActionEqualsTest.java b/subprojects/store-dse/src/test/java/tools/refinery/store/dse/ActionEqualsTest.java index 1489b413..d4a05d12 100644 --- a/subprojects/store-dse/src/test/java/tools/refinery/store/dse/ActionEqualsTest.java +++ b/subprojects/store-dse/src/test/java/tools/refinery/store/dse/ActionEqualsTest.java @@ -1,3 +1,8 @@ +/* + * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors + * + * SPDX-License-Identifier: EPL-2.0 + */ package tools.refinery.store.dse; import org.junit.jupiter.api.BeforeAll; @@ -7,46 +12,37 @@ import tools.refinery.store.dse.strategy.DepthFirstStrategy; import tools.refinery.store.model.Model; import tools.refinery.store.model.ModelStore; import tools.refinery.store.query.dnf.Query; -import tools.refinery.store.query.dnf.RelationalQuery; import tools.refinery.store.query.viatra.ViatraModelQueryAdapter; -import tools.refinery.store.query.view.AnySymbolView; import tools.refinery.store.query.view.KeyOnlyView; import tools.refinery.store.representation.Symbol; -import tools.refinery.store.representation.TruthValue; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; public class ActionEqualsTest { private static Model model; - private static DesignSpaceExplorationAdapter dseAdapter; private static Symbol type1; - private static Symbol type2; - private static Symbol type3; private static Symbol relation1; private static Symbol relation2; - private static RelationalQuery precondition1; - private static RelationalQuery precondition2; @BeforeAll public static void init() { type1 = Symbol.of("type1", 1); - type2 = Symbol.of("type2", 1); - type3 = Symbol.of("type3", 1, TruthValue.class); relation1 = Symbol.of("relation1", 2); relation2 = Symbol.of("relation2", 2); - AnySymbolView type1View = new KeyOnlyView<>(type1); - precondition1 = Query.of("CreateClassPrecondition", + var type1View = new KeyOnlyView<>(type1); + var precondition1 = Query.of("CreateClassPrecondition", (builder, model) -> builder.clause( type1View.call(model) )); - precondition2 = Query.of("CreateFeaturePrecondition", + var precondition2 = Query.of("CreateFeaturePrecondition", (builder, model) -> builder.clause( type1View.call(model) )); var store = ModelStore.builder() - .symbols(type1, type2, type3, relation2, relation1) + .symbols(type1, relation2, relation1) .with(ViatraModelQueryAdapter.builder() .queries(precondition1, precondition2)) .with(DesignSpaceExplorationAdapter.builder() @@ -55,7 +51,6 @@ public class ActionEqualsTest { model = store.createEmptyModel(); - dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); } @Test -- cgit v1.2.3-70-g09d2 From d66fae40e7246e3ac72548a3150e8b9b6d3b6a83 Mon Sep 17 00:00:00 2001 From: nagilooh Date: Fri, 25 Aug 2023 17:24:50 +0200 Subject: SuppressWarnings for using pseudorandom number generator in non-security sensitive contexts --- .../refinery/store/dse/internal/DesignSpaceExplorationAdapterImpl.java | 2 ++ .../main/java/tools/refinery/store/dse/internal/TransformationRule.java | 2 ++ .../store/dse/objectives/AlwaysSatisfiedRandomHardObjective.java | 1 + .../refinery/visualization/internal/ModelVisualizerAdapterImpl.java | 1 + 4 files changed, 6 insertions(+) (limited to 'subprojects/store-dse/src/main/java/tools') diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/DesignSpaceExplorationAdapterImpl.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/DesignSpaceExplorationAdapterImpl.java index 0a5cd7fc..1ae09916 100644 --- a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/DesignSpaceExplorationAdapterImpl.java +++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/DesignSpaceExplorationAdapterImpl.java @@ -46,6 +46,7 @@ public class DesignSpaceExplorationAdapterImpl implements DesignSpaceExploration private Map parents = new HashMap<>(); private final List solutions = new ArrayList<>(); private Map> statesAndTraversedActivations; + @SuppressWarnings("squid:S2245") private Random random = new Random(); private boolean isNewState = false; private final boolean isVisualizationEnabled; @@ -182,6 +183,7 @@ public class DesignSpaceExplorationAdapterImpl implements DesignSpaceExploration } @Override + @SuppressWarnings("squid:S2245") public void setRandom(long seed) { this.random = new Random(seed); } diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/TransformationRule.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/TransformationRule.java index 8123c0d6..37117164 100644 --- a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/TransformationRule.java +++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/TransformationRule.java @@ -26,10 +26,12 @@ public class TransformationRule { private Random random; private ModelQueryAdapter queryEngine; + @SuppressWarnings("squid:S2245") public TransformationRule(String name, RelationalQuery precondition, ActionFactory actionFactory) { this(name, precondition, actionFactory, new Random()); } + @SuppressWarnings("squid:S2245") public TransformationRule(String name, RelationalQuery precondition, ActionFactory actionFactory, long seed) { this(name, precondition, actionFactory, new Random(seed)); } diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/objectives/AlwaysSatisfiedRandomHardObjective.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/objectives/AlwaysSatisfiedRandomHardObjective.java index 327d5e2f..cdd1754f 100644 --- a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/objectives/AlwaysSatisfiedRandomHardObjective.java +++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/objectives/AlwaysSatisfiedRandomHardObjective.java @@ -22,6 +22,7 @@ import java.util.Random; public class AlwaysSatisfiedRandomHardObjective extends BaseObjective { private static final String DEFAULT_NAME = "AlwaysSatisfiedDummyHardObjective"; + @SuppressWarnings("squid:S2245") private static final Random random = new Random(0); public AlwaysSatisfiedRandomHardObjective() { diff --git a/subprojects/visualization/src/main/java/tools/refinery/visualization/internal/ModelVisualizerAdapterImpl.java b/subprojects/visualization/src/main/java/tools/refinery/visualization/internal/ModelVisualizerAdapterImpl.java index 531969b4..e60ae4b7 100644 --- a/subprojects/visualization/src/main/java/tools/refinery/visualization/internal/ModelVisualizerAdapterImpl.java +++ b/subprojects/visualization/src/main/java/tools/refinery/visualization/internal/ModelVisualizerAdapterImpl.java @@ -220,6 +220,7 @@ public class ModelVisualizerAdapterImpl implements ModelVisualizerAdapter { } private Integer[] typeColor(String name) { + @SuppressWarnings("squid:S2245") var random = new Random(name.hashCode()); return new Integer[] { random.nextInt(128) + 128, random.nextInt(128) + 128, random.nextInt(128) + 128 }; } -- cgit v1.2.3-70-g09d2