aboutsummaryrefslogtreecommitdiffstats
path: root/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/AvailableMemory.java
diff options
context:
space:
mode:
Diffstat (limited to 'Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/AvailableMemory.java')
-rw-r--r--Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/AvailableMemory.java743
1 files changed, 743 insertions, 0 deletions
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}