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-rete/src/main/java/tools/refinery/viatra/runtime/rete/construction/plancompiler/RecursionCutoffPoint.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-rete/src/main/java/tools/refinery/viatra/runtime/rete/construction/plancompiler/RecursionCutoffPoint.java')
-rw-r--r-- | subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/construction/plancompiler/RecursionCutoffPoint.java | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/construction/plancompiler/RecursionCutoffPoint.java b/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/construction/plancompiler/RecursionCutoffPoint.java new file mode 100644 index 00000000..7d1e4d3a --- /dev/null +++ b/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/construction/plancompiler/RecursionCutoffPoint.java | |||
@@ -0,0 +1,86 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010-2014, 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.rete.construction.plancompiler; | ||
10 | |||
11 | import java.util.Collections; | ||
12 | import java.util.HashMap; | ||
13 | import java.util.List; | ||
14 | import java.util.Map; | ||
15 | import java.util.stream.Collectors; | ||
16 | |||
17 | import tools.refinery.viatra.runtime.matchers.backend.QueryEvaluationHint; | ||
18 | import tools.refinery.viatra.runtime.matchers.context.IQueryMetaContext; | ||
19 | import tools.refinery.viatra.runtime.matchers.psystem.PBody; | ||
20 | import tools.refinery.viatra.runtime.matchers.psystem.queries.PQuery; | ||
21 | import tools.refinery.viatra.runtime.rete.matcher.TimelyConfiguration; | ||
22 | import tools.refinery.viatra.runtime.rete.recipes.ProductionRecipe; | ||
23 | import tools.refinery.viatra.runtime.rete.recipes.ReteNodeRecipe; | ||
24 | import tools.refinery.viatra.runtime.rete.traceability.CompiledQuery; | ||
25 | import tools.refinery.viatra.runtime.rete.traceability.RecipeTraceInfo; | ||
26 | |||
27 | /** | ||
28 | * In a recursive query structure, query composition references can be cut off so that the remaining structure is DAG. | ||
29 | * {@link RecursionCutoffPoint} represents one such cut off query composition. | ||
30 | * When the compilation of the recursive query finishes and the compiled form becomes available, | ||
31 | * the {@link RecursionCutoffPoint} has to be signaled to update parent traces and recipes of the recursive call. | ||
32 | * | ||
33 | * @author Bergmann Gabor | ||
34 | * @noreference This class is not intended to be referenced by clients | ||
35 | * | ||
36 | */ | ||
37 | public class RecursionCutoffPoint { | ||
38 | final Map<PBody, RecipeTraceInfo> futureTraceMap; | ||
39 | final CompiledQuery compiledQuery; | ||
40 | final ProductionRecipe recipe; | ||
41 | final QueryEvaluationHint hint; | ||
42 | |||
43 | public RecursionCutoffPoint(PQuery query, QueryEvaluationHint hint, IQueryMetaContext context, boolean deleteAndRederiveEvaluation, TimelyConfiguration timelyEvaluation) { | ||
44 | super(); | ||
45 | this.hint = hint; | ||
46 | this.futureTraceMap = new HashMap<>(); // IMPORTANT: the identity of futureTraceMap.values() will not change | ||
47 | this.compiledQuery = CompilerHelper.makeQueryTrace(query, futureTraceMap, Collections.<ReteNodeRecipe>emptySet(), hint, context, deleteAndRederiveEvaluation, timelyEvaluation); | ||
48 | this.recipe = (ProductionRecipe)compiledQuery.getRecipe(); | ||
49 | if (!compiledQuery.getParentRecipeTraces().isEmpty()) { | ||
50 | throw new IllegalArgumentException(String.format("Recursion cut-off point of query %s has trace parents: %s", | ||
51 | compiledQuery.getQuery(), | ||
52 | prettyPrintParentRecipeTraces(compiledQuery.getParentRecipeTraces()))); | ||
53 | } | ||
54 | if (!recipe.getParents().isEmpty()) { | ||
55 | throw new IllegalArgumentException(String.format("Recursion cut-off point of query %s has recipe parents: %s", | ||
56 | compiledQuery.getQuery(), | ||
57 | prettyPrintParentRecipeTraces(compiledQuery.getParentRecipeTraces()))); | ||
58 | } | ||
59 | } | ||
60 | |||
61 | |||
62 | |||
63 | private String prettyPrintParentRecipeTraces(List<RecipeTraceInfo> trace) { | ||
64 | return trace.stream().map(Object::toString).collect(Collectors.joining(", ")); | ||
65 | } | ||
66 | |||
67 | /** | ||
68 | * Signals that compilation of the recursive query has terminated, culminating into the given compiled form. | ||
69 | * The query composition that has been cut off will be connected now. | ||
70 | */ | ||
71 | public void mend(CompiledQuery finalCompiledForm) { | ||
72 | futureTraceMap.putAll(finalCompiledForm.getParentRecipeTracesPerBody()); | ||
73 | recipe.getParents().addAll(((ProductionRecipe)finalCompiledForm.getRecipe()).getParents()); | ||
74 | } | ||
75 | |||
76 | public CompiledQuery getCompiledQuery() { | ||
77 | return compiledQuery; | ||
78 | } | ||
79 | |||
80 | public ProductionRecipe getRecipe() { | ||
81 | return recipe; | ||
82 | } | ||
83 | |||
84 | |||
85 | |||
86 | } | ||