diff options
author | 2023-08-07 16:07:09 +0200 | |
---|---|---|
committer | 2023-08-07 16:07:09 +0200 | |
commit | 36550e2be2146b290210cb12c76d0341e499f849 (patch) | |
tree | be37f1544c1ee655d95e0139d881990dd014dc7f /subprojects/store/src/main/java/tools | |
parent | StateCoderBuilder improvement with individuals, and customizable calculators. (diff) | |
download | refinery-36550e2be2146b290210cb12c76d0341e499f849.tar.gz refinery-36550e2be2146b290210cb12c76d0341e499f849.tar.zst refinery-36550e2be2146b290210cb12c76d0341e499f849.zip |
Tests + small changes for AbstractNeighbourhoodCalculator and StateEquivalenceCheckerImpl
Diffstat (limited to 'subprojects/store/src/main/java/tools')
3 files changed, 17 insertions, 20 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 0de76519..c3f8a586 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 | |||
@@ -13,10 +13,7 @@ import tools.refinery.store.statecoding.ObjectCode; | |||
13 | import tools.refinery.store.tuple.Tuple; | 13 | import tools.refinery.store.tuple.Tuple; |
14 | import tools.refinery.store.tuple.Tuple0; | 14 | import tools.refinery.store.tuple.Tuple0; |
15 | 15 | ||
16 | import java.util.ArrayList; | 16 | import java.util.*; |
17 | import java.util.LinkedHashMap; | ||
18 | import java.util.List; | ||
19 | import java.util.Random; | ||
20 | 17 | ||
21 | public abstract class AbstractNeighbourhoodCalculator { | 18 | public abstract class AbstractNeighbourhoodCalculator { |
22 | protected final List<Interpretation<?>> nullImpactValues; | 19 | protected final List<Interpretation<?>> nullImpactValues; |
@@ -56,13 +53,13 @@ public abstract class AbstractNeighbourhoodCalculator { | |||
56 | } | 53 | } |
57 | 54 | ||
58 | protected long getTupleHash1(Tuple tuple, Object value, ObjectCode objectCodeImpl) { | 55 | protected long getTupleHash1(Tuple tuple, Object value, ObjectCode objectCodeImpl) { |
59 | long result = value.hashCode(); | 56 | long result = Objects.hashCode(value); |
60 | result = result * 31 + objectCodeImpl.get(tuple.get(0)); | 57 | result = result * 31 + objectCodeImpl.get(tuple.get(0)); |
61 | return result; | 58 | return result; |
62 | } | 59 | } |
63 | 60 | ||
64 | protected long getTupleHash2(Tuple tuple, Object value, ObjectCode objectCodeImpl) { | 61 | protected long getTupleHash2(Tuple tuple, Object value, ObjectCode objectCodeImpl) { |
65 | long result = value.hashCode(); | 62 | long result = Objects.hashCode(value); |
66 | result = result * 31 + objectCodeImpl.get(tuple.get(0)); | 63 | result = result * 31 + objectCodeImpl.get(tuple.get(0)); |
67 | result = result * 31 + objectCodeImpl.get(tuple.get(1)); | 64 | result = result * 31 + objectCodeImpl.get(tuple.get(1)); |
68 | if (tuple.get(0) == tuple.get(1)) { | 65 | if (tuple.get(0) == tuple.get(1)) { |
@@ -72,7 +69,7 @@ public abstract class AbstractNeighbourhoodCalculator { | |||
72 | } | 69 | } |
73 | 70 | ||
74 | protected long getTupleHashN(Tuple tuple, Object value, ObjectCode objectCodeImpl) { | 71 | protected long getTupleHashN(Tuple tuple, Object value, ObjectCode objectCodeImpl) { |
75 | long result = value.hashCode(); | 72 | long result = Objects.hashCode(value); |
76 | for (int i = 0; i < tuple.getSize(); i++) { | 73 | for (int i = 0; i < tuple.getSize(); i++) { |
77 | result = result * 31 + objectCodeImpl.get(tuple.get(i)); | 74 | result = result * 31 + objectCodeImpl.get(tuple.get(i)); |
78 | } | 75 | } |
@@ -85,9 +82,9 @@ public abstract class AbstractNeighbourhoodCalculator { | |||
85 | } | 82 | } |
86 | 83 | ||
87 | protected long calculateModelCode(long lastSum) { | 84 | protected long calculateModelCode(long lastSum) { |
88 | long result = 1; | 85 | long result = 0; |
89 | for (var nullImpactValue : nullImpactValues) { | 86 | for (var nullImpactValue : nullImpactValues) { |
90 | result = result * 31 + nullImpactValue.get(Tuple0.INSTANCE).hashCode(); | 87 | result = result * 31 + Objects.hashCode(nullImpactValue.get(Tuple0.INSTANCE)); |
91 | } | 88 | } |
92 | result += lastSum; | 89 | result += lastSum; |
93 | return result; | 90 | return result; |
diff --git a/subprojects/store/src/main/java/tools/refinery/store/statecoding/neighbourhood/ObjectCodeImpl.java b/subprojects/store/src/main/java/tools/refinery/store/statecoding/neighbourhood/ObjectCodeImpl.java index 08e3a90b..c4d86cf1 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/statecoding/neighbourhood/ObjectCodeImpl.java +++ b/subprojects/store/src/main/java/tools/refinery/store/statecoding/neighbourhood/ObjectCodeImpl.java | |||
@@ -50,7 +50,8 @@ public class ObjectCodeImpl implements ObjectCode { | |||
50 | 50 | ||
51 | public void set(int object, long value) { | 51 | public void set(int object, long value) { |
52 | ensureSize(object); | 52 | ensureSize(object); |
53 | vector[object]=value; | 53 | final long valueToPut = value == 0 ? 1 : value; |
54 | vector[object]=valueToPut; | ||
54 | } | 55 | } |
55 | 56 | ||
56 | public int getSize() { | 57 | public int getSize() { |
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 e58a2502..34dba34e 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 | |||
@@ -29,11 +29,8 @@ public class StateEquivalenceCheckerImpl implements StateEquivalenceChecker { | |||
29 | List<? extends Interpretation<?>> interpretations1, | 29 | List<? extends Interpretation<?>> interpretations1, |
30 | ObjectCode code1, | 30 | ObjectCode code1, |
31 | List<? extends Interpretation<?>> interpretations2, | 31 | List<? extends Interpretation<?>> interpretations2, |
32 | ObjectCode code2) { | 32 | ObjectCode code2) |
33 | if (code1.getSize() != code2.getSize()) { | 33 | { |
34 | return EquivalenceResult.DIFFERENT; | ||
35 | } | ||
36 | |||
37 | IntIntHashMap object2PermutationGroup = new IntIntHashMap(); | 34 | IntIntHashMap object2PermutationGroup = new IntIntHashMap(); |
38 | List<List<IntIntMap>> permutationsGroups = new ArrayList<>(); | 35 | List<List<IntIntMap>> permutationsGroups = new ArrayList<>(); |
39 | 36 | ||
@@ -69,12 +66,14 @@ public class StateEquivalenceCheckerImpl implements StateEquivalenceChecker { | |||
69 | for (int o = 0; o < code.getSize(); o++) { | 66 | for (int o = 0; o < code.getSize(); o++) { |
70 | if(! individuals.contains(o)){ | 67 | if(! individuals.contains(o)){ |
71 | long hash = code.get(o); | 68 | long hash = code.get(o); |
72 | var equivalenceClass = result.get(hash); | 69 | if(hash != 0) { |
73 | if (equivalenceClass == null) { | 70 | var equivalenceClass = result.get(hash); |
74 | equivalenceClass = new IntHashSet(); | 71 | if (equivalenceClass == null) { |
75 | result.put(hash, equivalenceClass); | 72 | equivalenceClass = new IntHashSet(); |
73 | result.put(hash, equivalenceClass); | ||
74 | } | ||
75 | equivalenceClass.add(o); | ||
76 | } | 76 | } |
77 | equivalenceClass.add(o); | ||
78 | } | 77 | } |
79 | } | 78 | } |
80 | return result; | 79 | return result; |