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