diff options
Diffstat (limited to 'store/src/main/java/org/eclipse/viatra/solver/data/model/representation')
4 files changed, 121 insertions, 0 deletions
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 @@ | |||
1 | package org.eclipse.viatra.solver.data.model.representation; | ||
2 | |||
3 | import org.eclipse.viatra.solver.data.map.ContinousHashProvider; | ||
4 | |||
5 | public class AuxilaryData<K,V> extends DataRepresentation<K, V> { | ||
6 | private final String name; | ||
7 | |||
8 | public AuxilaryData(String name, ContinousHashProvider<K> hashProvider, V defaultValue) { | ||
9 | super(hashProvider, defaultValue); | ||
10 | this.name = name; | ||
11 | } | ||
12 | |||
13 | @Override | ||
14 | public String getName() { | ||
15 | return name; | ||
16 | } | ||
17 | |||
18 | @Override | ||
19 | public boolean isValidKey(K key) { | ||
20 | return true; | ||
21 | } | ||
22 | } | ||
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 @@ | |||
1 | package org.eclipse.viatra.solver.data.model.representation; | ||
2 | |||
3 | import org.eclipse.viatra.solver.data.map.ContinousHashProvider; | ||
4 | |||
5 | public abstract class DataRepresentation<K, V> { | ||
6 | protected final ContinousHashProvider<K> hashProvider; | ||
7 | protected final V defaultValue; | ||
8 | |||
9 | protected DataRepresentation(ContinousHashProvider<K> hashProvider, V defaultValue) { | ||
10 | this.hashProvider = hashProvider; | ||
11 | this.defaultValue = defaultValue; | ||
12 | } | ||
13 | |||
14 | public abstract String getName(); | ||
15 | |||
16 | public ContinousHashProvider<K> getHashProvider() { | ||
17 | return hashProvider; | ||
18 | } | ||
19 | public abstract boolean isValidKey(K key); | ||
20 | |||
21 | public V getDefaultValue() { | ||
22 | return defaultValue; | ||
23 | } | ||
24 | } | ||
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 @@ | |||
1 | package org.eclipse.viatra.solver.data.model.representation; | ||
2 | |||
3 | import org.eclipse.viatra.solver.data.model.Tuple; | ||
4 | import org.eclipse.viatra.solver.data.model.TupleHashProvider; | ||
5 | |||
6 | public class Relation<D> extends DataRepresentation<Tuple, D> { | ||
7 | private final String name; | ||
8 | private final int arity; | ||
9 | |||
10 | public Relation(String name, int arity, D defaultValue) { | ||
11 | super(TupleHashProvider.singleton(), defaultValue); | ||
12 | this.name = name; | ||
13 | this.arity = arity; | ||
14 | } | ||
15 | |||
16 | @Override | ||
17 | public String getName() { | ||
18 | return name; | ||
19 | } | ||
20 | |||
21 | public int getArity() { | ||
22 | return arity; | ||
23 | } | ||
24 | |||
25 | @Override | ||
26 | public boolean isValidKey(Tuple key) { | ||
27 | if(key == null) { | ||
28 | return false; | ||
29 | } else return key.getSize() == getArity(); | ||
30 | } | ||
31 | } | ||
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 @@ | |||
1 | package org.eclipse.viatra.solver.data.model.representation; | ||
2 | |||
3 | public class TruthValue { | ||
4 | public static final TruthValue True = new TruthValue("true"); | ||
5 | public static final TruthValue False = new TruthValue("false"); | ||
6 | public static final TruthValue Unknown = new TruthValue("unknown"); | ||
7 | public static final TruthValue Error = new TruthValue("error"); | ||
8 | |||
9 | private final String name; | ||
10 | protected TruthValue(String name) { | ||
11 | this.name = name; | ||
12 | } | ||
13 | |||
14 | public String getName() { | ||
15 | return name; | ||
16 | } | ||
17 | |||
18 | public static TruthValue toTruthValue(boolean value) { | ||
19 | if(value) return True; | ||
20 | else return False; | ||
21 | } | ||
22 | public boolean isConsistent() { | ||
23 | return this != Error; | ||
24 | } | ||
25 | public boolean isComplete() { | ||
26 | return this != Unknown; | ||
27 | } | ||
28 | public boolean must() { | ||
29 | return this == True || this == Error; | ||
30 | } | ||
31 | public boolean may() { | ||
32 | return this == True || this == Unknown; | ||
33 | } | ||
34 | |||
35 | public TruthValue not() { | ||
36 | if(this == True) { | ||
37 | return False; | ||
38 | } else if(this == False) { | ||
39 | return True; | ||
40 | } else { | ||
41 | return this; | ||
42 | } | ||
43 | } | ||
44 | } | ||