diff options
author | Kristóf Marussy <kristof@marussy.com> | 2024-06-27 19:47:46 +0200 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2024-06-28 00:22:40 +0200 |
commit | 0bd7854ae802ad04c1c9e3da4e87dde542152b46 (patch) | |
tree | bf619e7cc716c058f094ce1267059d7c828ada94 | |
parent | interpreter: Fix NPE in VQE wipe/dispose -> EVM -> MatchUpdateListener chains (diff) | |
download | refinery-0bd7854ae802ad04c1c9e3da4e87dde542152b46.tar.gz refinery-0bd7854ae802ad04c1c9e3da4e87dde542152b46.tar.zst refinery-0bd7854ae802ad04c1c9e3da4e87dde542152b46.zip |
refactor(store): NeighborhoodCalculator API
* Use US English spelling consistently
* Avoid Eclipse Collections types on API
14 files changed, 96 insertions, 43 deletions
diff --git a/subprojects/generator/src/main/java/tools/refinery/generator/ModelGeneratorFactory.java b/subprojects/generator/src/main/java/tools/refinery/generator/ModelGeneratorFactory.java index 877db0bb..ca9dd728 100644 --- a/subprojects/generator/src/main/java/tools/refinery/generator/ModelGeneratorFactory.java +++ b/subprojects/generator/src/main/java/tools/refinery/generator/ModelGeneratorFactory.java | |||
@@ -15,11 +15,11 @@ import tools.refinery.store.dse.transition.DesignSpaceExplorationAdapter; | |||
15 | import tools.refinery.store.model.ModelStore; | 15 | import tools.refinery.store.model.ModelStore; |
16 | import tools.refinery.store.query.interpreter.QueryInterpreterAdapter; | 16 | import tools.refinery.store.query.interpreter.QueryInterpreterAdapter; |
17 | import tools.refinery.store.reasoning.ReasoningAdapter; | 17 | import tools.refinery.store.reasoning.ReasoningAdapter; |
18 | import tools.refinery.store.reasoning.interpretation.PartialNeighbourhoodCalculator; | 18 | import tools.refinery.store.reasoning.interpretation.PartialNeighborhoodCalculator; |
19 | import tools.refinery.store.reasoning.literal.Concreteness; | 19 | import tools.refinery.store.reasoning.literal.Concreteness; |
20 | import tools.refinery.store.statecoding.StateCodeCalculatorFactory; | 20 | import tools.refinery.store.statecoding.StateCodeCalculatorFactory; |
21 | import tools.refinery.store.statecoding.StateCoderAdapter; | 21 | import tools.refinery.store.statecoding.StateCoderAdapter; |
22 | import tools.refinery.store.statecoding.neighbourhood.NeighbourhoodCalculator; | 22 | import tools.refinery.store.statecoding.neighborhood.NeighborhoodCalculator; |
23 | import tools.refinery.store.util.CancellationToken; | 23 | import tools.refinery.store.util.CancellationToken; |
24 | 24 | ||
25 | import java.util.Collection; | 25 | import java.util.Collection; |
@@ -40,7 +40,7 @@ public final class ModelGeneratorFactory { | |||
40 | 40 | ||
41 | private boolean partialInterpretationBasedNeighbourhoods; | 41 | private boolean partialInterpretationBasedNeighbourhoods; |
42 | 42 | ||
43 | private int stateCoderDepth = NeighbourhoodCalculator.DEFAULT_DEPTH; | 43 | private int stateCoderDepth = NeighborhoodCalculator.DEFAULT_DEPTH; |
44 | 44 | ||
45 | public ModelGeneratorFactory cancellationToken(CancellationToken cancellationToken) { | 45 | public ModelGeneratorFactory cancellationToken(CancellationToken cancellationToken) { |
46 | this.cancellationToken = cancellationToken; | 46 | this.cancellationToken = cancellationToken; |
@@ -90,7 +90,7 @@ public final class ModelGeneratorFactory { | |||
90 | 90 | ||
91 | private StateCodeCalculatorFactory getStateCoderCalculatorFactory() { | 91 | private StateCodeCalculatorFactory getStateCoderCalculatorFactory() { |
92 | return partialInterpretationBasedNeighbourhoods ? | 92 | return partialInterpretationBasedNeighbourhoods ? |
93 | PartialNeighbourhoodCalculator.factory(Concreteness.PARTIAL, stateCoderDepth) : | 93 | PartialNeighborhoodCalculator.factory(Concreteness.PARTIAL, stateCoderDepth) : |
94 | NeighbourhoodCalculator.factory(stateCoderDepth); | 94 | NeighborhoodCalculator.factory(stateCoderDepth); |
95 | } | 95 | } |
96 | } | 96 | } |
diff --git a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/interpretation/PartialNeighbourhoodCalculator.java b/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/interpretation/PartialNeighborhoodCalculator.java index 67e20dbc..31295e64 100644 --- a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/interpretation/PartialNeighbourhoodCalculator.java +++ b/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/interpretation/PartialNeighborhoodCalculator.java | |||
@@ -5,7 +5,6 @@ | |||
5 | */ | 5 | */ |
6 | package tools.refinery.store.reasoning.interpretation; | 6 | package tools.refinery.store.reasoning.interpretation; |
7 | 7 | ||
8 | import org.eclipse.collections.api.set.primitive.IntSet; | ||
9 | import tools.refinery.store.map.Cursor; | 8 | import tools.refinery.store.map.Cursor; |
10 | import tools.refinery.store.model.Model; | 9 | import tools.refinery.store.model.Model; |
11 | import tools.refinery.store.query.ModelQueryAdapter; | 10 | import tools.refinery.store.query.ModelQueryAdapter; |
@@ -14,16 +13,18 @@ import tools.refinery.store.reasoning.literal.Concreteness; | |||
14 | import tools.refinery.store.reasoning.representation.PartialSymbol; | 13 | import tools.refinery.store.reasoning.representation.PartialSymbol; |
15 | import tools.refinery.store.statecoding.StateCodeCalculatorFactory; | 14 | import tools.refinery.store.statecoding.StateCodeCalculatorFactory; |
16 | import tools.refinery.store.statecoding.StateCoderResult; | 15 | import tools.refinery.store.statecoding.StateCoderResult; |
17 | import tools.refinery.store.statecoding.neighbourhood.AbstractNeighbourhoodCalculator; | 16 | import tools.refinery.store.statecoding.neighborhood.AbstractNeighborhoodCalculator; |
17 | import tools.refinery.store.statecoding.neighborhood.IndividualsSet; | ||
18 | import tools.refinery.store.tuple.Tuple; | 18 | import tools.refinery.store.tuple.Tuple; |
19 | 19 | ||
20 | import java.util.List; | 20 | import java.util.List; |
21 | 21 | ||
22 | public class PartialNeighbourhoodCalculator extends AbstractNeighbourhoodCalculator<PartialInterpretation<?, ?>> { | 22 | public class PartialNeighborhoodCalculator extends AbstractNeighborhoodCalculator<PartialInterpretation<?, ?>> { |
23 | private final ModelQueryAdapter queryAdapter; | 23 | private final ModelQueryAdapter queryAdapter; |
24 | private final Concreteness concreteness; | 24 | private final Concreteness concreteness; |
25 | 25 | ||
26 | protected PartialNeighbourhoodCalculator(Model model, IntSet individuals, Concreteness concreteness, int depth) { | 26 | protected PartialNeighborhoodCalculator(Model model, IndividualsSet individuals, Concreteness concreteness, |
27 | int depth) { | ||
27 | super(model, individuals, depth); | 28 | super(model, individuals, depth); |
28 | queryAdapter = model.getAdapter(ModelQueryAdapter.class); | 29 | queryAdapter = model.getAdapter(ModelQueryAdapter.class); |
29 | this.concreteness = concreteness; | 30 | this.concreteness = concreteness; |
@@ -61,7 +62,7 @@ public class PartialNeighbourhoodCalculator extends AbstractNeighbourhoodCalcula | |||
61 | } | 62 | } |
62 | 63 | ||
63 | public static StateCodeCalculatorFactory factory(Concreteness concreteness, int depth) { | 64 | public static StateCodeCalculatorFactory factory(Concreteness concreteness, int depth) { |
64 | return (model, interpretations, individuals) -> new PartialNeighbourhoodCalculator(model, individuals, | 65 | return (model, interpretations, individuals) -> new PartialNeighborhoodCalculator(model, individuals, |
65 | concreteness, depth); | 66 | concreteness, depth); |
66 | } | 67 | } |
67 | } | 68 | } |
diff --git a/subprojects/store/build.gradle.kts b/subprojects/store/build.gradle.kts index 55938987..ac4b92f6 100644 --- a/subprojects/store/build.gradle.kts +++ b/subprojects/store/build.gradle.kts | |||
@@ -14,6 +14,6 @@ mavenArtifact { | |||
14 | } | 14 | } |
15 | 15 | ||
16 | dependencies { | 16 | dependencies { |
17 | api(libs.eclipseCollections.api) | 17 | implementation(libs.eclipseCollections.api) |
18 | runtimeOnly(libs.eclipseCollections) | 18 | runtimeOnly(libs.eclipseCollections) |
19 | } | 19 | } |
diff --git a/subprojects/store/src/main/java/tools/refinery/store/statecoding/StateCodeCalculatorFactory.java b/subprojects/store/src/main/java/tools/refinery/store/statecoding/StateCodeCalculatorFactory.java index 809205e4..5e2a94b3 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/statecoding/StateCodeCalculatorFactory.java +++ b/subprojects/store/src/main/java/tools/refinery/store/statecoding/StateCodeCalculatorFactory.java | |||
@@ -5,12 +5,13 @@ | |||
5 | */ | 5 | */ |
6 | package tools.refinery.store.statecoding; | 6 | package tools.refinery.store.statecoding; |
7 | 7 | ||
8 | import org.eclipse.collections.api.set.primitive.IntSet; | ||
9 | import tools.refinery.store.model.Interpretation; | 8 | import tools.refinery.store.model.Interpretation; |
10 | import tools.refinery.store.model.Model; | 9 | import tools.refinery.store.model.Model; |
10 | import tools.refinery.store.statecoding.neighborhood.IndividualsSet; | ||
11 | 11 | ||
12 | import java.util.List; | 12 | import java.util.List; |
13 | 13 | ||
14 | public interface StateCodeCalculatorFactory { | 14 | public interface StateCodeCalculatorFactory { |
15 | StateCodeCalculator create(Model model, List<? extends Interpretation<?>> interpretations, IntSet individuals); | 15 | StateCodeCalculator create(Model model, List<? extends Interpretation<?>> interpretations, |
16 | IndividualsSet individuals); | ||
16 | } | 17 | } |
diff --git a/subprojects/store/src/main/java/tools/refinery/store/statecoding/StateEquivalenceChecker.java b/subprojects/store/src/main/java/tools/refinery/store/statecoding/StateEquivalenceChecker.java index 0f0023ed..ae599dff 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/statecoding/StateEquivalenceChecker.java +++ b/subprojects/store/src/main/java/tools/refinery/store/statecoding/StateEquivalenceChecker.java | |||
@@ -5,8 +5,8 @@ | |||
5 | */ | 5 | */ |
6 | package tools.refinery.store.statecoding; | 6 | package tools.refinery.store.statecoding; |
7 | 7 | ||
8 | import org.eclipse.collections.api.set.primitive.IntSet; | ||
9 | import tools.refinery.store.model.AnyInterpretation; | 8 | import tools.refinery.store.model.AnyInterpretation; |
9 | import tools.refinery.store.statecoding.neighborhood.IndividualsSet; | ||
10 | 10 | ||
11 | import java.util.List; | 11 | import java.util.List; |
12 | 12 | ||
@@ -16,6 +16,6 @@ public interface StateEquivalenceChecker { | |||
16 | } | 16 | } |
17 | 17 | ||
18 | EquivalenceResult constructMorphism( | 18 | EquivalenceResult constructMorphism( |
19 | IntSet individuals, List<? extends AnyInterpretation> interpretations1, ObjectCode code1, | 19 | IndividualsSet individuals, List<? extends AnyInterpretation> interpretations1, ObjectCode code1, |
20 | List<? extends AnyInterpretation> interpretations2, ObjectCode code2); | 20 | List<? extends AnyInterpretation> interpretations2, ObjectCode code2); |
21 | } | 21 | } |
diff --git a/subprojects/store/src/main/java/tools/refinery/store/statecoding/internal/StateCoderBuilderImpl.java b/subprojects/store/src/main/java/tools/refinery/store/statecoding/internal/StateCoderBuilderImpl.java index 36d7d4c7..7fec59c4 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/statecoding/internal/StateCoderBuilderImpl.java +++ b/subprojects/store/src/main/java/tools/refinery/store/statecoding/internal/StateCoderBuilderImpl.java | |||
@@ -15,7 +15,7 @@ import tools.refinery.store.statecoding.StateCodeCalculatorFactory; | |||
15 | import tools.refinery.store.statecoding.StateCoderBuilder; | 15 | import tools.refinery.store.statecoding.StateCoderBuilder; |
16 | import tools.refinery.store.statecoding.StateCoderStoreAdapter; | 16 | import tools.refinery.store.statecoding.StateCoderStoreAdapter; |
17 | import tools.refinery.store.statecoding.StateEquivalenceChecker; | 17 | import tools.refinery.store.statecoding.StateEquivalenceChecker; |
18 | import tools.refinery.store.statecoding.neighbourhood.NeighbourhoodCalculator; | 18 | import tools.refinery.store.statecoding.neighborhood.NeighborhoodCalculator; |
19 | import tools.refinery.store.statecoding.stateequivalence.StateEquivalenceCheckerImpl; | 19 | import tools.refinery.store.statecoding.stateequivalence.StateEquivalenceCheckerImpl; |
20 | import tools.refinery.store.tuple.Tuple1; | 20 | import tools.refinery.store.tuple.Tuple1; |
21 | 21 | ||
@@ -27,7 +27,7 @@ public class StateCoderBuilderImpl extends AbstractModelAdapterBuilder<StateCode | |||
27 | implements StateCoderBuilder { | 27 | implements StateCoderBuilder { |
28 | private final Set<AnySymbol> excluded = new HashSet<>(); | 28 | private final Set<AnySymbol> excluded = new HashSet<>(); |
29 | private final MutableIntSet individuals = IntSets.mutable.empty(); | 29 | private final MutableIntSet individuals = IntSets.mutable.empty(); |
30 | private StateCodeCalculatorFactory calculator = NeighbourhoodCalculator.factory(); | 30 | private StateCodeCalculatorFactory calculator = NeighborhoodCalculator.factory(); |
31 | private StateEquivalenceChecker checker = new StateEquivalenceCheckerImpl(); | 31 | private StateEquivalenceChecker checker = new StateEquivalenceCheckerImpl(); |
32 | 32 | ||
33 | @Override | 33 | @Override |
diff --git a/subprojects/store/src/main/java/tools/refinery/store/statecoding/internal/StateCoderStoreAdapterImpl.java b/subprojects/store/src/main/java/tools/refinery/store/statecoding/internal/StateCoderStoreAdapterImpl.java index 2cb6f3c1..70beedae 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/statecoding/internal/StateCoderStoreAdapterImpl.java +++ b/subprojects/store/src/main/java/tools/refinery/store/statecoding/internal/StateCoderStoreAdapterImpl.java | |||
@@ -14,6 +14,8 @@ import tools.refinery.store.statecoding.StateCodeCalculatorFactory; | |||
14 | import tools.refinery.store.statecoding.StateCoderAdapter; | 14 | import tools.refinery.store.statecoding.StateCoderAdapter; |
15 | import tools.refinery.store.statecoding.StateCoderStoreAdapter; | 15 | import tools.refinery.store.statecoding.StateCoderStoreAdapter; |
16 | import tools.refinery.store.statecoding.StateEquivalenceChecker; | 16 | import tools.refinery.store.statecoding.StateEquivalenceChecker; |
17 | import tools.refinery.store.statecoding.neighborhood.IndividualsSet; | ||
18 | import tools.refinery.store.statecoding.neighborhood.IndividualsArray; | ||
17 | 19 | ||
18 | import java.util.Collection; | 20 | import java.util.Collection; |
19 | import java.util.Objects; | 21 | import java.util.Objects; |
@@ -21,7 +23,7 @@ import java.util.Objects; | |||
21 | public class StateCoderStoreAdapterImpl implements StateCoderStoreAdapter { | 23 | public class StateCoderStoreAdapterImpl implements StateCoderStoreAdapter { |
22 | final ModelStore store; | 24 | final ModelStore store; |
23 | final Collection<Symbol<?>> symbols; | 25 | final Collection<Symbol<?>> symbols; |
24 | final IntSet individuals; | 26 | final IndividualsSet individuals; |
25 | 27 | ||
26 | final StateEquivalenceChecker equivalenceChecker; | 28 | final StateEquivalenceChecker equivalenceChecker; |
27 | final StateCodeCalculatorFactory codeCalculatorFactory; | 29 | final StateCodeCalculatorFactory codeCalculatorFactory; |
@@ -36,7 +38,7 @@ public class StateCoderStoreAdapterImpl implements StateCoderStoreAdapter { | |||
36 | this.equivalenceChecker = equivalenceChecker; | 38 | this.equivalenceChecker = equivalenceChecker; |
37 | this.store = store; | 39 | this.store = store; |
38 | this.symbols = symbols; | 40 | this.symbols = symbols; |
39 | this.individuals = individuals; | 41 | this.individuals = new IndividualsArray(individuals.toSortedArray()); |
40 | } | 42 | } |
41 | 43 | ||
42 | @Override | 44 | @Override |
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/neighborhood/AbstractNeighborhoodCalculator.java index a4060e74..fcc1c72d 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/statecoding/neighbourhood/AbstractNeighbourhoodCalculator.java +++ b/subprojects/store/src/main/java/tools/refinery/store/statecoding/neighborhood/AbstractNeighborhoodCalculator.java | |||
@@ -3,11 +3,10 @@ | |||
3 | * | 3 | * |
4 | * SPDX-License-Identifier: EPL-2.0 | 4 | * SPDX-License-Identifier: EPL-2.0 |
5 | */ | 5 | */ |
6 | package tools.refinery.store.statecoding.neighbourhood; | 6 | package tools.refinery.store.statecoding.neighborhood; |
7 | 7 | ||
8 | import org.eclipse.collections.api.factory.primitive.IntLongMaps; | 8 | import org.eclipse.collections.api.factory.primitive.IntLongMaps; |
9 | import org.eclipse.collections.api.map.primitive.MutableIntLongMap; | 9 | import org.eclipse.collections.api.map.primitive.MutableIntLongMap; |
10 | import org.eclipse.collections.api.set.primitive.IntSet; | ||
11 | import tools.refinery.store.map.Cursor; | 10 | import tools.refinery.store.map.Cursor; |
12 | import tools.refinery.store.model.Model; | 11 | import tools.refinery.store.model.Model; |
13 | import tools.refinery.store.statecoding.ObjectCode; | 12 | import tools.refinery.store.statecoding.ObjectCode; |
@@ -17,9 +16,9 @@ import tools.refinery.store.tuple.Tuple; | |||
17 | 16 | ||
18 | import java.util.*; | 17 | import java.util.*; |
19 | 18 | ||
20 | public abstract class AbstractNeighbourhoodCalculator<T> implements StateCodeCalculator { | 19 | public abstract class AbstractNeighborhoodCalculator<T> implements StateCodeCalculator { |
21 | private final Model model; | 20 | private final Model model; |
22 | private final IntSet individuals; | 21 | private final IndividualsSet individuals; |
23 | private final int depth; | 22 | private final int depth; |
24 | private List<T> nullImpactValues; | 23 | private List<T> nullImpactValues; |
25 | private LinkedHashMap<T, long[]> impactValues; | 24 | private LinkedHashMap<T, long[]> impactValues; |
@@ -29,7 +28,7 @@ public abstract class AbstractNeighbourhoodCalculator<T> implements StateCodeCal | |||
29 | 28 | ||
30 | protected static final long PRIME = 31; | 29 | protected static final long PRIME = 31; |
31 | 30 | ||
32 | protected AbstractNeighbourhoodCalculator(Model model, IntSet individuals, int depth) { | 31 | protected AbstractNeighborhoodCalculator(Model model, IndividualsSet individuals, int depth) { |
33 | this.model = model; | 32 | this.model = model; |
34 | this.individuals = individuals; | 33 | this.individuals = individuals; |
35 | this.depth = depth; | 34 | this.depth = depth; |
@@ -84,10 +83,7 @@ public abstract class AbstractNeighbourhoodCalculator<T> implements StateCodeCal | |||
84 | @SuppressWarnings("squid:S2245") | 83 | @SuppressWarnings("squid:S2245") |
85 | Random random = new Random(1); | 84 | Random random = new Random(1); |
86 | 85 | ||
87 | var individualsInOrder = individuals.toSortedList(Integer::compare); | 86 | individuals.stream().forEach(o -> individualHashValues.put(o, random.nextLong())); |
88 | for (int i = 0; i < individualsInOrder.size(); i++) { | ||
89 | individualHashValues.put(individualsInOrder.get(i), random.nextLong()); | ||
90 | } | ||
91 | 87 | ||
92 | for (var interpretation : getInterpretations()) { | 88 | for (var interpretation : getInterpretations()) { |
93 | int arity = getArity(interpretation); | 89 | int arity = getArity(interpretation); |
diff --git a/subprojects/store/src/main/java/tools/refinery/store/statecoding/neighborhood/IndividualsArray.java b/subprojects/store/src/main/java/tools/refinery/store/statecoding/neighborhood/IndividualsArray.java new file mode 100644 index 00000000..107a01b8 --- /dev/null +++ b/subprojects/store/src/main/java/tools/refinery/store/statecoding/neighborhood/IndividualsArray.java | |||
@@ -0,0 +1,27 @@ | |||
1 | /* | ||
2 | * SPDX-FileCopyrightText: 2024 The Refinery Authors <https://refinery.tools/> | ||
3 | * | ||
4 | * SPDX-License-Identifier: EPL-2.0 | ||
5 | */ | ||
6 | package tools.refinery.store.statecoding.neighborhood; | ||
7 | |||
8 | import java.util.Arrays; | ||
9 | import java.util.stream.IntStream; | ||
10 | |||
11 | public class IndividualsArray implements IndividualsSet { | ||
12 | private final int[] sortedArray; | ||
13 | |||
14 | public IndividualsArray(int[] sortedArray) { | ||
15 | this.sortedArray = sortedArray; | ||
16 | } | ||
17 | |||
18 | @Override | ||
19 | public boolean isIndividual(int nodeId) { | ||
20 | return Arrays.binarySearch(sortedArray, nodeId) >= 0; | ||
21 | } | ||
22 | |||
23 | @Override | ||
24 | public IntStream stream() { | ||
25 | return Arrays.stream(sortedArray); | ||
26 | } | ||
27 | } | ||
diff --git a/subprojects/store/src/main/java/tools/refinery/store/statecoding/neighborhood/IndividualsSet.java b/subprojects/store/src/main/java/tools/refinery/store/statecoding/neighborhood/IndividualsSet.java new file mode 100644 index 00000000..059dad41 --- /dev/null +++ b/subprojects/store/src/main/java/tools/refinery/store/statecoding/neighborhood/IndividualsSet.java | |||
@@ -0,0 +1,26 @@ | |||
1 | /* | ||
2 | * SPDX-FileCopyrightText: 2024 The Refinery Authors <https://refinery.tools/> | ||
3 | * | ||
4 | * SPDX-License-Identifier: EPL-2.0 | ||
5 | */ | ||
6 | package tools.refinery.store.statecoding.neighborhood; | ||
7 | |||
8 | import java.util.stream.IntStream; | ||
9 | |||
10 | public interface IndividualsSet { | ||
11 | IndividualsSet EMPTY = new IndividualsSet() { | ||
12 | @Override | ||
13 | public boolean isIndividual(int nodeId) { | ||
14 | return false; | ||
15 | } | ||
16 | |||
17 | @Override | ||
18 | public IntStream stream() { | ||
19 | return IntStream.empty(); | ||
20 | } | ||
21 | }; | ||
22 | |||
23 | boolean isIndividual(int nodeId); | ||
24 | |||
25 | IntStream stream(); | ||
26 | } | ||
diff --git a/subprojects/store/src/main/java/tools/refinery/store/statecoding/neighbourhood/NeighbourhoodCalculator.java b/subprojects/store/src/main/java/tools/refinery/store/statecoding/neighborhood/NeighborhoodCalculator.java index 5859ccc2..83ad133d 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/statecoding/neighbourhood/NeighbourhoodCalculator.java +++ b/subprojects/store/src/main/java/tools/refinery/store/statecoding/neighborhood/NeighborhoodCalculator.java | |||
@@ -3,9 +3,8 @@ | |||
3 | * | 3 | * |
4 | * SPDX-License-Identifier: EPL-2.0 | 4 | * SPDX-License-Identifier: EPL-2.0 |
5 | */ | 5 | */ |
6 | package tools.refinery.store.statecoding.neighbourhood; | 6 | package tools.refinery.store.statecoding.neighborhood; |
7 | 7 | ||
8 | import org.eclipse.collections.api.set.primitive.IntSet; | ||
9 | import tools.refinery.store.map.Cursor; | 8 | import tools.refinery.store.map.Cursor; |
10 | import tools.refinery.store.model.Interpretation; | 9 | import tools.refinery.store.model.Interpretation; |
11 | import tools.refinery.store.model.Model; | 10 | import tools.refinery.store.model.Model; |
@@ -14,13 +13,13 @@ import tools.refinery.store.tuple.Tuple; | |||
14 | 13 | ||
15 | import java.util.List; | 14 | import java.util.List; |
16 | 15 | ||
17 | public class NeighbourhoodCalculator extends AbstractNeighbourhoodCalculator<Interpretation<?>> { | 16 | public class NeighborhoodCalculator extends AbstractNeighborhoodCalculator<Interpretation<?>> { |
18 | public static final int DEFAULT_DEPTH = 7; | 17 | public static final int DEFAULT_DEPTH = 7; |
19 | 18 | ||
20 | private final List<Interpretation<?>> interpretations; | 19 | private final List<Interpretation<?>> interpretations; |
21 | 20 | ||
22 | protected NeighbourhoodCalculator(Model model, List<? extends Interpretation<?>> interpretations, | 21 | protected NeighborhoodCalculator(Model model, List<? extends Interpretation<?>> interpretations, |
23 | IntSet individuals, int depth) { | 22 | IndividualsSet individuals, int depth) { |
24 | super(model, individuals, depth); | 23 | super(model, individuals, depth); |
25 | this.interpretations = List.copyOf(interpretations); | 24 | this.interpretations = List.copyOf(interpretations); |
26 | } | 25 | } |
@@ -46,7 +45,7 @@ public class NeighbourhoodCalculator extends AbstractNeighbourhoodCalculator<Int | |||
46 | } | 45 | } |
47 | 46 | ||
48 | public static StateCodeCalculatorFactory factory(int depth) { | 47 | public static StateCodeCalculatorFactory factory(int depth) { |
49 | return (model, interpretations, individuals) -> new NeighbourhoodCalculator(model, interpretations, | 48 | return (model, interpretations, individuals) -> new NeighborhoodCalculator(model, interpretations, |
50 | individuals, depth); | 49 | individuals, depth); |
51 | } | 50 | } |
52 | 51 | ||
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/neighborhood/ObjectCodeImpl.java index 422e1d73..d6ef2e89 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/statecoding/neighbourhood/ObjectCodeImpl.java +++ b/subprojects/store/src/main/java/tools/refinery/store/statecoding/neighborhood/ObjectCodeImpl.java | |||
@@ -3,7 +3,7 @@ | |||
3 | * | 3 | * |
4 | * SPDX-License-Identifier: EPL-2.0 | 4 | * SPDX-License-Identifier: EPL-2.0 |
5 | */ | 5 | */ |
6 | package tools.refinery.store.statecoding.neighbourhood; | 6 | package tools.refinery.store.statecoding.neighborhood; |
7 | 7 | ||
8 | import tools.refinery.store.statecoding.ObjectCode; | 8 | import tools.refinery.store.statecoding.ObjectCode; |
9 | 9 | ||
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 5a62d8a0..54d6efdc 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 | |||
@@ -11,13 +11,13 @@ import org.eclipse.collections.api.factory.primitive.LongObjectMaps; | |||
11 | import org.eclipse.collections.api.map.primitive.IntIntMap; | 11 | import org.eclipse.collections.api.map.primitive.IntIntMap; |
12 | import org.eclipse.collections.api.map.primitive.MutableIntIntMap; | 12 | import org.eclipse.collections.api.map.primitive.MutableIntIntMap; |
13 | import org.eclipse.collections.api.map.primitive.MutableLongObjectMap; | 13 | import org.eclipse.collections.api.map.primitive.MutableLongObjectMap; |
14 | import org.eclipse.collections.api.set.primitive.IntSet; | ||
15 | import org.eclipse.collections.api.set.primitive.MutableIntSet; | 14 | import org.eclipse.collections.api.set.primitive.MutableIntSet; |
16 | import tools.refinery.store.model.AnyInterpretation; | 15 | import tools.refinery.store.model.AnyInterpretation; |
17 | import tools.refinery.store.model.Interpretation; | 16 | import tools.refinery.store.model.Interpretation; |
18 | import tools.refinery.store.statecoding.Morphism; | 17 | import tools.refinery.store.statecoding.Morphism; |
19 | import tools.refinery.store.statecoding.ObjectCode; | 18 | import tools.refinery.store.statecoding.ObjectCode; |
20 | import tools.refinery.store.statecoding.StateEquivalenceChecker; | 19 | import tools.refinery.store.statecoding.StateEquivalenceChecker; |
20 | import tools.refinery.store.statecoding.neighborhood.IndividualsSet; | ||
21 | import tools.refinery.store.tuple.Tuple; | 21 | import tools.refinery.store.tuple.Tuple; |
22 | 22 | ||
23 | import java.util.ArrayList; | 23 | import java.util.ArrayList; |
@@ -28,7 +28,7 @@ public class StateEquivalenceCheckerImpl implements StateEquivalenceChecker { | |||
28 | public static final int LIMIT = 1000; | 28 | public static final int LIMIT = 1000; |
29 | 29 | ||
30 | @Override | 30 | @Override |
31 | public EquivalenceResult constructMorphism(IntSet individuals, | 31 | public EquivalenceResult constructMorphism(IndividualsSet individuals, |
32 | List<? extends AnyInterpretation> interpretations1, | 32 | List<? extends AnyInterpretation> interpretations1, |
33 | ObjectCode code1, | 33 | ObjectCode code1, |
34 | List<? extends AnyInterpretation> interpretations2, | 34 | List<? extends AnyInterpretation> interpretations2, |
@@ -67,10 +67,10 @@ public class StateEquivalenceCheckerImpl implements StateEquivalenceChecker { | |||
67 | } | 67 | } |
68 | } | 68 | } |
69 | 69 | ||
70 | private MutableLongObjectMap<MutableIntSet> indexByHash(ObjectCode code, IntSet individuals) { | 70 | private MutableLongObjectMap<MutableIntSet> indexByHash(ObjectCode code, IndividualsSet individuals) { |
71 | MutableLongObjectMap<MutableIntSet> result = LongObjectMaps.mutable.empty(); | 71 | MutableLongObjectMap<MutableIntSet> result = LongObjectMaps.mutable.empty(); |
72 | for (int o = 0; o < code.getSize(); o++) { | 72 | for (int o = 0; o < code.getSize(); o++) { |
73 | if (!individuals.contains(o)) { | 73 | if (!individuals.isIndividual(o)) { |
74 | long hash = code.get(o); | 74 | long hash = code.get(o); |
75 | if (hash != 0) { | 75 | if (hash != 0) { |
76 | var equivalenceClass = result.get(hash); | 76 | var equivalenceClass = result.get(hash); |
@@ -86,8 +86,9 @@ public class StateEquivalenceCheckerImpl implements StateEquivalenceChecker { | |||
86 | } | 86 | } |
87 | 87 | ||
88 | private EquivalenceResult constructPermutationNavigation( | 88 | private EquivalenceResult constructPermutationNavigation( |
89 | IntSet individuals, MutableLongObjectMap<MutableIntSet> map1, MutableLongObjectMap<MutableIntSet> map2, | 89 | IndividualsSet individuals, MutableLongObjectMap<MutableIntSet> map1, |
90 | MutableIntIntMap object2OptionIndex, List<List<IntIntMap>> listOfOptions) { | 90 | MutableLongObjectMap<MutableIntSet> map2, MutableIntIntMap object2OptionIndex, |
91 | List<List<IntIntMap>> listOfOptions) { | ||
91 | if (map1.size() != map2.size()) { | 92 | if (map1.size() != map2.size()) { |
92 | return EquivalenceResult.DIFFERENT; | 93 | return EquivalenceResult.DIFFERENT; |
93 | } | 94 | } |
@@ -116,7 +117,7 @@ public class StateEquivalenceCheckerImpl implements StateEquivalenceChecker { | |||
116 | listOfOptions.add(pairing.permutations()); | 117 | listOfOptions.add(pairing.permutations()); |
117 | } | 118 | } |
118 | 119 | ||
119 | individuals.forEach(o -> listOfOptions.add(o, List.of(IntIntMaps.immutable.of(o, o)))); | 120 | individuals.stream().forEach(o -> listOfOptions.add(o, List.of(IntIntMaps.immutable.of(o, o)))); |
120 | 121 | ||
121 | if (allComplete) { | 122 | if (allComplete) { |
122 | return EquivalenceResult.ISOMORPHIC; | 123 | return EquivalenceResult.ISOMORPHIC; |
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 f2d2f7b5..31726133 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,7 +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.statecoding.neighborhood.ObjectCodeImpl; |
14 | import tools.refinery.store.tuple.Tuple; | 14 | import tools.refinery.store.tuple.Tuple; |
15 | 15 | ||
16 | import static org.junit.jupiter.api.Assertions.assertEquals; | 16 | import static org.junit.jupiter.api.Assertions.assertEquals; |