blob: b6bccb01640328fecfe1fc2354e1a08fa0f75f1a (
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
|
/*
* SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/>
*
* SPDX-License-Identifier: EPL-2.0
*/
package tools.refinery.store.reasoning.refinement;
import tools.refinery.store.model.Model;
import tools.refinery.store.reasoning.ReasoningAdapter;
import tools.refinery.store.reasoning.representation.PartialSymbol;
import tools.refinery.store.reasoning.seed.ModelSeed;
public class RefinementBasedInitializer<A, C> implements PartialModelInitializer {
private final PartialSymbol<A, C> partialSymbol;
public RefinementBasedInitializer(PartialSymbol<A, C> partialSymbol) {
this.partialSymbol = partialSymbol;
}
@Override
public void initialize(Model model, ModelSeed modelSeed) {
var refiner = model.getAdapter(ReasoningAdapter.class).getRefiner(partialSymbol);
var defaultValue = partialSymbol.abstractDomain().unknown();
var cursor = modelSeed.getCursor(partialSymbol, defaultValue);
while (cursor.move()) {
var key = cursor.getKey();
var value = cursor.getValue();
if (!refiner.merge(key, value)) {
throw new IllegalArgumentException("Failed to merge value %s for key %s into %s"
.formatted(value, key, partialSymbol));
}
}
}
}
|