diff options
Diffstat (limited to 'subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/psystem/basicdeferred/TypeFilterConstraint.java')
-rw-r--r-- | subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/psystem/basicdeferred/TypeFilterConstraint.java | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/psystem/basicdeferred/TypeFilterConstraint.java b/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/psystem/basicdeferred/TypeFilterConstraint.java new file mode 100644 index 00000000..8b6e29ef --- /dev/null +++ b/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/psystem/basicdeferred/TypeFilterConstraint.java | |||
@@ -0,0 +1,105 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010-2015, Bergmann Gabor, Istvan Rath and Daniel Varro | ||
3 | * This program and the accompanying materials are made available under the | ||
4 | * terms of the Eclipse Public License v. 2.0 which is available at | ||
5 | * http://www.eclipse.org/legal/epl-v20.html. | ||
6 | * | ||
7 | * SPDX-License-Identifier: EPL-2.0 | ||
8 | *******************************************************************************/ | ||
9 | package tools.refinery.viatra.runtime.matchers.psystem.basicdeferred; | ||
10 | |||
11 | import java.util.Collections; | ||
12 | import java.util.Map; | ||
13 | import java.util.Set; | ||
14 | |||
15 | import tools.refinery.viatra.runtime.matchers.context.IInputKey; | ||
16 | import tools.refinery.viatra.runtime.matchers.context.IQueryMetaContext; | ||
17 | import tools.refinery.viatra.runtime.matchers.psystem.ITypeConstraint; | ||
18 | import tools.refinery.viatra.runtime.matchers.psystem.PBody; | ||
19 | import tools.refinery.viatra.runtime.matchers.psystem.PVariable; | ||
20 | import tools.refinery.viatra.runtime.matchers.psystem.TypeJudgement; | ||
21 | import tools.refinery.viatra.runtime.matchers.psystem.VariableDeferredPConstraint; | ||
22 | import tools.refinery.viatra.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
23 | import tools.refinery.viatra.runtime.matchers.tuple.Tuple; | ||
24 | |||
25 | /** | ||
26 | * Represents a non-enumerable type constraint that asserts that values substituted for the given tuple of variables | ||
27 | * form a tuple that belongs to a (typically non-enumerable) extensional relation identified by an {@link IInputKey}. | ||
28 | * | ||
29 | * <p> The InputKey is typically not enumerable. If it is enumerable, use {@link TypeConstraint} instead, so that the PConstraint carries over the property of enumerability. | ||
30 | * | ||
31 | * @author Bergmann Gabor | ||
32 | * | ||
33 | */ | ||
34 | public class TypeFilterConstraint extends VariableDeferredPConstraint implements | ||
35 | ITypeConstraint { | ||
36 | |||
37 | private Tuple variablesTuple; | ||
38 | private IInputKey inputKey; | ||
39 | |||
40 | private TypeJudgement equivalentJudgement; | ||
41 | |||
42 | |||
43 | public TypeFilterConstraint(PBody pBody, Tuple variablesTuple, IInputKey inputKey) { | ||
44 | super(pBody, variablesTuple.<PVariable> getDistinctElements()); | ||
45 | this.equivalentJudgement = new TypeJudgement(inputKey, variablesTuple); | ||
46 | |||
47 | this.variablesTuple = variablesTuple; | ||
48 | this.inputKey = inputKey; | ||
49 | |||
50 | if (variablesTuple.getSize() != inputKey.getArity()) | ||
51 | throw new IllegalArgumentException( | ||
52 | this.getClass().getSimpleName() + | ||
53 | " applied for variable tuple " + variablesTuple + " having wrong arity for input key " + | ||
54 | inputKey); | ||
55 | } | ||
56 | |||
57 | |||
58 | |||
59 | public Tuple getVariablesTuple() { | ||
60 | return variablesTuple; | ||
61 | } | ||
62 | |||
63 | public IInputKey getInputKey() { | ||
64 | return inputKey; | ||
65 | } | ||
66 | |||
67 | @Override | ||
68 | public TypeJudgement getEquivalentJudgement() { | ||
69 | return equivalentJudgement; | ||
70 | } | ||
71 | |||
72 | @Override | ||
73 | protected void doReplaceVariable(PVariable obsolete, PVariable replacement) { | ||
74 | variablesTuple = variablesTuple.replaceAll(obsolete, replacement); | ||
75 | this.equivalentJudgement = new TypeJudgement(inputKey, variablesTuple); | ||
76 | } | ||
77 | |||
78 | @Override | ||
79 | public Set<TypeJudgement> getImpliedJudgements(IQueryMetaContext context) { | ||
80 | return Collections.singleton(equivalentJudgement); | ||
81 | } | ||
82 | |||
83 | @Override | ||
84 | public Set<PVariable> getDeducedVariables() { | ||
85 | return Collections.emptySet(); | ||
86 | } | ||
87 | |||
88 | @Override | ||
89 | public Set<PVariable> getDeferringVariables() { | ||
90 | return getAffectedVariables(); | ||
91 | } | ||
92 | |||
93 | @Override | ||
94 | protected String toStringRest() { | ||
95 | return inputKey.getPrettyPrintableName() + "@" + variablesTuple; | ||
96 | } | ||
97 | |||
98 | @Override | ||
99 | public Map<Set<PVariable>, Set<PVariable>> getFunctionalDependencies(IQueryMetaContext context) { | ||
100 | return TypeConstraintUtil.getFunctionalDependencies(context, inputKey, variablesTuple); | ||
101 | } | ||
102 | |||
103 | |||
104 | |||
105 | } | ||