diff options
Diffstat (limited to 'Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu')
35 files changed, 12902 insertions, 0 deletions
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/.gitignore b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/.gitignore new file mode 100644 index 00000000..d3114d9d --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/.gitignore | |||
@@ -0,0 +1,44 @@ | |||
1 | /.CpsApplications.java._trace | ||
2 | /.CpsQueries.java._trace | ||
3 | /.CpsHosts.java._trace | ||
4 | /.TotalMemory.java._trace | ||
5 | /.TotalHdd.java._trace | ||
6 | /.AvailableMemory.java._trace | ||
7 | /.AvailableHdd.java._trace | ||
8 | /.AllocationWithoutResourceRequirement.java._trace | ||
9 | /.NotEnoughAvailableMemory.java._trace | ||
10 | /.NotEnoughAvailableHdd.java._trace | ||
11 | /.InstanceDoesNotSatisfyRequirement.java._trace | ||
12 | /.RequirementNotSatisfied.java._trace | ||
13 | /.AverageFreeMemoryMetric.java._trace | ||
14 | /.AverageFreeHddMetric.java._trace | ||
15 | /.CostMetric.java._trace | ||
16 | /.CpsCost.java._trace | ||
17 | /.RedundantInstancesOnSameHost.java._trace | ||
18 | /.Allocate.java._trace | ||
19 | /.CpsTransformationRules.java._trace | ||
20 | /.ResourceRequirement.java._trace | ||
21 | /.CreateInstance.java._trace | ||
22 | /.CreateHostInstance.java._trace | ||
23 | /.UnallocatedAppInstance.java._trace | ||
24 | /.RequiredAppInstances.java._trace | ||
25 | /.GuidanceObjective.java._trace | ||
26 | /.RemoveHostInstance.java._trace | ||
27 | /.UnallocateAppInstance.java._trace | ||
28 | /Allocate.java | ||
29 | /AllocationWithoutResourceRequirement.java | ||
30 | /AverageFreeHddMetric.java | ||
31 | /AverageFreeMemoryMetric.java | ||
32 | /CostMetric.java | ||
33 | /CpsCost.java | ||
34 | /CpsQueries.java | ||
35 | /CreateHostInstance.java | ||
36 | /GuidanceObjective.java | ||
37 | /InstanceDoesNotSatisfyRequirement.java | ||
38 | /NotEnoughAvailableHdd.java | ||
39 | /NotEnoughAvailableMemory.java | ||
40 | /RedundantInstancesOnSameHost.java | ||
41 | /RemoveHostInstance.java | ||
42 | /RequirementNotSatisfied.java | ||
43 | /ResourceRequirement.java | ||
44 | /UnallocateAppInstance.java | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/Allocate.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/Allocate.java new file mode 100644 index 00000000..830dc8a0 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/Allocate.java | |||
@@ -0,0 +1,862 @@ | |||
1 | /** | ||
2 | * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql | ||
3 | */ | ||
4 | package hu.bme.mit.inf.dslreasoner.domains.cps.queries; | ||
5 | |||
6 | import hu.bme.mit.inf.dslreasoner.domains.cps.ApplicationInstance; | ||
7 | import hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance; | ||
8 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.AvailableHdd; | ||
9 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.AvailableMemory; | ||
10 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.UnallocatedAppInstance; | ||
11 | import java.util.Arrays; | ||
12 | import java.util.Collection; | ||
13 | import java.util.Collections; | ||
14 | import java.util.LinkedHashSet; | ||
15 | import java.util.List; | ||
16 | import java.util.Objects; | ||
17 | import java.util.Optional; | ||
18 | import java.util.Set; | ||
19 | import java.util.function.Consumer; | ||
20 | import java.util.stream.Collectors; | ||
21 | import java.util.stream.Stream; | ||
22 | import org.apache.log4j.Logger; | ||
23 | import org.eclipse.emf.ecore.EClass; | ||
24 | import org.eclipse.emf.ecore.EDataType; | ||
25 | import org.eclipse.viatra.query.runtime.api.IPatternMatch; | ||
26 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification; | ||
27 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; | ||
28 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; | ||
29 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; | ||
30 | import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; | ||
31 | import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; | ||
32 | import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; | ||
33 | import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey; | ||
34 | import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; | ||
35 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
36 | import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator; | ||
37 | import org.eclipse.viatra.query.runtime.matchers.psystem.IValueProvider; | ||
38 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | ||
39 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | ||
40 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; | ||
41 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
42 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation; | ||
43 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.NegativePatternCall; | ||
44 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall; | ||
45 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
46 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | ||
47 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; | ||
48 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | ||
49 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; | ||
50 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
51 | import 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") | ||
81 | public final class Allocate extends BaseGeneratedEMFQuerySpecification<Allocate.Matcher> { | ||
82 | /** | ||
83 | * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.allocate pattern, | ||
84 | * to be used in conjunction with {@link Matcher}. | ||
85 | * | ||
86 | * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. | ||
87 | * Each instance is a (possibly partial) substitution of pattern parameters, | ||
88 | * usable to represent a match of the pattern in the result of a query, | ||
89 | * or to specify the bound (fixed) input parameters when issuing a query. | ||
90 | * | ||
91 | * @see Matcher | ||
92 | * | ||
93 | */ | ||
94 | public static abstract class Match extends BasePatternMatch { | ||
95 | private ApplicationInstance fApp; | ||
96 | |||
97 | private HostInstance fHost; | ||
98 | |||
99 | private static List<String> parameterNames = makeImmutableList("App", "Host"); | ||
100 | |||
101 | private Match(final ApplicationInstance pApp, final HostInstance pHost) { | ||
102 | this.fApp = pApp; | ||
103 | this.fHost = pHost; | ||
104 | } | ||
105 | |||
106 | @Override | ||
107 | public Object get(final String parameterName) { | ||
108 | if ("App".equals(parameterName)) return this.fApp; | ||
109 | if ("Host".equals(parameterName)) return this.fHost; | ||
110 | return null; | ||
111 | } | ||
112 | |||
113 | public ApplicationInstance getApp() { | ||
114 | return this.fApp; | ||
115 | } | ||
116 | |||
117 | public HostInstance getHost() { | ||
118 | return this.fHost; | ||
119 | } | ||
120 | |||
121 | @Override | ||
122 | public boolean set(final String parameterName, final Object newValue) { | ||
123 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
124 | if ("App".equals(parameterName) ) { | ||
125 | this.fApp = (ApplicationInstance) newValue; | ||
126 | return true; | ||
127 | } | ||
128 | if ("Host".equals(parameterName) ) { | ||
129 | this.fHost = (HostInstance) newValue; | ||
130 | return true; | ||
131 | } | ||
132 | return false; | ||
133 | } | ||
134 | |||
135 | public void setApp(final ApplicationInstance pApp) { | ||
136 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
137 | this.fApp = pApp; | ||
138 | } | ||
139 | |||
140 | public void setHost(final HostInstance pHost) { | ||
141 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
142 | this.fHost = pHost; | ||
143 | } | ||
144 | |||
145 | @Override | ||
146 | public String patternName() { | ||
147 | return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.allocate"; | ||
148 | } | ||
149 | |||
150 | @Override | ||
151 | public List<String> parameterNames() { | ||
152 | return Allocate.Match.parameterNames; | ||
153 | } | ||
154 | |||
155 | @Override | ||
156 | public Object[] toArray() { | ||
157 | return new Object[]{fApp, fHost}; | ||
158 | } | ||
159 | |||
160 | @Override | ||
161 | public Allocate.Match toImmutable() { | ||
162 | return isMutable() ? newMatch(fApp, fHost) : this; | ||
163 | } | ||
164 | |||
165 | @Override | ||
166 | public String prettyPrint() { | ||
167 | StringBuilder result = new StringBuilder(); | ||
168 | result.append("\"App\"=" + prettyPrintValue(fApp) + ", "); | ||
169 | result.append("\"Host\"=" + prettyPrintValue(fHost)); | ||
170 | return result.toString(); | ||
171 | } | ||
172 | |||
173 | @Override | ||
174 | public int hashCode() { | ||
175 | return Objects.hash(fApp, fHost); | ||
176 | } | ||
177 | |||
178 | @Override | ||
179 | public boolean equals(final Object obj) { | ||
180 | if (this == obj) | ||
181 | return true; | ||
182 | if (obj == null) { | ||
183 | return false; | ||
184 | } | ||
185 | if ((obj instanceof Allocate.Match)) { | ||
186 | Allocate.Match other = (Allocate.Match) obj; | ||
187 | return Objects.equals(fApp, other.fApp) && Objects.equals(fHost, other.fHost); | ||
188 | } else { | ||
189 | // this should be infrequent | ||
190 | if (!(obj instanceof IPatternMatch)) { | ||
191 | return false; | ||
192 | } | ||
193 | IPatternMatch otherSig = (IPatternMatch) obj; | ||
194 | return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); | ||
195 | } | ||
196 | } | ||
197 | |||
198 | @Override | ||
199 | public Allocate specification() { | ||
200 | return Allocate.instance(); | ||
201 | } | ||
202 | |||
203 | /** | ||
204 | * Returns an empty, mutable match. | ||
205 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
206 | * | ||
207 | * @return the empty match. | ||
208 | * | ||
209 | */ | ||
210 | public static Allocate.Match newEmptyMatch() { | ||
211 | return new Mutable(null, null); | ||
212 | } | ||
213 | |||
214 | /** | ||
215 | * Returns a mutable (partial) match. | ||
216 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
217 | * | ||
218 | * @param pApp the fixed value of pattern parameter App, or null if not bound. | ||
219 | * @param pHost the fixed value of pattern parameter Host, or null if not bound. | ||
220 | * @return the new, mutable (partial) match object. | ||
221 | * | ||
222 | */ | ||
223 | public static Allocate.Match newMutableMatch(final ApplicationInstance pApp, final HostInstance pHost) { | ||
224 | return new Mutable(pApp, pHost); | ||
225 | } | ||
226 | |||
227 | /** | ||
228 | * Returns a new (partial) match. | ||
229 | * This can be used e.g. to call the matcher with a partial match. | ||
230 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
231 | * @param pApp the fixed value of pattern parameter App, or null if not bound. | ||
232 | * @param pHost the fixed value of pattern parameter Host, or null if not bound. | ||
233 | * @return the (partial) match object. | ||
234 | * | ||
235 | */ | ||
236 | public static Allocate.Match newMatch(final ApplicationInstance pApp, final HostInstance pHost) { | ||
237 | return new Immutable(pApp, pHost); | ||
238 | } | ||
239 | |||
240 | private static final class Mutable extends Allocate.Match { | ||
241 | Mutable(final ApplicationInstance pApp, final HostInstance pHost) { | ||
242 | super(pApp, pHost); | ||
243 | } | ||
244 | |||
245 | @Override | ||
246 | public boolean isMutable() { | ||
247 | return true; | ||
248 | } | ||
249 | } | ||
250 | |||
251 | private static final class Immutable extends Allocate.Match { | ||
252 | Immutable(final ApplicationInstance pApp, final HostInstance pHost) { | ||
253 | super(pApp, pHost); | ||
254 | } | ||
255 | |||
256 | @Override | ||
257 | public boolean isMutable() { | ||
258 | return false; | ||
259 | } | ||
260 | } | ||
261 | } | ||
262 | |||
263 | /** | ||
264 | * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.allocate pattern, | ||
265 | * providing pattern-specific query methods. | ||
266 | * | ||
267 | * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, | ||
268 | * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. | ||
269 | * | ||
270 | * <p>Matches of the pattern will be represented as {@link Match}. | ||
271 | * | ||
272 | * <p>Original source: | ||
273 | * <code><pre> | ||
274 | * // | ||
275 | * // Transformation rule preconditions for rule-based DSE | ||
276 | * // | ||
277 | * | ||
278 | * pattern allocate(App : ApplicationInstance, Host : HostInstance) { | ||
279 | * ApplicationInstance.type.requirements(App, Req); | ||
280 | * ResourceRequirement.hostType.instances(Req, Host); | ||
281 | * find unallocatedAppInstance(App); | ||
282 | * find availableMemory(Host, AvailableMem); | ||
283 | * find availableHdd(Host, AvailableHdd); | ||
284 | * ResourceRequirement.requiredMemory(Req, RequiredMem); | ||
285 | * ResourceRequirement.requiredHdd(Req, RequiredHdd); | ||
286 | * check(AvailableMem {@literal >}= RequiredMem); | ||
287 | * check(AvailableHdd {@literal >}= RequiredHdd); | ||
288 | * neg ApplicationInstance.requirement.instances.allocatedTo(App, Host); | ||
289 | * } | ||
290 | * </pre></code> | ||
291 | * | ||
292 | * @see Match | ||
293 | * @see Allocate | ||
294 | * | ||
295 | */ | ||
296 | public static class Matcher extends BaseMatcher<Allocate.Match> { | ||
297 | /** | ||
298 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
299 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
300 | * | ||
301 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
302 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
303 | * | ||
304 | */ | ||
305 | public static Allocate.Matcher on(final ViatraQueryEngine engine) { | ||
306 | // check if matcher already exists | ||
307 | Matcher matcher = engine.getExistingMatcher(querySpecification()); | ||
308 | if (matcher == null) { | ||
309 | matcher = (Matcher)engine.getMatcher(querySpecification()); | ||
310 | } | ||
311 | return matcher; | ||
312 | } | ||
313 | |||
314 | /** | ||
315 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
316 | * @return an initialized matcher | ||
317 | * @noreference This method is for internal matcher initialization by the framework, do not call it manually. | ||
318 | * | ||
319 | */ | ||
320 | public static Allocate.Matcher create() { | ||
321 | return new Matcher(); | ||
322 | } | ||
323 | |||
324 | private static final int POSITION_APP = 0; | ||
325 | |||
326 | private static final int POSITION_HOST = 1; | ||
327 | |||
328 | private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Allocate.Matcher.class); | ||
329 | |||
330 | /** | ||
331 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
332 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
333 | * | ||
334 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
335 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
336 | * | ||
337 | */ | ||
338 | private Matcher() { | ||
339 | super(querySpecification()); | ||
340 | } | ||
341 | |||
342 | /** | ||
343 | * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. | ||
344 | * @param pApp the fixed value of pattern parameter App, or null if not bound. | ||
345 | * @param pHost the fixed value of pattern parameter Host, or null if not bound. | ||
346 | * @return matches represented as a Match object. | ||
347 | * | ||
348 | */ | ||
349 | public Collection<Allocate.Match> getAllMatches(final ApplicationInstance pApp, final HostInstance pHost) { | ||
350 | return rawStreamAllMatches(new Object[]{pApp, pHost}).collect(Collectors.toSet()); | ||
351 | } | ||
352 | |||
353 | /** | ||
354 | * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. | ||
355 | * </p> | ||
356 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
357 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
358 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
359 | * @param pApp the fixed value of pattern parameter App, or null if not bound. | ||
360 | * @param pHost the fixed value of pattern parameter Host, or null if not bound. | ||
361 | * @return a stream of matches represented as a Match object. | ||
362 | * | ||
363 | */ | ||
364 | public Stream<Allocate.Match> streamAllMatches(final ApplicationInstance pApp, final HostInstance pHost) { | ||
365 | return rawStreamAllMatches(new Object[]{pApp, pHost}); | ||
366 | } | ||
367 | |||
368 | /** | ||
369 | * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
370 | * Neither determinism nor randomness of selection is guaranteed. | ||
371 | * @param pApp the fixed value of pattern parameter App, or null if not bound. | ||
372 | * @param pHost the fixed value of pattern parameter Host, or null if not bound. | ||
373 | * @return a match represented as a Match object, or null if no match is found. | ||
374 | * | ||
375 | */ | ||
376 | public Optional<Allocate.Match> getOneArbitraryMatch(final ApplicationInstance pApp, final HostInstance pHost) { | ||
377 | return rawGetOneArbitraryMatch(new Object[]{pApp, pHost}); | ||
378 | } | ||
379 | |||
380 | /** | ||
381 | * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, | ||
382 | * under any possible substitution of the unspecified parameters (if any). | ||
383 | * @param pApp the fixed value of pattern parameter App, or null if not bound. | ||
384 | * @param pHost the fixed value of pattern parameter Host, or null if not bound. | ||
385 | * @return true if the input is a valid (partial) match of the pattern. | ||
386 | * | ||
387 | */ | ||
388 | public boolean hasMatch(final ApplicationInstance pApp, final HostInstance pHost) { | ||
389 | return rawHasMatch(new Object[]{pApp, pHost}); | ||
390 | } | ||
391 | |||
392 | /** | ||
393 | * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. | ||
394 | * @param pApp the fixed value of pattern parameter App, or null if not bound. | ||
395 | * @param pHost the fixed value of pattern parameter Host, or null if not bound. | ||
396 | * @return the number of pattern matches found. | ||
397 | * | ||
398 | */ | ||
399 | public int countMatches(final ApplicationInstance pApp, final HostInstance pHost) { | ||
400 | return rawCountMatches(new Object[]{pApp, pHost}); | ||
401 | } | ||
402 | |||
403 | /** | ||
404 | * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
405 | * Neither determinism nor randomness of selection is guaranteed. | ||
406 | * @param pApp the fixed value of pattern parameter App, or null if not bound. | ||
407 | * @param pHost the fixed value of pattern parameter Host, or null if not bound. | ||
408 | * @param processor the action that will process the selected match. | ||
409 | * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked | ||
410 | * | ||
411 | */ | ||
412 | public boolean forOneArbitraryMatch(final ApplicationInstance pApp, final HostInstance pHost, final Consumer<? super Allocate.Match> processor) { | ||
413 | return rawForOneArbitraryMatch(new Object[]{pApp, pHost}, processor); | ||
414 | } | ||
415 | |||
416 | /** | ||
417 | * Returns a new (partial) match. | ||
418 | * This can be used e.g. to call the matcher with a partial match. | ||
419 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
420 | * @param pApp the fixed value of pattern parameter App, or null if not bound. | ||
421 | * @param pHost the fixed value of pattern parameter Host, or null if not bound. | ||
422 | * @return the (partial) match object. | ||
423 | * | ||
424 | */ | ||
425 | public Allocate.Match newMatch(final ApplicationInstance pApp, final HostInstance pHost) { | ||
426 | return Allocate.Match.newMatch(pApp, pHost); | ||
427 | } | ||
428 | |||
429 | /** | ||
430 | * Retrieve the set of values that occur in matches for App. | ||
431 | * @return the Set of all values or empty set if there are no matches | ||
432 | * | ||
433 | */ | ||
434 | protected Stream<ApplicationInstance> rawStreamAllValuesOfApp(final Object[] parameters) { | ||
435 | return rawStreamAllValues(POSITION_APP, parameters).map(ApplicationInstance.class::cast); | ||
436 | } | ||
437 | |||
438 | /** | ||
439 | * Retrieve the set of values that occur in matches for App. | ||
440 | * @return the Set of all values or empty set if there are no matches | ||
441 | * | ||
442 | */ | ||
443 | public Set<ApplicationInstance> getAllValuesOfApp() { | ||
444 | return rawStreamAllValuesOfApp(emptyArray()).collect(Collectors.toSet()); | ||
445 | } | ||
446 | |||
447 | /** | ||
448 | * Retrieve the set of values that occur in matches for App. | ||
449 | * @return the Set of all values or empty set if there are no matches | ||
450 | * | ||
451 | */ | ||
452 | public Stream<ApplicationInstance> streamAllValuesOfApp() { | ||
453 | return rawStreamAllValuesOfApp(emptyArray()); | ||
454 | } | ||
455 | |||
456 | /** | ||
457 | * Retrieve the set of values that occur in matches for App. | ||
458 | * </p> | ||
459 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
460 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
461 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
462 | * | ||
463 | * @return the Stream of all values or empty set if there are no matches | ||
464 | * | ||
465 | */ | ||
466 | public Stream<ApplicationInstance> streamAllValuesOfApp(final Allocate.Match partialMatch) { | ||
467 | return rawStreamAllValuesOfApp(partialMatch.toArray()); | ||
468 | } | ||
469 | |||
470 | /** | ||
471 | * Retrieve the set of values that occur in matches for App. | ||
472 | * </p> | ||
473 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
474 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
475 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
476 | * | ||
477 | * @return the Stream of all values or empty set if there are no matches | ||
478 | * | ||
479 | */ | ||
480 | public Stream<ApplicationInstance> streamAllValuesOfApp(final HostInstance pHost) { | ||
481 | return rawStreamAllValuesOfApp(new Object[]{null, pHost}); | ||
482 | } | ||
483 | |||
484 | /** | ||
485 | * Retrieve the set of values that occur in matches for App. | ||
486 | * @return the Set of all values or empty set if there are no matches | ||
487 | * | ||
488 | */ | ||
489 | public Set<ApplicationInstance> getAllValuesOfApp(final Allocate.Match partialMatch) { | ||
490 | return rawStreamAllValuesOfApp(partialMatch.toArray()).collect(Collectors.toSet()); | ||
491 | } | ||
492 | |||
493 | /** | ||
494 | * Retrieve the set of values that occur in matches for App. | ||
495 | * @return the Set of all values or empty set if there are no matches | ||
496 | * | ||
497 | */ | ||
498 | public Set<ApplicationInstance> getAllValuesOfApp(final HostInstance pHost) { | ||
499 | return rawStreamAllValuesOfApp(new Object[]{null, pHost}).collect(Collectors.toSet()); | ||
500 | } | ||
501 | |||
502 | /** | ||
503 | * Retrieve the set of values that occur in matches for Host. | ||
504 | * @return the Set of all values or empty set if there are no matches | ||
505 | * | ||
506 | */ | ||
507 | protected Stream<HostInstance> rawStreamAllValuesOfHost(final Object[] parameters) { | ||
508 | return rawStreamAllValues(POSITION_HOST, parameters).map(HostInstance.class::cast); | ||
509 | } | ||
510 | |||
511 | /** | ||
512 | * Retrieve the set of values that occur in matches for Host. | ||
513 | * @return the Set of all values or empty set if there are no matches | ||
514 | * | ||
515 | */ | ||
516 | public Set<HostInstance> getAllValuesOfHost() { | ||
517 | return rawStreamAllValuesOfHost(emptyArray()).collect(Collectors.toSet()); | ||
518 | } | ||
519 | |||
520 | /** | ||
521 | * Retrieve the set of values that occur in matches for Host. | ||
522 | * @return the Set of all values or empty set if there are no matches | ||
523 | * | ||
524 | */ | ||
525 | public Stream<HostInstance> streamAllValuesOfHost() { | ||
526 | return rawStreamAllValuesOfHost(emptyArray()); | ||
527 | } | ||
528 | |||
529 | /** | ||
530 | * Retrieve the set of values that occur in matches for Host. | ||
531 | * </p> | ||
532 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
533 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
534 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
535 | * | ||
536 | * @return the Stream of all values or empty set if there are no matches | ||
537 | * | ||
538 | */ | ||
539 | public Stream<HostInstance> streamAllValuesOfHost(final Allocate.Match partialMatch) { | ||
540 | return rawStreamAllValuesOfHost(partialMatch.toArray()); | ||
541 | } | ||
542 | |||
543 | /** | ||
544 | * Retrieve the set of values that occur in matches for Host. | ||
545 | * </p> | ||
546 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
547 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
548 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
549 | * | ||
550 | * @return the Stream of all values or empty set if there are no matches | ||
551 | * | ||
552 | */ | ||
553 | public Stream<HostInstance> streamAllValuesOfHost(final ApplicationInstance pApp) { | ||
554 | return rawStreamAllValuesOfHost(new Object[]{pApp, null}); | ||
555 | } | ||
556 | |||
557 | /** | ||
558 | * Retrieve the set of values that occur in matches for Host. | ||
559 | * @return the Set of all values or empty set if there are no matches | ||
560 | * | ||
561 | */ | ||
562 | public Set<HostInstance> getAllValuesOfHost(final Allocate.Match partialMatch) { | ||
563 | return rawStreamAllValuesOfHost(partialMatch.toArray()).collect(Collectors.toSet()); | ||
564 | } | ||
565 | |||
566 | /** | ||
567 | * Retrieve the set of values that occur in matches for Host. | ||
568 | * @return the Set of all values or empty set if there are no matches | ||
569 | * | ||
570 | */ | ||
571 | public Set<HostInstance> getAllValuesOfHost(final ApplicationInstance pApp) { | ||
572 | return rawStreamAllValuesOfHost(new Object[]{pApp, null}).collect(Collectors.toSet()); | ||
573 | } | ||
574 | |||
575 | @Override | ||
576 | protected Allocate.Match tupleToMatch(final Tuple t) { | ||
577 | try { | ||
578 | return Allocate.Match.newMatch((ApplicationInstance) t.get(POSITION_APP), (HostInstance) t.get(POSITION_HOST)); | ||
579 | } catch(ClassCastException e) { | ||
580 | LOGGER.error("Element(s) in tuple not properly typed!",e); | ||
581 | return null; | ||
582 | } | ||
583 | } | ||
584 | |||
585 | @Override | ||
586 | protected Allocate.Match arrayToMatch(final Object[] match) { | ||
587 | try { | ||
588 | return Allocate.Match.newMatch((ApplicationInstance) match[POSITION_APP], (HostInstance) match[POSITION_HOST]); | ||
589 | } catch(ClassCastException e) { | ||
590 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
591 | return null; | ||
592 | } | ||
593 | } | ||
594 | |||
595 | @Override | ||
596 | protected Allocate.Match arrayToMatchMutable(final Object[] match) { | ||
597 | try { | ||
598 | return Allocate.Match.newMutableMatch((ApplicationInstance) match[POSITION_APP], (HostInstance) match[POSITION_HOST]); | ||
599 | } catch(ClassCastException e) { | ||
600 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
601 | return null; | ||
602 | } | ||
603 | } | ||
604 | |||
605 | /** | ||
606 | * @return the singleton instance of the query specification of this pattern | ||
607 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
608 | * | ||
609 | */ | ||
610 | public static IQuerySpecification<Allocate.Matcher> querySpecification() { | ||
611 | return Allocate.instance(); | ||
612 | } | ||
613 | } | ||
614 | |||
615 | private Allocate() { | ||
616 | super(GeneratedPQuery.INSTANCE); | ||
617 | } | ||
618 | |||
619 | /** | ||
620 | * @return the singleton instance of the query specification | ||
621 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
622 | * | ||
623 | */ | ||
624 | public static Allocate instance() { | ||
625 | try{ | ||
626 | return LazyHolder.INSTANCE; | ||
627 | } catch (ExceptionInInitializerError err) { | ||
628 | throw processInitializerError(err); | ||
629 | } | ||
630 | } | ||
631 | |||
632 | @Override | ||
633 | protected Allocate.Matcher instantiate(final ViatraQueryEngine engine) { | ||
634 | return Allocate.Matcher.on(engine); | ||
635 | } | ||
636 | |||
637 | @Override | ||
638 | public Allocate.Matcher instantiate() { | ||
639 | return Allocate.Matcher.create(); | ||
640 | } | ||
641 | |||
642 | @Override | ||
643 | public Allocate.Match newEmptyMatch() { | ||
644 | return Allocate.Match.newEmptyMatch(); | ||
645 | } | ||
646 | |||
647 | @Override | ||
648 | public Allocate.Match newMatch(final Object... parameters) { | ||
649 | return Allocate.Match.newMatch((hu.bme.mit.inf.dslreasoner.domains.cps.ApplicationInstance) parameters[0], (hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance) parameters[1]); | ||
650 | } | ||
651 | |||
652 | /** | ||
653 | * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.Allocate (visibility: PUBLIC, simpleName: Allocate, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.Allocate, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)} to be created | ||
654 | * <b>not</b> at the class load time of the outer class, | ||
655 | * but rather at the first call to {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.Allocate (visibility: PUBLIC, simpleName: Allocate, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.Allocate, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}. | ||
656 | * | ||
657 | * <p> This workaround is required e.g. to support recursion. | ||
658 | * | ||
659 | */ | ||
660 | private static class LazyHolder { | ||
661 | private static final Allocate INSTANCE = new Allocate(); | ||
662 | |||
663 | /** | ||
664 | * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned. | ||
665 | * This initialization order is required to support indirect recursion. | ||
666 | * | ||
667 | * <p> The static initializer is defined using a helper field to work around limitations of the code generator. | ||
668 | * | ||
669 | */ | ||
670 | private static final Object STATIC_INITIALIZER = ensureInitialized(); | ||
671 | |||
672 | public static Object ensureInitialized() { | ||
673 | INSTANCE.ensureInitializedInternal(); | ||
674 | return null; | ||
675 | } | ||
676 | } | ||
677 | |||
678 | private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { | ||
679 | private static final Allocate.GeneratedPQuery INSTANCE = new GeneratedPQuery(); | ||
680 | |||
681 | private final PParameter parameter_App = new PParameter("App", "hu.bme.mit.inf.dslreasoner.domains.cps.ApplicationInstance", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "ApplicationInstance")), PParameterDirection.INOUT); | ||
682 | |||
683 | private final PParameter parameter_Host = new PParameter("Host", "hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "HostInstance")), PParameterDirection.INOUT); | ||
684 | |||
685 | private final List<PParameter> parameters = Arrays.asList(parameter_App, parameter_Host); | ||
686 | |||
687 | private class Embedded_1_ApplicationInstance_requirement_instances_allocatedTo extends BaseGeneratedEMFPQuery { | ||
688 | private final PParameter parameter_p0 = new PParameter("p0", "hu.bme.mit.inf.dslreasoner.domains.cps.ApplicationInstance", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "ApplicationInstance")), PParameterDirection.INOUT); | ||
689 | |||
690 | private final PParameter parameter_p1 = new PParameter("p1", "hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "HostInstance")), PParameterDirection.INOUT); | ||
691 | |||
692 | private final List<PParameter> embeddedParameters = Arrays.asList(parameter_p0, parameter_p1); | ||
693 | |||
694 | public Embedded_1_ApplicationInstance_requirement_instances_allocatedTo() { | ||
695 | super(PVisibility.EMBEDDED); | ||
696 | } | ||
697 | |||
698 | @Override | ||
699 | public String getFullyQualifiedName() { | ||
700 | return GeneratedPQuery.this.getFullyQualifiedName() + "$Embedded_1_ApplicationInstance_requirement_instances_allocatedTo"; | ||
701 | } | ||
702 | |||
703 | @Override | ||
704 | public List<PParameter> getParameters() { | ||
705 | return embeddedParameters; | ||
706 | } | ||
707 | |||
708 | @Override | ||
709 | public Set<PBody> doGetContainedBodies() { | ||
710 | PBody body = new PBody(this); | ||
711 | PVariable var_p0 = body.getOrCreateVariableByName("p0"); | ||
712 | PVariable var_p1 = body.getOrCreateVariableByName("p1"); | ||
713 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
714 | new ExportedParameter(body, var_p0, parameter_p0), | ||
715 | new ExportedParameter(body, var_p1, parameter_p1) | ||
716 | )); | ||
717 | // ApplicationInstance.requirement.instances.allocatedTo(App, Host) | ||
718 | new TypeConstraint(body, Tuples.flatTupleOf(var_p0), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance"))); | ||
719 | PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); | ||
720 | new TypeConstraint(body, Tuples.flatTupleOf(var_p0, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ApplicationInstance", "requirement"))); | ||
721 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "Requirement"))); | ||
722 | PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); | ||
723 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "Requirement", "instances"))); | ||
724 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance"))); | ||
725 | PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}"); | ||
726 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_, var__virtual_2_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ApplicationInstance", "allocatedTo"))); | ||
727 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); | ||
728 | new Equality(body, var__virtual_2_, var_p1); | ||
729 | return Collections.singleton(body); | ||
730 | } | ||
731 | } | ||
732 | |||
733 | private GeneratedPQuery() { | ||
734 | super(PVisibility.PUBLIC); | ||
735 | } | ||
736 | |||
737 | @Override | ||
738 | public String getFullyQualifiedName() { | ||
739 | return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.allocate"; | ||
740 | } | ||
741 | |||
742 | @Override | ||
743 | public List<String> getParameterNames() { | ||
744 | return Arrays.asList("App","Host"); | ||
745 | } | ||
746 | |||
747 | @Override | ||
748 | public List<PParameter> getParameters() { | ||
749 | return parameters; | ||
750 | } | ||
751 | |||
752 | @Override | ||
753 | public Set<PBody> doGetContainedBodies() { | ||
754 | setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); | ||
755 | Set<PBody> bodies = new LinkedHashSet<>(); | ||
756 | { | ||
757 | PBody body = new PBody(this); | ||
758 | PVariable var_App = body.getOrCreateVariableByName("App"); | ||
759 | PVariable var_Host = body.getOrCreateVariableByName("Host"); | ||
760 | PVariable var_Req = body.getOrCreateVariableByName("Req"); | ||
761 | PVariable var_AvailableMem = body.getOrCreateVariableByName("AvailableMem"); | ||
762 | PVariable var_AvailableHdd = body.getOrCreateVariableByName("AvailableHdd"); | ||
763 | PVariable var_RequiredMem = body.getOrCreateVariableByName("RequiredMem"); | ||
764 | PVariable var_RequiredHdd = body.getOrCreateVariableByName("RequiredHdd"); | ||
765 | new TypeConstraint(body, Tuples.flatTupleOf(var_App), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance"))); | ||
766 | new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); | ||
767 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
768 | new ExportedParameter(body, var_App, parameter_App), | ||
769 | new ExportedParameter(body, var_Host, parameter_Host) | ||
770 | )); | ||
771 | // ApplicationInstance.type.requirements(App, Req) | ||
772 | new TypeConstraint(body, Tuples.flatTupleOf(var_App), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance"))); | ||
773 | PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); | ||
774 | new TypeConstraint(body, Tuples.flatTupleOf(var_App, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ApplicationInstance", "type"))); | ||
775 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationType"))); | ||
776 | PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); | ||
777 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ApplicationType", "requirements"))); | ||
778 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ResourceRequirement"))); | ||
779 | new Equality(body, var__virtual_1_, var_Req); | ||
780 | // ResourceRequirement.hostType.instances(Req, Host) | ||
781 | new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ResourceRequirement"))); | ||
782 | PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}"); | ||
783 | new TypeConstraint(body, Tuples.flatTupleOf(var_Req, var__virtual_2_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ResourceRequirement", "hostType"))); | ||
784 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostType"))); | ||
785 | PVariable var__virtual_3_ = body.getOrCreateVariableByName(".virtual{3}"); | ||
786 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_, var__virtual_3_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "HostType", "instances"))); | ||
787 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_3_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); | ||
788 | new Equality(body, var__virtual_3_, var_Host); | ||
789 | // find unallocatedAppInstance(App) | ||
790 | new PositivePatternCall(body, Tuples.flatTupleOf(var_App), UnallocatedAppInstance.instance().getInternalQueryRepresentation()); | ||
791 | // find availableMemory(Host, AvailableMem) | ||
792 | new PositivePatternCall(body, Tuples.flatTupleOf(var_Host, var_AvailableMem), AvailableMemory.instance().getInternalQueryRepresentation()); | ||
793 | // find availableHdd(Host, AvailableHdd) | ||
794 | new PositivePatternCall(body, Tuples.flatTupleOf(var_Host, var_AvailableHdd), AvailableHdd.instance().getInternalQueryRepresentation()); | ||
795 | // ResourceRequirement.requiredMemory(Req, RequiredMem) | ||
796 | new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ResourceRequirement"))); | ||
797 | PVariable var__virtual_4_ = body.getOrCreateVariableByName(".virtual{4}"); | ||
798 | new TypeConstraint(body, Tuples.flatTupleOf(var_Req, var__virtual_4_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ResourceRequirement", "requiredMemory"))); | ||
799 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_4_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt"))); | ||
800 | new Equality(body, var__virtual_4_, var_RequiredMem); | ||
801 | // ResourceRequirement.requiredHdd(Req, RequiredHdd) | ||
802 | new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ResourceRequirement"))); | ||
803 | PVariable var__virtual_5_ = body.getOrCreateVariableByName(".virtual{5}"); | ||
804 | new TypeConstraint(body, Tuples.flatTupleOf(var_Req, var__virtual_5_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ResourceRequirement", "requiredHdd"))); | ||
805 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_5_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt"))); | ||
806 | new Equality(body, var__virtual_5_, var_RequiredHdd); | ||
807 | // check(AvailableMem >= RequiredMem) | ||
808 | new ExpressionEvaluation(body, new IExpressionEvaluator() { | ||
809 | |||
810 | @Override | ||
811 | public String getShortDescription() { | ||
812 | return "Expression evaluation from pattern allocate"; | ||
813 | } | ||
814 | |||
815 | @Override | ||
816 | public Iterable<String> getInputParameterNames() { | ||
817 | return Arrays.asList("AvailableMem", "RequiredMem");} | ||
818 | |||
819 | @Override | ||
820 | public Object evaluateExpression(IValueProvider provider) throws Exception { | ||
821 | Integer AvailableMem = (Integer) provider.getValue("AvailableMem"); | ||
822 | Integer RequiredMem = (Integer) provider.getValue("RequiredMem"); | ||
823 | return evaluateExpression_1_1(AvailableMem, RequiredMem); | ||
824 | } | ||
825 | }, null); | ||
826 | // check(AvailableHdd >= RequiredHdd) | ||
827 | new ExpressionEvaluation(body, new IExpressionEvaluator() { | ||
828 | |||
829 | @Override | ||
830 | public String getShortDescription() { | ||
831 | return "Expression evaluation from pattern allocate"; | ||
832 | } | ||
833 | |||
834 | @Override | ||
835 | public Iterable<String> getInputParameterNames() { | ||
836 | return Arrays.asList("AvailableHdd", "RequiredHdd");} | ||
837 | |||
838 | @Override | ||
839 | public Object evaluateExpression(IValueProvider provider) throws Exception { | ||
840 | Integer AvailableHdd = (Integer) provider.getValue("AvailableHdd"); | ||
841 | Integer RequiredHdd = (Integer) provider.getValue("RequiredHdd"); | ||
842 | return evaluateExpression_1_2(AvailableHdd, RequiredHdd); | ||
843 | } | ||
844 | }, null); | ||
845 | // neg ApplicationInstance.requirement.instances.allocatedTo(App, Host) | ||
846 | new NegativePatternCall(body, Tuples.flatTupleOf(var_App, var_Host), new Allocate.GeneratedPQuery.Embedded_1_ApplicationInstance_requirement_instances_allocatedTo()); | ||
847 | bodies.add(body); | ||
848 | } | ||
849 | return bodies; | ||
850 | } | ||
851 | } | ||
852 | |||
853 | private static boolean evaluateExpression_1_1(final Integer AvailableMem, final Integer RequiredMem) { | ||
854 | boolean _greaterEqualsThan = (AvailableMem.compareTo(RequiredMem) >= 0); | ||
855 | return _greaterEqualsThan; | ||
856 | } | ||
857 | |||
858 | private static boolean evaluateExpression_1_2(final Integer AvailableHdd, final Integer RequiredHdd) { | ||
859 | boolean _greaterEqualsThan = (AvailableHdd.compareTo(RequiredHdd) >= 0); | ||
860 | return _greaterEqualsThan; | ||
861 | } | ||
862 | } | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/AllocationWithoutResourceRequirement.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/AllocationWithoutResourceRequirement.java new file mode 100644 index 00000000..6da5f76d --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/AllocationWithoutResourceRequirement.java | |||
@@ -0,0 +1,717 @@ | |||
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.ApplicationInstance; | ||
7 | import hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance; | ||
8 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.ResourceRequirement; | ||
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.emf.types.EStructuralFeatureInstancesKey; | ||
30 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
31 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | ||
32 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | ||
33 | import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation; | ||
34 | import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference; | ||
35 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; | ||
36 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
37 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.NegativePatternCall; | ||
38 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
39 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | ||
40 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; | ||
41 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | ||
42 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; | ||
43 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
44 | import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; | ||
45 | |||
46 | /** | ||
47 | * A pattern-specific query specification that can instantiate Matcher in a type-safe way. | ||
48 | * | ||
49 | * <p>Original source: | ||
50 | * <code><pre> | ||
51 | * {@literal @}Constraint(severity = "error", key = {Host, App}, | ||
52 | * message = "Application instance must be allocated to a supported host type.") | ||
53 | * pattern allocationWithoutResourceRequirement(Host : HostInstance, App : ApplicationInstance) { | ||
54 | * ApplicationInstance.allocatedTo(App, Host); | ||
55 | * neg find resourceRequirement(Host, App, _); | ||
56 | * } | ||
57 | * </pre></code> | ||
58 | * | ||
59 | * @see Matcher | ||
60 | * @see Match | ||
61 | * | ||
62 | */ | ||
63 | @SuppressWarnings("all") | ||
64 | public final class AllocationWithoutResourceRequirement extends BaseGeneratedEMFQuerySpecification<AllocationWithoutResourceRequirement.Matcher> { | ||
65 | /** | ||
66 | * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.allocationWithoutResourceRequirement pattern, | ||
67 | * to be used in conjunction with {@link Matcher}. | ||
68 | * | ||
69 | * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. | ||
70 | * Each instance is a (possibly partial) substitution of pattern parameters, | ||
71 | * usable to represent a match of the pattern in the result of a query, | ||
72 | * or to specify the bound (fixed) input parameters when issuing a query. | ||
73 | * | ||
74 | * @see Matcher | ||
75 | * | ||
76 | */ | ||
77 | public static abstract class Match extends BasePatternMatch { | ||
78 | private HostInstance fHost; | ||
79 | |||
80 | private ApplicationInstance fApp; | ||
81 | |||
82 | private static List<String> parameterNames = makeImmutableList("Host", "App"); | ||
83 | |||
84 | private Match(final HostInstance pHost, final ApplicationInstance pApp) { | ||
85 | this.fHost = pHost; | ||
86 | this.fApp = pApp; | ||
87 | } | ||
88 | |||
89 | @Override | ||
90 | public Object get(final String parameterName) { | ||
91 | if ("Host".equals(parameterName)) return this.fHost; | ||
92 | if ("App".equals(parameterName)) return this.fApp; | ||
93 | return null; | ||
94 | } | ||
95 | |||
96 | public HostInstance getHost() { | ||
97 | return this.fHost; | ||
98 | } | ||
99 | |||
100 | public ApplicationInstance getApp() { | ||
101 | return this.fApp; | ||
102 | } | ||
103 | |||
104 | @Override | ||
105 | public boolean set(final String parameterName, final Object newValue) { | ||
106 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
107 | if ("Host".equals(parameterName) ) { | ||
108 | this.fHost = (HostInstance) newValue; | ||
109 | return true; | ||
110 | } | ||
111 | if ("App".equals(parameterName) ) { | ||
112 | this.fApp = (ApplicationInstance) newValue; | ||
113 | return true; | ||
114 | } | ||
115 | return false; | ||
116 | } | ||
117 | |||
118 | public void setHost(final HostInstance pHost) { | ||
119 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
120 | this.fHost = pHost; | ||
121 | } | ||
122 | |||
123 | public void setApp(final ApplicationInstance pApp) { | ||
124 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
125 | this.fApp = pApp; | ||
126 | } | ||
127 | |||
128 | @Override | ||
129 | public String patternName() { | ||
130 | return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.allocationWithoutResourceRequirement"; | ||
131 | } | ||
132 | |||
133 | @Override | ||
134 | public List<String> parameterNames() { | ||
135 | return AllocationWithoutResourceRequirement.Match.parameterNames; | ||
136 | } | ||
137 | |||
138 | @Override | ||
139 | public Object[] toArray() { | ||
140 | return new Object[]{fHost, fApp}; | ||
141 | } | ||
142 | |||
143 | @Override | ||
144 | public AllocationWithoutResourceRequirement.Match toImmutable() { | ||
145 | return isMutable() ? newMatch(fHost, fApp) : this; | ||
146 | } | ||
147 | |||
148 | @Override | ||
149 | public String prettyPrint() { | ||
150 | StringBuilder result = new StringBuilder(); | ||
151 | result.append("\"Host\"=" + prettyPrintValue(fHost) + ", "); | ||
152 | result.append("\"App\"=" + prettyPrintValue(fApp)); | ||
153 | return result.toString(); | ||
154 | } | ||
155 | |||
156 | @Override | ||
157 | public int hashCode() { | ||
158 | return Objects.hash(fHost, fApp); | ||
159 | } | ||
160 | |||
161 | @Override | ||
162 | public boolean equals(final Object obj) { | ||
163 | if (this == obj) | ||
164 | return true; | ||
165 | if (obj == null) { | ||
166 | return false; | ||
167 | } | ||
168 | if ((obj instanceof AllocationWithoutResourceRequirement.Match)) { | ||
169 | AllocationWithoutResourceRequirement.Match other = (AllocationWithoutResourceRequirement.Match) obj; | ||
170 | return Objects.equals(fHost, other.fHost) && Objects.equals(fApp, other.fApp); | ||
171 | } else { | ||
172 | // this should be infrequent | ||
173 | if (!(obj instanceof IPatternMatch)) { | ||
174 | return false; | ||
175 | } | ||
176 | IPatternMatch otherSig = (IPatternMatch) obj; | ||
177 | return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); | ||
178 | } | ||
179 | } | ||
180 | |||
181 | @Override | ||
182 | public AllocationWithoutResourceRequirement specification() { | ||
183 | return AllocationWithoutResourceRequirement.instance(); | ||
184 | } | ||
185 | |||
186 | /** | ||
187 | * Returns an empty, mutable match. | ||
188 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
189 | * | ||
190 | * @return the empty match. | ||
191 | * | ||
192 | */ | ||
193 | public static AllocationWithoutResourceRequirement.Match newEmptyMatch() { | ||
194 | return new Mutable(null, null); | ||
195 | } | ||
196 | |||
197 | /** | ||
198 | * Returns a mutable (partial) match. | ||
199 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
200 | * | ||
201 | * @param pHost the fixed value of pattern parameter Host, or null if not bound. | ||
202 | * @param pApp the fixed value of pattern parameter App, or null if not bound. | ||
203 | * @return the new, mutable (partial) match object. | ||
204 | * | ||
205 | */ | ||
206 | public static AllocationWithoutResourceRequirement.Match newMutableMatch(final HostInstance pHost, final ApplicationInstance pApp) { | ||
207 | return new Mutable(pHost, pApp); | ||
208 | } | ||
209 | |||
210 | /** | ||
211 | * Returns a new (partial) match. | ||
212 | * This can be used e.g. to call the matcher with a partial match. | ||
213 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
214 | * @param pHost the fixed value of pattern parameter Host, or null if not bound. | ||
215 | * @param pApp the fixed value of pattern parameter App, or null if not bound. | ||
216 | * @return the (partial) match object. | ||
217 | * | ||
218 | */ | ||
219 | public static AllocationWithoutResourceRequirement.Match newMatch(final HostInstance pHost, final ApplicationInstance pApp) { | ||
220 | return new Immutable(pHost, pApp); | ||
221 | } | ||
222 | |||
223 | private static final class Mutable extends AllocationWithoutResourceRequirement.Match { | ||
224 | Mutable(final HostInstance pHost, final ApplicationInstance pApp) { | ||
225 | super(pHost, pApp); | ||
226 | } | ||
227 | |||
228 | @Override | ||
229 | public boolean isMutable() { | ||
230 | return true; | ||
231 | } | ||
232 | } | ||
233 | |||
234 | private static final class Immutable extends AllocationWithoutResourceRequirement.Match { | ||
235 | Immutable(final HostInstance pHost, final ApplicationInstance pApp) { | ||
236 | super(pHost, pApp); | ||
237 | } | ||
238 | |||
239 | @Override | ||
240 | public boolean isMutable() { | ||
241 | return false; | ||
242 | } | ||
243 | } | ||
244 | } | ||
245 | |||
246 | /** | ||
247 | * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.allocationWithoutResourceRequirement pattern, | ||
248 | * providing pattern-specific query methods. | ||
249 | * | ||
250 | * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, | ||
251 | * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. | ||
252 | * | ||
253 | * <p>Matches of the pattern will be represented as {@link Match}. | ||
254 | * | ||
255 | * <p>Original source: | ||
256 | * <code><pre> | ||
257 | * {@literal @}Constraint(severity = "error", key = {Host, App}, | ||
258 | * message = "Application instance must be allocated to a supported host type.") | ||
259 | * pattern allocationWithoutResourceRequirement(Host : HostInstance, App : ApplicationInstance) { | ||
260 | * ApplicationInstance.allocatedTo(App, Host); | ||
261 | * neg find resourceRequirement(Host, App, _); | ||
262 | * } | ||
263 | * </pre></code> | ||
264 | * | ||
265 | * @see Match | ||
266 | * @see AllocationWithoutResourceRequirement | ||
267 | * | ||
268 | */ | ||
269 | public static class Matcher extends BaseMatcher<AllocationWithoutResourceRequirement.Match> { | ||
270 | /** | ||
271 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
272 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
273 | * | ||
274 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
275 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
276 | * | ||
277 | */ | ||
278 | public static AllocationWithoutResourceRequirement.Matcher on(final ViatraQueryEngine engine) { | ||
279 | // check if matcher already exists | ||
280 | Matcher matcher = engine.getExistingMatcher(querySpecification()); | ||
281 | if (matcher == null) { | ||
282 | matcher = (Matcher)engine.getMatcher(querySpecification()); | ||
283 | } | ||
284 | return matcher; | ||
285 | } | ||
286 | |||
287 | /** | ||
288 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
289 | * @return an initialized matcher | ||
290 | * @noreference This method is for internal matcher initialization by the framework, do not call it manually. | ||
291 | * | ||
292 | */ | ||
293 | public static AllocationWithoutResourceRequirement.Matcher create() { | ||
294 | return new Matcher(); | ||
295 | } | ||
296 | |||
297 | private static final int POSITION_HOST = 0; | ||
298 | |||
299 | private static final int POSITION_APP = 1; | ||
300 | |||
301 | private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(AllocationWithoutResourceRequirement.Matcher.class); | ||
302 | |||
303 | /** | ||
304 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
305 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
306 | * | ||
307 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
308 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
309 | * | ||
310 | */ | ||
311 | private Matcher() { | ||
312 | super(querySpecification()); | ||
313 | } | ||
314 | |||
315 | /** | ||
316 | * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. | ||
317 | * @param pHost the fixed value of pattern parameter Host, or null if not bound. | ||
318 | * @param pApp the fixed value of pattern parameter App, or null if not bound. | ||
319 | * @return matches represented as a Match object. | ||
320 | * | ||
321 | */ | ||
322 | public Collection<AllocationWithoutResourceRequirement.Match> getAllMatches(final HostInstance pHost, final ApplicationInstance pApp) { | ||
323 | return rawStreamAllMatches(new Object[]{pHost, pApp}).collect(Collectors.toSet()); | ||
324 | } | ||
325 | |||
326 | /** | ||
327 | * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. | ||
328 | * </p> | ||
329 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
330 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
331 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
332 | * @param pHost the fixed value of pattern parameter Host, or null if not bound. | ||
333 | * @param pApp the fixed value of pattern parameter App, or null if not bound. | ||
334 | * @return a stream of matches represented as a Match object. | ||
335 | * | ||
336 | */ | ||
337 | public Stream<AllocationWithoutResourceRequirement.Match> streamAllMatches(final HostInstance pHost, final ApplicationInstance pApp) { | ||
338 | return rawStreamAllMatches(new Object[]{pHost, pApp}); | ||
339 | } | ||
340 | |||
341 | /** | ||
342 | * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
343 | * Neither determinism nor randomness of selection is guaranteed. | ||
344 | * @param pHost the fixed value of pattern parameter Host, or null if not bound. | ||
345 | * @param pApp the fixed value of pattern parameter App, or null if not bound. | ||
346 | * @return a match represented as a Match object, or null if no match is found. | ||
347 | * | ||
348 | */ | ||
349 | public Optional<AllocationWithoutResourceRequirement.Match> getOneArbitraryMatch(final HostInstance pHost, final ApplicationInstance pApp) { | ||
350 | return rawGetOneArbitraryMatch(new Object[]{pHost, pApp}); | ||
351 | } | ||
352 | |||
353 | /** | ||
354 | * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, | ||
355 | * under any possible substitution of the unspecified parameters (if any). | ||
356 | * @param pHost the fixed value of pattern parameter Host, or null if not bound. | ||
357 | * @param pApp the fixed value of pattern parameter App, or null if not bound. | ||
358 | * @return true if the input is a valid (partial) match of the pattern. | ||
359 | * | ||
360 | */ | ||
361 | public boolean hasMatch(final HostInstance pHost, final ApplicationInstance pApp) { | ||
362 | return rawHasMatch(new Object[]{pHost, pApp}); | ||
363 | } | ||
364 | |||
365 | /** | ||
366 | * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. | ||
367 | * @param pHost the fixed value of pattern parameter Host, or null if not bound. | ||
368 | * @param pApp the fixed value of pattern parameter App, or null if not bound. | ||
369 | * @return the number of pattern matches found. | ||
370 | * | ||
371 | */ | ||
372 | public int countMatches(final HostInstance pHost, final ApplicationInstance pApp) { | ||
373 | return rawCountMatches(new Object[]{pHost, pApp}); | ||
374 | } | ||
375 | |||
376 | /** | ||
377 | * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
378 | * Neither determinism nor randomness of selection is guaranteed. | ||
379 | * @param pHost the fixed value of pattern parameter Host, or null if not bound. | ||
380 | * @param pApp the fixed value of pattern parameter App, or null if not bound. | ||
381 | * @param processor the action that will process the selected match. | ||
382 | * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked | ||
383 | * | ||
384 | */ | ||
385 | public boolean forOneArbitraryMatch(final HostInstance pHost, final ApplicationInstance pApp, final Consumer<? super AllocationWithoutResourceRequirement.Match> processor) { | ||
386 | return rawForOneArbitraryMatch(new Object[]{pHost, pApp}, processor); | ||
387 | } | ||
388 | |||
389 | /** | ||
390 | * Returns a new (partial) match. | ||
391 | * This can be used e.g. to call the matcher with a partial match. | ||
392 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
393 | * @param pHost the fixed value of pattern parameter Host, or null if not bound. | ||
394 | * @param pApp the fixed value of pattern parameter App, or null if not bound. | ||
395 | * @return the (partial) match object. | ||
396 | * | ||
397 | */ | ||
398 | public AllocationWithoutResourceRequirement.Match newMatch(final HostInstance pHost, final ApplicationInstance pApp) { | ||
399 | return AllocationWithoutResourceRequirement.Match.newMatch(pHost, pApp); | ||
400 | } | ||
401 | |||
402 | /** | ||
403 | * Retrieve the set of values that occur in matches for Host. | ||
404 | * @return the Set of all values or empty set if there are no matches | ||
405 | * | ||
406 | */ | ||
407 | protected Stream<HostInstance> rawStreamAllValuesOfHost(final Object[] parameters) { | ||
408 | return rawStreamAllValues(POSITION_HOST, parameters).map(HostInstance.class::cast); | ||
409 | } | ||
410 | |||
411 | /** | ||
412 | * Retrieve the set of values that occur in matches for Host. | ||
413 | * @return the Set of all values or empty set if there are no matches | ||
414 | * | ||
415 | */ | ||
416 | public Set<HostInstance> getAllValuesOfHost() { | ||
417 | return rawStreamAllValuesOfHost(emptyArray()).collect(Collectors.toSet()); | ||
418 | } | ||
419 | |||
420 | /** | ||
421 | * Retrieve the set of values that occur in matches for Host. | ||
422 | * @return the Set of all values or empty set if there are no matches | ||
423 | * | ||
424 | */ | ||
425 | public Stream<HostInstance> streamAllValuesOfHost() { | ||
426 | return rawStreamAllValuesOfHost(emptyArray()); | ||
427 | } | ||
428 | |||
429 | /** | ||
430 | * Retrieve the set of values that occur in matches for Host. | ||
431 | * </p> | ||
432 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
433 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
434 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
435 | * | ||
436 | * @return the Stream of all values or empty set if there are no matches | ||
437 | * | ||
438 | */ | ||
439 | public Stream<HostInstance> streamAllValuesOfHost(final AllocationWithoutResourceRequirement.Match partialMatch) { | ||
440 | return rawStreamAllValuesOfHost(partialMatch.toArray()); | ||
441 | } | ||
442 | |||
443 | /** | ||
444 | * Retrieve the set of values that occur in matches for Host. | ||
445 | * </p> | ||
446 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
447 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
448 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
449 | * | ||
450 | * @return the Stream of all values or empty set if there are no matches | ||
451 | * | ||
452 | */ | ||
453 | public Stream<HostInstance> streamAllValuesOfHost(final ApplicationInstance pApp) { | ||
454 | return rawStreamAllValuesOfHost(new Object[]{null, pApp}); | ||
455 | } | ||
456 | |||
457 | /** | ||
458 | * Retrieve the set of values that occur in matches for Host. | ||
459 | * @return the Set of all values or empty set if there are no matches | ||
460 | * | ||
461 | */ | ||
462 | public Set<HostInstance> getAllValuesOfHost(final AllocationWithoutResourceRequirement.Match partialMatch) { | ||
463 | return rawStreamAllValuesOfHost(partialMatch.toArray()).collect(Collectors.toSet()); | ||
464 | } | ||
465 | |||
466 | /** | ||
467 | * Retrieve the set of values that occur in matches for Host. | ||
468 | * @return the Set of all values or empty set if there are no matches | ||
469 | * | ||
470 | */ | ||
471 | public Set<HostInstance> getAllValuesOfHost(final ApplicationInstance pApp) { | ||
472 | return rawStreamAllValuesOfHost(new Object[]{null, pApp}).collect(Collectors.toSet()); | ||
473 | } | ||
474 | |||
475 | /** | ||
476 | * Retrieve the set of values that occur in matches for App. | ||
477 | * @return the Set of all values or empty set if there are no matches | ||
478 | * | ||
479 | */ | ||
480 | protected Stream<ApplicationInstance> rawStreamAllValuesOfApp(final Object[] parameters) { | ||
481 | return rawStreamAllValues(POSITION_APP, parameters).map(ApplicationInstance.class::cast); | ||
482 | } | ||
483 | |||
484 | /** | ||
485 | * Retrieve the set of values that occur in matches for App. | ||
486 | * @return the Set of all values or empty set if there are no matches | ||
487 | * | ||
488 | */ | ||
489 | public Set<ApplicationInstance> getAllValuesOfApp() { | ||
490 | return rawStreamAllValuesOfApp(emptyArray()).collect(Collectors.toSet()); | ||
491 | } | ||
492 | |||
493 | /** | ||
494 | * Retrieve the set of values that occur in matches for App. | ||
495 | * @return the Set of all values or empty set if there are no matches | ||
496 | * | ||
497 | */ | ||
498 | public Stream<ApplicationInstance> streamAllValuesOfApp() { | ||
499 | return rawStreamAllValuesOfApp(emptyArray()); | ||
500 | } | ||
501 | |||
502 | /** | ||
503 | * Retrieve the set of values that occur in matches for App. | ||
504 | * </p> | ||
505 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
506 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
507 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
508 | * | ||
509 | * @return the Stream of all values or empty set if there are no matches | ||
510 | * | ||
511 | */ | ||
512 | public Stream<ApplicationInstance> streamAllValuesOfApp(final AllocationWithoutResourceRequirement.Match partialMatch) { | ||
513 | return rawStreamAllValuesOfApp(partialMatch.toArray()); | ||
514 | } | ||
515 | |||
516 | /** | ||
517 | * Retrieve the set of values that occur in matches for App. | ||
518 | * </p> | ||
519 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
520 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
521 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
522 | * | ||
523 | * @return the Stream of all values or empty set if there are no matches | ||
524 | * | ||
525 | */ | ||
526 | public Stream<ApplicationInstance> streamAllValuesOfApp(final HostInstance pHost) { | ||
527 | return rawStreamAllValuesOfApp(new Object[]{pHost, null}); | ||
528 | } | ||
529 | |||
530 | /** | ||
531 | * Retrieve the set of values that occur in matches for App. | ||
532 | * @return the Set of all values or empty set if there are no matches | ||
533 | * | ||
534 | */ | ||
535 | public Set<ApplicationInstance> getAllValuesOfApp(final AllocationWithoutResourceRequirement.Match partialMatch) { | ||
536 | return rawStreamAllValuesOfApp(partialMatch.toArray()).collect(Collectors.toSet()); | ||
537 | } | ||
538 | |||
539 | /** | ||
540 | * Retrieve the set of values that occur in matches for App. | ||
541 | * @return the Set of all values or empty set if there are no matches | ||
542 | * | ||
543 | */ | ||
544 | public Set<ApplicationInstance> getAllValuesOfApp(final HostInstance pHost) { | ||
545 | return rawStreamAllValuesOfApp(new Object[]{pHost, null}).collect(Collectors.toSet()); | ||
546 | } | ||
547 | |||
548 | @Override | ||
549 | protected AllocationWithoutResourceRequirement.Match tupleToMatch(final Tuple t) { | ||
550 | try { | ||
551 | return AllocationWithoutResourceRequirement.Match.newMatch((HostInstance) t.get(POSITION_HOST), (ApplicationInstance) t.get(POSITION_APP)); | ||
552 | } catch(ClassCastException e) { | ||
553 | LOGGER.error("Element(s) in tuple not properly typed!",e); | ||
554 | return null; | ||
555 | } | ||
556 | } | ||
557 | |||
558 | @Override | ||
559 | protected AllocationWithoutResourceRequirement.Match arrayToMatch(final Object[] match) { | ||
560 | try { | ||
561 | return AllocationWithoutResourceRequirement.Match.newMatch((HostInstance) match[POSITION_HOST], (ApplicationInstance) match[POSITION_APP]); | ||
562 | } catch(ClassCastException e) { | ||
563 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
564 | return null; | ||
565 | } | ||
566 | } | ||
567 | |||
568 | @Override | ||
569 | protected AllocationWithoutResourceRequirement.Match arrayToMatchMutable(final Object[] match) { | ||
570 | try { | ||
571 | return AllocationWithoutResourceRequirement.Match.newMutableMatch((HostInstance) match[POSITION_HOST], (ApplicationInstance) match[POSITION_APP]); | ||
572 | } catch(ClassCastException e) { | ||
573 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
574 | return null; | ||
575 | } | ||
576 | } | ||
577 | |||
578 | /** | ||
579 | * @return the singleton instance of the query specification of this pattern | ||
580 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
581 | * | ||
582 | */ | ||
583 | public static IQuerySpecification<AllocationWithoutResourceRequirement.Matcher> querySpecification() { | ||
584 | return AllocationWithoutResourceRequirement.instance(); | ||
585 | } | ||
586 | } | ||
587 | |||
588 | private AllocationWithoutResourceRequirement() { | ||
589 | super(GeneratedPQuery.INSTANCE); | ||
590 | } | ||
591 | |||
592 | /** | ||
593 | * @return the singleton instance of the query specification | ||
594 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
595 | * | ||
596 | */ | ||
597 | public static AllocationWithoutResourceRequirement instance() { | ||
598 | try{ | ||
599 | return LazyHolder.INSTANCE; | ||
600 | } catch (ExceptionInInitializerError err) { | ||
601 | throw processInitializerError(err); | ||
602 | } | ||
603 | } | ||
604 | |||
605 | @Override | ||
606 | protected AllocationWithoutResourceRequirement.Matcher instantiate(final ViatraQueryEngine engine) { | ||
607 | return AllocationWithoutResourceRequirement.Matcher.on(engine); | ||
608 | } | ||
609 | |||
610 | @Override | ||
611 | public AllocationWithoutResourceRequirement.Matcher instantiate() { | ||
612 | return AllocationWithoutResourceRequirement.Matcher.create(); | ||
613 | } | ||
614 | |||
615 | @Override | ||
616 | public AllocationWithoutResourceRequirement.Match newEmptyMatch() { | ||
617 | return AllocationWithoutResourceRequirement.Match.newEmptyMatch(); | ||
618 | } | ||
619 | |||
620 | @Override | ||
621 | public AllocationWithoutResourceRequirement.Match newMatch(final Object... parameters) { | ||
622 | return AllocationWithoutResourceRequirement.Match.newMatch((hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance) parameters[0], (hu.bme.mit.inf.dslreasoner.domains.cps.ApplicationInstance) parameters[1]); | ||
623 | } | ||
624 | |||
625 | /** | ||
626 | * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.AllocationWithoutResourceRequirement (visibility: PUBLIC, simpleName: AllocationWithoutResourceRequirement, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.AllocationWithoutResourceRequirement, 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 | ||
627 | * <b>not</b> at the class load time of the outer class, | ||
628 | * but rather at the first call to {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.AllocationWithoutResourceRequirement (visibility: PUBLIC, simpleName: AllocationWithoutResourceRequirement, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.AllocationWithoutResourceRequirement, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}. | ||
629 | * | ||
630 | * <p> This workaround is required e.g. to support recursion. | ||
631 | * | ||
632 | */ | ||
633 | private static class LazyHolder { | ||
634 | private static final AllocationWithoutResourceRequirement INSTANCE = new AllocationWithoutResourceRequirement(); | ||
635 | |||
636 | /** | ||
637 | * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned. | ||
638 | * This initialization order is required to support indirect recursion. | ||
639 | * | ||
640 | * <p> The static initializer is defined using a helper field to work around limitations of the code generator. | ||
641 | * | ||
642 | */ | ||
643 | private static final Object STATIC_INITIALIZER = ensureInitialized(); | ||
644 | |||
645 | public static Object ensureInitialized() { | ||
646 | INSTANCE.ensureInitializedInternal(); | ||
647 | return null; | ||
648 | } | ||
649 | } | ||
650 | |||
651 | private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { | ||
652 | private static final AllocationWithoutResourceRequirement.GeneratedPQuery INSTANCE = new GeneratedPQuery(); | ||
653 | |||
654 | 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); | ||
655 | |||
656 | 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); | ||
657 | |||
658 | private final List<PParameter> parameters = Arrays.asList(parameter_Host, parameter_App); | ||
659 | |||
660 | private GeneratedPQuery() { | ||
661 | super(PVisibility.PUBLIC); | ||
662 | } | ||
663 | |||
664 | @Override | ||
665 | public String getFullyQualifiedName() { | ||
666 | return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.allocationWithoutResourceRequirement"; | ||
667 | } | ||
668 | |||
669 | @Override | ||
670 | public List<String> getParameterNames() { | ||
671 | return Arrays.asList("Host","App"); | ||
672 | } | ||
673 | |||
674 | @Override | ||
675 | public List<PParameter> getParameters() { | ||
676 | return parameters; | ||
677 | } | ||
678 | |||
679 | @Override | ||
680 | public Set<PBody> doGetContainedBodies() { | ||
681 | setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); | ||
682 | Set<PBody> bodies = new LinkedHashSet<>(); | ||
683 | { | ||
684 | PBody body = new PBody(this); | ||
685 | PVariable var_Host = body.getOrCreateVariableByName("Host"); | ||
686 | PVariable var_App = body.getOrCreateVariableByName("App"); | ||
687 | PVariable var___0_ = body.getOrCreateVariableByName("_<0>"); | ||
688 | new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); | ||
689 | new TypeConstraint(body, Tuples.flatTupleOf(var_App), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance"))); | ||
690 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
691 | new ExportedParameter(body, var_Host, parameter_Host), | ||
692 | new ExportedParameter(body, var_App, parameter_App) | ||
693 | )); | ||
694 | // ApplicationInstance.allocatedTo(App, Host) | ||
695 | new TypeConstraint(body, Tuples.flatTupleOf(var_App), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance"))); | ||
696 | PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); | ||
697 | new TypeConstraint(body, Tuples.flatTupleOf(var_App, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ApplicationInstance", "allocatedTo"))); | ||
698 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); | ||
699 | new Equality(body, var__virtual_0_, var_Host); | ||
700 | // neg find resourceRequirement(Host, App, _) | ||
701 | new NegativePatternCall(body, Tuples.flatTupleOf(var_Host, var_App, var___0_), ResourceRequirement.instance().getInternalQueryRepresentation()); | ||
702 | bodies.add(body); | ||
703 | } | ||
704 | { | ||
705 | PAnnotation annotation = new PAnnotation("Constraint"); | ||
706 | annotation.addAttribute("severity", "error"); | ||
707 | annotation.addAttribute("key", Arrays.asList(new Object[] { | ||
708 | new ParameterReference("Host"), | ||
709 | new ParameterReference("App") | ||
710 | })); | ||
711 | annotation.addAttribute("message", "Application instance must be allocated to a supported host type."); | ||
712 | addAnnotation(annotation); | ||
713 | } | ||
714 | return bodies; | ||
715 | } | ||
716 | } | ||
717 | } | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/AverageFreeHddMetric.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/AverageFreeHddMetric.java new file mode 100644 index 00000000..bc38b60b --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/AverageFreeHddMetric.java | |||
@@ -0,0 +1,544 @@ | |||
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.queries.internal.FreeHddPercentage; | ||
7 | import java.util.Arrays; | ||
8 | import java.util.Collection; | ||
9 | import java.util.LinkedHashSet; | ||
10 | import java.util.List; | ||
11 | import java.util.Objects; | ||
12 | import java.util.Optional; | ||
13 | import java.util.Set; | ||
14 | import java.util.function.Consumer; | ||
15 | import java.util.stream.Collectors; | ||
16 | import java.util.stream.Stream; | ||
17 | import org.apache.log4j.Logger; | ||
18 | import org.eclipse.viatra.query.runtime.api.IPatternMatch; | ||
19 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification; | ||
20 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; | ||
21 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; | ||
22 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; | ||
23 | import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; | ||
24 | import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; | ||
25 | import org.eclipse.viatra.query.runtime.matchers.aggregators.avg; | ||
26 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
27 | import org.eclipse.viatra.query.runtime.matchers.context.common.JavaTransitiveInstancesKey; | ||
28 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | ||
29 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | ||
30 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.AggregatorConstraint; | ||
31 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; | ||
32 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
33 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.TypeFilterConstraint; | ||
34 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | ||
35 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; | ||
36 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | ||
37 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; | ||
38 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
39 | import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; | ||
40 | |||
41 | /** | ||
42 | * A pattern-specific query specification that can instantiate Matcher in a type-safe way. | ||
43 | * | ||
44 | * <p>Original source: | ||
45 | * <code><pre> | ||
46 | * // Free HDD | ||
47 | * | ||
48 | * pattern averageFreeHddMetric(Average : java Double) { | ||
49 | * Average == avg find freeHddPercentage(_, #_); | ||
50 | * } | ||
51 | * </pre></code> | ||
52 | * | ||
53 | * @see Matcher | ||
54 | * @see Match | ||
55 | * | ||
56 | */ | ||
57 | @SuppressWarnings("all") | ||
58 | public final class AverageFreeHddMetric extends BaseGeneratedEMFQuerySpecification<AverageFreeHddMetric.Matcher> { | ||
59 | /** | ||
60 | * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.averageFreeHddMetric pattern, | ||
61 | * to be used in conjunction with {@link Matcher}. | ||
62 | * | ||
63 | * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. | ||
64 | * Each instance is a (possibly partial) substitution of pattern parameters, | ||
65 | * usable to represent a match of the pattern in the result of a query, | ||
66 | * or to specify the bound (fixed) input parameters when issuing a query. | ||
67 | * | ||
68 | * @see Matcher | ||
69 | * | ||
70 | */ | ||
71 | public static abstract class Match extends BasePatternMatch { | ||
72 | private Double fAverage; | ||
73 | |||
74 | private static List<String> parameterNames = makeImmutableList("Average"); | ||
75 | |||
76 | private Match(final Double pAverage) { | ||
77 | this.fAverage = pAverage; | ||
78 | } | ||
79 | |||
80 | @Override | ||
81 | public Object get(final String parameterName) { | ||
82 | if ("Average".equals(parameterName)) return this.fAverage; | ||
83 | return null; | ||
84 | } | ||
85 | |||
86 | public Double getAverage() { | ||
87 | return this.fAverage; | ||
88 | } | ||
89 | |||
90 | @Override | ||
91 | public boolean set(final String parameterName, final Object newValue) { | ||
92 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
93 | if ("Average".equals(parameterName) ) { | ||
94 | this.fAverage = (Double) newValue; | ||
95 | return true; | ||
96 | } | ||
97 | return false; | ||
98 | } | ||
99 | |||
100 | public void setAverage(final Double pAverage) { | ||
101 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
102 | this.fAverage = pAverage; | ||
103 | } | ||
104 | |||
105 | @Override | ||
106 | public String patternName() { | ||
107 | return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.averageFreeHddMetric"; | ||
108 | } | ||
109 | |||
110 | @Override | ||
111 | public List<String> parameterNames() { | ||
112 | return AverageFreeHddMetric.Match.parameterNames; | ||
113 | } | ||
114 | |||
115 | @Override | ||
116 | public Object[] toArray() { | ||
117 | return new Object[]{fAverage}; | ||
118 | } | ||
119 | |||
120 | @Override | ||
121 | public AverageFreeHddMetric.Match toImmutable() { | ||
122 | return isMutable() ? newMatch(fAverage) : this; | ||
123 | } | ||
124 | |||
125 | @Override | ||
126 | public String prettyPrint() { | ||
127 | StringBuilder result = new StringBuilder(); | ||
128 | result.append("\"Average\"=" + prettyPrintValue(fAverage)); | ||
129 | return result.toString(); | ||
130 | } | ||
131 | |||
132 | @Override | ||
133 | public int hashCode() { | ||
134 | return Objects.hash(fAverage); | ||
135 | } | ||
136 | |||
137 | @Override | ||
138 | public boolean equals(final Object obj) { | ||
139 | if (this == obj) | ||
140 | return true; | ||
141 | if (obj == null) { | ||
142 | return false; | ||
143 | } | ||
144 | if ((obj instanceof AverageFreeHddMetric.Match)) { | ||
145 | AverageFreeHddMetric.Match other = (AverageFreeHddMetric.Match) obj; | ||
146 | return Objects.equals(fAverage, other.fAverage); | ||
147 | } else { | ||
148 | // this should be infrequent | ||
149 | if (!(obj instanceof IPatternMatch)) { | ||
150 | return false; | ||
151 | } | ||
152 | IPatternMatch otherSig = (IPatternMatch) obj; | ||
153 | return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); | ||
154 | } | ||
155 | } | ||
156 | |||
157 | @Override | ||
158 | public AverageFreeHddMetric specification() { | ||
159 | return AverageFreeHddMetric.instance(); | ||
160 | } | ||
161 | |||
162 | /** | ||
163 | * Returns an empty, mutable match. | ||
164 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
165 | * | ||
166 | * @return the empty match. | ||
167 | * | ||
168 | */ | ||
169 | public static AverageFreeHddMetric.Match newEmptyMatch() { | ||
170 | return new Mutable(null); | ||
171 | } | ||
172 | |||
173 | /** | ||
174 | * Returns a mutable (partial) match. | ||
175 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
176 | * | ||
177 | * @param pAverage the fixed value of pattern parameter Average, or null if not bound. | ||
178 | * @return the new, mutable (partial) match object. | ||
179 | * | ||
180 | */ | ||
181 | public static AverageFreeHddMetric.Match newMutableMatch(final Double pAverage) { | ||
182 | return new Mutable(pAverage); | ||
183 | } | ||
184 | |||
185 | /** | ||
186 | * Returns a new (partial) match. | ||
187 | * This can be used e.g. to call the matcher with a partial match. | ||
188 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
189 | * @param pAverage the fixed value of pattern parameter Average, or null if not bound. | ||
190 | * @return the (partial) match object. | ||
191 | * | ||
192 | */ | ||
193 | public static AverageFreeHddMetric.Match newMatch(final Double pAverage) { | ||
194 | return new Immutable(pAverage); | ||
195 | } | ||
196 | |||
197 | private static final class Mutable extends AverageFreeHddMetric.Match { | ||
198 | Mutable(final Double pAverage) { | ||
199 | super(pAverage); | ||
200 | } | ||
201 | |||
202 | @Override | ||
203 | public boolean isMutable() { | ||
204 | return true; | ||
205 | } | ||
206 | } | ||
207 | |||
208 | private static final class Immutable extends AverageFreeHddMetric.Match { | ||
209 | Immutable(final Double pAverage) { | ||
210 | super(pAverage); | ||
211 | } | ||
212 | |||
213 | @Override | ||
214 | public boolean isMutable() { | ||
215 | return false; | ||
216 | } | ||
217 | } | ||
218 | } | ||
219 | |||
220 | /** | ||
221 | * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.averageFreeHddMetric pattern, | ||
222 | * providing pattern-specific query methods. | ||
223 | * | ||
224 | * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, | ||
225 | * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. | ||
226 | * | ||
227 | * <p>Matches of the pattern will be represented as {@link Match}. | ||
228 | * | ||
229 | * <p>Original source: | ||
230 | * <code><pre> | ||
231 | * // Free HDD | ||
232 | * | ||
233 | * pattern averageFreeHddMetric(Average : java Double) { | ||
234 | * Average == avg find freeHddPercentage(_, #_); | ||
235 | * } | ||
236 | * </pre></code> | ||
237 | * | ||
238 | * @see Match | ||
239 | * @see AverageFreeHddMetric | ||
240 | * | ||
241 | */ | ||
242 | public static class Matcher extends BaseMatcher<AverageFreeHddMetric.Match> { | ||
243 | /** | ||
244 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
245 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
246 | * | ||
247 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
248 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
249 | * | ||
250 | */ | ||
251 | public static AverageFreeHddMetric.Matcher on(final ViatraQueryEngine engine) { | ||
252 | // check if matcher already exists | ||
253 | Matcher matcher = engine.getExistingMatcher(querySpecification()); | ||
254 | if (matcher == null) { | ||
255 | matcher = (Matcher)engine.getMatcher(querySpecification()); | ||
256 | } | ||
257 | return matcher; | ||
258 | } | ||
259 | |||
260 | /** | ||
261 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
262 | * @return an initialized matcher | ||
263 | * @noreference This method is for internal matcher initialization by the framework, do not call it manually. | ||
264 | * | ||
265 | */ | ||
266 | public static AverageFreeHddMetric.Matcher create() { | ||
267 | return new Matcher(); | ||
268 | } | ||
269 | |||
270 | private static final int POSITION_AVERAGE = 0; | ||
271 | |||
272 | private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(AverageFreeHddMetric.Matcher.class); | ||
273 | |||
274 | /** | ||
275 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
276 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
277 | * | ||
278 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
279 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
280 | * | ||
281 | */ | ||
282 | private Matcher() { | ||
283 | super(querySpecification()); | ||
284 | } | ||
285 | |||
286 | /** | ||
287 | * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. | ||
288 | * @param pAverage the fixed value of pattern parameter Average, or null if not bound. | ||
289 | * @return matches represented as a Match object. | ||
290 | * | ||
291 | */ | ||
292 | public Collection<AverageFreeHddMetric.Match> getAllMatches(final Double pAverage) { | ||
293 | return rawStreamAllMatches(new Object[]{pAverage}).collect(Collectors.toSet()); | ||
294 | } | ||
295 | |||
296 | /** | ||
297 | * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. | ||
298 | * </p> | ||
299 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
300 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
301 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
302 | * @param pAverage the fixed value of pattern parameter Average, or null if not bound. | ||
303 | * @return a stream of matches represented as a Match object. | ||
304 | * | ||
305 | */ | ||
306 | public Stream<AverageFreeHddMetric.Match> streamAllMatches(final Double pAverage) { | ||
307 | return rawStreamAllMatches(new Object[]{pAverage}); | ||
308 | } | ||
309 | |||
310 | /** | ||
311 | * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
312 | * Neither determinism nor randomness of selection is guaranteed. | ||
313 | * @param pAverage the fixed value of pattern parameter Average, or null if not bound. | ||
314 | * @return a match represented as a Match object, or null if no match is found. | ||
315 | * | ||
316 | */ | ||
317 | public Optional<AverageFreeHddMetric.Match> getOneArbitraryMatch(final Double pAverage) { | ||
318 | return rawGetOneArbitraryMatch(new Object[]{pAverage}); | ||
319 | } | ||
320 | |||
321 | /** | ||
322 | * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, | ||
323 | * under any possible substitution of the unspecified parameters (if any). | ||
324 | * @param pAverage the fixed value of pattern parameter Average, or null if not bound. | ||
325 | * @return true if the input is a valid (partial) match of the pattern. | ||
326 | * | ||
327 | */ | ||
328 | public boolean hasMatch(final Double pAverage) { | ||
329 | return rawHasMatch(new Object[]{pAverage}); | ||
330 | } | ||
331 | |||
332 | /** | ||
333 | * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. | ||
334 | * @param pAverage the fixed value of pattern parameter Average, or null if not bound. | ||
335 | * @return the number of pattern matches found. | ||
336 | * | ||
337 | */ | ||
338 | public int countMatches(final Double pAverage) { | ||
339 | return rawCountMatches(new Object[]{pAverage}); | ||
340 | } | ||
341 | |||
342 | /** | ||
343 | * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
344 | * Neither determinism nor randomness of selection is guaranteed. | ||
345 | * @param pAverage the fixed value of pattern parameter Average, or null if not bound. | ||
346 | * @param processor the action that will process the selected match. | ||
347 | * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked | ||
348 | * | ||
349 | */ | ||
350 | public boolean forOneArbitraryMatch(final Double pAverage, final Consumer<? super AverageFreeHddMetric.Match> processor) { | ||
351 | return rawForOneArbitraryMatch(new Object[]{pAverage}, processor); | ||
352 | } | ||
353 | |||
354 | /** | ||
355 | * Returns a new (partial) match. | ||
356 | * This can be used e.g. to call the matcher with a partial match. | ||
357 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
358 | * @param pAverage the fixed value of pattern parameter Average, or null if not bound. | ||
359 | * @return the (partial) match object. | ||
360 | * | ||
361 | */ | ||
362 | public AverageFreeHddMetric.Match newMatch(final Double pAverage) { | ||
363 | return AverageFreeHddMetric.Match.newMatch(pAverage); | ||
364 | } | ||
365 | |||
366 | /** | ||
367 | * Retrieve the set of values that occur in matches for Average. | ||
368 | * @return the Set of all values or empty set if there are no matches | ||
369 | * | ||
370 | */ | ||
371 | protected Stream<Double> rawStreamAllValuesOfAverage(final Object[] parameters) { | ||
372 | return rawStreamAllValues(POSITION_AVERAGE, parameters).map(Double.class::cast); | ||
373 | } | ||
374 | |||
375 | /** | ||
376 | * Retrieve the set of values that occur in matches for Average. | ||
377 | * @return the Set of all values or empty set if there are no matches | ||
378 | * | ||
379 | */ | ||
380 | public Set<Double> getAllValuesOfAverage() { | ||
381 | return rawStreamAllValuesOfAverage(emptyArray()).collect(Collectors.toSet()); | ||
382 | } | ||
383 | |||
384 | /** | ||
385 | * Retrieve the set of values that occur in matches for Average. | ||
386 | * @return the Set of all values or empty set if there are no matches | ||
387 | * | ||
388 | */ | ||
389 | public Stream<Double> streamAllValuesOfAverage() { | ||
390 | return rawStreamAllValuesOfAverage(emptyArray()); | ||
391 | } | ||
392 | |||
393 | @Override | ||
394 | protected AverageFreeHddMetric.Match tupleToMatch(final Tuple t) { | ||
395 | try { | ||
396 | return AverageFreeHddMetric.Match.newMatch((Double) t.get(POSITION_AVERAGE)); | ||
397 | } catch(ClassCastException e) { | ||
398 | LOGGER.error("Element(s) in tuple not properly typed!",e); | ||
399 | return null; | ||
400 | } | ||
401 | } | ||
402 | |||
403 | @Override | ||
404 | protected AverageFreeHddMetric.Match arrayToMatch(final Object[] match) { | ||
405 | try { | ||
406 | return AverageFreeHddMetric.Match.newMatch((Double) match[POSITION_AVERAGE]); | ||
407 | } catch(ClassCastException e) { | ||
408 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
409 | return null; | ||
410 | } | ||
411 | } | ||
412 | |||
413 | @Override | ||
414 | protected AverageFreeHddMetric.Match arrayToMatchMutable(final Object[] match) { | ||
415 | try { | ||
416 | return AverageFreeHddMetric.Match.newMutableMatch((Double) match[POSITION_AVERAGE]); | ||
417 | } catch(ClassCastException e) { | ||
418 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
419 | return null; | ||
420 | } | ||
421 | } | ||
422 | |||
423 | /** | ||
424 | * @return the singleton instance of the query specification of this pattern | ||
425 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
426 | * | ||
427 | */ | ||
428 | public static IQuerySpecification<AverageFreeHddMetric.Matcher> querySpecification() { | ||
429 | return AverageFreeHddMetric.instance(); | ||
430 | } | ||
431 | } | ||
432 | |||
433 | private AverageFreeHddMetric() { | ||
434 | super(GeneratedPQuery.INSTANCE); | ||
435 | } | ||
436 | |||
437 | /** | ||
438 | * @return the singleton instance of the query specification | ||
439 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
440 | * | ||
441 | */ | ||
442 | public static AverageFreeHddMetric instance() { | ||
443 | try{ | ||
444 | return LazyHolder.INSTANCE; | ||
445 | } catch (ExceptionInInitializerError err) { | ||
446 | throw processInitializerError(err); | ||
447 | } | ||
448 | } | ||
449 | |||
450 | @Override | ||
451 | protected AverageFreeHddMetric.Matcher instantiate(final ViatraQueryEngine engine) { | ||
452 | return AverageFreeHddMetric.Matcher.on(engine); | ||
453 | } | ||
454 | |||
455 | @Override | ||
456 | public AverageFreeHddMetric.Matcher instantiate() { | ||
457 | return AverageFreeHddMetric.Matcher.create(); | ||
458 | } | ||
459 | |||
460 | @Override | ||
461 | public AverageFreeHddMetric.Match newEmptyMatch() { | ||
462 | return AverageFreeHddMetric.Match.newEmptyMatch(); | ||
463 | } | ||
464 | |||
465 | @Override | ||
466 | public AverageFreeHddMetric.Match newMatch(final Object... parameters) { | ||
467 | return AverageFreeHddMetric.Match.newMatch((java.lang.Double) parameters[0]); | ||
468 | } | ||
469 | |||
470 | /** | ||
471 | * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.AverageFreeHddMetric (visibility: PUBLIC, simpleName: AverageFreeHddMetric, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.AverageFreeHddMetric, 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 | ||
472 | * <b>not</b> at the class load time of the outer class, | ||
473 | * but rather at the first call to {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.AverageFreeHddMetric (visibility: PUBLIC, simpleName: AverageFreeHddMetric, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.AverageFreeHddMetric, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}. | ||
474 | * | ||
475 | * <p> This workaround is required e.g. to support recursion. | ||
476 | * | ||
477 | */ | ||
478 | private static class LazyHolder { | ||
479 | private static final AverageFreeHddMetric INSTANCE = new AverageFreeHddMetric(); | ||
480 | |||
481 | /** | ||
482 | * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned. | ||
483 | * This initialization order is required to support indirect recursion. | ||
484 | * | ||
485 | * <p> The static initializer is defined using a helper field to work around limitations of the code generator. | ||
486 | * | ||
487 | */ | ||
488 | private static final Object STATIC_INITIALIZER = ensureInitialized(); | ||
489 | |||
490 | public static Object ensureInitialized() { | ||
491 | INSTANCE.ensureInitializedInternal(); | ||
492 | return null; | ||
493 | } | ||
494 | } | ||
495 | |||
496 | private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { | ||
497 | private static final AverageFreeHddMetric.GeneratedPQuery INSTANCE = new GeneratedPQuery(); | ||
498 | |||
499 | private final PParameter parameter_Average = new PParameter("Average", "java.lang.Double", new JavaTransitiveInstancesKey(java.lang.Double.class), PParameterDirection.INOUT); | ||
500 | |||
501 | private final List<PParameter> parameters = Arrays.asList(parameter_Average); | ||
502 | |||
503 | private GeneratedPQuery() { | ||
504 | super(PVisibility.PUBLIC); | ||
505 | } | ||
506 | |||
507 | @Override | ||
508 | public String getFullyQualifiedName() { | ||
509 | return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.averageFreeHddMetric"; | ||
510 | } | ||
511 | |||
512 | @Override | ||
513 | public List<String> getParameterNames() { | ||
514 | return Arrays.asList("Average"); | ||
515 | } | ||
516 | |||
517 | @Override | ||
518 | public List<PParameter> getParameters() { | ||
519 | return parameters; | ||
520 | } | ||
521 | |||
522 | @Override | ||
523 | public Set<PBody> doGetContainedBodies() { | ||
524 | setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); | ||
525 | Set<PBody> bodies = new LinkedHashSet<>(); | ||
526 | { | ||
527 | PBody body = new PBody(this); | ||
528 | PVariable var_Average = body.getOrCreateVariableByName("Average"); | ||
529 | PVariable var___0_ = body.getOrCreateVariableByName("_<0>"); | ||
530 | PVariable var___1_ = body.getOrCreateVariableByName("_<1>"); | ||
531 | new TypeFilterConstraint(body, Tuples.flatTupleOf(var_Average), new JavaTransitiveInstancesKey(java.lang.Double.class)); | ||
532 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
533 | new ExportedParameter(body, var_Average, parameter_Average) | ||
534 | )); | ||
535 | // Average == avg find freeHddPercentage(_, #_) | ||
536 | PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); | ||
537 | new AggregatorConstraint(new avg().getAggregatorLogic(Double.class), body, Tuples.flatTupleOf(var___0_, var___1_), FreeHddPercentage.instance().getInternalQueryRepresentation(), var__virtual_0_, 1); | ||
538 | new Equality(body, var_Average, var__virtual_0_); | ||
539 | bodies.add(body); | ||
540 | } | ||
541 | return bodies; | ||
542 | } | ||
543 | } | ||
544 | } | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/AverageFreeMemoryMetric.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/AverageFreeMemoryMetric.java new file mode 100644 index 00000000..98974ea5 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/AverageFreeMemoryMetric.java | |||
@@ -0,0 +1,552 @@ | |||
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.queries.internal.FreeMemoryPercentage; | ||
7 | import java.util.Arrays; | ||
8 | import java.util.Collection; | ||
9 | import java.util.LinkedHashSet; | ||
10 | import java.util.List; | ||
11 | import java.util.Objects; | ||
12 | import java.util.Optional; | ||
13 | import java.util.Set; | ||
14 | import java.util.function.Consumer; | ||
15 | import java.util.stream.Collectors; | ||
16 | import java.util.stream.Stream; | ||
17 | import org.apache.log4j.Logger; | ||
18 | import org.eclipse.viatra.query.runtime.api.IPatternMatch; | ||
19 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification; | ||
20 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; | ||
21 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; | ||
22 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; | ||
23 | import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; | ||
24 | import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; | ||
25 | import org.eclipse.viatra.query.runtime.matchers.aggregators.avg; | ||
26 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
27 | import org.eclipse.viatra.query.runtime.matchers.context.common.JavaTransitiveInstancesKey; | ||
28 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | ||
29 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | ||
30 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.AggregatorConstraint; | ||
31 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; | ||
32 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
33 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.TypeFilterConstraint; | ||
34 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | ||
35 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; | ||
36 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | ||
37 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; | ||
38 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
39 | import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; | ||
40 | |||
41 | /** | ||
42 | * A pattern-specific query specification that can instantiate Matcher in a type-safe way. | ||
43 | * | ||
44 | * <p>Original source: | ||
45 | * <code><pre> | ||
46 | * // | ||
47 | * // Metrics | ||
48 | * // | ||
49 | * | ||
50 | * // Free memory | ||
51 | * | ||
52 | * pattern averageFreeMemoryMetric(Average : java Double) { | ||
53 | * Average == avg find freeMemoryPercentage(_, #_); | ||
54 | * } | ||
55 | * </pre></code> | ||
56 | * | ||
57 | * @see Matcher | ||
58 | * @see Match | ||
59 | * | ||
60 | */ | ||
61 | @SuppressWarnings("all") | ||
62 | public final class AverageFreeMemoryMetric extends BaseGeneratedEMFQuerySpecification<AverageFreeMemoryMetric.Matcher> { | ||
63 | /** | ||
64 | * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.averageFreeMemoryMetric pattern, | ||
65 | * to be used in conjunction with {@link Matcher}. | ||
66 | * | ||
67 | * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. | ||
68 | * Each instance is a (possibly partial) substitution of pattern parameters, | ||
69 | * usable to represent a match of the pattern in the result of a query, | ||
70 | * or to specify the bound (fixed) input parameters when issuing a query. | ||
71 | * | ||
72 | * @see Matcher | ||
73 | * | ||
74 | */ | ||
75 | public static abstract class Match extends BasePatternMatch { | ||
76 | private Double fAverage; | ||
77 | |||
78 | private static List<String> parameterNames = makeImmutableList("Average"); | ||
79 | |||
80 | private Match(final Double pAverage) { | ||
81 | this.fAverage = pAverage; | ||
82 | } | ||
83 | |||
84 | @Override | ||
85 | public Object get(final String parameterName) { | ||
86 | if ("Average".equals(parameterName)) return this.fAverage; | ||
87 | return null; | ||
88 | } | ||
89 | |||
90 | public Double getAverage() { | ||
91 | return this.fAverage; | ||
92 | } | ||
93 | |||
94 | @Override | ||
95 | public boolean set(final String parameterName, final Object newValue) { | ||
96 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
97 | if ("Average".equals(parameterName) ) { | ||
98 | this.fAverage = (Double) newValue; | ||
99 | return true; | ||
100 | } | ||
101 | return false; | ||
102 | } | ||
103 | |||
104 | public void setAverage(final Double pAverage) { | ||
105 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
106 | this.fAverage = pAverage; | ||
107 | } | ||
108 | |||
109 | @Override | ||
110 | public String patternName() { | ||
111 | return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.averageFreeMemoryMetric"; | ||
112 | } | ||
113 | |||
114 | @Override | ||
115 | public List<String> parameterNames() { | ||
116 | return AverageFreeMemoryMetric.Match.parameterNames; | ||
117 | } | ||
118 | |||
119 | @Override | ||
120 | public Object[] toArray() { | ||
121 | return new Object[]{fAverage}; | ||
122 | } | ||
123 | |||
124 | @Override | ||
125 | public AverageFreeMemoryMetric.Match toImmutable() { | ||
126 | return isMutable() ? newMatch(fAverage) : this; | ||
127 | } | ||
128 | |||
129 | @Override | ||
130 | public String prettyPrint() { | ||
131 | StringBuilder result = new StringBuilder(); | ||
132 | result.append("\"Average\"=" + prettyPrintValue(fAverage)); | ||
133 | return result.toString(); | ||
134 | } | ||
135 | |||
136 | @Override | ||
137 | public int hashCode() { | ||
138 | return Objects.hash(fAverage); | ||
139 | } | ||
140 | |||
141 | @Override | ||
142 | public boolean equals(final Object obj) { | ||
143 | if (this == obj) | ||
144 | return true; | ||
145 | if (obj == null) { | ||
146 | return false; | ||
147 | } | ||
148 | if ((obj instanceof AverageFreeMemoryMetric.Match)) { | ||
149 | AverageFreeMemoryMetric.Match other = (AverageFreeMemoryMetric.Match) obj; | ||
150 | return Objects.equals(fAverage, other.fAverage); | ||
151 | } else { | ||
152 | // this should be infrequent | ||
153 | if (!(obj instanceof IPatternMatch)) { | ||
154 | return false; | ||
155 | } | ||
156 | IPatternMatch otherSig = (IPatternMatch) obj; | ||
157 | return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); | ||
158 | } | ||
159 | } | ||
160 | |||
161 | @Override | ||
162 | public AverageFreeMemoryMetric specification() { | ||
163 | return AverageFreeMemoryMetric.instance(); | ||
164 | } | ||
165 | |||
166 | /** | ||
167 | * Returns an empty, mutable match. | ||
168 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
169 | * | ||
170 | * @return the empty match. | ||
171 | * | ||
172 | */ | ||
173 | public static AverageFreeMemoryMetric.Match newEmptyMatch() { | ||
174 | return new Mutable(null); | ||
175 | } | ||
176 | |||
177 | /** | ||
178 | * Returns a mutable (partial) match. | ||
179 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
180 | * | ||
181 | * @param pAverage the fixed value of pattern parameter Average, or null if not bound. | ||
182 | * @return the new, mutable (partial) match object. | ||
183 | * | ||
184 | */ | ||
185 | public static AverageFreeMemoryMetric.Match newMutableMatch(final Double pAverage) { | ||
186 | return new Mutable(pAverage); | ||
187 | } | ||
188 | |||
189 | /** | ||
190 | * Returns a new (partial) match. | ||
191 | * This can be used e.g. to call the matcher with a partial match. | ||
192 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
193 | * @param pAverage the fixed value of pattern parameter Average, or null if not bound. | ||
194 | * @return the (partial) match object. | ||
195 | * | ||
196 | */ | ||
197 | public static AverageFreeMemoryMetric.Match newMatch(final Double pAverage) { | ||
198 | return new Immutable(pAverage); | ||
199 | } | ||
200 | |||
201 | private static final class Mutable extends AverageFreeMemoryMetric.Match { | ||
202 | Mutable(final Double pAverage) { | ||
203 | super(pAverage); | ||
204 | } | ||
205 | |||
206 | @Override | ||
207 | public boolean isMutable() { | ||
208 | return true; | ||
209 | } | ||
210 | } | ||
211 | |||
212 | private static final class Immutable extends AverageFreeMemoryMetric.Match { | ||
213 | Immutable(final Double pAverage) { | ||
214 | super(pAverage); | ||
215 | } | ||
216 | |||
217 | @Override | ||
218 | public boolean isMutable() { | ||
219 | return false; | ||
220 | } | ||
221 | } | ||
222 | } | ||
223 | |||
224 | /** | ||
225 | * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.averageFreeMemoryMetric pattern, | ||
226 | * providing pattern-specific query methods. | ||
227 | * | ||
228 | * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, | ||
229 | * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. | ||
230 | * | ||
231 | * <p>Matches of the pattern will be represented as {@link Match}. | ||
232 | * | ||
233 | * <p>Original source: | ||
234 | * <code><pre> | ||
235 | * // | ||
236 | * // Metrics | ||
237 | * // | ||
238 | * | ||
239 | * // Free memory | ||
240 | * | ||
241 | * pattern averageFreeMemoryMetric(Average : java Double) { | ||
242 | * Average == avg find freeMemoryPercentage(_, #_); | ||
243 | * } | ||
244 | * </pre></code> | ||
245 | * | ||
246 | * @see Match | ||
247 | * @see AverageFreeMemoryMetric | ||
248 | * | ||
249 | */ | ||
250 | public static class Matcher extends BaseMatcher<AverageFreeMemoryMetric.Match> { | ||
251 | /** | ||
252 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
253 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
254 | * | ||
255 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
256 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
257 | * | ||
258 | */ | ||
259 | public static AverageFreeMemoryMetric.Matcher on(final ViatraQueryEngine engine) { | ||
260 | // check if matcher already exists | ||
261 | Matcher matcher = engine.getExistingMatcher(querySpecification()); | ||
262 | if (matcher == null) { | ||
263 | matcher = (Matcher)engine.getMatcher(querySpecification()); | ||
264 | } | ||
265 | return matcher; | ||
266 | } | ||
267 | |||
268 | /** | ||
269 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
270 | * @return an initialized matcher | ||
271 | * @noreference This method is for internal matcher initialization by the framework, do not call it manually. | ||
272 | * | ||
273 | */ | ||
274 | public static AverageFreeMemoryMetric.Matcher create() { | ||
275 | return new Matcher(); | ||
276 | } | ||
277 | |||
278 | private static final int POSITION_AVERAGE = 0; | ||
279 | |||
280 | private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(AverageFreeMemoryMetric.Matcher.class); | ||
281 | |||
282 | /** | ||
283 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
284 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
285 | * | ||
286 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
287 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
288 | * | ||
289 | */ | ||
290 | private Matcher() { | ||
291 | super(querySpecification()); | ||
292 | } | ||
293 | |||
294 | /** | ||
295 | * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. | ||
296 | * @param pAverage the fixed value of pattern parameter Average, or null if not bound. | ||
297 | * @return matches represented as a Match object. | ||
298 | * | ||
299 | */ | ||
300 | public Collection<AverageFreeMemoryMetric.Match> getAllMatches(final Double pAverage) { | ||
301 | return rawStreamAllMatches(new Object[]{pAverage}).collect(Collectors.toSet()); | ||
302 | } | ||
303 | |||
304 | /** | ||
305 | * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. | ||
306 | * </p> | ||
307 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
308 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
309 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
310 | * @param pAverage the fixed value of pattern parameter Average, or null if not bound. | ||
311 | * @return a stream of matches represented as a Match object. | ||
312 | * | ||
313 | */ | ||
314 | public Stream<AverageFreeMemoryMetric.Match> streamAllMatches(final Double pAverage) { | ||
315 | return rawStreamAllMatches(new Object[]{pAverage}); | ||
316 | } | ||
317 | |||
318 | /** | ||
319 | * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
320 | * Neither determinism nor randomness of selection is guaranteed. | ||
321 | * @param pAverage the fixed value of pattern parameter Average, or null if not bound. | ||
322 | * @return a match represented as a Match object, or null if no match is found. | ||
323 | * | ||
324 | */ | ||
325 | public Optional<AverageFreeMemoryMetric.Match> getOneArbitraryMatch(final Double pAverage) { | ||
326 | return rawGetOneArbitraryMatch(new Object[]{pAverage}); | ||
327 | } | ||
328 | |||
329 | /** | ||
330 | * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, | ||
331 | * under any possible substitution of the unspecified parameters (if any). | ||
332 | * @param pAverage the fixed value of pattern parameter Average, or null if not bound. | ||
333 | * @return true if the input is a valid (partial) match of the pattern. | ||
334 | * | ||
335 | */ | ||
336 | public boolean hasMatch(final Double pAverage) { | ||
337 | return rawHasMatch(new Object[]{pAverage}); | ||
338 | } | ||
339 | |||
340 | /** | ||
341 | * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. | ||
342 | * @param pAverage the fixed value of pattern parameter Average, or null if not bound. | ||
343 | * @return the number of pattern matches found. | ||
344 | * | ||
345 | */ | ||
346 | public int countMatches(final Double pAverage) { | ||
347 | return rawCountMatches(new Object[]{pAverage}); | ||
348 | } | ||
349 | |||
350 | /** | ||
351 | * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
352 | * Neither determinism nor randomness of selection is guaranteed. | ||
353 | * @param pAverage the fixed value of pattern parameter Average, or null if not bound. | ||
354 | * @param processor the action that will process the selected match. | ||
355 | * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked | ||
356 | * | ||
357 | */ | ||
358 | public boolean forOneArbitraryMatch(final Double pAverage, final Consumer<? super AverageFreeMemoryMetric.Match> processor) { | ||
359 | return rawForOneArbitraryMatch(new Object[]{pAverage}, processor); | ||
360 | } | ||
361 | |||
362 | /** | ||
363 | * Returns a new (partial) match. | ||
364 | * This can be used e.g. to call the matcher with a partial match. | ||
365 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
366 | * @param pAverage the fixed value of pattern parameter Average, or null if not bound. | ||
367 | * @return the (partial) match object. | ||
368 | * | ||
369 | */ | ||
370 | public AverageFreeMemoryMetric.Match newMatch(final Double pAverage) { | ||
371 | return AverageFreeMemoryMetric.Match.newMatch(pAverage); | ||
372 | } | ||
373 | |||
374 | /** | ||
375 | * Retrieve the set of values that occur in matches for Average. | ||
376 | * @return the Set of all values or empty set if there are no matches | ||
377 | * | ||
378 | */ | ||
379 | protected Stream<Double> rawStreamAllValuesOfAverage(final Object[] parameters) { | ||
380 | return rawStreamAllValues(POSITION_AVERAGE, parameters).map(Double.class::cast); | ||
381 | } | ||
382 | |||
383 | /** | ||
384 | * Retrieve the set of values that occur in matches for Average. | ||
385 | * @return the Set of all values or empty set if there are no matches | ||
386 | * | ||
387 | */ | ||
388 | public Set<Double> getAllValuesOfAverage() { | ||
389 | return rawStreamAllValuesOfAverage(emptyArray()).collect(Collectors.toSet()); | ||
390 | } | ||
391 | |||
392 | /** | ||
393 | * Retrieve the set of values that occur in matches for Average. | ||
394 | * @return the Set of all values or empty set if there are no matches | ||
395 | * | ||
396 | */ | ||
397 | public Stream<Double> streamAllValuesOfAverage() { | ||
398 | return rawStreamAllValuesOfAverage(emptyArray()); | ||
399 | } | ||
400 | |||
401 | @Override | ||
402 | protected AverageFreeMemoryMetric.Match tupleToMatch(final Tuple t) { | ||
403 | try { | ||
404 | return AverageFreeMemoryMetric.Match.newMatch((Double) t.get(POSITION_AVERAGE)); | ||
405 | } catch(ClassCastException e) { | ||
406 | LOGGER.error("Element(s) in tuple not properly typed!",e); | ||
407 | return null; | ||
408 | } | ||
409 | } | ||
410 | |||
411 | @Override | ||
412 | protected AverageFreeMemoryMetric.Match arrayToMatch(final Object[] match) { | ||
413 | try { | ||
414 | return AverageFreeMemoryMetric.Match.newMatch((Double) match[POSITION_AVERAGE]); | ||
415 | } catch(ClassCastException e) { | ||
416 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
417 | return null; | ||
418 | } | ||
419 | } | ||
420 | |||
421 | @Override | ||
422 | protected AverageFreeMemoryMetric.Match arrayToMatchMutable(final Object[] match) { | ||
423 | try { | ||
424 | return AverageFreeMemoryMetric.Match.newMutableMatch((Double) match[POSITION_AVERAGE]); | ||
425 | } catch(ClassCastException e) { | ||
426 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
427 | return null; | ||
428 | } | ||
429 | } | ||
430 | |||
431 | /** | ||
432 | * @return the singleton instance of the query specification of this pattern | ||
433 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
434 | * | ||
435 | */ | ||
436 | public static IQuerySpecification<AverageFreeMemoryMetric.Matcher> querySpecification() { | ||
437 | return AverageFreeMemoryMetric.instance(); | ||
438 | } | ||
439 | } | ||
440 | |||
441 | private AverageFreeMemoryMetric() { | ||
442 | super(GeneratedPQuery.INSTANCE); | ||
443 | } | ||
444 | |||
445 | /** | ||
446 | * @return the singleton instance of the query specification | ||
447 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
448 | * | ||
449 | */ | ||
450 | public static AverageFreeMemoryMetric instance() { | ||
451 | try{ | ||
452 | return LazyHolder.INSTANCE; | ||
453 | } catch (ExceptionInInitializerError err) { | ||
454 | throw processInitializerError(err); | ||
455 | } | ||
456 | } | ||
457 | |||
458 | @Override | ||
459 | protected AverageFreeMemoryMetric.Matcher instantiate(final ViatraQueryEngine engine) { | ||
460 | return AverageFreeMemoryMetric.Matcher.on(engine); | ||
461 | } | ||
462 | |||
463 | @Override | ||
464 | public AverageFreeMemoryMetric.Matcher instantiate() { | ||
465 | return AverageFreeMemoryMetric.Matcher.create(); | ||
466 | } | ||
467 | |||
468 | @Override | ||
469 | public AverageFreeMemoryMetric.Match newEmptyMatch() { | ||
470 | return AverageFreeMemoryMetric.Match.newEmptyMatch(); | ||
471 | } | ||
472 | |||
473 | @Override | ||
474 | public AverageFreeMemoryMetric.Match newMatch(final Object... parameters) { | ||
475 | return AverageFreeMemoryMetric.Match.newMatch((java.lang.Double) parameters[0]); | ||
476 | } | ||
477 | |||
478 | /** | ||
479 | * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.AverageFreeMemoryMetric (visibility: PUBLIC, simpleName: AverageFreeMemoryMetric, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.AverageFreeMemoryMetric, 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 | ||
480 | * <b>not</b> at the class load time of the outer class, | ||
481 | * but rather at the first call to {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.AverageFreeMemoryMetric (visibility: PUBLIC, simpleName: AverageFreeMemoryMetric, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.AverageFreeMemoryMetric, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}. | ||
482 | * | ||
483 | * <p> This workaround is required e.g. to support recursion. | ||
484 | * | ||
485 | */ | ||
486 | private static class LazyHolder { | ||
487 | private static final AverageFreeMemoryMetric INSTANCE = new AverageFreeMemoryMetric(); | ||
488 | |||
489 | /** | ||
490 | * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned. | ||
491 | * This initialization order is required to support indirect recursion. | ||
492 | * | ||
493 | * <p> The static initializer is defined using a helper field to work around limitations of the code generator. | ||
494 | * | ||
495 | */ | ||
496 | private static final Object STATIC_INITIALIZER = ensureInitialized(); | ||
497 | |||
498 | public static Object ensureInitialized() { | ||
499 | INSTANCE.ensureInitializedInternal(); | ||
500 | return null; | ||
501 | } | ||
502 | } | ||
503 | |||
504 | private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { | ||
505 | private static final AverageFreeMemoryMetric.GeneratedPQuery INSTANCE = new GeneratedPQuery(); | ||
506 | |||
507 | private final PParameter parameter_Average = new PParameter("Average", "java.lang.Double", new JavaTransitiveInstancesKey(java.lang.Double.class), PParameterDirection.INOUT); | ||
508 | |||
509 | private final List<PParameter> parameters = Arrays.asList(parameter_Average); | ||
510 | |||
511 | private GeneratedPQuery() { | ||
512 | super(PVisibility.PUBLIC); | ||
513 | } | ||
514 | |||
515 | @Override | ||
516 | public String getFullyQualifiedName() { | ||
517 | return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.averageFreeMemoryMetric"; | ||
518 | } | ||
519 | |||
520 | @Override | ||
521 | public List<String> getParameterNames() { | ||
522 | return Arrays.asList("Average"); | ||
523 | } | ||
524 | |||
525 | @Override | ||
526 | public List<PParameter> getParameters() { | ||
527 | return parameters; | ||
528 | } | ||
529 | |||
530 | @Override | ||
531 | public Set<PBody> doGetContainedBodies() { | ||
532 | setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); | ||
533 | Set<PBody> bodies = new LinkedHashSet<>(); | ||
534 | { | ||
535 | PBody body = new PBody(this); | ||
536 | PVariable var_Average = body.getOrCreateVariableByName("Average"); | ||
537 | PVariable var___0_ = body.getOrCreateVariableByName("_<0>"); | ||
538 | PVariable var___1_ = body.getOrCreateVariableByName("_<1>"); | ||
539 | new TypeFilterConstraint(body, Tuples.flatTupleOf(var_Average), new JavaTransitiveInstancesKey(java.lang.Double.class)); | ||
540 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
541 | new ExportedParameter(body, var_Average, parameter_Average) | ||
542 | )); | ||
543 | // Average == avg find freeMemoryPercentage(_, #_) | ||
544 | PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); | ||
545 | new AggregatorConstraint(new avg().getAggregatorLogic(Double.class), body, Tuples.flatTupleOf(var___0_, var___1_), FreeMemoryPercentage.instance().getInternalQueryRepresentation(), var__virtual_0_, 1); | ||
546 | new Equality(body, var_Average, var__virtual_0_); | ||
547 | bodies.add(body); | ||
548 | } | ||
549 | return bodies; | ||
550 | } | ||
551 | } | ||
552 | } | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CostMetric.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CostMetric.java new file mode 100644 index 00000000..bf886ec0 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CostMetric.java | |||
@@ -0,0 +1,544 @@ | |||
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.queries.CpsCost; | ||
7 | import java.util.Arrays; | ||
8 | import java.util.Collection; | ||
9 | import java.util.LinkedHashSet; | ||
10 | import java.util.List; | ||
11 | import java.util.Objects; | ||
12 | import java.util.Optional; | ||
13 | import java.util.Set; | ||
14 | import java.util.function.Consumer; | ||
15 | import java.util.stream.Collectors; | ||
16 | import java.util.stream.Stream; | ||
17 | import org.apache.log4j.Logger; | ||
18 | import org.eclipse.viatra.query.runtime.api.IPatternMatch; | ||
19 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification; | ||
20 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; | ||
21 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; | ||
22 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; | ||
23 | import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; | ||
24 | import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; | ||
25 | import org.eclipse.viatra.query.runtime.matchers.aggregators.sum; | ||
26 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
27 | import org.eclipse.viatra.query.runtime.matchers.context.common.JavaTransitiveInstancesKey; | ||
28 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | ||
29 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | ||
30 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.AggregatorConstraint; | ||
31 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; | ||
32 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
33 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.TypeFilterConstraint; | ||
34 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | ||
35 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; | ||
36 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | ||
37 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; | ||
38 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
39 | import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; | ||
40 | |||
41 | /** | ||
42 | * A pattern-specific query specification that can instantiate Matcher in a type-safe way. | ||
43 | * | ||
44 | * <p>Original source: | ||
45 | * <code><pre> | ||
46 | * // Total cost | ||
47 | * | ||
48 | * pattern costMetric(Cost : java Integer) { | ||
49 | * Cost == sum find cpsCost(_, #_); | ||
50 | * } | ||
51 | * </pre></code> | ||
52 | * | ||
53 | * @see Matcher | ||
54 | * @see Match | ||
55 | * | ||
56 | */ | ||
57 | @SuppressWarnings("all") | ||
58 | public final class CostMetric extends BaseGeneratedEMFQuerySpecification<CostMetric.Matcher> { | ||
59 | /** | ||
60 | * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.costMetric pattern, | ||
61 | * to be used in conjunction with {@link Matcher}. | ||
62 | * | ||
63 | * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. | ||
64 | * Each instance is a (possibly partial) substitution of pattern parameters, | ||
65 | * usable to represent a match of the pattern in the result of a query, | ||
66 | * or to specify the bound (fixed) input parameters when issuing a query. | ||
67 | * | ||
68 | * @see Matcher | ||
69 | * | ||
70 | */ | ||
71 | public static abstract class Match extends BasePatternMatch { | ||
72 | private Integer fCost; | ||
73 | |||
74 | private static List<String> parameterNames = makeImmutableList("Cost"); | ||
75 | |||
76 | private Match(final Integer pCost) { | ||
77 | this.fCost = pCost; | ||
78 | } | ||
79 | |||
80 | @Override | ||
81 | public Object get(final String parameterName) { | ||
82 | if ("Cost".equals(parameterName)) return this.fCost; | ||
83 | return null; | ||
84 | } | ||
85 | |||
86 | public Integer getCost() { | ||
87 | return this.fCost; | ||
88 | } | ||
89 | |||
90 | @Override | ||
91 | public boolean set(final String parameterName, final Object newValue) { | ||
92 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
93 | if ("Cost".equals(parameterName) ) { | ||
94 | this.fCost = (Integer) newValue; | ||
95 | return true; | ||
96 | } | ||
97 | return false; | ||
98 | } | ||
99 | |||
100 | public void setCost(final Integer pCost) { | ||
101 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
102 | this.fCost = pCost; | ||
103 | } | ||
104 | |||
105 | @Override | ||
106 | public String patternName() { | ||
107 | return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.costMetric"; | ||
108 | } | ||
109 | |||
110 | @Override | ||
111 | public List<String> parameterNames() { | ||
112 | return CostMetric.Match.parameterNames; | ||
113 | } | ||
114 | |||
115 | @Override | ||
116 | public Object[] toArray() { | ||
117 | return new Object[]{fCost}; | ||
118 | } | ||
119 | |||
120 | @Override | ||
121 | public CostMetric.Match toImmutable() { | ||
122 | return isMutable() ? newMatch(fCost) : this; | ||
123 | } | ||
124 | |||
125 | @Override | ||
126 | public String prettyPrint() { | ||
127 | StringBuilder result = new StringBuilder(); | ||
128 | result.append("\"Cost\"=" + prettyPrintValue(fCost)); | ||
129 | return result.toString(); | ||
130 | } | ||
131 | |||
132 | @Override | ||
133 | public int hashCode() { | ||
134 | return Objects.hash(fCost); | ||
135 | } | ||
136 | |||
137 | @Override | ||
138 | public boolean equals(final Object obj) { | ||
139 | if (this == obj) | ||
140 | return true; | ||
141 | if (obj == null) { | ||
142 | return false; | ||
143 | } | ||
144 | if ((obj instanceof CostMetric.Match)) { | ||
145 | CostMetric.Match other = (CostMetric.Match) obj; | ||
146 | return Objects.equals(fCost, other.fCost); | ||
147 | } else { | ||
148 | // this should be infrequent | ||
149 | if (!(obj instanceof IPatternMatch)) { | ||
150 | return false; | ||
151 | } | ||
152 | IPatternMatch otherSig = (IPatternMatch) obj; | ||
153 | return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); | ||
154 | } | ||
155 | } | ||
156 | |||
157 | @Override | ||
158 | public CostMetric specification() { | ||
159 | return CostMetric.instance(); | ||
160 | } | ||
161 | |||
162 | /** | ||
163 | * Returns an empty, mutable match. | ||
164 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
165 | * | ||
166 | * @return the empty match. | ||
167 | * | ||
168 | */ | ||
169 | public static CostMetric.Match newEmptyMatch() { | ||
170 | return new Mutable(null); | ||
171 | } | ||
172 | |||
173 | /** | ||
174 | * Returns a mutable (partial) match. | ||
175 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
176 | * | ||
177 | * @param pCost the fixed value of pattern parameter Cost, or null if not bound. | ||
178 | * @return the new, mutable (partial) match object. | ||
179 | * | ||
180 | */ | ||
181 | public static CostMetric.Match newMutableMatch(final Integer pCost) { | ||
182 | return new Mutable(pCost); | ||
183 | } | ||
184 | |||
185 | /** | ||
186 | * Returns a new (partial) match. | ||
187 | * This can be used e.g. to call the matcher with a partial match. | ||
188 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
189 | * @param pCost the fixed value of pattern parameter Cost, or null if not bound. | ||
190 | * @return the (partial) match object. | ||
191 | * | ||
192 | */ | ||
193 | public static CostMetric.Match newMatch(final Integer pCost) { | ||
194 | return new Immutable(pCost); | ||
195 | } | ||
196 | |||
197 | private static final class Mutable extends CostMetric.Match { | ||
198 | Mutable(final Integer pCost) { | ||
199 | super(pCost); | ||
200 | } | ||
201 | |||
202 | @Override | ||
203 | public boolean isMutable() { | ||
204 | return true; | ||
205 | } | ||
206 | } | ||
207 | |||
208 | private static final class Immutable extends CostMetric.Match { | ||
209 | Immutable(final Integer pCost) { | ||
210 | super(pCost); | ||
211 | } | ||
212 | |||
213 | @Override | ||
214 | public boolean isMutable() { | ||
215 | return false; | ||
216 | } | ||
217 | } | ||
218 | } | ||
219 | |||
220 | /** | ||
221 | * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.costMetric pattern, | ||
222 | * providing pattern-specific query methods. | ||
223 | * | ||
224 | * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, | ||
225 | * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. | ||
226 | * | ||
227 | * <p>Matches of the pattern will be represented as {@link Match}. | ||
228 | * | ||
229 | * <p>Original source: | ||
230 | * <code><pre> | ||
231 | * // Total cost | ||
232 | * | ||
233 | * pattern costMetric(Cost : java Integer) { | ||
234 | * Cost == sum find cpsCost(_, #_); | ||
235 | * } | ||
236 | * </pre></code> | ||
237 | * | ||
238 | * @see Match | ||
239 | * @see CostMetric | ||
240 | * | ||
241 | */ | ||
242 | public static class Matcher extends BaseMatcher<CostMetric.Match> { | ||
243 | /** | ||
244 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
245 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
246 | * | ||
247 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
248 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
249 | * | ||
250 | */ | ||
251 | public static CostMetric.Matcher on(final ViatraQueryEngine engine) { | ||
252 | // check if matcher already exists | ||
253 | Matcher matcher = engine.getExistingMatcher(querySpecification()); | ||
254 | if (matcher == null) { | ||
255 | matcher = (Matcher)engine.getMatcher(querySpecification()); | ||
256 | } | ||
257 | return matcher; | ||
258 | } | ||
259 | |||
260 | /** | ||
261 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
262 | * @return an initialized matcher | ||
263 | * @noreference This method is for internal matcher initialization by the framework, do not call it manually. | ||
264 | * | ||
265 | */ | ||
266 | public static CostMetric.Matcher create() { | ||
267 | return new Matcher(); | ||
268 | } | ||
269 | |||
270 | private static final int POSITION_COST = 0; | ||
271 | |||
272 | private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(CostMetric.Matcher.class); | ||
273 | |||
274 | /** | ||
275 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
276 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
277 | * | ||
278 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
279 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
280 | * | ||
281 | */ | ||
282 | private Matcher() { | ||
283 | super(querySpecification()); | ||
284 | } | ||
285 | |||
286 | /** | ||
287 | * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. | ||
288 | * @param pCost the fixed value of pattern parameter Cost, or null if not bound. | ||
289 | * @return matches represented as a Match object. | ||
290 | * | ||
291 | */ | ||
292 | public Collection<CostMetric.Match> getAllMatches(final Integer pCost) { | ||
293 | return rawStreamAllMatches(new Object[]{pCost}).collect(Collectors.toSet()); | ||
294 | } | ||
295 | |||
296 | /** | ||
297 | * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. | ||
298 | * </p> | ||
299 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
300 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
301 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
302 | * @param pCost the fixed value of pattern parameter Cost, or null if not bound. | ||
303 | * @return a stream of matches represented as a Match object. | ||
304 | * | ||
305 | */ | ||
306 | public Stream<CostMetric.Match> streamAllMatches(final Integer pCost) { | ||
307 | return rawStreamAllMatches(new Object[]{pCost}); | ||
308 | } | ||
309 | |||
310 | /** | ||
311 | * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
312 | * Neither determinism nor randomness of selection is guaranteed. | ||
313 | * @param pCost the fixed value of pattern parameter Cost, or null if not bound. | ||
314 | * @return a match represented as a Match object, or null if no match is found. | ||
315 | * | ||
316 | */ | ||
317 | public Optional<CostMetric.Match> getOneArbitraryMatch(final Integer pCost) { | ||
318 | return rawGetOneArbitraryMatch(new Object[]{pCost}); | ||
319 | } | ||
320 | |||
321 | /** | ||
322 | * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, | ||
323 | * under any possible substitution of the unspecified parameters (if any). | ||
324 | * @param pCost the fixed value of pattern parameter Cost, or null if not bound. | ||
325 | * @return true if the input is a valid (partial) match of the pattern. | ||
326 | * | ||
327 | */ | ||
328 | public boolean hasMatch(final Integer pCost) { | ||
329 | return rawHasMatch(new Object[]{pCost}); | ||
330 | } | ||
331 | |||
332 | /** | ||
333 | * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. | ||
334 | * @param pCost the fixed value of pattern parameter Cost, or null if not bound. | ||
335 | * @return the number of pattern matches found. | ||
336 | * | ||
337 | */ | ||
338 | public int countMatches(final Integer pCost) { | ||
339 | return rawCountMatches(new Object[]{pCost}); | ||
340 | } | ||
341 | |||
342 | /** | ||
343 | * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
344 | * Neither determinism nor randomness of selection is guaranteed. | ||
345 | * @param pCost the fixed value of pattern parameter Cost, or null if not bound. | ||
346 | * @param processor the action that will process the selected match. | ||
347 | * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked | ||
348 | * | ||
349 | */ | ||
350 | public boolean forOneArbitraryMatch(final Integer pCost, final Consumer<? super CostMetric.Match> processor) { | ||
351 | return rawForOneArbitraryMatch(new Object[]{pCost}, processor); | ||
352 | } | ||
353 | |||
354 | /** | ||
355 | * Returns a new (partial) match. | ||
356 | * This can be used e.g. to call the matcher with a partial match. | ||
357 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
358 | * @param pCost the fixed value of pattern parameter Cost, or null if not bound. | ||
359 | * @return the (partial) match object. | ||
360 | * | ||
361 | */ | ||
362 | public CostMetric.Match newMatch(final Integer pCost) { | ||
363 | return CostMetric.Match.newMatch(pCost); | ||
364 | } | ||
365 | |||
366 | /** | ||
367 | * Retrieve the set of values that occur in matches for Cost. | ||
368 | * @return the Set of all values or empty set if there are no matches | ||
369 | * | ||
370 | */ | ||
371 | protected Stream<Integer> rawStreamAllValuesOfCost(final Object[] parameters) { | ||
372 | return rawStreamAllValues(POSITION_COST, parameters).map(Integer.class::cast); | ||
373 | } | ||
374 | |||
375 | /** | ||
376 | * Retrieve the set of values that occur in matches for Cost. | ||
377 | * @return the Set of all values or empty set if there are no matches | ||
378 | * | ||
379 | */ | ||
380 | public Set<Integer> getAllValuesOfCost() { | ||
381 | return rawStreamAllValuesOfCost(emptyArray()).collect(Collectors.toSet()); | ||
382 | } | ||
383 | |||
384 | /** | ||
385 | * Retrieve the set of values that occur in matches for Cost. | ||
386 | * @return the Set of all values or empty set if there are no matches | ||
387 | * | ||
388 | */ | ||
389 | public Stream<Integer> streamAllValuesOfCost() { | ||
390 | return rawStreamAllValuesOfCost(emptyArray()); | ||
391 | } | ||
392 | |||
393 | @Override | ||
394 | protected CostMetric.Match tupleToMatch(final Tuple t) { | ||
395 | try { | ||
396 | return CostMetric.Match.newMatch((Integer) t.get(POSITION_COST)); | ||
397 | } catch(ClassCastException e) { | ||
398 | LOGGER.error("Element(s) in tuple not properly typed!",e); | ||
399 | return null; | ||
400 | } | ||
401 | } | ||
402 | |||
403 | @Override | ||
404 | protected CostMetric.Match arrayToMatch(final Object[] match) { | ||
405 | try { | ||
406 | return CostMetric.Match.newMatch((Integer) match[POSITION_COST]); | ||
407 | } catch(ClassCastException e) { | ||
408 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
409 | return null; | ||
410 | } | ||
411 | } | ||
412 | |||
413 | @Override | ||
414 | protected CostMetric.Match arrayToMatchMutable(final Object[] match) { | ||
415 | try { | ||
416 | return CostMetric.Match.newMutableMatch((Integer) match[POSITION_COST]); | ||
417 | } catch(ClassCastException e) { | ||
418 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
419 | return null; | ||
420 | } | ||
421 | } | ||
422 | |||
423 | /** | ||
424 | * @return the singleton instance of the query specification of this pattern | ||
425 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
426 | * | ||
427 | */ | ||
428 | public static IQuerySpecification<CostMetric.Matcher> querySpecification() { | ||
429 | return CostMetric.instance(); | ||
430 | } | ||
431 | } | ||
432 | |||
433 | private CostMetric() { | ||
434 | super(GeneratedPQuery.INSTANCE); | ||
435 | } | ||
436 | |||
437 | /** | ||
438 | * @return the singleton instance of the query specification | ||
439 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
440 | * | ||
441 | */ | ||
442 | public static CostMetric instance() { | ||
443 | try{ | ||
444 | return LazyHolder.INSTANCE; | ||
445 | } catch (ExceptionInInitializerError err) { | ||
446 | throw processInitializerError(err); | ||
447 | } | ||
448 | } | ||
449 | |||
450 | @Override | ||
451 | protected CostMetric.Matcher instantiate(final ViatraQueryEngine engine) { | ||
452 | return CostMetric.Matcher.on(engine); | ||
453 | } | ||
454 | |||
455 | @Override | ||
456 | public CostMetric.Matcher instantiate() { | ||
457 | return CostMetric.Matcher.create(); | ||
458 | } | ||
459 | |||
460 | @Override | ||
461 | public CostMetric.Match newEmptyMatch() { | ||
462 | return CostMetric.Match.newEmptyMatch(); | ||
463 | } | ||
464 | |||
465 | @Override | ||
466 | public CostMetric.Match newMatch(final Object... parameters) { | ||
467 | return CostMetric.Match.newMatch((java.lang.Integer) parameters[0]); | ||
468 | } | ||
469 | |||
470 | /** | ||
471 | * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.CostMetric (visibility: PUBLIC, simpleName: CostMetric, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.CostMetric, 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 | ||
472 | * <b>not</b> at the class load time of the outer class, | ||
473 | * but rather at the first call to {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.CostMetric (visibility: PUBLIC, simpleName: CostMetric, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.CostMetric, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}. | ||
474 | * | ||
475 | * <p> This workaround is required e.g. to support recursion. | ||
476 | * | ||
477 | */ | ||
478 | private static class LazyHolder { | ||
479 | private static final CostMetric INSTANCE = new CostMetric(); | ||
480 | |||
481 | /** | ||
482 | * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned. | ||
483 | * This initialization order is required to support indirect recursion. | ||
484 | * | ||
485 | * <p> The static initializer is defined using a helper field to work around limitations of the code generator. | ||
486 | * | ||
487 | */ | ||
488 | private static final Object STATIC_INITIALIZER = ensureInitialized(); | ||
489 | |||
490 | public static Object ensureInitialized() { | ||
491 | INSTANCE.ensureInitializedInternal(); | ||
492 | return null; | ||
493 | } | ||
494 | } | ||
495 | |||
496 | private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { | ||
497 | private static final CostMetric.GeneratedPQuery INSTANCE = new GeneratedPQuery(); | ||
498 | |||
499 | private final PParameter parameter_Cost = new PParameter("Cost", "java.lang.Integer", new JavaTransitiveInstancesKey(java.lang.Integer.class), PParameterDirection.INOUT); | ||
500 | |||
501 | private final List<PParameter> parameters = Arrays.asList(parameter_Cost); | ||
502 | |||
503 | private GeneratedPQuery() { | ||
504 | super(PVisibility.PUBLIC); | ||
505 | } | ||
506 | |||
507 | @Override | ||
508 | public String getFullyQualifiedName() { | ||
509 | return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.costMetric"; | ||
510 | } | ||
511 | |||
512 | @Override | ||
513 | public List<String> getParameterNames() { | ||
514 | return Arrays.asList("Cost"); | ||
515 | } | ||
516 | |||
517 | @Override | ||
518 | public List<PParameter> getParameters() { | ||
519 | return parameters; | ||
520 | } | ||
521 | |||
522 | @Override | ||
523 | public Set<PBody> doGetContainedBodies() { | ||
524 | setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); | ||
525 | Set<PBody> bodies = new LinkedHashSet<>(); | ||
526 | { | ||
527 | PBody body = new PBody(this); | ||
528 | PVariable var_Cost = body.getOrCreateVariableByName("Cost"); | ||
529 | PVariable var___0_ = body.getOrCreateVariableByName("_<0>"); | ||
530 | PVariable var___1_ = body.getOrCreateVariableByName("_<1>"); | ||
531 | new TypeFilterConstraint(body, Tuples.flatTupleOf(var_Cost), new JavaTransitiveInstancesKey(java.lang.Integer.class)); | ||
532 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
533 | new ExportedParameter(body, var_Cost, parameter_Cost) | ||
534 | )); | ||
535 | // Cost == sum find cpsCost(_, #_) | ||
536 | PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); | ||
537 | new AggregatorConstraint(new sum().getAggregatorLogic(Integer.class), body, Tuples.flatTupleOf(var___0_, var___1_), CpsCost.instance().getInternalQueryRepresentation(), var__virtual_0_, 1); | ||
538 | new Equality(body, var_Cost, var__virtual_0_); | ||
539 | bodies.add(body); | ||
540 | } | ||
541 | return bodies; | ||
542 | } | ||
543 | } | ||
544 | } | ||
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..fc90ef12 --- /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.internal.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 | } | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.java new file mode 100644 index 00000000..c889fbe0 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.java | |||
@@ -0,0 +1,218 @@ | |||
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.queries.Allocate; | ||
7 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.AllocationWithoutResourceRequirement; | ||
8 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.AverageFreeHddMetric; | ||
9 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.AverageFreeMemoryMetric; | ||
10 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.CostMetric; | ||
11 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.CpsCost; | ||
12 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.CreateHostInstance; | ||
13 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.GuidanceObjective; | ||
14 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.InstanceDoesNotSatisfyRequirement; | ||
15 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.NotEnoughAvailableHdd; | ||
16 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.NotEnoughAvailableMemory; | ||
17 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.RedundantInstancesOnSameHost; | ||
18 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.RemoveHostInstance; | ||
19 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.RequirementNotSatisfied; | ||
20 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.ResourceRequirement; | ||
21 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.UnallocateAppInstance; | ||
22 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; | ||
23 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedPatternGroup; | ||
24 | |||
25 | /** | ||
26 | * A pattern group formed of all public patterns defined in CpsQueries.vql. | ||
27 | * | ||
28 | * <p>Use the static instance as any {@link interface org.eclipse.viatra.query.runtime.api.IQueryGroup}, to conveniently prepare | ||
29 | * a VIATRA Query engine for matching all patterns originally defined in file CpsQueries.vql, | ||
30 | * in order to achieve better performance than one-by-one on-demand matcher initialization. | ||
31 | * | ||
32 | * <p> From package hu.bme.mit.inf.dslreasoner.domains.cps.queries, the group contains the definition of the following patterns: <ul> | ||
33 | * <li>resourceRequirement</li> | ||
34 | * <li>allocationWithoutResourceRequirement</li> | ||
35 | * <li>notEnoughAvailableMemory</li> | ||
36 | * <li>notEnoughAvailableHdd</li> | ||
37 | * <li>instanceDoesNotSatisfyRequirement</li> | ||
38 | * <li>requirementNotSatisfied</li> | ||
39 | * <li>redundantInstancesOnSameHost</li> | ||
40 | * <li>averageFreeMemoryMetric</li> | ||
41 | * <li>averageFreeHddMetric</li> | ||
42 | * <li>costMetric</li> | ||
43 | * <li>cpsCost</li> | ||
44 | * <li>allocate</li> | ||
45 | * <li>unallocateAppInstance</li> | ||
46 | * <li>createHostInstance</li> | ||
47 | * <li>removeHostInstance</li> | ||
48 | * <li>guidanceObjective</li> | ||
49 | * </ul> | ||
50 | * | ||
51 | * @see IQueryGroup | ||
52 | * | ||
53 | */ | ||
54 | @SuppressWarnings("all") | ||
55 | public final class CpsQueries extends BaseGeneratedPatternGroup { | ||
56 | /** | ||
57 | * Access the pattern group. | ||
58 | * | ||
59 | * @return the singleton instance of the group | ||
60 | * @throws ViatraQueryRuntimeException if there was an error loading the generated code of pattern specifications | ||
61 | * | ||
62 | */ | ||
63 | public static CpsQueries instance() { | ||
64 | if (INSTANCE == null) { | ||
65 | INSTANCE = new CpsQueries(); | ||
66 | } | ||
67 | return INSTANCE; | ||
68 | } | ||
69 | |||
70 | private static CpsQueries INSTANCE; | ||
71 | |||
72 | private CpsQueries() { | ||
73 | querySpecifications.add(ResourceRequirement.instance()); | ||
74 | querySpecifications.add(AllocationWithoutResourceRequirement.instance()); | ||
75 | querySpecifications.add(NotEnoughAvailableMemory.instance()); | ||
76 | querySpecifications.add(NotEnoughAvailableHdd.instance()); | ||
77 | querySpecifications.add(InstanceDoesNotSatisfyRequirement.instance()); | ||
78 | querySpecifications.add(RequirementNotSatisfied.instance()); | ||
79 | querySpecifications.add(RedundantInstancesOnSameHost.instance()); | ||
80 | querySpecifications.add(AverageFreeMemoryMetric.instance()); | ||
81 | querySpecifications.add(AverageFreeHddMetric.instance()); | ||
82 | querySpecifications.add(CostMetric.instance()); | ||
83 | querySpecifications.add(CpsCost.instance()); | ||
84 | querySpecifications.add(Allocate.instance()); | ||
85 | querySpecifications.add(UnallocateAppInstance.instance()); | ||
86 | querySpecifications.add(CreateHostInstance.instance()); | ||
87 | querySpecifications.add(RemoveHostInstance.instance()); | ||
88 | querySpecifications.add(GuidanceObjective.instance()); | ||
89 | } | ||
90 | |||
91 | public ResourceRequirement getResourceRequirement() { | ||
92 | return ResourceRequirement.instance(); | ||
93 | } | ||
94 | |||
95 | public ResourceRequirement.Matcher getResourceRequirement(final ViatraQueryEngine engine) { | ||
96 | return ResourceRequirement.Matcher.on(engine); | ||
97 | } | ||
98 | |||
99 | public AllocationWithoutResourceRequirement getAllocationWithoutResourceRequirement() { | ||
100 | return AllocationWithoutResourceRequirement.instance(); | ||
101 | } | ||
102 | |||
103 | public AllocationWithoutResourceRequirement.Matcher getAllocationWithoutResourceRequirement(final ViatraQueryEngine engine) { | ||
104 | return AllocationWithoutResourceRequirement.Matcher.on(engine); | ||
105 | } | ||
106 | |||
107 | public NotEnoughAvailableMemory getNotEnoughAvailableMemory() { | ||
108 | return NotEnoughAvailableMemory.instance(); | ||
109 | } | ||
110 | |||
111 | public NotEnoughAvailableMemory.Matcher getNotEnoughAvailableMemory(final ViatraQueryEngine engine) { | ||
112 | return NotEnoughAvailableMemory.Matcher.on(engine); | ||
113 | } | ||
114 | |||
115 | public NotEnoughAvailableHdd getNotEnoughAvailableHdd() { | ||
116 | return NotEnoughAvailableHdd.instance(); | ||
117 | } | ||
118 | |||
119 | public NotEnoughAvailableHdd.Matcher getNotEnoughAvailableHdd(final ViatraQueryEngine engine) { | ||
120 | return NotEnoughAvailableHdd.Matcher.on(engine); | ||
121 | } | ||
122 | |||
123 | public InstanceDoesNotSatisfyRequirement getInstanceDoesNotSatisfyRequirement() { | ||
124 | return InstanceDoesNotSatisfyRequirement.instance(); | ||
125 | } | ||
126 | |||
127 | public InstanceDoesNotSatisfyRequirement.Matcher getInstanceDoesNotSatisfyRequirement(final ViatraQueryEngine engine) { | ||
128 | return InstanceDoesNotSatisfyRequirement.Matcher.on(engine); | ||
129 | } | ||
130 | |||
131 | public RequirementNotSatisfied getRequirementNotSatisfied() { | ||
132 | return RequirementNotSatisfied.instance(); | ||
133 | } | ||
134 | |||
135 | public RequirementNotSatisfied.Matcher getRequirementNotSatisfied(final ViatraQueryEngine engine) { | ||
136 | return RequirementNotSatisfied.Matcher.on(engine); | ||
137 | } | ||
138 | |||
139 | public RedundantInstancesOnSameHost getRedundantInstancesOnSameHost() { | ||
140 | return RedundantInstancesOnSameHost.instance(); | ||
141 | } | ||
142 | |||
143 | public RedundantInstancesOnSameHost.Matcher getRedundantInstancesOnSameHost(final ViatraQueryEngine engine) { | ||
144 | return RedundantInstancesOnSameHost.Matcher.on(engine); | ||
145 | } | ||
146 | |||
147 | public AverageFreeMemoryMetric getAverageFreeMemoryMetric() { | ||
148 | return AverageFreeMemoryMetric.instance(); | ||
149 | } | ||
150 | |||
151 | public AverageFreeMemoryMetric.Matcher getAverageFreeMemoryMetric(final ViatraQueryEngine engine) { | ||
152 | return AverageFreeMemoryMetric.Matcher.on(engine); | ||
153 | } | ||
154 | |||
155 | public AverageFreeHddMetric getAverageFreeHddMetric() { | ||
156 | return AverageFreeHddMetric.instance(); | ||
157 | } | ||
158 | |||
159 | public AverageFreeHddMetric.Matcher getAverageFreeHddMetric(final ViatraQueryEngine engine) { | ||
160 | return AverageFreeHddMetric.Matcher.on(engine); | ||
161 | } | ||
162 | |||
163 | public CostMetric getCostMetric() { | ||
164 | return CostMetric.instance(); | ||
165 | } | ||
166 | |||
167 | public CostMetric.Matcher getCostMetric(final ViatraQueryEngine engine) { | ||
168 | return CostMetric.Matcher.on(engine); | ||
169 | } | ||
170 | |||
171 | public CpsCost getCpsCost() { | ||
172 | return CpsCost.instance(); | ||
173 | } | ||
174 | |||
175 | public CpsCost.Matcher getCpsCost(final ViatraQueryEngine engine) { | ||
176 | return CpsCost.Matcher.on(engine); | ||
177 | } | ||
178 | |||
179 | public Allocate getAllocate() { | ||
180 | return Allocate.instance(); | ||
181 | } | ||
182 | |||
183 | public Allocate.Matcher getAllocate(final ViatraQueryEngine engine) { | ||
184 | return Allocate.Matcher.on(engine); | ||
185 | } | ||
186 | |||
187 | public UnallocateAppInstance getUnallocateAppInstance() { | ||
188 | return UnallocateAppInstance.instance(); | ||
189 | } | ||
190 | |||
191 | public UnallocateAppInstance.Matcher getUnallocateAppInstance(final ViatraQueryEngine engine) { | ||
192 | return UnallocateAppInstance.Matcher.on(engine); | ||
193 | } | ||
194 | |||
195 | public CreateHostInstance getCreateHostInstance() { | ||
196 | return CreateHostInstance.instance(); | ||
197 | } | ||
198 | |||
199 | public CreateHostInstance.Matcher getCreateHostInstance(final ViatraQueryEngine engine) { | ||
200 | return CreateHostInstance.Matcher.on(engine); | ||
201 | } | ||
202 | |||
203 | public RemoveHostInstance getRemoveHostInstance() { | ||
204 | return RemoveHostInstance.instance(); | ||
205 | } | ||
206 | |||
207 | public RemoveHostInstance.Matcher getRemoveHostInstance(final ViatraQueryEngine engine) { | ||
208 | return RemoveHostInstance.Matcher.on(engine); | ||
209 | } | ||
210 | |||
211 | public GuidanceObjective getGuidanceObjective() { | ||
212 | return GuidanceObjective.instance(); | ||
213 | } | ||
214 | |||
215 | public GuidanceObjective.Matcher getGuidanceObjective(final ViatraQueryEngine engine) { | ||
216 | return GuidanceObjective.Matcher.on(engine); | ||
217 | } | ||
218 | } | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CreateHostInstance.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CreateHostInstance.java new file mode 100644 index 00000000..f475c9e9 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CreateHostInstance.java | |||
@@ -0,0 +1,553 @@ | |||
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.HostType; | ||
7 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.UnallocatedAppInstance; | ||
8 | import java.util.Arrays; | ||
9 | import java.util.Collection; | ||
10 | import java.util.LinkedHashSet; | ||
11 | import java.util.List; | ||
12 | import java.util.Objects; | ||
13 | import java.util.Optional; | ||
14 | import java.util.Set; | ||
15 | import java.util.function.Consumer; | ||
16 | import java.util.stream.Collectors; | ||
17 | import java.util.stream.Stream; | ||
18 | import org.apache.log4j.Logger; | ||
19 | import org.eclipse.emf.ecore.EClass; | ||
20 | import org.eclipse.viatra.query.runtime.api.IPatternMatch; | ||
21 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification; | ||
22 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; | ||
23 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; | ||
24 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; | ||
25 | import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; | ||
26 | import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; | ||
27 | import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; | ||
28 | import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; | ||
29 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
30 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | ||
31 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | ||
32 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; | ||
33 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
34 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall; | ||
35 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
36 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | ||
37 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; | ||
38 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | ||
39 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; | ||
40 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
41 | import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; | ||
42 | |||
43 | /** | ||
44 | * A pattern-specific query specification that can instantiate Matcher in a type-safe way. | ||
45 | * | ||
46 | * <p>Original source: | ||
47 | * <code><pre> | ||
48 | * pattern createHostInstance(HostType : HostType) { | ||
49 | * find unallocatedAppInstance(App); | ||
50 | * ApplicationInstance.type.requirements.hostType(App, HostType); | ||
51 | * } | ||
52 | * </pre></code> | ||
53 | * | ||
54 | * @see Matcher | ||
55 | * @see Match | ||
56 | * | ||
57 | */ | ||
58 | @SuppressWarnings("all") | ||
59 | public final class CreateHostInstance extends BaseGeneratedEMFQuerySpecification<CreateHostInstance.Matcher> { | ||
60 | /** | ||
61 | * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.createHostInstance pattern, | ||
62 | * to be used in conjunction with {@link Matcher}. | ||
63 | * | ||
64 | * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. | ||
65 | * Each instance is a (possibly partial) substitution of pattern parameters, | ||
66 | * usable to represent a match of the pattern in the result of a query, | ||
67 | * or to specify the bound (fixed) input parameters when issuing a query. | ||
68 | * | ||
69 | * @see Matcher | ||
70 | * | ||
71 | */ | ||
72 | public static abstract class Match extends BasePatternMatch { | ||
73 | private HostType fHostType; | ||
74 | |||
75 | private static List<String> parameterNames = makeImmutableList("HostType"); | ||
76 | |||
77 | private Match(final HostType pHostType) { | ||
78 | this.fHostType = pHostType; | ||
79 | } | ||
80 | |||
81 | @Override | ||
82 | public Object get(final String parameterName) { | ||
83 | if ("HostType".equals(parameterName)) return this.fHostType; | ||
84 | return null; | ||
85 | } | ||
86 | |||
87 | public HostType getHostType() { | ||
88 | return this.fHostType; | ||
89 | } | ||
90 | |||
91 | @Override | ||
92 | public boolean set(final String parameterName, final Object newValue) { | ||
93 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
94 | if ("HostType".equals(parameterName) ) { | ||
95 | this.fHostType = (HostType) newValue; | ||
96 | return true; | ||
97 | } | ||
98 | return false; | ||
99 | } | ||
100 | |||
101 | public void setHostType(final HostType pHostType) { | ||
102 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
103 | this.fHostType = pHostType; | ||
104 | } | ||
105 | |||
106 | @Override | ||
107 | public String patternName() { | ||
108 | return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.createHostInstance"; | ||
109 | } | ||
110 | |||
111 | @Override | ||
112 | public List<String> parameterNames() { | ||
113 | return CreateHostInstance.Match.parameterNames; | ||
114 | } | ||
115 | |||
116 | @Override | ||
117 | public Object[] toArray() { | ||
118 | return new Object[]{fHostType}; | ||
119 | } | ||
120 | |||
121 | @Override | ||
122 | public CreateHostInstance.Match toImmutable() { | ||
123 | return isMutable() ? newMatch(fHostType) : this; | ||
124 | } | ||
125 | |||
126 | @Override | ||
127 | public String prettyPrint() { | ||
128 | StringBuilder result = new StringBuilder(); | ||
129 | result.append("\"HostType\"=" + prettyPrintValue(fHostType)); | ||
130 | return result.toString(); | ||
131 | } | ||
132 | |||
133 | @Override | ||
134 | public int hashCode() { | ||
135 | return Objects.hash(fHostType); | ||
136 | } | ||
137 | |||
138 | @Override | ||
139 | public boolean equals(final Object obj) { | ||
140 | if (this == obj) | ||
141 | return true; | ||
142 | if (obj == null) { | ||
143 | return false; | ||
144 | } | ||
145 | if ((obj instanceof CreateHostInstance.Match)) { | ||
146 | CreateHostInstance.Match other = (CreateHostInstance.Match) obj; | ||
147 | return Objects.equals(fHostType, other.fHostType); | ||
148 | } else { | ||
149 | // this should be infrequent | ||
150 | if (!(obj instanceof IPatternMatch)) { | ||
151 | return false; | ||
152 | } | ||
153 | IPatternMatch otherSig = (IPatternMatch) obj; | ||
154 | return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); | ||
155 | } | ||
156 | } | ||
157 | |||
158 | @Override | ||
159 | public CreateHostInstance specification() { | ||
160 | return CreateHostInstance.instance(); | ||
161 | } | ||
162 | |||
163 | /** | ||
164 | * Returns an empty, mutable match. | ||
165 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
166 | * | ||
167 | * @return the empty match. | ||
168 | * | ||
169 | */ | ||
170 | public static CreateHostInstance.Match newEmptyMatch() { | ||
171 | return new Mutable(null); | ||
172 | } | ||
173 | |||
174 | /** | ||
175 | * Returns a mutable (partial) match. | ||
176 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
177 | * | ||
178 | * @param pHostType the fixed value of pattern parameter HostType, or null if not bound. | ||
179 | * @return the new, mutable (partial) match object. | ||
180 | * | ||
181 | */ | ||
182 | public static CreateHostInstance.Match newMutableMatch(final HostType pHostType) { | ||
183 | return new Mutable(pHostType); | ||
184 | } | ||
185 | |||
186 | /** | ||
187 | * Returns a new (partial) match. | ||
188 | * This can be used e.g. to call the matcher with a partial match. | ||
189 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
190 | * @param pHostType the fixed value of pattern parameter HostType, or null if not bound. | ||
191 | * @return the (partial) match object. | ||
192 | * | ||
193 | */ | ||
194 | public static CreateHostInstance.Match newMatch(final HostType pHostType) { | ||
195 | return new Immutable(pHostType); | ||
196 | } | ||
197 | |||
198 | private static final class Mutable extends CreateHostInstance.Match { | ||
199 | Mutable(final HostType pHostType) { | ||
200 | super(pHostType); | ||
201 | } | ||
202 | |||
203 | @Override | ||
204 | public boolean isMutable() { | ||
205 | return true; | ||
206 | } | ||
207 | } | ||
208 | |||
209 | private static final class Immutable extends CreateHostInstance.Match { | ||
210 | Immutable(final HostType pHostType) { | ||
211 | super(pHostType); | ||
212 | } | ||
213 | |||
214 | @Override | ||
215 | public boolean isMutable() { | ||
216 | return false; | ||
217 | } | ||
218 | } | ||
219 | } | ||
220 | |||
221 | /** | ||
222 | * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.createHostInstance pattern, | ||
223 | * providing pattern-specific query methods. | ||
224 | * | ||
225 | * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, | ||
226 | * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. | ||
227 | * | ||
228 | * <p>Matches of the pattern will be represented as {@link Match}. | ||
229 | * | ||
230 | * <p>Original source: | ||
231 | * <code><pre> | ||
232 | * pattern createHostInstance(HostType : HostType) { | ||
233 | * find unallocatedAppInstance(App); | ||
234 | * ApplicationInstance.type.requirements.hostType(App, HostType); | ||
235 | * } | ||
236 | * </pre></code> | ||
237 | * | ||
238 | * @see Match | ||
239 | * @see CreateHostInstance | ||
240 | * | ||
241 | */ | ||
242 | public static class Matcher extends BaseMatcher<CreateHostInstance.Match> { | ||
243 | /** | ||
244 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
245 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
246 | * | ||
247 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
248 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
249 | * | ||
250 | */ | ||
251 | public static CreateHostInstance.Matcher on(final ViatraQueryEngine engine) { | ||
252 | // check if matcher already exists | ||
253 | Matcher matcher = engine.getExistingMatcher(querySpecification()); | ||
254 | if (matcher == null) { | ||
255 | matcher = (Matcher)engine.getMatcher(querySpecification()); | ||
256 | } | ||
257 | return matcher; | ||
258 | } | ||
259 | |||
260 | /** | ||
261 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
262 | * @return an initialized matcher | ||
263 | * @noreference This method is for internal matcher initialization by the framework, do not call it manually. | ||
264 | * | ||
265 | */ | ||
266 | public static CreateHostInstance.Matcher create() { | ||
267 | return new Matcher(); | ||
268 | } | ||
269 | |||
270 | private static final int POSITION_HOSTTYPE = 0; | ||
271 | |||
272 | private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(CreateHostInstance.Matcher.class); | ||
273 | |||
274 | /** | ||
275 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
276 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
277 | * | ||
278 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
279 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
280 | * | ||
281 | */ | ||
282 | private Matcher() { | ||
283 | super(querySpecification()); | ||
284 | } | ||
285 | |||
286 | /** | ||
287 | * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. | ||
288 | * @param pHostType the fixed value of pattern parameter HostType, or null if not bound. | ||
289 | * @return matches represented as a Match object. | ||
290 | * | ||
291 | */ | ||
292 | public Collection<CreateHostInstance.Match> getAllMatches(final HostType pHostType) { | ||
293 | return rawStreamAllMatches(new Object[]{pHostType}).collect(Collectors.toSet()); | ||
294 | } | ||
295 | |||
296 | /** | ||
297 | * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. | ||
298 | * </p> | ||
299 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
300 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
301 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
302 | * @param pHostType the fixed value of pattern parameter HostType, or null if not bound. | ||
303 | * @return a stream of matches represented as a Match object. | ||
304 | * | ||
305 | */ | ||
306 | public Stream<CreateHostInstance.Match> streamAllMatches(final HostType pHostType) { | ||
307 | return rawStreamAllMatches(new Object[]{pHostType}); | ||
308 | } | ||
309 | |||
310 | /** | ||
311 | * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
312 | * Neither determinism nor randomness of selection is guaranteed. | ||
313 | * @param pHostType the fixed value of pattern parameter HostType, or null if not bound. | ||
314 | * @return a match represented as a Match object, or null if no match is found. | ||
315 | * | ||
316 | */ | ||
317 | public Optional<CreateHostInstance.Match> getOneArbitraryMatch(final HostType pHostType) { | ||
318 | return rawGetOneArbitraryMatch(new Object[]{pHostType}); | ||
319 | } | ||
320 | |||
321 | /** | ||
322 | * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, | ||
323 | * under any possible substitution of the unspecified parameters (if any). | ||
324 | * @param pHostType the fixed value of pattern parameter HostType, or null if not bound. | ||
325 | * @return true if the input is a valid (partial) match of the pattern. | ||
326 | * | ||
327 | */ | ||
328 | public boolean hasMatch(final HostType pHostType) { | ||
329 | return rawHasMatch(new Object[]{pHostType}); | ||
330 | } | ||
331 | |||
332 | /** | ||
333 | * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. | ||
334 | * @param pHostType the fixed value of pattern parameter HostType, or null if not bound. | ||
335 | * @return the number of pattern matches found. | ||
336 | * | ||
337 | */ | ||
338 | public int countMatches(final HostType pHostType) { | ||
339 | return rawCountMatches(new Object[]{pHostType}); | ||
340 | } | ||
341 | |||
342 | /** | ||
343 | * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
344 | * Neither determinism nor randomness of selection is guaranteed. | ||
345 | * @param pHostType the fixed value of pattern parameter HostType, or null if not bound. | ||
346 | * @param processor the action that will process the selected match. | ||
347 | * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked | ||
348 | * | ||
349 | */ | ||
350 | public boolean forOneArbitraryMatch(final HostType pHostType, final Consumer<? super CreateHostInstance.Match> processor) { | ||
351 | return rawForOneArbitraryMatch(new Object[]{pHostType}, processor); | ||
352 | } | ||
353 | |||
354 | /** | ||
355 | * Returns a new (partial) match. | ||
356 | * This can be used e.g. to call the matcher with a partial match. | ||
357 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
358 | * @param pHostType the fixed value of pattern parameter HostType, or null if not bound. | ||
359 | * @return the (partial) match object. | ||
360 | * | ||
361 | */ | ||
362 | public CreateHostInstance.Match newMatch(final HostType pHostType) { | ||
363 | return CreateHostInstance.Match.newMatch(pHostType); | ||
364 | } | ||
365 | |||
366 | /** | ||
367 | * Retrieve the set of values that occur in matches for HostType. | ||
368 | * @return the Set of all values or empty set if there are no matches | ||
369 | * | ||
370 | */ | ||
371 | protected Stream<HostType> rawStreamAllValuesOfHostType(final Object[] parameters) { | ||
372 | return rawStreamAllValues(POSITION_HOSTTYPE, parameters).map(HostType.class::cast); | ||
373 | } | ||
374 | |||
375 | /** | ||
376 | * Retrieve the set of values that occur in matches for HostType. | ||
377 | * @return the Set of all values or empty set if there are no matches | ||
378 | * | ||
379 | */ | ||
380 | public Set<HostType> getAllValuesOfHostType() { | ||
381 | return rawStreamAllValuesOfHostType(emptyArray()).collect(Collectors.toSet()); | ||
382 | } | ||
383 | |||
384 | /** | ||
385 | * Retrieve the set of values that occur in matches for HostType. | ||
386 | * @return the Set of all values or empty set if there are no matches | ||
387 | * | ||
388 | */ | ||
389 | public Stream<HostType> streamAllValuesOfHostType() { | ||
390 | return rawStreamAllValuesOfHostType(emptyArray()); | ||
391 | } | ||
392 | |||
393 | @Override | ||
394 | protected CreateHostInstance.Match tupleToMatch(final Tuple t) { | ||
395 | try { | ||
396 | return CreateHostInstance.Match.newMatch((HostType) t.get(POSITION_HOSTTYPE)); | ||
397 | } catch(ClassCastException e) { | ||
398 | LOGGER.error("Element(s) in tuple not properly typed!",e); | ||
399 | return null; | ||
400 | } | ||
401 | } | ||
402 | |||
403 | @Override | ||
404 | protected CreateHostInstance.Match arrayToMatch(final Object[] match) { | ||
405 | try { | ||
406 | return CreateHostInstance.Match.newMatch((HostType) match[POSITION_HOSTTYPE]); | ||
407 | } catch(ClassCastException e) { | ||
408 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
409 | return null; | ||
410 | } | ||
411 | } | ||
412 | |||
413 | @Override | ||
414 | protected CreateHostInstance.Match arrayToMatchMutable(final Object[] match) { | ||
415 | try { | ||
416 | return CreateHostInstance.Match.newMutableMatch((HostType) match[POSITION_HOSTTYPE]); | ||
417 | } catch(ClassCastException e) { | ||
418 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
419 | return null; | ||
420 | } | ||
421 | } | ||
422 | |||
423 | /** | ||
424 | * @return the singleton instance of the query specification of this pattern | ||
425 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
426 | * | ||
427 | */ | ||
428 | public static IQuerySpecification<CreateHostInstance.Matcher> querySpecification() { | ||
429 | return CreateHostInstance.instance(); | ||
430 | } | ||
431 | } | ||
432 | |||
433 | private CreateHostInstance() { | ||
434 | super(GeneratedPQuery.INSTANCE); | ||
435 | } | ||
436 | |||
437 | /** | ||
438 | * @return the singleton instance of the query specification | ||
439 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
440 | * | ||
441 | */ | ||
442 | public static CreateHostInstance instance() { | ||
443 | try{ | ||
444 | return LazyHolder.INSTANCE; | ||
445 | } catch (ExceptionInInitializerError err) { | ||
446 | throw processInitializerError(err); | ||
447 | } | ||
448 | } | ||
449 | |||
450 | @Override | ||
451 | protected CreateHostInstance.Matcher instantiate(final ViatraQueryEngine engine) { | ||
452 | return CreateHostInstance.Matcher.on(engine); | ||
453 | } | ||
454 | |||
455 | @Override | ||
456 | public CreateHostInstance.Matcher instantiate() { | ||
457 | return CreateHostInstance.Matcher.create(); | ||
458 | } | ||
459 | |||
460 | @Override | ||
461 | public CreateHostInstance.Match newEmptyMatch() { | ||
462 | return CreateHostInstance.Match.newEmptyMatch(); | ||
463 | } | ||
464 | |||
465 | @Override | ||
466 | public CreateHostInstance.Match newMatch(final Object... parameters) { | ||
467 | return CreateHostInstance.Match.newMatch((hu.bme.mit.inf.dslreasoner.domains.cps.HostType) parameters[0]); | ||
468 | } | ||
469 | |||
470 | /** | ||
471 | * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.CreateHostInstance (visibility: PUBLIC, simpleName: CreateHostInstance, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.CreateHostInstance, 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 | ||
472 | * <b>not</b> at the class load time of the outer class, | ||
473 | * but rather at the first call to {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.CreateHostInstance (visibility: PUBLIC, simpleName: CreateHostInstance, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.CreateHostInstance, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}. | ||
474 | * | ||
475 | * <p> This workaround is required e.g. to support recursion. | ||
476 | * | ||
477 | */ | ||
478 | private static class LazyHolder { | ||
479 | private static final CreateHostInstance INSTANCE = new CreateHostInstance(); | ||
480 | |||
481 | /** | ||
482 | * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned. | ||
483 | * This initialization order is required to support indirect recursion. | ||
484 | * | ||
485 | * <p> The static initializer is defined using a helper field to work around limitations of the code generator. | ||
486 | * | ||
487 | */ | ||
488 | private static final Object STATIC_INITIALIZER = ensureInitialized(); | ||
489 | |||
490 | public static Object ensureInitialized() { | ||
491 | INSTANCE.ensureInitializedInternal(); | ||
492 | return null; | ||
493 | } | ||
494 | } | ||
495 | |||
496 | private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { | ||
497 | private static final CreateHostInstance.GeneratedPQuery INSTANCE = new GeneratedPQuery(); | ||
498 | |||
499 | private final PParameter parameter_HostType = new PParameter("HostType", "hu.bme.mit.inf.dslreasoner.domains.cps.HostType", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "HostType")), PParameterDirection.INOUT); | ||
500 | |||
501 | private final List<PParameter> parameters = Arrays.asList(parameter_HostType); | ||
502 | |||
503 | private GeneratedPQuery() { | ||
504 | super(PVisibility.PUBLIC); | ||
505 | } | ||
506 | |||
507 | @Override | ||
508 | public String getFullyQualifiedName() { | ||
509 | return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.createHostInstance"; | ||
510 | } | ||
511 | |||
512 | @Override | ||
513 | public List<String> getParameterNames() { | ||
514 | return Arrays.asList("HostType"); | ||
515 | } | ||
516 | |||
517 | @Override | ||
518 | public List<PParameter> getParameters() { | ||
519 | return parameters; | ||
520 | } | ||
521 | |||
522 | @Override | ||
523 | public Set<PBody> doGetContainedBodies() { | ||
524 | setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); | ||
525 | Set<PBody> bodies = new LinkedHashSet<>(); | ||
526 | { | ||
527 | PBody body = new PBody(this); | ||
528 | PVariable var_HostType = body.getOrCreateVariableByName("HostType"); | ||
529 | PVariable var_App = body.getOrCreateVariableByName("App"); | ||
530 | new TypeConstraint(body, Tuples.flatTupleOf(var_HostType), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostType"))); | ||
531 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
532 | new ExportedParameter(body, var_HostType, parameter_HostType) | ||
533 | )); | ||
534 | // find unallocatedAppInstance(App) | ||
535 | new PositivePatternCall(body, Tuples.flatTupleOf(var_App), UnallocatedAppInstance.instance().getInternalQueryRepresentation()); | ||
536 | // ApplicationInstance.type.requirements.hostType(App, HostType) | ||
537 | new TypeConstraint(body, Tuples.flatTupleOf(var_App), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance"))); | ||
538 | PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); | ||
539 | new TypeConstraint(body, Tuples.flatTupleOf(var_App, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ApplicationInstance", "type"))); | ||
540 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationType"))); | ||
541 | PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); | ||
542 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ApplicationType", "requirements"))); | ||
543 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ResourceRequirement"))); | ||
544 | PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}"); | ||
545 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_, var__virtual_2_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ResourceRequirement", "hostType"))); | ||
546 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostType"))); | ||
547 | new Equality(body, var__virtual_2_, var_HostType); | ||
548 | bodies.add(body); | ||
549 | } | ||
550 | return bodies; | ||
551 | } | ||
552 | } | ||
553 | } | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/GuidanceObjective.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/GuidanceObjective.java new file mode 100644 index 00000000..cfed0c4b --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/GuidanceObjective.java | |||
@@ -0,0 +1,591 @@ | |||
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.queries.internal.NoHostToAllocateTo; | ||
7 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.RequiredAppInstances; | ||
8 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.UnallocatedAppInstance; | ||
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.viatra.query.runtime.api.IPatternMatch; | ||
21 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification; | ||
22 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; | ||
23 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; | ||
24 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; | ||
25 | import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; | ||
26 | import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; | ||
27 | import org.eclipse.viatra.query.runtime.matchers.aggregators.sum; | ||
28 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
29 | import org.eclipse.viatra.query.runtime.matchers.context.common.JavaTransitiveInstancesKey; | ||
30 | import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator; | ||
31 | import org.eclipse.viatra.query.runtime.matchers.psystem.IValueProvider; | ||
32 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | ||
33 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | ||
34 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.AggregatorConstraint; | ||
35 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; | ||
36 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
37 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation; | ||
38 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.PatternMatchCounter; | ||
39 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.TypeFilterConstraint; | ||
40 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | ||
41 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; | ||
42 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | ||
43 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; | ||
44 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
45 | import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; | ||
46 | |||
47 | /** | ||
48 | * A pattern-specific query specification that can instantiate Matcher in a type-safe way. | ||
49 | * | ||
50 | * <p>Original source: | ||
51 | * <code><pre> | ||
52 | * pattern guidanceObjective(Value : java Integer) { | ||
53 | * UnallocatedInstances == count find unallocatedAppInstance(_); | ||
54 | * RequiredInstances == sum find requiredAppInstances(_, #_); | ||
55 | * NoHostToAllocate == count find noHostToAllocateTo(_); | ||
56 | * Value == eval(2 UnallocatedInstances + 4 RequiredInstances + NoHostToAllocate); | ||
57 | * } | ||
58 | * </pre></code> | ||
59 | * | ||
60 | * @see Matcher | ||
61 | * @see Match | ||
62 | * | ||
63 | */ | ||
64 | @SuppressWarnings("all") | ||
65 | public final class GuidanceObjective extends BaseGeneratedEMFQuerySpecification<GuidanceObjective.Matcher> { | ||
66 | /** | ||
67 | * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.guidanceObjective pattern, | ||
68 | * to be used in conjunction with {@link Matcher}. | ||
69 | * | ||
70 | * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. | ||
71 | * Each instance is a (possibly partial) substitution of pattern parameters, | ||
72 | * usable to represent a match of the pattern in the result of a query, | ||
73 | * or to specify the bound (fixed) input parameters when issuing a query. | ||
74 | * | ||
75 | * @see Matcher | ||
76 | * | ||
77 | */ | ||
78 | public static abstract class Match extends BasePatternMatch { | ||
79 | private Integer fValue; | ||
80 | |||
81 | private static List<String> parameterNames = makeImmutableList("Value"); | ||
82 | |||
83 | private Match(final Integer pValue) { | ||
84 | this.fValue = pValue; | ||
85 | } | ||
86 | |||
87 | @Override | ||
88 | public Object get(final String parameterName) { | ||
89 | if ("Value".equals(parameterName)) return this.fValue; | ||
90 | return null; | ||
91 | } | ||
92 | |||
93 | public Integer getValue() { | ||
94 | return this.fValue; | ||
95 | } | ||
96 | |||
97 | @Override | ||
98 | public boolean set(final String parameterName, final Object newValue) { | ||
99 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
100 | if ("Value".equals(parameterName) ) { | ||
101 | this.fValue = (Integer) newValue; | ||
102 | return true; | ||
103 | } | ||
104 | return false; | ||
105 | } | ||
106 | |||
107 | public void setValue(final Integer pValue) { | ||
108 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
109 | this.fValue = pValue; | ||
110 | } | ||
111 | |||
112 | @Override | ||
113 | public String patternName() { | ||
114 | return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.guidanceObjective"; | ||
115 | } | ||
116 | |||
117 | @Override | ||
118 | public List<String> parameterNames() { | ||
119 | return GuidanceObjective.Match.parameterNames; | ||
120 | } | ||
121 | |||
122 | @Override | ||
123 | public Object[] toArray() { | ||
124 | return new Object[]{fValue}; | ||
125 | } | ||
126 | |||
127 | @Override | ||
128 | public GuidanceObjective.Match toImmutable() { | ||
129 | return isMutable() ? newMatch(fValue) : this; | ||
130 | } | ||
131 | |||
132 | @Override | ||
133 | public String prettyPrint() { | ||
134 | StringBuilder result = new StringBuilder(); | ||
135 | result.append("\"Value\"=" + prettyPrintValue(fValue)); | ||
136 | return result.toString(); | ||
137 | } | ||
138 | |||
139 | @Override | ||
140 | public int hashCode() { | ||
141 | return Objects.hash(fValue); | ||
142 | } | ||
143 | |||
144 | @Override | ||
145 | public boolean equals(final Object obj) { | ||
146 | if (this == obj) | ||
147 | return true; | ||
148 | if (obj == null) { | ||
149 | return false; | ||
150 | } | ||
151 | if ((obj instanceof GuidanceObjective.Match)) { | ||
152 | GuidanceObjective.Match other = (GuidanceObjective.Match) obj; | ||
153 | return Objects.equals(fValue, other.fValue); | ||
154 | } else { | ||
155 | // this should be infrequent | ||
156 | if (!(obj instanceof IPatternMatch)) { | ||
157 | return false; | ||
158 | } | ||
159 | IPatternMatch otherSig = (IPatternMatch) obj; | ||
160 | return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); | ||
161 | } | ||
162 | } | ||
163 | |||
164 | @Override | ||
165 | public GuidanceObjective specification() { | ||
166 | return GuidanceObjective.instance(); | ||
167 | } | ||
168 | |||
169 | /** | ||
170 | * Returns an empty, mutable match. | ||
171 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
172 | * | ||
173 | * @return the empty match. | ||
174 | * | ||
175 | */ | ||
176 | public static GuidanceObjective.Match newEmptyMatch() { | ||
177 | return new Mutable(null); | ||
178 | } | ||
179 | |||
180 | /** | ||
181 | * Returns a mutable (partial) match. | ||
182 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
183 | * | ||
184 | * @param pValue the fixed value of pattern parameter Value, or null if not bound. | ||
185 | * @return the new, mutable (partial) match object. | ||
186 | * | ||
187 | */ | ||
188 | public static GuidanceObjective.Match newMutableMatch(final Integer pValue) { | ||
189 | return new Mutable(pValue); | ||
190 | } | ||
191 | |||
192 | /** | ||
193 | * Returns a new (partial) match. | ||
194 | * This can be used e.g. to call the matcher with a partial match. | ||
195 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
196 | * @param pValue the fixed value of pattern parameter Value, or null if not bound. | ||
197 | * @return the (partial) match object. | ||
198 | * | ||
199 | */ | ||
200 | public static GuidanceObjective.Match newMatch(final Integer pValue) { | ||
201 | return new Immutable(pValue); | ||
202 | } | ||
203 | |||
204 | private static final class Mutable extends GuidanceObjective.Match { | ||
205 | Mutable(final Integer pValue) { | ||
206 | super(pValue); | ||
207 | } | ||
208 | |||
209 | @Override | ||
210 | public boolean isMutable() { | ||
211 | return true; | ||
212 | } | ||
213 | } | ||
214 | |||
215 | private static final class Immutable extends GuidanceObjective.Match { | ||
216 | Immutable(final Integer pValue) { | ||
217 | super(pValue); | ||
218 | } | ||
219 | |||
220 | @Override | ||
221 | public boolean isMutable() { | ||
222 | return false; | ||
223 | } | ||
224 | } | ||
225 | } | ||
226 | |||
227 | /** | ||
228 | * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.guidanceObjective pattern, | ||
229 | * providing pattern-specific query methods. | ||
230 | * | ||
231 | * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, | ||
232 | * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. | ||
233 | * | ||
234 | * <p>Matches of the pattern will be represented as {@link Match}. | ||
235 | * | ||
236 | * <p>Original source: | ||
237 | * <code><pre> | ||
238 | * pattern guidanceObjective(Value : java Integer) { | ||
239 | * UnallocatedInstances == count find unallocatedAppInstance(_); | ||
240 | * RequiredInstances == sum find requiredAppInstances(_, #_); | ||
241 | * NoHostToAllocate == count find noHostToAllocateTo(_); | ||
242 | * Value == eval(2 UnallocatedInstances + 4 RequiredInstances + NoHostToAllocate); | ||
243 | * } | ||
244 | * </pre></code> | ||
245 | * | ||
246 | * @see Match | ||
247 | * @see GuidanceObjective | ||
248 | * | ||
249 | */ | ||
250 | public static class Matcher extends BaseMatcher<GuidanceObjective.Match> { | ||
251 | /** | ||
252 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
253 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
254 | * | ||
255 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
256 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
257 | * | ||
258 | */ | ||
259 | public static GuidanceObjective.Matcher on(final ViatraQueryEngine engine) { | ||
260 | // check if matcher already exists | ||
261 | Matcher matcher = engine.getExistingMatcher(querySpecification()); | ||
262 | if (matcher == null) { | ||
263 | matcher = (Matcher)engine.getMatcher(querySpecification()); | ||
264 | } | ||
265 | return matcher; | ||
266 | } | ||
267 | |||
268 | /** | ||
269 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
270 | * @return an initialized matcher | ||
271 | * @noreference This method is for internal matcher initialization by the framework, do not call it manually. | ||
272 | * | ||
273 | */ | ||
274 | public static GuidanceObjective.Matcher create() { | ||
275 | return new Matcher(); | ||
276 | } | ||
277 | |||
278 | private static final int POSITION_VALUE = 0; | ||
279 | |||
280 | private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(GuidanceObjective.Matcher.class); | ||
281 | |||
282 | /** | ||
283 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
284 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
285 | * | ||
286 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
287 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
288 | * | ||
289 | */ | ||
290 | private Matcher() { | ||
291 | super(querySpecification()); | ||
292 | } | ||
293 | |||
294 | /** | ||
295 | * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. | ||
296 | * @param pValue the fixed value of pattern parameter Value, or null if not bound. | ||
297 | * @return matches represented as a Match object. | ||
298 | * | ||
299 | */ | ||
300 | public Collection<GuidanceObjective.Match> getAllMatches(final Integer pValue) { | ||
301 | return rawStreamAllMatches(new Object[]{pValue}).collect(Collectors.toSet()); | ||
302 | } | ||
303 | |||
304 | /** | ||
305 | * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. | ||
306 | * </p> | ||
307 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
308 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
309 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
310 | * @param pValue the fixed value of pattern parameter Value, or null if not bound. | ||
311 | * @return a stream of matches represented as a Match object. | ||
312 | * | ||
313 | */ | ||
314 | public Stream<GuidanceObjective.Match> streamAllMatches(final Integer pValue) { | ||
315 | return rawStreamAllMatches(new Object[]{pValue}); | ||
316 | } | ||
317 | |||
318 | /** | ||
319 | * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
320 | * Neither determinism nor randomness of selection is guaranteed. | ||
321 | * @param pValue the fixed value of pattern parameter Value, or null if not bound. | ||
322 | * @return a match represented as a Match object, or null if no match is found. | ||
323 | * | ||
324 | */ | ||
325 | public Optional<GuidanceObjective.Match> getOneArbitraryMatch(final Integer pValue) { | ||
326 | return rawGetOneArbitraryMatch(new Object[]{pValue}); | ||
327 | } | ||
328 | |||
329 | /** | ||
330 | * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, | ||
331 | * under any possible substitution of the unspecified parameters (if any). | ||
332 | * @param pValue the fixed value of pattern parameter Value, or null if not bound. | ||
333 | * @return true if the input is a valid (partial) match of the pattern. | ||
334 | * | ||
335 | */ | ||
336 | public boolean hasMatch(final Integer pValue) { | ||
337 | return rawHasMatch(new Object[]{pValue}); | ||
338 | } | ||
339 | |||
340 | /** | ||
341 | * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. | ||
342 | * @param pValue the fixed value of pattern parameter Value, or null if not bound. | ||
343 | * @return the number of pattern matches found. | ||
344 | * | ||
345 | */ | ||
346 | public int countMatches(final Integer pValue) { | ||
347 | return rawCountMatches(new Object[]{pValue}); | ||
348 | } | ||
349 | |||
350 | /** | ||
351 | * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
352 | * Neither determinism nor randomness of selection is guaranteed. | ||
353 | * @param pValue the fixed value of pattern parameter Value, or null if not bound. | ||
354 | * @param processor the action that will process the selected match. | ||
355 | * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked | ||
356 | * | ||
357 | */ | ||
358 | public boolean forOneArbitraryMatch(final Integer pValue, final Consumer<? super GuidanceObjective.Match> processor) { | ||
359 | return rawForOneArbitraryMatch(new Object[]{pValue}, processor); | ||
360 | } | ||
361 | |||
362 | /** | ||
363 | * Returns a new (partial) match. | ||
364 | * This can be used e.g. to call the matcher with a partial match. | ||
365 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
366 | * @param pValue the fixed value of pattern parameter Value, or null if not bound. | ||
367 | * @return the (partial) match object. | ||
368 | * | ||
369 | */ | ||
370 | public GuidanceObjective.Match newMatch(final Integer pValue) { | ||
371 | return GuidanceObjective.Match.newMatch(pValue); | ||
372 | } | ||
373 | |||
374 | /** | ||
375 | * Retrieve the set of values that occur in matches for Value. | ||
376 | * @return the Set of all values or empty set if there are no matches | ||
377 | * | ||
378 | */ | ||
379 | protected Stream<Integer> rawStreamAllValuesOfValue(final Object[] parameters) { | ||
380 | return rawStreamAllValues(POSITION_VALUE, parameters).map(Integer.class::cast); | ||
381 | } | ||
382 | |||
383 | /** | ||
384 | * Retrieve the set of values that occur in matches for Value. | ||
385 | * @return the Set of all values or empty set if there are no matches | ||
386 | * | ||
387 | */ | ||
388 | public Set<Integer> getAllValuesOfValue() { | ||
389 | return rawStreamAllValuesOfValue(emptyArray()).collect(Collectors.toSet()); | ||
390 | } | ||
391 | |||
392 | /** | ||
393 | * Retrieve the set of values that occur in matches for Value. | ||
394 | * @return the Set of all values or empty set if there are no matches | ||
395 | * | ||
396 | */ | ||
397 | public Stream<Integer> streamAllValuesOfValue() { | ||
398 | return rawStreamAllValuesOfValue(emptyArray()); | ||
399 | } | ||
400 | |||
401 | @Override | ||
402 | protected GuidanceObjective.Match tupleToMatch(final Tuple t) { | ||
403 | try { | ||
404 | return GuidanceObjective.Match.newMatch((Integer) t.get(POSITION_VALUE)); | ||
405 | } catch(ClassCastException e) { | ||
406 | LOGGER.error("Element(s) in tuple not properly typed!",e); | ||
407 | return null; | ||
408 | } | ||
409 | } | ||
410 | |||
411 | @Override | ||
412 | protected GuidanceObjective.Match arrayToMatch(final Object[] match) { | ||
413 | try { | ||
414 | return GuidanceObjective.Match.newMatch((Integer) match[POSITION_VALUE]); | ||
415 | } catch(ClassCastException e) { | ||
416 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
417 | return null; | ||
418 | } | ||
419 | } | ||
420 | |||
421 | @Override | ||
422 | protected GuidanceObjective.Match arrayToMatchMutable(final Object[] match) { | ||
423 | try { | ||
424 | return GuidanceObjective.Match.newMutableMatch((Integer) match[POSITION_VALUE]); | ||
425 | } catch(ClassCastException e) { | ||
426 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
427 | return null; | ||
428 | } | ||
429 | } | ||
430 | |||
431 | /** | ||
432 | * @return the singleton instance of the query specification of this pattern | ||
433 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
434 | * | ||
435 | */ | ||
436 | public static IQuerySpecification<GuidanceObjective.Matcher> querySpecification() { | ||
437 | return GuidanceObjective.instance(); | ||
438 | } | ||
439 | } | ||
440 | |||
441 | private GuidanceObjective() { | ||
442 | super(GeneratedPQuery.INSTANCE); | ||
443 | } | ||
444 | |||
445 | /** | ||
446 | * @return the singleton instance of the query specification | ||
447 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
448 | * | ||
449 | */ | ||
450 | public static GuidanceObjective instance() { | ||
451 | try{ | ||
452 | return LazyHolder.INSTANCE; | ||
453 | } catch (ExceptionInInitializerError err) { | ||
454 | throw processInitializerError(err); | ||
455 | } | ||
456 | } | ||
457 | |||
458 | @Override | ||
459 | protected GuidanceObjective.Matcher instantiate(final ViatraQueryEngine engine) { | ||
460 | return GuidanceObjective.Matcher.on(engine); | ||
461 | } | ||
462 | |||
463 | @Override | ||
464 | public GuidanceObjective.Matcher instantiate() { | ||
465 | return GuidanceObjective.Matcher.create(); | ||
466 | } | ||
467 | |||
468 | @Override | ||
469 | public GuidanceObjective.Match newEmptyMatch() { | ||
470 | return GuidanceObjective.Match.newEmptyMatch(); | ||
471 | } | ||
472 | |||
473 | @Override | ||
474 | public GuidanceObjective.Match newMatch(final Object... parameters) { | ||
475 | return GuidanceObjective.Match.newMatch((java.lang.Integer) parameters[0]); | ||
476 | } | ||
477 | |||
478 | /** | ||
479 | * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.GuidanceObjective (visibility: PUBLIC, simpleName: GuidanceObjective, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.GuidanceObjective, 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 | ||
480 | * <b>not</b> at the class load time of the outer class, | ||
481 | * but rather at the first call to {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.GuidanceObjective (visibility: PUBLIC, simpleName: GuidanceObjective, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.GuidanceObjective, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}. | ||
482 | * | ||
483 | * <p> This workaround is required e.g. to support recursion. | ||
484 | * | ||
485 | */ | ||
486 | private static class LazyHolder { | ||
487 | private static final GuidanceObjective INSTANCE = new GuidanceObjective(); | ||
488 | |||
489 | /** | ||
490 | * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned. | ||
491 | * This initialization order is required to support indirect recursion. | ||
492 | * | ||
493 | * <p> The static initializer is defined using a helper field to work around limitations of the code generator. | ||
494 | * | ||
495 | */ | ||
496 | private static final Object STATIC_INITIALIZER = ensureInitialized(); | ||
497 | |||
498 | public static Object ensureInitialized() { | ||
499 | INSTANCE.ensureInitializedInternal(); | ||
500 | return null; | ||
501 | } | ||
502 | } | ||
503 | |||
504 | private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { | ||
505 | private static final GuidanceObjective.GeneratedPQuery INSTANCE = new GeneratedPQuery(); | ||
506 | |||
507 | private final PParameter parameter_Value = new PParameter("Value", "java.lang.Integer", new JavaTransitiveInstancesKey(java.lang.Integer.class), PParameterDirection.INOUT); | ||
508 | |||
509 | private final List<PParameter> parameters = Arrays.asList(parameter_Value); | ||
510 | |||
511 | private GeneratedPQuery() { | ||
512 | super(PVisibility.PUBLIC); | ||
513 | } | ||
514 | |||
515 | @Override | ||
516 | public String getFullyQualifiedName() { | ||
517 | return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.guidanceObjective"; | ||
518 | } | ||
519 | |||
520 | @Override | ||
521 | public List<String> getParameterNames() { | ||
522 | return Arrays.asList("Value"); | ||
523 | } | ||
524 | |||
525 | @Override | ||
526 | public List<PParameter> getParameters() { | ||
527 | return parameters; | ||
528 | } | ||
529 | |||
530 | @Override | ||
531 | public Set<PBody> doGetContainedBodies() { | ||
532 | setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); | ||
533 | Set<PBody> bodies = new LinkedHashSet<>(); | ||
534 | { | ||
535 | PBody body = new PBody(this); | ||
536 | PVariable var_Value = body.getOrCreateVariableByName("Value"); | ||
537 | PVariable var_UnallocatedInstances = body.getOrCreateVariableByName("UnallocatedInstances"); | ||
538 | PVariable var___0_ = body.getOrCreateVariableByName("_<0>"); | ||
539 | PVariable var_RequiredInstances = body.getOrCreateVariableByName("RequiredInstances"); | ||
540 | PVariable var___1_ = body.getOrCreateVariableByName("_<1>"); | ||
541 | PVariable var___2_ = body.getOrCreateVariableByName("_<2>"); | ||
542 | PVariable var_NoHostToAllocate = body.getOrCreateVariableByName("NoHostToAllocate"); | ||
543 | PVariable var___3_ = body.getOrCreateVariableByName("_<3>"); | ||
544 | new TypeFilterConstraint(body, Tuples.flatTupleOf(var_Value), new JavaTransitiveInstancesKey(java.lang.Integer.class)); | ||
545 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
546 | new ExportedParameter(body, var_Value, parameter_Value) | ||
547 | )); | ||
548 | // UnallocatedInstances == count find unallocatedAppInstance(_) | ||
549 | PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); | ||
550 | new PatternMatchCounter(body, Tuples.flatTupleOf(var___0_), UnallocatedAppInstance.instance().getInternalQueryRepresentation(), var__virtual_0_); | ||
551 | new Equality(body, var_UnallocatedInstances, var__virtual_0_); | ||
552 | // RequiredInstances == sum find requiredAppInstances(_, #_) | ||
553 | PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); | ||
554 | new AggregatorConstraint(new sum().getAggregatorLogic(Integer.class), body, Tuples.flatTupleOf(var___1_, var___2_), RequiredAppInstances.instance().getInternalQueryRepresentation(), var__virtual_1_, 1); | ||
555 | new Equality(body, var_RequiredInstances, var__virtual_1_); | ||
556 | // NoHostToAllocate == count find noHostToAllocateTo(_) | ||
557 | PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}"); | ||
558 | new PatternMatchCounter(body, Tuples.flatTupleOf(var___3_), NoHostToAllocateTo.instance().getInternalQueryRepresentation(), var__virtual_2_); | ||
559 | new Equality(body, var_NoHostToAllocate, var__virtual_2_); | ||
560 | // Value == eval(2 * UnallocatedInstances + 4 * RequiredInstances + NoHostToAllocate) | ||
561 | PVariable var__virtual_3_ = body.getOrCreateVariableByName(".virtual{3}"); | ||
562 | new ExpressionEvaluation(body, new IExpressionEvaluator() { | ||
563 | |||
564 | @Override | ||
565 | public String getShortDescription() { | ||
566 | return "Expression evaluation from pattern guidanceObjective"; | ||
567 | } | ||
568 | |||
569 | @Override | ||
570 | public Iterable<String> getInputParameterNames() { | ||
571 | return Arrays.asList("NoHostToAllocate", "RequiredInstances", "UnallocatedInstances");} | ||
572 | |||
573 | @Override | ||
574 | public Object evaluateExpression(IValueProvider provider) throws Exception { | ||
575 | Integer NoHostToAllocate = (Integer) provider.getValue("NoHostToAllocate"); | ||
576 | Integer RequiredInstances = (Integer) provider.getValue("RequiredInstances"); | ||
577 | Integer UnallocatedInstances = (Integer) provider.getValue("UnallocatedInstances"); | ||
578 | return evaluateExpression_1_1(NoHostToAllocate, RequiredInstances, UnallocatedInstances); | ||
579 | } | ||
580 | }, var__virtual_3_ ); | ||
581 | new Equality(body, var_Value, var__virtual_3_); | ||
582 | bodies.add(body); | ||
583 | } | ||
584 | return bodies; | ||
585 | } | ||
586 | } | ||
587 | |||
588 | private static int evaluateExpression_1_1(final Integer NoHostToAllocate, final Integer RequiredInstances, final Integer UnallocatedInstances) { | ||
589 | return (((2 * (UnallocatedInstances).intValue()) + (4 * (RequiredInstances).intValue())) + (NoHostToAllocate).intValue()); | ||
590 | } | ||
591 | } | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/InstanceDoesNotSatisfyRequirement.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/InstanceDoesNotSatisfyRequirement.java new file mode 100644 index 00000000..14deb337 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/InstanceDoesNotSatisfyRequirement.java | |||
@@ -0,0 +1,716 @@ | |||
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.ApplicationInstance; | ||
7 | import hu.bme.mit.inf.dslreasoner.domains.cps.Requirement; | ||
8 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.SatisfyingInstance; | ||
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.emf.types.EStructuralFeatureInstancesKey; | ||
30 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
31 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | ||
32 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | ||
33 | import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation; | ||
34 | import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference; | ||
35 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; | ||
36 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
37 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.NegativePatternCall; | ||
38 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
39 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | ||
40 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; | ||
41 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | ||
42 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; | ||
43 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
44 | import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; | ||
45 | |||
46 | /** | ||
47 | * A pattern-specific query specification that can instantiate Matcher in a type-safe way. | ||
48 | * | ||
49 | * <p>Original source: | ||
50 | * <code><pre> | ||
51 | * {@literal @}Constraint(severity = "error", key = {Req, App}, | ||
52 | * message = "Requirement must be satisfied by the required application type.") | ||
53 | * pattern instanceDoesNotSatisfyRequirement(Req : Requirement, App : ApplicationInstance) { | ||
54 | * Requirement.instances(Req, App); | ||
55 | * neg find satisfyingInstance(Req, App); | ||
56 | * } | ||
57 | * </pre></code> | ||
58 | * | ||
59 | * @see Matcher | ||
60 | * @see Match | ||
61 | * | ||
62 | */ | ||
63 | @SuppressWarnings("all") | ||
64 | public final class InstanceDoesNotSatisfyRequirement extends BaseGeneratedEMFQuerySpecification<InstanceDoesNotSatisfyRequirement.Matcher> { | ||
65 | /** | ||
66 | * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.instanceDoesNotSatisfyRequirement pattern, | ||
67 | * to be used in conjunction with {@link Matcher}. | ||
68 | * | ||
69 | * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. | ||
70 | * Each instance is a (possibly partial) substitution of pattern parameters, | ||
71 | * usable to represent a match of the pattern in the result of a query, | ||
72 | * or to specify the bound (fixed) input parameters when issuing a query. | ||
73 | * | ||
74 | * @see Matcher | ||
75 | * | ||
76 | */ | ||
77 | public static abstract class Match extends BasePatternMatch { | ||
78 | private Requirement fReq; | ||
79 | |||
80 | private ApplicationInstance fApp; | ||
81 | |||
82 | private static List<String> parameterNames = makeImmutableList("Req", "App"); | ||
83 | |||
84 | private Match(final Requirement pReq, final ApplicationInstance pApp) { | ||
85 | this.fReq = pReq; | ||
86 | this.fApp = pApp; | ||
87 | } | ||
88 | |||
89 | @Override | ||
90 | public Object get(final String parameterName) { | ||
91 | if ("Req".equals(parameterName)) return this.fReq; | ||
92 | if ("App".equals(parameterName)) return this.fApp; | ||
93 | return null; | ||
94 | } | ||
95 | |||
96 | public Requirement getReq() { | ||
97 | return this.fReq; | ||
98 | } | ||
99 | |||
100 | public ApplicationInstance getApp() { | ||
101 | return this.fApp; | ||
102 | } | ||
103 | |||
104 | @Override | ||
105 | public boolean set(final String parameterName, final Object newValue) { | ||
106 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
107 | if ("Req".equals(parameterName) ) { | ||
108 | this.fReq = (Requirement) newValue; | ||
109 | return true; | ||
110 | } | ||
111 | if ("App".equals(parameterName) ) { | ||
112 | this.fApp = (ApplicationInstance) newValue; | ||
113 | return true; | ||
114 | } | ||
115 | return false; | ||
116 | } | ||
117 | |||
118 | public void setReq(final Requirement pReq) { | ||
119 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
120 | this.fReq = pReq; | ||
121 | } | ||
122 | |||
123 | public void setApp(final ApplicationInstance pApp) { | ||
124 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
125 | this.fApp = pApp; | ||
126 | } | ||
127 | |||
128 | @Override | ||
129 | public String patternName() { | ||
130 | return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.instanceDoesNotSatisfyRequirement"; | ||
131 | } | ||
132 | |||
133 | @Override | ||
134 | public List<String> parameterNames() { | ||
135 | return InstanceDoesNotSatisfyRequirement.Match.parameterNames; | ||
136 | } | ||
137 | |||
138 | @Override | ||
139 | public Object[] toArray() { | ||
140 | return new Object[]{fReq, fApp}; | ||
141 | } | ||
142 | |||
143 | @Override | ||
144 | public InstanceDoesNotSatisfyRequirement.Match toImmutable() { | ||
145 | return isMutable() ? newMatch(fReq, fApp) : this; | ||
146 | } | ||
147 | |||
148 | @Override | ||
149 | public String prettyPrint() { | ||
150 | StringBuilder result = new StringBuilder(); | ||
151 | result.append("\"Req\"=" + prettyPrintValue(fReq) + ", "); | ||
152 | result.append("\"App\"=" + prettyPrintValue(fApp)); | ||
153 | return result.toString(); | ||
154 | } | ||
155 | |||
156 | @Override | ||
157 | public int hashCode() { | ||
158 | return Objects.hash(fReq, fApp); | ||
159 | } | ||
160 | |||
161 | @Override | ||
162 | public boolean equals(final Object obj) { | ||
163 | if (this == obj) | ||
164 | return true; | ||
165 | if (obj == null) { | ||
166 | return false; | ||
167 | } | ||
168 | if ((obj instanceof InstanceDoesNotSatisfyRequirement.Match)) { | ||
169 | InstanceDoesNotSatisfyRequirement.Match other = (InstanceDoesNotSatisfyRequirement.Match) obj; | ||
170 | return Objects.equals(fReq, other.fReq) && Objects.equals(fApp, other.fApp); | ||
171 | } else { | ||
172 | // this should be infrequent | ||
173 | if (!(obj instanceof IPatternMatch)) { | ||
174 | return false; | ||
175 | } | ||
176 | IPatternMatch otherSig = (IPatternMatch) obj; | ||
177 | return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); | ||
178 | } | ||
179 | } | ||
180 | |||
181 | @Override | ||
182 | public InstanceDoesNotSatisfyRequirement specification() { | ||
183 | return InstanceDoesNotSatisfyRequirement.instance(); | ||
184 | } | ||
185 | |||
186 | /** | ||
187 | * Returns an empty, mutable match. | ||
188 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
189 | * | ||
190 | * @return the empty match. | ||
191 | * | ||
192 | */ | ||
193 | public static InstanceDoesNotSatisfyRequirement.Match newEmptyMatch() { | ||
194 | return new Mutable(null, null); | ||
195 | } | ||
196 | |||
197 | /** | ||
198 | * Returns a mutable (partial) match. | ||
199 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
200 | * | ||
201 | * @param pReq the fixed value of pattern parameter Req, or null if not bound. | ||
202 | * @param pApp the fixed value of pattern parameter App, or null if not bound. | ||
203 | * @return the new, mutable (partial) match object. | ||
204 | * | ||
205 | */ | ||
206 | public static InstanceDoesNotSatisfyRequirement.Match newMutableMatch(final Requirement pReq, final ApplicationInstance pApp) { | ||
207 | return new Mutable(pReq, pApp); | ||
208 | } | ||
209 | |||
210 | /** | ||
211 | * Returns a new (partial) match. | ||
212 | * This can be used e.g. to call the matcher with a partial match. | ||
213 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
214 | * @param pReq the fixed value of pattern parameter Req, or null if not bound. | ||
215 | * @param pApp the fixed value of pattern parameter App, or null if not bound. | ||
216 | * @return the (partial) match object. | ||
217 | * | ||
218 | */ | ||
219 | public static InstanceDoesNotSatisfyRequirement.Match newMatch(final Requirement pReq, final ApplicationInstance pApp) { | ||
220 | return new Immutable(pReq, pApp); | ||
221 | } | ||
222 | |||
223 | private static final class Mutable extends InstanceDoesNotSatisfyRequirement.Match { | ||
224 | Mutable(final Requirement pReq, final ApplicationInstance pApp) { | ||
225 | super(pReq, pApp); | ||
226 | } | ||
227 | |||
228 | @Override | ||
229 | public boolean isMutable() { | ||
230 | return true; | ||
231 | } | ||
232 | } | ||
233 | |||
234 | private static final class Immutable extends InstanceDoesNotSatisfyRequirement.Match { | ||
235 | Immutable(final Requirement pReq, final ApplicationInstance pApp) { | ||
236 | super(pReq, pApp); | ||
237 | } | ||
238 | |||
239 | @Override | ||
240 | public boolean isMutable() { | ||
241 | return false; | ||
242 | } | ||
243 | } | ||
244 | } | ||
245 | |||
246 | /** | ||
247 | * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.instanceDoesNotSatisfyRequirement pattern, | ||
248 | * providing pattern-specific query methods. | ||
249 | * | ||
250 | * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, | ||
251 | * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. | ||
252 | * | ||
253 | * <p>Matches of the pattern will be represented as {@link Match}. | ||
254 | * | ||
255 | * <p>Original source: | ||
256 | * <code><pre> | ||
257 | * {@literal @}Constraint(severity = "error", key = {Req, App}, | ||
258 | * message = "Requirement must be satisfied by the required application type.") | ||
259 | * pattern instanceDoesNotSatisfyRequirement(Req : Requirement, App : ApplicationInstance) { | ||
260 | * Requirement.instances(Req, App); | ||
261 | * neg find satisfyingInstance(Req, App); | ||
262 | * } | ||
263 | * </pre></code> | ||
264 | * | ||
265 | * @see Match | ||
266 | * @see InstanceDoesNotSatisfyRequirement | ||
267 | * | ||
268 | */ | ||
269 | public static class Matcher extends BaseMatcher<InstanceDoesNotSatisfyRequirement.Match> { | ||
270 | /** | ||
271 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
272 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
273 | * | ||
274 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
275 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
276 | * | ||
277 | */ | ||
278 | public static InstanceDoesNotSatisfyRequirement.Matcher on(final ViatraQueryEngine engine) { | ||
279 | // check if matcher already exists | ||
280 | Matcher matcher = engine.getExistingMatcher(querySpecification()); | ||
281 | if (matcher == null) { | ||
282 | matcher = (Matcher)engine.getMatcher(querySpecification()); | ||
283 | } | ||
284 | return matcher; | ||
285 | } | ||
286 | |||
287 | /** | ||
288 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
289 | * @return an initialized matcher | ||
290 | * @noreference This method is for internal matcher initialization by the framework, do not call it manually. | ||
291 | * | ||
292 | */ | ||
293 | public static InstanceDoesNotSatisfyRequirement.Matcher create() { | ||
294 | return new Matcher(); | ||
295 | } | ||
296 | |||
297 | private static final int POSITION_REQ = 0; | ||
298 | |||
299 | private static final int POSITION_APP = 1; | ||
300 | |||
301 | private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(InstanceDoesNotSatisfyRequirement.Matcher.class); | ||
302 | |||
303 | /** | ||
304 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
305 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
306 | * | ||
307 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
308 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
309 | * | ||
310 | */ | ||
311 | private Matcher() { | ||
312 | super(querySpecification()); | ||
313 | } | ||
314 | |||
315 | /** | ||
316 | * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. | ||
317 | * @param pReq the fixed value of pattern parameter Req, or null if not bound. | ||
318 | * @param pApp the fixed value of pattern parameter App, or null if not bound. | ||
319 | * @return matches represented as a Match object. | ||
320 | * | ||
321 | */ | ||
322 | public Collection<InstanceDoesNotSatisfyRequirement.Match> getAllMatches(final Requirement pReq, final ApplicationInstance pApp) { | ||
323 | return rawStreamAllMatches(new Object[]{pReq, pApp}).collect(Collectors.toSet()); | ||
324 | } | ||
325 | |||
326 | /** | ||
327 | * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. | ||
328 | * </p> | ||
329 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
330 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
331 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
332 | * @param pReq the fixed value of pattern parameter Req, or null if not bound. | ||
333 | * @param pApp the fixed value of pattern parameter App, or null if not bound. | ||
334 | * @return a stream of matches represented as a Match object. | ||
335 | * | ||
336 | */ | ||
337 | public Stream<InstanceDoesNotSatisfyRequirement.Match> streamAllMatches(final Requirement pReq, final ApplicationInstance pApp) { | ||
338 | return rawStreamAllMatches(new Object[]{pReq, pApp}); | ||
339 | } | ||
340 | |||
341 | /** | ||
342 | * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
343 | * Neither determinism nor randomness of selection is guaranteed. | ||
344 | * @param pReq the fixed value of pattern parameter Req, or null if not bound. | ||
345 | * @param pApp the fixed value of pattern parameter App, or null if not bound. | ||
346 | * @return a match represented as a Match object, or null if no match is found. | ||
347 | * | ||
348 | */ | ||
349 | public Optional<InstanceDoesNotSatisfyRequirement.Match> getOneArbitraryMatch(final Requirement pReq, final ApplicationInstance pApp) { | ||
350 | return rawGetOneArbitraryMatch(new Object[]{pReq, pApp}); | ||
351 | } | ||
352 | |||
353 | /** | ||
354 | * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, | ||
355 | * under any possible substitution of the unspecified parameters (if any). | ||
356 | * @param pReq the fixed value of pattern parameter Req, or null if not bound. | ||
357 | * @param pApp the fixed value of pattern parameter App, or null if not bound. | ||
358 | * @return true if the input is a valid (partial) match of the pattern. | ||
359 | * | ||
360 | */ | ||
361 | public boolean hasMatch(final Requirement pReq, final ApplicationInstance pApp) { | ||
362 | return rawHasMatch(new Object[]{pReq, pApp}); | ||
363 | } | ||
364 | |||
365 | /** | ||
366 | * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. | ||
367 | * @param pReq the fixed value of pattern parameter Req, or null if not bound. | ||
368 | * @param pApp the fixed value of pattern parameter App, or null if not bound. | ||
369 | * @return the number of pattern matches found. | ||
370 | * | ||
371 | */ | ||
372 | public int countMatches(final Requirement pReq, final ApplicationInstance pApp) { | ||
373 | return rawCountMatches(new Object[]{pReq, pApp}); | ||
374 | } | ||
375 | |||
376 | /** | ||
377 | * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
378 | * Neither determinism nor randomness of selection is guaranteed. | ||
379 | * @param pReq the fixed value of pattern parameter Req, or null if not bound. | ||
380 | * @param pApp the fixed value of pattern parameter App, or null if not bound. | ||
381 | * @param processor the action that will process the selected match. | ||
382 | * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked | ||
383 | * | ||
384 | */ | ||
385 | public boolean forOneArbitraryMatch(final Requirement pReq, final ApplicationInstance pApp, final Consumer<? super InstanceDoesNotSatisfyRequirement.Match> processor) { | ||
386 | return rawForOneArbitraryMatch(new Object[]{pReq, pApp}, processor); | ||
387 | } | ||
388 | |||
389 | /** | ||
390 | * Returns a new (partial) match. | ||
391 | * This can be used e.g. to call the matcher with a partial match. | ||
392 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
393 | * @param pReq the fixed value of pattern parameter Req, or null if not bound. | ||
394 | * @param pApp the fixed value of pattern parameter App, or null if not bound. | ||
395 | * @return the (partial) match object. | ||
396 | * | ||
397 | */ | ||
398 | public InstanceDoesNotSatisfyRequirement.Match newMatch(final Requirement pReq, final ApplicationInstance pApp) { | ||
399 | return InstanceDoesNotSatisfyRequirement.Match.newMatch(pReq, pApp); | ||
400 | } | ||
401 | |||
402 | /** | ||
403 | * Retrieve the set of values that occur in matches for Req. | ||
404 | * @return the Set of all values or empty set if there are no matches | ||
405 | * | ||
406 | */ | ||
407 | protected Stream<Requirement> rawStreamAllValuesOfReq(final Object[] parameters) { | ||
408 | return rawStreamAllValues(POSITION_REQ, parameters).map(Requirement.class::cast); | ||
409 | } | ||
410 | |||
411 | /** | ||
412 | * Retrieve the set of values that occur in matches for Req. | ||
413 | * @return the Set of all values or empty set if there are no matches | ||
414 | * | ||
415 | */ | ||
416 | public Set<Requirement> getAllValuesOfReq() { | ||
417 | return rawStreamAllValuesOfReq(emptyArray()).collect(Collectors.toSet()); | ||
418 | } | ||
419 | |||
420 | /** | ||
421 | * Retrieve the set of values that occur in matches for Req. | ||
422 | * @return the Set of all values or empty set if there are no matches | ||
423 | * | ||
424 | */ | ||
425 | public Stream<Requirement> streamAllValuesOfReq() { | ||
426 | return rawStreamAllValuesOfReq(emptyArray()); | ||
427 | } | ||
428 | |||
429 | /** | ||
430 | * Retrieve the set of values that occur in matches for Req. | ||
431 | * </p> | ||
432 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
433 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
434 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
435 | * | ||
436 | * @return the Stream of all values or empty set if there are no matches | ||
437 | * | ||
438 | */ | ||
439 | public Stream<Requirement> streamAllValuesOfReq(final InstanceDoesNotSatisfyRequirement.Match partialMatch) { | ||
440 | return rawStreamAllValuesOfReq(partialMatch.toArray()); | ||
441 | } | ||
442 | |||
443 | /** | ||
444 | * Retrieve the set of values that occur in matches for Req. | ||
445 | * </p> | ||
446 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
447 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
448 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
449 | * | ||
450 | * @return the Stream of all values or empty set if there are no matches | ||
451 | * | ||
452 | */ | ||
453 | public Stream<Requirement> streamAllValuesOfReq(final ApplicationInstance pApp) { | ||
454 | return rawStreamAllValuesOfReq(new Object[]{null, pApp}); | ||
455 | } | ||
456 | |||
457 | /** | ||
458 | * Retrieve the set of values that occur in matches for Req. | ||
459 | * @return the Set of all values or empty set if there are no matches | ||
460 | * | ||
461 | */ | ||
462 | public Set<Requirement> getAllValuesOfReq(final InstanceDoesNotSatisfyRequirement.Match partialMatch) { | ||
463 | return rawStreamAllValuesOfReq(partialMatch.toArray()).collect(Collectors.toSet()); | ||
464 | } | ||
465 | |||
466 | /** | ||
467 | * Retrieve the set of values that occur in matches for Req. | ||
468 | * @return the Set of all values or empty set if there are no matches | ||
469 | * | ||
470 | */ | ||
471 | public Set<Requirement> getAllValuesOfReq(final ApplicationInstance pApp) { | ||
472 | return rawStreamAllValuesOfReq(new Object[]{null, pApp}).collect(Collectors.toSet()); | ||
473 | } | ||
474 | |||
475 | /** | ||
476 | * Retrieve the set of values that occur in matches for App. | ||
477 | * @return the Set of all values or empty set if there are no matches | ||
478 | * | ||
479 | */ | ||
480 | protected Stream<ApplicationInstance> rawStreamAllValuesOfApp(final Object[] parameters) { | ||
481 | return rawStreamAllValues(POSITION_APP, parameters).map(ApplicationInstance.class::cast); | ||
482 | } | ||
483 | |||
484 | /** | ||
485 | * Retrieve the set of values that occur in matches for App. | ||
486 | * @return the Set of all values or empty set if there are no matches | ||
487 | * | ||
488 | */ | ||
489 | public Set<ApplicationInstance> getAllValuesOfApp() { | ||
490 | return rawStreamAllValuesOfApp(emptyArray()).collect(Collectors.toSet()); | ||
491 | } | ||
492 | |||
493 | /** | ||
494 | * Retrieve the set of values that occur in matches for App. | ||
495 | * @return the Set of all values or empty set if there are no matches | ||
496 | * | ||
497 | */ | ||
498 | public Stream<ApplicationInstance> streamAllValuesOfApp() { | ||
499 | return rawStreamAllValuesOfApp(emptyArray()); | ||
500 | } | ||
501 | |||
502 | /** | ||
503 | * Retrieve the set of values that occur in matches for App. | ||
504 | * </p> | ||
505 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
506 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
507 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
508 | * | ||
509 | * @return the Stream of all values or empty set if there are no matches | ||
510 | * | ||
511 | */ | ||
512 | public Stream<ApplicationInstance> streamAllValuesOfApp(final InstanceDoesNotSatisfyRequirement.Match partialMatch) { | ||
513 | return rawStreamAllValuesOfApp(partialMatch.toArray()); | ||
514 | } | ||
515 | |||
516 | /** | ||
517 | * Retrieve the set of values that occur in matches for App. | ||
518 | * </p> | ||
519 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
520 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
521 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
522 | * | ||
523 | * @return the Stream of all values or empty set if there are no matches | ||
524 | * | ||
525 | */ | ||
526 | public Stream<ApplicationInstance> streamAllValuesOfApp(final Requirement pReq) { | ||
527 | return rawStreamAllValuesOfApp(new Object[]{pReq, null}); | ||
528 | } | ||
529 | |||
530 | /** | ||
531 | * Retrieve the set of values that occur in matches for App. | ||
532 | * @return the Set of all values or empty set if there are no matches | ||
533 | * | ||
534 | */ | ||
535 | public Set<ApplicationInstance> getAllValuesOfApp(final InstanceDoesNotSatisfyRequirement.Match partialMatch) { | ||
536 | return rawStreamAllValuesOfApp(partialMatch.toArray()).collect(Collectors.toSet()); | ||
537 | } | ||
538 | |||
539 | /** | ||
540 | * Retrieve the set of values that occur in matches for App. | ||
541 | * @return the Set of all values or empty set if there are no matches | ||
542 | * | ||
543 | */ | ||
544 | public Set<ApplicationInstance> getAllValuesOfApp(final Requirement pReq) { | ||
545 | return rawStreamAllValuesOfApp(new Object[]{pReq, null}).collect(Collectors.toSet()); | ||
546 | } | ||
547 | |||
548 | @Override | ||
549 | protected InstanceDoesNotSatisfyRequirement.Match tupleToMatch(final Tuple t) { | ||
550 | try { | ||
551 | return InstanceDoesNotSatisfyRequirement.Match.newMatch((Requirement) t.get(POSITION_REQ), (ApplicationInstance) t.get(POSITION_APP)); | ||
552 | } catch(ClassCastException e) { | ||
553 | LOGGER.error("Element(s) in tuple not properly typed!",e); | ||
554 | return null; | ||
555 | } | ||
556 | } | ||
557 | |||
558 | @Override | ||
559 | protected InstanceDoesNotSatisfyRequirement.Match arrayToMatch(final Object[] match) { | ||
560 | try { | ||
561 | return InstanceDoesNotSatisfyRequirement.Match.newMatch((Requirement) match[POSITION_REQ], (ApplicationInstance) match[POSITION_APP]); | ||
562 | } catch(ClassCastException e) { | ||
563 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
564 | return null; | ||
565 | } | ||
566 | } | ||
567 | |||
568 | @Override | ||
569 | protected InstanceDoesNotSatisfyRequirement.Match arrayToMatchMutable(final Object[] match) { | ||
570 | try { | ||
571 | return InstanceDoesNotSatisfyRequirement.Match.newMutableMatch((Requirement) match[POSITION_REQ], (ApplicationInstance) match[POSITION_APP]); | ||
572 | } catch(ClassCastException e) { | ||
573 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
574 | return null; | ||
575 | } | ||
576 | } | ||
577 | |||
578 | /** | ||
579 | * @return the singleton instance of the query specification of this pattern | ||
580 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
581 | * | ||
582 | */ | ||
583 | public static IQuerySpecification<InstanceDoesNotSatisfyRequirement.Matcher> querySpecification() { | ||
584 | return InstanceDoesNotSatisfyRequirement.instance(); | ||
585 | } | ||
586 | } | ||
587 | |||
588 | private InstanceDoesNotSatisfyRequirement() { | ||
589 | super(GeneratedPQuery.INSTANCE); | ||
590 | } | ||
591 | |||
592 | /** | ||
593 | * @return the singleton instance of the query specification | ||
594 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
595 | * | ||
596 | */ | ||
597 | public static InstanceDoesNotSatisfyRequirement instance() { | ||
598 | try{ | ||
599 | return LazyHolder.INSTANCE; | ||
600 | } catch (ExceptionInInitializerError err) { | ||
601 | throw processInitializerError(err); | ||
602 | } | ||
603 | } | ||
604 | |||
605 | @Override | ||
606 | protected InstanceDoesNotSatisfyRequirement.Matcher instantiate(final ViatraQueryEngine engine) { | ||
607 | return InstanceDoesNotSatisfyRequirement.Matcher.on(engine); | ||
608 | } | ||
609 | |||
610 | @Override | ||
611 | public InstanceDoesNotSatisfyRequirement.Matcher instantiate() { | ||
612 | return InstanceDoesNotSatisfyRequirement.Matcher.create(); | ||
613 | } | ||
614 | |||
615 | @Override | ||
616 | public InstanceDoesNotSatisfyRequirement.Match newEmptyMatch() { | ||
617 | return InstanceDoesNotSatisfyRequirement.Match.newEmptyMatch(); | ||
618 | } | ||
619 | |||
620 | @Override | ||
621 | public InstanceDoesNotSatisfyRequirement.Match newMatch(final Object... parameters) { | ||
622 | return InstanceDoesNotSatisfyRequirement.Match.newMatch((hu.bme.mit.inf.dslreasoner.domains.cps.Requirement) parameters[0], (hu.bme.mit.inf.dslreasoner.domains.cps.ApplicationInstance) parameters[1]); | ||
623 | } | ||
624 | |||
625 | /** | ||
626 | * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.InstanceDoesNotSatisfyRequirement (visibility: PUBLIC, simpleName: InstanceDoesNotSatisfyRequirement, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.InstanceDoesNotSatisfyRequirement, 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 | ||
627 | * <b>not</b> at the class load time of the outer class, | ||
628 | * but rather at the first call to {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.InstanceDoesNotSatisfyRequirement (visibility: PUBLIC, simpleName: InstanceDoesNotSatisfyRequirement, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.InstanceDoesNotSatisfyRequirement, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}. | ||
629 | * | ||
630 | * <p> This workaround is required e.g. to support recursion. | ||
631 | * | ||
632 | */ | ||
633 | private static class LazyHolder { | ||
634 | private static final InstanceDoesNotSatisfyRequirement INSTANCE = new InstanceDoesNotSatisfyRequirement(); | ||
635 | |||
636 | /** | ||
637 | * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned. | ||
638 | * This initialization order is required to support indirect recursion. | ||
639 | * | ||
640 | * <p> The static initializer is defined using a helper field to work around limitations of the code generator. | ||
641 | * | ||
642 | */ | ||
643 | private static final Object STATIC_INITIALIZER = ensureInitialized(); | ||
644 | |||
645 | public static Object ensureInitialized() { | ||
646 | INSTANCE.ensureInitializedInternal(); | ||
647 | return null; | ||
648 | } | ||
649 | } | ||
650 | |||
651 | private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { | ||
652 | private static final InstanceDoesNotSatisfyRequirement.GeneratedPQuery INSTANCE = new GeneratedPQuery(); | ||
653 | |||
654 | private final PParameter parameter_Req = new PParameter("Req", "hu.bme.mit.inf.dslreasoner.domains.cps.Requirement", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "Requirement")), PParameterDirection.INOUT); | ||
655 | |||
656 | 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); | ||
657 | |||
658 | private final List<PParameter> parameters = Arrays.asList(parameter_Req, parameter_App); | ||
659 | |||
660 | private GeneratedPQuery() { | ||
661 | super(PVisibility.PUBLIC); | ||
662 | } | ||
663 | |||
664 | @Override | ||
665 | public String getFullyQualifiedName() { | ||
666 | return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.instanceDoesNotSatisfyRequirement"; | ||
667 | } | ||
668 | |||
669 | @Override | ||
670 | public List<String> getParameterNames() { | ||
671 | return Arrays.asList("Req","App"); | ||
672 | } | ||
673 | |||
674 | @Override | ||
675 | public List<PParameter> getParameters() { | ||
676 | return parameters; | ||
677 | } | ||
678 | |||
679 | @Override | ||
680 | public Set<PBody> doGetContainedBodies() { | ||
681 | setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); | ||
682 | Set<PBody> bodies = new LinkedHashSet<>(); | ||
683 | { | ||
684 | PBody body = new PBody(this); | ||
685 | PVariable var_Req = body.getOrCreateVariableByName("Req"); | ||
686 | PVariable var_App = body.getOrCreateVariableByName("App"); | ||
687 | new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "Requirement"))); | ||
688 | new TypeConstraint(body, Tuples.flatTupleOf(var_App), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance"))); | ||
689 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
690 | new ExportedParameter(body, var_Req, parameter_Req), | ||
691 | new ExportedParameter(body, var_App, parameter_App) | ||
692 | )); | ||
693 | // Requirement.instances(Req, App) | ||
694 | new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "Requirement"))); | ||
695 | PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); | ||
696 | new TypeConstraint(body, Tuples.flatTupleOf(var_Req, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "Requirement", "instances"))); | ||
697 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance"))); | ||
698 | new Equality(body, var__virtual_0_, var_App); | ||
699 | // neg find satisfyingInstance(Req, App) | ||
700 | new NegativePatternCall(body, Tuples.flatTupleOf(var_Req, var_App), SatisfyingInstance.instance().getInternalQueryRepresentation()); | ||
701 | bodies.add(body); | ||
702 | } | ||
703 | { | ||
704 | PAnnotation annotation = new PAnnotation("Constraint"); | ||
705 | annotation.addAttribute("severity", "error"); | ||
706 | annotation.addAttribute("key", Arrays.asList(new Object[] { | ||
707 | new ParameterReference("Req"), | ||
708 | new ParameterReference("App") | ||
709 | })); | ||
710 | annotation.addAttribute("message", "Requirement must be satisfied by the required application type."); | ||
711 | addAnnotation(annotation); | ||
712 | } | ||
713 | return bodies; | ||
714 | } | ||
715 | } | ||
716 | } | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/NotEnoughAvailableHdd.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/NotEnoughAvailableHdd.java new file mode 100644 index 00000000..0c0d57a6 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/NotEnoughAvailableHdd.java | |||
@@ -0,0 +1,579 @@ | |||
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.HostInstance; | ||
7 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.AvailableHdd; | ||
8 | import java.util.Arrays; | ||
9 | import java.util.Collection; | ||
10 | import java.util.LinkedHashSet; | ||
11 | import java.util.List; | ||
12 | import java.util.Objects; | ||
13 | import java.util.Optional; | ||
14 | import java.util.Set; | ||
15 | import java.util.function.Consumer; | ||
16 | import java.util.stream.Collectors; | ||
17 | import java.util.stream.Stream; | ||
18 | import org.apache.log4j.Logger; | ||
19 | import org.eclipse.emf.ecore.EClass; | ||
20 | import org.eclipse.viatra.query.runtime.api.IPatternMatch; | ||
21 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification; | ||
22 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; | ||
23 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; | ||
24 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; | ||
25 | import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; | ||
26 | import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; | ||
27 | import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; | ||
28 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
29 | import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator; | ||
30 | import org.eclipse.viatra.query.runtime.matchers.psystem.IValueProvider; | ||
31 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | ||
32 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | ||
33 | import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation; | ||
34 | import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference; | ||
35 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
36 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation; | ||
37 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall; | ||
38 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
39 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | ||
40 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; | ||
41 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | ||
42 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; | ||
43 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
44 | import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; | ||
45 | |||
46 | /** | ||
47 | * A pattern-specific query specification that can instantiate Matcher in a type-safe way. | ||
48 | * | ||
49 | * <p>Original source: | ||
50 | * <code><pre> | ||
51 | * {@literal @}Constraint(severity = "error", key = {Host}, | ||
52 | * message = "Insufficient HDD available on host.") | ||
53 | * pattern notEnoughAvailableHdd(Host : HostInstance) { | ||
54 | * find availableHdd(Host, Hdd); | ||
55 | * check(Hdd {@literal <} 0); | ||
56 | * } | ||
57 | * </pre></code> | ||
58 | * | ||
59 | * @see Matcher | ||
60 | * @see Match | ||
61 | * | ||
62 | */ | ||
63 | @SuppressWarnings("all") | ||
64 | public final class NotEnoughAvailableHdd extends BaseGeneratedEMFQuerySpecification<NotEnoughAvailableHdd.Matcher> { | ||
65 | /** | ||
66 | * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.notEnoughAvailableHdd pattern, | ||
67 | * to be used in conjunction with {@link Matcher}. | ||
68 | * | ||
69 | * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. | ||
70 | * Each instance is a (possibly partial) substitution of pattern parameters, | ||
71 | * usable to represent a match of the pattern in the result of a query, | ||
72 | * or to specify the bound (fixed) input parameters when issuing a query. | ||
73 | * | ||
74 | * @see Matcher | ||
75 | * | ||
76 | */ | ||
77 | public static abstract class Match extends BasePatternMatch { | ||
78 | private HostInstance fHost; | ||
79 | |||
80 | private static List<String> parameterNames = makeImmutableList("Host"); | ||
81 | |||
82 | private Match(final HostInstance pHost) { | ||
83 | this.fHost = pHost; | ||
84 | } | ||
85 | |||
86 | @Override | ||
87 | public Object get(final String parameterName) { | ||
88 | if ("Host".equals(parameterName)) return this.fHost; | ||
89 | return null; | ||
90 | } | ||
91 | |||
92 | public HostInstance getHost() { | ||
93 | return this.fHost; | ||
94 | } | ||
95 | |||
96 | @Override | ||
97 | public boolean set(final String parameterName, final Object newValue) { | ||
98 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
99 | if ("Host".equals(parameterName) ) { | ||
100 | this.fHost = (HostInstance) newValue; | ||
101 | return true; | ||
102 | } | ||
103 | return false; | ||
104 | } | ||
105 | |||
106 | public void setHost(final HostInstance pHost) { | ||
107 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
108 | this.fHost = pHost; | ||
109 | } | ||
110 | |||
111 | @Override | ||
112 | public String patternName() { | ||
113 | return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.notEnoughAvailableHdd"; | ||
114 | } | ||
115 | |||
116 | @Override | ||
117 | public List<String> parameterNames() { | ||
118 | return NotEnoughAvailableHdd.Match.parameterNames; | ||
119 | } | ||
120 | |||
121 | @Override | ||
122 | public Object[] toArray() { | ||
123 | return new Object[]{fHost}; | ||
124 | } | ||
125 | |||
126 | @Override | ||
127 | public NotEnoughAvailableHdd.Match toImmutable() { | ||
128 | return isMutable() ? newMatch(fHost) : this; | ||
129 | } | ||
130 | |||
131 | @Override | ||
132 | public String prettyPrint() { | ||
133 | StringBuilder result = new StringBuilder(); | ||
134 | result.append("\"Host\"=" + prettyPrintValue(fHost)); | ||
135 | return result.toString(); | ||
136 | } | ||
137 | |||
138 | @Override | ||
139 | public int hashCode() { | ||
140 | return Objects.hash(fHost); | ||
141 | } | ||
142 | |||
143 | @Override | ||
144 | public boolean equals(final Object obj) { | ||
145 | if (this == obj) | ||
146 | return true; | ||
147 | if (obj == null) { | ||
148 | return false; | ||
149 | } | ||
150 | if ((obj instanceof NotEnoughAvailableHdd.Match)) { | ||
151 | NotEnoughAvailableHdd.Match other = (NotEnoughAvailableHdd.Match) obj; | ||
152 | return Objects.equals(fHost, other.fHost); | ||
153 | } else { | ||
154 | // this should be infrequent | ||
155 | if (!(obj instanceof IPatternMatch)) { | ||
156 | return false; | ||
157 | } | ||
158 | IPatternMatch otherSig = (IPatternMatch) obj; | ||
159 | return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); | ||
160 | } | ||
161 | } | ||
162 | |||
163 | @Override | ||
164 | public NotEnoughAvailableHdd specification() { | ||
165 | return NotEnoughAvailableHdd.instance(); | ||
166 | } | ||
167 | |||
168 | /** | ||
169 | * Returns an empty, mutable match. | ||
170 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
171 | * | ||
172 | * @return the empty match. | ||
173 | * | ||
174 | */ | ||
175 | public static NotEnoughAvailableHdd.Match newEmptyMatch() { | ||
176 | return new Mutable(null); | ||
177 | } | ||
178 | |||
179 | /** | ||
180 | * Returns a mutable (partial) match. | ||
181 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
182 | * | ||
183 | * @param pHost the fixed value of pattern parameter Host, or null if not bound. | ||
184 | * @return the new, mutable (partial) match object. | ||
185 | * | ||
186 | */ | ||
187 | public static NotEnoughAvailableHdd.Match newMutableMatch(final HostInstance pHost) { | ||
188 | return new Mutable(pHost); | ||
189 | } | ||
190 | |||
191 | /** | ||
192 | * Returns a new (partial) match. | ||
193 | * This can be used e.g. to call the matcher with a partial match. | ||
194 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
195 | * @param pHost the fixed value of pattern parameter Host, or null if not bound. | ||
196 | * @return the (partial) match object. | ||
197 | * | ||
198 | */ | ||
199 | public static NotEnoughAvailableHdd.Match newMatch(final HostInstance pHost) { | ||
200 | return new Immutable(pHost); | ||
201 | } | ||
202 | |||
203 | private static final class Mutable extends NotEnoughAvailableHdd.Match { | ||
204 | Mutable(final HostInstance pHost) { | ||
205 | super(pHost); | ||
206 | } | ||
207 | |||
208 | @Override | ||
209 | public boolean isMutable() { | ||
210 | return true; | ||
211 | } | ||
212 | } | ||
213 | |||
214 | private static final class Immutable extends NotEnoughAvailableHdd.Match { | ||
215 | Immutable(final HostInstance pHost) { | ||
216 | super(pHost); | ||
217 | } | ||
218 | |||
219 | @Override | ||
220 | public boolean isMutable() { | ||
221 | return false; | ||
222 | } | ||
223 | } | ||
224 | } | ||
225 | |||
226 | /** | ||
227 | * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.notEnoughAvailableHdd pattern, | ||
228 | * providing pattern-specific query methods. | ||
229 | * | ||
230 | * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, | ||
231 | * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. | ||
232 | * | ||
233 | * <p>Matches of the pattern will be represented as {@link Match}. | ||
234 | * | ||
235 | * <p>Original source: | ||
236 | * <code><pre> | ||
237 | * {@literal @}Constraint(severity = "error", key = {Host}, | ||
238 | * message = "Insufficient HDD available on host.") | ||
239 | * pattern notEnoughAvailableHdd(Host : HostInstance) { | ||
240 | * find availableHdd(Host, Hdd); | ||
241 | * check(Hdd {@literal <} 0); | ||
242 | * } | ||
243 | * </pre></code> | ||
244 | * | ||
245 | * @see Match | ||
246 | * @see NotEnoughAvailableHdd | ||
247 | * | ||
248 | */ | ||
249 | public static class Matcher extends BaseMatcher<NotEnoughAvailableHdd.Match> { | ||
250 | /** | ||
251 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
252 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
253 | * | ||
254 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
255 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
256 | * | ||
257 | */ | ||
258 | public static NotEnoughAvailableHdd.Matcher on(final ViatraQueryEngine engine) { | ||
259 | // check if matcher already exists | ||
260 | Matcher matcher = engine.getExistingMatcher(querySpecification()); | ||
261 | if (matcher == null) { | ||
262 | matcher = (Matcher)engine.getMatcher(querySpecification()); | ||
263 | } | ||
264 | return matcher; | ||
265 | } | ||
266 | |||
267 | /** | ||
268 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
269 | * @return an initialized matcher | ||
270 | * @noreference This method is for internal matcher initialization by the framework, do not call it manually. | ||
271 | * | ||
272 | */ | ||
273 | public static NotEnoughAvailableHdd.Matcher create() { | ||
274 | return new Matcher(); | ||
275 | } | ||
276 | |||
277 | private static final int POSITION_HOST = 0; | ||
278 | |||
279 | private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(NotEnoughAvailableHdd.Matcher.class); | ||
280 | |||
281 | /** | ||
282 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
283 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
284 | * | ||
285 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
286 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
287 | * | ||
288 | */ | ||
289 | private Matcher() { | ||
290 | super(querySpecification()); | ||
291 | } | ||
292 | |||
293 | /** | ||
294 | * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. | ||
295 | * @param pHost the fixed value of pattern parameter Host, or null if not bound. | ||
296 | * @return matches represented as a Match object. | ||
297 | * | ||
298 | */ | ||
299 | public Collection<NotEnoughAvailableHdd.Match> getAllMatches(final HostInstance pHost) { | ||
300 | return rawStreamAllMatches(new Object[]{pHost}).collect(Collectors.toSet()); | ||
301 | } | ||
302 | |||
303 | /** | ||
304 | * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. | ||
305 | * </p> | ||
306 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
307 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
308 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
309 | * @param pHost the fixed value of pattern parameter Host, or null if not bound. | ||
310 | * @return a stream of matches represented as a Match object. | ||
311 | * | ||
312 | */ | ||
313 | public Stream<NotEnoughAvailableHdd.Match> streamAllMatches(final HostInstance pHost) { | ||
314 | return rawStreamAllMatches(new Object[]{pHost}); | ||
315 | } | ||
316 | |||
317 | /** | ||
318 | * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
319 | * Neither determinism nor randomness of selection is guaranteed. | ||
320 | * @param pHost the fixed value of pattern parameter Host, or null if not bound. | ||
321 | * @return a match represented as a Match object, or null if no match is found. | ||
322 | * | ||
323 | */ | ||
324 | public Optional<NotEnoughAvailableHdd.Match> getOneArbitraryMatch(final HostInstance pHost) { | ||
325 | return rawGetOneArbitraryMatch(new Object[]{pHost}); | ||
326 | } | ||
327 | |||
328 | /** | ||
329 | * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, | ||
330 | * under any possible substitution of the unspecified parameters (if any). | ||
331 | * @param pHost the fixed value of pattern parameter Host, or null if not bound. | ||
332 | * @return true if the input is a valid (partial) match of the pattern. | ||
333 | * | ||
334 | */ | ||
335 | public boolean hasMatch(final HostInstance pHost) { | ||
336 | return rawHasMatch(new Object[]{pHost}); | ||
337 | } | ||
338 | |||
339 | /** | ||
340 | * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. | ||
341 | * @param pHost the fixed value of pattern parameter Host, or null if not bound. | ||
342 | * @return the number of pattern matches found. | ||
343 | * | ||
344 | */ | ||
345 | public int countMatches(final HostInstance pHost) { | ||
346 | return rawCountMatches(new Object[]{pHost}); | ||
347 | } | ||
348 | |||
349 | /** | ||
350 | * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
351 | * Neither determinism nor randomness of selection is guaranteed. | ||
352 | * @param pHost the fixed value of pattern parameter Host, or null if not bound. | ||
353 | * @param processor the action that will process the selected match. | ||
354 | * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked | ||
355 | * | ||
356 | */ | ||
357 | public boolean forOneArbitraryMatch(final HostInstance pHost, final Consumer<? super NotEnoughAvailableHdd.Match> processor) { | ||
358 | return rawForOneArbitraryMatch(new Object[]{pHost}, processor); | ||
359 | } | ||
360 | |||
361 | /** | ||
362 | * Returns a new (partial) match. | ||
363 | * This can be used e.g. to call the matcher with a partial match. | ||
364 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
365 | * @param pHost the fixed value of pattern parameter Host, or null if not bound. | ||
366 | * @return the (partial) match object. | ||
367 | * | ||
368 | */ | ||
369 | public NotEnoughAvailableHdd.Match newMatch(final HostInstance pHost) { | ||
370 | return NotEnoughAvailableHdd.Match.newMatch(pHost); | ||
371 | } | ||
372 | |||
373 | /** | ||
374 | * Retrieve the set of values that occur in matches for Host. | ||
375 | * @return the Set of all values or empty set if there are no matches | ||
376 | * | ||
377 | */ | ||
378 | protected Stream<HostInstance> rawStreamAllValuesOfHost(final Object[] parameters) { | ||
379 | return rawStreamAllValues(POSITION_HOST, parameters).map(HostInstance.class::cast); | ||
380 | } | ||
381 | |||
382 | /** | ||
383 | * Retrieve the set of values that occur in matches for Host. | ||
384 | * @return the Set of all values or empty set if there are no matches | ||
385 | * | ||
386 | */ | ||
387 | public Set<HostInstance> getAllValuesOfHost() { | ||
388 | return rawStreamAllValuesOfHost(emptyArray()).collect(Collectors.toSet()); | ||
389 | } | ||
390 | |||
391 | /** | ||
392 | * Retrieve the set of values that occur in matches for Host. | ||
393 | * @return the Set of all values or empty set if there are no matches | ||
394 | * | ||
395 | */ | ||
396 | public Stream<HostInstance> streamAllValuesOfHost() { | ||
397 | return rawStreamAllValuesOfHost(emptyArray()); | ||
398 | } | ||
399 | |||
400 | @Override | ||
401 | protected NotEnoughAvailableHdd.Match tupleToMatch(final Tuple t) { | ||
402 | try { | ||
403 | return NotEnoughAvailableHdd.Match.newMatch((HostInstance) t.get(POSITION_HOST)); | ||
404 | } catch(ClassCastException e) { | ||
405 | LOGGER.error("Element(s) in tuple not properly typed!",e); | ||
406 | return null; | ||
407 | } | ||
408 | } | ||
409 | |||
410 | @Override | ||
411 | protected NotEnoughAvailableHdd.Match arrayToMatch(final Object[] match) { | ||
412 | try { | ||
413 | return NotEnoughAvailableHdd.Match.newMatch((HostInstance) match[POSITION_HOST]); | ||
414 | } catch(ClassCastException e) { | ||
415 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
416 | return null; | ||
417 | } | ||
418 | } | ||
419 | |||
420 | @Override | ||
421 | protected NotEnoughAvailableHdd.Match arrayToMatchMutable(final Object[] match) { | ||
422 | try { | ||
423 | return NotEnoughAvailableHdd.Match.newMutableMatch((HostInstance) match[POSITION_HOST]); | ||
424 | } catch(ClassCastException e) { | ||
425 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
426 | return null; | ||
427 | } | ||
428 | } | ||
429 | |||
430 | /** | ||
431 | * @return the singleton instance of the query specification of this pattern | ||
432 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
433 | * | ||
434 | */ | ||
435 | public static IQuerySpecification<NotEnoughAvailableHdd.Matcher> querySpecification() { | ||
436 | return NotEnoughAvailableHdd.instance(); | ||
437 | } | ||
438 | } | ||
439 | |||
440 | private NotEnoughAvailableHdd() { | ||
441 | super(GeneratedPQuery.INSTANCE); | ||
442 | } | ||
443 | |||
444 | /** | ||
445 | * @return the singleton instance of the query specification | ||
446 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
447 | * | ||
448 | */ | ||
449 | public static NotEnoughAvailableHdd instance() { | ||
450 | try{ | ||
451 | return LazyHolder.INSTANCE; | ||
452 | } catch (ExceptionInInitializerError err) { | ||
453 | throw processInitializerError(err); | ||
454 | } | ||
455 | } | ||
456 | |||
457 | @Override | ||
458 | protected NotEnoughAvailableHdd.Matcher instantiate(final ViatraQueryEngine engine) { | ||
459 | return NotEnoughAvailableHdd.Matcher.on(engine); | ||
460 | } | ||
461 | |||
462 | @Override | ||
463 | public NotEnoughAvailableHdd.Matcher instantiate() { | ||
464 | return NotEnoughAvailableHdd.Matcher.create(); | ||
465 | } | ||
466 | |||
467 | @Override | ||
468 | public NotEnoughAvailableHdd.Match newEmptyMatch() { | ||
469 | return NotEnoughAvailableHdd.Match.newEmptyMatch(); | ||
470 | } | ||
471 | |||
472 | @Override | ||
473 | public NotEnoughAvailableHdd.Match newMatch(final Object... parameters) { | ||
474 | return NotEnoughAvailableHdd.Match.newMatch((hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance) parameters[0]); | ||
475 | } | ||
476 | |||
477 | /** | ||
478 | * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.NotEnoughAvailableHdd (visibility: PUBLIC, simpleName: NotEnoughAvailableHdd, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.NotEnoughAvailableHdd, 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 | ||
479 | * <b>not</b> at the class load time of the outer class, | ||
480 | * but rather at the first call to {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.NotEnoughAvailableHdd (visibility: PUBLIC, simpleName: NotEnoughAvailableHdd, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.NotEnoughAvailableHdd, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}. | ||
481 | * | ||
482 | * <p> This workaround is required e.g. to support recursion. | ||
483 | * | ||
484 | */ | ||
485 | private static class LazyHolder { | ||
486 | private static final NotEnoughAvailableHdd INSTANCE = new NotEnoughAvailableHdd(); | ||
487 | |||
488 | /** | ||
489 | * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned. | ||
490 | * This initialization order is required to support indirect recursion. | ||
491 | * | ||
492 | * <p> The static initializer is defined using a helper field to work around limitations of the code generator. | ||
493 | * | ||
494 | */ | ||
495 | private static final Object STATIC_INITIALIZER = ensureInitialized(); | ||
496 | |||
497 | public static Object ensureInitialized() { | ||
498 | INSTANCE.ensureInitializedInternal(); | ||
499 | return null; | ||
500 | } | ||
501 | } | ||
502 | |||
503 | private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { | ||
504 | private static final NotEnoughAvailableHdd.GeneratedPQuery INSTANCE = new GeneratedPQuery(); | ||
505 | |||
506 | 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); | ||
507 | |||
508 | private final List<PParameter> parameters = Arrays.asList(parameter_Host); | ||
509 | |||
510 | private GeneratedPQuery() { | ||
511 | super(PVisibility.PUBLIC); | ||
512 | } | ||
513 | |||
514 | @Override | ||
515 | public String getFullyQualifiedName() { | ||
516 | return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.notEnoughAvailableHdd"; | ||
517 | } | ||
518 | |||
519 | @Override | ||
520 | public List<String> getParameterNames() { | ||
521 | return Arrays.asList("Host"); | ||
522 | } | ||
523 | |||
524 | @Override | ||
525 | public List<PParameter> getParameters() { | ||
526 | return parameters; | ||
527 | } | ||
528 | |||
529 | @Override | ||
530 | public Set<PBody> doGetContainedBodies() { | ||
531 | setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); | ||
532 | Set<PBody> bodies = new LinkedHashSet<>(); | ||
533 | { | ||
534 | PBody body = new PBody(this); | ||
535 | PVariable var_Host = body.getOrCreateVariableByName("Host"); | ||
536 | PVariable var_Hdd = body.getOrCreateVariableByName("Hdd"); | ||
537 | new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); | ||
538 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
539 | new ExportedParameter(body, var_Host, parameter_Host) | ||
540 | )); | ||
541 | // find availableHdd(Host, Hdd) | ||
542 | new PositivePatternCall(body, Tuples.flatTupleOf(var_Host, var_Hdd), AvailableHdd.instance().getInternalQueryRepresentation()); | ||
543 | // check(Hdd < 0) | ||
544 | new ExpressionEvaluation(body, new IExpressionEvaluator() { | ||
545 | |||
546 | @Override | ||
547 | public String getShortDescription() { | ||
548 | return "Expression evaluation from pattern notEnoughAvailableHdd"; | ||
549 | } | ||
550 | |||
551 | @Override | ||
552 | public Iterable<String> getInputParameterNames() { | ||
553 | return Arrays.asList("Hdd");} | ||
554 | |||
555 | @Override | ||
556 | public Object evaluateExpression(IValueProvider provider) throws Exception { | ||
557 | Integer Hdd = (Integer) provider.getValue("Hdd"); | ||
558 | return evaluateExpression_1_1(Hdd); | ||
559 | } | ||
560 | }, null); | ||
561 | bodies.add(body); | ||
562 | } | ||
563 | { | ||
564 | PAnnotation annotation = new PAnnotation("Constraint"); | ||
565 | annotation.addAttribute("severity", "error"); | ||
566 | annotation.addAttribute("key", Arrays.asList(new Object[] { | ||
567 | new ParameterReference("Host") | ||
568 | })); | ||
569 | annotation.addAttribute("message", "Insufficient HDD available on host."); | ||
570 | addAnnotation(annotation); | ||
571 | } | ||
572 | return bodies; | ||
573 | } | ||
574 | } | ||
575 | |||
576 | private static boolean evaluateExpression_1_1(final Integer Hdd) { | ||
577 | return ((Hdd).intValue() < 0); | ||
578 | } | ||
579 | } | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/NotEnoughAvailableMemory.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/NotEnoughAvailableMemory.java new file mode 100644 index 00000000..9f091a95 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/NotEnoughAvailableMemory.java | |||
@@ -0,0 +1,579 @@ | |||
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.HostInstance; | ||
7 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.AvailableMemory; | ||
8 | import java.util.Arrays; | ||
9 | import java.util.Collection; | ||
10 | import java.util.LinkedHashSet; | ||
11 | import java.util.List; | ||
12 | import java.util.Objects; | ||
13 | import java.util.Optional; | ||
14 | import java.util.Set; | ||
15 | import java.util.function.Consumer; | ||
16 | import java.util.stream.Collectors; | ||
17 | import java.util.stream.Stream; | ||
18 | import org.apache.log4j.Logger; | ||
19 | import org.eclipse.emf.ecore.EClass; | ||
20 | import org.eclipse.viatra.query.runtime.api.IPatternMatch; | ||
21 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification; | ||
22 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; | ||
23 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; | ||
24 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; | ||
25 | import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; | ||
26 | import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; | ||
27 | import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; | ||
28 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
29 | import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator; | ||
30 | import org.eclipse.viatra.query.runtime.matchers.psystem.IValueProvider; | ||
31 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | ||
32 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | ||
33 | import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation; | ||
34 | import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference; | ||
35 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
36 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation; | ||
37 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall; | ||
38 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
39 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | ||
40 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; | ||
41 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | ||
42 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; | ||
43 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
44 | import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; | ||
45 | |||
46 | /** | ||
47 | * A pattern-specific query specification that can instantiate Matcher in a type-safe way. | ||
48 | * | ||
49 | * <p>Original source: | ||
50 | * <code><pre> | ||
51 | * {@literal @}Constraint(severity = "error", key = {Host}, | ||
52 | * message = "Insufficient memory available on host.") | ||
53 | * pattern notEnoughAvailableMemory(Host : HostInstance) { | ||
54 | * find availableMemory(Host, Memory); | ||
55 | * check(Memory {@literal <} 0); | ||
56 | * } | ||
57 | * </pre></code> | ||
58 | * | ||
59 | * @see Matcher | ||
60 | * @see Match | ||
61 | * | ||
62 | */ | ||
63 | @SuppressWarnings("all") | ||
64 | public final class NotEnoughAvailableMemory extends BaseGeneratedEMFQuerySpecification<NotEnoughAvailableMemory.Matcher> { | ||
65 | /** | ||
66 | * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.notEnoughAvailableMemory pattern, | ||
67 | * to be used in conjunction with {@link Matcher}. | ||
68 | * | ||
69 | * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. | ||
70 | * Each instance is a (possibly partial) substitution of pattern parameters, | ||
71 | * usable to represent a match of the pattern in the result of a query, | ||
72 | * or to specify the bound (fixed) input parameters when issuing a query. | ||
73 | * | ||
74 | * @see Matcher | ||
75 | * | ||
76 | */ | ||
77 | public static abstract class Match extends BasePatternMatch { | ||
78 | private HostInstance fHost; | ||
79 | |||
80 | private static List<String> parameterNames = makeImmutableList("Host"); | ||
81 | |||
82 | private Match(final HostInstance pHost) { | ||
83 | this.fHost = pHost; | ||
84 | } | ||
85 | |||
86 | @Override | ||
87 | public Object get(final String parameterName) { | ||
88 | if ("Host".equals(parameterName)) return this.fHost; | ||
89 | return null; | ||
90 | } | ||
91 | |||
92 | public HostInstance getHost() { | ||
93 | return this.fHost; | ||
94 | } | ||
95 | |||
96 | @Override | ||
97 | public boolean set(final String parameterName, final Object newValue) { | ||
98 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
99 | if ("Host".equals(parameterName) ) { | ||
100 | this.fHost = (HostInstance) newValue; | ||
101 | return true; | ||
102 | } | ||
103 | return false; | ||
104 | } | ||
105 | |||
106 | public void setHost(final HostInstance pHost) { | ||
107 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
108 | this.fHost = pHost; | ||
109 | } | ||
110 | |||
111 | @Override | ||
112 | public String patternName() { | ||
113 | return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.notEnoughAvailableMemory"; | ||
114 | } | ||
115 | |||
116 | @Override | ||
117 | public List<String> parameterNames() { | ||
118 | return NotEnoughAvailableMemory.Match.parameterNames; | ||
119 | } | ||
120 | |||
121 | @Override | ||
122 | public Object[] toArray() { | ||
123 | return new Object[]{fHost}; | ||
124 | } | ||
125 | |||
126 | @Override | ||
127 | public NotEnoughAvailableMemory.Match toImmutable() { | ||
128 | return isMutable() ? newMatch(fHost) : this; | ||
129 | } | ||
130 | |||
131 | @Override | ||
132 | public String prettyPrint() { | ||
133 | StringBuilder result = new StringBuilder(); | ||
134 | result.append("\"Host\"=" + prettyPrintValue(fHost)); | ||
135 | return result.toString(); | ||
136 | } | ||
137 | |||
138 | @Override | ||
139 | public int hashCode() { | ||
140 | return Objects.hash(fHost); | ||
141 | } | ||
142 | |||
143 | @Override | ||
144 | public boolean equals(final Object obj) { | ||
145 | if (this == obj) | ||
146 | return true; | ||
147 | if (obj == null) { | ||
148 | return false; | ||
149 | } | ||
150 | if ((obj instanceof NotEnoughAvailableMemory.Match)) { | ||
151 | NotEnoughAvailableMemory.Match other = (NotEnoughAvailableMemory.Match) obj; | ||
152 | return Objects.equals(fHost, other.fHost); | ||
153 | } else { | ||
154 | // this should be infrequent | ||
155 | if (!(obj instanceof IPatternMatch)) { | ||
156 | return false; | ||
157 | } | ||
158 | IPatternMatch otherSig = (IPatternMatch) obj; | ||
159 | return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); | ||
160 | } | ||
161 | } | ||
162 | |||
163 | @Override | ||
164 | public NotEnoughAvailableMemory specification() { | ||
165 | return NotEnoughAvailableMemory.instance(); | ||
166 | } | ||
167 | |||
168 | /** | ||
169 | * Returns an empty, mutable match. | ||
170 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
171 | * | ||
172 | * @return the empty match. | ||
173 | * | ||
174 | */ | ||
175 | public static NotEnoughAvailableMemory.Match newEmptyMatch() { | ||
176 | return new Mutable(null); | ||
177 | } | ||
178 | |||
179 | /** | ||
180 | * Returns a mutable (partial) match. | ||
181 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
182 | * | ||
183 | * @param pHost the fixed value of pattern parameter Host, or null if not bound. | ||
184 | * @return the new, mutable (partial) match object. | ||
185 | * | ||
186 | */ | ||
187 | public static NotEnoughAvailableMemory.Match newMutableMatch(final HostInstance pHost) { | ||
188 | return new Mutable(pHost); | ||
189 | } | ||
190 | |||
191 | /** | ||
192 | * Returns a new (partial) match. | ||
193 | * This can be used e.g. to call the matcher with a partial match. | ||
194 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
195 | * @param pHost the fixed value of pattern parameter Host, or null if not bound. | ||
196 | * @return the (partial) match object. | ||
197 | * | ||
198 | */ | ||
199 | public static NotEnoughAvailableMemory.Match newMatch(final HostInstance pHost) { | ||
200 | return new Immutable(pHost); | ||
201 | } | ||
202 | |||
203 | private static final class Mutable extends NotEnoughAvailableMemory.Match { | ||
204 | Mutable(final HostInstance pHost) { | ||
205 | super(pHost); | ||
206 | } | ||
207 | |||
208 | @Override | ||
209 | public boolean isMutable() { | ||
210 | return true; | ||
211 | } | ||
212 | } | ||
213 | |||
214 | private static final class Immutable extends NotEnoughAvailableMemory.Match { | ||
215 | Immutable(final HostInstance pHost) { | ||
216 | super(pHost); | ||
217 | } | ||
218 | |||
219 | @Override | ||
220 | public boolean isMutable() { | ||
221 | return false; | ||
222 | } | ||
223 | } | ||
224 | } | ||
225 | |||
226 | /** | ||
227 | * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.notEnoughAvailableMemory pattern, | ||
228 | * providing pattern-specific query methods. | ||
229 | * | ||
230 | * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, | ||
231 | * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. | ||
232 | * | ||
233 | * <p>Matches of the pattern will be represented as {@link Match}. | ||
234 | * | ||
235 | * <p>Original source: | ||
236 | * <code><pre> | ||
237 | * {@literal @}Constraint(severity = "error", key = {Host}, | ||
238 | * message = "Insufficient memory available on host.") | ||
239 | * pattern notEnoughAvailableMemory(Host : HostInstance) { | ||
240 | * find availableMemory(Host, Memory); | ||
241 | * check(Memory {@literal <} 0); | ||
242 | * } | ||
243 | * </pre></code> | ||
244 | * | ||
245 | * @see Match | ||
246 | * @see NotEnoughAvailableMemory | ||
247 | * | ||
248 | */ | ||
249 | public static class Matcher extends BaseMatcher<NotEnoughAvailableMemory.Match> { | ||
250 | /** | ||
251 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
252 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
253 | * | ||
254 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
255 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
256 | * | ||
257 | */ | ||
258 | public static NotEnoughAvailableMemory.Matcher on(final ViatraQueryEngine engine) { | ||
259 | // check if matcher already exists | ||
260 | Matcher matcher = engine.getExistingMatcher(querySpecification()); | ||
261 | if (matcher == null) { | ||
262 | matcher = (Matcher)engine.getMatcher(querySpecification()); | ||
263 | } | ||
264 | return matcher; | ||
265 | } | ||
266 | |||
267 | /** | ||
268 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
269 | * @return an initialized matcher | ||
270 | * @noreference This method is for internal matcher initialization by the framework, do not call it manually. | ||
271 | * | ||
272 | */ | ||
273 | public static NotEnoughAvailableMemory.Matcher create() { | ||
274 | return new Matcher(); | ||
275 | } | ||
276 | |||
277 | private static final int POSITION_HOST = 0; | ||
278 | |||
279 | private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(NotEnoughAvailableMemory.Matcher.class); | ||
280 | |||
281 | /** | ||
282 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
283 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
284 | * | ||
285 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
286 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
287 | * | ||
288 | */ | ||
289 | private Matcher() { | ||
290 | super(querySpecification()); | ||
291 | } | ||
292 | |||
293 | /** | ||
294 | * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. | ||
295 | * @param pHost the fixed value of pattern parameter Host, or null if not bound. | ||
296 | * @return matches represented as a Match object. | ||
297 | * | ||
298 | */ | ||
299 | public Collection<NotEnoughAvailableMemory.Match> getAllMatches(final HostInstance pHost) { | ||
300 | return rawStreamAllMatches(new Object[]{pHost}).collect(Collectors.toSet()); | ||
301 | } | ||
302 | |||
303 | /** | ||
304 | * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. | ||
305 | * </p> | ||
306 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
307 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
308 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
309 | * @param pHost the fixed value of pattern parameter Host, or null if not bound. | ||
310 | * @return a stream of matches represented as a Match object. | ||
311 | * | ||
312 | */ | ||
313 | public Stream<NotEnoughAvailableMemory.Match> streamAllMatches(final HostInstance pHost) { | ||
314 | return rawStreamAllMatches(new Object[]{pHost}); | ||
315 | } | ||
316 | |||
317 | /** | ||
318 | * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
319 | * Neither determinism nor randomness of selection is guaranteed. | ||
320 | * @param pHost the fixed value of pattern parameter Host, or null if not bound. | ||
321 | * @return a match represented as a Match object, or null if no match is found. | ||
322 | * | ||
323 | */ | ||
324 | public Optional<NotEnoughAvailableMemory.Match> getOneArbitraryMatch(final HostInstance pHost) { | ||
325 | return rawGetOneArbitraryMatch(new Object[]{pHost}); | ||
326 | } | ||
327 | |||
328 | /** | ||
329 | * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, | ||
330 | * under any possible substitution of the unspecified parameters (if any). | ||
331 | * @param pHost the fixed value of pattern parameter Host, or null if not bound. | ||
332 | * @return true if the input is a valid (partial) match of the pattern. | ||
333 | * | ||
334 | */ | ||
335 | public boolean hasMatch(final HostInstance pHost) { | ||
336 | return rawHasMatch(new Object[]{pHost}); | ||
337 | } | ||
338 | |||
339 | /** | ||
340 | * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. | ||
341 | * @param pHost the fixed value of pattern parameter Host, or null if not bound. | ||
342 | * @return the number of pattern matches found. | ||
343 | * | ||
344 | */ | ||
345 | public int countMatches(final HostInstance pHost) { | ||
346 | return rawCountMatches(new Object[]{pHost}); | ||
347 | } | ||
348 | |||
349 | /** | ||
350 | * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
351 | * Neither determinism nor randomness of selection is guaranteed. | ||
352 | * @param pHost the fixed value of pattern parameter Host, or null if not bound. | ||
353 | * @param processor the action that will process the selected match. | ||
354 | * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked | ||
355 | * | ||
356 | */ | ||
357 | public boolean forOneArbitraryMatch(final HostInstance pHost, final Consumer<? super NotEnoughAvailableMemory.Match> processor) { | ||
358 | return rawForOneArbitraryMatch(new Object[]{pHost}, processor); | ||
359 | } | ||
360 | |||
361 | /** | ||
362 | * Returns a new (partial) match. | ||
363 | * This can be used e.g. to call the matcher with a partial match. | ||
364 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
365 | * @param pHost the fixed value of pattern parameter Host, or null if not bound. | ||
366 | * @return the (partial) match object. | ||
367 | * | ||
368 | */ | ||
369 | public NotEnoughAvailableMemory.Match newMatch(final HostInstance pHost) { | ||
370 | return NotEnoughAvailableMemory.Match.newMatch(pHost); | ||
371 | } | ||
372 | |||
373 | /** | ||
374 | * Retrieve the set of values that occur in matches for Host. | ||
375 | * @return the Set of all values or empty set if there are no matches | ||
376 | * | ||
377 | */ | ||
378 | protected Stream<HostInstance> rawStreamAllValuesOfHost(final Object[] parameters) { | ||
379 | return rawStreamAllValues(POSITION_HOST, parameters).map(HostInstance.class::cast); | ||
380 | } | ||
381 | |||
382 | /** | ||
383 | * Retrieve the set of values that occur in matches for Host. | ||
384 | * @return the Set of all values or empty set if there are no matches | ||
385 | * | ||
386 | */ | ||
387 | public Set<HostInstance> getAllValuesOfHost() { | ||
388 | return rawStreamAllValuesOfHost(emptyArray()).collect(Collectors.toSet()); | ||
389 | } | ||
390 | |||
391 | /** | ||
392 | * Retrieve the set of values that occur in matches for Host. | ||
393 | * @return the Set of all values or empty set if there are no matches | ||
394 | * | ||
395 | */ | ||
396 | public Stream<HostInstance> streamAllValuesOfHost() { | ||
397 | return rawStreamAllValuesOfHost(emptyArray()); | ||
398 | } | ||
399 | |||
400 | @Override | ||
401 | protected NotEnoughAvailableMemory.Match tupleToMatch(final Tuple t) { | ||
402 | try { | ||
403 | return NotEnoughAvailableMemory.Match.newMatch((HostInstance) t.get(POSITION_HOST)); | ||
404 | } catch(ClassCastException e) { | ||
405 | LOGGER.error("Element(s) in tuple not properly typed!",e); | ||
406 | return null; | ||
407 | } | ||
408 | } | ||
409 | |||
410 | @Override | ||
411 | protected NotEnoughAvailableMemory.Match arrayToMatch(final Object[] match) { | ||
412 | try { | ||
413 | return NotEnoughAvailableMemory.Match.newMatch((HostInstance) match[POSITION_HOST]); | ||
414 | } catch(ClassCastException e) { | ||
415 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
416 | return null; | ||
417 | } | ||
418 | } | ||
419 | |||
420 | @Override | ||
421 | protected NotEnoughAvailableMemory.Match arrayToMatchMutable(final Object[] match) { | ||
422 | try { | ||
423 | return NotEnoughAvailableMemory.Match.newMutableMatch((HostInstance) match[POSITION_HOST]); | ||
424 | } catch(ClassCastException e) { | ||
425 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
426 | return null; | ||
427 | } | ||
428 | } | ||
429 | |||
430 | /** | ||
431 | * @return the singleton instance of the query specification of this pattern | ||
432 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
433 | * | ||
434 | */ | ||
435 | public static IQuerySpecification<NotEnoughAvailableMemory.Matcher> querySpecification() { | ||
436 | return NotEnoughAvailableMemory.instance(); | ||
437 | } | ||
438 | } | ||
439 | |||
440 | private NotEnoughAvailableMemory() { | ||
441 | super(GeneratedPQuery.INSTANCE); | ||
442 | } | ||
443 | |||
444 | /** | ||
445 | * @return the singleton instance of the query specification | ||
446 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
447 | * | ||
448 | */ | ||
449 | public static NotEnoughAvailableMemory instance() { | ||
450 | try{ | ||
451 | return LazyHolder.INSTANCE; | ||
452 | } catch (ExceptionInInitializerError err) { | ||
453 | throw processInitializerError(err); | ||
454 | } | ||
455 | } | ||
456 | |||
457 | @Override | ||
458 | protected NotEnoughAvailableMemory.Matcher instantiate(final ViatraQueryEngine engine) { | ||
459 | return NotEnoughAvailableMemory.Matcher.on(engine); | ||
460 | } | ||
461 | |||
462 | @Override | ||
463 | public NotEnoughAvailableMemory.Matcher instantiate() { | ||
464 | return NotEnoughAvailableMemory.Matcher.create(); | ||
465 | } | ||
466 | |||
467 | @Override | ||
468 | public NotEnoughAvailableMemory.Match newEmptyMatch() { | ||
469 | return NotEnoughAvailableMemory.Match.newEmptyMatch(); | ||
470 | } | ||
471 | |||
472 | @Override | ||
473 | public NotEnoughAvailableMemory.Match newMatch(final Object... parameters) { | ||
474 | return NotEnoughAvailableMemory.Match.newMatch((hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance) parameters[0]); | ||
475 | } | ||
476 | |||
477 | /** | ||
478 | * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.NotEnoughAvailableMemory (visibility: PUBLIC, simpleName: NotEnoughAvailableMemory, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.NotEnoughAvailableMemory, 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 | ||
479 | * <b>not</b> at the class load time of the outer class, | ||
480 | * but rather at the first call to {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.NotEnoughAvailableMemory (visibility: PUBLIC, simpleName: NotEnoughAvailableMemory, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.NotEnoughAvailableMemory, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}. | ||
481 | * | ||
482 | * <p> This workaround is required e.g. to support recursion. | ||
483 | * | ||
484 | */ | ||
485 | private static class LazyHolder { | ||
486 | private static final NotEnoughAvailableMemory INSTANCE = new NotEnoughAvailableMemory(); | ||
487 | |||
488 | /** | ||
489 | * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned. | ||
490 | * This initialization order is required to support indirect recursion. | ||
491 | * | ||
492 | * <p> The static initializer is defined using a helper field to work around limitations of the code generator. | ||
493 | * | ||
494 | */ | ||
495 | private static final Object STATIC_INITIALIZER = ensureInitialized(); | ||
496 | |||
497 | public static Object ensureInitialized() { | ||
498 | INSTANCE.ensureInitializedInternal(); | ||
499 | return null; | ||
500 | } | ||
501 | } | ||
502 | |||
503 | private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { | ||
504 | private static final NotEnoughAvailableMemory.GeneratedPQuery INSTANCE = new GeneratedPQuery(); | ||
505 | |||
506 | 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); | ||
507 | |||
508 | private final List<PParameter> parameters = Arrays.asList(parameter_Host); | ||
509 | |||
510 | private GeneratedPQuery() { | ||
511 | super(PVisibility.PUBLIC); | ||
512 | } | ||
513 | |||
514 | @Override | ||
515 | public String getFullyQualifiedName() { | ||
516 | return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.notEnoughAvailableMemory"; | ||
517 | } | ||
518 | |||
519 | @Override | ||
520 | public List<String> getParameterNames() { | ||
521 | return Arrays.asList("Host"); | ||
522 | } | ||
523 | |||
524 | @Override | ||
525 | public List<PParameter> getParameters() { | ||
526 | return parameters; | ||
527 | } | ||
528 | |||
529 | @Override | ||
530 | public Set<PBody> doGetContainedBodies() { | ||
531 | setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); | ||
532 | Set<PBody> bodies = new LinkedHashSet<>(); | ||
533 | { | ||
534 | PBody body = new PBody(this); | ||
535 | PVariable var_Host = body.getOrCreateVariableByName("Host"); | ||
536 | PVariable var_Memory = body.getOrCreateVariableByName("Memory"); | ||
537 | new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); | ||
538 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
539 | new ExportedParameter(body, var_Host, parameter_Host) | ||
540 | )); | ||
541 | // find availableMemory(Host, Memory) | ||
542 | new PositivePatternCall(body, Tuples.flatTupleOf(var_Host, var_Memory), AvailableMemory.instance().getInternalQueryRepresentation()); | ||
543 | // check(Memory < 0) | ||
544 | new ExpressionEvaluation(body, new IExpressionEvaluator() { | ||
545 | |||
546 | @Override | ||
547 | public String getShortDescription() { | ||
548 | return "Expression evaluation from pattern notEnoughAvailableMemory"; | ||
549 | } | ||
550 | |||
551 | @Override | ||
552 | public Iterable<String> getInputParameterNames() { | ||
553 | return Arrays.asList("Memory");} | ||
554 | |||
555 | @Override | ||
556 | public Object evaluateExpression(IValueProvider provider) throws Exception { | ||
557 | Integer Memory = (Integer) provider.getValue("Memory"); | ||
558 | return evaluateExpression_1_1(Memory); | ||
559 | } | ||
560 | }, null); | ||
561 | bodies.add(body); | ||
562 | } | ||
563 | { | ||
564 | PAnnotation annotation = new PAnnotation("Constraint"); | ||
565 | annotation.addAttribute("severity", "error"); | ||
566 | annotation.addAttribute("key", Arrays.asList(new Object[] { | ||
567 | new ParameterReference("Host") | ||
568 | })); | ||
569 | annotation.addAttribute("message", "Insufficient memory available on host."); | ||
570 | addAnnotation(annotation); | ||
571 | } | ||
572 | return bodies; | ||
573 | } | ||
574 | } | ||
575 | |||
576 | private static boolean evaluateExpression_1_1(final Integer Memory) { | ||
577 | return ((Memory).intValue() < 0); | ||
578 | } | ||
579 | } | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/RedundantInstancesOnSameHost.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/RedundantInstancesOnSameHost.java new file mode 100644 index 00000000..bbb55158 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/RedundantInstancesOnSameHost.java | |||
@@ -0,0 +1,587 @@ | |||
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.Requirement; | ||
7 | import java.util.Arrays; | ||
8 | import java.util.Collection; | ||
9 | import java.util.LinkedHashSet; | ||
10 | import java.util.List; | ||
11 | import java.util.Objects; | ||
12 | import java.util.Optional; | ||
13 | import java.util.Set; | ||
14 | import java.util.function.Consumer; | ||
15 | import java.util.stream.Collectors; | ||
16 | import java.util.stream.Stream; | ||
17 | import org.apache.log4j.Logger; | ||
18 | import org.eclipse.emf.ecore.EClass; | ||
19 | import org.eclipse.viatra.query.runtime.api.IPatternMatch; | ||
20 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification; | ||
21 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; | ||
22 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; | ||
23 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; | ||
24 | import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; | ||
25 | import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; | ||
26 | import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; | ||
27 | import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; | ||
28 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
29 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | ||
30 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | ||
31 | import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation; | ||
32 | import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference; | ||
33 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; | ||
34 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
35 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Inequality; | ||
36 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
37 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | ||
38 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; | ||
39 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | ||
40 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; | ||
41 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
42 | import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; | ||
43 | |||
44 | /** | ||
45 | * A pattern-specific query specification that can instantiate Matcher in a type-safe way. | ||
46 | * | ||
47 | * <p>Original source: | ||
48 | * <code><pre> | ||
49 | * {@literal @}Constraint(severity = "error", key = {Req}, | ||
50 | * message = "Redundant instances must not be allocated to the same host.") | ||
51 | * pattern redundantInstancesOnSameHost(Req : Requirement) { | ||
52 | * Requirement.instances(Req, App1); | ||
53 | * Requirement.instances(Req, App2); | ||
54 | * App1 != App2; | ||
55 | * ApplicationInstance.allocatedTo(App1, Host); | ||
56 | * ApplicationInstance.allocatedTo(App2, Host); | ||
57 | * } | ||
58 | * </pre></code> | ||
59 | * | ||
60 | * @see Matcher | ||
61 | * @see Match | ||
62 | * | ||
63 | */ | ||
64 | @SuppressWarnings("all") | ||
65 | public final class RedundantInstancesOnSameHost extends BaseGeneratedEMFQuerySpecification<RedundantInstancesOnSameHost.Matcher> { | ||
66 | /** | ||
67 | * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.redundantInstancesOnSameHost pattern, | ||
68 | * to be used in conjunction with {@link Matcher}. | ||
69 | * | ||
70 | * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. | ||
71 | * Each instance is a (possibly partial) substitution of pattern parameters, | ||
72 | * usable to represent a match of the pattern in the result of a query, | ||
73 | * or to specify the bound (fixed) input parameters when issuing a query. | ||
74 | * | ||
75 | * @see Matcher | ||
76 | * | ||
77 | */ | ||
78 | public static abstract class Match extends BasePatternMatch { | ||
79 | private Requirement fReq; | ||
80 | |||
81 | private static List<String> parameterNames = makeImmutableList("Req"); | ||
82 | |||
83 | private Match(final Requirement pReq) { | ||
84 | this.fReq = pReq; | ||
85 | } | ||
86 | |||
87 | @Override | ||
88 | public Object get(final String parameterName) { | ||
89 | if ("Req".equals(parameterName)) return this.fReq; | ||
90 | return null; | ||
91 | } | ||
92 | |||
93 | public Requirement getReq() { | ||
94 | return this.fReq; | ||
95 | } | ||
96 | |||
97 | @Override | ||
98 | public boolean set(final String parameterName, final Object newValue) { | ||
99 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
100 | if ("Req".equals(parameterName) ) { | ||
101 | this.fReq = (Requirement) newValue; | ||
102 | return true; | ||
103 | } | ||
104 | return false; | ||
105 | } | ||
106 | |||
107 | public void setReq(final Requirement pReq) { | ||
108 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
109 | this.fReq = pReq; | ||
110 | } | ||
111 | |||
112 | @Override | ||
113 | public String patternName() { | ||
114 | return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.redundantInstancesOnSameHost"; | ||
115 | } | ||
116 | |||
117 | @Override | ||
118 | public List<String> parameterNames() { | ||
119 | return RedundantInstancesOnSameHost.Match.parameterNames; | ||
120 | } | ||
121 | |||
122 | @Override | ||
123 | public Object[] toArray() { | ||
124 | return new Object[]{fReq}; | ||
125 | } | ||
126 | |||
127 | @Override | ||
128 | public RedundantInstancesOnSameHost.Match toImmutable() { | ||
129 | return isMutable() ? newMatch(fReq) : this; | ||
130 | } | ||
131 | |||
132 | @Override | ||
133 | public String prettyPrint() { | ||
134 | StringBuilder result = new StringBuilder(); | ||
135 | result.append("\"Req\"=" + prettyPrintValue(fReq)); | ||
136 | return result.toString(); | ||
137 | } | ||
138 | |||
139 | @Override | ||
140 | public int hashCode() { | ||
141 | return Objects.hash(fReq); | ||
142 | } | ||
143 | |||
144 | @Override | ||
145 | public boolean equals(final Object obj) { | ||
146 | if (this == obj) | ||
147 | return true; | ||
148 | if (obj == null) { | ||
149 | return false; | ||
150 | } | ||
151 | if ((obj instanceof RedundantInstancesOnSameHost.Match)) { | ||
152 | RedundantInstancesOnSameHost.Match other = (RedundantInstancesOnSameHost.Match) obj; | ||
153 | return Objects.equals(fReq, other.fReq); | ||
154 | } else { | ||
155 | // this should be infrequent | ||
156 | if (!(obj instanceof IPatternMatch)) { | ||
157 | return false; | ||
158 | } | ||
159 | IPatternMatch otherSig = (IPatternMatch) obj; | ||
160 | return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); | ||
161 | } | ||
162 | } | ||
163 | |||
164 | @Override | ||
165 | public RedundantInstancesOnSameHost specification() { | ||
166 | return RedundantInstancesOnSameHost.instance(); | ||
167 | } | ||
168 | |||
169 | /** | ||
170 | * Returns an empty, mutable match. | ||
171 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
172 | * | ||
173 | * @return the empty match. | ||
174 | * | ||
175 | */ | ||
176 | public static RedundantInstancesOnSameHost.Match newEmptyMatch() { | ||
177 | return new Mutable(null); | ||
178 | } | ||
179 | |||
180 | /** | ||
181 | * Returns a mutable (partial) match. | ||
182 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
183 | * | ||
184 | * @param pReq the fixed value of pattern parameter Req, or null if not bound. | ||
185 | * @return the new, mutable (partial) match object. | ||
186 | * | ||
187 | */ | ||
188 | public static RedundantInstancesOnSameHost.Match newMutableMatch(final Requirement pReq) { | ||
189 | return new Mutable(pReq); | ||
190 | } | ||
191 | |||
192 | /** | ||
193 | * Returns a new (partial) match. | ||
194 | * This can be used e.g. to call the matcher with a partial match. | ||
195 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
196 | * @param pReq the fixed value of pattern parameter Req, or null if not bound. | ||
197 | * @return the (partial) match object. | ||
198 | * | ||
199 | */ | ||
200 | public static RedundantInstancesOnSameHost.Match newMatch(final Requirement pReq) { | ||
201 | return new Immutable(pReq); | ||
202 | } | ||
203 | |||
204 | private static final class Mutable extends RedundantInstancesOnSameHost.Match { | ||
205 | Mutable(final Requirement pReq) { | ||
206 | super(pReq); | ||
207 | } | ||
208 | |||
209 | @Override | ||
210 | public boolean isMutable() { | ||
211 | return true; | ||
212 | } | ||
213 | } | ||
214 | |||
215 | private static final class Immutable extends RedundantInstancesOnSameHost.Match { | ||
216 | Immutable(final Requirement pReq) { | ||
217 | super(pReq); | ||
218 | } | ||
219 | |||
220 | @Override | ||
221 | public boolean isMutable() { | ||
222 | return false; | ||
223 | } | ||
224 | } | ||
225 | } | ||
226 | |||
227 | /** | ||
228 | * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.redundantInstancesOnSameHost pattern, | ||
229 | * providing pattern-specific query methods. | ||
230 | * | ||
231 | * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, | ||
232 | * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. | ||
233 | * | ||
234 | * <p>Matches of the pattern will be represented as {@link Match}. | ||
235 | * | ||
236 | * <p>Original source: | ||
237 | * <code><pre> | ||
238 | * {@literal @}Constraint(severity = "error", key = {Req}, | ||
239 | * message = "Redundant instances must not be allocated to the same host.") | ||
240 | * pattern redundantInstancesOnSameHost(Req : Requirement) { | ||
241 | * Requirement.instances(Req, App1); | ||
242 | * Requirement.instances(Req, App2); | ||
243 | * App1 != App2; | ||
244 | * ApplicationInstance.allocatedTo(App1, Host); | ||
245 | * ApplicationInstance.allocatedTo(App2, Host); | ||
246 | * } | ||
247 | * </pre></code> | ||
248 | * | ||
249 | * @see Match | ||
250 | * @see RedundantInstancesOnSameHost | ||
251 | * | ||
252 | */ | ||
253 | public static class Matcher extends BaseMatcher<RedundantInstancesOnSameHost.Match> { | ||
254 | /** | ||
255 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
256 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
257 | * | ||
258 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
259 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
260 | * | ||
261 | */ | ||
262 | public static RedundantInstancesOnSameHost.Matcher on(final ViatraQueryEngine engine) { | ||
263 | // check if matcher already exists | ||
264 | Matcher matcher = engine.getExistingMatcher(querySpecification()); | ||
265 | if (matcher == null) { | ||
266 | matcher = (Matcher)engine.getMatcher(querySpecification()); | ||
267 | } | ||
268 | return matcher; | ||
269 | } | ||
270 | |||
271 | /** | ||
272 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
273 | * @return an initialized matcher | ||
274 | * @noreference This method is for internal matcher initialization by the framework, do not call it manually. | ||
275 | * | ||
276 | */ | ||
277 | public static RedundantInstancesOnSameHost.Matcher create() { | ||
278 | return new Matcher(); | ||
279 | } | ||
280 | |||
281 | private static final int POSITION_REQ = 0; | ||
282 | |||
283 | private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(RedundantInstancesOnSameHost.Matcher.class); | ||
284 | |||
285 | /** | ||
286 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
287 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
288 | * | ||
289 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
290 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
291 | * | ||
292 | */ | ||
293 | private Matcher() { | ||
294 | super(querySpecification()); | ||
295 | } | ||
296 | |||
297 | /** | ||
298 | * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. | ||
299 | * @param pReq the fixed value of pattern parameter Req, or null if not bound. | ||
300 | * @return matches represented as a Match object. | ||
301 | * | ||
302 | */ | ||
303 | public Collection<RedundantInstancesOnSameHost.Match> getAllMatches(final Requirement pReq) { | ||
304 | return rawStreamAllMatches(new Object[]{pReq}).collect(Collectors.toSet()); | ||
305 | } | ||
306 | |||
307 | /** | ||
308 | * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. | ||
309 | * </p> | ||
310 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
311 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
312 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
313 | * @param pReq the fixed value of pattern parameter Req, or null if not bound. | ||
314 | * @return a stream of matches represented as a Match object. | ||
315 | * | ||
316 | */ | ||
317 | public Stream<RedundantInstancesOnSameHost.Match> streamAllMatches(final Requirement pReq) { | ||
318 | return rawStreamAllMatches(new Object[]{pReq}); | ||
319 | } | ||
320 | |||
321 | /** | ||
322 | * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
323 | * Neither determinism nor randomness of selection is guaranteed. | ||
324 | * @param pReq the fixed value of pattern parameter Req, or null if not bound. | ||
325 | * @return a match represented as a Match object, or null if no match is found. | ||
326 | * | ||
327 | */ | ||
328 | public Optional<RedundantInstancesOnSameHost.Match> getOneArbitraryMatch(final Requirement pReq) { | ||
329 | return rawGetOneArbitraryMatch(new Object[]{pReq}); | ||
330 | } | ||
331 | |||
332 | /** | ||
333 | * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, | ||
334 | * under any possible substitution of the unspecified parameters (if any). | ||
335 | * @param pReq the fixed value of pattern parameter Req, or null if not bound. | ||
336 | * @return true if the input is a valid (partial) match of the pattern. | ||
337 | * | ||
338 | */ | ||
339 | public boolean hasMatch(final Requirement pReq) { | ||
340 | return rawHasMatch(new Object[]{pReq}); | ||
341 | } | ||
342 | |||
343 | /** | ||
344 | * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. | ||
345 | * @param pReq the fixed value of pattern parameter Req, or null if not bound. | ||
346 | * @return the number of pattern matches found. | ||
347 | * | ||
348 | */ | ||
349 | public int countMatches(final Requirement pReq) { | ||
350 | return rawCountMatches(new Object[]{pReq}); | ||
351 | } | ||
352 | |||
353 | /** | ||
354 | * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
355 | * Neither determinism nor randomness of selection is guaranteed. | ||
356 | * @param pReq the fixed value of pattern parameter Req, or null if not bound. | ||
357 | * @param processor the action that will process the selected match. | ||
358 | * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked | ||
359 | * | ||
360 | */ | ||
361 | public boolean forOneArbitraryMatch(final Requirement pReq, final Consumer<? super RedundantInstancesOnSameHost.Match> processor) { | ||
362 | return rawForOneArbitraryMatch(new Object[]{pReq}, processor); | ||
363 | } | ||
364 | |||
365 | /** | ||
366 | * Returns a new (partial) match. | ||
367 | * This can be used e.g. to call the matcher with a partial match. | ||
368 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
369 | * @param pReq the fixed value of pattern parameter Req, or null if not bound. | ||
370 | * @return the (partial) match object. | ||
371 | * | ||
372 | */ | ||
373 | public RedundantInstancesOnSameHost.Match newMatch(final Requirement pReq) { | ||
374 | return RedundantInstancesOnSameHost.Match.newMatch(pReq); | ||
375 | } | ||
376 | |||
377 | /** | ||
378 | * Retrieve the set of values that occur in matches for Req. | ||
379 | * @return the Set of all values or empty set if there are no matches | ||
380 | * | ||
381 | */ | ||
382 | protected Stream<Requirement> rawStreamAllValuesOfReq(final Object[] parameters) { | ||
383 | return rawStreamAllValues(POSITION_REQ, parameters).map(Requirement.class::cast); | ||
384 | } | ||
385 | |||
386 | /** | ||
387 | * Retrieve the set of values that occur in matches for Req. | ||
388 | * @return the Set of all values or empty set if there are no matches | ||
389 | * | ||
390 | */ | ||
391 | public Set<Requirement> getAllValuesOfReq() { | ||
392 | return rawStreamAllValuesOfReq(emptyArray()).collect(Collectors.toSet()); | ||
393 | } | ||
394 | |||
395 | /** | ||
396 | * Retrieve the set of values that occur in matches for Req. | ||
397 | * @return the Set of all values or empty set if there are no matches | ||
398 | * | ||
399 | */ | ||
400 | public Stream<Requirement> streamAllValuesOfReq() { | ||
401 | return rawStreamAllValuesOfReq(emptyArray()); | ||
402 | } | ||
403 | |||
404 | @Override | ||
405 | protected RedundantInstancesOnSameHost.Match tupleToMatch(final Tuple t) { | ||
406 | try { | ||
407 | return RedundantInstancesOnSameHost.Match.newMatch((Requirement) t.get(POSITION_REQ)); | ||
408 | } catch(ClassCastException e) { | ||
409 | LOGGER.error("Element(s) in tuple not properly typed!",e); | ||
410 | return null; | ||
411 | } | ||
412 | } | ||
413 | |||
414 | @Override | ||
415 | protected RedundantInstancesOnSameHost.Match arrayToMatch(final Object[] match) { | ||
416 | try { | ||
417 | return RedundantInstancesOnSameHost.Match.newMatch((Requirement) match[POSITION_REQ]); | ||
418 | } catch(ClassCastException e) { | ||
419 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
420 | return null; | ||
421 | } | ||
422 | } | ||
423 | |||
424 | @Override | ||
425 | protected RedundantInstancesOnSameHost.Match arrayToMatchMutable(final Object[] match) { | ||
426 | try { | ||
427 | return RedundantInstancesOnSameHost.Match.newMutableMatch((Requirement) match[POSITION_REQ]); | ||
428 | } catch(ClassCastException e) { | ||
429 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
430 | return null; | ||
431 | } | ||
432 | } | ||
433 | |||
434 | /** | ||
435 | * @return the singleton instance of the query specification of this pattern | ||
436 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
437 | * | ||
438 | */ | ||
439 | public static IQuerySpecification<RedundantInstancesOnSameHost.Matcher> querySpecification() { | ||
440 | return RedundantInstancesOnSameHost.instance(); | ||
441 | } | ||
442 | } | ||
443 | |||
444 | private RedundantInstancesOnSameHost() { | ||
445 | super(GeneratedPQuery.INSTANCE); | ||
446 | } | ||
447 | |||
448 | /** | ||
449 | * @return the singleton instance of the query specification | ||
450 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
451 | * | ||
452 | */ | ||
453 | public static RedundantInstancesOnSameHost instance() { | ||
454 | try{ | ||
455 | return LazyHolder.INSTANCE; | ||
456 | } catch (ExceptionInInitializerError err) { | ||
457 | throw processInitializerError(err); | ||
458 | } | ||
459 | } | ||
460 | |||
461 | @Override | ||
462 | protected RedundantInstancesOnSameHost.Matcher instantiate(final ViatraQueryEngine engine) { | ||
463 | return RedundantInstancesOnSameHost.Matcher.on(engine); | ||
464 | } | ||
465 | |||
466 | @Override | ||
467 | public RedundantInstancesOnSameHost.Matcher instantiate() { | ||
468 | return RedundantInstancesOnSameHost.Matcher.create(); | ||
469 | } | ||
470 | |||
471 | @Override | ||
472 | public RedundantInstancesOnSameHost.Match newEmptyMatch() { | ||
473 | return RedundantInstancesOnSameHost.Match.newEmptyMatch(); | ||
474 | } | ||
475 | |||
476 | @Override | ||
477 | public RedundantInstancesOnSameHost.Match newMatch(final Object... parameters) { | ||
478 | return RedundantInstancesOnSameHost.Match.newMatch((hu.bme.mit.inf.dslreasoner.domains.cps.Requirement) parameters[0]); | ||
479 | } | ||
480 | |||
481 | /** | ||
482 | * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.RedundantInstancesOnSameHost (visibility: PUBLIC, simpleName: RedundantInstancesOnSameHost, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.RedundantInstancesOnSameHost, 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 | ||
483 | * <b>not</b> at the class load time of the outer class, | ||
484 | * but rather at the first call to {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.RedundantInstancesOnSameHost (visibility: PUBLIC, simpleName: RedundantInstancesOnSameHost, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.RedundantInstancesOnSameHost, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}. | ||
485 | * | ||
486 | * <p> This workaround is required e.g. to support recursion. | ||
487 | * | ||
488 | */ | ||
489 | private static class LazyHolder { | ||
490 | private static final RedundantInstancesOnSameHost INSTANCE = new RedundantInstancesOnSameHost(); | ||
491 | |||
492 | /** | ||
493 | * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned. | ||
494 | * This initialization order is required to support indirect recursion. | ||
495 | * | ||
496 | * <p> The static initializer is defined using a helper field to work around limitations of the code generator. | ||
497 | * | ||
498 | */ | ||
499 | private static final Object STATIC_INITIALIZER = ensureInitialized(); | ||
500 | |||
501 | public static Object ensureInitialized() { | ||
502 | INSTANCE.ensureInitializedInternal(); | ||
503 | return null; | ||
504 | } | ||
505 | } | ||
506 | |||
507 | private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { | ||
508 | private static final RedundantInstancesOnSameHost.GeneratedPQuery INSTANCE = new GeneratedPQuery(); | ||
509 | |||
510 | private final PParameter parameter_Req = new PParameter("Req", "hu.bme.mit.inf.dslreasoner.domains.cps.Requirement", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "Requirement")), PParameterDirection.INOUT); | ||
511 | |||
512 | private final List<PParameter> parameters = Arrays.asList(parameter_Req); | ||
513 | |||
514 | private GeneratedPQuery() { | ||
515 | super(PVisibility.PUBLIC); | ||
516 | } | ||
517 | |||
518 | @Override | ||
519 | public String getFullyQualifiedName() { | ||
520 | return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.redundantInstancesOnSameHost"; | ||
521 | } | ||
522 | |||
523 | @Override | ||
524 | public List<String> getParameterNames() { | ||
525 | return Arrays.asList("Req"); | ||
526 | } | ||
527 | |||
528 | @Override | ||
529 | public List<PParameter> getParameters() { | ||
530 | return parameters; | ||
531 | } | ||
532 | |||
533 | @Override | ||
534 | public Set<PBody> doGetContainedBodies() { | ||
535 | setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); | ||
536 | Set<PBody> bodies = new LinkedHashSet<>(); | ||
537 | { | ||
538 | PBody body = new PBody(this); | ||
539 | PVariable var_Req = body.getOrCreateVariableByName("Req"); | ||
540 | PVariable var_App1 = body.getOrCreateVariableByName("App1"); | ||
541 | PVariable var_App2 = body.getOrCreateVariableByName("App2"); | ||
542 | PVariable var_Host = body.getOrCreateVariableByName("Host"); | ||
543 | new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "Requirement"))); | ||
544 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
545 | new ExportedParameter(body, var_Req, parameter_Req) | ||
546 | )); | ||
547 | // Requirement.instances(Req, App1) | ||
548 | new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "Requirement"))); | ||
549 | PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); | ||
550 | new TypeConstraint(body, Tuples.flatTupleOf(var_Req, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "Requirement", "instances"))); | ||
551 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance"))); | ||
552 | new Equality(body, var__virtual_0_, var_App1); | ||
553 | // Requirement.instances(Req, App2) | ||
554 | new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "Requirement"))); | ||
555 | PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); | ||
556 | new TypeConstraint(body, Tuples.flatTupleOf(var_Req, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "Requirement", "instances"))); | ||
557 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance"))); | ||
558 | new Equality(body, var__virtual_1_, var_App2); | ||
559 | // App1 != App2 | ||
560 | new Inequality(body, var_App1, var_App2); | ||
561 | // ApplicationInstance.allocatedTo(App1, Host) | ||
562 | new TypeConstraint(body, Tuples.flatTupleOf(var_App1), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance"))); | ||
563 | PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}"); | ||
564 | new TypeConstraint(body, Tuples.flatTupleOf(var_App1, var__virtual_2_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ApplicationInstance", "allocatedTo"))); | ||
565 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); | ||
566 | new Equality(body, var__virtual_2_, var_Host); | ||
567 | // ApplicationInstance.allocatedTo(App2, Host) | ||
568 | new TypeConstraint(body, Tuples.flatTupleOf(var_App2), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance"))); | ||
569 | PVariable var__virtual_3_ = body.getOrCreateVariableByName(".virtual{3}"); | ||
570 | new TypeConstraint(body, Tuples.flatTupleOf(var_App2, var__virtual_3_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ApplicationInstance", "allocatedTo"))); | ||
571 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_3_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); | ||
572 | new Equality(body, var__virtual_3_, var_Host); | ||
573 | bodies.add(body); | ||
574 | } | ||
575 | { | ||
576 | PAnnotation annotation = new PAnnotation("Constraint"); | ||
577 | annotation.addAttribute("severity", "error"); | ||
578 | annotation.addAttribute("key", Arrays.asList(new Object[] { | ||
579 | new ParameterReference("Req") | ||
580 | })); | ||
581 | annotation.addAttribute("message", "Redundant instances must not be allocated to the same host."); | ||
582 | addAnnotation(annotation); | ||
583 | } | ||
584 | return bodies; | ||
585 | } | ||
586 | } | ||
587 | } | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/RemoveHostInstance.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/RemoveHostInstance.java new file mode 100644 index 00000000..1141e898 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/RemoveHostInstance.java | |||
@@ -0,0 +1,579 @@ | |||
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.HostInstance; | ||
7 | import java.util.Arrays; | ||
8 | import java.util.Collection; | ||
9 | import java.util.Collections; | ||
10 | import java.util.LinkedHashSet; | ||
11 | import java.util.List; | ||
12 | import java.util.Objects; | ||
13 | import java.util.Optional; | ||
14 | import java.util.Set; | ||
15 | import java.util.function.Consumer; | ||
16 | import java.util.stream.Collectors; | ||
17 | import java.util.stream.Stream; | ||
18 | import org.apache.log4j.Logger; | ||
19 | import org.eclipse.emf.ecore.EClass; | ||
20 | import org.eclipse.viatra.query.runtime.api.IPatternMatch; | ||
21 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification; | ||
22 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; | ||
23 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; | ||
24 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; | ||
25 | import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; | ||
26 | import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; | ||
27 | import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; | ||
28 | import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; | ||
29 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
30 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | ||
31 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | ||
32 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; | ||
33 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
34 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.NegativePatternCall; | ||
35 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
36 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | ||
37 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; | ||
38 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | ||
39 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; | ||
40 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
41 | import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; | ||
42 | |||
43 | /** | ||
44 | * A pattern-specific query specification that can instantiate Matcher in a type-safe way. | ||
45 | * | ||
46 | * <p>Original source: | ||
47 | * <code><pre> | ||
48 | * pattern removeHostInstance(HostInstance : HostInstance) { | ||
49 | * neg HostInstance.applications(HostInstance, _); | ||
50 | * } | ||
51 | * </pre></code> | ||
52 | * | ||
53 | * @see Matcher | ||
54 | * @see Match | ||
55 | * | ||
56 | */ | ||
57 | @SuppressWarnings("all") | ||
58 | public final class RemoveHostInstance extends BaseGeneratedEMFQuerySpecification<RemoveHostInstance.Matcher> { | ||
59 | /** | ||
60 | * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.removeHostInstance pattern, | ||
61 | * to be used in conjunction with {@link Matcher}. | ||
62 | * | ||
63 | * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. | ||
64 | * Each instance is a (possibly partial) substitution of pattern parameters, | ||
65 | * usable to represent a match of the pattern in the result of a query, | ||
66 | * or to specify the bound (fixed) input parameters when issuing a query. | ||
67 | * | ||
68 | * @see Matcher | ||
69 | * | ||
70 | */ | ||
71 | public static abstract class Match extends BasePatternMatch { | ||
72 | private HostInstance fHostInstance; | ||
73 | |||
74 | private static List<String> parameterNames = makeImmutableList("HostInstance"); | ||
75 | |||
76 | private Match(final HostInstance pHostInstance) { | ||
77 | this.fHostInstance = pHostInstance; | ||
78 | } | ||
79 | |||
80 | @Override | ||
81 | public Object get(final String parameterName) { | ||
82 | if ("HostInstance".equals(parameterName)) return this.fHostInstance; | ||
83 | return null; | ||
84 | } | ||
85 | |||
86 | public HostInstance getHostInstance() { | ||
87 | return this.fHostInstance; | ||
88 | } | ||
89 | |||
90 | @Override | ||
91 | public boolean set(final String parameterName, final Object newValue) { | ||
92 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
93 | if ("HostInstance".equals(parameterName) ) { | ||
94 | this.fHostInstance = (HostInstance) newValue; | ||
95 | return true; | ||
96 | } | ||
97 | return false; | ||
98 | } | ||
99 | |||
100 | public void setHostInstance(final HostInstance pHostInstance) { | ||
101 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
102 | this.fHostInstance = pHostInstance; | ||
103 | } | ||
104 | |||
105 | @Override | ||
106 | public String patternName() { | ||
107 | return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.removeHostInstance"; | ||
108 | } | ||
109 | |||
110 | @Override | ||
111 | public List<String> parameterNames() { | ||
112 | return RemoveHostInstance.Match.parameterNames; | ||
113 | } | ||
114 | |||
115 | @Override | ||
116 | public Object[] toArray() { | ||
117 | return new Object[]{fHostInstance}; | ||
118 | } | ||
119 | |||
120 | @Override | ||
121 | public RemoveHostInstance.Match toImmutable() { | ||
122 | return isMutable() ? newMatch(fHostInstance) : this; | ||
123 | } | ||
124 | |||
125 | @Override | ||
126 | public String prettyPrint() { | ||
127 | StringBuilder result = new StringBuilder(); | ||
128 | result.append("\"HostInstance\"=" + prettyPrintValue(fHostInstance)); | ||
129 | return result.toString(); | ||
130 | } | ||
131 | |||
132 | @Override | ||
133 | public int hashCode() { | ||
134 | return Objects.hash(fHostInstance); | ||
135 | } | ||
136 | |||
137 | @Override | ||
138 | public boolean equals(final Object obj) { | ||
139 | if (this == obj) | ||
140 | return true; | ||
141 | if (obj == null) { | ||
142 | return false; | ||
143 | } | ||
144 | if ((obj instanceof RemoveHostInstance.Match)) { | ||
145 | RemoveHostInstance.Match other = (RemoveHostInstance.Match) obj; | ||
146 | return Objects.equals(fHostInstance, other.fHostInstance); | ||
147 | } else { | ||
148 | // this should be infrequent | ||
149 | if (!(obj instanceof IPatternMatch)) { | ||
150 | return false; | ||
151 | } | ||
152 | IPatternMatch otherSig = (IPatternMatch) obj; | ||
153 | return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); | ||
154 | } | ||
155 | } | ||
156 | |||
157 | @Override | ||
158 | public RemoveHostInstance specification() { | ||
159 | return RemoveHostInstance.instance(); | ||
160 | } | ||
161 | |||
162 | /** | ||
163 | * Returns an empty, mutable match. | ||
164 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
165 | * | ||
166 | * @return the empty match. | ||
167 | * | ||
168 | */ | ||
169 | public static RemoveHostInstance.Match newEmptyMatch() { | ||
170 | return new Mutable(null); | ||
171 | } | ||
172 | |||
173 | /** | ||
174 | * Returns a mutable (partial) match. | ||
175 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
176 | * | ||
177 | * @param pHostInstance the fixed value of pattern parameter HostInstance, or null if not bound. | ||
178 | * @return the new, mutable (partial) match object. | ||
179 | * | ||
180 | */ | ||
181 | public static RemoveHostInstance.Match newMutableMatch(final HostInstance pHostInstance) { | ||
182 | return new Mutable(pHostInstance); | ||
183 | } | ||
184 | |||
185 | /** | ||
186 | * Returns a new (partial) match. | ||
187 | * This can be used e.g. to call the matcher with a partial match. | ||
188 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
189 | * @param pHostInstance the fixed value of pattern parameter HostInstance, or null if not bound. | ||
190 | * @return the (partial) match object. | ||
191 | * | ||
192 | */ | ||
193 | public static RemoveHostInstance.Match newMatch(final HostInstance pHostInstance) { | ||
194 | return new Immutable(pHostInstance); | ||
195 | } | ||
196 | |||
197 | private static final class Mutable extends RemoveHostInstance.Match { | ||
198 | Mutable(final HostInstance pHostInstance) { | ||
199 | super(pHostInstance); | ||
200 | } | ||
201 | |||
202 | @Override | ||
203 | public boolean isMutable() { | ||
204 | return true; | ||
205 | } | ||
206 | } | ||
207 | |||
208 | private static final class Immutable extends RemoveHostInstance.Match { | ||
209 | Immutable(final HostInstance pHostInstance) { | ||
210 | super(pHostInstance); | ||
211 | } | ||
212 | |||
213 | @Override | ||
214 | public boolean isMutable() { | ||
215 | return false; | ||
216 | } | ||
217 | } | ||
218 | } | ||
219 | |||
220 | /** | ||
221 | * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.removeHostInstance pattern, | ||
222 | * providing pattern-specific query methods. | ||
223 | * | ||
224 | * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, | ||
225 | * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. | ||
226 | * | ||
227 | * <p>Matches of the pattern will be represented as {@link Match}. | ||
228 | * | ||
229 | * <p>Original source: | ||
230 | * <code><pre> | ||
231 | * pattern removeHostInstance(HostInstance : HostInstance) { | ||
232 | * neg HostInstance.applications(HostInstance, _); | ||
233 | * } | ||
234 | * </pre></code> | ||
235 | * | ||
236 | * @see Match | ||
237 | * @see RemoveHostInstance | ||
238 | * | ||
239 | */ | ||
240 | public static class Matcher extends BaseMatcher<RemoveHostInstance.Match> { | ||
241 | /** | ||
242 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
243 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
244 | * | ||
245 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
246 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
247 | * | ||
248 | */ | ||
249 | public static RemoveHostInstance.Matcher on(final ViatraQueryEngine engine) { | ||
250 | // check if matcher already exists | ||
251 | Matcher matcher = engine.getExistingMatcher(querySpecification()); | ||
252 | if (matcher == null) { | ||
253 | matcher = (Matcher)engine.getMatcher(querySpecification()); | ||
254 | } | ||
255 | return matcher; | ||
256 | } | ||
257 | |||
258 | /** | ||
259 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
260 | * @return an initialized matcher | ||
261 | * @noreference This method is for internal matcher initialization by the framework, do not call it manually. | ||
262 | * | ||
263 | */ | ||
264 | public static RemoveHostInstance.Matcher create() { | ||
265 | return new Matcher(); | ||
266 | } | ||
267 | |||
268 | private static final int POSITION_HOSTINSTANCE = 0; | ||
269 | |||
270 | private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(RemoveHostInstance.Matcher.class); | ||
271 | |||
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 | private Matcher() { | ||
281 | super(querySpecification()); | ||
282 | } | ||
283 | |||
284 | /** | ||
285 | * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. | ||
286 | * @param pHostInstance the fixed value of pattern parameter HostInstance, or null if not bound. | ||
287 | * @return matches represented as a Match object. | ||
288 | * | ||
289 | */ | ||
290 | public Collection<RemoveHostInstance.Match> getAllMatches(final HostInstance pHostInstance) { | ||
291 | return rawStreamAllMatches(new Object[]{pHostInstance}).collect(Collectors.toSet()); | ||
292 | } | ||
293 | |||
294 | /** | ||
295 | * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. | ||
296 | * </p> | ||
297 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
298 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
299 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
300 | * @param pHostInstance the fixed value of pattern parameter HostInstance, or null if not bound. | ||
301 | * @return a stream of matches represented as a Match object. | ||
302 | * | ||
303 | */ | ||
304 | public Stream<RemoveHostInstance.Match> streamAllMatches(final HostInstance pHostInstance) { | ||
305 | return rawStreamAllMatches(new Object[]{pHostInstance}); | ||
306 | } | ||
307 | |||
308 | /** | ||
309 | * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
310 | * Neither determinism nor randomness of selection is guaranteed. | ||
311 | * @param pHostInstance the fixed value of pattern parameter HostInstance, or null if not bound. | ||
312 | * @return a match represented as a Match object, or null if no match is found. | ||
313 | * | ||
314 | */ | ||
315 | public Optional<RemoveHostInstance.Match> getOneArbitraryMatch(final HostInstance pHostInstance) { | ||
316 | return rawGetOneArbitraryMatch(new Object[]{pHostInstance}); | ||
317 | } | ||
318 | |||
319 | /** | ||
320 | * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, | ||
321 | * under any possible substitution of the unspecified parameters (if any). | ||
322 | * @param pHostInstance the fixed value of pattern parameter HostInstance, or null if not bound. | ||
323 | * @return true if the input is a valid (partial) match of the pattern. | ||
324 | * | ||
325 | */ | ||
326 | public boolean hasMatch(final HostInstance pHostInstance) { | ||
327 | return rawHasMatch(new Object[]{pHostInstance}); | ||
328 | } | ||
329 | |||
330 | /** | ||
331 | * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. | ||
332 | * @param pHostInstance the fixed value of pattern parameter HostInstance, or null if not bound. | ||
333 | * @return the number of pattern matches found. | ||
334 | * | ||
335 | */ | ||
336 | public int countMatches(final HostInstance pHostInstance) { | ||
337 | return rawCountMatches(new Object[]{pHostInstance}); | ||
338 | } | ||
339 | |||
340 | /** | ||
341 | * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
342 | * Neither determinism nor randomness of selection is guaranteed. | ||
343 | * @param pHostInstance the fixed value of pattern parameter HostInstance, or null if not bound. | ||
344 | * @param processor the action that will process the selected match. | ||
345 | * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked | ||
346 | * | ||
347 | */ | ||
348 | public boolean forOneArbitraryMatch(final HostInstance pHostInstance, final Consumer<? super RemoveHostInstance.Match> processor) { | ||
349 | return rawForOneArbitraryMatch(new Object[]{pHostInstance}, processor); | ||
350 | } | ||
351 | |||
352 | /** | ||
353 | * Returns a new (partial) match. | ||
354 | * This can be used e.g. to call the matcher with a partial match. | ||
355 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
356 | * @param pHostInstance the fixed value of pattern parameter HostInstance, or null if not bound. | ||
357 | * @return the (partial) match object. | ||
358 | * | ||
359 | */ | ||
360 | public RemoveHostInstance.Match newMatch(final HostInstance pHostInstance) { | ||
361 | return RemoveHostInstance.Match.newMatch(pHostInstance); | ||
362 | } | ||
363 | |||
364 | /** | ||
365 | * Retrieve the set of values that occur in matches for HostInstance. | ||
366 | * @return the Set of all values or empty set if there are no matches | ||
367 | * | ||
368 | */ | ||
369 | protected Stream<HostInstance> rawStreamAllValuesOfHostInstance(final Object[] parameters) { | ||
370 | return rawStreamAllValues(POSITION_HOSTINSTANCE, parameters).map(HostInstance.class::cast); | ||
371 | } | ||
372 | |||
373 | /** | ||
374 | * Retrieve the set of values that occur in matches for HostInstance. | ||
375 | * @return the Set of all values or empty set if there are no matches | ||
376 | * | ||
377 | */ | ||
378 | public Set<HostInstance> getAllValuesOfHostInstance() { | ||
379 | return rawStreamAllValuesOfHostInstance(emptyArray()).collect(Collectors.toSet()); | ||
380 | } | ||
381 | |||
382 | /** | ||
383 | * Retrieve the set of values that occur in matches for HostInstance. | ||
384 | * @return the Set of all values or empty set if there are no matches | ||
385 | * | ||
386 | */ | ||
387 | public Stream<HostInstance> streamAllValuesOfHostInstance() { | ||
388 | return rawStreamAllValuesOfHostInstance(emptyArray()); | ||
389 | } | ||
390 | |||
391 | @Override | ||
392 | protected RemoveHostInstance.Match tupleToMatch(final Tuple t) { | ||
393 | try { | ||
394 | return RemoveHostInstance.Match.newMatch((HostInstance) t.get(POSITION_HOSTINSTANCE)); | ||
395 | } catch(ClassCastException e) { | ||
396 | LOGGER.error("Element(s) in tuple not properly typed!",e); | ||
397 | return null; | ||
398 | } | ||
399 | } | ||
400 | |||
401 | @Override | ||
402 | protected RemoveHostInstance.Match arrayToMatch(final Object[] match) { | ||
403 | try { | ||
404 | return RemoveHostInstance.Match.newMatch((HostInstance) match[POSITION_HOSTINSTANCE]); | ||
405 | } catch(ClassCastException e) { | ||
406 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
407 | return null; | ||
408 | } | ||
409 | } | ||
410 | |||
411 | @Override | ||
412 | protected RemoveHostInstance.Match arrayToMatchMutable(final Object[] match) { | ||
413 | try { | ||
414 | return RemoveHostInstance.Match.newMutableMatch((HostInstance) match[POSITION_HOSTINSTANCE]); | ||
415 | } catch(ClassCastException e) { | ||
416 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
417 | return null; | ||
418 | } | ||
419 | } | ||
420 | |||
421 | /** | ||
422 | * @return the singleton instance of the query specification of this pattern | ||
423 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
424 | * | ||
425 | */ | ||
426 | public static IQuerySpecification<RemoveHostInstance.Matcher> querySpecification() { | ||
427 | return RemoveHostInstance.instance(); | ||
428 | } | ||
429 | } | ||
430 | |||
431 | private RemoveHostInstance() { | ||
432 | super(GeneratedPQuery.INSTANCE); | ||
433 | } | ||
434 | |||
435 | /** | ||
436 | * @return the singleton instance of the query specification | ||
437 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
438 | * | ||
439 | */ | ||
440 | public static RemoveHostInstance instance() { | ||
441 | try{ | ||
442 | return LazyHolder.INSTANCE; | ||
443 | } catch (ExceptionInInitializerError err) { | ||
444 | throw processInitializerError(err); | ||
445 | } | ||
446 | } | ||
447 | |||
448 | @Override | ||
449 | protected RemoveHostInstance.Matcher instantiate(final ViatraQueryEngine engine) { | ||
450 | return RemoveHostInstance.Matcher.on(engine); | ||
451 | } | ||
452 | |||
453 | @Override | ||
454 | public RemoveHostInstance.Matcher instantiate() { | ||
455 | return RemoveHostInstance.Matcher.create(); | ||
456 | } | ||
457 | |||
458 | @Override | ||
459 | public RemoveHostInstance.Match newEmptyMatch() { | ||
460 | return RemoveHostInstance.Match.newEmptyMatch(); | ||
461 | } | ||
462 | |||
463 | @Override | ||
464 | public RemoveHostInstance.Match newMatch(final Object... parameters) { | ||
465 | return RemoveHostInstance.Match.newMatch((hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance) parameters[0]); | ||
466 | } | ||
467 | |||
468 | /** | ||
469 | * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.RemoveHostInstance (visibility: PUBLIC, simpleName: RemoveHostInstance, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.RemoveHostInstance, 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 | ||
470 | * <b>not</b> at the class load time of the outer class, | ||
471 | * but rather at the first call to {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.RemoveHostInstance (visibility: PUBLIC, simpleName: RemoveHostInstance, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.RemoveHostInstance, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}. | ||
472 | * | ||
473 | * <p> This workaround is required e.g. to support recursion. | ||
474 | * | ||
475 | */ | ||
476 | private static class LazyHolder { | ||
477 | private static final RemoveHostInstance INSTANCE = new RemoveHostInstance(); | ||
478 | |||
479 | /** | ||
480 | * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned. | ||
481 | * This initialization order is required to support indirect recursion. | ||
482 | * | ||
483 | * <p> The static initializer is defined using a helper field to work around limitations of the code generator. | ||
484 | * | ||
485 | */ | ||
486 | private static final Object STATIC_INITIALIZER = ensureInitialized(); | ||
487 | |||
488 | public static Object ensureInitialized() { | ||
489 | INSTANCE.ensureInitializedInternal(); | ||
490 | return null; | ||
491 | } | ||
492 | } | ||
493 | |||
494 | private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { | ||
495 | private static final RemoveHostInstance.GeneratedPQuery INSTANCE = new GeneratedPQuery(); | ||
496 | |||
497 | private final PParameter parameter_HostInstance = new PParameter("HostInstance", "hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "HostInstance")), PParameterDirection.INOUT); | ||
498 | |||
499 | private final List<PParameter> parameters = Arrays.asList(parameter_HostInstance); | ||
500 | |||
501 | private class Embedded_1_HostInstance_applications extends BaseGeneratedEMFPQuery { | ||
502 | private final PParameter parameter_p0 = new PParameter("p0", "hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "HostInstance")), PParameterDirection.INOUT); | ||
503 | |||
504 | private final PParameter parameter_p1 = new PParameter("p1", "hu.bme.mit.inf.dslreasoner.domains.cps.ApplicationInstance", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "ApplicationInstance")), PParameterDirection.INOUT); | ||
505 | |||
506 | private final List<PParameter> embeddedParameters = Arrays.asList(parameter_p0, parameter_p1); | ||
507 | |||
508 | public Embedded_1_HostInstance_applications() { | ||
509 | super(PVisibility.EMBEDDED); | ||
510 | } | ||
511 | |||
512 | @Override | ||
513 | public String getFullyQualifiedName() { | ||
514 | return GeneratedPQuery.this.getFullyQualifiedName() + "$Embedded_1_HostInstance_applications"; | ||
515 | } | ||
516 | |||
517 | @Override | ||
518 | public List<PParameter> getParameters() { | ||
519 | return embeddedParameters; | ||
520 | } | ||
521 | |||
522 | @Override | ||
523 | public Set<PBody> doGetContainedBodies() { | ||
524 | PBody body = new PBody(this); | ||
525 | PVariable var_p0 = body.getOrCreateVariableByName("p0"); | ||
526 | PVariable var_p1 = body.getOrCreateVariableByName("p1"); | ||
527 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
528 | new ExportedParameter(body, var_p0, parameter_p0), | ||
529 | new ExportedParameter(body, var_p1, parameter_p1) | ||
530 | )); | ||
531 | // HostInstance.applications(HostInstance, _) | ||
532 | new TypeConstraint(body, Tuples.flatTupleOf(var_p0), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); | ||
533 | PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); | ||
534 | new TypeConstraint(body, Tuples.flatTupleOf(var_p0, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "HostInstance", "applications"))); | ||
535 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance"))); | ||
536 | new Equality(body, var__virtual_0_, var_p1); | ||
537 | return Collections.singleton(body); | ||
538 | } | ||
539 | } | ||
540 | |||
541 | private GeneratedPQuery() { | ||
542 | super(PVisibility.PUBLIC); | ||
543 | } | ||
544 | |||
545 | @Override | ||
546 | public String getFullyQualifiedName() { | ||
547 | return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.removeHostInstance"; | ||
548 | } | ||
549 | |||
550 | @Override | ||
551 | public List<String> getParameterNames() { | ||
552 | return Arrays.asList("HostInstance"); | ||
553 | } | ||
554 | |||
555 | @Override | ||
556 | public List<PParameter> getParameters() { | ||
557 | return parameters; | ||
558 | } | ||
559 | |||
560 | @Override | ||
561 | public Set<PBody> doGetContainedBodies() { | ||
562 | setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); | ||
563 | Set<PBody> bodies = new LinkedHashSet<>(); | ||
564 | { | ||
565 | PBody body = new PBody(this); | ||
566 | PVariable var_HostInstance = body.getOrCreateVariableByName("HostInstance"); | ||
567 | PVariable var___0_ = body.getOrCreateVariableByName("_<0>"); | ||
568 | new TypeConstraint(body, Tuples.flatTupleOf(var_HostInstance), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); | ||
569 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
570 | new ExportedParameter(body, var_HostInstance, parameter_HostInstance) | ||
571 | )); | ||
572 | // neg HostInstance.applications(HostInstance, _) | ||
573 | new NegativePatternCall(body, Tuples.flatTupleOf(var_HostInstance, var___0_), new RemoveHostInstance.GeneratedPQuery.Embedded_1_HostInstance_applications()); | ||
574 | bodies.add(body); | ||
575 | } | ||
576 | return bodies; | ||
577 | } | ||
578 | } | ||
579 | } | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/RequirementNotSatisfied.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/RequirementNotSatisfied.java new file mode 100644 index 00000000..04066c50 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/RequirementNotSatisfied.java | |||
@@ -0,0 +1,597 @@ | |||
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.Requirement; | ||
7 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.SatisfyingInstance; | ||
8 | import java.util.Arrays; | ||
9 | import java.util.Collection; | ||
10 | import java.util.LinkedHashSet; | ||
11 | import java.util.List; | ||
12 | import java.util.Objects; | ||
13 | import java.util.Optional; | ||
14 | import java.util.Set; | ||
15 | import java.util.function.Consumer; | ||
16 | import java.util.stream.Collectors; | ||
17 | import java.util.stream.Stream; | ||
18 | import org.apache.log4j.Logger; | ||
19 | import org.eclipse.emf.ecore.EClass; | ||
20 | import org.eclipse.emf.ecore.EDataType; | ||
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.emf.types.EDataTypeInSlotsKey; | ||
30 | import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; | ||
31 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
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.annotations.PAnnotation; | ||
37 | import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference; | ||
38 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; | ||
39 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
40 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation; | ||
41 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.PatternMatchCounter; | ||
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 | * {@literal @}Constraint(severity = "error", key = {Req}, | ||
56 | * message = "Requirement is not satisfied by enough application instances.") | ||
57 | * pattern requirementNotSatisfied(Req : Requirement) { | ||
58 | * Instances == count find satisfyingInstance(Req, _); | ||
59 | * Requirement.count(Req, RequiredCount); | ||
60 | * check(Instances {@literal <} RequiredCount); | ||
61 | * } | ||
62 | * </pre></code> | ||
63 | * | ||
64 | * @see Matcher | ||
65 | * @see Match | ||
66 | * | ||
67 | */ | ||
68 | @SuppressWarnings("all") | ||
69 | public final class RequirementNotSatisfied extends BaseGeneratedEMFQuerySpecification<RequirementNotSatisfied.Matcher> { | ||
70 | /** | ||
71 | * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.requirementNotSatisfied pattern, | ||
72 | * to be used in conjunction with {@link Matcher}. | ||
73 | * | ||
74 | * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. | ||
75 | * Each instance is a (possibly partial) substitution of pattern parameters, | ||
76 | * usable to represent a match of the pattern in the result of a query, | ||
77 | * or to specify the bound (fixed) input parameters when issuing a query. | ||
78 | * | ||
79 | * @see Matcher | ||
80 | * | ||
81 | */ | ||
82 | public static abstract class Match extends BasePatternMatch { | ||
83 | private Requirement fReq; | ||
84 | |||
85 | private static List<String> parameterNames = makeImmutableList("Req"); | ||
86 | |||
87 | private Match(final Requirement pReq) { | ||
88 | this.fReq = pReq; | ||
89 | } | ||
90 | |||
91 | @Override | ||
92 | public Object get(final String parameterName) { | ||
93 | if ("Req".equals(parameterName)) return this.fReq; | ||
94 | return null; | ||
95 | } | ||
96 | |||
97 | public Requirement getReq() { | ||
98 | return this.fReq; | ||
99 | } | ||
100 | |||
101 | @Override | ||
102 | public boolean set(final String parameterName, final Object newValue) { | ||
103 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
104 | if ("Req".equals(parameterName) ) { | ||
105 | this.fReq = (Requirement) newValue; | ||
106 | return true; | ||
107 | } | ||
108 | return false; | ||
109 | } | ||
110 | |||
111 | public void setReq(final Requirement pReq) { | ||
112 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
113 | this.fReq = pReq; | ||
114 | } | ||
115 | |||
116 | @Override | ||
117 | public String patternName() { | ||
118 | return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.requirementNotSatisfied"; | ||
119 | } | ||
120 | |||
121 | @Override | ||
122 | public List<String> parameterNames() { | ||
123 | return RequirementNotSatisfied.Match.parameterNames; | ||
124 | } | ||
125 | |||
126 | @Override | ||
127 | public Object[] toArray() { | ||
128 | return new Object[]{fReq}; | ||
129 | } | ||
130 | |||
131 | @Override | ||
132 | public RequirementNotSatisfied.Match toImmutable() { | ||
133 | return isMutable() ? newMatch(fReq) : this; | ||
134 | } | ||
135 | |||
136 | @Override | ||
137 | public String prettyPrint() { | ||
138 | StringBuilder result = new StringBuilder(); | ||
139 | result.append("\"Req\"=" + prettyPrintValue(fReq)); | ||
140 | return result.toString(); | ||
141 | } | ||
142 | |||
143 | @Override | ||
144 | public int hashCode() { | ||
145 | return Objects.hash(fReq); | ||
146 | } | ||
147 | |||
148 | @Override | ||
149 | public boolean equals(final Object obj) { | ||
150 | if (this == obj) | ||
151 | return true; | ||
152 | if (obj == null) { | ||
153 | return false; | ||
154 | } | ||
155 | if ((obj instanceof RequirementNotSatisfied.Match)) { | ||
156 | RequirementNotSatisfied.Match other = (RequirementNotSatisfied.Match) obj; | ||
157 | return Objects.equals(fReq, other.fReq); | ||
158 | } else { | ||
159 | // this should be infrequent | ||
160 | if (!(obj instanceof IPatternMatch)) { | ||
161 | return false; | ||
162 | } | ||
163 | IPatternMatch otherSig = (IPatternMatch) obj; | ||
164 | return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); | ||
165 | } | ||
166 | } | ||
167 | |||
168 | @Override | ||
169 | public RequirementNotSatisfied specification() { | ||
170 | return RequirementNotSatisfied.instance(); | ||
171 | } | ||
172 | |||
173 | /** | ||
174 | * Returns an empty, mutable match. | ||
175 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
176 | * | ||
177 | * @return the empty match. | ||
178 | * | ||
179 | */ | ||
180 | public static RequirementNotSatisfied.Match newEmptyMatch() { | ||
181 | return new Mutable(null); | ||
182 | } | ||
183 | |||
184 | /** | ||
185 | * Returns a mutable (partial) match. | ||
186 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
187 | * | ||
188 | * @param pReq the fixed value of pattern parameter Req, or null if not bound. | ||
189 | * @return the new, mutable (partial) match object. | ||
190 | * | ||
191 | */ | ||
192 | public static RequirementNotSatisfied.Match newMutableMatch(final Requirement pReq) { | ||
193 | return new Mutable(pReq); | ||
194 | } | ||
195 | |||
196 | /** | ||
197 | * Returns a new (partial) match. | ||
198 | * This can be used e.g. to call the matcher with a partial match. | ||
199 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
200 | * @param pReq the fixed value of pattern parameter Req, or null if not bound. | ||
201 | * @return the (partial) match object. | ||
202 | * | ||
203 | */ | ||
204 | public static RequirementNotSatisfied.Match newMatch(final Requirement pReq) { | ||
205 | return new Immutable(pReq); | ||
206 | } | ||
207 | |||
208 | private static final class Mutable extends RequirementNotSatisfied.Match { | ||
209 | Mutable(final Requirement pReq) { | ||
210 | super(pReq); | ||
211 | } | ||
212 | |||
213 | @Override | ||
214 | public boolean isMutable() { | ||
215 | return true; | ||
216 | } | ||
217 | } | ||
218 | |||
219 | private static final class Immutable extends RequirementNotSatisfied.Match { | ||
220 | Immutable(final Requirement pReq) { | ||
221 | super(pReq); | ||
222 | } | ||
223 | |||
224 | @Override | ||
225 | public boolean isMutable() { | ||
226 | return false; | ||
227 | } | ||
228 | } | ||
229 | } | ||
230 | |||
231 | /** | ||
232 | * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.requirementNotSatisfied pattern, | ||
233 | * providing pattern-specific query methods. | ||
234 | * | ||
235 | * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, | ||
236 | * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. | ||
237 | * | ||
238 | * <p>Matches of the pattern will be represented as {@link Match}. | ||
239 | * | ||
240 | * <p>Original source: | ||
241 | * <code><pre> | ||
242 | * {@literal @}Constraint(severity = "error", key = {Req}, | ||
243 | * message = "Requirement is not satisfied by enough application instances.") | ||
244 | * pattern requirementNotSatisfied(Req : Requirement) { | ||
245 | * Instances == count find satisfyingInstance(Req, _); | ||
246 | * Requirement.count(Req, RequiredCount); | ||
247 | * check(Instances {@literal <} RequiredCount); | ||
248 | * } | ||
249 | * </pre></code> | ||
250 | * | ||
251 | * @see Match | ||
252 | * @see RequirementNotSatisfied | ||
253 | * | ||
254 | */ | ||
255 | public static class Matcher extends BaseMatcher<RequirementNotSatisfied.Match> { | ||
256 | /** | ||
257 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
258 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
259 | * | ||
260 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
261 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
262 | * | ||
263 | */ | ||
264 | public static RequirementNotSatisfied.Matcher on(final ViatraQueryEngine engine) { | ||
265 | // check if matcher already exists | ||
266 | Matcher matcher = engine.getExistingMatcher(querySpecification()); | ||
267 | if (matcher == null) { | ||
268 | matcher = (Matcher)engine.getMatcher(querySpecification()); | ||
269 | } | ||
270 | return matcher; | ||
271 | } | ||
272 | |||
273 | /** | ||
274 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
275 | * @return an initialized matcher | ||
276 | * @noreference This method is for internal matcher initialization by the framework, do not call it manually. | ||
277 | * | ||
278 | */ | ||
279 | public static RequirementNotSatisfied.Matcher create() { | ||
280 | return new Matcher(); | ||
281 | } | ||
282 | |||
283 | private static final int POSITION_REQ = 0; | ||
284 | |||
285 | private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(RequirementNotSatisfied.Matcher.class); | ||
286 | |||
287 | /** | ||
288 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
289 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
290 | * | ||
291 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
292 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
293 | * | ||
294 | */ | ||
295 | private Matcher() { | ||
296 | super(querySpecification()); | ||
297 | } | ||
298 | |||
299 | /** | ||
300 | * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. | ||
301 | * @param pReq the fixed value of pattern parameter Req, or null if not bound. | ||
302 | * @return matches represented as a Match object. | ||
303 | * | ||
304 | */ | ||
305 | public Collection<RequirementNotSatisfied.Match> getAllMatches(final Requirement pReq) { | ||
306 | return rawStreamAllMatches(new Object[]{pReq}).collect(Collectors.toSet()); | ||
307 | } | ||
308 | |||
309 | /** | ||
310 | * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. | ||
311 | * </p> | ||
312 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
313 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
314 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
315 | * @param pReq the fixed value of pattern parameter Req, or null if not bound. | ||
316 | * @return a stream of matches represented as a Match object. | ||
317 | * | ||
318 | */ | ||
319 | public Stream<RequirementNotSatisfied.Match> streamAllMatches(final Requirement pReq) { | ||
320 | return rawStreamAllMatches(new Object[]{pReq}); | ||
321 | } | ||
322 | |||
323 | /** | ||
324 | * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
325 | * Neither determinism nor randomness of selection is guaranteed. | ||
326 | * @param pReq the fixed value of pattern parameter Req, or null if not bound. | ||
327 | * @return a match represented as a Match object, or null if no match is found. | ||
328 | * | ||
329 | */ | ||
330 | public Optional<RequirementNotSatisfied.Match> getOneArbitraryMatch(final Requirement pReq) { | ||
331 | return rawGetOneArbitraryMatch(new Object[]{pReq}); | ||
332 | } | ||
333 | |||
334 | /** | ||
335 | * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, | ||
336 | * under any possible substitution of the unspecified parameters (if any). | ||
337 | * @param pReq the fixed value of pattern parameter Req, or null if not bound. | ||
338 | * @return true if the input is a valid (partial) match of the pattern. | ||
339 | * | ||
340 | */ | ||
341 | public boolean hasMatch(final Requirement pReq) { | ||
342 | return rawHasMatch(new Object[]{pReq}); | ||
343 | } | ||
344 | |||
345 | /** | ||
346 | * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. | ||
347 | * @param pReq the fixed value of pattern parameter Req, or null if not bound. | ||
348 | * @return the number of pattern matches found. | ||
349 | * | ||
350 | */ | ||
351 | public int countMatches(final Requirement pReq) { | ||
352 | return rawCountMatches(new Object[]{pReq}); | ||
353 | } | ||
354 | |||
355 | /** | ||
356 | * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
357 | * Neither determinism nor randomness of selection is guaranteed. | ||
358 | * @param pReq the fixed value of pattern parameter Req, or null if not bound. | ||
359 | * @param processor the action that will process the selected match. | ||
360 | * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked | ||
361 | * | ||
362 | */ | ||
363 | public boolean forOneArbitraryMatch(final Requirement pReq, final Consumer<? super RequirementNotSatisfied.Match> processor) { | ||
364 | return rawForOneArbitraryMatch(new Object[]{pReq}, processor); | ||
365 | } | ||
366 | |||
367 | /** | ||
368 | * Returns a new (partial) match. | ||
369 | * This can be used e.g. to call the matcher with a partial match. | ||
370 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
371 | * @param pReq the fixed value of pattern parameter Req, or null if not bound. | ||
372 | * @return the (partial) match object. | ||
373 | * | ||
374 | */ | ||
375 | public RequirementNotSatisfied.Match newMatch(final Requirement pReq) { | ||
376 | return RequirementNotSatisfied.Match.newMatch(pReq); | ||
377 | } | ||
378 | |||
379 | /** | ||
380 | * Retrieve the set of values that occur in matches for Req. | ||
381 | * @return the Set of all values or empty set if there are no matches | ||
382 | * | ||
383 | */ | ||
384 | protected Stream<Requirement> rawStreamAllValuesOfReq(final Object[] parameters) { | ||
385 | return rawStreamAllValues(POSITION_REQ, parameters).map(Requirement.class::cast); | ||
386 | } | ||
387 | |||
388 | /** | ||
389 | * Retrieve the set of values that occur in matches for Req. | ||
390 | * @return the Set of all values or empty set if there are no matches | ||
391 | * | ||
392 | */ | ||
393 | public Set<Requirement> getAllValuesOfReq() { | ||
394 | return rawStreamAllValuesOfReq(emptyArray()).collect(Collectors.toSet()); | ||
395 | } | ||
396 | |||
397 | /** | ||
398 | * Retrieve the set of values that occur in matches for Req. | ||
399 | * @return the Set of all values or empty set if there are no matches | ||
400 | * | ||
401 | */ | ||
402 | public Stream<Requirement> streamAllValuesOfReq() { | ||
403 | return rawStreamAllValuesOfReq(emptyArray()); | ||
404 | } | ||
405 | |||
406 | @Override | ||
407 | protected RequirementNotSatisfied.Match tupleToMatch(final Tuple t) { | ||
408 | try { | ||
409 | return RequirementNotSatisfied.Match.newMatch((Requirement) t.get(POSITION_REQ)); | ||
410 | } catch(ClassCastException e) { | ||
411 | LOGGER.error("Element(s) in tuple not properly typed!",e); | ||
412 | return null; | ||
413 | } | ||
414 | } | ||
415 | |||
416 | @Override | ||
417 | protected RequirementNotSatisfied.Match arrayToMatch(final Object[] match) { | ||
418 | try { | ||
419 | return RequirementNotSatisfied.Match.newMatch((Requirement) match[POSITION_REQ]); | ||
420 | } catch(ClassCastException e) { | ||
421 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
422 | return null; | ||
423 | } | ||
424 | } | ||
425 | |||
426 | @Override | ||
427 | protected RequirementNotSatisfied.Match arrayToMatchMutable(final Object[] match) { | ||
428 | try { | ||
429 | return RequirementNotSatisfied.Match.newMutableMatch((Requirement) match[POSITION_REQ]); | ||
430 | } catch(ClassCastException e) { | ||
431 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
432 | return null; | ||
433 | } | ||
434 | } | ||
435 | |||
436 | /** | ||
437 | * @return the singleton instance of the query specification of this pattern | ||
438 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
439 | * | ||
440 | */ | ||
441 | public static IQuerySpecification<RequirementNotSatisfied.Matcher> querySpecification() { | ||
442 | return RequirementNotSatisfied.instance(); | ||
443 | } | ||
444 | } | ||
445 | |||
446 | private RequirementNotSatisfied() { | ||
447 | super(GeneratedPQuery.INSTANCE); | ||
448 | } | ||
449 | |||
450 | /** | ||
451 | * @return the singleton instance of the query specification | ||
452 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
453 | * | ||
454 | */ | ||
455 | public static RequirementNotSatisfied instance() { | ||
456 | try{ | ||
457 | return LazyHolder.INSTANCE; | ||
458 | } catch (ExceptionInInitializerError err) { | ||
459 | throw processInitializerError(err); | ||
460 | } | ||
461 | } | ||
462 | |||
463 | @Override | ||
464 | protected RequirementNotSatisfied.Matcher instantiate(final ViatraQueryEngine engine) { | ||
465 | return RequirementNotSatisfied.Matcher.on(engine); | ||
466 | } | ||
467 | |||
468 | @Override | ||
469 | public RequirementNotSatisfied.Matcher instantiate() { | ||
470 | return RequirementNotSatisfied.Matcher.create(); | ||
471 | } | ||
472 | |||
473 | @Override | ||
474 | public RequirementNotSatisfied.Match newEmptyMatch() { | ||
475 | return RequirementNotSatisfied.Match.newEmptyMatch(); | ||
476 | } | ||
477 | |||
478 | @Override | ||
479 | public RequirementNotSatisfied.Match newMatch(final Object... parameters) { | ||
480 | return RequirementNotSatisfied.Match.newMatch((hu.bme.mit.inf.dslreasoner.domains.cps.Requirement) parameters[0]); | ||
481 | } | ||
482 | |||
483 | /** | ||
484 | * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.RequirementNotSatisfied (visibility: PUBLIC, simpleName: RequirementNotSatisfied, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.RequirementNotSatisfied, 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 | ||
485 | * <b>not</b> at the class load time of the outer class, | ||
486 | * but rather at the first call to {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.RequirementNotSatisfied (visibility: PUBLIC, simpleName: RequirementNotSatisfied, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.RequirementNotSatisfied, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}. | ||
487 | * | ||
488 | * <p> This workaround is required e.g. to support recursion. | ||
489 | * | ||
490 | */ | ||
491 | private static class LazyHolder { | ||
492 | private static final RequirementNotSatisfied INSTANCE = new RequirementNotSatisfied(); | ||
493 | |||
494 | /** | ||
495 | * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned. | ||
496 | * This initialization order is required to support indirect recursion. | ||
497 | * | ||
498 | * <p> The static initializer is defined using a helper field to work around limitations of the code generator. | ||
499 | * | ||
500 | */ | ||
501 | private static final Object STATIC_INITIALIZER = ensureInitialized(); | ||
502 | |||
503 | public static Object ensureInitialized() { | ||
504 | INSTANCE.ensureInitializedInternal(); | ||
505 | return null; | ||
506 | } | ||
507 | } | ||
508 | |||
509 | private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { | ||
510 | private static final RequirementNotSatisfied.GeneratedPQuery INSTANCE = new GeneratedPQuery(); | ||
511 | |||
512 | private final PParameter parameter_Req = new PParameter("Req", "hu.bme.mit.inf.dslreasoner.domains.cps.Requirement", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "Requirement")), PParameterDirection.INOUT); | ||
513 | |||
514 | private final List<PParameter> parameters = Arrays.asList(parameter_Req); | ||
515 | |||
516 | private GeneratedPQuery() { | ||
517 | super(PVisibility.PUBLIC); | ||
518 | } | ||
519 | |||
520 | @Override | ||
521 | public String getFullyQualifiedName() { | ||
522 | return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.requirementNotSatisfied"; | ||
523 | } | ||
524 | |||
525 | @Override | ||
526 | public List<String> getParameterNames() { | ||
527 | return Arrays.asList("Req"); | ||
528 | } | ||
529 | |||
530 | @Override | ||
531 | public List<PParameter> getParameters() { | ||
532 | return parameters; | ||
533 | } | ||
534 | |||
535 | @Override | ||
536 | public Set<PBody> doGetContainedBodies() { | ||
537 | setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); | ||
538 | Set<PBody> bodies = new LinkedHashSet<>(); | ||
539 | { | ||
540 | PBody body = new PBody(this); | ||
541 | PVariable var_Req = body.getOrCreateVariableByName("Req"); | ||
542 | PVariable var_Instances = body.getOrCreateVariableByName("Instances"); | ||
543 | PVariable var___0_ = body.getOrCreateVariableByName("_<0>"); | ||
544 | PVariable var_RequiredCount = body.getOrCreateVariableByName("RequiredCount"); | ||
545 | new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "Requirement"))); | ||
546 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
547 | new ExportedParameter(body, var_Req, parameter_Req) | ||
548 | )); | ||
549 | // Instances == count find satisfyingInstance(Req, _) | ||
550 | PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); | ||
551 | new PatternMatchCounter(body, Tuples.flatTupleOf(var_Req, var___0_), SatisfyingInstance.instance().getInternalQueryRepresentation(), var__virtual_0_); | ||
552 | new Equality(body, var_Instances, var__virtual_0_); | ||
553 | // Requirement.count(Req, RequiredCount) | ||
554 | new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "Requirement"))); | ||
555 | PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); | ||
556 | new TypeConstraint(body, Tuples.flatTupleOf(var_Req, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "Requirement", "count"))); | ||
557 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt"))); | ||
558 | new Equality(body, var__virtual_1_, var_RequiredCount); | ||
559 | // check(Instances < RequiredCount) | ||
560 | new ExpressionEvaluation(body, new IExpressionEvaluator() { | ||
561 | |||
562 | @Override | ||
563 | public String getShortDescription() { | ||
564 | return "Expression evaluation from pattern requirementNotSatisfied"; | ||
565 | } | ||
566 | |||
567 | @Override | ||
568 | public Iterable<String> getInputParameterNames() { | ||
569 | return Arrays.asList("Instances", "RequiredCount");} | ||
570 | |||
571 | @Override | ||
572 | public Object evaluateExpression(IValueProvider provider) throws Exception { | ||
573 | Integer Instances = (Integer) provider.getValue("Instances"); | ||
574 | Integer RequiredCount = (Integer) provider.getValue("RequiredCount"); | ||
575 | return evaluateExpression_1_1(Instances, RequiredCount); | ||
576 | } | ||
577 | }, null); | ||
578 | bodies.add(body); | ||
579 | } | ||
580 | { | ||
581 | PAnnotation annotation = new PAnnotation("Constraint"); | ||
582 | annotation.addAttribute("severity", "error"); | ||
583 | annotation.addAttribute("key", Arrays.asList(new Object[] { | ||
584 | new ParameterReference("Req") | ||
585 | })); | ||
586 | annotation.addAttribute("message", "Requirement is not satisfied by enough application instances."); | ||
587 | addAnnotation(annotation); | ||
588 | } | ||
589 | return bodies; | ||
590 | } | ||
591 | } | ||
592 | |||
593 | private static boolean evaluateExpression_1_1(final Integer Instances, final Integer RequiredCount) { | ||
594 | boolean _lessThan = (Instances.compareTo(RequiredCount) < 0); | ||
595 | return _lessThan; | ||
596 | } | ||
597 | } | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/ResourceRequirement.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/ResourceRequirement.java new file mode 100644 index 00000000..db7710f5 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/ResourceRequirement.java | |||
@@ -0,0 +1,829 @@ | |||
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.ApplicationInstance; | ||
7 | import hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance; | ||
8 | import java.util.Arrays; | ||
9 | import java.util.Collection; | ||
10 | import java.util.LinkedHashSet; | ||
11 | import java.util.List; | ||
12 | import java.util.Objects; | ||
13 | import java.util.Optional; | ||
14 | import java.util.Set; | ||
15 | import java.util.function.Consumer; | ||
16 | import java.util.stream.Collectors; | ||
17 | import java.util.stream.Stream; | ||
18 | import org.apache.log4j.Logger; | ||
19 | import org.eclipse.emf.ecore.EClass; | ||
20 | import org.eclipse.viatra.query.runtime.api.IPatternMatch; | ||
21 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification; | ||
22 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; | ||
23 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; | ||
24 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; | ||
25 | import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; | ||
26 | import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; | ||
27 | import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; | ||
28 | import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; | ||
29 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
30 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | ||
31 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | ||
32 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; | ||
33 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
34 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
35 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | ||
36 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; | ||
37 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | ||
38 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; | ||
39 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
40 | import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; | ||
41 | |||
42 | /** | ||
43 | * A pattern-specific query specification that can instantiate Matcher in a type-safe way. | ||
44 | * | ||
45 | * <p>Original source: | ||
46 | * <code><pre> | ||
47 | * pattern resourceRequirement(Host : HostInstance, App : ApplicationInstance, Req : ResourceRequirement) { | ||
48 | * ApplicationInstance.allocatedTo(App, Host); | ||
49 | * ApplicationInstance.type.requirements(App, Req); | ||
50 | * HostInstance.type(Host, HostType); | ||
51 | * ResourceRequirement.hostType(Req, HostType); | ||
52 | * } | ||
53 | * </pre></code> | ||
54 | * | ||
55 | * @see Matcher | ||
56 | * @see Match | ||
57 | * | ||
58 | */ | ||
59 | @SuppressWarnings("all") | ||
60 | public final class ResourceRequirement extends BaseGeneratedEMFQuerySpecification<ResourceRequirement.Matcher> { | ||
61 | /** | ||
62 | * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.resourceRequirement pattern, | ||
63 | * to be used in conjunction with {@link Matcher}. | ||
64 | * | ||
65 | * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. | ||
66 | * Each instance is a (possibly partial) substitution of pattern parameters, | ||
67 | * usable to represent a match of the pattern in the result of a query, | ||
68 | * or to specify the bound (fixed) input parameters when issuing a query. | ||
69 | * | ||
70 | * @see Matcher | ||
71 | * | ||
72 | */ | ||
73 | public static abstract class Match extends BasePatternMatch { | ||
74 | private HostInstance fHost; | ||
75 | |||
76 | private ApplicationInstance fApp; | ||
77 | |||
78 | private hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement fReq; | ||
79 | |||
80 | private static List<String> parameterNames = makeImmutableList("Host", "App", "Req"); | ||
81 | |||
82 | private Match(final HostInstance pHost, final ApplicationInstance pApp, final hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement pReq) { | ||
83 | this.fHost = pHost; | ||
84 | this.fApp = pApp; | ||
85 | this.fReq = pReq; | ||
86 | } | ||
87 | |||
88 | @Override | ||
89 | public Object get(final String parameterName) { | ||
90 | if ("Host".equals(parameterName)) return this.fHost; | ||
91 | if ("App".equals(parameterName)) return this.fApp; | ||
92 | if ("Req".equals(parameterName)) return this.fReq; | ||
93 | return null; | ||
94 | } | ||
95 | |||
96 | public HostInstance getHost() { | ||
97 | return this.fHost; | ||
98 | } | ||
99 | |||
100 | public ApplicationInstance getApp() { | ||
101 | return this.fApp; | ||
102 | } | ||
103 | |||
104 | public hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement getReq() { | ||
105 | return this.fReq; | ||
106 | } | ||
107 | |||
108 | @Override | ||
109 | public boolean set(final String parameterName, final Object newValue) { | ||
110 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
111 | if ("Host".equals(parameterName) ) { | ||
112 | this.fHost = (HostInstance) newValue; | ||
113 | return true; | ||
114 | } | ||
115 | if ("App".equals(parameterName) ) { | ||
116 | this.fApp = (ApplicationInstance) newValue; | ||
117 | return true; | ||
118 | } | ||
119 | if ("Req".equals(parameterName) ) { | ||
120 | this.fReq = (hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement) newValue; | ||
121 | return true; | ||
122 | } | ||
123 | return false; | ||
124 | } | ||
125 | |||
126 | public void setHost(final HostInstance pHost) { | ||
127 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
128 | this.fHost = pHost; | ||
129 | } | ||
130 | |||
131 | public void setApp(final ApplicationInstance pApp) { | ||
132 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
133 | this.fApp = pApp; | ||
134 | } | ||
135 | |||
136 | public void setReq(final hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement pReq) { | ||
137 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
138 | this.fReq = pReq; | ||
139 | } | ||
140 | |||
141 | @Override | ||
142 | public String patternName() { | ||
143 | return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.resourceRequirement"; | ||
144 | } | ||
145 | |||
146 | @Override | ||
147 | public List<String> parameterNames() { | ||
148 | return ResourceRequirement.Match.parameterNames; | ||
149 | } | ||
150 | |||
151 | @Override | ||
152 | public Object[] toArray() { | ||
153 | return new Object[]{fHost, fApp, fReq}; | ||
154 | } | ||
155 | |||
156 | @Override | ||
157 | public ResourceRequirement.Match toImmutable() { | ||
158 | return isMutable() ? newMatch(fHost, fApp, fReq) : this; | ||
159 | } | ||
160 | |||
161 | @Override | ||
162 | public String prettyPrint() { | ||
163 | StringBuilder result = new StringBuilder(); | ||
164 | result.append("\"Host\"=" + prettyPrintValue(fHost) + ", "); | ||
165 | result.append("\"App\"=" + prettyPrintValue(fApp) + ", "); | ||
166 | result.append("\"Req\"=" + prettyPrintValue(fReq)); | ||
167 | return result.toString(); | ||
168 | } | ||
169 | |||
170 | @Override | ||
171 | public int hashCode() { | ||
172 | return Objects.hash(fHost, fApp, fReq); | ||
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 ResourceRequirement.Match)) { | ||
183 | ResourceRequirement.Match other = (ResourceRequirement.Match) obj; | ||
184 | return Objects.equals(fHost, other.fHost) && Objects.equals(fApp, other.fApp) && Objects.equals(fReq, other.fReq); | ||
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 ResourceRequirement specification() { | ||
197 | return ResourceRequirement.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 ResourceRequirement.Match newEmptyMatch() { | ||
208 | return new Mutable(null, 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 pHost the fixed value of pattern parameter Host, or null if not bound. | ||
216 | * @param pApp the fixed value of pattern parameter App, or null if not bound. | ||
217 | * @param pReq the fixed value of pattern parameter Req, or null if not bound. | ||
218 | * @return the new, mutable (partial) match object. | ||
219 | * | ||
220 | */ | ||
221 | public static ResourceRequirement.Match newMutableMatch(final HostInstance pHost, final ApplicationInstance pApp, final hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement pReq) { | ||
222 | return new Mutable(pHost, pApp, pReq); | ||
223 | } | ||
224 | |||
225 | /** | ||
226 | * Returns a new (partial) match. | ||
227 | * This can be used e.g. to call the matcher with a partial match. | ||
228 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
229 | * @param pHost the fixed value of pattern parameter Host, or null if not bound. | ||
230 | * @param pApp the fixed value of pattern parameter App, or null if not bound. | ||
231 | * @param pReq the fixed value of pattern parameter Req, or null if not bound. | ||
232 | * @return the (partial) match object. | ||
233 | * | ||
234 | */ | ||
235 | public static ResourceRequirement.Match newMatch(final HostInstance pHost, final ApplicationInstance pApp, final hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement pReq) { | ||
236 | return new Immutable(pHost, pApp, pReq); | ||
237 | } | ||
238 | |||
239 | private static final class Mutable extends ResourceRequirement.Match { | ||
240 | Mutable(final HostInstance pHost, final ApplicationInstance pApp, final hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement pReq) { | ||
241 | super(pHost, pApp, pReq); | ||
242 | } | ||
243 | |||
244 | @Override | ||
245 | public boolean isMutable() { | ||
246 | return true; | ||
247 | } | ||
248 | } | ||
249 | |||
250 | private static final class Immutable extends ResourceRequirement.Match { | ||
251 | Immutable(final HostInstance pHost, final ApplicationInstance pApp, final hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement pReq) { | ||
252 | super(pHost, pApp, pReq); | ||
253 | } | ||
254 | |||
255 | @Override | ||
256 | public boolean isMutable() { | ||
257 | return false; | ||
258 | } | ||
259 | } | ||
260 | } | ||
261 | |||
262 | /** | ||
263 | * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.resourceRequirement pattern, | ||
264 | * providing pattern-specific query methods. | ||
265 | * | ||
266 | * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, | ||
267 | * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. | ||
268 | * | ||
269 | * <p>Matches of the pattern will be represented as {@link Match}. | ||
270 | * | ||
271 | * <p>Original source: | ||
272 | * <code><pre> | ||
273 | * pattern resourceRequirement(Host : HostInstance, App : ApplicationInstance, Req : ResourceRequirement) { | ||
274 | * ApplicationInstance.allocatedTo(App, Host); | ||
275 | * ApplicationInstance.type.requirements(App, Req); | ||
276 | * HostInstance.type(Host, HostType); | ||
277 | * ResourceRequirement.hostType(Req, HostType); | ||
278 | * } | ||
279 | * </pre></code> | ||
280 | * | ||
281 | * @see Match | ||
282 | * @see ResourceRequirement | ||
283 | * | ||
284 | */ | ||
285 | public static class Matcher extends BaseMatcher<ResourceRequirement.Match> { | ||
286 | /** | ||
287 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
288 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
289 | * | ||
290 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
291 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
292 | * | ||
293 | */ | ||
294 | public static ResourceRequirement.Matcher on(final ViatraQueryEngine engine) { | ||
295 | // check if matcher already exists | ||
296 | Matcher matcher = engine.getExistingMatcher(querySpecification()); | ||
297 | if (matcher == null) { | ||
298 | matcher = (Matcher)engine.getMatcher(querySpecification()); | ||
299 | } | ||
300 | return matcher; | ||
301 | } | ||
302 | |||
303 | /** | ||
304 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
305 | * @return an initialized matcher | ||
306 | * @noreference This method is for internal matcher initialization by the framework, do not call it manually. | ||
307 | * | ||
308 | */ | ||
309 | public static ResourceRequirement.Matcher create() { | ||
310 | return new Matcher(); | ||
311 | } | ||
312 | |||
313 | private static final int POSITION_HOST = 0; | ||
314 | |||
315 | private static final int POSITION_APP = 1; | ||
316 | |||
317 | private static final int POSITION_REQ = 2; | ||
318 | |||
319 | private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(ResourceRequirement.Matcher.class); | ||
320 | |||
321 | /** | ||
322 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
323 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
324 | * | ||
325 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
326 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
327 | * | ||
328 | */ | ||
329 | private Matcher() { | ||
330 | super(querySpecification()); | ||
331 | } | ||
332 | |||
333 | /** | ||
334 | * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. | ||
335 | * @param pHost the fixed value of pattern parameter Host, or null if not bound. | ||
336 | * @param pApp the fixed value of pattern parameter App, or null if not bound. | ||
337 | * @param pReq the fixed value of pattern parameter Req, or null if not bound. | ||
338 | * @return matches represented as a Match object. | ||
339 | * | ||
340 | */ | ||
341 | public Collection<ResourceRequirement.Match> getAllMatches(final HostInstance pHost, final ApplicationInstance pApp, final hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement pReq) { | ||
342 | return rawStreamAllMatches(new Object[]{pHost, pApp, pReq}).collect(Collectors.toSet()); | ||
343 | } | ||
344 | |||
345 | /** | ||
346 | * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. | ||
347 | * </p> | ||
348 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
349 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
350 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
351 | * @param pHost the fixed value of pattern parameter Host, or null if not bound. | ||
352 | * @param pApp the fixed value of pattern parameter App, or null if not bound. | ||
353 | * @param pReq the fixed value of pattern parameter Req, or null if not bound. | ||
354 | * @return a stream of matches represented as a Match object. | ||
355 | * | ||
356 | */ | ||
357 | public Stream<ResourceRequirement.Match> streamAllMatches(final HostInstance pHost, final ApplicationInstance pApp, final hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement pReq) { | ||
358 | return rawStreamAllMatches(new Object[]{pHost, pApp, pReq}); | ||
359 | } | ||
360 | |||
361 | /** | ||
362 | * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
363 | * Neither determinism nor randomness of selection is guaranteed. | ||
364 | * @param pHost the fixed value of pattern parameter Host, or null if not bound. | ||
365 | * @param pApp the fixed value of pattern parameter App, or null if not bound. | ||
366 | * @param pReq the fixed value of pattern parameter Req, or null if not bound. | ||
367 | * @return a match represented as a Match object, or null if no match is found. | ||
368 | * | ||
369 | */ | ||
370 | public Optional<ResourceRequirement.Match> getOneArbitraryMatch(final HostInstance pHost, final ApplicationInstance pApp, final hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement pReq) { | ||
371 | return rawGetOneArbitraryMatch(new Object[]{pHost, pApp, pReq}); | ||
372 | } | ||
373 | |||
374 | /** | ||
375 | * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, | ||
376 | * under any possible substitution of the unspecified parameters (if any). | ||
377 | * @param pHost the fixed value of pattern parameter Host, or null if not bound. | ||
378 | * @param pApp the fixed value of pattern parameter App, or null if not bound. | ||
379 | * @param pReq the fixed value of pattern parameter Req, or null if not bound. | ||
380 | * @return true if the input is a valid (partial) match of the pattern. | ||
381 | * | ||
382 | */ | ||
383 | public boolean hasMatch(final HostInstance pHost, final ApplicationInstance pApp, final hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement pReq) { | ||
384 | return rawHasMatch(new Object[]{pHost, pApp, pReq}); | ||
385 | } | ||
386 | |||
387 | /** | ||
388 | * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. | ||
389 | * @param pHost the fixed value of pattern parameter Host, or null if not bound. | ||
390 | * @param pApp the fixed value of pattern parameter App, or null if not bound. | ||
391 | * @param pReq the fixed value of pattern parameter Req, or null if not bound. | ||
392 | * @return the number of pattern matches found. | ||
393 | * | ||
394 | */ | ||
395 | public int countMatches(final HostInstance pHost, final ApplicationInstance pApp, final hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement pReq) { | ||
396 | return rawCountMatches(new Object[]{pHost, pApp, pReq}); | ||
397 | } | ||
398 | |||
399 | /** | ||
400 | * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
401 | * Neither determinism nor randomness of selection is guaranteed. | ||
402 | * @param pHost the fixed value of pattern parameter Host, or null if not bound. | ||
403 | * @param pApp the fixed value of pattern parameter App, or null if not bound. | ||
404 | * @param pReq the fixed value of pattern parameter Req, or null if not bound. | ||
405 | * @param processor the action that will process the selected match. | ||
406 | * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked | ||
407 | * | ||
408 | */ | ||
409 | public boolean forOneArbitraryMatch(final HostInstance pHost, final ApplicationInstance pApp, final hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement pReq, final Consumer<? super ResourceRequirement.Match> processor) { | ||
410 | return rawForOneArbitraryMatch(new Object[]{pHost, pApp, pReq}, processor); | ||
411 | } | ||
412 | |||
413 | /** | ||
414 | * Returns a new (partial) match. | ||
415 | * This can be used e.g. to call the matcher with a partial match. | ||
416 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
417 | * @param pHost the fixed value of pattern parameter Host, or null if not bound. | ||
418 | * @param pApp the fixed value of pattern parameter App, or null if not bound. | ||
419 | * @param pReq the fixed value of pattern parameter Req, or null if not bound. | ||
420 | * @return the (partial) match object. | ||
421 | * | ||
422 | */ | ||
423 | public ResourceRequirement.Match newMatch(final HostInstance pHost, final ApplicationInstance pApp, final hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement pReq) { | ||
424 | return ResourceRequirement.Match.newMatch(pHost, pApp, pReq); | ||
425 | } | ||
426 | |||
427 | /** | ||
428 | * Retrieve the set of values that occur in matches for Host. | ||
429 | * @return the Set of all values or empty set if there are no matches | ||
430 | * | ||
431 | */ | ||
432 | protected Stream<HostInstance> rawStreamAllValuesOfHost(final Object[] parameters) { | ||
433 | return rawStreamAllValues(POSITION_HOST, parameters).map(HostInstance.class::cast); | ||
434 | } | ||
435 | |||
436 | /** | ||
437 | * Retrieve the set of values that occur in matches for Host. | ||
438 | * @return the Set of all values or empty set if there are no matches | ||
439 | * | ||
440 | */ | ||
441 | public Set<HostInstance> getAllValuesOfHost() { | ||
442 | return rawStreamAllValuesOfHost(emptyArray()).collect(Collectors.toSet()); | ||
443 | } | ||
444 | |||
445 | /** | ||
446 | * Retrieve the set of values that occur in matches for Host. | ||
447 | * @return the Set of all values or empty set if there are no matches | ||
448 | * | ||
449 | */ | ||
450 | public Stream<HostInstance> streamAllValuesOfHost() { | ||
451 | return rawStreamAllValuesOfHost(emptyArray()); | ||
452 | } | ||
453 | |||
454 | /** | ||
455 | * Retrieve the set of values that occur in matches for Host. | ||
456 | * </p> | ||
457 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
458 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
459 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
460 | * | ||
461 | * @return the Stream of all values or empty set if there are no matches | ||
462 | * | ||
463 | */ | ||
464 | public Stream<HostInstance> streamAllValuesOfHost(final ResourceRequirement.Match partialMatch) { | ||
465 | return rawStreamAllValuesOfHost(partialMatch.toArray()); | ||
466 | } | ||
467 | |||
468 | /** | ||
469 | * Retrieve the set of values that occur in matches for Host. | ||
470 | * </p> | ||
471 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
472 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
473 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
474 | * | ||
475 | * @return the Stream of all values or empty set if there are no matches | ||
476 | * | ||
477 | */ | ||
478 | public Stream<HostInstance> streamAllValuesOfHost(final ApplicationInstance pApp, final hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement pReq) { | ||
479 | return rawStreamAllValuesOfHost(new Object[]{null, pApp, pReq}); | ||
480 | } | ||
481 | |||
482 | /** | ||
483 | * Retrieve the set of values that occur in matches for Host. | ||
484 | * @return the Set of all values or empty set if there are no matches | ||
485 | * | ||
486 | */ | ||
487 | public Set<HostInstance> getAllValuesOfHost(final ResourceRequirement.Match partialMatch) { | ||
488 | return rawStreamAllValuesOfHost(partialMatch.toArray()).collect(Collectors.toSet()); | ||
489 | } | ||
490 | |||
491 | /** | ||
492 | * Retrieve the set of values that occur in matches for Host. | ||
493 | * @return the Set of all values or empty set if there are no matches | ||
494 | * | ||
495 | */ | ||
496 | public Set<HostInstance> getAllValuesOfHost(final ApplicationInstance pApp, final hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement pReq) { | ||
497 | return rawStreamAllValuesOfHost(new Object[]{null, pApp, pReq}).collect(Collectors.toSet()); | ||
498 | } | ||
499 | |||
500 | /** | ||
501 | * Retrieve the set of values that occur in matches for App. | ||
502 | * @return the Set of all values or empty set if there are no matches | ||
503 | * | ||
504 | */ | ||
505 | protected Stream<ApplicationInstance> rawStreamAllValuesOfApp(final Object[] parameters) { | ||
506 | return rawStreamAllValues(POSITION_APP, parameters).map(ApplicationInstance.class::cast); | ||
507 | } | ||
508 | |||
509 | /** | ||
510 | * Retrieve the set of values that occur in matches for App. | ||
511 | * @return the Set of all values or empty set if there are no matches | ||
512 | * | ||
513 | */ | ||
514 | public Set<ApplicationInstance> getAllValuesOfApp() { | ||
515 | return rawStreamAllValuesOfApp(emptyArray()).collect(Collectors.toSet()); | ||
516 | } | ||
517 | |||
518 | /** | ||
519 | * Retrieve the set of values that occur in matches for App. | ||
520 | * @return the Set of all values or empty set if there are no matches | ||
521 | * | ||
522 | */ | ||
523 | public Stream<ApplicationInstance> streamAllValuesOfApp() { | ||
524 | return rawStreamAllValuesOfApp(emptyArray()); | ||
525 | } | ||
526 | |||
527 | /** | ||
528 | * Retrieve the set of values that occur in matches for App. | ||
529 | * </p> | ||
530 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
531 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
532 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
533 | * | ||
534 | * @return the Stream of all values or empty set if there are no matches | ||
535 | * | ||
536 | */ | ||
537 | public Stream<ApplicationInstance> streamAllValuesOfApp(final ResourceRequirement.Match partialMatch) { | ||
538 | return rawStreamAllValuesOfApp(partialMatch.toArray()); | ||
539 | } | ||
540 | |||
541 | /** | ||
542 | * Retrieve the set of values that occur in matches for App. | ||
543 | * </p> | ||
544 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
545 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
546 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
547 | * | ||
548 | * @return the Stream of all values or empty set if there are no matches | ||
549 | * | ||
550 | */ | ||
551 | public Stream<ApplicationInstance> streamAllValuesOfApp(final HostInstance pHost, final hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement pReq) { | ||
552 | return rawStreamAllValuesOfApp(new Object[]{pHost, null, pReq}); | ||
553 | } | ||
554 | |||
555 | /** | ||
556 | * Retrieve the set of values that occur in matches for App. | ||
557 | * @return the Set of all values or empty set if there are no matches | ||
558 | * | ||
559 | */ | ||
560 | public Set<ApplicationInstance> getAllValuesOfApp(final ResourceRequirement.Match partialMatch) { | ||
561 | return rawStreamAllValuesOfApp(partialMatch.toArray()).collect(Collectors.toSet()); | ||
562 | } | ||
563 | |||
564 | /** | ||
565 | * Retrieve the set of values that occur in matches for App. | ||
566 | * @return the Set of all values or empty set if there are no matches | ||
567 | * | ||
568 | */ | ||
569 | public Set<ApplicationInstance> getAllValuesOfApp(final HostInstance pHost, final hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement pReq) { | ||
570 | return rawStreamAllValuesOfApp(new Object[]{pHost, null, pReq}).collect(Collectors.toSet()); | ||
571 | } | ||
572 | |||
573 | /** | ||
574 | * Retrieve the set of values that occur in matches for Req. | ||
575 | * @return the Set of all values or empty set if there are no matches | ||
576 | * | ||
577 | */ | ||
578 | protected Stream<hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement> rawStreamAllValuesOfReq(final Object[] parameters) { | ||
579 | return rawStreamAllValues(POSITION_REQ, parameters).map(hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement.class::cast); | ||
580 | } | ||
581 | |||
582 | /** | ||
583 | * Retrieve the set of values that occur in matches for Req. | ||
584 | * @return the Set of all values or empty set if there are no matches | ||
585 | * | ||
586 | */ | ||
587 | public Set<hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement> getAllValuesOfReq() { | ||
588 | return rawStreamAllValuesOfReq(emptyArray()).collect(Collectors.toSet()); | ||
589 | } | ||
590 | |||
591 | /** | ||
592 | * Retrieve the set of values that occur in matches for Req. | ||
593 | * @return the Set of all values or empty set if there are no matches | ||
594 | * | ||
595 | */ | ||
596 | public Stream<hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement> streamAllValuesOfReq() { | ||
597 | return rawStreamAllValuesOfReq(emptyArray()); | ||
598 | } | ||
599 | |||
600 | /** | ||
601 | * Retrieve the set of values that occur in matches for Req. | ||
602 | * </p> | ||
603 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
604 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
605 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
606 | * | ||
607 | * @return the Stream of all values or empty set if there are no matches | ||
608 | * | ||
609 | */ | ||
610 | public Stream<hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement> streamAllValuesOfReq(final ResourceRequirement.Match partialMatch) { | ||
611 | return rawStreamAllValuesOfReq(partialMatch.toArray()); | ||
612 | } | ||
613 | |||
614 | /** | ||
615 | * Retrieve the set of values that occur in matches for Req. | ||
616 | * </p> | ||
617 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
618 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
619 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
620 | * | ||
621 | * @return the Stream of all values or empty set if there are no matches | ||
622 | * | ||
623 | */ | ||
624 | public Stream<hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement> streamAllValuesOfReq(final HostInstance pHost, final ApplicationInstance pApp) { | ||
625 | return rawStreamAllValuesOfReq(new Object[]{pHost, pApp, null}); | ||
626 | } | ||
627 | |||
628 | /** | ||
629 | * Retrieve the set of values that occur in matches for Req. | ||
630 | * @return the Set of all values or empty set if there are no matches | ||
631 | * | ||
632 | */ | ||
633 | public Set<hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement> getAllValuesOfReq(final ResourceRequirement.Match partialMatch) { | ||
634 | return rawStreamAllValuesOfReq(partialMatch.toArray()).collect(Collectors.toSet()); | ||
635 | } | ||
636 | |||
637 | /** | ||
638 | * Retrieve the set of values that occur in matches for Req. | ||
639 | * @return the Set of all values or empty set if there are no matches | ||
640 | * | ||
641 | */ | ||
642 | public Set<hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement> getAllValuesOfReq(final HostInstance pHost, final ApplicationInstance pApp) { | ||
643 | return rawStreamAllValuesOfReq(new Object[]{pHost, pApp, null}).collect(Collectors.toSet()); | ||
644 | } | ||
645 | |||
646 | @Override | ||
647 | protected ResourceRequirement.Match tupleToMatch(final Tuple t) { | ||
648 | try { | ||
649 | return ResourceRequirement.Match.newMatch((HostInstance) t.get(POSITION_HOST), (ApplicationInstance) t.get(POSITION_APP), (hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement) t.get(POSITION_REQ)); | ||
650 | } catch(ClassCastException e) { | ||
651 | LOGGER.error("Element(s) in tuple not properly typed!",e); | ||
652 | return null; | ||
653 | } | ||
654 | } | ||
655 | |||
656 | @Override | ||
657 | protected ResourceRequirement.Match arrayToMatch(final Object[] match) { | ||
658 | try { | ||
659 | return ResourceRequirement.Match.newMatch((HostInstance) match[POSITION_HOST], (ApplicationInstance) match[POSITION_APP], (hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement) match[POSITION_REQ]); | ||
660 | } catch(ClassCastException e) { | ||
661 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
662 | return null; | ||
663 | } | ||
664 | } | ||
665 | |||
666 | @Override | ||
667 | protected ResourceRequirement.Match arrayToMatchMutable(final Object[] match) { | ||
668 | try { | ||
669 | return ResourceRequirement.Match.newMutableMatch((HostInstance) match[POSITION_HOST], (ApplicationInstance) match[POSITION_APP], (hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement) match[POSITION_REQ]); | ||
670 | } catch(ClassCastException e) { | ||
671 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
672 | return null; | ||
673 | } | ||
674 | } | ||
675 | |||
676 | /** | ||
677 | * @return the singleton instance of the query specification of this pattern | ||
678 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
679 | * | ||
680 | */ | ||
681 | public static IQuerySpecification<ResourceRequirement.Matcher> querySpecification() { | ||
682 | return ResourceRequirement.instance(); | ||
683 | } | ||
684 | } | ||
685 | |||
686 | private ResourceRequirement() { | ||
687 | super(GeneratedPQuery.INSTANCE); | ||
688 | } | ||
689 | |||
690 | /** | ||
691 | * @return the singleton instance of the query specification | ||
692 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
693 | * | ||
694 | */ | ||
695 | public static ResourceRequirement instance() { | ||
696 | try{ | ||
697 | return LazyHolder.INSTANCE; | ||
698 | } catch (ExceptionInInitializerError err) { | ||
699 | throw processInitializerError(err); | ||
700 | } | ||
701 | } | ||
702 | |||
703 | @Override | ||
704 | protected ResourceRequirement.Matcher instantiate(final ViatraQueryEngine engine) { | ||
705 | return ResourceRequirement.Matcher.on(engine); | ||
706 | } | ||
707 | |||
708 | @Override | ||
709 | public ResourceRequirement.Matcher instantiate() { | ||
710 | return ResourceRequirement.Matcher.create(); | ||
711 | } | ||
712 | |||
713 | @Override | ||
714 | public ResourceRequirement.Match newEmptyMatch() { | ||
715 | return ResourceRequirement.Match.newEmptyMatch(); | ||
716 | } | ||
717 | |||
718 | @Override | ||
719 | public ResourceRequirement.Match newMatch(final Object... parameters) { | ||
720 | return ResourceRequirement.Match.newMatch((hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance) parameters[0], (hu.bme.mit.inf.dslreasoner.domains.cps.ApplicationInstance) parameters[1], (hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement) parameters[2]); | ||
721 | } | ||
722 | |||
723 | /** | ||
724 | * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.ResourceRequirement (visibility: PUBLIC, simpleName: ResourceRequirement, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.ResourceRequirement, 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 | ||
725 | * <b>not</b> at the class load time of the outer class, | ||
726 | * but rather at the first call to {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.ResourceRequirement (visibility: PUBLIC, simpleName: ResourceRequirement, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.ResourceRequirement, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}. | ||
727 | * | ||
728 | * <p> This workaround is required e.g. to support recursion. | ||
729 | * | ||
730 | */ | ||
731 | private static class LazyHolder { | ||
732 | private static final ResourceRequirement INSTANCE = new ResourceRequirement(); | ||
733 | |||
734 | /** | ||
735 | * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned. | ||
736 | * This initialization order is required to support indirect recursion. | ||
737 | * | ||
738 | * <p> The static initializer is defined using a helper field to work around limitations of the code generator. | ||
739 | * | ||
740 | */ | ||
741 | private static final Object STATIC_INITIALIZER = ensureInitialized(); | ||
742 | |||
743 | public static Object ensureInitialized() { | ||
744 | INSTANCE.ensureInitializedInternal(); | ||
745 | return null; | ||
746 | } | ||
747 | } | ||
748 | |||
749 | private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { | ||
750 | private static final ResourceRequirement.GeneratedPQuery INSTANCE = new GeneratedPQuery(); | ||
751 | |||
752 | 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); | ||
753 | |||
754 | 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); | ||
755 | |||
756 | private final PParameter parameter_Req = new PParameter("Req", "hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "ResourceRequirement")), PParameterDirection.INOUT); | ||
757 | |||
758 | private final List<PParameter> parameters = Arrays.asList(parameter_Host, parameter_App, parameter_Req); | ||
759 | |||
760 | private GeneratedPQuery() { | ||
761 | super(PVisibility.PUBLIC); | ||
762 | } | ||
763 | |||
764 | @Override | ||
765 | public String getFullyQualifiedName() { | ||
766 | return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.resourceRequirement"; | ||
767 | } | ||
768 | |||
769 | @Override | ||
770 | public List<String> getParameterNames() { | ||
771 | return Arrays.asList("Host","App","Req"); | ||
772 | } | ||
773 | |||
774 | @Override | ||
775 | public List<PParameter> getParameters() { | ||
776 | return parameters; | ||
777 | } | ||
778 | |||
779 | @Override | ||
780 | public Set<PBody> doGetContainedBodies() { | ||
781 | setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); | ||
782 | Set<PBody> bodies = new LinkedHashSet<>(); | ||
783 | { | ||
784 | PBody body = new PBody(this); | ||
785 | PVariable var_Host = body.getOrCreateVariableByName("Host"); | ||
786 | PVariable var_App = body.getOrCreateVariableByName("App"); | ||
787 | PVariable var_Req = body.getOrCreateVariableByName("Req"); | ||
788 | PVariable var_HostType = body.getOrCreateVariableByName("HostType"); | ||
789 | new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); | ||
790 | new TypeConstraint(body, Tuples.flatTupleOf(var_App), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance"))); | ||
791 | new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ResourceRequirement"))); | ||
792 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
793 | new ExportedParameter(body, var_Host, parameter_Host), | ||
794 | new ExportedParameter(body, var_App, parameter_App), | ||
795 | new ExportedParameter(body, var_Req, parameter_Req) | ||
796 | )); | ||
797 | // ApplicationInstance.allocatedTo(App, Host) | ||
798 | new TypeConstraint(body, Tuples.flatTupleOf(var_App), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance"))); | ||
799 | PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); | ||
800 | new TypeConstraint(body, Tuples.flatTupleOf(var_App, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ApplicationInstance", "allocatedTo"))); | ||
801 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); | ||
802 | new Equality(body, var__virtual_0_, var_Host); | ||
803 | // ApplicationInstance.type.requirements(App, Req) | ||
804 | new TypeConstraint(body, Tuples.flatTupleOf(var_App), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance"))); | ||
805 | PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); | ||
806 | new TypeConstraint(body, Tuples.flatTupleOf(var_App, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ApplicationInstance", "type"))); | ||
807 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationType"))); | ||
808 | PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}"); | ||
809 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_, var__virtual_2_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ApplicationType", "requirements"))); | ||
810 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ResourceRequirement"))); | ||
811 | new Equality(body, var__virtual_2_, var_Req); | ||
812 | // HostInstance.type(Host, HostType) | ||
813 | new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); | ||
814 | PVariable var__virtual_3_ = body.getOrCreateVariableByName(".virtual{3}"); | ||
815 | new TypeConstraint(body, Tuples.flatTupleOf(var_Host, var__virtual_3_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "HostInstance", "type"))); | ||
816 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_3_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostType"))); | ||
817 | new Equality(body, var__virtual_3_, var_HostType); | ||
818 | // ResourceRequirement.hostType(Req, HostType) | ||
819 | new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ResourceRequirement"))); | ||
820 | PVariable var__virtual_4_ = body.getOrCreateVariableByName(".virtual{4}"); | ||
821 | new TypeConstraint(body, Tuples.flatTupleOf(var_Req, var__virtual_4_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ResourceRequirement", "hostType"))); | ||
822 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_4_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostType"))); | ||
823 | new Equality(body, var__virtual_4_, var_HostType); | ||
824 | bodies.add(body); | ||
825 | } | ||
826 | return bodies; | ||
827 | } | ||
828 | } | ||
829 | } | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/UnallocateAppInstance.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/UnallocateAppInstance.java new file mode 100644 index 00000000..ccc0ba22 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/UnallocateAppInstance.java | |||
@@ -0,0 +1,541 @@ | |||
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.ApplicationInstance; | ||
7 | import java.util.Arrays; | ||
8 | import java.util.Collection; | ||
9 | import java.util.LinkedHashSet; | ||
10 | import java.util.List; | ||
11 | import java.util.Objects; | ||
12 | import java.util.Optional; | ||
13 | import java.util.Set; | ||
14 | import java.util.function.Consumer; | ||
15 | import java.util.stream.Collectors; | ||
16 | import java.util.stream.Stream; | ||
17 | import org.apache.log4j.Logger; | ||
18 | import org.eclipse.emf.ecore.EClass; | ||
19 | import org.eclipse.viatra.query.runtime.api.IPatternMatch; | ||
20 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification; | ||
21 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; | ||
22 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; | ||
23 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; | ||
24 | import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; | ||
25 | import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; | ||
26 | import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; | ||
27 | import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; | ||
28 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
29 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | ||
30 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | ||
31 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; | ||
32 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
33 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
34 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | ||
35 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; | ||
36 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | ||
37 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; | ||
38 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
39 | import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; | ||
40 | |||
41 | /** | ||
42 | * A pattern-specific query specification that can instantiate Matcher in a type-safe way. | ||
43 | * | ||
44 | * <p>Original source: | ||
45 | * <code><pre> | ||
46 | * pattern unallocateAppInstance(App : ApplicationInstance) { | ||
47 | * ApplicationInstance.allocatedTo(App, _); | ||
48 | * } | ||
49 | * </pre></code> | ||
50 | * | ||
51 | * @see Matcher | ||
52 | * @see Match | ||
53 | * | ||
54 | */ | ||
55 | @SuppressWarnings("all") | ||
56 | public final class UnallocateAppInstance extends BaseGeneratedEMFQuerySpecification<UnallocateAppInstance.Matcher> { | ||
57 | /** | ||
58 | * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.unallocateAppInstance pattern, | ||
59 | * to be used in conjunction with {@link Matcher}. | ||
60 | * | ||
61 | * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. | ||
62 | * Each instance is a (possibly partial) substitution of pattern parameters, | ||
63 | * usable to represent a match of the pattern in the result of a query, | ||
64 | * or to specify the bound (fixed) input parameters when issuing a query. | ||
65 | * | ||
66 | * @see Matcher | ||
67 | * | ||
68 | */ | ||
69 | public static abstract class Match extends BasePatternMatch { | ||
70 | private ApplicationInstance fApp; | ||
71 | |||
72 | private static List<String> parameterNames = makeImmutableList("App"); | ||
73 | |||
74 | private Match(final ApplicationInstance pApp) { | ||
75 | this.fApp = pApp; | ||
76 | } | ||
77 | |||
78 | @Override | ||
79 | public Object get(final String parameterName) { | ||
80 | if ("App".equals(parameterName)) return this.fApp; | ||
81 | return null; | ||
82 | } | ||
83 | |||
84 | public ApplicationInstance getApp() { | ||
85 | return this.fApp; | ||
86 | } | ||
87 | |||
88 | @Override | ||
89 | public boolean set(final String parameterName, final Object newValue) { | ||
90 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
91 | if ("App".equals(parameterName) ) { | ||
92 | this.fApp = (ApplicationInstance) newValue; | ||
93 | return true; | ||
94 | } | ||
95 | return false; | ||
96 | } | ||
97 | |||
98 | public void setApp(final ApplicationInstance pApp) { | ||
99 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
100 | this.fApp = pApp; | ||
101 | } | ||
102 | |||
103 | @Override | ||
104 | public String patternName() { | ||
105 | return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.unallocateAppInstance"; | ||
106 | } | ||
107 | |||
108 | @Override | ||
109 | public List<String> parameterNames() { | ||
110 | return UnallocateAppInstance.Match.parameterNames; | ||
111 | } | ||
112 | |||
113 | @Override | ||
114 | public Object[] toArray() { | ||
115 | return new Object[]{fApp}; | ||
116 | } | ||
117 | |||
118 | @Override | ||
119 | public UnallocateAppInstance.Match toImmutable() { | ||
120 | return isMutable() ? newMatch(fApp) : this; | ||
121 | } | ||
122 | |||
123 | @Override | ||
124 | public String prettyPrint() { | ||
125 | StringBuilder result = new StringBuilder(); | ||
126 | result.append("\"App\"=" + prettyPrintValue(fApp)); | ||
127 | return result.toString(); | ||
128 | } | ||
129 | |||
130 | @Override | ||
131 | public int hashCode() { | ||
132 | return Objects.hash(fApp); | ||
133 | } | ||
134 | |||
135 | @Override | ||
136 | public boolean equals(final Object obj) { | ||
137 | if (this == obj) | ||
138 | return true; | ||
139 | if (obj == null) { | ||
140 | return false; | ||
141 | } | ||
142 | if ((obj instanceof UnallocateAppInstance.Match)) { | ||
143 | UnallocateAppInstance.Match other = (UnallocateAppInstance.Match) obj; | ||
144 | return Objects.equals(fApp, other.fApp); | ||
145 | } else { | ||
146 | // this should be infrequent | ||
147 | if (!(obj instanceof IPatternMatch)) { | ||
148 | return false; | ||
149 | } | ||
150 | IPatternMatch otherSig = (IPatternMatch) obj; | ||
151 | return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); | ||
152 | } | ||
153 | } | ||
154 | |||
155 | @Override | ||
156 | public UnallocateAppInstance specification() { | ||
157 | return UnallocateAppInstance.instance(); | ||
158 | } | ||
159 | |||
160 | /** | ||
161 | * Returns an empty, mutable match. | ||
162 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
163 | * | ||
164 | * @return the empty match. | ||
165 | * | ||
166 | */ | ||
167 | public static UnallocateAppInstance.Match newEmptyMatch() { | ||
168 | return new Mutable(null); | ||
169 | } | ||
170 | |||
171 | /** | ||
172 | * Returns a mutable (partial) match. | ||
173 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
174 | * | ||
175 | * @param pApp the fixed value of pattern parameter App, or null if not bound. | ||
176 | * @return the new, mutable (partial) match object. | ||
177 | * | ||
178 | */ | ||
179 | public static UnallocateAppInstance.Match newMutableMatch(final ApplicationInstance pApp) { | ||
180 | return new Mutable(pApp); | ||
181 | } | ||
182 | |||
183 | /** | ||
184 | * Returns a new (partial) match. | ||
185 | * This can be used e.g. to call the matcher with a partial match. | ||
186 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
187 | * @param pApp the fixed value of pattern parameter App, or null if not bound. | ||
188 | * @return the (partial) match object. | ||
189 | * | ||
190 | */ | ||
191 | public static UnallocateAppInstance.Match newMatch(final ApplicationInstance pApp) { | ||
192 | return new Immutable(pApp); | ||
193 | } | ||
194 | |||
195 | private static final class Mutable extends UnallocateAppInstance.Match { | ||
196 | Mutable(final ApplicationInstance pApp) { | ||
197 | super(pApp); | ||
198 | } | ||
199 | |||
200 | @Override | ||
201 | public boolean isMutable() { | ||
202 | return true; | ||
203 | } | ||
204 | } | ||
205 | |||
206 | private static final class Immutable extends UnallocateAppInstance.Match { | ||
207 | Immutable(final ApplicationInstance pApp) { | ||
208 | super(pApp); | ||
209 | } | ||
210 | |||
211 | @Override | ||
212 | public boolean isMutable() { | ||
213 | return false; | ||
214 | } | ||
215 | } | ||
216 | } | ||
217 | |||
218 | /** | ||
219 | * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.unallocateAppInstance pattern, | ||
220 | * providing pattern-specific query methods. | ||
221 | * | ||
222 | * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, | ||
223 | * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. | ||
224 | * | ||
225 | * <p>Matches of the pattern will be represented as {@link Match}. | ||
226 | * | ||
227 | * <p>Original source: | ||
228 | * <code><pre> | ||
229 | * pattern unallocateAppInstance(App : ApplicationInstance) { | ||
230 | * ApplicationInstance.allocatedTo(App, _); | ||
231 | * } | ||
232 | * </pre></code> | ||
233 | * | ||
234 | * @see Match | ||
235 | * @see UnallocateAppInstance | ||
236 | * | ||
237 | */ | ||
238 | public static class Matcher extends BaseMatcher<UnallocateAppInstance.Match> { | ||
239 | /** | ||
240 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
241 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
242 | * | ||
243 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
244 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
245 | * | ||
246 | */ | ||
247 | public static UnallocateAppInstance.Matcher on(final ViatraQueryEngine engine) { | ||
248 | // check if matcher already exists | ||
249 | Matcher matcher = engine.getExistingMatcher(querySpecification()); | ||
250 | if (matcher == null) { | ||
251 | matcher = (Matcher)engine.getMatcher(querySpecification()); | ||
252 | } | ||
253 | return matcher; | ||
254 | } | ||
255 | |||
256 | /** | ||
257 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
258 | * @return an initialized matcher | ||
259 | * @noreference This method is for internal matcher initialization by the framework, do not call it manually. | ||
260 | * | ||
261 | */ | ||
262 | public static UnallocateAppInstance.Matcher create() { | ||
263 | return new Matcher(); | ||
264 | } | ||
265 | |||
266 | private static final int POSITION_APP = 0; | ||
267 | |||
268 | private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(UnallocateAppInstance.Matcher.class); | ||
269 | |||
270 | /** | ||
271 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
272 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
273 | * | ||
274 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
275 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
276 | * | ||
277 | */ | ||
278 | private Matcher() { | ||
279 | super(querySpecification()); | ||
280 | } | ||
281 | |||
282 | /** | ||
283 | * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. | ||
284 | * @param pApp the fixed value of pattern parameter App, or null if not bound. | ||
285 | * @return matches represented as a Match object. | ||
286 | * | ||
287 | */ | ||
288 | public Collection<UnallocateAppInstance.Match> getAllMatches(final ApplicationInstance pApp) { | ||
289 | return rawStreamAllMatches(new Object[]{pApp}).collect(Collectors.toSet()); | ||
290 | } | ||
291 | |||
292 | /** | ||
293 | * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. | ||
294 | * </p> | ||
295 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
296 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
297 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
298 | * @param pApp the fixed value of pattern parameter App, or null if not bound. | ||
299 | * @return a stream of matches represented as a Match object. | ||
300 | * | ||
301 | */ | ||
302 | public Stream<UnallocateAppInstance.Match> streamAllMatches(final ApplicationInstance pApp) { | ||
303 | return rawStreamAllMatches(new Object[]{pApp}); | ||
304 | } | ||
305 | |||
306 | /** | ||
307 | * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
308 | * Neither determinism nor randomness of selection is guaranteed. | ||
309 | * @param pApp the fixed value of pattern parameter App, or null if not bound. | ||
310 | * @return a match represented as a Match object, or null if no match is found. | ||
311 | * | ||
312 | */ | ||
313 | public Optional<UnallocateAppInstance.Match> getOneArbitraryMatch(final ApplicationInstance pApp) { | ||
314 | return rawGetOneArbitraryMatch(new Object[]{pApp}); | ||
315 | } | ||
316 | |||
317 | /** | ||
318 | * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, | ||
319 | * under any possible substitution of the unspecified parameters (if any). | ||
320 | * @param pApp the fixed value of pattern parameter App, or null if not bound. | ||
321 | * @return true if the input is a valid (partial) match of the pattern. | ||
322 | * | ||
323 | */ | ||
324 | public boolean hasMatch(final ApplicationInstance pApp) { | ||
325 | return rawHasMatch(new Object[]{pApp}); | ||
326 | } | ||
327 | |||
328 | /** | ||
329 | * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. | ||
330 | * @param pApp the fixed value of pattern parameter App, or null if not bound. | ||
331 | * @return the number of pattern matches found. | ||
332 | * | ||
333 | */ | ||
334 | public int countMatches(final ApplicationInstance pApp) { | ||
335 | return rawCountMatches(new Object[]{pApp}); | ||
336 | } | ||
337 | |||
338 | /** | ||
339 | * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
340 | * Neither determinism nor randomness of selection is guaranteed. | ||
341 | * @param pApp the fixed value of pattern parameter App, or null if not bound. | ||
342 | * @param processor the action that will process the selected match. | ||
343 | * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked | ||
344 | * | ||
345 | */ | ||
346 | public boolean forOneArbitraryMatch(final ApplicationInstance pApp, final Consumer<? super UnallocateAppInstance.Match> processor) { | ||
347 | return rawForOneArbitraryMatch(new Object[]{pApp}, processor); | ||
348 | } | ||
349 | |||
350 | /** | ||
351 | * Returns a new (partial) match. | ||
352 | * This can be used e.g. to call the matcher with a partial match. | ||
353 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
354 | * @param pApp the fixed value of pattern parameter App, or null if not bound. | ||
355 | * @return the (partial) match object. | ||
356 | * | ||
357 | */ | ||
358 | public UnallocateAppInstance.Match newMatch(final ApplicationInstance pApp) { | ||
359 | return UnallocateAppInstance.Match.newMatch(pApp); | ||
360 | } | ||
361 | |||
362 | /** | ||
363 | * Retrieve the set of values that occur in matches for App. | ||
364 | * @return the Set of all values or empty set if there are no matches | ||
365 | * | ||
366 | */ | ||
367 | protected Stream<ApplicationInstance> rawStreamAllValuesOfApp(final Object[] parameters) { | ||
368 | return rawStreamAllValues(POSITION_APP, parameters).map(ApplicationInstance.class::cast); | ||
369 | } | ||
370 | |||
371 | /** | ||
372 | * Retrieve the set of values that occur in matches for App. | ||
373 | * @return the Set of all values or empty set if there are no matches | ||
374 | * | ||
375 | */ | ||
376 | public Set<ApplicationInstance> getAllValuesOfApp() { | ||
377 | return rawStreamAllValuesOfApp(emptyArray()).collect(Collectors.toSet()); | ||
378 | } | ||
379 | |||
380 | /** | ||
381 | * Retrieve the set of values that occur in matches for App. | ||
382 | * @return the Set of all values or empty set if there are no matches | ||
383 | * | ||
384 | */ | ||
385 | public Stream<ApplicationInstance> streamAllValuesOfApp() { | ||
386 | return rawStreamAllValuesOfApp(emptyArray()); | ||
387 | } | ||
388 | |||
389 | @Override | ||
390 | protected UnallocateAppInstance.Match tupleToMatch(final Tuple t) { | ||
391 | try { | ||
392 | return UnallocateAppInstance.Match.newMatch((ApplicationInstance) t.get(POSITION_APP)); | ||
393 | } catch(ClassCastException e) { | ||
394 | LOGGER.error("Element(s) in tuple not properly typed!",e); | ||
395 | return null; | ||
396 | } | ||
397 | } | ||
398 | |||
399 | @Override | ||
400 | protected UnallocateAppInstance.Match arrayToMatch(final Object[] match) { | ||
401 | try { | ||
402 | return UnallocateAppInstance.Match.newMatch((ApplicationInstance) match[POSITION_APP]); | ||
403 | } catch(ClassCastException e) { | ||
404 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
405 | return null; | ||
406 | } | ||
407 | } | ||
408 | |||
409 | @Override | ||
410 | protected UnallocateAppInstance.Match arrayToMatchMutable(final Object[] match) { | ||
411 | try { | ||
412 | return UnallocateAppInstance.Match.newMutableMatch((ApplicationInstance) match[POSITION_APP]); | ||
413 | } catch(ClassCastException e) { | ||
414 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
415 | return null; | ||
416 | } | ||
417 | } | ||
418 | |||
419 | /** | ||
420 | * @return the singleton instance of the query specification of this pattern | ||
421 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
422 | * | ||
423 | */ | ||
424 | public static IQuerySpecification<UnallocateAppInstance.Matcher> querySpecification() { | ||
425 | return UnallocateAppInstance.instance(); | ||
426 | } | ||
427 | } | ||
428 | |||
429 | private UnallocateAppInstance() { | ||
430 | super(GeneratedPQuery.INSTANCE); | ||
431 | } | ||
432 | |||
433 | /** | ||
434 | * @return the singleton instance of the query specification | ||
435 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
436 | * | ||
437 | */ | ||
438 | public static UnallocateAppInstance instance() { | ||
439 | try{ | ||
440 | return LazyHolder.INSTANCE; | ||
441 | } catch (ExceptionInInitializerError err) { | ||
442 | throw processInitializerError(err); | ||
443 | } | ||
444 | } | ||
445 | |||
446 | @Override | ||
447 | protected UnallocateAppInstance.Matcher instantiate(final ViatraQueryEngine engine) { | ||
448 | return UnallocateAppInstance.Matcher.on(engine); | ||
449 | } | ||
450 | |||
451 | @Override | ||
452 | public UnallocateAppInstance.Matcher instantiate() { | ||
453 | return UnallocateAppInstance.Matcher.create(); | ||
454 | } | ||
455 | |||
456 | @Override | ||
457 | public UnallocateAppInstance.Match newEmptyMatch() { | ||
458 | return UnallocateAppInstance.Match.newEmptyMatch(); | ||
459 | } | ||
460 | |||
461 | @Override | ||
462 | public UnallocateAppInstance.Match newMatch(final Object... parameters) { | ||
463 | return UnallocateAppInstance.Match.newMatch((hu.bme.mit.inf.dslreasoner.domains.cps.ApplicationInstance) parameters[0]); | ||
464 | } | ||
465 | |||
466 | /** | ||
467 | * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.UnallocateAppInstance (visibility: PUBLIC, simpleName: UnallocateAppInstance, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.UnallocateAppInstance, 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 | ||
468 | * <b>not</b> at the class load time of the outer class, | ||
469 | * but rather at the first call to {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.UnallocateAppInstance (visibility: PUBLIC, simpleName: UnallocateAppInstance, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.UnallocateAppInstance, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}. | ||
470 | * | ||
471 | * <p> This workaround is required e.g. to support recursion. | ||
472 | * | ||
473 | */ | ||
474 | private static class LazyHolder { | ||
475 | private static final UnallocateAppInstance INSTANCE = new UnallocateAppInstance(); | ||
476 | |||
477 | /** | ||
478 | * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned. | ||
479 | * This initialization order is required to support indirect recursion. | ||
480 | * | ||
481 | * <p> The static initializer is defined using a helper field to work around limitations of the code generator. | ||
482 | * | ||
483 | */ | ||
484 | private static final Object STATIC_INITIALIZER = ensureInitialized(); | ||
485 | |||
486 | public static Object ensureInitialized() { | ||
487 | INSTANCE.ensureInitializedInternal(); | ||
488 | return null; | ||
489 | } | ||
490 | } | ||
491 | |||
492 | private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { | ||
493 | private static final UnallocateAppInstance.GeneratedPQuery INSTANCE = new GeneratedPQuery(); | ||
494 | |||
495 | 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); | ||
496 | |||
497 | private final List<PParameter> parameters = Arrays.asList(parameter_App); | ||
498 | |||
499 | private GeneratedPQuery() { | ||
500 | super(PVisibility.PUBLIC); | ||
501 | } | ||
502 | |||
503 | @Override | ||
504 | public String getFullyQualifiedName() { | ||
505 | return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.unallocateAppInstance"; | ||
506 | } | ||
507 | |||
508 | @Override | ||
509 | public List<String> getParameterNames() { | ||
510 | return Arrays.asList("App"); | ||
511 | } | ||
512 | |||
513 | @Override | ||
514 | public List<PParameter> getParameters() { | ||
515 | return parameters; | ||
516 | } | ||
517 | |||
518 | @Override | ||
519 | public Set<PBody> doGetContainedBodies() { | ||
520 | setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); | ||
521 | Set<PBody> bodies = new LinkedHashSet<>(); | ||
522 | { | ||
523 | PBody body = new PBody(this); | ||
524 | PVariable var_App = body.getOrCreateVariableByName("App"); | ||
525 | PVariable var___0_ = body.getOrCreateVariableByName("_<0>"); | ||
526 | new TypeConstraint(body, Tuples.flatTupleOf(var_App), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance"))); | ||
527 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
528 | new ExportedParameter(body, var_App, parameter_App) | ||
529 | )); | ||
530 | // ApplicationInstance.allocatedTo(App, _) | ||
531 | new TypeConstraint(body, Tuples.flatTupleOf(var_App), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance"))); | ||
532 | PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); | ||
533 | new TypeConstraint(body, Tuples.flatTupleOf(var_App, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ApplicationInstance", "allocatedTo"))); | ||
534 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); | ||
535 | new Equality(body, var__virtual_0_, var___0_); | ||
536 | bodies.add(body); | ||
537 | } | ||
538 | return bodies; | ||
539 | } | ||
540 | } | ||
541 | } | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/.gitignore b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/.gitignore new file mode 100644 index 00000000..a4f039d9 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/.gitignore | |||
@@ -0,0 +1,36 @@ | |||
1 | /.CpsQueriesAll.java._trace | ||
2 | /.ResourceRequirement.java._trace | ||
3 | /.MemoryRequirement.java._trace | ||
4 | /.HddRequirement.java._trace | ||
5 | /.AllocationWithoutResourceRequirement.java._trace | ||
6 | /.RequiredType.java._trace | ||
7 | /.SatisfyingInstance.java._trace | ||
8 | /.FreeMemoryPercentage.java._trace | ||
9 | /.FreeHddPercentage.java._trace | ||
10 | /.ApplicationInstance.java._trace | ||
11 | /.HostInstanceCost.java._trace | ||
12 | /.AvailableHdd.java._trace | ||
13 | /.AvailableMemory.java._trace | ||
14 | /.CpsApplications.java._trace | ||
15 | /.CpsHosts.java._trace | ||
16 | /.TotalHdd.java._trace | ||
17 | /.TotalMemory.java._trace | ||
18 | /.RequiredAppInstances.java._trace | ||
19 | /.UnallocatedAppInstance.java._trace | ||
20 | /.NoHostToAllocateTo.java._trace | ||
21 | /AvailableHdd.java | ||
22 | /AvailableMemory.java | ||
23 | /CpsApplications.java | ||
24 | /CpsHosts.java | ||
25 | /CpsQueriesAll.java | ||
26 | /FreeHddPercentage.java | ||
27 | /FreeMemoryPercentage.java | ||
28 | /HddRequirement.java | ||
29 | /HostInstanceCost.java | ||
30 | /MemoryRequirement.java | ||
31 | /NoHostToAllocateTo.java | ||
32 | /RequiredAppInstances.java | ||
33 | /SatisfyingInstance.java | ||
34 | /TotalHdd.java | ||
35 | /TotalMemory.java | ||
36 | /UnallocatedAppInstance.java | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/AvailableHdd.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/AvailableHdd.java new file mode 100644 index 00000000..7d07b83a --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/AvailableHdd.java | |||
@@ -0,0 +1,178 @@ | |||
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.internal; | ||
5 | |||
6 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.HddRequirement; | ||
7 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.TotalHdd; | ||
8 | import java.util.Arrays; | ||
9 | import java.util.LinkedHashSet; | ||
10 | import java.util.List; | ||
11 | import java.util.Set; | ||
12 | import org.eclipse.emf.ecore.EClass; | ||
13 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; | ||
14 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecificationWithGenericMatcher; | ||
15 | import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; | ||
16 | import org.eclipse.viatra.query.runtime.matchers.aggregators.sum; | ||
17 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
18 | import org.eclipse.viatra.query.runtime.matchers.context.common.JavaTransitiveInstancesKey; | ||
19 | import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator; | ||
20 | import org.eclipse.viatra.query.runtime.matchers.psystem.IValueProvider; | ||
21 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | ||
22 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | ||
23 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.AggregatorConstraint; | ||
24 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; | ||
25 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
26 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation; | ||
27 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.TypeFilterConstraint; | ||
28 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall; | ||
29 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
30 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | ||
31 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; | ||
32 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | ||
33 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
34 | |||
35 | /** | ||
36 | * A pattern-specific query specification that can instantiate GenericPatternMatcher in a type-safe way. | ||
37 | * | ||
38 | * <p>Original source: | ||
39 | * <code><pre> | ||
40 | * private pattern availableHdd(Host : HostInstance, Hdd : java Integer) { | ||
41 | * find totalHdd(Host, TotalHdd); | ||
42 | * RequiredHdd == sum find hddRequirement(Host, _, #_); | ||
43 | * Hdd == eval(TotalHdd - RequiredHdd); | ||
44 | * } | ||
45 | * </pre></code> | ||
46 | * | ||
47 | * @see GenericPatternMatcher | ||
48 | * @see GenericPatternMatch | ||
49 | * | ||
50 | */ | ||
51 | @SuppressWarnings("all") | ||
52 | public final class AvailableHdd extends BaseGeneratedEMFQuerySpecificationWithGenericMatcher { | ||
53 | private AvailableHdd() { | ||
54 | super(GeneratedPQuery.INSTANCE); | ||
55 | } | ||
56 | |||
57 | /** | ||
58 | * @return the singleton instance of the query specification | ||
59 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
60 | * | ||
61 | */ | ||
62 | public static AvailableHdd instance() { | ||
63 | try{ | ||
64 | return LazyHolder.INSTANCE; | ||
65 | } catch (ExceptionInInitializerError err) { | ||
66 | throw processInitializerError(err); | ||
67 | } | ||
68 | } | ||
69 | |||
70 | /** | ||
71 | * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.AvailableHdd (visibility: PUBLIC, simpleName: AvailableHdd, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.AvailableHdd, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal) (interface: false, strictFloatingPoint: false, anonymous: false)} to be created | ||
72 | * <b>not</b> at the class load time of the outer class, | ||
73 | * but rather at the first call to {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.AvailableHdd (visibility: PUBLIC, simpleName: AvailableHdd, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.AvailableHdd, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}. | ||
74 | * | ||
75 | * <p> This workaround is required e.g. to support recursion. | ||
76 | * | ||
77 | */ | ||
78 | private static class LazyHolder { | ||
79 | private static final AvailableHdd INSTANCE = new AvailableHdd(); | ||
80 | |||
81 | /** | ||
82 | * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned. | ||
83 | * This initialization order is required to support indirect recursion. | ||
84 | * | ||
85 | * <p> The static initializer is defined using a helper field to work around limitations of the code generator. | ||
86 | * | ||
87 | */ | ||
88 | private static final Object STATIC_INITIALIZER = ensureInitialized(); | ||
89 | |||
90 | public static Object ensureInitialized() { | ||
91 | INSTANCE.ensureInitializedInternal(); | ||
92 | return null; | ||
93 | } | ||
94 | } | ||
95 | |||
96 | private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { | ||
97 | private static final AvailableHdd.GeneratedPQuery INSTANCE = new GeneratedPQuery(); | ||
98 | |||
99 | 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); | ||
100 | |||
101 | private final PParameter parameter_Hdd = new PParameter("Hdd", "java.lang.Integer", new JavaTransitiveInstancesKey(java.lang.Integer.class), PParameterDirection.INOUT); | ||
102 | |||
103 | private final List<PParameter> parameters = Arrays.asList(parameter_Host, parameter_Hdd); | ||
104 | |||
105 | private GeneratedPQuery() { | ||
106 | super(PVisibility.PRIVATE); | ||
107 | } | ||
108 | |||
109 | @Override | ||
110 | public String getFullyQualifiedName() { | ||
111 | return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.availableHdd"; | ||
112 | } | ||
113 | |||
114 | @Override | ||
115 | public List<String> getParameterNames() { | ||
116 | return Arrays.asList("Host","Hdd"); | ||
117 | } | ||
118 | |||
119 | @Override | ||
120 | public List<PParameter> getParameters() { | ||
121 | return parameters; | ||
122 | } | ||
123 | |||
124 | @Override | ||
125 | public Set<PBody> doGetContainedBodies() { | ||
126 | setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); | ||
127 | Set<PBody> bodies = new LinkedHashSet<>(); | ||
128 | { | ||
129 | PBody body = new PBody(this); | ||
130 | PVariable var_Host = body.getOrCreateVariableByName("Host"); | ||
131 | PVariable var_Hdd = body.getOrCreateVariableByName("Hdd"); | ||
132 | PVariable var_TotalHdd = body.getOrCreateVariableByName("TotalHdd"); | ||
133 | PVariable var_RequiredHdd = body.getOrCreateVariableByName("RequiredHdd"); | ||
134 | PVariable var___0_ = body.getOrCreateVariableByName("_<0>"); | ||
135 | PVariable var___1_ = body.getOrCreateVariableByName("_<1>"); | ||
136 | new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); | ||
137 | new TypeFilterConstraint(body, Tuples.flatTupleOf(var_Hdd), new JavaTransitiveInstancesKey(java.lang.Integer.class)); | ||
138 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
139 | new ExportedParameter(body, var_Host, parameter_Host), | ||
140 | new ExportedParameter(body, var_Hdd, parameter_Hdd) | ||
141 | )); | ||
142 | // find totalHdd(Host, TotalHdd) | ||
143 | new PositivePatternCall(body, Tuples.flatTupleOf(var_Host, var_TotalHdd), TotalHdd.instance().getInternalQueryRepresentation()); | ||
144 | // RequiredHdd == sum find hddRequirement(Host, _, #_) | ||
145 | PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); | ||
146 | new AggregatorConstraint(new sum().getAggregatorLogic(Integer.class), body, Tuples.flatTupleOf(var_Host, var___0_, var___1_), HddRequirement.instance().getInternalQueryRepresentation(), var__virtual_0_, 2); | ||
147 | new Equality(body, var_RequiredHdd, var__virtual_0_); | ||
148 | // Hdd == eval(TotalHdd - RequiredHdd) | ||
149 | PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); | ||
150 | new ExpressionEvaluation(body, new IExpressionEvaluator() { | ||
151 | |||
152 | @Override | ||
153 | public String getShortDescription() { | ||
154 | return "Expression evaluation from pattern availableHdd"; | ||
155 | } | ||
156 | |||
157 | @Override | ||
158 | public Iterable<String> getInputParameterNames() { | ||
159 | return Arrays.asList("RequiredHdd", "TotalHdd");} | ||
160 | |||
161 | @Override | ||
162 | public Object evaluateExpression(IValueProvider provider) throws Exception { | ||
163 | Integer RequiredHdd = (Integer) provider.getValue("RequiredHdd"); | ||
164 | Integer TotalHdd = (Integer) provider.getValue("TotalHdd"); | ||
165 | return evaluateExpression_1_1(RequiredHdd, TotalHdd); | ||
166 | } | ||
167 | }, var__virtual_1_ ); | ||
168 | new Equality(body, var_Hdd, var__virtual_1_); | ||
169 | bodies.add(body); | ||
170 | } | ||
171 | return bodies; | ||
172 | } | ||
173 | } | ||
174 | |||
175 | private static int evaluateExpression_1_1(final Integer RequiredHdd, final Integer TotalHdd) { | ||
176 | return ((TotalHdd).intValue() - (RequiredHdd).intValue()); | ||
177 | } | ||
178 | } | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/AvailableMemory.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/AvailableMemory.java new file mode 100644 index 00000000..b06544d5 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/AvailableMemory.java | |||
@@ -0,0 +1,178 @@ | |||
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.internal; | ||
5 | |||
6 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.MemoryRequirement; | ||
7 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.TotalMemory; | ||
8 | import java.util.Arrays; | ||
9 | import java.util.LinkedHashSet; | ||
10 | import java.util.List; | ||
11 | import java.util.Set; | ||
12 | import org.eclipse.emf.ecore.EClass; | ||
13 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; | ||
14 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecificationWithGenericMatcher; | ||
15 | import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; | ||
16 | import org.eclipse.viatra.query.runtime.matchers.aggregators.sum; | ||
17 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
18 | import org.eclipse.viatra.query.runtime.matchers.context.common.JavaTransitiveInstancesKey; | ||
19 | import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator; | ||
20 | import org.eclipse.viatra.query.runtime.matchers.psystem.IValueProvider; | ||
21 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | ||
22 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | ||
23 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.AggregatorConstraint; | ||
24 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; | ||
25 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
26 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation; | ||
27 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.TypeFilterConstraint; | ||
28 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall; | ||
29 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
30 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | ||
31 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; | ||
32 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | ||
33 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
34 | |||
35 | /** | ||
36 | * A pattern-specific query specification that can instantiate GenericPatternMatcher in a type-safe way. | ||
37 | * | ||
38 | * <p>Original source: | ||
39 | * <code><pre> | ||
40 | * private pattern availableMemory(Host : HostInstance, Memory : java Integer) { | ||
41 | * find totalMemory(Host, TotalMemory); | ||
42 | * RequiredMemory == sum find memoryRequirement(Host, _, #_); | ||
43 | * Memory == eval(TotalMemory - RequiredMemory); | ||
44 | * } | ||
45 | * </pre></code> | ||
46 | * | ||
47 | * @see GenericPatternMatcher | ||
48 | * @see GenericPatternMatch | ||
49 | * | ||
50 | */ | ||
51 | @SuppressWarnings("all") | ||
52 | public final class AvailableMemory extends BaseGeneratedEMFQuerySpecificationWithGenericMatcher { | ||
53 | private AvailableMemory() { | ||
54 | super(GeneratedPQuery.INSTANCE); | ||
55 | } | ||
56 | |||
57 | /** | ||
58 | * @return the singleton instance of the query specification | ||
59 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
60 | * | ||
61 | */ | ||
62 | public static AvailableMemory instance() { | ||
63 | try{ | ||
64 | return LazyHolder.INSTANCE; | ||
65 | } catch (ExceptionInInitializerError err) { | ||
66 | throw processInitializerError(err); | ||
67 | } | ||
68 | } | ||
69 | |||
70 | /** | ||
71 | * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.AvailableMemory (visibility: PUBLIC, simpleName: AvailableMemory, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.AvailableMemory, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal) (interface: false, strictFloatingPoint: false, anonymous: false)} to be created | ||
72 | * <b>not</b> at the class load time of the outer class, | ||
73 | * but rather at the first call to {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.AvailableMemory (visibility: PUBLIC, simpleName: AvailableMemory, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.AvailableMemory, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}. | ||
74 | * | ||
75 | * <p> This workaround is required e.g. to support recursion. | ||
76 | * | ||
77 | */ | ||
78 | private static class LazyHolder { | ||
79 | private static final AvailableMemory INSTANCE = new AvailableMemory(); | ||
80 | |||
81 | /** | ||
82 | * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned. | ||
83 | * This initialization order is required to support indirect recursion. | ||
84 | * | ||
85 | * <p> The static initializer is defined using a helper field to work around limitations of the code generator. | ||
86 | * | ||
87 | */ | ||
88 | private static final Object STATIC_INITIALIZER = ensureInitialized(); | ||
89 | |||
90 | public static Object ensureInitialized() { | ||
91 | INSTANCE.ensureInitializedInternal(); | ||
92 | return null; | ||
93 | } | ||
94 | } | ||
95 | |||
96 | private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { | ||
97 | private static final AvailableMemory.GeneratedPQuery INSTANCE = new GeneratedPQuery(); | ||
98 | |||
99 | 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); | ||
100 | |||
101 | private final PParameter parameter_Memory = new PParameter("Memory", "java.lang.Integer", new JavaTransitiveInstancesKey(java.lang.Integer.class), PParameterDirection.INOUT); | ||
102 | |||
103 | private final List<PParameter> parameters = Arrays.asList(parameter_Host, parameter_Memory); | ||
104 | |||
105 | private GeneratedPQuery() { | ||
106 | super(PVisibility.PRIVATE); | ||
107 | } | ||
108 | |||
109 | @Override | ||
110 | public String getFullyQualifiedName() { | ||
111 | return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.availableMemory"; | ||
112 | } | ||
113 | |||
114 | @Override | ||
115 | public List<String> getParameterNames() { | ||
116 | return Arrays.asList("Host","Memory"); | ||
117 | } | ||
118 | |||
119 | @Override | ||
120 | public List<PParameter> getParameters() { | ||
121 | return parameters; | ||
122 | } | ||
123 | |||
124 | @Override | ||
125 | public Set<PBody> doGetContainedBodies() { | ||
126 | setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); | ||
127 | Set<PBody> bodies = new LinkedHashSet<>(); | ||
128 | { | ||
129 | PBody body = new PBody(this); | ||
130 | PVariable var_Host = body.getOrCreateVariableByName("Host"); | ||
131 | PVariable var_Memory = body.getOrCreateVariableByName("Memory"); | ||
132 | PVariable var_TotalMemory = body.getOrCreateVariableByName("TotalMemory"); | ||
133 | PVariable var_RequiredMemory = body.getOrCreateVariableByName("RequiredMemory"); | ||
134 | PVariable var___0_ = body.getOrCreateVariableByName("_<0>"); | ||
135 | PVariable var___1_ = body.getOrCreateVariableByName("_<1>"); | ||
136 | new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); | ||
137 | new TypeFilterConstraint(body, Tuples.flatTupleOf(var_Memory), new JavaTransitiveInstancesKey(java.lang.Integer.class)); | ||
138 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
139 | new ExportedParameter(body, var_Host, parameter_Host), | ||
140 | new ExportedParameter(body, var_Memory, parameter_Memory) | ||
141 | )); | ||
142 | // find totalMemory(Host, TotalMemory) | ||
143 | new PositivePatternCall(body, Tuples.flatTupleOf(var_Host, var_TotalMemory), TotalMemory.instance().getInternalQueryRepresentation()); | ||
144 | // RequiredMemory == sum find memoryRequirement(Host, _, #_) | ||
145 | PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); | ||
146 | new AggregatorConstraint(new sum().getAggregatorLogic(Integer.class), body, Tuples.flatTupleOf(var_Host, var___0_, var___1_), MemoryRequirement.instance().getInternalQueryRepresentation(), var__virtual_0_, 2); | ||
147 | new Equality(body, var_RequiredMemory, var__virtual_0_); | ||
148 | // Memory == eval(TotalMemory - RequiredMemory) | ||
149 | PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); | ||
150 | new ExpressionEvaluation(body, new IExpressionEvaluator() { | ||
151 | |||
152 | @Override | ||
153 | public String getShortDescription() { | ||
154 | return "Expression evaluation from pattern availableMemory"; | ||
155 | } | ||
156 | |||
157 | @Override | ||
158 | public Iterable<String> getInputParameterNames() { | ||
159 | return Arrays.asList("RequiredMemory", "TotalMemory");} | ||
160 | |||
161 | @Override | ||
162 | public Object evaluateExpression(IValueProvider provider) throws Exception { | ||
163 | Integer RequiredMemory = (Integer) provider.getValue("RequiredMemory"); | ||
164 | Integer TotalMemory = (Integer) provider.getValue("TotalMemory"); | ||
165 | return evaluateExpression_1_1(RequiredMemory, TotalMemory); | ||
166 | } | ||
167 | }, var__virtual_1_ ); | ||
168 | new Equality(body, var_Memory, var__virtual_1_); | ||
169 | bodies.add(body); | ||
170 | } | ||
171 | return bodies; | ||
172 | } | ||
173 | } | ||
174 | |||
175 | private static int evaluateExpression_1_1(final Integer RequiredMemory, final Integer TotalMemory) { | ||
176 | return ((TotalMemory).intValue() - (RequiredMemory).intValue()); | ||
177 | } | ||
178 | } | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/CpsApplications.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/CpsApplications.java new file mode 100644 index 00000000..23867558 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/CpsApplications.java | |||
@@ -0,0 +1,141 @@ | |||
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.internal; | ||
5 | |||
6 | import java.util.Arrays; | ||
7 | import java.util.LinkedHashSet; | ||
8 | import java.util.List; | ||
9 | import java.util.Set; | ||
10 | import org.eclipse.emf.ecore.EClass; | ||
11 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; | ||
12 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecificationWithGenericMatcher; | ||
13 | import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; | ||
14 | import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; | ||
15 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
16 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | ||
17 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | ||
18 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; | ||
19 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
20 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
21 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | ||
22 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; | ||
23 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | ||
24 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
25 | |||
26 | /** | ||
27 | * A pattern-specific query specification that can instantiate GenericPatternMatcher in a type-safe way. | ||
28 | * | ||
29 | * <p>Original source: | ||
30 | * <code><pre> | ||
31 | * private pattern cpsApplications(Cps : CyberPhysicalSystem, AppInstance : ApplicationInstance) { | ||
32 | * CyberPhysicalSystem.applicationTypes.instances(Cps, AppInstance); | ||
33 | * } | ||
34 | * </pre></code> | ||
35 | * | ||
36 | * @see GenericPatternMatcher | ||
37 | * @see GenericPatternMatch | ||
38 | * | ||
39 | */ | ||
40 | @SuppressWarnings("all") | ||
41 | public final class CpsApplications extends BaseGeneratedEMFQuerySpecificationWithGenericMatcher { | ||
42 | private CpsApplications() { | ||
43 | super(GeneratedPQuery.INSTANCE); | ||
44 | } | ||
45 | |||
46 | /** | ||
47 | * @return the singleton instance of the query specification | ||
48 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
49 | * | ||
50 | */ | ||
51 | public static CpsApplications instance() { | ||
52 | try{ | ||
53 | return LazyHolder.INSTANCE; | ||
54 | } catch (ExceptionInInitializerError err) { | ||
55 | throw processInitializerError(err); | ||
56 | } | ||
57 | } | ||
58 | |||
59 | /** | ||
60 | * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.CpsApplications (visibility: PUBLIC, simpleName: CpsApplications, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.CpsApplications, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal) (interface: false, strictFloatingPoint: false, anonymous: false)} to be created | ||
61 | * <b>not</b> at the class load time of the outer class, | ||
62 | * but rather at the first call to {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.CpsApplications (visibility: PUBLIC, simpleName: CpsApplications, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.CpsApplications, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}. | ||
63 | * | ||
64 | * <p> This workaround is required e.g. to support recursion. | ||
65 | * | ||
66 | */ | ||
67 | private static class LazyHolder { | ||
68 | private static final CpsApplications INSTANCE = new CpsApplications(); | ||
69 | |||
70 | /** | ||
71 | * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned. | ||
72 | * This initialization order is required to support indirect recursion. | ||
73 | * | ||
74 | * <p> The static initializer is defined using a helper field to work around limitations of the code generator. | ||
75 | * | ||
76 | */ | ||
77 | private static final Object STATIC_INITIALIZER = ensureInitialized(); | ||
78 | |||
79 | public static Object ensureInitialized() { | ||
80 | INSTANCE.ensureInitializedInternal(); | ||
81 | return null; | ||
82 | } | ||
83 | } | ||
84 | |||
85 | private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { | ||
86 | private static final CpsApplications.GeneratedPQuery INSTANCE = new GeneratedPQuery(); | ||
87 | |||
88 | 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); | ||
89 | |||
90 | private final PParameter parameter_AppInstance = new PParameter("AppInstance", "hu.bme.mit.inf.dslreasoner.domains.cps.ApplicationInstance", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "ApplicationInstance")), PParameterDirection.INOUT); | ||
91 | |||
92 | private final List<PParameter> parameters = Arrays.asList(parameter_Cps, parameter_AppInstance); | ||
93 | |||
94 | private GeneratedPQuery() { | ||
95 | super(PVisibility.PRIVATE); | ||
96 | } | ||
97 | |||
98 | @Override | ||
99 | public String getFullyQualifiedName() { | ||
100 | return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.cpsApplications"; | ||
101 | } | ||
102 | |||
103 | @Override | ||
104 | public List<String> getParameterNames() { | ||
105 | return Arrays.asList("Cps","AppInstance"); | ||
106 | } | ||
107 | |||
108 | @Override | ||
109 | public List<PParameter> getParameters() { | ||
110 | return parameters; | ||
111 | } | ||
112 | |||
113 | @Override | ||
114 | public Set<PBody> doGetContainedBodies() { | ||
115 | setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); | ||
116 | Set<PBody> bodies = new LinkedHashSet<>(); | ||
117 | { | ||
118 | PBody body = new PBody(this); | ||
119 | PVariable var_Cps = body.getOrCreateVariableByName("Cps"); | ||
120 | PVariable var_AppInstance = body.getOrCreateVariableByName("AppInstance"); | ||
121 | new TypeConstraint(body, Tuples.flatTupleOf(var_Cps), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "CyberPhysicalSystem"))); | ||
122 | new TypeConstraint(body, Tuples.flatTupleOf(var_AppInstance), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance"))); | ||
123 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
124 | new ExportedParameter(body, var_Cps, parameter_Cps), | ||
125 | new ExportedParameter(body, var_AppInstance, parameter_AppInstance) | ||
126 | )); | ||
127 | // CyberPhysicalSystem.applicationTypes.instances(Cps, AppInstance) | ||
128 | new TypeConstraint(body, Tuples.flatTupleOf(var_Cps), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "CyberPhysicalSystem"))); | ||
129 | PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); | ||
130 | new TypeConstraint(body, Tuples.flatTupleOf(var_Cps, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "CyberPhysicalSystem", "applicationTypes"))); | ||
131 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationType"))); | ||
132 | PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); | ||
133 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ApplicationType", "instances"))); | ||
134 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance"))); | ||
135 | new Equality(body, var__virtual_1_, var_AppInstance); | ||
136 | bodies.add(body); | ||
137 | } | ||
138 | return bodies; | ||
139 | } | ||
140 | } | ||
141 | } | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/CpsHosts.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/CpsHosts.java new file mode 100644 index 00000000..e55bddff --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/CpsHosts.java | |||
@@ -0,0 +1,141 @@ | |||
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.internal; | ||
5 | |||
6 | import java.util.Arrays; | ||
7 | import java.util.LinkedHashSet; | ||
8 | import java.util.List; | ||
9 | import java.util.Set; | ||
10 | import org.eclipse.emf.ecore.EClass; | ||
11 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; | ||
12 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecificationWithGenericMatcher; | ||
13 | import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; | ||
14 | import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; | ||
15 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
16 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | ||
17 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | ||
18 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; | ||
19 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
20 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
21 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | ||
22 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; | ||
23 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | ||
24 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
25 | |||
26 | /** | ||
27 | * A pattern-specific query specification that can instantiate GenericPatternMatcher in a type-safe way. | ||
28 | * | ||
29 | * <p>Original source: | ||
30 | * <code><pre> | ||
31 | * private pattern cpsHosts(Cps : CyberPhysicalSystem, HostInstance : HostInstance) { | ||
32 | * CyberPhysicalSystem.hostTypes.instances(Cps, HostInstance); | ||
33 | * } | ||
34 | * </pre></code> | ||
35 | * | ||
36 | * @see GenericPatternMatcher | ||
37 | * @see GenericPatternMatch | ||
38 | * | ||
39 | */ | ||
40 | @SuppressWarnings("all") | ||
41 | public final class CpsHosts extends BaseGeneratedEMFQuerySpecificationWithGenericMatcher { | ||
42 | private CpsHosts() { | ||
43 | super(GeneratedPQuery.INSTANCE); | ||
44 | } | ||
45 | |||
46 | /** | ||
47 | * @return the singleton instance of the query specification | ||
48 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
49 | * | ||
50 | */ | ||
51 | public static CpsHosts instance() { | ||
52 | try{ | ||
53 | return LazyHolder.INSTANCE; | ||
54 | } catch (ExceptionInInitializerError err) { | ||
55 | throw processInitializerError(err); | ||
56 | } | ||
57 | } | ||
58 | |||
59 | /** | ||
60 | * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.CpsHosts (visibility: PUBLIC, simpleName: CpsHosts, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.CpsHosts, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal) (interface: false, strictFloatingPoint: false, anonymous: false)} to be created | ||
61 | * <b>not</b> at the class load time of the outer class, | ||
62 | * but rather at the first call to {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.CpsHosts (visibility: PUBLIC, simpleName: CpsHosts, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.CpsHosts, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}. | ||
63 | * | ||
64 | * <p> This workaround is required e.g. to support recursion. | ||
65 | * | ||
66 | */ | ||
67 | private static class LazyHolder { | ||
68 | private static final CpsHosts INSTANCE = new CpsHosts(); | ||
69 | |||
70 | /** | ||
71 | * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned. | ||
72 | * This initialization order is required to support indirect recursion. | ||
73 | * | ||
74 | * <p> The static initializer is defined using a helper field to work around limitations of the code generator. | ||
75 | * | ||
76 | */ | ||
77 | private static final Object STATIC_INITIALIZER = ensureInitialized(); | ||
78 | |||
79 | public static Object ensureInitialized() { | ||
80 | INSTANCE.ensureInitializedInternal(); | ||
81 | return null; | ||
82 | } | ||
83 | } | ||
84 | |||
85 | private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { | ||
86 | private static final CpsHosts.GeneratedPQuery INSTANCE = new GeneratedPQuery(); | ||
87 | |||
88 | 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); | ||
89 | |||
90 | private final PParameter parameter_HostInstance = new PParameter("HostInstance", "hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "HostInstance")), PParameterDirection.INOUT); | ||
91 | |||
92 | private final List<PParameter> parameters = Arrays.asList(parameter_Cps, parameter_HostInstance); | ||
93 | |||
94 | private GeneratedPQuery() { | ||
95 | super(PVisibility.PRIVATE); | ||
96 | } | ||
97 | |||
98 | @Override | ||
99 | public String getFullyQualifiedName() { | ||
100 | return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.cpsHosts"; | ||
101 | } | ||
102 | |||
103 | @Override | ||
104 | public List<String> getParameterNames() { | ||
105 | return Arrays.asList("Cps","HostInstance"); | ||
106 | } | ||
107 | |||
108 | @Override | ||
109 | public List<PParameter> getParameters() { | ||
110 | return parameters; | ||
111 | } | ||
112 | |||
113 | @Override | ||
114 | public Set<PBody> doGetContainedBodies() { | ||
115 | setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); | ||
116 | Set<PBody> bodies = new LinkedHashSet<>(); | ||
117 | { | ||
118 | PBody body = new PBody(this); | ||
119 | PVariable var_Cps = body.getOrCreateVariableByName("Cps"); | ||
120 | PVariable var_HostInstance = body.getOrCreateVariableByName("HostInstance"); | ||
121 | new TypeConstraint(body, Tuples.flatTupleOf(var_Cps), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "CyberPhysicalSystem"))); | ||
122 | new TypeConstraint(body, Tuples.flatTupleOf(var_HostInstance), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); | ||
123 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
124 | new ExportedParameter(body, var_Cps, parameter_Cps), | ||
125 | new ExportedParameter(body, var_HostInstance, parameter_HostInstance) | ||
126 | )); | ||
127 | // CyberPhysicalSystem.hostTypes.instances(Cps, HostInstance) | ||
128 | new TypeConstraint(body, Tuples.flatTupleOf(var_Cps), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "CyberPhysicalSystem"))); | ||
129 | PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); | ||
130 | new TypeConstraint(body, Tuples.flatTupleOf(var_Cps, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "CyberPhysicalSystem", "hostTypes"))); | ||
131 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostType"))); | ||
132 | PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); | ||
133 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "HostType", "instances"))); | ||
134 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); | ||
135 | new Equality(body, var__virtual_1_, var_HostInstance); | ||
136 | bodies.add(body); | ||
137 | } | ||
138 | return bodies; | ||
139 | } | ||
140 | } | ||
141 | } | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/CpsQueriesAll.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/CpsQueriesAll.java new file mode 100644 index 00000000..67f75e1d --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/CpsQueriesAll.java | |||
@@ -0,0 +1,132 @@ | |||
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.internal; | ||
5 | |||
6 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.Allocate; | ||
7 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.AllocationWithoutResourceRequirement; | ||
8 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.AverageFreeHddMetric; | ||
9 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.AverageFreeMemoryMetric; | ||
10 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.CostMetric; | ||
11 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.CpsCost; | ||
12 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.CreateHostInstance; | ||
13 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.GuidanceObjective; | ||
14 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.InstanceDoesNotSatisfyRequirement; | ||
15 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.NotEnoughAvailableHdd; | ||
16 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.NotEnoughAvailableMemory; | ||
17 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.RedundantInstancesOnSameHost; | ||
18 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.RemoveHostInstance; | ||
19 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.RequirementNotSatisfied; | ||
20 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.ResourceRequirement; | ||
21 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.UnallocateAppInstance; | ||
22 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.AvailableHdd; | ||
23 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.AvailableMemory; | ||
24 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.CpsApplications; | ||
25 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.CpsHosts; | ||
26 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.FreeHddPercentage; | ||
27 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.FreeMemoryPercentage; | ||
28 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.HddRequirement; | ||
29 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.HostInstanceCost; | ||
30 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.MemoryRequirement; | ||
31 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.NoHostToAllocateTo; | ||
32 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.RequiredAppInstances; | ||
33 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.SatisfyingInstance; | ||
34 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.TotalHdd; | ||
35 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.TotalMemory; | ||
36 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.UnallocatedAppInstance; | ||
37 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedPatternGroup; | ||
38 | |||
39 | /** | ||
40 | * A pattern group formed of all patterns defined in CpsQueries.vql. | ||
41 | * | ||
42 | * <p>A private group that includes private patterns as well. Only intended use case is for pattern testing. | ||
43 | * | ||
44 | * <p> From package hu.bme.mit.inf.dslreasoner.domains.cps.queries, the group contains the definition of the following patterns: <ul> | ||
45 | * <li>cpsApplications</li> | ||
46 | * <li>cpsHosts</li> | ||
47 | * <li>totalMemory</li> | ||
48 | * <li>totalHdd</li> | ||
49 | * <li>availableMemory</li> | ||
50 | * <li>memoryRequirement</li> | ||
51 | * <li>availableHdd</li> | ||
52 | * <li>hddRequirement</li> | ||
53 | * <li>resourceRequirement</li> | ||
54 | * <li>allocationWithoutResourceRequirement</li> | ||
55 | * <li>notEnoughAvailableMemory</li> | ||
56 | * <li>notEnoughAvailableHdd</li> | ||
57 | * <li>instanceDoesNotSatisfyRequirement</li> | ||
58 | * <li>satisfyingInstance</li> | ||
59 | * <li>requirementNotSatisfied</li> | ||
60 | * <li>redundantInstancesOnSameHost</li> | ||
61 | * <li>averageFreeMemoryMetric</li> | ||
62 | * <li>freeMemoryPercentage</li> | ||
63 | * <li>averageFreeHddMetric</li> | ||
64 | * <li>freeHddPercentage</li> | ||
65 | * <li>costMetric</li> | ||
66 | * <li>cpsCost</li> | ||
67 | * <li>hostInstanceCost</li> | ||
68 | * <li>allocate</li> | ||
69 | * <li>unallocateAppInstance</li> | ||
70 | * <li>createHostInstance</li> | ||
71 | * <li>removeHostInstance</li> | ||
72 | * <li>unallocatedAppInstance</li> | ||
73 | * <li>requiredAppInstances</li> | ||
74 | * <li>noHostToAllocateTo</li> | ||
75 | * <li>guidanceObjective</li> | ||
76 | * </ul> | ||
77 | * | ||
78 | * @see IQueryGroup | ||
79 | * | ||
80 | */ | ||
81 | @SuppressWarnings("all") | ||
82 | public final class CpsQueriesAll extends BaseGeneratedPatternGroup { | ||
83 | /** | ||
84 | * Access the pattern group. | ||
85 | * | ||
86 | * @return the singleton instance of the group | ||
87 | * @throws ViatraQueryRuntimeException if there was an error loading the generated code of pattern specifications | ||
88 | * | ||
89 | */ | ||
90 | public static CpsQueriesAll instance() { | ||
91 | if (INSTANCE == null) { | ||
92 | INSTANCE = new CpsQueriesAll(); | ||
93 | } | ||
94 | return INSTANCE; | ||
95 | } | ||
96 | |||
97 | private static CpsQueriesAll INSTANCE; | ||
98 | |||
99 | private CpsQueriesAll() { | ||
100 | querySpecifications.add(CpsApplications.instance()); | ||
101 | querySpecifications.add(CpsHosts.instance()); | ||
102 | querySpecifications.add(TotalMemory.instance()); | ||
103 | querySpecifications.add(TotalHdd.instance()); | ||
104 | querySpecifications.add(AvailableMemory.instance()); | ||
105 | querySpecifications.add(MemoryRequirement.instance()); | ||
106 | querySpecifications.add(AvailableHdd.instance()); | ||
107 | querySpecifications.add(HddRequirement.instance()); | ||
108 | querySpecifications.add(ResourceRequirement.instance()); | ||
109 | querySpecifications.add(AllocationWithoutResourceRequirement.instance()); | ||
110 | querySpecifications.add(NotEnoughAvailableMemory.instance()); | ||
111 | querySpecifications.add(NotEnoughAvailableHdd.instance()); | ||
112 | querySpecifications.add(InstanceDoesNotSatisfyRequirement.instance()); | ||
113 | querySpecifications.add(SatisfyingInstance.instance()); | ||
114 | querySpecifications.add(RequirementNotSatisfied.instance()); | ||
115 | querySpecifications.add(RedundantInstancesOnSameHost.instance()); | ||
116 | querySpecifications.add(AverageFreeMemoryMetric.instance()); | ||
117 | querySpecifications.add(FreeMemoryPercentage.instance()); | ||
118 | querySpecifications.add(AverageFreeHddMetric.instance()); | ||
119 | querySpecifications.add(FreeHddPercentage.instance()); | ||
120 | querySpecifications.add(CostMetric.instance()); | ||
121 | querySpecifications.add(CpsCost.instance()); | ||
122 | querySpecifications.add(HostInstanceCost.instance()); | ||
123 | querySpecifications.add(Allocate.instance()); | ||
124 | querySpecifications.add(UnallocateAppInstance.instance()); | ||
125 | querySpecifications.add(CreateHostInstance.instance()); | ||
126 | querySpecifications.add(RemoveHostInstance.instance()); | ||
127 | querySpecifications.add(UnallocatedAppInstance.instance()); | ||
128 | querySpecifications.add(RequiredAppInstances.instance()); | ||
129 | querySpecifications.add(NoHostToAllocateTo.instance()); | ||
130 | querySpecifications.add(GuidanceObjective.instance()); | ||
131 | } | ||
132 | } | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/FreeHddPercentage.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/FreeHddPercentage.java new file mode 100644 index 00000000..c24f46a1 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/FreeHddPercentage.java | |||
@@ -0,0 +1,172 @@ | |||
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.internal; | ||
5 | |||
6 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.AvailableHdd; | ||
7 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.TotalHdd; | ||
8 | import java.util.Arrays; | ||
9 | import java.util.LinkedHashSet; | ||
10 | import java.util.List; | ||
11 | import java.util.Set; | ||
12 | import org.eclipse.emf.ecore.EClass; | ||
13 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; | ||
14 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecificationWithGenericMatcher; | ||
15 | import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; | ||
16 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
17 | import org.eclipse.viatra.query.runtime.matchers.context.common.JavaTransitiveInstancesKey; | ||
18 | import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator; | ||
19 | import org.eclipse.viatra.query.runtime.matchers.psystem.IValueProvider; | ||
20 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | ||
21 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | ||
22 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; | ||
23 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
24 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation; | ||
25 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.TypeFilterConstraint; | ||
26 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall; | ||
27 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
28 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | ||
29 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; | ||
30 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | ||
31 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
32 | |||
33 | /** | ||
34 | * A pattern-specific query specification that can instantiate GenericPatternMatcher in a type-safe way. | ||
35 | * | ||
36 | * <p>Original source: | ||
37 | * <code><pre> | ||
38 | * private pattern freeHddPercentage(Host : HostInstance, Free : java Double) { | ||
39 | * find totalHdd(Host, Total); | ||
40 | * find availableHdd(Host, Available); | ||
41 | * Free == eval((Available as double) / Total); | ||
42 | * } | ||
43 | * </pre></code> | ||
44 | * | ||
45 | * @see GenericPatternMatcher | ||
46 | * @see GenericPatternMatch | ||
47 | * | ||
48 | */ | ||
49 | @SuppressWarnings("all") | ||
50 | public final class FreeHddPercentage extends BaseGeneratedEMFQuerySpecificationWithGenericMatcher { | ||
51 | private FreeHddPercentage() { | ||
52 | super(GeneratedPQuery.INSTANCE); | ||
53 | } | ||
54 | |||
55 | /** | ||
56 | * @return the singleton instance of the query specification | ||
57 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
58 | * | ||
59 | */ | ||
60 | public static FreeHddPercentage instance() { | ||
61 | try{ | ||
62 | return LazyHolder.INSTANCE; | ||
63 | } catch (ExceptionInInitializerError err) { | ||
64 | throw processInitializerError(err); | ||
65 | } | ||
66 | } | ||
67 | |||
68 | /** | ||
69 | * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.FreeHddPercentage (visibility: PUBLIC, simpleName: FreeHddPercentage, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.FreeHddPercentage, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal) (interface: false, strictFloatingPoint: false, anonymous: false)} to be created | ||
70 | * <b>not</b> at the class load time of the outer class, | ||
71 | * but rather at the first call to {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.FreeHddPercentage (visibility: PUBLIC, simpleName: FreeHddPercentage, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.FreeHddPercentage, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}. | ||
72 | * | ||
73 | * <p> This workaround is required e.g. to support recursion. | ||
74 | * | ||
75 | */ | ||
76 | private static class LazyHolder { | ||
77 | private static final FreeHddPercentage INSTANCE = new FreeHddPercentage(); | ||
78 | |||
79 | /** | ||
80 | * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned. | ||
81 | * This initialization order is required to support indirect recursion. | ||
82 | * | ||
83 | * <p> The static initializer is defined using a helper field to work around limitations of the code generator. | ||
84 | * | ||
85 | */ | ||
86 | private static final Object STATIC_INITIALIZER = ensureInitialized(); | ||
87 | |||
88 | public static Object ensureInitialized() { | ||
89 | INSTANCE.ensureInitializedInternal(); | ||
90 | return null; | ||
91 | } | ||
92 | } | ||
93 | |||
94 | private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { | ||
95 | private static final FreeHddPercentage.GeneratedPQuery INSTANCE = new GeneratedPQuery(); | ||
96 | |||
97 | 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); | ||
98 | |||
99 | private final PParameter parameter_Free = new PParameter("Free", "java.lang.Double", new JavaTransitiveInstancesKey(java.lang.Double.class), PParameterDirection.INOUT); | ||
100 | |||
101 | private final List<PParameter> parameters = Arrays.asList(parameter_Host, parameter_Free); | ||
102 | |||
103 | private GeneratedPQuery() { | ||
104 | super(PVisibility.PRIVATE); | ||
105 | } | ||
106 | |||
107 | @Override | ||
108 | public String getFullyQualifiedName() { | ||
109 | return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.freeHddPercentage"; | ||
110 | } | ||
111 | |||
112 | @Override | ||
113 | public List<String> getParameterNames() { | ||
114 | return Arrays.asList("Host","Free"); | ||
115 | } | ||
116 | |||
117 | @Override | ||
118 | public List<PParameter> getParameters() { | ||
119 | return parameters; | ||
120 | } | ||
121 | |||
122 | @Override | ||
123 | public Set<PBody> doGetContainedBodies() { | ||
124 | setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); | ||
125 | Set<PBody> bodies = new LinkedHashSet<>(); | ||
126 | { | ||
127 | PBody body = new PBody(this); | ||
128 | PVariable var_Host = body.getOrCreateVariableByName("Host"); | ||
129 | PVariable var_Free = body.getOrCreateVariableByName("Free"); | ||
130 | PVariable var_Total = body.getOrCreateVariableByName("Total"); | ||
131 | PVariable var_Available = body.getOrCreateVariableByName("Available"); | ||
132 | new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); | ||
133 | new TypeFilterConstraint(body, Tuples.flatTupleOf(var_Free), new JavaTransitiveInstancesKey(java.lang.Double.class)); | ||
134 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
135 | new ExportedParameter(body, var_Host, parameter_Host), | ||
136 | new ExportedParameter(body, var_Free, parameter_Free) | ||
137 | )); | ||
138 | // find totalHdd(Host, Total) | ||
139 | new PositivePatternCall(body, Tuples.flatTupleOf(var_Host, var_Total), TotalHdd.instance().getInternalQueryRepresentation()); | ||
140 | // find availableHdd(Host, Available) | ||
141 | new PositivePatternCall(body, Tuples.flatTupleOf(var_Host, var_Available), AvailableHdd.instance().getInternalQueryRepresentation()); | ||
142 | // Free == eval((Available as double) / Total) | ||
143 | PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); | ||
144 | new ExpressionEvaluation(body, new IExpressionEvaluator() { | ||
145 | |||
146 | @Override | ||
147 | public String getShortDescription() { | ||
148 | return "Expression evaluation from pattern freeHddPercentage"; | ||
149 | } | ||
150 | |||
151 | @Override | ||
152 | public Iterable<String> getInputParameterNames() { | ||
153 | return Arrays.asList("Available", "Total");} | ||
154 | |||
155 | @Override | ||
156 | public Object evaluateExpression(IValueProvider provider) throws Exception { | ||
157 | Integer Available = (Integer) provider.getValue("Available"); | ||
158 | Integer Total = (Integer) provider.getValue("Total"); | ||
159 | return evaluateExpression_1_1(Available, Total); | ||
160 | } | ||
161 | }, var__virtual_0_ ); | ||
162 | new Equality(body, var_Free, var__virtual_0_); | ||
163 | bodies.add(body); | ||
164 | } | ||
165 | return bodies; | ||
166 | } | ||
167 | } | ||
168 | |||
169 | private static double evaluateExpression_1_1(final Integer Available, final Integer Total) { | ||
170 | return (((double) (Available).intValue()) / (Total).intValue()); | ||
171 | } | ||
172 | } | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/FreeMemoryPercentage.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/FreeMemoryPercentage.java new file mode 100644 index 00000000..c2bb2bb3 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/FreeMemoryPercentage.java | |||
@@ -0,0 +1,172 @@ | |||
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.internal; | ||
5 | |||
6 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.AvailableMemory; | ||
7 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.TotalMemory; | ||
8 | import java.util.Arrays; | ||
9 | import java.util.LinkedHashSet; | ||
10 | import java.util.List; | ||
11 | import java.util.Set; | ||
12 | import org.eclipse.emf.ecore.EClass; | ||
13 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; | ||
14 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecificationWithGenericMatcher; | ||
15 | import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; | ||
16 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
17 | import org.eclipse.viatra.query.runtime.matchers.context.common.JavaTransitiveInstancesKey; | ||
18 | import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator; | ||
19 | import org.eclipse.viatra.query.runtime.matchers.psystem.IValueProvider; | ||
20 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | ||
21 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | ||
22 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; | ||
23 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
24 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation; | ||
25 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.TypeFilterConstraint; | ||
26 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall; | ||
27 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
28 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | ||
29 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; | ||
30 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | ||
31 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
32 | |||
33 | /** | ||
34 | * A pattern-specific query specification that can instantiate GenericPatternMatcher in a type-safe way. | ||
35 | * | ||
36 | * <p>Original source: | ||
37 | * <code><pre> | ||
38 | * private pattern freeMemoryPercentage(Host : HostInstance, Free : java Double) { | ||
39 | * find totalMemory(Host, Total); | ||
40 | * find availableMemory(Host, Available); | ||
41 | * Free == eval((Available as double) / Total); | ||
42 | * } | ||
43 | * </pre></code> | ||
44 | * | ||
45 | * @see GenericPatternMatcher | ||
46 | * @see GenericPatternMatch | ||
47 | * | ||
48 | */ | ||
49 | @SuppressWarnings("all") | ||
50 | public final class FreeMemoryPercentage extends BaseGeneratedEMFQuerySpecificationWithGenericMatcher { | ||
51 | private FreeMemoryPercentage() { | ||
52 | super(GeneratedPQuery.INSTANCE); | ||
53 | } | ||
54 | |||
55 | /** | ||
56 | * @return the singleton instance of the query specification | ||
57 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
58 | * | ||
59 | */ | ||
60 | public static FreeMemoryPercentage instance() { | ||
61 | try{ | ||
62 | return LazyHolder.INSTANCE; | ||
63 | } catch (ExceptionInInitializerError err) { | ||
64 | throw processInitializerError(err); | ||
65 | } | ||
66 | } | ||
67 | |||
68 | /** | ||
69 | * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.FreeMemoryPercentage (visibility: PUBLIC, simpleName: FreeMemoryPercentage, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.FreeMemoryPercentage, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal) (interface: false, strictFloatingPoint: false, anonymous: false)} to be created | ||
70 | * <b>not</b> at the class load time of the outer class, | ||
71 | * but rather at the first call to {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.FreeMemoryPercentage (visibility: PUBLIC, simpleName: FreeMemoryPercentage, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.FreeMemoryPercentage, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}. | ||
72 | * | ||
73 | * <p> This workaround is required e.g. to support recursion. | ||
74 | * | ||
75 | */ | ||
76 | private static class LazyHolder { | ||
77 | private static final FreeMemoryPercentage INSTANCE = new FreeMemoryPercentage(); | ||
78 | |||
79 | /** | ||
80 | * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned. | ||
81 | * This initialization order is required to support indirect recursion. | ||
82 | * | ||
83 | * <p> The static initializer is defined using a helper field to work around limitations of the code generator. | ||
84 | * | ||
85 | */ | ||
86 | private static final Object STATIC_INITIALIZER = ensureInitialized(); | ||
87 | |||
88 | public static Object ensureInitialized() { | ||
89 | INSTANCE.ensureInitializedInternal(); | ||
90 | return null; | ||
91 | } | ||
92 | } | ||
93 | |||
94 | private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { | ||
95 | private static final FreeMemoryPercentage.GeneratedPQuery INSTANCE = new GeneratedPQuery(); | ||
96 | |||
97 | 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); | ||
98 | |||
99 | private final PParameter parameter_Free = new PParameter("Free", "java.lang.Double", new JavaTransitiveInstancesKey(java.lang.Double.class), PParameterDirection.INOUT); | ||
100 | |||
101 | private final List<PParameter> parameters = Arrays.asList(parameter_Host, parameter_Free); | ||
102 | |||
103 | private GeneratedPQuery() { | ||
104 | super(PVisibility.PRIVATE); | ||
105 | } | ||
106 | |||
107 | @Override | ||
108 | public String getFullyQualifiedName() { | ||
109 | return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.freeMemoryPercentage"; | ||
110 | } | ||
111 | |||
112 | @Override | ||
113 | public List<String> getParameterNames() { | ||
114 | return Arrays.asList("Host","Free"); | ||
115 | } | ||
116 | |||
117 | @Override | ||
118 | public List<PParameter> getParameters() { | ||
119 | return parameters; | ||
120 | } | ||
121 | |||
122 | @Override | ||
123 | public Set<PBody> doGetContainedBodies() { | ||
124 | setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); | ||
125 | Set<PBody> bodies = new LinkedHashSet<>(); | ||
126 | { | ||
127 | PBody body = new PBody(this); | ||
128 | PVariable var_Host = body.getOrCreateVariableByName("Host"); | ||
129 | PVariable var_Free = body.getOrCreateVariableByName("Free"); | ||
130 | PVariable var_Total = body.getOrCreateVariableByName("Total"); | ||
131 | PVariable var_Available = body.getOrCreateVariableByName("Available"); | ||
132 | new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); | ||
133 | new TypeFilterConstraint(body, Tuples.flatTupleOf(var_Free), new JavaTransitiveInstancesKey(java.lang.Double.class)); | ||
134 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
135 | new ExportedParameter(body, var_Host, parameter_Host), | ||
136 | new ExportedParameter(body, var_Free, parameter_Free) | ||
137 | )); | ||
138 | // find totalMemory(Host, Total) | ||
139 | new PositivePatternCall(body, Tuples.flatTupleOf(var_Host, var_Total), TotalMemory.instance().getInternalQueryRepresentation()); | ||
140 | // find availableMemory(Host, Available) | ||
141 | new PositivePatternCall(body, Tuples.flatTupleOf(var_Host, var_Available), AvailableMemory.instance().getInternalQueryRepresentation()); | ||
142 | // Free == eval((Available as double) / Total) | ||
143 | PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); | ||
144 | new ExpressionEvaluation(body, new IExpressionEvaluator() { | ||
145 | |||
146 | @Override | ||
147 | public String getShortDescription() { | ||
148 | return "Expression evaluation from pattern freeMemoryPercentage"; | ||
149 | } | ||
150 | |||
151 | @Override | ||
152 | public Iterable<String> getInputParameterNames() { | ||
153 | return Arrays.asList("Available", "Total");} | ||
154 | |||
155 | @Override | ||
156 | public Object evaluateExpression(IValueProvider provider) throws Exception { | ||
157 | Integer Available = (Integer) provider.getValue("Available"); | ||
158 | Integer Total = (Integer) provider.getValue("Total"); | ||
159 | return evaluateExpression_1_1(Available, Total); | ||
160 | } | ||
161 | }, var__virtual_0_ ); | ||
162 | new Equality(body, var_Free, var__virtual_0_); | ||
163 | bodies.add(body); | ||
164 | } | ||
165 | return bodies; | ||
166 | } | ||
167 | } | ||
168 | |||
169 | private static double evaluateExpression_1_1(final Integer Available, final Integer Total) { | ||
170 | return (((double) (Available).intValue()) / (Total).intValue()); | ||
171 | } | ||
172 | } | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/HddRequirement.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/HddRequirement.java new file mode 100644 index 00000000..68448930 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/HddRequirement.java | |||
@@ -0,0 +1,151 @@ | |||
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.internal; | ||
5 | |||
6 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.ResourceRequirement; | ||
7 | import java.util.Arrays; | ||
8 | import java.util.LinkedHashSet; | ||
9 | import java.util.List; | ||
10 | import java.util.Set; | ||
11 | import org.eclipse.emf.ecore.EClass; | ||
12 | import org.eclipse.emf.ecore.EDataType; | ||
13 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; | ||
14 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecificationWithGenericMatcher; | ||
15 | import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; | ||
16 | import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey; | ||
17 | import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; | ||
18 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
19 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | ||
20 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | ||
21 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; | ||
22 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
23 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall; | ||
24 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
25 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | ||
26 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; | ||
27 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | ||
28 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
29 | |||
30 | /** | ||
31 | * A pattern-specific query specification that can instantiate GenericPatternMatcher in a type-safe way. | ||
32 | * | ||
33 | * <p>Original source: | ||
34 | * <code><pre> | ||
35 | * private pattern hddRequirement(Host : HostInstance, App : ApplicationInstance, Hdd : EInt) { | ||
36 | * find resourceRequirement(Host, App, Req); | ||
37 | * ResourceRequirement.requiredHdd(Req, Hdd); | ||
38 | * } | ||
39 | * </pre></code> | ||
40 | * | ||
41 | * @see GenericPatternMatcher | ||
42 | * @see GenericPatternMatch | ||
43 | * | ||
44 | */ | ||
45 | @SuppressWarnings("all") | ||
46 | public final class HddRequirement extends BaseGeneratedEMFQuerySpecificationWithGenericMatcher { | ||
47 | private HddRequirement() { | ||
48 | super(GeneratedPQuery.INSTANCE); | ||
49 | } | ||
50 | |||
51 | /** | ||
52 | * @return the singleton instance of the query specification | ||
53 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
54 | * | ||
55 | */ | ||
56 | public static HddRequirement instance() { | ||
57 | try{ | ||
58 | return LazyHolder.INSTANCE; | ||
59 | } catch (ExceptionInInitializerError err) { | ||
60 | throw processInitializerError(err); | ||
61 | } | ||
62 | } | ||
63 | |||
64 | /** | ||
65 | * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.HddRequirement (visibility: PUBLIC, simpleName: HddRequirement, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.HddRequirement, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal) (interface: false, strictFloatingPoint: false, anonymous: false)} to be created | ||
66 | * <b>not</b> at the class load time of the outer class, | ||
67 | * but rather at the first call to {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.HddRequirement (visibility: PUBLIC, simpleName: HddRequirement, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.HddRequirement, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}. | ||
68 | * | ||
69 | * <p> This workaround is required e.g. to support recursion. | ||
70 | * | ||
71 | */ | ||
72 | private static class LazyHolder { | ||
73 | private static final HddRequirement INSTANCE = new HddRequirement(); | ||
74 | |||
75 | /** | ||
76 | * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned. | ||
77 | * This initialization order is required to support indirect recursion. | ||
78 | * | ||
79 | * <p> The static initializer is defined using a helper field to work around limitations of the code generator. | ||
80 | * | ||
81 | */ | ||
82 | private static final Object STATIC_INITIALIZER = ensureInitialized(); | ||
83 | |||
84 | public static Object ensureInitialized() { | ||
85 | INSTANCE.ensureInitializedInternal(); | ||
86 | return null; | ||
87 | } | ||
88 | } | ||
89 | |||
90 | private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { | ||
91 | private static final HddRequirement.GeneratedPQuery INSTANCE = new GeneratedPQuery(); | ||
92 | |||
93 | 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); | ||
94 | |||
95 | 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); | ||
96 | |||
97 | private final PParameter parameter_Hdd = new PParameter("Hdd", "java.lang.Integer", new EDataTypeInSlotsKey((EDataType)getClassifierLiteralSafe("http://www.eclipse.org/emf/2002/Ecore", "EInt")), PParameterDirection.INOUT); | ||
98 | |||
99 | private final List<PParameter> parameters = Arrays.asList(parameter_Host, parameter_App, parameter_Hdd); | ||
100 | |||
101 | private GeneratedPQuery() { | ||
102 | super(PVisibility.PRIVATE); | ||
103 | } | ||
104 | |||
105 | @Override | ||
106 | public String getFullyQualifiedName() { | ||
107 | return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.hddRequirement"; | ||
108 | } | ||
109 | |||
110 | @Override | ||
111 | public List<String> getParameterNames() { | ||
112 | return Arrays.asList("Host","App","Hdd"); | ||
113 | } | ||
114 | |||
115 | @Override | ||
116 | public List<PParameter> getParameters() { | ||
117 | return parameters; | ||
118 | } | ||
119 | |||
120 | @Override | ||
121 | public Set<PBody> doGetContainedBodies() { | ||
122 | setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); | ||
123 | Set<PBody> bodies = new LinkedHashSet<>(); | ||
124 | { | ||
125 | PBody body = new PBody(this); | ||
126 | PVariable var_Host = body.getOrCreateVariableByName("Host"); | ||
127 | PVariable var_App = body.getOrCreateVariableByName("App"); | ||
128 | PVariable var_Hdd = body.getOrCreateVariableByName("Hdd"); | ||
129 | PVariable var_Req = body.getOrCreateVariableByName("Req"); | ||
130 | new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); | ||
131 | new TypeConstraint(body, Tuples.flatTupleOf(var_App), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance"))); | ||
132 | new TypeConstraint(body, Tuples.flatTupleOf(var_Hdd), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt"))); | ||
133 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
134 | new ExportedParameter(body, var_Host, parameter_Host), | ||
135 | new ExportedParameter(body, var_App, parameter_App), | ||
136 | new ExportedParameter(body, var_Hdd, parameter_Hdd) | ||
137 | )); | ||
138 | // find resourceRequirement(Host, App, Req) | ||
139 | new PositivePatternCall(body, Tuples.flatTupleOf(var_Host, var_App, var_Req), ResourceRequirement.instance().getInternalQueryRepresentation()); | ||
140 | // ResourceRequirement.requiredHdd(Req, Hdd) | ||
141 | new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ResourceRequirement"))); | ||
142 | PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); | ||
143 | new TypeConstraint(body, Tuples.flatTupleOf(var_Req, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ResourceRequirement", "requiredHdd"))); | ||
144 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt"))); | ||
145 | new Equality(body, var__virtual_0_, var_Hdd); | ||
146 | bodies.add(body); | ||
147 | } | ||
148 | return bodies; | ||
149 | } | ||
150 | } | ||
151 | } | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/HostInstanceCost.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/HostInstanceCost.java new file mode 100644 index 00000000..db7f7021 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/HostInstanceCost.java | |||
@@ -0,0 +1,153 @@ | |||
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.internal; | ||
5 | |||
6 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.CpsHosts; | ||
7 | import java.util.Arrays; | ||
8 | import java.util.LinkedHashSet; | ||
9 | import java.util.List; | ||
10 | import java.util.Set; | ||
11 | import org.eclipse.emf.ecore.EClass; | ||
12 | import org.eclipse.emf.ecore.EDataType; | ||
13 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; | ||
14 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecificationWithGenericMatcher; | ||
15 | import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; | ||
16 | import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey; | ||
17 | import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; | ||
18 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
19 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | ||
20 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | ||
21 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; | ||
22 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
23 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall; | ||
24 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
25 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | ||
26 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; | ||
27 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | ||
28 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
29 | |||
30 | /** | ||
31 | * A pattern-specific query specification that can instantiate GenericPatternMatcher in a type-safe way. | ||
32 | * | ||
33 | * <p>Original source: | ||
34 | * <code><pre> | ||
35 | * private pattern hostInstanceCost(Cps : CyberPhysicalSystem, Host : HostInstance, Cost : EInt) { | ||
36 | * find cpsHosts(Cps, Host); | ||
37 | * HostInstance.type.cost(Host, Cost); | ||
38 | * } | ||
39 | * </pre></code> | ||
40 | * | ||
41 | * @see GenericPatternMatcher | ||
42 | * @see GenericPatternMatch | ||
43 | * | ||
44 | */ | ||
45 | @SuppressWarnings("all") | ||
46 | public final class HostInstanceCost extends BaseGeneratedEMFQuerySpecificationWithGenericMatcher { | ||
47 | private HostInstanceCost() { | ||
48 | super(GeneratedPQuery.INSTANCE); | ||
49 | } | ||
50 | |||
51 | /** | ||
52 | * @return the singleton instance of the query specification | ||
53 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
54 | * | ||
55 | */ | ||
56 | public static HostInstanceCost instance() { | ||
57 | try{ | ||
58 | return LazyHolder.INSTANCE; | ||
59 | } catch (ExceptionInInitializerError err) { | ||
60 | throw processInitializerError(err); | ||
61 | } | ||
62 | } | ||
63 | |||
64 | /** | ||
65 | * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.HostInstanceCost (visibility: PUBLIC, simpleName: HostInstanceCost, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.HostInstanceCost, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal) (interface: false, strictFloatingPoint: false, anonymous: false)} to be created | ||
66 | * <b>not</b> at the class load time of the outer class, | ||
67 | * but rather at the first call to {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.HostInstanceCost (visibility: PUBLIC, simpleName: HostInstanceCost, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.HostInstanceCost, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}. | ||
68 | * | ||
69 | * <p> This workaround is required e.g. to support recursion. | ||
70 | * | ||
71 | */ | ||
72 | private static class LazyHolder { | ||
73 | private static final HostInstanceCost INSTANCE = new HostInstanceCost(); | ||
74 | |||
75 | /** | ||
76 | * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned. | ||
77 | * This initialization order is required to support indirect recursion. | ||
78 | * | ||
79 | * <p> The static initializer is defined using a helper field to work around limitations of the code generator. | ||
80 | * | ||
81 | */ | ||
82 | private static final Object STATIC_INITIALIZER = ensureInitialized(); | ||
83 | |||
84 | public static Object ensureInitialized() { | ||
85 | INSTANCE.ensureInitializedInternal(); | ||
86 | return null; | ||
87 | } | ||
88 | } | ||
89 | |||
90 | private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { | ||
91 | private static final HostInstanceCost.GeneratedPQuery INSTANCE = new GeneratedPQuery(); | ||
92 | |||
93 | 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); | ||
94 | |||
95 | 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); | ||
96 | |||
97 | private final PParameter parameter_Cost = new PParameter("Cost", "java.lang.Integer", new EDataTypeInSlotsKey((EDataType)getClassifierLiteralSafe("http://www.eclipse.org/emf/2002/Ecore", "EInt")), PParameterDirection.INOUT); | ||
98 | |||
99 | private final List<PParameter> parameters = Arrays.asList(parameter_Cps, parameter_Host, parameter_Cost); | ||
100 | |||
101 | private GeneratedPQuery() { | ||
102 | super(PVisibility.PRIVATE); | ||
103 | } | ||
104 | |||
105 | @Override | ||
106 | public String getFullyQualifiedName() { | ||
107 | return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.hostInstanceCost"; | ||
108 | } | ||
109 | |||
110 | @Override | ||
111 | public List<String> getParameterNames() { | ||
112 | return Arrays.asList("Cps","Host","Cost"); | ||
113 | } | ||
114 | |||
115 | @Override | ||
116 | public List<PParameter> getParameters() { | ||
117 | return parameters; | ||
118 | } | ||
119 | |||
120 | @Override | ||
121 | public Set<PBody> doGetContainedBodies() { | ||
122 | setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); | ||
123 | Set<PBody> bodies = new LinkedHashSet<>(); | ||
124 | { | ||
125 | PBody body = new PBody(this); | ||
126 | PVariable var_Cps = body.getOrCreateVariableByName("Cps"); | ||
127 | PVariable var_Host = body.getOrCreateVariableByName("Host"); | ||
128 | PVariable var_Cost = body.getOrCreateVariableByName("Cost"); | ||
129 | new TypeConstraint(body, Tuples.flatTupleOf(var_Cps), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "CyberPhysicalSystem"))); | ||
130 | new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); | ||
131 | new TypeConstraint(body, Tuples.flatTupleOf(var_Cost), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt"))); | ||
132 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
133 | new ExportedParameter(body, var_Cps, parameter_Cps), | ||
134 | new ExportedParameter(body, var_Host, parameter_Host), | ||
135 | new ExportedParameter(body, var_Cost, parameter_Cost) | ||
136 | )); | ||
137 | // find cpsHosts(Cps, Host) | ||
138 | new PositivePatternCall(body, Tuples.flatTupleOf(var_Cps, var_Host), CpsHosts.instance().getInternalQueryRepresentation()); | ||
139 | // HostInstance.type.cost(Host, Cost) | ||
140 | new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); | ||
141 | PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); | ||
142 | new TypeConstraint(body, Tuples.flatTupleOf(var_Host, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "HostInstance", "type"))); | ||
143 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostType"))); | ||
144 | PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); | ||
145 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "HostType", "cost"))); | ||
146 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt"))); | ||
147 | new Equality(body, var__virtual_1_, var_Cost); | ||
148 | bodies.add(body); | ||
149 | } | ||
150 | return bodies; | ||
151 | } | ||
152 | } | ||
153 | } | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/MemoryRequirement.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/MemoryRequirement.java new file mode 100644 index 00000000..d15f9bfa --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/MemoryRequirement.java | |||
@@ -0,0 +1,151 @@ | |||
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.internal; | ||
5 | |||
6 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.ResourceRequirement; | ||
7 | import java.util.Arrays; | ||
8 | import java.util.LinkedHashSet; | ||
9 | import java.util.List; | ||
10 | import java.util.Set; | ||
11 | import org.eclipse.emf.ecore.EClass; | ||
12 | import org.eclipse.emf.ecore.EDataType; | ||
13 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; | ||
14 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecificationWithGenericMatcher; | ||
15 | import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; | ||
16 | import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey; | ||
17 | import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; | ||
18 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
19 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | ||
20 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | ||
21 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; | ||
22 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
23 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall; | ||
24 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
25 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | ||
26 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; | ||
27 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | ||
28 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
29 | |||
30 | /** | ||
31 | * A pattern-specific query specification that can instantiate GenericPatternMatcher in a type-safe way. | ||
32 | * | ||
33 | * <p>Original source: | ||
34 | * <code><pre> | ||
35 | * private pattern memoryRequirement(Host : HostInstance, App : ApplicationInstance, Memory : EInt) { | ||
36 | * find resourceRequirement(Host, App, Req); | ||
37 | * ResourceRequirement.requiredMemory(Req, Memory); | ||
38 | * } | ||
39 | * </pre></code> | ||
40 | * | ||
41 | * @see GenericPatternMatcher | ||
42 | * @see GenericPatternMatch | ||
43 | * | ||
44 | */ | ||
45 | @SuppressWarnings("all") | ||
46 | public final class MemoryRequirement extends BaseGeneratedEMFQuerySpecificationWithGenericMatcher { | ||
47 | private MemoryRequirement() { | ||
48 | super(GeneratedPQuery.INSTANCE); | ||
49 | } | ||
50 | |||
51 | /** | ||
52 | * @return the singleton instance of the query specification | ||
53 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
54 | * | ||
55 | */ | ||
56 | public static MemoryRequirement instance() { | ||
57 | try{ | ||
58 | return LazyHolder.INSTANCE; | ||
59 | } catch (ExceptionInInitializerError err) { | ||
60 | throw processInitializerError(err); | ||
61 | } | ||
62 | } | ||
63 | |||
64 | /** | ||
65 | * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.MemoryRequirement (visibility: PUBLIC, simpleName: MemoryRequirement, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.MemoryRequirement, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal) (interface: false, strictFloatingPoint: false, anonymous: false)} to be created | ||
66 | * <b>not</b> at the class load time of the outer class, | ||
67 | * but rather at the first call to {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.MemoryRequirement (visibility: PUBLIC, simpleName: MemoryRequirement, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.MemoryRequirement, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}. | ||
68 | * | ||
69 | * <p> This workaround is required e.g. to support recursion. | ||
70 | * | ||
71 | */ | ||
72 | private static class LazyHolder { | ||
73 | private static final MemoryRequirement INSTANCE = new MemoryRequirement(); | ||
74 | |||
75 | /** | ||
76 | * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned. | ||
77 | * This initialization order is required to support indirect recursion. | ||
78 | * | ||
79 | * <p> The static initializer is defined using a helper field to work around limitations of the code generator. | ||
80 | * | ||
81 | */ | ||
82 | private static final Object STATIC_INITIALIZER = ensureInitialized(); | ||
83 | |||
84 | public static Object ensureInitialized() { | ||
85 | INSTANCE.ensureInitializedInternal(); | ||
86 | return null; | ||
87 | } | ||
88 | } | ||
89 | |||
90 | private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { | ||
91 | private static final MemoryRequirement.GeneratedPQuery INSTANCE = new GeneratedPQuery(); | ||
92 | |||
93 | 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); | ||
94 | |||
95 | 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); | ||
96 | |||
97 | private final PParameter parameter_Memory = new PParameter("Memory", "java.lang.Integer", new EDataTypeInSlotsKey((EDataType)getClassifierLiteralSafe("http://www.eclipse.org/emf/2002/Ecore", "EInt")), PParameterDirection.INOUT); | ||
98 | |||
99 | private final List<PParameter> parameters = Arrays.asList(parameter_Host, parameter_App, parameter_Memory); | ||
100 | |||
101 | private GeneratedPQuery() { | ||
102 | super(PVisibility.PRIVATE); | ||
103 | } | ||
104 | |||
105 | @Override | ||
106 | public String getFullyQualifiedName() { | ||
107 | return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.memoryRequirement"; | ||
108 | } | ||
109 | |||
110 | @Override | ||
111 | public List<String> getParameterNames() { | ||
112 | return Arrays.asList("Host","App","Memory"); | ||
113 | } | ||
114 | |||
115 | @Override | ||
116 | public List<PParameter> getParameters() { | ||
117 | return parameters; | ||
118 | } | ||
119 | |||
120 | @Override | ||
121 | public Set<PBody> doGetContainedBodies() { | ||
122 | setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); | ||
123 | Set<PBody> bodies = new LinkedHashSet<>(); | ||
124 | { | ||
125 | PBody body = new PBody(this); | ||
126 | PVariable var_Host = body.getOrCreateVariableByName("Host"); | ||
127 | PVariable var_App = body.getOrCreateVariableByName("App"); | ||
128 | PVariable var_Memory = body.getOrCreateVariableByName("Memory"); | ||
129 | PVariable var_Req = body.getOrCreateVariableByName("Req"); | ||
130 | new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); | ||
131 | new TypeConstraint(body, Tuples.flatTupleOf(var_App), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance"))); | ||
132 | new TypeConstraint(body, Tuples.flatTupleOf(var_Memory), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt"))); | ||
133 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
134 | new ExportedParameter(body, var_Host, parameter_Host), | ||
135 | new ExportedParameter(body, var_App, parameter_App), | ||
136 | new ExportedParameter(body, var_Memory, parameter_Memory) | ||
137 | )); | ||
138 | // find resourceRequirement(Host, App, Req) | ||
139 | new PositivePatternCall(body, Tuples.flatTupleOf(var_Host, var_App, var_Req), ResourceRequirement.instance().getInternalQueryRepresentation()); | ||
140 | // ResourceRequirement.requiredMemory(Req, Memory) | ||
141 | new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ResourceRequirement"))); | ||
142 | PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); | ||
143 | new TypeConstraint(body, Tuples.flatTupleOf(var_Req, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ResourceRequirement", "requiredMemory"))); | ||
144 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt"))); | ||
145 | new Equality(body, var__virtual_0_, var_Memory); | ||
146 | bodies.add(body); | ||
147 | } | ||
148 | return bodies; | ||
149 | } | ||
150 | } | ||
151 | } | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/NoHostToAllocateTo.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/NoHostToAllocateTo.java new file mode 100644 index 00000000..50597805 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/NoHostToAllocateTo.java | |||
@@ -0,0 +1,135 @@ | |||
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.internal; | ||
5 | |||
6 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.Allocate; | ||
7 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.UnallocatedAppInstance; | ||
8 | import java.util.Arrays; | ||
9 | import java.util.LinkedHashSet; | ||
10 | import java.util.List; | ||
11 | import java.util.Set; | ||
12 | import org.eclipse.emf.ecore.EClass; | ||
13 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; | ||
14 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecificationWithGenericMatcher; | ||
15 | import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; | ||
16 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
17 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | ||
18 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | ||
19 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
20 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.NegativePatternCall; | ||
21 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall; | ||
22 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
23 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | ||
24 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; | ||
25 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | ||
26 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
27 | |||
28 | /** | ||
29 | * A pattern-specific query specification that can instantiate GenericPatternMatcher in a type-safe way. | ||
30 | * | ||
31 | * <p>Original source: | ||
32 | * <code><pre> | ||
33 | * private pattern noHostToAllocateTo(App : ApplicationInstance) { | ||
34 | * find unallocatedAppInstance(App); | ||
35 | * neg find allocate(App, _); | ||
36 | * } | ||
37 | * </pre></code> | ||
38 | * | ||
39 | * @see GenericPatternMatcher | ||
40 | * @see GenericPatternMatch | ||
41 | * | ||
42 | */ | ||
43 | @SuppressWarnings("all") | ||
44 | public final class NoHostToAllocateTo extends BaseGeneratedEMFQuerySpecificationWithGenericMatcher { | ||
45 | private NoHostToAllocateTo() { | ||
46 | super(GeneratedPQuery.INSTANCE); | ||
47 | } | ||
48 | |||
49 | /** | ||
50 | * @return the singleton instance of the query specification | ||
51 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
52 | * | ||
53 | */ | ||
54 | public static NoHostToAllocateTo instance() { | ||
55 | try{ | ||
56 | return LazyHolder.INSTANCE; | ||
57 | } catch (ExceptionInInitializerError err) { | ||
58 | throw processInitializerError(err); | ||
59 | } | ||
60 | } | ||
61 | |||
62 | /** | ||
63 | * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.NoHostToAllocateTo (visibility: PUBLIC, simpleName: NoHostToAllocateTo, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.NoHostToAllocateTo, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal) (interface: false, strictFloatingPoint: false, anonymous: false)} to be created | ||
64 | * <b>not</b> at the class load time of the outer class, | ||
65 | * but rather at the first call to {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.NoHostToAllocateTo (visibility: PUBLIC, simpleName: NoHostToAllocateTo, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.NoHostToAllocateTo, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}. | ||
66 | * | ||
67 | * <p> This workaround is required e.g. to support recursion. | ||
68 | * | ||
69 | */ | ||
70 | private static class LazyHolder { | ||
71 | private static final NoHostToAllocateTo INSTANCE = new NoHostToAllocateTo(); | ||
72 | |||
73 | /** | ||
74 | * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned. | ||
75 | * This initialization order is required to support indirect recursion. | ||
76 | * | ||
77 | * <p> The static initializer is defined using a helper field to work around limitations of the code generator. | ||
78 | * | ||
79 | */ | ||
80 | private static final Object STATIC_INITIALIZER = ensureInitialized(); | ||
81 | |||
82 | public static Object ensureInitialized() { | ||
83 | INSTANCE.ensureInitializedInternal(); | ||
84 | return null; | ||
85 | } | ||
86 | } | ||
87 | |||
88 | private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { | ||
89 | private static final NoHostToAllocateTo.GeneratedPQuery INSTANCE = new GeneratedPQuery(); | ||
90 | |||
91 | 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); | ||
92 | |||
93 | private final List<PParameter> parameters = Arrays.asList(parameter_App); | ||
94 | |||
95 | private GeneratedPQuery() { | ||
96 | super(PVisibility.PRIVATE); | ||
97 | } | ||
98 | |||
99 | @Override | ||
100 | public String getFullyQualifiedName() { | ||
101 | return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.noHostToAllocateTo"; | ||
102 | } | ||
103 | |||
104 | @Override | ||
105 | public List<String> getParameterNames() { | ||
106 | return Arrays.asList("App"); | ||
107 | } | ||
108 | |||
109 | @Override | ||
110 | public List<PParameter> getParameters() { | ||
111 | return parameters; | ||
112 | } | ||
113 | |||
114 | @Override | ||
115 | public Set<PBody> doGetContainedBodies() { | ||
116 | setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); | ||
117 | Set<PBody> bodies = new LinkedHashSet<>(); | ||
118 | { | ||
119 | PBody body = new PBody(this); | ||
120 | PVariable var_App = body.getOrCreateVariableByName("App"); | ||
121 | PVariable var___0_ = body.getOrCreateVariableByName("_<0>"); | ||
122 | new TypeConstraint(body, Tuples.flatTupleOf(var_App), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance"))); | ||
123 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
124 | new ExportedParameter(body, var_App, parameter_App) | ||
125 | )); | ||
126 | // find unallocatedAppInstance(App) | ||
127 | new PositivePatternCall(body, Tuples.flatTupleOf(var_App), UnallocatedAppInstance.instance().getInternalQueryRepresentation()); | ||
128 | // neg find allocate(App, _) | ||
129 | new NegativePatternCall(body, Tuples.flatTupleOf(var_App, var___0_), Allocate.instance().getInternalQueryRepresentation()); | ||
130 | bodies.add(body); | ||
131 | } | ||
132 | return bodies; | ||
133 | } | ||
134 | } | ||
135 | } | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/RequiredAppInstances.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/RequiredAppInstances.java new file mode 100644 index 00000000..dc76cbde --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/RequiredAppInstances.java | |||
@@ -0,0 +1,181 @@ | |||
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.internal; | ||
5 | |||
6 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.SatisfyingInstance; | ||
7 | import java.util.Arrays; | ||
8 | import java.util.LinkedHashSet; | ||
9 | import java.util.List; | ||
10 | import java.util.Set; | ||
11 | import org.eclipse.emf.ecore.EClass; | ||
12 | import org.eclipse.emf.ecore.EDataType; | ||
13 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; | ||
14 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecificationWithGenericMatcher; | ||
15 | import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; | ||
16 | import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey; | ||
17 | import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; | ||
18 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
19 | import org.eclipse.viatra.query.runtime.matchers.context.common.JavaTransitiveInstancesKey; | ||
20 | import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator; | ||
21 | import org.eclipse.viatra.query.runtime.matchers.psystem.IValueProvider; | ||
22 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | ||
23 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | ||
24 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; | ||
25 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
26 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation; | ||
27 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.PatternMatchCounter; | ||
28 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.TypeFilterConstraint; | ||
29 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
30 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | ||
31 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; | ||
32 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | ||
33 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
34 | |||
35 | /** | ||
36 | * A pattern-specific query specification that can instantiate GenericPatternMatcher in a type-safe way. | ||
37 | * | ||
38 | * <p>Original source: | ||
39 | * <code><pre> | ||
40 | * private pattern requiredAppInstances(Req : Requirement, Remaining : java Integer) { | ||
41 | * Instances == count find satisfyingInstance(Req, _); | ||
42 | * Requirement.count(Req, RequiredCount); | ||
43 | * Remaining == eval(RequiredCount - Instances); | ||
44 | * } | ||
45 | * </pre></code> | ||
46 | * | ||
47 | * @see GenericPatternMatcher | ||
48 | * @see GenericPatternMatch | ||
49 | * | ||
50 | */ | ||
51 | @SuppressWarnings("all") | ||
52 | public final class RequiredAppInstances extends BaseGeneratedEMFQuerySpecificationWithGenericMatcher { | ||
53 | private RequiredAppInstances() { | ||
54 | super(GeneratedPQuery.INSTANCE); | ||
55 | } | ||
56 | |||
57 | /** | ||
58 | * @return the singleton instance of the query specification | ||
59 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
60 | * | ||
61 | */ | ||
62 | public static RequiredAppInstances instance() { | ||
63 | try{ | ||
64 | return LazyHolder.INSTANCE; | ||
65 | } catch (ExceptionInInitializerError err) { | ||
66 | throw processInitializerError(err); | ||
67 | } | ||
68 | } | ||
69 | |||
70 | /** | ||
71 | * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.RequiredAppInstances (visibility: PUBLIC, simpleName: RequiredAppInstances, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.RequiredAppInstances, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal) (interface: false, strictFloatingPoint: false, anonymous: false)} to be created | ||
72 | * <b>not</b> at the class load time of the outer class, | ||
73 | * but rather at the first call to {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.RequiredAppInstances (visibility: PUBLIC, simpleName: RequiredAppInstances, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.RequiredAppInstances, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}. | ||
74 | * | ||
75 | * <p> This workaround is required e.g. to support recursion. | ||
76 | * | ||
77 | */ | ||
78 | private static class LazyHolder { | ||
79 | private static final RequiredAppInstances INSTANCE = new RequiredAppInstances(); | ||
80 | |||
81 | /** | ||
82 | * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned. | ||
83 | * This initialization order is required to support indirect recursion. | ||
84 | * | ||
85 | * <p> The static initializer is defined using a helper field to work around limitations of the code generator. | ||
86 | * | ||
87 | */ | ||
88 | private static final Object STATIC_INITIALIZER = ensureInitialized(); | ||
89 | |||
90 | public static Object ensureInitialized() { | ||
91 | INSTANCE.ensureInitializedInternal(); | ||
92 | return null; | ||
93 | } | ||
94 | } | ||
95 | |||
96 | private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { | ||
97 | private static final RequiredAppInstances.GeneratedPQuery INSTANCE = new GeneratedPQuery(); | ||
98 | |||
99 | private final PParameter parameter_Req = new PParameter("Req", "hu.bme.mit.inf.dslreasoner.domains.cps.Requirement", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "Requirement")), PParameterDirection.INOUT); | ||
100 | |||
101 | private final PParameter parameter_Remaining = new PParameter("Remaining", "java.lang.Integer", new JavaTransitiveInstancesKey(java.lang.Integer.class), PParameterDirection.INOUT); | ||
102 | |||
103 | private final List<PParameter> parameters = Arrays.asList(parameter_Req, parameter_Remaining); | ||
104 | |||
105 | private GeneratedPQuery() { | ||
106 | super(PVisibility.PRIVATE); | ||
107 | } | ||
108 | |||
109 | @Override | ||
110 | public String getFullyQualifiedName() { | ||
111 | return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.requiredAppInstances"; | ||
112 | } | ||
113 | |||
114 | @Override | ||
115 | public List<String> getParameterNames() { | ||
116 | return Arrays.asList("Req","Remaining"); | ||
117 | } | ||
118 | |||
119 | @Override | ||
120 | public List<PParameter> getParameters() { | ||
121 | return parameters; | ||
122 | } | ||
123 | |||
124 | @Override | ||
125 | public Set<PBody> doGetContainedBodies() { | ||
126 | setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); | ||
127 | Set<PBody> bodies = new LinkedHashSet<>(); | ||
128 | { | ||
129 | PBody body = new PBody(this); | ||
130 | PVariable var_Req = body.getOrCreateVariableByName("Req"); | ||
131 | PVariable var_Remaining = body.getOrCreateVariableByName("Remaining"); | ||
132 | PVariable var_Instances = body.getOrCreateVariableByName("Instances"); | ||
133 | PVariable var___0_ = body.getOrCreateVariableByName("_<0>"); | ||
134 | PVariable var_RequiredCount = body.getOrCreateVariableByName("RequiredCount"); | ||
135 | new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "Requirement"))); | ||
136 | new TypeFilterConstraint(body, Tuples.flatTupleOf(var_Remaining), new JavaTransitiveInstancesKey(java.lang.Integer.class)); | ||
137 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
138 | new ExportedParameter(body, var_Req, parameter_Req), | ||
139 | new ExportedParameter(body, var_Remaining, parameter_Remaining) | ||
140 | )); | ||
141 | // Instances == count find satisfyingInstance(Req, _) | ||
142 | PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); | ||
143 | new PatternMatchCounter(body, Tuples.flatTupleOf(var_Req, var___0_), SatisfyingInstance.instance().getInternalQueryRepresentation(), var__virtual_0_); | ||
144 | new Equality(body, var_Instances, var__virtual_0_); | ||
145 | // Requirement.count(Req, RequiredCount) | ||
146 | new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "Requirement"))); | ||
147 | PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); | ||
148 | new TypeConstraint(body, Tuples.flatTupleOf(var_Req, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "Requirement", "count"))); | ||
149 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt"))); | ||
150 | new Equality(body, var__virtual_1_, var_RequiredCount); | ||
151 | // Remaining == eval(RequiredCount - Instances) | ||
152 | PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}"); | ||
153 | new ExpressionEvaluation(body, new IExpressionEvaluator() { | ||
154 | |||
155 | @Override | ||
156 | public String getShortDescription() { | ||
157 | return "Expression evaluation from pattern requiredAppInstances"; | ||
158 | } | ||
159 | |||
160 | @Override | ||
161 | public Iterable<String> getInputParameterNames() { | ||
162 | return Arrays.asList("Instances", "RequiredCount");} | ||
163 | |||
164 | @Override | ||
165 | public Object evaluateExpression(IValueProvider provider) throws Exception { | ||
166 | Integer Instances = (Integer) provider.getValue("Instances"); | ||
167 | Integer RequiredCount = (Integer) provider.getValue("RequiredCount"); | ||
168 | return evaluateExpression_1_1(Instances, RequiredCount); | ||
169 | } | ||
170 | }, var__virtual_2_ ); | ||
171 | new Equality(body, var_Remaining, var__virtual_2_); | ||
172 | bodies.add(body); | ||
173 | } | ||
174 | return bodies; | ||
175 | } | ||
176 | } | ||
177 | |||
178 | private static int evaluateExpression_1_1(final Integer Instances, final Integer RequiredCount) { | ||
179 | return ((RequiredCount).intValue() - (Instances).intValue()); | ||
180 | } | ||
181 | } | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/SatisfyingInstance.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/SatisfyingInstance.java new file mode 100644 index 00000000..4285101c --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/SatisfyingInstance.java | |||
@@ -0,0 +1,153 @@ | |||
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.internal; | ||
5 | |||
6 | import java.util.Arrays; | ||
7 | import java.util.LinkedHashSet; | ||
8 | import java.util.List; | ||
9 | import java.util.Set; | ||
10 | import org.eclipse.emf.ecore.EClass; | ||
11 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; | ||
12 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecificationWithGenericMatcher; | ||
13 | import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; | ||
14 | import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; | ||
15 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
16 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | ||
17 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | ||
18 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; | ||
19 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
20 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
21 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | ||
22 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; | ||
23 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | ||
24 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
25 | |||
26 | /** | ||
27 | * A pattern-specific query specification that can instantiate GenericPatternMatcher in a type-safe way. | ||
28 | * | ||
29 | * <p>Original source: | ||
30 | * <code><pre> | ||
31 | * private pattern satisfyingInstance(Req : Requirement, App : ApplicationInstance) { | ||
32 | * Requirement.instances(Req, App); | ||
33 | * Requirement.type(Req, Type); | ||
34 | * ApplicationInstance.type(App, Type); | ||
35 | * } | ||
36 | * </pre></code> | ||
37 | * | ||
38 | * @see GenericPatternMatcher | ||
39 | * @see GenericPatternMatch | ||
40 | * | ||
41 | */ | ||
42 | @SuppressWarnings("all") | ||
43 | public final class SatisfyingInstance extends BaseGeneratedEMFQuerySpecificationWithGenericMatcher { | ||
44 | private SatisfyingInstance() { | ||
45 | super(GeneratedPQuery.INSTANCE); | ||
46 | } | ||
47 | |||
48 | /** | ||
49 | * @return the singleton instance of the query specification | ||
50 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
51 | * | ||
52 | */ | ||
53 | public static SatisfyingInstance instance() { | ||
54 | try{ | ||
55 | return LazyHolder.INSTANCE; | ||
56 | } catch (ExceptionInInitializerError err) { | ||
57 | throw processInitializerError(err); | ||
58 | } | ||
59 | } | ||
60 | |||
61 | /** | ||
62 | * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.SatisfyingInstance (visibility: PUBLIC, simpleName: SatisfyingInstance, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.SatisfyingInstance, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal) (interface: false, strictFloatingPoint: false, anonymous: false)} to be created | ||
63 | * <b>not</b> at the class load time of the outer class, | ||
64 | * but rather at the first call to {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.SatisfyingInstance (visibility: PUBLIC, simpleName: SatisfyingInstance, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.SatisfyingInstance, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}. | ||
65 | * | ||
66 | * <p> This workaround is required e.g. to support recursion. | ||
67 | * | ||
68 | */ | ||
69 | private static class LazyHolder { | ||
70 | private static final SatisfyingInstance INSTANCE = new SatisfyingInstance(); | ||
71 | |||
72 | /** | ||
73 | * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned. | ||
74 | * This initialization order is required to support indirect recursion. | ||
75 | * | ||
76 | * <p> The static initializer is defined using a helper field to work around limitations of the code generator. | ||
77 | * | ||
78 | */ | ||
79 | private static final Object STATIC_INITIALIZER = ensureInitialized(); | ||
80 | |||
81 | public static Object ensureInitialized() { | ||
82 | INSTANCE.ensureInitializedInternal(); | ||
83 | return null; | ||
84 | } | ||
85 | } | ||
86 | |||
87 | private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { | ||
88 | private static final SatisfyingInstance.GeneratedPQuery INSTANCE = new GeneratedPQuery(); | ||
89 | |||
90 | private final PParameter parameter_Req = new PParameter("Req", "hu.bme.mit.inf.dslreasoner.domains.cps.Requirement", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "Requirement")), PParameterDirection.INOUT); | ||
91 | |||
92 | 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); | ||
93 | |||
94 | private final List<PParameter> parameters = Arrays.asList(parameter_Req, parameter_App); | ||
95 | |||
96 | private GeneratedPQuery() { | ||
97 | super(PVisibility.PRIVATE); | ||
98 | } | ||
99 | |||
100 | @Override | ||
101 | public String getFullyQualifiedName() { | ||
102 | return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.satisfyingInstance"; | ||
103 | } | ||
104 | |||
105 | @Override | ||
106 | public List<String> getParameterNames() { | ||
107 | return Arrays.asList("Req","App"); | ||
108 | } | ||
109 | |||
110 | @Override | ||
111 | public List<PParameter> getParameters() { | ||
112 | return parameters; | ||
113 | } | ||
114 | |||
115 | @Override | ||
116 | public Set<PBody> doGetContainedBodies() { | ||
117 | setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); | ||
118 | Set<PBody> bodies = new LinkedHashSet<>(); | ||
119 | { | ||
120 | PBody body = new PBody(this); | ||
121 | PVariable var_Req = body.getOrCreateVariableByName("Req"); | ||
122 | PVariable var_App = body.getOrCreateVariableByName("App"); | ||
123 | PVariable var_Type = body.getOrCreateVariableByName("Type"); | ||
124 | new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "Requirement"))); | ||
125 | new TypeConstraint(body, Tuples.flatTupleOf(var_App), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance"))); | ||
126 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
127 | new ExportedParameter(body, var_Req, parameter_Req), | ||
128 | new ExportedParameter(body, var_App, parameter_App) | ||
129 | )); | ||
130 | // Requirement.instances(Req, App) | ||
131 | new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "Requirement"))); | ||
132 | PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); | ||
133 | new TypeConstraint(body, Tuples.flatTupleOf(var_Req, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "Requirement", "instances"))); | ||
134 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance"))); | ||
135 | new Equality(body, var__virtual_0_, var_App); | ||
136 | // Requirement.type(Req, Type) | ||
137 | new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "Requirement"))); | ||
138 | PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); | ||
139 | new TypeConstraint(body, Tuples.flatTupleOf(var_Req, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "Requirement", "type"))); | ||
140 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationType"))); | ||
141 | new Equality(body, var__virtual_1_, var_Type); | ||
142 | // ApplicationInstance.type(App, Type) | ||
143 | new TypeConstraint(body, Tuples.flatTupleOf(var_App), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance"))); | ||
144 | PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}"); | ||
145 | new TypeConstraint(body, Tuples.flatTupleOf(var_App, var__virtual_2_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ApplicationInstance", "type"))); | ||
146 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationType"))); | ||
147 | new Equality(body, var__virtual_2_, var_Type); | ||
148 | bodies.add(body); | ||
149 | } | ||
150 | return bodies; | ||
151 | } | ||
152 | } | ||
153 | } | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/TotalHdd.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/TotalHdd.java new file mode 100644 index 00000000..f250f76d --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/TotalHdd.java | |||
@@ -0,0 +1,143 @@ | |||
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.internal; | ||
5 | |||
6 | import java.util.Arrays; | ||
7 | import java.util.LinkedHashSet; | ||
8 | import java.util.List; | ||
9 | import java.util.Set; | ||
10 | import org.eclipse.emf.ecore.EClass; | ||
11 | import org.eclipse.emf.ecore.EDataType; | ||
12 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; | ||
13 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecificationWithGenericMatcher; | ||
14 | import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; | ||
15 | import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey; | ||
16 | import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; | ||
17 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
18 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | ||
19 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | ||
20 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; | ||
21 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
22 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
23 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | ||
24 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; | ||
25 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | ||
26 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
27 | |||
28 | /** | ||
29 | * A pattern-specific query specification that can instantiate GenericPatternMatcher in a type-safe way. | ||
30 | * | ||
31 | * <p>Original source: | ||
32 | * <code><pre> | ||
33 | * private pattern totalHdd(Host : HostInstance, Hdd : EInt) { | ||
34 | * HostInstance.type.defaultHdd(Host, Hdd); | ||
35 | * } | ||
36 | * </pre></code> | ||
37 | * | ||
38 | * @see GenericPatternMatcher | ||
39 | * @see GenericPatternMatch | ||
40 | * | ||
41 | */ | ||
42 | @SuppressWarnings("all") | ||
43 | public final class TotalHdd extends BaseGeneratedEMFQuerySpecificationWithGenericMatcher { | ||
44 | private TotalHdd() { | ||
45 | super(GeneratedPQuery.INSTANCE); | ||
46 | } | ||
47 | |||
48 | /** | ||
49 | * @return the singleton instance of the query specification | ||
50 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
51 | * | ||
52 | */ | ||
53 | public static TotalHdd instance() { | ||
54 | try{ | ||
55 | return LazyHolder.INSTANCE; | ||
56 | } catch (ExceptionInInitializerError err) { | ||
57 | throw processInitializerError(err); | ||
58 | } | ||
59 | } | ||
60 | |||
61 | /** | ||
62 | * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.TotalHdd (visibility: PUBLIC, simpleName: TotalHdd, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.TotalHdd, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal) (interface: false, strictFloatingPoint: false, anonymous: false)} to be created | ||
63 | * <b>not</b> at the class load time of the outer class, | ||
64 | * but rather at the first call to {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.TotalHdd (visibility: PUBLIC, simpleName: TotalHdd, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.TotalHdd, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}. | ||
65 | * | ||
66 | * <p> This workaround is required e.g. to support recursion. | ||
67 | * | ||
68 | */ | ||
69 | private static class LazyHolder { | ||
70 | private static final TotalHdd INSTANCE = new TotalHdd(); | ||
71 | |||
72 | /** | ||
73 | * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned. | ||
74 | * This initialization order is required to support indirect recursion. | ||
75 | * | ||
76 | * <p> The static initializer is defined using a helper field to work around limitations of the code generator. | ||
77 | * | ||
78 | */ | ||
79 | private static final Object STATIC_INITIALIZER = ensureInitialized(); | ||
80 | |||
81 | public static Object ensureInitialized() { | ||
82 | INSTANCE.ensureInitializedInternal(); | ||
83 | return null; | ||
84 | } | ||
85 | } | ||
86 | |||
87 | private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { | ||
88 | private static final TotalHdd.GeneratedPQuery INSTANCE = new GeneratedPQuery(); | ||
89 | |||
90 | 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); | ||
91 | |||
92 | private final PParameter parameter_Hdd = new PParameter("Hdd", "java.lang.Integer", new EDataTypeInSlotsKey((EDataType)getClassifierLiteralSafe("http://www.eclipse.org/emf/2002/Ecore", "EInt")), PParameterDirection.INOUT); | ||
93 | |||
94 | private final List<PParameter> parameters = Arrays.asList(parameter_Host, parameter_Hdd); | ||
95 | |||
96 | private GeneratedPQuery() { | ||
97 | super(PVisibility.PRIVATE); | ||
98 | } | ||
99 | |||
100 | @Override | ||
101 | public String getFullyQualifiedName() { | ||
102 | return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.totalHdd"; | ||
103 | } | ||
104 | |||
105 | @Override | ||
106 | public List<String> getParameterNames() { | ||
107 | return Arrays.asList("Host","Hdd"); | ||
108 | } | ||
109 | |||
110 | @Override | ||
111 | public List<PParameter> getParameters() { | ||
112 | return parameters; | ||
113 | } | ||
114 | |||
115 | @Override | ||
116 | public Set<PBody> doGetContainedBodies() { | ||
117 | setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); | ||
118 | Set<PBody> bodies = new LinkedHashSet<>(); | ||
119 | { | ||
120 | PBody body = new PBody(this); | ||
121 | PVariable var_Host = body.getOrCreateVariableByName("Host"); | ||
122 | PVariable var_Hdd = body.getOrCreateVariableByName("Hdd"); | ||
123 | new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); | ||
124 | new TypeConstraint(body, Tuples.flatTupleOf(var_Hdd), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt"))); | ||
125 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
126 | new ExportedParameter(body, var_Host, parameter_Host), | ||
127 | new ExportedParameter(body, var_Hdd, parameter_Hdd) | ||
128 | )); | ||
129 | // HostInstance.type.defaultHdd(Host, Hdd) | ||
130 | new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); | ||
131 | PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); | ||
132 | new TypeConstraint(body, Tuples.flatTupleOf(var_Host, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "HostInstance", "type"))); | ||
133 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostType"))); | ||
134 | PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); | ||
135 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "HostType", "defaultHdd"))); | ||
136 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt"))); | ||
137 | new Equality(body, var__virtual_1_, var_Hdd); | ||
138 | bodies.add(body); | ||
139 | } | ||
140 | return bodies; | ||
141 | } | ||
142 | } | ||
143 | } | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/TotalMemory.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/TotalMemory.java new file mode 100644 index 00000000..aecd97e2 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/TotalMemory.java | |||
@@ -0,0 +1,143 @@ | |||
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.internal; | ||
5 | |||
6 | import java.util.Arrays; | ||
7 | import java.util.LinkedHashSet; | ||
8 | import java.util.List; | ||
9 | import java.util.Set; | ||
10 | import org.eclipse.emf.ecore.EClass; | ||
11 | import org.eclipse.emf.ecore.EDataType; | ||
12 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; | ||
13 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecificationWithGenericMatcher; | ||
14 | import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; | ||
15 | import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey; | ||
16 | import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; | ||
17 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
18 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | ||
19 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | ||
20 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; | ||
21 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
22 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
23 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | ||
24 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; | ||
25 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | ||
26 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
27 | |||
28 | /** | ||
29 | * A pattern-specific query specification that can instantiate GenericPatternMatcher in a type-safe way. | ||
30 | * | ||
31 | * <p>Original source: | ||
32 | * <code><pre> | ||
33 | * private pattern totalMemory(Host : HostInstance, Memory : EInt) { | ||
34 | * HostInstance.type.defaultMemory(Host, Memory); | ||
35 | * } | ||
36 | * </pre></code> | ||
37 | * | ||
38 | * @see GenericPatternMatcher | ||
39 | * @see GenericPatternMatch | ||
40 | * | ||
41 | */ | ||
42 | @SuppressWarnings("all") | ||
43 | public final class TotalMemory extends BaseGeneratedEMFQuerySpecificationWithGenericMatcher { | ||
44 | private TotalMemory() { | ||
45 | super(GeneratedPQuery.INSTANCE); | ||
46 | } | ||
47 | |||
48 | /** | ||
49 | * @return the singleton instance of the query specification | ||
50 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
51 | * | ||
52 | */ | ||
53 | public static TotalMemory instance() { | ||
54 | try{ | ||
55 | return LazyHolder.INSTANCE; | ||
56 | } catch (ExceptionInInitializerError err) { | ||
57 | throw processInitializerError(err); | ||
58 | } | ||
59 | } | ||
60 | |||
61 | /** | ||
62 | * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.TotalMemory (visibility: PUBLIC, simpleName: TotalMemory, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.TotalMemory, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal) (interface: false, strictFloatingPoint: false, anonymous: false)} to be created | ||
63 | * <b>not</b> at the class load time of the outer class, | ||
64 | * but rather at the first call to {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.TotalMemory (visibility: PUBLIC, simpleName: TotalMemory, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.TotalMemory, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}. | ||
65 | * | ||
66 | * <p> This workaround is required e.g. to support recursion. | ||
67 | * | ||
68 | */ | ||
69 | private static class LazyHolder { | ||
70 | private static final TotalMemory INSTANCE = new TotalMemory(); | ||
71 | |||
72 | /** | ||
73 | * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned. | ||
74 | * This initialization order is required to support indirect recursion. | ||
75 | * | ||
76 | * <p> The static initializer is defined using a helper field to work around limitations of the code generator. | ||
77 | * | ||
78 | */ | ||
79 | private static final Object STATIC_INITIALIZER = ensureInitialized(); | ||
80 | |||
81 | public static Object ensureInitialized() { | ||
82 | INSTANCE.ensureInitializedInternal(); | ||
83 | return null; | ||
84 | } | ||
85 | } | ||
86 | |||
87 | private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { | ||
88 | private static final TotalMemory.GeneratedPQuery INSTANCE = new GeneratedPQuery(); | ||
89 | |||
90 | 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); | ||
91 | |||
92 | private final PParameter parameter_Memory = new PParameter("Memory", "java.lang.Integer", new EDataTypeInSlotsKey((EDataType)getClassifierLiteralSafe("http://www.eclipse.org/emf/2002/Ecore", "EInt")), PParameterDirection.INOUT); | ||
93 | |||
94 | private final List<PParameter> parameters = Arrays.asList(parameter_Host, parameter_Memory); | ||
95 | |||
96 | private GeneratedPQuery() { | ||
97 | super(PVisibility.PRIVATE); | ||
98 | } | ||
99 | |||
100 | @Override | ||
101 | public String getFullyQualifiedName() { | ||
102 | return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.totalMemory"; | ||
103 | } | ||
104 | |||
105 | @Override | ||
106 | public List<String> getParameterNames() { | ||
107 | return Arrays.asList("Host","Memory"); | ||
108 | } | ||
109 | |||
110 | @Override | ||
111 | public List<PParameter> getParameters() { | ||
112 | return parameters; | ||
113 | } | ||
114 | |||
115 | @Override | ||
116 | public Set<PBody> doGetContainedBodies() { | ||
117 | setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); | ||
118 | Set<PBody> bodies = new LinkedHashSet<>(); | ||
119 | { | ||
120 | PBody body = new PBody(this); | ||
121 | PVariable var_Host = body.getOrCreateVariableByName("Host"); | ||
122 | PVariable var_Memory = body.getOrCreateVariableByName("Memory"); | ||
123 | new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); | ||
124 | new TypeConstraint(body, Tuples.flatTupleOf(var_Memory), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt"))); | ||
125 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
126 | new ExportedParameter(body, var_Host, parameter_Host), | ||
127 | new ExportedParameter(body, var_Memory, parameter_Memory) | ||
128 | )); | ||
129 | // HostInstance.type.defaultMemory(Host, Memory) | ||
130 | new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); | ||
131 | PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); | ||
132 | new TypeConstraint(body, Tuples.flatTupleOf(var_Host, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "HostInstance", "type"))); | ||
133 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostType"))); | ||
134 | PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); | ||
135 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "HostType", "defaultMemory"))); | ||
136 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt"))); | ||
137 | new Equality(body, var__virtual_1_, var_Memory); | ||
138 | bodies.add(body); | ||
139 | } | ||
140 | return bodies; | ||
141 | } | ||
142 | } | ||
143 | } | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/UnallocatedAppInstance.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/UnallocatedAppInstance.java new file mode 100644 index 00000000..a20b534c --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/UnallocatedAppInstance.java | |||
@@ -0,0 +1,172 @@ | |||
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.internal; | ||
5 | |||
6 | import java.util.Arrays; | ||
7 | import java.util.Collections; | ||
8 | import java.util.LinkedHashSet; | ||
9 | import java.util.List; | ||
10 | import java.util.Set; | ||
11 | import org.eclipse.emf.ecore.EClass; | ||
12 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; | ||
13 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecificationWithGenericMatcher; | ||
14 | import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; | ||
15 | import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; | ||
16 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
17 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | ||
18 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | ||
19 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; | ||
20 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
21 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.NegativePatternCall; | ||
22 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
23 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | ||
24 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; | ||
25 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | ||
26 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
27 | |||
28 | /** | ||
29 | * A pattern-specific query specification that can instantiate GenericPatternMatcher in a type-safe way. | ||
30 | * | ||
31 | * <p>Original source: | ||
32 | * <code><pre> | ||
33 | * private pattern unallocatedAppInstance(App : ApplicationInstance) { | ||
34 | * neg ApplicationInstance.allocatedTo(App, _); | ||
35 | * } | ||
36 | * </pre></code> | ||
37 | * | ||
38 | * @see GenericPatternMatcher | ||
39 | * @see GenericPatternMatch | ||
40 | * | ||
41 | */ | ||
42 | @SuppressWarnings("all") | ||
43 | public final class UnallocatedAppInstance extends BaseGeneratedEMFQuerySpecificationWithGenericMatcher { | ||
44 | private UnallocatedAppInstance() { | ||
45 | super(GeneratedPQuery.INSTANCE); | ||
46 | } | ||
47 | |||
48 | /** | ||
49 | * @return the singleton instance of the query specification | ||
50 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
51 | * | ||
52 | */ | ||
53 | public static UnallocatedAppInstance instance() { | ||
54 | try{ | ||
55 | return LazyHolder.INSTANCE; | ||
56 | } catch (ExceptionInInitializerError err) { | ||
57 | throw processInitializerError(err); | ||
58 | } | ||
59 | } | ||
60 | |||
61 | /** | ||
62 | * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.UnallocatedAppInstance (visibility: PUBLIC, simpleName: UnallocatedAppInstance, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.UnallocatedAppInstance, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal) (interface: false, strictFloatingPoint: false, anonymous: false)} to be created | ||
63 | * <b>not</b> at the class load time of the outer class, | ||
64 | * but rather at the first call to {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.UnallocatedAppInstance (visibility: PUBLIC, simpleName: UnallocatedAppInstance, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.UnallocatedAppInstance, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}. | ||
65 | * | ||
66 | * <p> This workaround is required e.g. to support recursion. | ||
67 | * | ||
68 | */ | ||
69 | private static class LazyHolder { | ||
70 | private static final UnallocatedAppInstance INSTANCE = new UnallocatedAppInstance(); | ||
71 | |||
72 | /** | ||
73 | * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned. | ||
74 | * This initialization order is required to support indirect recursion. | ||
75 | * | ||
76 | * <p> The static initializer is defined using a helper field to work around limitations of the code generator. | ||
77 | * | ||
78 | */ | ||
79 | private static final Object STATIC_INITIALIZER = ensureInitialized(); | ||
80 | |||
81 | public static Object ensureInitialized() { | ||
82 | INSTANCE.ensureInitializedInternal(); | ||
83 | return null; | ||
84 | } | ||
85 | } | ||
86 | |||
87 | private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { | ||
88 | private static final UnallocatedAppInstance.GeneratedPQuery INSTANCE = new GeneratedPQuery(); | ||
89 | |||
90 | 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); | ||
91 | |||
92 | private final List<PParameter> parameters = Arrays.asList(parameter_App); | ||
93 | |||
94 | private class Embedded_1_ApplicationInstance_allocatedTo extends BaseGeneratedEMFPQuery { | ||
95 | 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); | ||
96 | |||
97 | 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); | ||
98 | |||
99 | private final List<PParameter> embeddedParameters = Arrays.asList(parameter_p0, parameter_p1); | ||
100 | |||
101 | public Embedded_1_ApplicationInstance_allocatedTo() { | ||
102 | super(PVisibility.EMBEDDED); | ||
103 | } | ||
104 | |||
105 | @Override | ||
106 | public String getFullyQualifiedName() { | ||
107 | return GeneratedPQuery.this.getFullyQualifiedName() + "$Embedded_1_ApplicationInstance_allocatedTo"; | ||
108 | } | ||
109 | |||
110 | @Override | ||
111 | public List<PParameter> getParameters() { | ||
112 | return embeddedParameters; | ||
113 | } | ||
114 | |||
115 | @Override | ||
116 | public Set<PBody> doGetContainedBodies() { | ||
117 | PBody body = new PBody(this); | ||
118 | PVariable var_p0 = body.getOrCreateVariableByName("p0"); | ||
119 | PVariable var_p1 = body.getOrCreateVariableByName("p1"); | ||
120 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
121 | new ExportedParameter(body, var_p0, parameter_p0), | ||
122 | new ExportedParameter(body, var_p1, parameter_p1) | ||
123 | )); | ||
124 | // ApplicationInstance.allocatedTo(App, _) | ||
125 | new TypeConstraint(body, Tuples.flatTupleOf(var_p0), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance"))); | ||
126 | PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); | ||
127 | new TypeConstraint(body, Tuples.flatTupleOf(var_p0, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ApplicationInstance", "allocatedTo"))); | ||
128 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); | ||
129 | new Equality(body, var__virtual_0_, var_p1); | ||
130 | return Collections.singleton(body); | ||
131 | } | ||
132 | } | ||
133 | |||
134 | private GeneratedPQuery() { | ||
135 | super(PVisibility.PRIVATE); | ||
136 | } | ||
137 | |||
138 | @Override | ||
139 | public String getFullyQualifiedName() { | ||
140 | return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.unallocatedAppInstance"; | ||
141 | } | ||
142 | |||
143 | @Override | ||
144 | public List<String> getParameterNames() { | ||
145 | return Arrays.asList("App"); | ||
146 | } | ||
147 | |||
148 | @Override | ||
149 | public List<PParameter> getParameters() { | ||
150 | return parameters; | ||
151 | } | ||
152 | |||
153 | @Override | ||
154 | public Set<PBody> doGetContainedBodies() { | ||
155 | setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); | ||
156 | Set<PBody> bodies = new LinkedHashSet<>(); | ||
157 | { | ||
158 | PBody body = new PBody(this); | ||
159 | PVariable var_App = body.getOrCreateVariableByName("App"); | ||
160 | PVariable var___0_ = body.getOrCreateVariableByName("_<0>"); | ||
161 | new TypeConstraint(body, Tuples.flatTupleOf(var_App), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance"))); | ||
162 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
163 | new ExportedParameter(body, var_App, parameter_App) | ||
164 | )); | ||
165 | // neg ApplicationInstance.allocatedTo(App, _) | ||
166 | new NegativePatternCall(body, Tuples.flatTupleOf(var_App, var___0_), new UnallocatedAppInstance.GeneratedPQuery.Embedded_1_ApplicationInstance_allocatedTo()); | ||
167 | bodies.add(body); | ||
168 | } | ||
169 | return bodies; | ||
170 | } | ||
171 | } | ||
172 | } | ||