aboutsummaryrefslogtreecommitdiffstats
path: root/store/src/main/java/org/eclipse/viatra/solver/data/model
diff options
context:
space:
mode:
Diffstat (limited to 'store/src/main/java/org/eclipse/viatra/solver/data/model')
-rw-r--r--store/src/main/java/org/eclipse/viatra/solver/data/model/ModelStoreImpl.java26
-rw-r--r--store/src/main/java/org/eclipse/viatra/solver/data/model/representation/TruthValue.java47
2 files changed, 37 insertions, 36 deletions
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
index f5e3b141..a97fb27a 100644
--- 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
@@ -1,7 +1,6 @@
1package org.eclipse.viatra.solver.data.model; 1package org.eclipse.viatra.solver.data.model;
2 2
3import java.util.HashMap; 3import java.util.HashMap;
4import java.util.HashSet;
5import java.util.LinkedList; 4import java.util.LinkedList;
6import java.util.List; 5import java.util.List;
7import java.util.Map; 6import java.util.Map;
@@ -34,8 +33,7 @@ public class ModelStoreImpl implements ModelStore {
34 Map<SimilarRelationEquivalenceClass, List<Relation<?>>> symbolRepresentationsPerHashPerArity = new HashMap<>(); 33 Map<SimilarRelationEquivalenceClass, List<Relation<?>>> symbolRepresentationsPerHashPerArity = new HashMap<>();
35 34
36 for (DataRepresentation<?, ?> dataRepresentation : dataRepresentations) { 35 for (DataRepresentation<?, ?> dataRepresentation : dataRepresentations) {
37 if (dataRepresentation instanceof Relation<?>) { 36 if (dataRepresentation instanceof Relation<?> symbolRepresentation) {
38 Relation<?> symbolRepresentation = (Relation<?>) dataRepresentation;
39 addOrCreate(symbolRepresentationsPerHashPerArity, 37 addOrCreate(symbolRepresentationsPerHashPerArity,
40 new SimilarRelationEquivalenceClass(symbolRepresentation), symbolRepresentation); 38 new SimilarRelationEquivalenceClass(symbolRepresentation), symbolRepresentation);
41 } else if (dataRepresentation instanceof AuxilaryData<?, ?>) { 39 } else if (dataRepresentation instanceof AuxilaryData<?, ?>) {
@@ -58,10 +56,10 @@ public class ModelStoreImpl implements ModelStore {
58 List<Relation<?>> symbolGroup) { 56 List<Relation<?>> symbolGroup) {
59 final ContinousHashProvider<Tuple> hashProvider = symbolGroup.get(0).getHashProvider(); 57 final ContinousHashProvider<Tuple> hashProvider = symbolGroup.get(0).getHashProvider();
60 final Object defaultValue = symbolGroup.get(0).getDefaultValue(); 58 final Object defaultValue = symbolGroup.get(0).getDefaultValue();
61 59
62 List<VersionedMapStore<Tuple, Object>> maps = VersionedMapStoreImpl 60 List<VersionedMapStore<Tuple, Object>> maps = VersionedMapStoreImpl
63 .createSharedVersionedMapStores(symbolGroup.size(), hashProvider, defaultValue); 61 .createSharedVersionedMapStores(symbolGroup.size(), hashProvider, defaultValue);
64 62
65 for (int i = 0; i < symbolGroup.size(); i++) { 63 for (int i = 0; i < symbolGroup.size(); i++) {
66 result.put(symbolGroup.get(i), maps.get(i)); 64 result.put(symbolGroup.get(i), maps.get(i));
67 } 65 }
@@ -100,24 +98,20 @@ public class ModelStoreImpl implements ModelStore {
100 } 98 }
101 return new ModelImpl(this, maps); 99 return new ModelImpl(this, maps);
102 } 100 }
103 101
104 @Override 102 @Override
105 @SuppressWarnings("squid:S1751")
106 public synchronized Set<Long> getStates() { 103 public synchronized Set<Long> getStates() {
107 // if not empty, return first 104 var iterator = stores.values().iterator();
108 for(VersionedMapStore<?, ?> store : stores.values()) { 105 if (iterator.hasNext()) {
109 return new HashSet<>(store.getStates()); 106 return Set.copyOf(iterator.next().getStates());
110 } 107 }
111 // if empty 108 return Set.of(0l);
112 Set<Long> result = new HashSet<>();
113 result.add(0l);
114 return result;
115 } 109 }
116 110
117 @Override 111 @Override
118 public synchronized ModelDiffCursor getDiffCursor(long from, long to) { 112 public synchronized ModelDiffCursor getDiffCursor(long from, long to) {
119 Map<DataRepresentation<?, ?>,DiffCursor<?,?>> diffcursors = new HashMap<>(); 113 Map<DataRepresentation<?, ?>, DiffCursor<?, ?>> diffcursors = new HashMap<>();
120 for(Entry<DataRepresentation<?, ?>, VersionedMapStore<?, ?>> entry : stores.entrySet()) { 114 for (Entry<DataRepresentation<?, ?>, VersionedMapStore<?, ?>> entry : stores.entrySet()) {
121 DataRepresentation<?, ?> representation = entry.getKey(); 115 DataRepresentation<?, ?> representation = entry.getKey();
122 DiffCursor<?, ?> diffCursor = entry.getValue().getDiffCursor(from, to); 116 DiffCursor<?, ?> diffCursor = entry.getValue().getDiffCursor(from, to);
123 diffcursors.put(representation, diffCursor); 117 diffcursors.put(representation, diffCursor);
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
index aeccde9e..049c7eac 100644
--- 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
@@ -1,42 +1,49 @@
1package org.eclipse.viatra.solver.data.model.representation; 1package org.eclipse.viatra.solver.data.model.representation;
2 2
3public class TruthValue { 3public enum TruthValue {
4 public static final TruthValue True = new TruthValue("true"); 4 TRUE("true"),
5 public static final TruthValue False = new TruthValue("false"); 5
6 public static final TruthValue Unknown = new TruthValue("unknown"); 6 FALSE("false"),
7 public static final TruthValue Error = new TruthValue("error"); 7
8 8 UNKNOWN("unknown"),
9
10 ERROR("error");
11
9 private final String name; 12 private final String name;
10 protected TruthValue(String name) { 13
14 private TruthValue(String name) {
11 this.name = name; 15 this.name = name;
12 } 16 }
13 17
14 public String getName() { 18 public String getName() {
15 return name; 19 return name;
16 } 20 }
17 21
18 public static TruthValue toTruthValue(boolean value) { 22 public static TruthValue toTruthValue(boolean value) {
19 if(value) return True; 23 return value ? TRUE : FALSE;
20 else return False;
21 } 24 }
25
22 public boolean isConsistent() { 26 public boolean isConsistent() {
23 return this != Error; 27 return this != ERROR;
24 } 28 }
29
25 public boolean isComplete() { 30 public boolean isComplete() {
26 return this != Unknown; 31 return this != UNKNOWN;
27 } 32 }
33
28 public boolean must() { 34 public boolean must() {
29 return this == True || this == Error; 35 return this == TRUE || this == ERROR;
30 } 36 }
37
31 public boolean may() { 38 public boolean may() {
32 return this == True || this == Unknown; 39 return this == TRUE || this == UNKNOWN;
33 } 40 }
34 41
35 public TruthValue not() { 42 public TruthValue not() {
36 if(this == True) { 43 if (this == TRUE) {
37 return False; 44 return FALSE;
38 } else if(this == False) { 45 } else if (this == FALSE) {
39 return True; 46 return TRUE;
40 } else { 47 } else {
41 return this; 48 return this;
42 } 49 }