From e904f9d4b1d2d15ab4ec6d72ee881f4c7de34eef Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Wed, 15 May 2019 13:46:38 -0400 Subject: Formalize CPS case study for optimization --- .../inf/dslreasoner/domains/cps/queries/.gitignore | 16 + .../AllocationWithoutResourceRequirement.java | 717 ++++++++++++++++++++ .../domains/cps/queries/AvailableHdd.java | 743 +++++++++++++++++++++ .../domains/cps/queries/AvailableMemory.java | 743 +++++++++++++++++++++ .../domains/cps/queries/AverageFreeHddMetric.java | 540 +++++++++++++++ .../cps/queries/AverageFreeMemoryMetric.java | 540 +++++++++++++++ .../domains/cps/queries/CostMetric.java | 540 +++++++++++++++ .../domains/cps/queries/CpsApplications.java | 705 +++++++++++++++++++ .../dslreasoner/domains/cps/queries/CpsCost.java | 738 ++++++++++++++++++++ .../dslreasoner/domains/cps/queries/CpsHosts.java | 705 +++++++++++++++++++ .../domains/cps/queries/CpsQueries.java | 207 ++++++ .../queries/InstanceDoesNotSatisfyRequirement.java | 716 ++++++++++++++++++++ .../domains/cps/queries/NotEnoughAvailableHdd.java | 579 ++++++++++++++++ .../cps/queries/NotEnoughAvailableMemory.java | 579 ++++++++++++++++ .../cps/queries/RequirementNotSatisfied.java | 597 +++++++++++++++++ .../dslreasoner/domains/cps/queries/TotalHdd.java | 706 ++++++++++++++++++++ .../domains/cps/queries/TotalMemory.java | 706 ++++++++++++++++++++ .../domains/cps/queries/internal/.gitignore | 11 + .../cps/queries/internal/CpsQueriesAll.java | 105 +++ .../cps/queries/internal/FreeHddPercentage.java | 172 +++++ .../cps/queries/internal/FreeMemoryPercentage.java | 172 +++++ .../cps/queries/internal/HddRequirement.java | 151 +++++ .../cps/queries/internal/HostInstanceCost.java | 153 +++++ .../cps/queries/internal/MemoryRequirement.java | 151 +++++ .../cps/queries/internal/ResourceRequirement.java | 168 +++++ .../cps/queries/internal/SatisfyingInstance.java | 153 +++++ 26 files changed, 11313 insertions(+) create mode 100644 Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/.gitignore create mode 100644 Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/AllocationWithoutResourceRequirement.java create mode 100644 Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/AvailableHdd.java create mode 100644 Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/AvailableMemory.java create mode 100644 Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/AverageFreeHddMetric.java create mode 100644 Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/AverageFreeMemoryMetric.java create mode 100644 Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CostMetric.java create mode 100644 Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsApplications.java create mode 100644 Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsCost.java create mode 100644 Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsHosts.java create mode 100644 Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.java create mode 100644 Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/InstanceDoesNotSatisfyRequirement.java create mode 100644 Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/NotEnoughAvailableHdd.java create mode 100644 Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/NotEnoughAvailableMemory.java create mode 100644 Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/RequirementNotSatisfied.java create mode 100644 Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/TotalHdd.java create mode 100644 Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/TotalMemory.java create mode 100644 Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/.gitignore create mode 100644 Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/CpsQueriesAll.java create mode 100644 Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/FreeHddPercentage.java create mode 100644 Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/FreeMemoryPercentage.java create mode 100644 Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/HddRequirement.java create mode 100644 Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/HostInstanceCost.java create mode 100644 Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/MemoryRequirement.java create mode 100644 Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/ResourceRequirement.java create mode 100644 Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/SatisfyingInstance.java (limited to 'Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains') 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..bd8f7d9f --- /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,16 @@ +/.CpsApplications.java._trace +/.CpsQueries.java._trace +/.CpsHosts.java._trace +/.TotalMemory.java._trace +/.TotalHdd.java._trace +/.AvailableMemory.java._trace +/.AvailableHdd.java._trace +/.AllocationWithoutResourceRequirement.java._trace +/.NotEnoughAvailableMemory.java._trace +/.NotEnoughAvailableHdd.java._trace +/.InstanceDoesNotSatisfyRequirement.java._trace +/.RequirementNotSatisfied.java._trace +/.AverageFreeMemoryMetric.java._trace +/.AverageFreeHddMetric.java._trace +/.CostMetric.java._trace +/.CpsCost.java._trace 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..be7488b6 --- /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 @@ +/** + * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql + */ +package hu.bme.mit.inf.dslreasoner.domains.cps.queries; + +import hu.bme.mit.inf.dslreasoner.domains.cps.ApplicationInstance; +import hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.ResourceRequirement; +import java.util.Arrays; +import java.util.Collection; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.function.Consumer; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import org.apache.log4j.Logger; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.viatra.query.runtime.api.IPatternMatch; +import org.eclipse.viatra.query.runtime.api.IQuerySpecification; +import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; +import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; +import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; +import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; +import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; +import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; +import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; +import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; +import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; +import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; +import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation; +import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.NegativePatternCall; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; +import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; +import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; +import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; + +/** + * A pattern-specific query specification that can instantiate Matcher in a type-safe way. + * + *

Original source: + *

+ *         {@literal @}Constraint(severity = "error", key = {Host, App},
+ *         	message = "Application instance must be allocated to a supported host type.")
+ *         pattern allocationWithoutResourceRequirement(Host : HostInstance, App : ApplicationInstance) {
+ *         	ApplicationInstance.allocatedTo(App, Host);
+ *         	neg find resourceRequirement(Host, App, _);
+ *         }
+ * 
+ * + * @see Matcher + * @see Match + * + */ +@SuppressWarnings("all") +public final class AllocationWithoutResourceRequirement extends BaseGeneratedEMFQuerySpecification { + /** + * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.allocationWithoutResourceRequirement pattern, + * to be used in conjunction with {@link Matcher}. + * + *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. + * Each instance is a (possibly partial) substitution of pattern parameters, + * usable to represent a match of the pattern in the result of a query, + * or to specify the bound (fixed) input parameters when issuing a query. + * + * @see Matcher + * + */ + public static abstract class Match extends BasePatternMatch { + private HostInstance fHost; + + private ApplicationInstance fApp; + + private static List parameterNames = makeImmutableList("Host", "App"); + + private Match(final HostInstance pHost, final ApplicationInstance pApp) { + this.fHost = pHost; + this.fApp = pApp; + } + + @Override + public Object get(final String parameterName) { + if ("Host".equals(parameterName)) return this.fHost; + if ("App".equals(parameterName)) return this.fApp; + return null; + } + + public HostInstance getHost() { + return this.fHost; + } + + public ApplicationInstance getApp() { + return this.fApp; + } + + @Override + public boolean set(final String parameterName, final Object newValue) { + if (!isMutable()) throw new java.lang.UnsupportedOperationException(); + if ("Host".equals(parameterName) ) { + this.fHost = (HostInstance) newValue; + return true; + } + if ("App".equals(parameterName) ) { + this.fApp = (ApplicationInstance) newValue; + return true; + } + return false; + } + + public void setHost(final HostInstance pHost) { + if (!isMutable()) throw new java.lang.UnsupportedOperationException(); + this.fHost = pHost; + } + + public void setApp(final ApplicationInstance pApp) { + if (!isMutable()) throw new java.lang.UnsupportedOperationException(); + this.fApp = pApp; + } + + @Override + public String patternName() { + return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.allocationWithoutResourceRequirement"; + } + + @Override + public List parameterNames() { + return AllocationWithoutResourceRequirement.Match.parameterNames; + } + + @Override + public Object[] toArray() { + return new Object[]{fHost, fApp}; + } + + @Override + public AllocationWithoutResourceRequirement.Match toImmutable() { + return isMutable() ? newMatch(fHost, fApp) : this; + } + + @Override + public String prettyPrint() { + StringBuilder result = new StringBuilder(); + result.append("\"Host\"=" + prettyPrintValue(fHost) + ", "); + result.append("\"App\"=" + prettyPrintValue(fApp)); + return result.toString(); + } + + @Override + public int hashCode() { + return Objects.hash(fHost, fApp); + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) + return true; + if (obj == null) { + return false; + } + if ((obj instanceof AllocationWithoutResourceRequirement.Match)) { + AllocationWithoutResourceRequirement.Match other = (AllocationWithoutResourceRequirement.Match) obj; + return Objects.equals(fHost, other.fHost) && Objects.equals(fApp, other.fApp); + } else { + // this should be infrequent + if (!(obj instanceof IPatternMatch)) { + return false; + } + IPatternMatch otherSig = (IPatternMatch) obj; + return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); + } + } + + @Override + public AllocationWithoutResourceRequirement specification() { + return AllocationWithoutResourceRequirement.instance(); + } + + /** + * Returns an empty, mutable match. + * Fields of the mutable match can be filled to create a partial match, usable as matcher input. + * + * @return the empty match. + * + */ + public static AllocationWithoutResourceRequirement.Match newEmptyMatch() { + return new Mutable(null, null); + } + + /** + * Returns a mutable (partial) match. + * Fields of the mutable match can be filled to create a partial match, usable as matcher input. + * + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @param pApp the fixed value of pattern parameter App, or null if not bound. + * @return the new, mutable (partial) match object. + * + */ + public static AllocationWithoutResourceRequirement.Match newMutableMatch(final HostInstance pHost, final ApplicationInstance pApp) { + return new Mutable(pHost, pApp); + } + + /** + * Returns a new (partial) match. + * This can be used e.g. to call the matcher with a partial match. + *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @param pApp the fixed value of pattern parameter App, or null if not bound. + * @return the (partial) match object. + * + */ + public static AllocationWithoutResourceRequirement.Match newMatch(final HostInstance pHost, final ApplicationInstance pApp) { + return new Immutable(pHost, pApp); + } + + private static final class Mutable extends AllocationWithoutResourceRequirement.Match { + Mutable(final HostInstance pHost, final ApplicationInstance pApp) { + super(pHost, pApp); + } + + @Override + public boolean isMutable() { + return true; + } + } + + private static final class Immutable extends AllocationWithoutResourceRequirement.Match { + Immutable(final HostInstance pHost, final ApplicationInstance pApp) { + super(pHost, pApp); + } + + @Override + public boolean isMutable() { + return false; + } + } + } + + /** + * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.allocationWithoutResourceRequirement pattern, + * providing pattern-specific query methods. + * + *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, + * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. + * + *

Matches of the pattern will be represented as {@link Match}. + * + *

Original source: + *

+   * {@literal @}Constraint(severity = "error", key = {Host, App},
+   * 	message = "Application instance must be allocated to a supported host type.")
+   * pattern allocationWithoutResourceRequirement(Host : HostInstance, App : ApplicationInstance) {
+   * 	ApplicationInstance.allocatedTo(App, Host);
+   * 	neg find resourceRequirement(Host, App, _);
+   * }
+   * 
+ * + * @see Match + * @see AllocationWithoutResourceRequirement + * + */ + public static class Matcher extends BaseMatcher { + /** + * Initializes the pattern matcher within an existing VIATRA Query engine. + * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. + * + * @param engine the existing VIATRA Query engine in which this matcher will be created. + * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation + * + */ + public static AllocationWithoutResourceRequirement.Matcher on(final ViatraQueryEngine engine) { + // check if matcher already exists + Matcher matcher = engine.getExistingMatcher(querySpecification()); + if (matcher == null) { + matcher = (Matcher)engine.getMatcher(querySpecification()); + } + return matcher; + } + + /** + * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation + * @return an initialized matcher + * @noreference This method is for internal matcher initialization by the framework, do not call it manually. + * + */ + public static AllocationWithoutResourceRequirement.Matcher create() { + return new Matcher(); + } + + private static final int POSITION_HOST = 0; + + private static final int POSITION_APP = 1; + + private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(AllocationWithoutResourceRequirement.Matcher.class); + + /** + * Initializes the pattern matcher within an existing VIATRA Query engine. + * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. + * + * @param engine the existing VIATRA Query engine in which this matcher will be created. + * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation + * + */ + private Matcher() { + super(querySpecification()); + } + + /** + * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @param pApp the fixed value of pattern parameter App, or null if not bound. + * @return matches represented as a Match object. + * + */ + public Collection getAllMatches(final HostInstance pHost, final ApplicationInstance pApp) { + return rawStreamAllMatches(new Object[]{pHost, pApp}).collect(Collectors.toSet()); + } + + /** + * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. + *

+ * NOTE: It is important not to modify the source model while the stream is being processed. + * If the match set of the pattern changes during processing, the contents of the stream is undefined. + * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @param pApp the fixed value of pattern parameter App, or null if not bound. + * @return a stream of matches represented as a Match object. + * + */ + public Stream streamAllMatches(final HostInstance pHost, final ApplicationInstance pApp) { + return rawStreamAllMatches(new Object[]{pHost, pApp}); + } + + /** + * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. + * Neither determinism nor randomness of selection is guaranteed. + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @param pApp the fixed value of pattern parameter App, or null if not bound. + * @return a match represented as a Match object, or null if no match is found. + * + */ + public Optional getOneArbitraryMatch(final HostInstance pHost, final ApplicationInstance pApp) { + return rawGetOneArbitraryMatch(new Object[]{pHost, pApp}); + } + + /** + * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, + * under any possible substitution of the unspecified parameters (if any). + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @param pApp the fixed value of pattern parameter App, or null if not bound. + * @return true if the input is a valid (partial) match of the pattern. + * + */ + public boolean hasMatch(final HostInstance pHost, final ApplicationInstance pApp) { + return rawHasMatch(new Object[]{pHost, pApp}); + } + + /** + * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @param pApp the fixed value of pattern parameter App, or null if not bound. + * @return the number of pattern matches found. + * + */ + public int countMatches(final HostInstance pHost, final ApplicationInstance pApp) { + return rawCountMatches(new Object[]{pHost, pApp}); + } + + /** + * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. + * Neither determinism nor randomness of selection is guaranteed. + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @param pApp the fixed value of pattern parameter App, or null if not bound. + * @param processor the action that will process the selected match. + * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked + * + */ + public boolean forOneArbitraryMatch(final HostInstance pHost, final ApplicationInstance pApp, final Consumer processor) { + return rawForOneArbitraryMatch(new Object[]{pHost, pApp}, processor); + } + + /** + * Returns a new (partial) match. + * This can be used e.g. to call the matcher with a partial match. + *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @param pApp the fixed value of pattern parameter App, or null if not bound. + * @return the (partial) match object. + * + */ + public AllocationWithoutResourceRequirement.Match newMatch(final HostInstance pHost, final ApplicationInstance pApp) { + return AllocationWithoutResourceRequirement.Match.newMatch(pHost, pApp); + } + + /** + * Retrieve the set of values that occur in matches for Host. + * @return the Set of all values or empty set if there are no matches + * + */ + protected Stream rawStreamAllValuesOfHost(final Object[] parameters) { + return rawStreamAllValues(POSITION_HOST, parameters).map(HostInstance.class::cast); + } + + /** + * Retrieve the set of values that occur in matches for Host. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfHost() { + return rawStreamAllValuesOfHost(emptyArray()).collect(Collectors.toSet()); + } + + /** + * Retrieve the set of values that occur in matches for Host. + * @return the Set of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfHost() { + return rawStreamAllValuesOfHost(emptyArray()); + } + + /** + * Retrieve the set of values that occur in matches for Host. + *

+ * NOTE: It is important not to modify the source model while the stream is being processed. + * If the match set of the pattern changes during processing, the contents of the stream is undefined. + * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. + * + * @return the Stream of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfHost(final AllocationWithoutResourceRequirement.Match partialMatch) { + return rawStreamAllValuesOfHost(partialMatch.toArray()); + } + + /** + * Retrieve the set of values that occur in matches for Host. + *

+ * NOTE: It is important not to modify the source model while the stream is being processed. + * If the match set of the pattern changes during processing, the contents of the stream is undefined. + * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. + * + * @return the Stream of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfHost(final ApplicationInstance pApp) { + return rawStreamAllValuesOfHost(new Object[]{null, pApp}); + } + + /** + * Retrieve the set of values that occur in matches for Host. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfHost(final AllocationWithoutResourceRequirement.Match partialMatch) { + return rawStreamAllValuesOfHost(partialMatch.toArray()).collect(Collectors.toSet()); + } + + /** + * Retrieve the set of values that occur in matches for Host. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfHost(final ApplicationInstance pApp) { + return rawStreamAllValuesOfHost(new Object[]{null, pApp}).collect(Collectors.toSet()); + } + + /** + * Retrieve the set of values that occur in matches for App. + * @return the Set of all values or empty set if there are no matches + * + */ + protected Stream rawStreamAllValuesOfApp(final Object[] parameters) { + return rawStreamAllValues(POSITION_APP, parameters).map(ApplicationInstance.class::cast); + } + + /** + * Retrieve the set of values that occur in matches for App. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfApp() { + return rawStreamAllValuesOfApp(emptyArray()).collect(Collectors.toSet()); + } + + /** + * Retrieve the set of values that occur in matches for App. + * @return the Set of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfApp() { + return rawStreamAllValuesOfApp(emptyArray()); + } + + /** + * Retrieve the set of values that occur in matches for App. + *

+ * NOTE: It is important not to modify the source model while the stream is being processed. + * If the match set of the pattern changes during processing, the contents of the stream is undefined. + * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. + * + * @return the Stream of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfApp(final AllocationWithoutResourceRequirement.Match partialMatch) { + return rawStreamAllValuesOfApp(partialMatch.toArray()); + } + + /** + * Retrieve the set of values that occur in matches for App. + *

+ * NOTE: It is important not to modify the source model while the stream is being processed. + * If the match set of the pattern changes during processing, the contents of the stream is undefined. + * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. + * + * @return the Stream of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfApp(final HostInstance pHost) { + return rawStreamAllValuesOfApp(new Object[]{pHost, null}); + } + + /** + * Retrieve the set of values that occur in matches for App. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfApp(final AllocationWithoutResourceRequirement.Match partialMatch) { + return rawStreamAllValuesOfApp(partialMatch.toArray()).collect(Collectors.toSet()); + } + + /** + * Retrieve the set of values that occur in matches for App. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfApp(final HostInstance pHost) { + return rawStreamAllValuesOfApp(new Object[]{pHost, null}).collect(Collectors.toSet()); + } + + @Override + protected AllocationWithoutResourceRequirement.Match tupleToMatch(final Tuple t) { + try { + return AllocationWithoutResourceRequirement.Match.newMatch((HostInstance) t.get(POSITION_HOST), (ApplicationInstance) t.get(POSITION_APP)); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in tuple not properly typed!",e); + return null; + } + } + + @Override + protected AllocationWithoutResourceRequirement.Match arrayToMatch(final Object[] match) { + try { + return AllocationWithoutResourceRequirement.Match.newMatch((HostInstance) match[POSITION_HOST], (ApplicationInstance) match[POSITION_APP]); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in array not properly typed!",e); + return null; + } + } + + @Override + protected AllocationWithoutResourceRequirement.Match arrayToMatchMutable(final Object[] match) { + try { + return AllocationWithoutResourceRequirement.Match.newMutableMatch((HostInstance) match[POSITION_HOST], (ApplicationInstance) match[POSITION_APP]); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in array not properly typed!",e); + return null; + } + } + + /** + * @return the singleton instance of the query specification of this pattern + * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded + * + */ + public static IQuerySpecification querySpecification() { + return AllocationWithoutResourceRequirement.instance(); + } + } + + private AllocationWithoutResourceRequirement() { + super(GeneratedPQuery.INSTANCE); + } + + /** + * @return the singleton instance of the query specification + * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded + * + */ + public static AllocationWithoutResourceRequirement instance() { + try{ + return LazyHolder.INSTANCE; + } catch (ExceptionInInitializerError err) { + throw processInitializerError(err); + } + } + + @Override + protected AllocationWithoutResourceRequirement.Matcher instantiate(final ViatraQueryEngine engine) { + return AllocationWithoutResourceRequirement.Matcher.on(engine); + } + + @Override + public AllocationWithoutResourceRequirement.Matcher instantiate() { + return AllocationWithoutResourceRequirement.Matcher.create(); + } + + @Override + public AllocationWithoutResourceRequirement.Match newEmptyMatch() { + return AllocationWithoutResourceRequirement.Match.newEmptyMatch(); + } + + @Override + public AllocationWithoutResourceRequirement.Match newMatch(final Object... parameters) { + return AllocationWithoutResourceRequirement.Match.newMatch((hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance) parameters[0], (hu.bme.mit.inf.dslreasoner.domains.cps.ApplicationInstance) parameters[1]); + } + + /** + * 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: ) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)} to be created + * not at the class load time of the outer class, + * 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: ) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}. + * + *

This workaround is required e.g. to support recursion. + * + */ + private static class LazyHolder { + private static final AllocationWithoutResourceRequirement INSTANCE = new AllocationWithoutResourceRequirement(); + + /** + * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. + * This initialization order is required to support indirect recursion. + * + *

The static initializer is defined using a helper field to work around limitations of the code generator. + * + */ + private static final Object STATIC_INITIALIZER = ensureInitialized(); + + public static Object ensureInitialized() { + INSTANCE.ensureInitializedInternal(); + return null; + } + } + + private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { + private static final AllocationWithoutResourceRequirement.GeneratedPQuery INSTANCE = new GeneratedPQuery(); + + 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); + + 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); + + private final List parameters = Arrays.asList(parameter_Host, parameter_App); + + private GeneratedPQuery() { + super(PVisibility.PUBLIC); + } + + @Override + public String getFullyQualifiedName() { + return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.allocationWithoutResourceRequirement"; + } + + @Override + public List getParameterNames() { + return Arrays.asList("Host","App"); + } + + @Override + public List getParameters() { + return parameters; + } + + @Override + public Set doGetContainedBodies() { + setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); + Set bodies = new LinkedHashSet<>(); + { + PBody body = new PBody(this); + PVariable var_Host = body.getOrCreateVariableByName("Host"); + PVariable var_App = body.getOrCreateVariableByName("App"); + PVariable var___0_ = body.getOrCreateVariableByName("_<0>"); + new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); + new TypeConstraint(body, Tuples.flatTupleOf(var_App), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance"))); + body.setSymbolicParameters(Arrays.asList( + new ExportedParameter(body, var_Host, parameter_Host), + new ExportedParameter(body, var_App, parameter_App) + )); + // ApplicationInstance.allocatedTo(App, Host) + new TypeConstraint(body, Tuples.flatTupleOf(var_App), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance"))); + PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); + new TypeConstraint(body, Tuples.flatTupleOf(var_App, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ApplicationInstance", "allocatedTo"))); + new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); + new Equality(body, var__virtual_0_, var_Host); + // neg find resourceRequirement(Host, App, _) + new NegativePatternCall(body, Tuples.flatTupleOf(var_Host, var_App, var___0_), ResourceRequirement.instance().getInternalQueryRepresentation()); + bodies.add(body); + } + { + PAnnotation annotation = new PAnnotation("Constraint"); + annotation.addAttribute("severity", "error"); + annotation.addAttribute("key", Arrays.asList(new Object[] { + new ParameterReference("Host"), + new ParameterReference("App") + })); + annotation.addAttribute("message", "Application instance must be allocated to a supported host type."); + addAnnotation(annotation); + } + return bodies; + } + } +} diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/AvailableHdd.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/AvailableHdd.java new file mode 100644 index 00000000..22821c4a --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/AvailableHdd.java @@ -0,0 +1,743 @@ +/** + * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql + */ +package hu.bme.mit.inf.dslreasoner.domains.cps.queries; + +import hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.TotalHdd; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.HddRequirement; +import java.util.Arrays; +import java.util.Collection; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.function.Consumer; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import org.apache.log4j.Logger; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.viatra.query.runtime.api.IPatternMatch; +import org.eclipse.viatra.query.runtime.api.IQuerySpecification; +import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; +import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; +import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; +import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; +import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; +import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; +import org.eclipse.viatra.query.runtime.matchers.aggregators.sum; +import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; +import org.eclipse.viatra.query.runtime.matchers.context.common.JavaTransitiveInstancesKey; +import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator; +import org.eclipse.viatra.query.runtime.matchers.psystem.IValueProvider; +import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; +import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; +import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.AggregatorConstraint; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.TypeFilterConstraint; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; +import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; +import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; +import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; + +/** + * A pattern-specific query specification that can instantiate Matcher in a type-safe way. + * + *

Original source: + *

+ *         {@literal @}QueryBasedFeature(feature = "availableHdd")
+ *         pattern availableHdd(Host : HostInstance, Hdd : java Integer) {
+ *         	find totalHdd(Host, TotalHdd);
+ *         	RequiredHdd == sum find hddRequirement(Host, _, #_);
+ *         	Hdd == eval(TotalHdd - RequiredHdd);
+ *         }
+ * 
+ * + * @see Matcher + * @see Match + * + */ +@SuppressWarnings("all") +public final class AvailableHdd extends BaseGeneratedEMFQuerySpecification { + /** + * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.availableHdd pattern, + * to be used in conjunction with {@link Matcher}. + * + *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. + * Each instance is a (possibly partial) substitution of pattern parameters, + * usable to represent a match of the pattern in the result of a query, + * or to specify the bound (fixed) input parameters when issuing a query. + * + * @see Matcher + * + */ + public static abstract class Match extends BasePatternMatch { + private HostInstance fHost; + + private Integer fHdd; + + private static List parameterNames = makeImmutableList("Host", "Hdd"); + + private Match(final HostInstance pHost, final Integer pHdd) { + this.fHost = pHost; + this.fHdd = pHdd; + } + + @Override + public Object get(final String parameterName) { + if ("Host".equals(parameterName)) return this.fHost; + if ("Hdd".equals(parameterName)) return this.fHdd; + return null; + } + + public HostInstance getHost() { + return this.fHost; + } + + public Integer getHdd() { + return this.fHdd; + } + + @Override + public boolean set(final String parameterName, final Object newValue) { + if (!isMutable()) throw new java.lang.UnsupportedOperationException(); + if ("Host".equals(parameterName) ) { + this.fHost = (HostInstance) newValue; + return true; + } + if ("Hdd".equals(parameterName) ) { + this.fHdd = (Integer) newValue; + return true; + } + return false; + } + + public void setHost(final HostInstance pHost) { + if (!isMutable()) throw new java.lang.UnsupportedOperationException(); + this.fHost = pHost; + } + + public void setHdd(final Integer pHdd) { + if (!isMutable()) throw new java.lang.UnsupportedOperationException(); + this.fHdd = pHdd; + } + + @Override + public String patternName() { + return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.availableHdd"; + } + + @Override + public List parameterNames() { + return AvailableHdd.Match.parameterNames; + } + + @Override + public Object[] toArray() { + return new Object[]{fHost, fHdd}; + } + + @Override + public AvailableHdd.Match toImmutable() { + return isMutable() ? newMatch(fHost, fHdd) : this; + } + + @Override + public String prettyPrint() { + StringBuilder result = new StringBuilder(); + result.append("\"Host\"=" + prettyPrintValue(fHost) + ", "); + result.append("\"Hdd\"=" + prettyPrintValue(fHdd)); + return result.toString(); + } + + @Override + public int hashCode() { + return Objects.hash(fHost, fHdd); + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) + return true; + if (obj == null) { + return false; + } + if ((obj instanceof AvailableHdd.Match)) { + AvailableHdd.Match other = (AvailableHdd.Match) obj; + return Objects.equals(fHost, other.fHost) && Objects.equals(fHdd, other.fHdd); + } else { + // this should be infrequent + if (!(obj instanceof IPatternMatch)) { + return false; + } + IPatternMatch otherSig = (IPatternMatch) obj; + return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); + } + } + + @Override + public AvailableHdd specification() { + return AvailableHdd.instance(); + } + + /** + * Returns an empty, mutable match. + * Fields of the mutable match can be filled to create a partial match, usable as matcher input. + * + * @return the empty match. + * + */ + public static AvailableHdd.Match newEmptyMatch() { + return new Mutable(null, null); + } + + /** + * Returns a mutable (partial) match. + * Fields of the mutable match can be filled to create a partial match, usable as matcher input. + * + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @param pHdd the fixed value of pattern parameter Hdd, or null if not bound. + * @return the new, mutable (partial) match object. + * + */ + public static AvailableHdd.Match newMutableMatch(final HostInstance pHost, final Integer pHdd) { + return new Mutable(pHost, pHdd); + } + + /** + * Returns a new (partial) match. + * This can be used e.g. to call the matcher with a partial match. + *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @param pHdd the fixed value of pattern parameter Hdd, or null if not bound. + * @return the (partial) match object. + * + */ + public static AvailableHdd.Match newMatch(final HostInstance pHost, final Integer pHdd) { + return new Immutable(pHost, pHdd); + } + + private static final class Mutable extends AvailableHdd.Match { + Mutable(final HostInstance pHost, final Integer pHdd) { + super(pHost, pHdd); + } + + @Override + public boolean isMutable() { + return true; + } + } + + private static final class Immutable extends AvailableHdd.Match { + Immutable(final HostInstance pHost, final Integer pHdd) { + super(pHost, pHdd); + } + + @Override + public boolean isMutable() { + return false; + } + } + } + + /** + * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.availableHdd pattern, + * providing pattern-specific query methods. + * + *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, + * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. + * + *

Matches of the pattern will be represented as {@link Match}. + * + *

Original source: + *

+   * {@literal @}QueryBasedFeature(feature = "availableHdd")
+   * pattern availableHdd(Host : HostInstance, Hdd : java Integer) {
+   * 	find totalHdd(Host, TotalHdd);
+   * 	RequiredHdd == sum find hddRequirement(Host, _, #_);
+   * 	Hdd == eval(TotalHdd - RequiredHdd);
+   * }
+   * 
+ * + * @see Match + * @see AvailableHdd + * + */ + public static class Matcher extends BaseMatcher { + /** + * Initializes the pattern matcher within an existing VIATRA Query engine. + * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. + * + * @param engine the existing VIATRA Query engine in which this matcher will be created. + * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation + * + */ + public static AvailableHdd.Matcher on(final ViatraQueryEngine engine) { + // check if matcher already exists + Matcher matcher = engine.getExistingMatcher(querySpecification()); + if (matcher == null) { + matcher = (Matcher)engine.getMatcher(querySpecification()); + } + return matcher; + } + + /** + * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation + * @return an initialized matcher + * @noreference This method is for internal matcher initialization by the framework, do not call it manually. + * + */ + public static AvailableHdd.Matcher create() { + return new Matcher(); + } + + private static final int POSITION_HOST = 0; + + private static final int POSITION_HDD = 1; + + private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(AvailableHdd.Matcher.class); + + /** + * Initializes the pattern matcher within an existing VIATRA Query engine. + * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. + * + * @param engine the existing VIATRA Query engine in which this matcher will be created. + * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation + * + */ + private Matcher() { + super(querySpecification()); + } + + /** + * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @param pHdd the fixed value of pattern parameter Hdd, or null if not bound. + * @return matches represented as a Match object. + * + */ + public Collection getAllMatches(final HostInstance pHost, final Integer pHdd) { + return rawStreamAllMatches(new Object[]{pHost, pHdd}).collect(Collectors.toSet()); + } + + /** + * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. + *

+ * NOTE: It is important not to modify the source model while the stream is being processed. + * If the match set of the pattern changes during processing, the contents of the stream is undefined. + * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @param pHdd the fixed value of pattern parameter Hdd, or null if not bound. + * @return a stream of matches represented as a Match object. + * + */ + public Stream streamAllMatches(final HostInstance pHost, final Integer pHdd) { + return rawStreamAllMatches(new Object[]{pHost, pHdd}); + } + + /** + * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. + * Neither determinism nor randomness of selection is guaranteed. + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @param pHdd the fixed value of pattern parameter Hdd, or null if not bound. + * @return a match represented as a Match object, or null if no match is found. + * + */ + public Optional getOneArbitraryMatch(final HostInstance pHost, final Integer pHdd) { + return rawGetOneArbitraryMatch(new Object[]{pHost, pHdd}); + } + + /** + * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, + * under any possible substitution of the unspecified parameters (if any). + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @param pHdd the fixed value of pattern parameter Hdd, or null if not bound. + * @return true if the input is a valid (partial) match of the pattern. + * + */ + public boolean hasMatch(final HostInstance pHost, final Integer pHdd) { + return rawHasMatch(new Object[]{pHost, pHdd}); + } + + /** + * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @param pHdd the fixed value of pattern parameter Hdd, or null if not bound. + * @return the number of pattern matches found. + * + */ + public int countMatches(final HostInstance pHost, final Integer pHdd) { + return rawCountMatches(new Object[]{pHost, pHdd}); + } + + /** + * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. + * Neither determinism nor randomness of selection is guaranteed. + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @param pHdd the fixed value of pattern parameter Hdd, or null if not bound. + * @param processor the action that will process the selected match. + * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked + * + */ + public boolean forOneArbitraryMatch(final HostInstance pHost, final Integer pHdd, final Consumer processor) { + return rawForOneArbitraryMatch(new Object[]{pHost, pHdd}, processor); + } + + /** + * Returns a new (partial) match. + * This can be used e.g. to call the matcher with a partial match. + *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @param pHdd the fixed value of pattern parameter Hdd, or null if not bound. + * @return the (partial) match object. + * + */ + public AvailableHdd.Match newMatch(final HostInstance pHost, final Integer pHdd) { + return AvailableHdd.Match.newMatch(pHost, pHdd); + } + + /** + * Retrieve the set of values that occur in matches for Host. + * @return the Set of all values or empty set if there are no matches + * + */ + protected Stream rawStreamAllValuesOfHost(final Object[] parameters) { + return rawStreamAllValues(POSITION_HOST, parameters).map(HostInstance.class::cast); + } + + /** + * Retrieve the set of values that occur in matches for Host. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfHost() { + return rawStreamAllValuesOfHost(emptyArray()).collect(Collectors.toSet()); + } + + /** + * Retrieve the set of values that occur in matches for Host. + * @return the Set of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfHost() { + return rawStreamAllValuesOfHost(emptyArray()); + } + + /** + * Retrieve the set of values that occur in matches for Host. + *

+ * NOTE: It is important not to modify the source model while the stream is being processed. + * If the match set of the pattern changes during processing, the contents of the stream is undefined. + * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. + * + * @return the Stream of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfHost(final AvailableHdd.Match partialMatch) { + return rawStreamAllValuesOfHost(partialMatch.toArray()); + } + + /** + * Retrieve the set of values that occur in matches for Host. + *

+ * NOTE: It is important not to modify the source model while the stream is being processed. + * If the match set of the pattern changes during processing, the contents of the stream is undefined. + * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. + * + * @return the Stream of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfHost(final Integer pHdd) { + return rawStreamAllValuesOfHost(new Object[]{null, pHdd}); + } + + /** + * Retrieve the set of values that occur in matches for Host. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfHost(final AvailableHdd.Match partialMatch) { + return rawStreamAllValuesOfHost(partialMatch.toArray()).collect(Collectors.toSet()); + } + + /** + * Retrieve the set of values that occur in matches for Host. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfHost(final Integer pHdd) { + return rawStreamAllValuesOfHost(new Object[]{null, pHdd}).collect(Collectors.toSet()); + } + + /** + * Retrieve the set of values that occur in matches for Hdd. + * @return the Set of all values or empty set if there are no matches + * + */ + protected Stream rawStreamAllValuesOfHdd(final Object[] parameters) { + return rawStreamAllValues(POSITION_HDD, parameters).map(Integer.class::cast); + } + + /** + * Retrieve the set of values that occur in matches for Hdd. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfHdd() { + return rawStreamAllValuesOfHdd(emptyArray()).collect(Collectors.toSet()); + } + + /** + * Retrieve the set of values that occur in matches for Hdd. + * @return the Set of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfHdd() { + return rawStreamAllValuesOfHdd(emptyArray()); + } + + /** + * Retrieve the set of values that occur in matches for Hdd. + *

+ * NOTE: It is important not to modify the source model while the stream is being processed. + * If the match set of the pattern changes during processing, the contents of the stream is undefined. + * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. + * + * @return the Stream of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfHdd(final AvailableHdd.Match partialMatch) { + return rawStreamAllValuesOfHdd(partialMatch.toArray()); + } + + /** + * Retrieve the set of values that occur in matches for Hdd. + *

+ * NOTE: It is important not to modify the source model while the stream is being processed. + * If the match set of the pattern changes during processing, the contents of the stream is undefined. + * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. + * + * @return the Stream of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfHdd(final HostInstance pHost) { + return rawStreamAllValuesOfHdd(new Object[]{pHost, null}); + } + + /** + * Retrieve the set of values that occur in matches for Hdd. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfHdd(final AvailableHdd.Match partialMatch) { + return rawStreamAllValuesOfHdd(partialMatch.toArray()).collect(Collectors.toSet()); + } + + /** + * Retrieve the set of values that occur in matches for Hdd. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfHdd(final HostInstance pHost) { + return rawStreamAllValuesOfHdd(new Object[]{pHost, null}).collect(Collectors.toSet()); + } + + @Override + protected AvailableHdd.Match tupleToMatch(final Tuple t) { + try { + return AvailableHdd.Match.newMatch((HostInstance) t.get(POSITION_HOST), (Integer) t.get(POSITION_HDD)); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in tuple not properly typed!",e); + return null; + } + } + + @Override + protected AvailableHdd.Match arrayToMatch(final Object[] match) { + try { + return AvailableHdd.Match.newMatch((HostInstance) match[POSITION_HOST], (Integer) match[POSITION_HDD]); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in array not properly typed!",e); + return null; + } + } + + @Override + protected AvailableHdd.Match arrayToMatchMutable(final Object[] match) { + try { + return AvailableHdd.Match.newMutableMatch((HostInstance) match[POSITION_HOST], (Integer) match[POSITION_HDD]); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in array not properly typed!",e); + return null; + } + } + + /** + * @return the singleton instance of the query specification of this pattern + * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded + * + */ + public static IQuerySpecification querySpecification() { + return AvailableHdd.instance(); + } + } + + private AvailableHdd() { + super(GeneratedPQuery.INSTANCE); + } + + /** + * @return the singleton instance of the query specification + * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded + * + */ + public static AvailableHdd instance() { + try{ + return LazyHolder.INSTANCE; + } catch (ExceptionInInitializerError err) { + throw processInitializerError(err); + } + } + + @Override + protected AvailableHdd.Matcher instantiate(final ViatraQueryEngine engine) { + return AvailableHdd.Matcher.on(engine); + } + + @Override + public AvailableHdd.Matcher instantiate() { + return AvailableHdd.Matcher.create(); + } + + @Override + public AvailableHdd.Match newEmptyMatch() { + return AvailableHdd.Match.newEmptyMatch(); + } + + @Override + public AvailableHdd.Match newMatch(final Object... parameters) { + return AvailableHdd.Match.newMatch((hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance) parameters[0], (java.lang.Integer) parameters[1]); + } + + /** + * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.AvailableHdd (visibility: PUBLIC, simpleName: AvailableHdd, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.AvailableHdd, deprecated: ) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)} to be created + * not at the class load time of the outer class, + * but rather at the first call to {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.AvailableHdd (visibility: PUBLIC, simpleName: AvailableHdd, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.AvailableHdd, deprecated: ) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}. + * + *

This workaround is required e.g. to support recursion. + * + */ + private static class LazyHolder { + private static final AvailableHdd INSTANCE = new AvailableHdd(); + + /** + * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. + * This initialization order is required to support indirect recursion. + * + *

The static initializer is defined using a helper field to work around limitations of the code generator. + * + */ + private static final Object STATIC_INITIALIZER = ensureInitialized(); + + public static Object ensureInitialized() { + INSTANCE.ensureInitializedInternal(); + return null; + } + } + + private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { + private static final AvailableHdd.GeneratedPQuery INSTANCE = new GeneratedPQuery(); + + 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); + + private final PParameter parameter_Hdd = new PParameter("Hdd", "java.lang.Integer", new JavaTransitiveInstancesKey(java.lang.Integer.class), PParameterDirection.INOUT); + + private final List parameters = Arrays.asList(parameter_Host, parameter_Hdd); + + private GeneratedPQuery() { + super(PVisibility.PUBLIC); + } + + @Override + public String getFullyQualifiedName() { + return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.availableHdd"; + } + + @Override + public List getParameterNames() { + return Arrays.asList("Host","Hdd"); + } + + @Override + public List getParameters() { + return parameters; + } + + @Override + public Set doGetContainedBodies() { + setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); + Set bodies = new LinkedHashSet<>(); + { + PBody body = new PBody(this); + PVariable var_Host = body.getOrCreateVariableByName("Host"); + PVariable var_Hdd = body.getOrCreateVariableByName("Hdd"); + PVariable var_TotalHdd = body.getOrCreateVariableByName("TotalHdd"); + PVariable var_RequiredHdd = body.getOrCreateVariableByName("RequiredHdd"); + PVariable var___0_ = body.getOrCreateVariableByName("_<0>"); + PVariable var___1_ = body.getOrCreateVariableByName("_<1>"); + new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); + new TypeFilterConstraint(body, Tuples.flatTupleOf(var_Hdd), new JavaTransitiveInstancesKey(java.lang.Integer.class)); + body.setSymbolicParameters(Arrays.asList( + new ExportedParameter(body, var_Host, parameter_Host), + new ExportedParameter(body, var_Hdd, parameter_Hdd) + )); + // find totalHdd(Host, TotalHdd) + new PositivePatternCall(body, Tuples.flatTupleOf(var_Host, var_TotalHdd), TotalHdd.instance().getInternalQueryRepresentation()); + // RequiredHdd == sum find hddRequirement(Host, _, #_) + PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); + new AggregatorConstraint(new sum().getAggregatorLogic(Integer.class), body, Tuples.flatTupleOf(var_Host, var___0_, var___1_), HddRequirement.instance().getInternalQueryRepresentation(), var__virtual_0_, 2); + new Equality(body, var_RequiredHdd, var__virtual_0_); + // Hdd == eval(TotalHdd - RequiredHdd) + PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); + new ExpressionEvaluation(body, new IExpressionEvaluator() { + + @Override + public String getShortDescription() { + return "Expression evaluation from pattern availableHdd"; + } + + @Override + public Iterable getInputParameterNames() { + return Arrays.asList("RequiredHdd", "TotalHdd");} + + @Override + public Object evaluateExpression(IValueProvider provider) throws Exception { + Integer RequiredHdd = (Integer) provider.getValue("RequiredHdd"); + Integer TotalHdd = (Integer) provider.getValue("TotalHdd"); + return evaluateExpression_1_1(RequiredHdd, TotalHdd); + } + }, var__virtual_1_ ); + new Equality(body, var_Hdd, var__virtual_1_); + bodies.add(body); + } + { + PAnnotation annotation = new PAnnotation("QueryBasedFeature"); + annotation.addAttribute("feature", "availableHdd"); + addAnnotation(annotation); + } + return bodies; + } + } + + private static int evaluateExpression_1_1(final Integer RequiredHdd, final Integer TotalHdd) { + return ((TotalHdd).intValue() - (RequiredHdd).intValue()); + } +} diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/AvailableMemory.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/AvailableMemory.java new file mode 100644 index 00000000..930a24ba --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/AvailableMemory.java @@ -0,0 +1,743 @@ +/** + * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql + */ +package hu.bme.mit.inf.dslreasoner.domains.cps.queries; + +import hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.TotalMemory; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.MemoryRequirement; +import java.util.Arrays; +import java.util.Collection; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.function.Consumer; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import org.apache.log4j.Logger; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.viatra.query.runtime.api.IPatternMatch; +import org.eclipse.viatra.query.runtime.api.IQuerySpecification; +import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; +import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; +import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; +import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; +import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; +import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; +import org.eclipse.viatra.query.runtime.matchers.aggregators.sum; +import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; +import org.eclipse.viatra.query.runtime.matchers.context.common.JavaTransitiveInstancesKey; +import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator; +import org.eclipse.viatra.query.runtime.matchers.psystem.IValueProvider; +import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; +import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; +import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.AggregatorConstraint; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.TypeFilterConstraint; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; +import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; +import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; +import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; + +/** + * A pattern-specific query specification that can instantiate Matcher in a type-safe way. + * + *

Original source: + *

+ *         {@literal @}QueryBasedFeature(feature = "availableMemory")
+ *         pattern availableMemory(Host : HostInstance, Memory : java Integer) {
+ *         	find totalMemory(Host, TotalMemory);
+ *         	RequiredMemory == sum find memoryRequirement(Host, _, #_);
+ *         	Memory == eval(TotalMemory - RequiredMemory);
+ *         }
+ * 
+ * + * @see Matcher + * @see Match + * + */ +@SuppressWarnings("all") +public final class AvailableMemory extends BaseGeneratedEMFQuerySpecification { + /** + * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.availableMemory pattern, + * to be used in conjunction with {@link Matcher}. + * + *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. + * Each instance is a (possibly partial) substitution of pattern parameters, + * usable to represent a match of the pattern in the result of a query, + * or to specify the bound (fixed) input parameters when issuing a query. + * + * @see Matcher + * + */ + public static abstract class Match extends BasePatternMatch { + private HostInstance fHost; + + private Integer fMemory; + + private static List parameterNames = makeImmutableList("Host", "Memory"); + + private Match(final HostInstance pHost, final Integer pMemory) { + this.fHost = pHost; + this.fMemory = pMemory; + } + + @Override + public Object get(final String parameterName) { + if ("Host".equals(parameterName)) return this.fHost; + if ("Memory".equals(parameterName)) return this.fMemory; + return null; + } + + public HostInstance getHost() { + return this.fHost; + } + + public Integer getMemory() { + return this.fMemory; + } + + @Override + public boolean set(final String parameterName, final Object newValue) { + if (!isMutable()) throw new java.lang.UnsupportedOperationException(); + if ("Host".equals(parameterName) ) { + this.fHost = (HostInstance) newValue; + return true; + } + if ("Memory".equals(parameterName) ) { + this.fMemory = (Integer) newValue; + return true; + } + return false; + } + + public void setHost(final HostInstance pHost) { + if (!isMutable()) throw new java.lang.UnsupportedOperationException(); + this.fHost = pHost; + } + + public void setMemory(final Integer pMemory) { + if (!isMutable()) throw new java.lang.UnsupportedOperationException(); + this.fMemory = pMemory; + } + + @Override + public String patternName() { + return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.availableMemory"; + } + + @Override + public List parameterNames() { + return AvailableMemory.Match.parameterNames; + } + + @Override + public Object[] toArray() { + return new Object[]{fHost, fMemory}; + } + + @Override + public AvailableMemory.Match toImmutable() { + return isMutable() ? newMatch(fHost, fMemory) : this; + } + + @Override + public String prettyPrint() { + StringBuilder result = new StringBuilder(); + result.append("\"Host\"=" + prettyPrintValue(fHost) + ", "); + result.append("\"Memory\"=" + prettyPrintValue(fMemory)); + return result.toString(); + } + + @Override + public int hashCode() { + return Objects.hash(fHost, fMemory); + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) + return true; + if (obj == null) { + return false; + } + if ((obj instanceof AvailableMemory.Match)) { + AvailableMemory.Match other = (AvailableMemory.Match) obj; + return Objects.equals(fHost, other.fHost) && Objects.equals(fMemory, other.fMemory); + } else { + // this should be infrequent + if (!(obj instanceof IPatternMatch)) { + return false; + } + IPatternMatch otherSig = (IPatternMatch) obj; + return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); + } + } + + @Override + public AvailableMemory specification() { + return AvailableMemory.instance(); + } + + /** + * Returns an empty, mutable match. + * Fields of the mutable match can be filled to create a partial match, usable as matcher input. + * + * @return the empty match. + * + */ + public static AvailableMemory.Match newEmptyMatch() { + return new Mutable(null, null); + } + + /** + * Returns a mutable (partial) match. + * Fields of the mutable match can be filled to create a partial match, usable as matcher input. + * + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @param pMemory the fixed value of pattern parameter Memory, or null if not bound. + * @return the new, mutable (partial) match object. + * + */ + public static AvailableMemory.Match newMutableMatch(final HostInstance pHost, final Integer pMemory) { + return new Mutable(pHost, pMemory); + } + + /** + * Returns a new (partial) match. + * This can be used e.g. to call the matcher with a partial match. + *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @param pMemory the fixed value of pattern parameter Memory, or null if not bound. + * @return the (partial) match object. + * + */ + public static AvailableMemory.Match newMatch(final HostInstance pHost, final Integer pMemory) { + return new Immutable(pHost, pMemory); + } + + private static final class Mutable extends AvailableMemory.Match { + Mutable(final HostInstance pHost, final Integer pMemory) { + super(pHost, pMemory); + } + + @Override + public boolean isMutable() { + return true; + } + } + + private static final class Immutable extends AvailableMemory.Match { + Immutable(final HostInstance pHost, final Integer pMemory) { + super(pHost, pMemory); + } + + @Override + public boolean isMutable() { + return false; + } + } + } + + /** + * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.availableMemory pattern, + * providing pattern-specific query methods. + * + *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, + * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. + * + *

Matches of the pattern will be represented as {@link Match}. + * + *

Original source: + *

+   * {@literal @}QueryBasedFeature(feature = "availableMemory")
+   * pattern availableMemory(Host : HostInstance, Memory : java Integer) {
+   * 	find totalMemory(Host, TotalMemory);
+   * 	RequiredMemory == sum find memoryRequirement(Host, _, #_);
+   * 	Memory == eval(TotalMemory - RequiredMemory);
+   * }
+   * 
+ * + * @see Match + * @see AvailableMemory + * + */ + public static class Matcher extends BaseMatcher { + /** + * Initializes the pattern matcher within an existing VIATRA Query engine. + * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. + * + * @param engine the existing VIATRA Query engine in which this matcher will be created. + * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation + * + */ + public static AvailableMemory.Matcher on(final ViatraQueryEngine engine) { + // check if matcher already exists + Matcher matcher = engine.getExistingMatcher(querySpecification()); + if (matcher == null) { + matcher = (Matcher)engine.getMatcher(querySpecification()); + } + return matcher; + } + + /** + * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation + * @return an initialized matcher + * @noreference This method is for internal matcher initialization by the framework, do not call it manually. + * + */ + public static AvailableMemory.Matcher create() { + return new Matcher(); + } + + private static final int POSITION_HOST = 0; + + private static final int POSITION_MEMORY = 1; + + private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(AvailableMemory.Matcher.class); + + /** + * Initializes the pattern matcher within an existing VIATRA Query engine. + * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. + * + * @param engine the existing VIATRA Query engine in which this matcher will be created. + * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation + * + */ + private Matcher() { + super(querySpecification()); + } + + /** + * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @param pMemory the fixed value of pattern parameter Memory, or null if not bound. + * @return matches represented as a Match object. + * + */ + public Collection getAllMatches(final HostInstance pHost, final Integer pMemory) { + return rawStreamAllMatches(new Object[]{pHost, pMemory}).collect(Collectors.toSet()); + } + + /** + * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. + *

+ * NOTE: It is important not to modify the source model while the stream is being processed. + * If the match set of the pattern changes during processing, the contents of the stream is undefined. + * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @param pMemory the fixed value of pattern parameter Memory, or null if not bound. + * @return a stream of matches represented as a Match object. + * + */ + public Stream streamAllMatches(final HostInstance pHost, final Integer pMemory) { + return rawStreamAllMatches(new Object[]{pHost, pMemory}); + } + + /** + * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. + * Neither determinism nor randomness of selection is guaranteed. + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @param pMemory the fixed value of pattern parameter Memory, or null if not bound. + * @return a match represented as a Match object, or null if no match is found. + * + */ + public Optional getOneArbitraryMatch(final HostInstance pHost, final Integer pMemory) { + return rawGetOneArbitraryMatch(new Object[]{pHost, pMemory}); + } + + /** + * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, + * under any possible substitution of the unspecified parameters (if any). + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @param pMemory the fixed value of pattern parameter Memory, or null if not bound. + * @return true if the input is a valid (partial) match of the pattern. + * + */ + public boolean hasMatch(final HostInstance pHost, final Integer pMemory) { + return rawHasMatch(new Object[]{pHost, pMemory}); + } + + /** + * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @param pMemory the fixed value of pattern parameter Memory, or null if not bound. + * @return the number of pattern matches found. + * + */ + public int countMatches(final HostInstance pHost, final Integer pMemory) { + return rawCountMatches(new Object[]{pHost, pMemory}); + } + + /** + * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. + * Neither determinism nor randomness of selection is guaranteed. + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @param pMemory the fixed value of pattern parameter Memory, or null if not bound. + * @param processor the action that will process the selected match. + * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked + * + */ + public boolean forOneArbitraryMatch(final HostInstance pHost, final Integer pMemory, final Consumer processor) { + return rawForOneArbitraryMatch(new Object[]{pHost, pMemory}, processor); + } + + /** + * Returns a new (partial) match. + * This can be used e.g. to call the matcher with a partial match. + *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @param pMemory the fixed value of pattern parameter Memory, or null if not bound. + * @return the (partial) match object. + * + */ + public AvailableMemory.Match newMatch(final HostInstance pHost, final Integer pMemory) { + return AvailableMemory.Match.newMatch(pHost, pMemory); + } + + /** + * Retrieve the set of values that occur in matches for Host. + * @return the Set of all values or empty set if there are no matches + * + */ + protected Stream rawStreamAllValuesOfHost(final Object[] parameters) { + return rawStreamAllValues(POSITION_HOST, parameters).map(HostInstance.class::cast); + } + + /** + * Retrieve the set of values that occur in matches for Host. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfHost() { + return rawStreamAllValuesOfHost(emptyArray()).collect(Collectors.toSet()); + } + + /** + * Retrieve the set of values that occur in matches for Host. + * @return the Set of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfHost() { + return rawStreamAllValuesOfHost(emptyArray()); + } + + /** + * Retrieve the set of values that occur in matches for Host. + *

+ * NOTE: It is important not to modify the source model while the stream is being processed. + * If the match set of the pattern changes during processing, the contents of the stream is undefined. + * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. + * + * @return the Stream of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfHost(final AvailableMemory.Match partialMatch) { + return rawStreamAllValuesOfHost(partialMatch.toArray()); + } + + /** + * Retrieve the set of values that occur in matches for Host. + *

+ * NOTE: It is important not to modify the source model while the stream is being processed. + * If the match set of the pattern changes during processing, the contents of the stream is undefined. + * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. + * + * @return the Stream of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfHost(final Integer pMemory) { + return rawStreamAllValuesOfHost(new Object[]{null, pMemory}); + } + + /** + * Retrieve the set of values that occur in matches for Host. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfHost(final AvailableMemory.Match partialMatch) { + return rawStreamAllValuesOfHost(partialMatch.toArray()).collect(Collectors.toSet()); + } + + /** + * Retrieve the set of values that occur in matches for Host. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfHost(final Integer pMemory) { + return rawStreamAllValuesOfHost(new Object[]{null, pMemory}).collect(Collectors.toSet()); + } + + /** + * Retrieve the set of values that occur in matches for Memory. + * @return the Set of all values or empty set if there are no matches + * + */ + protected Stream rawStreamAllValuesOfMemory(final Object[] parameters) { + return rawStreamAllValues(POSITION_MEMORY, parameters).map(Integer.class::cast); + } + + /** + * Retrieve the set of values that occur in matches for Memory. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfMemory() { + return rawStreamAllValuesOfMemory(emptyArray()).collect(Collectors.toSet()); + } + + /** + * Retrieve the set of values that occur in matches for Memory. + * @return the Set of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfMemory() { + return rawStreamAllValuesOfMemory(emptyArray()); + } + + /** + * Retrieve the set of values that occur in matches for Memory. + *

+ * NOTE: It is important not to modify the source model while the stream is being processed. + * If the match set of the pattern changes during processing, the contents of the stream is undefined. + * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. + * + * @return the Stream of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfMemory(final AvailableMemory.Match partialMatch) { + return rawStreamAllValuesOfMemory(partialMatch.toArray()); + } + + /** + * Retrieve the set of values that occur in matches for Memory. + *

+ * NOTE: It is important not to modify the source model while the stream is being processed. + * If the match set of the pattern changes during processing, the contents of the stream is undefined. + * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. + * + * @return the Stream of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfMemory(final HostInstance pHost) { + return rawStreamAllValuesOfMemory(new Object[]{pHost, null}); + } + + /** + * Retrieve the set of values that occur in matches for Memory. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfMemory(final AvailableMemory.Match partialMatch) { + return rawStreamAllValuesOfMemory(partialMatch.toArray()).collect(Collectors.toSet()); + } + + /** + * Retrieve the set of values that occur in matches for Memory. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfMemory(final HostInstance pHost) { + return rawStreamAllValuesOfMemory(new Object[]{pHost, null}).collect(Collectors.toSet()); + } + + @Override + protected AvailableMemory.Match tupleToMatch(final Tuple t) { + try { + return AvailableMemory.Match.newMatch((HostInstance) t.get(POSITION_HOST), (Integer) t.get(POSITION_MEMORY)); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in tuple not properly typed!",e); + return null; + } + } + + @Override + protected AvailableMemory.Match arrayToMatch(final Object[] match) { + try { + return AvailableMemory.Match.newMatch((HostInstance) match[POSITION_HOST], (Integer) match[POSITION_MEMORY]); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in array not properly typed!",e); + return null; + } + } + + @Override + protected AvailableMemory.Match arrayToMatchMutable(final Object[] match) { + try { + return AvailableMemory.Match.newMutableMatch((HostInstance) match[POSITION_HOST], (Integer) match[POSITION_MEMORY]); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in array not properly typed!",e); + return null; + } + } + + /** + * @return the singleton instance of the query specification of this pattern + * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded + * + */ + public static IQuerySpecification querySpecification() { + return AvailableMemory.instance(); + } + } + + private AvailableMemory() { + super(GeneratedPQuery.INSTANCE); + } + + /** + * @return the singleton instance of the query specification + * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded + * + */ + public static AvailableMemory instance() { + try{ + return LazyHolder.INSTANCE; + } catch (ExceptionInInitializerError err) { + throw processInitializerError(err); + } + } + + @Override + protected AvailableMemory.Matcher instantiate(final ViatraQueryEngine engine) { + return AvailableMemory.Matcher.on(engine); + } + + @Override + public AvailableMemory.Matcher instantiate() { + return AvailableMemory.Matcher.create(); + } + + @Override + public AvailableMemory.Match newEmptyMatch() { + return AvailableMemory.Match.newEmptyMatch(); + } + + @Override + public AvailableMemory.Match newMatch(final Object... parameters) { + return AvailableMemory.Match.newMatch((hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance) parameters[0], (java.lang.Integer) parameters[1]); + } + + /** + * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.AvailableMemory (visibility: PUBLIC, simpleName: AvailableMemory, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.AvailableMemory, deprecated: ) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)} to be created + * not at the class load time of the outer class, + * but rather at the first call to {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.AvailableMemory (visibility: PUBLIC, simpleName: AvailableMemory, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.AvailableMemory, deprecated: ) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}. + * + *

This workaround is required e.g. to support recursion. + * + */ + private static class LazyHolder { + private static final AvailableMemory INSTANCE = new AvailableMemory(); + + /** + * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. + * This initialization order is required to support indirect recursion. + * + *

The static initializer is defined using a helper field to work around limitations of the code generator. + * + */ + private static final Object STATIC_INITIALIZER = ensureInitialized(); + + public static Object ensureInitialized() { + INSTANCE.ensureInitializedInternal(); + return null; + } + } + + private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { + private static final AvailableMemory.GeneratedPQuery INSTANCE = new GeneratedPQuery(); + + 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); + + private final PParameter parameter_Memory = new PParameter("Memory", "java.lang.Integer", new JavaTransitiveInstancesKey(java.lang.Integer.class), PParameterDirection.INOUT); + + private final List parameters = Arrays.asList(parameter_Host, parameter_Memory); + + private GeneratedPQuery() { + super(PVisibility.PUBLIC); + } + + @Override + public String getFullyQualifiedName() { + return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.availableMemory"; + } + + @Override + public List getParameterNames() { + return Arrays.asList("Host","Memory"); + } + + @Override + public List getParameters() { + return parameters; + } + + @Override + public Set doGetContainedBodies() { + setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); + Set bodies = new LinkedHashSet<>(); + { + PBody body = new PBody(this); + PVariable var_Host = body.getOrCreateVariableByName("Host"); + PVariable var_Memory = body.getOrCreateVariableByName("Memory"); + PVariable var_TotalMemory = body.getOrCreateVariableByName("TotalMemory"); + PVariable var_RequiredMemory = body.getOrCreateVariableByName("RequiredMemory"); + PVariable var___0_ = body.getOrCreateVariableByName("_<0>"); + PVariable var___1_ = body.getOrCreateVariableByName("_<1>"); + new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); + new TypeFilterConstraint(body, Tuples.flatTupleOf(var_Memory), new JavaTransitiveInstancesKey(java.lang.Integer.class)); + body.setSymbolicParameters(Arrays.asList( + new ExportedParameter(body, var_Host, parameter_Host), + new ExportedParameter(body, var_Memory, parameter_Memory) + )); + // find totalMemory(Host, TotalMemory) + new PositivePatternCall(body, Tuples.flatTupleOf(var_Host, var_TotalMemory), TotalMemory.instance().getInternalQueryRepresentation()); + // RequiredMemory == sum find memoryRequirement(Host, _, #_) + PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); + new AggregatorConstraint(new sum().getAggregatorLogic(Integer.class), body, Tuples.flatTupleOf(var_Host, var___0_, var___1_), MemoryRequirement.instance().getInternalQueryRepresentation(), var__virtual_0_, 2); + new Equality(body, var_RequiredMemory, var__virtual_0_); + // Memory == eval(TotalMemory - RequiredMemory) + PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); + new ExpressionEvaluation(body, new IExpressionEvaluator() { + + @Override + public String getShortDescription() { + return "Expression evaluation from pattern availableMemory"; + } + + @Override + public Iterable getInputParameterNames() { + return Arrays.asList("RequiredMemory", "TotalMemory");} + + @Override + public Object evaluateExpression(IValueProvider provider) throws Exception { + Integer RequiredMemory = (Integer) provider.getValue("RequiredMemory"); + Integer TotalMemory = (Integer) provider.getValue("TotalMemory"); + return evaluateExpression_1_1(RequiredMemory, TotalMemory); + } + }, var__virtual_1_ ); + new Equality(body, var_Memory, var__virtual_1_); + bodies.add(body); + } + { + PAnnotation annotation = new PAnnotation("QueryBasedFeature"); + annotation.addAttribute("feature", "availableMemory"); + addAnnotation(annotation); + } + return bodies; + } + } + + private static int evaluateExpression_1_1(final Integer RequiredMemory, final Integer TotalMemory) { + return ((TotalMemory).intValue() - (RequiredMemory).intValue()); + } +} 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..59d4ad27 --- /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,540 @@ +/** + * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql + */ +package hu.bme.mit.inf.dslreasoner.domains.cps.queries; + +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.FreeHddPercentage; +import java.util.Arrays; +import java.util.Collection; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.function.Consumer; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import org.apache.log4j.Logger; +import org.eclipse.viatra.query.runtime.api.IPatternMatch; +import org.eclipse.viatra.query.runtime.api.IQuerySpecification; +import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; +import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; +import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; +import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; +import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; +import org.eclipse.viatra.query.runtime.matchers.aggregators.avg; +import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; +import org.eclipse.viatra.query.runtime.matchers.context.common.JavaTransitiveInstancesKey; +import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; +import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.AggregatorConstraint; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.TypeFilterConstraint; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; +import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; +import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; +import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; + +/** + * A pattern-specific query specification that can instantiate Matcher in a type-safe way. + * + *

Original source: + *

+ *         pattern averageFreeHddMetric(Average : java Double) {
+ *         	Average == avg find freeHddPercentage(_, #_);
+ *         }
+ * 
+ * + * @see Matcher + * @see Match + * + */ +@SuppressWarnings("all") +public final class AverageFreeHddMetric extends BaseGeneratedEMFQuerySpecification { + /** + * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.averageFreeHddMetric pattern, + * to be used in conjunction with {@link Matcher}. + * + *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. + * Each instance is a (possibly partial) substitution of pattern parameters, + * usable to represent a match of the pattern in the result of a query, + * or to specify the bound (fixed) input parameters when issuing a query. + * + * @see Matcher + * + */ + public static abstract class Match extends BasePatternMatch { + private Double fAverage; + + private static List parameterNames = makeImmutableList("Average"); + + private Match(final Double pAverage) { + this.fAverage = pAverage; + } + + @Override + public Object get(final String parameterName) { + if ("Average".equals(parameterName)) return this.fAverage; + return null; + } + + public Double getAverage() { + return this.fAverage; + } + + @Override + public boolean set(final String parameterName, final Object newValue) { + if (!isMutable()) throw new java.lang.UnsupportedOperationException(); + if ("Average".equals(parameterName) ) { + this.fAverage = (Double) newValue; + return true; + } + return false; + } + + public void setAverage(final Double pAverage) { + if (!isMutable()) throw new java.lang.UnsupportedOperationException(); + this.fAverage = pAverage; + } + + @Override + public String patternName() { + return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.averageFreeHddMetric"; + } + + @Override + public List parameterNames() { + return AverageFreeHddMetric.Match.parameterNames; + } + + @Override + public Object[] toArray() { + return new Object[]{fAverage}; + } + + @Override + public AverageFreeHddMetric.Match toImmutable() { + return isMutable() ? newMatch(fAverage) : this; + } + + @Override + public String prettyPrint() { + StringBuilder result = new StringBuilder(); + result.append("\"Average\"=" + prettyPrintValue(fAverage)); + return result.toString(); + } + + @Override + public int hashCode() { + return Objects.hash(fAverage); + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) + return true; + if (obj == null) { + return false; + } + if ((obj instanceof AverageFreeHddMetric.Match)) { + AverageFreeHddMetric.Match other = (AverageFreeHddMetric.Match) obj; + return Objects.equals(fAverage, other.fAverage); + } else { + // this should be infrequent + if (!(obj instanceof IPatternMatch)) { + return false; + } + IPatternMatch otherSig = (IPatternMatch) obj; + return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); + } + } + + @Override + public AverageFreeHddMetric specification() { + return AverageFreeHddMetric.instance(); + } + + /** + * Returns an empty, mutable match. + * Fields of the mutable match can be filled to create a partial match, usable as matcher input. + * + * @return the empty match. + * + */ + public static AverageFreeHddMetric.Match newEmptyMatch() { + return new Mutable(null); + } + + /** + * Returns a mutable (partial) match. + * Fields of the mutable match can be filled to create a partial match, usable as matcher input. + * + * @param pAverage the fixed value of pattern parameter Average, or null if not bound. + * @return the new, mutable (partial) match object. + * + */ + public static AverageFreeHddMetric.Match newMutableMatch(final Double pAverage) { + return new Mutable(pAverage); + } + + /** + * Returns a new (partial) match. + * This can be used e.g. to call the matcher with a partial match. + *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. + * @param pAverage the fixed value of pattern parameter Average, or null if not bound. + * @return the (partial) match object. + * + */ + public static AverageFreeHddMetric.Match newMatch(final Double pAverage) { + return new Immutable(pAverage); + } + + private static final class Mutable extends AverageFreeHddMetric.Match { + Mutable(final Double pAverage) { + super(pAverage); + } + + @Override + public boolean isMutable() { + return true; + } + } + + private static final class Immutable extends AverageFreeHddMetric.Match { + Immutable(final Double pAverage) { + super(pAverage); + } + + @Override + public boolean isMutable() { + return false; + } + } + } + + /** + * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.averageFreeHddMetric pattern, + * providing pattern-specific query methods. + * + *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, + * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. + * + *

Matches of the pattern will be represented as {@link Match}. + * + *

Original source: + *

+   * pattern averageFreeHddMetric(Average : java Double) {
+   * 	Average == avg find freeHddPercentage(_, #_);
+   * }
+   * 
+ * + * @see Match + * @see AverageFreeHddMetric + * + */ + public static class Matcher extends BaseMatcher { + /** + * Initializes the pattern matcher within an existing VIATRA Query engine. + * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. + * + * @param engine the existing VIATRA Query engine in which this matcher will be created. + * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation + * + */ + public static AverageFreeHddMetric.Matcher on(final ViatraQueryEngine engine) { + // check if matcher already exists + Matcher matcher = engine.getExistingMatcher(querySpecification()); + if (matcher == null) { + matcher = (Matcher)engine.getMatcher(querySpecification()); + } + return matcher; + } + + /** + * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation + * @return an initialized matcher + * @noreference This method is for internal matcher initialization by the framework, do not call it manually. + * + */ + public static AverageFreeHddMetric.Matcher create() { + return new Matcher(); + } + + private static final int POSITION_AVERAGE = 0; + + private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(AverageFreeHddMetric.Matcher.class); + + /** + * Initializes the pattern matcher within an existing VIATRA Query engine. + * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. + * + * @param engine the existing VIATRA Query engine in which this matcher will be created. + * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation + * + */ + private Matcher() { + super(querySpecification()); + } + + /** + * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. + * @param pAverage the fixed value of pattern parameter Average, or null if not bound. + * @return matches represented as a Match object. + * + */ + public Collection getAllMatches(final Double pAverage) { + return rawStreamAllMatches(new Object[]{pAverage}).collect(Collectors.toSet()); + } + + /** + * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. + *

+ * NOTE: It is important not to modify the source model while the stream is being processed. + * If the match set of the pattern changes during processing, the contents of the stream is undefined. + * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. + * @param pAverage the fixed value of pattern parameter Average, or null if not bound. + * @return a stream of matches represented as a Match object. + * + */ + public Stream streamAllMatches(final Double pAverage) { + return rawStreamAllMatches(new Object[]{pAverage}); + } + + /** + * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. + * Neither determinism nor randomness of selection is guaranteed. + * @param pAverage the fixed value of pattern parameter Average, or null if not bound. + * @return a match represented as a Match object, or null if no match is found. + * + */ + public Optional getOneArbitraryMatch(final Double pAverage) { + return rawGetOneArbitraryMatch(new Object[]{pAverage}); + } + + /** + * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, + * under any possible substitution of the unspecified parameters (if any). + * @param pAverage the fixed value of pattern parameter Average, or null if not bound. + * @return true if the input is a valid (partial) match of the pattern. + * + */ + public boolean hasMatch(final Double pAverage) { + return rawHasMatch(new Object[]{pAverage}); + } + + /** + * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. + * @param pAverage the fixed value of pattern parameter Average, or null if not bound. + * @return the number of pattern matches found. + * + */ + public int countMatches(final Double pAverage) { + return rawCountMatches(new Object[]{pAverage}); + } + + /** + * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. + * Neither determinism nor randomness of selection is guaranteed. + * @param pAverage the fixed value of pattern parameter Average, or null if not bound. + * @param processor the action that will process the selected match. + * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked + * + */ + public boolean forOneArbitraryMatch(final Double pAverage, final Consumer processor) { + return rawForOneArbitraryMatch(new Object[]{pAverage}, processor); + } + + /** + * Returns a new (partial) match. + * This can be used e.g. to call the matcher with a partial match. + *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. + * @param pAverage the fixed value of pattern parameter Average, or null if not bound. + * @return the (partial) match object. + * + */ + public AverageFreeHddMetric.Match newMatch(final Double pAverage) { + return AverageFreeHddMetric.Match.newMatch(pAverage); + } + + /** + * Retrieve the set of values that occur in matches for Average. + * @return the Set of all values or empty set if there are no matches + * + */ + protected Stream rawStreamAllValuesOfAverage(final Object[] parameters) { + return rawStreamAllValues(POSITION_AVERAGE, parameters).map(Double.class::cast); + } + + /** + * Retrieve the set of values that occur in matches for Average. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfAverage() { + return rawStreamAllValuesOfAverage(emptyArray()).collect(Collectors.toSet()); + } + + /** + * Retrieve the set of values that occur in matches for Average. + * @return the Set of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfAverage() { + return rawStreamAllValuesOfAverage(emptyArray()); + } + + @Override + protected AverageFreeHddMetric.Match tupleToMatch(final Tuple t) { + try { + return AverageFreeHddMetric.Match.newMatch((Double) t.get(POSITION_AVERAGE)); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in tuple not properly typed!",e); + return null; + } + } + + @Override + protected AverageFreeHddMetric.Match arrayToMatch(final Object[] match) { + try { + return AverageFreeHddMetric.Match.newMatch((Double) match[POSITION_AVERAGE]); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in array not properly typed!",e); + return null; + } + } + + @Override + protected AverageFreeHddMetric.Match arrayToMatchMutable(final Object[] match) { + try { + return AverageFreeHddMetric.Match.newMutableMatch((Double) match[POSITION_AVERAGE]); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in array not properly typed!",e); + return null; + } + } + + /** + * @return the singleton instance of the query specification of this pattern + * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded + * + */ + public static IQuerySpecification querySpecification() { + return AverageFreeHddMetric.instance(); + } + } + + private AverageFreeHddMetric() { + super(GeneratedPQuery.INSTANCE); + } + + /** + * @return the singleton instance of the query specification + * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded + * + */ + public static AverageFreeHddMetric instance() { + try{ + return LazyHolder.INSTANCE; + } catch (ExceptionInInitializerError err) { + throw processInitializerError(err); + } + } + + @Override + protected AverageFreeHddMetric.Matcher instantiate(final ViatraQueryEngine engine) { + return AverageFreeHddMetric.Matcher.on(engine); + } + + @Override + public AverageFreeHddMetric.Matcher instantiate() { + return AverageFreeHddMetric.Matcher.create(); + } + + @Override + public AverageFreeHddMetric.Match newEmptyMatch() { + return AverageFreeHddMetric.Match.newEmptyMatch(); + } + + @Override + public AverageFreeHddMetric.Match newMatch(final Object... parameters) { + return AverageFreeHddMetric.Match.newMatch((java.lang.Double) parameters[0]); + } + + /** + * 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: ) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)} to be created + * not at the class load time of the outer class, + * 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: ) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}. + * + *

This workaround is required e.g. to support recursion. + * + */ + private static class LazyHolder { + private static final AverageFreeHddMetric INSTANCE = new AverageFreeHddMetric(); + + /** + * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. + * This initialization order is required to support indirect recursion. + * + *

The static initializer is defined using a helper field to work around limitations of the code generator. + * + */ + private static final Object STATIC_INITIALIZER = ensureInitialized(); + + public static Object ensureInitialized() { + INSTANCE.ensureInitializedInternal(); + return null; + } + } + + private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { + private static final AverageFreeHddMetric.GeneratedPQuery INSTANCE = new GeneratedPQuery(); + + private final PParameter parameter_Average = new PParameter("Average", "java.lang.Double", new JavaTransitiveInstancesKey(java.lang.Double.class), PParameterDirection.INOUT); + + private final List parameters = Arrays.asList(parameter_Average); + + private GeneratedPQuery() { + super(PVisibility.PUBLIC); + } + + @Override + public String getFullyQualifiedName() { + return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.averageFreeHddMetric"; + } + + @Override + public List getParameterNames() { + return Arrays.asList("Average"); + } + + @Override + public List getParameters() { + return parameters; + } + + @Override + public Set doGetContainedBodies() { + setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); + Set bodies = new LinkedHashSet<>(); + { + PBody body = new PBody(this); + PVariable var_Average = body.getOrCreateVariableByName("Average"); + PVariable var___0_ = body.getOrCreateVariableByName("_<0>"); + PVariable var___1_ = body.getOrCreateVariableByName("_<1>"); + new TypeFilterConstraint(body, Tuples.flatTupleOf(var_Average), new JavaTransitiveInstancesKey(java.lang.Double.class)); + body.setSymbolicParameters(Arrays.asList( + new ExportedParameter(body, var_Average, parameter_Average) + )); + // Average == avg find freeHddPercentage(_, #_) + PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); + new AggregatorConstraint(new avg().getAggregatorLogic(Double.class), body, Tuples.flatTupleOf(var___0_, var___1_), FreeHddPercentage.instance().getInternalQueryRepresentation(), var__virtual_0_, 1); + new Equality(body, var_Average, var__virtual_0_); + bodies.add(body); + } + return bodies; + } + } +} 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..a0d087f4 --- /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,540 @@ +/** + * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql + */ +package hu.bme.mit.inf.dslreasoner.domains.cps.queries; + +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.FreeMemoryPercentage; +import java.util.Arrays; +import java.util.Collection; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.function.Consumer; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import org.apache.log4j.Logger; +import org.eclipse.viatra.query.runtime.api.IPatternMatch; +import org.eclipse.viatra.query.runtime.api.IQuerySpecification; +import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; +import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; +import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; +import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; +import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; +import org.eclipse.viatra.query.runtime.matchers.aggregators.avg; +import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; +import org.eclipse.viatra.query.runtime.matchers.context.common.JavaTransitiveInstancesKey; +import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; +import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.AggregatorConstraint; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.TypeFilterConstraint; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; +import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; +import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; +import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; + +/** + * A pattern-specific query specification that can instantiate Matcher in a type-safe way. + * + *

Original source: + *

+ *         pattern averageFreeMemoryMetric(Average : java Double) {
+ *         	Average == avg find freeMemoryPercentage(_, #_);
+ *         }
+ * 
+ * + * @see Matcher + * @see Match + * + */ +@SuppressWarnings("all") +public final class AverageFreeMemoryMetric extends BaseGeneratedEMFQuerySpecification { + /** + * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.averageFreeMemoryMetric pattern, + * to be used in conjunction with {@link Matcher}. + * + *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. + * Each instance is a (possibly partial) substitution of pattern parameters, + * usable to represent a match of the pattern in the result of a query, + * or to specify the bound (fixed) input parameters when issuing a query. + * + * @see Matcher + * + */ + public static abstract class Match extends BasePatternMatch { + private Double fAverage; + + private static List parameterNames = makeImmutableList("Average"); + + private Match(final Double pAverage) { + this.fAverage = pAverage; + } + + @Override + public Object get(final String parameterName) { + if ("Average".equals(parameterName)) return this.fAverage; + return null; + } + + public Double getAverage() { + return this.fAverage; + } + + @Override + public boolean set(final String parameterName, final Object newValue) { + if (!isMutable()) throw new java.lang.UnsupportedOperationException(); + if ("Average".equals(parameterName) ) { + this.fAverage = (Double) newValue; + return true; + } + return false; + } + + public void setAverage(final Double pAverage) { + if (!isMutable()) throw new java.lang.UnsupportedOperationException(); + this.fAverage = pAverage; + } + + @Override + public String patternName() { + return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.averageFreeMemoryMetric"; + } + + @Override + public List parameterNames() { + return AverageFreeMemoryMetric.Match.parameterNames; + } + + @Override + public Object[] toArray() { + return new Object[]{fAverage}; + } + + @Override + public AverageFreeMemoryMetric.Match toImmutable() { + return isMutable() ? newMatch(fAverage) : this; + } + + @Override + public String prettyPrint() { + StringBuilder result = new StringBuilder(); + result.append("\"Average\"=" + prettyPrintValue(fAverage)); + return result.toString(); + } + + @Override + public int hashCode() { + return Objects.hash(fAverage); + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) + return true; + if (obj == null) { + return false; + } + if ((obj instanceof AverageFreeMemoryMetric.Match)) { + AverageFreeMemoryMetric.Match other = (AverageFreeMemoryMetric.Match) obj; + return Objects.equals(fAverage, other.fAverage); + } else { + // this should be infrequent + if (!(obj instanceof IPatternMatch)) { + return false; + } + IPatternMatch otherSig = (IPatternMatch) obj; + return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); + } + } + + @Override + public AverageFreeMemoryMetric specification() { + return AverageFreeMemoryMetric.instance(); + } + + /** + * Returns an empty, mutable match. + * Fields of the mutable match can be filled to create a partial match, usable as matcher input. + * + * @return the empty match. + * + */ + public static AverageFreeMemoryMetric.Match newEmptyMatch() { + return new Mutable(null); + } + + /** + * Returns a mutable (partial) match. + * Fields of the mutable match can be filled to create a partial match, usable as matcher input. + * + * @param pAverage the fixed value of pattern parameter Average, or null if not bound. + * @return the new, mutable (partial) match object. + * + */ + public static AverageFreeMemoryMetric.Match newMutableMatch(final Double pAverage) { + return new Mutable(pAverage); + } + + /** + * Returns a new (partial) match. + * This can be used e.g. to call the matcher with a partial match. + *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. + * @param pAverage the fixed value of pattern parameter Average, or null if not bound. + * @return the (partial) match object. + * + */ + public static AverageFreeMemoryMetric.Match newMatch(final Double pAverage) { + return new Immutable(pAverage); + } + + private static final class Mutable extends AverageFreeMemoryMetric.Match { + Mutable(final Double pAverage) { + super(pAverage); + } + + @Override + public boolean isMutable() { + return true; + } + } + + private static final class Immutable extends AverageFreeMemoryMetric.Match { + Immutable(final Double pAverage) { + super(pAverage); + } + + @Override + public boolean isMutable() { + return false; + } + } + } + + /** + * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.averageFreeMemoryMetric pattern, + * providing pattern-specific query methods. + * + *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, + * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. + * + *

Matches of the pattern will be represented as {@link Match}. + * + *

Original source: + *

+   * pattern averageFreeMemoryMetric(Average : java Double) {
+   * 	Average == avg find freeMemoryPercentage(_, #_);
+   * }
+   * 
+ * + * @see Match + * @see AverageFreeMemoryMetric + * + */ + public static class Matcher extends BaseMatcher { + /** + * Initializes the pattern matcher within an existing VIATRA Query engine. + * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. + * + * @param engine the existing VIATRA Query engine in which this matcher will be created. + * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation + * + */ + public static AverageFreeMemoryMetric.Matcher on(final ViatraQueryEngine engine) { + // check if matcher already exists + Matcher matcher = engine.getExistingMatcher(querySpecification()); + if (matcher == null) { + matcher = (Matcher)engine.getMatcher(querySpecification()); + } + return matcher; + } + + /** + * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation + * @return an initialized matcher + * @noreference This method is for internal matcher initialization by the framework, do not call it manually. + * + */ + public static AverageFreeMemoryMetric.Matcher create() { + return new Matcher(); + } + + private static final int POSITION_AVERAGE = 0; + + private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(AverageFreeMemoryMetric.Matcher.class); + + /** + * Initializes the pattern matcher within an existing VIATRA Query engine. + * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. + * + * @param engine the existing VIATRA Query engine in which this matcher will be created. + * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation + * + */ + private Matcher() { + super(querySpecification()); + } + + /** + * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. + * @param pAverage the fixed value of pattern parameter Average, or null if not bound. + * @return matches represented as a Match object. + * + */ + public Collection getAllMatches(final Double pAverage) { + return rawStreamAllMatches(new Object[]{pAverage}).collect(Collectors.toSet()); + } + + /** + * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. + *

+ * NOTE: It is important not to modify the source model while the stream is being processed. + * If the match set of the pattern changes during processing, the contents of the stream is undefined. + * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. + * @param pAverage the fixed value of pattern parameter Average, or null if not bound. + * @return a stream of matches represented as a Match object. + * + */ + public Stream streamAllMatches(final Double pAverage) { + return rawStreamAllMatches(new Object[]{pAverage}); + } + + /** + * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. + * Neither determinism nor randomness of selection is guaranteed. + * @param pAverage the fixed value of pattern parameter Average, or null if not bound. + * @return a match represented as a Match object, or null if no match is found. + * + */ + public Optional getOneArbitraryMatch(final Double pAverage) { + return rawGetOneArbitraryMatch(new Object[]{pAverage}); + } + + /** + * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, + * under any possible substitution of the unspecified parameters (if any). + * @param pAverage the fixed value of pattern parameter Average, or null if not bound. + * @return true if the input is a valid (partial) match of the pattern. + * + */ + public boolean hasMatch(final Double pAverage) { + return rawHasMatch(new Object[]{pAverage}); + } + + /** + * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. + * @param pAverage the fixed value of pattern parameter Average, or null if not bound. + * @return the number of pattern matches found. + * + */ + public int countMatches(final Double pAverage) { + return rawCountMatches(new Object[]{pAverage}); + } + + /** + * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. + * Neither determinism nor randomness of selection is guaranteed. + * @param pAverage the fixed value of pattern parameter Average, or null if not bound. + * @param processor the action that will process the selected match. + * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked + * + */ + public boolean forOneArbitraryMatch(final Double pAverage, final Consumer processor) { + return rawForOneArbitraryMatch(new Object[]{pAverage}, processor); + } + + /** + * Returns a new (partial) match. + * This can be used e.g. to call the matcher with a partial match. + *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. + * @param pAverage the fixed value of pattern parameter Average, or null if not bound. + * @return the (partial) match object. + * + */ + public AverageFreeMemoryMetric.Match newMatch(final Double pAverage) { + return AverageFreeMemoryMetric.Match.newMatch(pAverage); + } + + /** + * Retrieve the set of values that occur in matches for Average. + * @return the Set of all values or empty set if there are no matches + * + */ + protected Stream rawStreamAllValuesOfAverage(final Object[] parameters) { + return rawStreamAllValues(POSITION_AVERAGE, parameters).map(Double.class::cast); + } + + /** + * Retrieve the set of values that occur in matches for Average. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfAverage() { + return rawStreamAllValuesOfAverage(emptyArray()).collect(Collectors.toSet()); + } + + /** + * Retrieve the set of values that occur in matches for Average. + * @return the Set of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfAverage() { + return rawStreamAllValuesOfAverage(emptyArray()); + } + + @Override + protected AverageFreeMemoryMetric.Match tupleToMatch(final Tuple t) { + try { + return AverageFreeMemoryMetric.Match.newMatch((Double) t.get(POSITION_AVERAGE)); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in tuple not properly typed!",e); + return null; + } + } + + @Override + protected AverageFreeMemoryMetric.Match arrayToMatch(final Object[] match) { + try { + return AverageFreeMemoryMetric.Match.newMatch((Double) match[POSITION_AVERAGE]); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in array not properly typed!",e); + return null; + } + } + + @Override + protected AverageFreeMemoryMetric.Match arrayToMatchMutable(final Object[] match) { + try { + return AverageFreeMemoryMetric.Match.newMutableMatch((Double) match[POSITION_AVERAGE]); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in array not properly typed!",e); + return null; + } + } + + /** + * @return the singleton instance of the query specification of this pattern + * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded + * + */ + public static IQuerySpecification querySpecification() { + return AverageFreeMemoryMetric.instance(); + } + } + + private AverageFreeMemoryMetric() { + super(GeneratedPQuery.INSTANCE); + } + + /** + * @return the singleton instance of the query specification + * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded + * + */ + public static AverageFreeMemoryMetric instance() { + try{ + return LazyHolder.INSTANCE; + } catch (ExceptionInInitializerError err) { + throw processInitializerError(err); + } + } + + @Override + protected AverageFreeMemoryMetric.Matcher instantiate(final ViatraQueryEngine engine) { + return AverageFreeMemoryMetric.Matcher.on(engine); + } + + @Override + public AverageFreeMemoryMetric.Matcher instantiate() { + return AverageFreeMemoryMetric.Matcher.create(); + } + + @Override + public AverageFreeMemoryMetric.Match newEmptyMatch() { + return AverageFreeMemoryMetric.Match.newEmptyMatch(); + } + + @Override + public AverageFreeMemoryMetric.Match newMatch(final Object... parameters) { + return AverageFreeMemoryMetric.Match.newMatch((java.lang.Double) parameters[0]); + } + + /** + * 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: ) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)} to be created + * not at the class load time of the outer class, + * 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: ) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}. + * + *

This workaround is required e.g. to support recursion. + * + */ + private static class LazyHolder { + private static final AverageFreeMemoryMetric INSTANCE = new AverageFreeMemoryMetric(); + + /** + * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. + * This initialization order is required to support indirect recursion. + * + *

The static initializer is defined using a helper field to work around limitations of the code generator. + * + */ + private static final Object STATIC_INITIALIZER = ensureInitialized(); + + public static Object ensureInitialized() { + INSTANCE.ensureInitializedInternal(); + return null; + } + } + + private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { + private static final AverageFreeMemoryMetric.GeneratedPQuery INSTANCE = new GeneratedPQuery(); + + private final PParameter parameter_Average = new PParameter("Average", "java.lang.Double", new JavaTransitiveInstancesKey(java.lang.Double.class), PParameterDirection.INOUT); + + private final List parameters = Arrays.asList(parameter_Average); + + private GeneratedPQuery() { + super(PVisibility.PUBLIC); + } + + @Override + public String getFullyQualifiedName() { + return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.averageFreeMemoryMetric"; + } + + @Override + public List getParameterNames() { + return Arrays.asList("Average"); + } + + @Override + public List getParameters() { + return parameters; + } + + @Override + public Set doGetContainedBodies() { + setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); + Set bodies = new LinkedHashSet<>(); + { + PBody body = new PBody(this); + PVariable var_Average = body.getOrCreateVariableByName("Average"); + PVariable var___0_ = body.getOrCreateVariableByName("_<0>"); + PVariable var___1_ = body.getOrCreateVariableByName("_<1>"); + new TypeFilterConstraint(body, Tuples.flatTupleOf(var_Average), new JavaTransitiveInstancesKey(java.lang.Double.class)); + body.setSymbolicParameters(Arrays.asList( + new ExportedParameter(body, var_Average, parameter_Average) + )); + // Average == avg find freeMemoryPercentage(_, #_) + PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); + new AggregatorConstraint(new avg().getAggregatorLogic(Double.class), body, Tuples.flatTupleOf(var___0_, var___1_), FreeMemoryPercentage.instance().getInternalQueryRepresentation(), var__virtual_0_, 1); + new Equality(body, var_Average, var__virtual_0_); + bodies.add(body); + } + return bodies; + } + } +} 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..4d8ca4cc --- /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,540 @@ +/** + * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql + */ +package hu.bme.mit.inf.dslreasoner.domains.cps.queries; + +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.CpsCost; +import java.util.Arrays; +import java.util.Collection; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.function.Consumer; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import org.apache.log4j.Logger; +import org.eclipse.viatra.query.runtime.api.IPatternMatch; +import org.eclipse.viatra.query.runtime.api.IQuerySpecification; +import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; +import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; +import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; +import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; +import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; +import org.eclipse.viatra.query.runtime.matchers.aggregators.sum; +import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; +import org.eclipse.viatra.query.runtime.matchers.context.common.JavaTransitiveInstancesKey; +import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; +import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.AggregatorConstraint; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.TypeFilterConstraint; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; +import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; +import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; +import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; + +/** + * A pattern-specific query specification that can instantiate Matcher in a type-safe way. + * + *

Original source: + *

+ *         pattern costMetric(Cost : java Integer) {
+ *         	Cost == sum find cpsCost(_, #_);
+ *         }
+ * 
+ * + * @see Matcher + * @see Match + * + */ +@SuppressWarnings("all") +public final class CostMetric extends BaseGeneratedEMFQuerySpecification { + /** + * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.costMetric pattern, + * to be used in conjunction with {@link Matcher}. + * + *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. + * Each instance is a (possibly partial) substitution of pattern parameters, + * usable to represent a match of the pattern in the result of a query, + * or to specify the bound (fixed) input parameters when issuing a query. + * + * @see Matcher + * + */ + public static abstract class Match extends BasePatternMatch { + private Integer fCost; + + private static List parameterNames = makeImmutableList("Cost"); + + private Match(final Integer pCost) { + this.fCost = pCost; + } + + @Override + public Object get(final String parameterName) { + if ("Cost".equals(parameterName)) return this.fCost; + return null; + } + + public Integer getCost() { + return this.fCost; + } + + @Override + public boolean set(final String parameterName, final Object newValue) { + if (!isMutable()) throw new java.lang.UnsupportedOperationException(); + if ("Cost".equals(parameterName) ) { + this.fCost = (Integer) newValue; + return true; + } + return false; + } + + public void setCost(final Integer pCost) { + if (!isMutable()) throw new java.lang.UnsupportedOperationException(); + this.fCost = pCost; + } + + @Override + public String patternName() { + return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.costMetric"; + } + + @Override + public List parameterNames() { + return CostMetric.Match.parameterNames; + } + + @Override + public Object[] toArray() { + return new Object[]{fCost}; + } + + @Override + public CostMetric.Match toImmutable() { + return isMutable() ? newMatch(fCost) : this; + } + + @Override + public String prettyPrint() { + StringBuilder result = new StringBuilder(); + result.append("\"Cost\"=" + prettyPrintValue(fCost)); + return result.toString(); + } + + @Override + public int hashCode() { + return Objects.hash(fCost); + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) + return true; + if (obj == null) { + return false; + } + if ((obj instanceof CostMetric.Match)) { + CostMetric.Match other = (CostMetric.Match) obj; + return Objects.equals(fCost, other.fCost); + } else { + // this should be infrequent + if (!(obj instanceof IPatternMatch)) { + return false; + } + IPatternMatch otherSig = (IPatternMatch) obj; + return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); + } + } + + @Override + public CostMetric specification() { + return CostMetric.instance(); + } + + /** + * Returns an empty, mutable match. + * Fields of the mutable match can be filled to create a partial match, usable as matcher input. + * + * @return the empty match. + * + */ + public static CostMetric.Match newEmptyMatch() { + return new Mutable(null); + } + + /** + * Returns a mutable (partial) match. + * Fields of the mutable match can be filled to create a partial match, usable as matcher input. + * + * @param pCost the fixed value of pattern parameter Cost, or null if not bound. + * @return the new, mutable (partial) match object. + * + */ + public static CostMetric.Match newMutableMatch(final Integer pCost) { + return new Mutable(pCost); + } + + /** + * Returns a new (partial) match. + * This can be used e.g. to call the matcher with a partial match. + *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. + * @param pCost the fixed value of pattern parameter Cost, or null if not bound. + * @return the (partial) match object. + * + */ + public static CostMetric.Match newMatch(final Integer pCost) { + return new Immutable(pCost); + } + + private static final class Mutable extends CostMetric.Match { + Mutable(final Integer pCost) { + super(pCost); + } + + @Override + public boolean isMutable() { + return true; + } + } + + private static final class Immutable extends CostMetric.Match { + Immutable(final Integer pCost) { + super(pCost); + } + + @Override + public boolean isMutable() { + return false; + } + } + } + + /** + * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.costMetric pattern, + * providing pattern-specific query methods. + * + *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, + * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. + * + *

Matches of the pattern will be represented as {@link Match}. + * + *

Original source: + *

+   * pattern costMetric(Cost : java Integer) {
+   * 	Cost == sum find cpsCost(_, #_);
+   * }
+   * 
+ * + * @see Match + * @see CostMetric + * + */ + public static class Matcher extends BaseMatcher { + /** + * Initializes the pattern matcher within an existing VIATRA Query engine. + * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. + * + * @param engine the existing VIATRA Query engine in which this matcher will be created. + * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation + * + */ + public static CostMetric.Matcher on(final ViatraQueryEngine engine) { + // check if matcher already exists + Matcher matcher = engine.getExistingMatcher(querySpecification()); + if (matcher == null) { + matcher = (Matcher)engine.getMatcher(querySpecification()); + } + return matcher; + } + + /** + * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation + * @return an initialized matcher + * @noreference This method is for internal matcher initialization by the framework, do not call it manually. + * + */ + public static CostMetric.Matcher create() { + return new Matcher(); + } + + private static final int POSITION_COST = 0; + + private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(CostMetric.Matcher.class); + + /** + * Initializes the pattern matcher within an existing VIATRA Query engine. + * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. + * + * @param engine the existing VIATRA Query engine in which this matcher will be created. + * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation + * + */ + private Matcher() { + super(querySpecification()); + } + + /** + * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. + * @param pCost the fixed value of pattern parameter Cost, or null if not bound. + * @return matches represented as a Match object. + * + */ + public Collection getAllMatches(final Integer pCost) { + return rawStreamAllMatches(new Object[]{pCost}).collect(Collectors.toSet()); + } + + /** + * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. + *

+ * NOTE: It is important not to modify the source model while the stream is being processed. + * If the match set of the pattern changes during processing, the contents of the stream is undefined. + * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. + * @param pCost the fixed value of pattern parameter Cost, or null if not bound. + * @return a stream of matches represented as a Match object. + * + */ + public Stream streamAllMatches(final Integer pCost) { + return rawStreamAllMatches(new Object[]{pCost}); + } + + /** + * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. + * Neither determinism nor randomness of selection is guaranteed. + * @param pCost the fixed value of pattern parameter Cost, or null if not bound. + * @return a match represented as a Match object, or null if no match is found. + * + */ + public Optional getOneArbitraryMatch(final Integer pCost) { + return rawGetOneArbitraryMatch(new Object[]{pCost}); + } + + /** + * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, + * under any possible substitution of the unspecified parameters (if any). + * @param pCost the fixed value of pattern parameter Cost, or null if not bound. + * @return true if the input is a valid (partial) match of the pattern. + * + */ + public boolean hasMatch(final Integer pCost) { + return rawHasMatch(new Object[]{pCost}); + } + + /** + * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. + * @param pCost the fixed value of pattern parameter Cost, or null if not bound. + * @return the number of pattern matches found. + * + */ + public int countMatches(final Integer pCost) { + return rawCountMatches(new Object[]{pCost}); + } + + /** + * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. + * Neither determinism nor randomness of selection is guaranteed. + * @param pCost the fixed value of pattern parameter Cost, or null if not bound. + * @param processor the action that will process the selected match. + * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked + * + */ + public boolean forOneArbitraryMatch(final Integer pCost, final Consumer processor) { + return rawForOneArbitraryMatch(new Object[]{pCost}, processor); + } + + /** + * Returns a new (partial) match. + * This can be used e.g. to call the matcher with a partial match. + *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. + * @param pCost the fixed value of pattern parameter Cost, or null if not bound. + * @return the (partial) match object. + * + */ + public CostMetric.Match newMatch(final Integer pCost) { + return CostMetric.Match.newMatch(pCost); + } + + /** + * Retrieve the set of values that occur in matches for Cost. + * @return the Set of all values or empty set if there are no matches + * + */ + protected Stream rawStreamAllValuesOfCost(final Object[] parameters) { + return rawStreamAllValues(POSITION_COST, parameters).map(Integer.class::cast); + } + + /** + * Retrieve the set of values that occur in matches for Cost. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfCost() { + return rawStreamAllValuesOfCost(emptyArray()).collect(Collectors.toSet()); + } + + /** + * Retrieve the set of values that occur in matches for Cost. + * @return the Set of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfCost() { + return rawStreamAllValuesOfCost(emptyArray()); + } + + @Override + protected CostMetric.Match tupleToMatch(final Tuple t) { + try { + return CostMetric.Match.newMatch((Integer) t.get(POSITION_COST)); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in tuple not properly typed!",e); + return null; + } + } + + @Override + protected CostMetric.Match arrayToMatch(final Object[] match) { + try { + return CostMetric.Match.newMatch((Integer) match[POSITION_COST]); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in array not properly typed!",e); + return null; + } + } + + @Override + protected CostMetric.Match arrayToMatchMutable(final Object[] match) { + try { + return CostMetric.Match.newMutableMatch((Integer) match[POSITION_COST]); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in array not properly typed!",e); + return null; + } + } + + /** + * @return the singleton instance of the query specification of this pattern + * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded + * + */ + public static IQuerySpecification querySpecification() { + return CostMetric.instance(); + } + } + + private CostMetric() { + super(GeneratedPQuery.INSTANCE); + } + + /** + * @return the singleton instance of the query specification + * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded + * + */ + public static CostMetric instance() { + try{ + return LazyHolder.INSTANCE; + } catch (ExceptionInInitializerError err) { + throw processInitializerError(err); + } + } + + @Override + protected CostMetric.Matcher instantiate(final ViatraQueryEngine engine) { + return CostMetric.Matcher.on(engine); + } + + @Override + public CostMetric.Matcher instantiate() { + return CostMetric.Matcher.create(); + } + + @Override + public CostMetric.Match newEmptyMatch() { + return CostMetric.Match.newEmptyMatch(); + } + + @Override + public CostMetric.Match newMatch(final Object... parameters) { + return CostMetric.Match.newMatch((java.lang.Integer) parameters[0]); + } + + /** + * 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: ) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)} to be created + * not at the class load time of the outer class, + * 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: ) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}. + * + *

This workaround is required e.g. to support recursion. + * + */ + private static class LazyHolder { + private static final CostMetric INSTANCE = new CostMetric(); + + /** + * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. + * This initialization order is required to support indirect recursion. + * + *

The static initializer is defined using a helper field to work around limitations of the code generator. + * + */ + private static final Object STATIC_INITIALIZER = ensureInitialized(); + + public static Object ensureInitialized() { + INSTANCE.ensureInitializedInternal(); + return null; + } + } + + private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { + private static final CostMetric.GeneratedPQuery INSTANCE = new GeneratedPQuery(); + + private final PParameter parameter_Cost = new PParameter("Cost", "java.lang.Integer", new JavaTransitiveInstancesKey(java.lang.Integer.class), PParameterDirection.INOUT); + + private final List parameters = Arrays.asList(parameter_Cost); + + private GeneratedPQuery() { + super(PVisibility.PUBLIC); + } + + @Override + public String getFullyQualifiedName() { + return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.costMetric"; + } + + @Override + public List getParameterNames() { + return Arrays.asList("Cost"); + } + + @Override + public List getParameters() { + return parameters; + } + + @Override + public Set doGetContainedBodies() { + setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); + Set bodies = new LinkedHashSet<>(); + { + PBody body = new PBody(this); + PVariable var_Cost = body.getOrCreateVariableByName("Cost"); + PVariable var___0_ = body.getOrCreateVariableByName("_<0>"); + PVariable var___1_ = body.getOrCreateVariableByName("_<1>"); + new TypeFilterConstraint(body, Tuples.flatTupleOf(var_Cost), new JavaTransitiveInstancesKey(java.lang.Integer.class)); + body.setSymbolicParameters(Arrays.asList( + new ExportedParameter(body, var_Cost, parameter_Cost) + )); + // Cost == sum find cpsCost(_, #_) + PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); + new AggregatorConstraint(new sum().getAggregatorLogic(Integer.class), body, Tuples.flatTupleOf(var___0_, var___1_), CpsCost.instance().getInternalQueryRepresentation(), var__virtual_0_, 1); + new Equality(body, var_Cost, var__virtual_0_); + bodies.add(body); + } + return bodies; + } + } +} diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsApplications.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsApplications.java new file mode 100644 index 00000000..2c20b38e --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsApplications.java @@ -0,0 +1,705 @@ +/** + * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql + */ +package hu.bme.mit.inf.dslreasoner.domains.cps.queries; + +import hu.bme.mit.inf.dslreasoner.domains.cps.ApplicationInstance; +import hu.bme.mit.inf.dslreasoner.domains.cps.CyberPhysicalSystem; +import java.util.Arrays; +import java.util.Collection; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.function.Consumer; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import org.apache.log4j.Logger; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.viatra.query.runtime.api.IPatternMatch; +import org.eclipse.viatra.query.runtime.api.IQuerySpecification; +import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; +import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; +import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; +import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; +import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; +import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; +import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; +import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; +import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; +import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; +import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; +import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; +import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; +import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; + +/** + * A pattern-specific query specification that can instantiate Matcher in a type-safe way. + * + *

Original source: + *

+ *         {@literal @}QueryBasedFeature(feature = "applications")
+ *         pattern cpsApplications(Cps : CyberPhysicalSystem, AppInstance : ApplicationInstance) {
+ *         	CyberPhysicalSystem.applicationTypes.instances(Cps, AppInstance);
+ *         }
+ * 
+ * + * @see Matcher + * @see Match + * + */ +@SuppressWarnings("all") +public final class CpsApplications extends BaseGeneratedEMFQuerySpecification { + /** + * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.cpsApplications pattern, + * to be used in conjunction with {@link Matcher}. + * + *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. + * Each instance is a (possibly partial) substitution of pattern parameters, + * usable to represent a match of the pattern in the result of a query, + * or to specify the bound (fixed) input parameters when issuing a query. + * + * @see Matcher + * + */ + public static abstract class Match extends BasePatternMatch { + private CyberPhysicalSystem fCps; + + private ApplicationInstance fAppInstance; + + private static List parameterNames = makeImmutableList("Cps", "AppInstance"); + + private Match(final CyberPhysicalSystem pCps, final ApplicationInstance pAppInstance) { + this.fCps = pCps; + this.fAppInstance = pAppInstance; + } + + @Override + public Object get(final String parameterName) { + if ("Cps".equals(parameterName)) return this.fCps; + if ("AppInstance".equals(parameterName)) return this.fAppInstance; + return null; + } + + public CyberPhysicalSystem getCps() { + return this.fCps; + } + + public ApplicationInstance getAppInstance() { + return this.fAppInstance; + } + + @Override + public boolean set(final String parameterName, final Object newValue) { + if (!isMutable()) throw new java.lang.UnsupportedOperationException(); + if ("Cps".equals(parameterName) ) { + this.fCps = (CyberPhysicalSystem) newValue; + return true; + } + if ("AppInstance".equals(parameterName) ) { + this.fAppInstance = (ApplicationInstance) newValue; + return true; + } + return false; + } + + public void setCps(final CyberPhysicalSystem pCps) { + if (!isMutable()) throw new java.lang.UnsupportedOperationException(); + this.fCps = pCps; + } + + public void setAppInstance(final ApplicationInstance pAppInstance) { + if (!isMutable()) throw new java.lang.UnsupportedOperationException(); + this.fAppInstance = pAppInstance; + } + + @Override + public String patternName() { + return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.cpsApplications"; + } + + @Override + public List parameterNames() { + return CpsApplications.Match.parameterNames; + } + + @Override + public Object[] toArray() { + return new Object[]{fCps, fAppInstance}; + } + + @Override + public CpsApplications.Match toImmutable() { + return isMutable() ? newMatch(fCps, fAppInstance) : this; + } + + @Override + public String prettyPrint() { + StringBuilder result = new StringBuilder(); + result.append("\"Cps\"=" + prettyPrintValue(fCps) + ", "); + result.append("\"AppInstance\"=" + prettyPrintValue(fAppInstance)); + return result.toString(); + } + + @Override + public int hashCode() { + return Objects.hash(fCps, fAppInstance); + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) + return true; + if (obj == null) { + return false; + } + if ((obj instanceof CpsApplications.Match)) { + CpsApplications.Match other = (CpsApplications.Match) obj; + return Objects.equals(fCps, other.fCps) && Objects.equals(fAppInstance, other.fAppInstance); + } else { + // this should be infrequent + if (!(obj instanceof IPatternMatch)) { + return false; + } + IPatternMatch otherSig = (IPatternMatch) obj; + return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); + } + } + + @Override + public CpsApplications specification() { + return CpsApplications.instance(); + } + + /** + * Returns an empty, mutable match. + * Fields of the mutable match can be filled to create a partial match, usable as matcher input. + * + * @return the empty match. + * + */ + public static CpsApplications.Match newEmptyMatch() { + return new Mutable(null, null); + } + + /** + * Returns a mutable (partial) match. + * Fields of the mutable match can be filled to create a partial match, usable as matcher input. + * + * @param pCps the fixed value of pattern parameter Cps, or null if not bound. + * @param pAppInstance the fixed value of pattern parameter AppInstance, or null if not bound. + * @return the new, mutable (partial) match object. + * + */ + public static CpsApplications.Match newMutableMatch(final CyberPhysicalSystem pCps, final ApplicationInstance pAppInstance) { + return new Mutable(pCps, pAppInstance); + } + + /** + * Returns a new (partial) match. + * This can be used e.g. to call the matcher with a partial match. + *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. + * @param pCps the fixed value of pattern parameter Cps, or null if not bound. + * @param pAppInstance the fixed value of pattern parameter AppInstance, or null if not bound. + * @return the (partial) match object. + * + */ + public static CpsApplications.Match newMatch(final CyberPhysicalSystem pCps, final ApplicationInstance pAppInstance) { + return new Immutable(pCps, pAppInstance); + } + + private static final class Mutable extends CpsApplications.Match { + Mutable(final CyberPhysicalSystem pCps, final ApplicationInstance pAppInstance) { + super(pCps, pAppInstance); + } + + @Override + public boolean isMutable() { + return true; + } + } + + private static final class Immutable extends CpsApplications.Match { + Immutable(final CyberPhysicalSystem pCps, final ApplicationInstance pAppInstance) { + super(pCps, pAppInstance); + } + + @Override + public boolean isMutable() { + return false; + } + } + } + + /** + * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.cpsApplications pattern, + * providing pattern-specific query methods. + * + *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, + * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. + * + *

Matches of the pattern will be represented as {@link Match}. + * + *

Original source: + *

+   * {@literal @}QueryBasedFeature(feature = "applications")
+   * pattern cpsApplications(Cps : CyberPhysicalSystem, AppInstance : ApplicationInstance) {
+   * 	CyberPhysicalSystem.applicationTypes.instances(Cps, AppInstance);
+   * }
+   * 
+ * + * @see Match + * @see CpsApplications + * + */ + public static class Matcher extends BaseMatcher { + /** + * Initializes the pattern matcher within an existing VIATRA Query engine. + * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. + * + * @param engine the existing VIATRA Query engine in which this matcher will be created. + * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation + * + */ + public static CpsApplications.Matcher on(final ViatraQueryEngine engine) { + // check if matcher already exists + Matcher matcher = engine.getExistingMatcher(querySpecification()); + if (matcher == null) { + matcher = (Matcher)engine.getMatcher(querySpecification()); + } + return matcher; + } + + /** + * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation + * @return an initialized matcher + * @noreference This method is for internal matcher initialization by the framework, do not call it manually. + * + */ + public static CpsApplications.Matcher create() { + return new Matcher(); + } + + private static final int POSITION_CPS = 0; + + private static final int POSITION_APPINSTANCE = 1; + + private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(CpsApplications.Matcher.class); + + /** + * Initializes the pattern matcher within an existing VIATRA Query engine. + * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. + * + * @param engine the existing VIATRA Query engine in which this matcher will be created. + * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation + * + */ + private Matcher() { + super(querySpecification()); + } + + /** + * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. + * @param pCps the fixed value of pattern parameter Cps, or null if not bound. + * @param pAppInstance the fixed value of pattern parameter AppInstance, or null if not bound. + * @return matches represented as a Match object. + * + */ + public Collection getAllMatches(final CyberPhysicalSystem pCps, final ApplicationInstance pAppInstance) { + return rawStreamAllMatches(new Object[]{pCps, pAppInstance}).collect(Collectors.toSet()); + } + + /** + * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. + *

+ * NOTE: It is important not to modify the source model while the stream is being processed. + * If the match set of the pattern changes during processing, the contents of the stream is undefined. + * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. + * @param pCps the fixed value of pattern parameter Cps, or null if not bound. + * @param pAppInstance the fixed value of pattern parameter AppInstance, or null if not bound. + * @return a stream of matches represented as a Match object. + * + */ + public Stream streamAllMatches(final CyberPhysicalSystem pCps, final ApplicationInstance pAppInstance) { + return rawStreamAllMatches(new Object[]{pCps, pAppInstance}); + } + + /** + * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. + * Neither determinism nor randomness of selection is guaranteed. + * @param pCps the fixed value of pattern parameter Cps, or null if not bound. + * @param pAppInstance the fixed value of pattern parameter AppInstance, or null if not bound. + * @return a match represented as a Match object, or null if no match is found. + * + */ + public Optional getOneArbitraryMatch(final CyberPhysicalSystem pCps, final ApplicationInstance pAppInstance) { + return rawGetOneArbitraryMatch(new Object[]{pCps, pAppInstance}); + } + + /** + * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, + * under any possible substitution of the unspecified parameters (if any). + * @param pCps the fixed value of pattern parameter Cps, or null if not bound. + * @param pAppInstance the fixed value of pattern parameter AppInstance, or null if not bound. + * @return true if the input is a valid (partial) match of the pattern. + * + */ + public boolean hasMatch(final CyberPhysicalSystem pCps, final ApplicationInstance pAppInstance) { + return rawHasMatch(new Object[]{pCps, pAppInstance}); + } + + /** + * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. + * @param pCps the fixed value of pattern parameter Cps, or null if not bound. + * @param pAppInstance the fixed value of pattern parameter AppInstance, or null if not bound. + * @return the number of pattern matches found. + * + */ + public int countMatches(final CyberPhysicalSystem pCps, final ApplicationInstance pAppInstance) { + return rawCountMatches(new Object[]{pCps, pAppInstance}); + } + + /** + * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. + * Neither determinism nor randomness of selection is guaranteed. + * @param pCps the fixed value of pattern parameter Cps, or null if not bound. + * @param pAppInstance the fixed value of pattern parameter AppInstance, or null if not bound. + * @param processor the action that will process the selected match. + * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked + * + */ + public boolean forOneArbitraryMatch(final CyberPhysicalSystem pCps, final ApplicationInstance pAppInstance, final Consumer processor) { + return rawForOneArbitraryMatch(new Object[]{pCps, pAppInstance}, processor); + } + + /** + * Returns a new (partial) match. + * This can be used e.g. to call the matcher with a partial match. + *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. + * @param pCps the fixed value of pattern parameter Cps, or null if not bound. + * @param pAppInstance the fixed value of pattern parameter AppInstance, or null if not bound. + * @return the (partial) match object. + * + */ + public CpsApplications.Match newMatch(final CyberPhysicalSystem pCps, final ApplicationInstance pAppInstance) { + return CpsApplications.Match.newMatch(pCps, pAppInstance); + } + + /** + * Retrieve the set of values that occur in matches for Cps. + * @return the Set of all values or empty set if there are no matches + * + */ + protected Stream rawStreamAllValuesOfCps(final Object[] parameters) { + return rawStreamAllValues(POSITION_CPS, parameters).map(CyberPhysicalSystem.class::cast); + } + + /** + * Retrieve the set of values that occur in matches for Cps. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfCps() { + return rawStreamAllValuesOfCps(emptyArray()).collect(Collectors.toSet()); + } + + /** + * Retrieve the set of values that occur in matches for Cps. + * @return the Set of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfCps() { + return rawStreamAllValuesOfCps(emptyArray()); + } + + /** + * Retrieve the set of values that occur in matches for Cps. + *

+ * NOTE: It is important not to modify the source model while the stream is being processed. + * If the match set of the pattern changes during processing, the contents of the stream is undefined. + * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. + * + * @return the Stream of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfCps(final CpsApplications.Match partialMatch) { + return rawStreamAllValuesOfCps(partialMatch.toArray()); + } + + /** + * Retrieve the set of values that occur in matches for Cps. + *

+ * NOTE: It is important not to modify the source model while the stream is being processed. + * If the match set of the pattern changes during processing, the contents of the stream is undefined. + * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. + * + * @return the Stream of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfCps(final ApplicationInstance pAppInstance) { + return rawStreamAllValuesOfCps(new Object[]{null, pAppInstance}); + } + + /** + * Retrieve the set of values that occur in matches for Cps. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfCps(final CpsApplications.Match partialMatch) { + return rawStreamAllValuesOfCps(partialMatch.toArray()).collect(Collectors.toSet()); + } + + /** + * Retrieve the set of values that occur in matches for Cps. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfCps(final ApplicationInstance pAppInstance) { + return rawStreamAllValuesOfCps(new Object[]{null, pAppInstance}).collect(Collectors.toSet()); + } + + /** + * Retrieve the set of values that occur in matches for AppInstance. + * @return the Set of all values or empty set if there are no matches + * + */ + protected Stream rawStreamAllValuesOfAppInstance(final Object[] parameters) { + return rawStreamAllValues(POSITION_APPINSTANCE, parameters).map(ApplicationInstance.class::cast); + } + + /** + * Retrieve the set of values that occur in matches for AppInstance. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfAppInstance() { + return rawStreamAllValuesOfAppInstance(emptyArray()).collect(Collectors.toSet()); + } + + /** + * Retrieve the set of values that occur in matches for AppInstance. + * @return the Set of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfAppInstance() { + return rawStreamAllValuesOfAppInstance(emptyArray()); + } + + /** + * Retrieve the set of values that occur in matches for AppInstance. + *

+ * NOTE: It is important not to modify the source model while the stream is being processed. + * If the match set of the pattern changes during processing, the contents of the stream is undefined. + * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. + * + * @return the Stream of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfAppInstance(final CpsApplications.Match partialMatch) { + return rawStreamAllValuesOfAppInstance(partialMatch.toArray()); + } + + /** + * Retrieve the set of values that occur in matches for AppInstance. + *

+ * NOTE: It is important not to modify the source model while the stream is being processed. + * If the match set of the pattern changes during processing, the contents of the stream is undefined. + * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. + * + * @return the Stream of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfAppInstance(final CyberPhysicalSystem pCps) { + return rawStreamAllValuesOfAppInstance(new Object[]{pCps, null}); + } + + /** + * Retrieve the set of values that occur in matches for AppInstance. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfAppInstance(final CpsApplications.Match partialMatch) { + return rawStreamAllValuesOfAppInstance(partialMatch.toArray()).collect(Collectors.toSet()); + } + + /** + * Retrieve the set of values that occur in matches for AppInstance. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfAppInstance(final CyberPhysicalSystem pCps) { + return rawStreamAllValuesOfAppInstance(new Object[]{pCps, null}).collect(Collectors.toSet()); + } + + @Override + protected CpsApplications.Match tupleToMatch(final Tuple t) { + try { + return CpsApplications.Match.newMatch((CyberPhysicalSystem) t.get(POSITION_CPS), (ApplicationInstance) t.get(POSITION_APPINSTANCE)); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in tuple not properly typed!",e); + return null; + } + } + + @Override + protected CpsApplications.Match arrayToMatch(final Object[] match) { + try { + return CpsApplications.Match.newMatch((CyberPhysicalSystem) match[POSITION_CPS], (ApplicationInstance) match[POSITION_APPINSTANCE]); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in array not properly typed!",e); + return null; + } + } + + @Override + protected CpsApplications.Match arrayToMatchMutable(final Object[] match) { + try { + return CpsApplications.Match.newMutableMatch((CyberPhysicalSystem) match[POSITION_CPS], (ApplicationInstance) match[POSITION_APPINSTANCE]); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in array not properly typed!",e); + return null; + } + } + + /** + * @return the singleton instance of the query specification of this pattern + * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded + * + */ + public static IQuerySpecification querySpecification() { + return CpsApplications.instance(); + } + } + + private CpsApplications() { + super(GeneratedPQuery.INSTANCE); + } + + /** + * @return the singleton instance of the query specification + * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded + * + */ + public static CpsApplications instance() { + try{ + return LazyHolder.INSTANCE; + } catch (ExceptionInInitializerError err) { + throw processInitializerError(err); + } + } + + @Override + protected CpsApplications.Matcher instantiate(final ViatraQueryEngine engine) { + return CpsApplications.Matcher.on(engine); + } + + @Override + public CpsApplications.Matcher instantiate() { + return CpsApplications.Matcher.create(); + } + + @Override + public CpsApplications.Match newEmptyMatch() { + return CpsApplications.Match.newEmptyMatch(); + } + + @Override + public CpsApplications.Match newMatch(final Object... parameters) { + return CpsApplications.Match.newMatch((hu.bme.mit.inf.dslreasoner.domains.cps.CyberPhysicalSystem) parameters[0], (hu.bme.mit.inf.dslreasoner.domains.cps.ApplicationInstance) parameters[1]); + } + + /** + * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.CpsApplications (visibility: PUBLIC, simpleName: CpsApplications, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.CpsApplications, deprecated: ) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)} to be created + * not at the class load time of the outer class, + * but rather at the first call to {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.CpsApplications (visibility: PUBLIC, simpleName: CpsApplications, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.CpsApplications, deprecated: ) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}. + * + *

This workaround is required e.g. to support recursion. + * + */ + private static class LazyHolder { + private static final CpsApplications INSTANCE = new CpsApplications(); + + /** + * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. + * This initialization order is required to support indirect recursion. + * + *

The static initializer is defined using a helper field to work around limitations of the code generator. + * + */ + private static final Object STATIC_INITIALIZER = ensureInitialized(); + + public static Object ensureInitialized() { + INSTANCE.ensureInitializedInternal(); + return null; + } + } + + private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { + private static final CpsApplications.GeneratedPQuery INSTANCE = new GeneratedPQuery(); + + 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); + + 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); + + private final List parameters = Arrays.asList(parameter_Cps, parameter_AppInstance); + + private GeneratedPQuery() { + super(PVisibility.PUBLIC); + } + + @Override + public String getFullyQualifiedName() { + return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.cpsApplications"; + } + + @Override + public List getParameterNames() { + return Arrays.asList("Cps","AppInstance"); + } + + @Override + public List getParameters() { + return parameters; + } + + @Override + public Set doGetContainedBodies() { + setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); + Set bodies = new LinkedHashSet<>(); + { + PBody body = new PBody(this); + PVariable var_Cps = body.getOrCreateVariableByName("Cps"); + PVariable var_AppInstance = body.getOrCreateVariableByName("AppInstance"); + new TypeConstraint(body, Tuples.flatTupleOf(var_Cps), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "CyberPhysicalSystem"))); + new TypeConstraint(body, Tuples.flatTupleOf(var_AppInstance), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance"))); + body.setSymbolicParameters(Arrays.asList( + new ExportedParameter(body, var_Cps, parameter_Cps), + new ExportedParameter(body, var_AppInstance, parameter_AppInstance) + )); + // CyberPhysicalSystem.applicationTypes.instances(Cps, AppInstance) + new TypeConstraint(body, Tuples.flatTupleOf(var_Cps), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "CyberPhysicalSystem"))); + PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); + new TypeConstraint(body, Tuples.flatTupleOf(var_Cps, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "CyberPhysicalSystem", "applicationTypes"))); + new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationType"))); + PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); + new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ApplicationType", "instances"))); + new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance"))); + new Equality(body, var__virtual_1_, var_AppInstance); + bodies.add(body); + } + { + PAnnotation annotation = new PAnnotation("QueryBasedFeature"); + annotation.addAttribute("feature", "applications"); + addAnnotation(annotation); + } + return bodies; + } + } +} diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsCost.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsCost.java new file mode 100644 index 00000000..169a30e5 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsCost.java @@ -0,0 +1,738 @@ +/** + * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql + */ +package hu.bme.mit.inf.dslreasoner.domains.cps.queries; + +import hu.bme.mit.inf.dslreasoner.domains.cps.CyberPhysicalSystem; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.CpsApplications; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.HostInstanceCost; +import java.util.Arrays; +import java.util.Collection; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.function.Consumer; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import org.apache.log4j.Logger; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.viatra.query.runtime.api.IPatternMatch; +import org.eclipse.viatra.query.runtime.api.IQuerySpecification; +import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; +import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; +import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; +import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; +import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; +import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; +import org.eclipse.viatra.query.runtime.matchers.aggregators.sum; +import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; +import org.eclipse.viatra.query.runtime.matchers.context.common.JavaTransitiveInstancesKey; +import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator; +import org.eclipse.viatra.query.runtime.matchers.psystem.IValueProvider; +import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; +import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.AggregatorConstraint; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.PatternMatchCounter; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.TypeFilterConstraint; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; +import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; +import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; +import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; + +/** + * A pattern-specific query specification that can instantiate Matcher in a type-safe way. + * + *

Original source: + *

+ *         pattern cpsCost(Cps : CyberPhysicalSystem, Cost : java Integer) {
+ *         	AppCount == count find cpsApplications(Cps, _);
+ *         	HostCost == sum find hostInstanceCost(Cps, _, #_);
+ *         	Cost == eval(5  AppCount + HostCost);
+ *         }
+ * 
+ * + * @see Matcher + * @see Match + * + */ +@SuppressWarnings("all") +public final class CpsCost extends BaseGeneratedEMFQuerySpecification { + /** + * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.cpsCost pattern, + * to be used in conjunction with {@link Matcher}. + * + *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. + * Each instance is a (possibly partial) substitution of pattern parameters, + * usable to represent a match of the pattern in the result of a query, + * or to specify the bound (fixed) input parameters when issuing a query. + * + * @see Matcher + * + */ + public static abstract class Match extends BasePatternMatch { + private CyberPhysicalSystem fCps; + + private Integer fCost; + + private static List parameterNames = makeImmutableList("Cps", "Cost"); + + private Match(final CyberPhysicalSystem pCps, final Integer pCost) { + this.fCps = pCps; + this.fCost = pCost; + } + + @Override + public Object get(final String parameterName) { + if ("Cps".equals(parameterName)) return this.fCps; + if ("Cost".equals(parameterName)) return this.fCost; + return null; + } + + public CyberPhysicalSystem getCps() { + return this.fCps; + } + + public Integer getCost() { + return this.fCost; + } + + @Override + public boolean set(final String parameterName, final Object newValue) { + if (!isMutable()) throw new java.lang.UnsupportedOperationException(); + if ("Cps".equals(parameterName) ) { + this.fCps = (CyberPhysicalSystem) newValue; + return true; + } + if ("Cost".equals(parameterName) ) { + this.fCost = (Integer) newValue; + return true; + } + return false; + } + + public void setCps(final CyberPhysicalSystem pCps) { + if (!isMutable()) throw new java.lang.UnsupportedOperationException(); + this.fCps = pCps; + } + + public void setCost(final Integer pCost) { + if (!isMutable()) throw new java.lang.UnsupportedOperationException(); + this.fCost = pCost; + } + + @Override + public String patternName() { + return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.cpsCost"; + } + + @Override + public List parameterNames() { + return CpsCost.Match.parameterNames; + } + + @Override + public Object[] toArray() { + return new Object[]{fCps, fCost}; + } + + @Override + public CpsCost.Match toImmutable() { + return isMutable() ? newMatch(fCps, fCost) : this; + } + + @Override + public String prettyPrint() { + StringBuilder result = new StringBuilder(); + result.append("\"Cps\"=" + prettyPrintValue(fCps) + ", "); + result.append("\"Cost\"=" + prettyPrintValue(fCost)); + return result.toString(); + } + + @Override + public int hashCode() { + return Objects.hash(fCps, fCost); + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) + return true; + if (obj == null) { + return false; + } + if ((obj instanceof CpsCost.Match)) { + CpsCost.Match other = (CpsCost.Match) obj; + return Objects.equals(fCps, other.fCps) && Objects.equals(fCost, other.fCost); + } else { + // this should be infrequent + if (!(obj instanceof IPatternMatch)) { + return false; + } + IPatternMatch otherSig = (IPatternMatch) obj; + return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); + } + } + + @Override + public CpsCost specification() { + return CpsCost.instance(); + } + + /** + * Returns an empty, mutable match. + * Fields of the mutable match can be filled to create a partial match, usable as matcher input. + * + * @return the empty match. + * + */ + public static CpsCost.Match newEmptyMatch() { + return new Mutable(null, null); + } + + /** + * Returns a mutable (partial) match. + * Fields of the mutable match can be filled to create a partial match, usable as matcher input. + * + * @param pCps the fixed value of pattern parameter Cps, or null if not bound. + * @param pCost the fixed value of pattern parameter Cost, or null if not bound. + * @return the new, mutable (partial) match object. + * + */ + public static CpsCost.Match newMutableMatch(final CyberPhysicalSystem pCps, final Integer pCost) { + return new Mutable(pCps, pCost); + } + + /** + * Returns a new (partial) match. + * This can be used e.g. to call the matcher with a partial match. + *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. + * @param pCps the fixed value of pattern parameter Cps, or null if not bound. + * @param pCost the fixed value of pattern parameter Cost, or null if not bound. + * @return the (partial) match object. + * + */ + public static CpsCost.Match newMatch(final CyberPhysicalSystem pCps, final Integer pCost) { + return new Immutable(pCps, pCost); + } + + private static final class Mutable extends CpsCost.Match { + Mutable(final CyberPhysicalSystem pCps, final Integer pCost) { + super(pCps, pCost); + } + + @Override + public boolean isMutable() { + return true; + } + } + + private static final class Immutable extends CpsCost.Match { + Immutable(final CyberPhysicalSystem pCps, final Integer pCost) { + super(pCps, pCost); + } + + @Override + public boolean isMutable() { + return false; + } + } + } + + /** + * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.cpsCost pattern, + * providing pattern-specific query methods. + * + *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, + * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. + * + *

Matches of the pattern will be represented as {@link Match}. + * + *

Original source: + *

+   * pattern cpsCost(Cps : CyberPhysicalSystem, Cost : java Integer) {
+   * 	AppCount == count find cpsApplications(Cps, _);
+   * 	HostCost == sum find hostInstanceCost(Cps, _, #_);
+   * 	Cost == eval(5  AppCount + HostCost);
+   * }
+   * 
+ * + * @see Match + * @see CpsCost + * + */ + public static class Matcher extends BaseMatcher { + /** + * Initializes the pattern matcher within an existing VIATRA Query engine. + * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. + * + * @param engine the existing VIATRA Query engine in which this matcher will be created. + * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation + * + */ + public static CpsCost.Matcher on(final ViatraQueryEngine engine) { + // check if matcher already exists + Matcher matcher = engine.getExistingMatcher(querySpecification()); + if (matcher == null) { + matcher = (Matcher)engine.getMatcher(querySpecification()); + } + return matcher; + } + + /** + * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation + * @return an initialized matcher + * @noreference This method is for internal matcher initialization by the framework, do not call it manually. + * + */ + public static CpsCost.Matcher create() { + return new Matcher(); + } + + private static final int POSITION_CPS = 0; + + private static final int POSITION_COST = 1; + + private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(CpsCost.Matcher.class); + + /** + * Initializes the pattern matcher within an existing VIATRA Query engine. + * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. + * + * @param engine the existing VIATRA Query engine in which this matcher will be created. + * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation + * + */ + private Matcher() { + super(querySpecification()); + } + + /** + * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. + * @param pCps the fixed value of pattern parameter Cps, or null if not bound. + * @param pCost the fixed value of pattern parameter Cost, or null if not bound. + * @return matches represented as a Match object. + * + */ + public Collection getAllMatches(final CyberPhysicalSystem pCps, final Integer pCost) { + return rawStreamAllMatches(new Object[]{pCps, pCost}).collect(Collectors.toSet()); + } + + /** + * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. + *

+ * NOTE: It is important not to modify the source model while the stream is being processed. + * If the match set of the pattern changes during processing, the contents of the stream is undefined. + * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. + * @param pCps the fixed value of pattern parameter Cps, or null if not bound. + * @param pCost the fixed value of pattern parameter Cost, or null if not bound. + * @return a stream of matches represented as a Match object. + * + */ + public Stream streamAllMatches(final CyberPhysicalSystem pCps, final Integer pCost) { + return rawStreamAllMatches(new Object[]{pCps, pCost}); + } + + /** + * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. + * Neither determinism nor randomness of selection is guaranteed. + * @param pCps the fixed value of pattern parameter Cps, or null if not bound. + * @param pCost the fixed value of pattern parameter Cost, or null if not bound. + * @return a match represented as a Match object, or null if no match is found. + * + */ + public Optional getOneArbitraryMatch(final CyberPhysicalSystem pCps, final Integer pCost) { + return rawGetOneArbitraryMatch(new Object[]{pCps, pCost}); + } + + /** + * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, + * under any possible substitution of the unspecified parameters (if any). + * @param pCps the fixed value of pattern parameter Cps, or null if not bound. + * @param pCost the fixed value of pattern parameter Cost, or null if not bound. + * @return true if the input is a valid (partial) match of the pattern. + * + */ + public boolean hasMatch(final CyberPhysicalSystem pCps, final Integer pCost) { + return rawHasMatch(new Object[]{pCps, pCost}); + } + + /** + * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. + * @param pCps the fixed value of pattern parameter Cps, or null if not bound. + * @param pCost the fixed value of pattern parameter Cost, or null if not bound. + * @return the number of pattern matches found. + * + */ + public int countMatches(final CyberPhysicalSystem pCps, final Integer pCost) { + return rawCountMatches(new Object[]{pCps, pCost}); + } + + /** + * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. + * Neither determinism nor randomness of selection is guaranteed. + * @param pCps the fixed value of pattern parameter Cps, or null if not bound. + * @param pCost the fixed value of pattern parameter Cost, or null if not bound. + * @param processor the action that will process the selected match. + * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked + * + */ + public boolean forOneArbitraryMatch(final CyberPhysicalSystem pCps, final Integer pCost, final Consumer processor) { + return rawForOneArbitraryMatch(new Object[]{pCps, pCost}, processor); + } + + /** + * Returns a new (partial) match. + * This can be used e.g. to call the matcher with a partial match. + *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. + * @param pCps the fixed value of pattern parameter Cps, or null if not bound. + * @param pCost the fixed value of pattern parameter Cost, or null if not bound. + * @return the (partial) match object. + * + */ + public CpsCost.Match newMatch(final CyberPhysicalSystem pCps, final Integer pCost) { + return CpsCost.Match.newMatch(pCps, pCost); + } + + /** + * Retrieve the set of values that occur in matches for Cps. + * @return the Set of all values or empty set if there are no matches + * + */ + protected Stream rawStreamAllValuesOfCps(final Object[] parameters) { + return rawStreamAllValues(POSITION_CPS, parameters).map(CyberPhysicalSystem.class::cast); + } + + /** + * Retrieve the set of values that occur in matches for Cps. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfCps() { + return rawStreamAllValuesOfCps(emptyArray()).collect(Collectors.toSet()); + } + + /** + * Retrieve the set of values that occur in matches for Cps. + * @return the Set of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfCps() { + return rawStreamAllValuesOfCps(emptyArray()); + } + + /** + * Retrieve the set of values that occur in matches for Cps. + *

+ * NOTE: It is important not to modify the source model while the stream is being processed. + * If the match set of the pattern changes during processing, the contents of the stream is undefined. + * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. + * + * @return the Stream of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfCps(final CpsCost.Match partialMatch) { + return rawStreamAllValuesOfCps(partialMatch.toArray()); + } + + /** + * Retrieve the set of values that occur in matches for Cps. + *

+ * NOTE: It is important not to modify the source model while the stream is being processed. + * If the match set of the pattern changes during processing, the contents of the stream is undefined. + * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. + * + * @return the Stream of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfCps(final Integer pCost) { + return rawStreamAllValuesOfCps(new Object[]{null, pCost}); + } + + /** + * Retrieve the set of values that occur in matches for Cps. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfCps(final CpsCost.Match partialMatch) { + return rawStreamAllValuesOfCps(partialMatch.toArray()).collect(Collectors.toSet()); + } + + /** + * Retrieve the set of values that occur in matches for Cps. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfCps(final Integer pCost) { + return rawStreamAllValuesOfCps(new Object[]{null, pCost}).collect(Collectors.toSet()); + } + + /** + * Retrieve the set of values that occur in matches for Cost. + * @return the Set of all values or empty set if there are no matches + * + */ + protected Stream rawStreamAllValuesOfCost(final Object[] parameters) { + return rawStreamAllValues(POSITION_COST, parameters).map(Integer.class::cast); + } + + /** + * Retrieve the set of values that occur in matches for Cost. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfCost() { + return rawStreamAllValuesOfCost(emptyArray()).collect(Collectors.toSet()); + } + + /** + * Retrieve the set of values that occur in matches for Cost. + * @return the Set of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfCost() { + return rawStreamAllValuesOfCost(emptyArray()); + } + + /** + * Retrieve the set of values that occur in matches for Cost. + *

+ * NOTE: It is important not to modify the source model while the stream is being processed. + * If the match set of the pattern changes during processing, the contents of the stream is undefined. + * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. + * + * @return the Stream of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfCost(final CpsCost.Match partialMatch) { + return rawStreamAllValuesOfCost(partialMatch.toArray()); + } + + /** + * Retrieve the set of values that occur in matches for Cost. + *

+ * NOTE: It is important not to modify the source model while the stream is being processed. + * If the match set of the pattern changes during processing, the contents of the stream is undefined. + * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. + * + * @return the Stream of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfCost(final CyberPhysicalSystem pCps) { + return rawStreamAllValuesOfCost(new Object[]{pCps, null}); + } + + /** + * Retrieve the set of values that occur in matches for Cost. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfCost(final CpsCost.Match partialMatch) { + return rawStreamAllValuesOfCost(partialMatch.toArray()).collect(Collectors.toSet()); + } + + /** + * Retrieve the set of values that occur in matches for Cost. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfCost(final CyberPhysicalSystem pCps) { + return rawStreamAllValuesOfCost(new Object[]{pCps, null}).collect(Collectors.toSet()); + } + + @Override + protected CpsCost.Match tupleToMatch(final Tuple t) { + try { + return CpsCost.Match.newMatch((CyberPhysicalSystem) t.get(POSITION_CPS), (Integer) t.get(POSITION_COST)); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in tuple not properly typed!",e); + return null; + } + } + + @Override + protected CpsCost.Match arrayToMatch(final Object[] match) { + try { + return CpsCost.Match.newMatch((CyberPhysicalSystem) match[POSITION_CPS], (Integer) match[POSITION_COST]); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in array not properly typed!",e); + return null; + } + } + + @Override + protected CpsCost.Match arrayToMatchMutable(final Object[] match) { + try { + return CpsCost.Match.newMutableMatch((CyberPhysicalSystem) match[POSITION_CPS], (Integer) match[POSITION_COST]); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in array not properly typed!",e); + return null; + } + } + + /** + * @return the singleton instance of the query specification of this pattern + * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded + * + */ + public static IQuerySpecification querySpecification() { + return CpsCost.instance(); + } + } + + private CpsCost() { + super(GeneratedPQuery.INSTANCE); + } + + /** + * @return the singleton instance of the query specification + * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded + * + */ + public static CpsCost instance() { + try{ + return LazyHolder.INSTANCE; + } catch (ExceptionInInitializerError err) { + throw processInitializerError(err); + } + } + + @Override + protected CpsCost.Matcher instantiate(final ViatraQueryEngine engine) { + return CpsCost.Matcher.on(engine); + } + + @Override + public CpsCost.Matcher instantiate() { + return CpsCost.Matcher.create(); + } + + @Override + public CpsCost.Match newEmptyMatch() { + return CpsCost.Match.newEmptyMatch(); + } + + @Override + public CpsCost.Match newMatch(final Object... parameters) { + return CpsCost.Match.newMatch((hu.bme.mit.inf.dslreasoner.domains.cps.CyberPhysicalSystem) parameters[0], (java.lang.Integer) parameters[1]); + } + + /** + * 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: ) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)} to be created + * not at the class load time of the outer class, + * 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: ) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}. + * + *

This workaround is required e.g. to support recursion. + * + */ + private static class LazyHolder { + private static final CpsCost INSTANCE = new CpsCost(); + + /** + * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. + * This initialization order is required to support indirect recursion. + * + *

The static initializer is defined using a helper field to work around limitations of the code generator. + * + */ + private static final Object STATIC_INITIALIZER = ensureInitialized(); + + public static Object ensureInitialized() { + INSTANCE.ensureInitializedInternal(); + return null; + } + } + + private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { + private static final CpsCost.GeneratedPQuery INSTANCE = new GeneratedPQuery(); + + 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); + + private final PParameter parameter_Cost = new PParameter("Cost", "java.lang.Integer", new JavaTransitiveInstancesKey(java.lang.Integer.class), PParameterDirection.INOUT); + + private final List parameters = Arrays.asList(parameter_Cps, parameter_Cost); + + private GeneratedPQuery() { + super(PVisibility.PUBLIC); + } + + @Override + public String getFullyQualifiedName() { + return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.cpsCost"; + } + + @Override + public List getParameterNames() { + return Arrays.asList("Cps","Cost"); + } + + @Override + public List getParameters() { + return parameters; + } + + @Override + public Set doGetContainedBodies() { + setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); + Set bodies = new LinkedHashSet<>(); + { + PBody body = new PBody(this); + PVariable var_Cps = body.getOrCreateVariableByName("Cps"); + PVariable var_Cost = body.getOrCreateVariableByName("Cost"); + PVariable var_AppCount = body.getOrCreateVariableByName("AppCount"); + PVariable var___0_ = body.getOrCreateVariableByName("_<0>"); + PVariable var_HostCost = body.getOrCreateVariableByName("HostCost"); + PVariable var___1_ = body.getOrCreateVariableByName("_<1>"); + PVariable var___2_ = body.getOrCreateVariableByName("_<2>"); + new TypeConstraint(body, Tuples.flatTupleOf(var_Cps), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "CyberPhysicalSystem"))); + new TypeFilterConstraint(body, Tuples.flatTupleOf(var_Cost), new JavaTransitiveInstancesKey(java.lang.Integer.class)); + body.setSymbolicParameters(Arrays.asList( + new ExportedParameter(body, var_Cps, parameter_Cps), + new ExportedParameter(body, var_Cost, parameter_Cost) + )); + // AppCount == count find cpsApplications(Cps, _) + PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); + new PatternMatchCounter(body, Tuples.flatTupleOf(var_Cps, var___0_), CpsApplications.instance().getInternalQueryRepresentation(), var__virtual_0_); + new Equality(body, var_AppCount, var__virtual_0_); + // HostCost == sum find hostInstanceCost(Cps, _, #_) + PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); + new AggregatorConstraint(new sum().getAggregatorLogic(Integer.class), body, Tuples.flatTupleOf(var_Cps, var___1_, var___2_), HostInstanceCost.instance().getInternalQueryRepresentation(), var__virtual_1_, 2); + new Equality(body, var_HostCost, var__virtual_1_); + // Cost == eval(5 * AppCount + HostCost) + PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}"); + new ExpressionEvaluation(body, new IExpressionEvaluator() { + + @Override + public String getShortDescription() { + return "Expression evaluation from pattern cpsCost"; + } + + @Override + public Iterable getInputParameterNames() { + return Arrays.asList("AppCount", "HostCost");} + + @Override + public Object evaluateExpression(IValueProvider provider) throws Exception { + Integer AppCount = (Integer) provider.getValue("AppCount"); + Integer HostCost = (Integer) provider.getValue("HostCost"); + return evaluateExpression_1_1(AppCount, HostCost); + } + }, var__virtual_2_ ); + new Equality(body, var_Cost, var__virtual_2_); + bodies.add(body); + } + return bodies; + } + } + + private static int evaluateExpression_1_1(final Integer AppCount, final Integer HostCost) { + return ((5 * (AppCount).intValue()) + (HostCost).intValue()); + } +} diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsHosts.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsHosts.java new file mode 100644 index 00000000..e1abf758 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsHosts.java @@ -0,0 +1,705 @@ +/** + * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql + */ +package hu.bme.mit.inf.dslreasoner.domains.cps.queries; + +import hu.bme.mit.inf.dslreasoner.domains.cps.CyberPhysicalSystem; +import hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance; +import java.util.Arrays; +import java.util.Collection; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.function.Consumer; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import org.apache.log4j.Logger; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.viatra.query.runtime.api.IPatternMatch; +import org.eclipse.viatra.query.runtime.api.IQuerySpecification; +import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; +import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; +import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; +import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; +import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; +import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; +import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; +import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; +import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; +import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; +import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; +import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; +import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; +import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; + +/** + * A pattern-specific query specification that can instantiate Matcher in a type-safe way. + * + *

Original source: + *

+ *         {@literal @}QueryBasedFeature(feature = "hosts")
+ *         pattern cpsHosts(Cps : CyberPhysicalSystem, HostInstance : HostInstance) {
+ *         	CyberPhysicalSystem.hostTypes.instances(Cps, HostInstance);
+ *         }
+ * 
+ * + * @see Matcher + * @see Match + * + */ +@SuppressWarnings("all") +public final class CpsHosts extends BaseGeneratedEMFQuerySpecification { + /** + * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.cpsHosts pattern, + * to be used in conjunction with {@link Matcher}. + * + *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. + * Each instance is a (possibly partial) substitution of pattern parameters, + * usable to represent a match of the pattern in the result of a query, + * or to specify the bound (fixed) input parameters when issuing a query. + * + * @see Matcher + * + */ + public static abstract class Match extends BasePatternMatch { + private CyberPhysicalSystem fCps; + + private HostInstance fHostInstance; + + private static List parameterNames = makeImmutableList("Cps", "HostInstance"); + + private Match(final CyberPhysicalSystem pCps, final HostInstance pHostInstance) { + this.fCps = pCps; + this.fHostInstance = pHostInstance; + } + + @Override + public Object get(final String parameterName) { + if ("Cps".equals(parameterName)) return this.fCps; + if ("HostInstance".equals(parameterName)) return this.fHostInstance; + return null; + } + + public CyberPhysicalSystem getCps() { + return this.fCps; + } + + public HostInstance getHostInstance() { + return this.fHostInstance; + } + + @Override + public boolean set(final String parameterName, final Object newValue) { + if (!isMutable()) throw new java.lang.UnsupportedOperationException(); + if ("Cps".equals(parameterName) ) { + this.fCps = (CyberPhysicalSystem) newValue; + return true; + } + if ("HostInstance".equals(parameterName) ) { + this.fHostInstance = (HostInstance) newValue; + return true; + } + return false; + } + + public void setCps(final CyberPhysicalSystem pCps) { + if (!isMutable()) throw new java.lang.UnsupportedOperationException(); + this.fCps = pCps; + } + + public void setHostInstance(final HostInstance pHostInstance) { + if (!isMutable()) throw new java.lang.UnsupportedOperationException(); + this.fHostInstance = pHostInstance; + } + + @Override + public String patternName() { + return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.cpsHosts"; + } + + @Override + public List parameterNames() { + return CpsHosts.Match.parameterNames; + } + + @Override + public Object[] toArray() { + return new Object[]{fCps, fHostInstance}; + } + + @Override + public CpsHosts.Match toImmutable() { + return isMutable() ? newMatch(fCps, fHostInstance) : this; + } + + @Override + public String prettyPrint() { + StringBuilder result = new StringBuilder(); + result.append("\"Cps\"=" + prettyPrintValue(fCps) + ", "); + result.append("\"HostInstance\"=" + prettyPrintValue(fHostInstance)); + return result.toString(); + } + + @Override + public int hashCode() { + return Objects.hash(fCps, fHostInstance); + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) + return true; + if (obj == null) { + return false; + } + if ((obj instanceof CpsHosts.Match)) { + CpsHosts.Match other = (CpsHosts.Match) obj; + return Objects.equals(fCps, other.fCps) && Objects.equals(fHostInstance, other.fHostInstance); + } else { + // this should be infrequent + if (!(obj instanceof IPatternMatch)) { + return false; + } + IPatternMatch otherSig = (IPatternMatch) obj; + return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); + } + } + + @Override + public CpsHosts specification() { + return CpsHosts.instance(); + } + + /** + * Returns an empty, mutable match. + * Fields of the mutable match can be filled to create a partial match, usable as matcher input. + * + * @return the empty match. + * + */ + public static CpsHosts.Match newEmptyMatch() { + return new Mutable(null, null); + } + + /** + * Returns a mutable (partial) match. + * Fields of the mutable match can be filled to create a partial match, usable as matcher input. + * + * @param pCps the fixed value of pattern parameter Cps, or null if not bound. + * @param pHostInstance the fixed value of pattern parameter HostInstance, or null if not bound. + * @return the new, mutable (partial) match object. + * + */ + public static CpsHosts.Match newMutableMatch(final CyberPhysicalSystem pCps, final HostInstance pHostInstance) { + return new Mutable(pCps, pHostInstance); + } + + /** + * Returns a new (partial) match. + * This can be used e.g. to call the matcher with a partial match. + *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. + * @param pCps the fixed value of pattern parameter Cps, or null if not bound. + * @param pHostInstance the fixed value of pattern parameter HostInstance, or null if not bound. + * @return the (partial) match object. + * + */ + public static CpsHosts.Match newMatch(final CyberPhysicalSystem pCps, final HostInstance pHostInstance) { + return new Immutable(pCps, pHostInstance); + } + + private static final class Mutable extends CpsHosts.Match { + Mutable(final CyberPhysicalSystem pCps, final HostInstance pHostInstance) { + super(pCps, pHostInstance); + } + + @Override + public boolean isMutable() { + return true; + } + } + + private static final class Immutable extends CpsHosts.Match { + Immutable(final CyberPhysicalSystem pCps, final HostInstance pHostInstance) { + super(pCps, pHostInstance); + } + + @Override + public boolean isMutable() { + return false; + } + } + } + + /** + * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.cpsHosts pattern, + * providing pattern-specific query methods. + * + *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, + * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. + * + *

Matches of the pattern will be represented as {@link Match}. + * + *

Original source: + *

+   * {@literal @}QueryBasedFeature(feature = "hosts")
+   * pattern cpsHosts(Cps : CyberPhysicalSystem, HostInstance : HostInstance) {
+   * 	CyberPhysicalSystem.hostTypes.instances(Cps, HostInstance);
+   * }
+   * 
+ * + * @see Match + * @see CpsHosts + * + */ + public static class Matcher extends BaseMatcher { + /** + * Initializes the pattern matcher within an existing VIATRA Query engine. + * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. + * + * @param engine the existing VIATRA Query engine in which this matcher will be created. + * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation + * + */ + public static CpsHosts.Matcher on(final ViatraQueryEngine engine) { + // check if matcher already exists + Matcher matcher = engine.getExistingMatcher(querySpecification()); + if (matcher == null) { + matcher = (Matcher)engine.getMatcher(querySpecification()); + } + return matcher; + } + + /** + * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation + * @return an initialized matcher + * @noreference This method is for internal matcher initialization by the framework, do not call it manually. + * + */ + public static CpsHosts.Matcher create() { + return new Matcher(); + } + + private static final int POSITION_CPS = 0; + + private static final int POSITION_HOSTINSTANCE = 1; + + private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(CpsHosts.Matcher.class); + + /** + * Initializes the pattern matcher within an existing VIATRA Query engine. + * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. + * + * @param engine the existing VIATRA Query engine in which this matcher will be created. + * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation + * + */ + private Matcher() { + super(querySpecification()); + } + + /** + * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. + * @param pCps the fixed value of pattern parameter Cps, or null if not bound. + * @param pHostInstance the fixed value of pattern parameter HostInstance, or null if not bound. + * @return matches represented as a Match object. + * + */ + public Collection getAllMatches(final CyberPhysicalSystem pCps, final HostInstance pHostInstance) { + return rawStreamAllMatches(new Object[]{pCps, pHostInstance}).collect(Collectors.toSet()); + } + + /** + * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. + *

+ * NOTE: It is important not to modify the source model while the stream is being processed. + * If the match set of the pattern changes during processing, the contents of the stream is undefined. + * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. + * @param pCps the fixed value of pattern parameter Cps, or null if not bound. + * @param pHostInstance the fixed value of pattern parameter HostInstance, or null if not bound. + * @return a stream of matches represented as a Match object. + * + */ + public Stream streamAllMatches(final CyberPhysicalSystem pCps, final HostInstance pHostInstance) { + return rawStreamAllMatches(new Object[]{pCps, pHostInstance}); + } + + /** + * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. + * Neither determinism nor randomness of selection is guaranteed. + * @param pCps the fixed value of pattern parameter Cps, or null if not bound. + * @param pHostInstance the fixed value of pattern parameter HostInstance, or null if not bound. + * @return a match represented as a Match object, or null if no match is found. + * + */ + public Optional getOneArbitraryMatch(final CyberPhysicalSystem pCps, final HostInstance pHostInstance) { + return rawGetOneArbitraryMatch(new Object[]{pCps, pHostInstance}); + } + + /** + * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, + * under any possible substitution of the unspecified parameters (if any). + * @param pCps the fixed value of pattern parameter Cps, or null if not bound. + * @param pHostInstance the fixed value of pattern parameter HostInstance, or null if not bound. + * @return true if the input is a valid (partial) match of the pattern. + * + */ + public boolean hasMatch(final CyberPhysicalSystem pCps, final HostInstance pHostInstance) { + return rawHasMatch(new Object[]{pCps, pHostInstance}); + } + + /** + * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. + * @param pCps the fixed value of pattern parameter Cps, or null if not bound. + * @param pHostInstance the fixed value of pattern parameter HostInstance, or null if not bound. + * @return the number of pattern matches found. + * + */ + public int countMatches(final CyberPhysicalSystem pCps, final HostInstance pHostInstance) { + return rawCountMatches(new Object[]{pCps, pHostInstance}); + } + + /** + * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. + * Neither determinism nor randomness of selection is guaranteed. + * @param pCps the fixed value of pattern parameter Cps, or null if not bound. + * @param pHostInstance the fixed value of pattern parameter HostInstance, or null if not bound. + * @param processor the action that will process the selected match. + * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked + * + */ + public boolean forOneArbitraryMatch(final CyberPhysicalSystem pCps, final HostInstance pHostInstance, final Consumer processor) { + return rawForOneArbitraryMatch(new Object[]{pCps, pHostInstance}, processor); + } + + /** + * Returns a new (partial) match. + * This can be used e.g. to call the matcher with a partial match. + *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. + * @param pCps the fixed value of pattern parameter Cps, or null if not bound. + * @param pHostInstance the fixed value of pattern parameter HostInstance, or null if not bound. + * @return the (partial) match object. + * + */ + public CpsHosts.Match newMatch(final CyberPhysicalSystem pCps, final HostInstance pHostInstance) { + return CpsHosts.Match.newMatch(pCps, pHostInstance); + } + + /** + * Retrieve the set of values that occur in matches for Cps. + * @return the Set of all values or empty set if there are no matches + * + */ + protected Stream rawStreamAllValuesOfCps(final Object[] parameters) { + return rawStreamAllValues(POSITION_CPS, parameters).map(CyberPhysicalSystem.class::cast); + } + + /** + * Retrieve the set of values that occur in matches for Cps. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfCps() { + return rawStreamAllValuesOfCps(emptyArray()).collect(Collectors.toSet()); + } + + /** + * Retrieve the set of values that occur in matches for Cps. + * @return the Set of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfCps() { + return rawStreamAllValuesOfCps(emptyArray()); + } + + /** + * Retrieve the set of values that occur in matches for Cps. + *

+ * NOTE: It is important not to modify the source model while the stream is being processed. + * If the match set of the pattern changes during processing, the contents of the stream is undefined. + * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. + * + * @return the Stream of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfCps(final CpsHosts.Match partialMatch) { + return rawStreamAllValuesOfCps(partialMatch.toArray()); + } + + /** + * Retrieve the set of values that occur in matches for Cps. + *

+ * NOTE: It is important not to modify the source model while the stream is being processed. + * If the match set of the pattern changes during processing, the contents of the stream is undefined. + * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. + * + * @return the Stream of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfCps(final HostInstance pHostInstance) { + return rawStreamAllValuesOfCps(new Object[]{null, pHostInstance}); + } + + /** + * Retrieve the set of values that occur in matches for Cps. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfCps(final CpsHosts.Match partialMatch) { + return rawStreamAllValuesOfCps(partialMatch.toArray()).collect(Collectors.toSet()); + } + + /** + * Retrieve the set of values that occur in matches for Cps. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfCps(final HostInstance pHostInstance) { + return rawStreamAllValuesOfCps(new Object[]{null, pHostInstance}).collect(Collectors.toSet()); + } + + /** + * Retrieve the set of values that occur in matches for HostInstance. + * @return the Set of all values or empty set if there are no matches + * + */ + protected Stream rawStreamAllValuesOfHostInstance(final Object[] parameters) { + return rawStreamAllValues(POSITION_HOSTINSTANCE, parameters).map(HostInstance.class::cast); + } + + /** + * Retrieve the set of values that occur in matches for HostInstance. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfHostInstance() { + return rawStreamAllValuesOfHostInstance(emptyArray()).collect(Collectors.toSet()); + } + + /** + * Retrieve the set of values that occur in matches for HostInstance. + * @return the Set of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfHostInstance() { + return rawStreamAllValuesOfHostInstance(emptyArray()); + } + + /** + * Retrieve the set of values that occur in matches for HostInstance. + *

+ * NOTE: It is important not to modify the source model while the stream is being processed. + * If the match set of the pattern changes during processing, the contents of the stream is undefined. + * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. + * + * @return the Stream of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfHostInstance(final CpsHosts.Match partialMatch) { + return rawStreamAllValuesOfHostInstance(partialMatch.toArray()); + } + + /** + * Retrieve the set of values that occur in matches for HostInstance. + *

+ * NOTE: It is important not to modify the source model while the stream is being processed. + * If the match set of the pattern changes during processing, the contents of the stream is undefined. + * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. + * + * @return the Stream of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfHostInstance(final CyberPhysicalSystem pCps) { + return rawStreamAllValuesOfHostInstance(new Object[]{pCps, null}); + } + + /** + * Retrieve the set of values that occur in matches for HostInstance. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfHostInstance(final CpsHosts.Match partialMatch) { + return rawStreamAllValuesOfHostInstance(partialMatch.toArray()).collect(Collectors.toSet()); + } + + /** + * Retrieve the set of values that occur in matches for HostInstance. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfHostInstance(final CyberPhysicalSystem pCps) { + return rawStreamAllValuesOfHostInstance(new Object[]{pCps, null}).collect(Collectors.toSet()); + } + + @Override + protected CpsHosts.Match tupleToMatch(final Tuple t) { + try { + return CpsHosts.Match.newMatch((CyberPhysicalSystem) t.get(POSITION_CPS), (HostInstance) t.get(POSITION_HOSTINSTANCE)); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in tuple not properly typed!",e); + return null; + } + } + + @Override + protected CpsHosts.Match arrayToMatch(final Object[] match) { + try { + return CpsHosts.Match.newMatch((CyberPhysicalSystem) match[POSITION_CPS], (HostInstance) match[POSITION_HOSTINSTANCE]); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in array not properly typed!",e); + return null; + } + } + + @Override + protected CpsHosts.Match arrayToMatchMutable(final Object[] match) { + try { + return CpsHosts.Match.newMutableMatch((CyberPhysicalSystem) match[POSITION_CPS], (HostInstance) match[POSITION_HOSTINSTANCE]); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in array not properly typed!",e); + return null; + } + } + + /** + * @return the singleton instance of the query specification of this pattern + * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded + * + */ + public static IQuerySpecification querySpecification() { + return CpsHosts.instance(); + } + } + + private CpsHosts() { + super(GeneratedPQuery.INSTANCE); + } + + /** + * @return the singleton instance of the query specification + * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded + * + */ + public static CpsHosts instance() { + try{ + return LazyHolder.INSTANCE; + } catch (ExceptionInInitializerError err) { + throw processInitializerError(err); + } + } + + @Override + protected CpsHosts.Matcher instantiate(final ViatraQueryEngine engine) { + return CpsHosts.Matcher.on(engine); + } + + @Override + public CpsHosts.Matcher instantiate() { + return CpsHosts.Matcher.create(); + } + + @Override + public CpsHosts.Match newEmptyMatch() { + return CpsHosts.Match.newEmptyMatch(); + } + + @Override + public CpsHosts.Match newMatch(final Object... parameters) { + return CpsHosts.Match.newMatch((hu.bme.mit.inf.dslreasoner.domains.cps.CyberPhysicalSystem) parameters[0], (hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance) parameters[1]); + } + + /** + * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.CpsHosts (visibility: PUBLIC, simpleName: CpsHosts, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.CpsHosts, deprecated: ) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)} to be created + * not at the class load time of the outer class, + * but rather at the first call to {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.CpsHosts (visibility: PUBLIC, simpleName: CpsHosts, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.CpsHosts, deprecated: ) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}. + * + *

This workaround is required e.g. to support recursion. + * + */ + private static class LazyHolder { + private static final CpsHosts INSTANCE = new CpsHosts(); + + /** + * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. + * This initialization order is required to support indirect recursion. + * + *

The static initializer is defined using a helper field to work around limitations of the code generator. + * + */ + private static final Object STATIC_INITIALIZER = ensureInitialized(); + + public static Object ensureInitialized() { + INSTANCE.ensureInitializedInternal(); + return null; + } + } + + private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { + private static final CpsHosts.GeneratedPQuery INSTANCE = new GeneratedPQuery(); + + 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); + + 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); + + private final List parameters = Arrays.asList(parameter_Cps, parameter_HostInstance); + + private GeneratedPQuery() { + super(PVisibility.PUBLIC); + } + + @Override + public String getFullyQualifiedName() { + return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.cpsHosts"; + } + + @Override + public List getParameterNames() { + return Arrays.asList("Cps","HostInstance"); + } + + @Override + public List getParameters() { + return parameters; + } + + @Override + public Set doGetContainedBodies() { + setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); + Set bodies = new LinkedHashSet<>(); + { + PBody body = new PBody(this); + PVariable var_Cps = body.getOrCreateVariableByName("Cps"); + PVariable var_HostInstance = body.getOrCreateVariableByName("HostInstance"); + new TypeConstraint(body, Tuples.flatTupleOf(var_Cps), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "CyberPhysicalSystem"))); + new TypeConstraint(body, Tuples.flatTupleOf(var_HostInstance), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); + body.setSymbolicParameters(Arrays.asList( + new ExportedParameter(body, var_Cps, parameter_Cps), + new ExportedParameter(body, var_HostInstance, parameter_HostInstance) + )); + // CyberPhysicalSystem.hostTypes.instances(Cps, HostInstance) + new TypeConstraint(body, Tuples.flatTupleOf(var_Cps), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "CyberPhysicalSystem"))); + PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); + new TypeConstraint(body, Tuples.flatTupleOf(var_Cps, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "CyberPhysicalSystem", "hostTypes"))); + new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostType"))); + PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); + new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "HostType", "instances"))); + new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); + new Equality(body, var__virtual_1_, var_HostInstance); + bodies.add(body); + } + { + PAnnotation annotation = new PAnnotation("QueryBasedFeature"); + annotation.addAttribute("feature", "hosts"); + addAnnotation(annotation); + } + return bodies; + } + } +} 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..4442718b --- /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,207 @@ +/** + * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql + */ +package hu.bme.mit.inf.dslreasoner.domains.cps.queries; + +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.AllocationWithoutResourceRequirement; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.AvailableHdd; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.AvailableMemory; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.AverageFreeHddMetric; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.AverageFreeMemoryMetric; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.CostMetric; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.CpsApplications; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.CpsCost; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.CpsHosts; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.InstanceDoesNotSatisfyRequirement; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.NotEnoughAvailableHdd; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.NotEnoughAvailableMemory; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.RequirementNotSatisfied; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.TotalHdd; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.TotalMemory; +import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; +import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedPatternGroup; + +/** + * A pattern group formed of all public patterns defined in CpsQueries.vql. + * + *

Use the static instance as any {@link interface org.eclipse.viatra.query.runtime.api.IQueryGroup}, to conveniently prepare + * a VIATRA Query engine for matching all patterns originally defined in file CpsQueries.vql, + * in order to achieve better performance than one-by-one on-demand matcher initialization. + * + *

From package hu.bme.mit.inf.dslreasoner.domains.cps.queries, the group contains the definition of the following patterns:

    + *
  • cpsApplications
  • + *
  • cpsHosts
  • + *
  • totalMemory
  • + *
  • totalHdd
  • + *
  • availableMemory
  • + *
  • availableHdd
  • + *
  • allocationWithoutResourceRequirement
  • + *
  • notEnoughAvailableMemory
  • + *
  • notEnoughAvailableHdd
  • + *
  • instanceDoesNotSatisfyRequirement
  • + *
  • requirementNotSatisfied
  • + *
  • averageFreeMemoryMetric
  • + *
  • averageFreeHddMetric
  • + *
  • costMetric
  • + *
  • cpsCost
  • + *
+ * + * @see IQueryGroup + * + */ +@SuppressWarnings("all") +public final class CpsQueries extends BaseGeneratedPatternGroup { + /** + * Access the pattern group. + * + * @return the singleton instance of the group + * @throws ViatraQueryRuntimeException if there was an error loading the generated code of pattern specifications + * + */ + public static CpsQueries instance() { + if (INSTANCE == null) { + INSTANCE = new CpsQueries(); + } + return INSTANCE; + } + + private static CpsQueries INSTANCE; + + private CpsQueries() { + querySpecifications.add(CpsApplications.instance()); + querySpecifications.add(CpsHosts.instance()); + querySpecifications.add(TotalMemory.instance()); + querySpecifications.add(TotalHdd.instance()); + querySpecifications.add(AvailableMemory.instance()); + querySpecifications.add(AvailableHdd.instance()); + querySpecifications.add(AllocationWithoutResourceRequirement.instance()); + querySpecifications.add(NotEnoughAvailableMemory.instance()); + querySpecifications.add(NotEnoughAvailableHdd.instance()); + querySpecifications.add(InstanceDoesNotSatisfyRequirement.instance()); + querySpecifications.add(RequirementNotSatisfied.instance()); + querySpecifications.add(AverageFreeMemoryMetric.instance()); + querySpecifications.add(AverageFreeHddMetric.instance()); + querySpecifications.add(CostMetric.instance()); + querySpecifications.add(CpsCost.instance()); + } + + public CpsApplications getCpsApplications() { + return CpsApplications.instance(); + } + + public CpsApplications.Matcher getCpsApplications(final ViatraQueryEngine engine) { + return CpsApplications.Matcher.on(engine); + } + + public CpsHosts getCpsHosts() { + return CpsHosts.instance(); + } + + public CpsHosts.Matcher getCpsHosts(final ViatraQueryEngine engine) { + return CpsHosts.Matcher.on(engine); + } + + public TotalMemory getTotalMemory() { + return TotalMemory.instance(); + } + + public TotalMemory.Matcher getTotalMemory(final ViatraQueryEngine engine) { + return TotalMemory.Matcher.on(engine); + } + + public TotalHdd getTotalHdd() { + return TotalHdd.instance(); + } + + public TotalHdd.Matcher getTotalHdd(final ViatraQueryEngine engine) { + return TotalHdd.Matcher.on(engine); + } + + public AvailableMemory getAvailableMemory() { + return AvailableMemory.instance(); + } + + public AvailableMemory.Matcher getAvailableMemory(final ViatraQueryEngine engine) { + return AvailableMemory.Matcher.on(engine); + } + + public AvailableHdd getAvailableHdd() { + return AvailableHdd.instance(); + } + + public AvailableHdd.Matcher getAvailableHdd(final ViatraQueryEngine engine) { + return AvailableHdd.Matcher.on(engine); + } + + public AllocationWithoutResourceRequirement getAllocationWithoutResourceRequirement() { + return AllocationWithoutResourceRequirement.instance(); + } + + public AllocationWithoutResourceRequirement.Matcher getAllocationWithoutResourceRequirement(final ViatraQueryEngine engine) { + return AllocationWithoutResourceRequirement.Matcher.on(engine); + } + + public NotEnoughAvailableMemory getNotEnoughAvailableMemory() { + return NotEnoughAvailableMemory.instance(); + } + + public NotEnoughAvailableMemory.Matcher getNotEnoughAvailableMemory(final ViatraQueryEngine engine) { + return NotEnoughAvailableMemory.Matcher.on(engine); + } + + public NotEnoughAvailableHdd getNotEnoughAvailableHdd() { + return NotEnoughAvailableHdd.instance(); + } + + public NotEnoughAvailableHdd.Matcher getNotEnoughAvailableHdd(final ViatraQueryEngine engine) { + return NotEnoughAvailableHdd.Matcher.on(engine); + } + + public InstanceDoesNotSatisfyRequirement getInstanceDoesNotSatisfyRequirement() { + return InstanceDoesNotSatisfyRequirement.instance(); + } + + public InstanceDoesNotSatisfyRequirement.Matcher getInstanceDoesNotSatisfyRequirement(final ViatraQueryEngine engine) { + return InstanceDoesNotSatisfyRequirement.Matcher.on(engine); + } + + public RequirementNotSatisfied getRequirementNotSatisfied() { + return RequirementNotSatisfied.instance(); + } + + public RequirementNotSatisfied.Matcher getRequirementNotSatisfied(final ViatraQueryEngine engine) { + return RequirementNotSatisfied.Matcher.on(engine); + } + + public AverageFreeMemoryMetric getAverageFreeMemoryMetric() { + return AverageFreeMemoryMetric.instance(); + } + + public AverageFreeMemoryMetric.Matcher getAverageFreeMemoryMetric(final ViatraQueryEngine engine) { + return AverageFreeMemoryMetric.Matcher.on(engine); + } + + public AverageFreeHddMetric getAverageFreeHddMetric() { + return AverageFreeHddMetric.instance(); + } + + public AverageFreeHddMetric.Matcher getAverageFreeHddMetric(final ViatraQueryEngine engine) { + return AverageFreeHddMetric.Matcher.on(engine); + } + + public CostMetric getCostMetric() { + return CostMetric.instance(); + } + + public CostMetric.Matcher getCostMetric(final ViatraQueryEngine engine) { + return CostMetric.Matcher.on(engine); + } + + public CpsCost getCpsCost() { + return CpsCost.instance(); + } + + public CpsCost.Matcher getCpsCost(final ViatraQueryEngine engine) { + return CpsCost.Matcher.on(engine); + } +} 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 @@ +/** + * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql + */ +package hu.bme.mit.inf.dslreasoner.domains.cps.queries; + +import hu.bme.mit.inf.dslreasoner.domains.cps.ApplicationInstance; +import hu.bme.mit.inf.dslreasoner.domains.cps.Requirement; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.SatisfyingInstance; +import java.util.Arrays; +import java.util.Collection; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.function.Consumer; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import org.apache.log4j.Logger; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.viatra.query.runtime.api.IPatternMatch; +import org.eclipse.viatra.query.runtime.api.IQuerySpecification; +import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; +import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; +import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; +import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; +import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; +import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; +import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; +import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; +import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; +import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; +import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation; +import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.NegativePatternCall; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; +import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; +import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; +import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; + +/** + * A pattern-specific query specification that can instantiate Matcher in a type-safe way. + * + *

Original source: + *

+ *         {@literal @}Constraint(severity = "error", key = {Req, App},
+ *         	message = "Requirement must be satisfied by the required application type.")
+ *         pattern instanceDoesNotSatisfyRequirement(Req : Requirement, App : ApplicationInstance) {
+ *         	Requirement.instances(Req, App);
+ *         	neg find satisfyingInstance(Req, App);
+ *         }
+ * 
+ * + * @see Matcher + * @see Match + * + */ +@SuppressWarnings("all") +public final class InstanceDoesNotSatisfyRequirement extends BaseGeneratedEMFQuerySpecification { + /** + * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.instanceDoesNotSatisfyRequirement pattern, + * to be used in conjunction with {@link Matcher}. + * + *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. + * Each instance is a (possibly partial) substitution of pattern parameters, + * usable to represent a match of the pattern in the result of a query, + * or to specify the bound (fixed) input parameters when issuing a query. + * + * @see Matcher + * + */ + public static abstract class Match extends BasePatternMatch { + private Requirement fReq; + + private ApplicationInstance fApp; + + private static List parameterNames = makeImmutableList("Req", "App"); + + private Match(final Requirement pReq, final ApplicationInstance pApp) { + this.fReq = pReq; + this.fApp = pApp; + } + + @Override + public Object get(final String parameterName) { + if ("Req".equals(parameterName)) return this.fReq; + if ("App".equals(parameterName)) return this.fApp; + return null; + } + + public Requirement getReq() { + return this.fReq; + } + + public ApplicationInstance getApp() { + return this.fApp; + } + + @Override + public boolean set(final String parameterName, final Object newValue) { + if (!isMutable()) throw new java.lang.UnsupportedOperationException(); + if ("Req".equals(parameterName) ) { + this.fReq = (Requirement) newValue; + return true; + } + if ("App".equals(parameterName) ) { + this.fApp = (ApplicationInstance) newValue; + return true; + } + return false; + } + + public void setReq(final Requirement pReq) { + if (!isMutable()) throw new java.lang.UnsupportedOperationException(); + this.fReq = pReq; + } + + public void setApp(final ApplicationInstance pApp) { + if (!isMutable()) throw new java.lang.UnsupportedOperationException(); + this.fApp = pApp; + } + + @Override + public String patternName() { + return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.instanceDoesNotSatisfyRequirement"; + } + + @Override + public List parameterNames() { + return InstanceDoesNotSatisfyRequirement.Match.parameterNames; + } + + @Override + public Object[] toArray() { + return new Object[]{fReq, fApp}; + } + + @Override + public InstanceDoesNotSatisfyRequirement.Match toImmutable() { + return isMutable() ? newMatch(fReq, fApp) : this; + } + + @Override + public String prettyPrint() { + StringBuilder result = new StringBuilder(); + result.append("\"Req\"=" + prettyPrintValue(fReq) + ", "); + result.append("\"App\"=" + prettyPrintValue(fApp)); + return result.toString(); + } + + @Override + public int hashCode() { + return Objects.hash(fReq, fApp); + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) + return true; + if (obj == null) { + return false; + } + if ((obj instanceof InstanceDoesNotSatisfyRequirement.Match)) { + InstanceDoesNotSatisfyRequirement.Match other = (InstanceDoesNotSatisfyRequirement.Match) obj; + return Objects.equals(fReq, other.fReq) && Objects.equals(fApp, other.fApp); + } else { + // this should be infrequent + if (!(obj instanceof IPatternMatch)) { + return false; + } + IPatternMatch otherSig = (IPatternMatch) obj; + return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); + } + } + + @Override + public InstanceDoesNotSatisfyRequirement specification() { + return InstanceDoesNotSatisfyRequirement.instance(); + } + + /** + * Returns an empty, mutable match. + * Fields of the mutable match can be filled to create a partial match, usable as matcher input. + * + * @return the empty match. + * + */ + public static InstanceDoesNotSatisfyRequirement.Match newEmptyMatch() { + return new Mutable(null, null); + } + + /** + * Returns a mutable (partial) match. + * Fields of the mutable match can be filled to create a partial match, usable as matcher input. + * + * @param pReq the fixed value of pattern parameter Req, or null if not bound. + * @param pApp the fixed value of pattern parameter App, or null if not bound. + * @return the new, mutable (partial) match object. + * + */ + public static InstanceDoesNotSatisfyRequirement.Match newMutableMatch(final Requirement pReq, final ApplicationInstance pApp) { + return new Mutable(pReq, pApp); + } + + /** + * Returns a new (partial) match. + * This can be used e.g. to call the matcher with a partial match. + *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. + * @param pReq the fixed value of pattern parameter Req, or null if not bound. + * @param pApp the fixed value of pattern parameter App, or null if not bound. + * @return the (partial) match object. + * + */ + public static InstanceDoesNotSatisfyRequirement.Match newMatch(final Requirement pReq, final ApplicationInstance pApp) { + return new Immutable(pReq, pApp); + } + + private static final class Mutable extends InstanceDoesNotSatisfyRequirement.Match { + Mutable(final Requirement pReq, final ApplicationInstance pApp) { + super(pReq, pApp); + } + + @Override + public boolean isMutable() { + return true; + } + } + + private static final class Immutable extends InstanceDoesNotSatisfyRequirement.Match { + Immutable(final Requirement pReq, final ApplicationInstance pApp) { + super(pReq, pApp); + } + + @Override + public boolean isMutable() { + return false; + } + } + } + + /** + * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.instanceDoesNotSatisfyRequirement pattern, + * providing pattern-specific query methods. + * + *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, + * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. + * + *

Matches of the pattern will be represented as {@link Match}. + * + *

Original source: + *

+   * {@literal @}Constraint(severity = "error", key = {Req, App},
+   * 	message = "Requirement must be satisfied by the required application type.")
+   * pattern instanceDoesNotSatisfyRequirement(Req : Requirement, App : ApplicationInstance) {
+   * 	Requirement.instances(Req, App);
+   * 	neg find satisfyingInstance(Req, App);
+   * }
+   * 
+ * + * @see Match + * @see InstanceDoesNotSatisfyRequirement + * + */ + public static class Matcher extends BaseMatcher { + /** + * Initializes the pattern matcher within an existing VIATRA Query engine. + * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. + * + * @param engine the existing VIATRA Query engine in which this matcher will be created. + * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation + * + */ + public static InstanceDoesNotSatisfyRequirement.Matcher on(final ViatraQueryEngine engine) { + // check if matcher already exists + Matcher matcher = engine.getExistingMatcher(querySpecification()); + if (matcher == null) { + matcher = (Matcher)engine.getMatcher(querySpecification()); + } + return matcher; + } + + /** + * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation + * @return an initialized matcher + * @noreference This method is for internal matcher initialization by the framework, do not call it manually. + * + */ + public static InstanceDoesNotSatisfyRequirement.Matcher create() { + return new Matcher(); + } + + private static final int POSITION_REQ = 0; + + private static final int POSITION_APP = 1; + + private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(InstanceDoesNotSatisfyRequirement.Matcher.class); + + /** + * Initializes the pattern matcher within an existing VIATRA Query engine. + * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. + * + * @param engine the existing VIATRA Query engine in which this matcher will be created. + * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation + * + */ + private Matcher() { + super(querySpecification()); + } + + /** + * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. + * @param pReq the fixed value of pattern parameter Req, or null if not bound. + * @param pApp the fixed value of pattern parameter App, or null if not bound. + * @return matches represented as a Match object. + * + */ + public Collection getAllMatches(final Requirement pReq, final ApplicationInstance pApp) { + return rawStreamAllMatches(new Object[]{pReq, pApp}).collect(Collectors.toSet()); + } + + /** + * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. + *

+ * NOTE: It is important not to modify the source model while the stream is being processed. + * If the match set of the pattern changes during processing, the contents of the stream is undefined. + * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. + * @param pReq the fixed value of pattern parameter Req, or null if not bound. + * @param pApp the fixed value of pattern parameter App, or null if not bound. + * @return a stream of matches represented as a Match object. + * + */ + public Stream streamAllMatches(final Requirement pReq, final ApplicationInstance pApp) { + return rawStreamAllMatches(new Object[]{pReq, pApp}); + } + + /** + * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. + * Neither determinism nor randomness of selection is guaranteed. + * @param pReq the fixed value of pattern parameter Req, or null if not bound. + * @param pApp the fixed value of pattern parameter App, or null if not bound. + * @return a match represented as a Match object, or null if no match is found. + * + */ + public Optional getOneArbitraryMatch(final Requirement pReq, final ApplicationInstance pApp) { + return rawGetOneArbitraryMatch(new Object[]{pReq, pApp}); + } + + /** + * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, + * under any possible substitution of the unspecified parameters (if any). + * @param pReq the fixed value of pattern parameter Req, or null if not bound. + * @param pApp the fixed value of pattern parameter App, or null if not bound. + * @return true if the input is a valid (partial) match of the pattern. + * + */ + public boolean hasMatch(final Requirement pReq, final ApplicationInstance pApp) { + return rawHasMatch(new Object[]{pReq, pApp}); + } + + /** + * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. + * @param pReq the fixed value of pattern parameter Req, or null if not bound. + * @param pApp the fixed value of pattern parameter App, or null if not bound. + * @return the number of pattern matches found. + * + */ + public int countMatches(final Requirement pReq, final ApplicationInstance pApp) { + return rawCountMatches(new Object[]{pReq, pApp}); + } + + /** + * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. + * Neither determinism nor randomness of selection is guaranteed. + * @param pReq the fixed value of pattern parameter Req, or null if not bound. + * @param pApp the fixed value of pattern parameter App, or null if not bound. + * @param processor the action that will process the selected match. + * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked + * + */ + public boolean forOneArbitraryMatch(final Requirement pReq, final ApplicationInstance pApp, final Consumer processor) { + return rawForOneArbitraryMatch(new Object[]{pReq, pApp}, processor); + } + + /** + * Returns a new (partial) match. + * This can be used e.g. to call the matcher with a partial match. + *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. + * @param pReq the fixed value of pattern parameter Req, or null if not bound. + * @param pApp the fixed value of pattern parameter App, or null if not bound. + * @return the (partial) match object. + * + */ + public InstanceDoesNotSatisfyRequirement.Match newMatch(final Requirement pReq, final ApplicationInstance pApp) { + return InstanceDoesNotSatisfyRequirement.Match.newMatch(pReq, pApp); + } + + /** + * Retrieve the set of values that occur in matches for Req. + * @return the Set of all values or empty set if there are no matches + * + */ + protected Stream rawStreamAllValuesOfReq(final Object[] parameters) { + return rawStreamAllValues(POSITION_REQ, parameters).map(Requirement.class::cast); + } + + /** + * Retrieve the set of values that occur in matches for Req. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfReq() { + return rawStreamAllValuesOfReq(emptyArray()).collect(Collectors.toSet()); + } + + /** + * Retrieve the set of values that occur in matches for Req. + * @return the Set of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfReq() { + return rawStreamAllValuesOfReq(emptyArray()); + } + + /** + * Retrieve the set of values that occur in matches for Req. + *

+ * NOTE: It is important not to modify the source model while the stream is being processed. + * If the match set of the pattern changes during processing, the contents of the stream is undefined. + * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. + * + * @return the Stream of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfReq(final InstanceDoesNotSatisfyRequirement.Match partialMatch) { + return rawStreamAllValuesOfReq(partialMatch.toArray()); + } + + /** + * Retrieve the set of values that occur in matches for Req. + *

+ * NOTE: It is important not to modify the source model while the stream is being processed. + * If the match set of the pattern changes during processing, the contents of the stream is undefined. + * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. + * + * @return the Stream of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfReq(final ApplicationInstance pApp) { + return rawStreamAllValuesOfReq(new Object[]{null, pApp}); + } + + /** + * Retrieve the set of values that occur in matches for Req. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfReq(final InstanceDoesNotSatisfyRequirement.Match partialMatch) { + return rawStreamAllValuesOfReq(partialMatch.toArray()).collect(Collectors.toSet()); + } + + /** + * Retrieve the set of values that occur in matches for Req. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfReq(final ApplicationInstance pApp) { + return rawStreamAllValuesOfReq(new Object[]{null, pApp}).collect(Collectors.toSet()); + } + + /** + * Retrieve the set of values that occur in matches for App. + * @return the Set of all values or empty set if there are no matches + * + */ + protected Stream rawStreamAllValuesOfApp(final Object[] parameters) { + return rawStreamAllValues(POSITION_APP, parameters).map(ApplicationInstance.class::cast); + } + + /** + * Retrieve the set of values that occur in matches for App. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfApp() { + return rawStreamAllValuesOfApp(emptyArray()).collect(Collectors.toSet()); + } + + /** + * Retrieve the set of values that occur in matches for App. + * @return the Set of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfApp() { + return rawStreamAllValuesOfApp(emptyArray()); + } + + /** + * Retrieve the set of values that occur in matches for App. + *

+ * NOTE: It is important not to modify the source model while the stream is being processed. + * If the match set of the pattern changes during processing, the contents of the stream is undefined. + * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. + * + * @return the Stream of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfApp(final InstanceDoesNotSatisfyRequirement.Match partialMatch) { + return rawStreamAllValuesOfApp(partialMatch.toArray()); + } + + /** + * Retrieve the set of values that occur in matches for App. + *

+ * NOTE: It is important not to modify the source model while the stream is being processed. + * If the match set of the pattern changes during processing, the contents of the stream is undefined. + * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. + * + * @return the Stream of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfApp(final Requirement pReq) { + return rawStreamAllValuesOfApp(new Object[]{pReq, null}); + } + + /** + * Retrieve the set of values that occur in matches for App. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfApp(final InstanceDoesNotSatisfyRequirement.Match partialMatch) { + return rawStreamAllValuesOfApp(partialMatch.toArray()).collect(Collectors.toSet()); + } + + /** + * Retrieve the set of values that occur in matches for App. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfApp(final Requirement pReq) { + return rawStreamAllValuesOfApp(new Object[]{pReq, null}).collect(Collectors.toSet()); + } + + @Override + protected InstanceDoesNotSatisfyRequirement.Match tupleToMatch(final Tuple t) { + try { + return InstanceDoesNotSatisfyRequirement.Match.newMatch((Requirement) t.get(POSITION_REQ), (ApplicationInstance) t.get(POSITION_APP)); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in tuple not properly typed!",e); + return null; + } + } + + @Override + protected InstanceDoesNotSatisfyRequirement.Match arrayToMatch(final Object[] match) { + try { + return InstanceDoesNotSatisfyRequirement.Match.newMatch((Requirement) match[POSITION_REQ], (ApplicationInstance) match[POSITION_APP]); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in array not properly typed!",e); + return null; + } + } + + @Override + protected InstanceDoesNotSatisfyRequirement.Match arrayToMatchMutable(final Object[] match) { + try { + return InstanceDoesNotSatisfyRequirement.Match.newMutableMatch((Requirement) match[POSITION_REQ], (ApplicationInstance) match[POSITION_APP]); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in array not properly typed!",e); + return null; + } + } + + /** + * @return the singleton instance of the query specification of this pattern + * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded + * + */ + public static IQuerySpecification querySpecification() { + return InstanceDoesNotSatisfyRequirement.instance(); + } + } + + private InstanceDoesNotSatisfyRequirement() { + super(GeneratedPQuery.INSTANCE); + } + + /** + * @return the singleton instance of the query specification + * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded + * + */ + public static InstanceDoesNotSatisfyRequirement instance() { + try{ + return LazyHolder.INSTANCE; + } catch (ExceptionInInitializerError err) { + throw processInitializerError(err); + } + } + + @Override + protected InstanceDoesNotSatisfyRequirement.Matcher instantiate(final ViatraQueryEngine engine) { + return InstanceDoesNotSatisfyRequirement.Matcher.on(engine); + } + + @Override + public InstanceDoesNotSatisfyRequirement.Matcher instantiate() { + return InstanceDoesNotSatisfyRequirement.Matcher.create(); + } + + @Override + public InstanceDoesNotSatisfyRequirement.Match newEmptyMatch() { + return InstanceDoesNotSatisfyRequirement.Match.newEmptyMatch(); + } + + @Override + public InstanceDoesNotSatisfyRequirement.Match newMatch(final Object... parameters) { + return InstanceDoesNotSatisfyRequirement.Match.newMatch((hu.bme.mit.inf.dslreasoner.domains.cps.Requirement) parameters[0], (hu.bme.mit.inf.dslreasoner.domains.cps.ApplicationInstance) parameters[1]); + } + + /** + * 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: ) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)} to be created + * not at the class load time of the outer class, + * 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: ) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}. + * + *

This workaround is required e.g. to support recursion. + * + */ + private static class LazyHolder { + private static final InstanceDoesNotSatisfyRequirement INSTANCE = new InstanceDoesNotSatisfyRequirement(); + + /** + * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. + * This initialization order is required to support indirect recursion. + * + *

The static initializer is defined using a helper field to work around limitations of the code generator. + * + */ + private static final Object STATIC_INITIALIZER = ensureInitialized(); + + public static Object ensureInitialized() { + INSTANCE.ensureInitializedInternal(); + return null; + } + } + + private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { + private static final InstanceDoesNotSatisfyRequirement.GeneratedPQuery INSTANCE = new GeneratedPQuery(); + + 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); + + 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); + + private final List parameters = Arrays.asList(parameter_Req, parameter_App); + + private GeneratedPQuery() { + super(PVisibility.PUBLIC); + } + + @Override + public String getFullyQualifiedName() { + return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.instanceDoesNotSatisfyRequirement"; + } + + @Override + public List getParameterNames() { + return Arrays.asList("Req","App"); + } + + @Override + public List getParameters() { + return parameters; + } + + @Override + public Set doGetContainedBodies() { + setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); + Set bodies = new LinkedHashSet<>(); + { + PBody body = new PBody(this); + PVariable var_Req = body.getOrCreateVariableByName("Req"); + PVariable var_App = body.getOrCreateVariableByName("App"); + new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "Requirement"))); + new TypeConstraint(body, Tuples.flatTupleOf(var_App), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance"))); + body.setSymbolicParameters(Arrays.asList( + new ExportedParameter(body, var_Req, parameter_Req), + new ExportedParameter(body, var_App, parameter_App) + )); + // Requirement.instances(Req, App) + new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "Requirement"))); + PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); + new TypeConstraint(body, Tuples.flatTupleOf(var_Req, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "Requirement", "instances"))); + new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance"))); + new Equality(body, var__virtual_0_, var_App); + // neg find satisfyingInstance(Req, App) + new NegativePatternCall(body, Tuples.flatTupleOf(var_Req, var_App), SatisfyingInstance.instance().getInternalQueryRepresentation()); + bodies.add(body); + } + { + PAnnotation annotation = new PAnnotation("Constraint"); + annotation.addAttribute("severity", "error"); + annotation.addAttribute("key", Arrays.asList(new Object[] { + new ParameterReference("Req"), + new ParameterReference("App") + })); + annotation.addAttribute("message", "Requirement must be satisfied by the required application type."); + addAnnotation(annotation); + } + return bodies; + } + } +} 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..41615598 --- /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 @@ +/** + * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql + */ +package hu.bme.mit.inf.dslreasoner.domains.cps.queries; + +import hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.AvailableHdd; +import java.util.Arrays; +import java.util.Collection; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.function.Consumer; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import org.apache.log4j.Logger; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.viatra.query.runtime.api.IPatternMatch; +import org.eclipse.viatra.query.runtime.api.IQuerySpecification; +import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; +import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; +import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; +import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; +import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; +import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; +import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; +import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator; +import org.eclipse.viatra.query.runtime.matchers.psystem.IValueProvider; +import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; +import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; +import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation; +import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; +import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; +import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; +import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; + +/** + * A pattern-specific query specification that can instantiate Matcher in a type-safe way. + * + *

Original source: + *

+ *         {@literal @}Constraint(severity = "error", key = {Host},
+ *         	message = "Insufficient HDD available on host.")
+ *         pattern notEnoughAvailableHdd(Host : HostInstance) {
+ *         	find availableHdd(Host, Hdd);
+ *         	check(Hdd {@literal <} 0);
+ *         }
+ * 
+ * + * @see Matcher + * @see Match + * + */ +@SuppressWarnings("all") +public final class NotEnoughAvailableHdd extends BaseGeneratedEMFQuerySpecification { + /** + * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.notEnoughAvailableHdd pattern, + * to be used in conjunction with {@link Matcher}. + * + *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. + * Each instance is a (possibly partial) substitution of pattern parameters, + * usable to represent a match of the pattern in the result of a query, + * or to specify the bound (fixed) input parameters when issuing a query. + * + * @see Matcher + * + */ + public static abstract class Match extends BasePatternMatch { + private HostInstance fHost; + + private static List parameterNames = makeImmutableList("Host"); + + private Match(final HostInstance pHost) { + this.fHost = pHost; + } + + @Override + public Object get(final String parameterName) { + if ("Host".equals(parameterName)) return this.fHost; + return null; + } + + public HostInstance getHost() { + return this.fHost; + } + + @Override + public boolean set(final String parameterName, final Object newValue) { + if (!isMutable()) throw new java.lang.UnsupportedOperationException(); + if ("Host".equals(parameterName) ) { + this.fHost = (HostInstance) newValue; + return true; + } + return false; + } + + public void setHost(final HostInstance pHost) { + if (!isMutable()) throw new java.lang.UnsupportedOperationException(); + this.fHost = pHost; + } + + @Override + public String patternName() { + return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.notEnoughAvailableHdd"; + } + + @Override + public List parameterNames() { + return NotEnoughAvailableHdd.Match.parameterNames; + } + + @Override + public Object[] toArray() { + return new Object[]{fHost}; + } + + @Override + public NotEnoughAvailableHdd.Match toImmutable() { + return isMutable() ? newMatch(fHost) : this; + } + + @Override + public String prettyPrint() { + StringBuilder result = new StringBuilder(); + result.append("\"Host\"=" + prettyPrintValue(fHost)); + return result.toString(); + } + + @Override + public int hashCode() { + return Objects.hash(fHost); + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) + return true; + if (obj == null) { + return false; + } + if ((obj instanceof NotEnoughAvailableHdd.Match)) { + NotEnoughAvailableHdd.Match other = (NotEnoughAvailableHdd.Match) obj; + return Objects.equals(fHost, other.fHost); + } else { + // this should be infrequent + if (!(obj instanceof IPatternMatch)) { + return false; + } + IPatternMatch otherSig = (IPatternMatch) obj; + return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); + } + } + + @Override + public NotEnoughAvailableHdd specification() { + return NotEnoughAvailableHdd.instance(); + } + + /** + * Returns an empty, mutable match. + * Fields of the mutable match can be filled to create a partial match, usable as matcher input. + * + * @return the empty match. + * + */ + public static NotEnoughAvailableHdd.Match newEmptyMatch() { + return new Mutable(null); + } + + /** + * Returns a mutable (partial) match. + * Fields of the mutable match can be filled to create a partial match, usable as matcher input. + * + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @return the new, mutable (partial) match object. + * + */ + public static NotEnoughAvailableHdd.Match newMutableMatch(final HostInstance pHost) { + return new Mutable(pHost); + } + + /** + * Returns a new (partial) match. + * This can be used e.g. to call the matcher with a partial match. + *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @return the (partial) match object. + * + */ + public static NotEnoughAvailableHdd.Match newMatch(final HostInstance pHost) { + return new Immutable(pHost); + } + + private static final class Mutable extends NotEnoughAvailableHdd.Match { + Mutable(final HostInstance pHost) { + super(pHost); + } + + @Override + public boolean isMutable() { + return true; + } + } + + private static final class Immutable extends NotEnoughAvailableHdd.Match { + Immutable(final HostInstance pHost) { + super(pHost); + } + + @Override + public boolean isMutable() { + return false; + } + } + } + + /** + * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.notEnoughAvailableHdd pattern, + * providing pattern-specific query methods. + * + *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, + * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. + * + *

Matches of the pattern will be represented as {@link Match}. + * + *

Original source: + *

+   * {@literal @}Constraint(severity = "error", key = {Host},
+   * 	message = "Insufficient HDD available on host.")
+   * pattern notEnoughAvailableHdd(Host : HostInstance) {
+   * 	find availableHdd(Host, Hdd);
+   * 	check(Hdd {@literal <} 0);
+   * }
+   * 
+ * + * @see Match + * @see NotEnoughAvailableHdd + * + */ + public static class Matcher extends BaseMatcher { + /** + * Initializes the pattern matcher within an existing VIATRA Query engine. + * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. + * + * @param engine the existing VIATRA Query engine in which this matcher will be created. + * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation + * + */ + public static NotEnoughAvailableHdd.Matcher on(final ViatraQueryEngine engine) { + // check if matcher already exists + Matcher matcher = engine.getExistingMatcher(querySpecification()); + if (matcher == null) { + matcher = (Matcher)engine.getMatcher(querySpecification()); + } + return matcher; + } + + /** + * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation + * @return an initialized matcher + * @noreference This method is for internal matcher initialization by the framework, do not call it manually. + * + */ + public static NotEnoughAvailableHdd.Matcher create() { + return new Matcher(); + } + + private static final int POSITION_HOST = 0; + + private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(NotEnoughAvailableHdd.Matcher.class); + + /** + * Initializes the pattern matcher within an existing VIATRA Query engine. + * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. + * + * @param engine the existing VIATRA Query engine in which this matcher will be created. + * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation + * + */ + private Matcher() { + super(querySpecification()); + } + + /** + * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @return matches represented as a Match object. + * + */ + public Collection getAllMatches(final HostInstance pHost) { + return rawStreamAllMatches(new Object[]{pHost}).collect(Collectors.toSet()); + } + + /** + * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. + *

+ * NOTE: It is important not to modify the source model while the stream is being processed. + * If the match set of the pattern changes during processing, the contents of the stream is undefined. + * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @return a stream of matches represented as a Match object. + * + */ + public Stream streamAllMatches(final HostInstance pHost) { + return rawStreamAllMatches(new Object[]{pHost}); + } + + /** + * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. + * Neither determinism nor randomness of selection is guaranteed. + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @return a match represented as a Match object, or null if no match is found. + * + */ + public Optional getOneArbitraryMatch(final HostInstance pHost) { + return rawGetOneArbitraryMatch(new Object[]{pHost}); + } + + /** + * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, + * under any possible substitution of the unspecified parameters (if any). + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @return true if the input is a valid (partial) match of the pattern. + * + */ + public boolean hasMatch(final HostInstance pHost) { + return rawHasMatch(new Object[]{pHost}); + } + + /** + * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @return the number of pattern matches found. + * + */ + public int countMatches(final HostInstance pHost) { + return rawCountMatches(new Object[]{pHost}); + } + + /** + * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. + * Neither determinism nor randomness of selection is guaranteed. + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @param processor the action that will process the selected match. + * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked + * + */ + public boolean forOneArbitraryMatch(final HostInstance pHost, final Consumer processor) { + return rawForOneArbitraryMatch(new Object[]{pHost}, processor); + } + + /** + * Returns a new (partial) match. + * This can be used e.g. to call the matcher with a partial match. + *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @return the (partial) match object. + * + */ + public NotEnoughAvailableHdd.Match newMatch(final HostInstance pHost) { + return NotEnoughAvailableHdd.Match.newMatch(pHost); + } + + /** + * Retrieve the set of values that occur in matches for Host. + * @return the Set of all values or empty set if there are no matches + * + */ + protected Stream rawStreamAllValuesOfHost(final Object[] parameters) { + return rawStreamAllValues(POSITION_HOST, parameters).map(HostInstance.class::cast); + } + + /** + * Retrieve the set of values that occur in matches for Host. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfHost() { + return rawStreamAllValuesOfHost(emptyArray()).collect(Collectors.toSet()); + } + + /** + * Retrieve the set of values that occur in matches for Host. + * @return the Set of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfHost() { + return rawStreamAllValuesOfHost(emptyArray()); + } + + @Override + protected NotEnoughAvailableHdd.Match tupleToMatch(final Tuple t) { + try { + return NotEnoughAvailableHdd.Match.newMatch((HostInstance) t.get(POSITION_HOST)); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in tuple not properly typed!",e); + return null; + } + } + + @Override + protected NotEnoughAvailableHdd.Match arrayToMatch(final Object[] match) { + try { + return NotEnoughAvailableHdd.Match.newMatch((HostInstance) match[POSITION_HOST]); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in array not properly typed!",e); + return null; + } + } + + @Override + protected NotEnoughAvailableHdd.Match arrayToMatchMutable(final Object[] match) { + try { + return NotEnoughAvailableHdd.Match.newMutableMatch((HostInstance) match[POSITION_HOST]); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in array not properly typed!",e); + return null; + } + } + + /** + * @return the singleton instance of the query specification of this pattern + * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded + * + */ + public static IQuerySpecification querySpecification() { + return NotEnoughAvailableHdd.instance(); + } + } + + private NotEnoughAvailableHdd() { + super(GeneratedPQuery.INSTANCE); + } + + /** + * @return the singleton instance of the query specification + * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded + * + */ + public static NotEnoughAvailableHdd instance() { + try{ + return LazyHolder.INSTANCE; + } catch (ExceptionInInitializerError err) { + throw processInitializerError(err); + } + } + + @Override + protected NotEnoughAvailableHdd.Matcher instantiate(final ViatraQueryEngine engine) { + return NotEnoughAvailableHdd.Matcher.on(engine); + } + + @Override + public NotEnoughAvailableHdd.Matcher instantiate() { + return NotEnoughAvailableHdd.Matcher.create(); + } + + @Override + public NotEnoughAvailableHdd.Match newEmptyMatch() { + return NotEnoughAvailableHdd.Match.newEmptyMatch(); + } + + @Override + public NotEnoughAvailableHdd.Match newMatch(final Object... parameters) { + return NotEnoughAvailableHdd.Match.newMatch((hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance) parameters[0]); + } + + /** + * 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: ) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)} to be created + * not at the class load time of the outer class, + * 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: ) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}. + * + *

This workaround is required e.g. to support recursion. + * + */ + private static class LazyHolder { + private static final NotEnoughAvailableHdd INSTANCE = new NotEnoughAvailableHdd(); + + /** + * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. + * This initialization order is required to support indirect recursion. + * + *

The static initializer is defined using a helper field to work around limitations of the code generator. + * + */ + private static final Object STATIC_INITIALIZER = ensureInitialized(); + + public static Object ensureInitialized() { + INSTANCE.ensureInitializedInternal(); + return null; + } + } + + private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { + private static final NotEnoughAvailableHdd.GeneratedPQuery INSTANCE = new GeneratedPQuery(); + + 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); + + private final List parameters = Arrays.asList(parameter_Host); + + private GeneratedPQuery() { + super(PVisibility.PUBLIC); + } + + @Override + public String getFullyQualifiedName() { + return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.notEnoughAvailableHdd"; + } + + @Override + public List getParameterNames() { + return Arrays.asList("Host"); + } + + @Override + public List getParameters() { + return parameters; + } + + @Override + public Set doGetContainedBodies() { + setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); + Set bodies = new LinkedHashSet<>(); + { + PBody body = new PBody(this); + PVariable var_Host = body.getOrCreateVariableByName("Host"); + PVariable var_Hdd = body.getOrCreateVariableByName("Hdd"); + new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); + body.setSymbolicParameters(Arrays.asList( + new ExportedParameter(body, var_Host, parameter_Host) + )); + // find availableHdd(Host, Hdd) + new PositivePatternCall(body, Tuples.flatTupleOf(var_Host, var_Hdd), AvailableHdd.instance().getInternalQueryRepresentation()); + // check(Hdd < 0) + new ExpressionEvaluation(body, new IExpressionEvaluator() { + + @Override + public String getShortDescription() { + return "Expression evaluation from pattern notEnoughAvailableHdd"; + } + + @Override + public Iterable getInputParameterNames() { + return Arrays.asList("Hdd");} + + @Override + public Object evaluateExpression(IValueProvider provider) throws Exception { + Integer Hdd = (Integer) provider.getValue("Hdd"); + return evaluateExpression_1_1(Hdd); + } + }, null); + bodies.add(body); + } + { + PAnnotation annotation = new PAnnotation("Constraint"); + annotation.addAttribute("severity", "error"); + annotation.addAttribute("key", Arrays.asList(new Object[] { + new ParameterReference("Host") + })); + annotation.addAttribute("message", "Insufficient HDD available on host."); + addAnnotation(annotation); + } + return bodies; + } + } + + private static boolean evaluateExpression_1_1(final Integer Hdd) { + return ((Hdd).intValue() < 0); + } +} 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..4803ec3a --- /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 @@ +/** + * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql + */ +package hu.bme.mit.inf.dslreasoner.domains.cps.queries; + +import hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.AvailableMemory; +import java.util.Arrays; +import java.util.Collection; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.function.Consumer; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import org.apache.log4j.Logger; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.viatra.query.runtime.api.IPatternMatch; +import org.eclipse.viatra.query.runtime.api.IQuerySpecification; +import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; +import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; +import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; +import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; +import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; +import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; +import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; +import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator; +import org.eclipse.viatra.query.runtime.matchers.psystem.IValueProvider; +import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; +import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; +import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation; +import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; +import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; +import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; +import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; + +/** + * A pattern-specific query specification that can instantiate Matcher in a type-safe way. + * + *

Original source: + *

+ *         {@literal @}Constraint(severity = "error", key = {Host},
+ *         	message = "Insufficient memory available on host.")
+ *         pattern notEnoughAvailableMemory(Host : HostInstance) {
+ *         	find availableMemory(Host, Memory);
+ *         	check(Memory {@literal <} 0);
+ *         }
+ * 
+ * + * @see Matcher + * @see Match + * + */ +@SuppressWarnings("all") +public final class NotEnoughAvailableMemory extends BaseGeneratedEMFQuerySpecification { + /** + * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.notEnoughAvailableMemory pattern, + * to be used in conjunction with {@link Matcher}. + * + *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. + * Each instance is a (possibly partial) substitution of pattern parameters, + * usable to represent a match of the pattern in the result of a query, + * or to specify the bound (fixed) input parameters when issuing a query. + * + * @see Matcher + * + */ + public static abstract class Match extends BasePatternMatch { + private HostInstance fHost; + + private static List parameterNames = makeImmutableList("Host"); + + private Match(final HostInstance pHost) { + this.fHost = pHost; + } + + @Override + public Object get(final String parameterName) { + if ("Host".equals(parameterName)) return this.fHost; + return null; + } + + public HostInstance getHost() { + return this.fHost; + } + + @Override + public boolean set(final String parameterName, final Object newValue) { + if (!isMutable()) throw new java.lang.UnsupportedOperationException(); + if ("Host".equals(parameterName) ) { + this.fHost = (HostInstance) newValue; + return true; + } + return false; + } + + public void setHost(final HostInstance pHost) { + if (!isMutable()) throw new java.lang.UnsupportedOperationException(); + this.fHost = pHost; + } + + @Override + public String patternName() { + return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.notEnoughAvailableMemory"; + } + + @Override + public List parameterNames() { + return NotEnoughAvailableMemory.Match.parameterNames; + } + + @Override + public Object[] toArray() { + return new Object[]{fHost}; + } + + @Override + public NotEnoughAvailableMemory.Match toImmutable() { + return isMutable() ? newMatch(fHost) : this; + } + + @Override + public String prettyPrint() { + StringBuilder result = new StringBuilder(); + result.append("\"Host\"=" + prettyPrintValue(fHost)); + return result.toString(); + } + + @Override + public int hashCode() { + return Objects.hash(fHost); + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) + return true; + if (obj == null) { + return false; + } + if ((obj instanceof NotEnoughAvailableMemory.Match)) { + NotEnoughAvailableMemory.Match other = (NotEnoughAvailableMemory.Match) obj; + return Objects.equals(fHost, other.fHost); + } else { + // this should be infrequent + if (!(obj instanceof IPatternMatch)) { + return false; + } + IPatternMatch otherSig = (IPatternMatch) obj; + return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); + } + } + + @Override + public NotEnoughAvailableMemory specification() { + return NotEnoughAvailableMemory.instance(); + } + + /** + * Returns an empty, mutable match. + * Fields of the mutable match can be filled to create a partial match, usable as matcher input. + * + * @return the empty match. + * + */ + public static NotEnoughAvailableMemory.Match newEmptyMatch() { + return new Mutable(null); + } + + /** + * Returns a mutable (partial) match. + * Fields of the mutable match can be filled to create a partial match, usable as matcher input. + * + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @return the new, mutable (partial) match object. + * + */ + public static NotEnoughAvailableMemory.Match newMutableMatch(final HostInstance pHost) { + return new Mutable(pHost); + } + + /** + * Returns a new (partial) match. + * This can be used e.g. to call the matcher with a partial match. + *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @return the (partial) match object. + * + */ + public static NotEnoughAvailableMemory.Match newMatch(final HostInstance pHost) { + return new Immutable(pHost); + } + + private static final class Mutable extends NotEnoughAvailableMemory.Match { + Mutable(final HostInstance pHost) { + super(pHost); + } + + @Override + public boolean isMutable() { + return true; + } + } + + private static final class Immutable extends NotEnoughAvailableMemory.Match { + Immutable(final HostInstance pHost) { + super(pHost); + } + + @Override + public boolean isMutable() { + return false; + } + } + } + + /** + * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.notEnoughAvailableMemory pattern, + * providing pattern-specific query methods. + * + *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, + * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. + * + *

Matches of the pattern will be represented as {@link Match}. + * + *

Original source: + *

+   * {@literal @}Constraint(severity = "error", key = {Host},
+   * 	message = "Insufficient memory available on host.")
+   * pattern notEnoughAvailableMemory(Host : HostInstance) {
+   * 	find availableMemory(Host, Memory);
+   * 	check(Memory {@literal <} 0);
+   * }
+   * 
+ * + * @see Match + * @see NotEnoughAvailableMemory + * + */ + public static class Matcher extends BaseMatcher { + /** + * Initializes the pattern matcher within an existing VIATRA Query engine. + * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. + * + * @param engine the existing VIATRA Query engine in which this matcher will be created. + * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation + * + */ + public static NotEnoughAvailableMemory.Matcher on(final ViatraQueryEngine engine) { + // check if matcher already exists + Matcher matcher = engine.getExistingMatcher(querySpecification()); + if (matcher == null) { + matcher = (Matcher)engine.getMatcher(querySpecification()); + } + return matcher; + } + + /** + * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation + * @return an initialized matcher + * @noreference This method is for internal matcher initialization by the framework, do not call it manually. + * + */ + public static NotEnoughAvailableMemory.Matcher create() { + return new Matcher(); + } + + private static final int POSITION_HOST = 0; + + private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(NotEnoughAvailableMemory.Matcher.class); + + /** + * Initializes the pattern matcher within an existing VIATRA Query engine. + * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. + * + * @param engine the existing VIATRA Query engine in which this matcher will be created. + * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation + * + */ + private Matcher() { + super(querySpecification()); + } + + /** + * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @return matches represented as a Match object. + * + */ + public Collection getAllMatches(final HostInstance pHost) { + return rawStreamAllMatches(new Object[]{pHost}).collect(Collectors.toSet()); + } + + /** + * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. + *

+ * NOTE: It is important not to modify the source model while the stream is being processed. + * If the match set of the pattern changes during processing, the contents of the stream is undefined. + * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @return a stream of matches represented as a Match object. + * + */ + public Stream streamAllMatches(final HostInstance pHost) { + return rawStreamAllMatches(new Object[]{pHost}); + } + + /** + * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. + * Neither determinism nor randomness of selection is guaranteed. + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @return a match represented as a Match object, or null if no match is found. + * + */ + public Optional getOneArbitraryMatch(final HostInstance pHost) { + return rawGetOneArbitraryMatch(new Object[]{pHost}); + } + + /** + * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, + * under any possible substitution of the unspecified parameters (if any). + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @return true if the input is a valid (partial) match of the pattern. + * + */ + public boolean hasMatch(final HostInstance pHost) { + return rawHasMatch(new Object[]{pHost}); + } + + /** + * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @return the number of pattern matches found. + * + */ + public int countMatches(final HostInstance pHost) { + return rawCountMatches(new Object[]{pHost}); + } + + /** + * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. + * Neither determinism nor randomness of selection is guaranteed. + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @param processor the action that will process the selected match. + * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked + * + */ + public boolean forOneArbitraryMatch(final HostInstance pHost, final Consumer processor) { + return rawForOneArbitraryMatch(new Object[]{pHost}, processor); + } + + /** + * Returns a new (partial) match. + * This can be used e.g. to call the matcher with a partial match. + *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @return the (partial) match object. + * + */ + public NotEnoughAvailableMemory.Match newMatch(final HostInstance pHost) { + return NotEnoughAvailableMemory.Match.newMatch(pHost); + } + + /** + * Retrieve the set of values that occur in matches for Host. + * @return the Set of all values or empty set if there are no matches + * + */ + protected Stream rawStreamAllValuesOfHost(final Object[] parameters) { + return rawStreamAllValues(POSITION_HOST, parameters).map(HostInstance.class::cast); + } + + /** + * Retrieve the set of values that occur in matches for Host. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfHost() { + return rawStreamAllValuesOfHost(emptyArray()).collect(Collectors.toSet()); + } + + /** + * Retrieve the set of values that occur in matches for Host. + * @return the Set of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfHost() { + return rawStreamAllValuesOfHost(emptyArray()); + } + + @Override + protected NotEnoughAvailableMemory.Match tupleToMatch(final Tuple t) { + try { + return NotEnoughAvailableMemory.Match.newMatch((HostInstance) t.get(POSITION_HOST)); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in tuple not properly typed!",e); + return null; + } + } + + @Override + protected NotEnoughAvailableMemory.Match arrayToMatch(final Object[] match) { + try { + return NotEnoughAvailableMemory.Match.newMatch((HostInstance) match[POSITION_HOST]); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in array not properly typed!",e); + return null; + } + } + + @Override + protected NotEnoughAvailableMemory.Match arrayToMatchMutable(final Object[] match) { + try { + return NotEnoughAvailableMemory.Match.newMutableMatch((HostInstance) match[POSITION_HOST]); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in array not properly typed!",e); + return null; + } + } + + /** + * @return the singleton instance of the query specification of this pattern + * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded + * + */ + public static IQuerySpecification querySpecification() { + return NotEnoughAvailableMemory.instance(); + } + } + + private NotEnoughAvailableMemory() { + super(GeneratedPQuery.INSTANCE); + } + + /** + * @return the singleton instance of the query specification + * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded + * + */ + public static NotEnoughAvailableMemory instance() { + try{ + return LazyHolder.INSTANCE; + } catch (ExceptionInInitializerError err) { + throw processInitializerError(err); + } + } + + @Override + protected NotEnoughAvailableMemory.Matcher instantiate(final ViatraQueryEngine engine) { + return NotEnoughAvailableMemory.Matcher.on(engine); + } + + @Override + public NotEnoughAvailableMemory.Matcher instantiate() { + return NotEnoughAvailableMemory.Matcher.create(); + } + + @Override + public NotEnoughAvailableMemory.Match newEmptyMatch() { + return NotEnoughAvailableMemory.Match.newEmptyMatch(); + } + + @Override + public NotEnoughAvailableMemory.Match newMatch(final Object... parameters) { + return NotEnoughAvailableMemory.Match.newMatch((hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance) parameters[0]); + } + + /** + * 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: ) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)} to be created + * not at the class load time of the outer class, + * 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: ) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}. + * + *

This workaround is required e.g. to support recursion. + * + */ + private static class LazyHolder { + private static final NotEnoughAvailableMemory INSTANCE = new NotEnoughAvailableMemory(); + + /** + * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. + * This initialization order is required to support indirect recursion. + * + *

The static initializer is defined using a helper field to work around limitations of the code generator. + * + */ + private static final Object STATIC_INITIALIZER = ensureInitialized(); + + public static Object ensureInitialized() { + INSTANCE.ensureInitializedInternal(); + return null; + } + } + + private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { + private static final NotEnoughAvailableMemory.GeneratedPQuery INSTANCE = new GeneratedPQuery(); + + 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); + + private final List parameters = Arrays.asList(parameter_Host); + + private GeneratedPQuery() { + super(PVisibility.PUBLIC); + } + + @Override + public String getFullyQualifiedName() { + return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.notEnoughAvailableMemory"; + } + + @Override + public List getParameterNames() { + return Arrays.asList("Host"); + } + + @Override + public List getParameters() { + return parameters; + } + + @Override + public Set doGetContainedBodies() { + setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); + Set bodies = new LinkedHashSet<>(); + { + PBody body = new PBody(this); + PVariable var_Host = body.getOrCreateVariableByName("Host"); + PVariable var_Memory = body.getOrCreateVariableByName("Memory"); + new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); + body.setSymbolicParameters(Arrays.asList( + new ExportedParameter(body, var_Host, parameter_Host) + )); + // find availableMemory(Host, Memory) + new PositivePatternCall(body, Tuples.flatTupleOf(var_Host, var_Memory), AvailableMemory.instance().getInternalQueryRepresentation()); + // check(Memory < 0) + new ExpressionEvaluation(body, new IExpressionEvaluator() { + + @Override + public String getShortDescription() { + return "Expression evaluation from pattern notEnoughAvailableMemory"; + } + + @Override + public Iterable getInputParameterNames() { + return Arrays.asList("Memory");} + + @Override + public Object evaluateExpression(IValueProvider provider) throws Exception { + Integer Memory = (Integer) provider.getValue("Memory"); + return evaluateExpression_1_1(Memory); + } + }, null); + bodies.add(body); + } + { + PAnnotation annotation = new PAnnotation("Constraint"); + annotation.addAttribute("severity", "error"); + annotation.addAttribute("key", Arrays.asList(new Object[] { + new ParameterReference("Host") + })); + annotation.addAttribute("message", "Insufficient memory available on host."); + addAnnotation(annotation); + } + return bodies; + } + } + + private static boolean evaluateExpression_1_1(final Integer Memory) { + return ((Memory).intValue() < 0); + } +} 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 @@ +/** + * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql + */ +package hu.bme.mit.inf.dslreasoner.domains.cps.queries; + +import hu.bme.mit.inf.dslreasoner.domains.cps.Requirement; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.SatisfyingInstance; +import java.util.Arrays; +import java.util.Collection; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.function.Consumer; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import org.apache.log4j.Logger; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EDataType; +import org.eclipse.viatra.query.runtime.api.IPatternMatch; +import org.eclipse.viatra.query.runtime.api.IQuerySpecification; +import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; +import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; +import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; +import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; +import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; +import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; +import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey; +import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; +import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; +import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator; +import org.eclipse.viatra.query.runtime.matchers.psystem.IValueProvider; +import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; +import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; +import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation; +import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.PatternMatchCounter; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; +import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; +import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; +import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; + +/** + * A pattern-specific query specification that can instantiate Matcher in a type-safe way. + * + *

Original source: + *

+ *         {@literal @}Constraint(severity = "error", key = {Req},
+ *         	message = "Requirement is not satisfied by enough application instances.")
+ *         pattern requirementNotSatisfied(Req : Requirement) {
+ *         	Instances == count find satisfyingInstance(Req, _);
+ *         	Requirement.count(Req, RequiredCount);
+ *         	check(Instances {@literal <} RequiredCount);
+ *         }
+ * 
+ * + * @see Matcher + * @see Match + * + */ +@SuppressWarnings("all") +public final class RequirementNotSatisfied extends BaseGeneratedEMFQuerySpecification { + /** + * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.requirementNotSatisfied pattern, + * to be used in conjunction with {@link Matcher}. + * + *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. + * Each instance is a (possibly partial) substitution of pattern parameters, + * usable to represent a match of the pattern in the result of a query, + * or to specify the bound (fixed) input parameters when issuing a query. + * + * @see Matcher + * + */ + public static abstract class Match extends BasePatternMatch { + private Requirement fReq; + + private static List parameterNames = makeImmutableList("Req"); + + private Match(final Requirement pReq) { + this.fReq = pReq; + } + + @Override + public Object get(final String parameterName) { + if ("Req".equals(parameterName)) return this.fReq; + return null; + } + + public Requirement getReq() { + return this.fReq; + } + + @Override + public boolean set(final String parameterName, final Object newValue) { + if (!isMutable()) throw new java.lang.UnsupportedOperationException(); + if ("Req".equals(parameterName) ) { + this.fReq = (Requirement) newValue; + return true; + } + return false; + } + + public void setReq(final Requirement pReq) { + if (!isMutable()) throw new java.lang.UnsupportedOperationException(); + this.fReq = pReq; + } + + @Override + public String patternName() { + return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.requirementNotSatisfied"; + } + + @Override + public List parameterNames() { + return RequirementNotSatisfied.Match.parameterNames; + } + + @Override + public Object[] toArray() { + return new Object[]{fReq}; + } + + @Override + public RequirementNotSatisfied.Match toImmutable() { + return isMutable() ? newMatch(fReq) : this; + } + + @Override + public String prettyPrint() { + StringBuilder result = new StringBuilder(); + result.append("\"Req\"=" + prettyPrintValue(fReq)); + return result.toString(); + } + + @Override + public int hashCode() { + return Objects.hash(fReq); + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) + return true; + if (obj == null) { + return false; + } + if ((obj instanceof RequirementNotSatisfied.Match)) { + RequirementNotSatisfied.Match other = (RequirementNotSatisfied.Match) obj; + return Objects.equals(fReq, other.fReq); + } else { + // this should be infrequent + if (!(obj instanceof IPatternMatch)) { + return false; + } + IPatternMatch otherSig = (IPatternMatch) obj; + return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); + } + } + + @Override + public RequirementNotSatisfied specification() { + return RequirementNotSatisfied.instance(); + } + + /** + * Returns an empty, mutable match. + * Fields of the mutable match can be filled to create a partial match, usable as matcher input. + * + * @return the empty match. + * + */ + public static RequirementNotSatisfied.Match newEmptyMatch() { + return new Mutable(null); + } + + /** + * Returns a mutable (partial) match. + * Fields of the mutable match can be filled to create a partial match, usable as matcher input. + * + * @param pReq the fixed value of pattern parameter Req, or null if not bound. + * @return the new, mutable (partial) match object. + * + */ + public static RequirementNotSatisfied.Match newMutableMatch(final Requirement pReq) { + return new Mutable(pReq); + } + + /** + * Returns a new (partial) match. + * This can be used e.g. to call the matcher with a partial match. + *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. + * @param pReq the fixed value of pattern parameter Req, or null if not bound. + * @return the (partial) match object. + * + */ + public static RequirementNotSatisfied.Match newMatch(final Requirement pReq) { + return new Immutable(pReq); + } + + private static final class Mutable extends RequirementNotSatisfied.Match { + Mutable(final Requirement pReq) { + super(pReq); + } + + @Override + public boolean isMutable() { + return true; + } + } + + private static final class Immutable extends RequirementNotSatisfied.Match { + Immutable(final Requirement pReq) { + super(pReq); + } + + @Override + public boolean isMutable() { + return false; + } + } + } + + /** + * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.requirementNotSatisfied pattern, + * providing pattern-specific query methods. + * + *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, + * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. + * + *

Matches of the pattern will be represented as {@link Match}. + * + *

Original source: + *

+   * {@literal @}Constraint(severity = "error", key = {Req},
+   * 	message = "Requirement is not satisfied by enough application instances.")
+   * pattern requirementNotSatisfied(Req : Requirement) {
+   * 	Instances == count find satisfyingInstance(Req, _);
+   * 	Requirement.count(Req, RequiredCount);
+   * 	check(Instances {@literal <} RequiredCount);
+   * }
+   * 
+ * + * @see Match + * @see RequirementNotSatisfied + * + */ + public static class Matcher extends BaseMatcher { + /** + * Initializes the pattern matcher within an existing VIATRA Query engine. + * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. + * + * @param engine the existing VIATRA Query engine in which this matcher will be created. + * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation + * + */ + public static RequirementNotSatisfied.Matcher on(final ViatraQueryEngine engine) { + // check if matcher already exists + Matcher matcher = engine.getExistingMatcher(querySpecification()); + if (matcher == null) { + matcher = (Matcher)engine.getMatcher(querySpecification()); + } + return matcher; + } + + /** + * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation + * @return an initialized matcher + * @noreference This method is for internal matcher initialization by the framework, do not call it manually. + * + */ + public static RequirementNotSatisfied.Matcher create() { + return new Matcher(); + } + + private static final int POSITION_REQ = 0; + + private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(RequirementNotSatisfied.Matcher.class); + + /** + * Initializes the pattern matcher within an existing VIATRA Query engine. + * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. + * + * @param engine the existing VIATRA Query engine in which this matcher will be created. + * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation + * + */ + private Matcher() { + super(querySpecification()); + } + + /** + * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. + * @param pReq the fixed value of pattern parameter Req, or null if not bound. + * @return matches represented as a Match object. + * + */ + public Collection getAllMatches(final Requirement pReq) { + return rawStreamAllMatches(new Object[]{pReq}).collect(Collectors.toSet()); + } + + /** + * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. + *

+ * NOTE: It is important not to modify the source model while the stream is being processed. + * If the match set of the pattern changes during processing, the contents of the stream is undefined. + * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. + * @param pReq the fixed value of pattern parameter Req, or null if not bound. + * @return a stream of matches represented as a Match object. + * + */ + public Stream streamAllMatches(final Requirement pReq) { + return rawStreamAllMatches(new Object[]{pReq}); + } + + /** + * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. + * Neither determinism nor randomness of selection is guaranteed. + * @param pReq the fixed value of pattern parameter Req, or null if not bound. + * @return a match represented as a Match object, or null if no match is found. + * + */ + public Optional getOneArbitraryMatch(final Requirement pReq) { + return rawGetOneArbitraryMatch(new Object[]{pReq}); + } + + /** + * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, + * under any possible substitution of the unspecified parameters (if any). + * @param pReq the fixed value of pattern parameter Req, or null if not bound. + * @return true if the input is a valid (partial) match of the pattern. + * + */ + public boolean hasMatch(final Requirement pReq) { + return rawHasMatch(new Object[]{pReq}); + } + + /** + * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. + * @param pReq the fixed value of pattern parameter Req, or null if not bound. + * @return the number of pattern matches found. + * + */ + public int countMatches(final Requirement pReq) { + return rawCountMatches(new Object[]{pReq}); + } + + /** + * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. + * Neither determinism nor randomness of selection is guaranteed. + * @param pReq the fixed value of pattern parameter Req, or null if not bound. + * @param processor the action that will process the selected match. + * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked + * + */ + public boolean forOneArbitraryMatch(final Requirement pReq, final Consumer processor) { + return rawForOneArbitraryMatch(new Object[]{pReq}, processor); + } + + /** + * Returns a new (partial) match. + * This can be used e.g. to call the matcher with a partial match. + *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. + * @param pReq the fixed value of pattern parameter Req, or null if not bound. + * @return the (partial) match object. + * + */ + public RequirementNotSatisfied.Match newMatch(final Requirement pReq) { + return RequirementNotSatisfied.Match.newMatch(pReq); + } + + /** + * Retrieve the set of values that occur in matches for Req. + * @return the Set of all values or empty set if there are no matches + * + */ + protected Stream rawStreamAllValuesOfReq(final Object[] parameters) { + return rawStreamAllValues(POSITION_REQ, parameters).map(Requirement.class::cast); + } + + /** + * Retrieve the set of values that occur in matches for Req. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfReq() { + return rawStreamAllValuesOfReq(emptyArray()).collect(Collectors.toSet()); + } + + /** + * Retrieve the set of values that occur in matches for Req. + * @return the Set of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfReq() { + return rawStreamAllValuesOfReq(emptyArray()); + } + + @Override + protected RequirementNotSatisfied.Match tupleToMatch(final Tuple t) { + try { + return RequirementNotSatisfied.Match.newMatch((Requirement) t.get(POSITION_REQ)); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in tuple not properly typed!",e); + return null; + } + } + + @Override + protected RequirementNotSatisfied.Match arrayToMatch(final Object[] match) { + try { + return RequirementNotSatisfied.Match.newMatch((Requirement) match[POSITION_REQ]); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in array not properly typed!",e); + return null; + } + } + + @Override + protected RequirementNotSatisfied.Match arrayToMatchMutable(final Object[] match) { + try { + return RequirementNotSatisfied.Match.newMutableMatch((Requirement) match[POSITION_REQ]); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in array not properly typed!",e); + return null; + } + } + + /** + * @return the singleton instance of the query specification of this pattern + * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded + * + */ + public static IQuerySpecification querySpecification() { + return RequirementNotSatisfied.instance(); + } + } + + private RequirementNotSatisfied() { + super(GeneratedPQuery.INSTANCE); + } + + /** + * @return the singleton instance of the query specification + * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded + * + */ + public static RequirementNotSatisfied instance() { + try{ + return LazyHolder.INSTANCE; + } catch (ExceptionInInitializerError err) { + throw processInitializerError(err); + } + } + + @Override + protected RequirementNotSatisfied.Matcher instantiate(final ViatraQueryEngine engine) { + return RequirementNotSatisfied.Matcher.on(engine); + } + + @Override + public RequirementNotSatisfied.Matcher instantiate() { + return RequirementNotSatisfied.Matcher.create(); + } + + @Override + public RequirementNotSatisfied.Match newEmptyMatch() { + return RequirementNotSatisfied.Match.newEmptyMatch(); + } + + @Override + public RequirementNotSatisfied.Match newMatch(final Object... parameters) { + return RequirementNotSatisfied.Match.newMatch((hu.bme.mit.inf.dslreasoner.domains.cps.Requirement) parameters[0]); + } + + /** + * 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: ) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)} to be created + * not at the class load time of the outer class, + * 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: ) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}. + * + *

This workaround is required e.g. to support recursion. + * + */ + private static class LazyHolder { + private static final RequirementNotSatisfied INSTANCE = new RequirementNotSatisfied(); + + /** + * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. + * This initialization order is required to support indirect recursion. + * + *

The static initializer is defined using a helper field to work around limitations of the code generator. + * + */ + private static final Object STATIC_INITIALIZER = ensureInitialized(); + + public static Object ensureInitialized() { + INSTANCE.ensureInitializedInternal(); + return null; + } + } + + private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { + private static final RequirementNotSatisfied.GeneratedPQuery INSTANCE = new GeneratedPQuery(); + + 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); + + private final List parameters = Arrays.asList(parameter_Req); + + private GeneratedPQuery() { + super(PVisibility.PUBLIC); + } + + @Override + public String getFullyQualifiedName() { + return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.requirementNotSatisfied"; + } + + @Override + public List getParameterNames() { + return Arrays.asList("Req"); + } + + @Override + public List getParameters() { + return parameters; + } + + @Override + public Set doGetContainedBodies() { + setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); + Set bodies = new LinkedHashSet<>(); + { + PBody body = new PBody(this); + PVariable var_Req = body.getOrCreateVariableByName("Req"); + PVariable var_Instances = body.getOrCreateVariableByName("Instances"); + PVariable var___0_ = body.getOrCreateVariableByName("_<0>"); + PVariable var_RequiredCount = body.getOrCreateVariableByName("RequiredCount"); + new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "Requirement"))); + body.setSymbolicParameters(Arrays.asList( + new ExportedParameter(body, var_Req, parameter_Req) + )); + // Instances == count find satisfyingInstance(Req, _) + PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); + new PatternMatchCounter(body, Tuples.flatTupleOf(var_Req, var___0_), SatisfyingInstance.instance().getInternalQueryRepresentation(), var__virtual_0_); + new Equality(body, var_Instances, var__virtual_0_); + // Requirement.count(Req, RequiredCount) + new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "Requirement"))); + PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); + new TypeConstraint(body, Tuples.flatTupleOf(var_Req, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "Requirement", "count"))); + new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt"))); + new Equality(body, var__virtual_1_, var_RequiredCount); + // check(Instances < RequiredCount) + new ExpressionEvaluation(body, new IExpressionEvaluator() { + + @Override + public String getShortDescription() { + return "Expression evaluation from pattern requirementNotSatisfied"; + } + + @Override + public Iterable getInputParameterNames() { + return Arrays.asList("Instances", "RequiredCount");} + + @Override + public Object evaluateExpression(IValueProvider provider) throws Exception { + Integer Instances = (Integer) provider.getValue("Instances"); + Integer RequiredCount = (Integer) provider.getValue("RequiredCount"); + return evaluateExpression_1_1(Instances, RequiredCount); + } + }, null); + bodies.add(body); + } + { + PAnnotation annotation = new PAnnotation("Constraint"); + annotation.addAttribute("severity", "error"); + annotation.addAttribute("key", Arrays.asList(new Object[] { + new ParameterReference("Req") + })); + annotation.addAttribute("message", "Requirement is not satisfied by enough application instances."); + addAnnotation(annotation); + } + return bodies; + } + } + + private static boolean evaluateExpression_1_1(final Integer Instances, final Integer RequiredCount) { + boolean _lessThan = (Instances.compareTo(RequiredCount) < 0); + return _lessThan; + } +} diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/TotalHdd.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/TotalHdd.java new file mode 100644 index 00000000..f91853de --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/TotalHdd.java @@ -0,0 +1,706 @@ +/** + * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql + */ +package hu.bme.mit.inf.dslreasoner.domains.cps.queries; + +import hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance; +import java.util.Arrays; +import java.util.Collection; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.function.Consumer; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import org.apache.log4j.Logger; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EDataType; +import org.eclipse.viatra.query.runtime.api.IPatternMatch; +import org.eclipse.viatra.query.runtime.api.IQuerySpecification; +import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; +import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; +import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; +import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; +import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; +import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; +import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey; +import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; +import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; +import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; +import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; +import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; +import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; +import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; +import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; + +/** + * A pattern-specific query specification that can instantiate Matcher in a type-safe way. + * + *

Original source: + *

+ *         {@literal @}QueryBasedFeature(feature = "totalHdd")
+ *         pattern totalHdd(Host : HostInstance, Hdd : EInt) {
+ *         	HostInstance.type.defaultHdd(Host, Hdd);
+ *         }
+ * 
+ * + * @see Matcher + * @see Match + * + */ +@SuppressWarnings("all") +public final class TotalHdd extends BaseGeneratedEMFQuerySpecification { + /** + * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.totalHdd pattern, + * to be used in conjunction with {@link Matcher}. + * + *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. + * Each instance is a (possibly partial) substitution of pattern parameters, + * usable to represent a match of the pattern in the result of a query, + * or to specify the bound (fixed) input parameters when issuing a query. + * + * @see Matcher + * + */ + public static abstract class Match extends BasePatternMatch { + private HostInstance fHost; + + private Integer fHdd; + + private static List parameterNames = makeImmutableList("Host", "Hdd"); + + private Match(final HostInstance pHost, final Integer pHdd) { + this.fHost = pHost; + this.fHdd = pHdd; + } + + @Override + public Object get(final String parameterName) { + if ("Host".equals(parameterName)) return this.fHost; + if ("Hdd".equals(parameterName)) return this.fHdd; + return null; + } + + public HostInstance getHost() { + return this.fHost; + } + + public Integer getHdd() { + return this.fHdd; + } + + @Override + public boolean set(final String parameterName, final Object newValue) { + if (!isMutable()) throw new java.lang.UnsupportedOperationException(); + if ("Host".equals(parameterName) ) { + this.fHost = (HostInstance) newValue; + return true; + } + if ("Hdd".equals(parameterName) ) { + this.fHdd = (Integer) newValue; + return true; + } + return false; + } + + public void setHost(final HostInstance pHost) { + if (!isMutable()) throw new java.lang.UnsupportedOperationException(); + this.fHost = pHost; + } + + public void setHdd(final Integer pHdd) { + if (!isMutable()) throw new java.lang.UnsupportedOperationException(); + this.fHdd = pHdd; + } + + @Override + public String patternName() { + return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.totalHdd"; + } + + @Override + public List parameterNames() { + return TotalHdd.Match.parameterNames; + } + + @Override + public Object[] toArray() { + return new Object[]{fHost, fHdd}; + } + + @Override + public TotalHdd.Match toImmutable() { + return isMutable() ? newMatch(fHost, fHdd) : this; + } + + @Override + public String prettyPrint() { + StringBuilder result = new StringBuilder(); + result.append("\"Host\"=" + prettyPrintValue(fHost) + ", "); + result.append("\"Hdd\"=" + prettyPrintValue(fHdd)); + return result.toString(); + } + + @Override + public int hashCode() { + return Objects.hash(fHost, fHdd); + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) + return true; + if (obj == null) { + return false; + } + if ((obj instanceof TotalHdd.Match)) { + TotalHdd.Match other = (TotalHdd.Match) obj; + return Objects.equals(fHost, other.fHost) && Objects.equals(fHdd, other.fHdd); + } else { + // this should be infrequent + if (!(obj instanceof IPatternMatch)) { + return false; + } + IPatternMatch otherSig = (IPatternMatch) obj; + return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); + } + } + + @Override + public TotalHdd specification() { + return TotalHdd.instance(); + } + + /** + * Returns an empty, mutable match. + * Fields of the mutable match can be filled to create a partial match, usable as matcher input. + * + * @return the empty match. + * + */ + public static TotalHdd.Match newEmptyMatch() { + return new Mutable(null, null); + } + + /** + * Returns a mutable (partial) match. + * Fields of the mutable match can be filled to create a partial match, usable as matcher input. + * + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @param pHdd the fixed value of pattern parameter Hdd, or null if not bound. + * @return the new, mutable (partial) match object. + * + */ + public static TotalHdd.Match newMutableMatch(final HostInstance pHost, final Integer pHdd) { + return new Mutable(pHost, pHdd); + } + + /** + * Returns a new (partial) match. + * This can be used e.g. to call the matcher with a partial match. + *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @param pHdd the fixed value of pattern parameter Hdd, or null if not bound. + * @return the (partial) match object. + * + */ + public static TotalHdd.Match newMatch(final HostInstance pHost, final Integer pHdd) { + return new Immutable(pHost, pHdd); + } + + private static final class Mutable extends TotalHdd.Match { + Mutable(final HostInstance pHost, final Integer pHdd) { + super(pHost, pHdd); + } + + @Override + public boolean isMutable() { + return true; + } + } + + private static final class Immutable extends TotalHdd.Match { + Immutable(final HostInstance pHost, final Integer pHdd) { + super(pHost, pHdd); + } + + @Override + public boolean isMutable() { + return false; + } + } + } + + /** + * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.totalHdd pattern, + * providing pattern-specific query methods. + * + *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, + * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. + * + *

Matches of the pattern will be represented as {@link Match}. + * + *

Original source: + *

+   * {@literal @}QueryBasedFeature(feature = "totalHdd")
+   * pattern totalHdd(Host : HostInstance, Hdd : EInt) {
+   * 	HostInstance.type.defaultHdd(Host, Hdd);
+   * }
+   * 
+ * + * @see Match + * @see TotalHdd + * + */ + public static class Matcher extends BaseMatcher { + /** + * Initializes the pattern matcher within an existing VIATRA Query engine. + * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. + * + * @param engine the existing VIATRA Query engine in which this matcher will be created. + * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation + * + */ + public static TotalHdd.Matcher on(final ViatraQueryEngine engine) { + // check if matcher already exists + Matcher matcher = engine.getExistingMatcher(querySpecification()); + if (matcher == null) { + matcher = (Matcher)engine.getMatcher(querySpecification()); + } + return matcher; + } + + /** + * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation + * @return an initialized matcher + * @noreference This method is for internal matcher initialization by the framework, do not call it manually. + * + */ + public static TotalHdd.Matcher create() { + return new Matcher(); + } + + private static final int POSITION_HOST = 0; + + private static final int POSITION_HDD = 1; + + private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(TotalHdd.Matcher.class); + + /** + * Initializes the pattern matcher within an existing VIATRA Query engine. + * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. + * + * @param engine the existing VIATRA Query engine in which this matcher will be created. + * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation + * + */ + private Matcher() { + super(querySpecification()); + } + + /** + * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @param pHdd the fixed value of pattern parameter Hdd, or null if not bound. + * @return matches represented as a Match object. + * + */ + public Collection getAllMatches(final HostInstance pHost, final Integer pHdd) { + return rawStreamAllMatches(new Object[]{pHost, pHdd}).collect(Collectors.toSet()); + } + + /** + * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. + *

+ * NOTE: It is important not to modify the source model while the stream is being processed. + * If the match set of the pattern changes during processing, the contents of the stream is undefined. + * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @param pHdd the fixed value of pattern parameter Hdd, or null if not bound. + * @return a stream of matches represented as a Match object. + * + */ + public Stream streamAllMatches(final HostInstance pHost, final Integer pHdd) { + return rawStreamAllMatches(new Object[]{pHost, pHdd}); + } + + /** + * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. + * Neither determinism nor randomness of selection is guaranteed. + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @param pHdd the fixed value of pattern parameter Hdd, or null if not bound. + * @return a match represented as a Match object, or null if no match is found. + * + */ + public Optional getOneArbitraryMatch(final HostInstance pHost, final Integer pHdd) { + return rawGetOneArbitraryMatch(new Object[]{pHost, pHdd}); + } + + /** + * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, + * under any possible substitution of the unspecified parameters (if any). + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @param pHdd the fixed value of pattern parameter Hdd, or null if not bound. + * @return true if the input is a valid (partial) match of the pattern. + * + */ + public boolean hasMatch(final HostInstance pHost, final Integer pHdd) { + return rawHasMatch(new Object[]{pHost, pHdd}); + } + + /** + * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @param pHdd the fixed value of pattern parameter Hdd, or null if not bound. + * @return the number of pattern matches found. + * + */ + public int countMatches(final HostInstance pHost, final Integer pHdd) { + return rawCountMatches(new Object[]{pHost, pHdd}); + } + + /** + * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. + * Neither determinism nor randomness of selection is guaranteed. + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @param pHdd the fixed value of pattern parameter Hdd, or null if not bound. + * @param processor the action that will process the selected match. + * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked + * + */ + public boolean forOneArbitraryMatch(final HostInstance pHost, final Integer pHdd, final Consumer processor) { + return rawForOneArbitraryMatch(new Object[]{pHost, pHdd}, processor); + } + + /** + * Returns a new (partial) match. + * This can be used e.g. to call the matcher with a partial match. + *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @param pHdd the fixed value of pattern parameter Hdd, or null if not bound. + * @return the (partial) match object. + * + */ + public TotalHdd.Match newMatch(final HostInstance pHost, final Integer pHdd) { + return TotalHdd.Match.newMatch(pHost, pHdd); + } + + /** + * Retrieve the set of values that occur in matches for Host. + * @return the Set of all values or empty set if there are no matches + * + */ + protected Stream rawStreamAllValuesOfHost(final Object[] parameters) { + return rawStreamAllValues(POSITION_HOST, parameters).map(HostInstance.class::cast); + } + + /** + * Retrieve the set of values that occur in matches for Host. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfHost() { + return rawStreamAllValuesOfHost(emptyArray()).collect(Collectors.toSet()); + } + + /** + * Retrieve the set of values that occur in matches for Host. + * @return the Set of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfHost() { + return rawStreamAllValuesOfHost(emptyArray()); + } + + /** + * Retrieve the set of values that occur in matches for Host. + *

+ * NOTE: It is important not to modify the source model while the stream is being processed. + * If the match set of the pattern changes during processing, the contents of the stream is undefined. + * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. + * + * @return the Stream of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfHost(final TotalHdd.Match partialMatch) { + return rawStreamAllValuesOfHost(partialMatch.toArray()); + } + + /** + * Retrieve the set of values that occur in matches for Host. + *

+ * NOTE: It is important not to modify the source model while the stream is being processed. + * If the match set of the pattern changes during processing, the contents of the stream is undefined. + * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. + * + * @return the Stream of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfHost(final Integer pHdd) { + return rawStreamAllValuesOfHost(new Object[]{null, pHdd}); + } + + /** + * Retrieve the set of values that occur in matches for Host. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfHost(final TotalHdd.Match partialMatch) { + return rawStreamAllValuesOfHost(partialMatch.toArray()).collect(Collectors.toSet()); + } + + /** + * Retrieve the set of values that occur in matches for Host. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfHost(final Integer pHdd) { + return rawStreamAllValuesOfHost(new Object[]{null, pHdd}).collect(Collectors.toSet()); + } + + /** + * Retrieve the set of values that occur in matches for Hdd. + * @return the Set of all values or empty set if there are no matches + * + */ + protected Stream rawStreamAllValuesOfHdd(final Object[] parameters) { + return rawStreamAllValues(POSITION_HDD, parameters).map(Integer.class::cast); + } + + /** + * Retrieve the set of values that occur in matches for Hdd. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfHdd() { + return rawStreamAllValuesOfHdd(emptyArray()).collect(Collectors.toSet()); + } + + /** + * Retrieve the set of values that occur in matches for Hdd. + * @return the Set of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfHdd() { + return rawStreamAllValuesOfHdd(emptyArray()); + } + + /** + * Retrieve the set of values that occur in matches for Hdd. + *

+ * NOTE: It is important not to modify the source model while the stream is being processed. + * If the match set of the pattern changes during processing, the contents of the stream is undefined. + * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. + * + * @return the Stream of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfHdd(final TotalHdd.Match partialMatch) { + return rawStreamAllValuesOfHdd(partialMatch.toArray()); + } + + /** + * Retrieve the set of values that occur in matches for Hdd. + *

+ * NOTE: It is important not to modify the source model while the stream is being processed. + * If the match set of the pattern changes during processing, the contents of the stream is undefined. + * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. + * + * @return the Stream of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfHdd(final HostInstance pHost) { + return rawStreamAllValuesOfHdd(new Object[]{pHost, null}); + } + + /** + * Retrieve the set of values that occur in matches for Hdd. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfHdd(final TotalHdd.Match partialMatch) { + return rawStreamAllValuesOfHdd(partialMatch.toArray()).collect(Collectors.toSet()); + } + + /** + * Retrieve the set of values that occur in matches for Hdd. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfHdd(final HostInstance pHost) { + return rawStreamAllValuesOfHdd(new Object[]{pHost, null}).collect(Collectors.toSet()); + } + + @Override + protected TotalHdd.Match tupleToMatch(final Tuple t) { + try { + return TotalHdd.Match.newMatch((HostInstance) t.get(POSITION_HOST), (Integer) t.get(POSITION_HDD)); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in tuple not properly typed!",e); + return null; + } + } + + @Override + protected TotalHdd.Match arrayToMatch(final Object[] match) { + try { + return TotalHdd.Match.newMatch((HostInstance) match[POSITION_HOST], (Integer) match[POSITION_HDD]); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in array not properly typed!",e); + return null; + } + } + + @Override + protected TotalHdd.Match arrayToMatchMutable(final Object[] match) { + try { + return TotalHdd.Match.newMutableMatch((HostInstance) match[POSITION_HOST], (Integer) match[POSITION_HDD]); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in array not properly typed!",e); + return null; + } + } + + /** + * @return the singleton instance of the query specification of this pattern + * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded + * + */ + public static IQuerySpecification querySpecification() { + return TotalHdd.instance(); + } + } + + private TotalHdd() { + super(GeneratedPQuery.INSTANCE); + } + + /** + * @return the singleton instance of the query specification + * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded + * + */ + public static TotalHdd instance() { + try{ + return LazyHolder.INSTANCE; + } catch (ExceptionInInitializerError err) { + throw processInitializerError(err); + } + } + + @Override + protected TotalHdd.Matcher instantiate(final ViatraQueryEngine engine) { + return TotalHdd.Matcher.on(engine); + } + + @Override + public TotalHdd.Matcher instantiate() { + return TotalHdd.Matcher.create(); + } + + @Override + public TotalHdd.Match newEmptyMatch() { + return TotalHdd.Match.newEmptyMatch(); + } + + @Override + public TotalHdd.Match newMatch(final Object... parameters) { + return TotalHdd.Match.newMatch((hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance) parameters[0], (java.lang.Integer) parameters[1]); + } + + /** + * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.TotalHdd (visibility: PUBLIC, simpleName: TotalHdd, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.TotalHdd, deprecated: ) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)} to be created + * not at the class load time of the outer class, + * but rather at the first call to {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.TotalHdd (visibility: PUBLIC, simpleName: TotalHdd, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.TotalHdd, deprecated: ) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}. + * + *

This workaround is required e.g. to support recursion. + * + */ + private static class LazyHolder { + private static final TotalHdd INSTANCE = new TotalHdd(); + + /** + * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. + * This initialization order is required to support indirect recursion. + * + *

The static initializer is defined using a helper field to work around limitations of the code generator. + * + */ + private static final Object STATIC_INITIALIZER = ensureInitialized(); + + public static Object ensureInitialized() { + INSTANCE.ensureInitializedInternal(); + return null; + } + } + + private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { + private static final TotalHdd.GeneratedPQuery INSTANCE = new GeneratedPQuery(); + + 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); + + 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); + + private final List parameters = Arrays.asList(parameter_Host, parameter_Hdd); + + private GeneratedPQuery() { + super(PVisibility.PUBLIC); + } + + @Override + public String getFullyQualifiedName() { + return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.totalHdd"; + } + + @Override + public List getParameterNames() { + return Arrays.asList("Host","Hdd"); + } + + @Override + public List getParameters() { + return parameters; + } + + @Override + public Set doGetContainedBodies() { + setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); + Set bodies = new LinkedHashSet<>(); + { + PBody body = new PBody(this); + PVariable var_Host = body.getOrCreateVariableByName("Host"); + PVariable var_Hdd = body.getOrCreateVariableByName("Hdd"); + new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); + new TypeConstraint(body, Tuples.flatTupleOf(var_Hdd), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt"))); + body.setSymbolicParameters(Arrays.asList( + new ExportedParameter(body, var_Host, parameter_Host), + new ExportedParameter(body, var_Hdd, parameter_Hdd) + )); + // HostInstance.type.defaultHdd(Host, Hdd) + new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); + PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); + new TypeConstraint(body, Tuples.flatTupleOf(var_Host, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "HostInstance", "type"))); + new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostType"))); + PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); + new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "HostType", "defaultHdd"))); + new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt"))); + new Equality(body, var__virtual_1_, var_Hdd); + bodies.add(body); + } + { + PAnnotation annotation = new PAnnotation("QueryBasedFeature"); + annotation.addAttribute("feature", "totalHdd"); + addAnnotation(annotation); + } + return bodies; + } + } +} diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/TotalMemory.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/TotalMemory.java new file mode 100644 index 00000000..e8a11e36 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/TotalMemory.java @@ -0,0 +1,706 @@ +/** + * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql + */ +package hu.bme.mit.inf.dslreasoner.domains.cps.queries; + +import hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance; +import java.util.Arrays; +import java.util.Collection; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.function.Consumer; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import org.apache.log4j.Logger; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EDataType; +import org.eclipse.viatra.query.runtime.api.IPatternMatch; +import org.eclipse.viatra.query.runtime.api.IQuerySpecification; +import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; +import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; +import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; +import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; +import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; +import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; +import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey; +import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; +import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; +import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; +import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; +import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; +import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; +import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; +import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; + +/** + * A pattern-specific query specification that can instantiate Matcher in a type-safe way. + * + *

Original source: + *

+ *         {@literal @}QueryBasedFeature(feature = "totalMemory")
+ *         pattern totalMemory(Host : HostInstance, Memory : EInt) {
+ *         	HostInstance.type.defaultMemory(Host, Memory);
+ *         }
+ * 
+ * + * @see Matcher + * @see Match + * + */ +@SuppressWarnings("all") +public final class TotalMemory extends BaseGeneratedEMFQuerySpecification { + /** + * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.totalMemory pattern, + * to be used in conjunction with {@link Matcher}. + * + *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. + * Each instance is a (possibly partial) substitution of pattern parameters, + * usable to represent a match of the pattern in the result of a query, + * or to specify the bound (fixed) input parameters when issuing a query. + * + * @see Matcher + * + */ + public static abstract class Match extends BasePatternMatch { + private HostInstance fHost; + + private Integer fMemory; + + private static List parameterNames = makeImmutableList("Host", "Memory"); + + private Match(final HostInstance pHost, final Integer pMemory) { + this.fHost = pHost; + this.fMemory = pMemory; + } + + @Override + public Object get(final String parameterName) { + if ("Host".equals(parameterName)) return this.fHost; + if ("Memory".equals(parameterName)) return this.fMemory; + return null; + } + + public HostInstance getHost() { + return this.fHost; + } + + public Integer getMemory() { + return this.fMemory; + } + + @Override + public boolean set(final String parameterName, final Object newValue) { + if (!isMutable()) throw new java.lang.UnsupportedOperationException(); + if ("Host".equals(parameterName) ) { + this.fHost = (HostInstance) newValue; + return true; + } + if ("Memory".equals(parameterName) ) { + this.fMemory = (Integer) newValue; + return true; + } + return false; + } + + public void setHost(final HostInstance pHost) { + if (!isMutable()) throw new java.lang.UnsupportedOperationException(); + this.fHost = pHost; + } + + public void setMemory(final Integer pMemory) { + if (!isMutable()) throw new java.lang.UnsupportedOperationException(); + this.fMemory = pMemory; + } + + @Override + public String patternName() { + return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.totalMemory"; + } + + @Override + public List parameterNames() { + return TotalMemory.Match.parameterNames; + } + + @Override + public Object[] toArray() { + return new Object[]{fHost, fMemory}; + } + + @Override + public TotalMemory.Match toImmutable() { + return isMutable() ? newMatch(fHost, fMemory) : this; + } + + @Override + public String prettyPrint() { + StringBuilder result = new StringBuilder(); + result.append("\"Host\"=" + prettyPrintValue(fHost) + ", "); + result.append("\"Memory\"=" + prettyPrintValue(fMemory)); + return result.toString(); + } + + @Override + public int hashCode() { + return Objects.hash(fHost, fMemory); + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) + return true; + if (obj == null) { + return false; + } + if ((obj instanceof TotalMemory.Match)) { + TotalMemory.Match other = (TotalMemory.Match) obj; + return Objects.equals(fHost, other.fHost) && Objects.equals(fMemory, other.fMemory); + } else { + // this should be infrequent + if (!(obj instanceof IPatternMatch)) { + return false; + } + IPatternMatch otherSig = (IPatternMatch) obj; + return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); + } + } + + @Override + public TotalMemory specification() { + return TotalMemory.instance(); + } + + /** + * Returns an empty, mutable match. + * Fields of the mutable match can be filled to create a partial match, usable as matcher input. + * + * @return the empty match. + * + */ + public static TotalMemory.Match newEmptyMatch() { + return new Mutable(null, null); + } + + /** + * Returns a mutable (partial) match. + * Fields of the mutable match can be filled to create a partial match, usable as matcher input. + * + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @param pMemory the fixed value of pattern parameter Memory, or null if not bound. + * @return the new, mutable (partial) match object. + * + */ + public static TotalMemory.Match newMutableMatch(final HostInstance pHost, final Integer pMemory) { + return new Mutable(pHost, pMemory); + } + + /** + * Returns a new (partial) match. + * This can be used e.g. to call the matcher with a partial match. + *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @param pMemory the fixed value of pattern parameter Memory, or null if not bound. + * @return the (partial) match object. + * + */ + public static TotalMemory.Match newMatch(final HostInstance pHost, final Integer pMemory) { + return new Immutable(pHost, pMemory); + } + + private static final class Mutable extends TotalMemory.Match { + Mutable(final HostInstance pHost, final Integer pMemory) { + super(pHost, pMemory); + } + + @Override + public boolean isMutable() { + return true; + } + } + + private static final class Immutable extends TotalMemory.Match { + Immutable(final HostInstance pHost, final Integer pMemory) { + super(pHost, pMemory); + } + + @Override + public boolean isMutable() { + return false; + } + } + } + + /** + * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.totalMemory pattern, + * providing pattern-specific query methods. + * + *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, + * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. + * + *

Matches of the pattern will be represented as {@link Match}. + * + *

Original source: + *

+   * {@literal @}QueryBasedFeature(feature = "totalMemory")
+   * pattern totalMemory(Host : HostInstance, Memory : EInt) {
+   * 	HostInstance.type.defaultMemory(Host, Memory);
+   * }
+   * 
+ * + * @see Match + * @see TotalMemory + * + */ + public static class Matcher extends BaseMatcher { + /** + * Initializes the pattern matcher within an existing VIATRA Query engine. + * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. + * + * @param engine the existing VIATRA Query engine in which this matcher will be created. + * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation + * + */ + public static TotalMemory.Matcher on(final ViatraQueryEngine engine) { + // check if matcher already exists + Matcher matcher = engine.getExistingMatcher(querySpecification()); + if (matcher == null) { + matcher = (Matcher)engine.getMatcher(querySpecification()); + } + return matcher; + } + + /** + * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation + * @return an initialized matcher + * @noreference This method is for internal matcher initialization by the framework, do not call it manually. + * + */ + public static TotalMemory.Matcher create() { + return new Matcher(); + } + + private static final int POSITION_HOST = 0; + + private static final int POSITION_MEMORY = 1; + + private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(TotalMemory.Matcher.class); + + /** + * Initializes the pattern matcher within an existing VIATRA Query engine. + * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. + * + * @param engine the existing VIATRA Query engine in which this matcher will be created. + * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation + * + */ + private Matcher() { + super(querySpecification()); + } + + /** + * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @param pMemory the fixed value of pattern parameter Memory, or null if not bound. + * @return matches represented as a Match object. + * + */ + public Collection getAllMatches(final HostInstance pHost, final Integer pMemory) { + return rawStreamAllMatches(new Object[]{pHost, pMemory}).collect(Collectors.toSet()); + } + + /** + * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. + *

+ * NOTE: It is important not to modify the source model while the stream is being processed. + * If the match set of the pattern changes during processing, the contents of the stream is undefined. + * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @param pMemory the fixed value of pattern parameter Memory, or null if not bound. + * @return a stream of matches represented as a Match object. + * + */ + public Stream streamAllMatches(final HostInstance pHost, final Integer pMemory) { + return rawStreamAllMatches(new Object[]{pHost, pMemory}); + } + + /** + * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. + * Neither determinism nor randomness of selection is guaranteed. + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @param pMemory the fixed value of pattern parameter Memory, or null if not bound. + * @return a match represented as a Match object, or null if no match is found. + * + */ + public Optional getOneArbitraryMatch(final HostInstance pHost, final Integer pMemory) { + return rawGetOneArbitraryMatch(new Object[]{pHost, pMemory}); + } + + /** + * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, + * under any possible substitution of the unspecified parameters (if any). + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @param pMemory the fixed value of pattern parameter Memory, or null if not bound. + * @return true if the input is a valid (partial) match of the pattern. + * + */ + public boolean hasMatch(final HostInstance pHost, final Integer pMemory) { + return rawHasMatch(new Object[]{pHost, pMemory}); + } + + /** + * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @param pMemory the fixed value of pattern parameter Memory, or null if not bound. + * @return the number of pattern matches found. + * + */ + public int countMatches(final HostInstance pHost, final Integer pMemory) { + return rawCountMatches(new Object[]{pHost, pMemory}); + } + + /** + * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. + * Neither determinism nor randomness of selection is guaranteed. + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @param pMemory the fixed value of pattern parameter Memory, or null if not bound. + * @param processor the action that will process the selected match. + * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked + * + */ + public boolean forOneArbitraryMatch(final HostInstance pHost, final Integer pMemory, final Consumer processor) { + return rawForOneArbitraryMatch(new Object[]{pHost, pMemory}, processor); + } + + /** + * Returns a new (partial) match. + * This can be used e.g. to call the matcher with a partial match. + *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @param pMemory the fixed value of pattern parameter Memory, or null if not bound. + * @return the (partial) match object. + * + */ + public TotalMemory.Match newMatch(final HostInstance pHost, final Integer pMemory) { + return TotalMemory.Match.newMatch(pHost, pMemory); + } + + /** + * Retrieve the set of values that occur in matches for Host. + * @return the Set of all values or empty set if there are no matches + * + */ + protected Stream rawStreamAllValuesOfHost(final Object[] parameters) { + return rawStreamAllValues(POSITION_HOST, parameters).map(HostInstance.class::cast); + } + + /** + * Retrieve the set of values that occur in matches for Host. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfHost() { + return rawStreamAllValuesOfHost(emptyArray()).collect(Collectors.toSet()); + } + + /** + * Retrieve the set of values that occur in matches for Host. + * @return the Set of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfHost() { + return rawStreamAllValuesOfHost(emptyArray()); + } + + /** + * Retrieve the set of values that occur in matches for Host. + *

+ * NOTE: It is important not to modify the source model while the stream is being processed. + * If the match set of the pattern changes during processing, the contents of the stream is undefined. + * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. + * + * @return the Stream of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfHost(final TotalMemory.Match partialMatch) { + return rawStreamAllValuesOfHost(partialMatch.toArray()); + } + + /** + * Retrieve the set of values that occur in matches for Host. + *

+ * NOTE: It is important not to modify the source model while the stream is being processed. + * If the match set of the pattern changes during processing, the contents of the stream is undefined. + * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. + * + * @return the Stream of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfHost(final Integer pMemory) { + return rawStreamAllValuesOfHost(new Object[]{null, pMemory}); + } + + /** + * Retrieve the set of values that occur in matches for Host. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfHost(final TotalMemory.Match partialMatch) { + return rawStreamAllValuesOfHost(partialMatch.toArray()).collect(Collectors.toSet()); + } + + /** + * Retrieve the set of values that occur in matches for Host. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfHost(final Integer pMemory) { + return rawStreamAllValuesOfHost(new Object[]{null, pMemory}).collect(Collectors.toSet()); + } + + /** + * Retrieve the set of values that occur in matches for Memory. + * @return the Set of all values or empty set if there are no matches + * + */ + protected Stream rawStreamAllValuesOfMemory(final Object[] parameters) { + return rawStreamAllValues(POSITION_MEMORY, parameters).map(Integer.class::cast); + } + + /** + * Retrieve the set of values that occur in matches for Memory. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfMemory() { + return rawStreamAllValuesOfMemory(emptyArray()).collect(Collectors.toSet()); + } + + /** + * Retrieve the set of values that occur in matches for Memory. + * @return the Set of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfMemory() { + return rawStreamAllValuesOfMemory(emptyArray()); + } + + /** + * Retrieve the set of values that occur in matches for Memory. + *

+ * NOTE: It is important not to modify the source model while the stream is being processed. + * If the match set of the pattern changes during processing, the contents of the stream is undefined. + * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. + * + * @return the Stream of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfMemory(final TotalMemory.Match partialMatch) { + return rawStreamAllValuesOfMemory(partialMatch.toArray()); + } + + /** + * Retrieve the set of values that occur in matches for Memory. + *

+ * NOTE: It is important not to modify the source model while the stream is being processed. + * If the match set of the pattern changes during processing, the contents of the stream is undefined. + * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. + * + * @return the Stream of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfMemory(final HostInstance pHost) { + return rawStreamAllValuesOfMemory(new Object[]{pHost, null}); + } + + /** + * Retrieve the set of values that occur in matches for Memory. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfMemory(final TotalMemory.Match partialMatch) { + return rawStreamAllValuesOfMemory(partialMatch.toArray()).collect(Collectors.toSet()); + } + + /** + * Retrieve the set of values that occur in matches for Memory. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfMemory(final HostInstance pHost) { + return rawStreamAllValuesOfMemory(new Object[]{pHost, null}).collect(Collectors.toSet()); + } + + @Override + protected TotalMemory.Match tupleToMatch(final Tuple t) { + try { + return TotalMemory.Match.newMatch((HostInstance) t.get(POSITION_HOST), (Integer) t.get(POSITION_MEMORY)); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in tuple not properly typed!",e); + return null; + } + } + + @Override + protected TotalMemory.Match arrayToMatch(final Object[] match) { + try { + return TotalMemory.Match.newMatch((HostInstance) match[POSITION_HOST], (Integer) match[POSITION_MEMORY]); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in array not properly typed!",e); + return null; + } + } + + @Override + protected TotalMemory.Match arrayToMatchMutable(final Object[] match) { + try { + return TotalMemory.Match.newMutableMatch((HostInstance) match[POSITION_HOST], (Integer) match[POSITION_MEMORY]); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in array not properly typed!",e); + return null; + } + } + + /** + * @return the singleton instance of the query specification of this pattern + * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded + * + */ + public static IQuerySpecification querySpecification() { + return TotalMemory.instance(); + } + } + + private TotalMemory() { + super(GeneratedPQuery.INSTANCE); + } + + /** + * @return the singleton instance of the query specification + * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded + * + */ + public static TotalMemory instance() { + try{ + return LazyHolder.INSTANCE; + } catch (ExceptionInInitializerError err) { + throw processInitializerError(err); + } + } + + @Override + protected TotalMemory.Matcher instantiate(final ViatraQueryEngine engine) { + return TotalMemory.Matcher.on(engine); + } + + @Override + public TotalMemory.Matcher instantiate() { + return TotalMemory.Matcher.create(); + } + + @Override + public TotalMemory.Match newEmptyMatch() { + return TotalMemory.Match.newEmptyMatch(); + } + + @Override + public TotalMemory.Match newMatch(final Object... parameters) { + return TotalMemory.Match.newMatch((hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance) parameters[0], (java.lang.Integer) parameters[1]); + } + + /** + * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.TotalMemory (visibility: PUBLIC, simpleName: TotalMemory, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.TotalMemory, deprecated: ) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)} to be created + * not at the class load time of the outer class, + * but rather at the first call to {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.TotalMemory (visibility: PUBLIC, simpleName: TotalMemory, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.TotalMemory, deprecated: ) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}. + * + *

This workaround is required e.g. to support recursion. + * + */ + private static class LazyHolder { + private static final TotalMemory INSTANCE = new TotalMemory(); + + /** + * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. + * This initialization order is required to support indirect recursion. + * + *

The static initializer is defined using a helper field to work around limitations of the code generator. + * + */ + private static final Object STATIC_INITIALIZER = ensureInitialized(); + + public static Object ensureInitialized() { + INSTANCE.ensureInitializedInternal(); + return null; + } + } + + private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { + private static final TotalMemory.GeneratedPQuery INSTANCE = new GeneratedPQuery(); + + 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); + + 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); + + private final List parameters = Arrays.asList(parameter_Host, parameter_Memory); + + private GeneratedPQuery() { + super(PVisibility.PUBLIC); + } + + @Override + public String getFullyQualifiedName() { + return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.totalMemory"; + } + + @Override + public List getParameterNames() { + return Arrays.asList("Host","Memory"); + } + + @Override + public List getParameters() { + return parameters; + } + + @Override + public Set doGetContainedBodies() { + setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); + Set bodies = new LinkedHashSet<>(); + { + PBody body = new PBody(this); + PVariable var_Host = body.getOrCreateVariableByName("Host"); + PVariable var_Memory = body.getOrCreateVariableByName("Memory"); + new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); + new TypeConstraint(body, Tuples.flatTupleOf(var_Memory), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt"))); + body.setSymbolicParameters(Arrays.asList( + new ExportedParameter(body, var_Host, parameter_Host), + new ExportedParameter(body, var_Memory, parameter_Memory) + )); + // HostInstance.type.defaultMemory(Host, Memory) + new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); + PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); + new TypeConstraint(body, Tuples.flatTupleOf(var_Host, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "HostInstance", "type"))); + new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostType"))); + PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); + new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "HostType", "defaultMemory"))); + new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt"))); + new Equality(body, var__virtual_1_, var_Memory); + bodies.add(body); + } + { + PAnnotation annotation = new PAnnotation("QueryBasedFeature"); + annotation.addAttribute("feature", "totalMemory"); + addAnnotation(annotation); + } + return bodies; + } + } +} 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..2f593811 --- /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,11 @@ +/.CpsQueriesAll.java._trace +/.ResourceRequirement.java._trace +/.MemoryRequirement.java._trace +/.HddRequirement.java._trace +/.AllocationWithoutResourceRequirement.java._trace +/.RequiredType.java._trace +/.SatisfyingInstance.java._trace +/.FreeMemoryPercentage.java._trace +/.FreeHddPercentage.java._trace +/.ApplicationInstance.java._trace +/.HostInstanceCost.java._trace 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..5f6d161d --- /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,105 @@ +/** + * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql + */ +package hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal; + +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.AllocationWithoutResourceRequirement; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.AvailableHdd; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.AvailableMemory; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.AverageFreeHddMetric; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.AverageFreeMemoryMetric; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.CostMetric; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.CpsApplications; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.CpsCost; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.CpsHosts; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.InstanceDoesNotSatisfyRequirement; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.NotEnoughAvailableHdd; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.NotEnoughAvailableMemory; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.RequirementNotSatisfied; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.TotalHdd; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.TotalMemory; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.FreeHddPercentage; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.FreeMemoryPercentage; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.HddRequirement; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.HostInstanceCost; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.MemoryRequirement; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.ResourceRequirement; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.SatisfyingInstance; +import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedPatternGroup; + +/** + * A pattern group formed of all patterns defined in CpsQueries.vql. + * + *

A private group that includes private patterns as well. Only intended use case is for pattern testing. + * + *

From package hu.bme.mit.inf.dslreasoner.domains.cps.queries, the group contains the definition of the following patterns:

    + *
  • cpsApplications
  • + *
  • cpsHosts
  • + *
  • totalMemory
  • + *
  • totalHdd
  • + *
  • availableMemory
  • + *
  • memoryRequirement
  • + *
  • availableHdd
  • + *
  • hddRequirement
  • + *
  • resourceRequirement
  • + *
  • allocationWithoutResourceRequirement
  • + *
  • notEnoughAvailableMemory
  • + *
  • notEnoughAvailableHdd
  • + *
  • instanceDoesNotSatisfyRequirement
  • + *
  • satisfyingInstance
  • + *
  • requirementNotSatisfied
  • + *
  • averageFreeMemoryMetric
  • + *
  • freeMemoryPercentage
  • + *
  • averageFreeHddMetric
  • + *
  • freeHddPercentage
  • + *
  • costMetric
  • + *
  • cpsCost
  • + *
  • hostInstanceCost
  • + *
+ * + * @see IQueryGroup + * + */ +@SuppressWarnings("all") +public final class CpsQueriesAll extends BaseGeneratedPatternGroup { + /** + * Access the pattern group. + * + * @return the singleton instance of the group + * @throws ViatraQueryRuntimeException if there was an error loading the generated code of pattern specifications + * + */ + public static CpsQueriesAll instance() { + if (INSTANCE == null) { + INSTANCE = new CpsQueriesAll(); + } + return INSTANCE; + } + + private static CpsQueriesAll INSTANCE; + + private CpsQueriesAll() { + querySpecifications.add(CpsApplications.instance()); + querySpecifications.add(CpsHosts.instance()); + querySpecifications.add(TotalMemory.instance()); + querySpecifications.add(TotalHdd.instance()); + querySpecifications.add(AvailableMemory.instance()); + querySpecifications.add(MemoryRequirement.instance()); + querySpecifications.add(AvailableHdd.instance()); + querySpecifications.add(HddRequirement.instance()); + querySpecifications.add(ResourceRequirement.instance()); + querySpecifications.add(AllocationWithoutResourceRequirement.instance()); + querySpecifications.add(NotEnoughAvailableMemory.instance()); + querySpecifications.add(NotEnoughAvailableHdd.instance()); + querySpecifications.add(InstanceDoesNotSatisfyRequirement.instance()); + querySpecifications.add(SatisfyingInstance.instance()); + querySpecifications.add(RequirementNotSatisfied.instance()); + querySpecifications.add(AverageFreeMemoryMetric.instance()); + querySpecifications.add(FreeMemoryPercentage.instance()); + querySpecifications.add(AverageFreeHddMetric.instance()); + querySpecifications.add(FreeHddPercentage.instance()); + querySpecifications.add(CostMetric.instance()); + querySpecifications.add(CpsCost.instance()); + querySpecifications.add(HostInstanceCost.instance()); + } +} 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..366677b5 --- /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 @@ +/** + * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql + */ +package hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal; + +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.AvailableHdd; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.TotalHdd; +import java.util.Arrays; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; +import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecificationWithGenericMatcher; +import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; +import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; +import org.eclipse.viatra.query.runtime.matchers.context.common.JavaTransitiveInstancesKey; +import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator; +import org.eclipse.viatra.query.runtime.matchers.psystem.IValueProvider; +import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; +import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.TypeFilterConstraint; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; +import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; + +/** + * A pattern-specific query specification that can instantiate GenericPatternMatcher in a type-safe way. + * + *

Original source: + *

+ *         private pattern freeHddPercentage(Host : HostInstance, Free : java Double) {
+ *         	find totalHdd(Host, Total);
+ *         	find availableHdd(Host, Available);
+ *         	Free == eval((Available as double) / Total);
+ *         }
+ * 
+ * + * @see GenericPatternMatcher + * @see GenericPatternMatch + * + */ +@SuppressWarnings("all") +public final class FreeHddPercentage extends BaseGeneratedEMFQuerySpecificationWithGenericMatcher { + private FreeHddPercentage() { + super(GeneratedPQuery.INSTANCE); + } + + /** + * @return the singleton instance of the query specification + * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded + * + */ + public static FreeHddPercentage instance() { + try{ + return LazyHolder.INSTANCE; + } catch (ExceptionInInitializerError err) { + throw processInitializerError(err); + } + } + + /** + * 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: ) (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 + * not at the class load time of the outer class, + * 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: ) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}. + * + *

This workaround is required e.g. to support recursion. + * + */ + private static class LazyHolder { + private static final FreeHddPercentage INSTANCE = new FreeHddPercentage(); + + /** + * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. + * This initialization order is required to support indirect recursion. + * + *

The static initializer is defined using a helper field to work around limitations of the code generator. + * + */ + private static final Object STATIC_INITIALIZER = ensureInitialized(); + + public static Object ensureInitialized() { + INSTANCE.ensureInitializedInternal(); + return null; + } + } + + private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { + private static final FreeHddPercentage.GeneratedPQuery INSTANCE = new GeneratedPQuery(); + + 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); + + private final PParameter parameter_Free = new PParameter("Free", "java.lang.Double", new JavaTransitiveInstancesKey(java.lang.Double.class), PParameterDirection.INOUT); + + private final List parameters = Arrays.asList(parameter_Host, parameter_Free); + + private GeneratedPQuery() { + super(PVisibility.PRIVATE); + } + + @Override + public String getFullyQualifiedName() { + return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.freeHddPercentage"; + } + + @Override + public List getParameterNames() { + return Arrays.asList("Host","Free"); + } + + @Override + public List getParameters() { + return parameters; + } + + @Override + public Set doGetContainedBodies() { + setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); + Set bodies = new LinkedHashSet<>(); + { + PBody body = new PBody(this); + PVariable var_Host = body.getOrCreateVariableByName("Host"); + PVariable var_Free = body.getOrCreateVariableByName("Free"); + PVariable var_Total = body.getOrCreateVariableByName("Total"); + PVariable var_Available = body.getOrCreateVariableByName("Available"); + new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); + new TypeFilterConstraint(body, Tuples.flatTupleOf(var_Free), new JavaTransitiveInstancesKey(java.lang.Double.class)); + body.setSymbolicParameters(Arrays.asList( + new ExportedParameter(body, var_Host, parameter_Host), + new ExportedParameter(body, var_Free, parameter_Free) + )); + // find totalHdd(Host, Total) + new PositivePatternCall(body, Tuples.flatTupleOf(var_Host, var_Total), TotalHdd.instance().getInternalQueryRepresentation()); + // find availableHdd(Host, Available) + new PositivePatternCall(body, Tuples.flatTupleOf(var_Host, var_Available), AvailableHdd.instance().getInternalQueryRepresentation()); + // Free == eval((Available as double) / Total) + PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); + new ExpressionEvaluation(body, new IExpressionEvaluator() { + + @Override + public String getShortDescription() { + return "Expression evaluation from pattern freeHddPercentage"; + } + + @Override + public Iterable getInputParameterNames() { + return Arrays.asList("Available", "Total");} + + @Override + public Object evaluateExpression(IValueProvider provider) throws Exception { + Integer Available = (Integer) provider.getValue("Available"); + Integer Total = (Integer) provider.getValue("Total"); + return evaluateExpression_1_1(Available, Total); + } + }, var__virtual_0_ ); + new Equality(body, var_Free, var__virtual_0_); + bodies.add(body); + } + return bodies; + } + } + + private static double evaluateExpression_1_1(final Integer Available, final Integer Total) { + return (((double) (Available).intValue()) / (Total).intValue()); + } +} 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..bd151ea6 --- /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 @@ +/** + * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql + */ +package hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal; + +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.AvailableMemory; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.TotalMemory; +import java.util.Arrays; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; +import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecificationWithGenericMatcher; +import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; +import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; +import org.eclipse.viatra.query.runtime.matchers.context.common.JavaTransitiveInstancesKey; +import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator; +import org.eclipse.viatra.query.runtime.matchers.psystem.IValueProvider; +import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; +import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.TypeFilterConstraint; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; +import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; + +/** + * A pattern-specific query specification that can instantiate GenericPatternMatcher in a type-safe way. + * + *

Original source: + *

+ *         private pattern freeMemoryPercentage(Host : HostInstance, Free : java Double) {
+ *         	find totalMemory(Host, Total);
+ *         	find availableMemory(Host, Available);
+ *         	Free == eval((Available as double) / Total);
+ *         }
+ * 
+ * + * @see GenericPatternMatcher + * @see GenericPatternMatch + * + */ +@SuppressWarnings("all") +public final class FreeMemoryPercentage extends BaseGeneratedEMFQuerySpecificationWithGenericMatcher { + private FreeMemoryPercentage() { + super(GeneratedPQuery.INSTANCE); + } + + /** + * @return the singleton instance of the query specification + * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded + * + */ + public static FreeMemoryPercentage instance() { + try{ + return LazyHolder.INSTANCE; + } catch (ExceptionInInitializerError err) { + throw processInitializerError(err); + } + } + + /** + * 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: ) (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 + * not at the class load time of the outer class, + * 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: ) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}. + * + *

This workaround is required e.g. to support recursion. + * + */ + private static class LazyHolder { + private static final FreeMemoryPercentage INSTANCE = new FreeMemoryPercentage(); + + /** + * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. + * This initialization order is required to support indirect recursion. + * + *

The static initializer is defined using a helper field to work around limitations of the code generator. + * + */ + private static final Object STATIC_INITIALIZER = ensureInitialized(); + + public static Object ensureInitialized() { + INSTANCE.ensureInitializedInternal(); + return null; + } + } + + private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { + private static final FreeMemoryPercentage.GeneratedPQuery INSTANCE = new GeneratedPQuery(); + + 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); + + private final PParameter parameter_Free = new PParameter("Free", "java.lang.Double", new JavaTransitiveInstancesKey(java.lang.Double.class), PParameterDirection.INOUT); + + private final List parameters = Arrays.asList(parameter_Host, parameter_Free); + + private GeneratedPQuery() { + super(PVisibility.PRIVATE); + } + + @Override + public String getFullyQualifiedName() { + return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.freeMemoryPercentage"; + } + + @Override + public List getParameterNames() { + return Arrays.asList("Host","Free"); + } + + @Override + public List getParameters() { + return parameters; + } + + @Override + public Set doGetContainedBodies() { + setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); + Set bodies = new LinkedHashSet<>(); + { + PBody body = new PBody(this); + PVariable var_Host = body.getOrCreateVariableByName("Host"); + PVariable var_Free = body.getOrCreateVariableByName("Free"); + PVariable var_Total = body.getOrCreateVariableByName("Total"); + PVariable var_Available = body.getOrCreateVariableByName("Available"); + new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); + new TypeFilterConstraint(body, Tuples.flatTupleOf(var_Free), new JavaTransitiveInstancesKey(java.lang.Double.class)); + body.setSymbolicParameters(Arrays.asList( + new ExportedParameter(body, var_Host, parameter_Host), + new ExportedParameter(body, var_Free, parameter_Free) + )); + // find totalMemory(Host, Total) + new PositivePatternCall(body, Tuples.flatTupleOf(var_Host, var_Total), TotalMemory.instance().getInternalQueryRepresentation()); + // find availableMemory(Host, Available) + new PositivePatternCall(body, Tuples.flatTupleOf(var_Host, var_Available), AvailableMemory.instance().getInternalQueryRepresentation()); + // Free == eval((Available as double) / Total) + PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); + new ExpressionEvaluation(body, new IExpressionEvaluator() { + + @Override + public String getShortDescription() { + return "Expression evaluation from pattern freeMemoryPercentage"; + } + + @Override + public Iterable getInputParameterNames() { + return Arrays.asList("Available", "Total");} + + @Override + public Object evaluateExpression(IValueProvider provider) throws Exception { + Integer Available = (Integer) provider.getValue("Available"); + Integer Total = (Integer) provider.getValue("Total"); + return evaluateExpression_1_1(Available, Total); + } + }, var__virtual_0_ ); + new Equality(body, var_Free, var__virtual_0_); + bodies.add(body); + } + return bodies; + } + } + + private static double evaluateExpression_1_1(final Integer Available, final Integer Total) { + return (((double) (Available).intValue()) / (Total).intValue()); + } +} 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..fbe7a46b --- /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 @@ +/** + * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql + */ +package hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal; + +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.ResourceRequirement; +import java.util.Arrays; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EDataType; +import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; +import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecificationWithGenericMatcher; +import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; +import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey; +import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; +import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; +import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; +import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; +import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; + +/** + * A pattern-specific query specification that can instantiate GenericPatternMatcher in a type-safe way. + * + *

Original source: + *

+ *         private pattern hddRequirement(Host : HostInstance, App : ApplicationInstance, Hdd : EInt) {
+ *         	find resourceRequirement(Host, App, Req);
+ *         	ResourceRequirement.requiredHdd(Req, Hdd);
+ *         }
+ * 
+ * + * @see GenericPatternMatcher + * @see GenericPatternMatch + * + */ +@SuppressWarnings("all") +public final class HddRequirement extends BaseGeneratedEMFQuerySpecificationWithGenericMatcher { + private HddRequirement() { + super(GeneratedPQuery.INSTANCE); + } + + /** + * @return the singleton instance of the query specification + * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded + * + */ + public static HddRequirement instance() { + try{ + return LazyHolder.INSTANCE; + } catch (ExceptionInInitializerError err) { + throw processInitializerError(err); + } + } + + /** + * 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: ) (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 + * not at the class load time of the outer class, + * 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: ) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}. + * + *

This workaround is required e.g. to support recursion. + * + */ + private static class LazyHolder { + private static final HddRequirement INSTANCE = new HddRequirement(); + + /** + * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. + * This initialization order is required to support indirect recursion. + * + *

The static initializer is defined using a helper field to work around limitations of the code generator. + * + */ + private static final Object STATIC_INITIALIZER = ensureInitialized(); + + public static Object ensureInitialized() { + INSTANCE.ensureInitializedInternal(); + return null; + } + } + + private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { + private static final HddRequirement.GeneratedPQuery INSTANCE = new GeneratedPQuery(); + + 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); + + 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); + + 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); + + private final List parameters = Arrays.asList(parameter_Host, parameter_App, parameter_Hdd); + + private GeneratedPQuery() { + super(PVisibility.PRIVATE); + } + + @Override + public String getFullyQualifiedName() { + return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.hddRequirement"; + } + + @Override + public List getParameterNames() { + return Arrays.asList("Host","App","Hdd"); + } + + @Override + public List getParameters() { + return parameters; + } + + @Override + public Set doGetContainedBodies() { + setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); + Set bodies = new LinkedHashSet<>(); + { + PBody body = new PBody(this); + PVariable var_Host = body.getOrCreateVariableByName("Host"); + PVariable var_App = body.getOrCreateVariableByName("App"); + PVariable var_Hdd = body.getOrCreateVariableByName("Hdd"); + PVariable var_Req = body.getOrCreateVariableByName("Req"); + new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); + new TypeConstraint(body, Tuples.flatTupleOf(var_App), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance"))); + new TypeConstraint(body, Tuples.flatTupleOf(var_Hdd), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt"))); + body.setSymbolicParameters(Arrays.asList( + new ExportedParameter(body, var_Host, parameter_Host), + new ExportedParameter(body, var_App, parameter_App), + new ExportedParameter(body, var_Hdd, parameter_Hdd) + )); + // find resourceRequirement(Host, App, Req) + new PositivePatternCall(body, Tuples.flatTupleOf(var_Host, var_App, var_Req), ResourceRequirement.instance().getInternalQueryRepresentation()); + // ResourceRequirement.requiredHdd(Req, Hdd) + new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ResourceRequirement"))); + PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); + new TypeConstraint(body, Tuples.flatTupleOf(var_Req, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ResourceRequirement", "requiredHdd"))); + new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt"))); + new Equality(body, var__virtual_0_, var_Hdd); + bodies.add(body); + } + return bodies; + } + } +} 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..767ca342 --- /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 @@ +/** + * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql + */ +package hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal; + +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.CpsHosts; +import java.util.Arrays; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EDataType; +import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; +import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecificationWithGenericMatcher; +import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; +import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey; +import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; +import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; +import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; +import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; +import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; + +/** + * A pattern-specific query specification that can instantiate GenericPatternMatcher in a type-safe way. + * + *

Original source: + *

+ *         private pattern hostInstanceCost(Cps : CyberPhysicalSystem, Host : HostInstance, Cost : EInt) {
+ *         	find cpsHosts(Cps, Host);
+ *         	HostInstance.type.cost(Host, Cost);
+ *         }
+ * 
+ * + * @see GenericPatternMatcher + * @see GenericPatternMatch + * + */ +@SuppressWarnings("all") +public final class HostInstanceCost extends BaseGeneratedEMFQuerySpecificationWithGenericMatcher { + private HostInstanceCost() { + super(GeneratedPQuery.INSTANCE); + } + + /** + * @return the singleton instance of the query specification + * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded + * + */ + public static HostInstanceCost instance() { + try{ + return LazyHolder.INSTANCE; + } catch (ExceptionInInitializerError err) { + throw processInitializerError(err); + } + } + + /** + * 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: ) (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 + * not at the class load time of the outer class, + * 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: ) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}. + * + *

This workaround is required e.g. to support recursion. + * + */ + private static class LazyHolder { + private static final HostInstanceCost INSTANCE = new HostInstanceCost(); + + /** + * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. + * This initialization order is required to support indirect recursion. + * + *

The static initializer is defined using a helper field to work around limitations of the code generator. + * + */ + private static final Object STATIC_INITIALIZER = ensureInitialized(); + + public static Object ensureInitialized() { + INSTANCE.ensureInitializedInternal(); + return null; + } + } + + private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { + private static final HostInstanceCost.GeneratedPQuery INSTANCE = new GeneratedPQuery(); + + 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); + + 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); + + 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); + + private final List parameters = Arrays.asList(parameter_Cps, parameter_Host, parameter_Cost); + + private GeneratedPQuery() { + super(PVisibility.PRIVATE); + } + + @Override + public String getFullyQualifiedName() { + return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.hostInstanceCost"; + } + + @Override + public List getParameterNames() { + return Arrays.asList("Cps","Host","Cost"); + } + + @Override + public List getParameters() { + return parameters; + } + + @Override + public Set doGetContainedBodies() { + setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); + Set bodies = new LinkedHashSet<>(); + { + PBody body = new PBody(this); + PVariable var_Cps = body.getOrCreateVariableByName("Cps"); + PVariable var_Host = body.getOrCreateVariableByName("Host"); + PVariable var_Cost = body.getOrCreateVariableByName("Cost"); + new TypeConstraint(body, Tuples.flatTupleOf(var_Cps), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "CyberPhysicalSystem"))); + new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); + new TypeConstraint(body, Tuples.flatTupleOf(var_Cost), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt"))); + body.setSymbolicParameters(Arrays.asList( + new ExportedParameter(body, var_Cps, parameter_Cps), + new ExportedParameter(body, var_Host, parameter_Host), + new ExportedParameter(body, var_Cost, parameter_Cost) + )); + // find cpsHosts(Cps, Host) + new PositivePatternCall(body, Tuples.flatTupleOf(var_Cps, var_Host), CpsHosts.instance().getInternalQueryRepresentation()); + // HostInstance.type.cost(Host, Cost) + new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); + PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); + new TypeConstraint(body, Tuples.flatTupleOf(var_Host, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "HostInstance", "type"))); + new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostType"))); + PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); + new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "HostType", "cost"))); + new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt"))); + new Equality(body, var__virtual_1_, var_Cost); + bodies.add(body); + } + return bodies; + } + } +} 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..0a24d105 --- /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 @@ +/** + * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql + */ +package hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal; + +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.ResourceRequirement; +import java.util.Arrays; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EDataType; +import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; +import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecificationWithGenericMatcher; +import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; +import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey; +import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; +import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; +import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; +import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; +import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; + +/** + * A pattern-specific query specification that can instantiate GenericPatternMatcher in a type-safe way. + * + *

Original source: + *

+ *         private pattern memoryRequirement(Host : HostInstance, App : ApplicationInstance, Memory : EInt) {
+ *         	find resourceRequirement(Host, App, Req);
+ *         	ResourceRequirement.requiredMemory(Req, Memory);
+ *         }
+ * 
+ * + * @see GenericPatternMatcher + * @see GenericPatternMatch + * + */ +@SuppressWarnings("all") +public final class MemoryRequirement extends BaseGeneratedEMFQuerySpecificationWithGenericMatcher { + private MemoryRequirement() { + super(GeneratedPQuery.INSTANCE); + } + + /** + * @return the singleton instance of the query specification + * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded + * + */ + public static MemoryRequirement instance() { + try{ + return LazyHolder.INSTANCE; + } catch (ExceptionInInitializerError err) { + throw processInitializerError(err); + } + } + + /** + * 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: ) (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 + * not at the class load time of the outer class, + * 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: ) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}. + * + *

This workaround is required e.g. to support recursion. + * + */ + private static class LazyHolder { + private static final MemoryRequirement INSTANCE = new MemoryRequirement(); + + /** + * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. + * This initialization order is required to support indirect recursion. + * + *

The static initializer is defined using a helper field to work around limitations of the code generator. + * + */ + private static final Object STATIC_INITIALIZER = ensureInitialized(); + + public static Object ensureInitialized() { + INSTANCE.ensureInitializedInternal(); + return null; + } + } + + private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { + private static final MemoryRequirement.GeneratedPQuery INSTANCE = new GeneratedPQuery(); + + 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); + + 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); + + 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); + + private final List parameters = Arrays.asList(parameter_Host, parameter_App, parameter_Memory); + + private GeneratedPQuery() { + super(PVisibility.PRIVATE); + } + + @Override + public String getFullyQualifiedName() { + return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.memoryRequirement"; + } + + @Override + public List getParameterNames() { + return Arrays.asList("Host","App","Memory"); + } + + @Override + public List getParameters() { + return parameters; + } + + @Override + public Set doGetContainedBodies() { + setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); + Set bodies = new LinkedHashSet<>(); + { + PBody body = new PBody(this); + PVariable var_Host = body.getOrCreateVariableByName("Host"); + PVariable var_App = body.getOrCreateVariableByName("App"); + PVariable var_Memory = body.getOrCreateVariableByName("Memory"); + PVariable var_Req = body.getOrCreateVariableByName("Req"); + new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); + new TypeConstraint(body, Tuples.flatTupleOf(var_App), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance"))); + new TypeConstraint(body, Tuples.flatTupleOf(var_Memory), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt"))); + body.setSymbolicParameters(Arrays.asList( + new ExportedParameter(body, var_Host, parameter_Host), + new ExportedParameter(body, var_App, parameter_App), + new ExportedParameter(body, var_Memory, parameter_Memory) + )); + // find resourceRequirement(Host, App, Req) + new PositivePatternCall(body, Tuples.flatTupleOf(var_Host, var_App, var_Req), ResourceRequirement.instance().getInternalQueryRepresentation()); + // ResourceRequirement.requiredMemory(Req, Memory) + new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ResourceRequirement"))); + PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); + new TypeConstraint(body, Tuples.flatTupleOf(var_Req, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ResourceRequirement", "requiredMemory"))); + new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt"))); + new Equality(body, var__virtual_0_, var_Memory); + bodies.add(body); + } + return bodies; + } + } +} diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/ResourceRequirement.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/ResourceRequirement.java new file mode 100644 index 00000000..8c5bdefe --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/ResourceRequirement.java @@ -0,0 +1,168 @@ +/** + * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql + */ +package hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal; + +import java.util.Arrays; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; +import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecificationWithGenericMatcher; +import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; +import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; +import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; +import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; +import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; +import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; + +/** + * A pattern-specific query specification that can instantiate GenericPatternMatcher in a type-safe way. + * + *

Original source: + *

+ *         private pattern resourceRequirement(Host : HostInstance, App : ApplicationInstance, Req : ResourceRequirement) {
+ *         	ApplicationInstance.allocatedTo(App, Host);
+ *         	ApplicationInstance.type.requirements(App, Req);
+ *         	HostInstance.type(Host, HostType);
+ *         	ResourceRequirement.hostType(Req, HostType);
+ *         }
+ * 
+ * + * @see GenericPatternMatcher + * @see GenericPatternMatch + * + */ +@SuppressWarnings("all") +public final class ResourceRequirement extends BaseGeneratedEMFQuerySpecificationWithGenericMatcher { + private ResourceRequirement() { + super(GeneratedPQuery.INSTANCE); + } + + /** + * @return the singleton instance of the query specification + * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded + * + */ + public static ResourceRequirement instance() { + try{ + return LazyHolder.INSTANCE; + } catch (ExceptionInInitializerError err) { + throw processInitializerError(err); + } + } + + /** + * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.ResourceRequirement (visibility: PUBLIC, simpleName: ResourceRequirement, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.ResourceRequirement, deprecated: ) (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 + * not at the class load time of the outer class, + * but rather at the first call to {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.ResourceRequirement (visibility: PUBLIC, simpleName: ResourceRequirement, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.ResourceRequirement, deprecated: ) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}. + * + *

This workaround is required e.g. to support recursion. + * + */ + private static class LazyHolder { + private static final ResourceRequirement INSTANCE = new ResourceRequirement(); + + /** + * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. + * This initialization order is required to support indirect recursion. + * + *

The static initializer is defined using a helper field to work around limitations of the code generator. + * + */ + private static final Object STATIC_INITIALIZER = ensureInitialized(); + + public static Object ensureInitialized() { + INSTANCE.ensureInitializedInternal(); + return null; + } + } + + private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { + private static final ResourceRequirement.GeneratedPQuery INSTANCE = new GeneratedPQuery(); + + 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); + + 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); + + 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); + + private final List parameters = Arrays.asList(parameter_Host, parameter_App, parameter_Req); + + private GeneratedPQuery() { + super(PVisibility.PRIVATE); + } + + @Override + public String getFullyQualifiedName() { + return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.resourceRequirement"; + } + + @Override + public List getParameterNames() { + return Arrays.asList("Host","App","Req"); + } + + @Override + public List getParameters() { + return parameters; + } + + @Override + public Set doGetContainedBodies() { + setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); + Set bodies = new LinkedHashSet<>(); + { + PBody body = new PBody(this); + PVariable var_Host = body.getOrCreateVariableByName("Host"); + PVariable var_App = body.getOrCreateVariableByName("App"); + PVariable var_Req = body.getOrCreateVariableByName("Req"); + PVariable var_HostType = body.getOrCreateVariableByName("HostType"); + new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); + new TypeConstraint(body, Tuples.flatTupleOf(var_App), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance"))); + new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ResourceRequirement"))); + body.setSymbolicParameters(Arrays.asList( + new ExportedParameter(body, var_Host, parameter_Host), + new ExportedParameter(body, var_App, parameter_App), + new ExportedParameter(body, var_Req, parameter_Req) + )); + // ApplicationInstance.allocatedTo(App, Host) + new TypeConstraint(body, Tuples.flatTupleOf(var_App), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance"))); + PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); + new TypeConstraint(body, Tuples.flatTupleOf(var_App, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ApplicationInstance", "allocatedTo"))); + new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); + new Equality(body, var__virtual_0_, var_Host); + // ApplicationInstance.type.requirements(App, Req) + new TypeConstraint(body, Tuples.flatTupleOf(var_App), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance"))); + PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); + new TypeConstraint(body, Tuples.flatTupleOf(var_App, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ApplicationInstance", "type"))); + new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationType"))); + PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}"); + new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_, var__virtual_2_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ApplicationType", "requirements"))); + new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ResourceRequirement"))); + new Equality(body, var__virtual_2_, var_Req); + // HostInstance.type(Host, HostType) + new TypeConstraint(body, Tuples.flatTupleOf(var_Host), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); + PVariable var__virtual_3_ = body.getOrCreateVariableByName(".virtual{3}"); + new TypeConstraint(body, Tuples.flatTupleOf(var_Host, var__virtual_3_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "HostInstance", "type"))); + new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_3_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostType"))); + new Equality(body, var__virtual_3_, var_HostType); + // ResourceRequirement.hostType(Req, HostType) + new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ResourceRequirement"))); + PVariable var__virtual_4_ = body.getOrCreateVariableByName(".virtual{4}"); + new TypeConstraint(body, Tuples.flatTupleOf(var_Req, var__virtual_4_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ResourceRequirement", "hostType"))); + new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_4_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostType"))); + new Equality(body, var__virtual_4_, var_HostType); + bodies.add(body); + } + return bodies; + } + } +} 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 @@ +/** + * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql + */ +package hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal; + +import java.util.Arrays; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; +import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecificationWithGenericMatcher; +import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; +import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; +import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; +import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; +import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; +import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; +import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; +import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; + +/** + * A pattern-specific query specification that can instantiate GenericPatternMatcher in a type-safe way. + * + *

Original source: + *

+ *         private pattern satisfyingInstance(Req : Requirement, App : ApplicationInstance) {
+ *         	Requirement.instances(Req, App);
+ *         	Requirement.type(Req, Type);
+ *         	ApplicationInstance.type(App, Type);
+ *         }
+ * 
+ * + * @see GenericPatternMatcher + * @see GenericPatternMatch + * + */ +@SuppressWarnings("all") +public final class SatisfyingInstance extends BaseGeneratedEMFQuerySpecificationWithGenericMatcher { + private SatisfyingInstance() { + super(GeneratedPQuery.INSTANCE); + } + + /** + * @return the singleton instance of the query specification + * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded + * + */ + public static SatisfyingInstance instance() { + try{ + return LazyHolder.INSTANCE; + } catch (ExceptionInInitializerError err) { + throw processInitializerError(err); + } + } + + /** + * 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: ) (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 + * not at the class load time of the outer class, + * 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: ) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}. + * + *

This workaround is required e.g. to support recursion. + * + */ + private static class LazyHolder { + private static final SatisfyingInstance INSTANCE = new SatisfyingInstance(); + + /** + * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. + * This initialization order is required to support indirect recursion. + * + *

The static initializer is defined using a helper field to work around limitations of the code generator. + * + */ + private static final Object STATIC_INITIALIZER = ensureInitialized(); + + public static Object ensureInitialized() { + INSTANCE.ensureInitializedInternal(); + return null; + } + } + + private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { + private static final SatisfyingInstance.GeneratedPQuery INSTANCE = new GeneratedPQuery(); + + 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); + + 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); + + private final List parameters = Arrays.asList(parameter_Req, parameter_App); + + private GeneratedPQuery() { + super(PVisibility.PRIVATE); + } + + @Override + public String getFullyQualifiedName() { + return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.satisfyingInstance"; + } + + @Override + public List getParameterNames() { + return Arrays.asList("Req","App"); + } + + @Override + public List getParameters() { + return parameters; + } + + @Override + public Set doGetContainedBodies() { + setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); + Set bodies = new LinkedHashSet<>(); + { + PBody body = new PBody(this); + PVariable var_Req = body.getOrCreateVariableByName("Req"); + PVariable var_App = body.getOrCreateVariableByName("App"); + PVariable var_Type = body.getOrCreateVariableByName("Type"); + new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "Requirement"))); + new TypeConstraint(body, Tuples.flatTupleOf(var_App), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance"))); + body.setSymbolicParameters(Arrays.asList( + new ExportedParameter(body, var_Req, parameter_Req), + new ExportedParameter(body, var_App, parameter_App) + )); + // Requirement.instances(Req, App) + new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "Requirement"))); + PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); + new TypeConstraint(body, Tuples.flatTupleOf(var_Req, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "Requirement", "instances"))); + new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance"))); + new Equality(body, var__virtual_0_, var_App); + // Requirement.type(Req, Type) + new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "Requirement"))); + PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); + new TypeConstraint(body, Tuples.flatTupleOf(var_Req, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "Requirement", "type"))); + new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationType"))); + new Equality(body, var__virtual_1_, var_Type); + // ApplicationInstance.type(App, Type) + new TypeConstraint(body, Tuples.flatTupleOf(var_App), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance"))); + PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}"); + new TypeConstraint(body, Tuples.flatTupleOf(var_App, var__virtual_2_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ApplicationInstance", "type"))); + new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationType"))); + new Equality(body, var__virtual_2_, var_Type); + bodies.add(body); + } + return bodies; + } + } +} -- cgit v1.2.3-54-g00ecf