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