From a155f6ba02e08a75ce6e474a86900b8363f506e8 Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Wed, 29 Sep 2021 02:45:57 +0200 Subject: build: migration to Gradle 7 --- .../eclipse/viatra/solver/data/model/Model.java | 20 +++ .../viatra/solver/data/model/ModelCursor.java | 25 ++++ .../viatra/solver/data/model/ModelDiffCursor.java | 26 ++++ .../viatra/solver/data/model/ModelStore.java | 16 +++ .../viatra/solver/data/model/ModelStoreImpl.java | 127 ++++++++++++++++++ .../eclipse/viatra/solver/data/model/Tuple.java | 148 +++++++++++++++++++++ .../solver/data/model/TupleHashProvider.java | 65 +++++++++ .../data/model/TupleHashProviderBitMagic.java | 28 ++++ .../solver/data/model/internal/ModelImpl.java | 124 +++++++++++++++++ .../internal/SimilarRelationEquivalenceClass.java | 33 +++++ .../data/model/representation/AuxilaryData.java | 22 +++ .../model/representation/DataRepresentation.java | 24 ++++ .../solver/data/model/representation/Relation.java | 31 +++++ .../data/model/representation/TruthValue.java | 44 ++++++ 14 files changed, 733 insertions(+) create mode 100644 store/src/main/java/org/eclipse/viatra/solver/data/model/Model.java create mode 100644 store/src/main/java/org/eclipse/viatra/solver/data/model/ModelCursor.java create mode 100644 store/src/main/java/org/eclipse/viatra/solver/data/model/ModelDiffCursor.java create mode 100644 store/src/main/java/org/eclipse/viatra/solver/data/model/ModelStore.java create mode 100644 store/src/main/java/org/eclipse/viatra/solver/data/model/ModelStoreImpl.java create mode 100644 store/src/main/java/org/eclipse/viatra/solver/data/model/Tuple.java create mode 100644 store/src/main/java/org/eclipse/viatra/solver/data/model/TupleHashProvider.java create mode 100644 store/src/main/java/org/eclipse/viatra/solver/data/model/TupleHashProviderBitMagic.java create mode 100644 store/src/main/java/org/eclipse/viatra/solver/data/model/internal/ModelImpl.java create mode 100644 store/src/main/java/org/eclipse/viatra/solver/data/model/internal/SimilarRelationEquivalenceClass.java create mode 100644 store/src/main/java/org/eclipse/viatra/solver/data/model/representation/AuxilaryData.java create mode 100644 store/src/main/java/org/eclipse/viatra/solver/data/model/representation/DataRepresentation.java create mode 100644 store/src/main/java/org/eclipse/viatra/solver/data/model/representation/Relation.java create mode 100644 store/src/main/java/org/eclipse/viatra/solver/data/model/representation/TruthValue.java (limited to 'store/src/main/java/org/eclipse/viatra/solver/data/model') diff --git a/store/src/main/java/org/eclipse/viatra/solver/data/model/Model.java b/store/src/main/java/org/eclipse/viatra/solver/data/model/Model.java new file mode 100644 index 00000000..2b21e3e7 --- /dev/null +++ b/store/src/main/java/org/eclipse/viatra/solver/data/model/Model.java @@ -0,0 +1,20 @@ +package org.eclipse.viatra.solver.data.model; + +import java.util.Set; + +import org.eclipse.viatra.solver.data.map.Cursor; +import org.eclipse.viatra.solver.data.map.Versioned; +import org.eclipse.viatra.solver.data.model.representation.DataRepresentation; + +public interface Model extends Versioned{ + @SuppressWarnings("squid:S1452") + Set> getDataRepresentations(); + + V get(DataRepresentation representation, K key); + Cursor getAll(DataRepresentation representation); + V put(DataRepresentation representation, K key, V value); + void putAll(DataRepresentation representation, Cursor cursor); + long getSize(DataRepresentation representation); + + ModelDiffCursor getDiffCursor(long to); +} diff --git a/store/src/main/java/org/eclipse/viatra/solver/data/model/ModelCursor.java b/store/src/main/java/org/eclipse/viatra/solver/data/model/ModelCursor.java new file mode 100644 index 00000000..3157c9f0 --- /dev/null +++ b/store/src/main/java/org/eclipse/viatra/solver/data/model/ModelCursor.java @@ -0,0 +1,25 @@ +package org.eclipse.viatra.solver.data.model; + +import java.util.Map; + +import org.eclipse.viatra.solver.data.map.Cursor; +import org.eclipse.viatra.solver.data.model.representation.DataRepresentation; + +public class ModelCursor { + final Map,Cursor> cursors; + + public ModelCursor(Map, Cursor> cursors) { + super(); + this.cursors = cursors; + } + + @SuppressWarnings("unchecked") + public Cursor getCursor(DataRepresentation representation) { + Cursor cursor = cursors.get(representation); + if(cursor != null) { + return (Cursor) cursor; + } else { + throw new IllegalArgumentException("ModelCursor does not contain cursor for representation "+representation); + } + } +} diff --git a/store/src/main/java/org/eclipse/viatra/solver/data/model/ModelDiffCursor.java b/store/src/main/java/org/eclipse/viatra/solver/data/model/ModelDiffCursor.java new file mode 100644 index 00000000..d3551e47 --- /dev/null +++ b/store/src/main/java/org/eclipse/viatra/solver/data/model/ModelDiffCursor.java @@ -0,0 +1,26 @@ +package org.eclipse.viatra.solver.data.model; + +import java.util.Map; + +import org.eclipse.viatra.solver.data.map.Cursor; +import org.eclipse.viatra.solver.data.map.DiffCursor; +import org.eclipse.viatra.solver.data.model.representation.DataRepresentation; + +public class ModelDiffCursor { + final Map,DiffCursor> diffcursors; + + public ModelDiffCursor(Map, DiffCursor> diffcursors) { + super(); + this.diffcursors = diffcursors; + } + + @SuppressWarnings("unchecked") + public DiffCursor getCursor(DataRepresentation representation) { + Cursor cursor = diffcursors.get(representation); + if(cursor != null) { + return (DiffCursor) cursor; + } else { + throw new IllegalArgumentException("ModelCursor does not contain cursor for representation "+representation); + } + } +} diff --git a/store/src/main/java/org/eclipse/viatra/solver/data/model/ModelStore.java b/store/src/main/java/org/eclipse/viatra/solver/data/model/ModelStore.java new file mode 100644 index 00000000..35ac72b5 --- /dev/null +++ b/store/src/main/java/org/eclipse/viatra/solver/data/model/ModelStore.java @@ -0,0 +1,16 @@ +package org.eclipse.viatra.solver.data.model; + +import java.util.Set; + +import org.eclipse.viatra.solver.data.model.representation.DataRepresentation; + +public interface ModelStore { + @SuppressWarnings("squid:S1452") + Set> getDataRepresentations(); + + Model createModel(); + Model createModel(long state); + + Set getStates(); + ModelDiffCursor getDiffCursor(long from, long to); +} \ No newline at end of file diff --git a/store/src/main/java/org/eclipse/viatra/solver/data/model/ModelStoreImpl.java b/store/src/main/java/org/eclipse/viatra/solver/data/model/ModelStoreImpl.java new file mode 100644 index 00000000..f5e3b141 --- /dev/null +++ b/store/src/main/java/org/eclipse/viatra/solver/data/model/ModelStoreImpl.java @@ -0,0 +1,127 @@ +package org.eclipse.viatra.solver.data.model; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +import org.eclipse.viatra.solver.data.map.ContinousHashProvider; +import org.eclipse.viatra.solver.data.map.DiffCursor; +import org.eclipse.viatra.solver.data.map.VersionedMap; +import org.eclipse.viatra.solver.data.map.VersionedMapStore; +import org.eclipse.viatra.solver.data.map.VersionedMapStoreImpl; +import org.eclipse.viatra.solver.data.model.internal.ModelImpl; +import org.eclipse.viatra.solver.data.model.internal.SimilarRelationEquivalenceClass; +import org.eclipse.viatra.solver.data.model.representation.AuxilaryData; +import org.eclipse.viatra.solver.data.model.representation.DataRepresentation; +import org.eclipse.viatra.solver.data.model.representation.Relation; + +public class ModelStoreImpl implements ModelStore { + + private final Map, VersionedMapStore> stores; + + public ModelStoreImpl(Set> dataRepresentations) { + stores = initStores(dataRepresentations); + } + + private Map, VersionedMapStore> initStores( + Set> dataRepresentations) { + Map, VersionedMapStore> result = new HashMap<>(); + + Map>> symbolRepresentationsPerHashPerArity = new HashMap<>(); + + for (DataRepresentation dataRepresentation : dataRepresentations) { + if (dataRepresentation instanceof Relation) { + Relation symbolRepresentation = (Relation) dataRepresentation; + addOrCreate(symbolRepresentationsPerHashPerArity, + new SimilarRelationEquivalenceClass(symbolRepresentation), symbolRepresentation); + } else if (dataRepresentation instanceof AuxilaryData) { + VersionedMapStoreImpl store = new VersionedMapStoreImpl<>(dataRepresentation.getHashProvider(), + dataRepresentation.getDefaultValue()); + result.put(dataRepresentation, store); + } else { + throw new UnsupportedOperationException( + "Model store does not have strategy to use " + dataRepresentation.getClass() + "!"); + } + } + for (List> symbolGroup : symbolRepresentationsPerHashPerArity.values()) { + initRepresentationGroup(result, symbolGroup); + } + + return result; + } + + private void initRepresentationGroup(Map, VersionedMapStore> result, + List> symbolGroup) { + final ContinousHashProvider hashProvider = symbolGroup.get(0).getHashProvider(); + final Object defaultValue = symbolGroup.get(0).getDefaultValue(); + + List> maps = VersionedMapStoreImpl + .createSharedVersionedMapStores(symbolGroup.size(), hashProvider, defaultValue); + + for (int i = 0; i < symbolGroup.size(); i++) { + result.put(symbolGroup.get(i), maps.get(i)); + } + } + + private static void addOrCreate(Map> map, K key, V value) { + List list; + if (map.containsKey(key)) { + list = map.get(key); + } else { + list = new LinkedList<>(); + map.put(key, list); + } + list.add(value); + } + + @Override + public Set> getDataRepresentations() { + return this.stores.keySet(); + } + + @Override + public ModelImpl createModel() { + Map, VersionedMap> maps = new HashMap<>(); + for (Entry, VersionedMapStore> entry : this.stores.entrySet()) { + maps.put(entry.getKey(), entry.getValue().createMap()); + } + return new ModelImpl(this, maps); + } + + @Override + public synchronized ModelImpl createModel(long state) { + Map, VersionedMap> maps = new HashMap<>(); + for (Entry, VersionedMapStore> entry : this.stores.entrySet()) { + maps.put(entry.getKey(), entry.getValue().createMap(state)); + } + return new ModelImpl(this, maps); + } + + @Override + @SuppressWarnings("squid:S1751") + public synchronized Set getStates() { + // if not empty, return first + for(VersionedMapStore store : stores.values()) { + return new HashSet<>(store.getStates()); + } + // if empty + Set result = new HashSet<>(); + result.add(0l); + return result; + } + + @Override + public synchronized ModelDiffCursor getDiffCursor(long from, long to) { + Map,DiffCursor> diffcursors = new HashMap<>(); + for(Entry, VersionedMapStore> entry : stores.entrySet()) { + DataRepresentation representation = entry.getKey(); + DiffCursor diffCursor = entry.getValue().getDiffCursor(from, to); + diffcursors.put(representation, diffCursor); + } + return new ModelDiffCursor(diffcursors); + } +} diff --git a/store/src/main/java/org/eclipse/viatra/solver/data/model/Tuple.java b/store/src/main/java/org/eclipse/viatra/solver/data/model/Tuple.java new file mode 100644 index 00000000..ca6548a4 --- /dev/null +++ b/store/src/main/java/org/eclipse/viatra/solver/data/model/Tuple.java @@ -0,0 +1,148 @@ +package org.eclipse.viatra.solver.data.model; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public abstract class Tuple { + private static final int CUSTOMTUPLESIZE = 2; + protected static final List tuple1Cash = new ArrayList<>(1024); + + public abstract int getSize(); + public abstract int get(int element); + public abstract int[] toArray(); + + @Override + public String toString() { + StringBuilder b = new StringBuilder(); + b.append("["); + for(int i = 0; i= tuple1Cash.size()) { + newlyCreated = new Tuple1(tuple1Cash.size()); + tuple1Cash.add(newlyCreated); + } + return newlyCreated; + } + } + + public static Tuple of(int... values) { + if(values.length == 0) { + return new Tuple0(); + } else if(values.length == 1) { + return of1(values[0]); + } else if(values.length == 2) { + return new Tuple2(values[0],values[1]); + } else return new TupleN(values); + } + + protected IllegalArgumentException doesNotContain(int element) { + return new IllegalArgumentException("Tuple does not contain element "+element); + } + + public static class Tuple0 extends Tuple{ + protected Tuple0() { } + @Override public int getSize() { return 0; } + @Override public int get(int element) { + throw doesNotContain(element); + } + @Override public int[] toArray() {return new int[]{};} + @Override public int hashCode() { return TupleHashProvider.singleton().getHash(this, 0); } + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + return true; + } + } + public static class Tuple1 extends Tuple{ + final int value0; + protected Tuple1(int value0) { this.value0 = value0; } + @Override public int getSize() { return 1; } + @Override public int get(int element) { + if(element == 0) return value0; + throw doesNotContain(element); + } + @Override public int[] toArray() {return new int[]{ value0 };} + @Override public int hashCode() { return TupleHashProvider.singleton().getHash(this, 0); } + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Tuple1 other = (Tuple1) obj; + return value0 == other.value0; + } + } + public static class Tuple2 extends Tuple{ + final int value0; + final int value1; + protected Tuple2(int value0, int value1) { this.value0 = value0; this.value1 = value1; } + @Override public int getSize() { return 2; } + @Override public int get(int element) { + if(element == 0) return value0; + else if(element == 1) return value1; + throw doesNotContain(element); + } + @Override public int[] toArray() {return new int[]{ value0,value1 };} + @Override public int hashCode() { return TupleHashProvider.singleton().getHash(this, 0); } + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Tuple2 other = (Tuple2) obj; + return value0 == other.value0 && value1 == other.value1; + } + } + public static class TupleN extends Tuple{ + final int[] values; + protected TupleN(int[] values) { + if(values.length { + protected static TupleHashProvider instance; + + public static TupleHashProvider singleton() { + if (instance == null) { + instance = new TupleHashProvider(); + } + return instance; + } + + protected static final int[] primes = new int[] { 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, + 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, + 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, + 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, + 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, + 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, + 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, + 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, 1009, 1013, 1019, 1021, + 1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069, 1087, 1091, 1093, 1097, 1103, 1109, 1117, 1123, 1129, 1151, + 1153, 1163, 1171, 1181, 1187, 1193, 1201, 1213, 1217, 1223, 1229, 1231, 1237, 1249, 1259, 1277, 1279, 1283, + 1289, 1291, 1297, 1301, 1303, 1307, 1319, 1321, 1327, 1361, 1367, 1373, 1381, 1399, 1409, 1423, 1427, 1429, + 1433, 1439, 1447, 1451, 1453, 1459, 1471, 1481, 1483, 1487, 1489, 1493, 1499, 1511, 1523, 1531, 1543, 1549, + 1553, 1559, 1567, 1571, 1579, 1583, 1597, 1601, 1607, 1609, 1613, 1619, 1621, 1627, 1637, 1657, 1663, 1667, + 1669, 1693, 1697, 1699, 1709, 1721, 1723, 1733, 1741, 1747, 1753, 1759, 1777, 1783, 1787, 1789, 1801, 1811, + 1823, 1831, 1847, 1861, 1867, 1871, 1873, 1877, 1879, 1889, 1901, 1907, 1913, 1931, 1933, 1949, 1951, 1973, + 1979, 1987, 1993, 1997, 1999, 2003, 2011, 2017, 2027, 2029, 2039, 2053, 2063, 2069, 2081, 2083, 2087, 2089, + 2099, 2111, 2113, 2129, 2131, 2137, 2141, 2143, 2153, 2161, 2179, 2203, 2207, 2213, 2221, 2237, 2239, 2243, + 2251, 2267, 2269, 2273, 2281, 2287, 2293, 2297, 2309, 2311, 2333, 2339, 2341, 2347, 2351, 2357, 2371, 2377, + 2381, 2383, 2389, 2393, 2399, 2411, 2417, 2423, 2437, 2441, 2447, 2459, 2467, 2473, 2477, 2503, 2521, 2531, + 2539, 2543, 2549, 2551, 2557, 2579, 2591, 2593, 2609, 2617, 2621, 2633, 2647, 2657, 2659, 2663, 2671, 2677, + 2683, 2687, 2689, 2693, 2699, 2707, 2711, 2713, 2719, 2729, 2731, 2741, 2749, 2753, 2767, 2777, 2789, 2791, + 2797, 2801, 2803, 2819, 3089, 3109, 3119, 3121, 3137, 3163, 3167, 3169, 3181, 3187, 3191, 3203, 3209, 3217, + 3221, 3229, 3251, 3253, 3257, 3259, 3271, 3299, 3301, 3307, 3313, 3319, 3323, 3329, 3331, 3343, 3347, 3359, + 3361, 3371, 3373, 3389, 3391, 3407, 3413, 3433, 3449, 3457, 3461, 3463, 3467, 3469, 3491, 3499, 3511, 3517, + 3527, 3529, 3533, 3539, 3541, 3547, 3557, 3559, 3571, 3581, 3583, 3593, 3607, 3613, 3617, 3623, 3631, 3637, + 3643, 3659, 3671, 3673, 3677, 3691, 3697, 3701, 3709, 3719, 3727, 3733, 3739, 3761, 3767, 3769, 3779, 3793, + 3797, 3803, 3821, 3823, 3833, 3847, 3851, 3853, 3863, 3877, 3881, 3889, 3907, 3911 }; + + protected static final long LARGESTPRIME30BITS = 1073741789; + + public TupleHashProvider() { + if (primes.length < MAX_PRACTICAL_DEPTH) { + throw new UnsupportedOperationException( + "Not enough prime numbers to support the practical depth of continuous hash!"); + } + } + + @Override + public int getHash(Tuple key, int index) { + if (index >= primes.length) { + throw new IllegalArgumentException("Not enough prime numbers to support index"); + } + long accumulator = 0; + final int prime = primes[index]; + for (int i = 0; i < key.getSize(); i++) { + accumulator = (prime * accumulator + key.get(i)) % LARGESTPRIME30BITS; + } + + return (int) accumulator; + } +} diff --git a/store/src/main/java/org/eclipse/viatra/solver/data/model/TupleHashProviderBitMagic.java b/store/src/main/java/org/eclipse/viatra/solver/data/model/TupleHashProviderBitMagic.java new file mode 100644 index 00000000..2a514d66 --- /dev/null +++ b/store/src/main/java/org/eclipse/viatra/solver/data/model/TupleHashProviderBitMagic.java @@ -0,0 +1,28 @@ +package org.eclipse.viatra.solver.data.model; + +import org.eclipse.viatra.solver.data.map.ContinousHashProvider; + +public class TupleHashProviderBitMagic implements ContinousHashProvider { + + @Override + public int getHash(Tuple key, int index) { + if(key.getSize() == 1) { + return key.get(0); + } + + int result = 0; + final int startBitIndex = index*30; + final int finalBitIndex = startBitIndex+30; + final int arity = key.getSize(); + + for(int i = startBitIndex; i<=finalBitIndex; i++) { + final int selectedKey = key.get(i%arity); + final int selectedPosition = 1<<(i/arity); + if((selectedKey&selectedPosition) != 0) { + result |= 1<<(i%30); + } + } + + return result; + } +} diff --git a/store/src/main/java/org/eclipse/viatra/solver/data/model/internal/ModelImpl.java b/store/src/main/java/org/eclipse/viatra/solver/data/model/internal/ModelImpl.java new file mode 100644 index 00000000..6d7f4e97 --- /dev/null +++ b/store/src/main/java/org/eclipse/viatra/solver/data/model/internal/ModelImpl.java @@ -0,0 +1,124 @@ +package org.eclipse.viatra.solver.data.model.internal; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +import org.eclipse.viatra.solver.data.map.ContinousHashProvider; +import org.eclipse.viatra.solver.data.map.Cursor; +import org.eclipse.viatra.solver.data.map.DiffCursor; +import org.eclipse.viatra.solver.data.map.VersionedMap; +import org.eclipse.viatra.solver.data.map.internal.MapDiffCursor; +import org.eclipse.viatra.solver.data.model.Model; +import org.eclipse.viatra.solver.data.model.ModelDiffCursor; +import org.eclipse.viatra.solver.data.model.ModelStore; +import org.eclipse.viatra.solver.data.model.representation.DataRepresentation; + +public class ModelImpl implements Model { + private final ModelStore store; + private final Map, VersionedMap> maps; + + public ModelImpl(ModelStore store, Map, VersionedMap> maps) { + this.store = store; + this.maps = maps; + } + + @Override + public Set> getDataRepresentations() { + return maps.keySet(); + } + + @SuppressWarnings("unchecked") + private VersionedMap getMap(DataRepresentation representation) { + if (maps.containsKey(representation)) { + return (VersionedMap) maps.get(representation); + } else { + throw new IllegalArgumentException("Model does have representation " + representation); + } + } + + private VersionedMap getMapValidateKey(DataRepresentation representation, K key) { + if (representation.isValidKey(key)) { + return getMap(representation); + } else { + throw new IllegalArgumentException( + "Key is not valid for representation! (representation=" + representation + ", key=" + key + ");"); + } + } + + @Override + public V get(DataRepresentation representation, K key) { + return getMapValidateKey(representation, key).get(key); + } + + @Override + public Cursor getAll(DataRepresentation representation) { + return getMap(representation).getAll(); + } + + @Override + public V put(DataRepresentation representation, K key, V value) { + return getMapValidateKey(representation, key).put(key, value); + } + + @Override + public void putAll(DataRepresentation representation, Cursor cursor) { + getMap(representation).putAll(cursor); + } + + @Override + public long getSize(DataRepresentation representation) { + return getMap(representation).getSize(); + } + + @Override + public ModelDiffCursor getDiffCursor(long to) { + Model toModel = store.createModel(to); + Map, DiffCursor> diffCursors = new HashMap<>(); + for (DataRepresentation representation : this.maps.keySet()) { + MapDiffCursor diffCursor = constructDiffCursor(toModel, representation); + diffCursors.put(representation, diffCursor); + } + return new ModelDiffCursor(diffCursors); + } + + private MapDiffCursor constructDiffCursor(Model toModel, DataRepresentation representation) { + @SuppressWarnings("unchecked") + Cursor fromCursor = (Cursor) this.maps.get(representation).getAll(); + Cursor toCursor = toModel.getAll(representation); + + ContinousHashProvider hashProvider = representation.getHashProvider(); + V defaultValue = representation.getDefaultValue(); + return new MapDiffCursor<>(hashProvider, defaultValue, fromCursor, toCursor); + } + + @Override + public long commit() { + long version = 0; + boolean versionSet = false; + for (VersionedMap map : maps.values()) { + long newVersion = map.commit(); + if (versionSet) { + if (version != newVersion) { + throw new IllegalStateException( + "Maps in model have different versions! (" + version + " and" + newVersion + ")"); + } + } else { + version = newVersion; + versionSet = true; + } + } + return version; + } + + @Override + public void restore(long state) { + if(store.getStates().contains(state)) { + for (VersionedMap map : maps.values()) { + map.restore(state); + } + } else { + throw new IllegalArgumentException("Map does not contain state "+state+"!"); + } + } +} diff --git a/store/src/main/java/org/eclipse/viatra/solver/data/model/internal/SimilarRelationEquivalenceClass.java b/store/src/main/java/org/eclipse/viatra/solver/data/model/internal/SimilarRelationEquivalenceClass.java new file mode 100644 index 00000000..7054e4db --- /dev/null +++ b/store/src/main/java/org/eclipse/viatra/solver/data/model/internal/SimilarRelationEquivalenceClass.java @@ -0,0 +1,33 @@ +package org.eclipse.viatra.solver.data.model.internal; + +import java.util.Objects; + +import org.eclipse.viatra.solver.data.map.ContinousHashProvider; +import org.eclipse.viatra.solver.data.model.Tuple; +import org.eclipse.viatra.solver.data.model.representation.Relation; + +public class SimilarRelationEquivalenceClass { + final ContinousHashProvider hashProvider; + final Object defaultValue; + final int arity; + public SimilarRelationEquivalenceClass(Relation representation) { + this.hashProvider = representation.getHashProvider(); + this.defaultValue = representation.getDefaultValue(); + this.arity = representation.getArity(); + } + @Override + public int hashCode() { + return Objects.hash(arity, defaultValue, hashProvider); + } + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!(obj instanceof SimilarRelationEquivalenceClass)) + return false; + SimilarRelationEquivalenceClass other = (SimilarRelationEquivalenceClass) obj; + return arity == other.arity && Objects.equals(defaultValue, other.defaultValue) + && Objects.equals(hashProvider, other.hashProvider); + } + +} diff --git a/store/src/main/java/org/eclipse/viatra/solver/data/model/representation/AuxilaryData.java b/store/src/main/java/org/eclipse/viatra/solver/data/model/representation/AuxilaryData.java new file mode 100644 index 00000000..7fc79348 --- /dev/null +++ b/store/src/main/java/org/eclipse/viatra/solver/data/model/representation/AuxilaryData.java @@ -0,0 +1,22 @@ +package org.eclipse.viatra.solver.data.model.representation; + +import org.eclipse.viatra.solver.data.map.ContinousHashProvider; + +public class AuxilaryData extends DataRepresentation { + private final String name; + + public AuxilaryData(String name, ContinousHashProvider hashProvider, V defaultValue) { + super(hashProvider, defaultValue); + this.name = name; + } + + @Override + public String getName() { + return name; + } + + @Override + public boolean isValidKey(K key) { + return true; + } +} diff --git a/store/src/main/java/org/eclipse/viatra/solver/data/model/representation/DataRepresentation.java b/store/src/main/java/org/eclipse/viatra/solver/data/model/representation/DataRepresentation.java new file mode 100644 index 00000000..fd48eb94 --- /dev/null +++ b/store/src/main/java/org/eclipse/viatra/solver/data/model/representation/DataRepresentation.java @@ -0,0 +1,24 @@ +package org.eclipse.viatra.solver.data.model.representation; + +import org.eclipse.viatra.solver.data.map.ContinousHashProvider; + +public abstract class DataRepresentation { + protected final ContinousHashProvider hashProvider; + protected final V defaultValue; + + protected DataRepresentation(ContinousHashProvider hashProvider, V defaultValue) { + this.hashProvider = hashProvider; + this.defaultValue = defaultValue; + } + + public abstract String getName(); + + public ContinousHashProvider getHashProvider() { + return hashProvider; + } + public abstract boolean isValidKey(K key); + + public V getDefaultValue() { + return defaultValue; + } +} diff --git a/store/src/main/java/org/eclipse/viatra/solver/data/model/representation/Relation.java b/store/src/main/java/org/eclipse/viatra/solver/data/model/representation/Relation.java new file mode 100644 index 00000000..eafb5c56 --- /dev/null +++ b/store/src/main/java/org/eclipse/viatra/solver/data/model/representation/Relation.java @@ -0,0 +1,31 @@ +package org.eclipse.viatra.solver.data.model.representation; + +import org.eclipse.viatra.solver.data.model.Tuple; +import org.eclipse.viatra.solver.data.model.TupleHashProvider; + +public class Relation extends DataRepresentation { + private final String name; + private final int arity; + + public Relation(String name, int arity, D defaultValue) { + super(TupleHashProvider.singleton(), defaultValue); + this.name = name; + this.arity = arity; + } + + @Override + public String getName() { + return name; + } + + public int getArity() { + return arity; + } + + @Override + public boolean isValidKey(Tuple key) { + if(key == null) { + return false; + } else return key.getSize() == getArity(); + } +} diff --git a/store/src/main/java/org/eclipse/viatra/solver/data/model/representation/TruthValue.java b/store/src/main/java/org/eclipse/viatra/solver/data/model/representation/TruthValue.java new file mode 100644 index 00000000..aeccde9e --- /dev/null +++ b/store/src/main/java/org/eclipse/viatra/solver/data/model/representation/TruthValue.java @@ -0,0 +1,44 @@ +package org.eclipse.viatra.solver.data.model.representation; + +public class TruthValue { + public static final TruthValue True = new TruthValue("true"); + public static final TruthValue False = new TruthValue("false"); + public static final TruthValue Unknown = new TruthValue("unknown"); + public static final TruthValue Error = new TruthValue("error"); + + private final String name; + protected TruthValue(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public static TruthValue toTruthValue(boolean value) { + if(value) return True; + else return False; + } + public boolean isConsistent() { + return this != Error; + } + public boolean isComplete() { + return this != Unknown; + } + public boolean must() { + return this == True || this == Error; + } + public boolean may() { + return this == True || this == Unknown; + } + + public TruthValue not() { + if(this == True) { + return False; + } else if(this == False) { + return True; + } else { + return this; + } + } +} -- cgit v1.2.3-54-g00ecf