From fd3684b5440dacca0c4bf4be15930555a79e2100 Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Tue, 21 May 2019 17:00:01 -0400 Subject: VIATRA DSE and COIN-OR CBC implementations of CPS case study --- .../inf/dslreasoner/domains/cps/queries/.gitignore | 10 + .../dslreasoner/domains/cps/queries/Allocate.java | 862 +++++++++++++++++++++ .../AllocationWithoutResourceRequirement.java | 2 +- .../domains/cps/queries/AvailableHdd.java | 743 ------------------ .../domains/cps/queries/AvailableMemory.java | 743 ------------------ .../domains/cps/queries/AverageFreeHddMetric.java | 4 + .../cps/queries/AverageFreeMemoryMetric.java | 12 + .../domains/cps/queries/CostMetric.java | 4 + .../domains/cps/queries/CpsApplications.java | 705 ----------------- .../dslreasoner/domains/cps/queries/CpsCost.java | 2 +- .../dslreasoner/domains/cps/queries/CpsHosts.java | 705 ----------------- .../domains/cps/queries/CpsQueries.java | 124 +-- .../domains/cps/queries/CreateHostInstance.java | 553 +++++++++++++ .../domains/cps/queries/GuidanceObjective.java | 591 ++++++++++++++ .../domains/cps/queries/NotEnoughAvailableHdd.java | 2 +- .../cps/queries/NotEnoughAvailableMemory.java | 2 +- .../domains/cps/queries/RemoveHostInstance.java | 579 ++++++++++++++ .../domains/cps/queries/ResourceRequirement.java | 829 ++++++++++++++++++++ .../dslreasoner/domains/cps/queries/TotalHdd.java | 706 ----------------- .../domains/cps/queries/TotalMemory.java | 706 ----------------- .../domains/cps/queries/UnallocateAppInstance.java | 541 +++++++++++++ .../domains/cps/queries/internal/.gitignore | 9 + .../domains/cps/queries/internal/AvailableHdd.java | 178 +++++ .../cps/queries/internal/AvailableMemory.java | 178 +++++ .../cps/queries/internal/CpsApplications.java | 141 ++++ .../domains/cps/queries/internal/CpsHosts.java | 141 ++++ .../cps/queries/internal/CpsQueriesAll.java | 38 +- .../cps/queries/internal/FreeHddPercentage.java | 4 +- .../cps/queries/internal/FreeMemoryPercentage.java | 4 +- .../cps/queries/internal/HddRequirement.java | 2 +- .../cps/queries/internal/HostInstanceCost.java | 2 +- .../cps/queries/internal/MemoryRequirement.java | 2 +- .../cps/queries/internal/NoHostToAllocateTo.java | 135 ++++ .../cps/queries/internal/RequiredAppInstances.java | 181 +++++ .../cps/queries/internal/ResourceRequirement.java | 168 ---- .../domains/cps/queries/internal/TotalHdd.java | 143 ++++ .../domains/cps/queries/internal/TotalMemory.java | 143 ++++ .../queries/internal/UnallocatedAppInstance.java | 172 ++++ 38 files changed, 5510 insertions(+), 4556 deletions(-) create mode 100644 Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/Allocate.java delete mode 100644 Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/AvailableHdd.java delete mode 100644 Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/AvailableMemory.java delete mode 100644 Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsApplications.java delete 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/CreateHostInstance.java create mode 100644 Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/GuidanceObjective.java create mode 100644 Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/RemoveHostInstance.java create mode 100644 Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/ResourceRequirement.java delete mode 100644 Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/TotalHdd.java delete 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/UnallocateAppInstance.java create mode 100644 Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/AvailableHdd.java create mode 100644 Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/AvailableMemory.java create mode 100644 Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/CpsApplications.java create mode 100644 Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/CpsHosts.java create mode 100644 Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/NoHostToAllocateTo.java create mode 100644 Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/RequiredAppInstances.java delete 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/TotalHdd.java create mode 100644 Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/TotalMemory.java create mode 100644 Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/UnallocatedAppInstance.java (limited to 'Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit') 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 index b634f74b..4e059848 100644 --- 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 @@ -15,3 +15,13 @@ /.CostMetric.java._trace /.CpsCost.java._trace /.RedundantInstancesOnSameHost.java._trace +/.Allocate.java._trace +/.CpsTransformationRules.java._trace +/.ResourceRequirement.java._trace +/.CreateInstance.java._trace +/.CreateHostInstance.java._trace +/.UnallocatedAppInstance.java._trace +/.RequiredAppInstances.java._trace +/.GuidanceObjective.java._trace +/.RemoveHostInstance.java._trace +/.UnallocateAppInstance.java._trace diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/Allocate.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/Allocate.java new file mode 100644 index 00000000..830dc8a0 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/Allocate.java @@ -0,0 +1,862 @@ +/** + * 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.AvailableHdd; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.AvailableMemory; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.UnallocatedAppInstance; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +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.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.NegativePatternCall; +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: + *

+ *         //
+ *         // Transformation rule preconditions for rule-based DSE
+ *         //
+ *         
+ *         pattern allocate(App : ApplicationInstance, Host : HostInstance) {
+ *         	ApplicationInstance.type.requirements(App, Req);
+ *         	ResourceRequirement.hostType.instances(Req, Host);
+ *         	find unallocatedAppInstance(App);
+ *         	find availableMemory(Host, AvailableMem);
+ *         	find availableHdd(Host, AvailableHdd);
+ *         	ResourceRequirement.requiredMemory(Req, RequiredMem);
+ *         	ResourceRequirement.requiredHdd(Req, RequiredHdd);
+ *         	check(AvailableMem {@literal >}= RequiredMem);
+ *         	check(AvailableHdd {@literal >}= RequiredHdd);
+ *         	neg ApplicationInstance.requirement.instances.allocatedTo(App, Host);
+ *         }
+ * 
+ * + * @see Matcher + * @see Match + * + */ +@SuppressWarnings("all") +public final class Allocate extends BaseGeneratedEMFQuerySpecification { + /** + * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.allocate 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 ApplicationInstance fApp; + + private HostInstance fHost; + + private static List parameterNames = makeImmutableList("App", "Host"); + + private Match(final ApplicationInstance pApp, final HostInstance pHost) { + this.fApp = pApp; + this.fHost = pHost; + } + + @Override + public Object get(final String parameterName) { + if ("App".equals(parameterName)) return this.fApp; + if ("Host".equals(parameterName)) return this.fHost; + return null; + } + + public ApplicationInstance getApp() { + return this.fApp; + } + + public HostInstance getHost() { + return this.fHost; + } + + @Override + public boolean set(final String parameterName, final Object newValue) { + if (!isMutable()) throw new java.lang.UnsupportedOperationException(); + if ("App".equals(parameterName) ) { + this.fApp = (ApplicationInstance) newValue; + return true; + } + if ("Host".equals(parameterName) ) { + this.fHost = (HostInstance) newValue; + return true; + } + return false; + } + + public void setApp(final ApplicationInstance pApp) { + if (!isMutable()) throw new java.lang.UnsupportedOperationException(); + this.fApp = pApp; + } + + 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.allocate"; + } + + @Override + public List parameterNames() { + return Allocate.Match.parameterNames; + } + + @Override + public Object[] toArray() { + return new Object[]{fApp, fHost}; + } + + @Override + public Allocate.Match toImmutable() { + return isMutable() ? newMatch(fApp, fHost) : this; + } + + @Override + public String prettyPrint() { + StringBuilder result = new StringBuilder(); + result.append("\"App\"=" + prettyPrintValue(fApp) + ", "); + result.append("\"Host\"=" + prettyPrintValue(fHost)); + return result.toString(); + } + + @Override + public int hashCode() { + return Objects.hash(fApp, fHost); + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) + return true; + if (obj == null) { + return false; + } + if ((obj instanceof Allocate.Match)) { + Allocate.Match other = (Allocate.Match) obj; + return Objects.equals(fApp, other.fApp) && 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 Allocate specification() { + return Allocate.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 Allocate.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 pApp the fixed value of pattern parameter App, or null if not bound. + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @return the new, mutable (partial) match object. + * + */ + public static Allocate.Match newMutableMatch(final ApplicationInstance pApp, final HostInstance pHost) { + return new Mutable(pApp, 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 pApp the fixed value of pattern parameter App, or null if not bound. + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @return the (partial) match object. + * + */ + public static Allocate.Match newMatch(final ApplicationInstance pApp, final HostInstance pHost) { + return new Immutable(pApp, pHost); + } + + private static final class Mutable extends Allocate.Match { + Mutable(final ApplicationInstance pApp, final HostInstance pHost) { + super(pApp, pHost); + } + + @Override + public boolean isMutable() { + return true; + } + } + + private static final class Immutable extends Allocate.Match { + Immutable(final ApplicationInstance pApp, final HostInstance pHost) { + super(pApp, pHost); + } + + @Override + public boolean isMutable() { + return false; + } + } + } + + /** + * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.allocate 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: + *

+   * //
+   * // Transformation rule preconditions for rule-based DSE
+   * //
+   * 
+   * pattern allocate(App : ApplicationInstance, Host : HostInstance) {
+   * 	ApplicationInstance.type.requirements(App, Req);
+   * 	ResourceRequirement.hostType.instances(Req, Host);
+   * 	find unallocatedAppInstance(App);
+   * 	find availableMemory(Host, AvailableMem);
+   * 	find availableHdd(Host, AvailableHdd);
+   * 	ResourceRequirement.requiredMemory(Req, RequiredMem);
+   * 	ResourceRequirement.requiredHdd(Req, RequiredHdd);
+   * 	check(AvailableMem {@literal >}= RequiredMem);
+   * 	check(AvailableHdd {@literal >}= RequiredHdd);
+   * 	neg ApplicationInstance.requirement.instances.allocatedTo(App, Host);
+   * }
+   * 
+ * + * @see Match + * @see Allocate + * + */ + 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 Allocate.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 Allocate.Matcher create() { + return new Matcher(); + } + + private static final int POSITION_APP = 0; + + private static final int POSITION_HOST = 1; + + private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Allocate.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 pApp the fixed value of pattern parameter App, or null if not bound. + * @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 ApplicationInstance pApp, final HostInstance pHost) { + return rawStreamAllMatches(new Object[]{pApp, 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 pApp the fixed value of pattern parameter App, or null if not bound. + * @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 ApplicationInstance pApp, final HostInstance pHost) { + return rawStreamAllMatches(new Object[]{pApp, 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 pApp the fixed value of pattern parameter App, or null if not bound. + * @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 ApplicationInstance pApp, final HostInstance pHost) { + return rawGetOneArbitraryMatch(new Object[]{pApp, 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 pApp the fixed value of pattern parameter App, or null if not bound. + * @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 ApplicationInstance pApp, final HostInstance pHost) { + return rawHasMatch(new Object[]{pApp, pHost}); + } + + /** + * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. + * @param pApp the fixed value of pattern parameter App, or null if not bound. + * @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 ApplicationInstance pApp, final HostInstance pHost) { + return rawCountMatches(new Object[]{pApp, 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 pApp the fixed value of pattern parameter App, or null if not bound. + * @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 ApplicationInstance pApp, final HostInstance pHost, final Consumer processor) { + return rawForOneArbitraryMatch(new Object[]{pApp, 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 pApp the fixed value of pattern parameter App, or null if not bound. + * @param pHost the fixed value of pattern parameter Host, or null if not bound. + * @return the (partial) match object. + * + */ + public Allocate.Match newMatch(final ApplicationInstance pApp, final HostInstance pHost) { + return Allocate.Match.newMatch(pApp, pHost); + } + + /** + * 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 Allocate.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[]{null, pHost}); + } + + /** + * 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 Allocate.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[]{null, pHost}).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 + * + */ + 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 Allocate.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[]{pApp, null}); + } + + /** + * 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 Allocate.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[]{pApp, null}).collect(Collectors.toSet()); + } + + @Override + protected Allocate.Match tupleToMatch(final Tuple t) { + try { + return Allocate.Match.newMatch((ApplicationInstance) t.get(POSITION_APP), (HostInstance) t.get(POSITION_HOST)); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in tuple not properly typed!",e); + return null; + } + } + + @Override + protected Allocate.Match arrayToMatch(final Object[] match) { + try { + return Allocate.Match.newMatch((ApplicationInstance) match[POSITION_APP], (HostInstance) match[POSITION_HOST]); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in array not properly typed!",e); + return null; + } + } + + @Override + protected Allocate.Match arrayToMatchMutable(final Object[] match) { + try { + return Allocate.Match.newMutableMatch((ApplicationInstance) match[POSITION_APP], (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 Allocate.instance(); + } + } + + private Allocate() { + super(GeneratedPQuery.INSTANCE); + } + + /** + * @return the singleton instance of the query specification + * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded + * + */ + public static Allocate instance() { + try{ + return LazyHolder.INSTANCE; + } catch (ExceptionInInitializerError err) { + throw processInitializerError(err); + } + } + + @Override + protected Allocate.Matcher instantiate(final ViatraQueryEngine engine) { + return Allocate.Matcher.on(engine); + } + + @Override + public Allocate.Matcher instantiate() { + return Allocate.Matcher.create(); + } + + @Override + public Allocate.Match newEmptyMatch() { + return Allocate.Match.newEmptyMatch(); + } + + @Override + public Allocate.Match newMatch(final Object... parameters) { + return Allocate.Match.newMatch((hu.bme.mit.inf.dslreasoner.domains.cps.ApplicationInstance) 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.Allocate (visibility: PUBLIC, simpleName: Allocate, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.Allocate, 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.Allocate (visibility: PUBLIC, simpleName: Allocate, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.Allocate, 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 Allocate INSTANCE = new Allocate(); + + /** + * 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 Allocate.GeneratedPQuery INSTANCE = new GeneratedPQuery(); + + 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_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_App, parameter_Host); + + private class Embedded_1_ApplicationInstance_requirement_instances_allocatedTo extends BaseGeneratedEMFPQuery { + private final PParameter parameter_p0 = new PParameter("p0", "hu.bme.mit.inf.dslreasoner.domains.cps.ApplicationInstance", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "ApplicationInstance")), PParameterDirection.INOUT); + + private final PParameter parameter_p1 = new PParameter("p1", "hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "HostInstance")), PParameterDirection.INOUT); + + private final List embeddedParameters = Arrays.asList(parameter_p0, parameter_p1); + + public Embedded_1_ApplicationInstance_requirement_instances_allocatedTo() { + super(PVisibility.EMBEDDED); + } + + @Override + public String getFullyQualifiedName() { + return GeneratedPQuery.this.getFullyQualifiedName() + "$Embedded_1_ApplicationInstance_requirement_instances_allocatedTo"; + } + + @Override + public List getParameters() { + return embeddedParameters; + } + + @Override + public Set doGetContainedBodies() { + PBody body = new PBody(this); + PVariable var_p0 = body.getOrCreateVariableByName("p0"); + PVariable var_p1 = body.getOrCreateVariableByName("p1"); + body.setSymbolicParameters(Arrays.asList( + new ExportedParameter(body, var_p0, parameter_p0), + new ExportedParameter(body, var_p1, parameter_p1) + )); + // ApplicationInstance.requirement.instances.allocatedTo(App, Host) + new TypeConstraint(body, Tuples.flatTupleOf(var_p0), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance"))); + PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); + new TypeConstraint(body, Tuples.flatTupleOf(var_p0, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ApplicationInstance", "requirement"))); + new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "Requirement"))); + 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", "Requirement", "instances"))); + new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance"))); + 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", "ApplicationInstance", "allocatedTo"))); + new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); + new Equality(body, var__virtual_2_, var_p1); + return Collections.singleton(body); + } + } + + private GeneratedPQuery() { + super(PVisibility.PUBLIC); + } + + @Override + public String getFullyQualifiedName() { + return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.allocate"; + } + + @Override + public List getParameterNames() { + return Arrays.asList("App","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_App = body.getOrCreateVariableByName("App"); + PVariable var_Host = body.getOrCreateVariableByName("Host"); + PVariable var_Req = body.getOrCreateVariableByName("Req"); + PVariable var_AvailableMem = body.getOrCreateVariableByName("AvailableMem"); + PVariable var_AvailableHdd = body.getOrCreateVariableByName("AvailableHdd"); + PVariable var_RequiredMem = body.getOrCreateVariableByName("RequiredMem"); + PVariable var_RequiredHdd = body.getOrCreateVariableByName("RequiredHdd"); + new TypeConstraint(body, Tuples.flatTupleOf(var_App), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance"))); + 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_App, parameter_App), + new ExportedParameter(body, var_Host, parameter_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_0_ = body.getOrCreateVariableByName(".virtual{0}"); + new TypeConstraint(body, Tuples.flatTupleOf(var_App, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ApplicationInstance", "type"))); + 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", "requirements"))); + new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ResourceRequirement"))); + new Equality(body, var__virtual_1_, var_Req); + // ResourceRequirement.hostType.instances(Req, Host) + new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ResourceRequirement"))); + PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}"); + new TypeConstraint(body, Tuples.flatTupleOf(var_Req, var__virtual_2_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ResourceRequirement", "hostType"))); + new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostType"))); + PVariable var__virtual_3_ = body.getOrCreateVariableByName(".virtual{3}"); + new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_, var__virtual_3_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "HostType", "instances"))); + new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_3_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); + new Equality(body, var__virtual_3_, var_Host); + // find unallocatedAppInstance(App) + new PositivePatternCall(body, Tuples.flatTupleOf(var_App), UnallocatedAppInstance.instance().getInternalQueryRepresentation()); + // find availableMemory(Host, AvailableMem) + new PositivePatternCall(body, Tuples.flatTupleOf(var_Host, var_AvailableMem), AvailableMemory.instance().getInternalQueryRepresentation()); + // find availableHdd(Host, AvailableHdd) + new PositivePatternCall(body, Tuples.flatTupleOf(var_Host, var_AvailableHdd), AvailableHdd.instance().getInternalQueryRepresentation()); + // ResourceRequirement.requiredMemory(Req, RequiredMem) + 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", "requiredMemory"))); + new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_4_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt"))); + new Equality(body, var__virtual_4_, var_RequiredMem); + // ResourceRequirement.requiredHdd(Req, RequiredHdd) + new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ResourceRequirement"))); + PVariable var__virtual_5_ = body.getOrCreateVariableByName(".virtual{5}"); + new TypeConstraint(body, Tuples.flatTupleOf(var_Req, var__virtual_5_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ResourceRequirement", "requiredHdd"))); + new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_5_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.eclipse.org/emf/2002/Ecore", "EInt"))); + new Equality(body, var__virtual_5_, var_RequiredHdd); + // check(AvailableMem >= RequiredMem) + new ExpressionEvaluation(body, new IExpressionEvaluator() { + + @Override + public String getShortDescription() { + return "Expression evaluation from pattern allocate"; + } + + @Override + public Iterable getInputParameterNames() { + return Arrays.asList("AvailableMem", "RequiredMem");} + + @Override + public Object evaluateExpression(IValueProvider provider) throws Exception { + Integer AvailableMem = (Integer) provider.getValue("AvailableMem"); + Integer RequiredMem = (Integer) provider.getValue("RequiredMem"); + return evaluateExpression_1_1(AvailableMem, RequiredMem); + } + }, null); + // check(AvailableHdd >= RequiredHdd) + new ExpressionEvaluation(body, new IExpressionEvaluator() { + + @Override + public String getShortDescription() { + return "Expression evaluation from pattern allocate"; + } + + @Override + public Iterable getInputParameterNames() { + return Arrays.asList("AvailableHdd", "RequiredHdd");} + + @Override + public Object evaluateExpression(IValueProvider provider) throws Exception { + Integer AvailableHdd = (Integer) provider.getValue("AvailableHdd"); + Integer RequiredHdd = (Integer) provider.getValue("RequiredHdd"); + return evaluateExpression_1_2(AvailableHdd, RequiredHdd); + } + }, null); + // neg ApplicationInstance.requirement.instances.allocatedTo(App, Host) + new NegativePatternCall(body, Tuples.flatTupleOf(var_App, var_Host), new Allocate.GeneratedPQuery.Embedded_1_ApplicationInstance_requirement_instances_allocatedTo()); + bodies.add(body); + } + return bodies; + } + } + + private static boolean evaluateExpression_1_1(final Integer AvailableMem, final Integer RequiredMem) { + boolean _greaterEqualsThan = (AvailableMem.compareTo(RequiredMem) >= 0); + return _greaterEqualsThan; + } + + private static boolean evaluateExpression_1_2(final Integer AvailableHdd, final Integer RequiredHdd) { + boolean _greaterEqualsThan = (AvailableHdd.compareTo(RequiredHdd) >= 0); + return _greaterEqualsThan; + } +} 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 index be7488b6..6da5f76d 100644 --- 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 @@ -5,7 +5,7 @@ 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 hu.bme.mit.inf.dslreasoner.domains.cps.queries.ResourceRequirement; import java.util.Arrays; import java.util.Collection; import java.util.LinkedHashSet; 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 deleted file mode 100644 index 22821c4a..00000000 --- a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/AvailableHdd.java +++ /dev/null @@ -1,743 +0,0 @@ -/** - * 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 deleted file mode 100644 index 930a24ba..00000000 --- a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/AvailableMemory.java +++ /dev/null @@ -1,743 +0,0 @@ -/** - * 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 index 59d4ad27..bc38b60b 100644 --- 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 @@ -43,6 +43,8 @@ import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; * *

Original source: *

+ *         // Free HDD
+ *         
  *         pattern averageFreeHddMetric(Average : java Double) {
  *         	Average == avg find freeHddPercentage(_, #_);
  *         }
@@ -226,6 +228,8 @@ public final class AverageFreeHddMetric extends BaseGeneratedEMFQuerySpecificati
    * 
    * 

Original source: *

+   * // Free HDD
+   * 
    * pattern averageFreeHddMetric(Average : java Double) {
    * 	Average == avg find freeHddPercentage(_, #_);
    * }
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
index a0d087f4..98974ea5 100644
--- 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
@@ -43,6 +43,12 @@ import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
  * 
  * 

Original source: *

+ *         //
+ *         // Metrics
+ *         //
+ *         
+ *         // Free memory
+ *         
  *         pattern averageFreeMemoryMetric(Average : java Double) {
  *         	Average == avg find freeMemoryPercentage(_, #_);
  *         }
@@ -226,6 +232,12 @@ public final class AverageFreeMemoryMetric extends BaseGeneratedEMFQuerySpecific
    * 
    * 

Original source: *

+   * //
+   * // Metrics
+   * //
+   * 
+   * // Free memory
+   * 
    * pattern averageFreeMemoryMetric(Average : java Double) {
    * 	Average == avg find freeMemoryPercentage(_, #_);
    * }
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
index 4d8ca4cc..bf886ec0 100644
--- 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
@@ -43,6 +43,8 @@ import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
  * 
  * 

Original source: *

+ *         // Total cost
+ *         
  *         pattern costMetric(Cost : java Integer) {
  *         	Cost == sum find cpsCost(_, #_);
  *         }
@@ -226,6 +228,8 @@ public final class CostMetric extends BaseGeneratedEMFQuerySpecificationOriginal source:
    * 
+   * // Total cost
+   * 
    * pattern costMetric(Cost : java Integer) {
    * 	Cost == sum find cpsCost(_, #_);
    * }
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
deleted file mode 100644
index 2c20b38e..00000000
--- a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsApplications.java
+++ /dev/null
@@ -1,705 +0,0 @@
-/**
- * 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 index 169a30e5..fc90ef12 100644 --- 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 @@ -4,7 +4,7 @@ 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.CpsApplications; import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.HostInstanceCost; import java.util.Arrays; import java.util.Collection; 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 deleted file mode 100644 index e1abf758..00000000 --- a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsHosts.java +++ /dev/null @@ -1,705 +0,0 @@ -/** - * 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 index 916f35f7..c889fbe0 100644 --- 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 @@ -3,22 +3,22 @@ */ package hu.bme.mit.inf.dslreasoner.domains.cps.queries; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.Allocate; 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.CreateHostInstance; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.GuidanceObjective; 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.RedundantInstancesOnSameHost; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.RemoveHostInstance; 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.ResourceRequirement; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.UnallocateAppInstance; import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedPatternGroup; @@ -30,12 +30,7 @@ import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedPatternGroup; * 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
  • + *
  • resourceRequirement
  • *
  • allocationWithoutResourceRequirement
  • *
  • notEnoughAvailableMemory
  • *
  • notEnoughAvailableHdd
  • @@ -46,6 +41,11 @@ import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedPatternGroup; *
  • averageFreeHddMetric
  • *
  • costMetric
  • *
  • cpsCost
  • + *
  • allocate
  • + *
  • unallocateAppInstance
  • + *
  • createHostInstance
  • + *
  • removeHostInstance
  • + *
  • guidanceObjective
  • *
* * @see IQueryGroup @@ -70,12 +70,7 @@ public final class CpsQueries extends BaseGeneratedPatternGroup { 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(ResourceRequirement.instance()); querySpecifications.add(AllocationWithoutResourceRequirement.instance()); querySpecifications.add(NotEnoughAvailableMemory.instance()); querySpecifications.add(NotEnoughAvailableHdd.instance()); @@ -86,54 +81,19 @@ public final class CpsQueries extends BaseGeneratedPatternGroup { querySpecifications.add(AverageFreeHddMetric.instance()); querySpecifications.add(CostMetric.instance()); querySpecifications.add(CpsCost.instance()); + querySpecifications.add(Allocate.instance()); + querySpecifications.add(UnallocateAppInstance.instance()); + querySpecifications.add(CreateHostInstance.instance()); + querySpecifications.add(RemoveHostInstance.instance()); + querySpecifications.add(GuidanceObjective.instance()); } - public CpsApplications getCpsApplications() { - return CpsApplications.instance(); + public ResourceRequirement getResourceRequirement() { + return ResourceRequirement.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 ResourceRequirement.Matcher getResourceRequirement(final ViatraQueryEngine engine) { + return ResourceRequirement.Matcher.on(engine); } public AllocationWithoutResourceRequirement getAllocationWithoutResourceRequirement() { @@ -215,4 +175,44 @@ public final class CpsQueries extends BaseGeneratedPatternGroup { public CpsCost.Matcher getCpsCost(final ViatraQueryEngine engine) { return CpsCost.Matcher.on(engine); } + + public Allocate getAllocate() { + return Allocate.instance(); + } + + public Allocate.Matcher getAllocate(final ViatraQueryEngine engine) { + return Allocate.Matcher.on(engine); + } + + public UnallocateAppInstance getUnallocateAppInstance() { + return UnallocateAppInstance.instance(); + } + + public UnallocateAppInstance.Matcher getUnallocateAppInstance(final ViatraQueryEngine engine) { + return UnallocateAppInstance.Matcher.on(engine); + } + + public CreateHostInstance getCreateHostInstance() { + return CreateHostInstance.instance(); + } + + public CreateHostInstance.Matcher getCreateHostInstance(final ViatraQueryEngine engine) { + return CreateHostInstance.Matcher.on(engine); + } + + public RemoveHostInstance getRemoveHostInstance() { + return RemoveHostInstance.instance(); + } + + public RemoveHostInstance.Matcher getRemoveHostInstance(final ViatraQueryEngine engine) { + return RemoveHostInstance.Matcher.on(engine); + } + + public GuidanceObjective getGuidanceObjective() { + return GuidanceObjective.instance(); + } + + public GuidanceObjective.Matcher getGuidanceObjective(final ViatraQueryEngine engine) { + return GuidanceObjective.Matcher.on(engine); + } } diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CreateHostInstance.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CreateHostInstance.java new file mode 100644 index 00000000..f475c9e9 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CreateHostInstance.java @@ -0,0 +1,553 @@ +/** + * 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.HostType; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.UnallocatedAppInstance; +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.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.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 createHostInstance(HostType : HostType) {
+ *         	find unallocatedAppInstance(App);
+ *         	ApplicationInstance.type.requirements.hostType(App, HostType);
+ *         }
+ * 
+ * + * @see Matcher + * @see Match + * + */ +@SuppressWarnings("all") +public final class CreateHostInstance extends BaseGeneratedEMFQuerySpecification { + /** + * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.createHostInstance 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 HostType fHostType; + + private static List parameterNames = makeImmutableList("HostType"); + + private Match(final HostType pHostType) { + this.fHostType = pHostType; + } + + @Override + public Object get(final String parameterName) { + if ("HostType".equals(parameterName)) return this.fHostType; + return null; + } + + public HostType getHostType() { + return this.fHostType; + } + + @Override + public boolean set(final String parameterName, final Object newValue) { + if (!isMutable()) throw new java.lang.UnsupportedOperationException(); + if ("HostType".equals(parameterName) ) { + this.fHostType = (HostType) newValue; + return true; + } + return false; + } + + public void setHostType(final HostType pHostType) { + if (!isMutable()) throw new java.lang.UnsupportedOperationException(); + this.fHostType = pHostType; + } + + @Override + public String patternName() { + return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.createHostInstance"; + } + + @Override + public List parameterNames() { + return CreateHostInstance.Match.parameterNames; + } + + @Override + public Object[] toArray() { + return new Object[]{fHostType}; + } + + @Override + public CreateHostInstance.Match toImmutable() { + return isMutable() ? newMatch(fHostType) : this; + } + + @Override + public String prettyPrint() { + StringBuilder result = new StringBuilder(); + result.append("\"HostType\"=" + prettyPrintValue(fHostType)); + return result.toString(); + } + + @Override + public int hashCode() { + return Objects.hash(fHostType); + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) + return true; + if (obj == null) { + return false; + } + if ((obj instanceof CreateHostInstance.Match)) { + CreateHostInstance.Match other = (CreateHostInstance.Match) obj; + return Objects.equals(fHostType, other.fHostType); + } 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 CreateHostInstance specification() { + return CreateHostInstance.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 CreateHostInstance.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 pHostType the fixed value of pattern parameter HostType, or null if not bound. + * @return the new, mutable (partial) match object. + * + */ + public static CreateHostInstance.Match newMutableMatch(final HostType pHostType) { + return new Mutable(pHostType); + } + + /** + * 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 pHostType the fixed value of pattern parameter HostType, or null if not bound. + * @return the (partial) match object. + * + */ + public static CreateHostInstance.Match newMatch(final HostType pHostType) { + return new Immutable(pHostType); + } + + private static final class Mutable extends CreateHostInstance.Match { + Mutable(final HostType pHostType) { + super(pHostType); + } + + @Override + public boolean isMutable() { + return true; + } + } + + private static final class Immutable extends CreateHostInstance.Match { + Immutable(final HostType pHostType) { + super(pHostType); + } + + @Override + public boolean isMutable() { + return false; + } + } + } + + /** + * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.createHostInstance 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 createHostInstance(HostType : HostType) {
+   * 	find unallocatedAppInstance(App);
+   * 	ApplicationInstance.type.requirements.hostType(App, HostType);
+   * }
+   * 
+ * + * @see Match + * @see CreateHostInstance + * + */ + 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 CreateHostInstance.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 CreateHostInstance.Matcher create() { + return new Matcher(); + } + + private static final int POSITION_HOSTTYPE = 0; + + private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(CreateHostInstance.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 pHostType the fixed value of pattern parameter HostType, or null if not bound. + * @return matches represented as a Match object. + * + */ + public Collection getAllMatches(final HostType pHostType) { + return rawStreamAllMatches(new Object[]{pHostType}).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 pHostType the fixed value of pattern parameter HostType, or null if not bound. + * @return a stream of matches represented as a Match object. + * + */ + public Stream streamAllMatches(final HostType pHostType) { + return rawStreamAllMatches(new Object[]{pHostType}); + } + + /** + * 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 pHostType the fixed value of pattern parameter HostType, or null if not bound. + * @return a match represented as a Match object, or null if no match is found. + * + */ + public Optional getOneArbitraryMatch(final HostType pHostType) { + return rawGetOneArbitraryMatch(new Object[]{pHostType}); + } + + /** + * 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 pHostType the fixed value of pattern parameter HostType, or null if not bound. + * @return true if the input is a valid (partial) match of the pattern. + * + */ + public boolean hasMatch(final HostType pHostType) { + return rawHasMatch(new Object[]{pHostType}); + } + + /** + * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. + * @param pHostType the fixed value of pattern parameter HostType, or null if not bound. + * @return the number of pattern matches found. + * + */ + public int countMatches(final HostType pHostType) { + return rawCountMatches(new Object[]{pHostType}); + } + + /** + * 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 pHostType the fixed value of pattern parameter HostType, 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 HostType pHostType, final Consumer processor) { + return rawForOneArbitraryMatch(new Object[]{pHostType}, 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 pHostType the fixed value of pattern parameter HostType, or null if not bound. + * @return the (partial) match object. + * + */ + public CreateHostInstance.Match newMatch(final HostType pHostType) { + return CreateHostInstance.Match.newMatch(pHostType); + } + + /** + * Retrieve the set of values that occur in matches for HostType. + * @return the Set of all values or empty set if there are no matches + * + */ + protected Stream rawStreamAllValuesOfHostType(final Object[] parameters) { + return rawStreamAllValues(POSITION_HOSTTYPE, parameters).map(HostType.class::cast); + } + + /** + * Retrieve the set of values that occur in matches for HostType. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfHostType() { + return rawStreamAllValuesOfHostType(emptyArray()).collect(Collectors.toSet()); + } + + /** + * Retrieve the set of values that occur in matches for HostType. + * @return the Set of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfHostType() { + return rawStreamAllValuesOfHostType(emptyArray()); + } + + @Override + protected CreateHostInstance.Match tupleToMatch(final Tuple t) { + try { + return CreateHostInstance.Match.newMatch((HostType) t.get(POSITION_HOSTTYPE)); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in tuple not properly typed!",e); + return null; + } + } + + @Override + protected CreateHostInstance.Match arrayToMatch(final Object[] match) { + try { + return CreateHostInstance.Match.newMatch((HostType) match[POSITION_HOSTTYPE]); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in array not properly typed!",e); + return null; + } + } + + @Override + protected CreateHostInstance.Match arrayToMatchMutable(final Object[] match) { + try { + return CreateHostInstance.Match.newMutableMatch((HostType) match[POSITION_HOSTTYPE]); + } 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 CreateHostInstance.instance(); + } + } + + private CreateHostInstance() { + super(GeneratedPQuery.INSTANCE); + } + + /** + * @return the singleton instance of the query specification + * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded + * + */ + public static CreateHostInstance instance() { + try{ + return LazyHolder.INSTANCE; + } catch (ExceptionInInitializerError err) { + throw processInitializerError(err); + } + } + + @Override + protected CreateHostInstance.Matcher instantiate(final ViatraQueryEngine engine) { + return CreateHostInstance.Matcher.on(engine); + } + + @Override + public CreateHostInstance.Matcher instantiate() { + return CreateHostInstance.Matcher.create(); + } + + @Override + public CreateHostInstance.Match newEmptyMatch() { + return CreateHostInstance.Match.newEmptyMatch(); + } + + @Override + public CreateHostInstance.Match newMatch(final Object... parameters) { + return CreateHostInstance.Match.newMatch((hu.bme.mit.inf.dslreasoner.domains.cps.HostType) parameters[0]); + } + + /** + * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.CreateHostInstance (visibility: PUBLIC, simpleName: CreateHostInstance, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.CreateHostInstance, deprecated: ) (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.CreateHostInstance (visibility: PUBLIC, simpleName: CreateHostInstance, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.CreateHostInstance, 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 CreateHostInstance INSTANCE = new CreateHostInstance(); + + /** + * 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 CreateHostInstance.GeneratedPQuery INSTANCE = new GeneratedPQuery(); + + private final PParameter parameter_HostType = new PParameter("HostType", "hu.bme.mit.inf.dslreasoner.domains.cps.HostType", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "HostType")), PParameterDirection.INOUT); + + private final List parameters = Arrays.asList(parameter_HostType); + + private GeneratedPQuery() { + super(PVisibility.PUBLIC); + } + + @Override + public String getFullyQualifiedName() { + return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.createHostInstance"; + } + + @Override + public List getParameterNames() { + return Arrays.asList("HostType"); + } + + @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_HostType = body.getOrCreateVariableByName("HostType"); + PVariable var_App = body.getOrCreateVariableByName("App"); + new TypeConstraint(body, Tuples.flatTupleOf(var_HostType), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostType"))); + body.setSymbolicParameters(Arrays.asList( + new ExportedParameter(body, var_HostType, parameter_HostType) + )); + // find unallocatedAppInstance(App) + new PositivePatternCall(body, Tuples.flatTupleOf(var_App), UnallocatedAppInstance.instance().getInternalQueryRepresentation()); + // ApplicationInstance.type.requirements.hostType(App, HostType) + 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", "type"))); + 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", "requirements"))); + new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ResourceRequirement"))); + 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", "ResourceRequirement", "hostType"))); + new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostType"))); + new Equality(body, var__virtual_2_, 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/GuidanceObjective.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/GuidanceObjective.java new file mode 100644 index 00000000..cfed0c4b --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/GuidanceObjective.java @@ -0,0 +1,591 @@ +/** + * 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.NoHostToAllocateTo; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.RequiredAppInstances; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.UnallocatedAppInstance; +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.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.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 guidanceObjective(Value : java Integer) {
+ *         	UnallocatedInstances == count find unallocatedAppInstance(_);
+ *         	RequiredInstances == sum find requiredAppInstances(_, #_);
+ *         	NoHostToAllocate == count find noHostToAllocateTo(_);
+ *         	Value == eval(2  UnallocatedInstances + 4  RequiredInstances + NoHostToAllocate);
+ *         }
+ * 
+ * + * @see Matcher + * @see Match + * + */ +@SuppressWarnings("all") +public final class GuidanceObjective extends BaseGeneratedEMFQuerySpecification { + /** + * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.guidanceObjective 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 fValue; + + private static List parameterNames = makeImmutableList("Value"); + + private Match(final Integer pValue) { + this.fValue = pValue; + } + + @Override + public Object get(final String parameterName) { + if ("Value".equals(parameterName)) return this.fValue; + return null; + } + + public Integer getValue() { + return this.fValue; + } + + @Override + public boolean set(final String parameterName, final Object newValue) { + if (!isMutable()) throw new java.lang.UnsupportedOperationException(); + if ("Value".equals(parameterName) ) { + this.fValue = (Integer) newValue; + return true; + } + return false; + } + + public void setValue(final Integer pValue) { + if (!isMutable()) throw new java.lang.UnsupportedOperationException(); + this.fValue = pValue; + } + + @Override + public String patternName() { + return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.guidanceObjective"; + } + + @Override + public List parameterNames() { + return GuidanceObjective.Match.parameterNames; + } + + @Override + public Object[] toArray() { + return new Object[]{fValue}; + } + + @Override + public GuidanceObjective.Match toImmutable() { + return isMutable() ? newMatch(fValue) : this; + } + + @Override + public String prettyPrint() { + StringBuilder result = new StringBuilder(); + result.append("\"Value\"=" + prettyPrintValue(fValue)); + return result.toString(); + } + + @Override + public int hashCode() { + return Objects.hash(fValue); + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) + return true; + if (obj == null) { + return false; + } + if ((obj instanceof GuidanceObjective.Match)) { + GuidanceObjective.Match other = (GuidanceObjective.Match) obj; + return Objects.equals(fValue, other.fValue); + } 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 GuidanceObjective specification() { + return GuidanceObjective.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 GuidanceObjective.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 pValue the fixed value of pattern parameter Value, or null if not bound. + * @return the new, mutable (partial) match object. + * + */ + public static GuidanceObjective.Match newMutableMatch(final Integer pValue) { + return new Mutable(pValue); + } + + /** + * 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 pValue the fixed value of pattern parameter Value, or null if not bound. + * @return the (partial) match object. + * + */ + public static GuidanceObjective.Match newMatch(final Integer pValue) { + return new Immutable(pValue); + } + + private static final class Mutable extends GuidanceObjective.Match { + Mutable(final Integer pValue) { + super(pValue); + } + + @Override + public boolean isMutable() { + return true; + } + } + + private static final class Immutable extends GuidanceObjective.Match { + Immutable(final Integer pValue) { + super(pValue); + } + + @Override + public boolean isMutable() { + return false; + } + } + } + + /** + * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.guidanceObjective 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 guidanceObjective(Value : java Integer) {
+   * 	UnallocatedInstances == count find unallocatedAppInstance(_);
+   * 	RequiredInstances == sum find requiredAppInstances(_, #_);
+   * 	NoHostToAllocate == count find noHostToAllocateTo(_);
+   * 	Value == eval(2  UnallocatedInstances + 4  RequiredInstances + NoHostToAllocate);
+   * }
+   * 
+ * + * @see Match + * @see GuidanceObjective + * + */ + 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 GuidanceObjective.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 GuidanceObjective.Matcher create() { + return new Matcher(); + } + + private static final int POSITION_VALUE = 0; + + private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(GuidanceObjective.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 pValue the fixed value of pattern parameter Value, or null if not bound. + * @return matches represented as a Match object. + * + */ + public Collection getAllMatches(final Integer pValue) { + return rawStreamAllMatches(new Object[]{pValue}).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 pValue the fixed value of pattern parameter Value, or null if not bound. + * @return a stream of matches represented as a Match object. + * + */ + public Stream streamAllMatches(final Integer pValue) { + return rawStreamAllMatches(new Object[]{pValue}); + } + + /** + * 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 pValue the fixed value of pattern parameter Value, 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 pValue) { + return rawGetOneArbitraryMatch(new Object[]{pValue}); + } + + /** + * 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 pValue the fixed value of pattern parameter Value, or null if not bound. + * @return true if the input is a valid (partial) match of the pattern. + * + */ + public boolean hasMatch(final Integer pValue) { + return rawHasMatch(new Object[]{pValue}); + } + + /** + * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. + * @param pValue the fixed value of pattern parameter Value, or null if not bound. + * @return the number of pattern matches found. + * + */ + public int countMatches(final Integer pValue) { + return rawCountMatches(new Object[]{pValue}); + } + + /** + * 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 pValue the fixed value of pattern parameter Value, 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 pValue, final Consumer processor) { + return rawForOneArbitraryMatch(new Object[]{pValue}, 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 pValue the fixed value of pattern parameter Value, or null if not bound. + * @return the (partial) match object. + * + */ + public GuidanceObjective.Match newMatch(final Integer pValue) { + return GuidanceObjective.Match.newMatch(pValue); + } + + /** + * Retrieve the set of values that occur in matches for Value. + * @return the Set of all values or empty set if there are no matches + * + */ + protected Stream rawStreamAllValuesOfValue(final Object[] parameters) { + return rawStreamAllValues(POSITION_VALUE, parameters).map(Integer.class::cast); + } + + /** + * Retrieve the set of values that occur in matches for Value. + * @return the Set of all values or empty set if there are no matches + * + */ + public Set getAllValuesOfValue() { + return rawStreamAllValuesOfValue(emptyArray()).collect(Collectors.toSet()); + } + + /** + * Retrieve the set of values that occur in matches for Value. + * @return the Set of all values or empty set if there are no matches + * + */ + public Stream streamAllValuesOfValue() { + return rawStreamAllValuesOfValue(emptyArray()); + } + + @Override + protected GuidanceObjective.Match tupleToMatch(final Tuple t) { + try { + return GuidanceObjective.Match.newMatch((Integer) t.get(POSITION_VALUE)); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in tuple not properly typed!",e); + return null; + } + } + + @Override + protected GuidanceObjective.Match arrayToMatch(final Object[] match) { + try { + return GuidanceObjective.Match.newMatch((Integer) match[POSITION_VALUE]); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in array not properly typed!",e); + return null; + } + } + + @Override + protected GuidanceObjective.Match arrayToMatchMutable(final Object[] match) { + try { + return GuidanceObjective.Match.newMutableMatch((Integer) match[POSITION_VALUE]); + } 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 GuidanceObjective.instance(); + } + } + + private GuidanceObjective() { + super(GeneratedPQuery.INSTANCE); + } + + /** + * @return the singleton instance of the query specification + * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded + * + */ + public static GuidanceObjective instance() { + try{ + return LazyHolder.INSTANCE; + } catch (ExceptionInInitializerError err) { + throw processInitializerError(err); + } + } + + @Override + protected GuidanceObjective.Matcher instantiate(final ViatraQueryEngine engine) { + return GuidanceObjective.Matcher.on(engine); + } + + @Override + public GuidanceObjective.Matcher instantiate() { + return GuidanceObjective.Matcher.create(); + } + + @Override + public GuidanceObjective.Match newEmptyMatch() { + return GuidanceObjective.Match.newEmptyMatch(); + } + + @Override + public GuidanceObjective.Match newMatch(final Object... parameters) { + return GuidanceObjective.Match.newMatch((java.lang.Integer) parameters[0]); + } + + /** + * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.GuidanceObjective (visibility: PUBLIC, simpleName: GuidanceObjective, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.GuidanceObjective, deprecated: ) (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.GuidanceObjective (visibility: PUBLIC, simpleName: GuidanceObjective, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.GuidanceObjective, 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 GuidanceObjective INSTANCE = new GuidanceObjective(); + + /** + * 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 GuidanceObjective.GeneratedPQuery INSTANCE = new GeneratedPQuery(); + + private final PParameter parameter_Value = new PParameter("Value", "java.lang.Integer", new JavaTransitiveInstancesKey(java.lang.Integer.class), PParameterDirection.INOUT); + + private final List parameters = Arrays.asList(parameter_Value); + + private GeneratedPQuery() { + super(PVisibility.PUBLIC); + } + + @Override + public String getFullyQualifiedName() { + return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.guidanceObjective"; + } + + @Override + public List getParameterNames() { + return Arrays.asList("Value"); + } + + @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_Value = body.getOrCreateVariableByName("Value"); + PVariable var_UnallocatedInstances = body.getOrCreateVariableByName("UnallocatedInstances"); + PVariable var___0_ = body.getOrCreateVariableByName("_<0>"); + PVariable var_RequiredInstances = body.getOrCreateVariableByName("RequiredInstances"); + PVariable var___1_ = body.getOrCreateVariableByName("_<1>"); + PVariable var___2_ = body.getOrCreateVariableByName("_<2>"); + PVariable var_NoHostToAllocate = body.getOrCreateVariableByName("NoHostToAllocate"); + PVariable var___3_ = body.getOrCreateVariableByName("_<3>"); + new TypeFilterConstraint(body, Tuples.flatTupleOf(var_Value), new JavaTransitiveInstancesKey(java.lang.Integer.class)); + body.setSymbolicParameters(Arrays.asList( + new ExportedParameter(body, var_Value, parameter_Value) + )); + // UnallocatedInstances == count find unallocatedAppInstance(_) + PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); + new PatternMatchCounter(body, Tuples.flatTupleOf(var___0_), UnallocatedAppInstance.instance().getInternalQueryRepresentation(), var__virtual_0_); + new Equality(body, var_UnallocatedInstances, var__virtual_0_); + // RequiredInstances == sum find requiredAppInstances(_, #_) + PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); + new AggregatorConstraint(new sum().getAggregatorLogic(Integer.class), body, Tuples.flatTupleOf(var___1_, var___2_), RequiredAppInstances.instance().getInternalQueryRepresentation(), var__virtual_1_, 1); + new Equality(body, var_RequiredInstances, var__virtual_1_); + // NoHostToAllocate == count find noHostToAllocateTo(_) + PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}"); + new PatternMatchCounter(body, Tuples.flatTupleOf(var___3_), NoHostToAllocateTo.instance().getInternalQueryRepresentation(), var__virtual_2_); + new Equality(body, var_NoHostToAllocate, var__virtual_2_); + // Value == eval(2 * UnallocatedInstances + 4 * RequiredInstances + NoHostToAllocate) + PVariable var__virtual_3_ = body.getOrCreateVariableByName(".virtual{3}"); + new ExpressionEvaluation(body, new IExpressionEvaluator() { + + @Override + public String getShortDescription() { + return "Expression evaluation from pattern guidanceObjective"; + } + + @Override + public Iterable getInputParameterNames() { + return Arrays.asList("NoHostToAllocate", "RequiredInstances", "UnallocatedInstances");} + + @Override + public Object evaluateExpression(IValueProvider provider) throws Exception { + Integer NoHostToAllocate = (Integer) provider.getValue("NoHostToAllocate"); + Integer RequiredInstances = (Integer) provider.getValue("RequiredInstances"); + Integer UnallocatedInstances = (Integer) provider.getValue("UnallocatedInstances"); + return evaluateExpression_1_1(NoHostToAllocate, RequiredInstances, UnallocatedInstances); + } + }, var__virtual_3_ ); + new Equality(body, var_Value, var__virtual_3_); + bodies.add(body); + } + return bodies; + } + } + + private static int evaluateExpression_1_1(final Integer NoHostToAllocate, final Integer RequiredInstances, final Integer UnallocatedInstances) { + return (((2 * (UnallocatedInstances).intValue()) + (4 * (RequiredInstances).intValue())) + (NoHostToAllocate).intValue()); + } +} 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 index 41615598..0c0d57a6 100644 --- 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 @@ -4,7 +4,7 @@ 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 hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.AvailableHdd; import java.util.Arrays; import java.util.Collection; import java.util.LinkedHashSet; 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 index 4803ec3a..9f091a95 100644 --- 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 @@ -4,7 +4,7 @@ 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 hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.AvailableMemory; import java.util.Arrays; import java.util.Collection; import java.util.LinkedHashSet; diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/RemoveHostInstance.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/RemoveHostInstance.java new file mode 100644 index 00000000..1141e898 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/RemoveHostInstance.java @@ -0,0 +1,579 @@ +/** + * 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.Collections; +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.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: + *

+ *         pattern removeHostInstance(HostInstance : HostInstance) {
+ *         	neg HostInstance.applications(HostInstance, _);
+ *         }
+ * 
+ * + * @see Matcher + * @see Match + * + */ +@SuppressWarnings("all") +public final class RemoveHostInstance extends BaseGeneratedEMFQuerySpecification { + /** + * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.removeHostInstance 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 fHostInstance; + + private static List parameterNames = makeImmutableList("HostInstance"); + + private Match(final HostInstance pHostInstance) { + this.fHostInstance = pHostInstance; + } + + @Override + public Object get(final String parameterName) { + if ("HostInstance".equals(parameterName)) return this.fHostInstance; + return null; + } + + public HostInstance getHostInstance() { + return this.fHostInstance; + } + + @Override + public boolean set(final String parameterName, final Object newValue) { + if (!isMutable()) throw new java.lang.UnsupportedOperationException(); + if ("HostInstance".equals(parameterName) ) { + this.fHostInstance = (HostInstance) newValue; + return true; + } + return false; + } + + 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.removeHostInstance"; + } + + @Override + public List parameterNames() { + return RemoveHostInstance.Match.parameterNames; + } + + @Override + public Object[] toArray() { + return new Object[]{fHostInstance}; + } + + @Override + public RemoveHostInstance.Match toImmutable() { + return isMutable() ? newMatch(fHostInstance) : this; + } + + @Override + public String prettyPrint() { + StringBuilder result = new StringBuilder(); + result.append("\"HostInstance\"=" + prettyPrintValue(fHostInstance)); + return result.toString(); + } + + @Override + public int hashCode() { + return Objects.hash(fHostInstance); + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) + return true; + if (obj == null) { + return false; + } + if ((obj instanceof RemoveHostInstance.Match)) { + RemoveHostInstance.Match other = (RemoveHostInstance.Match) obj; + return 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 RemoveHostInstance specification() { + return RemoveHostInstance.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 RemoveHostInstance.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 pHostInstance the fixed value of pattern parameter HostInstance, or null if not bound. + * @return the new, mutable (partial) match object. + * + */ + public static RemoveHostInstance.Match newMutableMatch(final HostInstance pHostInstance) { + return new Mutable(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 pHostInstance the fixed value of pattern parameter HostInstance, or null if not bound. + * @return the (partial) match object. + * + */ + public static RemoveHostInstance.Match newMatch(final HostInstance pHostInstance) { + return new Immutable(pHostInstance); + } + + private static final class Mutable extends RemoveHostInstance.Match { + Mutable(final HostInstance pHostInstance) { + super(pHostInstance); + } + + @Override + public boolean isMutable() { + return true; + } + } + + private static final class Immutable extends RemoveHostInstance.Match { + Immutable(final HostInstance pHostInstance) { + super(pHostInstance); + } + + @Override + public boolean isMutable() { + return false; + } + } + } + + /** + * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.removeHostInstance 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 removeHostInstance(HostInstance : HostInstance) {
+   * 	neg HostInstance.applications(HostInstance, _);
+   * }
+   * 
+ * + * @see Match + * @see RemoveHostInstance + * + */ + 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 RemoveHostInstance.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 RemoveHostInstance.Matcher create() { + return new Matcher(); + } + + private static final int POSITION_HOSTINSTANCE = 0; + + private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(RemoveHostInstance.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 pHostInstance the fixed value of pattern parameter HostInstance, or null if not bound. + * @return matches represented as a Match object. + * + */ + public Collection getAllMatches(final HostInstance pHostInstance) { + return rawStreamAllMatches(new Object[]{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 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 HostInstance pHostInstance) { + return rawStreamAllMatches(new Object[]{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 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 HostInstance pHostInstance) { + return rawGetOneArbitraryMatch(new Object[]{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 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 HostInstance pHostInstance) { + return rawHasMatch(new Object[]{pHostInstance}); + } + + /** + * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. + * @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 HostInstance pHostInstance) { + return rawCountMatches(new Object[]{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 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 HostInstance pHostInstance, final Consumer processor) { + return rawForOneArbitraryMatch(new Object[]{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 pHostInstance the fixed value of pattern parameter HostInstance, or null if not bound. + * @return the (partial) match object. + * + */ + public RemoveHostInstance.Match newMatch(final HostInstance pHostInstance) { + return RemoveHostInstance.Match.newMatch(pHostInstance); + } + + /** + * 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()); + } + + @Override + protected RemoveHostInstance.Match tupleToMatch(final Tuple t) { + try { + return RemoveHostInstance.Match.newMatch((HostInstance) t.get(POSITION_HOSTINSTANCE)); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in tuple not properly typed!",e); + return null; + } + } + + @Override + protected RemoveHostInstance.Match arrayToMatch(final Object[] match) { + try { + return RemoveHostInstance.Match.newMatch((HostInstance) match[POSITION_HOSTINSTANCE]); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in array not properly typed!",e); + return null; + } + } + + @Override + protected RemoveHostInstance.Match arrayToMatchMutable(final Object[] match) { + try { + return RemoveHostInstance.Match.newMutableMatch((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 RemoveHostInstance.instance(); + } + } + + private RemoveHostInstance() { + super(GeneratedPQuery.INSTANCE); + } + + /** + * @return the singleton instance of the query specification + * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded + * + */ + public static RemoveHostInstance instance() { + try{ + return LazyHolder.INSTANCE; + } catch (ExceptionInInitializerError err) { + throw processInitializerError(err); + } + } + + @Override + protected RemoveHostInstance.Matcher instantiate(final ViatraQueryEngine engine) { + return RemoveHostInstance.Matcher.on(engine); + } + + @Override + public RemoveHostInstance.Matcher instantiate() { + return RemoveHostInstance.Matcher.create(); + } + + @Override + public RemoveHostInstance.Match newEmptyMatch() { + return RemoveHostInstance.Match.newEmptyMatch(); + } + + @Override + public RemoveHostInstance.Match newMatch(final Object... parameters) { + return RemoveHostInstance.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.RemoveHostInstance (visibility: PUBLIC, simpleName: RemoveHostInstance, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.RemoveHostInstance, 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.RemoveHostInstance (visibility: PUBLIC, simpleName: RemoveHostInstance, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.RemoveHostInstance, 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 RemoveHostInstance INSTANCE = new RemoveHostInstance(); + + /** + * 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 RemoveHostInstance.GeneratedPQuery INSTANCE = new GeneratedPQuery(); + + 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_HostInstance); + + private class Embedded_1_HostInstance_applications extends BaseGeneratedEMFPQuery { + private final PParameter parameter_p0 = new PParameter("p0", "hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "HostInstance")), PParameterDirection.INOUT); + + private final PParameter parameter_p1 = new PParameter("p1", "hu.bme.mit.inf.dslreasoner.domains.cps.ApplicationInstance", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "ApplicationInstance")), PParameterDirection.INOUT); + + private final List embeddedParameters = Arrays.asList(parameter_p0, parameter_p1); + + public Embedded_1_HostInstance_applications() { + super(PVisibility.EMBEDDED); + } + + @Override + public String getFullyQualifiedName() { + return GeneratedPQuery.this.getFullyQualifiedName() + "$Embedded_1_HostInstance_applications"; + } + + @Override + public List getParameters() { + return embeddedParameters; + } + + @Override + public Set doGetContainedBodies() { + PBody body = new PBody(this); + PVariable var_p0 = body.getOrCreateVariableByName("p0"); + PVariable var_p1 = body.getOrCreateVariableByName("p1"); + body.setSymbolicParameters(Arrays.asList( + new ExportedParameter(body, var_p0, parameter_p0), + new ExportedParameter(body, var_p1, parameter_p1) + )); + // HostInstance.applications(HostInstance, _) + new TypeConstraint(body, Tuples.flatTupleOf(var_p0), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); + PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); + new TypeConstraint(body, Tuples.flatTupleOf(var_p0, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "HostInstance", "applications"))); + 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_p1); + return Collections.singleton(body); + } + } + + private GeneratedPQuery() { + super(PVisibility.PUBLIC); + } + + @Override + public String getFullyQualifiedName() { + return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.removeHostInstance"; + } + + @Override + public List getParameterNames() { + return Arrays.asList("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_HostInstance = body.getOrCreateVariableByName("HostInstance"); + PVariable var___0_ = body.getOrCreateVariableByName("_<0>"); + 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_HostInstance, parameter_HostInstance) + )); + // neg HostInstance.applications(HostInstance, _) + new NegativePatternCall(body, Tuples.flatTupleOf(var_HostInstance, var___0_), new RemoveHostInstance.GeneratedPQuery.Embedded_1_HostInstance_applications()); + 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/ResourceRequirement.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/ResourceRequirement.java new file mode 100644 index 00000000..db7710f5 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/ResourceRequirement.java @@ -0,0 +1,829 @@ +/** + * 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 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.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: + *

+ *         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 Matcher + * @see Match + * + */ +@SuppressWarnings("all") +public final class ResourceRequirement extends BaseGeneratedEMFQuerySpecification { + /** + * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.resourceRequirement 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 hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement fReq; + + private static List parameterNames = makeImmutableList("Host", "App", "Req"); + + private Match(final HostInstance pHost, final ApplicationInstance pApp, final hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement pReq) { + this.fHost = pHost; + this.fApp = pApp; + this.fReq = pReq; + } + + @Override + public Object get(final String parameterName) { + if ("Host".equals(parameterName)) return this.fHost; + if ("App".equals(parameterName)) return this.fApp; + if ("Req".equals(parameterName)) return this.fReq; + return null; + } + + public HostInstance getHost() { + return this.fHost; + } + + public ApplicationInstance getApp() { + return this.fApp; + } + + public hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement getReq() { + return this.fReq; + } + + @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; + } + if ("Req".equals(parameterName) ) { + this.fReq = (hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement) 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; + } + + public void setReq(final hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement pReq) { + if (!isMutable()) throw new java.lang.UnsupportedOperationException(); + this.fReq = pReq; + } + + @Override + public String patternName() { + return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.resourceRequirement"; + } + + @Override + public List parameterNames() { + return ResourceRequirement.Match.parameterNames; + } + + @Override + public Object[] toArray() { + return new Object[]{fHost, fApp, fReq}; + } + + @Override + public ResourceRequirement.Match toImmutable() { + return isMutable() ? newMatch(fHost, fApp, fReq) : this; + } + + @Override + public String prettyPrint() { + StringBuilder result = new StringBuilder(); + result.append("\"Host\"=" + prettyPrintValue(fHost) + ", "); + result.append("\"App\"=" + prettyPrintValue(fApp) + ", "); + result.append("\"Req\"=" + prettyPrintValue(fReq)); + return result.toString(); + } + + @Override + public int hashCode() { + return Objects.hash(fHost, fApp, fReq); + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) + return true; + if (obj == null) { + return false; + } + if ((obj instanceof ResourceRequirement.Match)) { + ResourceRequirement.Match other = (ResourceRequirement.Match) obj; + return Objects.equals(fHost, other.fHost) && Objects.equals(fApp, other.fApp) && 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 ResourceRequirement specification() { + return ResourceRequirement.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 ResourceRequirement.Match newEmptyMatch() { + return new Mutable(null, 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. + * @param pReq the fixed value of pattern parameter Req, or null if not bound. + * @return the new, mutable (partial) match object. + * + */ + public static ResourceRequirement.Match newMutableMatch(final HostInstance pHost, final ApplicationInstance pApp, final hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement pReq) { + return new Mutable(pHost, pApp, 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 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 pReq the fixed value of pattern parameter Req, or null if not bound. + * @return the (partial) match object. + * + */ + public static ResourceRequirement.Match newMatch(final HostInstance pHost, final ApplicationInstance pApp, final hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement pReq) { + return new Immutable(pHost, pApp, pReq); + } + + private static final class Mutable extends ResourceRequirement.Match { + Mutable(final HostInstance pHost, final ApplicationInstance pApp, final hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement pReq) { + super(pHost, pApp, pReq); + } + + @Override + public boolean isMutable() { + return true; + } + } + + private static final class Immutable extends ResourceRequirement.Match { + Immutable(final HostInstance pHost, final ApplicationInstance pApp, final hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement pReq) { + super(pHost, pApp, pReq); + } + + @Override + public boolean isMutable() { + return false; + } + } + } + + /** + * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.resourceRequirement 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 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 Match + * @see ResourceRequirement + * + */ + 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 ResourceRequirement.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 ResourceRequirement.Matcher create() { + return new Matcher(); + } + + private static final int POSITION_HOST = 0; + + private static final int POSITION_APP = 1; + + private static final int POSITION_REQ = 2; + + private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(ResourceRequirement.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. + * @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 HostInstance pHost, final ApplicationInstance pApp, final hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement pReq) { + return rawStreamAllMatches(new Object[]{pHost, pApp, 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 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 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 HostInstance pHost, final ApplicationInstance pApp, final hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement pReq) { + return rawStreamAllMatches(new Object[]{pHost, pApp, 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 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 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 HostInstance pHost, final ApplicationInstance pApp, final hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement pReq) { + return rawGetOneArbitraryMatch(new Object[]{pHost, pApp, 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 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 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 HostInstance pHost, final ApplicationInstance pApp, final hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement pReq) { + return rawHasMatch(new Object[]{pHost, pApp, pReq}); + } + + /** + * 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. + * @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 HostInstance pHost, final ApplicationInstance pApp, final hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement pReq) { + return rawCountMatches(new Object[]{pHost, pApp, 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 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 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 HostInstance pHost, final ApplicationInstance pApp, final hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement pReq, final Consumer processor) { + return rawForOneArbitraryMatch(new Object[]{pHost, pApp, 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 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 pReq the fixed value of pattern parameter Req, or null if not bound. + * @return the (partial) match object. + * + */ + public ResourceRequirement.Match newMatch(final HostInstance pHost, final ApplicationInstance pApp, final hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement pReq) { + return ResourceRequirement.Match.newMatch(pHost, pApp, pReq); + } + + /** + * 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 ResourceRequirement.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, final hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement pReq) { + return rawStreamAllValuesOfHost(new Object[]{null, pApp, pReq}); + } + + /** + * 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 ResourceRequirement.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, final hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement pReq) { + return rawStreamAllValuesOfHost(new Object[]{null, pApp, pReq}).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 ResourceRequirement.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, final hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement pReq) { + return rawStreamAllValuesOfApp(new Object[]{pHost, null, pReq}); + } + + /** + * 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 ResourceRequirement.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, final hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement pReq) { + return rawStreamAllValuesOfApp(new Object[]{pHost, null, pReq}).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 + * + */ + protected Stream rawStreamAllValuesOfReq(final Object[] parameters) { + return rawStreamAllValues(POSITION_REQ, parameters).map(hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement.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 ResourceRequirement.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 HostInstance pHost, final ApplicationInstance pApp) { + return rawStreamAllValuesOfReq(new Object[]{pHost, pApp, null}); + } + + /** + * 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 ResourceRequirement.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 HostInstance pHost, final ApplicationInstance pApp) { + return rawStreamAllValuesOfReq(new Object[]{pHost, pApp, null}).collect(Collectors.toSet()); + } + + @Override + protected ResourceRequirement.Match tupleToMatch(final Tuple t) { + try { + return ResourceRequirement.Match.newMatch((HostInstance) t.get(POSITION_HOST), (ApplicationInstance) t.get(POSITION_APP), (hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement) t.get(POSITION_REQ)); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in tuple not properly typed!",e); + return null; + } + } + + @Override + protected ResourceRequirement.Match arrayToMatch(final Object[] match) { + try { + return ResourceRequirement.Match.newMatch((HostInstance) match[POSITION_HOST], (ApplicationInstance) match[POSITION_APP], (hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement) match[POSITION_REQ]); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in array not properly typed!",e); + return null; + } + } + + @Override + protected ResourceRequirement.Match arrayToMatchMutable(final Object[] match) { + try { + return ResourceRequirement.Match.newMutableMatch((HostInstance) match[POSITION_HOST], (ApplicationInstance) match[POSITION_APP], (hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement) 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 ResourceRequirement.instance(); + } + } + + 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); + } + } + + @Override + protected ResourceRequirement.Matcher instantiate(final ViatraQueryEngine engine) { + return ResourceRequirement.Matcher.on(engine); + } + + @Override + public ResourceRequirement.Matcher instantiate() { + return ResourceRequirement.Matcher.create(); + } + + @Override + public ResourceRequirement.Match newEmptyMatch() { + return ResourceRequirement.Match.newEmptyMatch(); + } + + @Override + public ResourceRequirement.Match newMatch(final Object... parameters) { + return ResourceRequirement.Match.newMatch((hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance) parameters[0], (hu.bme.mit.inf.dslreasoner.domains.cps.ApplicationInstance) parameters[1], (hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement) parameters[2]); + } + + /** + * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.ResourceRequirement (visibility: PUBLIC, simpleName: ResourceRequirement, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.ResourceRequirement, deprecated: ) (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.ResourceRequirement (visibility: PUBLIC, simpleName: ResourceRequirement, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.ResourceRequirement, 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 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.PUBLIC); + } + + @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/TotalHdd.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/TotalHdd.java deleted file mode 100644 index f91853de..00000000 --- a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/TotalHdd.java +++ /dev/null @@ -1,706 +0,0 @@ -/** - * 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 deleted file mode 100644 index e8a11e36..00000000 --- a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/TotalMemory.java +++ /dev/null @@ -1,706 +0,0 @@ -/** - * 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/UnallocateAppInstance.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/UnallocateAppInstance.java new file mode 100644 index 00000000..ccc0ba22 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/UnallocateAppInstance.java @@ -0,0 +1,541 @@ +/** + * 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 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.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: + *

+ *         pattern unallocateAppInstance(App : ApplicationInstance) {
+ *         	ApplicationInstance.allocatedTo(App, _);
+ *         }
+ * 
+ * + * @see Matcher + * @see Match + * + */ +@SuppressWarnings("all") +public final class UnallocateAppInstance extends BaseGeneratedEMFQuerySpecification { + /** + * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.unallocateAppInstance 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 ApplicationInstance fApp; + + private static List parameterNames = makeImmutableList("App"); + + private Match(final ApplicationInstance pApp) { + this.fApp = pApp; + } + + @Override + public Object get(final String parameterName) { + if ("App".equals(parameterName)) return this.fApp; + return null; + } + + public ApplicationInstance getApp() { + return this.fApp; + } + + @Override + public boolean set(final String parameterName, final Object newValue) { + if (!isMutable()) throw new java.lang.UnsupportedOperationException(); + if ("App".equals(parameterName) ) { + this.fApp = (ApplicationInstance) newValue; + return true; + } + return false; + } + + 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.unallocateAppInstance"; + } + + @Override + public List parameterNames() { + return UnallocateAppInstance.Match.parameterNames; + } + + @Override + public Object[] toArray() { + return new Object[]{fApp}; + } + + @Override + public UnallocateAppInstance.Match toImmutable() { + return isMutable() ? newMatch(fApp) : this; + } + + @Override + public String prettyPrint() { + StringBuilder result = new StringBuilder(); + result.append("\"App\"=" + prettyPrintValue(fApp)); + return result.toString(); + } + + @Override + public int hashCode() { + return Objects.hash(fApp); + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) + return true; + if (obj == null) { + return false; + } + if ((obj instanceof UnallocateAppInstance.Match)) { + UnallocateAppInstance.Match other = (UnallocateAppInstance.Match) obj; + return 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 UnallocateAppInstance specification() { + return UnallocateAppInstance.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 UnallocateAppInstance.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 pApp the fixed value of pattern parameter App, or null if not bound. + * @return the new, mutable (partial) match object. + * + */ + public static UnallocateAppInstance.Match newMutableMatch(final ApplicationInstance pApp) { + return new Mutable(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 pApp the fixed value of pattern parameter App, or null if not bound. + * @return the (partial) match object. + * + */ + public static UnallocateAppInstance.Match newMatch(final ApplicationInstance pApp) { + return new Immutable(pApp); + } + + private static final class Mutable extends UnallocateAppInstance.Match { + Mutable(final ApplicationInstance pApp) { + super(pApp); + } + + @Override + public boolean isMutable() { + return true; + } + } + + private static final class Immutable extends UnallocateAppInstance.Match { + Immutable(final ApplicationInstance pApp) { + super(pApp); + } + + @Override + public boolean isMutable() { + return false; + } + } + } + + /** + * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.unallocateAppInstance 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 unallocateAppInstance(App : ApplicationInstance) {
+   * 	ApplicationInstance.allocatedTo(App, _);
+   * }
+   * 
+ * + * @see Match + * @see UnallocateAppInstance + * + */ + 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 UnallocateAppInstance.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 UnallocateAppInstance.Matcher create() { + return new Matcher(); + } + + private static final int POSITION_APP = 0; + + private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(UnallocateAppInstance.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 pApp the fixed value of pattern parameter App, or null if not bound. + * @return matches represented as a Match object. + * + */ + public Collection getAllMatches(final ApplicationInstance pApp) { + return rawStreamAllMatches(new Object[]{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 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 ApplicationInstance pApp) { + return rawStreamAllMatches(new Object[]{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 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 ApplicationInstance pApp) { + return rawGetOneArbitraryMatch(new Object[]{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 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 ApplicationInstance pApp) { + return rawHasMatch(new Object[]{pApp}); + } + + /** + * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. + * @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 ApplicationInstance pApp) { + return rawCountMatches(new Object[]{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 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 ApplicationInstance pApp, final Consumer processor) { + return rawForOneArbitraryMatch(new Object[]{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 pApp the fixed value of pattern parameter App, or null if not bound. + * @return the (partial) match object. + * + */ + public UnallocateAppInstance.Match newMatch(final ApplicationInstance pApp) { + return UnallocateAppInstance.Match.newMatch(pApp); + } + + /** + * 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()); + } + + @Override + protected UnallocateAppInstance.Match tupleToMatch(final Tuple t) { + try { + return UnallocateAppInstance.Match.newMatch((ApplicationInstance) t.get(POSITION_APP)); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in tuple not properly typed!",e); + return null; + } + } + + @Override + protected UnallocateAppInstance.Match arrayToMatch(final Object[] match) { + try { + return UnallocateAppInstance.Match.newMatch((ApplicationInstance) match[POSITION_APP]); + } catch(ClassCastException e) { + LOGGER.error("Element(s) in array not properly typed!",e); + return null; + } + } + + @Override + protected UnallocateAppInstance.Match arrayToMatchMutable(final Object[] match) { + try { + return UnallocateAppInstance.Match.newMutableMatch((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 UnallocateAppInstance.instance(); + } + } + + private UnallocateAppInstance() { + super(GeneratedPQuery.INSTANCE); + } + + /** + * @return the singleton instance of the query specification + * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded + * + */ + public static UnallocateAppInstance instance() { + try{ + return LazyHolder.INSTANCE; + } catch (ExceptionInInitializerError err) { + throw processInitializerError(err); + } + } + + @Override + protected UnallocateAppInstance.Matcher instantiate(final ViatraQueryEngine engine) { + return UnallocateAppInstance.Matcher.on(engine); + } + + @Override + public UnallocateAppInstance.Matcher instantiate() { + return UnallocateAppInstance.Matcher.create(); + } + + @Override + public UnallocateAppInstance.Match newEmptyMatch() { + return UnallocateAppInstance.Match.newEmptyMatch(); + } + + @Override + public UnallocateAppInstance.Match newMatch(final Object... parameters) { + return UnallocateAppInstance.Match.newMatch((hu.bme.mit.inf.dslreasoner.domains.cps.ApplicationInstance) parameters[0]); + } + + /** + * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.UnallocateAppInstance (visibility: PUBLIC, simpleName: UnallocateAppInstance, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.UnallocateAppInstance, deprecated: ) (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.UnallocateAppInstance (visibility: PUBLIC, simpleName: UnallocateAppInstance, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.UnallocateAppInstance, 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 UnallocateAppInstance INSTANCE = new UnallocateAppInstance(); + + /** + * 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 UnallocateAppInstance.GeneratedPQuery INSTANCE = new GeneratedPQuery(); + + 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_App); + + private GeneratedPQuery() { + super(PVisibility.PUBLIC); + } + + @Override + public String getFullyQualifiedName() { + return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.unallocateAppInstance"; + } + + @Override + public List getParameterNames() { + return Arrays.asList("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_App = body.getOrCreateVariableByName("App"); + PVariable var___0_ = body.getOrCreateVariableByName("_<0>"); + 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_App, parameter_App) + )); + // ApplicationInstance.allocatedTo(App, _) + 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___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/internal/.gitignore b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/.gitignore index 2f593811..c903a5e9 100644 --- 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 @@ -9,3 +9,12 @@ /.FreeHddPercentage.java._trace /.ApplicationInstance.java._trace /.HostInstanceCost.java._trace +/.AvailableHdd.java._trace +/.AvailableMemory.java._trace +/.CpsApplications.java._trace +/.CpsHosts.java._trace +/.TotalHdd.java._trace +/.TotalMemory.java._trace +/.RequiredAppInstances.java._trace +/.UnallocatedAppInstance.java._trace +/.NoHostToAllocateTo.java._trace diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/AvailableHdd.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/AvailableHdd.java new file mode 100644 index 00000000..7d07b83a --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/AvailableHdd.java @@ -0,0 +1,178 @@ +/** + * 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.HddRequirement; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.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.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.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 availableHdd(Host : HostInstance, Hdd : java Integer) {
+ *         	find totalHdd(Host, TotalHdd);
+ *         	RequiredHdd == sum find hddRequirement(Host, _, #_);
+ *         	Hdd == eval(TotalHdd - RequiredHdd);
+ *         }
+ * 
+ * + * @see GenericPatternMatcher + * @see GenericPatternMatch + * + */ +@SuppressWarnings("all") +public final class AvailableHdd extends BaseGeneratedEMFQuerySpecificationWithGenericMatcher { + 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); + } + } + + /** + * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.AvailableHdd (visibility: PUBLIC, simpleName: AvailableHdd, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.AvailableHdd, deprecated: ) (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.AvailableHdd (visibility: PUBLIC, simpleName: AvailableHdd, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.AvailableHdd, 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 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.PRIVATE); + } + + @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); + } + 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/internal/AvailableMemory.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/AvailableMemory.java new file mode 100644 index 00000000..b06544d5 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/AvailableMemory.java @@ -0,0 +1,178 @@ +/** + * 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.MemoryRequirement; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.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.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.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 availableMemory(Host : HostInstance, Memory : java Integer) {
+ *         	find totalMemory(Host, TotalMemory);
+ *         	RequiredMemory == sum find memoryRequirement(Host, _, #_);
+ *         	Memory == eval(TotalMemory - RequiredMemory);
+ *         }
+ * 
+ * + * @see GenericPatternMatcher + * @see GenericPatternMatch + * + */ +@SuppressWarnings("all") +public final class AvailableMemory extends BaseGeneratedEMFQuerySpecificationWithGenericMatcher { + 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); + } + } + + /** + * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.AvailableMemory (visibility: PUBLIC, simpleName: AvailableMemory, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.AvailableMemory, deprecated: ) (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.AvailableMemory (visibility: PUBLIC, simpleName: AvailableMemory, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.AvailableMemory, 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 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.PRIVATE); + } + + @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); + } + 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/internal/CpsApplications.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/CpsApplications.java new file mode 100644 index 00000000..23867558 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/CpsApplications.java @@ -0,0 +1,141 @@ +/** + * 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 cpsApplications(Cps : CyberPhysicalSystem, AppInstance : ApplicationInstance) {
+ *         	CyberPhysicalSystem.applicationTypes.instances(Cps, AppInstance);
+ *         }
+ * 
+ * + * @see GenericPatternMatcher + * @see GenericPatternMatch + * + */ +@SuppressWarnings("all") +public final class CpsApplications extends BaseGeneratedEMFQuerySpecificationWithGenericMatcher { + 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); + } + } + + /** + * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.CpsApplications (visibility: PUBLIC, simpleName: CpsApplications, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.CpsApplications, deprecated: ) (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.CpsApplications (visibility: PUBLIC, simpleName: CpsApplications, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.CpsApplications, 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 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.PRIVATE); + } + + @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); + } + return bodies; + } + } +} diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/CpsHosts.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/CpsHosts.java new file mode 100644 index 00000000..e55bddff --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/CpsHosts.java @@ -0,0 +1,141 @@ +/** + * 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 cpsHosts(Cps : CyberPhysicalSystem, HostInstance : HostInstance) {
+ *         	CyberPhysicalSystem.hostTypes.instances(Cps, HostInstance);
+ *         }
+ * 
+ * + * @see GenericPatternMatcher + * @see GenericPatternMatch + * + */ +@SuppressWarnings("all") +public final class CpsHosts extends BaseGeneratedEMFQuerySpecificationWithGenericMatcher { + 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); + } + } + + /** + * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.CpsHosts (visibility: PUBLIC, simpleName: CpsHosts, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.CpsHosts, deprecated: ) (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.CpsHosts (visibility: PUBLIC, simpleName: CpsHosts, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.CpsHosts, 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 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.PRIVATE); + } + + @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); + } + return bodies; + } + } +} 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 index 58b113eb..67f75e1d 100644 --- 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 @@ -3,29 +3,37 @@ */ package hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.Allocate; 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.CreateHostInstance; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.GuidanceObjective; 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.RedundantInstancesOnSameHost; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.RemoveHostInstance; 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.ResourceRequirement; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.UnallocateAppInstance; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.AvailableHdd; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.AvailableMemory; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.CpsApplications; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.CpsHosts; 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.NoHostToAllocateTo; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.RequiredAppInstances; import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.SatisfyingInstance; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.TotalHdd; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.TotalMemory; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.UnallocatedAppInstance; import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedPatternGroup; /** @@ -57,6 +65,14 @@ import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedPatternGroup; *

  • costMetric
  • *
  • cpsCost
  • *
  • hostInstanceCost
  • + *
  • allocate
  • + *
  • unallocateAppInstance
  • + *
  • createHostInstance
  • + *
  • removeHostInstance
  • + *
  • unallocatedAppInstance
  • + *
  • requiredAppInstances
  • + *
  • noHostToAllocateTo
  • + *
  • guidanceObjective
  • * * * @see IQueryGroup @@ -104,5 +120,13 @@ public final class CpsQueriesAll extends BaseGeneratedPatternGroup { querySpecifications.add(CostMetric.instance()); querySpecifications.add(CpsCost.instance()); querySpecifications.add(HostInstanceCost.instance()); + querySpecifications.add(Allocate.instance()); + querySpecifications.add(UnallocateAppInstance.instance()); + querySpecifications.add(CreateHostInstance.instance()); + querySpecifications.add(RemoveHostInstance.instance()); + querySpecifications.add(UnallocatedAppInstance.instance()); + querySpecifications.add(RequiredAppInstances.instance()); + querySpecifications.add(NoHostToAllocateTo.instance()); + querySpecifications.add(GuidanceObjective.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 index 366677b5..c24f46a1 100644 --- 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 @@ -3,8 +3,8 @@ */ 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 hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.AvailableHdd; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.TotalHdd; import java.util.Arrays; import java.util.LinkedHashSet; import java.util.List; 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 index bd151ea6..c2bb2bb3 100644 --- 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 @@ -3,8 +3,8 @@ */ 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 hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.AvailableMemory; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.TotalMemory; import java.util.Arrays; import java.util.LinkedHashSet; import java.util.List; 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 index fbe7a46b..68448930 100644 --- 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 @@ -3,7 +3,7 @@ */ package hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal; -import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.ResourceRequirement; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.ResourceRequirement; import java.util.Arrays; import java.util.LinkedHashSet; import java.util.List; 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 index 767ca342..db7f7021 100644 --- 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 @@ -3,7 +3,7 @@ */ package hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal; -import hu.bme.mit.inf.dslreasoner.domains.cps.queries.CpsHosts; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.CpsHosts; import java.util.Arrays; import java.util.LinkedHashSet; import java.util.List; 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 index 0a24d105..d15f9bfa 100644 --- 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 @@ -3,7 +3,7 @@ */ package hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal; -import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.ResourceRequirement; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.ResourceRequirement; import java.util.Arrays; import java.util.LinkedHashSet; import java.util.List; diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/NoHostToAllocateTo.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/NoHostToAllocateTo.java new file mode 100644 index 00000000..50597805 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/NoHostToAllocateTo.java @@ -0,0 +1,135 @@ +/** + * 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.Allocate; +import hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.UnallocatedAppInstance; +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.psystem.PBody; +import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; +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.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 noHostToAllocateTo(App : ApplicationInstance) {
    + *         	find unallocatedAppInstance(App);
    + *         	neg find allocate(App, _);
    + *         }
    + * 
    + * + * @see GenericPatternMatcher + * @see GenericPatternMatch + * + */ +@SuppressWarnings("all") +public final class NoHostToAllocateTo extends BaseGeneratedEMFQuerySpecificationWithGenericMatcher { + private NoHostToAllocateTo() { + super(GeneratedPQuery.INSTANCE); + } + + /** + * @return the singleton instance of the query specification + * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded + * + */ + public static NoHostToAllocateTo 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.NoHostToAllocateTo (visibility: PUBLIC, simpleName: NoHostToAllocateTo, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.NoHostToAllocateTo, 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.NoHostToAllocateTo (visibility: PUBLIC, simpleName: NoHostToAllocateTo, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.NoHostToAllocateTo, 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 NoHostToAllocateTo INSTANCE = new NoHostToAllocateTo(); + + /** + * 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 NoHostToAllocateTo.GeneratedPQuery INSTANCE = new GeneratedPQuery(); + + 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_App); + + private GeneratedPQuery() { + super(PVisibility.PRIVATE); + } + + @Override + public String getFullyQualifiedName() { + return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.noHostToAllocateTo"; + } + + @Override + public List getParameterNames() { + return Arrays.asList("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_App = body.getOrCreateVariableByName("App"); + PVariable var___0_ = body.getOrCreateVariableByName("_<0>"); + 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_App, parameter_App) + )); + // find unallocatedAppInstance(App) + new PositivePatternCall(body, Tuples.flatTupleOf(var_App), UnallocatedAppInstance.instance().getInternalQueryRepresentation()); + // neg find allocate(App, _) + new NegativePatternCall(body, Tuples.flatTupleOf(var_App, var___0_), Allocate.instance().getInternalQueryRepresentation()); + 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/RequiredAppInstances.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/RequiredAppInstances.java new file mode 100644 index 00000000..dc76cbde --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/RequiredAppInstances.java @@ -0,0 +1,181 @@ +/** + * 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.SatisfyingInstance; +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.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.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.Tuples; + +/** + * A pattern-specific query specification that can instantiate GenericPatternMatcher in a type-safe way. + * + *

    Original source: + *

    + *         private pattern requiredAppInstances(Req : Requirement, Remaining : java Integer) {
    + *         	Instances == count find satisfyingInstance(Req, _);
    + *         	Requirement.count(Req, RequiredCount);
    + *         	Remaining == eval(RequiredCount - Instances);
    + *         }
    + * 
    + * + * @see GenericPatternMatcher + * @see GenericPatternMatch + * + */ +@SuppressWarnings("all") +public final class RequiredAppInstances extends BaseGeneratedEMFQuerySpecificationWithGenericMatcher { + private RequiredAppInstances() { + super(GeneratedPQuery.INSTANCE); + } + + /** + * @return the singleton instance of the query specification + * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded + * + */ + public static RequiredAppInstances 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.RequiredAppInstances (visibility: PUBLIC, simpleName: RequiredAppInstances, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.RequiredAppInstances, 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.RequiredAppInstances (visibility: PUBLIC, simpleName: RequiredAppInstances, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.RequiredAppInstances, 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 RequiredAppInstances INSTANCE = new RequiredAppInstances(); + + /** + * 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 RequiredAppInstances.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_Remaining = new PParameter("Remaining", "java.lang.Integer", new JavaTransitiveInstancesKey(java.lang.Integer.class), PParameterDirection.INOUT); + + private final List parameters = Arrays.asList(parameter_Req, parameter_Remaining); + + private GeneratedPQuery() { + super(PVisibility.PRIVATE); + } + + @Override + public String getFullyQualifiedName() { + return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.requiredAppInstances"; + } + + @Override + public List getParameterNames() { + return Arrays.asList("Req","Remaining"); + } + + @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_Remaining = body.getOrCreateVariableByName("Remaining"); + 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"))); + new TypeFilterConstraint(body, Tuples.flatTupleOf(var_Remaining), new JavaTransitiveInstancesKey(java.lang.Integer.class)); + body.setSymbolicParameters(Arrays.asList( + new ExportedParameter(body, var_Req, parameter_Req), + new ExportedParameter(body, var_Remaining, parameter_Remaining) + )); + // 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); + // Remaining == eval(RequiredCount - Instances) + PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}"); + new ExpressionEvaluation(body, new IExpressionEvaluator() { + + @Override + public String getShortDescription() { + return "Expression evaluation from pattern requiredAppInstances"; + } + + @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); + } + }, var__virtual_2_ ); + new Equality(body, var_Remaining, var__virtual_2_); + bodies.add(body); + } + return bodies; + } + } + + private static int evaluateExpression_1_1(final Integer Instances, final Integer RequiredCount) { + return ((RequiredCount).intValue() - (Instances).intValue()); + } +} 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 deleted file mode 100644 index 8c5bdefe..00000000 --- a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/ResourceRequirement.java +++ /dev/null @@ -1,168 +0,0 @@ -/** - * 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/TotalHdd.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/TotalHdd.java new file mode 100644 index 00000000..f250f76d --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/TotalHdd.java @@ -0,0 +1,143 @@ +/** + * 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.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.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 totalHdd(Host : HostInstance, Hdd : EInt) {
    + *         	HostInstance.type.defaultHdd(Host, Hdd);
    + *         }
    + * 
    + * + * @see GenericPatternMatcher + * @see GenericPatternMatch + * + */ +@SuppressWarnings("all") +public final class TotalHdd extends BaseGeneratedEMFQuerySpecificationWithGenericMatcher { + 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); + } + } + + /** + * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.TotalHdd (visibility: PUBLIC, simpleName: TotalHdd, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.TotalHdd, deprecated: ) (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.TotalHdd (visibility: PUBLIC, simpleName: TotalHdd, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.TotalHdd, 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 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.PRIVATE); + } + + @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); + } + return bodies; + } + } +} diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/TotalMemory.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/TotalMemory.java new file mode 100644 index 00000000..aecd97e2 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/TotalMemory.java @@ -0,0 +1,143 @@ +/** + * 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.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.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 totalMemory(Host : HostInstance, Memory : EInt) {
    + *         	HostInstance.type.defaultMemory(Host, Memory);
    + *         }
    + * 
    + * + * @see GenericPatternMatcher + * @see GenericPatternMatch + * + */ +@SuppressWarnings("all") +public final class TotalMemory extends BaseGeneratedEMFQuerySpecificationWithGenericMatcher { + 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); + } + } + + /** + * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.TotalMemory (visibility: PUBLIC, simpleName: TotalMemory, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.TotalMemory, deprecated: ) (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.TotalMemory (visibility: PUBLIC, simpleName: TotalMemory, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.TotalMemory, 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 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.PRIVATE); + } + + @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); + } + return bodies; + } + } +} diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/UnallocatedAppInstance.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/UnallocatedAppInstance.java new file mode 100644 index 00000000..a20b534c --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/UnallocatedAppInstance.java @@ -0,0 +1,172 @@ +/** + * 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.Collections; +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.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.Tuples; + +/** + * A pattern-specific query specification that can instantiate GenericPatternMatcher in a type-safe way. + * + *

    Original source: + *

    + *         private pattern unallocatedAppInstance(App : ApplicationInstance) {
    + *         	neg ApplicationInstance.allocatedTo(App, _);
    + *         }
    + * 
    + * + * @see GenericPatternMatcher + * @see GenericPatternMatch + * + */ +@SuppressWarnings("all") +public final class UnallocatedAppInstance extends BaseGeneratedEMFQuerySpecificationWithGenericMatcher { + private UnallocatedAppInstance() { + super(GeneratedPQuery.INSTANCE); + } + + /** + * @return the singleton instance of the query specification + * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded + * + */ + public static UnallocatedAppInstance 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.UnallocatedAppInstance (visibility: PUBLIC, simpleName: UnallocatedAppInstance, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.UnallocatedAppInstance, 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.UnallocatedAppInstance (visibility: PUBLIC, simpleName: UnallocatedAppInstance, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.internal.UnallocatedAppInstance, 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 UnallocatedAppInstance INSTANCE = new UnallocatedAppInstance(); + + /** + * 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 UnallocatedAppInstance.GeneratedPQuery INSTANCE = new GeneratedPQuery(); + + 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_App); + + private class Embedded_1_ApplicationInstance_allocatedTo extends BaseGeneratedEMFPQuery { + private final PParameter parameter_p0 = new PParameter("p0", "hu.bme.mit.inf.dslreasoner.domains.cps.ApplicationInstance", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "ApplicationInstance")), PParameterDirection.INOUT); + + private final PParameter parameter_p1 = new PParameter("p1", "hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "HostInstance")), PParameterDirection.INOUT); + + private final List embeddedParameters = Arrays.asList(parameter_p0, parameter_p1); + + public Embedded_1_ApplicationInstance_allocatedTo() { + super(PVisibility.EMBEDDED); + } + + @Override + public String getFullyQualifiedName() { + return GeneratedPQuery.this.getFullyQualifiedName() + "$Embedded_1_ApplicationInstance_allocatedTo"; + } + + @Override + public List getParameters() { + return embeddedParameters; + } + + @Override + public Set doGetContainedBodies() { + PBody body = new PBody(this); + PVariable var_p0 = body.getOrCreateVariableByName("p0"); + PVariable var_p1 = body.getOrCreateVariableByName("p1"); + body.setSymbolicParameters(Arrays.asList( + new ExportedParameter(body, var_p0, parameter_p0), + new ExportedParameter(body, var_p1, parameter_p1) + )); + // ApplicationInstance.allocatedTo(App, _) + new TypeConstraint(body, Tuples.flatTupleOf(var_p0), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance"))); + PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); + new TypeConstraint(body, Tuples.flatTupleOf(var_p0, 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_p1); + return Collections.singleton(body); + } + } + + private GeneratedPQuery() { + super(PVisibility.PRIVATE); + } + + @Override + public String getFullyQualifiedName() { + return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.unallocatedAppInstance"; + } + + @Override + public List getParameterNames() { + return Arrays.asList("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_App = body.getOrCreateVariableByName("App"); + PVariable var___0_ = body.getOrCreateVariableByName("_<0>"); + 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_App, parameter_App) + )); + // neg ApplicationInstance.allocatedTo(App, _) + new NegativePatternCall(body, Tuples.flatTupleOf(var_App, var___0_), new UnallocatedAppInstance.GeneratedPQuery.Embedded_1_ApplicationInstance_allocatedTo()); + bodies.add(body); + } + return bodies; + } + } +} -- cgit v1.2.3-54-g00ecf