aboutsummaryrefslogtreecommitdiffstats
path: root/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kris7topher@gmail.com>2019-05-15 13:46:38 -0400
committerLibravatar Kristóf Marussy <kris7topher@gmail.com>2019-05-15 13:46:38 -0400
commite904f9d4b1d2d15ab4ec6d72ee881f4c7de34eef (patch)
tree42cb23ff8839308345c0859cdf99469c930af03b /Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen
parentMerge remote-tracking branch 'origin/master' into kris (diff)
downloadVIATRA-Generator-e904f9d4b1d2d15ab4ec6d72ee881f4c7de34eef.tar.gz
VIATRA-Generator-e904f9d4b1d2d15ab4ec6d72ee881f4c7de34eef.tar.zst
VIATRA-Generator-e904f9d4b1d2d15ab4ec6d72ee881f4c7de34eef.zip
Formalize CPS case study for optimization
Diffstat (limited to 'Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen')
-rw-r--r--Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/.gitignore16
-rw-r--r--Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/AllocationWithoutResourceRequirement.java717
-rw-r--r--Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/AvailableHdd.java743
-rw-r--r--Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/AvailableMemory.java743
-rw-r--r--Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/AverageFreeHddMetric.java540
-rw-r--r--Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/AverageFreeMemoryMetric.java540
-rw-r--r--Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CostMetric.java540
-rw-r--r--Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsApplications.java705
-rw-r--r--Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsCost.java738
-rw-r--r--Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsHosts.java705
-rw-r--r--Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.java207
-rw-r--r--Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/InstanceDoesNotSatisfyRequirement.java716
-rw-r--r--Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/NotEnoughAvailableHdd.java579
-rw-r--r--Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/NotEnoughAvailableMemory.java579
-rw-r--r--Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/RequirementNotSatisfied.java597
-rw-r--r--Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/TotalHdd.java706
-rw-r--r--Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/TotalMemory.java706
-rw-r--r--Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/.gitignore11
-rw-r--r--Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/CpsQueriesAll.java105
-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/ResourceRequirement.java168
-rw-r--r--Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/SatisfyingInstance.java153
26 files changed, 11313 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..bd8f7d9f
--- /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,16 @@
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
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..be7488b6
--- /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,717 @@
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.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 if ("Host".equals(parameterName)) return this.fHost;
92 if ("App".equals(parameterName)) return this.fApp;
93 return null;
94 }
95
96 public HostInstance getHost() {
97 return this.fHost;
98 }
99
100 public ApplicationInstance getApp() {
101 return this.fApp;
102 }
103
104 @Override
105 public boolean set(final String parameterName, final Object newValue) {
106 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
107 if ("Host".equals(parameterName) ) {
108 this.fHost = (HostInstance) newValue;
109 return true;
110 }
111 if ("App".equals(parameterName) ) {
112 this.fApp = (ApplicationInstance) newValue;
113 return true;
114 }
115 return false;
116 }
117
118 public void setHost(final HostInstance pHost) {
119 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
120 this.fHost = pHost;
121 }
122
123 public void setApp(final ApplicationInstance pApp) {
124 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
125 this.fApp = pApp;
126 }
127
128 @Override
129 public String patternName() {
130 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.allocationWithoutResourceRequirement";
131 }
132
133 @Override
134 public List<String> parameterNames() {
135 return AllocationWithoutResourceRequirement.Match.parameterNames;
136 }
137
138 @Override
139 public Object[] toArray() {
140 return new Object[]{fHost, fApp};
141 }
142
143 @Override
144 public AllocationWithoutResourceRequirement.Match toImmutable() {
145 return isMutable() ? newMatch(fHost, fApp) : this;
146 }
147
148 @Override
149 public String prettyPrint() {
150 StringBuilder result = new StringBuilder();
151 result.append("\"Host\"=" + prettyPrintValue(fHost) + ", ");
152 result.append("\"App\"=" + prettyPrintValue(fApp));
153 return result.toString();
154 }
155
156 @Override
157 public int hashCode() {
158 return Objects.hash(fHost, fApp);
159 }
160
161 @Override
162 public boolean equals(final Object obj) {
163 if (this == obj)
164 return true;
165 if (obj == null) {
166 return false;
167 }
168 if ((obj instanceof AllocationWithoutResourceRequirement.Match)) {
169 AllocationWithoutResourceRequirement.Match other = (AllocationWithoutResourceRequirement.Match) obj;
170 return Objects.equals(fHost, other.fHost) && Objects.equals(fApp, other.fApp);
171 } else {
172 // this should be infrequent
173 if (!(obj instanceof IPatternMatch)) {
174 return false;
175 }
176 IPatternMatch otherSig = (IPatternMatch) obj;
177 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
178 }
179 }
180
181 @Override
182 public AllocationWithoutResourceRequirement specification() {
183 return AllocationWithoutResourceRequirement.instance();
184 }
185
186 /**
187 * Returns an empty, mutable match.
188 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
189 *
190 * @return the empty match.
191 *
192 */
193 public static AllocationWithoutResourceRequirement.Match newEmptyMatch() {
194 return new Mutable(null, null);
195 }
196
197 /**
198 * Returns a mutable (partial) match.
199 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
200 *
201 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
202 * @param pApp the fixed value of pattern parameter App, or null if not bound.
203 * @return the new, mutable (partial) match object.
204 *
205 */
206 public static AllocationWithoutResourceRequirement.Match newMutableMatch(final HostInstance pHost, final ApplicationInstance pApp) {
207 return new Mutable(pHost, pApp);
208 }
209
210 /**
211 * Returns a new (partial) match.
212 * This can be used e.g. to call the matcher with a partial match.
213 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
214 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
215 * @param pApp the fixed value of pattern parameter App, or null if not bound.
216 * @return the (partial) match object.
217 *
218 */
219 public static AllocationWithoutResourceRequirement.Match newMatch(final HostInstance pHost, final ApplicationInstance pApp) {
220 return new Immutable(pHost, pApp);
221 }
222
223 private static final class Mutable extends AllocationWithoutResourceRequirement.Match {
224 Mutable(final HostInstance pHost, final ApplicationInstance pApp) {
225 super(pHost, pApp);
226 }
227
228 @Override
229 public boolean isMutable() {
230 return true;
231 }
232 }
233
234 private static final class Immutable extends AllocationWithoutResourceRequirement.Match {
235 Immutable(final HostInstance pHost, final ApplicationInstance pApp) {
236 super(pHost, pApp);
237 }
238
239 @Override
240 public boolean isMutable() {
241 return false;
242 }
243 }
244 }
245
246 /**
247 * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.allocationWithoutResourceRequirement pattern,
248 * providing pattern-specific query methods.
249 *
250 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
251 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
252 *
253 * <p>Matches of the pattern will be represented as {@link Match}.
254 *
255 * <p>Original source:
256 * <code><pre>
257 * {@literal @}Constraint(severity = "error", key = {Host, App},
258 * message = "Application instance must be allocated to a supported host type.")
259 * pattern allocationWithoutResourceRequirement(Host : HostInstance, App : ApplicationInstance) {
260 * ApplicationInstance.allocatedTo(App, Host);
261 * neg find resourceRequirement(Host, App, _);
262 * }
263 * </pre></code>
264 *
265 * @see Match
266 * @see AllocationWithoutResourceRequirement
267 *
268 */
269 public static class Matcher extends BaseMatcher<AllocationWithoutResourceRequirement.Match> {
270 /**
271 * Initializes the pattern matcher within an existing VIATRA Query engine.
272 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
273 *
274 * @param engine the existing VIATRA Query engine in which this matcher will be created.
275 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
276 *
277 */
278 public static AllocationWithoutResourceRequirement.Matcher on(final ViatraQueryEngine engine) {
279 // check if matcher already exists
280 Matcher matcher = engine.getExistingMatcher(querySpecification());
281 if (matcher == null) {
282 matcher = (Matcher)engine.getMatcher(querySpecification());
283 }
284 return matcher;
285 }
286
287 /**
288 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
289 * @return an initialized matcher
290 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
291 *
292 */
293 public static AllocationWithoutResourceRequirement.Matcher create() {
294 return new Matcher();
295 }
296
297 private static final int POSITION_HOST = 0;
298
299 private static final int POSITION_APP = 1;
300
301 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(AllocationWithoutResourceRequirement.Matcher.class);
302
303 /**
304 * Initializes the pattern matcher within an existing VIATRA Query engine.
305 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
306 *
307 * @param engine the existing VIATRA Query engine in which this matcher will be created.
308 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
309 *
310 */
311 private Matcher() {
312 super(querySpecification());
313 }
314
315 /**
316 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
317 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
318 * @param pApp the fixed value of pattern parameter App, or null if not bound.
319 * @return matches represented as a Match object.
320 *
321 */
322 public Collection<AllocationWithoutResourceRequirement.Match> getAllMatches(final HostInstance pHost, final ApplicationInstance pApp) {
323 return rawStreamAllMatches(new Object[]{pHost, pApp}).collect(Collectors.toSet());
324 }
325
326 /**
327 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
328 * </p>
329 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
330 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
331 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
332 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
333 * @param pApp the fixed value of pattern parameter App, or null if not bound.
334 * @return a stream of matches represented as a Match object.
335 *
336 */
337 public Stream<AllocationWithoutResourceRequirement.Match> streamAllMatches(final HostInstance pHost, final ApplicationInstance pApp) {
338 return rawStreamAllMatches(new Object[]{pHost, pApp});
339 }
340
341 /**
342 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
343 * Neither determinism nor randomness of selection is guaranteed.
344 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
345 * @param pApp the fixed value of pattern parameter App, or null if not bound.
346 * @return a match represented as a Match object, or null if no match is found.
347 *
348 */
349 public Optional<AllocationWithoutResourceRequirement.Match> getOneArbitraryMatch(final HostInstance pHost, final ApplicationInstance pApp) {
350 return rawGetOneArbitraryMatch(new Object[]{pHost, pApp});
351 }
352
353 /**
354 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
355 * under any possible substitution of the unspecified parameters (if any).
356 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
357 * @param pApp the fixed value of pattern parameter App, or null if not bound.
358 * @return true if the input is a valid (partial) match of the pattern.
359 *
360 */
361 public boolean hasMatch(final HostInstance pHost, final ApplicationInstance pApp) {
362 return rawHasMatch(new Object[]{pHost, pApp});
363 }
364
365 /**
366 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
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 the number of pattern matches found.
370 *
371 */
372 public int countMatches(final HostInstance pHost, final ApplicationInstance pApp) {
373 return rawCountMatches(new Object[]{pHost, pApp});
374 }
375
376 /**
377 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
378 * Neither determinism nor randomness of selection is guaranteed.
379 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
380 * @param pApp the fixed value of pattern parameter App, or null if not bound.
381 * @param processor the action that will process the selected match.
382 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
383 *
384 */
385 public boolean forOneArbitraryMatch(final HostInstance pHost, final ApplicationInstance pApp, final Consumer<? super AllocationWithoutResourceRequirement.Match> processor) {
386 return rawForOneArbitraryMatch(new Object[]{pHost, pApp}, processor);
387 }
388
389 /**
390 * Returns a new (partial) match.
391 * This can be used e.g. to call the matcher with a partial match.
392 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
393 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
394 * @param pApp the fixed value of pattern parameter App, or null if not bound.
395 * @return the (partial) match object.
396 *
397 */
398 public AllocationWithoutResourceRequirement.Match newMatch(final HostInstance pHost, final ApplicationInstance pApp) {
399 return AllocationWithoutResourceRequirement.Match.newMatch(pHost, pApp);
400 }
401
402 /**
403 * Retrieve the set of values that occur in matches for Host.
404 * @return the Set of all values or empty set if there are no matches
405 *
406 */
407 protected Stream<HostInstance> rawStreamAllValuesOfHost(final Object[] parameters) {
408 return rawStreamAllValues(POSITION_HOST, parameters).map(HostInstance.class::cast);
409 }
410
411 /**
412 * Retrieve the set of values that occur in matches for Host.
413 * @return the Set of all values or empty set if there are no matches
414 *
415 */
416 public Set<HostInstance> getAllValuesOfHost() {
417 return rawStreamAllValuesOfHost(emptyArray()).collect(Collectors.toSet());
418 }
419
420 /**
421 * Retrieve the set of values that occur in matches for Host.
422 * @return the Set of all values or empty set if there are no matches
423 *
424 */
425 public Stream<HostInstance> streamAllValuesOfHost() {
426 return rawStreamAllValuesOfHost(emptyArray());
427 }
428
429 /**
430 * Retrieve the set of values that occur in matches for Host.
431 * </p>
432 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
433 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
434 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
435 *
436 * @return the Stream of all values or empty set if there are no matches
437 *
438 */
439 public Stream<HostInstance> streamAllValuesOfHost(final AllocationWithoutResourceRequirement.Match partialMatch) {
440 return rawStreamAllValuesOfHost(partialMatch.toArray());
441 }
442
443 /**
444 * Retrieve the set of values that occur in matches for Host.
445 * </p>
446 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
447 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
448 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
449 *
450 * @return the Stream of all values or empty set if there are no matches
451 *
452 */
453 public Stream<HostInstance> streamAllValuesOfHost(final ApplicationInstance pApp) {
454 return rawStreamAllValuesOfHost(new Object[]{null, pApp});
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 Set<HostInstance> getAllValuesOfHost(final AllocationWithoutResourceRequirement.Match partialMatch) {
463 return rawStreamAllValuesOfHost(partialMatch.toArray()).collect(Collectors.toSet());
464 }
465
466 /**
467 * Retrieve the set of values that occur in matches for Host.
468 * @return the Set of all values or empty set if there are no matches
469 *
470 */
471 public Set<HostInstance> getAllValuesOfHost(final ApplicationInstance pApp) {
472 return rawStreamAllValuesOfHost(new Object[]{null, pApp}).collect(Collectors.toSet());
473 }
474
475 /**
476 * Retrieve the set of values that occur in matches for App.
477 * @return the Set of all values or empty set if there are no matches
478 *
479 */
480 protected Stream<ApplicationInstance> rawStreamAllValuesOfApp(final Object[] parameters) {
481 return rawStreamAllValues(POSITION_APP, parameters).map(ApplicationInstance.class::cast);
482 }
483
484 /**
485 * Retrieve the set of values that occur in matches for App.
486 * @return the Set of all values or empty set if there are no matches
487 *
488 */
489 public Set<ApplicationInstance> getAllValuesOfApp() {
490 return rawStreamAllValuesOfApp(emptyArray()).collect(Collectors.toSet());
491 }
492
493 /**
494 * Retrieve the set of values that occur in matches for App.
495 * @return the Set of all values or empty set if there are no matches
496 *
497 */
498 public Stream<ApplicationInstance> streamAllValuesOfApp() {
499 return rawStreamAllValuesOfApp(emptyArray());
500 }
501
502 /**
503 * Retrieve the set of values that occur in matches for App.
504 * </p>
505 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
506 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
507 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
508 *
509 * @return the Stream of all values or empty set if there are no matches
510 *
511 */
512 public Stream<ApplicationInstance> streamAllValuesOfApp(final AllocationWithoutResourceRequirement.Match partialMatch) {
513 return rawStreamAllValuesOfApp(partialMatch.toArray());
514 }
515
516 /**
517 * Retrieve the set of values that occur in matches for App.
518 * </p>
519 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
520 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
521 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
522 *
523 * @return the Stream of all values or empty set if there are no matches
524 *
525 */
526 public Stream<ApplicationInstance> streamAllValuesOfApp(final HostInstance pHost) {
527 return rawStreamAllValuesOfApp(new Object[]{pHost, null});
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 Set<ApplicationInstance> getAllValuesOfApp(final AllocationWithoutResourceRequirement.Match partialMatch) {
536 return rawStreamAllValuesOfApp(partialMatch.toArray()).collect(Collectors.toSet());
537 }
538
539 /**
540 * Retrieve the set of values that occur in matches for App.
541 * @return the Set of all values or empty set if there are no matches
542 *
543 */
544 public Set<ApplicationInstance> getAllValuesOfApp(final HostInstance pHost) {
545 return rawStreamAllValuesOfApp(new Object[]{pHost, null}).collect(Collectors.toSet());
546 }
547
548 @Override
549 protected AllocationWithoutResourceRequirement.Match tupleToMatch(final Tuple t) {
550 try {
551 return AllocationWithoutResourceRequirement.Match.newMatch((HostInstance) t.get(POSITION_HOST), (ApplicationInstance) t.get(POSITION_APP));
552 } catch(ClassCastException e) {
553 LOGGER.error("Element(s) in tuple not properly typed!",e);
554 return null;
555 }
556 }
557
558 @Override
559 protected AllocationWithoutResourceRequirement.Match arrayToMatch(final Object[] match) {
560 try {
561 return AllocationWithoutResourceRequirement.Match.newMatch((HostInstance) match[POSITION_HOST], (ApplicationInstance) match[POSITION_APP]);
562 } catch(ClassCastException e) {
563 LOGGER.error("Element(s) in array not properly typed!",e);
564 return null;
565 }
566 }
567
568 @Override
569 protected AllocationWithoutResourceRequirement.Match arrayToMatchMutable(final Object[] match) {
570 try {
571 return AllocationWithoutResourceRequirement.Match.newMutableMatch((HostInstance) match[POSITION_HOST], (ApplicationInstance) match[POSITION_APP]);
572 } catch(ClassCastException e) {
573 LOGGER.error("Element(s) in array not properly typed!",e);
574 return null;
575 }
576 }
577
578 /**
579 * @return the singleton instance of the query specification of this pattern
580 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
581 *
582 */
583 public static IQuerySpecification<AllocationWithoutResourceRequirement.Matcher> querySpecification() {
584 return AllocationWithoutResourceRequirement.instance();
585 }
586 }
587
588 private AllocationWithoutResourceRequirement() {
589 super(GeneratedPQuery.INSTANCE);
590 }
591
592 /**
593 * @return the singleton instance of the query specification
594 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
595 *
596 */
597 public static AllocationWithoutResourceRequirement instance() {
598 try{
599 return LazyHolder.INSTANCE;
600 } catch (ExceptionInInitializerError err) {
601 throw processInitializerError(err);
602 }
603 }
604
605 @Override
606 protected AllocationWithoutResourceRequirement.Matcher instantiate(final ViatraQueryEngine engine) {
607 return AllocationWithoutResourceRequirement.Matcher.on(engine);
608 }
609
610 @Override
611 public AllocationWithoutResourceRequirement.Matcher instantiate() {
612 return AllocationWithoutResourceRequirement.Matcher.create();
613 }
614
615 @Override
616 public AllocationWithoutResourceRequirement.Match newEmptyMatch() {
617 return AllocationWithoutResourceRequirement.Match.newEmptyMatch();
618 }
619
620 @Override
621 public AllocationWithoutResourceRequirement.Match newMatch(final Object... parameters) {
622 return AllocationWithoutResourceRequirement.Match.newMatch((hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance) parameters[0], (hu.bme.mit.inf.dslreasoner.domains.cps.ApplicationInstance) parameters[1]);
623 }
624
625 /**
626 * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.AllocationWithoutResourceRequirement (visibility: PUBLIC, simpleName: AllocationWithoutResourceRequirement, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.AllocationWithoutResourceRequirement, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)} to be created
627 * <b>not</b> at the class load time of the outer class,
628 * but rather at the first call to {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.AllocationWithoutResourceRequirement (visibility: PUBLIC, simpleName: AllocationWithoutResourceRequirement, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.AllocationWithoutResourceRequirement, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}.
629 *
630 * <p> This workaround is required e.g. to support recursion.
631 *
632 */
633 private static class LazyHolder {
634 private static final AllocationWithoutResourceRequirement INSTANCE = new AllocationWithoutResourceRequirement();
635
636 /**
637 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
638 * This initialization order is required to support indirect recursion.
639 *
640 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
641 *
642 */
643 private static final Object STATIC_INITIALIZER = ensureInitialized();
644
645 public static Object ensureInitialized() {
646 INSTANCE.ensureInitializedInternal();
647 return null;
648 }
649 }
650
651 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
652 private static final AllocationWithoutResourceRequirement.GeneratedPQuery INSTANCE = new GeneratedPQuery();
653
654 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);
655
656 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);
657
658 private final List<PParameter> parameters = Arrays.asList(parameter_Host, parameter_App);
659
660 private GeneratedPQuery() {
661 super(PVisibility.PUBLIC);
662 }
663
664 @Override
665 public String getFullyQualifiedName() {
666 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.allocationWithoutResourceRequirement";
667 }
668
669 @Override
670 public List<String> getParameterNames() {
671 return Arrays.asList("Host","App");
672 }
673
674 @Override
675 public List<PParameter> getParameters() {
676 return parameters;
677 }
678
679 @Override
680 public Set<PBody> doGetContainedBodies() {
681 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
682 Set<PBody> bodies = new LinkedHashSet<>();
683 {
684 PBody body = new PBody(this);
685 PVariable var_Host = body.getOrCreateVariableByName("Host");
686 PVariable var_App = body.getOrCreateVariableByName("App");
687 PVariable var___0_ = body.getOrCreateVariableByName("_<0>");
688 new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance")));
689 new TypeConstraint(body, Tuples.flatTupleOf(var_App), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance")));
690 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
691 new ExportedParameter(body, var_Host, parameter_Host),
692 new ExportedParameter(body, var_App, parameter_App)
693 ));
694 // ApplicationInstance.allocatedTo(App, Host)
695 new TypeConstraint(body, Tuples.flatTupleOf(var_App), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance")));
696 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
697 new TypeConstraint(body, Tuples.flatTupleOf(var_App, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ApplicationInstance", "allocatedTo")));
698 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance")));
699 new Equality(body, var__virtual_0_, var_Host);
700 // neg find resourceRequirement(Host, App, _)
701 new NegativePatternCall(body, Tuples.flatTupleOf(var_Host, var_App, var___0_), ResourceRequirement.instance().getInternalQueryRepresentation());
702 bodies.add(body);
703 }
704 {
705 PAnnotation annotation = new PAnnotation("Constraint");
706 annotation.addAttribute("severity", "error");
707 annotation.addAttribute("key", Arrays.asList(new Object[] {
708 new ParameterReference("Host"),
709 new ParameterReference("App")
710 }));
711 annotation.addAttribute("message", "Application instance must be allocated to a supported host type.");
712 addAnnotation(annotation);
713 }
714 return bodies;
715 }
716 }
717}
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/AvailableHdd.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/AvailableHdd.java
new file mode 100644
index 00000000..22821c4a
--- /dev/null
+++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/AvailableHdd.java
@@ -0,0 +1,743 @@
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.TotalHdd;
8import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.HddRequirement;
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.annotations.PAnnotation;
37import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.AggregatorConstraint;
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.TypeFilterConstraint;
42import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall;
43import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
44import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
45import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
46import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
47import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
48import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
49import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
50
51/**
52 * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
53 *
54 * <p>Original source:
55 * <code><pre>
56 * {@literal @}QueryBasedFeature(feature = "availableHdd")
57 * pattern availableHdd(Host : HostInstance, Hdd : java Integer) {
58 * find totalHdd(Host, TotalHdd);
59 * RequiredHdd == sum find hddRequirement(Host, _, #_);
60 * Hdd == eval(TotalHdd - RequiredHdd);
61 * }
62 * </pre></code>
63 *
64 * @see Matcher
65 * @see Match
66 *
67 */
68@SuppressWarnings("all")
69public final class AvailableHdd extends BaseGeneratedEMFQuerySpecification<AvailableHdd.Matcher> {
70 /**
71 * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.availableHdd 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 HostInstance fHost;
84
85 private Integer fHdd;
86
87 private static List<String> parameterNames = makeImmutableList("Host", "Hdd");
88
89 private Match(final HostInstance pHost, final Integer pHdd) {
90 this.fHost = pHost;
91 this.fHdd = pHdd;
92 }
93
94 @Override
95 public Object get(final String parameterName) {
96 if ("Host".equals(parameterName)) return this.fHost;
97 if ("Hdd".equals(parameterName)) return this.fHdd;
98 return null;
99 }
100
101 public HostInstance getHost() {
102 return this.fHost;
103 }
104
105 public Integer getHdd() {
106 return this.fHdd;
107 }
108
109 @Override
110 public boolean set(final String parameterName, final Object newValue) {
111 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
112 if ("Host".equals(parameterName) ) {
113 this.fHost = (HostInstance) newValue;
114 return true;
115 }
116 if ("Hdd".equals(parameterName) ) {
117 this.fHdd = (Integer) newValue;
118 return true;
119 }
120 return false;
121 }
122
123 public void setHost(final HostInstance pHost) {
124 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
125 this.fHost = pHost;
126 }
127
128 public void setHdd(final Integer pHdd) {
129 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
130 this.fHdd = pHdd;
131 }
132
133 @Override
134 public String patternName() {
135 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.availableHdd";
136 }
137
138 @Override
139 public List<String> parameterNames() {
140 return AvailableHdd.Match.parameterNames;
141 }
142
143 @Override
144 public Object[] toArray() {
145 return new Object[]{fHost, fHdd};
146 }
147
148 @Override
149 public AvailableHdd.Match toImmutable() {
150 return isMutable() ? newMatch(fHost, fHdd) : this;
151 }
152
153 @Override
154 public String prettyPrint() {
155 StringBuilder result = new StringBuilder();
156 result.append("\"Host\"=" + prettyPrintValue(fHost) + ", ");
157 result.append("\"Hdd\"=" + prettyPrintValue(fHdd));
158 return result.toString();
159 }
160
161 @Override
162 public int hashCode() {
163 return Objects.hash(fHost, fHdd);
164 }
165
166 @Override
167 public boolean equals(final Object obj) {
168 if (this == obj)
169 return true;
170 if (obj == null) {
171 return false;
172 }
173 if ((obj instanceof AvailableHdd.Match)) {
174 AvailableHdd.Match other = (AvailableHdd.Match) obj;
175 return Objects.equals(fHost, other.fHost) && Objects.equals(fHdd, other.fHdd);
176 } else {
177 // this should be infrequent
178 if (!(obj instanceof IPatternMatch)) {
179 return false;
180 }
181 IPatternMatch otherSig = (IPatternMatch) obj;
182 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
183 }
184 }
185
186 @Override
187 public AvailableHdd specification() {
188 return AvailableHdd.instance();
189 }
190
191 /**
192 * Returns an empty, mutable match.
193 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
194 *
195 * @return the empty match.
196 *
197 */
198 public static AvailableHdd.Match newEmptyMatch() {
199 return new Mutable(null, null);
200 }
201
202 /**
203 * Returns a mutable (partial) match.
204 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
205 *
206 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
207 * @param pHdd the fixed value of pattern parameter Hdd, or null if not bound.
208 * @return the new, mutable (partial) match object.
209 *
210 */
211 public static AvailableHdd.Match newMutableMatch(final HostInstance pHost, final Integer pHdd) {
212 return new Mutable(pHost, pHdd);
213 }
214
215 /**
216 * Returns a new (partial) match.
217 * This can be used e.g. to call the matcher with a partial match.
218 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
219 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
220 * @param pHdd the fixed value of pattern parameter Hdd, or null if not bound.
221 * @return the (partial) match object.
222 *
223 */
224 public static AvailableHdd.Match newMatch(final HostInstance pHost, final Integer pHdd) {
225 return new Immutable(pHost, pHdd);
226 }
227
228 private static final class Mutable extends AvailableHdd.Match {
229 Mutable(final HostInstance pHost, final Integer pHdd) {
230 super(pHost, pHdd);
231 }
232
233 @Override
234 public boolean isMutable() {
235 return true;
236 }
237 }
238
239 private static final class Immutable extends AvailableHdd.Match {
240 Immutable(final HostInstance pHost, final Integer pHdd) {
241 super(pHost, pHdd);
242 }
243
244 @Override
245 public boolean isMutable() {
246 return false;
247 }
248 }
249 }
250
251 /**
252 * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.availableHdd pattern,
253 * providing pattern-specific query methods.
254 *
255 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
256 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
257 *
258 * <p>Matches of the pattern will be represented as {@link Match}.
259 *
260 * <p>Original source:
261 * <code><pre>
262 * {@literal @}QueryBasedFeature(feature = "availableHdd")
263 * pattern availableHdd(Host : HostInstance, Hdd : java Integer) {
264 * find totalHdd(Host, TotalHdd);
265 * RequiredHdd == sum find hddRequirement(Host, _, #_);
266 * Hdd == eval(TotalHdd - RequiredHdd);
267 * }
268 * </pre></code>
269 *
270 * @see Match
271 * @see AvailableHdd
272 *
273 */
274 public static class Matcher extends BaseMatcher<AvailableHdd.Match> {
275 /**
276 * Initializes the pattern matcher within an existing VIATRA Query engine.
277 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
278 *
279 * @param engine the existing VIATRA Query engine in which this matcher will be created.
280 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
281 *
282 */
283 public static AvailableHdd.Matcher on(final ViatraQueryEngine engine) {
284 // check if matcher already exists
285 Matcher matcher = engine.getExistingMatcher(querySpecification());
286 if (matcher == null) {
287 matcher = (Matcher)engine.getMatcher(querySpecification());
288 }
289 return matcher;
290 }
291
292 /**
293 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
294 * @return an initialized matcher
295 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
296 *
297 */
298 public static AvailableHdd.Matcher create() {
299 return new Matcher();
300 }
301
302 private static final int POSITION_HOST = 0;
303
304 private static final int POSITION_HDD = 1;
305
306 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(AvailableHdd.Matcher.class);
307
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 private Matcher() {
317 super(querySpecification());
318 }
319
320 /**
321 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
322 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
323 * @param pHdd the fixed value of pattern parameter Hdd, or null if not bound.
324 * @return matches represented as a Match object.
325 *
326 */
327 public Collection<AvailableHdd.Match> getAllMatches(final HostInstance pHost, final Integer pHdd) {
328 return rawStreamAllMatches(new Object[]{pHost, pHdd}).collect(Collectors.toSet());
329 }
330
331 /**
332 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
333 * </p>
334 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
335 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
336 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
337 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
338 * @param pHdd the fixed value of pattern parameter Hdd, or null if not bound.
339 * @return a stream of matches represented as a Match object.
340 *
341 */
342 public Stream<AvailableHdd.Match> streamAllMatches(final HostInstance pHost, final Integer pHdd) {
343 return rawStreamAllMatches(new Object[]{pHost, pHdd});
344 }
345
346 /**
347 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
348 * Neither determinism nor randomness of selection is guaranteed.
349 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
350 * @param pHdd the fixed value of pattern parameter Hdd, or null if not bound.
351 * @return a match represented as a Match object, or null if no match is found.
352 *
353 */
354 public Optional<AvailableHdd.Match> getOneArbitraryMatch(final HostInstance pHost, final Integer pHdd) {
355 return rawGetOneArbitraryMatch(new Object[]{pHost, pHdd});
356 }
357
358 /**
359 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
360 * under any possible substitution of the unspecified parameters (if any).
361 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
362 * @param pHdd the fixed value of pattern parameter Hdd, or null if not bound.
363 * @return true if the input is a valid (partial) match of the pattern.
364 *
365 */
366 public boolean hasMatch(final HostInstance pHost, final Integer pHdd) {
367 return rawHasMatch(new Object[]{pHost, pHdd});
368 }
369
370 /**
371 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
372 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
373 * @param pHdd the fixed value of pattern parameter Hdd, or null if not bound.
374 * @return the number of pattern matches found.
375 *
376 */
377 public int countMatches(final HostInstance pHost, final Integer pHdd) {
378 return rawCountMatches(new Object[]{pHost, pHdd});
379 }
380
381 /**
382 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
383 * Neither determinism nor randomness of selection is guaranteed.
384 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
385 * @param pHdd the fixed value of pattern parameter Hdd, or null if not bound.
386 * @param processor the action that will process the selected match.
387 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
388 *
389 */
390 public boolean forOneArbitraryMatch(final HostInstance pHost, final Integer pHdd, final Consumer<? super AvailableHdd.Match> processor) {
391 return rawForOneArbitraryMatch(new Object[]{pHost, pHdd}, processor);
392 }
393
394 /**
395 * Returns a new (partial) match.
396 * This can be used e.g. to call the matcher with a partial match.
397 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
398 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
399 * @param pHdd the fixed value of pattern parameter Hdd, or null if not bound.
400 * @return the (partial) match object.
401 *
402 */
403 public AvailableHdd.Match newMatch(final HostInstance pHost, final Integer pHdd) {
404 return AvailableHdd.Match.newMatch(pHost, pHdd);
405 }
406
407 /**
408 * Retrieve the set of values that occur in matches for Host.
409 * @return the Set of all values or empty set if there are no matches
410 *
411 */
412 protected Stream<HostInstance> rawStreamAllValuesOfHost(final Object[] parameters) {
413 return rawStreamAllValues(POSITION_HOST, parameters).map(HostInstance.class::cast);
414 }
415
416 /**
417 * Retrieve the set of values that occur in matches for Host.
418 * @return the Set of all values or empty set if there are no matches
419 *
420 */
421 public Set<HostInstance> getAllValuesOfHost() {
422 return rawStreamAllValuesOfHost(emptyArray()).collect(Collectors.toSet());
423 }
424
425 /**
426 * Retrieve the set of values that occur in matches for Host.
427 * @return the Set of all values or empty set if there are no matches
428 *
429 */
430 public Stream<HostInstance> streamAllValuesOfHost() {
431 return rawStreamAllValuesOfHost(emptyArray());
432 }
433
434 /**
435 * Retrieve the set of values that occur in matches for Host.
436 * </p>
437 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
438 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
439 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
440 *
441 * @return the Stream of all values or empty set if there are no matches
442 *
443 */
444 public Stream<HostInstance> streamAllValuesOfHost(final AvailableHdd.Match partialMatch) {
445 return rawStreamAllValuesOfHost(partialMatch.toArray());
446 }
447
448 /**
449 * Retrieve the set of values that occur in matches for Host.
450 * </p>
451 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
452 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
453 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
454 *
455 * @return the Stream of all values or empty set if there are no matches
456 *
457 */
458 public Stream<HostInstance> streamAllValuesOfHost(final Integer pHdd) {
459 return rawStreamAllValuesOfHost(new Object[]{null, pHdd});
460 }
461
462 /**
463 * Retrieve the set of values that occur in matches for Host.
464 * @return the Set of all values or empty set if there are no matches
465 *
466 */
467 public Set<HostInstance> getAllValuesOfHost(final AvailableHdd.Match partialMatch) {
468 return rawStreamAllValuesOfHost(partialMatch.toArray()).collect(Collectors.toSet());
469 }
470
471 /**
472 * Retrieve the set of values that occur in matches for Host.
473 * @return the Set of all values or empty set if there are no matches
474 *
475 */
476 public Set<HostInstance> getAllValuesOfHost(final Integer pHdd) {
477 return rawStreamAllValuesOfHost(new Object[]{null, pHdd}).collect(Collectors.toSet());
478 }
479
480 /**
481 * Retrieve the set of values that occur in matches for Hdd.
482 * @return the Set of all values or empty set if there are no matches
483 *
484 */
485 protected Stream<Integer> rawStreamAllValuesOfHdd(final Object[] parameters) {
486 return rawStreamAllValues(POSITION_HDD, parameters).map(Integer.class::cast);
487 }
488
489 /**
490 * Retrieve the set of values that occur in matches for Hdd.
491 * @return the Set of all values or empty set if there are no matches
492 *
493 */
494 public Set<Integer> getAllValuesOfHdd() {
495 return rawStreamAllValuesOfHdd(emptyArray()).collect(Collectors.toSet());
496 }
497
498 /**
499 * Retrieve the set of values that occur in matches for Hdd.
500 * @return the Set of all values or empty set if there are no matches
501 *
502 */
503 public Stream<Integer> streamAllValuesOfHdd() {
504 return rawStreamAllValuesOfHdd(emptyArray());
505 }
506
507 /**
508 * Retrieve the set of values that occur in matches for Hdd.
509 * </p>
510 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
511 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
512 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
513 *
514 * @return the Stream of all values or empty set if there are no matches
515 *
516 */
517 public Stream<Integer> streamAllValuesOfHdd(final AvailableHdd.Match partialMatch) {
518 return rawStreamAllValuesOfHdd(partialMatch.toArray());
519 }
520
521 /**
522 * Retrieve the set of values that occur in matches for Hdd.
523 * </p>
524 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
525 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
526 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
527 *
528 * @return the Stream of all values or empty set if there are no matches
529 *
530 */
531 public Stream<Integer> streamAllValuesOfHdd(final HostInstance pHost) {
532 return rawStreamAllValuesOfHdd(new Object[]{pHost, null});
533 }
534
535 /**
536 * Retrieve the set of values that occur in matches for Hdd.
537 * @return the Set of all values or empty set if there are no matches
538 *
539 */
540 public Set<Integer> getAllValuesOfHdd(final AvailableHdd.Match partialMatch) {
541 return rawStreamAllValuesOfHdd(partialMatch.toArray()).collect(Collectors.toSet());
542 }
543
544 /**
545 * Retrieve the set of values that occur in matches for Hdd.
546 * @return the Set of all values or empty set if there are no matches
547 *
548 */
549 public Set<Integer> getAllValuesOfHdd(final HostInstance pHost) {
550 return rawStreamAllValuesOfHdd(new Object[]{pHost, null}).collect(Collectors.toSet());
551 }
552
553 @Override
554 protected AvailableHdd.Match tupleToMatch(final Tuple t) {
555 try {
556 return AvailableHdd.Match.newMatch((HostInstance) t.get(POSITION_HOST), (Integer) t.get(POSITION_HDD));
557 } catch(ClassCastException e) {
558 LOGGER.error("Element(s) in tuple not properly typed!",e);
559 return null;
560 }
561 }
562
563 @Override
564 protected AvailableHdd.Match arrayToMatch(final Object[] match) {
565 try {
566 return AvailableHdd.Match.newMatch((HostInstance) match[POSITION_HOST], (Integer) match[POSITION_HDD]);
567 } catch(ClassCastException e) {
568 LOGGER.error("Element(s) in array not properly typed!",e);
569 return null;
570 }
571 }
572
573 @Override
574 protected AvailableHdd.Match arrayToMatchMutable(final Object[] match) {
575 try {
576 return AvailableHdd.Match.newMutableMatch((HostInstance) match[POSITION_HOST], (Integer) match[POSITION_HDD]);
577 } catch(ClassCastException e) {
578 LOGGER.error("Element(s) in array not properly typed!",e);
579 return null;
580 }
581 }
582
583 /**
584 * @return the singleton instance of the query specification of this pattern
585 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
586 *
587 */
588 public static IQuerySpecification<AvailableHdd.Matcher> querySpecification() {
589 return AvailableHdd.instance();
590 }
591 }
592
593 private AvailableHdd() {
594 super(GeneratedPQuery.INSTANCE);
595 }
596
597 /**
598 * @return the singleton instance of the query specification
599 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
600 *
601 */
602 public static AvailableHdd instance() {
603 try{
604 return LazyHolder.INSTANCE;
605 } catch (ExceptionInInitializerError err) {
606 throw processInitializerError(err);
607 }
608 }
609
610 @Override
611 protected AvailableHdd.Matcher instantiate(final ViatraQueryEngine engine) {
612 return AvailableHdd.Matcher.on(engine);
613 }
614
615 @Override
616 public AvailableHdd.Matcher instantiate() {
617 return AvailableHdd.Matcher.create();
618 }
619
620 @Override
621 public AvailableHdd.Match newEmptyMatch() {
622 return AvailableHdd.Match.newEmptyMatch();
623 }
624
625 @Override
626 public AvailableHdd.Match newMatch(final Object... parameters) {
627 return AvailableHdd.Match.newMatch((hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance) parameters[0], (java.lang.Integer) parameters[1]);
628 }
629
630 /**
631 * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.AvailableHdd (visibility: PUBLIC, simpleName: AvailableHdd, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.AvailableHdd, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)} to be created
632 * <b>not</b> at the class load time of the outer class,
633 * but rather at the first call to {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.AvailableHdd (visibility: PUBLIC, simpleName: AvailableHdd, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.AvailableHdd, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}.
634 *
635 * <p> This workaround is required e.g. to support recursion.
636 *
637 */
638 private static class LazyHolder {
639 private static final AvailableHdd INSTANCE = new AvailableHdd();
640
641 /**
642 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
643 * This initialization order is required to support indirect recursion.
644 *
645 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
646 *
647 */
648 private static final Object STATIC_INITIALIZER = ensureInitialized();
649
650 public static Object ensureInitialized() {
651 INSTANCE.ensureInitializedInternal();
652 return null;
653 }
654 }
655
656 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
657 private static final AvailableHdd.GeneratedPQuery INSTANCE = new GeneratedPQuery();
658
659 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);
660
661 private final PParameter parameter_Hdd = new PParameter("Hdd", "java.lang.Integer", new JavaTransitiveInstancesKey(java.lang.Integer.class), PParameterDirection.INOUT);
662
663 private final List<PParameter> parameters = Arrays.asList(parameter_Host, parameter_Hdd);
664
665 private GeneratedPQuery() {
666 super(PVisibility.PUBLIC);
667 }
668
669 @Override
670 public String getFullyQualifiedName() {
671 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.availableHdd";
672 }
673
674 @Override
675 public List<String> getParameterNames() {
676 return Arrays.asList("Host","Hdd");
677 }
678
679 @Override
680 public List<PParameter> getParameters() {
681 return parameters;
682 }
683
684 @Override
685 public Set<PBody> doGetContainedBodies() {
686 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
687 Set<PBody> bodies = new LinkedHashSet<>();
688 {
689 PBody body = new PBody(this);
690 PVariable var_Host = body.getOrCreateVariableByName("Host");
691 PVariable var_Hdd = body.getOrCreateVariableByName("Hdd");
692 PVariable var_TotalHdd = body.getOrCreateVariableByName("TotalHdd");
693 PVariable var_RequiredHdd = body.getOrCreateVariableByName("RequiredHdd");
694 PVariable var___0_ = body.getOrCreateVariableByName("_<0>");
695 PVariable var___1_ = body.getOrCreateVariableByName("_<1>");
696 new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance")));
697 new TypeFilterConstraint(body, Tuples.flatTupleOf(var_Hdd), new JavaTransitiveInstancesKey(java.lang.Integer.class));
698 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
699 new ExportedParameter(body, var_Host, parameter_Host),
700 new ExportedParameter(body, var_Hdd, parameter_Hdd)
701 ));
702 // find totalHdd(Host, TotalHdd)
703 new PositivePatternCall(body, Tuples.flatTupleOf(var_Host, var_TotalHdd), TotalHdd.instance().getInternalQueryRepresentation());
704 // RequiredHdd == sum find hddRequirement(Host, _, #_)
705 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
706 new AggregatorConstraint(new sum().getAggregatorLogic(Integer.class), body, Tuples.flatTupleOf(var_Host, var___0_, var___1_), HddRequirement.instance().getInternalQueryRepresentation(), var__virtual_0_, 2);
707 new Equality(body, var_RequiredHdd, var__virtual_0_);
708 // Hdd == eval(TotalHdd - RequiredHdd)
709 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
710 new ExpressionEvaluation(body, new IExpressionEvaluator() {
711
712 @Override
713 public String getShortDescription() {
714 return "Expression evaluation from pattern availableHdd";
715 }
716
717 @Override
718 public Iterable<String> getInputParameterNames() {
719 return Arrays.asList("RequiredHdd", "TotalHdd");}
720
721 @Override
722 public Object evaluateExpression(IValueProvider provider) throws Exception {
723 Integer RequiredHdd = (Integer) provider.getValue("RequiredHdd");
724 Integer TotalHdd = (Integer) provider.getValue("TotalHdd");
725 return evaluateExpression_1_1(RequiredHdd, TotalHdd);
726 }
727 }, var__virtual_1_ );
728 new Equality(body, var_Hdd, var__virtual_1_);
729 bodies.add(body);
730 }
731 {
732 PAnnotation annotation = new PAnnotation("QueryBasedFeature");
733 annotation.addAttribute("feature", "availableHdd");
734 addAnnotation(annotation);
735 }
736 return bodies;
737 }
738 }
739
740 private static int evaluateExpression_1_1(final Integer RequiredHdd, final Integer TotalHdd) {
741 return ((TotalHdd).intValue() - (RequiredHdd).intValue());
742 }
743}
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/AvailableMemory.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/AvailableMemory.java
new file mode 100644
index 00000000..930a24ba
--- /dev/null
+++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/AvailableMemory.java
@@ -0,0 +1,743 @@
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.TotalMemory;
8import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.MemoryRequirement;
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.annotations.PAnnotation;
37import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.AggregatorConstraint;
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.TypeFilterConstraint;
42import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall;
43import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
44import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
45import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
46import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
47import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
48import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
49import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
50
51/**
52 * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
53 *
54 * <p>Original source:
55 * <code><pre>
56 * {@literal @}QueryBasedFeature(feature = "availableMemory")
57 * pattern availableMemory(Host : HostInstance, Memory : java Integer) {
58 * find totalMemory(Host, TotalMemory);
59 * RequiredMemory == sum find memoryRequirement(Host, _, #_);
60 * Memory == eval(TotalMemory - RequiredMemory);
61 * }
62 * </pre></code>
63 *
64 * @see Matcher
65 * @see Match
66 *
67 */
68@SuppressWarnings("all")
69public final class AvailableMemory extends BaseGeneratedEMFQuerySpecification<AvailableMemory.Matcher> {
70 /**
71 * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.availableMemory 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 HostInstance fHost;
84
85 private Integer fMemory;
86
87 private static List<String> parameterNames = makeImmutableList("Host", "Memory");
88
89 private Match(final HostInstance pHost, final Integer pMemory) {
90 this.fHost = pHost;
91 this.fMemory = pMemory;
92 }
93
94 @Override
95 public Object get(final String parameterName) {
96 if ("Host".equals(parameterName)) return this.fHost;
97 if ("Memory".equals(parameterName)) return this.fMemory;
98 return null;
99 }
100
101 public HostInstance getHost() {
102 return this.fHost;
103 }
104
105 public Integer getMemory() {
106 return this.fMemory;
107 }
108
109 @Override
110 public boolean set(final String parameterName, final Object newValue) {
111 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
112 if ("Host".equals(parameterName) ) {
113 this.fHost = (HostInstance) newValue;
114 return true;
115 }
116 if ("Memory".equals(parameterName) ) {
117 this.fMemory = (Integer) newValue;
118 return true;
119 }
120 return false;
121 }
122
123 public void setHost(final HostInstance pHost) {
124 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
125 this.fHost = pHost;
126 }
127
128 public void setMemory(final Integer pMemory) {
129 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
130 this.fMemory = pMemory;
131 }
132
133 @Override
134 public String patternName() {
135 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.availableMemory";
136 }
137
138 @Override
139 public List<String> parameterNames() {
140 return AvailableMemory.Match.parameterNames;
141 }
142
143 @Override
144 public Object[] toArray() {
145 return new Object[]{fHost, fMemory};
146 }
147
148 @Override
149 public AvailableMemory.Match toImmutable() {
150 return isMutable() ? newMatch(fHost, fMemory) : this;
151 }
152
153 @Override
154 public String prettyPrint() {
155 StringBuilder result = new StringBuilder();
156 result.append("\"Host\"=" + prettyPrintValue(fHost) + ", ");
157 result.append("\"Memory\"=" + prettyPrintValue(fMemory));
158 return result.toString();
159 }
160
161 @Override
162 public int hashCode() {
163 return Objects.hash(fHost, fMemory);
164 }
165
166 @Override
167 public boolean equals(final Object obj) {
168 if (this == obj)
169 return true;
170 if (obj == null) {
171 return false;
172 }
173 if ((obj instanceof AvailableMemory.Match)) {
174 AvailableMemory.Match other = (AvailableMemory.Match) obj;
175 return Objects.equals(fHost, other.fHost) && Objects.equals(fMemory, other.fMemory);
176 } else {
177 // this should be infrequent
178 if (!(obj instanceof IPatternMatch)) {
179 return false;
180 }
181 IPatternMatch otherSig = (IPatternMatch) obj;
182 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
183 }
184 }
185
186 @Override
187 public AvailableMemory specification() {
188 return AvailableMemory.instance();
189 }
190
191 /**
192 * Returns an empty, mutable match.
193 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
194 *
195 * @return the empty match.
196 *
197 */
198 public static AvailableMemory.Match newEmptyMatch() {
199 return new Mutable(null, null);
200 }
201
202 /**
203 * Returns a mutable (partial) match.
204 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
205 *
206 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
207 * @param pMemory the fixed value of pattern parameter Memory, or null if not bound.
208 * @return the new, mutable (partial) match object.
209 *
210 */
211 public static AvailableMemory.Match newMutableMatch(final HostInstance pHost, final Integer pMemory) {
212 return new Mutable(pHost, pMemory);
213 }
214
215 /**
216 * Returns a new (partial) match.
217 * This can be used e.g. to call the matcher with a partial match.
218 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
219 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
220 * @param pMemory the fixed value of pattern parameter Memory, or null if not bound.
221 * @return the (partial) match object.
222 *
223 */
224 public static AvailableMemory.Match newMatch(final HostInstance pHost, final Integer pMemory) {
225 return new Immutable(pHost, pMemory);
226 }
227
228 private static final class Mutable extends AvailableMemory.Match {
229 Mutable(final HostInstance pHost, final Integer pMemory) {
230 super(pHost, pMemory);
231 }
232
233 @Override
234 public boolean isMutable() {
235 return true;
236 }
237 }
238
239 private static final class Immutable extends AvailableMemory.Match {
240 Immutable(final HostInstance pHost, final Integer pMemory) {
241 super(pHost, pMemory);
242 }
243
244 @Override
245 public boolean isMutable() {
246 return false;
247 }
248 }
249 }
250
251 /**
252 * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.availableMemory pattern,
253 * providing pattern-specific query methods.
254 *
255 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
256 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
257 *
258 * <p>Matches of the pattern will be represented as {@link Match}.
259 *
260 * <p>Original source:
261 * <code><pre>
262 * {@literal @}QueryBasedFeature(feature = "availableMemory")
263 * pattern availableMemory(Host : HostInstance, Memory : java Integer) {
264 * find totalMemory(Host, TotalMemory);
265 * RequiredMemory == sum find memoryRequirement(Host, _, #_);
266 * Memory == eval(TotalMemory - RequiredMemory);
267 * }
268 * </pre></code>
269 *
270 * @see Match
271 * @see AvailableMemory
272 *
273 */
274 public static class Matcher extends BaseMatcher<AvailableMemory.Match> {
275 /**
276 * Initializes the pattern matcher within an existing VIATRA Query engine.
277 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
278 *
279 * @param engine the existing VIATRA Query engine in which this matcher will be created.
280 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
281 *
282 */
283 public static AvailableMemory.Matcher on(final ViatraQueryEngine engine) {
284 // check if matcher already exists
285 Matcher matcher = engine.getExistingMatcher(querySpecification());
286 if (matcher == null) {
287 matcher = (Matcher)engine.getMatcher(querySpecification());
288 }
289 return matcher;
290 }
291
292 /**
293 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
294 * @return an initialized matcher
295 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
296 *
297 */
298 public static AvailableMemory.Matcher create() {
299 return new Matcher();
300 }
301
302 private static final int POSITION_HOST = 0;
303
304 private static final int POSITION_MEMORY = 1;
305
306 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(AvailableMemory.Matcher.class);
307
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 private Matcher() {
317 super(querySpecification());
318 }
319
320 /**
321 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
322 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
323 * @param pMemory the fixed value of pattern parameter Memory, or null if not bound.
324 * @return matches represented as a Match object.
325 *
326 */
327 public Collection<AvailableMemory.Match> getAllMatches(final HostInstance pHost, final Integer pMemory) {
328 return rawStreamAllMatches(new Object[]{pHost, pMemory}).collect(Collectors.toSet());
329 }
330
331 /**
332 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
333 * </p>
334 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
335 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
336 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
337 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
338 * @param pMemory the fixed value of pattern parameter Memory, or null if not bound.
339 * @return a stream of matches represented as a Match object.
340 *
341 */
342 public Stream<AvailableMemory.Match> streamAllMatches(final HostInstance pHost, final Integer pMemory) {
343 return rawStreamAllMatches(new Object[]{pHost, pMemory});
344 }
345
346 /**
347 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
348 * Neither determinism nor randomness of selection is guaranteed.
349 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
350 * @param pMemory the fixed value of pattern parameter Memory, or null if not bound.
351 * @return a match represented as a Match object, or null if no match is found.
352 *
353 */
354 public Optional<AvailableMemory.Match> getOneArbitraryMatch(final HostInstance pHost, final Integer pMemory) {
355 return rawGetOneArbitraryMatch(new Object[]{pHost, pMemory});
356 }
357
358 /**
359 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
360 * under any possible substitution of the unspecified parameters (if any).
361 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
362 * @param pMemory the fixed value of pattern parameter Memory, or null if not bound.
363 * @return true if the input is a valid (partial) match of the pattern.
364 *
365 */
366 public boolean hasMatch(final HostInstance pHost, final Integer pMemory) {
367 return rawHasMatch(new Object[]{pHost, pMemory});
368 }
369
370 /**
371 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
372 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
373 * @param pMemory the fixed value of pattern parameter Memory, or null if not bound.
374 * @return the number of pattern matches found.
375 *
376 */
377 public int countMatches(final HostInstance pHost, final Integer pMemory) {
378 return rawCountMatches(new Object[]{pHost, pMemory});
379 }
380
381 /**
382 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
383 * Neither determinism nor randomness of selection is guaranteed.
384 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
385 * @param pMemory the fixed value of pattern parameter Memory, or null if not bound.
386 * @param processor the action that will process the selected match.
387 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
388 *
389 */
390 public boolean forOneArbitraryMatch(final HostInstance pHost, final Integer pMemory, final Consumer<? super AvailableMemory.Match> processor) {
391 return rawForOneArbitraryMatch(new Object[]{pHost, pMemory}, processor);
392 }
393
394 /**
395 * Returns a new (partial) match.
396 * This can be used e.g. to call the matcher with a partial match.
397 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
398 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
399 * @param pMemory the fixed value of pattern parameter Memory, or null if not bound.
400 * @return the (partial) match object.
401 *
402 */
403 public AvailableMemory.Match newMatch(final HostInstance pHost, final Integer pMemory) {
404 return AvailableMemory.Match.newMatch(pHost, pMemory);
405 }
406
407 /**
408 * Retrieve the set of values that occur in matches for Host.
409 * @return the Set of all values or empty set if there are no matches
410 *
411 */
412 protected Stream<HostInstance> rawStreamAllValuesOfHost(final Object[] parameters) {
413 return rawStreamAllValues(POSITION_HOST, parameters).map(HostInstance.class::cast);
414 }
415
416 /**
417 * Retrieve the set of values that occur in matches for Host.
418 * @return the Set of all values or empty set if there are no matches
419 *
420 */
421 public Set<HostInstance> getAllValuesOfHost() {
422 return rawStreamAllValuesOfHost(emptyArray()).collect(Collectors.toSet());
423 }
424
425 /**
426 * Retrieve the set of values that occur in matches for Host.
427 * @return the Set of all values or empty set if there are no matches
428 *
429 */
430 public Stream<HostInstance> streamAllValuesOfHost() {
431 return rawStreamAllValuesOfHost(emptyArray());
432 }
433
434 /**
435 * Retrieve the set of values that occur in matches for Host.
436 * </p>
437 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
438 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
439 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
440 *
441 * @return the Stream of all values or empty set if there are no matches
442 *
443 */
444 public Stream<HostInstance> streamAllValuesOfHost(final AvailableMemory.Match partialMatch) {
445 return rawStreamAllValuesOfHost(partialMatch.toArray());
446 }
447
448 /**
449 * Retrieve the set of values that occur in matches for Host.
450 * </p>
451 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
452 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
453 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
454 *
455 * @return the Stream of all values or empty set if there are no matches
456 *
457 */
458 public Stream<HostInstance> streamAllValuesOfHost(final Integer pMemory) {
459 return rawStreamAllValuesOfHost(new Object[]{null, pMemory});
460 }
461
462 /**
463 * Retrieve the set of values that occur in matches for Host.
464 * @return the Set of all values or empty set if there are no matches
465 *
466 */
467 public Set<HostInstance> getAllValuesOfHost(final AvailableMemory.Match partialMatch) {
468 return rawStreamAllValuesOfHost(partialMatch.toArray()).collect(Collectors.toSet());
469 }
470
471 /**
472 * Retrieve the set of values that occur in matches for Host.
473 * @return the Set of all values or empty set if there are no matches
474 *
475 */
476 public Set<HostInstance> getAllValuesOfHost(final Integer pMemory) {
477 return rawStreamAllValuesOfHost(new Object[]{null, pMemory}).collect(Collectors.toSet());
478 }
479
480 /**
481 * Retrieve the set of values that occur in matches for Memory.
482 * @return the Set of all values or empty set if there are no matches
483 *
484 */
485 protected Stream<Integer> rawStreamAllValuesOfMemory(final Object[] parameters) {
486 return rawStreamAllValues(POSITION_MEMORY, parameters).map(Integer.class::cast);
487 }
488
489 /**
490 * Retrieve the set of values that occur in matches for Memory.
491 * @return the Set of all values or empty set if there are no matches
492 *
493 */
494 public Set<Integer> getAllValuesOfMemory() {
495 return rawStreamAllValuesOfMemory(emptyArray()).collect(Collectors.toSet());
496 }
497
498 /**
499 * Retrieve the set of values that occur in matches for Memory.
500 * @return the Set of all values or empty set if there are no matches
501 *
502 */
503 public Stream<Integer> streamAllValuesOfMemory() {
504 return rawStreamAllValuesOfMemory(emptyArray());
505 }
506
507 /**
508 * Retrieve the set of values that occur in matches for Memory.
509 * </p>
510 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
511 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
512 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
513 *
514 * @return the Stream of all values or empty set if there are no matches
515 *
516 */
517 public Stream<Integer> streamAllValuesOfMemory(final AvailableMemory.Match partialMatch) {
518 return rawStreamAllValuesOfMemory(partialMatch.toArray());
519 }
520
521 /**
522 * Retrieve the set of values that occur in matches for Memory.
523 * </p>
524 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
525 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
526 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
527 *
528 * @return the Stream of all values or empty set if there are no matches
529 *
530 */
531 public Stream<Integer> streamAllValuesOfMemory(final HostInstance pHost) {
532 return rawStreamAllValuesOfMemory(new Object[]{pHost, null});
533 }
534
535 /**
536 * Retrieve the set of values that occur in matches for Memory.
537 * @return the Set of all values or empty set if there are no matches
538 *
539 */
540 public Set<Integer> getAllValuesOfMemory(final AvailableMemory.Match partialMatch) {
541 return rawStreamAllValuesOfMemory(partialMatch.toArray()).collect(Collectors.toSet());
542 }
543
544 /**
545 * Retrieve the set of values that occur in matches for Memory.
546 * @return the Set of all values or empty set if there are no matches
547 *
548 */
549 public Set<Integer> getAllValuesOfMemory(final HostInstance pHost) {
550 return rawStreamAllValuesOfMemory(new Object[]{pHost, null}).collect(Collectors.toSet());
551 }
552
553 @Override
554 protected AvailableMemory.Match tupleToMatch(final Tuple t) {
555 try {
556 return AvailableMemory.Match.newMatch((HostInstance) t.get(POSITION_HOST), (Integer) t.get(POSITION_MEMORY));
557 } catch(ClassCastException e) {
558 LOGGER.error("Element(s) in tuple not properly typed!",e);
559 return null;
560 }
561 }
562
563 @Override
564 protected AvailableMemory.Match arrayToMatch(final Object[] match) {
565 try {
566 return AvailableMemory.Match.newMatch((HostInstance) match[POSITION_HOST], (Integer) match[POSITION_MEMORY]);
567 } catch(ClassCastException e) {
568 LOGGER.error("Element(s) in array not properly typed!",e);
569 return null;
570 }
571 }
572
573 @Override
574 protected AvailableMemory.Match arrayToMatchMutable(final Object[] match) {
575 try {
576 return AvailableMemory.Match.newMutableMatch((HostInstance) match[POSITION_HOST], (Integer) match[POSITION_MEMORY]);
577 } catch(ClassCastException e) {
578 LOGGER.error("Element(s) in array not properly typed!",e);
579 return null;
580 }
581 }
582
583 /**
584 * @return the singleton instance of the query specification of this pattern
585 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
586 *
587 */
588 public static IQuerySpecification<AvailableMemory.Matcher> querySpecification() {
589 return AvailableMemory.instance();
590 }
591 }
592
593 private AvailableMemory() {
594 super(GeneratedPQuery.INSTANCE);
595 }
596
597 /**
598 * @return the singleton instance of the query specification
599 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
600 *
601 */
602 public static AvailableMemory instance() {
603 try{
604 return LazyHolder.INSTANCE;
605 } catch (ExceptionInInitializerError err) {
606 throw processInitializerError(err);
607 }
608 }
609
610 @Override
611 protected AvailableMemory.Matcher instantiate(final ViatraQueryEngine engine) {
612 return AvailableMemory.Matcher.on(engine);
613 }
614
615 @Override
616 public AvailableMemory.Matcher instantiate() {
617 return AvailableMemory.Matcher.create();
618 }
619
620 @Override
621 public AvailableMemory.Match newEmptyMatch() {
622 return AvailableMemory.Match.newEmptyMatch();
623 }
624
625 @Override
626 public AvailableMemory.Match newMatch(final Object... parameters) {
627 return AvailableMemory.Match.newMatch((hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance) parameters[0], (java.lang.Integer) parameters[1]);
628 }
629
630 /**
631 * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.AvailableMemory (visibility: PUBLIC, simpleName: AvailableMemory, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.AvailableMemory, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)} to be created
632 * <b>not</b> at the class load time of the outer class,
633 * but rather at the first call to {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.AvailableMemory (visibility: PUBLIC, simpleName: AvailableMemory, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.AvailableMemory, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}.
634 *
635 * <p> This workaround is required e.g. to support recursion.
636 *
637 */
638 private static class LazyHolder {
639 private static final AvailableMemory INSTANCE = new AvailableMemory();
640
641 /**
642 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
643 * This initialization order is required to support indirect recursion.
644 *
645 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
646 *
647 */
648 private static final Object STATIC_INITIALIZER = ensureInitialized();
649
650 public static Object ensureInitialized() {
651 INSTANCE.ensureInitializedInternal();
652 return null;
653 }
654 }
655
656 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
657 private static final AvailableMemory.GeneratedPQuery INSTANCE = new GeneratedPQuery();
658
659 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);
660
661 private final PParameter parameter_Memory = new PParameter("Memory", "java.lang.Integer", new JavaTransitiveInstancesKey(java.lang.Integer.class), PParameterDirection.INOUT);
662
663 private final List<PParameter> parameters = Arrays.asList(parameter_Host, parameter_Memory);
664
665 private GeneratedPQuery() {
666 super(PVisibility.PUBLIC);
667 }
668
669 @Override
670 public String getFullyQualifiedName() {
671 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.availableMemory";
672 }
673
674 @Override
675 public List<String> getParameterNames() {
676 return Arrays.asList("Host","Memory");
677 }
678
679 @Override
680 public List<PParameter> getParameters() {
681 return parameters;
682 }
683
684 @Override
685 public Set<PBody> doGetContainedBodies() {
686 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
687 Set<PBody> bodies = new LinkedHashSet<>();
688 {
689 PBody body = new PBody(this);
690 PVariable var_Host = body.getOrCreateVariableByName("Host");
691 PVariable var_Memory = body.getOrCreateVariableByName("Memory");
692 PVariable var_TotalMemory = body.getOrCreateVariableByName("TotalMemory");
693 PVariable var_RequiredMemory = body.getOrCreateVariableByName("RequiredMemory");
694 PVariable var___0_ = body.getOrCreateVariableByName("_<0>");
695 PVariable var___1_ = body.getOrCreateVariableByName("_<1>");
696 new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance")));
697 new TypeFilterConstraint(body, Tuples.flatTupleOf(var_Memory), new JavaTransitiveInstancesKey(java.lang.Integer.class));
698 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
699 new ExportedParameter(body, var_Host, parameter_Host),
700 new ExportedParameter(body, var_Memory, parameter_Memory)
701 ));
702 // find totalMemory(Host, TotalMemory)
703 new PositivePatternCall(body, Tuples.flatTupleOf(var_Host, var_TotalMemory), TotalMemory.instance().getInternalQueryRepresentation());
704 // RequiredMemory == sum find memoryRequirement(Host, _, #_)
705 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
706 new AggregatorConstraint(new sum().getAggregatorLogic(Integer.class), body, Tuples.flatTupleOf(var_Host, var___0_, var___1_), MemoryRequirement.instance().getInternalQueryRepresentation(), var__virtual_0_, 2);
707 new Equality(body, var_RequiredMemory, var__virtual_0_);
708 // Memory == eval(TotalMemory - RequiredMemory)
709 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
710 new ExpressionEvaluation(body, new IExpressionEvaluator() {
711
712 @Override
713 public String getShortDescription() {
714 return "Expression evaluation from pattern availableMemory";
715 }
716
717 @Override
718 public Iterable<String> getInputParameterNames() {
719 return Arrays.asList("RequiredMemory", "TotalMemory");}
720
721 @Override
722 public Object evaluateExpression(IValueProvider provider) throws Exception {
723 Integer RequiredMemory = (Integer) provider.getValue("RequiredMemory");
724 Integer TotalMemory = (Integer) provider.getValue("TotalMemory");
725 return evaluateExpression_1_1(RequiredMemory, TotalMemory);
726 }
727 }, var__virtual_1_ );
728 new Equality(body, var_Memory, var__virtual_1_);
729 bodies.add(body);
730 }
731 {
732 PAnnotation annotation = new PAnnotation("QueryBasedFeature");
733 annotation.addAttribute("feature", "availableMemory");
734 addAnnotation(annotation);
735 }
736 return bodies;
737 }
738 }
739
740 private static int evaluateExpression_1_1(final Integer RequiredMemory, final Integer TotalMemory) {
741 return ((TotalMemory).intValue() - (RequiredMemory).intValue());
742 }
743}
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..59d4ad27
--- /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,540 @@
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 * pattern averageFreeHddMetric(Average : java Double) {
47 * Average == avg find freeHddPercentage(_, #_);
48 * }
49 * </pre></code>
50 *
51 * @see Matcher
52 * @see Match
53 *
54 */
55@SuppressWarnings("all")
56public final class AverageFreeHddMetric extends BaseGeneratedEMFQuerySpecification<AverageFreeHddMetric.Matcher> {
57 /**
58 * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.averageFreeHddMetric 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 Double fAverage;
71
72 private static List<String> parameterNames = makeImmutableList("Average");
73
74 private Match(final Double pAverage) {
75 this.fAverage = pAverage;
76 }
77
78 @Override
79 public Object get(final String parameterName) {
80 if ("Average".equals(parameterName)) return this.fAverage;
81 return null;
82 }
83
84 public Double getAverage() {
85 return this.fAverage;
86 }
87
88 @Override
89 public boolean set(final String parameterName, final Object newValue) {
90 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
91 if ("Average".equals(parameterName) ) {
92 this.fAverage = (Double) newValue;
93 return true;
94 }
95 return false;
96 }
97
98 public void setAverage(final Double pAverage) {
99 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
100 this.fAverage = pAverage;
101 }
102
103 @Override
104 public String patternName() {
105 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.averageFreeHddMetric";
106 }
107
108 @Override
109 public List<String> parameterNames() {
110 return AverageFreeHddMetric.Match.parameterNames;
111 }
112
113 @Override
114 public Object[] toArray() {
115 return new Object[]{fAverage};
116 }
117
118 @Override
119 public AverageFreeHddMetric.Match toImmutable() {
120 return isMutable() ? newMatch(fAverage) : this;
121 }
122
123 @Override
124 public String prettyPrint() {
125 StringBuilder result = new StringBuilder();
126 result.append("\"Average\"=" + prettyPrintValue(fAverage));
127 return result.toString();
128 }
129
130 @Override
131 public int hashCode() {
132 return Objects.hash(fAverage);
133 }
134
135 @Override
136 public boolean equals(final Object obj) {
137 if (this == obj)
138 return true;
139 if (obj == null) {
140 return false;
141 }
142 if ((obj instanceof AverageFreeHddMetric.Match)) {
143 AverageFreeHddMetric.Match other = (AverageFreeHddMetric.Match) obj;
144 return Objects.equals(fAverage, other.fAverage);
145 } else {
146 // this should be infrequent
147 if (!(obj instanceof IPatternMatch)) {
148 return false;
149 }
150 IPatternMatch otherSig = (IPatternMatch) obj;
151 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
152 }
153 }
154
155 @Override
156 public AverageFreeHddMetric specification() {
157 return AverageFreeHddMetric.instance();
158 }
159
160 /**
161 * Returns an empty, mutable match.
162 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
163 *
164 * @return the empty match.
165 *
166 */
167 public static AverageFreeHddMetric.Match newEmptyMatch() {
168 return new Mutable(null);
169 }
170
171 /**
172 * Returns a mutable (partial) match.
173 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
174 *
175 * @param pAverage the fixed value of pattern parameter Average, or null if not bound.
176 * @return the new, mutable (partial) match object.
177 *
178 */
179 public static AverageFreeHddMetric.Match newMutableMatch(final Double pAverage) {
180 return new Mutable(pAverage);
181 }
182
183 /**
184 * Returns a new (partial) match.
185 * This can be used e.g. to call the matcher with a partial match.
186 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
187 * @param pAverage the fixed value of pattern parameter Average, or null if not bound.
188 * @return the (partial) match object.
189 *
190 */
191 public static AverageFreeHddMetric.Match newMatch(final Double pAverage) {
192 return new Immutable(pAverage);
193 }
194
195 private static final class Mutable extends AverageFreeHddMetric.Match {
196 Mutable(final Double pAverage) {
197 super(pAverage);
198 }
199
200 @Override
201 public boolean isMutable() {
202 return true;
203 }
204 }
205
206 private static final class Immutable extends AverageFreeHddMetric.Match {
207 Immutable(final Double pAverage) {
208 super(pAverage);
209 }
210
211 @Override
212 public boolean isMutable() {
213 return false;
214 }
215 }
216 }
217
218 /**
219 * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.averageFreeHddMetric pattern,
220 * providing pattern-specific query methods.
221 *
222 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
223 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
224 *
225 * <p>Matches of the pattern will be represented as {@link Match}.
226 *
227 * <p>Original source:
228 * <code><pre>
229 * pattern averageFreeHddMetric(Average : java Double) {
230 * Average == avg find freeHddPercentage(_, #_);
231 * }
232 * </pre></code>
233 *
234 * @see Match
235 * @see AverageFreeHddMetric
236 *
237 */
238 public static class Matcher extends BaseMatcher<AverageFreeHddMetric.Match> {
239 /**
240 * Initializes the pattern matcher within an existing VIATRA Query engine.
241 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
242 *
243 * @param engine the existing VIATRA Query engine in which this matcher will be created.
244 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
245 *
246 */
247 public static AverageFreeHddMetric.Matcher on(final ViatraQueryEngine engine) {
248 // check if matcher already exists
249 Matcher matcher = engine.getExistingMatcher(querySpecification());
250 if (matcher == null) {
251 matcher = (Matcher)engine.getMatcher(querySpecification());
252 }
253 return matcher;
254 }
255
256 /**
257 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
258 * @return an initialized matcher
259 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
260 *
261 */
262 public static AverageFreeHddMetric.Matcher create() {
263 return new Matcher();
264 }
265
266 private static final int POSITION_AVERAGE = 0;
267
268 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(AverageFreeHddMetric.Matcher.class);
269
270 /**
271 * Initializes the pattern matcher within an existing VIATRA Query engine.
272 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
273 *
274 * @param engine the existing VIATRA Query engine in which this matcher will be created.
275 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
276 *
277 */
278 private Matcher() {
279 super(querySpecification());
280 }
281
282 /**
283 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
284 * @param pAverage the fixed value of pattern parameter Average, or null if not bound.
285 * @return matches represented as a Match object.
286 *
287 */
288 public Collection<AverageFreeHddMetric.Match> getAllMatches(final Double pAverage) {
289 return rawStreamAllMatches(new Object[]{pAverage}).collect(Collectors.toSet());
290 }
291
292 /**
293 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
294 * </p>
295 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
296 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
297 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
298 * @param pAverage the fixed value of pattern parameter Average, or null if not bound.
299 * @return a stream of matches represented as a Match object.
300 *
301 */
302 public Stream<AverageFreeHddMetric.Match> streamAllMatches(final Double pAverage) {
303 return rawStreamAllMatches(new Object[]{pAverage});
304 }
305
306 /**
307 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
308 * Neither determinism nor randomness of selection is guaranteed.
309 * @param pAverage the fixed value of pattern parameter Average, or null if not bound.
310 * @return a match represented as a Match object, or null if no match is found.
311 *
312 */
313 public Optional<AverageFreeHddMetric.Match> getOneArbitraryMatch(final Double pAverage) {
314 return rawGetOneArbitraryMatch(new Object[]{pAverage});
315 }
316
317 /**
318 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
319 * under any possible substitution of the unspecified parameters (if any).
320 * @param pAverage the fixed value of pattern parameter Average, or null if not bound.
321 * @return true if the input is a valid (partial) match of the pattern.
322 *
323 */
324 public boolean hasMatch(final Double pAverage) {
325 return rawHasMatch(new Object[]{pAverage});
326 }
327
328 /**
329 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
330 * @param pAverage the fixed value of pattern parameter Average, or null if not bound.
331 * @return the number of pattern matches found.
332 *
333 */
334 public int countMatches(final Double pAverage) {
335 return rawCountMatches(new Object[]{pAverage});
336 }
337
338 /**
339 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
340 * Neither determinism nor randomness of selection is guaranteed.
341 * @param pAverage the fixed value of pattern parameter Average, or null if not bound.
342 * @param processor the action that will process the selected match.
343 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
344 *
345 */
346 public boolean forOneArbitraryMatch(final Double pAverage, final Consumer<? super AverageFreeHddMetric.Match> processor) {
347 return rawForOneArbitraryMatch(new Object[]{pAverage}, processor);
348 }
349
350 /**
351 * Returns a new (partial) match.
352 * This can be used e.g. to call the matcher with a partial match.
353 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
354 * @param pAverage the fixed value of pattern parameter Average, or null if not bound.
355 * @return the (partial) match object.
356 *
357 */
358 public AverageFreeHddMetric.Match newMatch(final Double pAverage) {
359 return AverageFreeHddMetric.Match.newMatch(pAverage);
360 }
361
362 /**
363 * Retrieve the set of values that occur in matches for Average.
364 * @return the Set of all values or empty set if there are no matches
365 *
366 */
367 protected Stream<Double> rawStreamAllValuesOfAverage(final Object[] parameters) {
368 return rawStreamAllValues(POSITION_AVERAGE, parameters).map(Double.class::cast);
369 }
370
371 /**
372 * Retrieve the set of values that occur in matches for Average.
373 * @return the Set of all values or empty set if there are no matches
374 *
375 */
376 public Set<Double> getAllValuesOfAverage() {
377 return rawStreamAllValuesOfAverage(emptyArray()).collect(Collectors.toSet());
378 }
379
380 /**
381 * Retrieve the set of values that occur in matches for Average.
382 * @return the Set of all values or empty set if there are no matches
383 *
384 */
385 public Stream<Double> streamAllValuesOfAverage() {
386 return rawStreamAllValuesOfAverage(emptyArray());
387 }
388
389 @Override
390 protected AverageFreeHddMetric.Match tupleToMatch(final Tuple t) {
391 try {
392 return AverageFreeHddMetric.Match.newMatch((Double) t.get(POSITION_AVERAGE));
393 } catch(ClassCastException e) {
394 LOGGER.error("Element(s) in tuple not properly typed!",e);
395 return null;
396 }
397 }
398
399 @Override
400 protected AverageFreeHddMetric.Match arrayToMatch(final Object[] match) {
401 try {
402 return AverageFreeHddMetric.Match.newMatch((Double) match[POSITION_AVERAGE]);
403 } catch(ClassCastException e) {
404 LOGGER.error("Element(s) in array not properly typed!",e);
405 return null;
406 }
407 }
408
409 @Override
410 protected AverageFreeHddMetric.Match arrayToMatchMutable(final Object[] match) {
411 try {
412 return AverageFreeHddMetric.Match.newMutableMatch((Double) match[POSITION_AVERAGE]);
413 } catch(ClassCastException e) {
414 LOGGER.error("Element(s) in array not properly typed!",e);
415 return null;
416 }
417 }
418
419 /**
420 * @return the singleton instance of the query specification of this pattern
421 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
422 *
423 */
424 public static IQuerySpecification<AverageFreeHddMetric.Matcher> querySpecification() {
425 return AverageFreeHddMetric.instance();
426 }
427 }
428
429 private AverageFreeHddMetric() {
430 super(GeneratedPQuery.INSTANCE);
431 }
432
433 /**
434 * @return the singleton instance of the query specification
435 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
436 *
437 */
438 public static AverageFreeHddMetric instance() {
439 try{
440 return LazyHolder.INSTANCE;
441 } catch (ExceptionInInitializerError err) {
442 throw processInitializerError(err);
443 }
444 }
445
446 @Override
447 protected AverageFreeHddMetric.Matcher instantiate(final ViatraQueryEngine engine) {
448 return AverageFreeHddMetric.Matcher.on(engine);
449 }
450
451 @Override
452 public AverageFreeHddMetric.Matcher instantiate() {
453 return AverageFreeHddMetric.Matcher.create();
454 }
455
456 @Override
457 public AverageFreeHddMetric.Match newEmptyMatch() {
458 return AverageFreeHddMetric.Match.newEmptyMatch();
459 }
460
461 @Override
462 public AverageFreeHddMetric.Match newMatch(final Object... parameters) {
463 return AverageFreeHddMetric.Match.newMatch((java.lang.Double) parameters[0]);
464 }
465
466 /**
467 * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.AverageFreeHddMetric (visibility: PUBLIC, simpleName: AverageFreeHddMetric, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.AverageFreeHddMetric, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)} to be created
468 * <b>not</b> at the class load time of the outer class,
469 * but rather at the first call to {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.AverageFreeHddMetric (visibility: PUBLIC, simpleName: AverageFreeHddMetric, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.AverageFreeHddMetric, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}.
470 *
471 * <p> This workaround is required e.g. to support recursion.
472 *
473 */
474 private static class LazyHolder {
475 private static final AverageFreeHddMetric INSTANCE = new AverageFreeHddMetric();
476
477 /**
478 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
479 * This initialization order is required to support indirect recursion.
480 *
481 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
482 *
483 */
484 private static final Object STATIC_INITIALIZER = ensureInitialized();
485
486 public static Object ensureInitialized() {
487 INSTANCE.ensureInitializedInternal();
488 return null;
489 }
490 }
491
492 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
493 private static final AverageFreeHddMetric.GeneratedPQuery INSTANCE = new GeneratedPQuery();
494
495 private final PParameter parameter_Average = new PParameter("Average", "java.lang.Double", new JavaTransitiveInstancesKey(java.lang.Double.class), PParameterDirection.INOUT);
496
497 private final List<PParameter> parameters = Arrays.asList(parameter_Average);
498
499 private GeneratedPQuery() {
500 super(PVisibility.PUBLIC);
501 }
502
503 @Override
504 public String getFullyQualifiedName() {
505 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.averageFreeHddMetric";
506 }
507
508 @Override
509 public List<String> getParameterNames() {
510 return Arrays.asList("Average");
511 }
512
513 @Override
514 public List<PParameter> getParameters() {
515 return parameters;
516 }
517
518 @Override
519 public Set<PBody> doGetContainedBodies() {
520 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
521 Set<PBody> bodies = new LinkedHashSet<>();
522 {
523 PBody body = new PBody(this);
524 PVariable var_Average = body.getOrCreateVariableByName("Average");
525 PVariable var___0_ = body.getOrCreateVariableByName("_<0>");
526 PVariable var___1_ = body.getOrCreateVariableByName("_<1>");
527 new TypeFilterConstraint(body, Tuples.flatTupleOf(var_Average), new JavaTransitiveInstancesKey(java.lang.Double.class));
528 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
529 new ExportedParameter(body, var_Average, parameter_Average)
530 ));
531 // Average == avg find freeHddPercentage(_, #_)
532 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
533 new AggregatorConstraint(new avg().getAggregatorLogic(Double.class), body, Tuples.flatTupleOf(var___0_, var___1_), FreeHddPercentage.instance().getInternalQueryRepresentation(), var__virtual_0_, 1);
534 new Equality(body, var_Average, var__virtual_0_);
535 bodies.add(body);
536 }
537 return bodies;
538 }
539 }
540}
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..a0d087f4
--- /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,540 @@
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 * pattern averageFreeMemoryMetric(Average : java Double) {
47 * Average == avg find freeMemoryPercentage(_, #_);
48 * }
49 * </pre></code>
50 *
51 * @see Matcher
52 * @see Match
53 *
54 */
55@SuppressWarnings("all")
56public final class AverageFreeMemoryMetric extends BaseGeneratedEMFQuerySpecification<AverageFreeMemoryMetric.Matcher> {
57 /**
58 * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.averageFreeMemoryMetric 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 Double fAverage;
71
72 private static List<String> parameterNames = makeImmutableList("Average");
73
74 private Match(final Double pAverage) {
75 this.fAverage = pAverage;
76 }
77
78 @Override
79 public Object get(final String parameterName) {
80 if ("Average".equals(parameterName)) return this.fAverage;
81 return null;
82 }
83
84 public Double getAverage() {
85 return this.fAverage;
86 }
87
88 @Override
89 public boolean set(final String parameterName, final Object newValue) {
90 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
91 if ("Average".equals(parameterName) ) {
92 this.fAverage = (Double) newValue;
93 return true;
94 }
95 return false;
96 }
97
98 public void setAverage(final Double pAverage) {
99 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
100 this.fAverage = pAverage;
101 }
102
103 @Override
104 public String patternName() {
105 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.averageFreeMemoryMetric";
106 }
107
108 @Override
109 public List<String> parameterNames() {
110 return AverageFreeMemoryMetric.Match.parameterNames;
111 }
112
113 @Override
114 public Object[] toArray() {
115 return new Object[]{fAverage};
116 }
117
118 @Override
119 public AverageFreeMemoryMetric.Match toImmutable() {
120 return isMutable() ? newMatch(fAverage) : this;
121 }
122
123 @Override
124 public String prettyPrint() {
125 StringBuilder result = new StringBuilder();
126 result.append("\"Average\"=" + prettyPrintValue(fAverage));
127 return result.toString();
128 }
129
130 @Override
131 public int hashCode() {
132 return Objects.hash(fAverage);
133 }
134
135 @Override
136 public boolean equals(final Object obj) {
137 if (this == obj)
138 return true;
139 if (obj == null) {
140 return false;
141 }
142 if ((obj instanceof AverageFreeMemoryMetric.Match)) {
143 AverageFreeMemoryMetric.Match other = (AverageFreeMemoryMetric.Match) obj;
144 return Objects.equals(fAverage, other.fAverage);
145 } else {
146 // this should be infrequent
147 if (!(obj instanceof IPatternMatch)) {
148 return false;
149 }
150 IPatternMatch otherSig = (IPatternMatch) obj;
151 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
152 }
153 }
154
155 @Override
156 public AverageFreeMemoryMetric specification() {
157 return AverageFreeMemoryMetric.instance();
158 }
159
160 /**
161 * Returns an empty, mutable match.
162 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
163 *
164 * @return the empty match.
165 *
166 */
167 public static AverageFreeMemoryMetric.Match newEmptyMatch() {
168 return new Mutable(null);
169 }
170
171 /**
172 * Returns a mutable (partial) match.
173 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
174 *
175 * @param pAverage the fixed value of pattern parameter Average, or null if not bound.
176 * @return the new, mutable (partial) match object.
177 *
178 */
179 public static AverageFreeMemoryMetric.Match newMutableMatch(final Double pAverage) {
180 return new Mutable(pAverage);
181 }
182
183 /**
184 * Returns a new (partial) match.
185 * This can be used e.g. to call the matcher with a partial match.
186 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
187 * @param pAverage the fixed value of pattern parameter Average, or null if not bound.
188 * @return the (partial) match object.
189 *
190 */
191 public static AverageFreeMemoryMetric.Match newMatch(final Double pAverage) {
192 return new Immutable(pAverage);
193 }
194
195 private static final class Mutable extends AverageFreeMemoryMetric.Match {
196 Mutable(final Double pAverage) {
197 super(pAverage);
198 }
199
200 @Override
201 public boolean isMutable() {
202 return true;
203 }
204 }
205
206 private static final class Immutable extends AverageFreeMemoryMetric.Match {
207 Immutable(final Double pAverage) {
208 super(pAverage);
209 }
210
211 @Override
212 public boolean isMutable() {
213 return false;
214 }
215 }
216 }
217
218 /**
219 * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.averageFreeMemoryMetric pattern,
220 * providing pattern-specific query methods.
221 *
222 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
223 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
224 *
225 * <p>Matches of the pattern will be represented as {@link Match}.
226 *
227 * <p>Original source:
228 * <code><pre>
229 * pattern averageFreeMemoryMetric(Average : java Double) {
230 * Average == avg find freeMemoryPercentage(_, #_);
231 * }
232 * </pre></code>
233 *
234 * @see Match
235 * @see AverageFreeMemoryMetric
236 *
237 */
238 public static class Matcher extends BaseMatcher<AverageFreeMemoryMetric.Match> {
239 /**
240 * Initializes the pattern matcher within an existing VIATRA Query engine.
241 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
242 *
243 * @param engine the existing VIATRA Query engine in which this matcher will be created.
244 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
245 *
246 */
247 public static AverageFreeMemoryMetric.Matcher on(final ViatraQueryEngine engine) {
248 // check if matcher already exists
249 Matcher matcher = engine.getExistingMatcher(querySpecification());
250 if (matcher == null) {
251 matcher = (Matcher)engine.getMatcher(querySpecification());
252 }
253 return matcher;
254 }
255
256 /**
257 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
258 * @return an initialized matcher
259 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
260 *
261 */
262 public static AverageFreeMemoryMetric.Matcher create() {
263 return new Matcher();
264 }
265
266 private static final int POSITION_AVERAGE = 0;
267
268 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(AverageFreeMemoryMetric.Matcher.class);
269
270 /**
271 * Initializes the pattern matcher within an existing VIATRA Query engine.
272 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
273 *
274 * @param engine the existing VIATRA Query engine in which this matcher will be created.
275 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
276 *
277 */
278 private Matcher() {
279 super(querySpecification());
280 }
281
282 /**
283 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
284 * @param pAverage the fixed value of pattern parameter Average, or null if not bound.
285 * @return matches represented as a Match object.
286 *
287 */
288 public Collection<AverageFreeMemoryMetric.Match> getAllMatches(final Double pAverage) {
289 return rawStreamAllMatches(new Object[]{pAverage}).collect(Collectors.toSet());
290 }
291
292 /**
293 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
294 * </p>
295 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
296 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
297 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
298 * @param pAverage the fixed value of pattern parameter Average, or null if not bound.
299 * @return a stream of matches represented as a Match object.
300 *
301 */
302 public Stream<AverageFreeMemoryMetric.Match> streamAllMatches(final Double pAverage) {
303 return rawStreamAllMatches(new Object[]{pAverage});
304 }
305
306 /**
307 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
308 * Neither determinism nor randomness of selection is guaranteed.
309 * @param pAverage the fixed value of pattern parameter Average, or null if not bound.
310 * @return a match represented as a Match object, or null if no match is found.
311 *
312 */
313 public Optional<AverageFreeMemoryMetric.Match> getOneArbitraryMatch(final Double pAverage) {
314 return rawGetOneArbitraryMatch(new Object[]{pAverage});
315 }
316
317 /**
318 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
319 * under any possible substitution of the unspecified parameters (if any).
320 * @param pAverage the fixed value of pattern parameter Average, or null if not bound.
321 * @return true if the input is a valid (partial) match of the pattern.
322 *
323 */
324 public boolean hasMatch(final Double pAverage) {
325 return rawHasMatch(new Object[]{pAverage});
326 }
327
328 /**
329 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
330 * @param pAverage the fixed value of pattern parameter Average, or null if not bound.
331 * @return the number of pattern matches found.
332 *
333 */
334 public int countMatches(final Double pAverage) {
335 return rawCountMatches(new Object[]{pAverage});
336 }
337
338 /**
339 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
340 * Neither determinism nor randomness of selection is guaranteed.
341 * @param pAverage the fixed value of pattern parameter Average, or null if not bound.
342 * @param processor the action that will process the selected match.
343 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
344 *
345 */
346 public boolean forOneArbitraryMatch(final Double pAverage, final Consumer<? super AverageFreeMemoryMetric.Match> processor) {
347 return rawForOneArbitraryMatch(new Object[]{pAverage}, processor);
348 }
349
350 /**
351 * Returns a new (partial) match.
352 * This can be used e.g. to call the matcher with a partial match.
353 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
354 * @param pAverage the fixed value of pattern parameter Average, or null if not bound.
355 * @return the (partial) match object.
356 *
357 */
358 public AverageFreeMemoryMetric.Match newMatch(final Double pAverage) {
359 return AverageFreeMemoryMetric.Match.newMatch(pAverage);
360 }
361
362 /**
363 * Retrieve the set of values that occur in matches for Average.
364 * @return the Set of all values or empty set if there are no matches
365 *
366 */
367 protected Stream<Double> rawStreamAllValuesOfAverage(final Object[] parameters) {
368 return rawStreamAllValues(POSITION_AVERAGE, parameters).map(Double.class::cast);
369 }
370
371 /**
372 * Retrieve the set of values that occur in matches for Average.
373 * @return the Set of all values or empty set if there are no matches
374 *
375 */
376 public Set<Double> getAllValuesOfAverage() {
377 return rawStreamAllValuesOfAverage(emptyArray()).collect(Collectors.toSet());
378 }
379
380 /**
381 * Retrieve the set of values that occur in matches for Average.
382 * @return the Set of all values or empty set if there are no matches
383 *
384 */
385 public Stream<Double> streamAllValuesOfAverage() {
386 return rawStreamAllValuesOfAverage(emptyArray());
387 }
388
389 @Override
390 protected AverageFreeMemoryMetric.Match tupleToMatch(final Tuple t) {
391 try {
392 return AverageFreeMemoryMetric.Match.newMatch((Double) t.get(POSITION_AVERAGE));
393 } catch(ClassCastException e) {
394 LOGGER.error("Element(s) in tuple not properly typed!",e);
395 return null;
396 }
397 }
398
399 @Override
400 protected AverageFreeMemoryMetric.Match arrayToMatch(final Object[] match) {
401 try {
402 return AverageFreeMemoryMetric.Match.newMatch((Double) match[POSITION_AVERAGE]);
403 } catch(ClassCastException e) {
404 LOGGER.error("Element(s) in array not properly typed!",e);
405 return null;
406 }
407 }
408
409 @Override
410 protected AverageFreeMemoryMetric.Match arrayToMatchMutable(final Object[] match) {
411 try {
412 return AverageFreeMemoryMetric.Match.newMutableMatch((Double) match[POSITION_AVERAGE]);
413 } catch(ClassCastException e) {
414 LOGGER.error("Element(s) in array not properly typed!",e);
415 return null;
416 }
417 }
418
419 /**
420 * @return the singleton instance of the query specification of this pattern
421 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
422 *
423 */
424 public static IQuerySpecification<AverageFreeMemoryMetric.Matcher> querySpecification() {
425 return AverageFreeMemoryMetric.instance();
426 }
427 }
428
429 private AverageFreeMemoryMetric() {
430 super(GeneratedPQuery.INSTANCE);
431 }
432
433 /**
434 * @return the singleton instance of the query specification
435 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
436 *
437 */
438 public static AverageFreeMemoryMetric instance() {
439 try{
440 return LazyHolder.INSTANCE;
441 } catch (ExceptionInInitializerError err) {
442 throw processInitializerError(err);
443 }
444 }
445
446 @Override
447 protected AverageFreeMemoryMetric.Matcher instantiate(final ViatraQueryEngine engine) {
448 return AverageFreeMemoryMetric.Matcher.on(engine);
449 }
450
451 @Override
452 public AverageFreeMemoryMetric.Matcher instantiate() {
453 return AverageFreeMemoryMetric.Matcher.create();
454 }
455
456 @Override
457 public AverageFreeMemoryMetric.Match newEmptyMatch() {
458 return AverageFreeMemoryMetric.Match.newEmptyMatch();
459 }
460
461 @Override
462 public AverageFreeMemoryMetric.Match newMatch(final Object... parameters) {
463 return AverageFreeMemoryMetric.Match.newMatch((java.lang.Double) parameters[0]);
464 }
465
466 /**
467 * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.AverageFreeMemoryMetric (visibility: PUBLIC, simpleName: AverageFreeMemoryMetric, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.AverageFreeMemoryMetric, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)} to be created
468 * <b>not</b> at the class load time of the outer class,
469 * but rather at the first call to {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.AverageFreeMemoryMetric (visibility: PUBLIC, simpleName: AverageFreeMemoryMetric, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.AverageFreeMemoryMetric, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}.
470 *
471 * <p> This workaround is required e.g. to support recursion.
472 *
473 */
474 private static class LazyHolder {
475 private static final AverageFreeMemoryMetric INSTANCE = new AverageFreeMemoryMetric();
476
477 /**
478 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
479 * This initialization order is required to support indirect recursion.
480 *
481 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
482 *
483 */
484 private static final Object STATIC_INITIALIZER = ensureInitialized();
485
486 public static Object ensureInitialized() {
487 INSTANCE.ensureInitializedInternal();
488 return null;
489 }
490 }
491
492 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
493 private static final AverageFreeMemoryMetric.GeneratedPQuery INSTANCE = new GeneratedPQuery();
494
495 private final PParameter parameter_Average = new PParameter("Average", "java.lang.Double", new JavaTransitiveInstancesKey(java.lang.Double.class), PParameterDirection.INOUT);
496
497 private final List<PParameter> parameters = Arrays.asList(parameter_Average);
498
499 private GeneratedPQuery() {
500 super(PVisibility.PUBLIC);
501 }
502
503 @Override
504 public String getFullyQualifiedName() {
505 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.averageFreeMemoryMetric";
506 }
507
508 @Override
509 public List<String> getParameterNames() {
510 return Arrays.asList("Average");
511 }
512
513 @Override
514 public List<PParameter> getParameters() {
515 return parameters;
516 }
517
518 @Override
519 public Set<PBody> doGetContainedBodies() {
520 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
521 Set<PBody> bodies = new LinkedHashSet<>();
522 {
523 PBody body = new PBody(this);
524 PVariable var_Average = body.getOrCreateVariableByName("Average");
525 PVariable var___0_ = body.getOrCreateVariableByName("_<0>");
526 PVariable var___1_ = body.getOrCreateVariableByName("_<1>");
527 new TypeFilterConstraint(body, Tuples.flatTupleOf(var_Average), new JavaTransitiveInstancesKey(java.lang.Double.class));
528 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
529 new ExportedParameter(body, var_Average, parameter_Average)
530 ));
531 // Average == avg find freeMemoryPercentage(_, #_)
532 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
533 new AggregatorConstraint(new avg().getAggregatorLogic(Double.class), body, Tuples.flatTupleOf(var___0_, var___1_), FreeMemoryPercentage.instance().getInternalQueryRepresentation(), var__virtual_0_, 1);
534 new Equality(body, var_Average, var__virtual_0_);
535 bodies.add(body);
536 }
537 return bodies;
538 }
539 }
540}
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..4d8ca4cc
--- /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,540 @@
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 * pattern costMetric(Cost : java Integer) {
47 * Cost == sum find cpsCost(_, #_);
48 * }
49 * </pre></code>
50 *
51 * @see Matcher
52 * @see Match
53 *
54 */
55@SuppressWarnings("all")
56public final class CostMetric extends BaseGeneratedEMFQuerySpecification<CostMetric.Matcher> {
57 /**
58 * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.costMetric 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 Integer fCost;
71
72 private static List<String> parameterNames = makeImmutableList("Cost");
73
74 private Match(final Integer pCost) {
75 this.fCost = pCost;
76 }
77
78 @Override
79 public Object get(final String parameterName) {
80 if ("Cost".equals(parameterName)) return this.fCost;
81 return null;
82 }
83
84 public Integer getCost() {
85 return this.fCost;
86 }
87
88 @Override
89 public boolean set(final String parameterName, final Object newValue) {
90 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
91 if ("Cost".equals(parameterName) ) {
92 this.fCost = (Integer) newValue;
93 return true;
94 }
95 return false;
96 }
97
98 public void setCost(final Integer pCost) {
99 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
100 this.fCost = pCost;
101 }
102
103 @Override
104 public String patternName() {
105 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.costMetric";
106 }
107
108 @Override
109 public List<String> parameterNames() {
110 return CostMetric.Match.parameterNames;
111 }
112
113 @Override
114 public Object[] toArray() {
115 return new Object[]{fCost};
116 }
117
118 @Override
119 public CostMetric.Match toImmutable() {
120 return isMutable() ? newMatch(fCost) : this;
121 }
122
123 @Override
124 public String prettyPrint() {
125 StringBuilder result = new StringBuilder();
126 result.append("\"Cost\"=" + prettyPrintValue(fCost));
127 return result.toString();
128 }
129
130 @Override
131 public int hashCode() {
132 return Objects.hash(fCost);
133 }
134
135 @Override
136 public boolean equals(final Object obj) {
137 if (this == obj)
138 return true;
139 if (obj == null) {
140 return false;
141 }
142 if ((obj instanceof CostMetric.Match)) {
143 CostMetric.Match other = (CostMetric.Match) obj;
144 return Objects.equals(fCost, other.fCost);
145 } else {
146 // this should be infrequent
147 if (!(obj instanceof IPatternMatch)) {
148 return false;
149 }
150 IPatternMatch otherSig = (IPatternMatch) obj;
151 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
152 }
153 }
154
155 @Override
156 public CostMetric specification() {
157 return CostMetric.instance();
158 }
159
160 /**
161 * Returns an empty, mutable match.
162 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
163 *
164 * @return the empty match.
165 *
166 */
167 public static CostMetric.Match newEmptyMatch() {
168 return new Mutable(null);
169 }
170
171 /**
172 * Returns a mutable (partial) match.
173 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
174 *
175 * @param pCost the fixed value of pattern parameter Cost, or null if not bound.
176 * @return the new, mutable (partial) match object.
177 *
178 */
179 public static CostMetric.Match newMutableMatch(final Integer pCost) {
180 return new Mutable(pCost);
181 }
182
183 /**
184 * Returns a new (partial) match.
185 * This can be used e.g. to call the matcher with a partial match.
186 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
187 * @param pCost the fixed value of pattern parameter Cost, or null if not bound.
188 * @return the (partial) match object.
189 *
190 */
191 public static CostMetric.Match newMatch(final Integer pCost) {
192 return new Immutable(pCost);
193 }
194
195 private static final class Mutable extends CostMetric.Match {
196 Mutable(final Integer pCost) {
197 super(pCost);
198 }
199
200 @Override
201 public boolean isMutable() {
202 return true;
203 }
204 }
205
206 private static final class Immutable extends CostMetric.Match {
207 Immutable(final Integer pCost) {
208 super(pCost);
209 }
210
211 @Override
212 public boolean isMutable() {
213 return false;
214 }
215 }
216 }
217
218 /**
219 * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.costMetric pattern,
220 * providing pattern-specific query methods.
221 *
222 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
223 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
224 *
225 * <p>Matches of the pattern will be represented as {@link Match}.
226 *
227 * <p>Original source:
228 * <code><pre>
229 * pattern costMetric(Cost : java Integer) {
230 * Cost == sum find cpsCost(_, #_);
231 * }
232 * </pre></code>
233 *
234 * @see Match
235 * @see CostMetric
236 *
237 */
238 public static class Matcher extends BaseMatcher<CostMetric.Match> {
239 /**
240 * Initializes the pattern matcher within an existing VIATRA Query engine.
241 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
242 *
243 * @param engine the existing VIATRA Query engine in which this matcher will be created.
244 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
245 *
246 */
247 public static CostMetric.Matcher on(final ViatraQueryEngine engine) {
248 // check if matcher already exists
249 Matcher matcher = engine.getExistingMatcher(querySpecification());
250 if (matcher == null) {
251 matcher = (Matcher)engine.getMatcher(querySpecification());
252 }
253 return matcher;
254 }
255
256 /**
257 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
258 * @return an initialized matcher
259 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
260 *
261 */
262 public static CostMetric.Matcher create() {
263 return new Matcher();
264 }
265
266 private static final int POSITION_COST = 0;
267
268 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(CostMetric.Matcher.class);
269
270 /**
271 * Initializes the pattern matcher within an existing VIATRA Query engine.
272 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
273 *
274 * @param engine the existing VIATRA Query engine in which this matcher will be created.
275 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
276 *
277 */
278 private Matcher() {
279 super(querySpecification());
280 }
281
282 /**
283 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
284 * @param pCost the fixed value of pattern parameter Cost, or null if not bound.
285 * @return matches represented as a Match object.
286 *
287 */
288 public Collection<CostMetric.Match> getAllMatches(final Integer pCost) {
289 return rawStreamAllMatches(new Object[]{pCost}).collect(Collectors.toSet());
290 }
291
292 /**
293 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
294 * </p>
295 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
296 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
297 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
298 * @param pCost the fixed value of pattern parameter Cost, or null if not bound.
299 * @return a stream of matches represented as a Match object.
300 *
301 */
302 public Stream<CostMetric.Match> streamAllMatches(final Integer pCost) {
303 return rawStreamAllMatches(new Object[]{pCost});
304 }
305
306 /**
307 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
308 * Neither determinism nor randomness of selection is guaranteed.
309 * @param pCost the fixed value of pattern parameter Cost, or null if not bound.
310 * @return a match represented as a Match object, or null if no match is found.
311 *
312 */
313 public Optional<CostMetric.Match> getOneArbitraryMatch(final Integer pCost) {
314 return rawGetOneArbitraryMatch(new Object[]{pCost});
315 }
316
317 /**
318 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
319 * under any possible substitution of the unspecified parameters (if any).
320 * @param pCost the fixed value of pattern parameter Cost, or null if not bound.
321 * @return true if the input is a valid (partial) match of the pattern.
322 *
323 */
324 public boolean hasMatch(final Integer pCost) {
325 return rawHasMatch(new Object[]{pCost});
326 }
327
328 /**
329 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
330 * @param pCost the fixed value of pattern parameter Cost, or null if not bound.
331 * @return the number of pattern matches found.
332 *
333 */
334 public int countMatches(final Integer pCost) {
335 return rawCountMatches(new Object[]{pCost});
336 }
337
338 /**
339 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
340 * Neither determinism nor randomness of selection is guaranteed.
341 * @param pCost the fixed value of pattern parameter Cost, or null if not bound.
342 * @param processor the action that will process the selected match.
343 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
344 *
345 */
346 public boolean forOneArbitraryMatch(final Integer pCost, final Consumer<? super CostMetric.Match> processor) {
347 return rawForOneArbitraryMatch(new Object[]{pCost}, processor);
348 }
349
350 /**
351 * Returns a new (partial) match.
352 * This can be used e.g. to call the matcher with a partial match.
353 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
354 * @param pCost the fixed value of pattern parameter Cost, or null if not bound.
355 * @return the (partial) match object.
356 *
357 */
358 public CostMetric.Match newMatch(final Integer pCost) {
359 return CostMetric.Match.newMatch(pCost);
360 }
361
362 /**
363 * Retrieve the set of values that occur in matches for Cost.
364 * @return the Set of all values or empty set if there are no matches
365 *
366 */
367 protected Stream<Integer> rawStreamAllValuesOfCost(final Object[] parameters) {
368 return rawStreamAllValues(POSITION_COST, parameters).map(Integer.class::cast);
369 }
370
371 /**
372 * Retrieve the set of values that occur in matches for Cost.
373 * @return the Set of all values or empty set if there are no matches
374 *
375 */
376 public Set<Integer> getAllValuesOfCost() {
377 return rawStreamAllValuesOfCost(emptyArray()).collect(Collectors.toSet());
378 }
379
380 /**
381 * Retrieve the set of values that occur in matches for Cost.
382 * @return the Set of all values or empty set if there are no matches
383 *
384 */
385 public Stream<Integer> streamAllValuesOfCost() {
386 return rawStreamAllValuesOfCost(emptyArray());
387 }
388
389 @Override
390 protected CostMetric.Match tupleToMatch(final Tuple t) {
391 try {
392 return CostMetric.Match.newMatch((Integer) t.get(POSITION_COST));
393 } catch(ClassCastException e) {
394 LOGGER.error("Element(s) in tuple not properly typed!",e);
395 return null;
396 }
397 }
398
399 @Override
400 protected CostMetric.Match arrayToMatch(final Object[] match) {
401 try {
402 return CostMetric.Match.newMatch((Integer) match[POSITION_COST]);
403 } catch(ClassCastException e) {
404 LOGGER.error("Element(s) in array not properly typed!",e);
405 return null;
406 }
407 }
408
409 @Override
410 protected CostMetric.Match arrayToMatchMutable(final Object[] match) {
411 try {
412 return CostMetric.Match.newMutableMatch((Integer) match[POSITION_COST]);
413 } catch(ClassCastException e) {
414 LOGGER.error("Element(s) in array not properly typed!",e);
415 return null;
416 }
417 }
418
419 /**
420 * @return the singleton instance of the query specification of this pattern
421 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
422 *
423 */
424 public static IQuerySpecification<CostMetric.Matcher> querySpecification() {
425 return CostMetric.instance();
426 }
427 }
428
429 private CostMetric() {
430 super(GeneratedPQuery.INSTANCE);
431 }
432
433 /**
434 * @return the singleton instance of the query specification
435 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
436 *
437 */
438 public static CostMetric instance() {
439 try{
440 return LazyHolder.INSTANCE;
441 } catch (ExceptionInInitializerError err) {
442 throw processInitializerError(err);
443 }
444 }
445
446 @Override
447 protected CostMetric.Matcher instantiate(final ViatraQueryEngine engine) {
448 return CostMetric.Matcher.on(engine);
449 }
450
451 @Override
452 public CostMetric.Matcher instantiate() {
453 return CostMetric.Matcher.create();
454 }
455
456 @Override
457 public CostMetric.Match newEmptyMatch() {
458 return CostMetric.Match.newEmptyMatch();
459 }
460
461 @Override
462 public CostMetric.Match newMatch(final Object... parameters) {
463 return CostMetric.Match.newMatch((java.lang.Integer) parameters[0]);
464 }
465
466 /**
467 * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.CostMetric (visibility: PUBLIC, simpleName: CostMetric, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.CostMetric, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)} to be created
468 * <b>not</b> at the class load time of the outer class,
469 * but rather at the first call to {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.CostMetric (visibility: PUBLIC, simpleName: CostMetric, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.CostMetric, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}.
470 *
471 * <p> This workaround is required e.g. to support recursion.
472 *
473 */
474 private static class LazyHolder {
475 private static final CostMetric INSTANCE = new CostMetric();
476
477 /**
478 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
479 * This initialization order is required to support indirect recursion.
480 *
481 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
482 *
483 */
484 private static final Object STATIC_INITIALIZER = ensureInitialized();
485
486 public static Object ensureInitialized() {
487 INSTANCE.ensureInitializedInternal();
488 return null;
489 }
490 }
491
492 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
493 private static final CostMetric.GeneratedPQuery INSTANCE = new GeneratedPQuery();
494
495 private final PParameter parameter_Cost = new PParameter("Cost", "java.lang.Integer", new JavaTransitiveInstancesKey(java.lang.Integer.class), PParameterDirection.INOUT);
496
497 private final List<PParameter> parameters = Arrays.asList(parameter_Cost);
498
499 private GeneratedPQuery() {
500 super(PVisibility.PUBLIC);
501 }
502
503 @Override
504 public String getFullyQualifiedName() {
505 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.costMetric";
506 }
507
508 @Override
509 public List<String> getParameterNames() {
510 return Arrays.asList("Cost");
511 }
512
513 @Override
514 public List<PParameter> getParameters() {
515 return parameters;
516 }
517
518 @Override
519 public Set<PBody> doGetContainedBodies() {
520 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
521 Set<PBody> bodies = new LinkedHashSet<>();
522 {
523 PBody body = new PBody(this);
524 PVariable var_Cost = body.getOrCreateVariableByName("Cost");
525 PVariable var___0_ = body.getOrCreateVariableByName("_<0>");
526 PVariable var___1_ = body.getOrCreateVariableByName("_<1>");
527 new TypeFilterConstraint(body, Tuples.flatTupleOf(var_Cost), new JavaTransitiveInstancesKey(java.lang.Integer.class));
528 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
529 new ExportedParameter(body, var_Cost, parameter_Cost)
530 ));
531 // Cost == sum find cpsCost(_, #_)
532 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
533 new AggregatorConstraint(new sum().getAggregatorLogic(Integer.class), body, Tuples.flatTupleOf(var___0_, var___1_), CpsCost.instance().getInternalQueryRepresentation(), var__virtual_0_, 1);
534 new Equality(body, var_Cost, var__virtual_0_);
535 bodies.add(body);
536 }
537 return bodies;
538 }
539 }
540}
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsApplications.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsApplications.java
new file mode 100644
index 00000000..2c20b38e
--- /dev/null
+++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsApplications.java
@@ -0,0 +1,705 @@
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.CyberPhysicalSystem;
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.annotations.PAnnotation;
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.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 * {@literal @}QueryBasedFeature(feature = "applications")
49 * pattern cpsApplications(Cps : CyberPhysicalSystem, AppInstance : ApplicationInstance) {
50 * CyberPhysicalSystem.applicationTypes.instances(Cps, AppInstance);
51 * }
52 * </pre></code>
53 *
54 * @see Matcher
55 * @see Match
56 *
57 */
58@SuppressWarnings("all")
59public final class CpsApplications extends BaseGeneratedEMFQuerySpecification<CpsApplications.Matcher> {
60 /**
61 * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.cpsApplications 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 CyberPhysicalSystem fCps;
74
75 private ApplicationInstance fAppInstance;
76
77 private static List<String> parameterNames = makeImmutableList("Cps", "AppInstance");
78
79 private Match(final CyberPhysicalSystem pCps, final ApplicationInstance pAppInstance) {
80 this.fCps = pCps;
81 this.fAppInstance = pAppInstance;
82 }
83
84 @Override
85 public Object get(final String parameterName) {
86 if ("Cps".equals(parameterName)) return this.fCps;
87 if ("AppInstance".equals(parameterName)) return this.fAppInstance;
88 return null;
89 }
90
91 public CyberPhysicalSystem getCps() {
92 return this.fCps;
93 }
94
95 public ApplicationInstance getAppInstance() {
96 return this.fAppInstance;
97 }
98
99 @Override
100 public boolean set(final String parameterName, final Object newValue) {
101 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
102 if ("Cps".equals(parameterName) ) {
103 this.fCps = (CyberPhysicalSystem) newValue;
104 return true;
105 }
106 if ("AppInstance".equals(parameterName) ) {
107 this.fAppInstance = (ApplicationInstance) newValue;
108 return true;
109 }
110 return false;
111 }
112
113 public void setCps(final CyberPhysicalSystem pCps) {
114 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
115 this.fCps = pCps;
116 }
117
118 public void setAppInstance(final ApplicationInstance pAppInstance) {
119 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
120 this.fAppInstance = pAppInstance;
121 }
122
123 @Override
124 public String patternName() {
125 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.cpsApplications";
126 }
127
128 @Override
129 public List<String> parameterNames() {
130 return CpsApplications.Match.parameterNames;
131 }
132
133 @Override
134 public Object[] toArray() {
135 return new Object[]{fCps, fAppInstance};
136 }
137
138 @Override
139 public CpsApplications.Match toImmutable() {
140 return isMutable() ? newMatch(fCps, fAppInstance) : this;
141 }
142
143 @Override
144 public String prettyPrint() {
145 StringBuilder result = new StringBuilder();
146 result.append("\"Cps\"=" + prettyPrintValue(fCps) + ", ");
147 result.append("\"AppInstance\"=" + prettyPrintValue(fAppInstance));
148 return result.toString();
149 }
150
151 @Override
152 public int hashCode() {
153 return Objects.hash(fCps, fAppInstance);
154 }
155
156 @Override
157 public boolean equals(final Object obj) {
158 if (this == obj)
159 return true;
160 if (obj == null) {
161 return false;
162 }
163 if ((obj instanceof CpsApplications.Match)) {
164 CpsApplications.Match other = (CpsApplications.Match) obj;
165 return Objects.equals(fCps, other.fCps) && Objects.equals(fAppInstance, other.fAppInstance);
166 } else {
167 // this should be infrequent
168 if (!(obj instanceof IPatternMatch)) {
169 return false;
170 }
171 IPatternMatch otherSig = (IPatternMatch) obj;
172 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
173 }
174 }
175
176 @Override
177 public CpsApplications specification() {
178 return CpsApplications.instance();
179 }
180
181 /**
182 * Returns an empty, mutable match.
183 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
184 *
185 * @return the empty match.
186 *
187 */
188 public static CpsApplications.Match newEmptyMatch() {
189 return new Mutable(null, null);
190 }
191
192 /**
193 * Returns a mutable (partial) match.
194 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
195 *
196 * @param pCps the fixed value of pattern parameter Cps, or null if not bound.
197 * @param pAppInstance the fixed value of pattern parameter AppInstance, or null if not bound.
198 * @return the new, mutable (partial) match object.
199 *
200 */
201 public static CpsApplications.Match newMutableMatch(final CyberPhysicalSystem pCps, final ApplicationInstance pAppInstance) {
202 return new Mutable(pCps, pAppInstance);
203 }
204
205 /**
206 * Returns a new (partial) match.
207 * This can be used e.g. to call the matcher with a partial match.
208 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
209 * @param pCps the fixed value of pattern parameter Cps, or null if not bound.
210 * @param pAppInstance the fixed value of pattern parameter AppInstance, or null if not bound.
211 * @return the (partial) match object.
212 *
213 */
214 public static CpsApplications.Match newMatch(final CyberPhysicalSystem pCps, final ApplicationInstance pAppInstance) {
215 return new Immutable(pCps, pAppInstance);
216 }
217
218 private static final class Mutable extends CpsApplications.Match {
219 Mutable(final CyberPhysicalSystem pCps, final ApplicationInstance pAppInstance) {
220 super(pCps, pAppInstance);
221 }
222
223 @Override
224 public boolean isMutable() {
225 return true;
226 }
227 }
228
229 private static final class Immutable extends CpsApplications.Match {
230 Immutable(final CyberPhysicalSystem pCps, final ApplicationInstance pAppInstance) {
231 super(pCps, pAppInstance);
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.cpsApplications 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 @}QueryBasedFeature(feature = "applications")
253 * pattern cpsApplications(Cps : CyberPhysicalSystem, AppInstance : ApplicationInstance) {
254 * CyberPhysicalSystem.applicationTypes.instances(Cps, AppInstance);
255 * }
256 * </pre></code>
257 *
258 * @see Match
259 * @see CpsApplications
260 *
261 */
262 public static class Matcher extends BaseMatcher<CpsApplications.Match> {
263 /**
264 * Initializes the pattern matcher within an existing VIATRA Query engine.
265 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
266 *
267 * @param engine the existing VIATRA Query engine in which this matcher will be created.
268 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
269 *
270 */
271 public static CpsApplications.Matcher on(final ViatraQueryEngine engine) {
272 // check if matcher already exists
273 Matcher matcher = engine.getExistingMatcher(querySpecification());
274 if (matcher == null) {
275 matcher = (Matcher)engine.getMatcher(querySpecification());
276 }
277 return matcher;
278 }
279
280 /**
281 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
282 * @return an initialized matcher
283 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
284 *
285 */
286 public static CpsApplications.Matcher create() {
287 return new Matcher();
288 }
289
290 private static final int POSITION_CPS = 0;
291
292 private static final int POSITION_APPINSTANCE = 1;
293
294 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(CpsApplications.Matcher.class);
295
296 /**
297 * Initializes the pattern matcher within an existing VIATRA Query engine.
298 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
299 *
300 * @param engine the existing VIATRA Query engine in which this matcher will be created.
301 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
302 *
303 */
304 private Matcher() {
305 super(querySpecification());
306 }
307
308 /**
309 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
310 * @param pCps the fixed value of pattern parameter Cps, or null if not bound.
311 * @param pAppInstance the fixed value of pattern parameter AppInstance, or null if not bound.
312 * @return matches represented as a Match object.
313 *
314 */
315 public Collection<CpsApplications.Match> getAllMatches(final CyberPhysicalSystem pCps, final ApplicationInstance pAppInstance) {
316 return rawStreamAllMatches(new Object[]{pCps, pAppInstance}).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 pCps the fixed value of pattern parameter Cps, or null if not bound.
326 * @param pAppInstance the fixed value of pattern parameter AppInstance, or null if not bound.
327 * @return a stream of matches represented as a Match object.
328 *
329 */
330 public Stream<CpsApplications.Match> streamAllMatches(final CyberPhysicalSystem pCps, final ApplicationInstance pAppInstance) {
331 return rawStreamAllMatches(new Object[]{pCps, pAppInstance});
332 }
333
334 /**
335 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
336 * Neither determinism nor randomness of selection is guaranteed.
337 * @param pCps the fixed value of pattern parameter Cps, or null if not bound.
338 * @param pAppInstance the fixed value of pattern parameter AppInstance, or null if not bound.
339 * @return a match represented as a Match object, or null if no match is found.
340 *
341 */
342 public Optional<CpsApplications.Match> getOneArbitraryMatch(final CyberPhysicalSystem pCps, final ApplicationInstance pAppInstance) {
343 return rawGetOneArbitraryMatch(new Object[]{pCps, pAppInstance});
344 }
345
346 /**
347 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
348 * under any possible substitution of the unspecified parameters (if any).
349 * @param pCps the fixed value of pattern parameter Cps, or null if not bound.
350 * @param pAppInstance the fixed value of pattern parameter AppInstance, or null if not bound.
351 * @return true if the input is a valid (partial) match of the pattern.
352 *
353 */
354 public boolean hasMatch(final CyberPhysicalSystem pCps, final ApplicationInstance pAppInstance) {
355 return rawHasMatch(new Object[]{pCps, pAppInstance});
356 }
357
358 /**
359 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
360 * @param pCps the fixed value of pattern parameter Cps, or null if not bound.
361 * @param pAppInstance the fixed value of pattern parameter AppInstance, or null if not bound.
362 * @return the number of pattern matches found.
363 *
364 */
365 public int countMatches(final CyberPhysicalSystem pCps, final ApplicationInstance pAppInstance) {
366 return rawCountMatches(new Object[]{pCps, pAppInstance});
367 }
368
369 /**
370 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
371 * Neither determinism nor randomness of selection is guaranteed.
372 * @param pCps the fixed value of pattern parameter Cps, or null if not bound.
373 * @param pAppInstance the fixed value of pattern parameter AppInstance, or null if not bound.
374 * @param processor the action that will process the selected match.
375 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
376 *
377 */
378 public boolean forOneArbitraryMatch(final CyberPhysicalSystem pCps, final ApplicationInstance pAppInstance, final Consumer<? super CpsApplications.Match> processor) {
379 return rawForOneArbitraryMatch(new Object[]{pCps, pAppInstance}, processor);
380 }
381
382 /**
383 * Returns a new (partial) match.
384 * This can be used e.g. to call the matcher with a partial match.
385 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
386 * @param pCps the fixed value of pattern parameter Cps, or null if not bound.
387 * @param pAppInstance the fixed value of pattern parameter AppInstance, or null if not bound.
388 * @return the (partial) match object.
389 *
390 */
391 public CpsApplications.Match newMatch(final CyberPhysicalSystem pCps, final ApplicationInstance pAppInstance) {
392 return CpsApplications.Match.newMatch(pCps, pAppInstance);
393 }
394
395 /**
396 * Retrieve the set of values that occur in matches for Cps.
397 * @return the Set of all values or empty set if there are no matches
398 *
399 */
400 protected Stream<CyberPhysicalSystem> rawStreamAllValuesOfCps(final Object[] parameters) {
401 return rawStreamAllValues(POSITION_CPS, parameters).map(CyberPhysicalSystem.class::cast);
402 }
403
404 /**
405 * Retrieve the set of values that occur in matches for Cps.
406 * @return the Set of all values or empty set if there are no matches
407 *
408 */
409 public Set<CyberPhysicalSystem> getAllValuesOfCps() {
410 return rawStreamAllValuesOfCps(emptyArray()).collect(Collectors.toSet());
411 }
412
413 /**
414 * Retrieve the set of values that occur in matches for Cps.
415 * @return the Set of all values or empty set if there are no matches
416 *
417 */
418 public Stream<CyberPhysicalSystem> streamAllValuesOfCps() {
419 return rawStreamAllValuesOfCps(emptyArray());
420 }
421
422 /**
423 * Retrieve the set of values that occur in matches for Cps.
424 * </p>
425 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
426 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
427 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
428 *
429 * @return the Stream of all values or empty set if there are no matches
430 *
431 */
432 public Stream<CyberPhysicalSystem> streamAllValuesOfCps(final CpsApplications.Match partialMatch) {
433 return rawStreamAllValuesOfCps(partialMatch.toArray());
434 }
435
436 /**
437 * Retrieve the set of values that occur in matches for Cps.
438 * </p>
439 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
440 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
441 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
442 *
443 * @return the Stream of all values or empty set if there are no matches
444 *
445 */
446 public Stream<CyberPhysicalSystem> streamAllValuesOfCps(final ApplicationInstance pAppInstance) {
447 return rawStreamAllValuesOfCps(new Object[]{null, pAppInstance});
448 }
449
450 /**
451 * Retrieve the set of values that occur in matches for Cps.
452 * @return the Set of all values or empty set if there are no matches
453 *
454 */
455 public Set<CyberPhysicalSystem> getAllValuesOfCps(final CpsApplications.Match partialMatch) {
456 return rawStreamAllValuesOfCps(partialMatch.toArray()).collect(Collectors.toSet());
457 }
458
459 /**
460 * Retrieve the set of values that occur in matches for Cps.
461 * @return the Set of all values or empty set if there are no matches
462 *
463 */
464 public Set<CyberPhysicalSystem> getAllValuesOfCps(final ApplicationInstance pAppInstance) {
465 return rawStreamAllValuesOfCps(new Object[]{null, pAppInstance}).collect(Collectors.toSet());
466 }
467
468 /**
469 * Retrieve the set of values that occur in matches for AppInstance.
470 * @return the Set of all values or empty set if there are no matches
471 *
472 */
473 protected Stream<ApplicationInstance> rawStreamAllValuesOfAppInstance(final Object[] parameters) {
474 return rawStreamAllValues(POSITION_APPINSTANCE, parameters).map(ApplicationInstance.class::cast);
475 }
476
477 /**
478 * Retrieve the set of values that occur in matches for AppInstance.
479 * @return the Set of all values or empty set if there are no matches
480 *
481 */
482 public Set<ApplicationInstance> getAllValuesOfAppInstance() {
483 return rawStreamAllValuesOfAppInstance(emptyArray()).collect(Collectors.toSet());
484 }
485
486 /**
487 * Retrieve the set of values that occur in matches for AppInstance.
488 * @return the Set of all values or empty set if there are no matches
489 *
490 */
491 public Stream<ApplicationInstance> streamAllValuesOfAppInstance() {
492 return rawStreamAllValuesOfAppInstance(emptyArray());
493 }
494
495 /**
496 * Retrieve the set of values that occur in matches for AppInstance.
497 * </p>
498 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
499 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
500 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
501 *
502 * @return the Stream of all values or empty set if there are no matches
503 *
504 */
505 public Stream<ApplicationInstance> streamAllValuesOfAppInstance(final CpsApplications.Match partialMatch) {
506 return rawStreamAllValuesOfAppInstance(partialMatch.toArray());
507 }
508
509 /**
510 * Retrieve the set of values that occur in matches for AppInstance.
511 * </p>
512 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
513 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
514 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
515 *
516 * @return the Stream of all values or empty set if there are no matches
517 *
518 */
519 public Stream<ApplicationInstance> streamAllValuesOfAppInstance(final CyberPhysicalSystem pCps) {
520 return rawStreamAllValuesOfAppInstance(new Object[]{pCps, null});
521 }
522
523 /**
524 * Retrieve the set of values that occur in matches for AppInstance.
525 * @return the Set of all values or empty set if there are no matches
526 *
527 */
528 public Set<ApplicationInstance> getAllValuesOfAppInstance(final CpsApplications.Match partialMatch) {
529 return rawStreamAllValuesOfAppInstance(partialMatch.toArray()).collect(Collectors.toSet());
530 }
531
532 /**
533 * Retrieve the set of values that occur in matches for AppInstance.
534 * @return the Set of all values or empty set if there are no matches
535 *
536 */
537 public Set<ApplicationInstance> getAllValuesOfAppInstance(final CyberPhysicalSystem pCps) {
538 return rawStreamAllValuesOfAppInstance(new Object[]{pCps, null}).collect(Collectors.toSet());
539 }
540
541 @Override
542 protected CpsApplications.Match tupleToMatch(final Tuple t) {
543 try {
544 return CpsApplications.Match.newMatch((CyberPhysicalSystem) t.get(POSITION_CPS), (ApplicationInstance) t.get(POSITION_APPINSTANCE));
545 } catch(ClassCastException e) {
546 LOGGER.error("Element(s) in tuple not properly typed!",e);
547 return null;
548 }
549 }
550
551 @Override
552 protected CpsApplications.Match arrayToMatch(final Object[] match) {
553 try {
554 return CpsApplications.Match.newMatch((CyberPhysicalSystem) match[POSITION_CPS], (ApplicationInstance) match[POSITION_APPINSTANCE]);
555 } catch(ClassCastException e) {
556 LOGGER.error("Element(s) in array not properly typed!",e);
557 return null;
558 }
559 }
560
561 @Override
562 protected CpsApplications.Match arrayToMatchMutable(final Object[] match) {
563 try {
564 return CpsApplications.Match.newMutableMatch((CyberPhysicalSystem) match[POSITION_CPS], (ApplicationInstance) match[POSITION_APPINSTANCE]);
565 } catch(ClassCastException e) {
566 LOGGER.error("Element(s) in array not properly typed!",e);
567 return null;
568 }
569 }
570
571 /**
572 * @return the singleton instance of the query specification of this pattern
573 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
574 *
575 */
576 public static IQuerySpecification<CpsApplications.Matcher> querySpecification() {
577 return CpsApplications.instance();
578 }
579 }
580
581 private CpsApplications() {
582 super(GeneratedPQuery.INSTANCE);
583 }
584
585 /**
586 * @return the singleton instance of the query specification
587 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
588 *
589 */
590 public static CpsApplications instance() {
591 try{
592 return LazyHolder.INSTANCE;
593 } catch (ExceptionInInitializerError err) {
594 throw processInitializerError(err);
595 }
596 }
597
598 @Override
599 protected CpsApplications.Matcher instantiate(final ViatraQueryEngine engine) {
600 return CpsApplications.Matcher.on(engine);
601 }
602
603 @Override
604 public CpsApplications.Matcher instantiate() {
605 return CpsApplications.Matcher.create();
606 }
607
608 @Override
609 public CpsApplications.Match newEmptyMatch() {
610 return CpsApplications.Match.newEmptyMatch();
611 }
612
613 @Override
614 public CpsApplications.Match newMatch(final Object... parameters) {
615 return CpsApplications.Match.newMatch((hu.bme.mit.inf.dslreasoner.domains.cps.CyberPhysicalSystem) parameters[0], (hu.bme.mit.inf.dslreasoner.domains.cps.ApplicationInstance) parameters[1]);
616 }
617
618 /**
619 * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.CpsApplications (visibility: PUBLIC, simpleName: CpsApplications, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.CpsApplications, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)} to be created
620 * <b>not</b> at the class load time of the outer class,
621 * but rather at the first call to {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.CpsApplications (visibility: PUBLIC, simpleName: CpsApplications, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.CpsApplications, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}.
622 *
623 * <p> This workaround is required e.g. to support recursion.
624 *
625 */
626 private static class LazyHolder {
627 private static final CpsApplications INSTANCE = new CpsApplications();
628
629 /**
630 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
631 * This initialization order is required to support indirect recursion.
632 *
633 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
634 *
635 */
636 private static final Object STATIC_INITIALIZER = ensureInitialized();
637
638 public static Object ensureInitialized() {
639 INSTANCE.ensureInitializedInternal();
640 return null;
641 }
642 }
643
644 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
645 private static final CpsApplications.GeneratedPQuery INSTANCE = new GeneratedPQuery();
646
647 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);
648
649 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);
650
651 private final List<PParameter> parameters = Arrays.asList(parameter_Cps, parameter_AppInstance);
652
653 private GeneratedPQuery() {
654 super(PVisibility.PUBLIC);
655 }
656
657 @Override
658 public String getFullyQualifiedName() {
659 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.cpsApplications";
660 }
661
662 @Override
663 public List<String> getParameterNames() {
664 return Arrays.asList("Cps","AppInstance");
665 }
666
667 @Override
668 public List<PParameter> getParameters() {
669 return parameters;
670 }
671
672 @Override
673 public Set<PBody> doGetContainedBodies() {
674 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
675 Set<PBody> bodies = new LinkedHashSet<>();
676 {
677 PBody body = new PBody(this);
678 PVariable var_Cps = body.getOrCreateVariableByName("Cps");
679 PVariable var_AppInstance = body.getOrCreateVariableByName("AppInstance");
680 new TypeConstraint(body, Tuples.flatTupleOf(var_Cps), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "CyberPhysicalSystem")));
681 new TypeConstraint(body, Tuples.flatTupleOf(var_AppInstance), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance")));
682 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
683 new ExportedParameter(body, var_Cps, parameter_Cps),
684 new ExportedParameter(body, var_AppInstance, parameter_AppInstance)
685 ));
686 // CyberPhysicalSystem.applicationTypes.instances(Cps, AppInstance)
687 new TypeConstraint(body, Tuples.flatTupleOf(var_Cps), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "CyberPhysicalSystem")));
688 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
689 new TypeConstraint(body, Tuples.flatTupleOf(var_Cps, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "CyberPhysicalSystem", "applicationTypes")));
690 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationType")));
691 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
692 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ApplicationType", "instances")));
693 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance")));
694 new Equality(body, var__virtual_1_, var_AppInstance);
695 bodies.add(body);
696 }
697 {
698 PAnnotation annotation = new PAnnotation("QueryBasedFeature");
699 annotation.addAttribute("feature", "applications");
700 addAnnotation(annotation);
701 }
702 return bodies;
703 }
704 }
705}
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..169a30e5
--- /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,738 @@
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.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 if ("Cps".equals(parameterName)) return this.fCps;
95 if ("Cost".equals(parameterName)) return this.fCost;
96 return null;
97 }
98
99 public CyberPhysicalSystem getCps() {
100 return this.fCps;
101 }
102
103 public Integer getCost() {
104 return this.fCost;
105 }
106
107 @Override
108 public boolean set(final String parameterName, final Object newValue) {
109 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
110 if ("Cps".equals(parameterName) ) {
111 this.fCps = (CyberPhysicalSystem) newValue;
112 return true;
113 }
114 if ("Cost".equals(parameterName) ) {
115 this.fCost = (Integer) newValue;
116 return true;
117 }
118 return false;
119 }
120
121 public void setCps(final CyberPhysicalSystem pCps) {
122 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
123 this.fCps = pCps;
124 }
125
126 public void setCost(final Integer pCost) {
127 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
128 this.fCost = pCost;
129 }
130
131 @Override
132 public String patternName() {
133 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.cpsCost";
134 }
135
136 @Override
137 public List<String> parameterNames() {
138 return CpsCost.Match.parameterNames;
139 }
140
141 @Override
142 public Object[] toArray() {
143 return new Object[]{fCps, fCost};
144 }
145
146 @Override
147 public CpsCost.Match toImmutable() {
148 return isMutable() ? newMatch(fCps, fCost) : this;
149 }
150
151 @Override
152 public String prettyPrint() {
153 StringBuilder result = new StringBuilder();
154 result.append("\"Cps\"=" + prettyPrintValue(fCps) + ", ");
155 result.append("\"Cost\"=" + prettyPrintValue(fCost));
156 return result.toString();
157 }
158
159 @Override
160 public int hashCode() {
161 return Objects.hash(fCps, fCost);
162 }
163
164 @Override
165 public boolean equals(final Object obj) {
166 if (this == obj)
167 return true;
168 if (obj == null) {
169 return false;
170 }
171 if ((obj instanceof CpsCost.Match)) {
172 CpsCost.Match other = (CpsCost.Match) obj;
173 return Objects.equals(fCps, other.fCps) && Objects.equals(fCost, other.fCost);
174 } else {
175 // this should be infrequent
176 if (!(obj instanceof IPatternMatch)) {
177 return false;
178 }
179 IPatternMatch otherSig = (IPatternMatch) obj;
180 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
181 }
182 }
183
184 @Override
185 public CpsCost specification() {
186 return CpsCost.instance();
187 }
188
189 /**
190 * Returns an empty, mutable match.
191 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
192 *
193 * @return the empty match.
194 *
195 */
196 public static CpsCost.Match newEmptyMatch() {
197 return new Mutable(null, null);
198 }
199
200 /**
201 * Returns a mutable (partial) match.
202 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
203 *
204 * @param pCps the fixed value of pattern parameter Cps, or null if not bound.
205 * @param pCost the fixed value of pattern parameter Cost, or null if not bound.
206 * @return the new, mutable (partial) match object.
207 *
208 */
209 public static CpsCost.Match newMutableMatch(final CyberPhysicalSystem pCps, final Integer pCost) {
210 return new Mutable(pCps, pCost);
211 }
212
213 /**
214 * Returns a new (partial) match.
215 * This can be used e.g. to call the matcher with a partial match.
216 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
217 * @param pCps the fixed value of pattern parameter Cps, or null if not bound.
218 * @param pCost the fixed value of pattern parameter Cost, or null if not bound.
219 * @return the (partial) match object.
220 *
221 */
222 public static CpsCost.Match newMatch(final CyberPhysicalSystem pCps, final Integer pCost) {
223 return new Immutable(pCps, pCost);
224 }
225
226 private static final class Mutable extends CpsCost.Match {
227 Mutable(final CyberPhysicalSystem pCps, final Integer pCost) {
228 super(pCps, pCost);
229 }
230
231 @Override
232 public boolean isMutable() {
233 return true;
234 }
235 }
236
237 private static final class Immutable extends CpsCost.Match {
238 Immutable(final CyberPhysicalSystem pCps, final Integer pCost) {
239 super(pCps, pCost);
240 }
241
242 @Override
243 public boolean isMutable() {
244 return false;
245 }
246 }
247 }
248
249 /**
250 * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.cpsCost pattern,
251 * providing pattern-specific query methods.
252 *
253 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
254 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
255 *
256 * <p>Matches of the pattern will be represented as {@link Match}.
257 *
258 * <p>Original source:
259 * <code><pre>
260 * pattern cpsCost(Cps : CyberPhysicalSystem, Cost : java Integer) {
261 * AppCount == count find cpsApplications(Cps, _);
262 * HostCost == sum find hostInstanceCost(Cps, _, #_);
263 * Cost == eval(5 AppCount + HostCost);
264 * }
265 * </pre></code>
266 *
267 * @see Match
268 * @see CpsCost
269 *
270 */
271 public static class Matcher extends BaseMatcher<CpsCost.Match> {
272 /**
273 * Initializes the pattern matcher within an existing VIATRA Query engine.
274 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
275 *
276 * @param engine the existing VIATRA Query engine in which this matcher will be created.
277 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
278 *
279 */
280 public static CpsCost.Matcher on(final ViatraQueryEngine engine) {
281 // check if matcher already exists
282 Matcher matcher = engine.getExistingMatcher(querySpecification());
283 if (matcher == null) {
284 matcher = (Matcher)engine.getMatcher(querySpecification());
285 }
286 return matcher;
287 }
288
289 /**
290 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
291 * @return an initialized matcher
292 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
293 *
294 */
295 public static CpsCost.Matcher create() {
296 return new Matcher();
297 }
298
299 private static final int POSITION_CPS = 0;
300
301 private static final int POSITION_COST = 1;
302
303 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(CpsCost.Matcher.class);
304
305 /**
306 * Initializes the pattern matcher within an existing VIATRA Query engine.
307 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
308 *
309 * @param engine the existing VIATRA Query engine in which this matcher will be created.
310 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
311 *
312 */
313 private Matcher() {
314 super(querySpecification());
315 }
316
317 /**
318 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
319 * @param pCps the fixed value of pattern parameter Cps, or null if not bound.
320 * @param pCost the fixed value of pattern parameter Cost, or null if not bound.
321 * @return matches represented as a Match object.
322 *
323 */
324 public Collection<CpsCost.Match> getAllMatches(final CyberPhysicalSystem pCps, final Integer pCost) {
325 return rawStreamAllMatches(new Object[]{pCps, pCost}).collect(Collectors.toSet());
326 }
327
328 /**
329 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
330 * </p>
331 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
332 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
333 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
334 * @param pCps the fixed value of pattern parameter Cps, or null if not bound.
335 * @param pCost the fixed value of pattern parameter Cost, or null if not bound.
336 * @return a stream of matches represented as a Match object.
337 *
338 */
339 public Stream<CpsCost.Match> streamAllMatches(final CyberPhysicalSystem pCps, final Integer pCost) {
340 return rawStreamAllMatches(new Object[]{pCps, pCost});
341 }
342
343 /**
344 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
345 * Neither determinism nor randomness of selection is guaranteed.
346 * @param pCps the fixed value of pattern parameter Cps, or null if not bound.
347 * @param pCost the fixed value of pattern parameter Cost, or null if not bound.
348 * @return a match represented as a Match object, or null if no match is found.
349 *
350 */
351 public Optional<CpsCost.Match> getOneArbitraryMatch(final CyberPhysicalSystem pCps, final Integer pCost) {
352 return rawGetOneArbitraryMatch(new Object[]{pCps, pCost});
353 }
354
355 /**
356 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
357 * under any possible substitution of the unspecified parameters (if any).
358 * @param pCps the fixed value of pattern parameter Cps, or null if not bound.
359 * @param pCost the fixed value of pattern parameter Cost, or null if not bound.
360 * @return true if the input is a valid (partial) match of the pattern.
361 *
362 */
363 public boolean hasMatch(final CyberPhysicalSystem pCps, final Integer pCost) {
364 return rawHasMatch(new Object[]{pCps, pCost});
365 }
366
367 /**
368 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
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 the number of pattern matches found.
372 *
373 */
374 public int countMatches(final CyberPhysicalSystem pCps, final Integer pCost) {
375 return rawCountMatches(new Object[]{pCps, pCost});
376 }
377
378 /**
379 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
380 * Neither determinism nor randomness of selection is guaranteed.
381 * @param pCps the fixed value of pattern parameter Cps, or null if not bound.
382 * @param pCost the fixed value of pattern parameter Cost, or null if not bound.
383 * @param processor the action that will process the selected match.
384 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
385 *
386 */
387 public boolean forOneArbitraryMatch(final CyberPhysicalSystem pCps, final Integer pCost, final Consumer<? super CpsCost.Match> processor) {
388 return rawForOneArbitraryMatch(new Object[]{pCps, pCost}, processor);
389 }
390
391 /**
392 * Returns a new (partial) match.
393 * This can be used e.g. to call the matcher with a partial match.
394 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
395 * @param pCps the fixed value of pattern parameter Cps, or null if not bound.
396 * @param pCost the fixed value of pattern parameter Cost, or null if not bound.
397 * @return the (partial) match object.
398 *
399 */
400 public CpsCost.Match newMatch(final CyberPhysicalSystem pCps, final Integer pCost) {
401 return CpsCost.Match.newMatch(pCps, pCost);
402 }
403
404 /**
405 * Retrieve the set of values that occur in matches for Cps.
406 * @return the Set of all values or empty set if there are no matches
407 *
408 */
409 protected Stream<CyberPhysicalSystem> rawStreamAllValuesOfCps(final Object[] parameters) {
410 return rawStreamAllValues(POSITION_CPS, parameters).map(CyberPhysicalSystem.class::cast);
411 }
412
413 /**
414 * Retrieve the set of values that occur in matches for Cps.
415 * @return the Set of all values or empty set if there are no matches
416 *
417 */
418 public Set<CyberPhysicalSystem> getAllValuesOfCps() {
419 return rawStreamAllValuesOfCps(emptyArray()).collect(Collectors.toSet());
420 }
421
422 /**
423 * Retrieve the set of values that occur in matches for Cps.
424 * @return the Set of all values or empty set if there are no matches
425 *
426 */
427 public Stream<CyberPhysicalSystem> streamAllValuesOfCps() {
428 return rawStreamAllValuesOfCps(emptyArray());
429 }
430
431 /**
432 * Retrieve the set of values that occur in matches for Cps.
433 * </p>
434 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
435 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
436 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
437 *
438 * @return the Stream of all values or empty set if there are no matches
439 *
440 */
441 public Stream<CyberPhysicalSystem> streamAllValuesOfCps(final CpsCost.Match partialMatch) {
442 return rawStreamAllValuesOfCps(partialMatch.toArray());
443 }
444
445 /**
446 * Retrieve the set of values that occur in matches for Cps.
447 * </p>
448 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
449 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
450 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
451 *
452 * @return the Stream of all values or empty set if there are no matches
453 *
454 */
455 public Stream<CyberPhysicalSystem> streamAllValuesOfCps(final Integer pCost) {
456 return rawStreamAllValuesOfCps(new Object[]{null, pCost});
457 }
458
459 /**
460 * Retrieve the set of values that occur in matches for Cps.
461 * @return the Set of all values or empty set if there are no matches
462 *
463 */
464 public Set<CyberPhysicalSystem> getAllValuesOfCps(final CpsCost.Match partialMatch) {
465 return rawStreamAllValuesOfCps(partialMatch.toArray()).collect(Collectors.toSet());
466 }
467
468 /**
469 * Retrieve the set of values that occur in matches for Cps.
470 * @return the Set of all values or empty set if there are no matches
471 *
472 */
473 public Set<CyberPhysicalSystem> getAllValuesOfCps(final Integer pCost) {
474 return rawStreamAllValuesOfCps(new Object[]{null, pCost}).collect(Collectors.toSet());
475 }
476
477 /**
478 * Retrieve the set of values that occur in matches for Cost.
479 * @return the Set of all values or empty set if there are no matches
480 *
481 */
482 protected Stream<Integer> rawStreamAllValuesOfCost(final Object[] parameters) {
483 return rawStreamAllValues(POSITION_COST, parameters).map(Integer.class::cast);
484 }
485
486 /**
487 * Retrieve the set of values that occur in matches for Cost.
488 * @return the Set of all values or empty set if there are no matches
489 *
490 */
491 public Set<Integer> getAllValuesOfCost() {
492 return rawStreamAllValuesOfCost(emptyArray()).collect(Collectors.toSet());
493 }
494
495 /**
496 * Retrieve the set of values that occur in matches for Cost.
497 * @return the Set of all values or empty set if there are no matches
498 *
499 */
500 public Stream<Integer> streamAllValuesOfCost() {
501 return rawStreamAllValuesOfCost(emptyArray());
502 }
503
504 /**
505 * Retrieve the set of values that occur in matches for Cost.
506 * </p>
507 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
508 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
509 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
510 *
511 * @return the Stream of all values or empty set if there are no matches
512 *
513 */
514 public Stream<Integer> streamAllValuesOfCost(final CpsCost.Match partialMatch) {
515 return rawStreamAllValuesOfCost(partialMatch.toArray());
516 }
517
518 /**
519 * Retrieve the set of values that occur in matches for Cost.
520 * </p>
521 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
522 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
523 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
524 *
525 * @return the Stream of all values or empty set if there are no matches
526 *
527 */
528 public Stream<Integer> streamAllValuesOfCost(final CyberPhysicalSystem pCps) {
529 return rawStreamAllValuesOfCost(new Object[]{pCps, null});
530 }
531
532 /**
533 * Retrieve the set of values that occur in matches for Cost.
534 * @return the Set of all values or empty set if there are no matches
535 *
536 */
537 public Set<Integer> getAllValuesOfCost(final CpsCost.Match partialMatch) {
538 return rawStreamAllValuesOfCost(partialMatch.toArray()).collect(Collectors.toSet());
539 }
540
541 /**
542 * Retrieve the set of values that occur in matches for Cost.
543 * @return the Set of all values or empty set if there are no matches
544 *
545 */
546 public Set<Integer> getAllValuesOfCost(final CyberPhysicalSystem pCps) {
547 return rawStreamAllValuesOfCost(new Object[]{pCps, null}).collect(Collectors.toSet());
548 }
549
550 @Override
551 protected CpsCost.Match tupleToMatch(final Tuple t) {
552 try {
553 return CpsCost.Match.newMatch((CyberPhysicalSystem) t.get(POSITION_CPS), (Integer) t.get(POSITION_COST));
554 } catch(ClassCastException e) {
555 LOGGER.error("Element(s) in tuple not properly typed!",e);
556 return null;
557 }
558 }
559
560 @Override
561 protected CpsCost.Match arrayToMatch(final Object[] match) {
562 try {
563 return CpsCost.Match.newMatch((CyberPhysicalSystem) match[POSITION_CPS], (Integer) match[POSITION_COST]);
564 } catch(ClassCastException e) {
565 LOGGER.error("Element(s) in array not properly typed!",e);
566 return null;
567 }
568 }
569
570 @Override
571 protected CpsCost.Match arrayToMatchMutable(final Object[] match) {
572 try {
573 return CpsCost.Match.newMutableMatch((CyberPhysicalSystem) match[POSITION_CPS], (Integer) match[POSITION_COST]);
574 } catch(ClassCastException e) {
575 LOGGER.error("Element(s) in array not properly typed!",e);
576 return null;
577 }
578 }
579
580 /**
581 * @return the singleton instance of the query specification of this pattern
582 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
583 *
584 */
585 public static IQuerySpecification<CpsCost.Matcher> querySpecification() {
586 return CpsCost.instance();
587 }
588 }
589
590 private CpsCost() {
591 super(GeneratedPQuery.INSTANCE);
592 }
593
594 /**
595 * @return the singleton instance of the query specification
596 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
597 *
598 */
599 public static CpsCost instance() {
600 try{
601 return LazyHolder.INSTANCE;
602 } catch (ExceptionInInitializerError err) {
603 throw processInitializerError(err);
604 }
605 }
606
607 @Override
608 protected CpsCost.Matcher instantiate(final ViatraQueryEngine engine) {
609 return CpsCost.Matcher.on(engine);
610 }
611
612 @Override
613 public CpsCost.Matcher instantiate() {
614 return CpsCost.Matcher.create();
615 }
616
617 @Override
618 public CpsCost.Match newEmptyMatch() {
619 return CpsCost.Match.newEmptyMatch();
620 }
621
622 @Override
623 public CpsCost.Match newMatch(final Object... parameters) {
624 return CpsCost.Match.newMatch((hu.bme.mit.inf.dslreasoner.domains.cps.CyberPhysicalSystem) parameters[0], (java.lang.Integer) parameters[1]);
625 }
626
627 /**
628 * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.CpsCost (visibility: PUBLIC, simpleName: CpsCost, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.CpsCost, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)} to be created
629 * <b>not</b> at the class load time of the outer class,
630 * but rather at the first call to {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.CpsCost (visibility: PUBLIC, simpleName: CpsCost, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.CpsCost, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}.
631 *
632 * <p> This workaround is required e.g. to support recursion.
633 *
634 */
635 private static class LazyHolder {
636 private static final CpsCost INSTANCE = new CpsCost();
637
638 /**
639 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
640 * This initialization order is required to support indirect recursion.
641 *
642 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
643 *
644 */
645 private static final Object STATIC_INITIALIZER = ensureInitialized();
646
647 public static Object ensureInitialized() {
648 INSTANCE.ensureInitializedInternal();
649 return null;
650 }
651 }
652
653 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
654 private static final CpsCost.GeneratedPQuery INSTANCE = new GeneratedPQuery();
655
656 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);
657
658 private final PParameter parameter_Cost = new PParameter("Cost", "java.lang.Integer", new JavaTransitiveInstancesKey(java.lang.Integer.class), PParameterDirection.INOUT);
659
660 private final List<PParameter> parameters = Arrays.asList(parameter_Cps, parameter_Cost);
661
662 private GeneratedPQuery() {
663 super(PVisibility.PUBLIC);
664 }
665
666 @Override
667 public String getFullyQualifiedName() {
668 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.cpsCost";
669 }
670
671 @Override
672 public List<String> getParameterNames() {
673 return Arrays.asList("Cps","Cost");
674 }
675
676 @Override
677 public List<PParameter> getParameters() {
678 return parameters;
679 }
680
681 @Override
682 public Set<PBody> doGetContainedBodies() {
683 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
684 Set<PBody> bodies = new LinkedHashSet<>();
685 {
686 PBody body = new PBody(this);
687 PVariable var_Cps = body.getOrCreateVariableByName("Cps");
688 PVariable var_Cost = body.getOrCreateVariableByName("Cost");
689 PVariable var_AppCount = body.getOrCreateVariableByName("AppCount");
690 PVariable var___0_ = body.getOrCreateVariableByName("_<0>");
691 PVariable var_HostCost = body.getOrCreateVariableByName("HostCost");
692 PVariable var___1_ = body.getOrCreateVariableByName("_<1>");
693 PVariable var___2_ = body.getOrCreateVariableByName("_<2>");
694 new TypeConstraint(body, Tuples.flatTupleOf(var_Cps), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "CyberPhysicalSystem")));
695 new TypeFilterConstraint(body, Tuples.flatTupleOf(var_Cost), new JavaTransitiveInstancesKey(java.lang.Integer.class));
696 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
697 new ExportedParameter(body, var_Cps, parameter_Cps),
698 new ExportedParameter(body, var_Cost, parameter_Cost)
699 ));
700 // AppCount == count find cpsApplications(Cps, _)
701 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
702 new PatternMatchCounter(body, Tuples.flatTupleOf(var_Cps, var___0_), CpsApplications.instance().getInternalQueryRepresentation(), var__virtual_0_);
703 new Equality(body, var_AppCount, var__virtual_0_);
704 // HostCost == sum find hostInstanceCost(Cps, _, #_)
705 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
706 new AggregatorConstraint(new sum().getAggregatorLogic(Integer.class), body, Tuples.flatTupleOf(var_Cps, var___1_, var___2_), HostInstanceCost.instance().getInternalQueryRepresentation(), var__virtual_1_, 2);
707 new Equality(body, var_HostCost, var__virtual_1_);
708 // Cost == eval(5 * AppCount + HostCost)
709 PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}");
710 new ExpressionEvaluation(body, new IExpressionEvaluator() {
711
712 @Override
713 public String getShortDescription() {
714 return "Expression evaluation from pattern cpsCost";
715 }
716
717 @Override
718 public Iterable<String> getInputParameterNames() {
719 return Arrays.asList("AppCount", "HostCost");}
720
721 @Override
722 public Object evaluateExpression(IValueProvider provider) throws Exception {
723 Integer AppCount = (Integer) provider.getValue("AppCount");
724 Integer HostCost = (Integer) provider.getValue("HostCost");
725 return evaluateExpression_1_1(AppCount, HostCost);
726 }
727 }, var__virtual_2_ );
728 new Equality(body, var_Cost, var__virtual_2_);
729 bodies.add(body);
730 }
731 return bodies;
732 }
733 }
734
735 private static int evaluateExpression_1_1(final Integer AppCount, final Integer HostCost) {
736 return ((5 * (AppCount).intValue()) + (HostCost).intValue());
737 }
738}
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsHosts.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsHosts.java
new file mode 100644
index 00000000..e1abf758
--- /dev/null
+++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsHosts.java
@@ -0,0 +1,705 @@
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.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.annotations.PAnnotation;
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.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 * {@literal @}QueryBasedFeature(feature = "hosts")
49 * pattern cpsHosts(Cps : CyberPhysicalSystem, HostInstance : HostInstance) {
50 * CyberPhysicalSystem.hostTypes.instances(Cps, HostInstance);
51 * }
52 * </pre></code>
53 *
54 * @see Matcher
55 * @see Match
56 *
57 */
58@SuppressWarnings("all")
59public final class CpsHosts extends BaseGeneratedEMFQuerySpecification<CpsHosts.Matcher> {
60 /**
61 * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.cpsHosts 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 CyberPhysicalSystem fCps;
74
75 private HostInstance fHostInstance;
76
77 private static List<String> parameterNames = makeImmutableList("Cps", "HostInstance");
78
79 private Match(final CyberPhysicalSystem pCps, final HostInstance pHostInstance) {
80 this.fCps = pCps;
81 this.fHostInstance = pHostInstance;
82 }
83
84 @Override
85 public Object get(final String parameterName) {
86 if ("Cps".equals(parameterName)) return this.fCps;
87 if ("HostInstance".equals(parameterName)) return this.fHostInstance;
88 return null;
89 }
90
91 public CyberPhysicalSystem getCps() {
92 return this.fCps;
93 }
94
95 public HostInstance getHostInstance() {
96 return this.fHostInstance;
97 }
98
99 @Override
100 public boolean set(final String parameterName, final Object newValue) {
101 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
102 if ("Cps".equals(parameterName) ) {
103 this.fCps = (CyberPhysicalSystem) newValue;
104 return true;
105 }
106 if ("HostInstance".equals(parameterName) ) {
107 this.fHostInstance = (HostInstance) newValue;
108 return true;
109 }
110 return false;
111 }
112
113 public void setCps(final CyberPhysicalSystem pCps) {
114 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
115 this.fCps = pCps;
116 }
117
118 public void setHostInstance(final HostInstance pHostInstance) {
119 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
120 this.fHostInstance = pHostInstance;
121 }
122
123 @Override
124 public String patternName() {
125 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.cpsHosts";
126 }
127
128 @Override
129 public List<String> parameterNames() {
130 return CpsHosts.Match.parameterNames;
131 }
132
133 @Override
134 public Object[] toArray() {
135 return new Object[]{fCps, fHostInstance};
136 }
137
138 @Override
139 public CpsHosts.Match toImmutable() {
140 return isMutable() ? newMatch(fCps, fHostInstance) : this;
141 }
142
143 @Override
144 public String prettyPrint() {
145 StringBuilder result = new StringBuilder();
146 result.append("\"Cps\"=" + prettyPrintValue(fCps) + ", ");
147 result.append("\"HostInstance\"=" + prettyPrintValue(fHostInstance));
148 return result.toString();
149 }
150
151 @Override
152 public int hashCode() {
153 return Objects.hash(fCps, fHostInstance);
154 }
155
156 @Override
157 public boolean equals(final Object obj) {
158 if (this == obj)
159 return true;
160 if (obj == null) {
161 return false;
162 }
163 if ((obj instanceof CpsHosts.Match)) {
164 CpsHosts.Match other = (CpsHosts.Match) obj;
165 return Objects.equals(fCps, other.fCps) && Objects.equals(fHostInstance, other.fHostInstance);
166 } else {
167 // this should be infrequent
168 if (!(obj instanceof IPatternMatch)) {
169 return false;
170 }
171 IPatternMatch otherSig = (IPatternMatch) obj;
172 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
173 }
174 }
175
176 @Override
177 public CpsHosts specification() {
178 return CpsHosts.instance();
179 }
180
181 /**
182 * Returns an empty, mutable match.
183 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
184 *
185 * @return the empty match.
186 *
187 */
188 public static CpsHosts.Match newEmptyMatch() {
189 return new Mutable(null, null);
190 }
191
192 /**
193 * Returns a mutable (partial) match.
194 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
195 *
196 * @param pCps the fixed value of pattern parameter Cps, or null if not bound.
197 * @param pHostInstance the fixed value of pattern parameter HostInstance, or null if not bound.
198 * @return the new, mutable (partial) match object.
199 *
200 */
201 public static CpsHosts.Match newMutableMatch(final CyberPhysicalSystem pCps, final HostInstance pHostInstance) {
202 return new Mutable(pCps, pHostInstance);
203 }
204
205 /**
206 * Returns a new (partial) match.
207 * This can be used e.g. to call the matcher with a partial match.
208 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
209 * @param pCps the fixed value of pattern parameter Cps, or null if not bound.
210 * @param pHostInstance the fixed value of pattern parameter HostInstance, or null if not bound.
211 * @return the (partial) match object.
212 *
213 */
214 public static CpsHosts.Match newMatch(final CyberPhysicalSystem pCps, final HostInstance pHostInstance) {
215 return new Immutable(pCps, pHostInstance);
216 }
217
218 private static final class Mutable extends CpsHosts.Match {
219 Mutable(final CyberPhysicalSystem pCps, final HostInstance pHostInstance) {
220 super(pCps, pHostInstance);
221 }
222
223 @Override
224 public boolean isMutable() {
225 return true;
226 }
227 }
228
229 private static final class Immutable extends CpsHosts.Match {
230 Immutable(final CyberPhysicalSystem pCps, final HostInstance pHostInstance) {
231 super(pCps, pHostInstance);
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.cpsHosts 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 @}QueryBasedFeature(feature = "hosts")
253 * pattern cpsHosts(Cps : CyberPhysicalSystem, HostInstance : HostInstance) {
254 * CyberPhysicalSystem.hostTypes.instances(Cps, HostInstance);
255 * }
256 * </pre></code>
257 *
258 * @see Match
259 * @see CpsHosts
260 *
261 */
262 public static class Matcher extends BaseMatcher<CpsHosts.Match> {
263 /**
264 * Initializes the pattern matcher within an existing VIATRA Query engine.
265 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
266 *
267 * @param engine the existing VIATRA Query engine in which this matcher will be created.
268 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
269 *
270 */
271 public static CpsHosts.Matcher on(final ViatraQueryEngine engine) {
272 // check if matcher already exists
273 Matcher matcher = engine.getExistingMatcher(querySpecification());
274 if (matcher == null) {
275 matcher = (Matcher)engine.getMatcher(querySpecification());
276 }
277 return matcher;
278 }
279
280 /**
281 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
282 * @return an initialized matcher
283 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
284 *
285 */
286 public static CpsHosts.Matcher create() {
287 return new Matcher();
288 }
289
290 private static final int POSITION_CPS = 0;
291
292 private static final int POSITION_HOSTINSTANCE = 1;
293
294 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(CpsHosts.Matcher.class);
295
296 /**
297 * Initializes the pattern matcher within an existing VIATRA Query engine.
298 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
299 *
300 * @param engine the existing VIATRA Query engine in which this matcher will be created.
301 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
302 *
303 */
304 private Matcher() {
305 super(querySpecification());
306 }
307
308 /**
309 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
310 * @param pCps the fixed value of pattern parameter Cps, or null if not bound.
311 * @param pHostInstance the fixed value of pattern parameter HostInstance, or null if not bound.
312 * @return matches represented as a Match object.
313 *
314 */
315 public Collection<CpsHosts.Match> getAllMatches(final CyberPhysicalSystem pCps, final HostInstance pHostInstance) {
316 return rawStreamAllMatches(new Object[]{pCps, pHostInstance}).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 pCps the fixed value of pattern parameter Cps, or null if not bound.
326 * @param pHostInstance the fixed value of pattern parameter HostInstance, or null if not bound.
327 * @return a stream of matches represented as a Match object.
328 *
329 */
330 public Stream<CpsHosts.Match> streamAllMatches(final CyberPhysicalSystem pCps, final HostInstance pHostInstance) {
331 return rawStreamAllMatches(new Object[]{pCps, pHostInstance});
332 }
333
334 /**
335 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
336 * Neither determinism nor randomness of selection is guaranteed.
337 * @param pCps the fixed value of pattern parameter Cps, or null if not bound.
338 * @param pHostInstance the fixed value of pattern parameter HostInstance, or null if not bound.
339 * @return a match represented as a Match object, or null if no match is found.
340 *
341 */
342 public Optional<CpsHosts.Match> getOneArbitraryMatch(final CyberPhysicalSystem pCps, final HostInstance pHostInstance) {
343 return rawGetOneArbitraryMatch(new Object[]{pCps, pHostInstance});
344 }
345
346 /**
347 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
348 * under any possible substitution of the unspecified parameters (if any).
349 * @param pCps the fixed value of pattern parameter Cps, or null if not bound.
350 * @param pHostInstance the fixed value of pattern parameter HostInstance, or null if not bound.
351 * @return true if the input is a valid (partial) match of the pattern.
352 *
353 */
354 public boolean hasMatch(final CyberPhysicalSystem pCps, final HostInstance pHostInstance) {
355 return rawHasMatch(new Object[]{pCps, pHostInstance});
356 }
357
358 /**
359 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
360 * @param pCps the fixed value of pattern parameter Cps, or null if not bound.
361 * @param pHostInstance the fixed value of pattern parameter HostInstance, or null if not bound.
362 * @return the number of pattern matches found.
363 *
364 */
365 public int countMatches(final CyberPhysicalSystem pCps, final HostInstance pHostInstance) {
366 return rawCountMatches(new Object[]{pCps, pHostInstance});
367 }
368
369 /**
370 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
371 * Neither determinism nor randomness of selection is guaranteed.
372 * @param pCps the fixed value of pattern parameter Cps, or null if not bound.
373 * @param pHostInstance the fixed value of pattern parameter HostInstance, or null if not bound.
374 * @param processor the action that will process the selected match.
375 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
376 *
377 */
378 public boolean forOneArbitraryMatch(final CyberPhysicalSystem pCps, final HostInstance pHostInstance, final Consumer<? super CpsHosts.Match> processor) {
379 return rawForOneArbitraryMatch(new Object[]{pCps, pHostInstance}, processor);
380 }
381
382 /**
383 * Returns a new (partial) match.
384 * This can be used e.g. to call the matcher with a partial match.
385 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
386 * @param pCps the fixed value of pattern parameter Cps, or null if not bound.
387 * @param pHostInstance the fixed value of pattern parameter HostInstance, or null if not bound.
388 * @return the (partial) match object.
389 *
390 */
391 public CpsHosts.Match newMatch(final CyberPhysicalSystem pCps, final HostInstance pHostInstance) {
392 return CpsHosts.Match.newMatch(pCps, pHostInstance);
393 }
394
395 /**
396 * Retrieve the set of values that occur in matches for Cps.
397 * @return the Set of all values or empty set if there are no matches
398 *
399 */
400 protected Stream<CyberPhysicalSystem> rawStreamAllValuesOfCps(final Object[] parameters) {
401 return rawStreamAllValues(POSITION_CPS, parameters).map(CyberPhysicalSystem.class::cast);
402 }
403
404 /**
405 * Retrieve the set of values that occur in matches for Cps.
406 * @return the Set of all values or empty set if there are no matches
407 *
408 */
409 public Set<CyberPhysicalSystem> getAllValuesOfCps() {
410 return rawStreamAllValuesOfCps(emptyArray()).collect(Collectors.toSet());
411 }
412
413 /**
414 * Retrieve the set of values that occur in matches for Cps.
415 * @return the Set of all values or empty set if there are no matches
416 *
417 */
418 public Stream<CyberPhysicalSystem> streamAllValuesOfCps() {
419 return rawStreamAllValuesOfCps(emptyArray());
420 }
421
422 /**
423 * Retrieve the set of values that occur in matches for Cps.
424 * </p>
425 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
426 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
427 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
428 *
429 * @return the Stream of all values or empty set if there are no matches
430 *
431 */
432 public Stream<CyberPhysicalSystem> streamAllValuesOfCps(final CpsHosts.Match partialMatch) {
433 return rawStreamAllValuesOfCps(partialMatch.toArray());
434 }
435
436 /**
437 * Retrieve the set of values that occur in matches for Cps.
438 * </p>
439 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
440 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
441 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
442 *
443 * @return the Stream of all values or empty set if there are no matches
444 *
445 */
446 public Stream<CyberPhysicalSystem> streamAllValuesOfCps(final HostInstance pHostInstance) {
447 return rawStreamAllValuesOfCps(new Object[]{null, pHostInstance});
448 }
449
450 /**
451 * Retrieve the set of values that occur in matches for Cps.
452 * @return the Set of all values or empty set if there are no matches
453 *
454 */
455 public Set<CyberPhysicalSystem> getAllValuesOfCps(final CpsHosts.Match partialMatch) {
456 return rawStreamAllValuesOfCps(partialMatch.toArray()).collect(Collectors.toSet());
457 }
458
459 /**
460 * Retrieve the set of values that occur in matches for Cps.
461 * @return the Set of all values or empty set if there are no matches
462 *
463 */
464 public Set<CyberPhysicalSystem> getAllValuesOfCps(final HostInstance pHostInstance) {
465 return rawStreamAllValuesOfCps(new Object[]{null, pHostInstance}).collect(Collectors.toSet());
466 }
467
468 /**
469 * Retrieve the set of values that occur in matches for HostInstance.
470 * @return the Set of all values or empty set if there are no matches
471 *
472 */
473 protected Stream<HostInstance> rawStreamAllValuesOfHostInstance(final Object[] parameters) {
474 return rawStreamAllValues(POSITION_HOSTINSTANCE, parameters).map(HostInstance.class::cast);
475 }
476
477 /**
478 * Retrieve the set of values that occur in matches for HostInstance.
479 * @return the Set of all values or empty set if there are no matches
480 *
481 */
482 public Set<HostInstance> getAllValuesOfHostInstance() {
483 return rawStreamAllValuesOfHostInstance(emptyArray()).collect(Collectors.toSet());
484 }
485
486 /**
487 * Retrieve the set of values that occur in matches for HostInstance.
488 * @return the Set of all values or empty set if there are no matches
489 *
490 */
491 public Stream<HostInstance> streamAllValuesOfHostInstance() {
492 return rawStreamAllValuesOfHostInstance(emptyArray());
493 }
494
495 /**
496 * Retrieve the set of values that occur in matches for HostInstance.
497 * </p>
498 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
499 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
500 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
501 *
502 * @return the Stream of all values or empty set if there are no matches
503 *
504 */
505 public Stream<HostInstance> streamAllValuesOfHostInstance(final CpsHosts.Match partialMatch) {
506 return rawStreamAllValuesOfHostInstance(partialMatch.toArray());
507 }
508
509 /**
510 * Retrieve the set of values that occur in matches for HostInstance.
511 * </p>
512 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
513 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
514 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
515 *
516 * @return the Stream of all values or empty set if there are no matches
517 *
518 */
519 public Stream<HostInstance> streamAllValuesOfHostInstance(final CyberPhysicalSystem pCps) {
520 return rawStreamAllValuesOfHostInstance(new Object[]{pCps, null});
521 }
522
523 /**
524 * Retrieve the set of values that occur in matches for HostInstance.
525 * @return the Set of all values or empty set if there are no matches
526 *
527 */
528 public Set<HostInstance> getAllValuesOfHostInstance(final CpsHosts.Match partialMatch) {
529 return rawStreamAllValuesOfHostInstance(partialMatch.toArray()).collect(Collectors.toSet());
530 }
531
532 /**
533 * Retrieve the set of values that occur in matches for HostInstance.
534 * @return the Set of all values or empty set if there are no matches
535 *
536 */
537 public Set<HostInstance> getAllValuesOfHostInstance(final CyberPhysicalSystem pCps) {
538 return rawStreamAllValuesOfHostInstance(new Object[]{pCps, null}).collect(Collectors.toSet());
539 }
540
541 @Override
542 protected CpsHosts.Match tupleToMatch(final Tuple t) {
543 try {
544 return CpsHosts.Match.newMatch((CyberPhysicalSystem) t.get(POSITION_CPS), (HostInstance) t.get(POSITION_HOSTINSTANCE));
545 } catch(ClassCastException e) {
546 LOGGER.error("Element(s) in tuple not properly typed!",e);
547 return null;
548 }
549 }
550
551 @Override
552 protected CpsHosts.Match arrayToMatch(final Object[] match) {
553 try {
554 return CpsHosts.Match.newMatch((CyberPhysicalSystem) match[POSITION_CPS], (HostInstance) match[POSITION_HOSTINSTANCE]);
555 } catch(ClassCastException e) {
556 LOGGER.error("Element(s) in array not properly typed!",e);
557 return null;
558 }
559 }
560
561 @Override
562 protected CpsHosts.Match arrayToMatchMutable(final Object[] match) {
563 try {
564 return CpsHosts.Match.newMutableMatch((CyberPhysicalSystem) match[POSITION_CPS], (HostInstance) match[POSITION_HOSTINSTANCE]);
565 } catch(ClassCastException e) {
566 LOGGER.error("Element(s) in array not properly typed!",e);
567 return null;
568 }
569 }
570
571 /**
572 * @return the singleton instance of the query specification of this pattern
573 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
574 *
575 */
576 public static IQuerySpecification<CpsHosts.Matcher> querySpecification() {
577 return CpsHosts.instance();
578 }
579 }
580
581 private CpsHosts() {
582 super(GeneratedPQuery.INSTANCE);
583 }
584
585 /**
586 * @return the singleton instance of the query specification
587 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
588 *
589 */
590 public static CpsHosts instance() {
591 try{
592 return LazyHolder.INSTANCE;
593 } catch (ExceptionInInitializerError err) {
594 throw processInitializerError(err);
595 }
596 }
597
598 @Override
599 protected CpsHosts.Matcher instantiate(final ViatraQueryEngine engine) {
600 return CpsHosts.Matcher.on(engine);
601 }
602
603 @Override
604 public CpsHosts.Matcher instantiate() {
605 return CpsHosts.Matcher.create();
606 }
607
608 @Override
609 public CpsHosts.Match newEmptyMatch() {
610 return CpsHosts.Match.newEmptyMatch();
611 }
612
613 @Override
614 public CpsHosts.Match newMatch(final Object... parameters) {
615 return CpsHosts.Match.newMatch((hu.bme.mit.inf.dslreasoner.domains.cps.CyberPhysicalSystem) parameters[0], (hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance) parameters[1]);
616 }
617
618 /**
619 * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.CpsHosts (visibility: PUBLIC, simpleName: CpsHosts, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.CpsHosts, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)} to be created
620 * <b>not</b> at the class load time of the outer class,
621 * but rather at the first call to {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.CpsHosts (visibility: PUBLIC, simpleName: CpsHosts, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.CpsHosts, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}.
622 *
623 * <p> This workaround is required e.g. to support recursion.
624 *
625 */
626 private static class LazyHolder {
627 private static final CpsHosts INSTANCE = new CpsHosts();
628
629 /**
630 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
631 * This initialization order is required to support indirect recursion.
632 *
633 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
634 *
635 */
636 private static final Object STATIC_INITIALIZER = ensureInitialized();
637
638 public static Object ensureInitialized() {
639 INSTANCE.ensureInitializedInternal();
640 return null;
641 }
642 }
643
644 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
645 private static final CpsHosts.GeneratedPQuery INSTANCE = new GeneratedPQuery();
646
647 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);
648
649 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);
650
651 private final List<PParameter> parameters = Arrays.asList(parameter_Cps, parameter_HostInstance);
652
653 private GeneratedPQuery() {
654 super(PVisibility.PUBLIC);
655 }
656
657 @Override
658 public String getFullyQualifiedName() {
659 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.cpsHosts";
660 }
661
662 @Override
663 public List<String> getParameterNames() {
664 return Arrays.asList("Cps","HostInstance");
665 }
666
667 @Override
668 public List<PParameter> getParameters() {
669 return parameters;
670 }
671
672 @Override
673 public Set<PBody> doGetContainedBodies() {
674 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
675 Set<PBody> bodies = new LinkedHashSet<>();
676 {
677 PBody body = new PBody(this);
678 PVariable var_Cps = body.getOrCreateVariableByName("Cps");
679 PVariable var_HostInstance = body.getOrCreateVariableByName("HostInstance");
680 new TypeConstraint(body, Tuples.flatTupleOf(var_Cps), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "CyberPhysicalSystem")));
681 new TypeConstraint(body, Tuples.flatTupleOf(var_HostInstance), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance")));
682 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
683 new ExportedParameter(body, var_Cps, parameter_Cps),
684 new ExportedParameter(body, var_HostInstance, parameter_HostInstance)
685 ));
686 // CyberPhysicalSystem.hostTypes.instances(Cps, HostInstance)
687 new TypeConstraint(body, Tuples.flatTupleOf(var_Cps), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "CyberPhysicalSystem")));
688 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
689 new TypeConstraint(body, Tuples.flatTupleOf(var_Cps, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "CyberPhysicalSystem", "hostTypes")));
690 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostType")));
691 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
692 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "HostType", "instances")));
693 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance")));
694 new Equality(body, var__virtual_1_, var_HostInstance);
695 bodies.add(body);
696 }
697 {
698 PAnnotation annotation = new PAnnotation("QueryBasedFeature");
699 annotation.addAttribute("feature", "hosts");
700 addAnnotation(annotation);
701 }
702 return bodies;
703 }
704 }
705}
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..4442718b
--- /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,207 @@
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.AllocationWithoutResourceRequirement;
7import hu.bme.mit.inf.dslreasoner.domains.cps.queries.AvailableHdd;
8import hu.bme.mit.inf.dslreasoner.domains.cps.queries.AvailableMemory;
9import hu.bme.mit.inf.dslreasoner.domains.cps.queries.AverageFreeHddMetric;
10import hu.bme.mit.inf.dslreasoner.domains.cps.queries.AverageFreeMemoryMetric;
11import hu.bme.mit.inf.dslreasoner.domains.cps.queries.CostMetric;
12import hu.bme.mit.inf.dslreasoner.domains.cps.queries.CpsApplications;
13import hu.bme.mit.inf.dslreasoner.domains.cps.queries.CpsCost;
14import hu.bme.mit.inf.dslreasoner.domains.cps.queries.CpsHosts;
15import hu.bme.mit.inf.dslreasoner.domains.cps.queries.InstanceDoesNotSatisfyRequirement;
16import hu.bme.mit.inf.dslreasoner.domains.cps.queries.NotEnoughAvailableHdd;
17import hu.bme.mit.inf.dslreasoner.domains.cps.queries.NotEnoughAvailableMemory;
18import hu.bme.mit.inf.dslreasoner.domains.cps.queries.RequirementNotSatisfied;
19import hu.bme.mit.inf.dslreasoner.domains.cps.queries.TotalHdd;
20import hu.bme.mit.inf.dslreasoner.domains.cps.queries.TotalMemory;
21import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine;
22import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedPatternGroup;
23
24/**
25 * A pattern group formed of all public patterns defined in CpsQueries.vql.
26 *
27 * <p>Use the static instance as any {@link interface org.eclipse.viatra.query.runtime.api.IQueryGroup}, to conveniently prepare
28 * a VIATRA Query engine for matching all patterns originally defined in file CpsQueries.vql,
29 * in order to achieve better performance than one-by-one on-demand matcher initialization.
30 *
31 * <p> From package hu.bme.mit.inf.dslreasoner.domains.cps.queries, the group contains the definition of the following patterns: <ul>
32 * <li>cpsApplications</li>
33 * <li>cpsHosts</li>
34 * <li>totalMemory</li>
35 * <li>totalHdd</li>
36 * <li>availableMemory</li>
37 * <li>availableHdd</li>
38 * <li>allocationWithoutResourceRequirement</li>
39 * <li>notEnoughAvailableMemory</li>
40 * <li>notEnoughAvailableHdd</li>
41 * <li>instanceDoesNotSatisfyRequirement</li>
42 * <li>requirementNotSatisfied</li>
43 * <li>averageFreeMemoryMetric</li>
44 * <li>averageFreeHddMetric</li>
45 * <li>costMetric</li>
46 * <li>cpsCost</li>
47 * </ul>
48 *
49 * @see IQueryGroup
50 *
51 */
52@SuppressWarnings("all")
53public final class CpsQueries extends BaseGeneratedPatternGroup {
54 /**
55 * Access the pattern group.
56 *
57 * @return the singleton instance of the group
58 * @throws ViatraQueryRuntimeException if there was an error loading the generated code of pattern specifications
59 *
60 */
61 public static CpsQueries instance() {
62 if (INSTANCE == null) {
63 INSTANCE = new CpsQueries();
64 }
65 return INSTANCE;
66 }
67
68 private static CpsQueries INSTANCE;
69
70 private CpsQueries() {
71 querySpecifications.add(CpsApplications.instance());
72 querySpecifications.add(CpsHosts.instance());
73 querySpecifications.add(TotalMemory.instance());
74 querySpecifications.add(TotalHdd.instance());
75 querySpecifications.add(AvailableMemory.instance());
76 querySpecifications.add(AvailableHdd.instance());
77 querySpecifications.add(AllocationWithoutResourceRequirement.instance());
78 querySpecifications.add(NotEnoughAvailableMemory.instance());
79 querySpecifications.add(NotEnoughAvailableHdd.instance());
80 querySpecifications.add(InstanceDoesNotSatisfyRequirement.instance());
81 querySpecifications.add(RequirementNotSatisfied.instance());
82 querySpecifications.add(AverageFreeMemoryMetric.instance());
83 querySpecifications.add(AverageFreeHddMetric.instance());
84 querySpecifications.add(CostMetric.instance());
85 querySpecifications.add(CpsCost.instance());
86 }
87
88 public CpsApplications getCpsApplications() {
89 return CpsApplications.instance();
90 }
91
92 public CpsApplications.Matcher getCpsApplications(final ViatraQueryEngine engine) {
93 return CpsApplications.Matcher.on(engine);
94 }
95
96 public CpsHosts getCpsHosts() {
97 return CpsHosts.instance();
98 }
99
100 public CpsHosts.Matcher getCpsHosts(final ViatraQueryEngine engine) {
101 return CpsHosts.Matcher.on(engine);
102 }
103
104 public TotalMemory getTotalMemory() {
105 return TotalMemory.instance();
106 }
107
108 public TotalMemory.Matcher getTotalMemory(final ViatraQueryEngine engine) {
109 return TotalMemory.Matcher.on(engine);
110 }
111
112 public TotalHdd getTotalHdd() {
113 return TotalHdd.instance();
114 }
115
116 public TotalHdd.Matcher getTotalHdd(final ViatraQueryEngine engine) {
117 return TotalHdd.Matcher.on(engine);
118 }
119
120 public AvailableMemory getAvailableMemory() {
121 return AvailableMemory.instance();
122 }
123
124 public AvailableMemory.Matcher getAvailableMemory(final ViatraQueryEngine engine) {
125 return AvailableMemory.Matcher.on(engine);
126 }
127
128 public AvailableHdd getAvailableHdd() {
129 return AvailableHdd.instance();
130 }
131
132 public AvailableHdd.Matcher getAvailableHdd(final ViatraQueryEngine engine) {
133 return AvailableHdd.Matcher.on(engine);
134 }
135
136 public AllocationWithoutResourceRequirement getAllocationWithoutResourceRequirement() {
137 return AllocationWithoutResourceRequirement.instance();
138 }
139
140 public AllocationWithoutResourceRequirement.Matcher getAllocationWithoutResourceRequirement(final ViatraQueryEngine engine) {
141 return AllocationWithoutResourceRequirement.Matcher.on(engine);
142 }
143
144 public NotEnoughAvailableMemory getNotEnoughAvailableMemory() {
145 return NotEnoughAvailableMemory.instance();
146 }
147
148 public NotEnoughAvailableMemory.Matcher getNotEnoughAvailableMemory(final ViatraQueryEngine engine) {
149 return NotEnoughAvailableMemory.Matcher.on(engine);
150 }
151
152 public NotEnoughAvailableHdd getNotEnoughAvailableHdd() {
153 return NotEnoughAvailableHdd.instance();
154 }
155
156 public NotEnoughAvailableHdd.Matcher getNotEnoughAvailableHdd(final ViatraQueryEngine engine) {
157 return NotEnoughAvailableHdd.Matcher.on(engine);
158 }
159
160 public InstanceDoesNotSatisfyRequirement getInstanceDoesNotSatisfyRequirement() {
161 return InstanceDoesNotSatisfyRequirement.instance();
162 }
163
164 public InstanceDoesNotSatisfyRequirement.Matcher getInstanceDoesNotSatisfyRequirement(final ViatraQueryEngine engine) {
165 return InstanceDoesNotSatisfyRequirement.Matcher.on(engine);
166 }
167
168 public RequirementNotSatisfied getRequirementNotSatisfied() {
169 return RequirementNotSatisfied.instance();
170 }
171
172 public RequirementNotSatisfied.Matcher getRequirementNotSatisfied(final ViatraQueryEngine engine) {
173 return RequirementNotSatisfied.Matcher.on(engine);
174 }
175
176 public AverageFreeMemoryMetric getAverageFreeMemoryMetric() {
177 return AverageFreeMemoryMetric.instance();
178 }
179
180 public AverageFreeMemoryMetric.Matcher getAverageFreeMemoryMetric(final ViatraQueryEngine engine) {
181 return AverageFreeMemoryMetric.Matcher.on(engine);
182 }
183
184 public AverageFreeHddMetric getAverageFreeHddMetric() {
185 return AverageFreeHddMetric.instance();
186 }
187
188 public AverageFreeHddMetric.Matcher getAverageFreeHddMetric(final ViatraQueryEngine engine) {
189 return AverageFreeHddMetric.Matcher.on(engine);
190 }
191
192 public CostMetric getCostMetric() {
193 return CostMetric.instance();
194 }
195
196 public CostMetric.Matcher getCostMetric(final ViatraQueryEngine engine) {
197 return CostMetric.Matcher.on(engine);
198 }
199
200 public CpsCost getCpsCost() {
201 return CpsCost.instance();
202 }
203
204 public CpsCost.Matcher getCpsCost(final ViatraQueryEngine engine) {
205 return CpsCost.Matcher.on(engine);
206 }
207}
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..14deb337
--- /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,716 @@
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 if ("Req".equals(parameterName)) return this.fReq;
92 if ("App".equals(parameterName)) return this.fApp;
93 return null;
94 }
95
96 public Requirement getReq() {
97 return this.fReq;
98 }
99
100 public ApplicationInstance getApp() {
101 return this.fApp;
102 }
103
104 @Override
105 public boolean set(final String parameterName, final Object newValue) {
106 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
107 if ("Req".equals(parameterName) ) {
108 this.fReq = (Requirement) newValue;
109 return true;
110 }
111 if ("App".equals(parameterName) ) {
112 this.fApp = (ApplicationInstance) newValue;
113 return true;
114 }
115 return false;
116 }
117
118 public void setReq(final Requirement pReq) {
119 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
120 this.fReq = pReq;
121 }
122
123 public void setApp(final ApplicationInstance pApp) {
124 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
125 this.fApp = pApp;
126 }
127
128 @Override
129 public String patternName() {
130 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.instanceDoesNotSatisfyRequirement";
131 }
132
133 @Override
134 public List<String> parameterNames() {
135 return InstanceDoesNotSatisfyRequirement.Match.parameterNames;
136 }
137
138 @Override
139 public Object[] toArray() {
140 return new Object[]{fReq, fApp};
141 }
142
143 @Override
144 public InstanceDoesNotSatisfyRequirement.Match toImmutable() {
145 return isMutable() ? newMatch(fReq, fApp) : this;
146 }
147
148 @Override
149 public String prettyPrint() {
150 StringBuilder result = new StringBuilder();
151 result.append("\"Req\"=" + prettyPrintValue(fReq) + ", ");
152 result.append("\"App\"=" + prettyPrintValue(fApp));
153 return result.toString();
154 }
155
156 @Override
157 public int hashCode() {
158 return Objects.hash(fReq, fApp);
159 }
160
161 @Override
162 public boolean equals(final Object obj) {
163 if (this == obj)
164 return true;
165 if (obj == null) {
166 return false;
167 }
168 if ((obj instanceof InstanceDoesNotSatisfyRequirement.Match)) {
169 InstanceDoesNotSatisfyRequirement.Match other = (InstanceDoesNotSatisfyRequirement.Match) obj;
170 return Objects.equals(fReq, other.fReq) && Objects.equals(fApp, other.fApp);
171 } else {
172 // this should be infrequent
173 if (!(obj instanceof IPatternMatch)) {
174 return false;
175 }
176 IPatternMatch otherSig = (IPatternMatch) obj;
177 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
178 }
179 }
180
181 @Override
182 public InstanceDoesNotSatisfyRequirement specification() {
183 return InstanceDoesNotSatisfyRequirement.instance();
184 }
185
186 /**
187 * Returns an empty, mutable match.
188 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
189 *
190 * @return the empty match.
191 *
192 */
193 public static InstanceDoesNotSatisfyRequirement.Match newEmptyMatch() {
194 return new Mutable(null, null);
195 }
196
197 /**
198 * Returns a mutable (partial) match.
199 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
200 *
201 * @param pReq the fixed value of pattern parameter Req, or null if not bound.
202 * @param pApp the fixed value of pattern parameter App, or null if not bound.
203 * @return the new, mutable (partial) match object.
204 *
205 */
206 public static InstanceDoesNotSatisfyRequirement.Match newMutableMatch(final Requirement pReq, final ApplicationInstance pApp) {
207 return new Mutable(pReq, pApp);
208 }
209
210 /**
211 * Returns a new (partial) match.
212 * This can be used e.g. to call the matcher with a partial match.
213 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
214 * @param pReq the fixed value of pattern parameter Req, or null if not bound.
215 * @param pApp the fixed value of pattern parameter App, or null if not bound.
216 * @return the (partial) match object.
217 *
218 */
219 public static InstanceDoesNotSatisfyRequirement.Match newMatch(final Requirement pReq, final ApplicationInstance pApp) {
220 return new Immutable(pReq, pApp);
221 }
222
223 private static final class Mutable extends InstanceDoesNotSatisfyRequirement.Match {
224 Mutable(final Requirement pReq, final ApplicationInstance pApp) {
225 super(pReq, pApp);
226 }
227
228 @Override
229 public boolean isMutable() {
230 return true;
231 }
232 }
233
234 private static final class Immutable extends InstanceDoesNotSatisfyRequirement.Match {
235 Immutable(final Requirement pReq, final ApplicationInstance pApp) {
236 super(pReq, pApp);
237 }
238
239 @Override
240 public boolean isMutable() {
241 return false;
242 }
243 }
244 }
245
246 /**
247 * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.instanceDoesNotSatisfyRequirement pattern,
248 * providing pattern-specific query methods.
249 *
250 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
251 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
252 *
253 * <p>Matches of the pattern will be represented as {@link Match}.
254 *
255 * <p>Original source:
256 * <code><pre>
257 * {@literal @}Constraint(severity = "error", key = {Req, App},
258 * message = "Requirement must be satisfied by the required application type.")
259 * pattern instanceDoesNotSatisfyRequirement(Req : Requirement, App : ApplicationInstance) {
260 * Requirement.instances(Req, App);
261 * neg find satisfyingInstance(Req, App);
262 * }
263 * </pre></code>
264 *
265 * @see Match
266 * @see InstanceDoesNotSatisfyRequirement
267 *
268 */
269 public static class Matcher extends BaseMatcher<InstanceDoesNotSatisfyRequirement.Match> {
270 /**
271 * Initializes the pattern matcher within an existing VIATRA Query engine.
272 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
273 *
274 * @param engine the existing VIATRA Query engine in which this matcher will be created.
275 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
276 *
277 */
278 public static InstanceDoesNotSatisfyRequirement.Matcher on(final ViatraQueryEngine engine) {
279 // check if matcher already exists
280 Matcher matcher = engine.getExistingMatcher(querySpecification());
281 if (matcher == null) {
282 matcher = (Matcher)engine.getMatcher(querySpecification());
283 }
284 return matcher;
285 }
286
287 /**
288 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
289 * @return an initialized matcher
290 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
291 *
292 */
293 public static InstanceDoesNotSatisfyRequirement.Matcher create() {
294 return new Matcher();
295 }
296
297 private static final int POSITION_REQ = 0;
298
299 private static final int POSITION_APP = 1;
300
301 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(InstanceDoesNotSatisfyRequirement.Matcher.class);
302
303 /**
304 * Initializes the pattern matcher within an existing VIATRA Query engine.
305 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
306 *
307 * @param engine the existing VIATRA Query engine in which this matcher will be created.
308 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
309 *
310 */
311 private Matcher() {
312 super(querySpecification());
313 }
314
315 /**
316 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
317 * @param pReq the fixed value of pattern parameter Req, or null if not bound.
318 * @param pApp the fixed value of pattern parameter App, or null if not bound.
319 * @return matches represented as a Match object.
320 *
321 */
322 public Collection<InstanceDoesNotSatisfyRequirement.Match> getAllMatches(final Requirement pReq, final ApplicationInstance pApp) {
323 return rawStreamAllMatches(new Object[]{pReq, pApp}).collect(Collectors.toSet());
324 }
325
326 /**
327 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
328 * </p>
329 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
330 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
331 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
332 * @param pReq the fixed value of pattern parameter Req, or null if not bound.
333 * @param pApp the fixed value of pattern parameter App, or null if not bound.
334 * @return a stream of matches represented as a Match object.
335 *
336 */
337 public Stream<InstanceDoesNotSatisfyRequirement.Match> streamAllMatches(final Requirement pReq, final ApplicationInstance pApp) {
338 return rawStreamAllMatches(new Object[]{pReq, pApp});
339 }
340
341 /**
342 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
343 * Neither determinism nor randomness of selection is guaranteed.
344 * @param pReq the fixed value of pattern parameter Req, or null if not bound.
345 * @param pApp the fixed value of pattern parameter App, or null if not bound.
346 * @return a match represented as a Match object, or null if no match is found.
347 *
348 */
349 public Optional<InstanceDoesNotSatisfyRequirement.Match> getOneArbitraryMatch(final Requirement pReq, final ApplicationInstance pApp) {
350 return rawGetOneArbitraryMatch(new Object[]{pReq, pApp});
351 }
352
353 /**
354 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
355 * under any possible substitution of the unspecified parameters (if any).
356 * @param pReq the fixed value of pattern parameter Req, or null if not bound.
357 * @param pApp the fixed value of pattern parameter App, or null if not bound.
358 * @return true if the input is a valid (partial) match of the pattern.
359 *
360 */
361 public boolean hasMatch(final Requirement pReq, final ApplicationInstance pApp) {
362 return rawHasMatch(new Object[]{pReq, pApp});
363 }
364
365 /**
366 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
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 the number of pattern matches found.
370 *
371 */
372 public int countMatches(final Requirement pReq, final ApplicationInstance pApp) {
373 return rawCountMatches(new Object[]{pReq, pApp});
374 }
375
376 /**
377 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
378 * Neither determinism nor randomness of selection is guaranteed.
379 * @param pReq the fixed value of pattern parameter Req, or null if not bound.
380 * @param pApp the fixed value of pattern parameter App, or null if not bound.
381 * @param processor the action that will process the selected match.
382 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
383 *
384 */
385 public boolean forOneArbitraryMatch(final Requirement pReq, final ApplicationInstance pApp, final Consumer<? super InstanceDoesNotSatisfyRequirement.Match> processor) {
386 return rawForOneArbitraryMatch(new Object[]{pReq, pApp}, processor);
387 }
388
389 /**
390 * Returns a new (partial) match.
391 * This can be used e.g. to call the matcher with a partial match.
392 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
393 * @param pReq the fixed value of pattern parameter Req, or null if not bound.
394 * @param pApp the fixed value of pattern parameter App, or null if not bound.
395 * @return the (partial) match object.
396 *
397 */
398 public InstanceDoesNotSatisfyRequirement.Match newMatch(final Requirement pReq, final ApplicationInstance pApp) {
399 return InstanceDoesNotSatisfyRequirement.Match.newMatch(pReq, pApp);
400 }
401
402 /**
403 * Retrieve the set of values that occur in matches for Req.
404 * @return the Set of all values or empty set if there are no matches
405 *
406 */
407 protected Stream<Requirement> rawStreamAllValuesOfReq(final Object[] parameters) {
408 return rawStreamAllValues(POSITION_REQ, parameters).map(Requirement.class::cast);
409 }
410
411 /**
412 * Retrieve the set of values that occur in matches for Req.
413 * @return the Set of all values or empty set if there are no matches
414 *
415 */
416 public Set<Requirement> getAllValuesOfReq() {
417 return rawStreamAllValuesOfReq(emptyArray()).collect(Collectors.toSet());
418 }
419
420 /**
421 * Retrieve the set of values that occur in matches for Req.
422 * @return the Set of all values or empty set if there are no matches
423 *
424 */
425 public Stream<Requirement> streamAllValuesOfReq() {
426 return rawStreamAllValuesOfReq(emptyArray());
427 }
428
429 /**
430 * Retrieve the set of values that occur in matches for Req.
431 * </p>
432 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
433 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
434 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
435 *
436 * @return the Stream of all values or empty set if there are no matches
437 *
438 */
439 public Stream<Requirement> streamAllValuesOfReq(final InstanceDoesNotSatisfyRequirement.Match partialMatch) {
440 return rawStreamAllValuesOfReq(partialMatch.toArray());
441 }
442
443 /**
444 * Retrieve the set of values that occur in matches for Req.
445 * </p>
446 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
447 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
448 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
449 *
450 * @return the Stream of all values or empty set if there are no matches
451 *
452 */
453 public Stream<Requirement> streamAllValuesOfReq(final ApplicationInstance pApp) {
454 return rawStreamAllValuesOfReq(new Object[]{null, pApp});
455 }
456
457 /**
458 * Retrieve the set of values that occur in matches for Req.
459 * @return the Set of all values or empty set if there are no matches
460 *
461 */
462 public Set<Requirement> getAllValuesOfReq(final InstanceDoesNotSatisfyRequirement.Match partialMatch) {
463 return rawStreamAllValuesOfReq(partialMatch.toArray()).collect(Collectors.toSet());
464 }
465
466 /**
467 * Retrieve the set of values that occur in matches for Req.
468 * @return the Set of all values or empty set if there are no matches
469 *
470 */
471 public Set<Requirement> getAllValuesOfReq(final ApplicationInstance pApp) {
472 return rawStreamAllValuesOfReq(new Object[]{null, pApp}).collect(Collectors.toSet());
473 }
474
475 /**
476 * Retrieve the set of values that occur in matches for App.
477 * @return the Set of all values or empty set if there are no matches
478 *
479 */
480 protected Stream<ApplicationInstance> rawStreamAllValuesOfApp(final Object[] parameters) {
481 return rawStreamAllValues(POSITION_APP, parameters).map(ApplicationInstance.class::cast);
482 }
483
484 /**
485 * Retrieve the set of values that occur in matches for App.
486 * @return the Set of all values or empty set if there are no matches
487 *
488 */
489 public Set<ApplicationInstance> getAllValuesOfApp() {
490 return rawStreamAllValuesOfApp(emptyArray()).collect(Collectors.toSet());
491 }
492
493 /**
494 * Retrieve the set of values that occur in matches for App.
495 * @return the Set of all values or empty set if there are no matches
496 *
497 */
498 public Stream<ApplicationInstance> streamAllValuesOfApp() {
499 return rawStreamAllValuesOfApp(emptyArray());
500 }
501
502 /**
503 * Retrieve the set of values that occur in matches for App.
504 * </p>
505 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
506 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
507 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
508 *
509 * @return the Stream of all values or empty set if there are no matches
510 *
511 */
512 public Stream<ApplicationInstance> streamAllValuesOfApp(final InstanceDoesNotSatisfyRequirement.Match partialMatch) {
513 return rawStreamAllValuesOfApp(partialMatch.toArray());
514 }
515
516 /**
517 * Retrieve the set of values that occur in matches for App.
518 * </p>
519 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
520 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
521 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
522 *
523 * @return the Stream of all values or empty set if there are no matches
524 *
525 */
526 public Stream<ApplicationInstance> streamAllValuesOfApp(final Requirement pReq) {
527 return rawStreamAllValuesOfApp(new Object[]{pReq, null});
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 Set<ApplicationInstance> getAllValuesOfApp(final InstanceDoesNotSatisfyRequirement.Match partialMatch) {
536 return rawStreamAllValuesOfApp(partialMatch.toArray()).collect(Collectors.toSet());
537 }
538
539 /**
540 * Retrieve the set of values that occur in matches for App.
541 * @return the Set of all values or empty set if there are no matches
542 *
543 */
544 public Set<ApplicationInstance> getAllValuesOfApp(final Requirement pReq) {
545 return rawStreamAllValuesOfApp(new Object[]{pReq, null}).collect(Collectors.toSet());
546 }
547
548 @Override
549 protected InstanceDoesNotSatisfyRequirement.Match tupleToMatch(final Tuple t) {
550 try {
551 return InstanceDoesNotSatisfyRequirement.Match.newMatch((Requirement) t.get(POSITION_REQ), (ApplicationInstance) t.get(POSITION_APP));
552 } catch(ClassCastException e) {
553 LOGGER.error("Element(s) in tuple not properly typed!",e);
554 return null;
555 }
556 }
557
558 @Override
559 protected InstanceDoesNotSatisfyRequirement.Match arrayToMatch(final Object[] match) {
560 try {
561 return InstanceDoesNotSatisfyRequirement.Match.newMatch((Requirement) match[POSITION_REQ], (ApplicationInstance) match[POSITION_APP]);
562 } catch(ClassCastException e) {
563 LOGGER.error("Element(s) in array not properly typed!",e);
564 return null;
565 }
566 }
567
568 @Override
569 protected InstanceDoesNotSatisfyRequirement.Match arrayToMatchMutable(final Object[] match) {
570 try {
571 return InstanceDoesNotSatisfyRequirement.Match.newMutableMatch((Requirement) match[POSITION_REQ], (ApplicationInstance) match[POSITION_APP]);
572 } catch(ClassCastException e) {
573 LOGGER.error("Element(s) in array not properly typed!",e);
574 return null;
575 }
576 }
577
578 /**
579 * @return the singleton instance of the query specification of this pattern
580 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
581 *
582 */
583 public static IQuerySpecification<InstanceDoesNotSatisfyRequirement.Matcher> querySpecification() {
584 return InstanceDoesNotSatisfyRequirement.instance();
585 }
586 }
587
588 private InstanceDoesNotSatisfyRequirement() {
589 super(GeneratedPQuery.INSTANCE);
590 }
591
592 /**
593 * @return the singleton instance of the query specification
594 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
595 *
596 */
597 public static InstanceDoesNotSatisfyRequirement instance() {
598 try{
599 return LazyHolder.INSTANCE;
600 } catch (ExceptionInInitializerError err) {
601 throw processInitializerError(err);
602 }
603 }
604
605 @Override
606 protected InstanceDoesNotSatisfyRequirement.Matcher instantiate(final ViatraQueryEngine engine) {
607 return InstanceDoesNotSatisfyRequirement.Matcher.on(engine);
608 }
609
610 @Override
611 public InstanceDoesNotSatisfyRequirement.Matcher instantiate() {
612 return InstanceDoesNotSatisfyRequirement.Matcher.create();
613 }
614
615 @Override
616 public InstanceDoesNotSatisfyRequirement.Match newEmptyMatch() {
617 return InstanceDoesNotSatisfyRequirement.Match.newEmptyMatch();
618 }
619
620 @Override
621 public InstanceDoesNotSatisfyRequirement.Match newMatch(final Object... parameters) {
622 return InstanceDoesNotSatisfyRequirement.Match.newMatch((hu.bme.mit.inf.dslreasoner.domains.cps.Requirement) parameters[0], (hu.bme.mit.inf.dslreasoner.domains.cps.ApplicationInstance) parameters[1]);
623 }
624
625 /**
626 * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.InstanceDoesNotSatisfyRequirement (visibility: PUBLIC, simpleName: InstanceDoesNotSatisfyRequirement, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.InstanceDoesNotSatisfyRequirement, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)} to be created
627 * <b>not</b> at the class load time of the outer class,
628 * but rather at the first call to {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.InstanceDoesNotSatisfyRequirement (visibility: PUBLIC, simpleName: InstanceDoesNotSatisfyRequirement, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.InstanceDoesNotSatisfyRequirement, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}.
629 *
630 * <p> This workaround is required e.g. to support recursion.
631 *
632 */
633 private static class LazyHolder {
634 private static final InstanceDoesNotSatisfyRequirement INSTANCE = new InstanceDoesNotSatisfyRequirement();
635
636 /**
637 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
638 * This initialization order is required to support indirect recursion.
639 *
640 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
641 *
642 */
643 private static final Object STATIC_INITIALIZER = ensureInitialized();
644
645 public static Object ensureInitialized() {
646 INSTANCE.ensureInitializedInternal();
647 return null;
648 }
649 }
650
651 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
652 private static final InstanceDoesNotSatisfyRequirement.GeneratedPQuery INSTANCE = new GeneratedPQuery();
653
654 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);
655
656 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);
657
658 private final List<PParameter> parameters = Arrays.asList(parameter_Req, parameter_App);
659
660 private GeneratedPQuery() {
661 super(PVisibility.PUBLIC);
662 }
663
664 @Override
665 public String getFullyQualifiedName() {
666 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.instanceDoesNotSatisfyRequirement";
667 }
668
669 @Override
670 public List<String> getParameterNames() {
671 return Arrays.asList("Req","App");
672 }
673
674 @Override
675 public List<PParameter> getParameters() {
676 return parameters;
677 }
678
679 @Override
680 public Set<PBody> doGetContainedBodies() {
681 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
682 Set<PBody> bodies = new LinkedHashSet<>();
683 {
684 PBody body = new PBody(this);
685 PVariable var_Req = body.getOrCreateVariableByName("Req");
686 PVariable var_App = body.getOrCreateVariableByName("App");
687 new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "Requirement")));
688 new TypeConstraint(body, Tuples.flatTupleOf(var_App), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance")));
689 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
690 new ExportedParameter(body, var_Req, parameter_Req),
691 new ExportedParameter(body, var_App, parameter_App)
692 ));
693 // Requirement.instances(Req, App)
694 new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "Requirement")));
695 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
696 new TypeConstraint(body, Tuples.flatTupleOf(var_Req, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "Requirement", "instances")));
697 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance")));
698 new Equality(body, var__virtual_0_, var_App);
699 // neg find satisfyingInstance(Req, App)
700 new NegativePatternCall(body, Tuples.flatTupleOf(var_Req, var_App), SatisfyingInstance.instance().getInternalQueryRepresentation());
701 bodies.add(body);
702 }
703 {
704 PAnnotation annotation = new PAnnotation("Constraint");
705 annotation.addAttribute("severity", "error");
706 annotation.addAttribute("key", Arrays.asList(new Object[] {
707 new ParameterReference("Req"),
708 new ParameterReference("App")
709 }));
710 annotation.addAttribute("message", "Requirement must be satisfied by the required application type.");
711 addAnnotation(annotation);
712 }
713 return bodies;
714 }
715 }
716}
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..41615598
--- /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,579 @@
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.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 if ("Host".equals(parameterName)) return this.fHost;
89 return null;
90 }
91
92 public HostInstance getHost() {
93 return this.fHost;
94 }
95
96 @Override
97 public boolean set(final String parameterName, final Object newValue) {
98 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
99 if ("Host".equals(parameterName) ) {
100 this.fHost = (HostInstance) newValue;
101 return true;
102 }
103 return false;
104 }
105
106 public void setHost(final HostInstance pHost) {
107 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
108 this.fHost = pHost;
109 }
110
111 @Override
112 public String patternName() {
113 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.notEnoughAvailableHdd";
114 }
115
116 @Override
117 public List<String> parameterNames() {
118 return NotEnoughAvailableHdd.Match.parameterNames;
119 }
120
121 @Override
122 public Object[] toArray() {
123 return new Object[]{fHost};
124 }
125
126 @Override
127 public NotEnoughAvailableHdd.Match toImmutable() {
128 return isMutable() ? newMatch(fHost) : this;
129 }
130
131 @Override
132 public String prettyPrint() {
133 StringBuilder result = new StringBuilder();
134 result.append("\"Host\"=" + prettyPrintValue(fHost));
135 return result.toString();
136 }
137
138 @Override
139 public int hashCode() {
140 return Objects.hash(fHost);
141 }
142
143 @Override
144 public boolean equals(final Object obj) {
145 if (this == obj)
146 return true;
147 if (obj == null) {
148 return false;
149 }
150 if ((obj instanceof NotEnoughAvailableHdd.Match)) {
151 NotEnoughAvailableHdd.Match other = (NotEnoughAvailableHdd.Match) obj;
152 return Objects.equals(fHost, other.fHost);
153 } else {
154 // this should be infrequent
155 if (!(obj instanceof IPatternMatch)) {
156 return false;
157 }
158 IPatternMatch otherSig = (IPatternMatch) obj;
159 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
160 }
161 }
162
163 @Override
164 public NotEnoughAvailableHdd specification() {
165 return NotEnoughAvailableHdd.instance();
166 }
167
168 /**
169 * Returns an empty, mutable match.
170 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
171 *
172 * @return the empty match.
173 *
174 */
175 public static NotEnoughAvailableHdd.Match newEmptyMatch() {
176 return new Mutable(null);
177 }
178
179 /**
180 * Returns a mutable (partial) match.
181 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
182 *
183 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
184 * @return the new, mutable (partial) match object.
185 *
186 */
187 public static NotEnoughAvailableHdd.Match newMutableMatch(final HostInstance pHost) {
188 return new Mutable(pHost);
189 }
190
191 /**
192 * Returns a new (partial) match.
193 * This can be used e.g. to call the matcher with a partial match.
194 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
195 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
196 * @return the (partial) match object.
197 *
198 */
199 public static NotEnoughAvailableHdd.Match newMatch(final HostInstance pHost) {
200 return new Immutable(pHost);
201 }
202
203 private static final class Mutable extends NotEnoughAvailableHdd.Match {
204 Mutable(final HostInstance pHost) {
205 super(pHost);
206 }
207
208 @Override
209 public boolean isMutable() {
210 return true;
211 }
212 }
213
214 private static final class Immutable extends NotEnoughAvailableHdd.Match {
215 Immutable(final HostInstance pHost) {
216 super(pHost);
217 }
218
219 @Override
220 public boolean isMutable() {
221 return false;
222 }
223 }
224 }
225
226 /**
227 * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.notEnoughAvailableHdd pattern,
228 * providing pattern-specific query methods.
229 *
230 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
231 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
232 *
233 * <p>Matches of the pattern will be represented as {@link Match}.
234 *
235 * <p>Original source:
236 * <code><pre>
237 * {@literal @}Constraint(severity = "error", key = {Host},
238 * message = "Insufficient HDD available on host.")
239 * pattern notEnoughAvailableHdd(Host : HostInstance) {
240 * find availableHdd(Host, Hdd);
241 * check(Hdd {@literal <} 0);
242 * }
243 * </pre></code>
244 *
245 * @see Match
246 * @see NotEnoughAvailableHdd
247 *
248 */
249 public static class Matcher extends BaseMatcher<NotEnoughAvailableHdd.Match> {
250 /**
251 * Initializes the pattern matcher within an existing VIATRA Query engine.
252 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
253 *
254 * @param engine the existing VIATRA Query engine in which this matcher will be created.
255 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
256 *
257 */
258 public static NotEnoughAvailableHdd.Matcher on(final ViatraQueryEngine engine) {
259 // check if matcher already exists
260 Matcher matcher = engine.getExistingMatcher(querySpecification());
261 if (matcher == null) {
262 matcher = (Matcher)engine.getMatcher(querySpecification());
263 }
264 return matcher;
265 }
266
267 /**
268 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
269 * @return an initialized matcher
270 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
271 *
272 */
273 public static NotEnoughAvailableHdd.Matcher create() {
274 return new Matcher();
275 }
276
277 private static final int POSITION_HOST = 0;
278
279 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(NotEnoughAvailableHdd.Matcher.class);
280
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 private Matcher() {
290 super(querySpecification());
291 }
292
293 /**
294 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
295 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
296 * @return matches represented as a Match object.
297 *
298 */
299 public Collection<NotEnoughAvailableHdd.Match> getAllMatches(final HostInstance pHost) {
300 return rawStreamAllMatches(new Object[]{pHost}).collect(Collectors.toSet());
301 }
302
303 /**
304 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
305 * </p>
306 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
307 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
308 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
309 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
310 * @return a stream of matches represented as a Match object.
311 *
312 */
313 public Stream<NotEnoughAvailableHdd.Match> streamAllMatches(final HostInstance pHost) {
314 return rawStreamAllMatches(new Object[]{pHost});
315 }
316
317 /**
318 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
319 * Neither determinism nor randomness of selection is guaranteed.
320 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
321 * @return a match represented as a Match object, or null if no match is found.
322 *
323 */
324 public Optional<NotEnoughAvailableHdd.Match> getOneArbitraryMatch(final HostInstance pHost) {
325 return rawGetOneArbitraryMatch(new Object[]{pHost});
326 }
327
328 /**
329 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
330 * under any possible substitution of the unspecified parameters (if any).
331 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
332 * @return true if the input is a valid (partial) match of the pattern.
333 *
334 */
335 public boolean hasMatch(final HostInstance pHost) {
336 return rawHasMatch(new Object[]{pHost});
337 }
338
339 /**
340 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
341 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
342 * @return the number of pattern matches found.
343 *
344 */
345 public int countMatches(final HostInstance pHost) {
346 return rawCountMatches(new Object[]{pHost});
347 }
348
349 /**
350 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
351 * Neither determinism nor randomness of selection is guaranteed.
352 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
353 * @param processor the action that will process the selected match.
354 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
355 *
356 */
357 public boolean forOneArbitraryMatch(final HostInstance pHost, final Consumer<? super NotEnoughAvailableHdd.Match> processor) {
358 return rawForOneArbitraryMatch(new Object[]{pHost}, processor);
359 }
360
361 /**
362 * Returns a new (partial) match.
363 * This can be used e.g. to call the matcher with a partial match.
364 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
365 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
366 * @return the (partial) match object.
367 *
368 */
369 public NotEnoughAvailableHdd.Match newMatch(final HostInstance pHost) {
370 return NotEnoughAvailableHdd.Match.newMatch(pHost);
371 }
372
373 /**
374 * Retrieve the set of values that occur in matches for Host.
375 * @return the Set of all values or empty set if there are no matches
376 *
377 */
378 protected Stream<HostInstance> rawStreamAllValuesOfHost(final Object[] parameters) {
379 return rawStreamAllValues(POSITION_HOST, parameters).map(HostInstance.class::cast);
380 }
381
382 /**
383 * Retrieve the set of values that occur in matches for Host.
384 * @return the Set of all values or empty set if there are no matches
385 *
386 */
387 public Set<HostInstance> getAllValuesOfHost() {
388 return rawStreamAllValuesOfHost(emptyArray()).collect(Collectors.toSet());
389 }
390
391 /**
392 * Retrieve the set of values that occur in matches for Host.
393 * @return the Set of all values or empty set if there are no matches
394 *
395 */
396 public Stream<HostInstance> streamAllValuesOfHost() {
397 return rawStreamAllValuesOfHost(emptyArray());
398 }
399
400 @Override
401 protected NotEnoughAvailableHdd.Match tupleToMatch(final Tuple t) {
402 try {
403 return NotEnoughAvailableHdd.Match.newMatch((HostInstance) t.get(POSITION_HOST));
404 } catch(ClassCastException e) {
405 LOGGER.error("Element(s) in tuple not properly typed!",e);
406 return null;
407 }
408 }
409
410 @Override
411 protected NotEnoughAvailableHdd.Match arrayToMatch(final Object[] match) {
412 try {
413 return NotEnoughAvailableHdd.Match.newMatch((HostInstance) match[POSITION_HOST]);
414 } catch(ClassCastException e) {
415 LOGGER.error("Element(s) in array not properly typed!",e);
416 return null;
417 }
418 }
419
420 @Override
421 protected NotEnoughAvailableHdd.Match arrayToMatchMutable(final Object[] match) {
422 try {
423 return NotEnoughAvailableHdd.Match.newMutableMatch((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 /**
431 * @return the singleton instance of the query specification of this pattern
432 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
433 *
434 */
435 public static IQuerySpecification<NotEnoughAvailableHdd.Matcher> querySpecification() {
436 return NotEnoughAvailableHdd.instance();
437 }
438 }
439
440 private NotEnoughAvailableHdd() {
441 super(GeneratedPQuery.INSTANCE);
442 }
443
444 /**
445 * @return the singleton instance of the query specification
446 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
447 *
448 */
449 public static NotEnoughAvailableHdd instance() {
450 try{
451 return LazyHolder.INSTANCE;
452 } catch (ExceptionInInitializerError err) {
453 throw processInitializerError(err);
454 }
455 }
456
457 @Override
458 protected NotEnoughAvailableHdd.Matcher instantiate(final ViatraQueryEngine engine) {
459 return NotEnoughAvailableHdd.Matcher.on(engine);
460 }
461
462 @Override
463 public NotEnoughAvailableHdd.Matcher instantiate() {
464 return NotEnoughAvailableHdd.Matcher.create();
465 }
466
467 @Override
468 public NotEnoughAvailableHdd.Match newEmptyMatch() {
469 return NotEnoughAvailableHdd.Match.newEmptyMatch();
470 }
471
472 @Override
473 public NotEnoughAvailableHdd.Match newMatch(final Object... parameters) {
474 return NotEnoughAvailableHdd.Match.newMatch((hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance) parameters[0]);
475 }
476
477 /**
478 * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.NotEnoughAvailableHdd (visibility: PUBLIC, simpleName: NotEnoughAvailableHdd, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.NotEnoughAvailableHdd, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)} to be created
479 * <b>not</b> at the class load time of the outer class,
480 * but rather at the first call to {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.NotEnoughAvailableHdd (visibility: PUBLIC, simpleName: NotEnoughAvailableHdd, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.NotEnoughAvailableHdd, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}.
481 *
482 * <p> This workaround is required e.g. to support recursion.
483 *
484 */
485 private static class LazyHolder {
486 private static final NotEnoughAvailableHdd INSTANCE = new NotEnoughAvailableHdd();
487
488 /**
489 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
490 * This initialization order is required to support indirect recursion.
491 *
492 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
493 *
494 */
495 private static final Object STATIC_INITIALIZER = ensureInitialized();
496
497 public static Object ensureInitialized() {
498 INSTANCE.ensureInitializedInternal();
499 return null;
500 }
501 }
502
503 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
504 private static final NotEnoughAvailableHdd.GeneratedPQuery INSTANCE = new GeneratedPQuery();
505
506 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);
507
508 private final List<PParameter> parameters = Arrays.asList(parameter_Host);
509
510 private GeneratedPQuery() {
511 super(PVisibility.PUBLIC);
512 }
513
514 @Override
515 public String getFullyQualifiedName() {
516 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.notEnoughAvailableHdd";
517 }
518
519 @Override
520 public List<String> getParameterNames() {
521 return Arrays.asList("Host");
522 }
523
524 @Override
525 public List<PParameter> getParameters() {
526 return parameters;
527 }
528
529 @Override
530 public Set<PBody> doGetContainedBodies() {
531 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
532 Set<PBody> bodies = new LinkedHashSet<>();
533 {
534 PBody body = new PBody(this);
535 PVariable var_Host = body.getOrCreateVariableByName("Host");
536 PVariable var_Hdd = body.getOrCreateVariableByName("Hdd");
537 new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance")));
538 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
539 new ExportedParameter(body, var_Host, parameter_Host)
540 ));
541 // find availableHdd(Host, Hdd)
542 new PositivePatternCall(body, Tuples.flatTupleOf(var_Host, var_Hdd), AvailableHdd.instance().getInternalQueryRepresentation());
543 // check(Hdd < 0)
544 new ExpressionEvaluation(body, new IExpressionEvaluator() {
545
546 @Override
547 public String getShortDescription() {
548 return "Expression evaluation from pattern notEnoughAvailableHdd";
549 }
550
551 @Override
552 public Iterable<String> getInputParameterNames() {
553 return Arrays.asList("Hdd");}
554
555 @Override
556 public Object evaluateExpression(IValueProvider provider) throws Exception {
557 Integer Hdd = (Integer) provider.getValue("Hdd");
558 return evaluateExpression_1_1(Hdd);
559 }
560 }, null);
561 bodies.add(body);
562 }
563 {
564 PAnnotation annotation = new PAnnotation("Constraint");
565 annotation.addAttribute("severity", "error");
566 annotation.addAttribute("key", Arrays.asList(new Object[] {
567 new ParameterReference("Host")
568 }));
569 annotation.addAttribute("message", "Insufficient HDD available on host.");
570 addAnnotation(annotation);
571 }
572 return bodies;
573 }
574 }
575
576 private static boolean evaluateExpression_1_1(final Integer Hdd) {
577 return ((Hdd).intValue() < 0);
578 }
579}
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..4803ec3a
--- /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,579 @@
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.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 if ("Host".equals(parameterName)) return this.fHost;
89 return null;
90 }
91
92 public HostInstance getHost() {
93 return this.fHost;
94 }
95
96 @Override
97 public boolean set(final String parameterName, final Object newValue) {
98 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
99 if ("Host".equals(parameterName) ) {
100 this.fHost = (HostInstance) newValue;
101 return true;
102 }
103 return false;
104 }
105
106 public void setHost(final HostInstance pHost) {
107 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
108 this.fHost = pHost;
109 }
110
111 @Override
112 public String patternName() {
113 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.notEnoughAvailableMemory";
114 }
115
116 @Override
117 public List<String> parameterNames() {
118 return NotEnoughAvailableMemory.Match.parameterNames;
119 }
120
121 @Override
122 public Object[] toArray() {
123 return new Object[]{fHost};
124 }
125
126 @Override
127 public NotEnoughAvailableMemory.Match toImmutable() {
128 return isMutable() ? newMatch(fHost) : this;
129 }
130
131 @Override
132 public String prettyPrint() {
133 StringBuilder result = new StringBuilder();
134 result.append("\"Host\"=" + prettyPrintValue(fHost));
135 return result.toString();
136 }
137
138 @Override
139 public int hashCode() {
140 return Objects.hash(fHost);
141 }
142
143 @Override
144 public boolean equals(final Object obj) {
145 if (this == obj)
146 return true;
147 if (obj == null) {
148 return false;
149 }
150 if ((obj instanceof NotEnoughAvailableMemory.Match)) {
151 NotEnoughAvailableMemory.Match other = (NotEnoughAvailableMemory.Match) obj;
152 return Objects.equals(fHost, other.fHost);
153 } else {
154 // this should be infrequent
155 if (!(obj instanceof IPatternMatch)) {
156 return false;
157 }
158 IPatternMatch otherSig = (IPatternMatch) obj;
159 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
160 }
161 }
162
163 @Override
164 public NotEnoughAvailableMemory specification() {
165 return NotEnoughAvailableMemory.instance();
166 }
167
168 /**
169 * Returns an empty, mutable match.
170 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
171 *
172 * @return the empty match.
173 *
174 */
175 public static NotEnoughAvailableMemory.Match newEmptyMatch() {
176 return new Mutable(null);
177 }
178
179 /**
180 * Returns a mutable (partial) match.
181 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
182 *
183 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
184 * @return the new, mutable (partial) match object.
185 *
186 */
187 public static NotEnoughAvailableMemory.Match newMutableMatch(final HostInstance pHost) {
188 return new Mutable(pHost);
189 }
190
191 /**
192 * Returns a new (partial) match.
193 * This can be used e.g. to call the matcher with a partial match.
194 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
195 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
196 * @return the (partial) match object.
197 *
198 */
199 public static NotEnoughAvailableMemory.Match newMatch(final HostInstance pHost) {
200 return new Immutable(pHost);
201 }
202
203 private static final class Mutable extends NotEnoughAvailableMemory.Match {
204 Mutable(final HostInstance pHost) {
205 super(pHost);
206 }
207
208 @Override
209 public boolean isMutable() {
210 return true;
211 }
212 }
213
214 private static final class Immutable extends NotEnoughAvailableMemory.Match {
215 Immutable(final HostInstance pHost) {
216 super(pHost);
217 }
218
219 @Override
220 public boolean isMutable() {
221 return false;
222 }
223 }
224 }
225
226 /**
227 * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.notEnoughAvailableMemory pattern,
228 * providing pattern-specific query methods.
229 *
230 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
231 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
232 *
233 * <p>Matches of the pattern will be represented as {@link Match}.
234 *
235 * <p>Original source:
236 * <code><pre>
237 * {@literal @}Constraint(severity = "error", key = {Host},
238 * message = "Insufficient memory available on host.")
239 * pattern notEnoughAvailableMemory(Host : HostInstance) {
240 * find availableMemory(Host, Memory);
241 * check(Memory {@literal <} 0);
242 * }
243 * </pre></code>
244 *
245 * @see Match
246 * @see NotEnoughAvailableMemory
247 *
248 */
249 public static class Matcher extends BaseMatcher<NotEnoughAvailableMemory.Match> {
250 /**
251 * Initializes the pattern matcher within an existing VIATRA Query engine.
252 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
253 *
254 * @param engine the existing VIATRA Query engine in which this matcher will be created.
255 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
256 *
257 */
258 public static NotEnoughAvailableMemory.Matcher on(final ViatraQueryEngine engine) {
259 // check if matcher already exists
260 Matcher matcher = engine.getExistingMatcher(querySpecification());
261 if (matcher == null) {
262 matcher = (Matcher)engine.getMatcher(querySpecification());
263 }
264 return matcher;
265 }
266
267 /**
268 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
269 * @return an initialized matcher
270 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
271 *
272 */
273 public static NotEnoughAvailableMemory.Matcher create() {
274 return new Matcher();
275 }
276
277 private static final int POSITION_HOST = 0;
278
279 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(NotEnoughAvailableMemory.Matcher.class);
280
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 private Matcher() {
290 super(querySpecification());
291 }
292
293 /**
294 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
295 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
296 * @return matches represented as a Match object.
297 *
298 */
299 public Collection<NotEnoughAvailableMemory.Match> getAllMatches(final HostInstance pHost) {
300 return rawStreamAllMatches(new Object[]{pHost}).collect(Collectors.toSet());
301 }
302
303 /**
304 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
305 * </p>
306 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
307 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
308 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
309 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
310 * @return a stream of matches represented as a Match object.
311 *
312 */
313 public Stream<NotEnoughAvailableMemory.Match> streamAllMatches(final HostInstance pHost) {
314 return rawStreamAllMatches(new Object[]{pHost});
315 }
316
317 /**
318 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
319 * Neither determinism nor randomness of selection is guaranteed.
320 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
321 * @return a match represented as a Match object, or null if no match is found.
322 *
323 */
324 public Optional<NotEnoughAvailableMemory.Match> getOneArbitraryMatch(final HostInstance pHost) {
325 return rawGetOneArbitraryMatch(new Object[]{pHost});
326 }
327
328 /**
329 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
330 * under any possible substitution of the unspecified parameters (if any).
331 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
332 * @return true if the input is a valid (partial) match of the pattern.
333 *
334 */
335 public boolean hasMatch(final HostInstance pHost) {
336 return rawHasMatch(new Object[]{pHost});
337 }
338
339 /**
340 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
341 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
342 * @return the number of pattern matches found.
343 *
344 */
345 public int countMatches(final HostInstance pHost) {
346 return rawCountMatches(new Object[]{pHost});
347 }
348
349 /**
350 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
351 * Neither determinism nor randomness of selection is guaranteed.
352 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
353 * @param processor the action that will process the selected match.
354 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
355 *
356 */
357 public boolean forOneArbitraryMatch(final HostInstance pHost, final Consumer<? super NotEnoughAvailableMemory.Match> processor) {
358 return rawForOneArbitraryMatch(new Object[]{pHost}, processor);
359 }
360
361 /**
362 * Returns a new (partial) match.
363 * This can be used e.g. to call the matcher with a partial match.
364 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
365 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
366 * @return the (partial) match object.
367 *
368 */
369 public NotEnoughAvailableMemory.Match newMatch(final HostInstance pHost) {
370 return NotEnoughAvailableMemory.Match.newMatch(pHost);
371 }
372
373 /**
374 * Retrieve the set of values that occur in matches for Host.
375 * @return the Set of all values or empty set if there are no matches
376 *
377 */
378 protected Stream<HostInstance> rawStreamAllValuesOfHost(final Object[] parameters) {
379 return rawStreamAllValues(POSITION_HOST, parameters).map(HostInstance.class::cast);
380 }
381
382 /**
383 * Retrieve the set of values that occur in matches for Host.
384 * @return the Set of all values or empty set if there are no matches
385 *
386 */
387 public Set<HostInstance> getAllValuesOfHost() {
388 return rawStreamAllValuesOfHost(emptyArray()).collect(Collectors.toSet());
389 }
390
391 /**
392 * Retrieve the set of values that occur in matches for Host.
393 * @return the Set of all values or empty set if there are no matches
394 *
395 */
396 public Stream<HostInstance> streamAllValuesOfHost() {
397 return rawStreamAllValuesOfHost(emptyArray());
398 }
399
400 @Override
401 protected NotEnoughAvailableMemory.Match tupleToMatch(final Tuple t) {
402 try {
403 return NotEnoughAvailableMemory.Match.newMatch((HostInstance) t.get(POSITION_HOST));
404 } catch(ClassCastException e) {
405 LOGGER.error("Element(s) in tuple not properly typed!",e);
406 return null;
407 }
408 }
409
410 @Override
411 protected NotEnoughAvailableMemory.Match arrayToMatch(final Object[] match) {
412 try {
413 return NotEnoughAvailableMemory.Match.newMatch((HostInstance) match[POSITION_HOST]);
414 } catch(ClassCastException e) {
415 LOGGER.error("Element(s) in array not properly typed!",e);
416 return null;
417 }
418 }
419
420 @Override
421 protected NotEnoughAvailableMemory.Match arrayToMatchMutable(final Object[] match) {
422 try {
423 return NotEnoughAvailableMemory.Match.newMutableMatch((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 /**
431 * @return the singleton instance of the query specification of this pattern
432 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
433 *
434 */
435 public static IQuerySpecification<NotEnoughAvailableMemory.Matcher> querySpecification() {
436 return NotEnoughAvailableMemory.instance();
437 }
438 }
439
440 private NotEnoughAvailableMemory() {
441 super(GeneratedPQuery.INSTANCE);
442 }
443
444 /**
445 * @return the singleton instance of the query specification
446 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
447 *
448 */
449 public static NotEnoughAvailableMemory instance() {
450 try{
451 return LazyHolder.INSTANCE;
452 } catch (ExceptionInInitializerError err) {
453 throw processInitializerError(err);
454 }
455 }
456
457 @Override
458 protected NotEnoughAvailableMemory.Matcher instantiate(final ViatraQueryEngine engine) {
459 return NotEnoughAvailableMemory.Matcher.on(engine);
460 }
461
462 @Override
463 public NotEnoughAvailableMemory.Matcher instantiate() {
464 return NotEnoughAvailableMemory.Matcher.create();
465 }
466
467 @Override
468 public NotEnoughAvailableMemory.Match newEmptyMatch() {
469 return NotEnoughAvailableMemory.Match.newEmptyMatch();
470 }
471
472 @Override
473 public NotEnoughAvailableMemory.Match newMatch(final Object... parameters) {
474 return NotEnoughAvailableMemory.Match.newMatch((hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance) parameters[0]);
475 }
476
477 /**
478 * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.NotEnoughAvailableMemory (visibility: PUBLIC, simpleName: NotEnoughAvailableMemory, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.NotEnoughAvailableMemory, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)} to be created
479 * <b>not</b> at the class load time of the outer class,
480 * but rather at the first call to {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.NotEnoughAvailableMemory (visibility: PUBLIC, simpleName: NotEnoughAvailableMemory, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.NotEnoughAvailableMemory, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}.
481 *
482 * <p> This workaround is required e.g. to support recursion.
483 *
484 */
485 private static class LazyHolder {
486 private static final NotEnoughAvailableMemory INSTANCE = new NotEnoughAvailableMemory();
487
488 /**
489 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
490 * This initialization order is required to support indirect recursion.
491 *
492 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
493 *
494 */
495 private static final Object STATIC_INITIALIZER = ensureInitialized();
496
497 public static Object ensureInitialized() {
498 INSTANCE.ensureInitializedInternal();
499 return null;
500 }
501 }
502
503 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
504 private static final NotEnoughAvailableMemory.GeneratedPQuery INSTANCE = new GeneratedPQuery();
505
506 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);
507
508 private final List<PParameter> parameters = Arrays.asList(parameter_Host);
509
510 private GeneratedPQuery() {
511 super(PVisibility.PUBLIC);
512 }
513
514 @Override
515 public String getFullyQualifiedName() {
516 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.notEnoughAvailableMemory";
517 }
518
519 @Override
520 public List<String> getParameterNames() {
521 return Arrays.asList("Host");
522 }
523
524 @Override
525 public List<PParameter> getParameters() {
526 return parameters;
527 }
528
529 @Override
530 public Set<PBody> doGetContainedBodies() {
531 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
532 Set<PBody> bodies = new LinkedHashSet<>();
533 {
534 PBody body = new PBody(this);
535 PVariable var_Host = body.getOrCreateVariableByName("Host");
536 PVariable var_Memory = body.getOrCreateVariableByName("Memory");
537 new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance")));
538 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
539 new ExportedParameter(body, var_Host, parameter_Host)
540 ));
541 // find availableMemory(Host, Memory)
542 new PositivePatternCall(body, Tuples.flatTupleOf(var_Host, var_Memory), AvailableMemory.instance().getInternalQueryRepresentation());
543 // check(Memory < 0)
544 new ExpressionEvaluation(body, new IExpressionEvaluator() {
545
546 @Override
547 public String getShortDescription() {
548 return "Expression evaluation from pattern notEnoughAvailableMemory";
549 }
550
551 @Override
552 public Iterable<String> getInputParameterNames() {
553 return Arrays.asList("Memory");}
554
555 @Override
556 public Object evaluateExpression(IValueProvider provider) throws Exception {
557 Integer Memory = (Integer) provider.getValue("Memory");
558 return evaluateExpression_1_1(Memory);
559 }
560 }, null);
561 bodies.add(body);
562 }
563 {
564 PAnnotation annotation = new PAnnotation("Constraint");
565 annotation.addAttribute("severity", "error");
566 annotation.addAttribute("key", Arrays.asList(new Object[] {
567 new ParameterReference("Host")
568 }));
569 annotation.addAttribute("message", "Insufficient memory available on host.");
570 addAnnotation(annotation);
571 }
572 return bodies;
573 }
574 }
575
576 private static boolean evaluateExpression_1_1(final Integer Memory) {
577 return ((Memory).intValue() < 0);
578 }
579}
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..04066c50
--- /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,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 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 if ("Req".equals(parameterName)) return this.fReq;
94 return null;
95 }
96
97 public Requirement getReq() {
98 return this.fReq;
99 }
100
101 @Override
102 public boolean set(final String parameterName, final Object newValue) {
103 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
104 if ("Req".equals(parameterName) ) {
105 this.fReq = (Requirement) newValue;
106 return true;
107 }
108 return false;
109 }
110
111 public void setReq(final Requirement pReq) {
112 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
113 this.fReq = pReq;
114 }
115
116 @Override
117 public String patternName() {
118 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.requirementNotSatisfied";
119 }
120
121 @Override
122 public List<String> parameterNames() {
123 return RequirementNotSatisfied.Match.parameterNames;
124 }
125
126 @Override
127 public Object[] toArray() {
128 return new Object[]{fReq};
129 }
130
131 @Override
132 public RequirementNotSatisfied.Match toImmutable() {
133 return isMutable() ? newMatch(fReq) : this;
134 }
135
136 @Override
137 public String prettyPrint() {
138 StringBuilder result = new StringBuilder();
139 result.append("\"Req\"=" + prettyPrintValue(fReq));
140 return result.toString();
141 }
142
143 @Override
144 public int hashCode() {
145 return Objects.hash(fReq);
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 RequirementNotSatisfied.Match)) {
156 RequirementNotSatisfied.Match other = (RequirementNotSatisfied.Match) obj;
157 return Objects.equals(fReq, other.fReq);
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 RequirementNotSatisfied specification() {
170 return RequirementNotSatisfied.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 RequirementNotSatisfied.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 pReq the fixed value of pattern parameter Req, or null if not bound.
189 * @return the new, mutable (partial) match object.
190 *
191 */
192 public static RequirementNotSatisfied.Match newMutableMatch(final Requirement pReq) {
193 return new Mutable(pReq);
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 pReq the fixed value of pattern parameter Req, or null if not bound.
201 * @return the (partial) match object.
202 *
203 */
204 public static RequirementNotSatisfied.Match newMatch(final Requirement pReq) {
205 return new Immutable(pReq);
206 }
207
208 private static final class Mutable extends RequirementNotSatisfied.Match {
209 Mutable(final Requirement pReq) {
210 super(pReq);
211 }
212
213 @Override
214 public boolean isMutable() {
215 return true;
216 }
217 }
218
219 private static final class Immutable extends RequirementNotSatisfied.Match {
220 Immutable(final Requirement pReq) {
221 super(pReq);
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.requirementNotSatisfied 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 * {@literal @}Constraint(severity = "error", key = {Req},
243 * message = "Requirement is not satisfied by enough application instances.")
244 * pattern requirementNotSatisfied(Req : Requirement) {
245 * Instances == count find satisfyingInstance(Req, _);
246 * Requirement.count(Req, RequiredCount);
247 * check(Instances {@literal <} RequiredCount);
248 * }
249 * </pre></code>
250 *
251 * @see Match
252 * @see RequirementNotSatisfied
253 *
254 */
255 public static class Matcher extends BaseMatcher<RequirementNotSatisfied.Match> {
256 /**
257 * Initializes the pattern matcher within an existing VIATRA Query engine.
258 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
259 *
260 * @param engine the existing VIATRA Query engine in which this matcher will be created.
261 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
262 *
263 */
264 public static RequirementNotSatisfied.Matcher on(final ViatraQueryEngine engine) {
265 // check if matcher already exists
266 Matcher matcher = engine.getExistingMatcher(querySpecification());
267 if (matcher == null) {
268 matcher = (Matcher)engine.getMatcher(querySpecification());
269 }
270 return matcher;
271 }
272
273 /**
274 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
275 * @return an initialized matcher
276 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
277 *
278 */
279 public static RequirementNotSatisfied.Matcher create() {
280 return new Matcher();
281 }
282
283 private static final int POSITION_REQ = 0;
284
285 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(RequirementNotSatisfied.Matcher.class);
286
287 /**
288 * Initializes the pattern matcher within an existing VIATRA Query engine.
289 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
290 *
291 * @param engine the existing VIATRA Query engine in which this matcher will be created.
292 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
293 *
294 */
295 private Matcher() {
296 super(querySpecification());
297 }
298
299 /**
300 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
301 * @param pReq the fixed value of pattern parameter Req, or null if not bound.
302 * @return matches represented as a Match object.
303 *
304 */
305 public Collection<RequirementNotSatisfied.Match> getAllMatches(final Requirement pReq) {
306 return rawStreamAllMatches(new Object[]{pReq}).collect(Collectors.toSet());
307 }
308
309 /**
310 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
311 * </p>
312 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
313 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
314 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
315 * @param pReq the fixed value of pattern parameter Req, or null if not bound.
316 * @return a stream of matches represented as a Match object.
317 *
318 */
319 public Stream<RequirementNotSatisfied.Match> streamAllMatches(final Requirement pReq) {
320 return rawStreamAllMatches(new Object[]{pReq});
321 }
322
323 /**
324 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
325 * Neither determinism nor randomness of selection is guaranteed.
326 * @param pReq the fixed value of pattern parameter Req, or null if not bound.
327 * @return a match represented as a Match object, or null if no match is found.
328 *
329 */
330 public Optional<RequirementNotSatisfied.Match> getOneArbitraryMatch(final Requirement pReq) {
331 return rawGetOneArbitraryMatch(new Object[]{pReq});
332 }
333
334 /**
335 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
336 * under any possible substitution of the unspecified parameters (if any).
337 * @param pReq the fixed value of pattern parameter Req, or null if not bound.
338 * @return true if the input is a valid (partial) match of the pattern.
339 *
340 */
341 public boolean hasMatch(final Requirement pReq) {
342 return rawHasMatch(new Object[]{pReq});
343 }
344
345 /**
346 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
347 * @param pReq the fixed value of pattern parameter Req, or null if not bound.
348 * @return the number of pattern matches found.
349 *
350 */
351 public int countMatches(final Requirement pReq) {
352 return rawCountMatches(new Object[]{pReq});
353 }
354
355 /**
356 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
357 * Neither determinism nor randomness of selection is guaranteed.
358 * @param pReq the fixed value of pattern parameter Req, or null if not bound.
359 * @param processor the action that will process the selected match.
360 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
361 *
362 */
363 public boolean forOneArbitraryMatch(final Requirement pReq, final Consumer<? super RequirementNotSatisfied.Match> processor) {
364 return rawForOneArbitraryMatch(new Object[]{pReq}, processor);
365 }
366
367 /**
368 * Returns a new (partial) match.
369 * This can be used e.g. to call the matcher with a partial match.
370 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
371 * @param pReq the fixed value of pattern parameter Req, or null if not bound.
372 * @return the (partial) match object.
373 *
374 */
375 public RequirementNotSatisfied.Match newMatch(final Requirement pReq) {
376 return RequirementNotSatisfied.Match.newMatch(pReq);
377 }
378
379 /**
380 * Retrieve the set of values that occur in matches for Req.
381 * @return the Set of all values or empty set if there are no matches
382 *
383 */
384 protected Stream<Requirement> rawStreamAllValuesOfReq(final Object[] parameters) {
385 return rawStreamAllValues(POSITION_REQ, parameters).map(Requirement.class::cast);
386 }
387
388 /**
389 * Retrieve the set of values that occur in matches for Req.
390 * @return the Set of all values or empty set if there are no matches
391 *
392 */
393 public Set<Requirement> getAllValuesOfReq() {
394 return rawStreamAllValuesOfReq(emptyArray()).collect(Collectors.toSet());
395 }
396
397 /**
398 * Retrieve the set of values that occur in matches for Req.
399 * @return the Set of all values or empty set if there are no matches
400 *
401 */
402 public Stream<Requirement> streamAllValuesOfReq() {
403 return rawStreamAllValuesOfReq(emptyArray());
404 }
405
406 @Override
407 protected RequirementNotSatisfied.Match tupleToMatch(final Tuple t) {
408 try {
409 return RequirementNotSatisfied.Match.newMatch((Requirement) t.get(POSITION_REQ));
410 } catch(ClassCastException e) {
411 LOGGER.error("Element(s) in tuple not properly typed!",e);
412 return null;
413 }
414 }
415
416 @Override
417 protected RequirementNotSatisfied.Match arrayToMatch(final Object[] match) {
418 try {
419 return RequirementNotSatisfied.Match.newMatch((Requirement) match[POSITION_REQ]);
420 } catch(ClassCastException e) {
421 LOGGER.error("Element(s) in array not properly typed!",e);
422 return null;
423 }
424 }
425
426 @Override
427 protected RequirementNotSatisfied.Match arrayToMatchMutable(final Object[] match) {
428 try {
429 return RequirementNotSatisfied.Match.newMutableMatch((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 /**
437 * @return the singleton instance of the query specification of this pattern
438 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
439 *
440 */
441 public static IQuerySpecification<RequirementNotSatisfied.Matcher> querySpecification() {
442 return RequirementNotSatisfied.instance();
443 }
444 }
445
446 private RequirementNotSatisfied() {
447 super(GeneratedPQuery.INSTANCE);
448 }
449
450 /**
451 * @return the singleton instance of the query specification
452 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
453 *
454 */
455 public static RequirementNotSatisfied instance() {
456 try{
457 return LazyHolder.INSTANCE;
458 } catch (ExceptionInInitializerError err) {
459 throw processInitializerError(err);
460 }
461 }
462
463 @Override
464 protected RequirementNotSatisfied.Matcher instantiate(final ViatraQueryEngine engine) {
465 return RequirementNotSatisfied.Matcher.on(engine);
466 }
467
468 @Override
469 public RequirementNotSatisfied.Matcher instantiate() {
470 return RequirementNotSatisfied.Matcher.create();
471 }
472
473 @Override
474 public RequirementNotSatisfied.Match newEmptyMatch() {
475 return RequirementNotSatisfied.Match.newEmptyMatch();
476 }
477
478 @Override
479 public RequirementNotSatisfied.Match newMatch(final Object... parameters) {
480 return RequirementNotSatisfied.Match.newMatch((hu.bme.mit.inf.dslreasoner.domains.cps.Requirement) parameters[0]);
481 }
482
483 /**
484 * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.RequirementNotSatisfied (visibility: PUBLIC, simpleName: RequirementNotSatisfied, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.RequirementNotSatisfied, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)} to be created
485 * <b>not</b> at the class load time of the outer class,
486 * but rather at the first call to {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.RequirementNotSatisfied (visibility: PUBLIC, simpleName: RequirementNotSatisfied, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.RequirementNotSatisfied, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}.
487 *
488 * <p> This workaround is required e.g. to support recursion.
489 *
490 */
491 private static class LazyHolder {
492 private static final RequirementNotSatisfied INSTANCE = new RequirementNotSatisfied();
493
494 /**
495 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
496 * This initialization order is required to support indirect recursion.
497 *
498 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
499 *
500 */
501 private static final Object STATIC_INITIALIZER = ensureInitialized();
502
503 public static Object ensureInitialized() {
504 INSTANCE.ensureInitializedInternal();
505 return null;
506 }
507 }
508
509 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
510 private static final RequirementNotSatisfied.GeneratedPQuery INSTANCE = new GeneratedPQuery();
511
512 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);
513
514 private final List<PParameter> parameters = Arrays.asList(parameter_Req);
515
516 private GeneratedPQuery() {
517 super(PVisibility.PUBLIC);
518 }
519
520 @Override
521 public String getFullyQualifiedName() {
522 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.requirementNotSatisfied";
523 }
524
525 @Override
526 public List<String> getParameterNames() {
527 return Arrays.asList("Req");
528 }
529
530 @Override
531 public List<PParameter> getParameters() {
532 return parameters;
533 }
534
535 @Override
536 public Set<PBody> doGetContainedBodies() {
537 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
538 Set<PBody> bodies = new LinkedHashSet<>();
539 {
540 PBody body = new PBody(this);
541 PVariable var_Req = body.getOrCreateVariableByName("Req");
542 PVariable var_Instances = body.getOrCreateVariableByName("Instances");
543 PVariable var___0_ = body.getOrCreateVariableByName("_<0>");
544 PVariable var_RequiredCount = body.getOrCreateVariableByName("RequiredCount");
545 new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "Requirement")));
546 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
547 new ExportedParameter(body, var_Req, parameter_Req)
548 ));
549 // Instances == count find satisfyingInstance(Req, _)
550 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
551 new PatternMatchCounter(body, Tuples.flatTupleOf(var_Req, var___0_), SatisfyingInstance.instance().getInternalQueryRepresentation(), var__virtual_0_);
552 new Equality(body, var_Instances, var__virtual_0_);
553 // Requirement.count(Req, RequiredCount)
554 new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "Requirement")));
555 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
556 new TypeConstraint(body, Tuples.flatTupleOf(var_Req, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "Requirement", "count")));
557 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt")));
558 new Equality(body, var__virtual_1_, var_RequiredCount);
559 // check(Instances < RequiredCount)
560 new ExpressionEvaluation(body, new IExpressionEvaluator() {
561
562 @Override
563 public String getShortDescription() {
564 return "Expression evaluation from pattern requirementNotSatisfied";
565 }
566
567 @Override
568 public Iterable<String> getInputParameterNames() {
569 return Arrays.asList("Instances", "RequiredCount");}
570
571 @Override
572 public Object evaluateExpression(IValueProvider provider) throws Exception {
573 Integer Instances = (Integer) provider.getValue("Instances");
574 Integer RequiredCount = (Integer) provider.getValue("RequiredCount");
575 return evaluateExpression_1_1(Instances, RequiredCount);
576 }
577 }, null);
578 bodies.add(body);
579 }
580 {
581 PAnnotation annotation = new PAnnotation("Constraint");
582 annotation.addAttribute("severity", "error");
583 annotation.addAttribute("key", Arrays.asList(new Object[] {
584 new ParameterReference("Req")
585 }));
586 annotation.addAttribute("message", "Requirement is not satisfied by enough application instances.");
587 addAnnotation(annotation);
588 }
589 return bodies;
590 }
591 }
592
593 private static boolean evaluateExpression_1_1(final Integer Instances, final Integer RequiredCount) {
594 boolean _lessThan = (Instances.compareTo(RequiredCount) < 0);
595 return _lessThan;
596 }
597}
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/TotalHdd.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/TotalHdd.java
new file mode 100644
index 00000000..f91853de
--- /dev/null
+++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/TotalHdd.java
@@ -0,0 +1,706 @@
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.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.emf.ecore.EDataType;
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.EDataTypeInSlotsKey;
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.basicdeferred.Equality;
35import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
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 @}QueryBasedFeature(feature = "totalHdd")
50 * pattern totalHdd(Host : HostInstance, Hdd : EInt) {
51 * HostInstance.type.defaultHdd(Host, Hdd);
52 * }
53 * </pre></code>
54 *
55 * @see Matcher
56 * @see Match
57 *
58 */
59@SuppressWarnings("all")
60public final class TotalHdd extends BaseGeneratedEMFQuerySpecification<TotalHdd.Matcher> {
61 /**
62 * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.totalHdd 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 Integer fHdd;
77
78 private static List<String> parameterNames = makeImmutableList("Host", "Hdd");
79
80 private Match(final HostInstance pHost, final Integer pHdd) {
81 this.fHost = pHost;
82 this.fHdd = pHdd;
83 }
84
85 @Override
86 public Object get(final String parameterName) {
87 if ("Host".equals(parameterName)) return this.fHost;
88 if ("Hdd".equals(parameterName)) return this.fHdd;
89 return null;
90 }
91
92 public HostInstance getHost() {
93 return this.fHost;
94 }
95
96 public Integer getHdd() {
97 return this.fHdd;
98 }
99
100 @Override
101 public boolean set(final String parameterName, final Object newValue) {
102 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
103 if ("Host".equals(parameterName) ) {
104 this.fHost = (HostInstance) newValue;
105 return true;
106 }
107 if ("Hdd".equals(parameterName) ) {
108 this.fHdd = (Integer) newValue;
109 return true;
110 }
111 return false;
112 }
113
114 public void setHost(final HostInstance pHost) {
115 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
116 this.fHost = pHost;
117 }
118
119 public void setHdd(final Integer pHdd) {
120 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
121 this.fHdd = pHdd;
122 }
123
124 @Override
125 public String patternName() {
126 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.totalHdd";
127 }
128
129 @Override
130 public List<String> parameterNames() {
131 return TotalHdd.Match.parameterNames;
132 }
133
134 @Override
135 public Object[] toArray() {
136 return new Object[]{fHost, fHdd};
137 }
138
139 @Override
140 public TotalHdd.Match toImmutable() {
141 return isMutable() ? newMatch(fHost, fHdd) : this;
142 }
143
144 @Override
145 public String prettyPrint() {
146 StringBuilder result = new StringBuilder();
147 result.append("\"Host\"=" + prettyPrintValue(fHost) + ", ");
148 result.append("\"Hdd\"=" + prettyPrintValue(fHdd));
149 return result.toString();
150 }
151
152 @Override
153 public int hashCode() {
154 return Objects.hash(fHost, fHdd);
155 }
156
157 @Override
158 public boolean equals(final Object obj) {
159 if (this == obj)
160 return true;
161 if (obj == null) {
162 return false;
163 }
164 if ((obj instanceof TotalHdd.Match)) {
165 TotalHdd.Match other = (TotalHdd.Match) obj;
166 return Objects.equals(fHost, other.fHost) && Objects.equals(fHdd, other.fHdd);
167 } else {
168 // this should be infrequent
169 if (!(obj instanceof IPatternMatch)) {
170 return false;
171 }
172 IPatternMatch otherSig = (IPatternMatch) obj;
173 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
174 }
175 }
176
177 @Override
178 public TotalHdd specification() {
179 return TotalHdd.instance();
180 }
181
182 /**
183 * Returns an empty, mutable match.
184 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
185 *
186 * @return the empty match.
187 *
188 */
189 public static TotalHdd.Match newEmptyMatch() {
190 return new Mutable(null, null);
191 }
192
193 /**
194 * Returns a mutable (partial) match.
195 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
196 *
197 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
198 * @param pHdd the fixed value of pattern parameter Hdd, or null if not bound.
199 * @return the new, mutable (partial) match object.
200 *
201 */
202 public static TotalHdd.Match newMutableMatch(final HostInstance pHost, final Integer pHdd) {
203 return new Mutable(pHost, pHdd);
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 pHost the fixed value of pattern parameter Host, or null if not bound.
211 * @param pHdd the fixed value of pattern parameter Hdd, or null if not bound.
212 * @return the (partial) match object.
213 *
214 */
215 public static TotalHdd.Match newMatch(final HostInstance pHost, final Integer pHdd) {
216 return new Immutable(pHost, pHdd);
217 }
218
219 private static final class Mutable extends TotalHdd.Match {
220 Mutable(final HostInstance pHost, final Integer pHdd) {
221 super(pHost, pHdd);
222 }
223
224 @Override
225 public boolean isMutable() {
226 return true;
227 }
228 }
229
230 private static final class Immutable extends TotalHdd.Match {
231 Immutable(final HostInstance pHost, final Integer pHdd) {
232 super(pHost, pHdd);
233 }
234
235 @Override
236 public boolean isMutable() {
237 return false;
238 }
239 }
240 }
241
242 /**
243 * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.totalHdd pattern,
244 * providing pattern-specific query methods.
245 *
246 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
247 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
248 *
249 * <p>Matches of the pattern will be represented as {@link Match}.
250 *
251 * <p>Original source:
252 * <code><pre>
253 * {@literal @}QueryBasedFeature(feature = "totalHdd")
254 * pattern totalHdd(Host : HostInstance, Hdd : EInt) {
255 * HostInstance.type.defaultHdd(Host, Hdd);
256 * }
257 * </pre></code>
258 *
259 * @see Match
260 * @see TotalHdd
261 *
262 */
263 public static class Matcher extends BaseMatcher<TotalHdd.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 TotalHdd.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 TotalHdd.Matcher create() {
288 return new Matcher();
289 }
290
291 private static final int POSITION_HOST = 0;
292
293 private static final int POSITION_HDD = 1;
294
295 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(TotalHdd.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 pHost the fixed value of pattern parameter Host, or null if not bound.
312 * @param pHdd the fixed value of pattern parameter Hdd, or null if not bound.
313 * @return matches represented as a Match object.
314 *
315 */
316 public Collection<TotalHdd.Match> getAllMatches(final HostInstance pHost, final Integer pHdd) {
317 return rawStreamAllMatches(new Object[]{pHost, pHdd}).collect(Collectors.toSet());
318 }
319
320 /**
321 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
322 * </p>
323 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
324 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
325 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
326 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
327 * @param pHdd the fixed value of pattern parameter Hdd, or null if not bound.
328 * @return a stream of matches represented as a Match object.
329 *
330 */
331 public Stream<TotalHdd.Match> streamAllMatches(final HostInstance pHost, final Integer pHdd) {
332 return rawStreamAllMatches(new Object[]{pHost, pHdd});
333 }
334
335 /**
336 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
337 * Neither determinism nor randomness of selection is guaranteed.
338 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
339 * @param pHdd the fixed value of pattern parameter Hdd, or null if not bound.
340 * @return a match represented as a Match object, or null if no match is found.
341 *
342 */
343 public Optional<TotalHdd.Match> getOneArbitraryMatch(final HostInstance pHost, final Integer pHdd) {
344 return rawGetOneArbitraryMatch(new Object[]{pHost, pHdd});
345 }
346
347 /**
348 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
349 * under any possible substitution of the unspecified parameters (if any).
350 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
351 * @param pHdd the fixed value of pattern parameter Hdd, or null if not bound.
352 * @return true if the input is a valid (partial) match of the pattern.
353 *
354 */
355 public boolean hasMatch(final HostInstance pHost, final Integer pHdd) {
356 return rawHasMatch(new Object[]{pHost, pHdd});
357 }
358
359 /**
360 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
361 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
362 * @param pHdd the fixed value of pattern parameter Hdd, or null if not bound.
363 * @return the number of pattern matches found.
364 *
365 */
366 public int countMatches(final HostInstance pHost, final Integer pHdd) {
367 return rawCountMatches(new Object[]{pHost, pHdd});
368 }
369
370 /**
371 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
372 * Neither determinism nor randomness of selection is guaranteed.
373 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
374 * @param pHdd the fixed value of pattern parameter Hdd, or null if not bound.
375 * @param processor the action that will process the selected match.
376 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
377 *
378 */
379 public boolean forOneArbitraryMatch(final HostInstance pHost, final Integer pHdd, final Consumer<? super TotalHdd.Match> processor) {
380 return rawForOneArbitraryMatch(new Object[]{pHost, pHdd}, processor);
381 }
382
383 /**
384 * Returns a new (partial) match.
385 * This can be used e.g. to call the matcher with a partial match.
386 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
387 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
388 * @param pHdd the fixed value of pattern parameter Hdd, or null if not bound.
389 * @return the (partial) match object.
390 *
391 */
392 public TotalHdd.Match newMatch(final HostInstance pHost, final Integer pHdd) {
393 return TotalHdd.Match.newMatch(pHost, pHdd);
394 }
395
396 /**
397 * Retrieve the set of values that occur in matches for Host.
398 * @return the Set of all values or empty set if there are no matches
399 *
400 */
401 protected Stream<HostInstance> rawStreamAllValuesOfHost(final Object[] parameters) {
402 return rawStreamAllValues(POSITION_HOST, parameters).map(HostInstance.class::cast);
403 }
404
405 /**
406 * Retrieve the set of values that occur in matches for Host.
407 * @return the Set of all values or empty set if there are no matches
408 *
409 */
410 public Set<HostInstance> getAllValuesOfHost() {
411 return rawStreamAllValuesOfHost(emptyArray()).collect(Collectors.toSet());
412 }
413
414 /**
415 * Retrieve the set of values that occur in matches for Host.
416 * @return the Set of all values or empty set if there are no matches
417 *
418 */
419 public Stream<HostInstance> streamAllValuesOfHost() {
420 return rawStreamAllValuesOfHost(emptyArray());
421 }
422
423 /**
424 * Retrieve the set of values that occur in matches for Host.
425 * </p>
426 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
427 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
428 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
429 *
430 * @return the Stream of all values or empty set if there are no matches
431 *
432 */
433 public Stream<HostInstance> streamAllValuesOfHost(final TotalHdd.Match partialMatch) {
434 return rawStreamAllValuesOfHost(partialMatch.toArray());
435 }
436
437 /**
438 * Retrieve the set of values that occur in matches for Host.
439 * </p>
440 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
441 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
442 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
443 *
444 * @return the Stream of all values or empty set if there are no matches
445 *
446 */
447 public Stream<HostInstance> streamAllValuesOfHost(final Integer pHdd) {
448 return rawStreamAllValuesOfHost(new Object[]{null, pHdd});
449 }
450
451 /**
452 * Retrieve the set of values that occur in matches for Host.
453 * @return the Set of all values or empty set if there are no matches
454 *
455 */
456 public Set<HostInstance> getAllValuesOfHost(final TotalHdd.Match partialMatch) {
457 return rawStreamAllValuesOfHost(partialMatch.toArray()).collect(Collectors.toSet());
458 }
459
460 /**
461 * Retrieve the set of values that occur in matches for Host.
462 * @return the Set of all values or empty set if there are no matches
463 *
464 */
465 public Set<HostInstance> getAllValuesOfHost(final Integer pHdd) {
466 return rawStreamAllValuesOfHost(new Object[]{null, pHdd}).collect(Collectors.toSet());
467 }
468
469 /**
470 * Retrieve the set of values that occur in matches for Hdd.
471 * @return the Set of all values or empty set if there are no matches
472 *
473 */
474 protected Stream<Integer> rawStreamAllValuesOfHdd(final Object[] parameters) {
475 return rawStreamAllValues(POSITION_HDD, parameters).map(Integer.class::cast);
476 }
477
478 /**
479 * Retrieve the set of values that occur in matches for Hdd.
480 * @return the Set of all values or empty set if there are no matches
481 *
482 */
483 public Set<Integer> getAllValuesOfHdd() {
484 return rawStreamAllValuesOfHdd(emptyArray()).collect(Collectors.toSet());
485 }
486
487 /**
488 * Retrieve the set of values that occur in matches for Hdd.
489 * @return the Set of all values or empty set if there are no matches
490 *
491 */
492 public Stream<Integer> streamAllValuesOfHdd() {
493 return rawStreamAllValuesOfHdd(emptyArray());
494 }
495
496 /**
497 * Retrieve the set of values that occur in matches for Hdd.
498 * </p>
499 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
500 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
501 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
502 *
503 * @return the Stream of all values or empty set if there are no matches
504 *
505 */
506 public Stream<Integer> streamAllValuesOfHdd(final TotalHdd.Match partialMatch) {
507 return rawStreamAllValuesOfHdd(partialMatch.toArray());
508 }
509
510 /**
511 * Retrieve the set of values that occur in matches for Hdd.
512 * </p>
513 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
514 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
515 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
516 *
517 * @return the Stream of all values or empty set if there are no matches
518 *
519 */
520 public Stream<Integer> streamAllValuesOfHdd(final HostInstance pHost) {
521 return rawStreamAllValuesOfHdd(new Object[]{pHost, null});
522 }
523
524 /**
525 * Retrieve the set of values that occur in matches for Hdd.
526 * @return the Set of all values or empty set if there are no matches
527 *
528 */
529 public Set<Integer> getAllValuesOfHdd(final TotalHdd.Match partialMatch) {
530 return rawStreamAllValuesOfHdd(partialMatch.toArray()).collect(Collectors.toSet());
531 }
532
533 /**
534 * Retrieve the set of values that occur in matches for Hdd.
535 * @return the Set of all values or empty set if there are no matches
536 *
537 */
538 public Set<Integer> getAllValuesOfHdd(final HostInstance pHost) {
539 return rawStreamAllValuesOfHdd(new Object[]{pHost, null}).collect(Collectors.toSet());
540 }
541
542 @Override
543 protected TotalHdd.Match tupleToMatch(final Tuple t) {
544 try {
545 return TotalHdd.Match.newMatch((HostInstance) t.get(POSITION_HOST), (Integer) t.get(POSITION_HDD));
546 } catch(ClassCastException e) {
547 LOGGER.error("Element(s) in tuple not properly typed!",e);
548 return null;
549 }
550 }
551
552 @Override
553 protected TotalHdd.Match arrayToMatch(final Object[] match) {
554 try {
555 return TotalHdd.Match.newMatch((HostInstance) match[POSITION_HOST], (Integer) match[POSITION_HDD]);
556 } catch(ClassCastException e) {
557 LOGGER.error("Element(s) in array not properly typed!",e);
558 return null;
559 }
560 }
561
562 @Override
563 protected TotalHdd.Match arrayToMatchMutable(final Object[] match) {
564 try {
565 return TotalHdd.Match.newMutableMatch((HostInstance) match[POSITION_HOST], (Integer) match[POSITION_HDD]);
566 } catch(ClassCastException e) {
567 LOGGER.error("Element(s) in array not properly typed!",e);
568 return null;
569 }
570 }
571
572 /**
573 * @return the singleton instance of the query specification of this pattern
574 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
575 *
576 */
577 public static IQuerySpecification<TotalHdd.Matcher> querySpecification() {
578 return TotalHdd.instance();
579 }
580 }
581
582 private TotalHdd() {
583 super(GeneratedPQuery.INSTANCE);
584 }
585
586 /**
587 * @return the singleton instance of the query specification
588 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
589 *
590 */
591 public static TotalHdd instance() {
592 try{
593 return LazyHolder.INSTANCE;
594 } catch (ExceptionInInitializerError err) {
595 throw processInitializerError(err);
596 }
597 }
598
599 @Override
600 protected TotalHdd.Matcher instantiate(final ViatraQueryEngine engine) {
601 return TotalHdd.Matcher.on(engine);
602 }
603
604 @Override
605 public TotalHdd.Matcher instantiate() {
606 return TotalHdd.Matcher.create();
607 }
608
609 @Override
610 public TotalHdd.Match newEmptyMatch() {
611 return TotalHdd.Match.newEmptyMatch();
612 }
613
614 @Override
615 public TotalHdd.Match newMatch(final Object... parameters) {
616 return TotalHdd.Match.newMatch((hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance) parameters[0], (java.lang.Integer) parameters[1]);
617 }
618
619 /**
620 * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.TotalHdd (visibility: PUBLIC, simpleName: TotalHdd, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.TotalHdd, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)} to be created
621 * <b>not</b> at the class load time of the outer class,
622 * but rather at the first call to {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.TotalHdd (visibility: PUBLIC, simpleName: TotalHdd, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.TotalHdd, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}.
623 *
624 * <p> This workaround is required e.g. to support recursion.
625 *
626 */
627 private static class LazyHolder {
628 private static final TotalHdd INSTANCE = new TotalHdd();
629
630 /**
631 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
632 * This initialization order is required to support indirect recursion.
633 *
634 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
635 *
636 */
637 private static final Object STATIC_INITIALIZER = ensureInitialized();
638
639 public static Object ensureInitialized() {
640 INSTANCE.ensureInitializedInternal();
641 return null;
642 }
643 }
644
645 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
646 private static final TotalHdd.GeneratedPQuery INSTANCE = new GeneratedPQuery();
647
648 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);
649
650 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);
651
652 private final List<PParameter> parameters = Arrays.asList(parameter_Host, parameter_Hdd);
653
654 private GeneratedPQuery() {
655 super(PVisibility.PUBLIC);
656 }
657
658 @Override
659 public String getFullyQualifiedName() {
660 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.totalHdd";
661 }
662
663 @Override
664 public List<String> getParameterNames() {
665 return Arrays.asList("Host","Hdd");
666 }
667
668 @Override
669 public List<PParameter> getParameters() {
670 return parameters;
671 }
672
673 @Override
674 public Set<PBody> doGetContainedBodies() {
675 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
676 Set<PBody> bodies = new LinkedHashSet<>();
677 {
678 PBody body = new PBody(this);
679 PVariable var_Host = body.getOrCreateVariableByName("Host");
680 PVariable var_Hdd = body.getOrCreateVariableByName("Hdd");
681 new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance")));
682 new TypeConstraint(body, Tuples.flatTupleOf(var_Hdd), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt")));
683 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
684 new ExportedParameter(body, var_Host, parameter_Host),
685 new ExportedParameter(body, var_Hdd, parameter_Hdd)
686 ));
687 // HostInstance.type.defaultHdd(Host, Hdd)
688 new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance")));
689 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
690 new TypeConstraint(body, Tuples.flatTupleOf(var_Host, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "HostInstance", "type")));
691 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostType")));
692 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
693 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "HostType", "defaultHdd")));
694 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt")));
695 new Equality(body, var__virtual_1_, var_Hdd);
696 bodies.add(body);
697 }
698 {
699 PAnnotation annotation = new PAnnotation("QueryBasedFeature");
700 annotation.addAttribute("feature", "totalHdd");
701 addAnnotation(annotation);
702 }
703 return bodies;
704 }
705 }
706}
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/TotalMemory.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/TotalMemory.java
new file mode 100644
index 00000000..e8a11e36
--- /dev/null
+++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/TotalMemory.java
@@ -0,0 +1,706 @@
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.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.emf.ecore.EDataType;
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.EDataTypeInSlotsKey;
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.basicdeferred.Equality;
35import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
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 @}QueryBasedFeature(feature = "totalMemory")
50 * pattern totalMemory(Host : HostInstance, Memory : EInt) {
51 * HostInstance.type.defaultMemory(Host, Memory);
52 * }
53 * </pre></code>
54 *
55 * @see Matcher
56 * @see Match
57 *
58 */
59@SuppressWarnings("all")
60public final class TotalMemory extends BaseGeneratedEMFQuerySpecification<TotalMemory.Matcher> {
61 /**
62 * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.totalMemory 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 Integer fMemory;
77
78 private static List<String> parameterNames = makeImmutableList("Host", "Memory");
79
80 private Match(final HostInstance pHost, final Integer pMemory) {
81 this.fHost = pHost;
82 this.fMemory = pMemory;
83 }
84
85 @Override
86 public Object get(final String parameterName) {
87 if ("Host".equals(parameterName)) return this.fHost;
88 if ("Memory".equals(parameterName)) return this.fMemory;
89 return null;
90 }
91
92 public HostInstance getHost() {
93 return this.fHost;
94 }
95
96 public Integer getMemory() {
97 return this.fMemory;
98 }
99
100 @Override
101 public boolean set(final String parameterName, final Object newValue) {
102 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
103 if ("Host".equals(parameterName) ) {
104 this.fHost = (HostInstance) newValue;
105 return true;
106 }
107 if ("Memory".equals(parameterName) ) {
108 this.fMemory = (Integer) newValue;
109 return true;
110 }
111 return false;
112 }
113
114 public void setHost(final HostInstance pHost) {
115 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
116 this.fHost = pHost;
117 }
118
119 public void setMemory(final Integer pMemory) {
120 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
121 this.fMemory = pMemory;
122 }
123
124 @Override
125 public String patternName() {
126 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.totalMemory";
127 }
128
129 @Override
130 public List<String> parameterNames() {
131 return TotalMemory.Match.parameterNames;
132 }
133
134 @Override
135 public Object[] toArray() {
136 return new Object[]{fHost, fMemory};
137 }
138
139 @Override
140 public TotalMemory.Match toImmutable() {
141 return isMutable() ? newMatch(fHost, fMemory) : this;
142 }
143
144 @Override
145 public String prettyPrint() {
146 StringBuilder result = new StringBuilder();
147 result.append("\"Host\"=" + prettyPrintValue(fHost) + ", ");
148 result.append("\"Memory\"=" + prettyPrintValue(fMemory));
149 return result.toString();
150 }
151
152 @Override
153 public int hashCode() {
154 return Objects.hash(fHost, fMemory);
155 }
156
157 @Override
158 public boolean equals(final Object obj) {
159 if (this == obj)
160 return true;
161 if (obj == null) {
162 return false;
163 }
164 if ((obj instanceof TotalMemory.Match)) {
165 TotalMemory.Match other = (TotalMemory.Match) obj;
166 return Objects.equals(fHost, other.fHost) && Objects.equals(fMemory, other.fMemory);
167 } else {
168 // this should be infrequent
169 if (!(obj instanceof IPatternMatch)) {
170 return false;
171 }
172 IPatternMatch otherSig = (IPatternMatch) obj;
173 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
174 }
175 }
176
177 @Override
178 public TotalMemory specification() {
179 return TotalMemory.instance();
180 }
181
182 /**
183 * Returns an empty, mutable match.
184 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
185 *
186 * @return the empty match.
187 *
188 */
189 public static TotalMemory.Match newEmptyMatch() {
190 return new Mutable(null, null);
191 }
192
193 /**
194 * Returns a mutable (partial) match.
195 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
196 *
197 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
198 * @param pMemory the fixed value of pattern parameter Memory, or null if not bound.
199 * @return the new, mutable (partial) match object.
200 *
201 */
202 public static TotalMemory.Match newMutableMatch(final HostInstance pHost, final Integer pMemory) {
203 return new Mutable(pHost, pMemory);
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 pHost the fixed value of pattern parameter Host, or null if not bound.
211 * @param pMemory the fixed value of pattern parameter Memory, or null if not bound.
212 * @return the (partial) match object.
213 *
214 */
215 public static TotalMemory.Match newMatch(final HostInstance pHost, final Integer pMemory) {
216 return new Immutable(pHost, pMemory);
217 }
218
219 private static final class Mutable extends TotalMemory.Match {
220 Mutable(final HostInstance pHost, final Integer pMemory) {
221 super(pHost, pMemory);
222 }
223
224 @Override
225 public boolean isMutable() {
226 return true;
227 }
228 }
229
230 private static final class Immutable extends TotalMemory.Match {
231 Immutable(final HostInstance pHost, final Integer pMemory) {
232 super(pHost, pMemory);
233 }
234
235 @Override
236 public boolean isMutable() {
237 return false;
238 }
239 }
240 }
241
242 /**
243 * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.totalMemory pattern,
244 * providing pattern-specific query methods.
245 *
246 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
247 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
248 *
249 * <p>Matches of the pattern will be represented as {@link Match}.
250 *
251 * <p>Original source:
252 * <code><pre>
253 * {@literal @}QueryBasedFeature(feature = "totalMemory")
254 * pattern totalMemory(Host : HostInstance, Memory : EInt) {
255 * HostInstance.type.defaultMemory(Host, Memory);
256 * }
257 * </pre></code>
258 *
259 * @see Match
260 * @see TotalMemory
261 *
262 */
263 public static class Matcher extends BaseMatcher<TotalMemory.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 TotalMemory.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 TotalMemory.Matcher create() {
288 return new Matcher();
289 }
290
291 private static final int POSITION_HOST = 0;
292
293 private static final int POSITION_MEMORY = 1;
294
295 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(TotalMemory.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 pHost the fixed value of pattern parameter Host, or null if not bound.
312 * @param pMemory the fixed value of pattern parameter Memory, or null if not bound.
313 * @return matches represented as a Match object.
314 *
315 */
316 public Collection<TotalMemory.Match> getAllMatches(final HostInstance pHost, final Integer pMemory) {
317 return rawStreamAllMatches(new Object[]{pHost, pMemory}).collect(Collectors.toSet());
318 }
319
320 /**
321 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
322 * </p>
323 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
324 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
325 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
326 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
327 * @param pMemory the fixed value of pattern parameter Memory, or null if not bound.
328 * @return a stream of matches represented as a Match object.
329 *
330 */
331 public Stream<TotalMemory.Match> streamAllMatches(final HostInstance pHost, final Integer pMemory) {
332 return rawStreamAllMatches(new Object[]{pHost, pMemory});
333 }
334
335 /**
336 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
337 * Neither determinism nor randomness of selection is guaranteed.
338 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
339 * @param pMemory the fixed value of pattern parameter Memory, or null if not bound.
340 * @return a match represented as a Match object, or null if no match is found.
341 *
342 */
343 public Optional<TotalMemory.Match> getOneArbitraryMatch(final HostInstance pHost, final Integer pMemory) {
344 return rawGetOneArbitraryMatch(new Object[]{pHost, pMemory});
345 }
346
347 /**
348 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
349 * under any possible substitution of the unspecified parameters (if any).
350 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
351 * @param pMemory the fixed value of pattern parameter Memory, or null if not bound.
352 * @return true if the input is a valid (partial) match of the pattern.
353 *
354 */
355 public boolean hasMatch(final HostInstance pHost, final Integer pMemory) {
356 return rawHasMatch(new Object[]{pHost, pMemory});
357 }
358
359 /**
360 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
361 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
362 * @param pMemory the fixed value of pattern parameter Memory, or null if not bound.
363 * @return the number of pattern matches found.
364 *
365 */
366 public int countMatches(final HostInstance pHost, final Integer pMemory) {
367 return rawCountMatches(new Object[]{pHost, pMemory});
368 }
369
370 /**
371 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
372 * Neither determinism nor randomness of selection is guaranteed.
373 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
374 * @param pMemory the fixed value of pattern parameter Memory, or null if not bound.
375 * @param processor the action that will process the selected match.
376 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
377 *
378 */
379 public boolean forOneArbitraryMatch(final HostInstance pHost, final Integer pMemory, final Consumer<? super TotalMemory.Match> processor) {
380 return rawForOneArbitraryMatch(new Object[]{pHost, pMemory}, processor);
381 }
382
383 /**
384 * Returns a new (partial) match.
385 * This can be used e.g. to call the matcher with a partial match.
386 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
387 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
388 * @param pMemory the fixed value of pattern parameter Memory, or null if not bound.
389 * @return the (partial) match object.
390 *
391 */
392 public TotalMemory.Match newMatch(final HostInstance pHost, final Integer pMemory) {
393 return TotalMemory.Match.newMatch(pHost, pMemory);
394 }
395
396 /**
397 * Retrieve the set of values that occur in matches for Host.
398 * @return the Set of all values or empty set if there are no matches
399 *
400 */
401 protected Stream<HostInstance> rawStreamAllValuesOfHost(final Object[] parameters) {
402 return rawStreamAllValues(POSITION_HOST, parameters).map(HostInstance.class::cast);
403 }
404
405 /**
406 * Retrieve the set of values that occur in matches for Host.
407 * @return the Set of all values or empty set if there are no matches
408 *
409 */
410 public Set<HostInstance> getAllValuesOfHost() {
411 return rawStreamAllValuesOfHost(emptyArray()).collect(Collectors.toSet());
412 }
413
414 /**
415 * Retrieve the set of values that occur in matches for Host.
416 * @return the Set of all values or empty set if there are no matches
417 *
418 */
419 public Stream<HostInstance> streamAllValuesOfHost() {
420 return rawStreamAllValuesOfHost(emptyArray());
421 }
422
423 /**
424 * Retrieve the set of values that occur in matches for Host.
425 * </p>
426 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
427 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
428 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
429 *
430 * @return the Stream of all values or empty set if there are no matches
431 *
432 */
433 public Stream<HostInstance> streamAllValuesOfHost(final TotalMemory.Match partialMatch) {
434 return rawStreamAllValuesOfHost(partialMatch.toArray());
435 }
436
437 /**
438 * Retrieve the set of values that occur in matches for Host.
439 * </p>
440 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
441 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
442 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
443 *
444 * @return the Stream of all values or empty set if there are no matches
445 *
446 */
447 public Stream<HostInstance> streamAllValuesOfHost(final Integer pMemory) {
448 return rawStreamAllValuesOfHost(new Object[]{null, pMemory});
449 }
450
451 /**
452 * Retrieve the set of values that occur in matches for Host.
453 * @return the Set of all values or empty set if there are no matches
454 *
455 */
456 public Set<HostInstance> getAllValuesOfHost(final TotalMemory.Match partialMatch) {
457 return rawStreamAllValuesOfHost(partialMatch.toArray()).collect(Collectors.toSet());
458 }
459
460 /**
461 * Retrieve the set of values that occur in matches for Host.
462 * @return the Set of all values or empty set if there are no matches
463 *
464 */
465 public Set<HostInstance> getAllValuesOfHost(final Integer pMemory) {
466 return rawStreamAllValuesOfHost(new Object[]{null, pMemory}).collect(Collectors.toSet());
467 }
468
469 /**
470 * Retrieve the set of values that occur in matches for Memory.
471 * @return the Set of all values or empty set if there are no matches
472 *
473 */
474 protected Stream<Integer> rawStreamAllValuesOfMemory(final Object[] parameters) {
475 return rawStreamAllValues(POSITION_MEMORY, parameters).map(Integer.class::cast);
476 }
477
478 /**
479 * Retrieve the set of values that occur in matches for Memory.
480 * @return the Set of all values or empty set if there are no matches
481 *
482 */
483 public Set<Integer> getAllValuesOfMemory() {
484 return rawStreamAllValuesOfMemory(emptyArray()).collect(Collectors.toSet());
485 }
486
487 /**
488 * Retrieve the set of values that occur in matches for Memory.
489 * @return the Set of all values or empty set if there are no matches
490 *
491 */
492 public Stream<Integer> streamAllValuesOfMemory() {
493 return rawStreamAllValuesOfMemory(emptyArray());
494 }
495
496 /**
497 * Retrieve the set of values that occur in matches for Memory.
498 * </p>
499 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
500 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
501 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
502 *
503 * @return the Stream of all values or empty set if there are no matches
504 *
505 */
506 public Stream<Integer> streamAllValuesOfMemory(final TotalMemory.Match partialMatch) {
507 return rawStreamAllValuesOfMemory(partialMatch.toArray());
508 }
509
510 /**
511 * Retrieve the set of values that occur in matches for Memory.
512 * </p>
513 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
514 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
515 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
516 *
517 * @return the Stream of all values or empty set if there are no matches
518 *
519 */
520 public Stream<Integer> streamAllValuesOfMemory(final HostInstance pHost) {
521 return rawStreamAllValuesOfMemory(new Object[]{pHost, null});
522 }
523
524 /**
525 * Retrieve the set of values that occur in matches for Memory.
526 * @return the Set of all values or empty set if there are no matches
527 *
528 */
529 public Set<Integer> getAllValuesOfMemory(final TotalMemory.Match partialMatch) {
530 return rawStreamAllValuesOfMemory(partialMatch.toArray()).collect(Collectors.toSet());
531 }
532
533 /**
534 * Retrieve the set of values that occur in matches for Memory.
535 * @return the Set of all values or empty set if there are no matches
536 *
537 */
538 public Set<Integer> getAllValuesOfMemory(final HostInstance pHost) {
539 return rawStreamAllValuesOfMemory(new Object[]{pHost, null}).collect(Collectors.toSet());
540 }
541
542 @Override
543 protected TotalMemory.Match tupleToMatch(final Tuple t) {
544 try {
545 return TotalMemory.Match.newMatch((HostInstance) t.get(POSITION_HOST), (Integer) t.get(POSITION_MEMORY));
546 } catch(ClassCastException e) {
547 LOGGER.error("Element(s) in tuple not properly typed!",e);
548 return null;
549 }
550 }
551
552 @Override
553 protected TotalMemory.Match arrayToMatch(final Object[] match) {
554 try {
555 return TotalMemory.Match.newMatch((HostInstance) match[POSITION_HOST], (Integer) match[POSITION_MEMORY]);
556 } catch(ClassCastException e) {
557 LOGGER.error("Element(s) in array not properly typed!",e);
558 return null;
559 }
560 }
561
562 @Override
563 protected TotalMemory.Match arrayToMatchMutable(final Object[] match) {
564 try {
565 return TotalMemory.Match.newMutableMatch((HostInstance) match[POSITION_HOST], (Integer) match[POSITION_MEMORY]);
566 } catch(ClassCastException e) {
567 LOGGER.error("Element(s) in array not properly typed!",e);
568 return null;
569 }
570 }
571
572 /**
573 * @return the singleton instance of the query specification of this pattern
574 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
575 *
576 */
577 public static IQuerySpecification<TotalMemory.Matcher> querySpecification() {
578 return TotalMemory.instance();
579 }
580 }
581
582 private TotalMemory() {
583 super(GeneratedPQuery.INSTANCE);
584 }
585
586 /**
587 * @return the singleton instance of the query specification
588 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
589 *
590 */
591 public static TotalMemory instance() {
592 try{
593 return LazyHolder.INSTANCE;
594 } catch (ExceptionInInitializerError err) {
595 throw processInitializerError(err);
596 }
597 }
598
599 @Override
600 protected TotalMemory.Matcher instantiate(final ViatraQueryEngine engine) {
601 return TotalMemory.Matcher.on(engine);
602 }
603
604 @Override
605 public TotalMemory.Matcher instantiate() {
606 return TotalMemory.Matcher.create();
607 }
608
609 @Override
610 public TotalMemory.Match newEmptyMatch() {
611 return TotalMemory.Match.newEmptyMatch();
612 }
613
614 @Override
615 public TotalMemory.Match newMatch(final Object... parameters) {
616 return TotalMemory.Match.newMatch((hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance) parameters[0], (java.lang.Integer) parameters[1]);
617 }
618
619 /**
620 * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.TotalMemory (visibility: PUBLIC, simpleName: TotalMemory, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.TotalMemory, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)} to be created
621 * <b>not</b> at the class load time of the outer class,
622 * but rather at the first call to {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.TotalMemory (visibility: PUBLIC, simpleName: TotalMemory, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.TotalMemory, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}.
623 *
624 * <p> This workaround is required e.g. to support recursion.
625 *
626 */
627 private static class LazyHolder {
628 private static final TotalMemory INSTANCE = new TotalMemory();
629
630 /**
631 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
632 * This initialization order is required to support indirect recursion.
633 *
634 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
635 *
636 */
637 private static final Object STATIC_INITIALIZER = ensureInitialized();
638
639 public static Object ensureInitialized() {
640 INSTANCE.ensureInitializedInternal();
641 return null;
642 }
643 }
644
645 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
646 private static final TotalMemory.GeneratedPQuery INSTANCE = new GeneratedPQuery();
647
648 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);
649
650 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);
651
652 private final List<PParameter> parameters = Arrays.asList(parameter_Host, parameter_Memory);
653
654 private GeneratedPQuery() {
655 super(PVisibility.PUBLIC);
656 }
657
658 @Override
659 public String getFullyQualifiedName() {
660 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.totalMemory";
661 }
662
663 @Override
664 public List<String> getParameterNames() {
665 return Arrays.asList("Host","Memory");
666 }
667
668 @Override
669 public List<PParameter> getParameters() {
670 return parameters;
671 }
672
673 @Override
674 public Set<PBody> doGetContainedBodies() {
675 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
676 Set<PBody> bodies = new LinkedHashSet<>();
677 {
678 PBody body = new PBody(this);
679 PVariable var_Host = body.getOrCreateVariableByName("Host");
680 PVariable var_Memory = body.getOrCreateVariableByName("Memory");
681 new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance")));
682 new TypeConstraint(body, Tuples.flatTupleOf(var_Memory), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt")));
683 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
684 new ExportedParameter(body, var_Host, parameter_Host),
685 new ExportedParameter(body, var_Memory, parameter_Memory)
686 ));
687 // HostInstance.type.defaultMemory(Host, Memory)
688 new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance")));
689 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
690 new TypeConstraint(body, Tuples.flatTupleOf(var_Host, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "HostInstance", "type")));
691 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostType")));
692 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
693 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "HostType", "defaultMemory")));
694 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt")));
695 new Equality(body, var__virtual_1_, var_Memory);
696 bodies.add(body);
697 }
698 {
699 PAnnotation annotation = new PAnnotation("QueryBasedFeature");
700 annotation.addAttribute("feature", "totalMemory");
701 addAnnotation(annotation);
702 }
703 return bodies;
704 }
705 }
706}
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..2f593811
--- /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,11 @@
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
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..5f6d161d
--- /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,105 @@
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.AllocationWithoutResourceRequirement;
7import hu.bme.mit.inf.dslreasoner.domains.cps.queries.AvailableHdd;
8import hu.bme.mit.inf.dslreasoner.domains.cps.queries.AvailableMemory;
9import hu.bme.mit.inf.dslreasoner.domains.cps.queries.AverageFreeHddMetric;
10import hu.bme.mit.inf.dslreasoner.domains.cps.queries.AverageFreeMemoryMetric;
11import hu.bme.mit.inf.dslreasoner.domains.cps.queries.CostMetric;
12import hu.bme.mit.inf.dslreasoner.domains.cps.queries.CpsApplications;
13import hu.bme.mit.inf.dslreasoner.domains.cps.queries.CpsCost;
14import hu.bme.mit.inf.dslreasoner.domains.cps.queries.CpsHosts;
15import hu.bme.mit.inf.dslreasoner.domains.cps.queries.InstanceDoesNotSatisfyRequirement;
16import hu.bme.mit.inf.dslreasoner.domains.cps.queries.NotEnoughAvailableHdd;
17import hu.bme.mit.inf.dslreasoner.domains.cps.queries.NotEnoughAvailableMemory;
18import hu.bme.mit.inf.dslreasoner.domains.cps.queries.RequirementNotSatisfied;
19import hu.bme.mit.inf.dslreasoner.domains.cps.queries.TotalHdd;
20import hu.bme.mit.inf.dslreasoner.domains.cps.queries.TotalMemory;
21import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.FreeHddPercentage;
22import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.FreeMemoryPercentage;
23import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.HddRequirement;
24import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.HostInstanceCost;
25import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.MemoryRequirement;
26import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.ResourceRequirement;
27import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.SatisfyingInstance;
28import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedPatternGroup;
29
30/**
31 * A pattern group formed of all patterns defined in CpsQueries.vql.
32 *
33 * <p>A private group that includes private patterns as well. Only intended use case is for pattern testing.
34 *
35 * <p> From package hu.bme.mit.inf.dslreasoner.domains.cps.queries, the group contains the definition of the following patterns: <ul>
36 * <li>cpsApplications</li>
37 * <li>cpsHosts</li>
38 * <li>totalMemory</li>
39 * <li>totalHdd</li>
40 * <li>availableMemory</li>
41 * <li>memoryRequirement</li>
42 * <li>availableHdd</li>
43 * <li>hddRequirement</li>
44 * <li>resourceRequirement</li>
45 * <li>allocationWithoutResourceRequirement</li>
46 * <li>notEnoughAvailableMemory</li>
47 * <li>notEnoughAvailableHdd</li>
48 * <li>instanceDoesNotSatisfyRequirement</li>
49 * <li>satisfyingInstance</li>
50 * <li>requirementNotSatisfied</li>
51 * <li>averageFreeMemoryMetric</li>
52 * <li>freeMemoryPercentage</li>
53 * <li>averageFreeHddMetric</li>
54 * <li>freeHddPercentage</li>
55 * <li>costMetric</li>
56 * <li>cpsCost</li>
57 * <li>hostInstanceCost</li>
58 * </ul>
59 *
60 * @see IQueryGroup
61 *
62 */
63@SuppressWarnings("all")
64public final class CpsQueriesAll extends BaseGeneratedPatternGroup {
65 /**
66 * Access the pattern group.
67 *
68 * @return the singleton instance of the group
69 * @throws ViatraQueryRuntimeException if there was an error loading the generated code of pattern specifications
70 *
71 */
72 public static CpsQueriesAll instance() {
73 if (INSTANCE == null) {
74 INSTANCE = new CpsQueriesAll();
75 }
76 return INSTANCE;
77 }
78
79 private static CpsQueriesAll INSTANCE;
80
81 private CpsQueriesAll() {
82 querySpecifications.add(CpsApplications.instance());
83 querySpecifications.add(CpsHosts.instance());
84 querySpecifications.add(TotalMemory.instance());
85 querySpecifications.add(TotalHdd.instance());
86 querySpecifications.add(AvailableMemory.instance());
87 querySpecifications.add(MemoryRequirement.instance());
88 querySpecifications.add(AvailableHdd.instance());
89 querySpecifications.add(HddRequirement.instance());
90 querySpecifications.add(ResourceRequirement.instance());
91 querySpecifications.add(AllocationWithoutResourceRequirement.instance());
92 querySpecifications.add(NotEnoughAvailableMemory.instance());
93 querySpecifications.add(NotEnoughAvailableHdd.instance());
94 querySpecifications.add(InstanceDoesNotSatisfyRequirement.instance());
95 querySpecifications.add(SatisfyingInstance.instance());
96 querySpecifications.add(RequirementNotSatisfied.instance());
97 querySpecifications.add(AverageFreeMemoryMetric.instance());
98 querySpecifications.add(FreeMemoryPercentage.instance());
99 querySpecifications.add(AverageFreeHddMetric.instance());
100 querySpecifications.add(FreeHddPercentage.instance());
101 querySpecifications.add(CostMetric.instance());
102 querySpecifications.add(CpsCost.instance());
103 querySpecifications.add(HostInstanceCost.instance());
104 }
105}
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..366677b5
--- /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.AvailableHdd;
7import hu.bme.mit.inf.dslreasoner.domains.cps.queries.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 JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.FreeHddPercentage (visibility: PUBLIC, simpleName: FreeHddPercentage, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.FreeHddPercentage, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal) (interface: false, strictFloatingPoint: false, anonymous: false)} 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 JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.FreeHddPercentage (visibility: PUBLIC, simpleName: FreeHddPercentage, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.FreeHddPercentage, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal) (interface: false, strictFloatingPoint: false, anonymous: false)#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..bd151ea6
--- /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.AvailableMemory;
7import hu.bme.mit.inf.dslreasoner.domains.cps.queries.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 JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.FreeMemoryPercentage (visibility: PUBLIC, simpleName: FreeMemoryPercentage, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.FreeMemoryPercentage, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal) (interface: false, strictFloatingPoint: false, anonymous: false)} 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 JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.FreeMemoryPercentage (visibility: PUBLIC, simpleName: FreeMemoryPercentage, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.FreeMemoryPercentage, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal) (interface: false, strictFloatingPoint: false, anonymous: false)#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..fbe7a46b
--- /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.internal.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 JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.HddRequirement (visibility: PUBLIC, simpleName: HddRequirement, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.HddRequirement, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal) (interface: false, strictFloatingPoint: false, anonymous: false)} 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 JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.HddRequirement (visibility: PUBLIC, simpleName: HddRequirement, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.HddRequirement, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal) (interface: false, strictFloatingPoint: false, anonymous: false)#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..767ca342
--- /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.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 JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.HostInstanceCost (visibility: PUBLIC, simpleName: HostInstanceCost, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.HostInstanceCost, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal) (interface: false, strictFloatingPoint: false, anonymous: false)} 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 JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.HostInstanceCost (visibility: PUBLIC, simpleName: HostInstanceCost, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.HostInstanceCost, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal) (interface: false, strictFloatingPoint: false, anonymous: false)#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..0a24d105
--- /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.internal.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 JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.MemoryRequirement (visibility: PUBLIC, simpleName: MemoryRequirement, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.MemoryRequirement, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal) (interface: false, strictFloatingPoint: false, anonymous: false)} 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 JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.MemoryRequirement (visibility: PUBLIC, simpleName: MemoryRequirement, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.MemoryRequirement, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal) (interface: false, strictFloatingPoint: false, anonymous: false)#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/ResourceRequirement.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/ResourceRequirement.java
new file mode 100644
index 00000000..8c5bdefe
--- /dev/null
+++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/ResourceRequirement.java
@@ -0,0 +1,168 @@
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 resourceRequirement(Host : HostInstance, App : ApplicationInstance, Req : ResourceRequirement) {
32 * ApplicationInstance.allocatedTo(App, Host);
33 * ApplicationInstance.type.requirements(App, Req);
34 * HostInstance.type(Host, HostType);
35 * ResourceRequirement.hostType(Req, HostType);
36 * }
37 * </pre></code>
38 *
39 * @see GenericPatternMatcher
40 * @see GenericPatternMatch
41 *
42 */
43@SuppressWarnings("all")
44public final class ResourceRequirement extends BaseGeneratedEMFQuerySpecificationWithGenericMatcher {
45 private ResourceRequirement() {
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 ResourceRequirement 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 JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.ResourceRequirement (visibility: PUBLIC, simpleName: ResourceRequirement, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.ResourceRequirement, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal) (interface: false, strictFloatingPoint: false, anonymous: false)} 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 JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.ResourceRequirement (visibility: PUBLIC, simpleName: ResourceRequirement, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.ResourceRequirement, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}.
66 *
67 * <p> This workaround is required e.g. to support recursion.
68 *
69 */
70 private static class LazyHolder {
71 private static final ResourceRequirement INSTANCE = new ResourceRequirement();
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 ResourceRequirement.GeneratedPQuery INSTANCE = new GeneratedPQuery();
90
91 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);
92
93 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);
94
95 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);
96
97 private final List<PParameter> parameters = Arrays.asList(parameter_Host, parameter_App, parameter_Req);
98
99 private GeneratedPQuery() {
100 super(PVisibility.PRIVATE);
101 }
102
103 @Override
104 public String getFullyQualifiedName() {
105 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.resourceRequirement";
106 }
107
108 @Override
109 public List<String> getParameterNames() {
110 return Arrays.asList("Host","App","Req");
111 }
112
113 @Override
114 public List<PParameter> getParameters() {
115 return parameters;
116 }
117
118 @Override
119 public Set<PBody> doGetContainedBodies() {
120 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
121 Set<PBody> bodies = new LinkedHashSet<>();
122 {
123 PBody body = new PBody(this);
124 PVariable var_Host = body.getOrCreateVariableByName("Host");
125 PVariable var_App = body.getOrCreateVariableByName("App");
126 PVariable var_Req = body.getOrCreateVariableByName("Req");
127 PVariable var_HostType = body.getOrCreateVariableByName("HostType");
128 new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance")));
129 new TypeConstraint(body, Tuples.flatTupleOf(var_App), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance")));
130 new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ResourceRequirement")));
131 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
132 new ExportedParameter(body, var_Host, parameter_Host),
133 new ExportedParameter(body, var_App, parameter_App),
134 new ExportedParameter(body, var_Req, parameter_Req)
135 ));
136 // ApplicationInstance.allocatedTo(App, Host)
137 new TypeConstraint(body, Tuples.flatTupleOf(var_App), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance")));
138 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
139 new TypeConstraint(body, Tuples.flatTupleOf(var_App, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ApplicationInstance", "allocatedTo")));
140 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance")));
141 new Equality(body, var__virtual_0_, var_Host);
142 // ApplicationInstance.type.requirements(App, Req)
143 new TypeConstraint(body, Tuples.flatTupleOf(var_App), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance")));
144 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
145 new TypeConstraint(body, Tuples.flatTupleOf(var_App, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ApplicationInstance", "type")));
146 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationType")));
147 PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}");
148 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_, var__virtual_2_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ApplicationType", "requirements")));
149 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ResourceRequirement")));
150 new Equality(body, var__virtual_2_, var_Req);
151 // HostInstance.type(Host, HostType)
152 new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance")));
153 PVariable var__virtual_3_ = body.getOrCreateVariableByName(".virtual{3}");
154 new TypeConstraint(body, Tuples.flatTupleOf(var_Host, var__virtual_3_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "HostInstance", "type")));
155 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_3_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostType")));
156 new Equality(body, var__virtual_3_, var_HostType);
157 // ResourceRequirement.hostType(Req, HostType)
158 new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ResourceRequirement")));
159 PVariable var__virtual_4_ = body.getOrCreateVariableByName(".virtual{4}");
160 new TypeConstraint(body, Tuples.flatTupleOf(var_Req, var__virtual_4_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ResourceRequirement", "hostType")));
161 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_4_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostType")));
162 new Equality(body, var__virtual_4_, var_HostType);
163 bodies.add(body);
164 }
165 return bodies;
166 }
167 }
168}
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..4285101c
--- /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 JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.SatisfyingInstance (visibility: PUBLIC, simpleName: SatisfyingInstance, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.SatisfyingInstance, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal) (interface: false, strictFloatingPoint: false, anonymous: false)} 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 JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.SatisfyingInstance (visibility: PUBLIC, simpleName: SatisfyingInstance, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.SatisfyingInstance, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal) (interface: false, strictFloatingPoint: false, anonymous: false)#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}