diff options
author | 2023-08-08 19:37:54 +0200 | |
---|---|---|
committer | 2023-08-08 19:37:54 +0200 | |
commit | 7fb2e47c13f798511b0fa6b47c34f53d42c00f34 (patch) | |
tree | 13ca537dd08067933cb5d9cdcf95cd845f5df205 /subprojects/store/src/main/java/tools | |
parent | Added two build tests for custom coding and equivalence checking algorithms. (diff) | |
download | refinery-7fb2e47c13f798511b0fa6b47c34f53d42c00f34.tar.gz refinery-7fb2e47c13f798511b0fa6b47c34f53d42c00f34.tar.zst refinery-7fb2e47c13f798511b0fa6b47c34f53d42c00f34.zip |
ObjectCodeImpl.effectiveSize introduced to correctly handle models with different indices.
Diffstat (limited to 'subprojects/store/src/main/java/tools')
2 files changed, 20 insertions, 11 deletions
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/neighbourhood/NeighbourhoodCalculator.java index d3b3ccae..5b3e5ea3 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/statecoding/neighbourhood/NeighbourhoodCalculator.java +++ b/subprojects/store/src/main/java/tools/refinery/store/statecoding/neighbourhood/NeighbourhoodCalculator.java | |||
@@ -34,7 +34,7 @@ public class NeighbourhoodCalculator extends AbstractNeighbourhoodCalculator imp | |||
34 | constructNextObjectCodes(previousObjectCode, nextObjectCode); | 34 | constructNextObjectCodes(previousObjectCode, nextObjectCode); |
35 | previousObjectCode = nextObjectCode; | 35 | previousObjectCode = nextObjectCode; |
36 | rounds++; | 36 | rounds++; |
37 | } while (rounds <= 7 && rounds <= previousObjectCode.getSize()); | 37 | } while (rounds <= 7 && rounds <= previousObjectCode.getEffectiveSize()); |
38 | 38 | ||
39 | long result = calculateLastSum(previousObjectCode); | 39 | long result = calculateLastSum(previousObjectCode); |
40 | return new StateCoderResult((int) result, previousObjectCode); | 40 | return new StateCoderResult((int) result, previousObjectCode); |
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 0d629176..0cd7ff58 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 | |||
@@ -12,31 +12,35 @@ import java.util.Arrays; | |||
12 | public class ObjectCodeImpl implements ObjectCode { | 12 | public class ObjectCodeImpl implements ObjectCode { |
13 | private long[] vector; | 13 | private long[] vector; |
14 | private int size; | 14 | private int size; |
15 | private int effectiveSize; | ||
15 | 16 | ||
16 | public ObjectCodeImpl() { | 17 | public ObjectCodeImpl() { |
17 | vector = new long[10]; | 18 | vector = new long[10]; |
18 | size = 0; | 19 | size = 0; |
20 | effectiveSize = 0; | ||
19 | } | 21 | } |
20 | 22 | ||
21 | public ObjectCodeImpl(int size) { | 23 | public ObjectCodeImpl(int size) { |
22 | this.vector = new long[size]; | 24 | this.vector = new long[size]; |
23 | this.size = size; | 25 | this.size = size; |
26 | effectiveSize = 0; | ||
24 | } | 27 | } |
25 | 28 | ||
26 | public ObjectCodeImpl(ObjectCodeImpl copy) { | 29 | public ObjectCodeImpl(ObjectCodeImpl copy) { |
27 | this.vector = Arrays.copyOf(copy.vector,copy.size); | 30 | this.vector = Arrays.copyOf(copy.vector, copy.size); |
28 | this.size = copy.size; | 31 | this.size = copy.size; |
32 | effectiveSize = copy.effectiveSize; | ||
29 | } | 33 | } |
30 | 34 | ||
31 | public void ensureSize(int object) { | 35 | public void ensureSize(int object) { |
32 | if(object >= size) { | 36 | if (object >= size) { |
33 | size = object+1; | 37 | size = object + 1; |
34 | } | 38 | } |
35 | 39 | ||
36 | if(object >= vector.length) { | 40 | if (object >= vector.length) { |
37 | int newLength = vector.length*2; | 41 | int newLength = vector.length * 2; |
38 | while(object >= newLength) { | 42 | while (object >= newLength) { |
39 | newLength*=2; | 43 | newLength *= 2; |
40 | } | 44 | } |
41 | 45 | ||
42 | long[] newVector = new long[newLength]; | 46 | long[] newVector = new long[newLength]; |
@@ -46,7 +50,7 @@ public class ObjectCodeImpl implements ObjectCode { | |||
46 | } | 50 | } |
47 | 51 | ||
48 | public long get(int object) { | 52 | public long get(int object) { |
49 | if(object < vector.length) { | 53 | if (object < vector.length) { |
50 | return vector[object]; | 54 | return vector[object]; |
51 | } else { | 55 | } else { |
52 | return 0; | 56 | return 0; |
@@ -56,17 +60,22 @@ public class ObjectCodeImpl implements ObjectCode { | |||
56 | public void set(int object, long value) { | 60 | public void set(int object, long value) { |
57 | ensureSize(object); | 61 | ensureSize(object); |
58 | final long valueToPut = value == 0 ? 1 : value; | 62 | final long valueToPut = value == 0 ? 1 : value; |
59 | vector[object]=valueToPut; | 63 | if (vector[object] == 0) effectiveSize++; |
64 | vector[object] = valueToPut; | ||
60 | } | 65 | } |
61 | 66 | ||
62 | public int getSize() { | 67 | public int getSize() { |
63 | return this.size; | 68 | return this.size; |
64 | } | 69 | } |
65 | 70 | ||
71 | public int getEffectiveSize() { | ||
72 | return this.effectiveSize; | ||
73 | } | ||
74 | |||
66 | @Override | 75 | @Override |
67 | public String toString() { | 76 | public String toString() { |
68 | return "ObjectCodeImpl{" + | 77 | return "ObjectCodeImpl{" + |
69 | "vector=" + Arrays.toString(Arrays.copyOf(vector,this.size)) + | 78 | "vector=" + Arrays.toString(Arrays.copyOf(vector, this.size)) + |
70 | '}'; | 79 | '}'; |
71 | } | 80 | } |
72 | } | 81 | } |