aboutsummaryrefslogtreecommitdiffstats
path: root/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu
diff options
context:
space:
mode:
Diffstat (limited to 'Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu')
-rw-r--r--Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/.gitignore44
-rw-r--r--Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/Allocate.java873
-rw-r--r--Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/AllocationWithoutResourceRequirement.java728
-rw-r--r--Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/AverageFreeHddMetric.java554
-rw-r--r--Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/AverageFreeMemoryMetric.java562
-rw-r--r--Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CostMetric.java554
-rw-r--r--Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsCost.java749
-rw-r--r--Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.java218
-rw-r--r--Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CreateHostInstance.java563
-rw-r--r--Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/GuidanceObjective.java601
-rw-r--r--Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/InstanceDoesNotSatisfyRequirement.java727
-rw-r--r--Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/NotEnoughAvailableHdd.java589
-rw-r--r--Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/NotEnoughAvailableMemory.java589
-rw-r--r--Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/RedundantInstancesOnSameHost.java597
-rw-r--r--Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/RemoveHostInstance.java589
-rw-r--r--Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/RequirementNotSatisfied.java607
-rw-r--r--Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/ResourceRequirement.java841
-rw-r--r--Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/UnallocateAppInstance.java551
-rw-r--r--Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/.gitignore36
-rw-r--r--Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/AvailableHdd.java178
-rw-r--r--Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/AvailableMemory.java178
-rw-r--r--Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/CpsApplications.java141
-rw-r--r--Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/CpsHosts.java141
-rw-r--r--Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/CpsQueriesAll.java132
-rw-r--r--Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/FreeHddPercentage.java172
-rw-r--r--Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/FreeMemoryPercentage.java172
-rw-r--r--Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/HddRequirement.java151
-rw-r--r--Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/HostInstanceCost.java153
-rw-r--r--Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/MemoryRequirement.java151
-rw-r--r--Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/NoHostToAllocateTo.java135
-rw-r--r--Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/RequiredAppInstances.java181
-rw-r--r--Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/SatisfyingInstance.java153
-rw-r--r--Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/TotalHdd.java143
-rw-r--r--Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/TotalMemory.java143
-rw-r--r--Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/UnallocatedAppInstance.java172
35 files changed, 13068 insertions, 0 deletions
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/.gitignore b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/.gitignore
new file mode 100644
index 00000000..d3114d9d
--- /dev/null
+++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/.gitignore
@@ -0,0 +1,44 @@
1/.CpsApplications.java._trace
2/.CpsQueries.java._trace
3/.CpsHosts.java._trace
4/.TotalMemory.java._trace
5/.TotalHdd.java._trace
6/.AvailableMemory.java._trace
7/.AvailableHdd.java._trace
8/.AllocationWithoutResourceRequirement.java._trace
9/.NotEnoughAvailableMemory.java._trace
10/.NotEnoughAvailableHdd.java._trace
11/.InstanceDoesNotSatisfyRequirement.java._trace
12/.RequirementNotSatisfied.java._trace
13/.AverageFreeMemoryMetric.java._trace
14/.AverageFreeHddMetric.java._trace
15/.CostMetric.java._trace
16/.CpsCost.java._trace
17/.RedundantInstancesOnSameHost.java._trace
18/.Allocate.java._trace
19/.CpsTransformationRules.java._trace
20/.ResourceRequirement.java._trace
21/.CreateInstance.java._trace
22/.CreateHostInstance.java._trace
23/.UnallocatedAppInstance.java._trace
24/.RequiredAppInstances.java._trace
25/.GuidanceObjective.java._trace
26/.RemoveHostInstance.java._trace
27/.UnallocateAppInstance.java._trace
28/Allocate.java
29/AllocationWithoutResourceRequirement.java
30/AverageFreeHddMetric.java
31/AverageFreeMemoryMetric.java
32/CostMetric.java
33/CpsCost.java
34/CpsQueries.java
35/CreateHostInstance.java
36/GuidanceObjective.java
37/InstanceDoesNotSatisfyRequirement.java
38/NotEnoughAvailableHdd.java
39/NotEnoughAvailableMemory.java
40/RedundantInstancesOnSameHost.java
41/RemoveHostInstance.java
42/RequirementNotSatisfied.java
43/ResourceRequirement.java
44/UnallocateAppInstance.java
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/Allocate.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/Allocate.java
new file mode 100644
index 00000000..1fc70124
--- /dev/null
+++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/Allocate.java
@@ -0,0 +1,873 @@
1/**
2 * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql
3 */
4package hu.bme.mit.inf.dslreasoner.domains.cps.queries;
5
6import hu.bme.mit.inf.dslreasoner.domains.cps.ApplicationInstance;
7import hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance;
8import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.AvailableHdd;
9import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.AvailableMemory;
10import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.UnallocatedAppInstance;
11import java.util.Arrays;
12import java.util.Collection;
13import java.util.Collections;
14import java.util.LinkedHashSet;
15import java.util.List;
16import java.util.Objects;
17import java.util.Optional;
18import java.util.Set;
19import java.util.function.Consumer;
20import java.util.stream.Collectors;
21import java.util.stream.Stream;
22import org.apache.log4j.Logger;
23import org.eclipse.emf.ecore.EClass;
24import org.eclipse.emf.ecore.EDataType;
25import org.eclipse.viatra.query.runtime.api.IPatternMatch;
26import org.eclipse.viatra.query.runtime.api.IQuerySpecification;
27import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine;
28import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
29import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification;
30import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher;
31import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch;
32import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey;
33import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey;
34import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey;
35import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
36import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator;
37import org.eclipse.viatra.query.runtime.matchers.psystem.IValueProvider;
38import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
39import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
40import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality;
41import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
42import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation;
43import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.NegativePatternCall;
44import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall;
45import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
46import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
47import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
48import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
49import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
50import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
51import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
52
53/**
54 * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
55 *
56 * <p>Original source:
57 * <code><pre>
58 * //
59 * // Transformation rule preconditions for rule-based DSE
60 * //
61 *
62 * pattern allocate(App : ApplicationInstance, Host : HostInstance) {
63 * ApplicationInstance.type.requirements(App, Req);
64 * ResourceRequirement.hostType.instances(Req, Host);
65 * find unallocatedAppInstance(App);
66 * find availableMemory(Host, AvailableMem);
67 * find availableHdd(Host, AvailableHdd);
68 * ResourceRequirement.requiredMemory(Req, RequiredMem);
69 * ResourceRequirement.requiredHdd(Req, RequiredHdd);
70 * check(AvailableMem {@literal >}= RequiredMem);
71 * check(AvailableHdd {@literal >}= RequiredHdd);
72 * neg ApplicationInstance.requirement.instances.allocatedTo(App, Host);
73 * }
74 * </pre></code>
75 *
76 * @see Matcher
77 * @see Match
78 *
79 */
80@SuppressWarnings("all")
81public final class Allocate extends BaseGeneratedEMFQuerySpecification<Allocate.Matcher> {
82 /**
83 * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.allocate pattern,
84 * to be used in conjunction with {@link Matcher}.
85 *
86 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
87 * Each instance is a (possibly partial) substitution of pattern parameters,
88 * usable to represent a match of the pattern in the result of a query,
89 * or to specify the bound (fixed) input parameters when issuing a query.
90 *
91 * @see Matcher
92 *
93 */
94 public static abstract class Match extends BasePatternMatch {
95 private ApplicationInstance fApp;
96
97 private HostInstance fHost;
98
99 private static List<String> parameterNames = makeImmutableList("App", "Host");
100
101 private Match(final ApplicationInstance pApp, final HostInstance pHost) {
102 this.fApp = pApp;
103 this.fHost = pHost;
104 }
105
106 @Override
107 public Object get(final String parameterName) {
108 switch(parameterName) {
109 case "App": return this.fApp;
110 case "Host": return this.fHost;
111 default: return null;
112 }
113 }
114
115 @Override
116 public Object get(final int index) {
117 switch(index) {
118 case 0: return this.fApp;
119 case 1: return this.fHost;
120 default: return null;
121 }
122 }
123
124 public ApplicationInstance getApp() {
125 return this.fApp;
126 }
127
128 public HostInstance getHost() {
129 return this.fHost;
130 }
131
132 @Override
133 public boolean set(final String parameterName, final Object newValue) {
134 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
135 if ("App".equals(parameterName) ) {
136 this.fApp = (ApplicationInstance) newValue;
137 return true;
138 }
139 if ("Host".equals(parameterName) ) {
140 this.fHost = (HostInstance) newValue;
141 return true;
142 }
143 return false;
144 }
145
146 public void setApp(final ApplicationInstance pApp) {
147 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
148 this.fApp = pApp;
149 }
150
151 public void setHost(final HostInstance pHost) {
152 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
153 this.fHost = pHost;
154 }
155
156 @Override
157 public String patternName() {
158 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.allocate";
159 }
160
161 @Override
162 public List<String> parameterNames() {
163 return Allocate.Match.parameterNames;
164 }
165
166 @Override
167 public Object[] toArray() {
168 return new Object[]{fApp, fHost};
169 }
170
171 @Override
172 public Allocate.Match toImmutable() {
173 return isMutable() ? newMatch(fApp, fHost) : this;
174 }
175
176 @Override
177 public String prettyPrint() {
178 StringBuilder result = new StringBuilder();
179 result.append("\"App\"=" + prettyPrintValue(fApp) + ", ");
180 result.append("\"Host\"=" + prettyPrintValue(fHost));
181 return result.toString();
182 }
183
184 @Override
185 public int hashCode() {
186 return Objects.hash(fApp, fHost);
187 }
188
189 @Override
190 public boolean equals(final Object obj) {
191 if (this == obj)
192 return true;
193 if (obj == null) {
194 return false;
195 }
196 if ((obj instanceof Allocate.Match)) {
197 Allocate.Match other = (Allocate.Match) obj;
198 return Objects.equals(fApp, other.fApp) && Objects.equals(fHost, other.fHost);
199 } else {
200 // this should be infrequent
201 if (!(obj instanceof IPatternMatch)) {
202 return false;
203 }
204 IPatternMatch otherSig = (IPatternMatch) obj;
205 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
206 }
207 }
208
209 @Override
210 public Allocate specification() {
211 return Allocate.instance();
212 }
213
214 /**
215 * Returns an empty, mutable match.
216 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
217 *
218 * @return the empty match.
219 *
220 */
221 public static Allocate.Match newEmptyMatch() {
222 return new Mutable(null, null);
223 }
224
225 /**
226 * Returns a mutable (partial) match.
227 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
228 *
229 * @param pApp the fixed value of pattern parameter App, or null if not bound.
230 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
231 * @return the new, mutable (partial) match object.
232 *
233 */
234 public static Allocate.Match newMutableMatch(final ApplicationInstance pApp, final HostInstance pHost) {
235 return new Mutable(pApp, pHost);
236 }
237
238 /**
239 * Returns a new (partial) match.
240 * This can be used e.g. to call the matcher with a partial match.
241 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
242 * @param pApp the fixed value of pattern parameter App, or null if not bound.
243 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
244 * @return the (partial) match object.
245 *
246 */
247 public static Allocate.Match newMatch(final ApplicationInstance pApp, final HostInstance pHost) {
248 return new Immutable(pApp, pHost);
249 }
250
251 private static final class Mutable extends Allocate.Match {
252 Mutable(final ApplicationInstance pApp, final HostInstance pHost) {
253 super(pApp, pHost);
254 }
255
256 @Override
257 public boolean isMutable() {
258 return true;
259 }
260 }
261
262 private static final class Immutable extends Allocate.Match {
263 Immutable(final ApplicationInstance pApp, final HostInstance pHost) {
264 super(pApp, pHost);
265 }
266
267 @Override
268 public boolean isMutable() {
269 return false;
270 }
271 }
272 }
273
274 /**
275 * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.allocate pattern,
276 * providing pattern-specific query methods.
277 *
278 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
279 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
280 *
281 * <p>Matches of the pattern will be represented as {@link Match}.
282 *
283 * <p>Original source:
284 * <code><pre>
285 * //
286 * // Transformation rule preconditions for rule-based DSE
287 * //
288 *
289 * pattern allocate(App : ApplicationInstance, Host : HostInstance) {
290 * ApplicationInstance.type.requirements(App, Req);
291 * ResourceRequirement.hostType.instances(Req, Host);
292 * find unallocatedAppInstance(App);
293 * find availableMemory(Host, AvailableMem);
294 * find availableHdd(Host, AvailableHdd);
295 * ResourceRequirement.requiredMemory(Req, RequiredMem);
296 * ResourceRequirement.requiredHdd(Req, RequiredHdd);
297 * check(AvailableMem {@literal >}= RequiredMem);
298 * check(AvailableHdd {@literal >}= RequiredHdd);
299 * neg ApplicationInstance.requirement.instances.allocatedTo(App, Host);
300 * }
301 * </pre></code>
302 *
303 * @see Match
304 * @see Allocate
305 *
306 */
307 public static class Matcher extends BaseMatcher<Allocate.Match> {
308 /**
309 * Initializes the pattern matcher within an existing VIATRA Query engine.
310 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
311 *
312 * @param engine the existing VIATRA Query engine in which this matcher will be created.
313 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
314 *
315 */
316 public static Allocate.Matcher on(final ViatraQueryEngine engine) {
317 // check if matcher already exists
318 Matcher matcher = engine.getExistingMatcher(querySpecification());
319 if (matcher == null) {
320 matcher = (Matcher)engine.getMatcher(querySpecification());
321 }
322 return matcher;
323 }
324
325 /**
326 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
327 * @return an initialized matcher
328 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
329 *
330 */
331 public static Allocate.Matcher create() {
332 return new Matcher();
333 }
334
335 private static final int POSITION_APP = 0;
336
337 private static final int POSITION_HOST = 1;
338
339 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Allocate.Matcher.class);
340
341 /**
342 * Initializes the pattern matcher within an existing VIATRA Query engine.
343 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
344 *
345 * @param engine the existing VIATRA Query engine in which this matcher will be created.
346 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
347 *
348 */
349 private Matcher() {
350 super(querySpecification());
351 }
352
353 /**
354 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
355 * @param pApp the fixed value of pattern parameter App, or null if not bound.
356 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
357 * @return matches represented as a Match object.
358 *
359 */
360 public Collection<Allocate.Match> getAllMatches(final ApplicationInstance pApp, final HostInstance pHost) {
361 return rawStreamAllMatches(new Object[]{pApp, pHost}).collect(Collectors.toSet());
362 }
363
364 /**
365 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
366 * </p>
367 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
368 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
369 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
370 * @param pApp the fixed value of pattern parameter App, or null if not bound.
371 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
372 * @return a stream of matches represented as a Match object.
373 *
374 */
375 public Stream<Allocate.Match> streamAllMatches(final ApplicationInstance pApp, final HostInstance pHost) {
376 return rawStreamAllMatches(new Object[]{pApp, pHost});
377 }
378
379 /**
380 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
381 * Neither determinism nor randomness of selection is guaranteed.
382 * @param pApp the fixed value of pattern parameter App, or null if not bound.
383 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
384 * @return a match represented as a Match object, or null if no match is found.
385 *
386 */
387 public Optional<Allocate.Match> getOneArbitraryMatch(final ApplicationInstance pApp, final HostInstance pHost) {
388 return rawGetOneArbitraryMatch(new Object[]{pApp, pHost});
389 }
390
391 /**
392 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
393 * under any possible substitution of the unspecified parameters (if any).
394 * @param pApp the fixed value of pattern parameter App, or null if not bound.
395 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
396 * @return true if the input is a valid (partial) match of the pattern.
397 *
398 */
399 public boolean hasMatch(final ApplicationInstance pApp, final HostInstance pHost) {
400 return rawHasMatch(new Object[]{pApp, pHost});
401 }
402
403 /**
404 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
405 * @param pApp the fixed value of pattern parameter App, or null if not bound.
406 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
407 * @return the number of pattern matches found.
408 *
409 */
410 public int countMatches(final ApplicationInstance pApp, final HostInstance pHost) {
411 return rawCountMatches(new Object[]{pApp, pHost});
412 }
413
414 /**
415 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
416 * Neither determinism nor randomness of selection is guaranteed.
417 * @param pApp the fixed value of pattern parameter App, or null if not bound.
418 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
419 * @param processor the action that will process the selected match.
420 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
421 *
422 */
423 public boolean forOneArbitraryMatch(final ApplicationInstance pApp, final HostInstance pHost, final Consumer<? super Allocate.Match> processor) {
424 return rawForOneArbitraryMatch(new Object[]{pApp, pHost}, processor);
425 }
426
427 /**
428 * Returns a new (partial) match.
429 * This can be used e.g. to call the matcher with a partial match.
430 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
431 * @param pApp the fixed value of pattern parameter App, or null if not bound.
432 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
433 * @return the (partial) match object.
434 *
435 */
436 public Allocate.Match newMatch(final ApplicationInstance pApp, final HostInstance pHost) {
437 return Allocate.Match.newMatch(pApp, pHost);
438 }
439
440 /**
441 * Retrieve the set of values that occur in matches for App.
442 * @return the Set of all values or empty set if there are no matches
443 *
444 */
445 protected Stream<ApplicationInstance> rawStreamAllValuesOfApp(final Object[] parameters) {
446 return rawStreamAllValues(POSITION_APP, parameters).map(ApplicationInstance.class::cast);
447 }
448
449 /**
450 * Retrieve the set of values that occur in matches for App.
451 * @return the Set of all values or empty set if there are no matches
452 *
453 */
454 public Set<ApplicationInstance> getAllValuesOfApp() {
455 return rawStreamAllValuesOfApp(emptyArray()).collect(Collectors.toSet());
456 }
457
458 /**
459 * Retrieve the set of values that occur in matches for App.
460 * @return the Set of all values or empty set if there are no matches
461 *
462 */
463 public Stream<ApplicationInstance> streamAllValuesOfApp() {
464 return rawStreamAllValuesOfApp(emptyArray());
465 }
466
467 /**
468 * Retrieve the set of values that occur in matches for App.
469 * </p>
470 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
471 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
472 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
473 *
474 * @return the Stream of all values or empty set if there are no matches
475 *
476 */
477 public Stream<ApplicationInstance> streamAllValuesOfApp(final Allocate.Match partialMatch) {
478 return rawStreamAllValuesOfApp(partialMatch.toArray());
479 }
480
481 /**
482 * Retrieve the set of values that occur in matches for App.
483 * </p>
484 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
485 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
486 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
487 *
488 * @return the Stream of all values or empty set if there are no matches
489 *
490 */
491 public Stream<ApplicationInstance> streamAllValuesOfApp(final HostInstance pHost) {
492 return rawStreamAllValuesOfApp(new Object[]{null, pHost});
493 }
494
495 /**
496 * Retrieve the set of values that occur in matches for App.
497 * @return the Set of all values or empty set if there are no matches
498 *
499 */
500 public Set<ApplicationInstance> getAllValuesOfApp(final Allocate.Match partialMatch) {
501 return rawStreamAllValuesOfApp(partialMatch.toArray()).collect(Collectors.toSet());
502 }
503
504 /**
505 * Retrieve the set of values that occur in matches for App.
506 * @return the Set of all values or empty set if there are no matches
507 *
508 */
509 public Set<ApplicationInstance> getAllValuesOfApp(final HostInstance pHost) {
510 return rawStreamAllValuesOfApp(new Object[]{null, pHost}).collect(Collectors.toSet());
511 }
512
513 /**
514 * Retrieve the set of values that occur in matches for Host.
515 * @return the Set of all values or empty set if there are no matches
516 *
517 */
518 protected Stream<HostInstance> rawStreamAllValuesOfHost(final Object[] parameters) {
519 return rawStreamAllValues(POSITION_HOST, parameters).map(HostInstance.class::cast);
520 }
521
522 /**
523 * Retrieve the set of values that occur in matches for Host.
524 * @return the Set of all values or empty set if there are no matches
525 *
526 */
527 public Set<HostInstance> getAllValuesOfHost() {
528 return rawStreamAllValuesOfHost(emptyArray()).collect(Collectors.toSet());
529 }
530
531 /**
532 * Retrieve the set of values that occur in matches for Host.
533 * @return the Set of all values or empty set if there are no matches
534 *
535 */
536 public Stream<HostInstance> streamAllValuesOfHost() {
537 return rawStreamAllValuesOfHost(emptyArray());
538 }
539
540 /**
541 * Retrieve the set of values that occur in matches for Host.
542 * </p>
543 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
544 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
545 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
546 *
547 * @return the Stream of all values or empty set if there are no matches
548 *
549 */
550 public Stream<HostInstance> streamAllValuesOfHost(final Allocate.Match partialMatch) {
551 return rawStreamAllValuesOfHost(partialMatch.toArray());
552 }
553
554 /**
555 * Retrieve the set of values that occur in matches for Host.
556 * </p>
557 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
558 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
559 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
560 *
561 * @return the Stream of all values or empty set if there are no matches
562 *
563 */
564 public Stream<HostInstance> streamAllValuesOfHost(final ApplicationInstance pApp) {
565 return rawStreamAllValuesOfHost(new Object[]{pApp, null});
566 }
567
568 /**
569 * Retrieve the set of values that occur in matches for Host.
570 * @return the Set of all values or empty set if there are no matches
571 *
572 */
573 public Set<HostInstance> getAllValuesOfHost(final Allocate.Match partialMatch) {
574 return rawStreamAllValuesOfHost(partialMatch.toArray()).collect(Collectors.toSet());
575 }
576
577 /**
578 * Retrieve the set of values that occur in matches for Host.
579 * @return the Set of all values or empty set if there are no matches
580 *
581 */
582 public Set<HostInstance> getAllValuesOfHost(final ApplicationInstance pApp) {
583 return rawStreamAllValuesOfHost(new Object[]{pApp, null}).collect(Collectors.toSet());
584 }
585
586 @Override
587 protected Allocate.Match tupleToMatch(final Tuple t) {
588 try {
589 return Allocate.Match.newMatch((ApplicationInstance) t.get(POSITION_APP), (HostInstance) t.get(POSITION_HOST));
590 } catch(ClassCastException e) {
591 LOGGER.error("Element(s) in tuple not properly typed!",e);
592 return null;
593 }
594 }
595
596 @Override
597 protected Allocate.Match arrayToMatch(final Object[] match) {
598 try {
599 return Allocate.Match.newMatch((ApplicationInstance) match[POSITION_APP], (HostInstance) match[POSITION_HOST]);
600 } catch(ClassCastException e) {
601 LOGGER.error("Element(s) in array not properly typed!",e);
602 return null;
603 }
604 }
605
606 @Override
607 protected Allocate.Match arrayToMatchMutable(final Object[] match) {
608 try {
609 return Allocate.Match.newMutableMatch((ApplicationInstance) match[POSITION_APP], (HostInstance) match[POSITION_HOST]);
610 } catch(ClassCastException e) {
611 LOGGER.error("Element(s) in array not properly typed!",e);
612 return null;
613 }
614 }
615
616 /**
617 * @return the singleton instance of the query specification of this pattern
618 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
619 *
620 */
621 public static IQuerySpecification<Allocate.Matcher> querySpecification() {
622 return Allocate.instance();
623 }
624 }
625
626 private Allocate() {
627 super(GeneratedPQuery.INSTANCE);
628 }
629
630 /**
631 * @return the singleton instance of the query specification
632 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
633 *
634 */
635 public static Allocate instance() {
636 try{
637 return LazyHolder.INSTANCE;
638 } catch (ExceptionInInitializerError err) {
639 throw processInitializerError(err);
640 }
641 }
642
643 @Override
644 protected Allocate.Matcher instantiate(final ViatraQueryEngine engine) {
645 return Allocate.Matcher.on(engine);
646 }
647
648 @Override
649 public Allocate.Matcher instantiate() {
650 return Allocate.Matcher.create();
651 }
652
653 @Override
654 public Allocate.Match newEmptyMatch() {
655 return Allocate.Match.newEmptyMatch();
656 }
657
658 @Override
659 public Allocate.Match newMatch(final Object... parameters) {
660 return Allocate.Match.newMatch((hu.bme.mit.inf.dslreasoner.domains.cps.ApplicationInstance) parameters[0], (hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance) parameters[1]);
661 }
662
663 /**
664 * Inner class allowing the singleton instance of {@link Allocate} to be created
665 * <b>not</b> at the class load time of the outer class,
666 * but rather at the first call to {@link Allocate#instance()}.
667 *
668 * <p> This workaround is required e.g. to support recursion.
669 *
670 */
671 private static class LazyHolder {
672 private static final Allocate INSTANCE = new Allocate();
673
674 /**
675 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
676 * This initialization order is required to support indirect recursion.
677 *
678 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
679 *
680 */
681 private static final Object STATIC_INITIALIZER = ensureInitialized();
682
683 public static Object ensureInitialized() {
684 INSTANCE.ensureInitializedInternal();
685 return null;
686 }
687 }
688
689 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
690 private static final Allocate.GeneratedPQuery INSTANCE = new GeneratedPQuery();
691
692 private final PParameter parameter_App = new PParameter("App", "hu.bme.mit.inf.dslreasoner.domains.cps.ApplicationInstance", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "ApplicationInstance")), PParameterDirection.INOUT);
693
694 private final PParameter parameter_Host = new PParameter("Host", "hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "HostInstance")), PParameterDirection.INOUT);
695
696 private final List<PParameter> parameters = Arrays.asList(parameter_App, parameter_Host);
697
698 private class Embedded_1_ApplicationInstance_requirement_instances_allocatedTo extends BaseGeneratedEMFPQuery {
699 private final PParameter parameter_p0 = new PParameter("p0", "hu.bme.mit.inf.dslreasoner.domains.cps.ApplicationInstance", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "ApplicationInstance")), PParameterDirection.INOUT);
700
701 private final PParameter parameter_p1 = new PParameter("p1", "hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "HostInstance")), PParameterDirection.INOUT);
702
703 private final List<PParameter> embeddedParameters = Arrays.asList(parameter_p0, parameter_p1);
704
705 public Embedded_1_ApplicationInstance_requirement_instances_allocatedTo() {
706 super(PVisibility.EMBEDDED);
707 }
708
709 @Override
710 public String getFullyQualifiedName() {
711 return GeneratedPQuery.this.getFullyQualifiedName() + "$Embedded_1_ApplicationInstance_requirement_instances_allocatedTo";
712 }
713
714 @Override
715 public List<PParameter> getParameters() {
716 return embeddedParameters;
717 }
718
719 @Override
720 public Set<PBody> doGetContainedBodies() {
721 PBody body = new PBody(this);
722 PVariable var_p0 = body.getOrCreateVariableByName("p0");
723 PVariable var_p1 = body.getOrCreateVariableByName("p1");
724 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
725 new ExportedParameter(body, var_p0, parameter_p0),
726 new ExportedParameter(body, var_p1, parameter_p1)
727 ));
728 // ApplicationInstance.requirement.instances.allocatedTo(App, Host)
729 new TypeConstraint(body, Tuples.flatTupleOf(var_p0), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance")));
730 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
731 new TypeConstraint(body, Tuples.flatTupleOf(var_p0, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ApplicationInstance", "requirement")));
732 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "Requirement")));
733 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
734 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "Requirement", "instances")));
735 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance")));
736 PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}");
737 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_, var__virtual_2_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ApplicationInstance", "allocatedTo")));
738 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance")));
739 new Equality(body, var__virtual_2_, var_p1);
740 return Collections.singleton(body);
741 }
742 }
743
744 private GeneratedPQuery() {
745 super(PVisibility.PUBLIC);
746 }
747
748 @Override
749 public String getFullyQualifiedName() {
750 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.allocate";
751 }
752
753 @Override
754 public List<String> getParameterNames() {
755 return Arrays.asList("App","Host");
756 }
757
758 @Override
759 public List<PParameter> getParameters() {
760 return parameters;
761 }
762
763 @Override
764 public Set<PBody> doGetContainedBodies() {
765 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
766 Set<PBody> bodies = new LinkedHashSet<>();
767 {
768 PBody body = new PBody(this);
769 PVariable var_App = body.getOrCreateVariableByName("App");
770 PVariable var_Host = body.getOrCreateVariableByName("Host");
771 PVariable var_Req = body.getOrCreateVariableByName("Req");
772 PVariable var_AvailableMem = body.getOrCreateVariableByName("AvailableMem");
773 PVariable var_AvailableHdd = body.getOrCreateVariableByName("AvailableHdd");
774 PVariable var_RequiredMem = body.getOrCreateVariableByName("RequiredMem");
775 PVariable var_RequiredHdd = body.getOrCreateVariableByName("RequiredHdd");
776 new TypeConstraint(body, Tuples.flatTupleOf(var_App), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance")));
777 new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance")));
778 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
779 new ExportedParameter(body, var_App, parameter_App),
780 new ExportedParameter(body, var_Host, parameter_Host)
781 ));
782 // ApplicationInstance.type.requirements(App, Req)
783 new TypeConstraint(body, Tuples.flatTupleOf(var_App), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance")));
784 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
785 new TypeConstraint(body, Tuples.flatTupleOf(var_App, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ApplicationInstance", "type")));
786 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationType")));
787 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
788 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ApplicationType", "requirements")));
789 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ResourceRequirement")));
790 new Equality(body, var__virtual_1_, var_Req);
791 // ResourceRequirement.hostType.instances(Req, Host)
792 new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ResourceRequirement")));
793 PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}");
794 new TypeConstraint(body, Tuples.flatTupleOf(var_Req, var__virtual_2_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ResourceRequirement", "hostType")));
795 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostType")));
796 PVariable var__virtual_3_ = body.getOrCreateVariableByName(".virtual{3}");
797 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_, var__virtual_3_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "HostType", "instances")));
798 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_3_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance")));
799 new Equality(body, var__virtual_3_, var_Host);
800 // find unallocatedAppInstance(App)
801 new PositivePatternCall(body, Tuples.flatTupleOf(var_App), UnallocatedAppInstance.instance().getInternalQueryRepresentation());
802 // find availableMemory(Host, AvailableMem)
803 new PositivePatternCall(body, Tuples.flatTupleOf(var_Host, var_AvailableMem), AvailableMemory.instance().getInternalQueryRepresentation());
804 // find availableHdd(Host, AvailableHdd)
805 new PositivePatternCall(body, Tuples.flatTupleOf(var_Host, var_AvailableHdd), AvailableHdd.instance().getInternalQueryRepresentation());
806 // ResourceRequirement.requiredMemory(Req, RequiredMem)
807 new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ResourceRequirement")));
808 PVariable var__virtual_4_ = body.getOrCreateVariableByName(".virtual{4}");
809 new TypeConstraint(body, Tuples.flatTupleOf(var_Req, var__virtual_4_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ResourceRequirement", "requiredMemory")));
810 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_4_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt")));
811 new Equality(body, var__virtual_4_, var_RequiredMem);
812 // ResourceRequirement.requiredHdd(Req, RequiredHdd)
813 new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ResourceRequirement")));
814 PVariable var__virtual_5_ = body.getOrCreateVariableByName(".virtual{5}");
815 new TypeConstraint(body, Tuples.flatTupleOf(var_Req, var__virtual_5_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ResourceRequirement", "requiredHdd")));
816 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_5_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt")));
817 new Equality(body, var__virtual_5_, var_RequiredHdd);
818 // check(AvailableMem >= RequiredMem)
819 new ExpressionEvaluation(body, new IExpressionEvaluator() {
820
821 @Override
822 public String getShortDescription() {
823 return "Expression evaluation from pattern allocate";
824 }
825
826 @Override
827 public Iterable<String> getInputParameterNames() {
828 return Arrays.asList("AvailableMem", "RequiredMem");}
829
830 @Override
831 public Object evaluateExpression(IValueProvider provider) throws Exception {
832 Integer AvailableMem = (Integer) provider.getValue("AvailableMem");
833 Integer RequiredMem = (Integer) provider.getValue("RequiredMem");
834 return evaluateExpression_1_1(AvailableMem, RequiredMem);
835 }
836 }, null);
837 // check(AvailableHdd >= RequiredHdd)
838 new ExpressionEvaluation(body, new IExpressionEvaluator() {
839
840 @Override
841 public String getShortDescription() {
842 return "Expression evaluation from pattern allocate";
843 }
844
845 @Override
846 public Iterable<String> getInputParameterNames() {
847 return Arrays.asList("AvailableHdd", "RequiredHdd");}
848
849 @Override
850 public Object evaluateExpression(IValueProvider provider) throws Exception {
851 Integer AvailableHdd = (Integer) provider.getValue("AvailableHdd");
852 Integer RequiredHdd = (Integer) provider.getValue("RequiredHdd");
853 return evaluateExpression_1_2(AvailableHdd, RequiredHdd);
854 }
855 }, null);
856 // neg ApplicationInstance.requirement.instances.allocatedTo(App, Host)
857 new NegativePatternCall(body, Tuples.flatTupleOf(var_App, var_Host), new Allocate.GeneratedPQuery.Embedded_1_ApplicationInstance_requirement_instances_allocatedTo());
858 bodies.add(body);
859 }
860 return bodies;
861 }
862 }
863
864 private static boolean evaluateExpression_1_1(final Integer AvailableMem, final Integer RequiredMem) {
865 boolean _greaterEqualsThan = (AvailableMem.compareTo(RequiredMem) >= 0);
866 return _greaterEqualsThan;
867 }
868
869 private static boolean evaluateExpression_1_2(final Integer AvailableHdd, final Integer RequiredHdd) {
870 boolean _greaterEqualsThan = (AvailableHdd.compareTo(RequiredHdd) >= 0);
871 return _greaterEqualsThan;
872 }
873}
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/AllocationWithoutResourceRequirement.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/AllocationWithoutResourceRequirement.java
new file mode 100644
index 00000000..b49fee74
--- /dev/null
+++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/AllocationWithoutResourceRequirement.java
@@ -0,0 +1,728 @@
1/**
2 * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql
3 */
4package hu.bme.mit.inf.dslreasoner.domains.cps.queries;
5
6import hu.bme.mit.inf.dslreasoner.domains.cps.ApplicationInstance;
7import hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance;
8import hu.bme.mit.inf.dslreasoner.domains.cps.queries.ResourceRequirement;
9import java.util.Arrays;
10import java.util.Collection;
11import java.util.LinkedHashSet;
12import java.util.List;
13import java.util.Objects;
14import java.util.Optional;
15import java.util.Set;
16import java.util.function.Consumer;
17import java.util.stream.Collectors;
18import java.util.stream.Stream;
19import org.apache.log4j.Logger;
20import org.eclipse.emf.ecore.EClass;
21import org.eclipse.viatra.query.runtime.api.IPatternMatch;
22import org.eclipse.viatra.query.runtime.api.IQuerySpecification;
23import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine;
24import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
25import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification;
26import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher;
27import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch;
28import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey;
29import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey;
30import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
31import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
32import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
33import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation;
34import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference;
35import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality;
36import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
37import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.NegativePatternCall;
38import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
39import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
40import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
41import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
42import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
43import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
44import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
45
46/**
47 * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
48 *
49 * <p>Original source:
50 * <code><pre>
51 * {@literal @}Constraint(severity = "error", key = {Host, App},
52 * message = "Application instance must be allocated to a supported host type.")
53 * pattern allocationWithoutResourceRequirement(Host : HostInstance, App : ApplicationInstance) {
54 * ApplicationInstance.allocatedTo(App, Host);
55 * neg find resourceRequirement(Host, App, _);
56 * }
57 * </pre></code>
58 *
59 * @see Matcher
60 * @see Match
61 *
62 */
63@SuppressWarnings("all")
64public final class AllocationWithoutResourceRequirement extends BaseGeneratedEMFQuerySpecification<AllocationWithoutResourceRequirement.Matcher> {
65 /**
66 * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.allocationWithoutResourceRequirement pattern,
67 * to be used in conjunction with {@link Matcher}.
68 *
69 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
70 * Each instance is a (possibly partial) substitution of pattern parameters,
71 * usable to represent a match of the pattern in the result of a query,
72 * or to specify the bound (fixed) input parameters when issuing a query.
73 *
74 * @see Matcher
75 *
76 */
77 public static abstract class Match extends BasePatternMatch {
78 private HostInstance fHost;
79
80 private ApplicationInstance fApp;
81
82 private static List<String> parameterNames = makeImmutableList("Host", "App");
83
84 private Match(final HostInstance pHost, final ApplicationInstance pApp) {
85 this.fHost = pHost;
86 this.fApp = pApp;
87 }
88
89 @Override
90 public Object get(final String parameterName) {
91 switch(parameterName) {
92 case "Host": return this.fHost;
93 case "App": return this.fApp;
94 default: return null;
95 }
96 }
97
98 @Override
99 public Object get(final int index) {
100 switch(index) {
101 case 0: return this.fHost;
102 case 1: return this.fApp;
103 default: return null;
104 }
105 }
106
107 public HostInstance getHost() {
108 return this.fHost;
109 }
110
111 public ApplicationInstance getApp() {
112 return this.fApp;
113 }
114
115 @Override
116 public boolean set(final String parameterName, final Object newValue) {
117 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
118 if ("Host".equals(parameterName) ) {
119 this.fHost = (HostInstance) newValue;
120 return true;
121 }
122 if ("App".equals(parameterName) ) {
123 this.fApp = (ApplicationInstance) newValue;
124 return true;
125 }
126 return false;
127 }
128
129 public void setHost(final HostInstance pHost) {
130 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
131 this.fHost = pHost;
132 }
133
134 public void setApp(final ApplicationInstance pApp) {
135 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
136 this.fApp = pApp;
137 }
138
139 @Override
140 public String patternName() {
141 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.allocationWithoutResourceRequirement";
142 }
143
144 @Override
145 public List<String> parameterNames() {
146 return AllocationWithoutResourceRequirement.Match.parameterNames;
147 }
148
149 @Override
150 public Object[] toArray() {
151 return new Object[]{fHost, fApp};
152 }
153
154 @Override
155 public AllocationWithoutResourceRequirement.Match toImmutable() {
156 return isMutable() ? newMatch(fHost, fApp) : this;
157 }
158
159 @Override
160 public String prettyPrint() {
161 StringBuilder result = new StringBuilder();
162 result.append("\"Host\"=" + prettyPrintValue(fHost) + ", ");
163 result.append("\"App\"=" + prettyPrintValue(fApp));
164 return result.toString();
165 }
166
167 @Override
168 public int hashCode() {
169 return Objects.hash(fHost, fApp);
170 }
171
172 @Override
173 public boolean equals(final Object obj) {
174 if (this == obj)
175 return true;
176 if (obj == null) {
177 return false;
178 }
179 if ((obj instanceof AllocationWithoutResourceRequirement.Match)) {
180 AllocationWithoutResourceRequirement.Match other = (AllocationWithoutResourceRequirement.Match) obj;
181 return Objects.equals(fHost, other.fHost) && Objects.equals(fApp, other.fApp);
182 } else {
183 // this should be infrequent
184 if (!(obj instanceof IPatternMatch)) {
185 return false;
186 }
187 IPatternMatch otherSig = (IPatternMatch) obj;
188 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
189 }
190 }
191
192 @Override
193 public AllocationWithoutResourceRequirement specification() {
194 return AllocationWithoutResourceRequirement.instance();
195 }
196
197 /**
198 * Returns an empty, mutable match.
199 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
200 *
201 * @return the empty match.
202 *
203 */
204 public static AllocationWithoutResourceRequirement.Match newEmptyMatch() {
205 return new Mutable(null, null);
206 }
207
208 /**
209 * Returns a mutable (partial) match.
210 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
211 *
212 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
213 * @param pApp the fixed value of pattern parameter App, or null if not bound.
214 * @return the new, mutable (partial) match object.
215 *
216 */
217 public static AllocationWithoutResourceRequirement.Match newMutableMatch(final HostInstance pHost, final ApplicationInstance pApp) {
218 return new Mutable(pHost, pApp);
219 }
220
221 /**
222 * Returns a new (partial) match.
223 * This can be used e.g. to call the matcher with a partial match.
224 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
225 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
226 * @param pApp the fixed value of pattern parameter App, or null if not bound.
227 * @return the (partial) match object.
228 *
229 */
230 public static AllocationWithoutResourceRequirement.Match newMatch(final HostInstance pHost, final ApplicationInstance pApp) {
231 return new Immutable(pHost, pApp);
232 }
233
234 private static final class Mutable extends AllocationWithoutResourceRequirement.Match {
235 Mutable(final HostInstance pHost, final ApplicationInstance pApp) {
236 super(pHost, pApp);
237 }
238
239 @Override
240 public boolean isMutable() {
241 return true;
242 }
243 }
244
245 private static final class Immutable extends AllocationWithoutResourceRequirement.Match {
246 Immutable(final HostInstance pHost, final ApplicationInstance pApp) {
247 super(pHost, pApp);
248 }
249
250 @Override
251 public boolean isMutable() {
252 return false;
253 }
254 }
255 }
256
257 /**
258 * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.allocationWithoutResourceRequirement pattern,
259 * providing pattern-specific query methods.
260 *
261 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
262 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
263 *
264 * <p>Matches of the pattern will be represented as {@link Match}.
265 *
266 * <p>Original source:
267 * <code><pre>
268 * {@literal @}Constraint(severity = "error", key = {Host, App},
269 * message = "Application instance must be allocated to a supported host type.")
270 * pattern allocationWithoutResourceRequirement(Host : HostInstance, App : ApplicationInstance) {
271 * ApplicationInstance.allocatedTo(App, Host);
272 * neg find resourceRequirement(Host, App, _);
273 * }
274 * </pre></code>
275 *
276 * @see Match
277 * @see AllocationWithoutResourceRequirement
278 *
279 */
280 public static class Matcher extends BaseMatcher<AllocationWithoutResourceRequirement.Match> {
281 /**
282 * Initializes the pattern matcher within an existing VIATRA Query engine.
283 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
284 *
285 * @param engine the existing VIATRA Query engine in which this matcher will be created.
286 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
287 *
288 */
289 public static AllocationWithoutResourceRequirement.Matcher on(final ViatraQueryEngine engine) {
290 // check if matcher already exists
291 Matcher matcher = engine.getExistingMatcher(querySpecification());
292 if (matcher == null) {
293 matcher = (Matcher)engine.getMatcher(querySpecification());
294 }
295 return matcher;
296 }
297
298 /**
299 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
300 * @return an initialized matcher
301 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
302 *
303 */
304 public static AllocationWithoutResourceRequirement.Matcher create() {
305 return new Matcher();
306 }
307
308 private static final int POSITION_HOST = 0;
309
310 private static final int POSITION_APP = 1;
311
312 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(AllocationWithoutResourceRequirement.Matcher.class);
313
314 /**
315 * Initializes the pattern matcher within an existing VIATRA Query engine.
316 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
317 *
318 * @param engine the existing VIATRA Query engine in which this matcher will be created.
319 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
320 *
321 */
322 private Matcher() {
323 super(querySpecification());
324 }
325
326 /**
327 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
328 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
329 * @param pApp the fixed value of pattern parameter App, or null if not bound.
330 * @return matches represented as a Match object.
331 *
332 */
333 public Collection<AllocationWithoutResourceRequirement.Match> getAllMatches(final HostInstance pHost, final ApplicationInstance pApp) {
334 return rawStreamAllMatches(new Object[]{pHost, pApp}).collect(Collectors.toSet());
335 }
336
337 /**
338 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
339 * </p>
340 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
341 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
342 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
343 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
344 * @param pApp the fixed value of pattern parameter App, or null if not bound.
345 * @return a stream of matches represented as a Match object.
346 *
347 */
348 public Stream<AllocationWithoutResourceRequirement.Match> streamAllMatches(final HostInstance pHost, final ApplicationInstance pApp) {
349 return rawStreamAllMatches(new Object[]{pHost, pApp});
350 }
351
352 /**
353 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
354 * Neither determinism nor randomness of selection is guaranteed.
355 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
356 * @param pApp the fixed value of pattern parameter App, or null if not bound.
357 * @return a match represented as a Match object, or null if no match is found.
358 *
359 */
360 public Optional<AllocationWithoutResourceRequirement.Match> getOneArbitraryMatch(final HostInstance pHost, final ApplicationInstance pApp) {
361 return rawGetOneArbitraryMatch(new Object[]{pHost, pApp});
362 }
363
364 /**
365 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
366 * under any possible substitution of the unspecified parameters (if any).
367 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
368 * @param pApp the fixed value of pattern parameter App, or null if not bound.
369 * @return true if the input is a valid (partial) match of the pattern.
370 *
371 */
372 public boolean hasMatch(final HostInstance pHost, final ApplicationInstance pApp) {
373 return rawHasMatch(new Object[]{pHost, pApp});
374 }
375
376 /**
377 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
378 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
379 * @param pApp the fixed value of pattern parameter App, or null if not bound.
380 * @return the number of pattern matches found.
381 *
382 */
383 public int countMatches(final HostInstance pHost, final ApplicationInstance pApp) {
384 return rawCountMatches(new Object[]{pHost, pApp});
385 }
386
387 /**
388 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
389 * Neither determinism nor randomness of selection is guaranteed.
390 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
391 * @param pApp the fixed value of pattern parameter App, or null if not bound.
392 * @param processor the action that will process the selected match.
393 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
394 *
395 */
396 public boolean forOneArbitraryMatch(final HostInstance pHost, final ApplicationInstance pApp, final Consumer<? super AllocationWithoutResourceRequirement.Match> processor) {
397 return rawForOneArbitraryMatch(new Object[]{pHost, pApp}, processor);
398 }
399
400 /**
401 * Returns a new (partial) match.
402 * This can be used e.g. to call the matcher with a partial match.
403 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
404 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
405 * @param pApp the fixed value of pattern parameter App, or null if not bound.
406 * @return the (partial) match object.
407 *
408 */
409 public AllocationWithoutResourceRequirement.Match newMatch(final HostInstance pHost, final ApplicationInstance pApp) {
410 return AllocationWithoutResourceRequirement.Match.newMatch(pHost, pApp);
411 }
412
413 /**
414 * Retrieve the set of values that occur in matches for Host.
415 * @return the Set of all values or empty set if there are no matches
416 *
417 */
418 protected Stream<HostInstance> rawStreamAllValuesOfHost(final Object[] parameters) {
419 return rawStreamAllValues(POSITION_HOST, parameters).map(HostInstance.class::cast);
420 }
421
422 /**
423 * Retrieve the set of values that occur in matches for Host.
424 * @return the Set of all values or empty set if there are no matches
425 *
426 */
427 public Set<HostInstance> getAllValuesOfHost() {
428 return rawStreamAllValuesOfHost(emptyArray()).collect(Collectors.toSet());
429 }
430
431 /**
432 * Retrieve the set of values that occur in matches for Host.
433 * @return the Set of all values or empty set if there are no matches
434 *
435 */
436 public Stream<HostInstance> streamAllValuesOfHost() {
437 return rawStreamAllValuesOfHost(emptyArray());
438 }
439
440 /**
441 * Retrieve the set of values that occur in matches for Host.
442 * </p>
443 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
444 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
445 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
446 *
447 * @return the Stream of all values or empty set if there are no matches
448 *
449 */
450 public Stream<HostInstance> streamAllValuesOfHost(final AllocationWithoutResourceRequirement.Match partialMatch) {
451 return rawStreamAllValuesOfHost(partialMatch.toArray());
452 }
453
454 /**
455 * Retrieve the set of values that occur in matches for Host.
456 * </p>
457 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
458 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
459 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
460 *
461 * @return the Stream of all values or empty set if there are no matches
462 *
463 */
464 public Stream<HostInstance> streamAllValuesOfHost(final ApplicationInstance pApp) {
465 return rawStreamAllValuesOfHost(new Object[]{null, pApp});
466 }
467
468 /**
469 * Retrieve the set of values that occur in matches for Host.
470 * @return the Set of all values or empty set if there are no matches
471 *
472 */
473 public Set<HostInstance> getAllValuesOfHost(final AllocationWithoutResourceRequirement.Match partialMatch) {
474 return rawStreamAllValuesOfHost(partialMatch.toArray()).collect(Collectors.toSet());
475 }
476
477 /**
478 * Retrieve the set of values that occur in matches for Host.
479 * @return the Set of all values or empty set if there are no matches
480 *
481 */
482 public Set<HostInstance> getAllValuesOfHost(final ApplicationInstance pApp) {
483 return rawStreamAllValuesOfHost(new Object[]{null, pApp}).collect(Collectors.toSet());
484 }
485
486 /**
487 * Retrieve the set of values that occur in matches for App.
488 * @return the Set of all values or empty set if there are no matches
489 *
490 */
491 protected Stream<ApplicationInstance> rawStreamAllValuesOfApp(final Object[] parameters) {
492 return rawStreamAllValues(POSITION_APP, parameters).map(ApplicationInstance.class::cast);
493 }
494
495 /**
496 * Retrieve the set of values that occur in matches for App.
497 * @return the Set of all values or empty set if there are no matches
498 *
499 */
500 public Set<ApplicationInstance> getAllValuesOfApp() {
501 return rawStreamAllValuesOfApp(emptyArray()).collect(Collectors.toSet());
502 }
503
504 /**
505 * Retrieve the set of values that occur in matches for App.
506 * @return the Set of all values or empty set if there are no matches
507 *
508 */
509 public Stream<ApplicationInstance> streamAllValuesOfApp() {
510 return rawStreamAllValuesOfApp(emptyArray());
511 }
512
513 /**
514 * Retrieve the set of values that occur in matches for App.
515 * </p>
516 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
517 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
518 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
519 *
520 * @return the Stream of all values or empty set if there are no matches
521 *
522 */
523 public Stream<ApplicationInstance> streamAllValuesOfApp(final AllocationWithoutResourceRequirement.Match partialMatch) {
524 return rawStreamAllValuesOfApp(partialMatch.toArray());
525 }
526
527 /**
528 * Retrieve the set of values that occur in matches for App.
529 * </p>
530 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
531 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
532 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
533 *
534 * @return the Stream of all values or empty set if there are no matches
535 *
536 */
537 public Stream<ApplicationInstance> streamAllValuesOfApp(final HostInstance pHost) {
538 return rawStreamAllValuesOfApp(new Object[]{pHost, null});
539 }
540
541 /**
542 * Retrieve the set of values that occur in matches for App.
543 * @return the Set of all values or empty set if there are no matches
544 *
545 */
546 public Set<ApplicationInstance> getAllValuesOfApp(final AllocationWithoutResourceRequirement.Match partialMatch) {
547 return rawStreamAllValuesOfApp(partialMatch.toArray()).collect(Collectors.toSet());
548 }
549
550 /**
551 * Retrieve the set of values that occur in matches for App.
552 * @return the Set of all values or empty set if there are no matches
553 *
554 */
555 public Set<ApplicationInstance> getAllValuesOfApp(final HostInstance pHost) {
556 return rawStreamAllValuesOfApp(new Object[]{pHost, null}).collect(Collectors.toSet());
557 }
558
559 @Override
560 protected AllocationWithoutResourceRequirement.Match tupleToMatch(final Tuple t) {
561 try {
562 return AllocationWithoutResourceRequirement.Match.newMatch((HostInstance) t.get(POSITION_HOST), (ApplicationInstance) t.get(POSITION_APP));
563 } catch(ClassCastException e) {
564 LOGGER.error("Element(s) in tuple not properly typed!",e);
565 return null;
566 }
567 }
568
569 @Override
570 protected AllocationWithoutResourceRequirement.Match arrayToMatch(final Object[] match) {
571 try {
572 return AllocationWithoutResourceRequirement.Match.newMatch((HostInstance) match[POSITION_HOST], (ApplicationInstance) match[POSITION_APP]);
573 } catch(ClassCastException e) {
574 LOGGER.error("Element(s) in array not properly typed!",e);
575 return null;
576 }
577 }
578
579 @Override
580 protected AllocationWithoutResourceRequirement.Match arrayToMatchMutable(final Object[] match) {
581 try {
582 return AllocationWithoutResourceRequirement.Match.newMutableMatch((HostInstance) match[POSITION_HOST], (ApplicationInstance) match[POSITION_APP]);
583 } catch(ClassCastException e) {
584 LOGGER.error("Element(s) in array not properly typed!",e);
585 return null;
586 }
587 }
588
589 /**
590 * @return the singleton instance of the query specification of this pattern
591 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
592 *
593 */
594 public static IQuerySpecification<AllocationWithoutResourceRequirement.Matcher> querySpecification() {
595 return AllocationWithoutResourceRequirement.instance();
596 }
597 }
598
599 private AllocationWithoutResourceRequirement() {
600 super(GeneratedPQuery.INSTANCE);
601 }
602
603 /**
604 * @return the singleton instance of the query specification
605 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
606 *
607 */
608 public static AllocationWithoutResourceRequirement instance() {
609 try{
610 return LazyHolder.INSTANCE;
611 } catch (ExceptionInInitializerError err) {
612 throw processInitializerError(err);
613 }
614 }
615
616 @Override
617 protected AllocationWithoutResourceRequirement.Matcher instantiate(final ViatraQueryEngine engine) {
618 return AllocationWithoutResourceRequirement.Matcher.on(engine);
619 }
620
621 @Override
622 public AllocationWithoutResourceRequirement.Matcher instantiate() {
623 return AllocationWithoutResourceRequirement.Matcher.create();
624 }
625
626 @Override
627 public AllocationWithoutResourceRequirement.Match newEmptyMatch() {
628 return AllocationWithoutResourceRequirement.Match.newEmptyMatch();
629 }
630
631 @Override
632 public AllocationWithoutResourceRequirement.Match newMatch(final Object... parameters) {
633 return AllocationWithoutResourceRequirement.Match.newMatch((hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance) parameters[0], (hu.bme.mit.inf.dslreasoner.domains.cps.ApplicationInstance) parameters[1]);
634 }
635
636 /**
637 * Inner class allowing the singleton instance of {@link AllocationWithoutResourceRequirement} to be created
638 * <b>not</b> at the class load time of the outer class,
639 * but rather at the first call to {@link AllocationWithoutResourceRequirement#instance()}.
640 *
641 * <p> This workaround is required e.g. to support recursion.
642 *
643 */
644 private static class LazyHolder {
645 private static final AllocationWithoutResourceRequirement INSTANCE = new AllocationWithoutResourceRequirement();
646
647 /**
648 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
649 * This initialization order is required to support indirect recursion.
650 *
651 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
652 *
653 */
654 private static final Object STATIC_INITIALIZER = ensureInitialized();
655
656 public static Object ensureInitialized() {
657 INSTANCE.ensureInitializedInternal();
658 return null;
659 }
660 }
661
662 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
663 private static final AllocationWithoutResourceRequirement.GeneratedPQuery INSTANCE = new GeneratedPQuery();
664
665 private final PParameter parameter_Host = new PParameter("Host", "hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "HostInstance")), PParameterDirection.INOUT);
666
667 private final PParameter parameter_App = new PParameter("App", "hu.bme.mit.inf.dslreasoner.domains.cps.ApplicationInstance", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "ApplicationInstance")), PParameterDirection.INOUT);
668
669 private final List<PParameter> parameters = Arrays.asList(parameter_Host, parameter_App);
670
671 private GeneratedPQuery() {
672 super(PVisibility.PUBLIC);
673 }
674
675 @Override
676 public String getFullyQualifiedName() {
677 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.allocationWithoutResourceRequirement";
678 }
679
680 @Override
681 public List<String> getParameterNames() {
682 return Arrays.asList("Host","App");
683 }
684
685 @Override
686 public List<PParameter> getParameters() {
687 return parameters;
688 }
689
690 @Override
691 public Set<PBody> doGetContainedBodies() {
692 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
693 Set<PBody> bodies = new LinkedHashSet<>();
694 {
695 PBody body = new PBody(this);
696 PVariable var_Host = body.getOrCreateVariableByName("Host");
697 PVariable var_App = body.getOrCreateVariableByName("App");
698 PVariable var___0_ = body.getOrCreateVariableByName("_<0>");
699 new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance")));
700 new TypeConstraint(body, Tuples.flatTupleOf(var_App), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance")));
701 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
702 new ExportedParameter(body, var_Host, parameter_Host),
703 new ExportedParameter(body, var_App, parameter_App)
704 ));
705 // ApplicationInstance.allocatedTo(App, Host)
706 new TypeConstraint(body, Tuples.flatTupleOf(var_App), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance")));
707 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
708 new TypeConstraint(body, Tuples.flatTupleOf(var_App, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ApplicationInstance", "allocatedTo")));
709 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance")));
710 new Equality(body, var__virtual_0_, var_Host);
711 // neg find resourceRequirement(Host, App, _)
712 new NegativePatternCall(body, Tuples.flatTupleOf(var_Host, var_App, var___0_), ResourceRequirement.instance().getInternalQueryRepresentation());
713 bodies.add(body);
714 }
715 {
716 PAnnotation annotation = new PAnnotation("Constraint");
717 annotation.addAttribute("severity", "error");
718 annotation.addAttribute("key", Arrays.asList(new Object[] {
719 new ParameterReference("Host"),
720 new ParameterReference("App")
721 }));
722 annotation.addAttribute("message", "Application instance must be allocated to a supported host type.");
723 addAnnotation(annotation);
724 }
725 return bodies;
726 }
727 }
728}
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/AverageFreeHddMetric.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/AverageFreeHddMetric.java
new file mode 100644
index 00000000..607854bf
--- /dev/null
+++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/AverageFreeHddMetric.java
@@ -0,0 +1,554 @@
1/**
2 * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql
3 */
4package hu.bme.mit.inf.dslreasoner.domains.cps.queries;
5
6import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.FreeHddPercentage;
7import java.util.Arrays;
8import java.util.Collection;
9import java.util.LinkedHashSet;
10import java.util.List;
11import java.util.Objects;
12import java.util.Optional;
13import java.util.Set;
14import java.util.function.Consumer;
15import java.util.stream.Collectors;
16import java.util.stream.Stream;
17import org.apache.log4j.Logger;
18import org.eclipse.viatra.query.runtime.api.IPatternMatch;
19import org.eclipse.viatra.query.runtime.api.IQuerySpecification;
20import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine;
21import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
22import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification;
23import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher;
24import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch;
25import org.eclipse.viatra.query.runtime.matchers.aggregators.avg;
26import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
27import org.eclipse.viatra.query.runtime.matchers.context.common.JavaTransitiveInstancesKey;
28import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
29import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
30import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.AggregatorConstraint;
31import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality;
32import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
33import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.TypeFilterConstraint;
34import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
35import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
36import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
37import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
38import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
39import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
40
41/**
42 * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
43 *
44 * <p>Original source:
45 * <code><pre>
46 * // Free HDD
47 *
48 * pattern averageFreeHddMetric(Average : java Double) {
49 * Average == avg find freeHddPercentage(_, #_);
50 * }
51 * </pre></code>
52 *
53 * @see Matcher
54 * @see Match
55 *
56 */
57@SuppressWarnings("all")
58public final class AverageFreeHddMetric extends BaseGeneratedEMFQuerySpecification<AverageFreeHddMetric.Matcher> {
59 /**
60 * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.averageFreeHddMetric pattern,
61 * to be used in conjunction with {@link Matcher}.
62 *
63 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
64 * Each instance is a (possibly partial) substitution of pattern parameters,
65 * usable to represent a match of the pattern in the result of a query,
66 * or to specify the bound (fixed) input parameters when issuing a query.
67 *
68 * @see Matcher
69 *
70 */
71 public static abstract class Match extends BasePatternMatch {
72 private Double fAverage;
73
74 private static List<String> parameterNames = makeImmutableList("Average");
75
76 private Match(final Double pAverage) {
77 this.fAverage = pAverage;
78 }
79
80 @Override
81 public Object get(final String parameterName) {
82 switch(parameterName) {
83 case "Average": return this.fAverage;
84 default: return null;
85 }
86 }
87
88 @Override
89 public Object get(final int index) {
90 switch(index) {
91 case 0: return this.fAverage;
92 default: return null;
93 }
94 }
95
96 public Double getAverage() {
97 return this.fAverage;
98 }
99
100 @Override
101 public boolean set(final String parameterName, final Object newValue) {
102 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
103 if ("Average".equals(parameterName) ) {
104 this.fAverage = (Double) newValue;
105 return true;
106 }
107 return false;
108 }
109
110 public void setAverage(final Double pAverage) {
111 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
112 this.fAverage = pAverage;
113 }
114
115 @Override
116 public String patternName() {
117 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.averageFreeHddMetric";
118 }
119
120 @Override
121 public List<String> parameterNames() {
122 return AverageFreeHddMetric.Match.parameterNames;
123 }
124
125 @Override
126 public Object[] toArray() {
127 return new Object[]{fAverage};
128 }
129
130 @Override
131 public AverageFreeHddMetric.Match toImmutable() {
132 return isMutable() ? newMatch(fAverage) : this;
133 }
134
135 @Override
136 public String prettyPrint() {
137 StringBuilder result = new StringBuilder();
138 result.append("\"Average\"=" + prettyPrintValue(fAverage));
139 return result.toString();
140 }
141
142 @Override
143 public int hashCode() {
144 return Objects.hash(fAverage);
145 }
146
147 @Override
148 public boolean equals(final Object obj) {
149 if (this == obj)
150 return true;
151 if (obj == null) {
152 return false;
153 }
154 if ((obj instanceof AverageFreeHddMetric.Match)) {
155 AverageFreeHddMetric.Match other = (AverageFreeHddMetric.Match) obj;
156 return Objects.equals(fAverage, other.fAverage);
157 } else {
158 // this should be infrequent
159 if (!(obj instanceof IPatternMatch)) {
160 return false;
161 }
162 IPatternMatch otherSig = (IPatternMatch) obj;
163 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
164 }
165 }
166
167 @Override
168 public AverageFreeHddMetric specification() {
169 return AverageFreeHddMetric.instance();
170 }
171
172 /**
173 * Returns an empty, mutable match.
174 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
175 *
176 * @return the empty match.
177 *
178 */
179 public static AverageFreeHddMetric.Match newEmptyMatch() {
180 return new Mutable(null);
181 }
182
183 /**
184 * Returns a mutable (partial) match.
185 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
186 *
187 * @param pAverage the fixed value of pattern parameter Average, or null if not bound.
188 * @return the new, mutable (partial) match object.
189 *
190 */
191 public static AverageFreeHddMetric.Match newMutableMatch(final Double pAverage) {
192 return new Mutable(pAverage);
193 }
194
195 /**
196 * Returns a new (partial) match.
197 * This can be used e.g. to call the matcher with a partial match.
198 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
199 * @param pAverage the fixed value of pattern parameter Average, or null if not bound.
200 * @return the (partial) match object.
201 *
202 */
203 public static AverageFreeHddMetric.Match newMatch(final Double pAverage) {
204 return new Immutable(pAverage);
205 }
206
207 private static final class Mutable extends AverageFreeHddMetric.Match {
208 Mutable(final Double pAverage) {
209 super(pAverage);
210 }
211
212 @Override
213 public boolean isMutable() {
214 return true;
215 }
216 }
217
218 private static final class Immutable extends AverageFreeHddMetric.Match {
219 Immutable(final Double pAverage) {
220 super(pAverage);
221 }
222
223 @Override
224 public boolean isMutable() {
225 return false;
226 }
227 }
228 }
229
230 /**
231 * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.averageFreeHddMetric pattern,
232 * providing pattern-specific query methods.
233 *
234 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
235 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
236 *
237 * <p>Matches of the pattern will be represented as {@link Match}.
238 *
239 * <p>Original source:
240 * <code><pre>
241 * // Free HDD
242 *
243 * pattern averageFreeHddMetric(Average : java Double) {
244 * Average == avg find freeHddPercentage(_, #_);
245 * }
246 * </pre></code>
247 *
248 * @see Match
249 * @see AverageFreeHddMetric
250 *
251 */
252 public static class Matcher extends BaseMatcher<AverageFreeHddMetric.Match> {
253 /**
254 * Initializes the pattern matcher within an existing VIATRA Query engine.
255 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
256 *
257 * @param engine the existing VIATRA Query engine in which this matcher will be created.
258 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
259 *
260 */
261 public static AverageFreeHddMetric.Matcher on(final ViatraQueryEngine engine) {
262 // check if matcher already exists
263 Matcher matcher = engine.getExistingMatcher(querySpecification());
264 if (matcher == null) {
265 matcher = (Matcher)engine.getMatcher(querySpecification());
266 }
267 return matcher;
268 }
269
270 /**
271 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
272 * @return an initialized matcher
273 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
274 *
275 */
276 public static AverageFreeHddMetric.Matcher create() {
277 return new Matcher();
278 }
279
280 private static final int POSITION_AVERAGE = 0;
281
282 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(AverageFreeHddMetric.Matcher.class);
283
284 /**
285 * Initializes the pattern matcher within an existing VIATRA Query engine.
286 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
287 *
288 * @param engine the existing VIATRA Query engine in which this matcher will be created.
289 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
290 *
291 */
292 private Matcher() {
293 super(querySpecification());
294 }
295
296 /**
297 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
298 * @param pAverage the fixed value of pattern parameter Average, or null if not bound.
299 * @return matches represented as a Match object.
300 *
301 */
302 public Collection<AverageFreeHddMetric.Match> getAllMatches(final Double pAverage) {
303 return rawStreamAllMatches(new Object[]{pAverage}).collect(Collectors.toSet());
304 }
305
306 /**
307 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
308 * </p>
309 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
310 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
311 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
312 * @param pAverage the fixed value of pattern parameter Average, or null if not bound.
313 * @return a stream of matches represented as a Match object.
314 *
315 */
316 public Stream<AverageFreeHddMetric.Match> streamAllMatches(final Double pAverage) {
317 return rawStreamAllMatches(new Object[]{pAverage});
318 }
319
320 /**
321 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
322 * Neither determinism nor randomness of selection is guaranteed.
323 * @param pAverage the fixed value of pattern parameter Average, or null if not bound.
324 * @return a match represented as a Match object, or null if no match is found.
325 *
326 */
327 public Optional<AverageFreeHddMetric.Match> getOneArbitraryMatch(final Double pAverage) {
328 return rawGetOneArbitraryMatch(new Object[]{pAverage});
329 }
330
331 /**
332 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
333 * under any possible substitution of the unspecified parameters (if any).
334 * @param pAverage the fixed value of pattern parameter Average, or null if not bound.
335 * @return true if the input is a valid (partial) match of the pattern.
336 *
337 */
338 public boolean hasMatch(final Double pAverage) {
339 return rawHasMatch(new Object[]{pAverage});
340 }
341
342 /**
343 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
344 * @param pAverage the fixed value of pattern parameter Average, or null if not bound.
345 * @return the number of pattern matches found.
346 *
347 */
348 public int countMatches(final Double pAverage) {
349 return rawCountMatches(new Object[]{pAverage});
350 }
351
352 /**
353 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
354 * Neither determinism nor randomness of selection is guaranteed.
355 * @param pAverage the fixed value of pattern parameter Average, or null if not bound.
356 * @param processor the action that will process the selected match.
357 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
358 *
359 */
360 public boolean forOneArbitraryMatch(final Double pAverage, final Consumer<? super AverageFreeHddMetric.Match> processor) {
361 return rawForOneArbitraryMatch(new Object[]{pAverage}, processor);
362 }
363
364 /**
365 * Returns a new (partial) match.
366 * This can be used e.g. to call the matcher with a partial match.
367 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
368 * @param pAverage the fixed value of pattern parameter Average, or null if not bound.
369 * @return the (partial) match object.
370 *
371 */
372 public AverageFreeHddMetric.Match newMatch(final Double pAverage) {
373 return AverageFreeHddMetric.Match.newMatch(pAverage);
374 }
375
376 /**
377 * Retrieve the set of values that occur in matches for Average.
378 * @return the Set of all values or empty set if there are no matches
379 *
380 */
381 protected Stream<Double> rawStreamAllValuesOfAverage(final Object[] parameters) {
382 return rawStreamAllValues(POSITION_AVERAGE, parameters).map(Double.class::cast);
383 }
384
385 /**
386 * Retrieve the set of values that occur in matches for Average.
387 * @return the Set of all values or empty set if there are no matches
388 *
389 */
390 public Set<Double> getAllValuesOfAverage() {
391 return rawStreamAllValuesOfAverage(emptyArray()).collect(Collectors.toSet());
392 }
393
394 /**
395 * Retrieve the set of values that occur in matches for Average.
396 * @return the Set of all values or empty set if there are no matches
397 *
398 */
399 public Stream<Double> streamAllValuesOfAverage() {
400 return rawStreamAllValuesOfAverage(emptyArray());
401 }
402
403 @Override
404 protected AverageFreeHddMetric.Match tupleToMatch(final Tuple t) {
405 try {
406 return AverageFreeHddMetric.Match.newMatch((Double) t.get(POSITION_AVERAGE));
407 } catch(ClassCastException e) {
408 LOGGER.error("Element(s) in tuple not properly typed!",e);
409 return null;
410 }
411 }
412
413 @Override
414 protected AverageFreeHddMetric.Match arrayToMatch(final Object[] match) {
415 try {
416 return AverageFreeHddMetric.Match.newMatch((Double) match[POSITION_AVERAGE]);
417 } catch(ClassCastException e) {
418 LOGGER.error("Element(s) in array not properly typed!",e);
419 return null;
420 }
421 }
422
423 @Override
424 protected AverageFreeHddMetric.Match arrayToMatchMutable(final Object[] match) {
425 try {
426 return AverageFreeHddMetric.Match.newMutableMatch((Double) match[POSITION_AVERAGE]);
427 } catch(ClassCastException e) {
428 LOGGER.error("Element(s) in array not properly typed!",e);
429 return null;
430 }
431 }
432
433 /**
434 * @return the singleton instance of the query specification of this pattern
435 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
436 *
437 */
438 public static IQuerySpecification<AverageFreeHddMetric.Matcher> querySpecification() {
439 return AverageFreeHddMetric.instance();
440 }
441 }
442
443 private AverageFreeHddMetric() {
444 super(GeneratedPQuery.INSTANCE);
445 }
446
447 /**
448 * @return the singleton instance of the query specification
449 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
450 *
451 */
452 public static AverageFreeHddMetric instance() {
453 try{
454 return LazyHolder.INSTANCE;
455 } catch (ExceptionInInitializerError err) {
456 throw processInitializerError(err);
457 }
458 }
459
460 @Override
461 protected AverageFreeHddMetric.Matcher instantiate(final ViatraQueryEngine engine) {
462 return AverageFreeHddMetric.Matcher.on(engine);
463 }
464
465 @Override
466 public AverageFreeHddMetric.Matcher instantiate() {
467 return AverageFreeHddMetric.Matcher.create();
468 }
469
470 @Override
471 public AverageFreeHddMetric.Match newEmptyMatch() {
472 return AverageFreeHddMetric.Match.newEmptyMatch();
473 }
474
475 @Override
476 public AverageFreeHddMetric.Match newMatch(final Object... parameters) {
477 return AverageFreeHddMetric.Match.newMatch((java.lang.Double) parameters[0]);
478 }
479
480 /**
481 * Inner class allowing the singleton instance of {@link AverageFreeHddMetric} to be created
482 * <b>not</b> at the class load time of the outer class,
483 * but rather at the first call to {@link AverageFreeHddMetric#instance()}.
484 *
485 * <p> This workaround is required e.g. to support recursion.
486 *
487 */
488 private static class LazyHolder {
489 private static final AverageFreeHddMetric INSTANCE = new AverageFreeHddMetric();
490
491 /**
492 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
493 * This initialization order is required to support indirect recursion.
494 *
495 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
496 *
497 */
498 private static final Object STATIC_INITIALIZER = ensureInitialized();
499
500 public static Object ensureInitialized() {
501 INSTANCE.ensureInitializedInternal();
502 return null;
503 }
504 }
505
506 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
507 private static final AverageFreeHddMetric.GeneratedPQuery INSTANCE = new GeneratedPQuery();
508
509 private final PParameter parameter_Average = new PParameter("Average", "java.lang.Double", new JavaTransitiveInstancesKey(java.lang.Double.class), PParameterDirection.INOUT);
510
511 private final List<PParameter> parameters = Arrays.asList(parameter_Average);
512
513 private GeneratedPQuery() {
514 super(PVisibility.PUBLIC);
515 }
516
517 @Override
518 public String getFullyQualifiedName() {
519 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.averageFreeHddMetric";
520 }
521
522 @Override
523 public List<String> getParameterNames() {
524 return Arrays.asList("Average");
525 }
526
527 @Override
528 public List<PParameter> getParameters() {
529 return parameters;
530 }
531
532 @Override
533 public Set<PBody> doGetContainedBodies() {
534 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
535 Set<PBody> bodies = new LinkedHashSet<>();
536 {
537 PBody body = new PBody(this);
538 PVariable var_Average = body.getOrCreateVariableByName("Average");
539 PVariable var___0_ = body.getOrCreateVariableByName("_<0>");
540 PVariable var___1_ = body.getOrCreateVariableByName("_<1>");
541 new TypeFilterConstraint(body, Tuples.flatTupleOf(var_Average), new JavaTransitiveInstancesKey(java.lang.Double.class));
542 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
543 new ExportedParameter(body, var_Average, parameter_Average)
544 ));
545 // Average == avg find freeHddPercentage(_, #_)
546 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
547 new AggregatorConstraint(new avg().getAggregatorLogic(Double.class), body, Tuples.flatTupleOf(var___0_, var___1_), FreeHddPercentage.instance().getInternalQueryRepresentation(), var__virtual_0_, 1);
548 new Equality(body, var_Average, var__virtual_0_);
549 bodies.add(body);
550 }
551 return bodies;
552 }
553 }
554}
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/AverageFreeMemoryMetric.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/AverageFreeMemoryMetric.java
new file mode 100644
index 00000000..627a5f89
--- /dev/null
+++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/AverageFreeMemoryMetric.java
@@ -0,0 +1,562 @@
1/**
2 * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql
3 */
4package hu.bme.mit.inf.dslreasoner.domains.cps.queries;
5
6import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.FreeMemoryPercentage;
7import java.util.Arrays;
8import java.util.Collection;
9import java.util.LinkedHashSet;
10import java.util.List;
11import java.util.Objects;
12import java.util.Optional;
13import java.util.Set;
14import java.util.function.Consumer;
15import java.util.stream.Collectors;
16import java.util.stream.Stream;
17import org.apache.log4j.Logger;
18import org.eclipse.viatra.query.runtime.api.IPatternMatch;
19import org.eclipse.viatra.query.runtime.api.IQuerySpecification;
20import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine;
21import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
22import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification;
23import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher;
24import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch;
25import org.eclipse.viatra.query.runtime.matchers.aggregators.avg;
26import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
27import org.eclipse.viatra.query.runtime.matchers.context.common.JavaTransitiveInstancesKey;
28import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
29import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
30import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.AggregatorConstraint;
31import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality;
32import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
33import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.TypeFilterConstraint;
34import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
35import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
36import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
37import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
38import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
39import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
40
41/**
42 * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
43 *
44 * <p>Original source:
45 * <code><pre>
46 * //
47 * // Metrics
48 * //
49 *
50 * // Free memory
51 *
52 * pattern averageFreeMemoryMetric(Average : java Double) {
53 * Average == avg find freeMemoryPercentage(_, #_);
54 * }
55 * </pre></code>
56 *
57 * @see Matcher
58 * @see Match
59 *
60 */
61@SuppressWarnings("all")
62public final class AverageFreeMemoryMetric extends BaseGeneratedEMFQuerySpecification<AverageFreeMemoryMetric.Matcher> {
63 /**
64 * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.averageFreeMemoryMetric pattern,
65 * to be used in conjunction with {@link Matcher}.
66 *
67 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
68 * Each instance is a (possibly partial) substitution of pattern parameters,
69 * usable to represent a match of the pattern in the result of a query,
70 * or to specify the bound (fixed) input parameters when issuing a query.
71 *
72 * @see Matcher
73 *
74 */
75 public static abstract class Match extends BasePatternMatch {
76 private Double fAverage;
77
78 private static List<String> parameterNames = makeImmutableList("Average");
79
80 private Match(final Double pAverage) {
81 this.fAverage = pAverage;
82 }
83
84 @Override
85 public Object get(final String parameterName) {
86 switch(parameterName) {
87 case "Average": return this.fAverage;
88 default: return null;
89 }
90 }
91
92 @Override
93 public Object get(final int index) {
94 switch(index) {
95 case 0: return this.fAverage;
96 default: return null;
97 }
98 }
99
100 public Double getAverage() {
101 return this.fAverage;
102 }
103
104 @Override
105 public boolean set(final String parameterName, final Object newValue) {
106 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
107 if ("Average".equals(parameterName) ) {
108 this.fAverage = (Double) newValue;
109 return true;
110 }
111 return false;
112 }
113
114 public void setAverage(final Double pAverage) {
115 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
116 this.fAverage = pAverage;
117 }
118
119 @Override
120 public String patternName() {
121 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.averageFreeMemoryMetric";
122 }
123
124 @Override
125 public List<String> parameterNames() {
126 return AverageFreeMemoryMetric.Match.parameterNames;
127 }
128
129 @Override
130 public Object[] toArray() {
131 return new Object[]{fAverage};
132 }
133
134 @Override
135 public AverageFreeMemoryMetric.Match toImmutable() {
136 return isMutable() ? newMatch(fAverage) : this;
137 }
138
139 @Override
140 public String prettyPrint() {
141 StringBuilder result = new StringBuilder();
142 result.append("\"Average\"=" + prettyPrintValue(fAverage));
143 return result.toString();
144 }
145
146 @Override
147 public int hashCode() {
148 return Objects.hash(fAverage);
149 }
150
151 @Override
152 public boolean equals(final Object obj) {
153 if (this == obj)
154 return true;
155 if (obj == null) {
156 return false;
157 }
158 if ((obj instanceof AverageFreeMemoryMetric.Match)) {
159 AverageFreeMemoryMetric.Match other = (AverageFreeMemoryMetric.Match) obj;
160 return Objects.equals(fAverage, other.fAverage);
161 } else {
162 // this should be infrequent
163 if (!(obj instanceof IPatternMatch)) {
164 return false;
165 }
166 IPatternMatch otherSig = (IPatternMatch) obj;
167 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
168 }
169 }
170
171 @Override
172 public AverageFreeMemoryMetric specification() {
173 return AverageFreeMemoryMetric.instance();
174 }
175
176 /**
177 * Returns an empty, mutable match.
178 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
179 *
180 * @return the empty match.
181 *
182 */
183 public static AverageFreeMemoryMetric.Match newEmptyMatch() {
184 return new Mutable(null);
185 }
186
187 /**
188 * Returns a mutable (partial) match.
189 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
190 *
191 * @param pAverage the fixed value of pattern parameter Average, or null if not bound.
192 * @return the new, mutable (partial) match object.
193 *
194 */
195 public static AverageFreeMemoryMetric.Match newMutableMatch(final Double pAverage) {
196 return new Mutable(pAverage);
197 }
198
199 /**
200 * Returns a new (partial) match.
201 * This can be used e.g. to call the matcher with a partial match.
202 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
203 * @param pAverage the fixed value of pattern parameter Average, or null if not bound.
204 * @return the (partial) match object.
205 *
206 */
207 public static AverageFreeMemoryMetric.Match newMatch(final Double pAverage) {
208 return new Immutable(pAverage);
209 }
210
211 private static final class Mutable extends AverageFreeMemoryMetric.Match {
212 Mutable(final Double pAverage) {
213 super(pAverage);
214 }
215
216 @Override
217 public boolean isMutable() {
218 return true;
219 }
220 }
221
222 private static final class Immutable extends AverageFreeMemoryMetric.Match {
223 Immutable(final Double pAverage) {
224 super(pAverage);
225 }
226
227 @Override
228 public boolean isMutable() {
229 return false;
230 }
231 }
232 }
233
234 /**
235 * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.averageFreeMemoryMetric pattern,
236 * providing pattern-specific query methods.
237 *
238 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
239 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
240 *
241 * <p>Matches of the pattern will be represented as {@link Match}.
242 *
243 * <p>Original source:
244 * <code><pre>
245 * //
246 * // Metrics
247 * //
248 *
249 * // Free memory
250 *
251 * pattern averageFreeMemoryMetric(Average : java Double) {
252 * Average == avg find freeMemoryPercentage(_, #_);
253 * }
254 * </pre></code>
255 *
256 * @see Match
257 * @see AverageFreeMemoryMetric
258 *
259 */
260 public static class Matcher extends BaseMatcher<AverageFreeMemoryMetric.Match> {
261 /**
262 * Initializes the pattern matcher within an existing VIATRA Query engine.
263 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
264 *
265 * @param engine the existing VIATRA Query engine in which this matcher will be created.
266 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
267 *
268 */
269 public static AverageFreeMemoryMetric.Matcher on(final ViatraQueryEngine engine) {
270 // check if matcher already exists
271 Matcher matcher = engine.getExistingMatcher(querySpecification());
272 if (matcher == null) {
273 matcher = (Matcher)engine.getMatcher(querySpecification());
274 }
275 return matcher;
276 }
277
278 /**
279 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
280 * @return an initialized matcher
281 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
282 *
283 */
284 public static AverageFreeMemoryMetric.Matcher create() {
285 return new Matcher();
286 }
287
288 private static final int POSITION_AVERAGE = 0;
289
290 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(AverageFreeMemoryMetric.Matcher.class);
291
292 /**
293 * Initializes the pattern matcher within an existing VIATRA Query engine.
294 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
295 *
296 * @param engine the existing VIATRA Query engine in which this matcher will be created.
297 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
298 *
299 */
300 private Matcher() {
301 super(querySpecification());
302 }
303
304 /**
305 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
306 * @param pAverage the fixed value of pattern parameter Average, or null if not bound.
307 * @return matches represented as a Match object.
308 *
309 */
310 public Collection<AverageFreeMemoryMetric.Match> getAllMatches(final Double pAverage) {
311 return rawStreamAllMatches(new Object[]{pAverage}).collect(Collectors.toSet());
312 }
313
314 /**
315 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
316 * </p>
317 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
318 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
319 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
320 * @param pAverage the fixed value of pattern parameter Average, or null if not bound.
321 * @return a stream of matches represented as a Match object.
322 *
323 */
324 public Stream<AverageFreeMemoryMetric.Match> streamAllMatches(final Double pAverage) {
325 return rawStreamAllMatches(new Object[]{pAverage});
326 }
327
328 /**
329 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
330 * Neither determinism nor randomness of selection is guaranteed.
331 * @param pAverage the fixed value of pattern parameter Average, or null if not bound.
332 * @return a match represented as a Match object, or null if no match is found.
333 *
334 */
335 public Optional<AverageFreeMemoryMetric.Match> getOneArbitraryMatch(final Double pAverage) {
336 return rawGetOneArbitraryMatch(new Object[]{pAverage});
337 }
338
339 /**
340 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
341 * under any possible substitution of the unspecified parameters (if any).
342 * @param pAverage the fixed value of pattern parameter Average, or null if not bound.
343 * @return true if the input is a valid (partial) match of the pattern.
344 *
345 */
346 public boolean hasMatch(final Double pAverage) {
347 return rawHasMatch(new Object[]{pAverage});
348 }
349
350 /**
351 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
352 * @param pAverage the fixed value of pattern parameter Average, or null if not bound.
353 * @return the number of pattern matches found.
354 *
355 */
356 public int countMatches(final Double pAverage) {
357 return rawCountMatches(new Object[]{pAverage});
358 }
359
360 /**
361 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
362 * Neither determinism nor randomness of selection is guaranteed.
363 * @param pAverage the fixed value of pattern parameter Average, or null if not bound.
364 * @param processor the action that will process the selected match.
365 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
366 *
367 */
368 public boolean forOneArbitraryMatch(final Double pAverage, final Consumer<? super AverageFreeMemoryMetric.Match> processor) {
369 return rawForOneArbitraryMatch(new Object[]{pAverage}, processor);
370 }
371
372 /**
373 * Returns a new (partial) match.
374 * This can be used e.g. to call the matcher with a partial match.
375 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
376 * @param pAverage the fixed value of pattern parameter Average, or null if not bound.
377 * @return the (partial) match object.
378 *
379 */
380 public AverageFreeMemoryMetric.Match newMatch(final Double pAverage) {
381 return AverageFreeMemoryMetric.Match.newMatch(pAverage);
382 }
383
384 /**
385 * Retrieve the set of values that occur in matches for Average.
386 * @return the Set of all values or empty set if there are no matches
387 *
388 */
389 protected Stream<Double> rawStreamAllValuesOfAverage(final Object[] parameters) {
390 return rawStreamAllValues(POSITION_AVERAGE, parameters).map(Double.class::cast);
391 }
392
393 /**
394 * Retrieve the set of values that occur in matches for Average.
395 * @return the Set of all values or empty set if there are no matches
396 *
397 */
398 public Set<Double> getAllValuesOfAverage() {
399 return rawStreamAllValuesOfAverage(emptyArray()).collect(Collectors.toSet());
400 }
401
402 /**
403 * Retrieve the set of values that occur in matches for Average.
404 * @return the Set of all values or empty set if there are no matches
405 *
406 */
407 public Stream<Double> streamAllValuesOfAverage() {
408 return rawStreamAllValuesOfAverage(emptyArray());
409 }
410
411 @Override
412 protected AverageFreeMemoryMetric.Match tupleToMatch(final Tuple t) {
413 try {
414 return AverageFreeMemoryMetric.Match.newMatch((Double) t.get(POSITION_AVERAGE));
415 } catch(ClassCastException e) {
416 LOGGER.error("Element(s) in tuple not properly typed!",e);
417 return null;
418 }
419 }
420
421 @Override
422 protected AverageFreeMemoryMetric.Match arrayToMatch(final Object[] match) {
423 try {
424 return AverageFreeMemoryMetric.Match.newMatch((Double) match[POSITION_AVERAGE]);
425 } catch(ClassCastException e) {
426 LOGGER.error("Element(s) in array not properly typed!",e);
427 return null;
428 }
429 }
430
431 @Override
432 protected AverageFreeMemoryMetric.Match arrayToMatchMutable(final Object[] match) {
433 try {
434 return AverageFreeMemoryMetric.Match.newMutableMatch((Double) match[POSITION_AVERAGE]);
435 } catch(ClassCastException e) {
436 LOGGER.error("Element(s) in array not properly typed!",e);
437 return null;
438 }
439 }
440
441 /**
442 * @return the singleton instance of the query specification of this pattern
443 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
444 *
445 */
446 public static IQuerySpecification<AverageFreeMemoryMetric.Matcher> querySpecification() {
447 return AverageFreeMemoryMetric.instance();
448 }
449 }
450
451 private AverageFreeMemoryMetric() {
452 super(GeneratedPQuery.INSTANCE);
453 }
454
455 /**
456 * @return the singleton instance of the query specification
457 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
458 *
459 */
460 public static AverageFreeMemoryMetric instance() {
461 try{
462 return LazyHolder.INSTANCE;
463 } catch (ExceptionInInitializerError err) {
464 throw processInitializerError(err);
465 }
466 }
467
468 @Override
469 protected AverageFreeMemoryMetric.Matcher instantiate(final ViatraQueryEngine engine) {
470 return AverageFreeMemoryMetric.Matcher.on(engine);
471 }
472
473 @Override
474 public AverageFreeMemoryMetric.Matcher instantiate() {
475 return AverageFreeMemoryMetric.Matcher.create();
476 }
477
478 @Override
479 public AverageFreeMemoryMetric.Match newEmptyMatch() {
480 return AverageFreeMemoryMetric.Match.newEmptyMatch();
481 }
482
483 @Override
484 public AverageFreeMemoryMetric.Match newMatch(final Object... parameters) {
485 return AverageFreeMemoryMetric.Match.newMatch((java.lang.Double) parameters[0]);
486 }
487
488 /**
489 * Inner class allowing the singleton instance of {@link AverageFreeMemoryMetric} to be created
490 * <b>not</b> at the class load time of the outer class,
491 * but rather at the first call to {@link AverageFreeMemoryMetric#instance()}.
492 *
493 * <p> This workaround is required e.g. to support recursion.
494 *
495 */
496 private static class LazyHolder {
497 private static final AverageFreeMemoryMetric INSTANCE = new AverageFreeMemoryMetric();
498
499 /**
500 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
501 * This initialization order is required to support indirect recursion.
502 *
503 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
504 *
505 */
506 private static final Object STATIC_INITIALIZER = ensureInitialized();
507
508 public static Object ensureInitialized() {
509 INSTANCE.ensureInitializedInternal();
510 return null;
511 }
512 }
513
514 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
515 private static final AverageFreeMemoryMetric.GeneratedPQuery INSTANCE = new GeneratedPQuery();
516
517 private final PParameter parameter_Average = new PParameter("Average", "java.lang.Double", new JavaTransitiveInstancesKey(java.lang.Double.class), PParameterDirection.INOUT);
518
519 private final List<PParameter> parameters = Arrays.asList(parameter_Average);
520
521 private GeneratedPQuery() {
522 super(PVisibility.PUBLIC);
523 }
524
525 @Override
526 public String getFullyQualifiedName() {
527 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.averageFreeMemoryMetric";
528 }
529
530 @Override
531 public List<String> getParameterNames() {
532 return Arrays.asList("Average");
533 }
534
535 @Override
536 public List<PParameter> getParameters() {
537 return parameters;
538 }
539
540 @Override
541 public Set<PBody> doGetContainedBodies() {
542 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
543 Set<PBody> bodies = new LinkedHashSet<>();
544 {
545 PBody body = new PBody(this);
546 PVariable var_Average = body.getOrCreateVariableByName("Average");
547 PVariable var___0_ = body.getOrCreateVariableByName("_<0>");
548 PVariable var___1_ = body.getOrCreateVariableByName("_<1>");
549 new TypeFilterConstraint(body, Tuples.flatTupleOf(var_Average), new JavaTransitiveInstancesKey(java.lang.Double.class));
550 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
551 new ExportedParameter(body, var_Average, parameter_Average)
552 ));
553 // Average == avg find freeMemoryPercentage(_, #_)
554 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
555 new AggregatorConstraint(new avg().getAggregatorLogic(Double.class), body, Tuples.flatTupleOf(var___0_, var___1_), FreeMemoryPercentage.instance().getInternalQueryRepresentation(), var__virtual_0_, 1);
556 new Equality(body, var_Average, var__virtual_0_);
557 bodies.add(body);
558 }
559 return bodies;
560 }
561 }
562}
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CostMetric.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CostMetric.java
new file mode 100644
index 00000000..eff44f0a
--- /dev/null
+++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CostMetric.java
@@ -0,0 +1,554 @@
1/**
2 * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql
3 */
4package hu.bme.mit.inf.dslreasoner.domains.cps.queries;
5
6import hu.bme.mit.inf.dslreasoner.domains.cps.queries.CpsCost;
7import java.util.Arrays;
8import java.util.Collection;
9import java.util.LinkedHashSet;
10import java.util.List;
11import java.util.Objects;
12import java.util.Optional;
13import java.util.Set;
14import java.util.function.Consumer;
15import java.util.stream.Collectors;
16import java.util.stream.Stream;
17import org.apache.log4j.Logger;
18import org.eclipse.viatra.query.runtime.api.IPatternMatch;
19import org.eclipse.viatra.query.runtime.api.IQuerySpecification;
20import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine;
21import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
22import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification;
23import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher;
24import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch;
25import org.eclipse.viatra.query.runtime.matchers.aggregators.sum;
26import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
27import org.eclipse.viatra.query.runtime.matchers.context.common.JavaTransitiveInstancesKey;
28import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
29import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
30import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.AggregatorConstraint;
31import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality;
32import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
33import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.TypeFilterConstraint;
34import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
35import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
36import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
37import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
38import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
39import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
40
41/**
42 * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
43 *
44 * <p>Original source:
45 * <code><pre>
46 * // Total cost
47 *
48 * pattern costMetric(Cost : java Integer) {
49 * Cost == sum find cpsCost(_, #_);
50 * }
51 * </pre></code>
52 *
53 * @see Matcher
54 * @see Match
55 *
56 */
57@SuppressWarnings("all")
58public final class CostMetric extends BaseGeneratedEMFQuerySpecification<CostMetric.Matcher> {
59 /**
60 * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.costMetric pattern,
61 * to be used in conjunction with {@link Matcher}.
62 *
63 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
64 * Each instance is a (possibly partial) substitution of pattern parameters,
65 * usable to represent a match of the pattern in the result of a query,
66 * or to specify the bound (fixed) input parameters when issuing a query.
67 *
68 * @see Matcher
69 *
70 */
71 public static abstract class Match extends BasePatternMatch {
72 private Integer fCost;
73
74 private static List<String> parameterNames = makeImmutableList("Cost");
75
76 private Match(final Integer pCost) {
77 this.fCost = pCost;
78 }
79
80 @Override
81 public Object get(final String parameterName) {
82 switch(parameterName) {
83 case "Cost": return this.fCost;
84 default: return null;
85 }
86 }
87
88 @Override
89 public Object get(final int index) {
90 switch(index) {
91 case 0: return this.fCost;
92 default: return null;
93 }
94 }
95
96 public Integer getCost() {
97 return this.fCost;
98 }
99
100 @Override
101 public boolean set(final String parameterName, final Object newValue) {
102 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
103 if ("Cost".equals(parameterName) ) {
104 this.fCost = (Integer) newValue;
105 return true;
106 }
107 return false;
108 }
109
110 public void setCost(final Integer pCost) {
111 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
112 this.fCost = pCost;
113 }
114
115 @Override
116 public String patternName() {
117 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.costMetric";
118 }
119
120 @Override
121 public List<String> parameterNames() {
122 return CostMetric.Match.parameterNames;
123 }
124
125 @Override
126 public Object[] toArray() {
127 return new Object[]{fCost};
128 }
129
130 @Override
131 public CostMetric.Match toImmutable() {
132 return isMutable() ? newMatch(fCost) : this;
133 }
134
135 @Override
136 public String prettyPrint() {
137 StringBuilder result = new StringBuilder();
138 result.append("\"Cost\"=" + prettyPrintValue(fCost));
139 return result.toString();
140 }
141
142 @Override
143 public int hashCode() {
144 return Objects.hash(fCost);
145 }
146
147 @Override
148 public boolean equals(final Object obj) {
149 if (this == obj)
150 return true;
151 if (obj == null) {
152 return false;
153 }
154 if ((obj instanceof CostMetric.Match)) {
155 CostMetric.Match other = (CostMetric.Match) obj;
156 return Objects.equals(fCost, other.fCost);
157 } else {
158 // this should be infrequent
159 if (!(obj instanceof IPatternMatch)) {
160 return false;
161 }
162 IPatternMatch otherSig = (IPatternMatch) obj;
163 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
164 }
165 }
166
167 @Override
168 public CostMetric specification() {
169 return CostMetric.instance();
170 }
171
172 /**
173 * Returns an empty, mutable match.
174 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
175 *
176 * @return the empty match.
177 *
178 */
179 public static CostMetric.Match newEmptyMatch() {
180 return new Mutable(null);
181 }
182
183 /**
184 * Returns a mutable (partial) match.
185 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
186 *
187 * @param pCost the fixed value of pattern parameter Cost, or null if not bound.
188 * @return the new, mutable (partial) match object.
189 *
190 */
191 public static CostMetric.Match newMutableMatch(final Integer pCost) {
192 return new Mutable(pCost);
193 }
194
195 /**
196 * Returns a new (partial) match.
197 * This can be used e.g. to call the matcher with a partial match.
198 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
199 * @param pCost the fixed value of pattern parameter Cost, or null if not bound.
200 * @return the (partial) match object.
201 *
202 */
203 public static CostMetric.Match newMatch(final Integer pCost) {
204 return new Immutable(pCost);
205 }
206
207 private static final class Mutable extends CostMetric.Match {
208 Mutable(final Integer pCost) {
209 super(pCost);
210 }
211
212 @Override
213 public boolean isMutable() {
214 return true;
215 }
216 }
217
218 private static final class Immutable extends CostMetric.Match {
219 Immutable(final Integer pCost) {
220 super(pCost);
221 }
222
223 @Override
224 public boolean isMutable() {
225 return false;
226 }
227 }
228 }
229
230 /**
231 * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.costMetric pattern,
232 * providing pattern-specific query methods.
233 *
234 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
235 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
236 *
237 * <p>Matches of the pattern will be represented as {@link Match}.
238 *
239 * <p>Original source:
240 * <code><pre>
241 * // Total cost
242 *
243 * pattern costMetric(Cost : java Integer) {
244 * Cost == sum find cpsCost(_, #_);
245 * }
246 * </pre></code>
247 *
248 * @see Match
249 * @see CostMetric
250 *
251 */
252 public static class Matcher extends BaseMatcher<CostMetric.Match> {
253 /**
254 * Initializes the pattern matcher within an existing VIATRA Query engine.
255 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
256 *
257 * @param engine the existing VIATRA Query engine in which this matcher will be created.
258 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
259 *
260 */
261 public static CostMetric.Matcher on(final ViatraQueryEngine engine) {
262 // check if matcher already exists
263 Matcher matcher = engine.getExistingMatcher(querySpecification());
264 if (matcher == null) {
265 matcher = (Matcher)engine.getMatcher(querySpecification());
266 }
267 return matcher;
268 }
269
270 /**
271 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
272 * @return an initialized matcher
273 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
274 *
275 */
276 public static CostMetric.Matcher create() {
277 return new Matcher();
278 }
279
280 private static final int POSITION_COST = 0;
281
282 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(CostMetric.Matcher.class);
283
284 /**
285 * Initializes the pattern matcher within an existing VIATRA Query engine.
286 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
287 *
288 * @param engine the existing VIATRA Query engine in which this matcher will be created.
289 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
290 *
291 */
292 private Matcher() {
293 super(querySpecification());
294 }
295
296 /**
297 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
298 * @param pCost the fixed value of pattern parameter Cost, or null if not bound.
299 * @return matches represented as a Match object.
300 *
301 */
302 public Collection<CostMetric.Match> getAllMatches(final Integer pCost) {
303 return rawStreamAllMatches(new Object[]{pCost}).collect(Collectors.toSet());
304 }
305
306 /**
307 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
308 * </p>
309 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
310 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
311 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
312 * @param pCost the fixed value of pattern parameter Cost, or null if not bound.
313 * @return a stream of matches represented as a Match object.
314 *
315 */
316 public Stream<CostMetric.Match> streamAllMatches(final Integer pCost) {
317 return rawStreamAllMatches(new Object[]{pCost});
318 }
319
320 /**
321 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
322 * Neither determinism nor randomness of selection is guaranteed.
323 * @param pCost the fixed value of pattern parameter Cost, or null if not bound.
324 * @return a match represented as a Match object, or null if no match is found.
325 *
326 */
327 public Optional<CostMetric.Match> getOneArbitraryMatch(final Integer pCost) {
328 return rawGetOneArbitraryMatch(new Object[]{pCost});
329 }
330
331 /**
332 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
333 * under any possible substitution of the unspecified parameters (if any).
334 * @param pCost the fixed value of pattern parameter Cost, or null if not bound.
335 * @return true if the input is a valid (partial) match of the pattern.
336 *
337 */
338 public boolean hasMatch(final Integer pCost) {
339 return rawHasMatch(new Object[]{pCost});
340 }
341
342 /**
343 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
344 * @param pCost the fixed value of pattern parameter Cost, or null if not bound.
345 * @return the number of pattern matches found.
346 *
347 */
348 public int countMatches(final Integer pCost) {
349 return rawCountMatches(new Object[]{pCost});
350 }
351
352 /**
353 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
354 * Neither determinism nor randomness of selection is guaranteed.
355 * @param pCost the fixed value of pattern parameter Cost, or null if not bound.
356 * @param processor the action that will process the selected match.
357 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
358 *
359 */
360 public boolean forOneArbitraryMatch(final Integer pCost, final Consumer<? super CostMetric.Match> processor) {
361 return rawForOneArbitraryMatch(new Object[]{pCost}, processor);
362 }
363
364 /**
365 * Returns a new (partial) match.
366 * This can be used e.g. to call the matcher with a partial match.
367 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
368 * @param pCost the fixed value of pattern parameter Cost, or null if not bound.
369 * @return the (partial) match object.
370 *
371 */
372 public CostMetric.Match newMatch(final Integer pCost) {
373 return CostMetric.Match.newMatch(pCost);
374 }
375
376 /**
377 * Retrieve the set of values that occur in matches for Cost.
378 * @return the Set of all values or empty set if there are no matches
379 *
380 */
381 protected Stream<Integer> rawStreamAllValuesOfCost(final Object[] parameters) {
382 return rawStreamAllValues(POSITION_COST, parameters).map(Integer.class::cast);
383 }
384
385 /**
386 * Retrieve the set of values that occur in matches for Cost.
387 * @return the Set of all values or empty set if there are no matches
388 *
389 */
390 public Set<Integer> getAllValuesOfCost() {
391 return rawStreamAllValuesOfCost(emptyArray()).collect(Collectors.toSet());
392 }
393
394 /**
395 * Retrieve the set of values that occur in matches for Cost.
396 * @return the Set of all values or empty set if there are no matches
397 *
398 */
399 public Stream<Integer> streamAllValuesOfCost() {
400 return rawStreamAllValuesOfCost(emptyArray());
401 }
402
403 @Override
404 protected CostMetric.Match tupleToMatch(final Tuple t) {
405 try {
406 return CostMetric.Match.newMatch((Integer) t.get(POSITION_COST));
407 } catch(ClassCastException e) {
408 LOGGER.error("Element(s) in tuple not properly typed!",e);
409 return null;
410 }
411 }
412
413 @Override
414 protected CostMetric.Match arrayToMatch(final Object[] match) {
415 try {
416 return CostMetric.Match.newMatch((Integer) match[POSITION_COST]);
417 } catch(ClassCastException e) {
418 LOGGER.error("Element(s) in array not properly typed!",e);
419 return null;
420 }
421 }
422
423 @Override
424 protected CostMetric.Match arrayToMatchMutable(final Object[] match) {
425 try {
426 return CostMetric.Match.newMutableMatch((Integer) match[POSITION_COST]);
427 } catch(ClassCastException e) {
428 LOGGER.error("Element(s) in array not properly typed!",e);
429 return null;
430 }
431 }
432
433 /**
434 * @return the singleton instance of the query specification of this pattern
435 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
436 *
437 */
438 public static IQuerySpecification<CostMetric.Matcher> querySpecification() {
439 return CostMetric.instance();
440 }
441 }
442
443 private CostMetric() {
444 super(GeneratedPQuery.INSTANCE);
445 }
446
447 /**
448 * @return the singleton instance of the query specification
449 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
450 *
451 */
452 public static CostMetric instance() {
453 try{
454 return LazyHolder.INSTANCE;
455 } catch (ExceptionInInitializerError err) {
456 throw processInitializerError(err);
457 }
458 }
459
460 @Override
461 protected CostMetric.Matcher instantiate(final ViatraQueryEngine engine) {
462 return CostMetric.Matcher.on(engine);
463 }
464
465 @Override
466 public CostMetric.Matcher instantiate() {
467 return CostMetric.Matcher.create();
468 }
469
470 @Override
471 public CostMetric.Match newEmptyMatch() {
472 return CostMetric.Match.newEmptyMatch();
473 }
474
475 @Override
476 public CostMetric.Match newMatch(final Object... parameters) {
477 return CostMetric.Match.newMatch((java.lang.Integer) parameters[0]);
478 }
479
480 /**
481 * Inner class allowing the singleton instance of {@link CostMetric} to be created
482 * <b>not</b> at the class load time of the outer class,
483 * but rather at the first call to {@link CostMetric#instance()}.
484 *
485 * <p> This workaround is required e.g. to support recursion.
486 *
487 */
488 private static class LazyHolder {
489 private static final CostMetric INSTANCE = new CostMetric();
490
491 /**
492 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
493 * This initialization order is required to support indirect recursion.
494 *
495 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
496 *
497 */
498 private static final Object STATIC_INITIALIZER = ensureInitialized();
499
500 public static Object ensureInitialized() {
501 INSTANCE.ensureInitializedInternal();
502 return null;
503 }
504 }
505
506 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
507 private static final CostMetric.GeneratedPQuery INSTANCE = new GeneratedPQuery();
508
509 private final PParameter parameter_Cost = new PParameter("Cost", "java.lang.Integer", new JavaTransitiveInstancesKey(java.lang.Integer.class), PParameterDirection.INOUT);
510
511 private final List<PParameter> parameters = Arrays.asList(parameter_Cost);
512
513 private GeneratedPQuery() {
514 super(PVisibility.PUBLIC);
515 }
516
517 @Override
518 public String getFullyQualifiedName() {
519 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.costMetric";
520 }
521
522 @Override
523 public List<String> getParameterNames() {
524 return Arrays.asList("Cost");
525 }
526
527 @Override
528 public List<PParameter> getParameters() {
529 return parameters;
530 }
531
532 @Override
533 public Set<PBody> doGetContainedBodies() {
534 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
535 Set<PBody> bodies = new LinkedHashSet<>();
536 {
537 PBody body = new PBody(this);
538 PVariable var_Cost = body.getOrCreateVariableByName("Cost");
539 PVariable var___0_ = body.getOrCreateVariableByName("_<0>");
540 PVariable var___1_ = body.getOrCreateVariableByName("_<1>");
541 new TypeFilterConstraint(body, Tuples.flatTupleOf(var_Cost), new JavaTransitiveInstancesKey(java.lang.Integer.class));
542 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
543 new ExportedParameter(body, var_Cost, parameter_Cost)
544 ));
545 // Cost == sum find cpsCost(_, #_)
546 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
547 new AggregatorConstraint(new sum().getAggregatorLogic(Integer.class), body, Tuples.flatTupleOf(var___0_, var___1_), CpsCost.instance().getInternalQueryRepresentation(), var__virtual_0_, 1);
548 new Equality(body, var_Cost, var__virtual_0_);
549 bodies.add(body);
550 }
551 return bodies;
552 }
553 }
554}
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsCost.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsCost.java
new file mode 100644
index 00000000..1cf09b0d
--- /dev/null
+++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsCost.java
@@ -0,0 +1,749 @@
1/**
2 * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql
3 */
4package hu.bme.mit.inf.dslreasoner.domains.cps.queries;
5
6import hu.bme.mit.inf.dslreasoner.domains.cps.CyberPhysicalSystem;
7import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.CpsApplications;
8import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.HostInstanceCost;
9import java.util.Arrays;
10import java.util.Collection;
11import java.util.LinkedHashSet;
12import java.util.List;
13import java.util.Objects;
14import java.util.Optional;
15import java.util.Set;
16import java.util.function.Consumer;
17import java.util.stream.Collectors;
18import java.util.stream.Stream;
19import org.apache.log4j.Logger;
20import org.eclipse.emf.ecore.EClass;
21import org.eclipse.viatra.query.runtime.api.IPatternMatch;
22import org.eclipse.viatra.query.runtime.api.IQuerySpecification;
23import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine;
24import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
25import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification;
26import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher;
27import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch;
28import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey;
29import org.eclipse.viatra.query.runtime.matchers.aggregators.sum;
30import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
31import org.eclipse.viatra.query.runtime.matchers.context.common.JavaTransitiveInstancesKey;
32import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator;
33import org.eclipse.viatra.query.runtime.matchers.psystem.IValueProvider;
34import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
35import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
36import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.AggregatorConstraint;
37import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality;
38import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
39import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation;
40import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.PatternMatchCounter;
41import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.TypeFilterConstraint;
42import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
43import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
44import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
45import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
46import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
47import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
48import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
49
50/**
51 * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
52 *
53 * <p>Original source:
54 * <code><pre>
55 * pattern cpsCost(Cps : CyberPhysicalSystem, Cost : java Integer) {
56 * AppCount == count find cpsApplications(Cps, _);
57 * HostCost == sum find hostInstanceCost(Cps, _, #_);
58 * Cost == eval(5 AppCount + HostCost);
59 * }
60 * </pre></code>
61 *
62 * @see Matcher
63 * @see Match
64 *
65 */
66@SuppressWarnings("all")
67public final class CpsCost extends BaseGeneratedEMFQuerySpecification<CpsCost.Matcher> {
68 /**
69 * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.cpsCost pattern,
70 * to be used in conjunction with {@link Matcher}.
71 *
72 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
73 * Each instance is a (possibly partial) substitution of pattern parameters,
74 * usable to represent a match of the pattern in the result of a query,
75 * or to specify the bound (fixed) input parameters when issuing a query.
76 *
77 * @see Matcher
78 *
79 */
80 public static abstract class Match extends BasePatternMatch {
81 private CyberPhysicalSystem fCps;
82
83 private Integer fCost;
84
85 private static List<String> parameterNames = makeImmutableList("Cps", "Cost");
86
87 private Match(final CyberPhysicalSystem pCps, final Integer pCost) {
88 this.fCps = pCps;
89 this.fCost = pCost;
90 }
91
92 @Override
93 public Object get(final String parameterName) {
94 switch(parameterName) {
95 case "Cps": return this.fCps;
96 case "Cost": return this.fCost;
97 default: return null;
98 }
99 }
100
101 @Override
102 public Object get(final int index) {
103 switch(index) {
104 case 0: return this.fCps;
105 case 1: return this.fCost;
106 default: return null;
107 }
108 }
109
110 public CyberPhysicalSystem getCps() {
111 return this.fCps;
112 }
113
114 public Integer getCost() {
115 return this.fCost;
116 }
117
118 @Override
119 public boolean set(final String parameterName, final Object newValue) {
120 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
121 if ("Cps".equals(parameterName) ) {
122 this.fCps = (CyberPhysicalSystem) newValue;
123 return true;
124 }
125 if ("Cost".equals(parameterName) ) {
126 this.fCost = (Integer) newValue;
127 return true;
128 }
129 return false;
130 }
131
132 public void setCps(final CyberPhysicalSystem pCps) {
133 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
134 this.fCps = pCps;
135 }
136
137 public void setCost(final Integer pCost) {
138 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
139 this.fCost = pCost;
140 }
141
142 @Override
143 public String patternName() {
144 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.cpsCost";
145 }
146
147 @Override
148 public List<String> parameterNames() {
149 return CpsCost.Match.parameterNames;
150 }
151
152 @Override
153 public Object[] toArray() {
154 return new Object[]{fCps, fCost};
155 }
156
157 @Override
158 public CpsCost.Match toImmutable() {
159 return isMutable() ? newMatch(fCps, fCost) : this;
160 }
161
162 @Override
163 public String prettyPrint() {
164 StringBuilder result = new StringBuilder();
165 result.append("\"Cps\"=" + prettyPrintValue(fCps) + ", ");
166 result.append("\"Cost\"=" + prettyPrintValue(fCost));
167 return result.toString();
168 }
169
170 @Override
171 public int hashCode() {
172 return Objects.hash(fCps, fCost);
173 }
174
175 @Override
176 public boolean equals(final Object obj) {
177 if (this == obj)
178 return true;
179 if (obj == null) {
180 return false;
181 }
182 if ((obj instanceof CpsCost.Match)) {
183 CpsCost.Match other = (CpsCost.Match) obj;
184 return Objects.equals(fCps, other.fCps) && Objects.equals(fCost, other.fCost);
185 } else {
186 // this should be infrequent
187 if (!(obj instanceof IPatternMatch)) {
188 return false;
189 }
190 IPatternMatch otherSig = (IPatternMatch) obj;
191 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
192 }
193 }
194
195 @Override
196 public CpsCost specification() {
197 return CpsCost.instance();
198 }
199
200 /**
201 * Returns an empty, mutable match.
202 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
203 *
204 * @return the empty match.
205 *
206 */
207 public static CpsCost.Match newEmptyMatch() {
208 return new Mutable(null, null);
209 }
210
211 /**
212 * Returns a mutable (partial) match.
213 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
214 *
215 * @param pCps the fixed value of pattern parameter Cps, or null if not bound.
216 * @param pCost the fixed value of pattern parameter Cost, or null if not bound.
217 * @return the new, mutable (partial) match object.
218 *
219 */
220 public static CpsCost.Match newMutableMatch(final CyberPhysicalSystem pCps, final Integer pCost) {
221 return new Mutable(pCps, pCost);
222 }
223
224 /**
225 * Returns a new (partial) match.
226 * This can be used e.g. to call the matcher with a partial match.
227 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
228 * @param pCps the fixed value of pattern parameter Cps, or null if not bound.
229 * @param pCost the fixed value of pattern parameter Cost, or null if not bound.
230 * @return the (partial) match object.
231 *
232 */
233 public static CpsCost.Match newMatch(final CyberPhysicalSystem pCps, final Integer pCost) {
234 return new Immutable(pCps, pCost);
235 }
236
237 private static final class Mutable extends CpsCost.Match {
238 Mutable(final CyberPhysicalSystem pCps, final Integer pCost) {
239 super(pCps, pCost);
240 }
241
242 @Override
243 public boolean isMutable() {
244 return true;
245 }
246 }
247
248 private static final class Immutable extends CpsCost.Match {
249 Immutable(final CyberPhysicalSystem pCps, final Integer pCost) {
250 super(pCps, pCost);
251 }
252
253 @Override
254 public boolean isMutable() {
255 return false;
256 }
257 }
258 }
259
260 /**
261 * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.cpsCost pattern,
262 * providing pattern-specific query methods.
263 *
264 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
265 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
266 *
267 * <p>Matches of the pattern will be represented as {@link Match}.
268 *
269 * <p>Original source:
270 * <code><pre>
271 * pattern cpsCost(Cps : CyberPhysicalSystem, Cost : java Integer) {
272 * AppCount == count find cpsApplications(Cps, _);
273 * HostCost == sum find hostInstanceCost(Cps, _, #_);
274 * Cost == eval(5 AppCount + HostCost);
275 * }
276 * </pre></code>
277 *
278 * @see Match
279 * @see CpsCost
280 *
281 */
282 public static class Matcher extends BaseMatcher<CpsCost.Match> {
283 /**
284 * Initializes the pattern matcher within an existing VIATRA Query engine.
285 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
286 *
287 * @param engine the existing VIATRA Query engine in which this matcher will be created.
288 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
289 *
290 */
291 public static CpsCost.Matcher on(final ViatraQueryEngine engine) {
292 // check if matcher already exists
293 Matcher matcher = engine.getExistingMatcher(querySpecification());
294 if (matcher == null) {
295 matcher = (Matcher)engine.getMatcher(querySpecification());
296 }
297 return matcher;
298 }
299
300 /**
301 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
302 * @return an initialized matcher
303 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
304 *
305 */
306 public static CpsCost.Matcher create() {
307 return new Matcher();
308 }
309
310 private static final int POSITION_CPS = 0;
311
312 private static final int POSITION_COST = 1;
313
314 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(CpsCost.Matcher.class);
315
316 /**
317 * Initializes the pattern matcher within an existing VIATRA Query engine.
318 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
319 *
320 * @param engine the existing VIATRA Query engine in which this matcher will be created.
321 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
322 *
323 */
324 private Matcher() {
325 super(querySpecification());
326 }
327
328 /**
329 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
330 * @param pCps the fixed value of pattern parameter Cps, or null if not bound.
331 * @param pCost the fixed value of pattern parameter Cost, or null if not bound.
332 * @return matches represented as a Match object.
333 *
334 */
335 public Collection<CpsCost.Match> getAllMatches(final CyberPhysicalSystem pCps, final Integer pCost) {
336 return rawStreamAllMatches(new Object[]{pCps, pCost}).collect(Collectors.toSet());
337 }
338
339 /**
340 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
341 * </p>
342 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
343 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
344 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
345 * @param pCps the fixed value of pattern parameter Cps, or null if not bound.
346 * @param pCost the fixed value of pattern parameter Cost, or null if not bound.
347 * @return a stream of matches represented as a Match object.
348 *
349 */
350 public Stream<CpsCost.Match> streamAllMatches(final CyberPhysicalSystem pCps, final Integer pCost) {
351 return rawStreamAllMatches(new Object[]{pCps, pCost});
352 }
353
354 /**
355 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
356 * Neither determinism nor randomness of selection is guaranteed.
357 * @param pCps the fixed value of pattern parameter Cps, or null if not bound.
358 * @param pCost the fixed value of pattern parameter Cost, or null if not bound.
359 * @return a match represented as a Match object, or null if no match is found.
360 *
361 */
362 public Optional<CpsCost.Match> getOneArbitraryMatch(final CyberPhysicalSystem pCps, final Integer pCost) {
363 return rawGetOneArbitraryMatch(new Object[]{pCps, pCost});
364 }
365
366 /**
367 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
368 * under any possible substitution of the unspecified parameters (if any).
369 * @param pCps the fixed value of pattern parameter Cps, or null if not bound.
370 * @param pCost the fixed value of pattern parameter Cost, or null if not bound.
371 * @return true if the input is a valid (partial) match of the pattern.
372 *
373 */
374 public boolean hasMatch(final CyberPhysicalSystem pCps, final Integer pCost) {
375 return rawHasMatch(new Object[]{pCps, pCost});
376 }
377
378 /**
379 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
380 * @param pCps the fixed value of pattern parameter Cps, or null if not bound.
381 * @param pCost the fixed value of pattern parameter Cost, or null if not bound.
382 * @return the number of pattern matches found.
383 *
384 */
385 public int countMatches(final CyberPhysicalSystem pCps, final Integer pCost) {
386 return rawCountMatches(new Object[]{pCps, pCost});
387 }
388
389 /**
390 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
391 * Neither determinism nor randomness of selection is guaranteed.
392 * @param pCps the fixed value of pattern parameter Cps, or null if not bound.
393 * @param pCost the fixed value of pattern parameter Cost, or null if not bound.
394 * @param processor the action that will process the selected match.
395 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
396 *
397 */
398 public boolean forOneArbitraryMatch(final CyberPhysicalSystem pCps, final Integer pCost, final Consumer<? super CpsCost.Match> processor) {
399 return rawForOneArbitraryMatch(new Object[]{pCps, pCost}, processor);
400 }
401
402 /**
403 * Returns a new (partial) match.
404 * This can be used e.g. to call the matcher with a partial match.
405 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
406 * @param pCps the fixed value of pattern parameter Cps, or null if not bound.
407 * @param pCost the fixed value of pattern parameter Cost, or null if not bound.
408 * @return the (partial) match object.
409 *
410 */
411 public CpsCost.Match newMatch(final CyberPhysicalSystem pCps, final Integer pCost) {
412 return CpsCost.Match.newMatch(pCps, pCost);
413 }
414
415 /**
416 * Retrieve the set of values that occur in matches for Cps.
417 * @return the Set of all values or empty set if there are no matches
418 *
419 */
420 protected Stream<CyberPhysicalSystem> rawStreamAllValuesOfCps(final Object[] parameters) {
421 return rawStreamAllValues(POSITION_CPS, parameters).map(CyberPhysicalSystem.class::cast);
422 }
423
424 /**
425 * Retrieve the set of values that occur in matches for Cps.
426 * @return the Set of all values or empty set if there are no matches
427 *
428 */
429 public Set<CyberPhysicalSystem> getAllValuesOfCps() {
430 return rawStreamAllValuesOfCps(emptyArray()).collect(Collectors.toSet());
431 }
432
433 /**
434 * Retrieve the set of values that occur in matches for Cps.
435 * @return the Set of all values or empty set if there are no matches
436 *
437 */
438 public Stream<CyberPhysicalSystem> streamAllValuesOfCps() {
439 return rawStreamAllValuesOfCps(emptyArray());
440 }
441
442 /**
443 * Retrieve the set of values that occur in matches for Cps.
444 * </p>
445 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
446 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
447 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
448 *
449 * @return the Stream of all values or empty set if there are no matches
450 *
451 */
452 public Stream<CyberPhysicalSystem> streamAllValuesOfCps(final CpsCost.Match partialMatch) {
453 return rawStreamAllValuesOfCps(partialMatch.toArray());
454 }
455
456 /**
457 * Retrieve the set of values that occur in matches for Cps.
458 * </p>
459 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
460 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
461 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
462 *
463 * @return the Stream of all values or empty set if there are no matches
464 *
465 */
466 public Stream<CyberPhysicalSystem> streamAllValuesOfCps(final Integer pCost) {
467 return rawStreamAllValuesOfCps(new Object[]{null, pCost});
468 }
469
470 /**
471 * Retrieve the set of values that occur in matches for Cps.
472 * @return the Set of all values or empty set if there are no matches
473 *
474 */
475 public Set<CyberPhysicalSystem> getAllValuesOfCps(final CpsCost.Match partialMatch) {
476 return rawStreamAllValuesOfCps(partialMatch.toArray()).collect(Collectors.toSet());
477 }
478
479 /**
480 * Retrieve the set of values that occur in matches for Cps.
481 * @return the Set of all values or empty set if there are no matches
482 *
483 */
484 public Set<CyberPhysicalSystem> getAllValuesOfCps(final Integer pCost) {
485 return rawStreamAllValuesOfCps(new Object[]{null, pCost}).collect(Collectors.toSet());
486 }
487
488 /**
489 * Retrieve the set of values that occur in matches for Cost.
490 * @return the Set of all values or empty set if there are no matches
491 *
492 */
493 protected Stream<Integer> rawStreamAllValuesOfCost(final Object[] parameters) {
494 return rawStreamAllValues(POSITION_COST, parameters).map(Integer.class::cast);
495 }
496
497 /**
498 * Retrieve the set of values that occur in matches for Cost.
499 * @return the Set of all values or empty set if there are no matches
500 *
501 */
502 public Set<Integer> getAllValuesOfCost() {
503 return rawStreamAllValuesOfCost(emptyArray()).collect(Collectors.toSet());
504 }
505
506 /**
507 * Retrieve the set of values that occur in matches for Cost.
508 * @return the Set of all values or empty set if there are no matches
509 *
510 */
511 public Stream<Integer> streamAllValuesOfCost() {
512 return rawStreamAllValuesOfCost(emptyArray());
513 }
514
515 /**
516 * Retrieve the set of values that occur in matches for Cost.
517 * </p>
518 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
519 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
520 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
521 *
522 * @return the Stream of all values or empty set if there are no matches
523 *
524 */
525 public Stream<Integer> streamAllValuesOfCost(final CpsCost.Match partialMatch) {
526 return rawStreamAllValuesOfCost(partialMatch.toArray());
527 }
528
529 /**
530 * Retrieve the set of values that occur in matches for Cost.
531 * </p>
532 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
533 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
534 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
535 *
536 * @return the Stream of all values or empty set if there are no matches
537 *
538 */
539 public Stream<Integer> streamAllValuesOfCost(final CyberPhysicalSystem pCps) {
540 return rawStreamAllValuesOfCost(new Object[]{pCps, null});
541 }
542
543 /**
544 * Retrieve the set of values that occur in matches for Cost.
545 * @return the Set of all values or empty set if there are no matches
546 *
547 */
548 public Set<Integer> getAllValuesOfCost(final CpsCost.Match partialMatch) {
549 return rawStreamAllValuesOfCost(partialMatch.toArray()).collect(Collectors.toSet());
550 }
551
552 /**
553 * Retrieve the set of values that occur in matches for Cost.
554 * @return the Set of all values or empty set if there are no matches
555 *
556 */
557 public Set<Integer> getAllValuesOfCost(final CyberPhysicalSystem pCps) {
558 return rawStreamAllValuesOfCost(new Object[]{pCps, null}).collect(Collectors.toSet());
559 }
560
561 @Override
562 protected CpsCost.Match tupleToMatch(final Tuple t) {
563 try {
564 return CpsCost.Match.newMatch((CyberPhysicalSystem) t.get(POSITION_CPS), (Integer) t.get(POSITION_COST));
565 } catch(ClassCastException e) {
566 LOGGER.error("Element(s) in tuple not properly typed!",e);
567 return null;
568 }
569 }
570
571 @Override
572 protected CpsCost.Match arrayToMatch(final Object[] match) {
573 try {
574 return CpsCost.Match.newMatch((CyberPhysicalSystem) match[POSITION_CPS], (Integer) match[POSITION_COST]);
575 } catch(ClassCastException e) {
576 LOGGER.error("Element(s) in array not properly typed!",e);
577 return null;
578 }
579 }
580
581 @Override
582 protected CpsCost.Match arrayToMatchMutable(final Object[] match) {
583 try {
584 return CpsCost.Match.newMutableMatch((CyberPhysicalSystem) match[POSITION_CPS], (Integer) match[POSITION_COST]);
585 } catch(ClassCastException e) {
586 LOGGER.error("Element(s) in array not properly typed!",e);
587 return null;
588 }
589 }
590
591 /**
592 * @return the singleton instance of the query specification of this pattern
593 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
594 *
595 */
596 public static IQuerySpecification<CpsCost.Matcher> querySpecification() {
597 return CpsCost.instance();
598 }
599 }
600
601 private CpsCost() {
602 super(GeneratedPQuery.INSTANCE);
603 }
604
605 /**
606 * @return the singleton instance of the query specification
607 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
608 *
609 */
610 public static CpsCost instance() {
611 try{
612 return LazyHolder.INSTANCE;
613 } catch (ExceptionInInitializerError err) {
614 throw processInitializerError(err);
615 }
616 }
617
618 @Override
619 protected CpsCost.Matcher instantiate(final ViatraQueryEngine engine) {
620 return CpsCost.Matcher.on(engine);
621 }
622
623 @Override
624 public CpsCost.Matcher instantiate() {
625 return CpsCost.Matcher.create();
626 }
627
628 @Override
629 public CpsCost.Match newEmptyMatch() {
630 return CpsCost.Match.newEmptyMatch();
631 }
632
633 @Override
634 public CpsCost.Match newMatch(final Object... parameters) {
635 return CpsCost.Match.newMatch((hu.bme.mit.inf.dslreasoner.domains.cps.CyberPhysicalSystem) parameters[0], (java.lang.Integer) parameters[1]);
636 }
637
638 /**
639 * Inner class allowing the singleton instance of {@link CpsCost} to be created
640 * <b>not</b> at the class load time of the outer class,
641 * but rather at the first call to {@link CpsCost#instance()}.
642 *
643 * <p> This workaround is required e.g. to support recursion.
644 *
645 */
646 private static class LazyHolder {
647 private static final CpsCost INSTANCE = new CpsCost();
648
649 /**
650 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
651 * This initialization order is required to support indirect recursion.
652 *
653 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
654 *
655 */
656 private static final Object STATIC_INITIALIZER = ensureInitialized();
657
658 public static Object ensureInitialized() {
659 INSTANCE.ensureInitializedInternal();
660 return null;
661 }
662 }
663
664 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
665 private static final CpsCost.GeneratedPQuery INSTANCE = new GeneratedPQuery();
666
667 private final PParameter parameter_Cps = new PParameter("Cps", "hu.bme.mit.inf.dslreasoner.domains.cps.CyberPhysicalSystem", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "CyberPhysicalSystem")), PParameterDirection.INOUT);
668
669 private final PParameter parameter_Cost = new PParameter("Cost", "java.lang.Integer", new JavaTransitiveInstancesKey(java.lang.Integer.class), PParameterDirection.INOUT);
670
671 private final List<PParameter> parameters = Arrays.asList(parameter_Cps, parameter_Cost);
672
673 private GeneratedPQuery() {
674 super(PVisibility.PUBLIC);
675 }
676
677 @Override
678 public String getFullyQualifiedName() {
679 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.cpsCost";
680 }
681
682 @Override
683 public List<String> getParameterNames() {
684 return Arrays.asList("Cps","Cost");
685 }
686
687 @Override
688 public List<PParameter> getParameters() {
689 return parameters;
690 }
691
692 @Override
693 public Set<PBody> doGetContainedBodies() {
694 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
695 Set<PBody> bodies = new LinkedHashSet<>();
696 {
697 PBody body = new PBody(this);
698 PVariable var_Cps = body.getOrCreateVariableByName("Cps");
699 PVariable var_Cost = body.getOrCreateVariableByName("Cost");
700 PVariable var_AppCount = body.getOrCreateVariableByName("AppCount");
701 PVariable var___0_ = body.getOrCreateVariableByName("_<0>");
702 PVariable var_HostCost = body.getOrCreateVariableByName("HostCost");
703 PVariable var___1_ = body.getOrCreateVariableByName("_<1>");
704 PVariable var___2_ = body.getOrCreateVariableByName("_<2>");
705 new TypeConstraint(body, Tuples.flatTupleOf(var_Cps), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "CyberPhysicalSystem")));
706 new TypeFilterConstraint(body, Tuples.flatTupleOf(var_Cost), new JavaTransitiveInstancesKey(java.lang.Integer.class));
707 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
708 new ExportedParameter(body, var_Cps, parameter_Cps),
709 new ExportedParameter(body, var_Cost, parameter_Cost)
710 ));
711 // AppCount == count find cpsApplications(Cps, _)
712 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
713 new PatternMatchCounter(body, Tuples.flatTupleOf(var_Cps, var___0_), CpsApplications.instance().getInternalQueryRepresentation(), var__virtual_0_);
714 new Equality(body, var_AppCount, var__virtual_0_);
715 // HostCost == sum find hostInstanceCost(Cps, _, #_)
716 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
717 new AggregatorConstraint(new sum().getAggregatorLogic(Integer.class), body, Tuples.flatTupleOf(var_Cps, var___1_, var___2_), HostInstanceCost.instance().getInternalQueryRepresentation(), var__virtual_1_, 2);
718 new Equality(body, var_HostCost, var__virtual_1_);
719 // Cost == eval(5 * AppCount + HostCost)
720 PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}");
721 new ExpressionEvaluation(body, new IExpressionEvaluator() {
722
723 @Override
724 public String getShortDescription() {
725 return "Expression evaluation from pattern cpsCost";
726 }
727
728 @Override
729 public Iterable<String> getInputParameterNames() {
730 return Arrays.asList("AppCount", "HostCost");}
731
732 @Override
733 public Object evaluateExpression(IValueProvider provider) throws Exception {
734 Integer AppCount = (Integer) provider.getValue("AppCount");
735 Integer HostCost = (Integer) provider.getValue("HostCost");
736 return evaluateExpression_1_1(AppCount, HostCost);
737 }
738 }, var__virtual_2_ );
739 new Equality(body, var_Cost, var__virtual_2_);
740 bodies.add(body);
741 }
742 return bodies;
743 }
744 }
745
746 private static int evaluateExpression_1_1(final Integer AppCount, final Integer HostCost) {
747 return ((5 * (AppCount).intValue()) + (HostCost).intValue());
748 }
749}
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.java
new file mode 100644
index 00000000..c889fbe0
--- /dev/null
+++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.java
@@ -0,0 +1,218 @@
1/**
2 * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql
3 */
4package hu.bme.mit.inf.dslreasoner.domains.cps.queries;
5
6import hu.bme.mit.inf.dslreasoner.domains.cps.queries.Allocate;
7import hu.bme.mit.inf.dslreasoner.domains.cps.queries.AllocationWithoutResourceRequirement;
8import hu.bme.mit.inf.dslreasoner.domains.cps.queries.AverageFreeHddMetric;
9import hu.bme.mit.inf.dslreasoner.domains.cps.queries.AverageFreeMemoryMetric;
10import hu.bme.mit.inf.dslreasoner.domains.cps.queries.CostMetric;
11import hu.bme.mit.inf.dslreasoner.domains.cps.queries.CpsCost;
12import hu.bme.mit.inf.dslreasoner.domains.cps.queries.CreateHostInstance;
13import hu.bme.mit.inf.dslreasoner.domains.cps.queries.GuidanceObjective;
14import hu.bme.mit.inf.dslreasoner.domains.cps.queries.InstanceDoesNotSatisfyRequirement;
15import hu.bme.mit.inf.dslreasoner.domains.cps.queries.NotEnoughAvailableHdd;
16import hu.bme.mit.inf.dslreasoner.domains.cps.queries.NotEnoughAvailableMemory;
17import hu.bme.mit.inf.dslreasoner.domains.cps.queries.RedundantInstancesOnSameHost;
18import hu.bme.mit.inf.dslreasoner.domains.cps.queries.RemoveHostInstance;
19import hu.bme.mit.inf.dslreasoner.domains.cps.queries.RequirementNotSatisfied;
20import hu.bme.mit.inf.dslreasoner.domains.cps.queries.ResourceRequirement;
21import hu.bme.mit.inf.dslreasoner.domains.cps.queries.UnallocateAppInstance;
22import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine;
23import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedPatternGroup;
24
25/**
26 * A pattern group formed of all public patterns defined in CpsQueries.vql.
27 *
28 * <p>Use the static instance as any {@link interface org.eclipse.viatra.query.runtime.api.IQueryGroup}, to conveniently prepare
29 * a VIATRA Query engine for matching all patterns originally defined in file CpsQueries.vql,
30 * in order to achieve better performance than one-by-one on-demand matcher initialization.
31 *
32 * <p> From package hu.bme.mit.inf.dslreasoner.domains.cps.queries, the group contains the definition of the following patterns: <ul>
33 * <li>resourceRequirement</li>
34 * <li>allocationWithoutResourceRequirement</li>
35 * <li>notEnoughAvailableMemory</li>
36 * <li>notEnoughAvailableHdd</li>
37 * <li>instanceDoesNotSatisfyRequirement</li>
38 * <li>requirementNotSatisfied</li>
39 * <li>redundantInstancesOnSameHost</li>
40 * <li>averageFreeMemoryMetric</li>
41 * <li>averageFreeHddMetric</li>
42 * <li>costMetric</li>
43 * <li>cpsCost</li>
44 * <li>allocate</li>
45 * <li>unallocateAppInstance</li>
46 * <li>createHostInstance</li>
47 * <li>removeHostInstance</li>
48 * <li>guidanceObjective</li>
49 * </ul>
50 *
51 * @see IQueryGroup
52 *
53 */
54@SuppressWarnings("all")
55public final class CpsQueries extends BaseGeneratedPatternGroup {
56 /**
57 * Access the pattern group.
58 *
59 * @return the singleton instance of the group
60 * @throws ViatraQueryRuntimeException if there was an error loading the generated code of pattern specifications
61 *
62 */
63 public static CpsQueries instance() {
64 if (INSTANCE == null) {
65 INSTANCE = new CpsQueries();
66 }
67 return INSTANCE;
68 }
69
70 private static CpsQueries INSTANCE;
71
72 private CpsQueries() {
73 querySpecifications.add(ResourceRequirement.instance());
74 querySpecifications.add(AllocationWithoutResourceRequirement.instance());
75 querySpecifications.add(NotEnoughAvailableMemory.instance());
76 querySpecifications.add(NotEnoughAvailableHdd.instance());
77 querySpecifications.add(InstanceDoesNotSatisfyRequirement.instance());
78 querySpecifications.add(RequirementNotSatisfied.instance());
79 querySpecifications.add(RedundantInstancesOnSameHost.instance());
80 querySpecifications.add(AverageFreeMemoryMetric.instance());
81 querySpecifications.add(AverageFreeHddMetric.instance());
82 querySpecifications.add(CostMetric.instance());
83 querySpecifications.add(CpsCost.instance());
84 querySpecifications.add(Allocate.instance());
85 querySpecifications.add(UnallocateAppInstance.instance());
86 querySpecifications.add(CreateHostInstance.instance());
87 querySpecifications.add(RemoveHostInstance.instance());
88 querySpecifications.add(GuidanceObjective.instance());
89 }
90
91 public ResourceRequirement getResourceRequirement() {
92 return ResourceRequirement.instance();
93 }
94
95 public ResourceRequirement.Matcher getResourceRequirement(final ViatraQueryEngine engine) {
96 return ResourceRequirement.Matcher.on(engine);
97 }
98
99 public AllocationWithoutResourceRequirement getAllocationWithoutResourceRequirement() {
100 return AllocationWithoutResourceRequirement.instance();
101 }
102
103 public AllocationWithoutResourceRequirement.Matcher getAllocationWithoutResourceRequirement(final ViatraQueryEngine engine) {
104 return AllocationWithoutResourceRequirement.Matcher.on(engine);
105 }
106
107 public NotEnoughAvailableMemory getNotEnoughAvailableMemory() {
108 return NotEnoughAvailableMemory.instance();
109 }
110
111 public NotEnoughAvailableMemory.Matcher getNotEnoughAvailableMemory(final ViatraQueryEngine engine) {
112 return NotEnoughAvailableMemory.Matcher.on(engine);
113 }
114
115 public NotEnoughAvailableHdd getNotEnoughAvailableHdd() {
116 return NotEnoughAvailableHdd.instance();
117 }
118
119 public NotEnoughAvailableHdd.Matcher getNotEnoughAvailableHdd(final ViatraQueryEngine engine) {
120 return NotEnoughAvailableHdd.Matcher.on(engine);
121 }
122
123 public InstanceDoesNotSatisfyRequirement getInstanceDoesNotSatisfyRequirement() {
124 return InstanceDoesNotSatisfyRequirement.instance();
125 }
126
127 public InstanceDoesNotSatisfyRequirement.Matcher getInstanceDoesNotSatisfyRequirement(final ViatraQueryEngine engine) {
128 return InstanceDoesNotSatisfyRequirement.Matcher.on(engine);
129 }
130
131 public RequirementNotSatisfied getRequirementNotSatisfied() {
132 return RequirementNotSatisfied.instance();
133 }
134
135 public RequirementNotSatisfied.Matcher getRequirementNotSatisfied(final ViatraQueryEngine engine) {
136 return RequirementNotSatisfied.Matcher.on(engine);
137 }
138
139 public RedundantInstancesOnSameHost getRedundantInstancesOnSameHost() {
140 return RedundantInstancesOnSameHost.instance();
141 }
142
143 public RedundantInstancesOnSameHost.Matcher getRedundantInstancesOnSameHost(final ViatraQueryEngine engine) {
144 return RedundantInstancesOnSameHost.Matcher.on(engine);
145 }
146
147 public AverageFreeMemoryMetric getAverageFreeMemoryMetric() {
148 return AverageFreeMemoryMetric.instance();
149 }
150
151 public AverageFreeMemoryMetric.Matcher getAverageFreeMemoryMetric(final ViatraQueryEngine engine) {
152 return AverageFreeMemoryMetric.Matcher.on(engine);
153 }
154
155 public AverageFreeHddMetric getAverageFreeHddMetric() {
156 return AverageFreeHddMetric.instance();
157 }
158
159 public AverageFreeHddMetric.Matcher getAverageFreeHddMetric(final ViatraQueryEngine engine) {
160 return AverageFreeHddMetric.Matcher.on(engine);
161 }
162
163 public CostMetric getCostMetric() {
164 return CostMetric.instance();
165 }
166
167 public CostMetric.Matcher getCostMetric(final ViatraQueryEngine engine) {
168 return CostMetric.Matcher.on(engine);
169 }
170
171 public CpsCost getCpsCost() {
172 return CpsCost.instance();
173 }
174
175 public CpsCost.Matcher getCpsCost(final ViatraQueryEngine engine) {
176 return CpsCost.Matcher.on(engine);
177 }
178
179 public Allocate getAllocate() {
180 return Allocate.instance();
181 }
182
183 public Allocate.Matcher getAllocate(final ViatraQueryEngine engine) {
184 return Allocate.Matcher.on(engine);
185 }
186
187 public UnallocateAppInstance getUnallocateAppInstance() {
188 return UnallocateAppInstance.instance();
189 }
190
191 public UnallocateAppInstance.Matcher getUnallocateAppInstance(final ViatraQueryEngine engine) {
192 return UnallocateAppInstance.Matcher.on(engine);
193 }
194
195 public CreateHostInstance getCreateHostInstance() {
196 return CreateHostInstance.instance();
197 }
198
199 public CreateHostInstance.Matcher getCreateHostInstance(final ViatraQueryEngine engine) {
200 return CreateHostInstance.Matcher.on(engine);
201 }
202
203 public RemoveHostInstance getRemoveHostInstance() {
204 return RemoveHostInstance.instance();
205 }
206
207 public RemoveHostInstance.Matcher getRemoveHostInstance(final ViatraQueryEngine engine) {
208 return RemoveHostInstance.Matcher.on(engine);
209 }
210
211 public GuidanceObjective getGuidanceObjective() {
212 return GuidanceObjective.instance();
213 }
214
215 public GuidanceObjective.Matcher getGuidanceObjective(final ViatraQueryEngine engine) {
216 return GuidanceObjective.Matcher.on(engine);
217 }
218}
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CreateHostInstance.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CreateHostInstance.java
new file mode 100644
index 00000000..04036e11
--- /dev/null
+++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CreateHostInstance.java
@@ -0,0 +1,563 @@
1/**
2 * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql
3 */
4package hu.bme.mit.inf.dslreasoner.domains.cps.queries;
5
6import hu.bme.mit.inf.dslreasoner.domains.cps.HostType;
7import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.UnallocatedAppInstance;
8import java.util.Arrays;
9import java.util.Collection;
10import java.util.LinkedHashSet;
11import java.util.List;
12import java.util.Objects;
13import java.util.Optional;
14import java.util.Set;
15import java.util.function.Consumer;
16import java.util.stream.Collectors;
17import java.util.stream.Stream;
18import org.apache.log4j.Logger;
19import org.eclipse.emf.ecore.EClass;
20import org.eclipse.viatra.query.runtime.api.IPatternMatch;
21import org.eclipse.viatra.query.runtime.api.IQuerySpecification;
22import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine;
23import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
24import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification;
25import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher;
26import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch;
27import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey;
28import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey;
29import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
30import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
31import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
32import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality;
33import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
34import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall;
35import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
36import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
37import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
38import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
39import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
40import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
41import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
42
43/**
44 * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
45 *
46 * <p>Original source:
47 * <code><pre>
48 * pattern createHostInstance(HostType : HostType) {
49 * find unallocatedAppInstance(App);
50 * ApplicationInstance.type.requirements.hostType(App, HostType);
51 * }
52 * </pre></code>
53 *
54 * @see Matcher
55 * @see Match
56 *
57 */
58@SuppressWarnings("all")
59public final class CreateHostInstance extends BaseGeneratedEMFQuerySpecification<CreateHostInstance.Matcher> {
60 /**
61 * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.createHostInstance pattern,
62 * to be used in conjunction with {@link Matcher}.
63 *
64 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
65 * Each instance is a (possibly partial) substitution of pattern parameters,
66 * usable to represent a match of the pattern in the result of a query,
67 * or to specify the bound (fixed) input parameters when issuing a query.
68 *
69 * @see Matcher
70 *
71 */
72 public static abstract class Match extends BasePatternMatch {
73 private HostType fHostType;
74
75 private static List<String> parameterNames = makeImmutableList("HostType");
76
77 private Match(final HostType pHostType) {
78 this.fHostType = pHostType;
79 }
80
81 @Override
82 public Object get(final String parameterName) {
83 switch(parameterName) {
84 case "HostType": return this.fHostType;
85 default: return null;
86 }
87 }
88
89 @Override
90 public Object get(final int index) {
91 switch(index) {
92 case 0: return this.fHostType;
93 default: return null;
94 }
95 }
96
97 public HostType getHostType() {
98 return this.fHostType;
99 }
100
101 @Override
102 public boolean set(final String parameterName, final Object newValue) {
103 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
104 if ("HostType".equals(parameterName) ) {
105 this.fHostType = (HostType) newValue;
106 return true;
107 }
108 return false;
109 }
110
111 public void setHostType(final HostType pHostType) {
112 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
113 this.fHostType = pHostType;
114 }
115
116 @Override
117 public String patternName() {
118 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.createHostInstance";
119 }
120
121 @Override
122 public List<String> parameterNames() {
123 return CreateHostInstance.Match.parameterNames;
124 }
125
126 @Override
127 public Object[] toArray() {
128 return new Object[]{fHostType};
129 }
130
131 @Override
132 public CreateHostInstance.Match toImmutable() {
133 return isMutable() ? newMatch(fHostType) : this;
134 }
135
136 @Override
137 public String prettyPrint() {
138 StringBuilder result = new StringBuilder();
139 result.append("\"HostType\"=" + prettyPrintValue(fHostType));
140 return result.toString();
141 }
142
143 @Override
144 public int hashCode() {
145 return Objects.hash(fHostType);
146 }
147
148 @Override
149 public boolean equals(final Object obj) {
150 if (this == obj)
151 return true;
152 if (obj == null) {
153 return false;
154 }
155 if ((obj instanceof CreateHostInstance.Match)) {
156 CreateHostInstance.Match other = (CreateHostInstance.Match) obj;
157 return Objects.equals(fHostType, other.fHostType);
158 } else {
159 // this should be infrequent
160 if (!(obj instanceof IPatternMatch)) {
161 return false;
162 }
163 IPatternMatch otherSig = (IPatternMatch) obj;
164 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
165 }
166 }
167
168 @Override
169 public CreateHostInstance specification() {
170 return CreateHostInstance.instance();
171 }
172
173 /**
174 * Returns an empty, mutable match.
175 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
176 *
177 * @return the empty match.
178 *
179 */
180 public static CreateHostInstance.Match newEmptyMatch() {
181 return new Mutable(null);
182 }
183
184 /**
185 * Returns a mutable (partial) match.
186 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
187 *
188 * @param pHostType the fixed value of pattern parameter HostType, or null if not bound.
189 * @return the new, mutable (partial) match object.
190 *
191 */
192 public static CreateHostInstance.Match newMutableMatch(final HostType pHostType) {
193 return new Mutable(pHostType);
194 }
195
196 /**
197 * Returns a new (partial) match.
198 * This can be used e.g. to call the matcher with a partial match.
199 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
200 * @param pHostType the fixed value of pattern parameter HostType, or null if not bound.
201 * @return the (partial) match object.
202 *
203 */
204 public static CreateHostInstance.Match newMatch(final HostType pHostType) {
205 return new Immutable(pHostType);
206 }
207
208 private static final class Mutable extends CreateHostInstance.Match {
209 Mutable(final HostType pHostType) {
210 super(pHostType);
211 }
212
213 @Override
214 public boolean isMutable() {
215 return true;
216 }
217 }
218
219 private static final class Immutable extends CreateHostInstance.Match {
220 Immutable(final HostType pHostType) {
221 super(pHostType);
222 }
223
224 @Override
225 public boolean isMutable() {
226 return false;
227 }
228 }
229 }
230
231 /**
232 * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.createHostInstance pattern,
233 * providing pattern-specific query methods.
234 *
235 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
236 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
237 *
238 * <p>Matches of the pattern will be represented as {@link Match}.
239 *
240 * <p>Original source:
241 * <code><pre>
242 * pattern createHostInstance(HostType : HostType) {
243 * find unallocatedAppInstance(App);
244 * ApplicationInstance.type.requirements.hostType(App, HostType);
245 * }
246 * </pre></code>
247 *
248 * @see Match
249 * @see CreateHostInstance
250 *
251 */
252 public static class Matcher extends BaseMatcher<CreateHostInstance.Match> {
253 /**
254 * Initializes the pattern matcher within an existing VIATRA Query engine.
255 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
256 *
257 * @param engine the existing VIATRA Query engine in which this matcher will be created.
258 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
259 *
260 */
261 public static CreateHostInstance.Matcher on(final ViatraQueryEngine engine) {
262 // check if matcher already exists
263 Matcher matcher = engine.getExistingMatcher(querySpecification());
264 if (matcher == null) {
265 matcher = (Matcher)engine.getMatcher(querySpecification());
266 }
267 return matcher;
268 }
269
270 /**
271 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
272 * @return an initialized matcher
273 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
274 *
275 */
276 public static CreateHostInstance.Matcher create() {
277 return new Matcher();
278 }
279
280 private static final int POSITION_HOSTTYPE = 0;
281
282 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(CreateHostInstance.Matcher.class);
283
284 /**
285 * Initializes the pattern matcher within an existing VIATRA Query engine.
286 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
287 *
288 * @param engine the existing VIATRA Query engine in which this matcher will be created.
289 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
290 *
291 */
292 private Matcher() {
293 super(querySpecification());
294 }
295
296 /**
297 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
298 * @param pHostType the fixed value of pattern parameter HostType, or null if not bound.
299 * @return matches represented as a Match object.
300 *
301 */
302 public Collection<CreateHostInstance.Match> getAllMatches(final HostType pHostType) {
303 return rawStreamAllMatches(new Object[]{pHostType}).collect(Collectors.toSet());
304 }
305
306 /**
307 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
308 * </p>
309 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
310 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
311 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
312 * @param pHostType the fixed value of pattern parameter HostType, or null if not bound.
313 * @return a stream of matches represented as a Match object.
314 *
315 */
316 public Stream<CreateHostInstance.Match> streamAllMatches(final HostType pHostType) {
317 return rawStreamAllMatches(new Object[]{pHostType});
318 }
319
320 /**
321 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
322 * Neither determinism nor randomness of selection is guaranteed.
323 * @param pHostType the fixed value of pattern parameter HostType, or null if not bound.
324 * @return a match represented as a Match object, or null if no match is found.
325 *
326 */
327 public Optional<CreateHostInstance.Match> getOneArbitraryMatch(final HostType pHostType) {
328 return rawGetOneArbitraryMatch(new Object[]{pHostType});
329 }
330
331 /**
332 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
333 * under any possible substitution of the unspecified parameters (if any).
334 * @param pHostType the fixed value of pattern parameter HostType, or null if not bound.
335 * @return true if the input is a valid (partial) match of the pattern.
336 *
337 */
338 public boolean hasMatch(final HostType pHostType) {
339 return rawHasMatch(new Object[]{pHostType});
340 }
341
342 /**
343 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
344 * @param pHostType the fixed value of pattern parameter HostType, or null if not bound.
345 * @return the number of pattern matches found.
346 *
347 */
348 public int countMatches(final HostType pHostType) {
349 return rawCountMatches(new Object[]{pHostType});
350 }
351
352 /**
353 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
354 * Neither determinism nor randomness of selection is guaranteed.
355 * @param pHostType the fixed value of pattern parameter HostType, or null if not bound.
356 * @param processor the action that will process the selected match.
357 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
358 *
359 */
360 public boolean forOneArbitraryMatch(final HostType pHostType, final Consumer<? super CreateHostInstance.Match> processor) {
361 return rawForOneArbitraryMatch(new Object[]{pHostType}, processor);
362 }
363
364 /**
365 * Returns a new (partial) match.
366 * This can be used e.g. to call the matcher with a partial match.
367 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
368 * @param pHostType the fixed value of pattern parameter HostType, or null if not bound.
369 * @return the (partial) match object.
370 *
371 */
372 public CreateHostInstance.Match newMatch(final HostType pHostType) {
373 return CreateHostInstance.Match.newMatch(pHostType);
374 }
375
376 /**
377 * Retrieve the set of values that occur in matches for HostType.
378 * @return the Set of all values or empty set if there are no matches
379 *
380 */
381 protected Stream<HostType> rawStreamAllValuesOfHostType(final Object[] parameters) {
382 return rawStreamAllValues(POSITION_HOSTTYPE, parameters).map(HostType.class::cast);
383 }
384
385 /**
386 * Retrieve the set of values that occur in matches for HostType.
387 * @return the Set of all values or empty set if there are no matches
388 *
389 */
390 public Set<HostType> getAllValuesOfHostType() {
391 return rawStreamAllValuesOfHostType(emptyArray()).collect(Collectors.toSet());
392 }
393
394 /**
395 * Retrieve the set of values that occur in matches for HostType.
396 * @return the Set of all values or empty set if there are no matches
397 *
398 */
399 public Stream<HostType> streamAllValuesOfHostType() {
400 return rawStreamAllValuesOfHostType(emptyArray());
401 }
402
403 @Override
404 protected CreateHostInstance.Match tupleToMatch(final Tuple t) {
405 try {
406 return CreateHostInstance.Match.newMatch((HostType) t.get(POSITION_HOSTTYPE));
407 } catch(ClassCastException e) {
408 LOGGER.error("Element(s) in tuple not properly typed!",e);
409 return null;
410 }
411 }
412
413 @Override
414 protected CreateHostInstance.Match arrayToMatch(final Object[] match) {
415 try {
416 return CreateHostInstance.Match.newMatch((HostType) match[POSITION_HOSTTYPE]);
417 } catch(ClassCastException e) {
418 LOGGER.error("Element(s) in array not properly typed!",e);
419 return null;
420 }
421 }
422
423 @Override
424 protected CreateHostInstance.Match arrayToMatchMutable(final Object[] match) {
425 try {
426 return CreateHostInstance.Match.newMutableMatch((HostType) match[POSITION_HOSTTYPE]);
427 } catch(ClassCastException e) {
428 LOGGER.error("Element(s) in array not properly typed!",e);
429 return null;
430 }
431 }
432
433 /**
434 * @return the singleton instance of the query specification of this pattern
435 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
436 *
437 */
438 public static IQuerySpecification<CreateHostInstance.Matcher> querySpecification() {
439 return CreateHostInstance.instance();
440 }
441 }
442
443 private CreateHostInstance() {
444 super(GeneratedPQuery.INSTANCE);
445 }
446
447 /**
448 * @return the singleton instance of the query specification
449 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
450 *
451 */
452 public static CreateHostInstance instance() {
453 try{
454 return LazyHolder.INSTANCE;
455 } catch (ExceptionInInitializerError err) {
456 throw processInitializerError(err);
457 }
458 }
459
460 @Override
461 protected CreateHostInstance.Matcher instantiate(final ViatraQueryEngine engine) {
462 return CreateHostInstance.Matcher.on(engine);
463 }
464
465 @Override
466 public CreateHostInstance.Matcher instantiate() {
467 return CreateHostInstance.Matcher.create();
468 }
469
470 @Override
471 public CreateHostInstance.Match newEmptyMatch() {
472 return CreateHostInstance.Match.newEmptyMatch();
473 }
474
475 @Override
476 public CreateHostInstance.Match newMatch(final Object... parameters) {
477 return CreateHostInstance.Match.newMatch((hu.bme.mit.inf.dslreasoner.domains.cps.HostType) parameters[0]);
478 }
479
480 /**
481 * Inner class allowing the singleton instance of {@link CreateHostInstance} to be created
482 * <b>not</b> at the class load time of the outer class,
483 * but rather at the first call to {@link CreateHostInstance#instance()}.
484 *
485 * <p> This workaround is required e.g. to support recursion.
486 *
487 */
488 private static class LazyHolder {
489 private static final CreateHostInstance INSTANCE = new CreateHostInstance();
490
491 /**
492 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
493 * This initialization order is required to support indirect recursion.
494 *
495 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
496 *
497 */
498 private static final Object STATIC_INITIALIZER = ensureInitialized();
499
500 public static Object ensureInitialized() {
501 INSTANCE.ensureInitializedInternal();
502 return null;
503 }
504 }
505
506 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
507 private static final CreateHostInstance.GeneratedPQuery INSTANCE = new GeneratedPQuery();
508
509 private final PParameter parameter_HostType = new PParameter("HostType", "hu.bme.mit.inf.dslreasoner.domains.cps.HostType", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "HostType")), PParameterDirection.INOUT);
510
511 private final List<PParameter> parameters = Arrays.asList(parameter_HostType);
512
513 private GeneratedPQuery() {
514 super(PVisibility.PUBLIC);
515 }
516
517 @Override
518 public String getFullyQualifiedName() {
519 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.createHostInstance";
520 }
521
522 @Override
523 public List<String> getParameterNames() {
524 return Arrays.asList("HostType");
525 }
526
527 @Override
528 public List<PParameter> getParameters() {
529 return parameters;
530 }
531
532 @Override
533 public Set<PBody> doGetContainedBodies() {
534 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
535 Set<PBody> bodies = new LinkedHashSet<>();
536 {
537 PBody body = new PBody(this);
538 PVariable var_HostType = body.getOrCreateVariableByName("HostType");
539 PVariable var_App = body.getOrCreateVariableByName("App");
540 new TypeConstraint(body, Tuples.flatTupleOf(var_HostType), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostType")));
541 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
542 new ExportedParameter(body, var_HostType, parameter_HostType)
543 ));
544 // find unallocatedAppInstance(App)
545 new PositivePatternCall(body, Tuples.flatTupleOf(var_App), UnallocatedAppInstance.instance().getInternalQueryRepresentation());
546 // ApplicationInstance.type.requirements.hostType(App, HostType)
547 new TypeConstraint(body, Tuples.flatTupleOf(var_App), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance")));
548 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
549 new TypeConstraint(body, Tuples.flatTupleOf(var_App, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ApplicationInstance", "type")));
550 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationType")));
551 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
552 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ApplicationType", "requirements")));
553 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ResourceRequirement")));
554 PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}");
555 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_, var__virtual_2_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ResourceRequirement", "hostType")));
556 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostType")));
557 new Equality(body, var__virtual_2_, var_HostType);
558 bodies.add(body);
559 }
560 return bodies;
561 }
562 }
563}
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/GuidanceObjective.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/GuidanceObjective.java
new file mode 100644
index 00000000..1ed6c9cc
--- /dev/null
+++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/GuidanceObjective.java
@@ -0,0 +1,601 @@
1/**
2 * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql
3 */
4package hu.bme.mit.inf.dslreasoner.domains.cps.queries;
5
6import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.NoHostToAllocateTo;
7import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.RequiredAppInstances;
8import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.UnallocatedAppInstance;
9import java.util.Arrays;
10import java.util.Collection;
11import java.util.LinkedHashSet;
12import java.util.List;
13import java.util.Objects;
14import java.util.Optional;
15import java.util.Set;
16import java.util.function.Consumer;
17import java.util.stream.Collectors;
18import java.util.stream.Stream;
19import org.apache.log4j.Logger;
20import org.eclipse.viatra.query.runtime.api.IPatternMatch;
21import org.eclipse.viatra.query.runtime.api.IQuerySpecification;
22import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine;
23import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
24import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification;
25import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher;
26import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch;
27import org.eclipse.viatra.query.runtime.matchers.aggregators.sum;
28import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
29import org.eclipse.viatra.query.runtime.matchers.context.common.JavaTransitiveInstancesKey;
30import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator;
31import org.eclipse.viatra.query.runtime.matchers.psystem.IValueProvider;
32import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
33import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
34import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.AggregatorConstraint;
35import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality;
36import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
37import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation;
38import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.PatternMatchCounter;
39import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.TypeFilterConstraint;
40import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
41import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
42import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
43import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
44import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
45import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
46
47/**
48 * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
49 *
50 * <p>Original source:
51 * <code><pre>
52 * pattern guidanceObjective(Value : java Integer) {
53 * UnallocatedInstances == count find unallocatedAppInstance(_);
54 * RequiredInstances == sum find requiredAppInstances(_, #_);
55 * NoHostToAllocate == count find noHostToAllocateTo(_);
56 * Value == eval(2 UnallocatedInstances + 4 RequiredInstances + NoHostToAllocate);
57 * }
58 * </pre></code>
59 *
60 * @see Matcher
61 * @see Match
62 *
63 */
64@SuppressWarnings("all")
65public final class GuidanceObjective extends BaseGeneratedEMFQuerySpecification<GuidanceObjective.Matcher> {
66 /**
67 * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.guidanceObjective pattern,
68 * to be used in conjunction with {@link Matcher}.
69 *
70 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
71 * Each instance is a (possibly partial) substitution of pattern parameters,
72 * usable to represent a match of the pattern in the result of a query,
73 * or to specify the bound (fixed) input parameters when issuing a query.
74 *
75 * @see Matcher
76 *
77 */
78 public static abstract class Match extends BasePatternMatch {
79 private Integer fValue;
80
81 private static List<String> parameterNames = makeImmutableList("Value");
82
83 private Match(final Integer pValue) {
84 this.fValue = pValue;
85 }
86
87 @Override
88 public Object get(final String parameterName) {
89 switch(parameterName) {
90 case "Value": return this.fValue;
91 default: return null;
92 }
93 }
94
95 @Override
96 public Object get(final int index) {
97 switch(index) {
98 case 0: return this.fValue;
99 default: return null;
100 }
101 }
102
103 public Integer getValue() {
104 return this.fValue;
105 }
106
107 @Override
108 public boolean set(final String parameterName, final Object newValue) {
109 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
110 if ("Value".equals(parameterName) ) {
111 this.fValue = (Integer) newValue;
112 return true;
113 }
114 return false;
115 }
116
117 public void setValue(final Integer pValue) {
118 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
119 this.fValue = pValue;
120 }
121
122 @Override
123 public String patternName() {
124 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.guidanceObjective";
125 }
126
127 @Override
128 public List<String> parameterNames() {
129 return GuidanceObjective.Match.parameterNames;
130 }
131
132 @Override
133 public Object[] toArray() {
134 return new Object[]{fValue};
135 }
136
137 @Override
138 public GuidanceObjective.Match toImmutable() {
139 return isMutable() ? newMatch(fValue) : this;
140 }
141
142 @Override
143 public String prettyPrint() {
144 StringBuilder result = new StringBuilder();
145 result.append("\"Value\"=" + prettyPrintValue(fValue));
146 return result.toString();
147 }
148
149 @Override
150 public int hashCode() {
151 return Objects.hash(fValue);
152 }
153
154 @Override
155 public boolean equals(final Object obj) {
156 if (this == obj)
157 return true;
158 if (obj == null) {
159 return false;
160 }
161 if ((obj instanceof GuidanceObjective.Match)) {
162 GuidanceObjective.Match other = (GuidanceObjective.Match) obj;
163 return Objects.equals(fValue, other.fValue);
164 } else {
165 // this should be infrequent
166 if (!(obj instanceof IPatternMatch)) {
167 return false;
168 }
169 IPatternMatch otherSig = (IPatternMatch) obj;
170 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
171 }
172 }
173
174 @Override
175 public GuidanceObjective specification() {
176 return GuidanceObjective.instance();
177 }
178
179 /**
180 * Returns an empty, mutable match.
181 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
182 *
183 * @return the empty match.
184 *
185 */
186 public static GuidanceObjective.Match newEmptyMatch() {
187 return new Mutable(null);
188 }
189
190 /**
191 * Returns a mutable (partial) match.
192 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
193 *
194 * @param pValue the fixed value of pattern parameter Value, or null if not bound.
195 * @return the new, mutable (partial) match object.
196 *
197 */
198 public static GuidanceObjective.Match newMutableMatch(final Integer pValue) {
199 return new Mutable(pValue);
200 }
201
202 /**
203 * Returns a new (partial) match.
204 * This can be used e.g. to call the matcher with a partial match.
205 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
206 * @param pValue the fixed value of pattern parameter Value, or null if not bound.
207 * @return the (partial) match object.
208 *
209 */
210 public static GuidanceObjective.Match newMatch(final Integer pValue) {
211 return new Immutable(pValue);
212 }
213
214 private static final class Mutable extends GuidanceObjective.Match {
215 Mutable(final Integer pValue) {
216 super(pValue);
217 }
218
219 @Override
220 public boolean isMutable() {
221 return true;
222 }
223 }
224
225 private static final class Immutable extends GuidanceObjective.Match {
226 Immutable(final Integer pValue) {
227 super(pValue);
228 }
229
230 @Override
231 public boolean isMutable() {
232 return false;
233 }
234 }
235 }
236
237 /**
238 * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.guidanceObjective pattern,
239 * providing pattern-specific query methods.
240 *
241 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
242 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
243 *
244 * <p>Matches of the pattern will be represented as {@link Match}.
245 *
246 * <p>Original source:
247 * <code><pre>
248 * pattern guidanceObjective(Value : java Integer) {
249 * UnallocatedInstances == count find unallocatedAppInstance(_);
250 * RequiredInstances == sum find requiredAppInstances(_, #_);
251 * NoHostToAllocate == count find noHostToAllocateTo(_);
252 * Value == eval(2 UnallocatedInstances + 4 RequiredInstances + NoHostToAllocate);
253 * }
254 * </pre></code>
255 *
256 * @see Match
257 * @see GuidanceObjective
258 *
259 */
260 public static class Matcher extends BaseMatcher<GuidanceObjective.Match> {
261 /**
262 * Initializes the pattern matcher within an existing VIATRA Query engine.
263 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
264 *
265 * @param engine the existing VIATRA Query engine in which this matcher will be created.
266 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
267 *
268 */
269 public static GuidanceObjective.Matcher on(final ViatraQueryEngine engine) {
270 // check if matcher already exists
271 Matcher matcher = engine.getExistingMatcher(querySpecification());
272 if (matcher == null) {
273 matcher = (Matcher)engine.getMatcher(querySpecification());
274 }
275 return matcher;
276 }
277
278 /**
279 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
280 * @return an initialized matcher
281 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
282 *
283 */
284 public static GuidanceObjective.Matcher create() {
285 return new Matcher();
286 }
287
288 private static final int POSITION_VALUE = 0;
289
290 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(GuidanceObjective.Matcher.class);
291
292 /**
293 * Initializes the pattern matcher within an existing VIATRA Query engine.
294 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
295 *
296 * @param engine the existing VIATRA Query engine in which this matcher will be created.
297 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
298 *
299 */
300 private Matcher() {
301 super(querySpecification());
302 }
303
304 /**
305 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
306 * @param pValue the fixed value of pattern parameter Value, or null if not bound.
307 * @return matches represented as a Match object.
308 *
309 */
310 public Collection<GuidanceObjective.Match> getAllMatches(final Integer pValue) {
311 return rawStreamAllMatches(new Object[]{pValue}).collect(Collectors.toSet());
312 }
313
314 /**
315 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
316 * </p>
317 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
318 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
319 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
320 * @param pValue the fixed value of pattern parameter Value, or null if not bound.
321 * @return a stream of matches represented as a Match object.
322 *
323 */
324 public Stream<GuidanceObjective.Match> streamAllMatches(final Integer pValue) {
325 return rawStreamAllMatches(new Object[]{pValue});
326 }
327
328 /**
329 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
330 * Neither determinism nor randomness of selection is guaranteed.
331 * @param pValue the fixed value of pattern parameter Value, or null if not bound.
332 * @return a match represented as a Match object, or null if no match is found.
333 *
334 */
335 public Optional<GuidanceObjective.Match> getOneArbitraryMatch(final Integer pValue) {
336 return rawGetOneArbitraryMatch(new Object[]{pValue});
337 }
338
339 /**
340 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
341 * under any possible substitution of the unspecified parameters (if any).
342 * @param pValue the fixed value of pattern parameter Value, or null if not bound.
343 * @return true if the input is a valid (partial) match of the pattern.
344 *
345 */
346 public boolean hasMatch(final Integer pValue) {
347 return rawHasMatch(new Object[]{pValue});
348 }
349
350 /**
351 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
352 * @param pValue the fixed value of pattern parameter Value, or null if not bound.
353 * @return the number of pattern matches found.
354 *
355 */
356 public int countMatches(final Integer pValue) {
357 return rawCountMatches(new Object[]{pValue});
358 }
359
360 /**
361 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
362 * Neither determinism nor randomness of selection is guaranteed.
363 * @param pValue the fixed value of pattern parameter Value, or null if not bound.
364 * @param processor the action that will process the selected match.
365 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
366 *
367 */
368 public boolean forOneArbitraryMatch(final Integer pValue, final Consumer<? super GuidanceObjective.Match> processor) {
369 return rawForOneArbitraryMatch(new Object[]{pValue}, processor);
370 }
371
372 /**
373 * Returns a new (partial) match.
374 * This can be used e.g. to call the matcher with a partial match.
375 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
376 * @param pValue the fixed value of pattern parameter Value, or null if not bound.
377 * @return the (partial) match object.
378 *
379 */
380 public GuidanceObjective.Match newMatch(final Integer pValue) {
381 return GuidanceObjective.Match.newMatch(pValue);
382 }
383
384 /**
385 * Retrieve the set of values that occur in matches for Value.
386 * @return the Set of all values or empty set if there are no matches
387 *
388 */
389 protected Stream<Integer> rawStreamAllValuesOfValue(final Object[] parameters) {
390 return rawStreamAllValues(POSITION_VALUE, parameters).map(Integer.class::cast);
391 }
392
393 /**
394 * Retrieve the set of values that occur in matches for Value.
395 * @return the Set of all values or empty set if there are no matches
396 *
397 */
398 public Set<Integer> getAllValuesOfValue() {
399 return rawStreamAllValuesOfValue(emptyArray()).collect(Collectors.toSet());
400 }
401
402 /**
403 * Retrieve the set of values that occur in matches for Value.
404 * @return the Set of all values or empty set if there are no matches
405 *
406 */
407 public Stream<Integer> streamAllValuesOfValue() {
408 return rawStreamAllValuesOfValue(emptyArray());
409 }
410
411 @Override
412 protected GuidanceObjective.Match tupleToMatch(final Tuple t) {
413 try {
414 return GuidanceObjective.Match.newMatch((Integer) t.get(POSITION_VALUE));
415 } catch(ClassCastException e) {
416 LOGGER.error("Element(s) in tuple not properly typed!",e);
417 return null;
418 }
419 }
420
421 @Override
422 protected GuidanceObjective.Match arrayToMatch(final Object[] match) {
423 try {
424 return GuidanceObjective.Match.newMatch((Integer) match[POSITION_VALUE]);
425 } catch(ClassCastException e) {
426 LOGGER.error("Element(s) in array not properly typed!",e);
427 return null;
428 }
429 }
430
431 @Override
432 protected GuidanceObjective.Match arrayToMatchMutable(final Object[] match) {
433 try {
434 return GuidanceObjective.Match.newMutableMatch((Integer) match[POSITION_VALUE]);
435 } catch(ClassCastException e) {
436 LOGGER.error("Element(s) in array not properly typed!",e);
437 return null;
438 }
439 }
440
441 /**
442 * @return the singleton instance of the query specification of this pattern
443 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
444 *
445 */
446 public static IQuerySpecification<GuidanceObjective.Matcher> querySpecification() {
447 return GuidanceObjective.instance();
448 }
449 }
450
451 private GuidanceObjective() {
452 super(GeneratedPQuery.INSTANCE);
453 }
454
455 /**
456 * @return the singleton instance of the query specification
457 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
458 *
459 */
460 public static GuidanceObjective instance() {
461 try{
462 return LazyHolder.INSTANCE;
463 } catch (ExceptionInInitializerError err) {
464 throw processInitializerError(err);
465 }
466 }
467
468 @Override
469 protected GuidanceObjective.Matcher instantiate(final ViatraQueryEngine engine) {
470 return GuidanceObjective.Matcher.on(engine);
471 }
472
473 @Override
474 public GuidanceObjective.Matcher instantiate() {
475 return GuidanceObjective.Matcher.create();
476 }
477
478 @Override
479 public GuidanceObjective.Match newEmptyMatch() {
480 return GuidanceObjective.Match.newEmptyMatch();
481 }
482
483 @Override
484 public GuidanceObjective.Match newMatch(final Object... parameters) {
485 return GuidanceObjective.Match.newMatch((java.lang.Integer) parameters[0]);
486 }
487
488 /**
489 * Inner class allowing the singleton instance of {@link GuidanceObjective} to be created
490 * <b>not</b> at the class load time of the outer class,
491 * but rather at the first call to {@link GuidanceObjective#instance()}.
492 *
493 * <p> This workaround is required e.g. to support recursion.
494 *
495 */
496 private static class LazyHolder {
497 private static final GuidanceObjective INSTANCE = new GuidanceObjective();
498
499 /**
500 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
501 * This initialization order is required to support indirect recursion.
502 *
503 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
504 *
505 */
506 private static final Object STATIC_INITIALIZER = ensureInitialized();
507
508 public static Object ensureInitialized() {
509 INSTANCE.ensureInitializedInternal();
510 return null;
511 }
512 }
513
514 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
515 private static final GuidanceObjective.GeneratedPQuery INSTANCE = new GeneratedPQuery();
516
517 private final PParameter parameter_Value = new PParameter("Value", "java.lang.Integer", new JavaTransitiveInstancesKey(java.lang.Integer.class), PParameterDirection.INOUT);
518
519 private final List<PParameter> parameters = Arrays.asList(parameter_Value);
520
521 private GeneratedPQuery() {
522 super(PVisibility.PUBLIC);
523 }
524
525 @Override
526 public String getFullyQualifiedName() {
527 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.guidanceObjective";
528 }
529
530 @Override
531 public List<String> getParameterNames() {
532 return Arrays.asList("Value");
533 }
534
535 @Override
536 public List<PParameter> getParameters() {
537 return parameters;
538 }
539
540 @Override
541 public Set<PBody> doGetContainedBodies() {
542 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
543 Set<PBody> bodies = new LinkedHashSet<>();
544 {
545 PBody body = new PBody(this);
546 PVariable var_Value = body.getOrCreateVariableByName("Value");
547 PVariable var_UnallocatedInstances = body.getOrCreateVariableByName("UnallocatedInstances");
548 PVariable var___0_ = body.getOrCreateVariableByName("_<0>");
549 PVariable var_RequiredInstances = body.getOrCreateVariableByName("RequiredInstances");
550 PVariable var___1_ = body.getOrCreateVariableByName("_<1>");
551 PVariable var___2_ = body.getOrCreateVariableByName("_<2>");
552 PVariable var_NoHostToAllocate = body.getOrCreateVariableByName("NoHostToAllocate");
553 PVariable var___3_ = body.getOrCreateVariableByName("_<3>");
554 new TypeFilterConstraint(body, Tuples.flatTupleOf(var_Value), new JavaTransitiveInstancesKey(java.lang.Integer.class));
555 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
556 new ExportedParameter(body, var_Value, parameter_Value)
557 ));
558 // UnallocatedInstances == count find unallocatedAppInstance(_)
559 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
560 new PatternMatchCounter(body, Tuples.flatTupleOf(var___0_), UnallocatedAppInstance.instance().getInternalQueryRepresentation(), var__virtual_0_);
561 new Equality(body, var_UnallocatedInstances, var__virtual_0_);
562 // RequiredInstances == sum find requiredAppInstances(_, #_)
563 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
564 new AggregatorConstraint(new sum().getAggregatorLogic(Integer.class), body, Tuples.flatTupleOf(var___1_, var___2_), RequiredAppInstances.instance().getInternalQueryRepresentation(), var__virtual_1_, 1);
565 new Equality(body, var_RequiredInstances, var__virtual_1_);
566 // NoHostToAllocate == count find noHostToAllocateTo(_)
567 PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}");
568 new PatternMatchCounter(body, Tuples.flatTupleOf(var___3_), NoHostToAllocateTo.instance().getInternalQueryRepresentation(), var__virtual_2_);
569 new Equality(body, var_NoHostToAllocate, var__virtual_2_);
570 // Value == eval(2 * UnallocatedInstances + 4 * RequiredInstances + NoHostToAllocate)
571 PVariable var__virtual_3_ = body.getOrCreateVariableByName(".virtual{3}");
572 new ExpressionEvaluation(body, new IExpressionEvaluator() {
573
574 @Override
575 public String getShortDescription() {
576 return "Expression evaluation from pattern guidanceObjective";
577 }
578
579 @Override
580 public Iterable<String> getInputParameterNames() {
581 return Arrays.asList("NoHostToAllocate", "RequiredInstances", "UnallocatedInstances");}
582
583 @Override
584 public Object evaluateExpression(IValueProvider provider) throws Exception {
585 Integer NoHostToAllocate = (Integer) provider.getValue("NoHostToAllocate");
586 Integer RequiredInstances = (Integer) provider.getValue("RequiredInstances");
587 Integer UnallocatedInstances = (Integer) provider.getValue("UnallocatedInstances");
588 return evaluateExpression_1_1(NoHostToAllocate, RequiredInstances, UnallocatedInstances);
589 }
590 }, var__virtual_3_ );
591 new Equality(body, var_Value, var__virtual_3_);
592 bodies.add(body);
593 }
594 return bodies;
595 }
596 }
597
598 private static int evaluateExpression_1_1(final Integer NoHostToAllocate, final Integer RequiredInstances, final Integer UnallocatedInstances) {
599 return (((2 * (UnallocatedInstances).intValue()) + (4 * (RequiredInstances).intValue())) + (NoHostToAllocate).intValue());
600 }
601}
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/InstanceDoesNotSatisfyRequirement.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/InstanceDoesNotSatisfyRequirement.java
new file mode 100644
index 00000000..932501ff
--- /dev/null
+++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/InstanceDoesNotSatisfyRequirement.java
@@ -0,0 +1,727 @@
1/**
2 * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql
3 */
4package hu.bme.mit.inf.dslreasoner.domains.cps.queries;
5
6import hu.bme.mit.inf.dslreasoner.domains.cps.ApplicationInstance;
7import hu.bme.mit.inf.dslreasoner.domains.cps.Requirement;
8import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.SatisfyingInstance;
9import java.util.Arrays;
10import java.util.Collection;
11import java.util.LinkedHashSet;
12import java.util.List;
13import java.util.Objects;
14import java.util.Optional;
15import java.util.Set;
16import java.util.function.Consumer;
17import java.util.stream.Collectors;
18import java.util.stream.Stream;
19import org.apache.log4j.Logger;
20import org.eclipse.emf.ecore.EClass;
21import org.eclipse.viatra.query.runtime.api.IPatternMatch;
22import org.eclipse.viatra.query.runtime.api.IQuerySpecification;
23import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine;
24import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
25import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification;
26import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher;
27import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch;
28import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey;
29import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey;
30import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
31import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
32import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
33import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation;
34import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference;
35import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality;
36import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
37import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.NegativePatternCall;
38import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
39import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
40import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
41import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
42import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
43import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
44import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
45
46/**
47 * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
48 *
49 * <p>Original source:
50 * <code><pre>
51 * {@literal @}Constraint(severity = "error", key = {Req, App},
52 * message = "Requirement must be satisfied by the required application type.")
53 * pattern instanceDoesNotSatisfyRequirement(Req : Requirement, App : ApplicationInstance) {
54 * Requirement.instances(Req, App);
55 * neg find satisfyingInstance(Req, App);
56 * }
57 * </pre></code>
58 *
59 * @see Matcher
60 * @see Match
61 *
62 */
63@SuppressWarnings("all")
64public final class InstanceDoesNotSatisfyRequirement extends BaseGeneratedEMFQuerySpecification<InstanceDoesNotSatisfyRequirement.Matcher> {
65 /**
66 * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.instanceDoesNotSatisfyRequirement pattern,
67 * to be used in conjunction with {@link Matcher}.
68 *
69 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
70 * Each instance is a (possibly partial) substitution of pattern parameters,
71 * usable to represent a match of the pattern in the result of a query,
72 * or to specify the bound (fixed) input parameters when issuing a query.
73 *
74 * @see Matcher
75 *
76 */
77 public static abstract class Match extends BasePatternMatch {
78 private Requirement fReq;
79
80 private ApplicationInstance fApp;
81
82 private static List<String> parameterNames = makeImmutableList("Req", "App");
83
84 private Match(final Requirement pReq, final ApplicationInstance pApp) {
85 this.fReq = pReq;
86 this.fApp = pApp;
87 }
88
89 @Override
90 public Object get(final String parameterName) {
91 switch(parameterName) {
92 case "Req": return this.fReq;
93 case "App": return this.fApp;
94 default: return null;
95 }
96 }
97
98 @Override
99 public Object get(final int index) {
100 switch(index) {
101 case 0: return this.fReq;
102 case 1: return this.fApp;
103 default: return null;
104 }
105 }
106
107 public Requirement getReq() {
108 return this.fReq;
109 }
110
111 public ApplicationInstance getApp() {
112 return this.fApp;
113 }
114
115 @Override
116 public boolean set(final String parameterName, final Object newValue) {
117 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
118 if ("Req".equals(parameterName) ) {
119 this.fReq = (Requirement) newValue;
120 return true;
121 }
122 if ("App".equals(parameterName) ) {
123 this.fApp = (ApplicationInstance) newValue;
124 return true;
125 }
126 return false;
127 }
128
129 public void setReq(final Requirement pReq) {
130 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
131 this.fReq = pReq;
132 }
133
134 public void setApp(final ApplicationInstance pApp) {
135 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
136 this.fApp = pApp;
137 }
138
139 @Override
140 public String patternName() {
141 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.instanceDoesNotSatisfyRequirement";
142 }
143
144 @Override
145 public List<String> parameterNames() {
146 return InstanceDoesNotSatisfyRequirement.Match.parameterNames;
147 }
148
149 @Override
150 public Object[] toArray() {
151 return new Object[]{fReq, fApp};
152 }
153
154 @Override
155 public InstanceDoesNotSatisfyRequirement.Match toImmutable() {
156 return isMutable() ? newMatch(fReq, fApp) : this;
157 }
158
159 @Override
160 public String prettyPrint() {
161 StringBuilder result = new StringBuilder();
162 result.append("\"Req\"=" + prettyPrintValue(fReq) + ", ");
163 result.append("\"App\"=" + prettyPrintValue(fApp));
164 return result.toString();
165 }
166
167 @Override
168 public int hashCode() {
169 return Objects.hash(fReq, fApp);
170 }
171
172 @Override
173 public boolean equals(final Object obj) {
174 if (this == obj)
175 return true;
176 if (obj == null) {
177 return false;
178 }
179 if ((obj instanceof InstanceDoesNotSatisfyRequirement.Match)) {
180 InstanceDoesNotSatisfyRequirement.Match other = (InstanceDoesNotSatisfyRequirement.Match) obj;
181 return Objects.equals(fReq, other.fReq) && Objects.equals(fApp, other.fApp);
182 } else {
183 // this should be infrequent
184 if (!(obj instanceof IPatternMatch)) {
185 return false;
186 }
187 IPatternMatch otherSig = (IPatternMatch) obj;
188 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
189 }
190 }
191
192 @Override
193 public InstanceDoesNotSatisfyRequirement specification() {
194 return InstanceDoesNotSatisfyRequirement.instance();
195 }
196
197 /**
198 * Returns an empty, mutable match.
199 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
200 *
201 * @return the empty match.
202 *
203 */
204 public static InstanceDoesNotSatisfyRequirement.Match newEmptyMatch() {
205 return new Mutable(null, null);
206 }
207
208 /**
209 * Returns a mutable (partial) match.
210 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
211 *
212 * @param pReq the fixed value of pattern parameter Req, or null if not bound.
213 * @param pApp the fixed value of pattern parameter App, or null if not bound.
214 * @return the new, mutable (partial) match object.
215 *
216 */
217 public static InstanceDoesNotSatisfyRequirement.Match newMutableMatch(final Requirement pReq, final ApplicationInstance pApp) {
218 return new Mutable(pReq, pApp);
219 }
220
221 /**
222 * Returns a new (partial) match.
223 * This can be used e.g. to call the matcher with a partial match.
224 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
225 * @param pReq the fixed value of pattern parameter Req, or null if not bound.
226 * @param pApp the fixed value of pattern parameter App, or null if not bound.
227 * @return the (partial) match object.
228 *
229 */
230 public static InstanceDoesNotSatisfyRequirement.Match newMatch(final Requirement pReq, final ApplicationInstance pApp) {
231 return new Immutable(pReq, pApp);
232 }
233
234 private static final class Mutable extends InstanceDoesNotSatisfyRequirement.Match {
235 Mutable(final Requirement pReq, final ApplicationInstance pApp) {
236 super(pReq, pApp);
237 }
238
239 @Override
240 public boolean isMutable() {
241 return true;
242 }
243 }
244
245 private static final class Immutable extends InstanceDoesNotSatisfyRequirement.Match {
246 Immutable(final Requirement pReq, final ApplicationInstance pApp) {
247 super(pReq, pApp);
248 }
249
250 @Override
251 public boolean isMutable() {
252 return false;
253 }
254 }
255 }
256
257 /**
258 * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.instanceDoesNotSatisfyRequirement pattern,
259 * providing pattern-specific query methods.
260 *
261 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
262 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
263 *
264 * <p>Matches of the pattern will be represented as {@link Match}.
265 *
266 * <p>Original source:
267 * <code><pre>
268 * {@literal @}Constraint(severity = "error", key = {Req, App},
269 * message = "Requirement must be satisfied by the required application type.")
270 * pattern instanceDoesNotSatisfyRequirement(Req : Requirement, App : ApplicationInstance) {
271 * Requirement.instances(Req, App);
272 * neg find satisfyingInstance(Req, App);
273 * }
274 * </pre></code>
275 *
276 * @see Match
277 * @see InstanceDoesNotSatisfyRequirement
278 *
279 */
280 public static class Matcher extends BaseMatcher<InstanceDoesNotSatisfyRequirement.Match> {
281 /**
282 * Initializes the pattern matcher within an existing VIATRA Query engine.
283 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
284 *
285 * @param engine the existing VIATRA Query engine in which this matcher will be created.
286 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
287 *
288 */
289 public static InstanceDoesNotSatisfyRequirement.Matcher on(final ViatraQueryEngine engine) {
290 // check if matcher already exists
291 Matcher matcher = engine.getExistingMatcher(querySpecification());
292 if (matcher == null) {
293 matcher = (Matcher)engine.getMatcher(querySpecification());
294 }
295 return matcher;
296 }
297
298 /**
299 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
300 * @return an initialized matcher
301 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
302 *
303 */
304 public static InstanceDoesNotSatisfyRequirement.Matcher create() {
305 return new Matcher();
306 }
307
308 private static final int POSITION_REQ = 0;
309
310 private static final int POSITION_APP = 1;
311
312 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(InstanceDoesNotSatisfyRequirement.Matcher.class);
313
314 /**
315 * Initializes the pattern matcher within an existing VIATRA Query engine.
316 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
317 *
318 * @param engine the existing VIATRA Query engine in which this matcher will be created.
319 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
320 *
321 */
322 private Matcher() {
323 super(querySpecification());
324 }
325
326 /**
327 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
328 * @param pReq the fixed value of pattern parameter Req, or null if not bound.
329 * @param pApp the fixed value of pattern parameter App, or null if not bound.
330 * @return matches represented as a Match object.
331 *
332 */
333 public Collection<InstanceDoesNotSatisfyRequirement.Match> getAllMatches(final Requirement pReq, final ApplicationInstance pApp) {
334 return rawStreamAllMatches(new Object[]{pReq, pApp}).collect(Collectors.toSet());
335 }
336
337 /**
338 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
339 * </p>
340 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
341 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
342 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
343 * @param pReq the fixed value of pattern parameter Req, or null if not bound.
344 * @param pApp the fixed value of pattern parameter App, or null if not bound.
345 * @return a stream of matches represented as a Match object.
346 *
347 */
348 public Stream<InstanceDoesNotSatisfyRequirement.Match> streamAllMatches(final Requirement pReq, final ApplicationInstance pApp) {
349 return rawStreamAllMatches(new Object[]{pReq, pApp});
350 }
351
352 /**
353 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
354 * Neither determinism nor randomness of selection is guaranteed.
355 * @param pReq the fixed value of pattern parameter Req, or null if not bound.
356 * @param pApp the fixed value of pattern parameter App, or null if not bound.
357 * @return a match represented as a Match object, or null if no match is found.
358 *
359 */
360 public Optional<InstanceDoesNotSatisfyRequirement.Match> getOneArbitraryMatch(final Requirement pReq, final ApplicationInstance pApp) {
361 return rawGetOneArbitraryMatch(new Object[]{pReq, pApp});
362 }
363
364 /**
365 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
366 * under any possible substitution of the unspecified parameters (if any).
367 * @param pReq the fixed value of pattern parameter Req, or null if not bound.
368 * @param pApp the fixed value of pattern parameter App, or null if not bound.
369 * @return true if the input is a valid (partial) match of the pattern.
370 *
371 */
372 public boolean hasMatch(final Requirement pReq, final ApplicationInstance pApp) {
373 return rawHasMatch(new Object[]{pReq, pApp});
374 }
375
376 /**
377 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
378 * @param pReq the fixed value of pattern parameter Req, or null if not bound.
379 * @param pApp the fixed value of pattern parameter App, or null if not bound.
380 * @return the number of pattern matches found.
381 *
382 */
383 public int countMatches(final Requirement pReq, final ApplicationInstance pApp) {
384 return rawCountMatches(new Object[]{pReq, pApp});
385 }
386
387 /**
388 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
389 * Neither determinism nor randomness of selection is guaranteed.
390 * @param pReq the fixed value of pattern parameter Req, or null if not bound.
391 * @param pApp the fixed value of pattern parameter App, or null if not bound.
392 * @param processor the action that will process the selected match.
393 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
394 *
395 */
396 public boolean forOneArbitraryMatch(final Requirement pReq, final ApplicationInstance pApp, final Consumer<? super InstanceDoesNotSatisfyRequirement.Match> processor) {
397 return rawForOneArbitraryMatch(new Object[]{pReq, pApp}, processor);
398 }
399
400 /**
401 * Returns a new (partial) match.
402 * This can be used e.g. to call the matcher with a partial match.
403 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
404 * @param pReq the fixed value of pattern parameter Req, or null if not bound.
405 * @param pApp the fixed value of pattern parameter App, or null if not bound.
406 * @return the (partial) match object.
407 *
408 */
409 public InstanceDoesNotSatisfyRequirement.Match newMatch(final Requirement pReq, final ApplicationInstance pApp) {
410 return InstanceDoesNotSatisfyRequirement.Match.newMatch(pReq, pApp);
411 }
412
413 /**
414 * Retrieve the set of values that occur in matches for Req.
415 * @return the Set of all values or empty set if there are no matches
416 *
417 */
418 protected Stream<Requirement> rawStreamAllValuesOfReq(final Object[] parameters) {
419 return rawStreamAllValues(POSITION_REQ, parameters).map(Requirement.class::cast);
420 }
421
422 /**
423 * Retrieve the set of values that occur in matches for Req.
424 * @return the Set of all values or empty set if there are no matches
425 *
426 */
427 public Set<Requirement> getAllValuesOfReq() {
428 return rawStreamAllValuesOfReq(emptyArray()).collect(Collectors.toSet());
429 }
430
431 /**
432 * Retrieve the set of values that occur in matches for Req.
433 * @return the Set of all values or empty set if there are no matches
434 *
435 */
436 public Stream<Requirement> streamAllValuesOfReq() {
437 return rawStreamAllValuesOfReq(emptyArray());
438 }
439
440 /**
441 * Retrieve the set of values that occur in matches for Req.
442 * </p>
443 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
444 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
445 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
446 *
447 * @return the Stream of all values or empty set if there are no matches
448 *
449 */
450 public Stream<Requirement> streamAllValuesOfReq(final InstanceDoesNotSatisfyRequirement.Match partialMatch) {
451 return rawStreamAllValuesOfReq(partialMatch.toArray());
452 }
453
454 /**
455 * Retrieve the set of values that occur in matches for Req.
456 * </p>
457 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
458 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
459 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
460 *
461 * @return the Stream of all values or empty set if there are no matches
462 *
463 */
464 public Stream<Requirement> streamAllValuesOfReq(final ApplicationInstance pApp) {
465 return rawStreamAllValuesOfReq(new Object[]{null, pApp});
466 }
467
468 /**
469 * Retrieve the set of values that occur in matches for Req.
470 * @return the Set of all values or empty set if there are no matches
471 *
472 */
473 public Set<Requirement> getAllValuesOfReq(final InstanceDoesNotSatisfyRequirement.Match partialMatch) {
474 return rawStreamAllValuesOfReq(partialMatch.toArray()).collect(Collectors.toSet());
475 }
476
477 /**
478 * Retrieve the set of values that occur in matches for Req.
479 * @return the Set of all values or empty set if there are no matches
480 *
481 */
482 public Set<Requirement> getAllValuesOfReq(final ApplicationInstance pApp) {
483 return rawStreamAllValuesOfReq(new Object[]{null, pApp}).collect(Collectors.toSet());
484 }
485
486 /**
487 * Retrieve the set of values that occur in matches for App.
488 * @return the Set of all values or empty set if there are no matches
489 *
490 */
491 protected Stream<ApplicationInstance> rawStreamAllValuesOfApp(final Object[] parameters) {
492 return rawStreamAllValues(POSITION_APP, parameters).map(ApplicationInstance.class::cast);
493 }
494
495 /**
496 * Retrieve the set of values that occur in matches for App.
497 * @return the Set of all values or empty set if there are no matches
498 *
499 */
500 public Set<ApplicationInstance> getAllValuesOfApp() {
501 return rawStreamAllValuesOfApp(emptyArray()).collect(Collectors.toSet());
502 }
503
504 /**
505 * Retrieve the set of values that occur in matches for App.
506 * @return the Set of all values or empty set if there are no matches
507 *
508 */
509 public Stream<ApplicationInstance> streamAllValuesOfApp() {
510 return rawStreamAllValuesOfApp(emptyArray());
511 }
512
513 /**
514 * Retrieve the set of values that occur in matches for App.
515 * </p>
516 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
517 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
518 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
519 *
520 * @return the Stream of all values or empty set if there are no matches
521 *
522 */
523 public Stream<ApplicationInstance> streamAllValuesOfApp(final InstanceDoesNotSatisfyRequirement.Match partialMatch) {
524 return rawStreamAllValuesOfApp(partialMatch.toArray());
525 }
526
527 /**
528 * Retrieve the set of values that occur in matches for App.
529 * </p>
530 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
531 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
532 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
533 *
534 * @return the Stream of all values or empty set if there are no matches
535 *
536 */
537 public Stream<ApplicationInstance> streamAllValuesOfApp(final Requirement pReq) {
538 return rawStreamAllValuesOfApp(new Object[]{pReq, null});
539 }
540
541 /**
542 * Retrieve the set of values that occur in matches for App.
543 * @return the Set of all values or empty set if there are no matches
544 *
545 */
546 public Set<ApplicationInstance> getAllValuesOfApp(final InstanceDoesNotSatisfyRequirement.Match partialMatch) {
547 return rawStreamAllValuesOfApp(partialMatch.toArray()).collect(Collectors.toSet());
548 }
549
550 /**
551 * Retrieve the set of values that occur in matches for App.
552 * @return the Set of all values or empty set if there are no matches
553 *
554 */
555 public Set<ApplicationInstance> getAllValuesOfApp(final Requirement pReq) {
556 return rawStreamAllValuesOfApp(new Object[]{pReq, null}).collect(Collectors.toSet());
557 }
558
559 @Override
560 protected InstanceDoesNotSatisfyRequirement.Match tupleToMatch(final Tuple t) {
561 try {
562 return InstanceDoesNotSatisfyRequirement.Match.newMatch((Requirement) t.get(POSITION_REQ), (ApplicationInstance) t.get(POSITION_APP));
563 } catch(ClassCastException e) {
564 LOGGER.error("Element(s) in tuple not properly typed!",e);
565 return null;
566 }
567 }
568
569 @Override
570 protected InstanceDoesNotSatisfyRequirement.Match arrayToMatch(final Object[] match) {
571 try {
572 return InstanceDoesNotSatisfyRequirement.Match.newMatch((Requirement) match[POSITION_REQ], (ApplicationInstance) match[POSITION_APP]);
573 } catch(ClassCastException e) {
574 LOGGER.error("Element(s) in array not properly typed!",e);
575 return null;
576 }
577 }
578
579 @Override
580 protected InstanceDoesNotSatisfyRequirement.Match arrayToMatchMutable(final Object[] match) {
581 try {
582 return InstanceDoesNotSatisfyRequirement.Match.newMutableMatch((Requirement) match[POSITION_REQ], (ApplicationInstance) match[POSITION_APP]);
583 } catch(ClassCastException e) {
584 LOGGER.error("Element(s) in array not properly typed!",e);
585 return null;
586 }
587 }
588
589 /**
590 * @return the singleton instance of the query specification of this pattern
591 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
592 *
593 */
594 public static IQuerySpecification<InstanceDoesNotSatisfyRequirement.Matcher> querySpecification() {
595 return InstanceDoesNotSatisfyRequirement.instance();
596 }
597 }
598
599 private InstanceDoesNotSatisfyRequirement() {
600 super(GeneratedPQuery.INSTANCE);
601 }
602
603 /**
604 * @return the singleton instance of the query specification
605 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
606 *
607 */
608 public static InstanceDoesNotSatisfyRequirement instance() {
609 try{
610 return LazyHolder.INSTANCE;
611 } catch (ExceptionInInitializerError err) {
612 throw processInitializerError(err);
613 }
614 }
615
616 @Override
617 protected InstanceDoesNotSatisfyRequirement.Matcher instantiate(final ViatraQueryEngine engine) {
618 return InstanceDoesNotSatisfyRequirement.Matcher.on(engine);
619 }
620
621 @Override
622 public InstanceDoesNotSatisfyRequirement.Matcher instantiate() {
623 return InstanceDoesNotSatisfyRequirement.Matcher.create();
624 }
625
626 @Override
627 public InstanceDoesNotSatisfyRequirement.Match newEmptyMatch() {
628 return InstanceDoesNotSatisfyRequirement.Match.newEmptyMatch();
629 }
630
631 @Override
632 public InstanceDoesNotSatisfyRequirement.Match newMatch(final Object... parameters) {
633 return InstanceDoesNotSatisfyRequirement.Match.newMatch((hu.bme.mit.inf.dslreasoner.domains.cps.Requirement) parameters[0], (hu.bme.mit.inf.dslreasoner.domains.cps.ApplicationInstance) parameters[1]);
634 }
635
636 /**
637 * Inner class allowing the singleton instance of {@link InstanceDoesNotSatisfyRequirement} to be created
638 * <b>not</b> at the class load time of the outer class,
639 * but rather at the first call to {@link InstanceDoesNotSatisfyRequirement#instance()}.
640 *
641 * <p> This workaround is required e.g. to support recursion.
642 *
643 */
644 private static class LazyHolder {
645 private static final InstanceDoesNotSatisfyRequirement INSTANCE = new InstanceDoesNotSatisfyRequirement();
646
647 /**
648 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
649 * This initialization order is required to support indirect recursion.
650 *
651 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
652 *
653 */
654 private static final Object STATIC_INITIALIZER = ensureInitialized();
655
656 public static Object ensureInitialized() {
657 INSTANCE.ensureInitializedInternal();
658 return null;
659 }
660 }
661
662 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
663 private static final InstanceDoesNotSatisfyRequirement.GeneratedPQuery INSTANCE = new GeneratedPQuery();
664
665 private final PParameter parameter_Req = new PParameter("Req", "hu.bme.mit.inf.dslreasoner.domains.cps.Requirement", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "Requirement")), PParameterDirection.INOUT);
666
667 private final PParameter parameter_App = new PParameter("App", "hu.bme.mit.inf.dslreasoner.domains.cps.ApplicationInstance", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "ApplicationInstance")), PParameterDirection.INOUT);
668
669 private final List<PParameter> parameters = Arrays.asList(parameter_Req, parameter_App);
670
671 private GeneratedPQuery() {
672 super(PVisibility.PUBLIC);
673 }
674
675 @Override
676 public String getFullyQualifiedName() {
677 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.instanceDoesNotSatisfyRequirement";
678 }
679
680 @Override
681 public List<String> getParameterNames() {
682 return Arrays.asList("Req","App");
683 }
684
685 @Override
686 public List<PParameter> getParameters() {
687 return parameters;
688 }
689
690 @Override
691 public Set<PBody> doGetContainedBodies() {
692 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
693 Set<PBody> bodies = new LinkedHashSet<>();
694 {
695 PBody body = new PBody(this);
696 PVariable var_Req = body.getOrCreateVariableByName("Req");
697 PVariable var_App = body.getOrCreateVariableByName("App");
698 new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "Requirement")));
699 new TypeConstraint(body, Tuples.flatTupleOf(var_App), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance")));
700 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
701 new ExportedParameter(body, var_Req, parameter_Req),
702 new ExportedParameter(body, var_App, parameter_App)
703 ));
704 // Requirement.instances(Req, App)
705 new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "Requirement")));
706 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
707 new TypeConstraint(body, Tuples.flatTupleOf(var_Req, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "Requirement", "instances")));
708 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance")));
709 new Equality(body, var__virtual_0_, var_App);
710 // neg find satisfyingInstance(Req, App)
711 new NegativePatternCall(body, Tuples.flatTupleOf(var_Req, var_App), SatisfyingInstance.instance().getInternalQueryRepresentation());
712 bodies.add(body);
713 }
714 {
715 PAnnotation annotation = new PAnnotation("Constraint");
716 annotation.addAttribute("severity", "error");
717 annotation.addAttribute("key", Arrays.asList(new Object[] {
718 new ParameterReference("Req"),
719 new ParameterReference("App")
720 }));
721 annotation.addAttribute("message", "Requirement must be satisfied by the required application type.");
722 addAnnotation(annotation);
723 }
724 return bodies;
725 }
726 }
727}
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/NotEnoughAvailableHdd.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/NotEnoughAvailableHdd.java
new file mode 100644
index 00000000..4077c103
--- /dev/null
+++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/NotEnoughAvailableHdd.java
@@ -0,0 +1,589 @@
1/**
2 * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql
3 */
4package hu.bme.mit.inf.dslreasoner.domains.cps.queries;
5
6import hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance;
7import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.AvailableHdd;
8import java.util.Arrays;
9import java.util.Collection;
10import java.util.LinkedHashSet;
11import java.util.List;
12import java.util.Objects;
13import java.util.Optional;
14import java.util.Set;
15import java.util.function.Consumer;
16import java.util.stream.Collectors;
17import java.util.stream.Stream;
18import org.apache.log4j.Logger;
19import org.eclipse.emf.ecore.EClass;
20import org.eclipse.viatra.query.runtime.api.IPatternMatch;
21import org.eclipse.viatra.query.runtime.api.IQuerySpecification;
22import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine;
23import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
24import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification;
25import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher;
26import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch;
27import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey;
28import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
29import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator;
30import org.eclipse.viatra.query.runtime.matchers.psystem.IValueProvider;
31import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
32import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
33import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation;
34import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference;
35import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
36import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation;
37import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall;
38import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
39import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
40import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
41import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
42import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
43import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
44import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
45
46/**
47 * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
48 *
49 * <p>Original source:
50 * <code><pre>
51 * {@literal @}Constraint(severity = "error", key = {Host},
52 * message = "Insufficient HDD available on host.")
53 * pattern notEnoughAvailableHdd(Host : HostInstance) {
54 * find availableHdd(Host, Hdd);
55 * check(Hdd {@literal <} 0);
56 * }
57 * </pre></code>
58 *
59 * @see Matcher
60 * @see Match
61 *
62 */
63@SuppressWarnings("all")
64public final class NotEnoughAvailableHdd extends BaseGeneratedEMFQuerySpecification<NotEnoughAvailableHdd.Matcher> {
65 /**
66 * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.notEnoughAvailableHdd pattern,
67 * to be used in conjunction with {@link Matcher}.
68 *
69 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
70 * Each instance is a (possibly partial) substitution of pattern parameters,
71 * usable to represent a match of the pattern in the result of a query,
72 * or to specify the bound (fixed) input parameters when issuing a query.
73 *
74 * @see Matcher
75 *
76 */
77 public static abstract class Match extends BasePatternMatch {
78 private HostInstance fHost;
79
80 private static List<String> parameterNames = makeImmutableList("Host");
81
82 private Match(final HostInstance pHost) {
83 this.fHost = pHost;
84 }
85
86 @Override
87 public Object get(final String parameterName) {
88 switch(parameterName) {
89 case "Host": return this.fHost;
90 default: return null;
91 }
92 }
93
94 @Override
95 public Object get(final int index) {
96 switch(index) {
97 case 0: return this.fHost;
98 default: return null;
99 }
100 }
101
102 public HostInstance getHost() {
103 return this.fHost;
104 }
105
106 @Override
107 public boolean set(final String parameterName, final Object newValue) {
108 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
109 if ("Host".equals(parameterName) ) {
110 this.fHost = (HostInstance) newValue;
111 return true;
112 }
113 return false;
114 }
115
116 public void setHost(final HostInstance pHost) {
117 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
118 this.fHost = pHost;
119 }
120
121 @Override
122 public String patternName() {
123 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.notEnoughAvailableHdd";
124 }
125
126 @Override
127 public List<String> parameterNames() {
128 return NotEnoughAvailableHdd.Match.parameterNames;
129 }
130
131 @Override
132 public Object[] toArray() {
133 return new Object[]{fHost};
134 }
135
136 @Override
137 public NotEnoughAvailableHdd.Match toImmutable() {
138 return isMutable() ? newMatch(fHost) : this;
139 }
140
141 @Override
142 public String prettyPrint() {
143 StringBuilder result = new StringBuilder();
144 result.append("\"Host\"=" + prettyPrintValue(fHost));
145 return result.toString();
146 }
147
148 @Override
149 public int hashCode() {
150 return Objects.hash(fHost);
151 }
152
153 @Override
154 public boolean equals(final Object obj) {
155 if (this == obj)
156 return true;
157 if (obj == null) {
158 return false;
159 }
160 if ((obj instanceof NotEnoughAvailableHdd.Match)) {
161 NotEnoughAvailableHdd.Match other = (NotEnoughAvailableHdd.Match) obj;
162 return Objects.equals(fHost, other.fHost);
163 } else {
164 // this should be infrequent
165 if (!(obj instanceof IPatternMatch)) {
166 return false;
167 }
168 IPatternMatch otherSig = (IPatternMatch) obj;
169 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
170 }
171 }
172
173 @Override
174 public NotEnoughAvailableHdd specification() {
175 return NotEnoughAvailableHdd.instance();
176 }
177
178 /**
179 * Returns an empty, mutable match.
180 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
181 *
182 * @return the empty match.
183 *
184 */
185 public static NotEnoughAvailableHdd.Match newEmptyMatch() {
186 return new Mutable(null);
187 }
188
189 /**
190 * Returns a mutable (partial) match.
191 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
192 *
193 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
194 * @return the new, mutable (partial) match object.
195 *
196 */
197 public static NotEnoughAvailableHdd.Match newMutableMatch(final HostInstance pHost) {
198 return new Mutable(pHost);
199 }
200
201 /**
202 * Returns a new (partial) match.
203 * This can be used e.g. to call the matcher with a partial match.
204 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
205 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
206 * @return the (partial) match object.
207 *
208 */
209 public static NotEnoughAvailableHdd.Match newMatch(final HostInstance pHost) {
210 return new Immutable(pHost);
211 }
212
213 private static final class Mutable extends NotEnoughAvailableHdd.Match {
214 Mutable(final HostInstance pHost) {
215 super(pHost);
216 }
217
218 @Override
219 public boolean isMutable() {
220 return true;
221 }
222 }
223
224 private static final class Immutable extends NotEnoughAvailableHdd.Match {
225 Immutable(final HostInstance pHost) {
226 super(pHost);
227 }
228
229 @Override
230 public boolean isMutable() {
231 return false;
232 }
233 }
234 }
235
236 /**
237 * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.notEnoughAvailableHdd pattern,
238 * providing pattern-specific query methods.
239 *
240 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
241 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
242 *
243 * <p>Matches of the pattern will be represented as {@link Match}.
244 *
245 * <p>Original source:
246 * <code><pre>
247 * {@literal @}Constraint(severity = "error", key = {Host},
248 * message = "Insufficient HDD available on host.")
249 * pattern notEnoughAvailableHdd(Host : HostInstance) {
250 * find availableHdd(Host, Hdd);
251 * check(Hdd {@literal <} 0);
252 * }
253 * </pre></code>
254 *
255 * @see Match
256 * @see NotEnoughAvailableHdd
257 *
258 */
259 public static class Matcher extends BaseMatcher<NotEnoughAvailableHdd.Match> {
260 /**
261 * Initializes the pattern matcher within an existing VIATRA Query engine.
262 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
263 *
264 * @param engine the existing VIATRA Query engine in which this matcher will be created.
265 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
266 *
267 */
268 public static NotEnoughAvailableHdd.Matcher on(final ViatraQueryEngine engine) {
269 // check if matcher already exists
270 Matcher matcher = engine.getExistingMatcher(querySpecification());
271 if (matcher == null) {
272 matcher = (Matcher)engine.getMatcher(querySpecification());
273 }
274 return matcher;
275 }
276
277 /**
278 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
279 * @return an initialized matcher
280 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
281 *
282 */
283 public static NotEnoughAvailableHdd.Matcher create() {
284 return new Matcher();
285 }
286
287 private static final int POSITION_HOST = 0;
288
289 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(NotEnoughAvailableHdd.Matcher.class);
290
291 /**
292 * Initializes the pattern matcher within an existing VIATRA Query engine.
293 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
294 *
295 * @param engine the existing VIATRA Query engine in which this matcher will be created.
296 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
297 *
298 */
299 private Matcher() {
300 super(querySpecification());
301 }
302
303 /**
304 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
305 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
306 * @return matches represented as a Match object.
307 *
308 */
309 public Collection<NotEnoughAvailableHdd.Match> getAllMatches(final HostInstance pHost) {
310 return rawStreamAllMatches(new Object[]{pHost}).collect(Collectors.toSet());
311 }
312
313 /**
314 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
315 * </p>
316 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
317 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
318 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
319 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
320 * @return a stream of matches represented as a Match object.
321 *
322 */
323 public Stream<NotEnoughAvailableHdd.Match> streamAllMatches(final HostInstance pHost) {
324 return rawStreamAllMatches(new Object[]{pHost});
325 }
326
327 /**
328 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
329 * Neither determinism nor randomness of selection is guaranteed.
330 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
331 * @return a match represented as a Match object, or null if no match is found.
332 *
333 */
334 public Optional<NotEnoughAvailableHdd.Match> getOneArbitraryMatch(final HostInstance pHost) {
335 return rawGetOneArbitraryMatch(new Object[]{pHost});
336 }
337
338 /**
339 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
340 * under any possible substitution of the unspecified parameters (if any).
341 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
342 * @return true if the input is a valid (partial) match of the pattern.
343 *
344 */
345 public boolean hasMatch(final HostInstance pHost) {
346 return rawHasMatch(new Object[]{pHost});
347 }
348
349 /**
350 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
351 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
352 * @return the number of pattern matches found.
353 *
354 */
355 public int countMatches(final HostInstance pHost) {
356 return rawCountMatches(new Object[]{pHost});
357 }
358
359 /**
360 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
361 * Neither determinism nor randomness of selection is guaranteed.
362 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
363 * @param processor the action that will process the selected match.
364 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
365 *
366 */
367 public boolean forOneArbitraryMatch(final HostInstance pHost, final Consumer<? super NotEnoughAvailableHdd.Match> processor) {
368 return rawForOneArbitraryMatch(new Object[]{pHost}, processor);
369 }
370
371 /**
372 * Returns a new (partial) match.
373 * This can be used e.g. to call the matcher with a partial match.
374 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
375 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
376 * @return the (partial) match object.
377 *
378 */
379 public NotEnoughAvailableHdd.Match newMatch(final HostInstance pHost) {
380 return NotEnoughAvailableHdd.Match.newMatch(pHost);
381 }
382
383 /**
384 * Retrieve the set of values that occur in matches for Host.
385 * @return the Set of all values or empty set if there are no matches
386 *
387 */
388 protected Stream<HostInstance> rawStreamAllValuesOfHost(final Object[] parameters) {
389 return rawStreamAllValues(POSITION_HOST, parameters).map(HostInstance.class::cast);
390 }
391
392 /**
393 * Retrieve the set of values that occur in matches for Host.
394 * @return the Set of all values or empty set if there are no matches
395 *
396 */
397 public Set<HostInstance> getAllValuesOfHost() {
398 return rawStreamAllValuesOfHost(emptyArray()).collect(Collectors.toSet());
399 }
400
401 /**
402 * Retrieve the set of values that occur in matches for Host.
403 * @return the Set of all values or empty set if there are no matches
404 *
405 */
406 public Stream<HostInstance> streamAllValuesOfHost() {
407 return rawStreamAllValuesOfHost(emptyArray());
408 }
409
410 @Override
411 protected NotEnoughAvailableHdd.Match tupleToMatch(final Tuple t) {
412 try {
413 return NotEnoughAvailableHdd.Match.newMatch((HostInstance) t.get(POSITION_HOST));
414 } catch(ClassCastException e) {
415 LOGGER.error("Element(s) in tuple not properly typed!",e);
416 return null;
417 }
418 }
419
420 @Override
421 protected NotEnoughAvailableHdd.Match arrayToMatch(final Object[] match) {
422 try {
423 return NotEnoughAvailableHdd.Match.newMatch((HostInstance) match[POSITION_HOST]);
424 } catch(ClassCastException e) {
425 LOGGER.error("Element(s) in array not properly typed!",e);
426 return null;
427 }
428 }
429
430 @Override
431 protected NotEnoughAvailableHdd.Match arrayToMatchMutable(final Object[] match) {
432 try {
433 return NotEnoughAvailableHdd.Match.newMutableMatch((HostInstance) match[POSITION_HOST]);
434 } catch(ClassCastException e) {
435 LOGGER.error("Element(s) in array not properly typed!",e);
436 return null;
437 }
438 }
439
440 /**
441 * @return the singleton instance of the query specification of this pattern
442 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
443 *
444 */
445 public static IQuerySpecification<NotEnoughAvailableHdd.Matcher> querySpecification() {
446 return NotEnoughAvailableHdd.instance();
447 }
448 }
449
450 private NotEnoughAvailableHdd() {
451 super(GeneratedPQuery.INSTANCE);
452 }
453
454 /**
455 * @return the singleton instance of the query specification
456 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
457 *
458 */
459 public static NotEnoughAvailableHdd instance() {
460 try{
461 return LazyHolder.INSTANCE;
462 } catch (ExceptionInInitializerError err) {
463 throw processInitializerError(err);
464 }
465 }
466
467 @Override
468 protected NotEnoughAvailableHdd.Matcher instantiate(final ViatraQueryEngine engine) {
469 return NotEnoughAvailableHdd.Matcher.on(engine);
470 }
471
472 @Override
473 public NotEnoughAvailableHdd.Matcher instantiate() {
474 return NotEnoughAvailableHdd.Matcher.create();
475 }
476
477 @Override
478 public NotEnoughAvailableHdd.Match newEmptyMatch() {
479 return NotEnoughAvailableHdd.Match.newEmptyMatch();
480 }
481
482 @Override
483 public NotEnoughAvailableHdd.Match newMatch(final Object... parameters) {
484 return NotEnoughAvailableHdd.Match.newMatch((hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance) parameters[0]);
485 }
486
487 /**
488 * Inner class allowing the singleton instance of {@link NotEnoughAvailableHdd} to be created
489 * <b>not</b> at the class load time of the outer class,
490 * but rather at the first call to {@link NotEnoughAvailableHdd#instance()}.
491 *
492 * <p> This workaround is required e.g. to support recursion.
493 *
494 */
495 private static class LazyHolder {
496 private static final NotEnoughAvailableHdd INSTANCE = new NotEnoughAvailableHdd();
497
498 /**
499 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
500 * This initialization order is required to support indirect recursion.
501 *
502 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
503 *
504 */
505 private static final Object STATIC_INITIALIZER = ensureInitialized();
506
507 public static Object ensureInitialized() {
508 INSTANCE.ensureInitializedInternal();
509 return null;
510 }
511 }
512
513 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
514 private static final NotEnoughAvailableHdd.GeneratedPQuery INSTANCE = new GeneratedPQuery();
515
516 private final PParameter parameter_Host = new PParameter("Host", "hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "HostInstance")), PParameterDirection.INOUT);
517
518 private final List<PParameter> parameters = Arrays.asList(parameter_Host);
519
520 private GeneratedPQuery() {
521 super(PVisibility.PUBLIC);
522 }
523
524 @Override
525 public String getFullyQualifiedName() {
526 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.notEnoughAvailableHdd";
527 }
528
529 @Override
530 public List<String> getParameterNames() {
531 return Arrays.asList("Host");
532 }
533
534 @Override
535 public List<PParameter> getParameters() {
536 return parameters;
537 }
538
539 @Override
540 public Set<PBody> doGetContainedBodies() {
541 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
542 Set<PBody> bodies = new LinkedHashSet<>();
543 {
544 PBody body = new PBody(this);
545 PVariable var_Host = body.getOrCreateVariableByName("Host");
546 PVariable var_Hdd = body.getOrCreateVariableByName("Hdd");
547 new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance")));
548 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
549 new ExportedParameter(body, var_Host, parameter_Host)
550 ));
551 // find availableHdd(Host, Hdd)
552 new PositivePatternCall(body, Tuples.flatTupleOf(var_Host, var_Hdd), AvailableHdd.instance().getInternalQueryRepresentation());
553 // check(Hdd < 0)
554 new ExpressionEvaluation(body, new IExpressionEvaluator() {
555
556 @Override
557 public String getShortDescription() {
558 return "Expression evaluation from pattern notEnoughAvailableHdd";
559 }
560
561 @Override
562 public Iterable<String> getInputParameterNames() {
563 return Arrays.asList("Hdd");}
564
565 @Override
566 public Object evaluateExpression(IValueProvider provider) throws Exception {
567 Integer Hdd = (Integer) provider.getValue("Hdd");
568 return evaluateExpression_1_1(Hdd);
569 }
570 }, null);
571 bodies.add(body);
572 }
573 {
574 PAnnotation annotation = new PAnnotation("Constraint");
575 annotation.addAttribute("severity", "error");
576 annotation.addAttribute("key", Arrays.asList(new Object[] {
577 new ParameterReference("Host")
578 }));
579 annotation.addAttribute("message", "Insufficient HDD available on host.");
580 addAnnotation(annotation);
581 }
582 return bodies;
583 }
584 }
585
586 private static boolean evaluateExpression_1_1(final Integer Hdd) {
587 return ((Hdd).intValue() < 0);
588 }
589}
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/NotEnoughAvailableMemory.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/NotEnoughAvailableMemory.java
new file mode 100644
index 00000000..6e52bee8
--- /dev/null
+++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/NotEnoughAvailableMemory.java
@@ -0,0 +1,589 @@
1/**
2 * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql
3 */
4package hu.bme.mit.inf.dslreasoner.domains.cps.queries;
5
6import hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance;
7import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.AvailableMemory;
8import java.util.Arrays;
9import java.util.Collection;
10import java.util.LinkedHashSet;
11import java.util.List;
12import java.util.Objects;
13import java.util.Optional;
14import java.util.Set;
15import java.util.function.Consumer;
16import java.util.stream.Collectors;
17import java.util.stream.Stream;
18import org.apache.log4j.Logger;
19import org.eclipse.emf.ecore.EClass;
20import org.eclipse.viatra.query.runtime.api.IPatternMatch;
21import org.eclipse.viatra.query.runtime.api.IQuerySpecification;
22import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine;
23import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
24import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification;
25import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher;
26import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch;
27import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey;
28import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
29import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator;
30import org.eclipse.viatra.query.runtime.matchers.psystem.IValueProvider;
31import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
32import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
33import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation;
34import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference;
35import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
36import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation;
37import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall;
38import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
39import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
40import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
41import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
42import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
43import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
44import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
45
46/**
47 * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
48 *
49 * <p>Original source:
50 * <code><pre>
51 * {@literal @}Constraint(severity = "error", key = {Host},
52 * message = "Insufficient memory available on host.")
53 * pattern notEnoughAvailableMemory(Host : HostInstance) {
54 * find availableMemory(Host, Memory);
55 * check(Memory {@literal <} 0);
56 * }
57 * </pre></code>
58 *
59 * @see Matcher
60 * @see Match
61 *
62 */
63@SuppressWarnings("all")
64public final class NotEnoughAvailableMemory extends BaseGeneratedEMFQuerySpecification<NotEnoughAvailableMemory.Matcher> {
65 /**
66 * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.notEnoughAvailableMemory pattern,
67 * to be used in conjunction with {@link Matcher}.
68 *
69 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
70 * Each instance is a (possibly partial) substitution of pattern parameters,
71 * usable to represent a match of the pattern in the result of a query,
72 * or to specify the bound (fixed) input parameters when issuing a query.
73 *
74 * @see Matcher
75 *
76 */
77 public static abstract class Match extends BasePatternMatch {
78 private HostInstance fHost;
79
80 private static List<String> parameterNames = makeImmutableList("Host");
81
82 private Match(final HostInstance pHost) {
83 this.fHost = pHost;
84 }
85
86 @Override
87 public Object get(final String parameterName) {
88 switch(parameterName) {
89 case "Host": return this.fHost;
90 default: return null;
91 }
92 }
93
94 @Override
95 public Object get(final int index) {
96 switch(index) {
97 case 0: return this.fHost;
98 default: return null;
99 }
100 }
101
102 public HostInstance getHost() {
103 return this.fHost;
104 }
105
106 @Override
107 public boolean set(final String parameterName, final Object newValue) {
108 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
109 if ("Host".equals(parameterName) ) {
110 this.fHost = (HostInstance) newValue;
111 return true;
112 }
113 return false;
114 }
115
116 public void setHost(final HostInstance pHost) {
117 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
118 this.fHost = pHost;
119 }
120
121 @Override
122 public String patternName() {
123 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.notEnoughAvailableMemory";
124 }
125
126 @Override
127 public List<String> parameterNames() {
128 return NotEnoughAvailableMemory.Match.parameterNames;
129 }
130
131 @Override
132 public Object[] toArray() {
133 return new Object[]{fHost};
134 }
135
136 @Override
137 public NotEnoughAvailableMemory.Match toImmutable() {
138 return isMutable() ? newMatch(fHost) : this;
139 }
140
141 @Override
142 public String prettyPrint() {
143 StringBuilder result = new StringBuilder();
144 result.append("\"Host\"=" + prettyPrintValue(fHost));
145 return result.toString();
146 }
147
148 @Override
149 public int hashCode() {
150 return Objects.hash(fHost);
151 }
152
153 @Override
154 public boolean equals(final Object obj) {
155 if (this == obj)
156 return true;
157 if (obj == null) {
158 return false;
159 }
160 if ((obj instanceof NotEnoughAvailableMemory.Match)) {
161 NotEnoughAvailableMemory.Match other = (NotEnoughAvailableMemory.Match) obj;
162 return Objects.equals(fHost, other.fHost);
163 } else {
164 // this should be infrequent
165 if (!(obj instanceof IPatternMatch)) {
166 return false;
167 }
168 IPatternMatch otherSig = (IPatternMatch) obj;
169 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
170 }
171 }
172
173 @Override
174 public NotEnoughAvailableMemory specification() {
175 return NotEnoughAvailableMemory.instance();
176 }
177
178 /**
179 * Returns an empty, mutable match.
180 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
181 *
182 * @return the empty match.
183 *
184 */
185 public static NotEnoughAvailableMemory.Match newEmptyMatch() {
186 return new Mutable(null);
187 }
188
189 /**
190 * Returns a mutable (partial) match.
191 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
192 *
193 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
194 * @return the new, mutable (partial) match object.
195 *
196 */
197 public static NotEnoughAvailableMemory.Match newMutableMatch(final HostInstance pHost) {
198 return new Mutable(pHost);
199 }
200
201 /**
202 * Returns a new (partial) match.
203 * This can be used e.g. to call the matcher with a partial match.
204 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
205 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
206 * @return the (partial) match object.
207 *
208 */
209 public static NotEnoughAvailableMemory.Match newMatch(final HostInstance pHost) {
210 return new Immutable(pHost);
211 }
212
213 private static final class Mutable extends NotEnoughAvailableMemory.Match {
214 Mutable(final HostInstance pHost) {
215 super(pHost);
216 }
217
218 @Override
219 public boolean isMutable() {
220 return true;
221 }
222 }
223
224 private static final class Immutable extends NotEnoughAvailableMemory.Match {
225 Immutable(final HostInstance pHost) {
226 super(pHost);
227 }
228
229 @Override
230 public boolean isMutable() {
231 return false;
232 }
233 }
234 }
235
236 /**
237 * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.notEnoughAvailableMemory pattern,
238 * providing pattern-specific query methods.
239 *
240 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
241 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
242 *
243 * <p>Matches of the pattern will be represented as {@link Match}.
244 *
245 * <p>Original source:
246 * <code><pre>
247 * {@literal @}Constraint(severity = "error", key = {Host},
248 * message = "Insufficient memory available on host.")
249 * pattern notEnoughAvailableMemory(Host : HostInstance) {
250 * find availableMemory(Host, Memory);
251 * check(Memory {@literal <} 0);
252 * }
253 * </pre></code>
254 *
255 * @see Match
256 * @see NotEnoughAvailableMemory
257 *
258 */
259 public static class Matcher extends BaseMatcher<NotEnoughAvailableMemory.Match> {
260 /**
261 * Initializes the pattern matcher within an existing VIATRA Query engine.
262 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
263 *
264 * @param engine the existing VIATRA Query engine in which this matcher will be created.
265 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
266 *
267 */
268 public static NotEnoughAvailableMemory.Matcher on(final ViatraQueryEngine engine) {
269 // check if matcher already exists
270 Matcher matcher = engine.getExistingMatcher(querySpecification());
271 if (matcher == null) {
272 matcher = (Matcher)engine.getMatcher(querySpecification());
273 }
274 return matcher;
275 }
276
277 /**
278 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
279 * @return an initialized matcher
280 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
281 *
282 */
283 public static NotEnoughAvailableMemory.Matcher create() {
284 return new Matcher();
285 }
286
287 private static final int POSITION_HOST = 0;
288
289 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(NotEnoughAvailableMemory.Matcher.class);
290
291 /**
292 * Initializes the pattern matcher within an existing VIATRA Query engine.
293 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
294 *
295 * @param engine the existing VIATRA Query engine in which this matcher will be created.
296 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
297 *
298 */
299 private Matcher() {
300 super(querySpecification());
301 }
302
303 /**
304 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
305 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
306 * @return matches represented as a Match object.
307 *
308 */
309 public Collection<NotEnoughAvailableMemory.Match> getAllMatches(final HostInstance pHost) {
310 return rawStreamAllMatches(new Object[]{pHost}).collect(Collectors.toSet());
311 }
312
313 /**
314 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
315 * </p>
316 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
317 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
318 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
319 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
320 * @return a stream of matches represented as a Match object.
321 *
322 */
323 public Stream<NotEnoughAvailableMemory.Match> streamAllMatches(final HostInstance pHost) {
324 return rawStreamAllMatches(new Object[]{pHost});
325 }
326
327 /**
328 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
329 * Neither determinism nor randomness of selection is guaranteed.
330 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
331 * @return a match represented as a Match object, or null if no match is found.
332 *
333 */
334 public Optional<NotEnoughAvailableMemory.Match> getOneArbitraryMatch(final HostInstance pHost) {
335 return rawGetOneArbitraryMatch(new Object[]{pHost});
336 }
337
338 /**
339 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
340 * under any possible substitution of the unspecified parameters (if any).
341 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
342 * @return true if the input is a valid (partial) match of the pattern.
343 *
344 */
345 public boolean hasMatch(final HostInstance pHost) {
346 return rawHasMatch(new Object[]{pHost});
347 }
348
349 /**
350 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
351 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
352 * @return the number of pattern matches found.
353 *
354 */
355 public int countMatches(final HostInstance pHost) {
356 return rawCountMatches(new Object[]{pHost});
357 }
358
359 /**
360 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
361 * Neither determinism nor randomness of selection is guaranteed.
362 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
363 * @param processor the action that will process the selected match.
364 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
365 *
366 */
367 public boolean forOneArbitraryMatch(final HostInstance pHost, final Consumer<? super NotEnoughAvailableMemory.Match> processor) {
368 return rawForOneArbitraryMatch(new Object[]{pHost}, processor);
369 }
370
371 /**
372 * Returns a new (partial) match.
373 * This can be used e.g. to call the matcher with a partial match.
374 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
375 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
376 * @return the (partial) match object.
377 *
378 */
379 public NotEnoughAvailableMemory.Match newMatch(final HostInstance pHost) {
380 return NotEnoughAvailableMemory.Match.newMatch(pHost);
381 }
382
383 /**
384 * Retrieve the set of values that occur in matches for Host.
385 * @return the Set of all values or empty set if there are no matches
386 *
387 */
388 protected Stream<HostInstance> rawStreamAllValuesOfHost(final Object[] parameters) {
389 return rawStreamAllValues(POSITION_HOST, parameters).map(HostInstance.class::cast);
390 }
391
392 /**
393 * Retrieve the set of values that occur in matches for Host.
394 * @return the Set of all values or empty set if there are no matches
395 *
396 */
397 public Set<HostInstance> getAllValuesOfHost() {
398 return rawStreamAllValuesOfHost(emptyArray()).collect(Collectors.toSet());
399 }
400
401 /**
402 * Retrieve the set of values that occur in matches for Host.
403 * @return the Set of all values or empty set if there are no matches
404 *
405 */
406 public Stream<HostInstance> streamAllValuesOfHost() {
407 return rawStreamAllValuesOfHost(emptyArray());
408 }
409
410 @Override
411 protected NotEnoughAvailableMemory.Match tupleToMatch(final Tuple t) {
412 try {
413 return NotEnoughAvailableMemory.Match.newMatch((HostInstance) t.get(POSITION_HOST));
414 } catch(ClassCastException e) {
415 LOGGER.error("Element(s) in tuple not properly typed!",e);
416 return null;
417 }
418 }
419
420 @Override
421 protected NotEnoughAvailableMemory.Match arrayToMatch(final Object[] match) {
422 try {
423 return NotEnoughAvailableMemory.Match.newMatch((HostInstance) match[POSITION_HOST]);
424 } catch(ClassCastException e) {
425 LOGGER.error("Element(s) in array not properly typed!",e);
426 return null;
427 }
428 }
429
430 @Override
431 protected NotEnoughAvailableMemory.Match arrayToMatchMutable(final Object[] match) {
432 try {
433 return NotEnoughAvailableMemory.Match.newMutableMatch((HostInstance) match[POSITION_HOST]);
434 } catch(ClassCastException e) {
435 LOGGER.error("Element(s) in array not properly typed!",e);
436 return null;
437 }
438 }
439
440 /**
441 * @return the singleton instance of the query specification of this pattern
442 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
443 *
444 */
445 public static IQuerySpecification<NotEnoughAvailableMemory.Matcher> querySpecification() {
446 return NotEnoughAvailableMemory.instance();
447 }
448 }
449
450 private NotEnoughAvailableMemory() {
451 super(GeneratedPQuery.INSTANCE);
452 }
453
454 /**
455 * @return the singleton instance of the query specification
456 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
457 *
458 */
459 public static NotEnoughAvailableMemory instance() {
460 try{
461 return LazyHolder.INSTANCE;
462 } catch (ExceptionInInitializerError err) {
463 throw processInitializerError(err);
464 }
465 }
466
467 @Override
468 protected NotEnoughAvailableMemory.Matcher instantiate(final ViatraQueryEngine engine) {
469 return NotEnoughAvailableMemory.Matcher.on(engine);
470 }
471
472 @Override
473 public NotEnoughAvailableMemory.Matcher instantiate() {
474 return NotEnoughAvailableMemory.Matcher.create();
475 }
476
477 @Override
478 public NotEnoughAvailableMemory.Match newEmptyMatch() {
479 return NotEnoughAvailableMemory.Match.newEmptyMatch();
480 }
481
482 @Override
483 public NotEnoughAvailableMemory.Match newMatch(final Object... parameters) {
484 return NotEnoughAvailableMemory.Match.newMatch((hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance) parameters[0]);
485 }
486
487 /**
488 * Inner class allowing the singleton instance of {@link NotEnoughAvailableMemory} to be created
489 * <b>not</b> at the class load time of the outer class,
490 * but rather at the first call to {@link NotEnoughAvailableMemory#instance()}.
491 *
492 * <p> This workaround is required e.g. to support recursion.
493 *
494 */
495 private static class LazyHolder {
496 private static final NotEnoughAvailableMemory INSTANCE = new NotEnoughAvailableMemory();
497
498 /**
499 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
500 * This initialization order is required to support indirect recursion.
501 *
502 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
503 *
504 */
505 private static final Object STATIC_INITIALIZER = ensureInitialized();
506
507 public static Object ensureInitialized() {
508 INSTANCE.ensureInitializedInternal();
509 return null;
510 }
511 }
512
513 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
514 private static final NotEnoughAvailableMemory.GeneratedPQuery INSTANCE = new GeneratedPQuery();
515
516 private final PParameter parameter_Host = new PParameter("Host", "hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "HostInstance")), PParameterDirection.INOUT);
517
518 private final List<PParameter> parameters = Arrays.asList(parameter_Host);
519
520 private GeneratedPQuery() {
521 super(PVisibility.PUBLIC);
522 }
523
524 @Override
525 public String getFullyQualifiedName() {
526 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.notEnoughAvailableMemory";
527 }
528
529 @Override
530 public List<String> getParameterNames() {
531 return Arrays.asList("Host");
532 }
533
534 @Override
535 public List<PParameter> getParameters() {
536 return parameters;
537 }
538
539 @Override
540 public Set<PBody> doGetContainedBodies() {
541 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
542 Set<PBody> bodies = new LinkedHashSet<>();
543 {
544 PBody body = new PBody(this);
545 PVariable var_Host = body.getOrCreateVariableByName("Host");
546 PVariable var_Memory = body.getOrCreateVariableByName("Memory");
547 new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance")));
548 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
549 new ExportedParameter(body, var_Host, parameter_Host)
550 ));
551 // find availableMemory(Host, Memory)
552 new PositivePatternCall(body, Tuples.flatTupleOf(var_Host, var_Memory), AvailableMemory.instance().getInternalQueryRepresentation());
553 // check(Memory < 0)
554 new ExpressionEvaluation(body, new IExpressionEvaluator() {
555
556 @Override
557 public String getShortDescription() {
558 return "Expression evaluation from pattern notEnoughAvailableMemory";
559 }
560
561 @Override
562 public Iterable<String> getInputParameterNames() {
563 return Arrays.asList("Memory");}
564
565 @Override
566 public Object evaluateExpression(IValueProvider provider) throws Exception {
567 Integer Memory = (Integer) provider.getValue("Memory");
568 return evaluateExpression_1_1(Memory);
569 }
570 }, null);
571 bodies.add(body);
572 }
573 {
574 PAnnotation annotation = new PAnnotation("Constraint");
575 annotation.addAttribute("severity", "error");
576 annotation.addAttribute("key", Arrays.asList(new Object[] {
577 new ParameterReference("Host")
578 }));
579 annotation.addAttribute("message", "Insufficient memory available on host.");
580 addAnnotation(annotation);
581 }
582 return bodies;
583 }
584 }
585
586 private static boolean evaluateExpression_1_1(final Integer Memory) {
587 return ((Memory).intValue() < 0);
588 }
589}
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/RedundantInstancesOnSameHost.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/RedundantInstancesOnSameHost.java
new file mode 100644
index 00000000..2a40ac57
--- /dev/null
+++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/RedundantInstancesOnSameHost.java
@@ -0,0 +1,597 @@
1/**
2 * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql
3 */
4package hu.bme.mit.inf.dslreasoner.domains.cps.queries;
5
6import hu.bme.mit.inf.dslreasoner.domains.cps.Requirement;
7import java.util.Arrays;
8import java.util.Collection;
9import java.util.LinkedHashSet;
10import java.util.List;
11import java.util.Objects;
12import java.util.Optional;
13import java.util.Set;
14import java.util.function.Consumer;
15import java.util.stream.Collectors;
16import java.util.stream.Stream;
17import org.apache.log4j.Logger;
18import org.eclipse.emf.ecore.EClass;
19import org.eclipse.viatra.query.runtime.api.IPatternMatch;
20import org.eclipse.viatra.query.runtime.api.IQuerySpecification;
21import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine;
22import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
23import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification;
24import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher;
25import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch;
26import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey;
27import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey;
28import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
29import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
30import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
31import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation;
32import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference;
33import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality;
34import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
35import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Inequality;
36import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
37import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
38import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
39import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
40import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
41import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
42import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
43
44/**
45 * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
46 *
47 * <p>Original source:
48 * <code><pre>
49 * {@literal @}Constraint(severity = "error", key = {Req},
50 * message = "Redundant instances must not be allocated to the same host.")
51 * pattern redundantInstancesOnSameHost(Req : Requirement) {
52 * Requirement.instances(Req, App1);
53 * Requirement.instances(Req, App2);
54 * App1 != App2;
55 * ApplicationInstance.allocatedTo(App1, Host);
56 * ApplicationInstance.allocatedTo(App2, Host);
57 * }
58 * </pre></code>
59 *
60 * @see Matcher
61 * @see Match
62 *
63 */
64@SuppressWarnings("all")
65public final class RedundantInstancesOnSameHost extends BaseGeneratedEMFQuerySpecification<RedundantInstancesOnSameHost.Matcher> {
66 /**
67 * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.redundantInstancesOnSameHost pattern,
68 * to be used in conjunction with {@link Matcher}.
69 *
70 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
71 * Each instance is a (possibly partial) substitution of pattern parameters,
72 * usable to represent a match of the pattern in the result of a query,
73 * or to specify the bound (fixed) input parameters when issuing a query.
74 *
75 * @see Matcher
76 *
77 */
78 public static abstract class Match extends BasePatternMatch {
79 private Requirement fReq;
80
81 private static List<String> parameterNames = makeImmutableList("Req");
82
83 private Match(final Requirement pReq) {
84 this.fReq = pReq;
85 }
86
87 @Override
88 public Object get(final String parameterName) {
89 switch(parameterName) {
90 case "Req": return this.fReq;
91 default: return null;
92 }
93 }
94
95 @Override
96 public Object get(final int index) {
97 switch(index) {
98 case 0: return this.fReq;
99 default: return null;
100 }
101 }
102
103 public Requirement getReq() {
104 return this.fReq;
105 }
106
107 @Override
108 public boolean set(final String parameterName, final Object newValue) {
109 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
110 if ("Req".equals(parameterName) ) {
111 this.fReq = (Requirement) newValue;
112 return true;
113 }
114 return false;
115 }
116
117 public void setReq(final Requirement pReq) {
118 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
119 this.fReq = pReq;
120 }
121
122 @Override
123 public String patternName() {
124 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.redundantInstancesOnSameHost";
125 }
126
127 @Override
128 public List<String> parameterNames() {
129 return RedundantInstancesOnSameHost.Match.parameterNames;
130 }
131
132 @Override
133 public Object[] toArray() {
134 return new Object[]{fReq};
135 }
136
137 @Override
138 public RedundantInstancesOnSameHost.Match toImmutable() {
139 return isMutable() ? newMatch(fReq) : this;
140 }
141
142 @Override
143 public String prettyPrint() {
144 StringBuilder result = new StringBuilder();
145 result.append("\"Req\"=" + prettyPrintValue(fReq));
146 return result.toString();
147 }
148
149 @Override
150 public int hashCode() {
151 return Objects.hash(fReq);
152 }
153
154 @Override
155 public boolean equals(final Object obj) {
156 if (this == obj)
157 return true;
158 if (obj == null) {
159 return false;
160 }
161 if ((obj instanceof RedundantInstancesOnSameHost.Match)) {
162 RedundantInstancesOnSameHost.Match other = (RedundantInstancesOnSameHost.Match) obj;
163 return Objects.equals(fReq, other.fReq);
164 } else {
165 // this should be infrequent
166 if (!(obj instanceof IPatternMatch)) {
167 return false;
168 }
169 IPatternMatch otherSig = (IPatternMatch) obj;
170 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
171 }
172 }
173
174 @Override
175 public RedundantInstancesOnSameHost specification() {
176 return RedundantInstancesOnSameHost.instance();
177 }
178
179 /**
180 * Returns an empty, mutable match.
181 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
182 *
183 * @return the empty match.
184 *
185 */
186 public static RedundantInstancesOnSameHost.Match newEmptyMatch() {
187 return new Mutable(null);
188 }
189
190 /**
191 * Returns a mutable (partial) match.
192 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
193 *
194 * @param pReq the fixed value of pattern parameter Req, or null if not bound.
195 * @return the new, mutable (partial) match object.
196 *
197 */
198 public static RedundantInstancesOnSameHost.Match newMutableMatch(final Requirement pReq) {
199 return new Mutable(pReq);
200 }
201
202 /**
203 * Returns a new (partial) match.
204 * This can be used e.g. to call the matcher with a partial match.
205 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
206 * @param pReq the fixed value of pattern parameter Req, or null if not bound.
207 * @return the (partial) match object.
208 *
209 */
210 public static RedundantInstancesOnSameHost.Match newMatch(final Requirement pReq) {
211 return new Immutable(pReq);
212 }
213
214 private static final class Mutable extends RedundantInstancesOnSameHost.Match {
215 Mutable(final Requirement pReq) {
216 super(pReq);
217 }
218
219 @Override
220 public boolean isMutable() {
221 return true;
222 }
223 }
224
225 private static final class Immutable extends RedundantInstancesOnSameHost.Match {
226 Immutable(final Requirement pReq) {
227 super(pReq);
228 }
229
230 @Override
231 public boolean isMutable() {
232 return false;
233 }
234 }
235 }
236
237 /**
238 * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.redundantInstancesOnSameHost pattern,
239 * providing pattern-specific query methods.
240 *
241 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
242 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
243 *
244 * <p>Matches of the pattern will be represented as {@link Match}.
245 *
246 * <p>Original source:
247 * <code><pre>
248 * {@literal @}Constraint(severity = "error", key = {Req},
249 * message = "Redundant instances must not be allocated to the same host.")
250 * pattern redundantInstancesOnSameHost(Req : Requirement) {
251 * Requirement.instances(Req, App1);
252 * Requirement.instances(Req, App2);
253 * App1 != App2;
254 * ApplicationInstance.allocatedTo(App1, Host);
255 * ApplicationInstance.allocatedTo(App2, Host);
256 * }
257 * </pre></code>
258 *
259 * @see Match
260 * @see RedundantInstancesOnSameHost
261 *
262 */
263 public static class Matcher extends BaseMatcher<RedundantInstancesOnSameHost.Match> {
264 /**
265 * Initializes the pattern matcher within an existing VIATRA Query engine.
266 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
267 *
268 * @param engine the existing VIATRA Query engine in which this matcher will be created.
269 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
270 *
271 */
272 public static RedundantInstancesOnSameHost.Matcher on(final ViatraQueryEngine engine) {
273 // check if matcher already exists
274 Matcher matcher = engine.getExistingMatcher(querySpecification());
275 if (matcher == null) {
276 matcher = (Matcher)engine.getMatcher(querySpecification());
277 }
278 return matcher;
279 }
280
281 /**
282 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
283 * @return an initialized matcher
284 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
285 *
286 */
287 public static RedundantInstancesOnSameHost.Matcher create() {
288 return new Matcher();
289 }
290
291 private static final int POSITION_REQ = 0;
292
293 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(RedundantInstancesOnSameHost.Matcher.class);
294
295 /**
296 * Initializes the pattern matcher within an existing VIATRA Query engine.
297 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
298 *
299 * @param engine the existing VIATRA Query engine in which this matcher will be created.
300 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
301 *
302 */
303 private Matcher() {
304 super(querySpecification());
305 }
306
307 /**
308 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
309 * @param pReq the fixed value of pattern parameter Req, or null if not bound.
310 * @return matches represented as a Match object.
311 *
312 */
313 public Collection<RedundantInstancesOnSameHost.Match> getAllMatches(final Requirement pReq) {
314 return rawStreamAllMatches(new Object[]{pReq}).collect(Collectors.toSet());
315 }
316
317 /**
318 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
319 * </p>
320 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
321 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
322 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
323 * @param pReq the fixed value of pattern parameter Req, or null if not bound.
324 * @return a stream of matches represented as a Match object.
325 *
326 */
327 public Stream<RedundantInstancesOnSameHost.Match> streamAllMatches(final Requirement pReq) {
328 return rawStreamAllMatches(new Object[]{pReq});
329 }
330
331 /**
332 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
333 * Neither determinism nor randomness of selection is guaranteed.
334 * @param pReq the fixed value of pattern parameter Req, or null if not bound.
335 * @return a match represented as a Match object, or null if no match is found.
336 *
337 */
338 public Optional<RedundantInstancesOnSameHost.Match> getOneArbitraryMatch(final Requirement pReq) {
339 return rawGetOneArbitraryMatch(new Object[]{pReq});
340 }
341
342 /**
343 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
344 * under any possible substitution of the unspecified parameters (if any).
345 * @param pReq the fixed value of pattern parameter Req, or null if not bound.
346 * @return true if the input is a valid (partial) match of the pattern.
347 *
348 */
349 public boolean hasMatch(final Requirement pReq) {
350 return rawHasMatch(new Object[]{pReq});
351 }
352
353 /**
354 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
355 * @param pReq the fixed value of pattern parameter Req, or null if not bound.
356 * @return the number of pattern matches found.
357 *
358 */
359 public int countMatches(final Requirement pReq) {
360 return rawCountMatches(new Object[]{pReq});
361 }
362
363 /**
364 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
365 * Neither determinism nor randomness of selection is guaranteed.
366 * @param pReq the fixed value of pattern parameter Req, or null if not bound.
367 * @param processor the action that will process the selected match.
368 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
369 *
370 */
371 public boolean forOneArbitraryMatch(final Requirement pReq, final Consumer<? super RedundantInstancesOnSameHost.Match> processor) {
372 return rawForOneArbitraryMatch(new Object[]{pReq}, processor);
373 }
374
375 /**
376 * Returns a new (partial) match.
377 * This can be used e.g. to call the matcher with a partial match.
378 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
379 * @param pReq the fixed value of pattern parameter Req, or null if not bound.
380 * @return the (partial) match object.
381 *
382 */
383 public RedundantInstancesOnSameHost.Match newMatch(final Requirement pReq) {
384 return RedundantInstancesOnSameHost.Match.newMatch(pReq);
385 }
386
387 /**
388 * Retrieve the set of values that occur in matches for Req.
389 * @return the Set of all values or empty set if there are no matches
390 *
391 */
392 protected Stream<Requirement> rawStreamAllValuesOfReq(final Object[] parameters) {
393 return rawStreamAllValues(POSITION_REQ, parameters).map(Requirement.class::cast);
394 }
395
396 /**
397 * Retrieve the set of values that occur in matches for Req.
398 * @return the Set of all values or empty set if there are no matches
399 *
400 */
401 public Set<Requirement> getAllValuesOfReq() {
402 return rawStreamAllValuesOfReq(emptyArray()).collect(Collectors.toSet());
403 }
404
405 /**
406 * Retrieve the set of values that occur in matches for Req.
407 * @return the Set of all values or empty set if there are no matches
408 *
409 */
410 public Stream<Requirement> streamAllValuesOfReq() {
411 return rawStreamAllValuesOfReq(emptyArray());
412 }
413
414 @Override
415 protected RedundantInstancesOnSameHost.Match tupleToMatch(final Tuple t) {
416 try {
417 return RedundantInstancesOnSameHost.Match.newMatch((Requirement) t.get(POSITION_REQ));
418 } catch(ClassCastException e) {
419 LOGGER.error("Element(s) in tuple not properly typed!",e);
420 return null;
421 }
422 }
423
424 @Override
425 protected RedundantInstancesOnSameHost.Match arrayToMatch(final Object[] match) {
426 try {
427 return RedundantInstancesOnSameHost.Match.newMatch((Requirement) match[POSITION_REQ]);
428 } catch(ClassCastException e) {
429 LOGGER.error("Element(s) in array not properly typed!",e);
430 return null;
431 }
432 }
433
434 @Override
435 protected RedundantInstancesOnSameHost.Match arrayToMatchMutable(final Object[] match) {
436 try {
437 return RedundantInstancesOnSameHost.Match.newMutableMatch((Requirement) match[POSITION_REQ]);
438 } catch(ClassCastException e) {
439 LOGGER.error("Element(s) in array not properly typed!",e);
440 return null;
441 }
442 }
443
444 /**
445 * @return the singleton instance of the query specification of this pattern
446 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
447 *
448 */
449 public static IQuerySpecification<RedundantInstancesOnSameHost.Matcher> querySpecification() {
450 return RedundantInstancesOnSameHost.instance();
451 }
452 }
453
454 private RedundantInstancesOnSameHost() {
455 super(GeneratedPQuery.INSTANCE);
456 }
457
458 /**
459 * @return the singleton instance of the query specification
460 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
461 *
462 */
463 public static RedundantInstancesOnSameHost instance() {
464 try{
465 return LazyHolder.INSTANCE;
466 } catch (ExceptionInInitializerError err) {
467 throw processInitializerError(err);
468 }
469 }
470
471 @Override
472 protected RedundantInstancesOnSameHost.Matcher instantiate(final ViatraQueryEngine engine) {
473 return RedundantInstancesOnSameHost.Matcher.on(engine);
474 }
475
476 @Override
477 public RedundantInstancesOnSameHost.Matcher instantiate() {
478 return RedundantInstancesOnSameHost.Matcher.create();
479 }
480
481 @Override
482 public RedundantInstancesOnSameHost.Match newEmptyMatch() {
483 return RedundantInstancesOnSameHost.Match.newEmptyMatch();
484 }
485
486 @Override
487 public RedundantInstancesOnSameHost.Match newMatch(final Object... parameters) {
488 return RedundantInstancesOnSameHost.Match.newMatch((hu.bme.mit.inf.dslreasoner.domains.cps.Requirement) parameters[0]);
489 }
490
491 /**
492 * Inner class allowing the singleton instance of {@link RedundantInstancesOnSameHost} to be created
493 * <b>not</b> at the class load time of the outer class,
494 * but rather at the first call to {@link RedundantInstancesOnSameHost#instance()}.
495 *
496 * <p> This workaround is required e.g. to support recursion.
497 *
498 */
499 private static class LazyHolder {
500 private static final RedundantInstancesOnSameHost INSTANCE = new RedundantInstancesOnSameHost();
501
502 /**
503 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
504 * This initialization order is required to support indirect recursion.
505 *
506 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
507 *
508 */
509 private static final Object STATIC_INITIALIZER = ensureInitialized();
510
511 public static Object ensureInitialized() {
512 INSTANCE.ensureInitializedInternal();
513 return null;
514 }
515 }
516
517 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
518 private static final RedundantInstancesOnSameHost.GeneratedPQuery INSTANCE = new GeneratedPQuery();
519
520 private final PParameter parameter_Req = new PParameter("Req", "hu.bme.mit.inf.dslreasoner.domains.cps.Requirement", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "Requirement")), PParameterDirection.INOUT);
521
522 private final List<PParameter> parameters = Arrays.asList(parameter_Req);
523
524 private GeneratedPQuery() {
525 super(PVisibility.PUBLIC);
526 }
527
528 @Override
529 public String getFullyQualifiedName() {
530 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.redundantInstancesOnSameHost";
531 }
532
533 @Override
534 public List<String> getParameterNames() {
535 return Arrays.asList("Req");
536 }
537
538 @Override
539 public List<PParameter> getParameters() {
540 return parameters;
541 }
542
543 @Override
544 public Set<PBody> doGetContainedBodies() {
545 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
546 Set<PBody> bodies = new LinkedHashSet<>();
547 {
548 PBody body = new PBody(this);
549 PVariable var_Req = body.getOrCreateVariableByName("Req");
550 PVariable var_App1 = body.getOrCreateVariableByName("App1");
551 PVariable var_App2 = body.getOrCreateVariableByName("App2");
552 PVariable var_Host = body.getOrCreateVariableByName("Host");
553 new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "Requirement")));
554 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
555 new ExportedParameter(body, var_Req, parameter_Req)
556 ));
557 // Requirement.instances(Req, App1)
558 new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "Requirement")));
559 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
560 new TypeConstraint(body, Tuples.flatTupleOf(var_Req, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "Requirement", "instances")));
561 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance")));
562 new Equality(body, var__virtual_0_, var_App1);
563 // Requirement.instances(Req, App2)
564 new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "Requirement")));
565 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
566 new TypeConstraint(body, Tuples.flatTupleOf(var_Req, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "Requirement", "instances")));
567 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance")));
568 new Equality(body, var__virtual_1_, var_App2);
569 // App1 != App2
570 new Inequality(body, var_App1, var_App2);
571 // ApplicationInstance.allocatedTo(App1, Host)
572 new TypeConstraint(body, Tuples.flatTupleOf(var_App1), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance")));
573 PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}");
574 new TypeConstraint(body, Tuples.flatTupleOf(var_App1, var__virtual_2_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ApplicationInstance", "allocatedTo")));
575 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance")));
576 new Equality(body, var__virtual_2_, var_Host);
577 // ApplicationInstance.allocatedTo(App2, Host)
578 new TypeConstraint(body, Tuples.flatTupleOf(var_App2), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance")));
579 PVariable var__virtual_3_ = body.getOrCreateVariableByName(".virtual{3}");
580 new TypeConstraint(body, Tuples.flatTupleOf(var_App2, var__virtual_3_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ApplicationInstance", "allocatedTo")));
581 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_3_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance")));
582 new Equality(body, var__virtual_3_, var_Host);
583 bodies.add(body);
584 }
585 {
586 PAnnotation annotation = new PAnnotation("Constraint");
587 annotation.addAttribute("severity", "error");
588 annotation.addAttribute("key", Arrays.asList(new Object[] {
589 new ParameterReference("Req")
590 }));
591 annotation.addAttribute("message", "Redundant instances must not be allocated to the same host.");
592 addAnnotation(annotation);
593 }
594 return bodies;
595 }
596 }
597}
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/RemoveHostInstance.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/RemoveHostInstance.java
new file mode 100644
index 00000000..ed3c903c
--- /dev/null
+++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/RemoveHostInstance.java
@@ -0,0 +1,589 @@
1/**
2 * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql
3 */
4package hu.bme.mit.inf.dslreasoner.domains.cps.queries;
5
6import hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance;
7import java.util.Arrays;
8import java.util.Collection;
9import java.util.Collections;
10import java.util.LinkedHashSet;
11import java.util.List;
12import java.util.Objects;
13import java.util.Optional;
14import java.util.Set;
15import java.util.function.Consumer;
16import java.util.stream.Collectors;
17import java.util.stream.Stream;
18import org.apache.log4j.Logger;
19import org.eclipse.emf.ecore.EClass;
20import org.eclipse.viatra.query.runtime.api.IPatternMatch;
21import org.eclipse.viatra.query.runtime.api.IQuerySpecification;
22import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine;
23import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
24import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification;
25import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher;
26import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch;
27import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey;
28import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey;
29import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
30import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
31import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
32import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality;
33import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
34import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.NegativePatternCall;
35import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
36import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
37import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
38import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
39import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
40import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
41import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
42
43/**
44 * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
45 *
46 * <p>Original source:
47 * <code><pre>
48 * pattern removeHostInstance(HostInstance : HostInstance) {
49 * neg HostInstance.applications(HostInstance, _);
50 * }
51 * </pre></code>
52 *
53 * @see Matcher
54 * @see Match
55 *
56 */
57@SuppressWarnings("all")
58public final class RemoveHostInstance extends BaseGeneratedEMFQuerySpecification<RemoveHostInstance.Matcher> {
59 /**
60 * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.removeHostInstance pattern,
61 * to be used in conjunction with {@link Matcher}.
62 *
63 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
64 * Each instance is a (possibly partial) substitution of pattern parameters,
65 * usable to represent a match of the pattern in the result of a query,
66 * or to specify the bound (fixed) input parameters when issuing a query.
67 *
68 * @see Matcher
69 *
70 */
71 public static abstract class Match extends BasePatternMatch {
72 private HostInstance fHostInstance;
73
74 private static List<String> parameterNames = makeImmutableList("HostInstance");
75
76 private Match(final HostInstance pHostInstance) {
77 this.fHostInstance = pHostInstance;
78 }
79
80 @Override
81 public Object get(final String parameterName) {
82 switch(parameterName) {
83 case "HostInstance": return this.fHostInstance;
84 default: return null;
85 }
86 }
87
88 @Override
89 public Object get(final int index) {
90 switch(index) {
91 case 0: return this.fHostInstance;
92 default: return null;
93 }
94 }
95
96 public HostInstance getHostInstance() {
97 return this.fHostInstance;
98 }
99
100 @Override
101 public boolean set(final String parameterName, final Object newValue) {
102 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
103 if ("HostInstance".equals(parameterName) ) {
104 this.fHostInstance = (HostInstance) newValue;
105 return true;
106 }
107 return false;
108 }
109
110 public void setHostInstance(final HostInstance pHostInstance) {
111 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
112 this.fHostInstance = pHostInstance;
113 }
114
115 @Override
116 public String patternName() {
117 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.removeHostInstance";
118 }
119
120 @Override
121 public List<String> parameterNames() {
122 return RemoveHostInstance.Match.parameterNames;
123 }
124
125 @Override
126 public Object[] toArray() {
127 return new Object[]{fHostInstance};
128 }
129
130 @Override
131 public RemoveHostInstance.Match toImmutable() {
132 return isMutable() ? newMatch(fHostInstance) : this;
133 }
134
135 @Override
136 public String prettyPrint() {
137 StringBuilder result = new StringBuilder();
138 result.append("\"HostInstance\"=" + prettyPrintValue(fHostInstance));
139 return result.toString();
140 }
141
142 @Override
143 public int hashCode() {
144 return Objects.hash(fHostInstance);
145 }
146
147 @Override
148 public boolean equals(final Object obj) {
149 if (this == obj)
150 return true;
151 if (obj == null) {
152 return false;
153 }
154 if ((obj instanceof RemoveHostInstance.Match)) {
155 RemoveHostInstance.Match other = (RemoveHostInstance.Match) obj;
156 return Objects.equals(fHostInstance, other.fHostInstance);
157 } else {
158 // this should be infrequent
159 if (!(obj instanceof IPatternMatch)) {
160 return false;
161 }
162 IPatternMatch otherSig = (IPatternMatch) obj;
163 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
164 }
165 }
166
167 @Override
168 public RemoveHostInstance specification() {
169 return RemoveHostInstance.instance();
170 }
171
172 /**
173 * Returns an empty, mutable match.
174 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
175 *
176 * @return the empty match.
177 *
178 */
179 public static RemoveHostInstance.Match newEmptyMatch() {
180 return new Mutable(null);
181 }
182
183 /**
184 * Returns a mutable (partial) match.
185 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
186 *
187 * @param pHostInstance the fixed value of pattern parameter HostInstance, or null if not bound.
188 * @return the new, mutable (partial) match object.
189 *
190 */
191 public static RemoveHostInstance.Match newMutableMatch(final HostInstance pHostInstance) {
192 return new Mutable(pHostInstance);
193 }
194
195 /**
196 * Returns a new (partial) match.
197 * This can be used e.g. to call the matcher with a partial match.
198 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
199 * @param pHostInstance the fixed value of pattern parameter HostInstance, or null if not bound.
200 * @return the (partial) match object.
201 *
202 */
203 public static RemoveHostInstance.Match newMatch(final HostInstance pHostInstance) {
204 return new Immutable(pHostInstance);
205 }
206
207 private static final class Mutable extends RemoveHostInstance.Match {
208 Mutable(final HostInstance pHostInstance) {
209 super(pHostInstance);
210 }
211
212 @Override
213 public boolean isMutable() {
214 return true;
215 }
216 }
217
218 private static final class Immutable extends RemoveHostInstance.Match {
219 Immutable(final HostInstance pHostInstance) {
220 super(pHostInstance);
221 }
222
223 @Override
224 public boolean isMutable() {
225 return false;
226 }
227 }
228 }
229
230 /**
231 * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.removeHostInstance pattern,
232 * providing pattern-specific query methods.
233 *
234 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
235 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
236 *
237 * <p>Matches of the pattern will be represented as {@link Match}.
238 *
239 * <p>Original source:
240 * <code><pre>
241 * pattern removeHostInstance(HostInstance : HostInstance) {
242 * neg HostInstance.applications(HostInstance, _);
243 * }
244 * </pre></code>
245 *
246 * @see Match
247 * @see RemoveHostInstance
248 *
249 */
250 public static class Matcher extends BaseMatcher<RemoveHostInstance.Match> {
251 /**
252 * Initializes the pattern matcher within an existing VIATRA Query engine.
253 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
254 *
255 * @param engine the existing VIATRA Query engine in which this matcher will be created.
256 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
257 *
258 */
259 public static RemoveHostInstance.Matcher on(final ViatraQueryEngine engine) {
260 // check if matcher already exists
261 Matcher matcher = engine.getExistingMatcher(querySpecification());
262 if (matcher == null) {
263 matcher = (Matcher)engine.getMatcher(querySpecification());
264 }
265 return matcher;
266 }
267
268 /**
269 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
270 * @return an initialized matcher
271 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
272 *
273 */
274 public static RemoveHostInstance.Matcher create() {
275 return new Matcher();
276 }
277
278 private static final int POSITION_HOSTINSTANCE = 0;
279
280 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(RemoveHostInstance.Matcher.class);
281
282 /**
283 * Initializes the pattern matcher within an existing VIATRA Query engine.
284 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
285 *
286 * @param engine the existing VIATRA Query engine in which this matcher will be created.
287 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
288 *
289 */
290 private Matcher() {
291 super(querySpecification());
292 }
293
294 /**
295 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
296 * @param pHostInstance the fixed value of pattern parameter HostInstance, or null if not bound.
297 * @return matches represented as a Match object.
298 *
299 */
300 public Collection<RemoveHostInstance.Match> getAllMatches(final HostInstance pHostInstance) {
301 return rawStreamAllMatches(new Object[]{pHostInstance}).collect(Collectors.toSet());
302 }
303
304 /**
305 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
306 * </p>
307 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
308 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
309 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
310 * @param pHostInstance the fixed value of pattern parameter HostInstance, or null if not bound.
311 * @return a stream of matches represented as a Match object.
312 *
313 */
314 public Stream<RemoveHostInstance.Match> streamAllMatches(final HostInstance pHostInstance) {
315 return rawStreamAllMatches(new Object[]{pHostInstance});
316 }
317
318 /**
319 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
320 * Neither determinism nor randomness of selection is guaranteed.
321 * @param pHostInstance the fixed value of pattern parameter HostInstance, or null if not bound.
322 * @return a match represented as a Match object, or null if no match is found.
323 *
324 */
325 public Optional<RemoveHostInstance.Match> getOneArbitraryMatch(final HostInstance pHostInstance) {
326 return rawGetOneArbitraryMatch(new Object[]{pHostInstance});
327 }
328
329 /**
330 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
331 * under any possible substitution of the unspecified parameters (if any).
332 * @param pHostInstance the fixed value of pattern parameter HostInstance, or null if not bound.
333 * @return true if the input is a valid (partial) match of the pattern.
334 *
335 */
336 public boolean hasMatch(final HostInstance pHostInstance) {
337 return rawHasMatch(new Object[]{pHostInstance});
338 }
339
340 /**
341 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
342 * @param pHostInstance the fixed value of pattern parameter HostInstance, or null if not bound.
343 * @return the number of pattern matches found.
344 *
345 */
346 public int countMatches(final HostInstance pHostInstance) {
347 return rawCountMatches(new Object[]{pHostInstance});
348 }
349
350 /**
351 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
352 * Neither determinism nor randomness of selection is guaranteed.
353 * @param pHostInstance the fixed value of pattern parameter HostInstance, or null if not bound.
354 * @param processor the action that will process the selected match.
355 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
356 *
357 */
358 public boolean forOneArbitraryMatch(final HostInstance pHostInstance, final Consumer<? super RemoveHostInstance.Match> processor) {
359 return rawForOneArbitraryMatch(new Object[]{pHostInstance}, processor);
360 }
361
362 /**
363 * Returns a new (partial) match.
364 * This can be used e.g. to call the matcher with a partial match.
365 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
366 * @param pHostInstance the fixed value of pattern parameter HostInstance, or null if not bound.
367 * @return the (partial) match object.
368 *
369 */
370 public RemoveHostInstance.Match newMatch(final HostInstance pHostInstance) {
371 return RemoveHostInstance.Match.newMatch(pHostInstance);
372 }
373
374 /**
375 * Retrieve the set of values that occur in matches for HostInstance.
376 * @return the Set of all values or empty set if there are no matches
377 *
378 */
379 protected Stream<HostInstance> rawStreamAllValuesOfHostInstance(final Object[] parameters) {
380 return rawStreamAllValues(POSITION_HOSTINSTANCE, parameters).map(HostInstance.class::cast);
381 }
382
383 /**
384 * Retrieve the set of values that occur in matches for HostInstance.
385 * @return the Set of all values or empty set if there are no matches
386 *
387 */
388 public Set<HostInstance> getAllValuesOfHostInstance() {
389 return rawStreamAllValuesOfHostInstance(emptyArray()).collect(Collectors.toSet());
390 }
391
392 /**
393 * Retrieve the set of values that occur in matches for HostInstance.
394 * @return the Set of all values or empty set if there are no matches
395 *
396 */
397 public Stream<HostInstance> streamAllValuesOfHostInstance() {
398 return rawStreamAllValuesOfHostInstance(emptyArray());
399 }
400
401 @Override
402 protected RemoveHostInstance.Match tupleToMatch(final Tuple t) {
403 try {
404 return RemoveHostInstance.Match.newMatch((HostInstance) t.get(POSITION_HOSTINSTANCE));
405 } catch(ClassCastException e) {
406 LOGGER.error("Element(s) in tuple not properly typed!",e);
407 return null;
408 }
409 }
410
411 @Override
412 protected RemoveHostInstance.Match arrayToMatch(final Object[] match) {
413 try {
414 return RemoveHostInstance.Match.newMatch((HostInstance) match[POSITION_HOSTINSTANCE]);
415 } catch(ClassCastException e) {
416 LOGGER.error("Element(s) in array not properly typed!",e);
417 return null;
418 }
419 }
420
421 @Override
422 protected RemoveHostInstance.Match arrayToMatchMutable(final Object[] match) {
423 try {
424 return RemoveHostInstance.Match.newMutableMatch((HostInstance) match[POSITION_HOSTINSTANCE]);
425 } catch(ClassCastException e) {
426 LOGGER.error("Element(s) in array not properly typed!",e);
427 return null;
428 }
429 }
430
431 /**
432 * @return the singleton instance of the query specification of this pattern
433 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
434 *
435 */
436 public static IQuerySpecification<RemoveHostInstance.Matcher> querySpecification() {
437 return RemoveHostInstance.instance();
438 }
439 }
440
441 private RemoveHostInstance() {
442 super(GeneratedPQuery.INSTANCE);
443 }
444
445 /**
446 * @return the singleton instance of the query specification
447 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
448 *
449 */
450 public static RemoveHostInstance instance() {
451 try{
452 return LazyHolder.INSTANCE;
453 } catch (ExceptionInInitializerError err) {
454 throw processInitializerError(err);
455 }
456 }
457
458 @Override
459 protected RemoveHostInstance.Matcher instantiate(final ViatraQueryEngine engine) {
460 return RemoveHostInstance.Matcher.on(engine);
461 }
462
463 @Override
464 public RemoveHostInstance.Matcher instantiate() {
465 return RemoveHostInstance.Matcher.create();
466 }
467
468 @Override
469 public RemoveHostInstance.Match newEmptyMatch() {
470 return RemoveHostInstance.Match.newEmptyMatch();
471 }
472
473 @Override
474 public RemoveHostInstance.Match newMatch(final Object... parameters) {
475 return RemoveHostInstance.Match.newMatch((hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance) parameters[0]);
476 }
477
478 /**
479 * Inner class allowing the singleton instance of {@link RemoveHostInstance} to be created
480 * <b>not</b> at the class load time of the outer class,
481 * but rather at the first call to {@link RemoveHostInstance#instance()}.
482 *
483 * <p> This workaround is required e.g. to support recursion.
484 *
485 */
486 private static class LazyHolder {
487 private static final RemoveHostInstance INSTANCE = new RemoveHostInstance();
488
489 /**
490 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
491 * This initialization order is required to support indirect recursion.
492 *
493 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
494 *
495 */
496 private static final Object STATIC_INITIALIZER = ensureInitialized();
497
498 public static Object ensureInitialized() {
499 INSTANCE.ensureInitializedInternal();
500 return null;
501 }
502 }
503
504 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
505 private static final RemoveHostInstance.GeneratedPQuery INSTANCE = new GeneratedPQuery();
506
507 private final PParameter parameter_HostInstance = new PParameter("HostInstance", "hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "HostInstance")), PParameterDirection.INOUT);
508
509 private final List<PParameter> parameters = Arrays.asList(parameter_HostInstance);
510
511 private class Embedded_1_HostInstance_applications extends BaseGeneratedEMFPQuery {
512 private final PParameter parameter_p0 = new PParameter("p0", "hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "HostInstance")), PParameterDirection.INOUT);
513
514 private final PParameter parameter_p1 = new PParameter("p1", "hu.bme.mit.inf.dslreasoner.domains.cps.ApplicationInstance", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "ApplicationInstance")), PParameterDirection.INOUT);
515
516 private final List<PParameter> embeddedParameters = Arrays.asList(parameter_p0, parameter_p1);
517
518 public Embedded_1_HostInstance_applications() {
519 super(PVisibility.EMBEDDED);
520 }
521
522 @Override
523 public String getFullyQualifiedName() {
524 return GeneratedPQuery.this.getFullyQualifiedName() + "$Embedded_1_HostInstance_applications";
525 }
526
527 @Override
528 public List<PParameter> getParameters() {
529 return embeddedParameters;
530 }
531
532 @Override
533 public Set<PBody> doGetContainedBodies() {
534 PBody body = new PBody(this);
535 PVariable var_p0 = body.getOrCreateVariableByName("p0");
536 PVariable var_p1 = body.getOrCreateVariableByName("p1");
537 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
538 new ExportedParameter(body, var_p0, parameter_p0),
539 new ExportedParameter(body, var_p1, parameter_p1)
540 ));
541 // HostInstance.applications(HostInstance, _)
542 new TypeConstraint(body, Tuples.flatTupleOf(var_p0), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance")));
543 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
544 new TypeConstraint(body, Tuples.flatTupleOf(var_p0, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "HostInstance", "applications")));
545 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance")));
546 new Equality(body, var__virtual_0_, var_p1);
547 return Collections.singleton(body);
548 }
549 }
550
551 private GeneratedPQuery() {
552 super(PVisibility.PUBLIC);
553 }
554
555 @Override
556 public String getFullyQualifiedName() {
557 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.removeHostInstance";
558 }
559
560 @Override
561 public List<String> getParameterNames() {
562 return Arrays.asList("HostInstance");
563 }
564
565 @Override
566 public List<PParameter> getParameters() {
567 return parameters;
568 }
569
570 @Override
571 public Set<PBody> doGetContainedBodies() {
572 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
573 Set<PBody> bodies = new LinkedHashSet<>();
574 {
575 PBody body = new PBody(this);
576 PVariable var_HostInstance = body.getOrCreateVariableByName("HostInstance");
577 PVariable var___0_ = body.getOrCreateVariableByName("_<0>");
578 new TypeConstraint(body, Tuples.flatTupleOf(var_HostInstance), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance")));
579 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
580 new ExportedParameter(body, var_HostInstance, parameter_HostInstance)
581 ));
582 // neg HostInstance.applications(HostInstance, _)
583 new NegativePatternCall(body, Tuples.flatTupleOf(var_HostInstance, var___0_), new RemoveHostInstance.GeneratedPQuery.Embedded_1_HostInstance_applications());
584 bodies.add(body);
585 }
586 return bodies;
587 }
588 }
589}
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/RequirementNotSatisfied.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/RequirementNotSatisfied.java
new file mode 100644
index 00000000..eaceec5f
--- /dev/null
+++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/RequirementNotSatisfied.java
@@ -0,0 +1,607 @@
1/**
2 * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql
3 */
4package hu.bme.mit.inf.dslreasoner.domains.cps.queries;
5
6import hu.bme.mit.inf.dslreasoner.domains.cps.Requirement;
7import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.SatisfyingInstance;
8import java.util.Arrays;
9import java.util.Collection;
10import java.util.LinkedHashSet;
11import java.util.List;
12import java.util.Objects;
13import java.util.Optional;
14import java.util.Set;
15import java.util.function.Consumer;
16import java.util.stream.Collectors;
17import java.util.stream.Stream;
18import org.apache.log4j.Logger;
19import org.eclipse.emf.ecore.EClass;
20import org.eclipse.emf.ecore.EDataType;
21import org.eclipse.viatra.query.runtime.api.IPatternMatch;
22import org.eclipse.viatra.query.runtime.api.IQuerySpecification;
23import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine;
24import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
25import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification;
26import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher;
27import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch;
28import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey;
29import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey;
30import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey;
31import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
32import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator;
33import org.eclipse.viatra.query.runtime.matchers.psystem.IValueProvider;
34import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
35import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
36import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation;
37import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference;
38import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality;
39import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
40import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation;
41import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.PatternMatchCounter;
42import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
43import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
44import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
45import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
46import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
47import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
48import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
49
50/**
51 * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
52 *
53 * <p>Original source:
54 * <code><pre>
55 * {@literal @}Constraint(severity = "error", key = {Req},
56 * message = "Requirement is not satisfied by enough application instances.")
57 * pattern requirementNotSatisfied(Req : Requirement) {
58 * Instances == count find satisfyingInstance(Req, _);
59 * Requirement.count(Req, RequiredCount);
60 * check(Instances {@literal <} RequiredCount);
61 * }
62 * </pre></code>
63 *
64 * @see Matcher
65 * @see Match
66 *
67 */
68@SuppressWarnings("all")
69public final class RequirementNotSatisfied extends BaseGeneratedEMFQuerySpecification<RequirementNotSatisfied.Matcher> {
70 /**
71 * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.requirementNotSatisfied pattern,
72 * to be used in conjunction with {@link Matcher}.
73 *
74 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
75 * Each instance is a (possibly partial) substitution of pattern parameters,
76 * usable to represent a match of the pattern in the result of a query,
77 * or to specify the bound (fixed) input parameters when issuing a query.
78 *
79 * @see Matcher
80 *
81 */
82 public static abstract class Match extends BasePatternMatch {
83 private Requirement fReq;
84
85 private static List<String> parameterNames = makeImmutableList("Req");
86
87 private Match(final Requirement pReq) {
88 this.fReq = pReq;
89 }
90
91 @Override
92 public Object get(final String parameterName) {
93 switch(parameterName) {
94 case "Req": return this.fReq;
95 default: return null;
96 }
97 }
98
99 @Override
100 public Object get(final int index) {
101 switch(index) {
102 case 0: return this.fReq;
103 default: return null;
104 }
105 }
106
107 public Requirement getReq() {
108 return this.fReq;
109 }
110
111 @Override
112 public boolean set(final String parameterName, final Object newValue) {
113 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
114 if ("Req".equals(parameterName) ) {
115 this.fReq = (Requirement) newValue;
116 return true;
117 }
118 return false;
119 }
120
121 public void setReq(final Requirement pReq) {
122 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
123 this.fReq = pReq;
124 }
125
126 @Override
127 public String patternName() {
128 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.requirementNotSatisfied";
129 }
130
131 @Override
132 public List<String> parameterNames() {
133 return RequirementNotSatisfied.Match.parameterNames;
134 }
135
136 @Override
137 public Object[] toArray() {
138 return new Object[]{fReq};
139 }
140
141 @Override
142 public RequirementNotSatisfied.Match toImmutable() {
143 return isMutable() ? newMatch(fReq) : this;
144 }
145
146 @Override
147 public String prettyPrint() {
148 StringBuilder result = new StringBuilder();
149 result.append("\"Req\"=" + prettyPrintValue(fReq));
150 return result.toString();
151 }
152
153 @Override
154 public int hashCode() {
155 return Objects.hash(fReq);
156 }
157
158 @Override
159 public boolean equals(final Object obj) {
160 if (this == obj)
161 return true;
162 if (obj == null) {
163 return false;
164 }
165 if ((obj instanceof RequirementNotSatisfied.Match)) {
166 RequirementNotSatisfied.Match other = (RequirementNotSatisfied.Match) obj;
167 return Objects.equals(fReq, other.fReq);
168 } else {
169 // this should be infrequent
170 if (!(obj instanceof IPatternMatch)) {
171 return false;
172 }
173 IPatternMatch otherSig = (IPatternMatch) obj;
174 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
175 }
176 }
177
178 @Override
179 public RequirementNotSatisfied specification() {
180 return RequirementNotSatisfied.instance();
181 }
182
183 /**
184 * Returns an empty, mutable match.
185 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
186 *
187 * @return the empty match.
188 *
189 */
190 public static RequirementNotSatisfied.Match newEmptyMatch() {
191 return new Mutable(null);
192 }
193
194 /**
195 * Returns a mutable (partial) match.
196 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
197 *
198 * @param pReq the fixed value of pattern parameter Req, or null if not bound.
199 * @return the new, mutable (partial) match object.
200 *
201 */
202 public static RequirementNotSatisfied.Match newMutableMatch(final Requirement pReq) {
203 return new Mutable(pReq);
204 }
205
206 /**
207 * Returns a new (partial) match.
208 * This can be used e.g. to call the matcher with a partial match.
209 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
210 * @param pReq the fixed value of pattern parameter Req, or null if not bound.
211 * @return the (partial) match object.
212 *
213 */
214 public static RequirementNotSatisfied.Match newMatch(final Requirement pReq) {
215 return new Immutable(pReq);
216 }
217
218 private static final class Mutable extends RequirementNotSatisfied.Match {
219 Mutable(final Requirement pReq) {
220 super(pReq);
221 }
222
223 @Override
224 public boolean isMutable() {
225 return true;
226 }
227 }
228
229 private static final class Immutable extends RequirementNotSatisfied.Match {
230 Immutable(final Requirement pReq) {
231 super(pReq);
232 }
233
234 @Override
235 public boolean isMutable() {
236 return false;
237 }
238 }
239 }
240
241 /**
242 * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.requirementNotSatisfied pattern,
243 * providing pattern-specific query methods.
244 *
245 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
246 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
247 *
248 * <p>Matches of the pattern will be represented as {@link Match}.
249 *
250 * <p>Original source:
251 * <code><pre>
252 * {@literal @}Constraint(severity = "error", key = {Req},
253 * message = "Requirement is not satisfied by enough application instances.")
254 * pattern requirementNotSatisfied(Req : Requirement) {
255 * Instances == count find satisfyingInstance(Req, _);
256 * Requirement.count(Req, RequiredCount);
257 * check(Instances {@literal <} RequiredCount);
258 * }
259 * </pre></code>
260 *
261 * @see Match
262 * @see RequirementNotSatisfied
263 *
264 */
265 public static class Matcher extends BaseMatcher<RequirementNotSatisfied.Match> {
266 /**
267 * Initializes the pattern matcher within an existing VIATRA Query engine.
268 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
269 *
270 * @param engine the existing VIATRA Query engine in which this matcher will be created.
271 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
272 *
273 */
274 public static RequirementNotSatisfied.Matcher on(final ViatraQueryEngine engine) {
275 // check if matcher already exists
276 Matcher matcher = engine.getExistingMatcher(querySpecification());
277 if (matcher == null) {
278 matcher = (Matcher)engine.getMatcher(querySpecification());
279 }
280 return matcher;
281 }
282
283 /**
284 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
285 * @return an initialized matcher
286 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
287 *
288 */
289 public static RequirementNotSatisfied.Matcher create() {
290 return new Matcher();
291 }
292
293 private static final int POSITION_REQ = 0;
294
295 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(RequirementNotSatisfied.Matcher.class);
296
297 /**
298 * Initializes the pattern matcher within an existing VIATRA Query engine.
299 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
300 *
301 * @param engine the existing VIATRA Query engine in which this matcher will be created.
302 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
303 *
304 */
305 private Matcher() {
306 super(querySpecification());
307 }
308
309 /**
310 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
311 * @param pReq the fixed value of pattern parameter Req, or null if not bound.
312 * @return matches represented as a Match object.
313 *
314 */
315 public Collection<RequirementNotSatisfied.Match> getAllMatches(final Requirement pReq) {
316 return rawStreamAllMatches(new Object[]{pReq}).collect(Collectors.toSet());
317 }
318
319 /**
320 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
321 * </p>
322 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
323 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
324 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
325 * @param pReq the fixed value of pattern parameter Req, or null if not bound.
326 * @return a stream of matches represented as a Match object.
327 *
328 */
329 public Stream<RequirementNotSatisfied.Match> streamAllMatches(final Requirement pReq) {
330 return rawStreamAllMatches(new Object[]{pReq});
331 }
332
333 /**
334 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
335 * Neither determinism nor randomness of selection is guaranteed.
336 * @param pReq the fixed value of pattern parameter Req, or null if not bound.
337 * @return a match represented as a Match object, or null if no match is found.
338 *
339 */
340 public Optional<RequirementNotSatisfied.Match> getOneArbitraryMatch(final Requirement pReq) {
341 return rawGetOneArbitraryMatch(new Object[]{pReq});
342 }
343
344 /**
345 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
346 * under any possible substitution of the unspecified parameters (if any).
347 * @param pReq the fixed value of pattern parameter Req, or null if not bound.
348 * @return true if the input is a valid (partial) match of the pattern.
349 *
350 */
351 public boolean hasMatch(final Requirement pReq) {
352 return rawHasMatch(new Object[]{pReq});
353 }
354
355 /**
356 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
357 * @param pReq the fixed value of pattern parameter Req, or null if not bound.
358 * @return the number of pattern matches found.
359 *
360 */
361 public int countMatches(final Requirement pReq) {
362 return rawCountMatches(new Object[]{pReq});
363 }
364
365 /**
366 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
367 * Neither determinism nor randomness of selection is guaranteed.
368 * @param pReq the fixed value of pattern parameter Req, or null if not bound.
369 * @param processor the action that will process the selected match.
370 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
371 *
372 */
373 public boolean forOneArbitraryMatch(final Requirement pReq, final Consumer<? super RequirementNotSatisfied.Match> processor) {
374 return rawForOneArbitraryMatch(new Object[]{pReq}, processor);
375 }
376
377 /**
378 * Returns a new (partial) match.
379 * This can be used e.g. to call the matcher with a partial match.
380 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
381 * @param pReq the fixed value of pattern parameter Req, or null if not bound.
382 * @return the (partial) match object.
383 *
384 */
385 public RequirementNotSatisfied.Match newMatch(final Requirement pReq) {
386 return RequirementNotSatisfied.Match.newMatch(pReq);
387 }
388
389 /**
390 * Retrieve the set of values that occur in matches for Req.
391 * @return the Set of all values or empty set if there are no matches
392 *
393 */
394 protected Stream<Requirement> rawStreamAllValuesOfReq(final Object[] parameters) {
395 return rawStreamAllValues(POSITION_REQ, parameters).map(Requirement.class::cast);
396 }
397
398 /**
399 * Retrieve the set of values that occur in matches for Req.
400 * @return the Set of all values or empty set if there are no matches
401 *
402 */
403 public Set<Requirement> getAllValuesOfReq() {
404 return rawStreamAllValuesOfReq(emptyArray()).collect(Collectors.toSet());
405 }
406
407 /**
408 * Retrieve the set of values that occur in matches for Req.
409 * @return the Set of all values or empty set if there are no matches
410 *
411 */
412 public Stream<Requirement> streamAllValuesOfReq() {
413 return rawStreamAllValuesOfReq(emptyArray());
414 }
415
416 @Override
417 protected RequirementNotSatisfied.Match tupleToMatch(final Tuple t) {
418 try {
419 return RequirementNotSatisfied.Match.newMatch((Requirement) t.get(POSITION_REQ));
420 } catch(ClassCastException e) {
421 LOGGER.error("Element(s) in tuple not properly typed!",e);
422 return null;
423 }
424 }
425
426 @Override
427 protected RequirementNotSatisfied.Match arrayToMatch(final Object[] match) {
428 try {
429 return RequirementNotSatisfied.Match.newMatch((Requirement) match[POSITION_REQ]);
430 } catch(ClassCastException e) {
431 LOGGER.error("Element(s) in array not properly typed!",e);
432 return null;
433 }
434 }
435
436 @Override
437 protected RequirementNotSatisfied.Match arrayToMatchMutable(final Object[] match) {
438 try {
439 return RequirementNotSatisfied.Match.newMutableMatch((Requirement) match[POSITION_REQ]);
440 } catch(ClassCastException e) {
441 LOGGER.error("Element(s) in array not properly typed!",e);
442 return null;
443 }
444 }
445
446 /**
447 * @return the singleton instance of the query specification of this pattern
448 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
449 *
450 */
451 public static IQuerySpecification<RequirementNotSatisfied.Matcher> querySpecification() {
452 return RequirementNotSatisfied.instance();
453 }
454 }
455
456 private RequirementNotSatisfied() {
457 super(GeneratedPQuery.INSTANCE);
458 }
459
460 /**
461 * @return the singleton instance of the query specification
462 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
463 *
464 */
465 public static RequirementNotSatisfied instance() {
466 try{
467 return LazyHolder.INSTANCE;
468 } catch (ExceptionInInitializerError err) {
469 throw processInitializerError(err);
470 }
471 }
472
473 @Override
474 protected RequirementNotSatisfied.Matcher instantiate(final ViatraQueryEngine engine) {
475 return RequirementNotSatisfied.Matcher.on(engine);
476 }
477
478 @Override
479 public RequirementNotSatisfied.Matcher instantiate() {
480 return RequirementNotSatisfied.Matcher.create();
481 }
482
483 @Override
484 public RequirementNotSatisfied.Match newEmptyMatch() {
485 return RequirementNotSatisfied.Match.newEmptyMatch();
486 }
487
488 @Override
489 public RequirementNotSatisfied.Match newMatch(final Object... parameters) {
490 return RequirementNotSatisfied.Match.newMatch((hu.bme.mit.inf.dslreasoner.domains.cps.Requirement) parameters[0]);
491 }
492
493 /**
494 * Inner class allowing the singleton instance of {@link RequirementNotSatisfied} to be created
495 * <b>not</b> at the class load time of the outer class,
496 * but rather at the first call to {@link RequirementNotSatisfied#instance()}.
497 *
498 * <p> This workaround is required e.g. to support recursion.
499 *
500 */
501 private static class LazyHolder {
502 private static final RequirementNotSatisfied INSTANCE = new RequirementNotSatisfied();
503
504 /**
505 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
506 * This initialization order is required to support indirect recursion.
507 *
508 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
509 *
510 */
511 private static final Object STATIC_INITIALIZER = ensureInitialized();
512
513 public static Object ensureInitialized() {
514 INSTANCE.ensureInitializedInternal();
515 return null;
516 }
517 }
518
519 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
520 private static final RequirementNotSatisfied.GeneratedPQuery INSTANCE = new GeneratedPQuery();
521
522 private final PParameter parameter_Req = new PParameter("Req", "hu.bme.mit.inf.dslreasoner.domains.cps.Requirement", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "Requirement")), PParameterDirection.INOUT);
523
524 private final List<PParameter> parameters = Arrays.asList(parameter_Req);
525
526 private GeneratedPQuery() {
527 super(PVisibility.PUBLIC);
528 }
529
530 @Override
531 public String getFullyQualifiedName() {
532 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.requirementNotSatisfied";
533 }
534
535 @Override
536 public List<String> getParameterNames() {
537 return Arrays.asList("Req");
538 }
539
540 @Override
541 public List<PParameter> getParameters() {
542 return parameters;
543 }
544
545 @Override
546 public Set<PBody> doGetContainedBodies() {
547 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
548 Set<PBody> bodies = new LinkedHashSet<>();
549 {
550 PBody body = new PBody(this);
551 PVariable var_Req = body.getOrCreateVariableByName("Req");
552 PVariable var_Instances = body.getOrCreateVariableByName("Instances");
553 PVariable var___0_ = body.getOrCreateVariableByName("_<0>");
554 PVariable var_RequiredCount = body.getOrCreateVariableByName("RequiredCount");
555 new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "Requirement")));
556 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
557 new ExportedParameter(body, var_Req, parameter_Req)
558 ));
559 // Instances == count find satisfyingInstance(Req, _)
560 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
561 new PatternMatchCounter(body, Tuples.flatTupleOf(var_Req, var___0_), SatisfyingInstance.instance().getInternalQueryRepresentation(), var__virtual_0_);
562 new Equality(body, var_Instances, var__virtual_0_);
563 // Requirement.count(Req, RequiredCount)
564 new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "Requirement")));
565 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
566 new TypeConstraint(body, Tuples.flatTupleOf(var_Req, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "Requirement", "count")));
567 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt")));
568 new Equality(body, var__virtual_1_, var_RequiredCount);
569 // check(Instances < RequiredCount)
570 new ExpressionEvaluation(body, new IExpressionEvaluator() {
571
572 @Override
573 public String getShortDescription() {
574 return "Expression evaluation from pattern requirementNotSatisfied";
575 }
576
577 @Override
578 public Iterable<String> getInputParameterNames() {
579 return Arrays.asList("Instances", "RequiredCount");}
580
581 @Override
582 public Object evaluateExpression(IValueProvider provider) throws Exception {
583 Integer Instances = (Integer) provider.getValue("Instances");
584 Integer RequiredCount = (Integer) provider.getValue("RequiredCount");
585 return evaluateExpression_1_1(Instances, RequiredCount);
586 }
587 }, null);
588 bodies.add(body);
589 }
590 {
591 PAnnotation annotation = new PAnnotation("Constraint");
592 annotation.addAttribute("severity", "error");
593 annotation.addAttribute("key", Arrays.asList(new Object[] {
594 new ParameterReference("Req")
595 }));
596 annotation.addAttribute("message", "Requirement is not satisfied by enough application instances.");
597 addAnnotation(annotation);
598 }
599 return bodies;
600 }
601 }
602
603 private static boolean evaluateExpression_1_1(final Integer Instances, final Integer RequiredCount) {
604 boolean _lessThan = (Instances.compareTo(RequiredCount) < 0);
605 return _lessThan;
606 }
607}
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/ResourceRequirement.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/ResourceRequirement.java
new file mode 100644
index 00000000..23b578ea
--- /dev/null
+++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/ResourceRequirement.java
@@ -0,0 +1,841 @@
1/**
2 * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql
3 */
4package hu.bme.mit.inf.dslreasoner.domains.cps.queries;
5
6import hu.bme.mit.inf.dslreasoner.domains.cps.ApplicationInstance;
7import hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance;
8import java.util.Arrays;
9import java.util.Collection;
10import java.util.LinkedHashSet;
11import java.util.List;
12import java.util.Objects;
13import java.util.Optional;
14import java.util.Set;
15import java.util.function.Consumer;
16import java.util.stream.Collectors;
17import java.util.stream.Stream;
18import org.apache.log4j.Logger;
19import org.eclipse.emf.ecore.EClass;
20import org.eclipse.viatra.query.runtime.api.IPatternMatch;
21import org.eclipse.viatra.query.runtime.api.IQuerySpecification;
22import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine;
23import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
24import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification;
25import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher;
26import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch;
27import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey;
28import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey;
29import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
30import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
31import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
32import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality;
33import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
34import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
35import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
36import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
37import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
38import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
39import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
40import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
41
42/**
43 * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
44 *
45 * <p>Original source:
46 * <code><pre>
47 * pattern resourceRequirement(Host : HostInstance, App : ApplicationInstance, Req : ResourceRequirement) {
48 * ApplicationInstance.allocatedTo(App, Host);
49 * ApplicationInstance.type.requirements(App, Req);
50 * HostInstance.type(Host, HostType);
51 * ResourceRequirement.hostType(Req, HostType);
52 * }
53 * </pre></code>
54 *
55 * @see Matcher
56 * @see Match
57 *
58 */
59@SuppressWarnings("all")
60public final class ResourceRequirement extends BaseGeneratedEMFQuerySpecification<ResourceRequirement.Matcher> {
61 /**
62 * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.resourceRequirement pattern,
63 * to be used in conjunction with {@link Matcher}.
64 *
65 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
66 * Each instance is a (possibly partial) substitution of pattern parameters,
67 * usable to represent a match of the pattern in the result of a query,
68 * or to specify the bound (fixed) input parameters when issuing a query.
69 *
70 * @see Matcher
71 *
72 */
73 public static abstract class Match extends BasePatternMatch {
74 private HostInstance fHost;
75
76 private ApplicationInstance fApp;
77
78 private hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement fReq;
79
80 private static List<String> parameterNames = makeImmutableList("Host", "App", "Req");
81
82 private Match(final HostInstance pHost, final ApplicationInstance pApp, final hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement pReq) {
83 this.fHost = pHost;
84 this.fApp = pApp;
85 this.fReq = pReq;
86 }
87
88 @Override
89 public Object get(final String parameterName) {
90 switch(parameterName) {
91 case "Host": return this.fHost;
92 case "App": return this.fApp;
93 case "Req": return this.fReq;
94 default: return null;
95 }
96 }
97
98 @Override
99 public Object get(final int index) {
100 switch(index) {
101 case 0: return this.fHost;
102 case 1: return this.fApp;
103 case 2: return this.fReq;
104 default: return null;
105 }
106 }
107
108 public HostInstance getHost() {
109 return this.fHost;
110 }
111
112 public ApplicationInstance getApp() {
113 return this.fApp;
114 }
115
116 public hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement getReq() {
117 return this.fReq;
118 }
119
120 @Override
121 public boolean set(final String parameterName, final Object newValue) {
122 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
123 if ("Host".equals(parameterName) ) {
124 this.fHost = (HostInstance) newValue;
125 return true;
126 }
127 if ("App".equals(parameterName) ) {
128 this.fApp = (ApplicationInstance) newValue;
129 return true;
130 }
131 if ("Req".equals(parameterName) ) {
132 this.fReq = (hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement) newValue;
133 return true;
134 }
135 return false;
136 }
137
138 public void setHost(final HostInstance pHost) {
139 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
140 this.fHost = pHost;
141 }
142
143 public void setApp(final ApplicationInstance pApp) {
144 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
145 this.fApp = pApp;
146 }
147
148 public void setReq(final hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement pReq) {
149 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
150 this.fReq = pReq;
151 }
152
153 @Override
154 public String patternName() {
155 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.resourceRequirement";
156 }
157
158 @Override
159 public List<String> parameterNames() {
160 return ResourceRequirement.Match.parameterNames;
161 }
162
163 @Override
164 public Object[] toArray() {
165 return new Object[]{fHost, fApp, fReq};
166 }
167
168 @Override
169 public ResourceRequirement.Match toImmutable() {
170 return isMutable() ? newMatch(fHost, fApp, fReq) : this;
171 }
172
173 @Override
174 public String prettyPrint() {
175 StringBuilder result = new StringBuilder();
176 result.append("\"Host\"=" + prettyPrintValue(fHost) + ", ");
177 result.append("\"App\"=" + prettyPrintValue(fApp) + ", ");
178 result.append("\"Req\"=" + prettyPrintValue(fReq));
179 return result.toString();
180 }
181
182 @Override
183 public int hashCode() {
184 return Objects.hash(fHost, fApp, fReq);
185 }
186
187 @Override
188 public boolean equals(final Object obj) {
189 if (this == obj)
190 return true;
191 if (obj == null) {
192 return false;
193 }
194 if ((obj instanceof ResourceRequirement.Match)) {
195 ResourceRequirement.Match other = (ResourceRequirement.Match) obj;
196 return Objects.equals(fHost, other.fHost) && Objects.equals(fApp, other.fApp) && Objects.equals(fReq, other.fReq);
197 } else {
198 // this should be infrequent
199 if (!(obj instanceof IPatternMatch)) {
200 return false;
201 }
202 IPatternMatch otherSig = (IPatternMatch) obj;
203 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
204 }
205 }
206
207 @Override
208 public ResourceRequirement specification() {
209 return ResourceRequirement.instance();
210 }
211
212 /**
213 * Returns an empty, mutable match.
214 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
215 *
216 * @return the empty match.
217 *
218 */
219 public static ResourceRequirement.Match newEmptyMatch() {
220 return new Mutable(null, null, null);
221 }
222
223 /**
224 * Returns a mutable (partial) match.
225 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
226 *
227 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
228 * @param pApp the fixed value of pattern parameter App, or null if not bound.
229 * @param pReq the fixed value of pattern parameter Req, or null if not bound.
230 * @return the new, mutable (partial) match object.
231 *
232 */
233 public static ResourceRequirement.Match newMutableMatch(final HostInstance pHost, final ApplicationInstance pApp, final hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement pReq) {
234 return new Mutable(pHost, pApp, pReq);
235 }
236
237 /**
238 * Returns a new (partial) match.
239 * This can be used e.g. to call the matcher with a partial match.
240 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
241 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
242 * @param pApp the fixed value of pattern parameter App, or null if not bound.
243 * @param pReq the fixed value of pattern parameter Req, or null if not bound.
244 * @return the (partial) match object.
245 *
246 */
247 public static ResourceRequirement.Match newMatch(final HostInstance pHost, final ApplicationInstance pApp, final hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement pReq) {
248 return new Immutable(pHost, pApp, pReq);
249 }
250
251 private static final class Mutable extends ResourceRequirement.Match {
252 Mutable(final HostInstance pHost, final ApplicationInstance pApp, final hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement pReq) {
253 super(pHost, pApp, pReq);
254 }
255
256 @Override
257 public boolean isMutable() {
258 return true;
259 }
260 }
261
262 private static final class Immutable extends ResourceRequirement.Match {
263 Immutable(final HostInstance pHost, final ApplicationInstance pApp, final hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement pReq) {
264 super(pHost, pApp, pReq);
265 }
266
267 @Override
268 public boolean isMutable() {
269 return false;
270 }
271 }
272 }
273
274 /**
275 * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.resourceRequirement pattern,
276 * providing pattern-specific query methods.
277 *
278 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
279 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
280 *
281 * <p>Matches of the pattern will be represented as {@link Match}.
282 *
283 * <p>Original source:
284 * <code><pre>
285 * pattern resourceRequirement(Host : HostInstance, App : ApplicationInstance, Req : ResourceRequirement) {
286 * ApplicationInstance.allocatedTo(App, Host);
287 * ApplicationInstance.type.requirements(App, Req);
288 * HostInstance.type(Host, HostType);
289 * ResourceRequirement.hostType(Req, HostType);
290 * }
291 * </pre></code>
292 *
293 * @see Match
294 * @see ResourceRequirement
295 *
296 */
297 public static class Matcher extends BaseMatcher<ResourceRequirement.Match> {
298 /**
299 * Initializes the pattern matcher within an existing VIATRA Query engine.
300 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
301 *
302 * @param engine the existing VIATRA Query engine in which this matcher will be created.
303 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
304 *
305 */
306 public static ResourceRequirement.Matcher on(final ViatraQueryEngine engine) {
307 // check if matcher already exists
308 Matcher matcher = engine.getExistingMatcher(querySpecification());
309 if (matcher == null) {
310 matcher = (Matcher)engine.getMatcher(querySpecification());
311 }
312 return matcher;
313 }
314
315 /**
316 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
317 * @return an initialized matcher
318 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
319 *
320 */
321 public static ResourceRequirement.Matcher create() {
322 return new Matcher();
323 }
324
325 private static final int POSITION_HOST = 0;
326
327 private static final int POSITION_APP = 1;
328
329 private static final int POSITION_REQ = 2;
330
331 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(ResourceRequirement.Matcher.class);
332
333 /**
334 * Initializes the pattern matcher within an existing VIATRA Query engine.
335 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
336 *
337 * @param engine the existing VIATRA Query engine in which this matcher will be created.
338 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
339 *
340 */
341 private Matcher() {
342 super(querySpecification());
343 }
344
345 /**
346 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
347 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
348 * @param pApp the fixed value of pattern parameter App, or null if not bound.
349 * @param pReq the fixed value of pattern parameter Req, or null if not bound.
350 * @return matches represented as a Match object.
351 *
352 */
353 public Collection<ResourceRequirement.Match> getAllMatches(final HostInstance pHost, final ApplicationInstance pApp, final hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement pReq) {
354 return rawStreamAllMatches(new Object[]{pHost, pApp, pReq}).collect(Collectors.toSet());
355 }
356
357 /**
358 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
359 * </p>
360 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
361 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
362 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
363 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
364 * @param pApp the fixed value of pattern parameter App, or null if not bound.
365 * @param pReq the fixed value of pattern parameter Req, or null if not bound.
366 * @return a stream of matches represented as a Match object.
367 *
368 */
369 public Stream<ResourceRequirement.Match> streamAllMatches(final HostInstance pHost, final ApplicationInstance pApp, final hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement pReq) {
370 return rawStreamAllMatches(new Object[]{pHost, pApp, pReq});
371 }
372
373 /**
374 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
375 * Neither determinism nor randomness of selection is guaranteed.
376 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
377 * @param pApp the fixed value of pattern parameter App, or null if not bound.
378 * @param pReq the fixed value of pattern parameter Req, or null if not bound.
379 * @return a match represented as a Match object, or null if no match is found.
380 *
381 */
382 public Optional<ResourceRequirement.Match> getOneArbitraryMatch(final HostInstance pHost, final ApplicationInstance pApp, final hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement pReq) {
383 return rawGetOneArbitraryMatch(new Object[]{pHost, pApp, pReq});
384 }
385
386 /**
387 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
388 * under any possible substitution of the unspecified parameters (if any).
389 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
390 * @param pApp the fixed value of pattern parameter App, or null if not bound.
391 * @param pReq the fixed value of pattern parameter Req, or null if not bound.
392 * @return true if the input is a valid (partial) match of the pattern.
393 *
394 */
395 public boolean hasMatch(final HostInstance pHost, final ApplicationInstance pApp, final hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement pReq) {
396 return rawHasMatch(new Object[]{pHost, pApp, pReq});
397 }
398
399 /**
400 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
401 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
402 * @param pApp the fixed value of pattern parameter App, or null if not bound.
403 * @param pReq the fixed value of pattern parameter Req, or null if not bound.
404 * @return the number of pattern matches found.
405 *
406 */
407 public int countMatches(final HostInstance pHost, final ApplicationInstance pApp, final hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement pReq) {
408 return rawCountMatches(new Object[]{pHost, pApp, pReq});
409 }
410
411 /**
412 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
413 * Neither determinism nor randomness of selection is guaranteed.
414 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
415 * @param pApp the fixed value of pattern parameter App, or null if not bound.
416 * @param pReq the fixed value of pattern parameter Req, or null if not bound.
417 * @param processor the action that will process the selected match.
418 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
419 *
420 */
421 public boolean forOneArbitraryMatch(final HostInstance pHost, final ApplicationInstance pApp, final hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement pReq, final Consumer<? super ResourceRequirement.Match> processor) {
422 return rawForOneArbitraryMatch(new Object[]{pHost, pApp, pReq}, processor);
423 }
424
425 /**
426 * Returns a new (partial) match.
427 * This can be used e.g. to call the matcher with a partial match.
428 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
429 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
430 * @param pApp the fixed value of pattern parameter App, or null if not bound.
431 * @param pReq the fixed value of pattern parameter Req, or null if not bound.
432 * @return the (partial) match object.
433 *
434 */
435 public ResourceRequirement.Match newMatch(final HostInstance pHost, final ApplicationInstance pApp, final hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement pReq) {
436 return ResourceRequirement.Match.newMatch(pHost, pApp, pReq);
437 }
438
439 /**
440 * Retrieve the set of values that occur in matches for Host.
441 * @return the Set of all values or empty set if there are no matches
442 *
443 */
444 protected Stream<HostInstance> rawStreamAllValuesOfHost(final Object[] parameters) {
445 return rawStreamAllValues(POSITION_HOST, parameters).map(HostInstance.class::cast);
446 }
447
448 /**
449 * Retrieve the set of values that occur in matches for Host.
450 * @return the Set of all values or empty set if there are no matches
451 *
452 */
453 public Set<HostInstance> getAllValuesOfHost() {
454 return rawStreamAllValuesOfHost(emptyArray()).collect(Collectors.toSet());
455 }
456
457 /**
458 * Retrieve the set of values that occur in matches for Host.
459 * @return the Set of all values or empty set if there are no matches
460 *
461 */
462 public Stream<HostInstance> streamAllValuesOfHost() {
463 return rawStreamAllValuesOfHost(emptyArray());
464 }
465
466 /**
467 * Retrieve the set of values that occur in matches for Host.
468 * </p>
469 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
470 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
471 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
472 *
473 * @return the Stream of all values or empty set if there are no matches
474 *
475 */
476 public Stream<HostInstance> streamAllValuesOfHost(final ResourceRequirement.Match partialMatch) {
477 return rawStreamAllValuesOfHost(partialMatch.toArray());
478 }
479
480 /**
481 * Retrieve the set of values that occur in matches for Host.
482 * </p>
483 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
484 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
485 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
486 *
487 * @return the Stream of all values or empty set if there are no matches
488 *
489 */
490 public Stream<HostInstance> streamAllValuesOfHost(final ApplicationInstance pApp, final hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement pReq) {
491 return rawStreamAllValuesOfHost(new Object[]{null, pApp, pReq});
492 }
493
494 /**
495 * Retrieve the set of values that occur in matches for Host.
496 * @return the Set of all values or empty set if there are no matches
497 *
498 */
499 public Set<HostInstance> getAllValuesOfHost(final ResourceRequirement.Match partialMatch) {
500 return rawStreamAllValuesOfHost(partialMatch.toArray()).collect(Collectors.toSet());
501 }
502
503 /**
504 * Retrieve the set of values that occur in matches for Host.
505 * @return the Set of all values or empty set if there are no matches
506 *
507 */
508 public Set<HostInstance> getAllValuesOfHost(final ApplicationInstance pApp, final hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement pReq) {
509 return rawStreamAllValuesOfHost(new Object[]{null, pApp, pReq}).collect(Collectors.toSet());
510 }
511
512 /**
513 * Retrieve the set of values that occur in matches for App.
514 * @return the Set of all values or empty set if there are no matches
515 *
516 */
517 protected Stream<ApplicationInstance> rawStreamAllValuesOfApp(final Object[] parameters) {
518 return rawStreamAllValues(POSITION_APP, parameters).map(ApplicationInstance.class::cast);
519 }
520
521 /**
522 * Retrieve the set of values that occur in matches for App.
523 * @return the Set of all values or empty set if there are no matches
524 *
525 */
526 public Set<ApplicationInstance> getAllValuesOfApp() {
527 return rawStreamAllValuesOfApp(emptyArray()).collect(Collectors.toSet());
528 }
529
530 /**
531 * Retrieve the set of values that occur in matches for App.
532 * @return the Set of all values or empty set if there are no matches
533 *
534 */
535 public Stream<ApplicationInstance> streamAllValuesOfApp() {
536 return rawStreamAllValuesOfApp(emptyArray());
537 }
538
539 /**
540 * Retrieve the set of values that occur in matches for App.
541 * </p>
542 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
543 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
544 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
545 *
546 * @return the Stream of all values or empty set if there are no matches
547 *
548 */
549 public Stream<ApplicationInstance> streamAllValuesOfApp(final ResourceRequirement.Match partialMatch) {
550 return rawStreamAllValuesOfApp(partialMatch.toArray());
551 }
552
553 /**
554 * Retrieve the set of values that occur in matches for App.
555 * </p>
556 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
557 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
558 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
559 *
560 * @return the Stream of all values or empty set if there are no matches
561 *
562 */
563 public Stream<ApplicationInstance> streamAllValuesOfApp(final HostInstance pHost, final hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement pReq) {
564 return rawStreamAllValuesOfApp(new Object[]{pHost, null, pReq});
565 }
566
567 /**
568 * Retrieve the set of values that occur in matches for App.
569 * @return the Set of all values or empty set if there are no matches
570 *
571 */
572 public Set<ApplicationInstance> getAllValuesOfApp(final ResourceRequirement.Match partialMatch) {
573 return rawStreamAllValuesOfApp(partialMatch.toArray()).collect(Collectors.toSet());
574 }
575
576 /**
577 * Retrieve the set of values that occur in matches for App.
578 * @return the Set of all values or empty set if there are no matches
579 *
580 */
581 public Set<ApplicationInstance> getAllValuesOfApp(final HostInstance pHost, final hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement pReq) {
582 return rawStreamAllValuesOfApp(new Object[]{pHost, null, pReq}).collect(Collectors.toSet());
583 }
584
585 /**
586 * Retrieve the set of values that occur in matches for Req.
587 * @return the Set of all values or empty set if there are no matches
588 *
589 */
590 protected Stream<hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement> rawStreamAllValuesOfReq(final Object[] parameters) {
591 return rawStreamAllValues(POSITION_REQ, parameters).map(hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement.class::cast);
592 }
593
594 /**
595 * Retrieve the set of values that occur in matches for Req.
596 * @return the Set of all values or empty set if there are no matches
597 *
598 */
599 public Set<hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement> getAllValuesOfReq() {
600 return rawStreamAllValuesOfReq(emptyArray()).collect(Collectors.toSet());
601 }
602
603 /**
604 * Retrieve the set of values that occur in matches for Req.
605 * @return the Set of all values or empty set if there are no matches
606 *
607 */
608 public Stream<hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement> streamAllValuesOfReq() {
609 return rawStreamAllValuesOfReq(emptyArray());
610 }
611
612 /**
613 * Retrieve the set of values that occur in matches for Req.
614 * </p>
615 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
616 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
617 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
618 *
619 * @return the Stream of all values or empty set if there are no matches
620 *
621 */
622 public Stream<hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement> streamAllValuesOfReq(final ResourceRequirement.Match partialMatch) {
623 return rawStreamAllValuesOfReq(partialMatch.toArray());
624 }
625
626 /**
627 * Retrieve the set of values that occur in matches for Req.
628 * </p>
629 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
630 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
631 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
632 *
633 * @return the Stream of all values or empty set if there are no matches
634 *
635 */
636 public Stream<hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement> streamAllValuesOfReq(final HostInstance pHost, final ApplicationInstance pApp) {
637 return rawStreamAllValuesOfReq(new Object[]{pHost, pApp, null});
638 }
639
640 /**
641 * Retrieve the set of values that occur in matches for Req.
642 * @return the Set of all values or empty set if there are no matches
643 *
644 */
645 public Set<hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement> getAllValuesOfReq(final ResourceRequirement.Match partialMatch) {
646 return rawStreamAllValuesOfReq(partialMatch.toArray()).collect(Collectors.toSet());
647 }
648
649 /**
650 * Retrieve the set of values that occur in matches for Req.
651 * @return the Set of all values or empty set if there are no matches
652 *
653 */
654 public Set<hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement> getAllValuesOfReq(final HostInstance pHost, final ApplicationInstance pApp) {
655 return rawStreamAllValuesOfReq(new Object[]{pHost, pApp, null}).collect(Collectors.toSet());
656 }
657
658 @Override
659 protected ResourceRequirement.Match tupleToMatch(final Tuple t) {
660 try {
661 return ResourceRequirement.Match.newMatch((HostInstance) t.get(POSITION_HOST), (ApplicationInstance) t.get(POSITION_APP), (hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement) t.get(POSITION_REQ));
662 } catch(ClassCastException e) {
663 LOGGER.error("Element(s) in tuple not properly typed!",e);
664 return null;
665 }
666 }
667
668 @Override
669 protected ResourceRequirement.Match arrayToMatch(final Object[] match) {
670 try {
671 return ResourceRequirement.Match.newMatch((HostInstance) match[POSITION_HOST], (ApplicationInstance) match[POSITION_APP], (hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement) match[POSITION_REQ]);
672 } catch(ClassCastException e) {
673 LOGGER.error("Element(s) in array not properly typed!",e);
674 return null;
675 }
676 }
677
678 @Override
679 protected ResourceRequirement.Match arrayToMatchMutable(final Object[] match) {
680 try {
681 return ResourceRequirement.Match.newMutableMatch((HostInstance) match[POSITION_HOST], (ApplicationInstance) match[POSITION_APP], (hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement) match[POSITION_REQ]);
682 } catch(ClassCastException e) {
683 LOGGER.error("Element(s) in array not properly typed!",e);
684 return null;
685 }
686 }
687
688 /**
689 * @return the singleton instance of the query specification of this pattern
690 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
691 *
692 */
693 public static IQuerySpecification<ResourceRequirement.Matcher> querySpecification() {
694 return ResourceRequirement.instance();
695 }
696 }
697
698 private ResourceRequirement() {
699 super(GeneratedPQuery.INSTANCE);
700 }
701
702 /**
703 * @return the singleton instance of the query specification
704 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
705 *
706 */
707 public static ResourceRequirement instance() {
708 try{
709 return LazyHolder.INSTANCE;
710 } catch (ExceptionInInitializerError err) {
711 throw processInitializerError(err);
712 }
713 }
714
715 @Override
716 protected ResourceRequirement.Matcher instantiate(final ViatraQueryEngine engine) {
717 return ResourceRequirement.Matcher.on(engine);
718 }
719
720 @Override
721 public ResourceRequirement.Matcher instantiate() {
722 return ResourceRequirement.Matcher.create();
723 }
724
725 @Override
726 public ResourceRequirement.Match newEmptyMatch() {
727 return ResourceRequirement.Match.newEmptyMatch();
728 }
729
730 @Override
731 public ResourceRequirement.Match newMatch(final Object... parameters) {
732 return ResourceRequirement.Match.newMatch((hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance) parameters[0], (hu.bme.mit.inf.dslreasoner.domains.cps.ApplicationInstance) parameters[1], (hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement) parameters[2]);
733 }
734
735 /**
736 * Inner class allowing the singleton instance of {@link ResourceRequirement} to be created
737 * <b>not</b> at the class load time of the outer class,
738 * but rather at the first call to {@link ResourceRequirement#instance()}.
739 *
740 * <p> This workaround is required e.g. to support recursion.
741 *
742 */
743 private static class LazyHolder {
744 private static final ResourceRequirement INSTANCE = new ResourceRequirement();
745
746 /**
747 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
748 * This initialization order is required to support indirect recursion.
749 *
750 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
751 *
752 */
753 private static final Object STATIC_INITIALIZER = ensureInitialized();
754
755 public static Object ensureInitialized() {
756 INSTANCE.ensureInitializedInternal();
757 return null;
758 }
759 }
760
761 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
762 private static final ResourceRequirement.GeneratedPQuery INSTANCE = new GeneratedPQuery();
763
764 private final PParameter parameter_Host = new PParameter("Host", "hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "HostInstance")), PParameterDirection.INOUT);
765
766 private final PParameter parameter_App = new PParameter("App", "hu.bme.mit.inf.dslreasoner.domains.cps.ApplicationInstance", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "ApplicationInstance")), PParameterDirection.INOUT);
767
768 private final PParameter parameter_Req = new PParameter("Req", "hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "ResourceRequirement")), PParameterDirection.INOUT);
769
770 private final List<PParameter> parameters = Arrays.asList(parameter_Host, parameter_App, parameter_Req);
771
772 private GeneratedPQuery() {
773 super(PVisibility.PUBLIC);
774 }
775
776 @Override
777 public String getFullyQualifiedName() {
778 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.resourceRequirement";
779 }
780
781 @Override
782 public List<String> getParameterNames() {
783 return Arrays.asList("Host","App","Req");
784 }
785
786 @Override
787 public List<PParameter> getParameters() {
788 return parameters;
789 }
790
791 @Override
792 public Set<PBody> doGetContainedBodies() {
793 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
794 Set<PBody> bodies = new LinkedHashSet<>();
795 {
796 PBody body = new PBody(this);
797 PVariable var_Host = body.getOrCreateVariableByName("Host");
798 PVariable var_App = body.getOrCreateVariableByName("App");
799 PVariable var_Req = body.getOrCreateVariableByName("Req");
800 PVariable var_HostType = body.getOrCreateVariableByName("HostType");
801 new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance")));
802 new TypeConstraint(body, Tuples.flatTupleOf(var_App), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance")));
803 new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ResourceRequirement")));
804 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
805 new ExportedParameter(body, var_Host, parameter_Host),
806 new ExportedParameter(body, var_App, parameter_App),
807 new ExportedParameter(body, var_Req, parameter_Req)
808 ));
809 // ApplicationInstance.allocatedTo(App, Host)
810 new TypeConstraint(body, Tuples.flatTupleOf(var_App), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance")));
811 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
812 new TypeConstraint(body, Tuples.flatTupleOf(var_App, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ApplicationInstance", "allocatedTo")));
813 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance")));
814 new Equality(body, var__virtual_0_, var_Host);
815 // ApplicationInstance.type.requirements(App, Req)
816 new TypeConstraint(body, Tuples.flatTupleOf(var_App), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance")));
817 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
818 new TypeConstraint(body, Tuples.flatTupleOf(var_App, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ApplicationInstance", "type")));
819 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationType")));
820 PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}");
821 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_, var__virtual_2_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ApplicationType", "requirements")));
822 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ResourceRequirement")));
823 new Equality(body, var__virtual_2_, var_Req);
824 // HostInstance.type(Host, HostType)
825 new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance")));
826 PVariable var__virtual_3_ = body.getOrCreateVariableByName(".virtual{3}");
827 new TypeConstraint(body, Tuples.flatTupleOf(var_Host, var__virtual_3_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "HostInstance", "type")));
828 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_3_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostType")));
829 new Equality(body, var__virtual_3_, var_HostType);
830 // ResourceRequirement.hostType(Req, HostType)
831 new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ResourceRequirement")));
832 PVariable var__virtual_4_ = body.getOrCreateVariableByName(".virtual{4}");
833 new TypeConstraint(body, Tuples.flatTupleOf(var_Req, var__virtual_4_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ResourceRequirement", "hostType")));
834 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_4_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostType")));
835 new Equality(body, var__virtual_4_, var_HostType);
836 bodies.add(body);
837 }
838 return bodies;
839 }
840 }
841}
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/UnallocateAppInstance.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/UnallocateAppInstance.java
new file mode 100644
index 00000000..9f3d74b6
--- /dev/null
+++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/UnallocateAppInstance.java
@@ -0,0 +1,551 @@
1/**
2 * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql
3 */
4package hu.bme.mit.inf.dslreasoner.domains.cps.queries;
5
6import hu.bme.mit.inf.dslreasoner.domains.cps.ApplicationInstance;
7import java.util.Arrays;
8import java.util.Collection;
9import java.util.LinkedHashSet;
10import java.util.List;
11import java.util.Objects;
12import java.util.Optional;
13import java.util.Set;
14import java.util.function.Consumer;
15import java.util.stream.Collectors;
16import java.util.stream.Stream;
17import org.apache.log4j.Logger;
18import org.eclipse.emf.ecore.EClass;
19import org.eclipse.viatra.query.runtime.api.IPatternMatch;
20import org.eclipse.viatra.query.runtime.api.IQuerySpecification;
21import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine;
22import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
23import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification;
24import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher;
25import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch;
26import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey;
27import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey;
28import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
29import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
30import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
31import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality;
32import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
33import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
34import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
35import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
36import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
37import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
38import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
39import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
40
41/**
42 * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
43 *
44 * <p>Original source:
45 * <code><pre>
46 * pattern unallocateAppInstance(App : ApplicationInstance) {
47 * ApplicationInstance.allocatedTo(App, _);
48 * }
49 * </pre></code>
50 *
51 * @see Matcher
52 * @see Match
53 *
54 */
55@SuppressWarnings("all")
56public final class UnallocateAppInstance extends BaseGeneratedEMFQuerySpecification<UnallocateAppInstance.Matcher> {
57 /**
58 * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.unallocateAppInstance pattern,
59 * to be used in conjunction with {@link Matcher}.
60 *
61 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
62 * Each instance is a (possibly partial) substitution of pattern parameters,
63 * usable to represent a match of the pattern in the result of a query,
64 * or to specify the bound (fixed) input parameters when issuing a query.
65 *
66 * @see Matcher
67 *
68 */
69 public static abstract class Match extends BasePatternMatch {
70 private ApplicationInstance fApp;
71
72 private static List<String> parameterNames = makeImmutableList("App");
73
74 private Match(final ApplicationInstance pApp) {
75 this.fApp = pApp;
76 }
77
78 @Override
79 public Object get(final String parameterName) {
80 switch(parameterName) {
81 case "App": return this.fApp;
82 default: return null;
83 }
84 }
85
86 @Override
87 public Object get(final int index) {
88 switch(index) {
89 case 0: return this.fApp;
90 default: return null;
91 }
92 }
93
94 public ApplicationInstance getApp() {
95 return this.fApp;
96 }
97
98 @Override
99 public boolean set(final String parameterName, final Object newValue) {
100 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
101 if ("App".equals(parameterName) ) {
102 this.fApp = (ApplicationInstance) newValue;
103 return true;
104 }
105 return false;
106 }
107
108 public void setApp(final ApplicationInstance pApp) {
109 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
110 this.fApp = pApp;
111 }
112
113 @Override
114 public String patternName() {
115 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.unallocateAppInstance";
116 }
117
118 @Override
119 public List<String> parameterNames() {
120 return UnallocateAppInstance.Match.parameterNames;
121 }
122
123 @Override
124 public Object[] toArray() {
125 return new Object[]{fApp};
126 }
127
128 @Override
129 public UnallocateAppInstance.Match toImmutable() {
130 return isMutable() ? newMatch(fApp) : this;
131 }
132
133 @Override
134 public String prettyPrint() {
135 StringBuilder result = new StringBuilder();
136 result.append("\"App\"=" + prettyPrintValue(fApp));
137 return result.toString();
138 }
139
140 @Override
141 public int hashCode() {
142 return Objects.hash(fApp);
143 }
144
145 @Override
146 public boolean equals(final Object obj) {
147 if (this == obj)
148 return true;
149 if (obj == null) {
150 return false;
151 }
152 if ((obj instanceof UnallocateAppInstance.Match)) {
153 UnallocateAppInstance.Match other = (UnallocateAppInstance.Match) obj;
154 return Objects.equals(fApp, other.fApp);
155 } else {
156 // this should be infrequent
157 if (!(obj instanceof IPatternMatch)) {
158 return false;
159 }
160 IPatternMatch otherSig = (IPatternMatch) obj;
161 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
162 }
163 }
164
165 @Override
166 public UnallocateAppInstance specification() {
167 return UnallocateAppInstance.instance();
168 }
169
170 /**
171 * Returns an empty, mutable match.
172 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
173 *
174 * @return the empty match.
175 *
176 */
177 public static UnallocateAppInstance.Match newEmptyMatch() {
178 return new Mutable(null);
179 }
180
181 /**
182 * Returns a mutable (partial) match.
183 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
184 *
185 * @param pApp the fixed value of pattern parameter App, or null if not bound.
186 * @return the new, mutable (partial) match object.
187 *
188 */
189 public static UnallocateAppInstance.Match newMutableMatch(final ApplicationInstance pApp) {
190 return new Mutable(pApp);
191 }
192
193 /**
194 * Returns a new (partial) match.
195 * This can be used e.g. to call the matcher with a partial match.
196 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
197 * @param pApp the fixed value of pattern parameter App, or null if not bound.
198 * @return the (partial) match object.
199 *
200 */
201 public static UnallocateAppInstance.Match newMatch(final ApplicationInstance pApp) {
202 return new Immutable(pApp);
203 }
204
205 private static final class Mutable extends UnallocateAppInstance.Match {
206 Mutable(final ApplicationInstance pApp) {
207 super(pApp);
208 }
209
210 @Override
211 public boolean isMutable() {
212 return true;
213 }
214 }
215
216 private static final class Immutable extends UnallocateAppInstance.Match {
217 Immutable(final ApplicationInstance pApp) {
218 super(pApp);
219 }
220
221 @Override
222 public boolean isMutable() {
223 return false;
224 }
225 }
226 }
227
228 /**
229 * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.unallocateAppInstance pattern,
230 * providing pattern-specific query methods.
231 *
232 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
233 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
234 *
235 * <p>Matches of the pattern will be represented as {@link Match}.
236 *
237 * <p>Original source:
238 * <code><pre>
239 * pattern unallocateAppInstance(App : ApplicationInstance) {
240 * ApplicationInstance.allocatedTo(App, _);
241 * }
242 * </pre></code>
243 *
244 * @see Match
245 * @see UnallocateAppInstance
246 *
247 */
248 public static class Matcher extends BaseMatcher<UnallocateAppInstance.Match> {
249 /**
250 * Initializes the pattern matcher within an existing VIATRA Query engine.
251 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
252 *
253 * @param engine the existing VIATRA Query engine in which this matcher will be created.
254 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
255 *
256 */
257 public static UnallocateAppInstance.Matcher on(final ViatraQueryEngine engine) {
258 // check if matcher already exists
259 Matcher matcher = engine.getExistingMatcher(querySpecification());
260 if (matcher == null) {
261 matcher = (Matcher)engine.getMatcher(querySpecification());
262 }
263 return matcher;
264 }
265
266 /**
267 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
268 * @return an initialized matcher
269 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
270 *
271 */
272 public static UnallocateAppInstance.Matcher create() {
273 return new Matcher();
274 }
275
276 private static final int POSITION_APP = 0;
277
278 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(UnallocateAppInstance.Matcher.class);
279
280 /**
281 * Initializes the pattern matcher within an existing VIATRA Query engine.
282 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
283 *
284 * @param engine the existing VIATRA Query engine in which this matcher will be created.
285 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
286 *
287 */
288 private Matcher() {
289 super(querySpecification());
290 }
291
292 /**
293 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
294 * @param pApp the fixed value of pattern parameter App, or null if not bound.
295 * @return matches represented as a Match object.
296 *
297 */
298 public Collection<UnallocateAppInstance.Match> getAllMatches(final ApplicationInstance pApp) {
299 return rawStreamAllMatches(new Object[]{pApp}).collect(Collectors.toSet());
300 }
301
302 /**
303 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
304 * </p>
305 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
306 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
307 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
308 * @param pApp the fixed value of pattern parameter App, or null if not bound.
309 * @return a stream of matches represented as a Match object.
310 *
311 */
312 public Stream<UnallocateAppInstance.Match> streamAllMatches(final ApplicationInstance pApp) {
313 return rawStreamAllMatches(new Object[]{pApp});
314 }
315
316 /**
317 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
318 * Neither determinism nor randomness of selection is guaranteed.
319 * @param pApp the fixed value of pattern parameter App, or null if not bound.
320 * @return a match represented as a Match object, or null if no match is found.
321 *
322 */
323 public Optional<UnallocateAppInstance.Match> getOneArbitraryMatch(final ApplicationInstance pApp) {
324 return rawGetOneArbitraryMatch(new Object[]{pApp});
325 }
326
327 /**
328 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
329 * under any possible substitution of the unspecified parameters (if any).
330 * @param pApp the fixed value of pattern parameter App, or null if not bound.
331 * @return true if the input is a valid (partial) match of the pattern.
332 *
333 */
334 public boolean hasMatch(final ApplicationInstance pApp) {
335 return rawHasMatch(new Object[]{pApp});
336 }
337
338 /**
339 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
340 * @param pApp the fixed value of pattern parameter App, or null if not bound.
341 * @return the number of pattern matches found.
342 *
343 */
344 public int countMatches(final ApplicationInstance pApp) {
345 return rawCountMatches(new Object[]{pApp});
346 }
347
348 /**
349 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
350 * Neither determinism nor randomness of selection is guaranteed.
351 * @param pApp the fixed value of pattern parameter App, or null if not bound.
352 * @param processor the action that will process the selected match.
353 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
354 *
355 */
356 public boolean forOneArbitraryMatch(final ApplicationInstance pApp, final Consumer<? super UnallocateAppInstance.Match> processor) {
357 return rawForOneArbitraryMatch(new Object[]{pApp}, processor);
358 }
359
360 /**
361 * Returns a new (partial) match.
362 * This can be used e.g. to call the matcher with a partial match.
363 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
364 * @param pApp the fixed value of pattern parameter App, or null if not bound.
365 * @return the (partial) match object.
366 *
367 */
368 public UnallocateAppInstance.Match newMatch(final ApplicationInstance pApp) {
369 return UnallocateAppInstance.Match.newMatch(pApp);
370 }
371
372 /**
373 * Retrieve the set of values that occur in matches for App.
374 * @return the Set of all values or empty set if there are no matches
375 *
376 */
377 protected Stream<ApplicationInstance> rawStreamAllValuesOfApp(final Object[] parameters) {
378 return rawStreamAllValues(POSITION_APP, parameters).map(ApplicationInstance.class::cast);
379 }
380
381 /**
382 * Retrieve the set of values that occur in matches for App.
383 * @return the Set of all values or empty set if there are no matches
384 *
385 */
386 public Set<ApplicationInstance> getAllValuesOfApp() {
387 return rawStreamAllValuesOfApp(emptyArray()).collect(Collectors.toSet());
388 }
389
390 /**
391 * Retrieve the set of values that occur in matches for App.
392 * @return the Set of all values or empty set if there are no matches
393 *
394 */
395 public Stream<ApplicationInstance> streamAllValuesOfApp() {
396 return rawStreamAllValuesOfApp(emptyArray());
397 }
398
399 @Override
400 protected UnallocateAppInstance.Match tupleToMatch(final Tuple t) {
401 try {
402 return UnallocateAppInstance.Match.newMatch((ApplicationInstance) t.get(POSITION_APP));
403 } catch(ClassCastException e) {
404 LOGGER.error("Element(s) in tuple not properly typed!",e);
405 return null;
406 }
407 }
408
409 @Override
410 protected UnallocateAppInstance.Match arrayToMatch(final Object[] match) {
411 try {
412 return UnallocateAppInstance.Match.newMatch((ApplicationInstance) match[POSITION_APP]);
413 } catch(ClassCastException e) {
414 LOGGER.error("Element(s) in array not properly typed!",e);
415 return null;
416 }
417 }
418
419 @Override
420 protected UnallocateAppInstance.Match arrayToMatchMutable(final Object[] match) {
421 try {
422 return UnallocateAppInstance.Match.newMutableMatch((ApplicationInstance) match[POSITION_APP]);
423 } catch(ClassCastException e) {
424 LOGGER.error("Element(s) in array not properly typed!",e);
425 return null;
426 }
427 }
428
429 /**
430 * @return the singleton instance of the query specification of this pattern
431 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
432 *
433 */
434 public static IQuerySpecification<UnallocateAppInstance.Matcher> querySpecification() {
435 return UnallocateAppInstance.instance();
436 }
437 }
438
439 private UnallocateAppInstance() {
440 super(GeneratedPQuery.INSTANCE);
441 }
442
443 /**
444 * @return the singleton instance of the query specification
445 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
446 *
447 */
448 public static UnallocateAppInstance instance() {
449 try{
450 return LazyHolder.INSTANCE;
451 } catch (ExceptionInInitializerError err) {
452 throw processInitializerError(err);
453 }
454 }
455
456 @Override
457 protected UnallocateAppInstance.Matcher instantiate(final ViatraQueryEngine engine) {
458 return UnallocateAppInstance.Matcher.on(engine);
459 }
460
461 @Override
462 public UnallocateAppInstance.Matcher instantiate() {
463 return UnallocateAppInstance.Matcher.create();
464 }
465
466 @Override
467 public UnallocateAppInstance.Match newEmptyMatch() {
468 return UnallocateAppInstance.Match.newEmptyMatch();
469 }
470
471 @Override
472 public UnallocateAppInstance.Match newMatch(final Object... parameters) {
473 return UnallocateAppInstance.Match.newMatch((hu.bme.mit.inf.dslreasoner.domains.cps.ApplicationInstance) parameters[0]);
474 }
475
476 /**
477 * Inner class allowing the singleton instance of {@link UnallocateAppInstance} to be created
478 * <b>not</b> at the class load time of the outer class,
479 * but rather at the first call to {@link UnallocateAppInstance#instance()}.
480 *
481 * <p> This workaround is required e.g. to support recursion.
482 *
483 */
484 private static class LazyHolder {
485 private static final UnallocateAppInstance INSTANCE = new UnallocateAppInstance();
486
487 /**
488 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
489 * This initialization order is required to support indirect recursion.
490 *
491 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
492 *
493 */
494 private static final Object STATIC_INITIALIZER = ensureInitialized();
495
496 public static Object ensureInitialized() {
497 INSTANCE.ensureInitializedInternal();
498 return null;
499 }
500 }
501
502 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
503 private static final UnallocateAppInstance.GeneratedPQuery INSTANCE = new GeneratedPQuery();
504
505 private final PParameter parameter_App = new PParameter("App", "hu.bme.mit.inf.dslreasoner.domains.cps.ApplicationInstance", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "ApplicationInstance")), PParameterDirection.INOUT);
506
507 private final List<PParameter> parameters = Arrays.asList(parameter_App);
508
509 private GeneratedPQuery() {
510 super(PVisibility.PUBLIC);
511 }
512
513 @Override
514 public String getFullyQualifiedName() {
515 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.unallocateAppInstance";
516 }
517
518 @Override
519 public List<String> getParameterNames() {
520 return Arrays.asList("App");
521 }
522
523 @Override
524 public List<PParameter> getParameters() {
525 return parameters;
526 }
527
528 @Override
529 public Set<PBody> doGetContainedBodies() {
530 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
531 Set<PBody> bodies = new LinkedHashSet<>();
532 {
533 PBody body = new PBody(this);
534 PVariable var_App = body.getOrCreateVariableByName("App");
535 PVariable var___0_ = body.getOrCreateVariableByName("_<0>");
536 new TypeConstraint(body, Tuples.flatTupleOf(var_App), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance")));
537 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
538 new ExportedParameter(body, var_App, parameter_App)
539 ));
540 // ApplicationInstance.allocatedTo(App, _)
541 new TypeConstraint(body, Tuples.flatTupleOf(var_App), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance")));
542 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
543 new TypeConstraint(body, Tuples.flatTupleOf(var_App, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ApplicationInstance", "allocatedTo")));
544 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance")));
545 new Equality(body, var__virtual_0_, var___0_);
546 bodies.add(body);
547 }
548 return bodies;
549 }
550 }
551}
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/.gitignore b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/.gitignore
new file mode 100644
index 00000000..a4f039d9
--- /dev/null
+++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/.gitignore
@@ -0,0 +1,36 @@
1/.CpsQueriesAll.java._trace
2/.ResourceRequirement.java._trace
3/.MemoryRequirement.java._trace
4/.HddRequirement.java._trace
5/.AllocationWithoutResourceRequirement.java._trace
6/.RequiredType.java._trace
7/.SatisfyingInstance.java._trace
8/.FreeMemoryPercentage.java._trace
9/.FreeHddPercentage.java._trace
10/.ApplicationInstance.java._trace
11/.HostInstanceCost.java._trace
12/.AvailableHdd.java._trace
13/.AvailableMemory.java._trace
14/.CpsApplications.java._trace
15/.CpsHosts.java._trace
16/.TotalHdd.java._trace
17/.TotalMemory.java._trace
18/.RequiredAppInstances.java._trace
19/.UnallocatedAppInstance.java._trace
20/.NoHostToAllocateTo.java._trace
21/AvailableHdd.java
22/AvailableMemory.java
23/CpsApplications.java
24/CpsHosts.java
25/CpsQueriesAll.java
26/FreeHddPercentage.java
27/FreeMemoryPercentage.java
28/HddRequirement.java
29/HostInstanceCost.java
30/MemoryRequirement.java
31/NoHostToAllocateTo.java
32/RequiredAppInstances.java
33/SatisfyingInstance.java
34/TotalHdd.java
35/TotalMemory.java
36/UnallocatedAppInstance.java
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/AvailableHdd.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/AvailableHdd.java
new file mode 100644
index 00000000..8a150288
--- /dev/null
+++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/AvailableHdd.java
@@ -0,0 +1,178 @@
1/**
2 * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql
3 */
4package hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal;
5
6import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.HddRequirement;
7import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.TotalHdd;
8import java.util.Arrays;
9import java.util.LinkedHashSet;
10import java.util.List;
11import java.util.Set;
12import org.eclipse.emf.ecore.EClass;
13import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
14import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecificationWithGenericMatcher;
15import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey;
16import org.eclipse.viatra.query.runtime.matchers.aggregators.sum;
17import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
18import org.eclipse.viatra.query.runtime.matchers.context.common.JavaTransitiveInstancesKey;
19import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator;
20import org.eclipse.viatra.query.runtime.matchers.psystem.IValueProvider;
21import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
22import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
23import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.AggregatorConstraint;
24import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality;
25import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
26import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation;
27import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.TypeFilterConstraint;
28import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall;
29import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
30import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
31import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
32import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
33import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
34
35/**
36 * A pattern-specific query specification that can instantiate GenericPatternMatcher in a type-safe way.
37 *
38 * <p>Original source:
39 * <code><pre>
40 * private pattern availableHdd(Host : HostInstance, Hdd : java Integer) {
41 * find totalHdd(Host, TotalHdd);
42 * RequiredHdd == sum find hddRequirement(Host, _, #_);
43 * Hdd == eval(TotalHdd - RequiredHdd);
44 * }
45 * </pre></code>
46 *
47 * @see GenericPatternMatcher
48 * @see GenericPatternMatch
49 *
50 */
51@SuppressWarnings("all")
52public final class AvailableHdd extends BaseGeneratedEMFQuerySpecificationWithGenericMatcher {
53 private AvailableHdd() {
54 super(GeneratedPQuery.INSTANCE);
55 }
56
57 /**
58 * @return the singleton instance of the query specification
59 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
60 *
61 */
62 public static AvailableHdd instance() {
63 try{
64 return LazyHolder.INSTANCE;
65 } catch (ExceptionInInitializerError err) {
66 throw processInitializerError(err);
67 }
68 }
69
70 /**
71 * Inner class allowing the singleton instance of {@link AvailableHdd} to be created
72 * <b>not</b> at the class load time of the outer class,
73 * but rather at the first call to {@link AvailableHdd#instance()}.
74 *
75 * <p> This workaround is required e.g. to support recursion.
76 *
77 */
78 private static class LazyHolder {
79 private static final AvailableHdd INSTANCE = new AvailableHdd();
80
81 /**
82 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
83 * This initialization order is required to support indirect recursion.
84 *
85 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
86 *
87 */
88 private static final Object STATIC_INITIALIZER = ensureInitialized();
89
90 public static Object ensureInitialized() {
91 INSTANCE.ensureInitializedInternal();
92 return null;
93 }
94 }
95
96 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
97 private static final AvailableHdd.GeneratedPQuery INSTANCE = new GeneratedPQuery();
98
99 private final PParameter parameter_Host = new PParameter("Host", "hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "HostInstance")), PParameterDirection.INOUT);
100
101 private final PParameter parameter_Hdd = new PParameter("Hdd", "java.lang.Integer", new JavaTransitiveInstancesKey(java.lang.Integer.class), PParameterDirection.INOUT);
102
103 private final List<PParameter> parameters = Arrays.asList(parameter_Host, parameter_Hdd);
104
105 private GeneratedPQuery() {
106 super(PVisibility.PRIVATE);
107 }
108
109 @Override
110 public String getFullyQualifiedName() {
111 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.availableHdd";
112 }
113
114 @Override
115 public List<String> getParameterNames() {
116 return Arrays.asList("Host","Hdd");
117 }
118
119 @Override
120 public List<PParameter> getParameters() {
121 return parameters;
122 }
123
124 @Override
125 public Set<PBody> doGetContainedBodies() {
126 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
127 Set<PBody> bodies = new LinkedHashSet<>();
128 {
129 PBody body = new PBody(this);
130 PVariable var_Host = body.getOrCreateVariableByName("Host");
131 PVariable var_Hdd = body.getOrCreateVariableByName("Hdd");
132 PVariable var_TotalHdd = body.getOrCreateVariableByName("TotalHdd");
133 PVariable var_RequiredHdd = body.getOrCreateVariableByName("RequiredHdd");
134 PVariable var___0_ = body.getOrCreateVariableByName("_<0>");
135 PVariable var___1_ = body.getOrCreateVariableByName("_<1>");
136 new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance")));
137 new TypeFilterConstraint(body, Tuples.flatTupleOf(var_Hdd), new JavaTransitiveInstancesKey(java.lang.Integer.class));
138 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
139 new ExportedParameter(body, var_Host, parameter_Host),
140 new ExportedParameter(body, var_Hdd, parameter_Hdd)
141 ));
142 // find totalHdd(Host, TotalHdd)
143 new PositivePatternCall(body, Tuples.flatTupleOf(var_Host, var_TotalHdd), TotalHdd.instance().getInternalQueryRepresentation());
144 // RequiredHdd == sum find hddRequirement(Host, _, #_)
145 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
146 new AggregatorConstraint(new sum().getAggregatorLogic(Integer.class), body, Tuples.flatTupleOf(var_Host, var___0_, var___1_), HddRequirement.instance().getInternalQueryRepresentation(), var__virtual_0_, 2);
147 new Equality(body, var_RequiredHdd, var__virtual_0_);
148 // Hdd == eval(TotalHdd - RequiredHdd)
149 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
150 new ExpressionEvaluation(body, new IExpressionEvaluator() {
151
152 @Override
153 public String getShortDescription() {
154 return "Expression evaluation from pattern availableHdd";
155 }
156
157 @Override
158 public Iterable<String> getInputParameterNames() {
159 return Arrays.asList("RequiredHdd", "TotalHdd");}
160
161 @Override
162 public Object evaluateExpression(IValueProvider provider) throws Exception {
163 Integer RequiredHdd = (Integer) provider.getValue("RequiredHdd");
164 Integer TotalHdd = (Integer) provider.getValue("TotalHdd");
165 return evaluateExpression_1_1(RequiredHdd, TotalHdd);
166 }
167 }, var__virtual_1_ );
168 new Equality(body, var_Hdd, var__virtual_1_);
169 bodies.add(body);
170 }
171 return bodies;
172 }
173 }
174
175 private static int evaluateExpression_1_1(final Integer RequiredHdd, final Integer TotalHdd) {
176 return ((TotalHdd).intValue() - (RequiredHdd).intValue());
177 }
178}
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/AvailableMemory.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/AvailableMemory.java
new file mode 100644
index 00000000..c89872e6
--- /dev/null
+++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/AvailableMemory.java
@@ -0,0 +1,178 @@
1/**
2 * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql
3 */
4package hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal;
5
6import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.MemoryRequirement;
7import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.TotalMemory;
8import java.util.Arrays;
9import java.util.LinkedHashSet;
10import java.util.List;
11import java.util.Set;
12import org.eclipse.emf.ecore.EClass;
13import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
14import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecificationWithGenericMatcher;
15import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey;
16import org.eclipse.viatra.query.runtime.matchers.aggregators.sum;
17import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
18import org.eclipse.viatra.query.runtime.matchers.context.common.JavaTransitiveInstancesKey;
19import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator;
20import org.eclipse.viatra.query.runtime.matchers.psystem.IValueProvider;
21import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
22import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
23import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.AggregatorConstraint;
24import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality;
25import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
26import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation;
27import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.TypeFilterConstraint;
28import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall;
29import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
30import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
31import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
32import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
33import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
34
35/**
36 * A pattern-specific query specification that can instantiate GenericPatternMatcher in a type-safe way.
37 *
38 * <p>Original source:
39 * <code><pre>
40 * private pattern availableMemory(Host : HostInstance, Memory : java Integer) {
41 * find totalMemory(Host, TotalMemory);
42 * RequiredMemory == sum find memoryRequirement(Host, _, #_);
43 * Memory == eval(TotalMemory - RequiredMemory);
44 * }
45 * </pre></code>
46 *
47 * @see GenericPatternMatcher
48 * @see GenericPatternMatch
49 *
50 */
51@SuppressWarnings("all")
52public final class AvailableMemory extends BaseGeneratedEMFQuerySpecificationWithGenericMatcher {
53 private AvailableMemory() {
54 super(GeneratedPQuery.INSTANCE);
55 }
56
57 /**
58 * @return the singleton instance of the query specification
59 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
60 *
61 */
62 public static AvailableMemory instance() {
63 try{
64 return LazyHolder.INSTANCE;
65 } catch (ExceptionInInitializerError err) {
66 throw processInitializerError(err);
67 }
68 }
69
70 /**
71 * Inner class allowing the singleton instance of {@link AvailableMemory} to be created
72 * <b>not</b> at the class load time of the outer class,
73 * but rather at the first call to {@link AvailableMemory#instance()}.
74 *
75 * <p> This workaround is required e.g. to support recursion.
76 *
77 */
78 private static class LazyHolder {
79 private static final AvailableMemory INSTANCE = new AvailableMemory();
80
81 /**
82 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
83 * This initialization order is required to support indirect recursion.
84 *
85 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
86 *
87 */
88 private static final Object STATIC_INITIALIZER = ensureInitialized();
89
90 public static Object ensureInitialized() {
91 INSTANCE.ensureInitializedInternal();
92 return null;
93 }
94 }
95
96 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
97 private static final AvailableMemory.GeneratedPQuery INSTANCE = new GeneratedPQuery();
98
99 private final PParameter parameter_Host = new PParameter("Host", "hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "HostInstance")), PParameterDirection.INOUT);
100
101 private final PParameter parameter_Memory = new PParameter("Memory", "java.lang.Integer", new JavaTransitiveInstancesKey(java.lang.Integer.class), PParameterDirection.INOUT);
102
103 private final List<PParameter> parameters = Arrays.asList(parameter_Host, parameter_Memory);
104
105 private GeneratedPQuery() {
106 super(PVisibility.PRIVATE);
107 }
108
109 @Override
110 public String getFullyQualifiedName() {
111 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.availableMemory";
112 }
113
114 @Override
115 public List<String> getParameterNames() {
116 return Arrays.asList("Host","Memory");
117 }
118
119 @Override
120 public List<PParameter> getParameters() {
121 return parameters;
122 }
123
124 @Override
125 public Set<PBody> doGetContainedBodies() {
126 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
127 Set<PBody> bodies = new LinkedHashSet<>();
128 {
129 PBody body = new PBody(this);
130 PVariable var_Host = body.getOrCreateVariableByName("Host");
131 PVariable var_Memory = body.getOrCreateVariableByName("Memory");
132 PVariable var_TotalMemory = body.getOrCreateVariableByName("TotalMemory");
133 PVariable var_RequiredMemory = body.getOrCreateVariableByName("RequiredMemory");
134 PVariable var___0_ = body.getOrCreateVariableByName("_<0>");
135 PVariable var___1_ = body.getOrCreateVariableByName("_<1>");
136 new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance")));
137 new TypeFilterConstraint(body, Tuples.flatTupleOf(var_Memory), new JavaTransitiveInstancesKey(java.lang.Integer.class));
138 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
139 new ExportedParameter(body, var_Host, parameter_Host),
140 new ExportedParameter(body, var_Memory, parameter_Memory)
141 ));
142 // find totalMemory(Host, TotalMemory)
143 new PositivePatternCall(body, Tuples.flatTupleOf(var_Host, var_TotalMemory), TotalMemory.instance().getInternalQueryRepresentation());
144 // RequiredMemory == sum find memoryRequirement(Host, _, #_)
145 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
146 new AggregatorConstraint(new sum().getAggregatorLogic(Integer.class), body, Tuples.flatTupleOf(var_Host, var___0_, var___1_), MemoryRequirement.instance().getInternalQueryRepresentation(), var__virtual_0_, 2);
147 new Equality(body, var_RequiredMemory, var__virtual_0_);
148 // Memory == eval(TotalMemory - RequiredMemory)
149 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
150 new ExpressionEvaluation(body, new IExpressionEvaluator() {
151
152 @Override
153 public String getShortDescription() {
154 return "Expression evaluation from pattern availableMemory";
155 }
156
157 @Override
158 public Iterable<String> getInputParameterNames() {
159 return Arrays.asList("RequiredMemory", "TotalMemory");}
160
161 @Override
162 public Object evaluateExpression(IValueProvider provider) throws Exception {
163 Integer RequiredMemory = (Integer) provider.getValue("RequiredMemory");
164 Integer TotalMemory = (Integer) provider.getValue("TotalMemory");
165 return evaluateExpression_1_1(RequiredMemory, TotalMemory);
166 }
167 }, var__virtual_1_ );
168 new Equality(body, var_Memory, var__virtual_1_);
169 bodies.add(body);
170 }
171 return bodies;
172 }
173 }
174
175 private static int evaluateExpression_1_1(final Integer RequiredMemory, final Integer TotalMemory) {
176 return ((TotalMemory).intValue() - (RequiredMemory).intValue());
177 }
178}
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/CpsApplications.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/CpsApplications.java
new file mode 100644
index 00000000..fe115086
--- /dev/null
+++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/CpsApplications.java
@@ -0,0 +1,141 @@
1/**
2 * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql
3 */
4package hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal;
5
6import java.util.Arrays;
7import java.util.LinkedHashSet;
8import java.util.List;
9import java.util.Set;
10import org.eclipse.emf.ecore.EClass;
11import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
12import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecificationWithGenericMatcher;
13import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey;
14import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey;
15import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
16import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
17import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
18import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality;
19import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
20import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
21import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
22import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
23import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
24import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
25
26/**
27 * A pattern-specific query specification that can instantiate GenericPatternMatcher in a type-safe way.
28 *
29 * <p>Original source:
30 * <code><pre>
31 * private pattern cpsApplications(Cps : CyberPhysicalSystem, AppInstance : ApplicationInstance) {
32 * CyberPhysicalSystem.applicationTypes.instances(Cps, AppInstance);
33 * }
34 * </pre></code>
35 *
36 * @see GenericPatternMatcher
37 * @see GenericPatternMatch
38 *
39 */
40@SuppressWarnings("all")
41public final class CpsApplications extends BaseGeneratedEMFQuerySpecificationWithGenericMatcher {
42 private CpsApplications() {
43 super(GeneratedPQuery.INSTANCE);
44 }
45
46 /**
47 * @return the singleton instance of the query specification
48 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
49 *
50 */
51 public static CpsApplications instance() {
52 try{
53 return LazyHolder.INSTANCE;
54 } catch (ExceptionInInitializerError err) {
55 throw processInitializerError(err);
56 }
57 }
58
59 /**
60 * Inner class allowing the singleton instance of {@link CpsApplications} to be created
61 * <b>not</b> at the class load time of the outer class,
62 * but rather at the first call to {@link CpsApplications#instance()}.
63 *
64 * <p> This workaround is required e.g. to support recursion.
65 *
66 */
67 private static class LazyHolder {
68 private static final CpsApplications INSTANCE = new CpsApplications();
69
70 /**
71 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
72 * This initialization order is required to support indirect recursion.
73 *
74 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
75 *
76 */
77 private static final Object STATIC_INITIALIZER = ensureInitialized();
78
79 public static Object ensureInitialized() {
80 INSTANCE.ensureInitializedInternal();
81 return null;
82 }
83 }
84
85 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
86 private static final CpsApplications.GeneratedPQuery INSTANCE = new GeneratedPQuery();
87
88 private final PParameter parameter_Cps = new PParameter("Cps", "hu.bme.mit.inf.dslreasoner.domains.cps.CyberPhysicalSystem", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "CyberPhysicalSystem")), PParameterDirection.INOUT);
89
90 private final PParameter parameter_AppInstance = new PParameter("AppInstance", "hu.bme.mit.inf.dslreasoner.domains.cps.ApplicationInstance", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "ApplicationInstance")), PParameterDirection.INOUT);
91
92 private final List<PParameter> parameters = Arrays.asList(parameter_Cps, parameter_AppInstance);
93
94 private GeneratedPQuery() {
95 super(PVisibility.PRIVATE);
96 }
97
98 @Override
99 public String getFullyQualifiedName() {
100 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.cpsApplications";
101 }
102
103 @Override
104 public List<String> getParameterNames() {
105 return Arrays.asList("Cps","AppInstance");
106 }
107
108 @Override
109 public List<PParameter> getParameters() {
110 return parameters;
111 }
112
113 @Override
114 public Set<PBody> doGetContainedBodies() {
115 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
116 Set<PBody> bodies = new LinkedHashSet<>();
117 {
118 PBody body = new PBody(this);
119 PVariable var_Cps = body.getOrCreateVariableByName("Cps");
120 PVariable var_AppInstance = body.getOrCreateVariableByName("AppInstance");
121 new TypeConstraint(body, Tuples.flatTupleOf(var_Cps), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "CyberPhysicalSystem")));
122 new TypeConstraint(body, Tuples.flatTupleOf(var_AppInstance), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance")));
123 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
124 new ExportedParameter(body, var_Cps, parameter_Cps),
125 new ExportedParameter(body, var_AppInstance, parameter_AppInstance)
126 ));
127 // CyberPhysicalSystem.applicationTypes.instances(Cps, AppInstance)
128 new TypeConstraint(body, Tuples.flatTupleOf(var_Cps), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "CyberPhysicalSystem")));
129 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
130 new TypeConstraint(body, Tuples.flatTupleOf(var_Cps, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "CyberPhysicalSystem", "applicationTypes")));
131 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationType")));
132 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
133 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ApplicationType", "instances")));
134 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance")));
135 new Equality(body, var__virtual_1_, var_AppInstance);
136 bodies.add(body);
137 }
138 return bodies;
139 }
140 }
141}
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/CpsHosts.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/CpsHosts.java
new file mode 100644
index 00000000..cea8c097
--- /dev/null
+++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/CpsHosts.java
@@ -0,0 +1,141 @@
1/**
2 * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql
3 */
4package hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal;
5
6import java.util.Arrays;
7import java.util.LinkedHashSet;
8import java.util.List;
9import java.util.Set;
10import org.eclipse.emf.ecore.EClass;
11import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
12import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecificationWithGenericMatcher;
13import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey;
14import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey;
15import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
16import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
17import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
18import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality;
19import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
20import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
21import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
22import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
23import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
24import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
25
26/**
27 * A pattern-specific query specification that can instantiate GenericPatternMatcher in a type-safe way.
28 *
29 * <p>Original source:
30 * <code><pre>
31 * private pattern cpsHosts(Cps : CyberPhysicalSystem, HostInstance : HostInstance) {
32 * CyberPhysicalSystem.hostTypes.instances(Cps, HostInstance);
33 * }
34 * </pre></code>
35 *
36 * @see GenericPatternMatcher
37 * @see GenericPatternMatch
38 *
39 */
40@SuppressWarnings("all")
41public final class CpsHosts extends BaseGeneratedEMFQuerySpecificationWithGenericMatcher {
42 private CpsHosts() {
43 super(GeneratedPQuery.INSTANCE);
44 }
45
46 /**
47 * @return the singleton instance of the query specification
48 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
49 *
50 */
51 public static CpsHosts instance() {
52 try{
53 return LazyHolder.INSTANCE;
54 } catch (ExceptionInInitializerError err) {
55 throw processInitializerError(err);
56 }
57 }
58
59 /**
60 * Inner class allowing the singleton instance of {@link CpsHosts} to be created
61 * <b>not</b> at the class load time of the outer class,
62 * but rather at the first call to {@link CpsHosts#instance()}.
63 *
64 * <p> This workaround is required e.g. to support recursion.
65 *
66 */
67 private static class LazyHolder {
68 private static final CpsHosts INSTANCE = new CpsHosts();
69
70 /**
71 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
72 * This initialization order is required to support indirect recursion.
73 *
74 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
75 *
76 */
77 private static final Object STATIC_INITIALIZER = ensureInitialized();
78
79 public static Object ensureInitialized() {
80 INSTANCE.ensureInitializedInternal();
81 return null;
82 }
83 }
84
85 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
86 private static final CpsHosts.GeneratedPQuery INSTANCE = new GeneratedPQuery();
87
88 private final PParameter parameter_Cps = new PParameter("Cps", "hu.bme.mit.inf.dslreasoner.domains.cps.CyberPhysicalSystem", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "CyberPhysicalSystem")), PParameterDirection.INOUT);
89
90 private final PParameter parameter_HostInstance = new PParameter("HostInstance", "hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "HostInstance")), PParameterDirection.INOUT);
91
92 private final List<PParameter> parameters = Arrays.asList(parameter_Cps, parameter_HostInstance);
93
94 private GeneratedPQuery() {
95 super(PVisibility.PRIVATE);
96 }
97
98 @Override
99 public String getFullyQualifiedName() {
100 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.cpsHosts";
101 }
102
103 @Override
104 public List<String> getParameterNames() {
105 return Arrays.asList("Cps","HostInstance");
106 }
107
108 @Override
109 public List<PParameter> getParameters() {
110 return parameters;
111 }
112
113 @Override
114 public Set<PBody> doGetContainedBodies() {
115 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
116 Set<PBody> bodies = new LinkedHashSet<>();
117 {
118 PBody body = new PBody(this);
119 PVariable var_Cps = body.getOrCreateVariableByName("Cps");
120 PVariable var_HostInstance = body.getOrCreateVariableByName("HostInstance");
121 new TypeConstraint(body, Tuples.flatTupleOf(var_Cps), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "CyberPhysicalSystem")));
122 new TypeConstraint(body, Tuples.flatTupleOf(var_HostInstance), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance")));
123 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
124 new ExportedParameter(body, var_Cps, parameter_Cps),
125 new ExportedParameter(body, var_HostInstance, parameter_HostInstance)
126 ));
127 // CyberPhysicalSystem.hostTypes.instances(Cps, HostInstance)
128 new TypeConstraint(body, Tuples.flatTupleOf(var_Cps), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "CyberPhysicalSystem")));
129 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
130 new TypeConstraint(body, Tuples.flatTupleOf(var_Cps, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "CyberPhysicalSystem", "hostTypes")));
131 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostType")));
132 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
133 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "HostType", "instances")));
134 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance")));
135 new Equality(body, var__virtual_1_, var_HostInstance);
136 bodies.add(body);
137 }
138 return bodies;
139 }
140 }
141}
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/CpsQueriesAll.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/CpsQueriesAll.java
new file mode 100644
index 00000000..67f75e1d
--- /dev/null
+++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/CpsQueriesAll.java
@@ -0,0 +1,132 @@
1/**
2 * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql
3 */
4package hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal;
5
6import hu.bme.mit.inf.dslreasoner.domains.cps.queries.Allocate;
7import hu.bme.mit.inf.dslreasoner.domains.cps.queries.AllocationWithoutResourceRequirement;
8import hu.bme.mit.inf.dslreasoner.domains.cps.queries.AverageFreeHddMetric;
9import hu.bme.mit.inf.dslreasoner.domains.cps.queries.AverageFreeMemoryMetric;
10import hu.bme.mit.inf.dslreasoner.domains.cps.queries.CostMetric;
11import hu.bme.mit.inf.dslreasoner.domains.cps.queries.CpsCost;
12import hu.bme.mit.inf.dslreasoner.domains.cps.queries.CreateHostInstance;
13import hu.bme.mit.inf.dslreasoner.domains.cps.queries.GuidanceObjective;
14import hu.bme.mit.inf.dslreasoner.domains.cps.queries.InstanceDoesNotSatisfyRequirement;
15import hu.bme.mit.inf.dslreasoner.domains.cps.queries.NotEnoughAvailableHdd;
16import hu.bme.mit.inf.dslreasoner.domains.cps.queries.NotEnoughAvailableMemory;
17import hu.bme.mit.inf.dslreasoner.domains.cps.queries.RedundantInstancesOnSameHost;
18import hu.bme.mit.inf.dslreasoner.domains.cps.queries.RemoveHostInstance;
19import hu.bme.mit.inf.dslreasoner.domains.cps.queries.RequirementNotSatisfied;
20import hu.bme.mit.inf.dslreasoner.domains.cps.queries.ResourceRequirement;
21import hu.bme.mit.inf.dslreasoner.domains.cps.queries.UnallocateAppInstance;
22import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.AvailableHdd;
23import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.AvailableMemory;
24import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.CpsApplications;
25import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.CpsHosts;
26import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.FreeHddPercentage;
27import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.FreeMemoryPercentage;
28import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.HddRequirement;
29import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.HostInstanceCost;
30import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.MemoryRequirement;
31import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.NoHostToAllocateTo;
32import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.RequiredAppInstances;
33import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.SatisfyingInstance;
34import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.TotalHdd;
35import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.TotalMemory;
36import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.UnallocatedAppInstance;
37import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedPatternGroup;
38
39/**
40 * A pattern group formed of all patterns defined in CpsQueries.vql.
41 *
42 * <p>A private group that includes private patterns as well. Only intended use case is for pattern testing.
43 *
44 * <p> From package hu.bme.mit.inf.dslreasoner.domains.cps.queries, the group contains the definition of the following patterns: <ul>
45 * <li>cpsApplications</li>
46 * <li>cpsHosts</li>
47 * <li>totalMemory</li>
48 * <li>totalHdd</li>
49 * <li>availableMemory</li>
50 * <li>memoryRequirement</li>
51 * <li>availableHdd</li>
52 * <li>hddRequirement</li>
53 * <li>resourceRequirement</li>
54 * <li>allocationWithoutResourceRequirement</li>
55 * <li>notEnoughAvailableMemory</li>
56 * <li>notEnoughAvailableHdd</li>
57 * <li>instanceDoesNotSatisfyRequirement</li>
58 * <li>satisfyingInstance</li>
59 * <li>requirementNotSatisfied</li>
60 * <li>redundantInstancesOnSameHost</li>
61 * <li>averageFreeMemoryMetric</li>
62 * <li>freeMemoryPercentage</li>
63 * <li>averageFreeHddMetric</li>
64 * <li>freeHddPercentage</li>
65 * <li>costMetric</li>
66 * <li>cpsCost</li>
67 * <li>hostInstanceCost</li>
68 * <li>allocate</li>
69 * <li>unallocateAppInstance</li>
70 * <li>createHostInstance</li>
71 * <li>removeHostInstance</li>
72 * <li>unallocatedAppInstance</li>
73 * <li>requiredAppInstances</li>
74 * <li>noHostToAllocateTo</li>
75 * <li>guidanceObjective</li>
76 * </ul>
77 *
78 * @see IQueryGroup
79 *
80 */
81@SuppressWarnings("all")
82public final class CpsQueriesAll extends BaseGeneratedPatternGroup {
83 /**
84 * Access the pattern group.
85 *
86 * @return the singleton instance of the group
87 * @throws ViatraQueryRuntimeException if there was an error loading the generated code of pattern specifications
88 *
89 */
90 public static CpsQueriesAll instance() {
91 if (INSTANCE == null) {
92 INSTANCE = new CpsQueriesAll();
93 }
94 return INSTANCE;
95 }
96
97 private static CpsQueriesAll INSTANCE;
98
99 private CpsQueriesAll() {
100 querySpecifications.add(CpsApplications.instance());
101 querySpecifications.add(CpsHosts.instance());
102 querySpecifications.add(TotalMemory.instance());
103 querySpecifications.add(TotalHdd.instance());
104 querySpecifications.add(AvailableMemory.instance());
105 querySpecifications.add(MemoryRequirement.instance());
106 querySpecifications.add(AvailableHdd.instance());
107 querySpecifications.add(HddRequirement.instance());
108 querySpecifications.add(ResourceRequirement.instance());
109 querySpecifications.add(AllocationWithoutResourceRequirement.instance());
110 querySpecifications.add(NotEnoughAvailableMemory.instance());
111 querySpecifications.add(NotEnoughAvailableHdd.instance());
112 querySpecifications.add(InstanceDoesNotSatisfyRequirement.instance());
113 querySpecifications.add(SatisfyingInstance.instance());
114 querySpecifications.add(RequirementNotSatisfied.instance());
115 querySpecifications.add(RedundantInstancesOnSameHost.instance());
116 querySpecifications.add(AverageFreeMemoryMetric.instance());
117 querySpecifications.add(FreeMemoryPercentage.instance());
118 querySpecifications.add(AverageFreeHddMetric.instance());
119 querySpecifications.add(FreeHddPercentage.instance());
120 querySpecifications.add(CostMetric.instance());
121 querySpecifications.add(CpsCost.instance());
122 querySpecifications.add(HostInstanceCost.instance());
123 querySpecifications.add(Allocate.instance());
124 querySpecifications.add(UnallocateAppInstance.instance());
125 querySpecifications.add(CreateHostInstance.instance());
126 querySpecifications.add(RemoveHostInstance.instance());
127 querySpecifications.add(UnallocatedAppInstance.instance());
128 querySpecifications.add(RequiredAppInstances.instance());
129 querySpecifications.add(NoHostToAllocateTo.instance());
130 querySpecifications.add(GuidanceObjective.instance());
131 }
132}
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/FreeHddPercentage.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/FreeHddPercentage.java
new file mode 100644
index 00000000..ed5c9cda
--- /dev/null
+++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/FreeHddPercentage.java
@@ -0,0 +1,172 @@
1/**
2 * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql
3 */
4package hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal;
5
6import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.AvailableHdd;
7import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.TotalHdd;
8import java.util.Arrays;
9import java.util.LinkedHashSet;
10import java.util.List;
11import java.util.Set;
12import org.eclipse.emf.ecore.EClass;
13import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
14import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecificationWithGenericMatcher;
15import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey;
16import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
17import org.eclipse.viatra.query.runtime.matchers.context.common.JavaTransitiveInstancesKey;
18import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator;
19import org.eclipse.viatra.query.runtime.matchers.psystem.IValueProvider;
20import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
21import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
22import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality;
23import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
24import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation;
25import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.TypeFilterConstraint;
26import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall;
27import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
28import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
29import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
30import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
31import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
32
33/**
34 * A pattern-specific query specification that can instantiate GenericPatternMatcher in a type-safe way.
35 *
36 * <p>Original source:
37 * <code><pre>
38 * private pattern freeHddPercentage(Host : HostInstance, Free : java Double) {
39 * find totalHdd(Host, Total);
40 * find availableHdd(Host, Available);
41 * Free == eval((Available as double) / Total);
42 * }
43 * </pre></code>
44 *
45 * @see GenericPatternMatcher
46 * @see GenericPatternMatch
47 *
48 */
49@SuppressWarnings("all")
50public final class FreeHddPercentage extends BaseGeneratedEMFQuerySpecificationWithGenericMatcher {
51 private FreeHddPercentage() {
52 super(GeneratedPQuery.INSTANCE);
53 }
54
55 /**
56 * @return the singleton instance of the query specification
57 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
58 *
59 */
60 public static FreeHddPercentage instance() {
61 try{
62 return LazyHolder.INSTANCE;
63 } catch (ExceptionInInitializerError err) {
64 throw processInitializerError(err);
65 }
66 }
67
68 /**
69 * Inner class allowing the singleton instance of {@link FreeHddPercentage} to be created
70 * <b>not</b> at the class load time of the outer class,
71 * but rather at the first call to {@link FreeHddPercentage#instance()}.
72 *
73 * <p> This workaround is required e.g. to support recursion.
74 *
75 */
76 private static class LazyHolder {
77 private static final FreeHddPercentage INSTANCE = new FreeHddPercentage();
78
79 /**
80 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
81 * This initialization order is required to support indirect recursion.
82 *
83 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
84 *
85 */
86 private static final Object STATIC_INITIALIZER = ensureInitialized();
87
88 public static Object ensureInitialized() {
89 INSTANCE.ensureInitializedInternal();
90 return null;
91 }
92 }
93
94 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
95 private static final FreeHddPercentage.GeneratedPQuery INSTANCE = new GeneratedPQuery();
96
97 private final PParameter parameter_Host = new PParameter("Host", "hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "HostInstance")), PParameterDirection.INOUT);
98
99 private final PParameter parameter_Free = new PParameter("Free", "java.lang.Double", new JavaTransitiveInstancesKey(java.lang.Double.class), PParameterDirection.INOUT);
100
101 private final List<PParameter> parameters = Arrays.asList(parameter_Host, parameter_Free);
102
103 private GeneratedPQuery() {
104 super(PVisibility.PRIVATE);
105 }
106
107 @Override
108 public String getFullyQualifiedName() {
109 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.freeHddPercentage";
110 }
111
112 @Override
113 public List<String> getParameterNames() {
114 return Arrays.asList("Host","Free");
115 }
116
117 @Override
118 public List<PParameter> getParameters() {
119 return parameters;
120 }
121
122 @Override
123 public Set<PBody> doGetContainedBodies() {
124 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
125 Set<PBody> bodies = new LinkedHashSet<>();
126 {
127 PBody body = new PBody(this);
128 PVariable var_Host = body.getOrCreateVariableByName("Host");
129 PVariable var_Free = body.getOrCreateVariableByName("Free");
130 PVariable var_Total = body.getOrCreateVariableByName("Total");
131 PVariable var_Available = body.getOrCreateVariableByName("Available");
132 new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance")));
133 new TypeFilterConstraint(body, Tuples.flatTupleOf(var_Free), new JavaTransitiveInstancesKey(java.lang.Double.class));
134 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
135 new ExportedParameter(body, var_Host, parameter_Host),
136 new ExportedParameter(body, var_Free, parameter_Free)
137 ));
138 // find totalHdd(Host, Total)
139 new PositivePatternCall(body, Tuples.flatTupleOf(var_Host, var_Total), TotalHdd.instance().getInternalQueryRepresentation());
140 // find availableHdd(Host, Available)
141 new PositivePatternCall(body, Tuples.flatTupleOf(var_Host, var_Available), AvailableHdd.instance().getInternalQueryRepresentation());
142 // Free == eval((Available as double) / Total)
143 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
144 new ExpressionEvaluation(body, new IExpressionEvaluator() {
145
146 @Override
147 public String getShortDescription() {
148 return "Expression evaluation from pattern freeHddPercentage";
149 }
150
151 @Override
152 public Iterable<String> getInputParameterNames() {
153 return Arrays.asList("Available", "Total");}
154
155 @Override
156 public Object evaluateExpression(IValueProvider provider) throws Exception {
157 Integer Available = (Integer) provider.getValue("Available");
158 Integer Total = (Integer) provider.getValue("Total");
159 return evaluateExpression_1_1(Available, Total);
160 }
161 }, var__virtual_0_ );
162 new Equality(body, var_Free, var__virtual_0_);
163 bodies.add(body);
164 }
165 return bodies;
166 }
167 }
168
169 private static double evaluateExpression_1_1(final Integer Available, final Integer Total) {
170 return (((double) (Available).intValue()) / (Total).intValue());
171 }
172}
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/FreeMemoryPercentage.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/FreeMemoryPercentage.java
new file mode 100644
index 00000000..b5923ba9
--- /dev/null
+++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/FreeMemoryPercentage.java
@@ -0,0 +1,172 @@
1/**
2 * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql
3 */
4package hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal;
5
6import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.AvailableMemory;
7import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.TotalMemory;
8import java.util.Arrays;
9import java.util.LinkedHashSet;
10import java.util.List;
11import java.util.Set;
12import org.eclipse.emf.ecore.EClass;
13import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
14import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecificationWithGenericMatcher;
15import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey;
16import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
17import org.eclipse.viatra.query.runtime.matchers.context.common.JavaTransitiveInstancesKey;
18import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator;
19import org.eclipse.viatra.query.runtime.matchers.psystem.IValueProvider;
20import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
21import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
22import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality;
23import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
24import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation;
25import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.TypeFilterConstraint;
26import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall;
27import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
28import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
29import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
30import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
31import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
32
33/**
34 * A pattern-specific query specification that can instantiate GenericPatternMatcher in a type-safe way.
35 *
36 * <p>Original source:
37 * <code><pre>
38 * private pattern freeMemoryPercentage(Host : HostInstance, Free : java Double) {
39 * find totalMemory(Host, Total);
40 * find availableMemory(Host, Available);
41 * Free == eval((Available as double) / Total);
42 * }
43 * </pre></code>
44 *
45 * @see GenericPatternMatcher
46 * @see GenericPatternMatch
47 *
48 */
49@SuppressWarnings("all")
50public final class FreeMemoryPercentage extends BaseGeneratedEMFQuerySpecificationWithGenericMatcher {
51 private FreeMemoryPercentage() {
52 super(GeneratedPQuery.INSTANCE);
53 }
54
55 /**
56 * @return the singleton instance of the query specification
57 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
58 *
59 */
60 public static FreeMemoryPercentage instance() {
61 try{
62 return LazyHolder.INSTANCE;
63 } catch (ExceptionInInitializerError err) {
64 throw processInitializerError(err);
65 }
66 }
67
68 /**
69 * Inner class allowing the singleton instance of {@link FreeMemoryPercentage} to be created
70 * <b>not</b> at the class load time of the outer class,
71 * but rather at the first call to {@link FreeMemoryPercentage#instance()}.
72 *
73 * <p> This workaround is required e.g. to support recursion.
74 *
75 */
76 private static class LazyHolder {
77 private static final FreeMemoryPercentage INSTANCE = new FreeMemoryPercentage();
78
79 /**
80 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
81 * This initialization order is required to support indirect recursion.
82 *
83 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
84 *
85 */
86 private static final Object STATIC_INITIALIZER = ensureInitialized();
87
88 public static Object ensureInitialized() {
89 INSTANCE.ensureInitializedInternal();
90 return null;
91 }
92 }
93
94 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
95 private static final FreeMemoryPercentage.GeneratedPQuery INSTANCE = new GeneratedPQuery();
96
97 private final PParameter parameter_Host = new PParameter("Host", "hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "HostInstance")), PParameterDirection.INOUT);
98
99 private final PParameter parameter_Free = new PParameter("Free", "java.lang.Double", new JavaTransitiveInstancesKey(java.lang.Double.class), PParameterDirection.INOUT);
100
101 private final List<PParameter> parameters = Arrays.asList(parameter_Host, parameter_Free);
102
103 private GeneratedPQuery() {
104 super(PVisibility.PRIVATE);
105 }
106
107 @Override
108 public String getFullyQualifiedName() {
109 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.freeMemoryPercentage";
110 }
111
112 @Override
113 public List<String> getParameterNames() {
114 return Arrays.asList("Host","Free");
115 }
116
117 @Override
118 public List<PParameter> getParameters() {
119 return parameters;
120 }
121
122 @Override
123 public Set<PBody> doGetContainedBodies() {
124 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
125 Set<PBody> bodies = new LinkedHashSet<>();
126 {
127 PBody body = new PBody(this);
128 PVariable var_Host = body.getOrCreateVariableByName("Host");
129 PVariable var_Free = body.getOrCreateVariableByName("Free");
130 PVariable var_Total = body.getOrCreateVariableByName("Total");
131 PVariable var_Available = body.getOrCreateVariableByName("Available");
132 new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance")));
133 new TypeFilterConstraint(body, Tuples.flatTupleOf(var_Free), new JavaTransitiveInstancesKey(java.lang.Double.class));
134 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
135 new ExportedParameter(body, var_Host, parameter_Host),
136 new ExportedParameter(body, var_Free, parameter_Free)
137 ));
138 // find totalMemory(Host, Total)
139 new PositivePatternCall(body, Tuples.flatTupleOf(var_Host, var_Total), TotalMemory.instance().getInternalQueryRepresentation());
140 // find availableMemory(Host, Available)
141 new PositivePatternCall(body, Tuples.flatTupleOf(var_Host, var_Available), AvailableMemory.instance().getInternalQueryRepresentation());
142 // Free == eval((Available as double) / Total)
143 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
144 new ExpressionEvaluation(body, new IExpressionEvaluator() {
145
146 @Override
147 public String getShortDescription() {
148 return "Expression evaluation from pattern freeMemoryPercentage";
149 }
150
151 @Override
152 public Iterable<String> getInputParameterNames() {
153 return Arrays.asList("Available", "Total");}
154
155 @Override
156 public Object evaluateExpression(IValueProvider provider) throws Exception {
157 Integer Available = (Integer) provider.getValue("Available");
158 Integer Total = (Integer) provider.getValue("Total");
159 return evaluateExpression_1_1(Available, Total);
160 }
161 }, var__virtual_0_ );
162 new Equality(body, var_Free, var__virtual_0_);
163 bodies.add(body);
164 }
165 return bodies;
166 }
167 }
168
169 private static double evaluateExpression_1_1(final Integer Available, final Integer Total) {
170 return (((double) (Available).intValue()) / (Total).intValue());
171 }
172}
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/HddRequirement.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/HddRequirement.java
new file mode 100644
index 00000000..4e6a2d10
--- /dev/null
+++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/HddRequirement.java
@@ -0,0 +1,151 @@
1/**
2 * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql
3 */
4package hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal;
5
6import hu.bme.mit.inf.dslreasoner.domains.cps.queries.ResourceRequirement;
7import java.util.Arrays;
8import java.util.LinkedHashSet;
9import java.util.List;
10import java.util.Set;
11import org.eclipse.emf.ecore.EClass;
12import org.eclipse.emf.ecore.EDataType;
13import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
14import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecificationWithGenericMatcher;
15import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey;
16import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey;
17import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey;
18import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
19import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
20import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
21import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality;
22import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
23import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall;
24import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
25import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
26import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
27import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
28import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
29
30/**
31 * A pattern-specific query specification that can instantiate GenericPatternMatcher in a type-safe way.
32 *
33 * <p>Original source:
34 * <code><pre>
35 * private pattern hddRequirement(Host : HostInstance, App : ApplicationInstance, Hdd : EInt) {
36 * find resourceRequirement(Host, App, Req);
37 * ResourceRequirement.requiredHdd(Req, Hdd);
38 * }
39 * </pre></code>
40 *
41 * @see GenericPatternMatcher
42 * @see GenericPatternMatch
43 *
44 */
45@SuppressWarnings("all")
46public final class HddRequirement extends BaseGeneratedEMFQuerySpecificationWithGenericMatcher {
47 private HddRequirement() {
48 super(GeneratedPQuery.INSTANCE);
49 }
50
51 /**
52 * @return the singleton instance of the query specification
53 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
54 *
55 */
56 public static HddRequirement instance() {
57 try{
58 return LazyHolder.INSTANCE;
59 } catch (ExceptionInInitializerError err) {
60 throw processInitializerError(err);
61 }
62 }
63
64 /**
65 * Inner class allowing the singleton instance of {@link HddRequirement} to be created
66 * <b>not</b> at the class load time of the outer class,
67 * but rather at the first call to {@link HddRequirement#instance()}.
68 *
69 * <p> This workaround is required e.g. to support recursion.
70 *
71 */
72 private static class LazyHolder {
73 private static final HddRequirement INSTANCE = new HddRequirement();
74
75 /**
76 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
77 * This initialization order is required to support indirect recursion.
78 *
79 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
80 *
81 */
82 private static final Object STATIC_INITIALIZER = ensureInitialized();
83
84 public static Object ensureInitialized() {
85 INSTANCE.ensureInitializedInternal();
86 return null;
87 }
88 }
89
90 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
91 private static final HddRequirement.GeneratedPQuery INSTANCE = new GeneratedPQuery();
92
93 private final PParameter parameter_Host = new PParameter("Host", "hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "HostInstance")), PParameterDirection.INOUT);
94
95 private final PParameter parameter_App = new PParameter("App", "hu.bme.mit.inf.dslreasoner.domains.cps.ApplicationInstance", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "ApplicationInstance")), PParameterDirection.INOUT);
96
97 private final PParameter parameter_Hdd = new PParameter("Hdd", "java.lang.Integer", new EDataTypeInSlotsKey((EDataType)getClassifierLiteralSafe("http://www.eclipse.org/emf/2002/Ecore", "EInt")), PParameterDirection.INOUT);
98
99 private final List<PParameter> parameters = Arrays.asList(parameter_Host, parameter_App, parameter_Hdd);
100
101 private GeneratedPQuery() {
102 super(PVisibility.PRIVATE);
103 }
104
105 @Override
106 public String getFullyQualifiedName() {
107 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.hddRequirement";
108 }
109
110 @Override
111 public List<String> getParameterNames() {
112 return Arrays.asList("Host","App","Hdd");
113 }
114
115 @Override
116 public List<PParameter> getParameters() {
117 return parameters;
118 }
119
120 @Override
121 public Set<PBody> doGetContainedBodies() {
122 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
123 Set<PBody> bodies = new LinkedHashSet<>();
124 {
125 PBody body = new PBody(this);
126 PVariable var_Host = body.getOrCreateVariableByName("Host");
127 PVariable var_App = body.getOrCreateVariableByName("App");
128 PVariable var_Hdd = body.getOrCreateVariableByName("Hdd");
129 PVariable var_Req = body.getOrCreateVariableByName("Req");
130 new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance")));
131 new TypeConstraint(body, Tuples.flatTupleOf(var_App), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance")));
132 new TypeConstraint(body, Tuples.flatTupleOf(var_Hdd), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt")));
133 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
134 new ExportedParameter(body, var_Host, parameter_Host),
135 new ExportedParameter(body, var_App, parameter_App),
136 new ExportedParameter(body, var_Hdd, parameter_Hdd)
137 ));
138 // find resourceRequirement(Host, App, Req)
139 new PositivePatternCall(body, Tuples.flatTupleOf(var_Host, var_App, var_Req), ResourceRequirement.instance().getInternalQueryRepresentation());
140 // ResourceRequirement.requiredHdd(Req, Hdd)
141 new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ResourceRequirement")));
142 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
143 new TypeConstraint(body, Tuples.flatTupleOf(var_Req, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ResourceRequirement", "requiredHdd")));
144 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt")));
145 new Equality(body, var__virtual_0_, var_Hdd);
146 bodies.add(body);
147 }
148 return bodies;
149 }
150 }
151}
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/HostInstanceCost.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/HostInstanceCost.java
new file mode 100644
index 00000000..429817ce
--- /dev/null
+++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/HostInstanceCost.java
@@ -0,0 +1,153 @@
1/**
2 * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql
3 */
4package hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal;
5
6import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.CpsHosts;
7import java.util.Arrays;
8import java.util.LinkedHashSet;
9import java.util.List;
10import java.util.Set;
11import org.eclipse.emf.ecore.EClass;
12import org.eclipse.emf.ecore.EDataType;
13import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
14import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecificationWithGenericMatcher;
15import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey;
16import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey;
17import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey;
18import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
19import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
20import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
21import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality;
22import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
23import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall;
24import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
25import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
26import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
27import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
28import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
29
30/**
31 * A pattern-specific query specification that can instantiate GenericPatternMatcher in a type-safe way.
32 *
33 * <p>Original source:
34 * <code><pre>
35 * private pattern hostInstanceCost(Cps : CyberPhysicalSystem, Host : HostInstance, Cost : EInt) {
36 * find cpsHosts(Cps, Host);
37 * HostInstance.type.cost(Host, Cost);
38 * }
39 * </pre></code>
40 *
41 * @see GenericPatternMatcher
42 * @see GenericPatternMatch
43 *
44 */
45@SuppressWarnings("all")
46public final class HostInstanceCost extends BaseGeneratedEMFQuerySpecificationWithGenericMatcher {
47 private HostInstanceCost() {
48 super(GeneratedPQuery.INSTANCE);
49 }
50
51 /**
52 * @return the singleton instance of the query specification
53 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
54 *
55 */
56 public static HostInstanceCost instance() {
57 try{
58 return LazyHolder.INSTANCE;
59 } catch (ExceptionInInitializerError err) {
60 throw processInitializerError(err);
61 }
62 }
63
64 /**
65 * Inner class allowing the singleton instance of {@link HostInstanceCost} to be created
66 * <b>not</b> at the class load time of the outer class,
67 * but rather at the first call to {@link HostInstanceCost#instance()}.
68 *
69 * <p> This workaround is required e.g. to support recursion.
70 *
71 */
72 private static class LazyHolder {
73 private static final HostInstanceCost INSTANCE = new HostInstanceCost();
74
75 /**
76 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
77 * This initialization order is required to support indirect recursion.
78 *
79 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
80 *
81 */
82 private static final Object STATIC_INITIALIZER = ensureInitialized();
83
84 public static Object ensureInitialized() {
85 INSTANCE.ensureInitializedInternal();
86 return null;
87 }
88 }
89
90 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
91 private static final HostInstanceCost.GeneratedPQuery INSTANCE = new GeneratedPQuery();
92
93 private final PParameter parameter_Cps = new PParameter("Cps", "hu.bme.mit.inf.dslreasoner.domains.cps.CyberPhysicalSystem", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "CyberPhysicalSystem")), PParameterDirection.INOUT);
94
95 private final PParameter parameter_Host = new PParameter("Host", "hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "HostInstance")), PParameterDirection.INOUT);
96
97 private final PParameter parameter_Cost = new PParameter("Cost", "java.lang.Integer", new EDataTypeInSlotsKey((EDataType)getClassifierLiteralSafe("http://www.eclipse.org/emf/2002/Ecore", "EInt")), PParameterDirection.INOUT);
98
99 private final List<PParameter> parameters = Arrays.asList(parameter_Cps, parameter_Host, parameter_Cost);
100
101 private GeneratedPQuery() {
102 super(PVisibility.PRIVATE);
103 }
104
105 @Override
106 public String getFullyQualifiedName() {
107 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.hostInstanceCost";
108 }
109
110 @Override
111 public List<String> getParameterNames() {
112 return Arrays.asList("Cps","Host","Cost");
113 }
114
115 @Override
116 public List<PParameter> getParameters() {
117 return parameters;
118 }
119
120 @Override
121 public Set<PBody> doGetContainedBodies() {
122 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
123 Set<PBody> bodies = new LinkedHashSet<>();
124 {
125 PBody body = new PBody(this);
126 PVariable var_Cps = body.getOrCreateVariableByName("Cps");
127 PVariable var_Host = body.getOrCreateVariableByName("Host");
128 PVariable var_Cost = body.getOrCreateVariableByName("Cost");
129 new TypeConstraint(body, Tuples.flatTupleOf(var_Cps), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "CyberPhysicalSystem")));
130 new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance")));
131 new TypeConstraint(body, Tuples.flatTupleOf(var_Cost), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt")));
132 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
133 new ExportedParameter(body, var_Cps, parameter_Cps),
134 new ExportedParameter(body, var_Host, parameter_Host),
135 new ExportedParameter(body, var_Cost, parameter_Cost)
136 ));
137 // find cpsHosts(Cps, Host)
138 new PositivePatternCall(body, Tuples.flatTupleOf(var_Cps, var_Host), CpsHosts.instance().getInternalQueryRepresentation());
139 // HostInstance.type.cost(Host, Cost)
140 new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance")));
141 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
142 new TypeConstraint(body, Tuples.flatTupleOf(var_Host, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "HostInstance", "type")));
143 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostType")));
144 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
145 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "HostType", "cost")));
146 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt")));
147 new Equality(body, var__virtual_1_, var_Cost);
148 bodies.add(body);
149 }
150 return bodies;
151 }
152 }
153}
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/MemoryRequirement.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/MemoryRequirement.java
new file mode 100644
index 00000000..98924467
--- /dev/null
+++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/MemoryRequirement.java
@@ -0,0 +1,151 @@
1/**
2 * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql
3 */
4package hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal;
5
6import hu.bme.mit.inf.dslreasoner.domains.cps.queries.ResourceRequirement;
7import java.util.Arrays;
8import java.util.LinkedHashSet;
9import java.util.List;
10import java.util.Set;
11import org.eclipse.emf.ecore.EClass;
12import org.eclipse.emf.ecore.EDataType;
13import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
14import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecificationWithGenericMatcher;
15import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey;
16import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey;
17import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey;
18import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
19import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
20import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
21import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality;
22import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
23import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall;
24import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
25import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
26import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
27import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
28import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
29
30/**
31 * A pattern-specific query specification that can instantiate GenericPatternMatcher in a type-safe way.
32 *
33 * <p>Original source:
34 * <code><pre>
35 * private pattern memoryRequirement(Host : HostInstance, App : ApplicationInstance, Memory : EInt) {
36 * find resourceRequirement(Host, App, Req);
37 * ResourceRequirement.requiredMemory(Req, Memory);
38 * }
39 * </pre></code>
40 *
41 * @see GenericPatternMatcher
42 * @see GenericPatternMatch
43 *
44 */
45@SuppressWarnings("all")
46public final class MemoryRequirement extends BaseGeneratedEMFQuerySpecificationWithGenericMatcher {
47 private MemoryRequirement() {
48 super(GeneratedPQuery.INSTANCE);
49 }
50
51 /**
52 * @return the singleton instance of the query specification
53 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
54 *
55 */
56 public static MemoryRequirement instance() {
57 try{
58 return LazyHolder.INSTANCE;
59 } catch (ExceptionInInitializerError err) {
60 throw processInitializerError(err);
61 }
62 }
63
64 /**
65 * Inner class allowing the singleton instance of {@link MemoryRequirement} to be created
66 * <b>not</b> at the class load time of the outer class,
67 * but rather at the first call to {@link MemoryRequirement#instance()}.
68 *
69 * <p> This workaround is required e.g. to support recursion.
70 *
71 */
72 private static class LazyHolder {
73 private static final MemoryRequirement INSTANCE = new MemoryRequirement();
74
75 /**
76 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
77 * This initialization order is required to support indirect recursion.
78 *
79 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
80 *
81 */
82 private static final Object STATIC_INITIALIZER = ensureInitialized();
83
84 public static Object ensureInitialized() {
85 INSTANCE.ensureInitializedInternal();
86 return null;
87 }
88 }
89
90 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
91 private static final MemoryRequirement.GeneratedPQuery INSTANCE = new GeneratedPQuery();
92
93 private final PParameter parameter_Host = new PParameter("Host", "hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "HostInstance")), PParameterDirection.INOUT);
94
95 private final PParameter parameter_App = new PParameter("App", "hu.bme.mit.inf.dslreasoner.domains.cps.ApplicationInstance", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "ApplicationInstance")), PParameterDirection.INOUT);
96
97 private final PParameter parameter_Memory = new PParameter("Memory", "java.lang.Integer", new EDataTypeInSlotsKey((EDataType)getClassifierLiteralSafe("http://www.eclipse.org/emf/2002/Ecore", "EInt")), PParameterDirection.INOUT);
98
99 private final List<PParameter> parameters = Arrays.asList(parameter_Host, parameter_App, parameter_Memory);
100
101 private GeneratedPQuery() {
102 super(PVisibility.PRIVATE);
103 }
104
105 @Override
106 public String getFullyQualifiedName() {
107 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.memoryRequirement";
108 }
109
110 @Override
111 public List<String> getParameterNames() {
112 return Arrays.asList("Host","App","Memory");
113 }
114
115 @Override
116 public List<PParameter> getParameters() {
117 return parameters;
118 }
119
120 @Override
121 public Set<PBody> doGetContainedBodies() {
122 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
123 Set<PBody> bodies = new LinkedHashSet<>();
124 {
125 PBody body = new PBody(this);
126 PVariable var_Host = body.getOrCreateVariableByName("Host");
127 PVariable var_App = body.getOrCreateVariableByName("App");
128 PVariable var_Memory = body.getOrCreateVariableByName("Memory");
129 PVariable var_Req = body.getOrCreateVariableByName("Req");
130 new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance")));
131 new TypeConstraint(body, Tuples.flatTupleOf(var_App), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance")));
132 new TypeConstraint(body, Tuples.flatTupleOf(var_Memory), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt")));
133 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
134 new ExportedParameter(body, var_Host, parameter_Host),
135 new ExportedParameter(body, var_App, parameter_App),
136 new ExportedParameter(body, var_Memory, parameter_Memory)
137 ));
138 // find resourceRequirement(Host, App, Req)
139 new PositivePatternCall(body, Tuples.flatTupleOf(var_Host, var_App, var_Req), ResourceRequirement.instance().getInternalQueryRepresentation());
140 // ResourceRequirement.requiredMemory(Req, Memory)
141 new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ResourceRequirement")));
142 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
143 new TypeConstraint(body, Tuples.flatTupleOf(var_Req, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ResourceRequirement", "requiredMemory")));
144 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt")));
145 new Equality(body, var__virtual_0_, var_Memory);
146 bodies.add(body);
147 }
148 return bodies;
149 }
150 }
151}
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/NoHostToAllocateTo.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/NoHostToAllocateTo.java
new file mode 100644
index 00000000..155ed09b
--- /dev/null
+++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/NoHostToAllocateTo.java
@@ -0,0 +1,135 @@
1/**
2 * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql
3 */
4package hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal;
5
6import hu.bme.mit.inf.dslreasoner.domains.cps.queries.Allocate;
7import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.UnallocatedAppInstance;
8import java.util.Arrays;
9import java.util.LinkedHashSet;
10import java.util.List;
11import java.util.Set;
12import org.eclipse.emf.ecore.EClass;
13import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
14import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecificationWithGenericMatcher;
15import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey;
16import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
17import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
18import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
19import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
20import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.NegativePatternCall;
21import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall;
22import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
23import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
24import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
25import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
26import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
27
28/**
29 * A pattern-specific query specification that can instantiate GenericPatternMatcher in a type-safe way.
30 *
31 * <p>Original source:
32 * <code><pre>
33 * private pattern noHostToAllocateTo(App : ApplicationInstance) {
34 * find unallocatedAppInstance(App);
35 * neg find allocate(App, _);
36 * }
37 * </pre></code>
38 *
39 * @see GenericPatternMatcher
40 * @see GenericPatternMatch
41 *
42 */
43@SuppressWarnings("all")
44public final class NoHostToAllocateTo extends BaseGeneratedEMFQuerySpecificationWithGenericMatcher {
45 private NoHostToAllocateTo() {
46 super(GeneratedPQuery.INSTANCE);
47 }
48
49 /**
50 * @return the singleton instance of the query specification
51 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
52 *
53 */
54 public static NoHostToAllocateTo instance() {
55 try{
56 return LazyHolder.INSTANCE;
57 } catch (ExceptionInInitializerError err) {
58 throw processInitializerError(err);
59 }
60 }
61
62 /**
63 * Inner class allowing the singleton instance of {@link NoHostToAllocateTo} to be created
64 * <b>not</b> at the class load time of the outer class,
65 * but rather at the first call to {@link NoHostToAllocateTo#instance()}.
66 *
67 * <p> This workaround is required e.g. to support recursion.
68 *
69 */
70 private static class LazyHolder {
71 private static final NoHostToAllocateTo INSTANCE = new NoHostToAllocateTo();
72
73 /**
74 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
75 * This initialization order is required to support indirect recursion.
76 *
77 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
78 *
79 */
80 private static final Object STATIC_INITIALIZER = ensureInitialized();
81
82 public static Object ensureInitialized() {
83 INSTANCE.ensureInitializedInternal();
84 return null;
85 }
86 }
87
88 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
89 private static final NoHostToAllocateTo.GeneratedPQuery INSTANCE = new GeneratedPQuery();
90
91 private final PParameter parameter_App = new PParameter("App", "hu.bme.mit.inf.dslreasoner.domains.cps.ApplicationInstance", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "ApplicationInstance")), PParameterDirection.INOUT);
92
93 private final List<PParameter> parameters = Arrays.asList(parameter_App);
94
95 private GeneratedPQuery() {
96 super(PVisibility.PRIVATE);
97 }
98
99 @Override
100 public String getFullyQualifiedName() {
101 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.noHostToAllocateTo";
102 }
103
104 @Override
105 public List<String> getParameterNames() {
106 return Arrays.asList("App");
107 }
108
109 @Override
110 public List<PParameter> getParameters() {
111 return parameters;
112 }
113
114 @Override
115 public Set<PBody> doGetContainedBodies() {
116 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
117 Set<PBody> bodies = new LinkedHashSet<>();
118 {
119 PBody body = new PBody(this);
120 PVariable var_App = body.getOrCreateVariableByName("App");
121 PVariable var___0_ = body.getOrCreateVariableByName("_<0>");
122 new TypeConstraint(body, Tuples.flatTupleOf(var_App), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance")));
123 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
124 new ExportedParameter(body, var_App, parameter_App)
125 ));
126 // find unallocatedAppInstance(App)
127 new PositivePatternCall(body, Tuples.flatTupleOf(var_App), UnallocatedAppInstance.instance().getInternalQueryRepresentation());
128 // neg find allocate(App, _)
129 new NegativePatternCall(body, Tuples.flatTupleOf(var_App, var___0_), Allocate.instance().getInternalQueryRepresentation());
130 bodies.add(body);
131 }
132 return bodies;
133 }
134 }
135}
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/RequiredAppInstances.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/RequiredAppInstances.java
new file mode 100644
index 00000000..ffce9148
--- /dev/null
+++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/RequiredAppInstances.java
@@ -0,0 +1,181 @@
1/**
2 * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql
3 */
4package hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal;
5
6import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.SatisfyingInstance;
7import java.util.Arrays;
8import java.util.LinkedHashSet;
9import java.util.List;
10import java.util.Set;
11import org.eclipse.emf.ecore.EClass;
12import org.eclipse.emf.ecore.EDataType;
13import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
14import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecificationWithGenericMatcher;
15import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey;
16import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey;
17import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey;
18import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
19import org.eclipse.viatra.query.runtime.matchers.context.common.JavaTransitiveInstancesKey;
20import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator;
21import org.eclipse.viatra.query.runtime.matchers.psystem.IValueProvider;
22import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
23import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
24import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality;
25import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
26import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation;
27import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.PatternMatchCounter;
28import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.TypeFilterConstraint;
29import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
30import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
31import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
32import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
33import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
34
35/**
36 * A pattern-specific query specification that can instantiate GenericPatternMatcher in a type-safe way.
37 *
38 * <p>Original source:
39 * <code><pre>
40 * private pattern requiredAppInstances(Req : Requirement, Remaining : java Integer) {
41 * Instances == count find satisfyingInstance(Req, _);
42 * Requirement.count(Req, RequiredCount);
43 * Remaining == eval(RequiredCount - Instances);
44 * }
45 * </pre></code>
46 *
47 * @see GenericPatternMatcher
48 * @see GenericPatternMatch
49 *
50 */
51@SuppressWarnings("all")
52public final class RequiredAppInstances extends BaseGeneratedEMFQuerySpecificationWithGenericMatcher {
53 private RequiredAppInstances() {
54 super(GeneratedPQuery.INSTANCE);
55 }
56
57 /**
58 * @return the singleton instance of the query specification
59 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
60 *
61 */
62 public static RequiredAppInstances instance() {
63 try{
64 return LazyHolder.INSTANCE;
65 } catch (ExceptionInInitializerError err) {
66 throw processInitializerError(err);
67 }
68 }
69
70 /**
71 * Inner class allowing the singleton instance of {@link RequiredAppInstances} to be created
72 * <b>not</b> at the class load time of the outer class,
73 * but rather at the first call to {@link RequiredAppInstances#instance()}.
74 *
75 * <p> This workaround is required e.g. to support recursion.
76 *
77 */
78 private static class LazyHolder {
79 private static final RequiredAppInstances INSTANCE = new RequiredAppInstances();
80
81 /**
82 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
83 * This initialization order is required to support indirect recursion.
84 *
85 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
86 *
87 */
88 private static final Object STATIC_INITIALIZER = ensureInitialized();
89
90 public static Object ensureInitialized() {
91 INSTANCE.ensureInitializedInternal();
92 return null;
93 }
94 }
95
96 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
97 private static final RequiredAppInstances.GeneratedPQuery INSTANCE = new GeneratedPQuery();
98
99 private final PParameter parameter_Req = new PParameter("Req", "hu.bme.mit.inf.dslreasoner.domains.cps.Requirement", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "Requirement")), PParameterDirection.INOUT);
100
101 private final PParameter parameter_Remaining = new PParameter("Remaining", "java.lang.Integer", new JavaTransitiveInstancesKey(java.lang.Integer.class), PParameterDirection.INOUT);
102
103 private final List<PParameter> parameters = Arrays.asList(parameter_Req, parameter_Remaining);
104
105 private GeneratedPQuery() {
106 super(PVisibility.PRIVATE);
107 }
108
109 @Override
110 public String getFullyQualifiedName() {
111 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.requiredAppInstances";
112 }
113
114 @Override
115 public List<String> getParameterNames() {
116 return Arrays.asList("Req","Remaining");
117 }
118
119 @Override
120 public List<PParameter> getParameters() {
121 return parameters;
122 }
123
124 @Override
125 public Set<PBody> doGetContainedBodies() {
126 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
127 Set<PBody> bodies = new LinkedHashSet<>();
128 {
129 PBody body = new PBody(this);
130 PVariable var_Req = body.getOrCreateVariableByName("Req");
131 PVariable var_Remaining = body.getOrCreateVariableByName("Remaining");
132 PVariable var_Instances = body.getOrCreateVariableByName("Instances");
133 PVariable var___0_ = body.getOrCreateVariableByName("_<0>");
134 PVariable var_RequiredCount = body.getOrCreateVariableByName("RequiredCount");
135 new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "Requirement")));
136 new TypeFilterConstraint(body, Tuples.flatTupleOf(var_Remaining), new JavaTransitiveInstancesKey(java.lang.Integer.class));
137 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
138 new ExportedParameter(body, var_Req, parameter_Req),
139 new ExportedParameter(body, var_Remaining, parameter_Remaining)
140 ));
141 // Instances == count find satisfyingInstance(Req, _)
142 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
143 new PatternMatchCounter(body, Tuples.flatTupleOf(var_Req, var___0_), SatisfyingInstance.instance().getInternalQueryRepresentation(), var__virtual_0_);
144 new Equality(body, var_Instances, var__virtual_0_);
145 // Requirement.count(Req, RequiredCount)
146 new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "Requirement")));
147 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
148 new TypeConstraint(body, Tuples.flatTupleOf(var_Req, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "Requirement", "count")));
149 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt")));
150 new Equality(body, var__virtual_1_, var_RequiredCount);
151 // Remaining == eval(RequiredCount - Instances)
152 PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}");
153 new ExpressionEvaluation(body, new IExpressionEvaluator() {
154
155 @Override
156 public String getShortDescription() {
157 return "Expression evaluation from pattern requiredAppInstances";
158 }
159
160 @Override
161 public Iterable<String> getInputParameterNames() {
162 return Arrays.asList("Instances", "RequiredCount");}
163
164 @Override
165 public Object evaluateExpression(IValueProvider provider) throws Exception {
166 Integer Instances = (Integer) provider.getValue("Instances");
167 Integer RequiredCount = (Integer) provider.getValue("RequiredCount");
168 return evaluateExpression_1_1(Instances, RequiredCount);
169 }
170 }, var__virtual_2_ );
171 new Equality(body, var_Remaining, var__virtual_2_);
172 bodies.add(body);
173 }
174 return bodies;
175 }
176 }
177
178 private static int evaluateExpression_1_1(final Integer Instances, final Integer RequiredCount) {
179 return ((RequiredCount).intValue() - (Instances).intValue());
180 }
181}
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/SatisfyingInstance.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/SatisfyingInstance.java
new file mode 100644
index 00000000..dea68f94
--- /dev/null
+++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/SatisfyingInstance.java
@@ -0,0 +1,153 @@
1/**
2 * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql
3 */
4package hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal;
5
6import java.util.Arrays;
7import java.util.LinkedHashSet;
8import java.util.List;
9import java.util.Set;
10import org.eclipse.emf.ecore.EClass;
11import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
12import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecificationWithGenericMatcher;
13import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey;
14import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey;
15import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
16import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
17import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
18import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality;
19import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
20import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
21import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
22import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
23import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
24import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
25
26/**
27 * A pattern-specific query specification that can instantiate GenericPatternMatcher in a type-safe way.
28 *
29 * <p>Original source:
30 * <code><pre>
31 * private pattern satisfyingInstance(Req : Requirement, App : ApplicationInstance) {
32 * Requirement.instances(Req, App);
33 * Requirement.type(Req, Type);
34 * ApplicationInstance.type(App, Type);
35 * }
36 * </pre></code>
37 *
38 * @see GenericPatternMatcher
39 * @see GenericPatternMatch
40 *
41 */
42@SuppressWarnings("all")
43public final class SatisfyingInstance extends BaseGeneratedEMFQuerySpecificationWithGenericMatcher {
44 private SatisfyingInstance() {
45 super(GeneratedPQuery.INSTANCE);
46 }
47
48 /**
49 * @return the singleton instance of the query specification
50 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
51 *
52 */
53 public static SatisfyingInstance instance() {
54 try{
55 return LazyHolder.INSTANCE;
56 } catch (ExceptionInInitializerError err) {
57 throw processInitializerError(err);
58 }
59 }
60
61 /**
62 * Inner class allowing the singleton instance of {@link SatisfyingInstance} to be created
63 * <b>not</b> at the class load time of the outer class,
64 * but rather at the first call to {@link SatisfyingInstance#instance()}.
65 *
66 * <p> This workaround is required e.g. to support recursion.
67 *
68 */
69 private static class LazyHolder {
70 private static final SatisfyingInstance INSTANCE = new SatisfyingInstance();
71
72 /**
73 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
74 * This initialization order is required to support indirect recursion.
75 *
76 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
77 *
78 */
79 private static final Object STATIC_INITIALIZER = ensureInitialized();
80
81 public static Object ensureInitialized() {
82 INSTANCE.ensureInitializedInternal();
83 return null;
84 }
85 }
86
87 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
88 private static final SatisfyingInstance.GeneratedPQuery INSTANCE = new GeneratedPQuery();
89
90 private final PParameter parameter_Req = new PParameter("Req", "hu.bme.mit.inf.dslreasoner.domains.cps.Requirement", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "Requirement")), PParameterDirection.INOUT);
91
92 private final PParameter parameter_App = new PParameter("App", "hu.bme.mit.inf.dslreasoner.domains.cps.ApplicationInstance", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "ApplicationInstance")), PParameterDirection.INOUT);
93
94 private final List<PParameter> parameters = Arrays.asList(parameter_Req, parameter_App);
95
96 private GeneratedPQuery() {
97 super(PVisibility.PRIVATE);
98 }
99
100 @Override
101 public String getFullyQualifiedName() {
102 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.satisfyingInstance";
103 }
104
105 @Override
106 public List<String> getParameterNames() {
107 return Arrays.asList("Req","App");
108 }
109
110 @Override
111 public List<PParameter> getParameters() {
112 return parameters;
113 }
114
115 @Override
116 public Set<PBody> doGetContainedBodies() {
117 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
118 Set<PBody> bodies = new LinkedHashSet<>();
119 {
120 PBody body = new PBody(this);
121 PVariable var_Req = body.getOrCreateVariableByName("Req");
122 PVariable var_App = body.getOrCreateVariableByName("App");
123 PVariable var_Type = body.getOrCreateVariableByName("Type");
124 new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "Requirement")));
125 new TypeConstraint(body, Tuples.flatTupleOf(var_App), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance")));
126 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
127 new ExportedParameter(body, var_Req, parameter_Req),
128 new ExportedParameter(body, var_App, parameter_App)
129 ));
130 // Requirement.instances(Req, App)
131 new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "Requirement")));
132 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
133 new TypeConstraint(body, Tuples.flatTupleOf(var_Req, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "Requirement", "instances")));
134 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance")));
135 new Equality(body, var__virtual_0_, var_App);
136 // Requirement.type(Req, Type)
137 new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "Requirement")));
138 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
139 new TypeConstraint(body, Tuples.flatTupleOf(var_Req, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "Requirement", "type")));
140 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationType")));
141 new Equality(body, var__virtual_1_, var_Type);
142 // ApplicationInstance.type(App, Type)
143 new TypeConstraint(body, Tuples.flatTupleOf(var_App), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance")));
144 PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}");
145 new TypeConstraint(body, Tuples.flatTupleOf(var_App, var__virtual_2_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ApplicationInstance", "type")));
146 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationType")));
147 new Equality(body, var__virtual_2_, var_Type);
148 bodies.add(body);
149 }
150 return bodies;
151 }
152 }
153}
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/TotalHdd.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/TotalHdd.java
new file mode 100644
index 00000000..efa13033
--- /dev/null
+++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/TotalHdd.java
@@ -0,0 +1,143 @@
1/**
2 * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql
3 */
4package hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal;
5
6import java.util.Arrays;
7import java.util.LinkedHashSet;
8import java.util.List;
9import java.util.Set;
10import org.eclipse.emf.ecore.EClass;
11import org.eclipse.emf.ecore.EDataType;
12import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
13import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecificationWithGenericMatcher;
14import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey;
15import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey;
16import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey;
17import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
18import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
19import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
20import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality;
21import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
22import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
23import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
24import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
25import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
26import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
27
28/**
29 * A pattern-specific query specification that can instantiate GenericPatternMatcher in a type-safe way.
30 *
31 * <p>Original source:
32 * <code><pre>
33 * private pattern totalHdd(Host : HostInstance, Hdd : EInt) {
34 * HostInstance.type.defaultHdd(Host, Hdd);
35 * }
36 * </pre></code>
37 *
38 * @see GenericPatternMatcher
39 * @see GenericPatternMatch
40 *
41 */
42@SuppressWarnings("all")
43public final class TotalHdd extends BaseGeneratedEMFQuerySpecificationWithGenericMatcher {
44 private TotalHdd() {
45 super(GeneratedPQuery.INSTANCE);
46 }
47
48 /**
49 * @return the singleton instance of the query specification
50 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
51 *
52 */
53 public static TotalHdd instance() {
54 try{
55 return LazyHolder.INSTANCE;
56 } catch (ExceptionInInitializerError err) {
57 throw processInitializerError(err);
58 }
59 }
60
61 /**
62 * Inner class allowing the singleton instance of {@link TotalHdd} to be created
63 * <b>not</b> at the class load time of the outer class,
64 * but rather at the first call to {@link TotalHdd#instance()}.
65 *
66 * <p> This workaround is required e.g. to support recursion.
67 *
68 */
69 private static class LazyHolder {
70 private static final TotalHdd INSTANCE = new TotalHdd();
71
72 /**
73 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
74 * This initialization order is required to support indirect recursion.
75 *
76 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
77 *
78 */
79 private static final Object STATIC_INITIALIZER = ensureInitialized();
80
81 public static Object ensureInitialized() {
82 INSTANCE.ensureInitializedInternal();
83 return null;
84 }
85 }
86
87 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
88 private static final TotalHdd.GeneratedPQuery INSTANCE = new GeneratedPQuery();
89
90 private final PParameter parameter_Host = new PParameter("Host", "hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "HostInstance")), PParameterDirection.INOUT);
91
92 private final PParameter parameter_Hdd = new PParameter("Hdd", "java.lang.Integer", new EDataTypeInSlotsKey((EDataType)getClassifierLiteralSafe("http://www.eclipse.org/emf/2002/Ecore", "EInt")), PParameterDirection.INOUT);
93
94 private final List<PParameter> parameters = Arrays.asList(parameter_Host, parameter_Hdd);
95
96 private GeneratedPQuery() {
97 super(PVisibility.PRIVATE);
98 }
99
100 @Override
101 public String getFullyQualifiedName() {
102 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.totalHdd";
103 }
104
105 @Override
106 public List<String> getParameterNames() {
107 return Arrays.asList("Host","Hdd");
108 }
109
110 @Override
111 public List<PParameter> getParameters() {
112 return parameters;
113 }
114
115 @Override
116 public Set<PBody> doGetContainedBodies() {
117 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
118 Set<PBody> bodies = new LinkedHashSet<>();
119 {
120 PBody body = new PBody(this);
121 PVariable var_Host = body.getOrCreateVariableByName("Host");
122 PVariable var_Hdd = body.getOrCreateVariableByName("Hdd");
123 new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance")));
124 new TypeConstraint(body, Tuples.flatTupleOf(var_Hdd), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt")));
125 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
126 new ExportedParameter(body, var_Host, parameter_Host),
127 new ExportedParameter(body, var_Hdd, parameter_Hdd)
128 ));
129 // HostInstance.type.defaultHdd(Host, Hdd)
130 new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance")));
131 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
132 new TypeConstraint(body, Tuples.flatTupleOf(var_Host, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "HostInstance", "type")));
133 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostType")));
134 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
135 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "HostType", "defaultHdd")));
136 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt")));
137 new Equality(body, var__virtual_1_, var_Hdd);
138 bodies.add(body);
139 }
140 return bodies;
141 }
142 }
143}
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/TotalMemory.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/TotalMemory.java
new file mode 100644
index 00000000..2fe3e741
--- /dev/null
+++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/TotalMemory.java
@@ -0,0 +1,143 @@
1/**
2 * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql
3 */
4package hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal;
5
6import java.util.Arrays;
7import java.util.LinkedHashSet;
8import java.util.List;
9import java.util.Set;
10import org.eclipse.emf.ecore.EClass;
11import org.eclipse.emf.ecore.EDataType;
12import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
13import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecificationWithGenericMatcher;
14import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey;
15import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey;
16import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey;
17import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
18import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
19import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
20import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality;
21import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
22import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
23import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
24import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
25import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
26import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
27
28/**
29 * A pattern-specific query specification that can instantiate GenericPatternMatcher in a type-safe way.
30 *
31 * <p>Original source:
32 * <code><pre>
33 * private pattern totalMemory(Host : HostInstance, Memory : EInt) {
34 * HostInstance.type.defaultMemory(Host, Memory);
35 * }
36 * </pre></code>
37 *
38 * @see GenericPatternMatcher
39 * @see GenericPatternMatch
40 *
41 */
42@SuppressWarnings("all")
43public final class TotalMemory extends BaseGeneratedEMFQuerySpecificationWithGenericMatcher {
44 private TotalMemory() {
45 super(GeneratedPQuery.INSTANCE);
46 }
47
48 /**
49 * @return the singleton instance of the query specification
50 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
51 *
52 */
53 public static TotalMemory instance() {
54 try{
55 return LazyHolder.INSTANCE;
56 } catch (ExceptionInInitializerError err) {
57 throw processInitializerError(err);
58 }
59 }
60
61 /**
62 * Inner class allowing the singleton instance of {@link TotalMemory} to be created
63 * <b>not</b> at the class load time of the outer class,
64 * but rather at the first call to {@link TotalMemory#instance()}.
65 *
66 * <p> This workaround is required e.g. to support recursion.
67 *
68 */
69 private static class LazyHolder {
70 private static final TotalMemory INSTANCE = new TotalMemory();
71
72 /**
73 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
74 * This initialization order is required to support indirect recursion.
75 *
76 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
77 *
78 */
79 private static final Object STATIC_INITIALIZER = ensureInitialized();
80
81 public static Object ensureInitialized() {
82 INSTANCE.ensureInitializedInternal();
83 return null;
84 }
85 }
86
87 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
88 private static final TotalMemory.GeneratedPQuery INSTANCE = new GeneratedPQuery();
89
90 private final PParameter parameter_Host = new PParameter("Host", "hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "HostInstance")), PParameterDirection.INOUT);
91
92 private final PParameter parameter_Memory = new PParameter("Memory", "java.lang.Integer", new EDataTypeInSlotsKey((EDataType)getClassifierLiteralSafe("http://www.eclipse.org/emf/2002/Ecore", "EInt")), PParameterDirection.INOUT);
93
94 private final List<PParameter> parameters = Arrays.asList(parameter_Host, parameter_Memory);
95
96 private GeneratedPQuery() {
97 super(PVisibility.PRIVATE);
98 }
99
100 @Override
101 public String getFullyQualifiedName() {
102 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.totalMemory";
103 }
104
105 @Override
106 public List<String> getParameterNames() {
107 return Arrays.asList("Host","Memory");
108 }
109
110 @Override
111 public List<PParameter> getParameters() {
112 return parameters;
113 }
114
115 @Override
116 public Set<PBody> doGetContainedBodies() {
117 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
118 Set<PBody> bodies = new LinkedHashSet<>();
119 {
120 PBody body = new PBody(this);
121 PVariable var_Host = body.getOrCreateVariableByName("Host");
122 PVariable var_Memory = body.getOrCreateVariableByName("Memory");
123 new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance")));
124 new TypeConstraint(body, Tuples.flatTupleOf(var_Memory), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt")));
125 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
126 new ExportedParameter(body, var_Host, parameter_Host),
127 new ExportedParameter(body, var_Memory, parameter_Memory)
128 ));
129 // HostInstance.type.defaultMemory(Host, Memory)
130 new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance")));
131 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
132 new TypeConstraint(body, Tuples.flatTupleOf(var_Host, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "HostInstance", "type")));
133 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostType")));
134 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
135 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "HostType", "defaultMemory")));
136 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt")));
137 new Equality(body, var__virtual_1_, var_Memory);
138 bodies.add(body);
139 }
140 return bodies;
141 }
142 }
143}
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/UnallocatedAppInstance.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/UnallocatedAppInstance.java
new file mode 100644
index 00000000..66b315f4
--- /dev/null
+++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/UnallocatedAppInstance.java
@@ -0,0 +1,172 @@
1/**
2 * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql
3 */
4package hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal;
5
6import java.util.Arrays;
7import java.util.Collections;
8import java.util.LinkedHashSet;
9import java.util.List;
10import java.util.Set;
11import org.eclipse.emf.ecore.EClass;
12import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
13import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecificationWithGenericMatcher;
14import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey;
15import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey;
16import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
17import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
18import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
19import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality;
20import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
21import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.NegativePatternCall;
22import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
23import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
24import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
25import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
26import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
27
28/**
29 * A pattern-specific query specification that can instantiate GenericPatternMatcher in a type-safe way.
30 *
31 * <p>Original source:
32 * <code><pre>
33 * private pattern unallocatedAppInstance(App : ApplicationInstance) {
34 * neg ApplicationInstance.allocatedTo(App, _);
35 * }
36 * </pre></code>
37 *
38 * @see GenericPatternMatcher
39 * @see GenericPatternMatch
40 *
41 */
42@SuppressWarnings("all")
43public final class UnallocatedAppInstance extends BaseGeneratedEMFQuerySpecificationWithGenericMatcher {
44 private UnallocatedAppInstance() {
45 super(GeneratedPQuery.INSTANCE);
46 }
47
48 /**
49 * @return the singleton instance of the query specification
50 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
51 *
52 */
53 public static UnallocatedAppInstance instance() {
54 try{
55 return LazyHolder.INSTANCE;
56 } catch (ExceptionInInitializerError err) {
57 throw processInitializerError(err);
58 }
59 }
60
61 /**
62 * Inner class allowing the singleton instance of {@link UnallocatedAppInstance} to be created
63 * <b>not</b> at the class load time of the outer class,
64 * but rather at the first call to {@link UnallocatedAppInstance#instance()}.
65 *
66 * <p> This workaround is required e.g. to support recursion.
67 *
68 */
69 private static class LazyHolder {
70 private static final UnallocatedAppInstance INSTANCE = new UnallocatedAppInstance();
71
72 /**
73 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
74 * This initialization order is required to support indirect recursion.
75 *
76 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
77 *
78 */
79 private static final Object STATIC_INITIALIZER = ensureInitialized();
80
81 public static Object ensureInitialized() {
82 INSTANCE.ensureInitializedInternal();
83 return null;
84 }
85 }
86
87 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
88 private static final UnallocatedAppInstance.GeneratedPQuery INSTANCE = new GeneratedPQuery();
89
90 private final PParameter parameter_App = new PParameter("App", "hu.bme.mit.inf.dslreasoner.domains.cps.ApplicationInstance", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "ApplicationInstance")), PParameterDirection.INOUT);
91
92 private final List<PParameter> parameters = Arrays.asList(parameter_App);
93
94 private class Embedded_1_ApplicationInstance_allocatedTo extends BaseGeneratedEMFPQuery {
95 private final PParameter parameter_p0 = new PParameter("p0", "hu.bme.mit.inf.dslreasoner.domains.cps.ApplicationInstance", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "ApplicationInstance")), PParameterDirection.INOUT);
96
97 private final PParameter parameter_p1 = new PParameter("p1", "hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "HostInstance")), PParameterDirection.INOUT);
98
99 private final List<PParameter> embeddedParameters = Arrays.asList(parameter_p0, parameter_p1);
100
101 public Embedded_1_ApplicationInstance_allocatedTo() {
102 super(PVisibility.EMBEDDED);
103 }
104
105 @Override
106 public String getFullyQualifiedName() {
107 return GeneratedPQuery.this.getFullyQualifiedName() + "$Embedded_1_ApplicationInstance_allocatedTo";
108 }
109
110 @Override
111 public List<PParameter> getParameters() {
112 return embeddedParameters;
113 }
114
115 @Override
116 public Set<PBody> doGetContainedBodies() {
117 PBody body = new PBody(this);
118 PVariable var_p0 = body.getOrCreateVariableByName("p0");
119 PVariable var_p1 = body.getOrCreateVariableByName("p1");
120 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
121 new ExportedParameter(body, var_p0, parameter_p0),
122 new ExportedParameter(body, var_p1, parameter_p1)
123 ));
124 // ApplicationInstance.allocatedTo(App, _)
125 new TypeConstraint(body, Tuples.flatTupleOf(var_p0), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance")));
126 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
127 new TypeConstraint(body, Tuples.flatTupleOf(var_p0, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ApplicationInstance", "allocatedTo")));
128 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance")));
129 new Equality(body, var__virtual_0_, var_p1);
130 return Collections.singleton(body);
131 }
132 }
133
134 private GeneratedPQuery() {
135 super(PVisibility.PRIVATE);
136 }
137
138 @Override
139 public String getFullyQualifiedName() {
140 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.unallocatedAppInstance";
141 }
142
143 @Override
144 public List<String> getParameterNames() {
145 return Arrays.asList("App");
146 }
147
148 @Override
149 public List<PParameter> getParameters() {
150 return parameters;
151 }
152
153 @Override
154 public Set<PBody> doGetContainedBodies() {
155 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
156 Set<PBody> bodies = new LinkedHashSet<>();
157 {
158 PBody body = new PBody(this);
159 PVariable var_App = body.getOrCreateVariableByName("App");
160 PVariable var___0_ = body.getOrCreateVariableByName("_<0>");
161 new TypeConstraint(body, Tuples.flatTupleOf(var_App), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance")));
162 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
163 new ExportedParameter(body, var_App, parameter_App)
164 ));
165 // neg ApplicationInstance.allocatedTo(App, _)
166 new NegativePatternCall(body, Tuples.flatTupleOf(var_App, var___0_), new UnallocatedAppInstance.GeneratedPQuery.Embedded_1_ApplicationInstance_allocatedTo());
167 bodies.add(body);
168 }
169 return bodies;
170 }
171 }
172}