aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/store/src/main/java/tools/refinery/store/statecoding/stateequivalence/StateEquivalenceCheckerImpl.java
diff options
context:
space:
mode:
Diffstat (limited to 'subprojects/store/src/main/java/tools/refinery/store/statecoding/stateequivalence/StateEquivalenceCheckerImpl.java')
-rw-r--r--subprojects/store/src/main/java/tools/refinery/store/statecoding/stateequivalence/StateEquivalenceCheckerImpl.java53
1 files changed, 27 insertions, 26 deletions
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 ef0d76a7..5a62d8a0 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
@@ -6,11 +6,14 @@
6package tools.refinery.store.statecoding.stateequivalence; 6package tools.refinery.store.statecoding.stateequivalence;
7 7
8import org.eclipse.collections.api.factory.primitive.IntIntMaps; 8import org.eclipse.collections.api.factory.primitive.IntIntMaps;
9import org.eclipse.collections.api.factory.primitive.IntSets;
10import org.eclipse.collections.api.factory.primitive.LongObjectMaps;
9import org.eclipse.collections.api.map.primitive.IntIntMap; 11import org.eclipse.collections.api.map.primitive.IntIntMap;
12import org.eclipse.collections.api.map.primitive.MutableIntIntMap;
13import org.eclipse.collections.api.map.primitive.MutableLongObjectMap;
10import org.eclipse.collections.api.set.primitive.IntSet; 14import org.eclipse.collections.api.set.primitive.IntSet;
11import org.eclipse.collections.impl.map.mutable.primitive.IntIntHashMap; 15import org.eclipse.collections.api.set.primitive.MutableIntSet;
12import org.eclipse.collections.impl.map.mutable.primitive.LongObjectHashMap; 16import tools.refinery.store.model.AnyInterpretation;
13import org.eclipse.collections.impl.set.mutable.primitive.IntHashSet;
14import tools.refinery.store.model.Interpretation; 17import tools.refinery.store.model.Interpretation;
15import tools.refinery.store.statecoding.Morphism; 18import tools.refinery.store.statecoding.Morphism;
16import tools.refinery.store.statecoding.ObjectCode; 19import tools.refinery.store.statecoding.ObjectCode;
@@ -26,12 +29,11 @@ public class StateEquivalenceCheckerImpl implements StateEquivalenceChecker {
26 29
27 @Override 30 @Override
28 public EquivalenceResult constructMorphism(IntSet individuals, 31 public EquivalenceResult constructMorphism(IntSet individuals,
29 List<? extends Interpretation<?>> interpretations1, 32 List<? extends AnyInterpretation> interpretations1,
30 ObjectCode code1, 33 ObjectCode code1,
31 List<? extends Interpretation<?>> interpretations2, 34 List<? extends AnyInterpretation> interpretations2,
32 ObjectCode code2) 35 ObjectCode code2) {
33 { 36 MutableIntIntMap object2PermutationGroup = IntIntMaps.mutable.empty();
34 IntIntHashMap object2PermutationGroup = new IntIntHashMap();
35 List<List<IntIntMap>> permutationsGroups = new ArrayList<>(); 37 List<List<IntIntMap>> permutationsGroups = new ArrayList<>();
36 38
37 final EquivalenceResult permutations = constructPermutationNavigation(individuals, 39 final EquivalenceResult permutations = constructPermutationNavigation(individuals,
@@ -50,7 +52,7 @@ public class StateEquivalenceCheckerImpl implements StateEquivalenceChecker {
50 return permutations; 52 return permutations;
51 } 53 }
52 54
53 if(tried >= LIMIT) { 55 if (tried >= LIMIT) {
54 return EquivalenceResult.UNKNOWN; 56 return EquivalenceResult.UNKNOWN;
55 } 57 }
56 58
@@ -58,22 +60,22 @@ public class StateEquivalenceCheckerImpl implements StateEquivalenceChecker {
58 tried++; 60 tried++;
59 } while (hasNext); 61 } while (hasNext);
60 62
61 if(permutations == EquivalenceResult.UNKNOWN) { 63 if (permutations == EquivalenceResult.UNKNOWN) {
62 return EquivalenceResult.UNKNOWN; 64 return EquivalenceResult.UNKNOWN;
63 } else { 65 } else {
64 return EquivalenceResult.DIFFERENT; 66 return EquivalenceResult.DIFFERENT;
65 } 67 }
66 } 68 }
67 69
68 private LongObjectHashMap<IntHashSet> indexByHash(ObjectCode code, IntSet individuals) { 70 private MutableLongObjectMap<MutableIntSet> indexByHash(ObjectCode code, IntSet individuals) {
69 LongObjectHashMap<IntHashSet> result = new LongObjectHashMap<>(); 71 MutableLongObjectMap<MutableIntSet> result = LongObjectMaps.mutable.empty();
70 for (int o = 0; o < code.getSize(); o++) { 72 for (int o = 0; o < code.getSize(); o++) {
71 if(! individuals.contains(o)){ 73 if (!individuals.contains(o)) {
72 long hash = code.get(o); 74 long hash = code.get(o);
73 if(hash != 0) { 75 if (hash != 0) {
74 var equivalenceClass = result.get(hash); 76 var equivalenceClass = result.get(hash);
75 if (equivalenceClass == null) { 77 if (equivalenceClass == null) {
76 equivalenceClass = new IntHashSet(); 78 equivalenceClass = IntSets.mutable.empty();
77 result.put(hash, equivalenceClass); 79 result.put(hash, equivalenceClass);
78 } 80 }
79 equivalenceClass.add(o); 81 equivalenceClass.add(o);
@@ -83,11 +85,9 @@ public class StateEquivalenceCheckerImpl implements StateEquivalenceChecker {
83 return result; 85 return result;
84 } 86 }
85 87
86 private EquivalenceResult constructPermutationNavigation(IntSet individuals, 88 private EquivalenceResult constructPermutationNavigation(
87 LongObjectHashMap<IntHashSet> map1, 89 IntSet individuals, MutableLongObjectMap<MutableIntSet> map1, MutableLongObjectMap<MutableIntSet> map2,
88 LongObjectHashMap<IntHashSet> map2, 90 MutableIntIntMap object2OptionIndex, List<List<IntIntMap>> listOfOptions) {
89 IntIntHashMap object2OptionIndex,
90 List<List<IntIntMap>> listOfOptions) {
91 if (map1.size() != map2.size()) { 91 if (map1.size() != map2.size()) {
92 return EquivalenceResult.DIFFERENT; 92 return EquivalenceResult.DIFFERENT;
93 } 93 }
@@ -116,27 +116,28 @@ public class StateEquivalenceCheckerImpl implements StateEquivalenceChecker {
116 listOfOptions.add(pairing.permutations()); 116 listOfOptions.add(pairing.permutations());
117 } 117 }
118 118
119 individuals.forEach(o -> listOfOptions.add(o,List.of(IntIntMaps.immutable.of(o,o)))); 119 individuals.forEach(o -> listOfOptions.add(o, List.of(IntIntMaps.immutable.of(o, o))));
120 120
121 if(allComplete) { 121 if (allComplete) {
122 return EquivalenceResult.ISOMORPHIC; 122 return EquivalenceResult.ISOMORPHIC;
123 } else { 123 } else {
124 return EquivalenceResult.UNKNOWN; 124 return EquivalenceResult.UNKNOWN;
125 } 125 }
126 } 126 }
127 127
128 private boolean testMorphism(List<? extends Interpretation<?>> s, List<? extends Interpretation<?>> t, Morphism m) { 128 private boolean testMorphism(List<? extends AnyInterpretation> s, List<? extends AnyInterpretation> t,
129 Morphism m) {
129 for (int interpretationIndex = 0; interpretationIndex < s.size(); interpretationIndex++) { 130 for (int interpretationIndex = 0; interpretationIndex < s.size(); interpretationIndex++) {
130 var sI = s.get(interpretationIndex); 131 var sI = s.get(interpretationIndex);
131 var tI = t.get(interpretationIndex); 132 var tI = t.get(interpretationIndex);
132 133
133 var cursor = sI.getAll(); 134 var cursor = ((Interpretation<?>) sI).getAll();
134 while (cursor.move()) { 135 while (cursor.move()) {
135 final Tuple sTuple = cursor.getKey(); 136 final Tuple sTuple = cursor.getKey();
136 final Object sValue = cursor.getValue(); 137 final Object sValue = cursor.getValue();
137 138
138 final Tuple tTuple = apply(sTuple, m); 139 final Tuple tTuple = apply(sTuple, m);
139 final Object tValue = tI.get(tTuple); 140 final Object tValue = ((Interpretation<?>) tI).get(tTuple);
140 141
141 if (!Objects.equals(sValue, tValue)) { 142 if (!Objects.equals(sValue, tValue)) {
142 return false; 143 return false;