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