aboutsummaryrefslogtreecommitdiffstats
path: root/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/Allocate.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/Allocate.java')
-rw-r--r--Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/Allocate.java862
1 files changed, 862 insertions, 0 deletions
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/Allocate.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/Allocate.java
new file mode 100644
index 00000000..830dc8a0
--- /dev/null
+++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/Allocate.java
@@ -0,0 +1,862 @@
1/**
2 * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql
3 */
4package hu.bme.mit.inf.dslreasoner.domains.cps.queries;
5
6import hu.bme.mit.inf.dslreasoner.domains.cps.ApplicationInstance;
7import hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance;
8import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.AvailableHdd;
9import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.AvailableMemory;
10import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.UnallocatedAppInstance;
11import java.util.Arrays;
12import java.util.Collection;
13import java.util.Collections;
14import java.util.LinkedHashSet;
15import java.util.List;
16import java.util.Objects;
17import java.util.Optional;
18import java.util.Set;
19import java.util.function.Consumer;
20import java.util.stream.Collectors;
21import java.util.stream.Stream;
22import org.apache.log4j.Logger;
23import org.eclipse.emf.ecore.EClass;
24import org.eclipse.emf.ecore.EDataType;
25import org.eclipse.viatra.query.runtime.api.IPatternMatch;
26import org.eclipse.viatra.query.runtime.api.IQuerySpecification;
27import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine;
28import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
29import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification;
30import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher;
31import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch;
32import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey;
33import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey;
34import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey;
35import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
36import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator;
37import org.eclipse.viatra.query.runtime.matchers.psystem.IValueProvider;
38import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
39import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
40import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality;
41import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
42import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation;
43import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.NegativePatternCall;
44import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall;
45import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
46import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
47import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
48import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
49import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
50import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
51import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
52
53/**
54 * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
55 *
56 * <p>Original source:
57 * <code><pre>
58 * //
59 * // Transformation rule preconditions for rule-based DSE
60 * //
61 *
62 * pattern allocate(App : ApplicationInstance, Host : HostInstance) {
63 * ApplicationInstance.type.requirements(App, Req);
64 * ResourceRequirement.hostType.instances(Req, Host);
65 * find unallocatedAppInstance(App);
66 * find availableMemory(Host, AvailableMem);
67 * find availableHdd(Host, AvailableHdd);
68 * ResourceRequirement.requiredMemory(Req, RequiredMem);
69 * ResourceRequirement.requiredHdd(Req, RequiredHdd);
70 * check(AvailableMem {@literal >}= RequiredMem);
71 * check(AvailableHdd {@literal >}= RequiredHdd);
72 * neg ApplicationInstance.requirement.instances.allocatedTo(App, Host);
73 * }
74 * </pre></code>
75 *
76 * @see Matcher
77 * @see Match
78 *
79 */
80@SuppressWarnings("all")
81public final class Allocate extends BaseGeneratedEMFQuerySpecification<Allocate.Matcher> {
82 /**
83 * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.allocate pattern,
84 * to be used in conjunction with {@link Matcher}.
85 *
86 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
87 * Each instance is a (possibly partial) substitution of pattern parameters,
88 * usable to represent a match of the pattern in the result of a query,
89 * or to specify the bound (fixed) input parameters when issuing a query.
90 *
91 * @see Matcher
92 *
93 */
94 public static abstract class Match extends BasePatternMatch {
95 private ApplicationInstance fApp;
96
97 private HostInstance fHost;
98
99 private static List<String> parameterNames = makeImmutableList("App", "Host");
100
101 private Match(final ApplicationInstance pApp, final HostInstance pHost) {
102 this.fApp = pApp;
103 this.fHost = pHost;
104 }
105
106 @Override
107 public Object get(final String parameterName) {
108 if ("App".equals(parameterName)) return this.fApp;
109 if ("Host".equals(parameterName)) return this.fHost;
110 return null;
111 }
112
113 public ApplicationInstance getApp() {
114 return this.fApp;
115 }
116
117 public HostInstance getHost() {
118 return this.fHost;
119 }
120
121 @Override
122 public boolean set(final String parameterName, final Object newValue) {
123 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
124 if ("App".equals(parameterName) ) {
125 this.fApp = (ApplicationInstance) newValue;
126 return true;
127 }
128 if ("Host".equals(parameterName) ) {
129 this.fHost = (HostInstance) newValue;
130 return true;
131 }
132 return false;
133 }
134
135 public void setApp(final ApplicationInstance pApp) {
136 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
137 this.fApp = pApp;
138 }
139
140 public void setHost(final HostInstance pHost) {
141 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
142 this.fHost = pHost;
143 }
144
145 @Override
146 public String patternName() {
147 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.allocate";
148 }
149
150 @Override
151 public List<String> parameterNames() {
152 return Allocate.Match.parameterNames;
153 }
154
155 @Override
156 public Object[] toArray() {
157 return new Object[]{fApp, fHost};
158 }
159
160 @Override
161 public Allocate.Match toImmutable() {
162 return isMutable() ? newMatch(fApp, fHost) : this;
163 }
164
165 @Override
166 public String prettyPrint() {
167 StringBuilder result = new StringBuilder();
168 result.append("\"App\"=" + prettyPrintValue(fApp) + ", ");
169 result.append("\"Host\"=" + prettyPrintValue(fHost));
170 return result.toString();
171 }
172
173 @Override
174 public int hashCode() {
175 return Objects.hash(fApp, fHost);
176 }
177
178 @Override
179 public boolean equals(final Object obj) {
180 if (this == obj)
181 return true;
182 if (obj == null) {
183 return false;
184 }
185 if ((obj instanceof Allocate.Match)) {
186 Allocate.Match other = (Allocate.Match) obj;
187 return Objects.equals(fApp, other.fApp) && Objects.equals(fHost, other.fHost);
188 } else {
189 // this should be infrequent
190 if (!(obj instanceof IPatternMatch)) {
191 return false;
192 }
193 IPatternMatch otherSig = (IPatternMatch) obj;
194 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
195 }
196 }
197
198 @Override
199 public Allocate specification() {
200 return Allocate.instance();
201 }
202
203 /**
204 * Returns an empty, mutable match.
205 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
206 *
207 * @return the empty match.
208 *
209 */
210 public static Allocate.Match newEmptyMatch() {
211 return new Mutable(null, null);
212 }
213
214 /**
215 * Returns a mutable (partial) match.
216 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
217 *
218 * @param pApp the fixed value of pattern parameter App, or null if not bound.
219 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
220 * @return the new, mutable (partial) match object.
221 *
222 */
223 public static Allocate.Match newMutableMatch(final ApplicationInstance pApp, final HostInstance pHost) {
224 return new Mutable(pApp, pHost);
225 }
226
227 /**
228 * Returns a new (partial) match.
229 * This can be used e.g. to call the matcher with a partial match.
230 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
231 * @param pApp the fixed value of pattern parameter App, or null if not bound.
232 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
233 * @return the (partial) match object.
234 *
235 */
236 public static Allocate.Match newMatch(final ApplicationInstance pApp, final HostInstance pHost) {
237 return new Immutable(pApp, pHost);
238 }
239
240 private static final class Mutable extends Allocate.Match {
241 Mutable(final ApplicationInstance pApp, final HostInstance pHost) {
242 super(pApp, pHost);
243 }
244
245 @Override
246 public boolean isMutable() {
247 return true;
248 }
249 }
250
251 private static final class Immutable extends Allocate.Match {
252 Immutable(final ApplicationInstance pApp, final HostInstance pHost) {
253 super(pApp, pHost);
254 }
255
256 @Override
257 public boolean isMutable() {
258 return false;
259 }
260 }
261 }
262
263 /**
264 * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.allocate pattern,
265 * providing pattern-specific query methods.
266 *
267 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
268 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
269 *
270 * <p>Matches of the pattern will be represented as {@link Match}.
271 *
272 * <p>Original source:
273 * <code><pre>
274 * //
275 * // Transformation rule preconditions for rule-based DSE
276 * //
277 *
278 * pattern allocate(App : ApplicationInstance, Host : HostInstance) {
279 * ApplicationInstance.type.requirements(App, Req);
280 * ResourceRequirement.hostType.instances(Req, Host);
281 * find unallocatedAppInstance(App);
282 * find availableMemory(Host, AvailableMem);
283 * find availableHdd(Host, AvailableHdd);
284 * ResourceRequirement.requiredMemory(Req, RequiredMem);
285 * ResourceRequirement.requiredHdd(Req, RequiredHdd);
286 * check(AvailableMem {@literal >}= RequiredMem);
287 * check(AvailableHdd {@literal >}= RequiredHdd);
288 * neg ApplicationInstance.requirement.instances.allocatedTo(App, Host);
289 * }
290 * </pre></code>
291 *
292 * @see Match
293 * @see Allocate
294 *
295 */
296 public static class Matcher extends BaseMatcher<Allocate.Match> {
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 public static Allocate.Matcher on(final ViatraQueryEngine engine) {
306 // check if matcher already exists
307 Matcher matcher = engine.getExistingMatcher(querySpecification());
308 if (matcher == null) {
309 matcher = (Matcher)engine.getMatcher(querySpecification());
310 }
311 return matcher;
312 }
313
314 /**
315 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
316 * @return an initialized matcher
317 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
318 *
319 */
320 public static Allocate.Matcher create() {
321 return new Matcher();
322 }
323
324 private static final int POSITION_APP = 0;
325
326 private static final int POSITION_HOST = 1;
327
328 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Allocate.Matcher.class);
329
330 /**
331 * Initializes the pattern matcher within an existing VIATRA Query engine.
332 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
333 *
334 * @param engine the existing VIATRA Query engine in which this matcher will be created.
335 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
336 *
337 */
338 private Matcher() {
339 super(querySpecification());
340 }
341
342 /**
343 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
344 * @param pApp the fixed value of pattern parameter App, or null if not bound.
345 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
346 * @return matches represented as a Match object.
347 *
348 */
349 public Collection<Allocate.Match> getAllMatches(final ApplicationInstance pApp, final HostInstance pHost) {
350 return rawStreamAllMatches(new Object[]{pApp, pHost}).collect(Collectors.toSet());
351 }
352
353 /**
354 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
355 * </p>
356 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
357 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
358 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
359 * @param pApp the fixed value of pattern parameter App, or null if not bound.
360 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
361 * @return a stream of matches represented as a Match object.
362 *
363 */
364 public Stream<Allocate.Match> streamAllMatches(final ApplicationInstance pApp, final HostInstance pHost) {
365 return rawStreamAllMatches(new Object[]{pApp, pHost});
366 }
367
368 /**
369 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
370 * Neither determinism nor randomness of selection is guaranteed.
371 * @param pApp the fixed value of pattern parameter App, or null if not bound.
372 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
373 * @return a match represented as a Match object, or null if no match is found.
374 *
375 */
376 public Optional<Allocate.Match> getOneArbitraryMatch(final ApplicationInstance pApp, final HostInstance pHost) {
377 return rawGetOneArbitraryMatch(new Object[]{pApp, pHost});
378 }
379
380 /**
381 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
382 * under any possible substitution of the unspecified parameters (if any).
383 * @param pApp the fixed value of pattern parameter App, or null if not bound.
384 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
385 * @return true if the input is a valid (partial) match of the pattern.
386 *
387 */
388 public boolean hasMatch(final ApplicationInstance pApp, final HostInstance pHost) {
389 return rawHasMatch(new Object[]{pApp, pHost});
390 }
391
392 /**
393 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
394 * @param pApp the fixed value of pattern parameter App, or null if not bound.
395 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
396 * @return the number of pattern matches found.
397 *
398 */
399 public int countMatches(final ApplicationInstance pApp, final HostInstance pHost) {
400 return rawCountMatches(new Object[]{pApp, pHost});
401 }
402
403 /**
404 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
405 * Neither determinism nor randomness of selection is guaranteed.
406 * @param pApp the fixed value of pattern parameter App, or null if not bound.
407 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
408 * @param processor the action that will process the selected match.
409 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
410 *
411 */
412 public boolean forOneArbitraryMatch(final ApplicationInstance pApp, final HostInstance pHost, final Consumer<? super Allocate.Match> processor) {
413 return rawForOneArbitraryMatch(new Object[]{pApp, pHost}, processor);
414 }
415
416 /**
417 * Returns a new (partial) match.
418 * This can be used e.g. to call the matcher with a partial match.
419 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
420 * @param pApp the fixed value of pattern parameter App, or null if not bound.
421 * @param pHost the fixed value of pattern parameter Host, or null if not bound.
422 * @return the (partial) match object.
423 *
424 */
425 public Allocate.Match newMatch(final ApplicationInstance pApp, final HostInstance pHost) {
426 return Allocate.Match.newMatch(pApp, pHost);
427 }
428
429 /**
430 * Retrieve the set of values that occur in matches for App.
431 * @return the Set of all values or empty set if there are no matches
432 *
433 */
434 protected Stream<ApplicationInstance> rawStreamAllValuesOfApp(final Object[] parameters) {
435 return rawStreamAllValues(POSITION_APP, parameters).map(ApplicationInstance.class::cast);
436 }
437
438 /**
439 * Retrieve the set of values that occur in matches for App.
440 * @return the Set of all values or empty set if there are no matches
441 *
442 */
443 public Set<ApplicationInstance> getAllValuesOfApp() {
444 return rawStreamAllValuesOfApp(emptyArray()).collect(Collectors.toSet());
445 }
446
447 /**
448 * Retrieve the set of values that occur in matches for App.
449 * @return the Set of all values or empty set if there are no matches
450 *
451 */
452 public Stream<ApplicationInstance> streamAllValuesOfApp() {
453 return rawStreamAllValuesOfApp(emptyArray());
454 }
455
456 /**
457 * Retrieve the set of values that occur in matches for App.
458 * </p>
459 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
460 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
461 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
462 *
463 * @return the Stream of all values or empty set if there are no matches
464 *
465 */
466 public Stream<ApplicationInstance> streamAllValuesOfApp(final Allocate.Match partialMatch) {
467 return rawStreamAllValuesOfApp(partialMatch.toArray());
468 }
469
470 /**
471 * Retrieve the set of values that occur in matches for App.
472 * </p>
473 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
474 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
475 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
476 *
477 * @return the Stream of all values or empty set if there are no matches
478 *
479 */
480 public Stream<ApplicationInstance> streamAllValuesOfApp(final HostInstance pHost) {
481 return rawStreamAllValuesOfApp(new Object[]{null, pHost});
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(final Allocate.Match partialMatch) {
490 return rawStreamAllValuesOfApp(partialMatch.toArray()).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 Set<ApplicationInstance> getAllValuesOfApp(final HostInstance pHost) {
499 return rawStreamAllValuesOfApp(new Object[]{null, pHost}).collect(Collectors.toSet());
500 }
501
502 /**
503 * Retrieve the set of values that occur in matches for Host.
504 * @return the Set of all values or empty set if there are no matches
505 *
506 */
507 protected Stream<HostInstance> rawStreamAllValuesOfHost(final Object[] parameters) {
508 return rawStreamAllValues(POSITION_HOST, parameters).map(HostInstance.class::cast);
509 }
510
511 /**
512 * Retrieve the set of values that occur in matches for Host.
513 * @return the Set of all values or empty set if there are no matches
514 *
515 */
516 public Set<HostInstance> getAllValuesOfHost() {
517 return rawStreamAllValuesOfHost(emptyArray()).collect(Collectors.toSet());
518 }
519
520 /**
521 * Retrieve the set of values that occur in matches for Host.
522 * @return the Set of all values or empty set if there are no matches
523 *
524 */
525 public Stream<HostInstance> streamAllValuesOfHost() {
526 return rawStreamAllValuesOfHost(emptyArray());
527 }
528
529 /**
530 * Retrieve the set of values that occur in matches for Host.
531 * </p>
532 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
533 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
534 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
535 *
536 * @return the Stream of all values or empty set if there are no matches
537 *
538 */
539 public Stream<HostInstance> streamAllValuesOfHost(final Allocate.Match partialMatch) {
540 return rawStreamAllValuesOfHost(partialMatch.toArray());
541 }
542
543 /**
544 * Retrieve the set of values that occur in matches for Host.
545 * </p>
546 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
547 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
548 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
549 *
550 * @return the Stream of all values or empty set if there are no matches
551 *
552 */
553 public Stream<HostInstance> streamAllValuesOfHost(final ApplicationInstance pApp) {
554 return rawStreamAllValuesOfHost(new Object[]{pApp, null});
555 }
556
557 /**
558 * Retrieve the set of values that occur in matches for Host.
559 * @return the Set of all values or empty set if there are no matches
560 *
561 */
562 public Set<HostInstance> getAllValuesOfHost(final Allocate.Match partialMatch) {
563 return rawStreamAllValuesOfHost(partialMatch.toArray()).collect(Collectors.toSet());
564 }
565
566 /**
567 * Retrieve the set of values that occur in matches for Host.
568 * @return the Set of all values or empty set if there are no matches
569 *
570 */
571 public Set<HostInstance> getAllValuesOfHost(final ApplicationInstance pApp) {
572 return rawStreamAllValuesOfHost(new Object[]{pApp, null}).collect(Collectors.toSet());
573 }
574
575 @Override
576 protected Allocate.Match tupleToMatch(final Tuple t) {
577 try {
578 return Allocate.Match.newMatch((ApplicationInstance) t.get(POSITION_APP), (HostInstance) t.get(POSITION_HOST));
579 } catch(ClassCastException e) {
580 LOGGER.error("Element(s) in tuple not properly typed!",e);
581 return null;
582 }
583 }
584
585 @Override
586 protected Allocate.Match arrayToMatch(final Object[] match) {
587 try {
588 return Allocate.Match.newMatch((ApplicationInstance) match[POSITION_APP], (HostInstance) match[POSITION_HOST]);
589 } catch(ClassCastException e) {
590 LOGGER.error("Element(s) in array not properly typed!",e);
591 return null;
592 }
593 }
594
595 @Override
596 protected Allocate.Match arrayToMatchMutable(final Object[] match) {
597 try {
598 return Allocate.Match.newMutableMatch((ApplicationInstance) match[POSITION_APP], (HostInstance) match[POSITION_HOST]);
599 } catch(ClassCastException e) {
600 LOGGER.error("Element(s) in array not properly typed!",e);
601 return null;
602 }
603 }
604
605 /**
606 * @return the singleton instance of the query specification of this pattern
607 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
608 *
609 */
610 public static IQuerySpecification<Allocate.Matcher> querySpecification() {
611 return Allocate.instance();
612 }
613 }
614
615 private Allocate() {
616 super(GeneratedPQuery.INSTANCE);
617 }
618
619 /**
620 * @return the singleton instance of the query specification
621 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
622 *
623 */
624 public static Allocate instance() {
625 try{
626 return LazyHolder.INSTANCE;
627 } catch (ExceptionInInitializerError err) {
628 throw processInitializerError(err);
629 }
630 }
631
632 @Override
633 protected Allocate.Matcher instantiate(final ViatraQueryEngine engine) {
634 return Allocate.Matcher.on(engine);
635 }
636
637 @Override
638 public Allocate.Matcher instantiate() {
639 return Allocate.Matcher.create();
640 }
641
642 @Override
643 public Allocate.Match newEmptyMatch() {
644 return Allocate.Match.newEmptyMatch();
645 }
646
647 @Override
648 public Allocate.Match newMatch(final Object... parameters) {
649 return Allocate.Match.newMatch((hu.bme.mit.inf.dslreasoner.domains.cps.ApplicationInstance) parameters[0], (hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance) parameters[1]);
650 }
651
652 /**
653 * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.Allocate (visibility: PUBLIC, simpleName: Allocate, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.Allocate, 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
654 * <b>not</b> at the class load time of the outer class,
655 * but rather at the first call to {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.Allocate (visibility: PUBLIC, simpleName: Allocate, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.Allocate, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}.
656 *
657 * <p> This workaround is required e.g. to support recursion.
658 *
659 */
660 private static class LazyHolder {
661 private static final Allocate INSTANCE = new Allocate();
662
663 /**
664 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
665 * This initialization order is required to support indirect recursion.
666 *
667 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
668 *
669 */
670 private static final Object STATIC_INITIALIZER = ensureInitialized();
671
672 public static Object ensureInitialized() {
673 INSTANCE.ensureInitializedInternal();
674 return null;
675 }
676 }
677
678 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
679 private static final Allocate.GeneratedPQuery INSTANCE = new GeneratedPQuery();
680
681 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);
682
683 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);
684
685 private final List<PParameter> parameters = Arrays.asList(parameter_App, parameter_Host);
686
687 private class Embedded_1_ApplicationInstance_requirement_instances_allocatedTo extends BaseGeneratedEMFPQuery {
688 private final PParameter parameter_p0 = new PParameter("p0", "hu.bme.mit.inf.dslreasoner.domains.cps.ApplicationInstance", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "ApplicationInstance")), PParameterDirection.INOUT);
689
690 private final PParameter parameter_p1 = new PParameter("p1", "hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "HostInstance")), PParameterDirection.INOUT);
691
692 private final List<PParameter> embeddedParameters = Arrays.asList(parameter_p0, parameter_p1);
693
694 public Embedded_1_ApplicationInstance_requirement_instances_allocatedTo() {
695 super(PVisibility.EMBEDDED);
696 }
697
698 @Override
699 public String getFullyQualifiedName() {
700 return GeneratedPQuery.this.getFullyQualifiedName() + "$Embedded_1_ApplicationInstance_requirement_instances_allocatedTo";
701 }
702
703 @Override
704 public List<PParameter> getParameters() {
705 return embeddedParameters;
706 }
707
708 @Override
709 public Set<PBody> doGetContainedBodies() {
710 PBody body = new PBody(this);
711 PVariable var_p0 = body.getOrCreateVariableByName("p0");
712 PVariable var_p1 = body.getOrCreateVariableByName("p1");
713 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
714 new ExportedParameter(body, var_p0, parameter_p0),
715 new ExportedParameter(body, var_p1, parameter_p1)
716 ));
717 // ApplicationInstance.requirement.instances.allocatedTo(App, Host)
718 new TypeConstraint(body, Tuples.flatTupleOf(var_p0), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance")));
719 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
720 new TypeConstraint(body, Tuples.flatTupleOf(var_p0, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ApplicationInstance", "requirement")));
721 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "Requirement")));
722 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
723 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "Requirement", "instances")));
724 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance")));
725 PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}");
726 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_, var__virtual_2_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ApplicationInstance", "allocatedTo")));
727 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance")));
728 new Equality(body, var__virtual_2_, var_p1);
729 return Collections.singleton(body);
730 }
731 }
732
733 private GeneratedPQuery() {
734 super(PVisibility.PUBLIC);
735 }
736
737 @Override
738 public String getFullyQualifiedName() {
739 return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.allocate";
740 }
741
742 @Override
743 public List<String> getParameterNames() {
744 return Arrays.asList("App","Host");
745 }
746
747 @Override
748 public List<PParameter> getParameters() {
749 return parameters;
750 }
751
752 @Override
753 public Set<PBody> doGetContainedBodies() {
754 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
755 Set<PBody> bodies = new LinkedHashSet<>();
756 {
757 PBody body = new PBody(this);
758 PVariable var_App = body.getOrCreateVariableByName("App");
759 PVariable var_Host = body.getOrCreateVariableByName("Host");
760 PVariable var_Req = body.getOrCreateVariableByName("Req");
761 PVariable var_AvailableMem = body.getOrCreateVariableByName("AvailableMem");
762 PVariable var_AvailableHdd = body.getOrCreateVariableByName("AvailableHdd");
763 PVariable var_RequiredMem = body.getOrCreateVariableByName("RequiredMem");
764 PVariable var_RequiredHdd = body.getOrCreateVariableByName("RequiredHdd");
765 new TypeConstraint(body, Tuples.flatTupleOf(var_App), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance")));
766 new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance")));
767 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
768 new ExportedParameter(body, var_App, parameter_App),
769 new ExportedParameter(body, var_Host, parameter_Host)
770 ));
771 // ApplicationInstance.type.requirements(App, Req)
772 new TypeConstraint(body, Tuples.flatTupleOf(var_App), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance")));
773 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
774 new TypeConstraint(body, Tuples.flatTupleOf(var_App, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ApplicationInstance", "type")));
775 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationType")));
776 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
777 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ApplicationType", "requirements")));
778 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ResourceRequirement")));
779 new Equality(body, var__virtual_1_, var_Req);
780 // ResourceRequirement.hostType.instances(Req, Host)
781 new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ResourceRequirement")));
782 PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}");
783 new TypeConstraint(body, Tuples.flatTupleOf(var_Req, var__virtual_2_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ResourceRequirement", "hostType")));
784 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostType")));
785 PVariable var__virtual_3_ = body.getOrCreateVariableByName(".virtual{3}");
786 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_, var__virtual_3_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "HostType", "instances")));
787 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_3_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance")));
788 new Equality(body, var__virtual_3_, var_Host);
789 // find unallocatedAppInstance(App)
790 new PositivePatternCall(body, Tuples.flatTupleOf(var_App), UnallocatedAppInstance.instance().getInternalQueryRepresentation());
791 // find availableMemory(Host, AvailableMem)
792 new PositivePatternCall(body, Tuples.flatTupleOf(var_Host, var_AvailableMem), AvailableMemory.instance().getInternalQueryRepresentation());
793 // find availableHdd(Host, AvailableHdd)
794 new PositivePatternCall(body, Tuples.flatTupleOf(var_Host, var_AvailableHdd), AvailableHdd.instance().getInternalQueryRepresentation());
795 // ResourceRequirement.requiredMemory(Req, RequiredMem)
796 new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ResourceRequirement")));
797 PVariable var__virtual_4_ = body.getOrCreateVariableByName(".virtual{4}");
798 new TypeConstraint(body, Tuples.flatTupleOf(var_Req, var__virtual_4_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ResourceRequirement", "requiredMemory")));
799 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_4_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt")));
800 new Equality(body, var__virtual_4_, var_RequiredMem);
801 // ResourceRequirement.requiredHdd(Req, RequiredHdd)
802 new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ResourceRequirement")));
803 PVariable var__virtual_5_ = body.getOrCreateVariableByName(".virtual{5}");
804 new TypeConstraint(body, Tuples.flatTupleOf(var_Req, var__virtual_5_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ResourceRequirement", "requiredHdd")));
805 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_5_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt")));
806 new Equality(body, var__virtual_5_, var_RequiredHdd);
807 // check(AvailableMem >= RequiredMem)
808 new ExpressionEvaluation(body, new IExpressionEvaluator() {
809
810 @Override
811 public String getShortDescription() {
812 return "Expression evaluation from pattern allocate";
813 }
814
815 @Override
816 public Iterable<String> getInputParameterNames() {
817 return Arrays.asList("AvailableMem", "RequiredMem");}
818
819 @Override
820 public Object evaluateExpression(IValueProvider provider) throws Exception {
821 Integer AvailableMem = (Integer) provider.getValue("AvailableMem");
822 Integer RequiredMem = (Integer) provider.getValue("RequiredMem");
823 return evaluateExpression_1_1(AvailableMem, RequiredMem);
824 }
825 }, null);
826 // check(AvailableHdd >= RequiredHdd)
827 new ExpressionEvaluation(body, new IExpressionEvaluator() {
828
829 @Override
830 public String getShortDescription() {
831 return "Expression evaluation from pattern allocate";
832 }
833
834 @Override
835 public Iterable<String> getInputParameterNames() {
836 return Arrays.asList("AvailableHdd", "RequiredHdd");}
837
838 @Override
839 public Object evaluateExpression(IValueProvider provider) throws Exception {
840 Integer AvailableHdd = (Integer) provider.getValue("AvailableHdd");
841 Integer RequiredHdd = (Integer) provider.getValue("RequiredHdd");
842 return evaluateExpression_1_2(AvailableHdd, RequiredHdd);
843 }
844 }, null);
845 // neg ApplicationInstance.requirement.instances.allocatedTo(App, Host)
846 new NegativePatternCall(body, Tuples.flatTupleOf(var_App, var_Host), new Allocate.GeneratedPQuery.Embedded_1_ApplicationInstance_requirement_instances_allocatedTo());
847 bodies.add(body);
848 }
849 return bodies;
850 }
851 }
852
853 private static boolean evaluateExpression_1_1(final Integer AvailableMem, final Integer RequiredMem) {
854 boolean _greaterEqualsThan = (AvailableMem.compareTo(RequiredMem) >= 0);
855 return _greaterEqualsThan;
856 }
857
858 private static boolean evaluateExpression_1_2(final Integer AvailableHdd, final Integer RequiredHdd) {
859 boolean _greaterEqualsThan = (AvailableHdd.compareTo(RequiredHdd) >= 0);
860 return _greaterEqualsThan;
861 }
862}