diff options
author | Kristóf Marussy <marussy@mit.bme.hu> | 2023-09-14 19:29:36 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-14 19:29:36 +0200 |
commit | 98ed3b6db5f4e51961a161050cc31c66015116e8 (patch) | |
tree | 8bfd6d9bc8d6ed23b9eb0f889dd40b6c24fe8f92 /subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/psystem/basicdeferred/AggregatorConstraint.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/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/psystem/basicdeferred/AggregatorConstraint.java')
-rw-r--r-- | subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/psystem/basicdeferred/AggregatorConstraint.java | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/psystem/basicdeferred/AggregatorConstraint.java b/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/psystem/basicdeferred/AggregatorConstraint.java new file mode 100644 index 00000000..56f86e89 --- /dev/null +++ b/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/psystem/basicdeferred/AggregatorConstraint.java | |||
@@ -0,0 +1,98 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010-2016, Tamas Szabo, 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.HashMap; | ||
13 | import java.util.HashSet; | ||
14 | import java.util.Map; | ||
15 | import java.util.Set; | ||
16 | |||
17 | import tools.refinery.viatra.runtime.matchers.context.IInputKey; | ||
18 | import tools.refinery.viatra.runtime.matchers.context.IQueryMetaContext; | ||
19 | import tools.refinery.viatra.runtime.matchers.psystem.ITypeInfoProviderConstraint; | ||
20 | import tools.refinery.viatra.runtime.matchers.psystem.PBody; | ||
21 | import tools.refinery.viatra.runtime.matchers.psystem.PVariable; | ||
22 | import tools.refinery.viatra.runtime.matchers.psystem.TypeJudgement; | ||
23 | import tools.refinery.viatra.runtime.matchers.psystem.aggregations.BoundAggregator; | ||
24 | import tools.refinery.viatra.runtime.matchers.psystem.queries.PQuery; | ||
25 | import tools.refinery.viatra.runtime.matchers.tuple.Tuple; | ||
26 | import tools.refinery.viatra.runtime.matchers.tuple.Tuples; | ||
27 | |||
28 | /** | ||
29 | * The PSystem representation of an aggregation. | ||
30 | * | ||
31 | * @author Tamas Szabo | ||
32 | * @since 1.4 | ||
33 | */ | ||
34 | public class AggregatorConstraint extends PatternCallBasedDeferred implements ITypeInfoProviderConstraint { | ||
35 | |||
36 | protected PVariable resultVariable; | ||
37 | private BoundAggregator aggregator; | ||
38 | protected int aggregatedColumn; | ||
39 | |||
40 | public AggregatorConstraint(BoundAggregator aggregator, PBody pBody, Tuple actualParametersTuple, PQuery query, | ||
41 | PVariable resultVariable, int aggregatedColumn) { | ||
42 | super(pBody, actualParametersTuple, query, Collections.singleton(resultVariable)); | ||
43 | this.resultVariable = resultVariable; | ||
44 | this.aggregatedColumn = aggregatedColumn; | ||
45 | this.aggregator = aggregator; | ||
46 | } | ||
47 | |||
48 | public int getAggregatedColumn() { | ||
49 | return this.aggregatedColumn; | ||
50 | } | ||
51 | |||
52 | public BoundAggregator getAggregator() { | ||
53 | return this.aggregator; | ||
54 | } | ||
55 | |||
56 | @Override | ||
57 | public Set<PVariable> getDeducedVariables() { | ||
58 | return Collections.singleton(resultVariable); | ||
59 | } | ||
60 | |||
61 | @Override | ||
62 | public Map<Set<PVariable>, Set<PVariable>> getFunctionalDependencies(IQueryMetaContext context) { | ||
63 | final Map<Set<PVariable>, Set<PVariable>> result = new HashMap<Set<PVariable>, Set<PVariable>>(); | ||
64 | result.put(getDeferringVariables(), getDeducedVariables()); | ||
65 | return result; | ||
66 | } | ||
67 | |||
68 | @Override | ||
69 | protected void doDoReplaceVariables(PVariable obsolete, PVariable replacement) { | ||
70 | if (resultVariable.equals(obsolete)) | ||
71 | resultVariable = replacement; | ||
72 | } | ||
73 | |||
74 | @Override | ||
75 | protected Set<PVariable> getCandidateQuantifiedVariables() { | ||
76 | return actualParametersTuple.<PVariable> getDistinctElements(); | ||
77 | } | ||
78 | |||
79 | @Override | ||
80 | protected String toStringRest() { | ||
81 | return query.getFullyQualifiedName() + "@" + actualParametersTuple.toString() + "->" | ||
82 | + resultVariable.toString(); | ||
83 | } | ||
84 | |||
85 | public PVariable getResultVariable() { | ||
86 | return resultVariable; | ||
87 | } | ||
88 | |||
89 | @Override | ||
90 | public Set<TypeJudgement> getImpliedJudgements(IQueryMetaContext context) { | ||
91 | Set<TypeJudgement> result = new HashSet<TypeJudgement>(); | ||
92 | IInputKey aggregateResultType = aggregator.getAggregateResultTypeAsInputKey(); | ||
93 | if (aggregateResultType != null) { | ||
94 | result.add(new TypeJudgement(aggregateResultType, Tuples.staticArityFlatTupleOf(resultVariable))); | ||
95 | } | ||
96 | return result; | ||
97 | } | ||
98 | } | ||