diff options
author | Oszkár Semeráth <semerath@mit.bme.hu> | 2023-08-08 20:23:29 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-08 20:23:29 +0200 |
commit | e33529c418db1b27c759cb8fe6e36d413779853f (patch) | |
tree | 194b1a1a0a95be71180f39020489e2368937f403 /subprojects | |
parent | Merge pull request #35 from OszkarSemerath/datastructure (diff) | |
parent | Added test for StateEquivalenceChecker Unknown outcome. (diff) | |
download | refinery-e33529c418db1b27c759cb8fe6e36d413779853f.tar.gz refinery-e33529c418db1b27c759cb8fe6e36d413779853f.tar.zst refinery-e33529c418db1b27c759cb8fe6e36d413779853f.zip |
Merge pull request #36 from OszkarSemerath/datastructure
SuppressWarnings for using deterministic random in hash code generation.
Diffstat (limited to 'subprojects')
4 files changed, 46 insertions, 3 deletions
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 { | |||
24 | protected AbstractNeighbourhoodCalculator(List<? extends Interpretation<?>> interpretations, IntSet individuals) { | 24 | protected AbstractNeighbourhoodCalculator(List<? extends Interpretation<?>> interpretations, IntSet individuals) { |
25 | this.nullImpactValues = new ArrayList<>(); | 25 | this.nullImpactValues = new ArrayList<>(); |
26 | this.impactValues = new LinkedHashMap<>(); | 26 | this.impactValues = new LinkedHashMap<>(); |
27 | @SuppressWarnings("squid:S2245") | ||
27 | Random random = new Random(1); | 28 | Random random = new Random(1); |
28 | 29 | ||
29 | individualHashValues = new IntLongHashMap(); | 30 | individualHashValues = new IntLongHashMap(); |
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 { | |||
57 | for (var permutation : previousPermutations) { | 57 | for (var permutation : previousPermutations) { |
58 | for (int pos = 0; pos <= max; pos++) { | 58 | for (int pos = 0; pos <= max; pos++) { |
59 | int[] newPermutation = new int[max + 1]; | 59 | int[] newPermutation = new int[max + 1]; |
60 | if (pos >= 0) | 60 | System.arraycopy(permutation, 0, newPermutation, 0, pos); |
61 | System.arraycopy(permutation, 0, newPermutation, 0, pos); | ||
62 | newPermutation[pos] = max; | 61 | newPermutation[pos] = max; |
63 | if (max - (pos + 1) >= 0) | 62 | if (max - (pos + 1) >= 0) |
64 | System.arraycopy(permutation, pos + 1, newPermutation, pos + 1 + 1, max - (pos + 1)); | 63 | System.arraycopy(permutation, pos + 1, newPermutation, pos + 1 + 1, max - (pos + 1)); |
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 { | |||
58 | tried++; | 58 | tried++; |
59 | } while (hasNext); | 59 | } while (hasNext); |
60 | 60 | ||
61 | return EquivalenceResult.DIFFERENT; | 61 | if(permutations == EquivalenceResult.UNKNOWN) { |
62 | return EquivalenceResult.UNKNOWN; | ||
63 | } else { | ||
64 | return EquivalenceResult.DIFFERENT; | ||
65 | } | ||
62 | } | 66 | } |
63 | 67 | ||
64 | private LongObjectHashMap<IntHashSet> indexByHash(ObjectCode code, IntSet individuals) { | 68 | private LongObjectHashMap<IntHashSet> 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; | |||
10 | import tools.refinery.store.model.Model; | 10 | import tools.refinery.store.model.Model; |
11 | import tools.refinery.store.model.ModelStore; | 11 | import tools.refinery.store.model.ModelStore; |
12 | import tools.refinery.store.representation.Symbol; | 12 | import tools.refinery.store.representation.Symbol; |
13 | import tools.refinery.store.statecoding.neighbourhood.ObjectCodeImpl; | ||
13 | import tools.refinery.store.tuple.Tuple; | 14 | import tools.refinery.store.tuple.Tuple; |
14 | 15 | ||
15 | import static org.junit.jupiter.api.Assertions.assertEquals; | 16 | import static org.junit.jupiter.api.Assertions.assertEquals; |
@@ -175,4 +176,42 @@ class EquivalenceTest { | |||
175 | 176 | ||
176 | assertEquals(StateEquivalenceChecker.EquivalenceResult.ISOMORPHIC, stateCoder.checkEquivalence(v2, v4)); | 177 | assertEquals(StateEquivalenceChecker.EquivalenceResult.ISOMORPHIC, stateCoder.checkEquivalence(v2, v4)); |
177 | } | 178 | } |
179 | |||
180 | @Test | ||
181 | void largeUnknownTest() { | ||
182 | final int limit = 100; | ||
183 | |||
184 | StateCodeCalculator calculator = () -> { | ||
185 | var code = new ObjectCodeImpl(); | ||
186 | for (int i = 0; i < limit; i++) { | ||
187 | code.set(i, 1); | ||
188 | } | ||
189 | return new StateCoderResult(1, code); | ||
190 | }; | ||
191 | |||
192 | ModelStore store = ModelStore.builder() | ||
193 | .symbols(person, age, friend, parents, population) | ||
194 | .with(StateCoderAdapter.builder() | ||
195 | .stateCodeCalculatorFactory((p1, p2) -> calculator)) | ||
196 | .build(); | ||
197 | |||
198 | var stateCoder = store.getAdapter(StateCoderStoreAdapter.class); | ||
199 | Model model = createStore().createEmptyModel(); | ||
200 | |||
201 | var personI = model.getInterpretation(person); | ||
202 | var friendI = model.getInterpretation(friend); | ||
203 | |||
204 | for (int i = 0; i < limit; i++) { | ||
205 | personI.put(Tuple.of(i), true); | ||
206 | } | ||
207 | |||
208 | friendI.put(Tuple.of(11,12),true); | ||
209 | var v1 = model.commit(); | ||
210 | |||
211 | friendI.put(Tuple.of(11,12),false); | ||
212 | friendI.put(Tuple.of(21,22),false); | ||
213 | var v2 = model.commit(); | ||
214 | |||
215 | assertEquals(StateEquivalenceChecker.EquivalenceResult.UNKNOWN, stateCoder.checkEquivalence(v1,v2)); | ||
216 | } | ||
178 | } | 217 | } |