diff options
author | 2023-09-14 19:29:36 +0200 | |
---|---|---|
committer | 2023-09-14 19:29:36 +0200 | |
commit | 98ed3b6db5f4e51961a161050cc31c66015116e8 (patch) | |
tree | 8bfd6d9bc8d6ed23b9eb0f889dd40b6c24fe8f92 /subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/translator/crossreference/UndirectedCrossReferenceTranslator.java | |
parent | Merge pull request #38 from nagilooh/design-space-exploration (diff) | |
parent | Merge remote-tracking branch 'upstream/main' into partial-interpretation (diff) | |
download | refinery-98ed3b6db5f4e51961a161050cc31c66015116e8.tar.gz refinery-98ed3b6db5f4e51961a161050cc31c66015116e8.tar.zst refinery-98ed3b6db5f4e51961a161050cc31c66015116e8.zip |
Merge pull request #39 from kris7t/partial-interpretation
Implement partial interpretation based model generation
Diffstat (limited to 'subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/translator/crossreference/UndirectedCrossReferenceTranslator.java')
-rw-r--r-- | subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/translator/crossreference/UndirectedCrossReferenceTranslator.java | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/translator/crossreference/UndirectedCrossReferenceTranslator.java b/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/translator/crossreference/UndirectedCrossReferenceTranslator.java new file mode 100644 index 00000000..c554e2a4 --- /dev/null +++ b/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/translator/crossreference/UndirectedCrossReferenceTranslator.java | |||
@@ -0,0 +1,83 @@ | |||
1 | /* | ||
2 | * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/> | ||
3 | * | ||
4 | * SPDX-License-Identifier: EPL-2.0 | ||
5 | */ | ||
6 | package tools.refinery.store.reasoning.translator.crossreference; | ||
7 | |||
8 | import tools.refinery.store.dse.transition.Rule; | ||
9 | import tools.refinery.store.model.ModelStoreBuilder; | ||
10 | import tools.refinery.store.model.ModelStoreConfiguration; | ||
11 | import tools.refinery.store.query.dnf.Query; | ||
12 | import tools.refinery.store.query.view.ForbiddenView; | ||
13 | import tools.refinery.store.reasoning.lifting.DnfLifter; | ||
14 | import tools.refinery.store.reasoning.literal.Concreteness; | ||
15 | import tools.refinery.store.reasoning.literal.Modality; | ||
16 | import tools.refinery.store.reasoning.refinement.RefinementBasedInitializer; | ||
17 | import tools.refinery.store.reasoning.representation.PartialRelation; | ||
18 | import tools.refinery.store.reasoning.translator.PartialRelationTranslator; | ||
19 | import tools.refinery.store.reasoning.translator.multiplicity.InvalidMultiplicityErrorTranslator; | ||
20 | import tools.refinery.store.representation.Symbol; | ||
21 | import tools.refinery.store.representation.TruthValue; | ||
22 | |||
23 | import static tools.refinery.store.query.literal.Literals.not; | ||
24 | import static tools.refinery.store.reasoning.actions.PartialActionLiterals.add; | ||
25 | import static tools.refinery.store.reasoning.literal.PartialLiterals.*; | ||
26 | import static tools.refinery.store.reasoning.translator.multiobject.MultiObjectTranslator.MULTI_VIEW; | ||
27 | |||
28 | public class UndirectedCrossReferenceTranslator implements ModelStoreConfiguration { | ||
29 | private final PartialRelation linkType; | ||
30 | private final UndirectedCrossReferenceInfo info; | ||
31 | private final Symbol<TruthValue> symbol; | ||
32 | |||
33 | public UndirectedCrossReferenceTranslator(PartialRelation linkType, UndirectedCrossReferenceInfo info) { | ||
34 | this.linkType = linkType; | ||
35 | this.info = info; | ||
36 | symbol = Symbol.of(linkType.name(), 2, TruthValue.class, TruthValue.UNKNOWN); | ||
37 | } | ||
38 | |||
39 | @Override | ||
40 | public void apply(ModelStoreBuilder storeBuilder) { | ||
41 | var name = linkType.name(); | ||
42 | var type = info.type(); | ||
43 | var forbiddenView = new ForbiddenView(symbol); | ||
44 | var mayName = DnfLifter.decorateName(name, Modality.MAY, Concreteness.PARTIAL); | ||
45 | |||
46 | var mayNewSource = CrossReferenceUtils.createMayHelper(linkType, type, info.multiplicity(), false); | ||
47 | |||
48 | storeBuilder.with(PartialRelationTranslator.of(linkType) | ||
49 | .symbol(symbol) | ||
50 | .may(Query.of(mayName, (builder, source, target) -> { | ||
51 | builder.clause( | ||
52 | mayNewSource.call(source), | ||
53 | mayNewSource.call(target), | ||
54 | not(forbiddenView.call(source, target)) | ||
55 | ); | ||
56 | if (info.isConstrained()) { | ||
57 | // Violation of monotonicity: | ||
58 | // Edges violating upper multiplicity will not be marked as {@code ERROR}, but the | ||
59 | // corresponding error pattern will already mark the node as invalid. | ||
60 | builder.clause( | ||
61 | must(linkType.call(source, target)), | ||
62 | not(forbiddenView.call(source, target)), | ||
63 | may(type.call(source)), | ||
64 | may(type.call(target)) | ||
65 | ); | ||
66 | } | ||
67 | })) | ||
68 | .refiner(UndirectedCrossReferenceRefiner.of(symbol, type)) | ||
69 | .initializer(new RefinementBasedInitializer<>(linkType)) | ||
70 | .decision(Rule.of(linkType.name(), (builder, source, target) -> builder | ||
71 | .clause( | ||
72 | may(linkType.call(source, target)), | ||
73 | not(candidateMust(linkType.call(source, target))), | ||
74 | not(MULTI_VIEW.call(source)), | ||
75 | not(MULTI_VIEW.call(target)) | ||
76 | ) | ||
77 | .action( | ||
78 | add(linkType, source, target) | ||
79 | )))); | ||
80 | |||
81 | storeBuilder.with(new InvalidMultiplicityErrorTranslator(type, linkType, false, info.multiplicity())); | ||
82 | } | ||
83 | } | ||