blob: 8c18550911a575f8955ca735fffe20f9a1f7c6f2 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
package tools.refinery.language.semantics.model.internal;
import org.eclipse.collections.api.factory.primitive.IntObjectMaps;
import tools.refinery.store.map.Cursor;
import tools.refinery.store.model.Tuple;
import tools.refinery.store.model.representation.TruthValue;
public class DecisionTree {
private final int levels;
private final DecisionTreeNode root;
public DecisionTree(int levels, TruthValue initialValue) {
this.levels = levels;
DecisionTreeNode node = new TerminalNode(IntObjectMaps.mutable.empty(),
DecisionTreeValue.fromTruthValue(initialValue));
for (int level = 1; level < levels; level++) {
node = new IntermediateNode(IntObjectMaps.mutable.empty(), node);
}
root = node;
}
public TruthValue get(Tuple tuple) {
return root.getValue(levels - 1, tuple).getTruthValue();
}
public void mergeValue(Tuple tuple, TruthValue truthValue) {
if (truthValue == null) {
return;
}
root.mergeValue(levels - 1, tuple, truthValue);
}
public void overwriteValues(DecisionTree values) {
root.overwriteValues(values.root);
}
public Cursor<Tuple, TruthValue> getCursor(TruthValue defaultValue, int nodeCount) {
return new DecisionTreeCursor(levels, defaultValue, nodeCount, root);
}
}
|