aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/store/src/main/java/tools/refinery/store/statecoding/neighbourhood/AbstractNeighbourhoodCalculator.java
diff options
context:
space:
mode:
Diffstat (limited to 'subprojects/store/src/main/java/tools/refinery/store/statecoding/neighbourhood/AbstractNeighbourhoodCalculator.java')
-rw-r--r--subprojects/store/src/main/java/tools/refinery/store/statecoding/neighbourhood/AbstractNeighbourhoodCalculator.java22
1 files changed, 14 insertions, 8 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 0a40a19d..4cef6786 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
@@ -5,9 +5,12 @@
5 */ 5 */
6package tools.refinery.store.statecoding.neighbourhood; 6package tools.refinery.store.statecoding.neighbourhood;
7 7
8import org.eclipse.collections.api.factory.primitive.IntLongMaps;
9import org.eclipse.collections.api.map.primitive.MutableIntLongMap;
8import org.eclipse.collections.api.set.primitive.IntSet; 10import org.eclipse.collections.api.set.primitive.IntSet;
9import org.eclipse.collections.impl.map.mutable.primitive.IntLongHashMap; 11import tools.refinery.store.model.AnyInterpretation;
10import tools.refinery.store.model.Interpretation; 12import tools.refinery.store.model.Interpretation;
13import tools.refinery.store.model.Model;
11import tools.refinery.store.statecoding.ObjectCode; 14import tools.refinery.store.statecoding.ObjectCode;
12import tools.refinery.store.tuple.Tuple; 15import tools.refinery.store.tuple.Tuple;
13import tools.refinery.store.tuple.Tuple0; 16import tools.refinery.store.tuple.Tuple0;
@@ -15,25 +18,28 @@ import tools.refinery.store.tuple.Tuple0;
15import java.util.*; 18import java.util.*;
16 19
17public abstract class AbstractNeighbourhoodCalculator { 20public abstract class AbstractNeighbourhoodCalculator {
18 protected final List<Interpretation<?>> nullImpactValues; 21 protected final Model model;
19 protected final LinkedHashMap<Interpretation<?>, long[]> impactValues; 22 protected final List<AnyInterpretation> nullImpactValues;
20 protected final IntLongHashMap individualHashValues; 23 protected final LinkedHashMap<AnyInterpretation, long[]> impactValues;
24 protected final MutableIntLongMap individualHashValues = IntLongMaps.mutable.empty();
21 25
22 protected static final long PRIME = 31; 26 protected static final long PRIME = 31;
23 27
24 protected AbstractNeighbourhoodCalculator(List<? extends Interpretation<?>> interpretations, IntSet individuals) { 28 protected AbstractNeighbourhoodCalculator(Model model, List<? extends AnyInterpretation> interpretations,
29 IntSet individuals) {
30 this.model = model;
25 this.nullImpactValues = new ArrayList<>(); 31 this.nullImpactValues = new ArrayList<>();
26 this.impactValues = new LinkedHashMap<>(); 32 this.impactValues = new LinkedHashMap<>();
33 // Random isn't used for cryptographical purposes but just to assign distinguishable identifiers to symbols.
27 @SuppressWarnings("squid:S2245") 34 @SuppressWarnings("squid:S2245")
28 Random random = new Random(1); 35 Random random = new Random(1);
29 36
30 individualHashValues = new IntLongHashMap();
31 var individualsInOrder = individuals.toSortedList(Integer::compare); 37 var individualsInOrder = individuals.toSortedList(Integer::compare);
32 for(int i = 0; i<individualsInOrder.size(); i++) { 38 for(int i = 0; i<individualsInOrder.size(); i++) {
33 individualHashValues.put(individualsInOrder.get(i), random.nextLong()); 39 individualHashValues.put(individualsInOrder.get(i), random.nextLong());
34 } 40 }
35 41
36 for (Interpretation<?> interpretation : interpretations) { 42 for (AnyInterpretation interpretation : interpretations) {
37 int arity = interpretation.getSymbol().arity(); 43 int arity = interpretation.getSymbol().arity();
38 if (arity == 0) { 44 if (arity == 0) {
39 nullImpactValues.add(interpretation); 45 nullImpactValues.add(interpretation);
@@ -86,7 +92,7 @@ public abstract class AbstractNeighbourhoodCalculator {
86 protected long calculateModelCode(long lastSum) { 92 protected long calculateModelCode(long lastSum) {
87 long result = 0; 93 long result = 0;
88 for (var nullImpactValue : nullImpactValues) { 94 for (var nullImpactValue : nullImpactValues) {
89 result = result * PRIME + Objects.hashCode(nullImpactValue.get(Tuple0.INSTANCE)); 95 result = result * PRIME + Objects.hashCode(((Interpretation<?>) nullImpactValue).get(Tuple0.INSTANCE));
90 } 96 }
91 result += lastSum; 97 result += lastSum;
92 return result; 98 return result;