From 5154a8055112de064ebf3bcf5be8065ac3dc8b7b Mon Sep 17 00:00:00 2001 From: OszkarSemerath Date: Tue, 8 Aug 2023 19:47:51 +0200 Subject: SuppressWarnings for using deterministic random in hash code generation. --- .../store/statecoding/neighbourhood/AbstractNeighbourhoodCalculator.java | 1 + 1 file changed, 1 insertion(+) diff --git a/subprojects/store/src/main/java/tools/refinery/store/statecoding/neighbourhood/AbstractNeighbourhoodCalculator.java b/subprojects/store/src/main/java/tools/refinery/store/statecoding/neighbourhood/AbstractNeighbourhoodCalculator.java index 8fcf24b1..0a40a19d 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/statecoding/neighbourhood/AbstractNeighbourhoodCalculator.java +++ b/subprojects/store/src/main/java/tools/refinery/store/statecoding/neighbourhood/AbstractNeighbourhoodCalculator.java @@ -24,6 +24,7 @@ public abstract class AbstractNeighbourhoodCalculator { protected AbstractNeighbourhoodCalculator(List> interpretations, IntSet individuals) { this.nullImpactValues = new ArrayList<>(); this.impactValues = new LinkedHashMap<>(); + @SuppressWarnings("squid:S2245") Random random = new Random(1); individualHashValues = new IntLongHashMap(); -- cgit v1.2.3-54-g00ecf From eef4d3b16789e19c35be38e012d45540a226eca1 Mon Sep 17 00:00:00 2001 From: OszkarSemerath Date: Tue, 8 Aug 2023 20:18:12 +0200 Subject: Unused condition simplified. --- .../store/statecoding/stateequivalence/CombinationNodePairing.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/subprojects/store/src/main/java/tools/refinery/store/statecoding/stateequivalence/CombinationNodePairing.java b/subprojects/store/src/main/java/tools/refinery/store/statecoding/stateequivalence/CombinationNodePairing.java index 2877bd0f..decff1d5 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/statecoding/stateequivalence/CombinationNodePairing.java +++ b/subprojects/store/src/main/java/tools/refinery/store/statecoding/stateequivalence/CombinationNodePairing.java @@ -57,8 +57,7 @@ public class CombinationNodePairing implements NodePairing { for (var permutation : previousPermutations) { for (int pos = 0; pos <= max; pos++) { int[] newPermutation = new int[max + 1]; - if (pos >= 0) - System.arraycopy(permutation, 0, newPermutation, 0, pos); + System.arraycopy(permutation, 0, newPermutation, 0, pos); newPermutation[pos] = max; if (max - (pos + 1) >= 0) System.arraycopy(permutation, pos + 1, newPermutation, pos + 1 + 1, max - (pos + 1)); -- cgit v1.2.3-54-g00ecf From e2268925741bd4c68dcead708b211bf5fd99440c Mon Sep 17 00:00:00 2001 From: OszkarSemerath Date: Tue, 8 Aug 2023 20:19:03 +0200 Subject: Added test for StateEquivalenceChecker Unknown outcome. --- .../StateEquivalenceCheckerImpl.java | 6 +++- .../store/statecoding/EquivalenceTest.java | 39 ++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/subprojects/store/src/main/java/tools/refinery/store/statecoding/stateequivalence/StateEquivalenceCheckerImpl.java b/subprojects/store/src/main/java/tools/refinery/store/statecoding/stateequivalence/StateEquivalenceCheckerImpl.java index 34dba34e..ef0d76a7 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/statecoding/stateequivalence/StateEquivalenceCheckerImpl.java +++ b/subprojects/store/src/main/java/tools/refinery/store/statecoding/stateequivalence/StateEquivalenceCheckerImpl.java @@ -58,7 +58,11 @@ public class StateEquivalenceCheckerImpl implements StateEquivalenceChecker { tried++; } while (hasNext); - return EquivalenceResult.DIFFERENT; + if(permutations == EquivalenceResult.UNKNOWN) { + return EquivalenceResult.UNKNOWN; + } else { + return EquivalenceResult.DIFFERENT; + } } private LongObjectHashMap indexByHash(ObjectCode code, IntSet individuals) { diff --git a/subprojects/store/src/test/java/tools/refinery/store/statecoding/EquivalenceTest.java b/subprojects/store/src/test/java/tools/refinery/store/statecoding/EquivalenceTest.java index 8a9c0e9b..3c35849e 100644 --- a/subprojects/store/src/test/java/tools/refinery/store/statecoding/EquivalenceTest.java +++ b/subprojects/store/src/test/java/tools/refinery/store/statecoding/EquivalenceTest.java @@ -10,6 +10,7 @@ import tools.refinery.store.map.Version; import tools.refinery.store.model.Model; import tools.refinery.store.model.ModelStore; import tools.refinery.store.representation.Symbol; +import tools.refinery.store.statecoding.neighbourhood.ObjectCodeImpl; import tools.refinery.store.tuple.Tuple; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -175,4 +176,42 @@ class EquivalenceTest { assertEquals(StateEquivalenceChecker.EquivalenceResult.ISOMORPHIC, stateCoder.checkEquivalence(v2, v4)); } + + @Test + void largeUnknownTest() { + final int limit = 100; + + StateCodeCalculator calculator = () -> { + var code = new ObjectCodeImpl(); + for (int i = 0; i < limit; i++) { + code.set(i, 1); + } + return new StateCoderResult(1, code); + }; + + ModelStore store = ModelStore.builder() + .symbols(person, age, friend, parents, population) + .with(StateCoderAdapter.builder() + .stateCodeCalculatorFactory((p1, p2) -> calculator)) + .build(); + + var stateCoder = store.getAdapter(StateCoderStoreAdapter.class); + Model model = createStore().createEmptyModel(); + + var personI = model.getInterpretation(person); + var friendI = model.getInterpretation(friend); + + for (int i = 0; i < limit; i++) { + personI.put(Tuple.of(i), true); + } + + friendI.put(Tuple.of(11,12),true); + var v1 = model.commit(); + + friendI.put(Tuple.of(11,12),false); + friendI.put(Tuple.of(21,22),false); + var v2 = model.commit(); + + assertEquals(StateEquivalenceChecker.EquivalenceResult.UNKNOWN, stateCoder.checkEquivalence(v1,v2)); + } } -- cgit v1.2.3-54-g00ecf