diff options
Diffstat (limited to 'Domains')
75 files changed, 22830 insertions, 69 deletions
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/.classpath b/Domains/ca.mcgill.rtgmrt.example.modes3/.classpath new file mode 100644 index 00000000..73ebde52 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/.classpath | |||
@@ -0,0 +1,10 @@ | |||
1 | <?xml version="1.0" encoding="UTF-8"?> | ||
2 | <classpath> | ||
3 | <classpathentry kind="src" path="ecore-gen"/> | ||
4 | <classpathentry kind="src" path="src"/> | ||
5 | <classpathentry kind="src" path="xtend-gen"/> | ||
6 | <classpathentry kind="src" path="vql-gen"/> | ||
7 | <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11"/> | ||
8 | <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> | ||
9 | <classpathentry kind="output" path="bin"/> | ||
10 | </classpath> | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/.gitignore b/Domains/ca.mcgill.rtgmrt.example.modes3/.gitignore new file mode 100644 index 00000000..6cef8ea6 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/.gitignore | |||
@@ -0,0 +1,2 @@ | |||
1 | /bin/ | ||
2 | output/ | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/.project b/Domains/ca.mcgill.rtgmrt.example.modes3/.project new file mode 100644 index 00000000..5e0fbc45 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/.project | |||
@@ -0,0 +1,40 @@ | |||
1 | <?xml version="1.0" encoding="UTF-8"?> | ||
2 | <projectDescription> | ||
3 | <name>ca.mcgill.rtgmrt.example.modes3</name> | ||
4 | <comment></comment> | ||
5 | <projects> | ||
6 | </projects> | ||
7 | <buildSpec> | ||
8 | <buildCommand> | ||
9 | <name>org.eclipse.viatra.query.tooling.ui.projectbuilder</name> | ||
10 | <arguments> | ||
11 | </arguments> | ||
12 | </buildCommand> | ||
13 | <buildCommand> | ||
14 | <name>org.eclipse.xtext.ui.shared.xtextBuilder</name> | ||
15 | <arguments> | ||
16 | </arguments> | ||
17 | </buildCommand> | ||
18 | <buildCommand> | ||
19 | <name>org.eclipse.jdt.core.javabuilder</name> | ||
20 | <arguments> | ||
21 | </arguments> | ||
22 | </buildCommand> | ||
23 | <buildCommand> | ||
24 | <name>org.eclipse.pde.ManifestBuilder</name> | ||
25 | <arguments> | ||
26 | </arguments> | ||
27 | </buildCommand> | ||
28 | <buildCommand> | ||
29 | <name>org.eclipse.pde.SchemaBuilder</name> | ||
30 | <arguments> | ||
31 | </arguments> | ||
32 | </buildCommand> | ||
33 | </buildSpec> | ||
34 | <natures> | ||
35 | <nature>org.eclipse.jdt.core.javanature</nature> | ||
36 | <nature>org.eclipse.pde.PluginNature</nature> | ||
37 | <nature>org.eclipse.xtext.ui.shared.xtextNature</nature> | ||
38 | <nature>org.eclipse.viatra.query.projectnature</nature> | ||
39 | </natures> | ||
40 | </projectDescription> | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/.settings/org.eclipse.viatra.query.patternlanguage.emf.EMFPatternLanguage.prefs b/Domains/ca.mcgill.rtgmrt.example.modes3/.settings/org.eclipse.viatra.query.patternlanguage.emf.EMFPatternLanguage.prefs new file mode 100644 index 00000000..31cda49a --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/.settings/org.eclipse.viatra.query.patternlanguage.emf.EMFPatternLanguage.prefs | |||
@@ -0,0 +1,27 @@ | |||
1 | BuilderConfiguration.is_project_specific=true | ||
2 | autobuilding=true | ||
3 | eclipse.preferences.version=1 | ||
4 | generateEclipseExtensions=true | ||
5 | generateGeneratedAnnotation=false | ||
6 | generateManifestEntries=true | ||
7 | generateMatchProcessors=false | ||
8 | generateMatchers=NESTED_CLASS | ||
9 | generateSuppressWarnings=true | ||
10 | generatedAnnotationComment= | ||
11 | includeDateInGenerated=false | ||
12 | outlet.DEFAULT_OUTPUT.cleanDirectory=false | ||
13 | outlet.DEFAULT_OUTPUT.cleanupDerived=true | ||
14 | outlet.DEFAULT_OUTPUT.createDirectory=true | ||
15 | outlet.DEFAULT_OUTPUT.derived=true | ||
16 | outlet.DEFAULT_OUTPUT.directory=./vql-gen | ||
17 | outlet.DEFAULT_OUTPUT.hideLocalSyntheticVariables=true | ||
18 | outlet.DEFAULT_OUTPUT.installDslAsPrimarySource=false | ||
19 | outlet.DEFAULT_OUTPUT.keepLocalHistory=true | ||
20 | outlet.DEFAULT_OUTPUT.override=true | ||
21 | outlet.DEFAULT_OUTPUT.sourceFolder.ecore-gen.directory= | ||
22 | outlet.DEFAULT_OUTPUT.sourceFolder.ecore-gen.ignore= | ||
23 | outlet.DEFAULT_OUTPUT.sourceFolder.src.directory= | ||
24 | outlet.DEFAULT_OUTPUT.sourceFolder.src.ignore= | ||
25 | outlet.DEFAULT_OUTPUT.userOutputPerSourceFolder= | ||
26 | targetJavaVersion=JAVA5 | ||
27 | useJavaCompilerCompliance=true | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/META-INF/MANIFEST.MF b/Domains/ca.mcgill.rtgmrt.example.modes3/META-INF/MANIFEST.MF new file mode 100644 index 00000000..8f900199 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/META-INF/MANIFEST.MF | |||
@@ -0,0 +1,36 @@ | |||
1 | Manifest-Version: 1.0 | ||
2 | Bundle-ManifestVersion: 2 | ||
3 | Bundle-Name: %pluginName | ||
4 | Bundle-SymbolicName: ca.mcgill.rtgmrt.example.modes3;singleton:=true | ||
5 | Bundle-Version: 0.1.0.qualifier | ||
6 | Bundle-ClassPath: . | ||
7 | Bundle-Vendor: %providerName | ||
8 | Bundle-Localization: plugin | ||
9 | Export-Package: modes3, | ||
10 | modes3.impl, | ||
11 | modes3.queries, | ||
12 | modes3.util | ||
13 | Require-Bundle: org.eclipse.viatra.query.runtime, | ||
14 | org.eclipse.viatra.query.runtime.rete, | ||
15 | org.eclipse.viatra.query.runtime.localsearch, | ||
16 | org.eclipse.xtext.xbase.lib, | ||
17 | org.eclipse.emf.ecore;visibility:=reexport, | ||
18 | org.eclipse.core.runtime, | ||
19 | org.eclipse.xtend.lib;bundle-version="2.21.0", | ||
20 | org.eclipse.xtend.lib.macro;bundle-version="2.21.0", | ||
21 | hu.bme.mit.inf.dslreasoner.application;bundle-version="1.0.0", | ||
22 | hu.bme.mit.inf.dslreasoner.logic.model;bundle-version="1.0.0", | ||
23 | hu.bme.mit.inf.dslreasoner.logic2ecore;bundle-version="1.0.0", | ||
24 | hu.bme.mit.inf.dslreasoner.viatra2logic;bundle-version="1.0.0", | ||
25 | hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatraquery;bundle-version="1.0.0", | ||
26 | hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage;bundle-version="1.0.0", | ||
27 | hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner;bundle-version="1.0.0", | ||
28 | hu.bme.mit.inf.dslreasoner.ecore2logic;bundle-version="1.0.0", | ||
29 | org.eclipse.emf.ecore.xmi;bundle-version="2.16.0", | ||
30 | hu.bme.mit.inf.dslreasoner.visualisation;bundle-version="1.0.0", | ||
31 | org.eclipse.viatra.query.patternlanguage.emf;bundle-version="2.4.0", | ||
32 | org.eclipse.viatra.dse;bundle-version="0.24.0" | ||
33 | Import-Package: org.apache.log4j | ||
34 | Automatic-Module-Name: ca.mcgill.rtgmrt.example.modes3 | ||
35 | Bundle-ActivationPolicy: lazy | ||
36 | Bundle-RequiredExecutionEnvironment: J2SE-1.5 | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/build.properties b/Domains/ca.mcgill.rtgmrt.example.modes3/build.properties new file mode 100644 index 00000000..a431f6b2 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/build.properties | |||
@@ -0,0 +1,11 @@ | |||
1 | bin.includes = .,\ | ||
2 | model/,\ | ||
3 | META-INF/,\ | ||
4 | plugin.xml,\ | ||
5 | plugin.properties | ||
6 | jars.compile.order = . | ||
7 | source.. = src/,\ | ||
8 | ecore-gen/,\ | ||
9 | vql-gen/,\ | ||
10 | xtend-gen/ | ||
11 | output.. = bin/ | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/ecore-gen/modes3/Modes3Factory.java b/Domains/ca.mcgill.rtgmrt.example.modes3/ecore-gen/modes3/Modes3Factory.java new file mode 100644 index 00000000..10ce47a1 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/ecore-gen/modes3/Modes3Factory.java | |||
@@ -0,0 +1,78 @@ | |||
1 | /** | ||
2 | */ | ||
3 | package modes3; | ||
4 | |||
5 | import org.eclipse.emf.ecore.EFactory; | ||
6 | |||
7 | /** | ||
8 | * <!-- begin-user-doc --> | ||
9 | * The <b>Factory</b> for the model. | ||
10 | * It provides a create method for each non-abstract class of the model. | ||
11 | * <!-- end-user-doc --> | ||
12 | * @see modes3.Modes3Package | ||
13 | * @generated | ||
14 | */ | ||
15 | public interface Modes3Factory extends EFactory { | ||
16 | /** | ||
17 | * The singleton instance of the factory. | ||
18 | * <!-- begin-user-doc --> | ||
19 | * <!-- end-user-doc --> | ||
20 | * @generated | ||
21 | */ | ||
22 | Modes3Factory eINSTANCE = modes3.impl.Modes3FactoryImpl.init(); | ||
23 | |||
24 | /** | ||
25 | * Returns a new object of class '<em>Segment</em>'. | ||
26 | * <!-- begin-user-doc --> | ||
27 | * <!-- end-user-doc --> | ||
28 | * @return a new object of class '<em>Segment</em>'. | ||
29 | * @generated | ||
30 | */ | ||
31 | Segment createSegment(); | ||
32 | |||
33 | /** | ||
34 | * Returns a new object of class '<em>Model Root</em>'. | ||
35 | * <!-- begin-user-doc --> | ||
36 | * <!-- end-user-doc --> | ||
37 | * @return a new object of class '<em>Model Root</em>'. | ||
38 | * @generated | ||
39 | */ | ||
40 | Modes3ModelRoot createModes3ModelRoot(); | ||
41 | |||
42 | /** | ||
43 | * Returns a new object of class '<em>Turnout</em>'. | ||
44 | * <!-- begin-user-doc --> | ||
45 | * <!-- end-user-doc --> | ||
46 | * @return a new object of class '<em>Turnout</em>'. | ||
47 | * @generated | ||
48 | */ | ||
49 | Turnout createTurnout(); | ||
50 | |||
51 | /** | ||
52 | * Returns a new object of class '<em>Train</em>'. | ||
53 | * <!-- begin-user-doc --> | ||
54 | * <!-- end-user-doc --> | ||
55 | * @return a new object of class '<em>Train</em>'. | ||
56 | * @generated | ||
57 | */ | ||
58 | Train createTrain(); | ||
59 | |||
60 | /** | ||
61 | * Returns a new object of class '<em>Simple Segment</em>'. | ||
62 | * <!-- begin-user-doc --> | ||
63 | * <!-- end-user-doc --> | ||
64 | * @return a new object of class '<em>Simple Segment</em>'. | ||
65 | * @generated | ||
66 | */ | ||
67 | SimpleSegment createSimpleSegment(); | ||
68 | |||
69 | /** | ||
70 | * Returns the package supported by this factory. | ||
71 | * <!-- begin-user-doc --> | ||
72 | * <!-- end-user-doc --> | ||
73 | * @return the package supported by this factory. | ||
74 | * @generated | ||
75 | */ | ||
76 | Modes3Package getModes3Package(); | ||
77 | |||
78 | } //Modes3Factory | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/ecore-gen/modes3/Modes3ModelRoot.java b/Domains/ca.mcgill.rtgmrt.example.modes3/ecore-gen/modes3/Modes3ModelRoot.java new file mode 100644 index 00000000..d46ee305 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/ecore-gen/modes3/Modes3ModelRoot.java | |||
@@ -0,0 +1,87 @@ | |||
1 | /** | ||
2 | */ | ||
3 | package modes3; | ||
4 | |||
5 | import org.eclipse.emf.common.util.EList; | ||
6 | |||
7 | import org.eclipse.emf.ecore.EObject; | ||
8 | |||
9 | /** | ||
10 | * <!-- begin-user-doc --> | ||
11 | * A representation of the model object '<em><b>Model Root</b></em>'. | ||
12 | * <!-- end-user-doc --> | ||
13 | * | ||
14 | * <p> | ||
15 | * The following features are supported: | ||
16 | * </p> | ||
17 | * <ul> | ||
18 | * <li>{@link modes3.Modes3ModelRoot#getId <em>Id</em>}</li> | ||
19 | * <li>{@link modes3.Modes3ModelRoot#getTrains <em>Trains</em>}</li> | ||
20 | * <li>{@link modes3.Modes3ModelRoot#getSegments <em>Segments</em>}</li> | ||
21 | * <li>{@link modes3.Modes3ModelRoot#getTurnouts <em>Turnouts</em>}</li> | ||
22 | * </ul> | ||
23 | * | ||
24 | * @see modes3.Modes3Package#getModes3ModelRoot() | ||
25 | * @model | ||
26 | * @generated | ||
27 | */ | ||
28 | public interface Modes3ModelRoot extends EObject { | ||
29 | /** | ||
30 | * Returns the value of the '<em><b>Id</b></em>' attribute. | ||
31 | * <!-- begin-user-doc --> | ||
32 | * <!-- end-user-doc --> | ||
33 | * @return the value of the '<em>Id</em>' attribute. | ||
34 | * @see #setId(int) | ||
35 | * @see modes3.Modes3Package#getModes3ModelRoot_Id() | ||
36 | * @model | ||
37 | * @generated | ||
38 | */ | ||
39 | int getId(); | ||
40 | |||
41 | /** | ||
42 | * Sets the value of the '{@link modes3.Modes3ModelRoot#getId <em>Id</em>}' attribute. | ||
43 | * <!-- begin-user-doc --> | ||
44 | * <!-- end-user-doc --> | ||
45 | * @param value the new value of the '<em>Id</em>' attribute. | ||
46 | * @see #getId() | ||
47 | * @generated | ||
48 | */ | ||
49 | void setId(int value); | ||
50 | |||
51 | /** | ||
52 | * Returns the value of the '<em><b>Trains</b></em>' containment reference list. | ||
53 | * The list contents are of type {@link modes3.Train}. | ||
54 | * <!-- begin-user-doc --> | ||
55 | * <!-- end-user-doc --> | ||
56 | * @return the value of the '<em>Trains</em>' containment reference list. | ||
57 | * @see modes3.Modes3Package#getModes3ModelRoot_Trains() | ||
58 | * @model containment="true" | ||
59 | * @generated | ||
60 | */ | ||
61 | EList<Train> getTrains(); | ||
62 | |||
63 | /** | ||
64 | * Returns the value of the '<em><b>Segments</b></em>' containment reference list. | ||
65 | * The list contents are of type {@link modes3.SimpleSegment}. | ||
66 | * <!-- begin-user-doc --> | ||
67 | * <!-- end-user-doc --> | ||
68 | * @return the value of the '<em>Segments</em>' containment reference list. | ||
69 | * @see modes3.Modes3Package#getModes3ModelRoot_Segments() | ||
70 | * @model containment="true" | ||
71 | * @generated | ||
72 | */ | ||
73 | EList<SimpleSegment> getSegments(); | ||
74 | |||
75 | /** | ||
76 | * Returns the value of the '<em><b>Turnouts</b></em>' containment reference list. | ||
77 | * The list contents are of type {@link modes3.Turnout}. | ||
78 | * <!-- begin-user-doc --> | ||
79 | * <!-- end-user-doc --> | ||
80 | * @return the value of the '<em>Turnouts</em>' containment reference list. | ||
81 | * @see modes3.Modes3Package#getModes3ModelRoot_Turnouts() | ||
82 | * @model containment="true" | ||
83 | * @generated | ||
84 | */ | ||
85 | EList<Turnout> getTurnouts(); | ||
86 | |||
87 | } // Modes3ModelRoot | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/ecore-gen/modes3/Modes3Package.java b/Domains/ca.mcgill.rtgmrt.example.modes3/ecore-gen/modes3/Modes3Package.java new file mode 100644 index 00000000..a19c1955 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/ecore-gen/modes3/Modes3Package.java | |||
@@ -0,0 +1,716 @@ | |||
1 | /** | ||
2 | */ | ||
3 | package modes3; | ||
4 | |||
5 | import org.eclipse.emf.ecore.EAttribute; | ||
6 | import org.eclipse.emf.ecore.EClass; | ||
7 | import org.eclipse.emf.ecore.EPackage; | ||
8 | import org.eclipse.emf.ecore.EReference; | ||
9 | |||
10 | /** | ||
11 | * <!-- begin-user-doc --> | ||
12 | * The <b>Package</b> for the model. | ||
13 | * It contains accessors for the meta objects to represent | ||
14 | * <ul> | ||
15 | * <li>each class,</li> | ||
16 | * <li>each feature of each class,</li> | ||
17 | * <li>each operation of each class,</li> | ||
18 | * <li>each enum,</li> | ||
19 | * <li>and each data type</li> | ||
20 | * </ul> | ||
21 | * <!-- end-user-doc --> | ||
22 | * @see modes3.Modes3Factory | ||
23 | * @model kind="package" | ||
24 | * @generated | ||
25 | */ | ||
26 | public interface Modes3Package extends EPackage { | ||
27 | /** | ||
28 | * The package name. | ||
29 | * <!-- begin-user-doc --> | ||
30 | * <!-- end-user-doc --> | ||
31 | * @generated | ||
32 | */ | ||
33 | String eNAME = "modes3"; | ||
34 | |||
35 | /** | ||
36 | * The package namespace URI. | ||
37 | * <!-- begin-user-doc --> | ||
38 | * <!-- end-user-doc --> | ||
39 | * @generated | ||
40 | */ | ||
41 | String eNS_URI = "http://www.ece.mcgill.ca/wcet/modes3"; | ||
42 | |||
43 | /** | ||
44 | * The package namespace name. | ||
45 | * <!-- begin-user-doc --> | ||
46 | * <!-- end-user-doc --> | ||
47 | * @generated | ||
48 | */ | ||
49 | String eNS_PREFIX = "modes3"; | ||
50 | |||
51 | /** | ||
52 | * The singleton instance of the package. | ||
53 | * <!-- begin-user-doc --> | ||
54 | * <!-- end-user-doc --> | ||
55 | * @generated | ||
56 | */ | ||
57 | Modes3Package eINSTANCE = modes3.impl.Modes3PackageImpl.init(); | ||
58 | |||
59 | /** | ||
60 | * The meta object id for the '{@link modes3.impl.SegmentImpl <em>Segment</em>}' class. | ||
61 | * <!-- begin-user-doc --> | ||
62 | * <!-- end-user-doc --> | ||
63 | * @see modes3.impl.SegmentImpl | ||
64 | * @see modes3.impl.Modes3PackageImpl#getSegment() | ||
65 | * @generated | ||
66 | */ | ||
67 | int SEGMENT = 0; | ||
68 | |||
69 | /** | ||
70 | * The feature id for the '<em><b>Connected To</b></em>' reference list. | ||
71 | * <!-- begin-user-doc --> | ||
72 | * <!-- end-user-doc --> | ||
73 | * @generated | ||
74 | * @ordered | ||
75 | */ | ||
76 | int SEGMENT__CONNECTED_TO = 0; | ||
77 | |||
78 | /** | ||
79 | * The feature id for the '<em><b>Occupied By</b></em>' reference. | ||
80 | * <!-- begin-user-doc --> | ||
81 | * <!-- end-user-doc --> | ||
82 | * @generated | ||
83 | * @ordered | ||
84 | */ | ||
85 | int SEGMENT__OCCUPIED_BY = 1; | ||
86 | |||
87 | /** | ||
88 | * The feature id for the '<em><b>Id</b></em>' attribute. | ||
89 | * <!-- begin-user-doc --> | ||
90 | * <!-- end-user-doc --> | ||
91 | * @generated | ||
92 | * @ordered | ||
93 | */ | ||
94 | int SEGMENT__ID = 2; | ||
95 | |||
96 | /** | ||
97 | * The number of structural features of the '<em>Segment</em>' class. | ||
98 | * <!-- begin-user-doc --> | ||
99 | * <!-- end-user-doc --> | ||
100 | * @generated | ||
101 | * @ordered | ||
102 | */ | ||
103 | int SEGMENT_FEATURE_COUNT = 3; | ||
104 | |||
105 | /** | ||
106 | * The number of operations of the '<em>Segment</em>' class. | ||
107 | * <!-- begin-user-doc --> | ||
108 | * <!-- end-user-doc --> | ||
109 | * @generated | ||
110 | * @ordered | ||
111 | */ | ||
112 | int SEGMENT_OPERATION_COUNT = 0; | ||
113 | |||
114 | /** | ||
115 | * The meta object id for the '{@link modes3.impl.Modes3ModelRootImpl <em>Model Root</em>}' class. | ||
116 | * <!-- begin-user-doc --> | ||
117 | * <!-- end-user-doc --> | ||
118 | * @see modes3.impl.Modes3ModelRootImpl | ||
119 | * @see modes3.impl.Modes3PackageImpl#getModes3ModelRoot() | ||
120 | * @generated | ||
121 | */ | ||
122 | int MODES3_MODEL_ROOT = 1; | ||
123 | |||
124 | /** | ||
125 | * The feature id for the '<em><b>Id</b></em>' attribute. | ||
126 | * <!-- begin-user-doc --> | ||
127 | * <!-- end-user-doc --> | ||
128 | * @generated | ||
129 | * @ordered | ||
130 | */ | ||
131 | int MODES3_MODEL_ROOT__ID = 0; | ||
132 | |||
133 | /** | ||
134 | * The feature id for the '<em><b>Trains</b></em>' containment reference list. | ||
135 | * <!-- begin-user-doc --> | ||
136 | * <!-- end-user-doc --> | ||
137 | * @generated | ||
138 | * @ordered | ||
139 | */ | ||
140 | int MODES3_MODEL_ROOT__TRAINS = 1; | ||
141 | |||
142 | /** | ||
143 | * The feature id for the '<em><b>Segments</b></em>' containment reference list. | ||
144 | * <!-- begin-user-doc --> | ||
145 | * <!-- end-user-doc --> | ||
146 | * @generated | ||
147 | * @ordered | ||
148 | */ | ||
149 | int MODES3_MODEL_ROOT__SEGMENTS = 2; | ||
150 | |||
151 | /** | ||
152 | * The feature id for the '<em><b>Turnouts</b></em>' containment reference list. | ||
153 | * <!-- begin-user-doc --> | ||
154 | * <!-- end-user-doc --> | ||
155 | * @generated | ||
156 | * @ordered | ||
157 | */ | ||
158 | int MODES3_MODEL_ROOT__TURNOUTS = 3; | ||
159 | |||
160 | /** | ||
161 | * The number of structural features of the '<em>Model Root</em>' class. | ||
162 | * <!-- begin-user-doc --> | ||
163 | * <!-- end-user-doc --> | ||
164 | * @generated | ||
165 | * @ordered | ||
166 | */ | ||
167 | int MODES3_MODEL_ROOT_FEATURE_COUNT = 4; | ||
168 | |||
169 | /** | ||
170 | * The number of operations of the '<em>Model Root</em>' class. | ||
171 | * <!-- begin-user-doc --> | ||
172 | * <!-- end-user-doc --> | ||
173 | * @generated | ||
174 | * @ordered | ||
175 | */ | ||
176 | int MODES3_MODEL_ROOT_OPERATION_COUNT = 0; | ||
177 | |||
178 | /** | ||
179 | * The meta object id for the '{@link modes3.impl.TurnoutImpl <em>Turnout</em>}' class. | ||
180 | * <!-- begin-user-doc --> | ||
181 | * <!-- end-user-doc --> | ||
182 | * @see modes3.impl.TurnoutImpl | ||
183 | * @see modes3.impl.Modes3PackageImpl#getTurnout() | ||
184 | * @generated | ||
185 | */ | ||
186 | int TURNOUT = 2; | ||
187 | |||
188 | /** | ||
189 | * The feature id for the '<em><b>Connected To</b></em>' reference list. | ||
190 | * <!-- begin-user-doc --> | ||
191 | * <!-- end-user-doc --> | ||
192 | * @generated | ||
193 | * @ordered | ||
194 | */ | ||
195 | int TURNOUT__CONNECTED_TO = SEGMENT__CONNECTED_TO; | ||
196 | |||
197 | /** | ||
198 | * The feature id for the '<em><b>Occupied By</b></em>' reference. | ||
199 | * <!-- begin-user-doc --> | ||
200 | * <!-- end-user-doc --> | ||
201 | * @generated | ||
202 | * @ordered | ||
203 | */ | ||
204 | int TURNOUT__OCCUPIED_BY = SEGMENT__OCCUPIED_BY; | ||
205 | |||
206 | /** | ||
207 | * The feature id for the '<em><b>Id</b></em>' attribute. | ||
208 | * <!-- begin-user-doc --> | ||
209 | * <!-- end-user-doc --> | ||
210 | * @generated | ||
211 | * @ordered | ||
212 | */ | ||
213 | int TURNOUT__ID = SEGMENT__ID; | ||
214 | |||
215 | /** | ||
216 | * The feature id for the '<em><b>Straight</b></em>' reference. | ||
217 | * <!-- begin-user-doc --> | ||
218 | * <!-- end-user-doc --> | ||
219 | * @generated | ||
220 | * @ordered | ||
221 | */ | ||
222 | int TURNOUT__STRAIGHT = SEGMENT_FEATURE_COUNT + 0; | ||
223 | |||
224 | /** | ||
225 | * The feature id for the '<em><b>Divergent</b></em>' reference. | ||
226 | * <!-- begin-user-doc --> | ||
227 | * <!-- end-user-doc --> | ||
228 | * @generated | ||
229 | * @ordered | ||
230 | */ | ||
231 | int TURNOUT__DIVERGENT = SEGMENT_FEATURE_COUNT + 1; | ||
232 | |||
233 | /** | ||
234 | * The number of structural features of the '<em>Turnout</em>' class. | ||
235 | * <!-- begin-user-doc --> | ||
236 | * <!-- end-user-doc --> | ||
237 | * @generated | ||
238 | * @ordered | ||
239 | */ | ||
240 | int TURNOUT_FEATURE_COUNT = SEGMENT_FEATURE_COUNT + 2; | ||
241 | |||
242 | /** | ||
243 | * The number of operations of the '<em>Turnout</em>' class. | ||
244 | * <!-- begin-user-doc --> | ||
245 | * <!-- end-user-doc --> | ||
246 | * @generated | ||
247 | * @ordered | ||
248 | */ | ||
249 | int TURNOUT_OPERATION_COUNT = SEGMENT_OPERATION_COUNT + 0; | ||
250 | |||
251 | /** | ||
252 | * The meta object id for the '{@link modes3.impl.TrainImpl <em>Train</em>}' class. | ||
253 | * <!-- begin-user-doc --> | ||
254 | * <!-- end-user-doc --> | ||
255 | * @see modes3.impl.TrainImpl | ||
256 | * @see modes3.impl.Modes3PackageImpl#getTrain() | ||
257 | * @generated | ||
258 | */ | ||
259 | int TRAIN = 3; | ||
260 | |||
261 | /** | ||
262 | * The feature id for the '<em><b>Location</b></em>' reference. | ||
263 | * <!-- begin-user-doc --> | ||
264 | * <!-- end-user-doc --> | ||
265 | * @generated | ||
266 | * @ordered | ||
267 | */ | ||
268 | int TRAIN__LOCATION = 0; | ||
269 | |||
270 | /** | ||
271 | * The feature id for the '<em><b>Id</b></em>' attribute. | ||
272 | * <!-- begin-user-doc --> | ||
273 | * <!-- end-user-doc --> | ||
274 | * @generated | ||
275 | * @ordered | ||
276 | */ | ||
277 | int TRAIN__ID = 1; | ||
278 | |||
279 | /** | ||
280 | * The feature id for the '<em><b>Speed</b></em>' attribute. | ||
281 | * <!-- begin-user-doc --> | ||
282 | * <!-- end-user-doc --> | ||
283 | * @generated | ||
284 | * @ordered | ||
285 | */ | ||
286 | int TRAIN__SPEED = 2; | ||
287 | |||
288 | /** | ||
289 | * The number of structural features of the '<em>Train</em>' class. | ||
290 | * <!-- begin-user-doc --> | ||
291 | * <!-- end-user-doc --> | ||
292 | * @generated | ||
293 | * @ordered | ||
294 | */ | ||
295 | int TRAIN_FEATURE_COUNT = 3; | ||
296 | |||
297 | /** | ||
298 | * The number of operations of the '<em>Train</em>' class. | ||
299 | * <!-- begin-user-doc --> | ||
300 | * <!-- end-user-doc --> | ||
301 | * @generated | ||
302 | * @ordered | ||
303 | */ | ||
304 | int TRAIN_OPERATION_COUNT = 0; | ||
305 | |||
306 | |||
307 | /** | ||
308 | * The meta object id for the '{@link modes3.impl.SimpleSegmentImpl <em>Simple Segment</em>}' class. | ||
309 | * <!-- begin-user-doc --> | ||
310 | * <!-- end-user-doc --> | ||
311 | * @see modes3.impl.SimpleSegmentImpl | ||
312 | * @see modes3.impl.Modes3PackageImpl#getSimpleSegment() | ||
313 | * @generated | ||
314 | */ | ||
315 | int SIMPLE_SEGMENT = 4; | ||
316 | |||
317 | /** | ||
318 | * The feature id for the '<em><b>Connected To</b></em>' reference list. | ||
319 | * <!-- begin-user-doc --> | ||
320 | * <!-- end-user-doc --> | ||
321 | * @generated | ||
322 | * @ordered | ||
323 | */ | ||
324 | int SIMPLE_SEGMENT__CONNECTED_TO = SEGMENT__CONNECTED_TO; | ||
325 | |||
326 | /** | ||
327 | * The feature id for the '<em><b>Occupied By</b></em>' reference. | ||
328 | * <!-- begin-user-doc --> | ||
329 | * <!-- end-user-doc --> | ||
330 | * @generated | ||
331 | * @ordered | ||
332 | */ | ||
333 | int SIMPLE_SEGMENT__OCCUPIED_BY = SEGMENT__OCCUPIED_BY; | ||
334 | |||
335 | /** | ||
336 | * The feature id for the '<em><b>Id</b></em>' attribute. | ||
337 | * <!-- begin-user-doc --> | ||
338 | * <!-- end-user-doc --> | ||
339 | * @generated | ||
340 | * @ordered | ||
341 | */ | ||
342 | int SIMPLE_SEGMENT__ID = SEGMENT__ID; | ||
343 | |||
344 | /** | ||
345 | * The number of structural features of the '<em>Simple Segment</em>' class. | ||
346 | * <!-- begin-user-doc --> | ||
347 | * <!-- end-user-doc --> | ||
348 | * @generated | ||
349 | * @ordered | ||
350 | */ | ||
351 | int SIMPLE_SEGMENT_FEATURE_COUNT = SEGMENT_FEATURE_COUNT + 0; | ||
352 | |||
353 | /** | ||
354 | * The number of operations of the '<em>Simple Segment</em>' class. | ||
355 | * <!-- begin-user-doc --> | ||
356 | * <!-- end-user-doc --> | ||
357 | * @generated | ||
358 | * @ordered | ||
359 | */ | ||
360 | int SIMPLE_SEGMENT_OPERATION_COUNT = SEGMENT_OPERATION_COUNT + 0; | ||
361 | |||
362 | |||
363 | /** | ||
364 | * Returns the meta object for class '{@link modes3.Segment <em>Segment</em>}'. | ||
365 | * <!-- begin-user-doc --> | ||
366 | * <!-- end-user-doc --> | ||
367 | * @return the meta object for class '<em>Segment</em>'. | ||
368 | * @see modes3.Segment | ||
369 | * @generated | ||
370 | */ | ||
371 | EClass getSegment(); | ||
372 | |||
373 | /** | ||
374 | * Returns the meta object for the reference list '{@link modes3.Segment#getConnectedTo <em>Connected To</em>}'. | ||
375 | * <!-- begin-user-doc --> | ||
376 | * <!-- end-user-doc --> | ||
377 | * @return the meta object for the reference list '<em>Connected To</em>'. | ||
378 | * @see modes3.Segment#getConnectedTo() | ||
379 | * @see #getSegment() | ||
380 | * @generated | ||
381 | */ | ||
382 | EReference getSegment_ConnectedTo(); | ||
383 | |||
384 | /** | ||
385 | * Returns the meta object for the reference '{@link modes3.Segment#getOccupiedBy <em>Occupied By</em>}'. | ||
386 | * <!-- begin-user-doc --> | ||
387 | * <!-- end-user-doc --> | ||
388 | * @return the meta object for the reference '<em>Occupied By</em>'. | ||
389 | * @see modes3.Segment#getOccupiedBy() | ||
390 | * @see #getSegment() | ||
391 | * @generated | ||
392 | */ | ||
393 | EReference getSegment_OccupiedBy(); | ||
394 | |||
395 | /** | ||
396 | * Returns the meta object for the attribute '{@link modes3.Segment#getId <em>Id</em>}'. | ||
397 | * <!-- begin-user-doc --> | ||
398 | * <!-- end-user-doc --> | ||
399 | * @return the meta object for the attribute '<em>Id</em>'. | ||
400 | * @see modes3.Segment#getId() | ||
401 | * @see #getSegment() | ||
402 | * @generated | ||
403 | */ | ||
404 | EAttribute getSegment_Id(); | ||
405 | |||
406 | /** | ||
407 | * Returns the meta object for class '{@link modes3.Modes3ModelRoot <em>Model Root</em>}'. | ||
408 | * <!-- begin-user-doc --> | ||
409 | * <!-- end-user-doc --> | ||
410 | * @return the meta object for class '<em>Model Root</em>'. | ||
411 | * @see modes3.Modes3ModelRoot | ||
412 | * @generated | ||
413 | */ | ||
414 | EClass getModes3ModelRoot(); | ||
415 | |||
416 | /** | ||
417 | * Returns the meta object for the attribute '{@link modes3.Modes3ModelRoot#getId <em>Id</em>}'. | ||
418 | * <!-- begin-user-doc --> | ||
419 | * <!-- end-user-doc --> | ||
420 | * @return the meta object for the attribute '<em>Id</em>'. | ||
421 | * @see modes3.Modes3ModelRoot#getId() | ||
422 | * @see #getModes3ModelRoot() | ||
423 | * @generated | ||
424 | */ | ||
425 | EAttribute getModes3ModelRoot_Id(); | ||
426 | |||
427 | /** | ||
428 | * Returns the meta object for the containment reference list '{@link modes3.Modes3ModelRoot#getTrains <em>Trains</em>}'. | ||
429 | * <!-- begin-user-doc --> | ||
430 | * <!-- end-user-doc --> | ||
431 | * @return the meta object for the containment reference list '<em>Trains</em>'. | ||
432 | * @see modes3.Modes3ModelRoot#getTrains() | ||
433 | * @see #getModes3ModelRoot() | ||
434 | * @generated | ||
435 | */ | ||
436 | EReference getModes3ModelRoot_Trains(); | ||
437 | |||
438 | /** | ||
439 | * Returns the meta object for the containment reference list '{@link modes3.Modes3ModelRoot#getSegments <em>Segments</em>}'. | ||
440 | * <!-- begin-user-doc --> | ||
441 | * <!-- end-user-doc --> | ||
442 | * @return the meta object for the containment reference list '<em>Segments</em>'. | ||
443 | * @see modes3.Modes3ModelRoot#getSegments() | ||
444 | * @see #getModes3ModelRoot() | ||
445 | * @generated | ||
446 | */ | ||
447 | EReference getModes3ModelRoot_Segments(); | ||
448 | |||
449 | /** | ||
450 | * Returns the meta object for the containment reference list '{@link modes3.Modes3ModelRoot#getTurnouts <em>Turnouts</em>}'. | ||
451 | * <!-- begin-user-doc --> | ||
452 | * <!-- end-user-doc --> | ||
453 | * @return the meta object for the containment reference list '<em>Turnouts</em>'. | ||
454 | * @see modes3.Modes3ModelRoot#getTurnouts() | ||
455 | * @see #getModes3ModelRoot() | ||
456 | * @generated | ||
457 | */ | ||
458 | EReference getModes3ModelRoot_Turnouts(); | ||
459 | |||
460 | /** | ||
461 | * Returns the meta object for class '{@link modes3.Turnout <em>Turnout</em>}'. | ||
462 | * <!-- begin-user-doc --> | ||
463 | * <!-- end-user-doc --> | ||
464 | * @return the meta object for class '<em>Turnout</em>'. | ||
465 | * @see modes3.Turnout | ||
466 | * @generated | ||
467 | */ | ||
468 | EClass getTurnout(); | ||
469 | |||
470 | /** | ||
471 | * Returns the meta object for the reference '{@link modes3.Turnout#getStraight <em>Straight</em>}'. | ||
472 | * <!-- begin-user-doc --> | ||
473 | * <!-- end-user-doc --> | ||
474 | * @return the meta object for the reference '<em>Straight</em>'. | ||
475 | * @see modes3.Turnout#getStraight() | ||
476 | * @see #getTurnout() | ||
477 | * @generated | ||
478 | */ | ||
479 | EReference getTurnout_Straight(); | ||
480 | |||
481 | /** | ||
482 | * Returns the meta object for the reference '{@link modes3.Turnout#getDivergent <em>Divergent</em>}'. | ||
483 | * <!-- begin-user-doc --> | ||
484 | * <!-- end-user-doc --> | ||
485 | * @return the meta object for the reference '<em>Divergent</em>'. | ||
486 | * @see modes3.Turnout#getDivergent() | ||
487 | * @see #getTurnout() | ||
488 | * @generated | ||
489 | */ | ||
490 | EReference getTurnout_Divergent(); | ||
491 | |||
492 | /** | ||
493 | * Returns the meta object for class '{@link modes3.Train <em>Train</em>}'. | ||
494 | * <!-- begin-user-doc --> | ||
495 | * <!-- end-user-doc --> | ||
496 | * @return the meta object for class '<em>Train</em>'. | ||
497 | * @see modes3.Train | ||
498 | * @generated | ||
499 | */ | ||
500 | EClass getTrain(); | ||
501 | |||
502 | /** | ||
503 | * Returns the meta object for the reference '{@link modes3.Train#getLocation <em>Location</em>}'. | ||
504 | * <!-- begin-user-doc --> | ||
505 | * <!-- end-user-doc --> | ||
506 | * @return the meta object for the reference '<em>Location</em>'. | ||
507 | * @see modes3.Train#getLocation() | ||
508 | * @see #getTrain() | ||
509 | * @generated | ||
510 | */ | ||
511 | EReference getTrain_Location(); | ||
512 | |||
513 | /** | ||
514 | * Returns the meta object for the attribute '{@link modes3.Train#getId <em>Id</em>}'. | ||
515 | * <!-- begin-user-doc --> | ||
516 | * <!-- end-user-doc --> | ||
517 | * @return the meta object for the attribute '<em>Id</em>'. | ||
518 | * @see modes3.Train#getId() | ||
519 | * @see #getTrain() | ||
520 | * @generated | ||
521 | */ | ||
522 | EAttribute getTrain_Id(); | ||
523 | |||
524 | /** | ||
525 | * Returns the meta object for the attribute '{@link modes3.Train#getSpeed <em>Speed</em>}'. | ||
526 | * <!-- begin-user-doc --> | ||
527 | * <!-- end-user-doc --> | ||
528 | * @return the meta object for the attribute '<em>Speed</em>'. | ||
529 | * @see modes3.Train#getSpeed() | ||
530 | * @see #getTrain() | ||
531 | * @generated | ||
532 | */ | ||
533 | EAttribute getTrain_Speed(); | ||
534 | |||
535 | /** | ||
536 | * Returns the meta object for class '{@link modes3.SimpleSegment <em>Simple Segment</em>}'. | ||
537 | * <!-- begin-user-doc --> | ||
538 | * <!-- end-user-doc --> | ||
539 | * @return the meta object for class '<em>Simple Segment</em>'. | ||
540 | * @see modes3.SimpleSegment | ||
541 | * @generated | ||
542 | */ | ||
543 | EClass getSimpleSegment(); | ||
544 | |||
545 | /** | ||
546 | * Returns the factory that creates the instances of the model. | ||
547 | * <!-- begin-user-doc --> | ||
548 | * <!-- end-user-doc --> | ||
549 | * @return the factory that creates the instances of the model. | ||
550 | * @generated | ||
551 | */ | ||
552 | Modes3Factory getModes3Factory(); | ||
553 | |||
554 | /** | ||
555 | * <!-- begin-user-doc --> | ||
556 | * Defines literals for the meta objects that represent | ||
557 | * <ul> | ||
558 | * <li>each class,</li> | ||
559 | * <li>each feature of each class,</li> | ||
560 | * <li>each operation of each class,</li> | ||
561 | * <li>each enum,</li> | ||
562 | * <li>and each data type</li> | ||
563 | * </ul> | ||
564 | * <!-- end-user-doc --> | ||
565 | * @generated | ||
566 | */ | ||
567 | interface Literals { | ||
568 | /** | ||
569 | * The meta object literal for the '{@link modes3.impl.SegmentImpl <em>Segment</em>}' class. | ||
570 | * <!-- begin-user-doc --> | ||
571 | * <!-- end-user-doc --> | ||
572 | * @see modes3.impl.SegmentImpl | ||
573 | * @see modes3.impl.Modes3PackageImpl#getSegment() | ||
574 | * @generated | ||
575 | */ | ||
576 | EClass SEGMENT = eINSTANCE.getSegment(); | ||
577 | |||
578 | /** | ||
579 | * The meta object literal for the '<em><b>Connected To</b></em>' reference list feature. | ||
580 | * <!-- begin-user-doc --> | ||
581 | * <!-- end-user-doc --> | ||
582 | * @generated | ||
583 | */ | ||
584 | EReference SEGMENT__CONNECTED_TO = eINSTANCE.getSegment_ConnectedTo(); | ||
585 | |||
586 | /** | ||
587 | * The meta object literal for the '<em><b>Occupied By</b></em>' reference feature. | ||
588 | * <!-- begin-user-doc --> | ||
589 | * <!-- end-user-doc --> | ||
590 | * @generated | ||
591 | */ | ||
592 | EReference SEGMENT__OCCUPIED_BY = eINSTANCE.getSegment_OccupiedBy(); | ||
593 | |||
594 | /** | ||
595 | * The meta object literal for the '<em><b>Id</b></em>' attribute feature. | ||
596 | * <!-- begin-user-doc --> | ||
597 | * <!-- end-user-doc --> | ||
598 | * @generated | ||
599 | */ | ||
600 | EAttribute SEGMENT__ID = eINSTANCE.getSegment_Id(); | ||
601 | |||
602 | /** | ||
603 | * The meta object literal for the '{@link modes3.impl.Modes3ModelRootImpl <em>Model Root</em>}' class. | ||
604 | * <!-- begin-user-doc --> | ||
605 | * <!-- end-user-doc --> | ||
606 | * @see modes3.impl.Modes3ModelRootImpl | ||
607 | * @see modes3.impl.Modes3PackageImpl#getModes3ModelRoot() | ||
608 | * @generated | ||
609 | */ | ||
610 | EClass MODES3_MODEL_ROOT = eINSTANCE.getModes3ModelRoot(); | ||
611 | |||
612 | /** | ||
613 | * The meta object literal for the '<em><b>Id</b></em>' attribute feature. | ||
614 | * <!-- begin-user-doc --> | ||
615 | * <!-- end-user-doc --> | ||
616 | * @generated | ||
617 | */ | ||
618 | EAttribute MODES3_MODEL_ROOT__ID = eINSTANCE.getModes3ModelRoot_Id(); | ||
619 | |||
620 | /** | ||
621 | * The meta object literal for the '<em><b>Trains</b></em>' containment reference list feature. | ||
622 | * <!-- begin-user-doc --> | ||
623 | * <!-- end-user-doc --> | ||
624 | * @generated | ||
625 | */ | ||
626 | EReference MODES3_MODEL_ROOT__TRAINS = eINSTANCE.getModes3ModelRoot_Trains(); | ||
627 | |||
628 | /** | ||
629 | * The meta object literal for the '<em><b>Segments</b></em>' containment reference list feature. | ||
630 | * <!-- begin-user-doc --> | ||
631 | * <!-- end-user-doc --> | ||
632 | * @generated | ||
633 | */ | ||
634 | EReference MODES3_MODEL_ROOT__SEGMENTS = eINSTANCE.getModes3ModelRoot_Segments(); | ||
635 | |||
636 | /** | ||
637 | * The meta object literal for the '<em><b>Turnouts</b></em>' containment reference list feature. | ||
638 | * <!-- begin-user-doc --> | ||
639 | * <!-- end-user-doc --> | ||
640 | * @generated | ||
641 | */ | ||
642 | EReference MODES3_MODEL_ROOT__TURNOUTS = eINSTANCE.getModes3ModelRoot_Turnouts(); | ||
643 | |||
644 | /** | ||
645 | * The meta object literal for the '{@link modes3.impl.TurnoutImpl <em>Turnout</em>}' class. | ||
646 | * <!-- begin-user-doc --> | ||
647 | * <!-- end-user-doc --> | ||
648 | * @see modes3.impl.TurnoutImpl | ||
649 | * @see modes3.impl.Modes3PackageImpl#getTurnout() | ||
650 | * @generated | ||
651 | */ | ||
652 | EClass TURNOUT = eINSTANCE.getTurnout(); | ||
653 | |||
654 | /** | ||
655 | * The meta object literal for the '<em><b>Straight</b></em>' reference feature. | ||
656 | * <!-- begin-user-doc --> | ||
657 | * <!-- end-user-doc --> | ||
658 | * @generated | ||
659 | */ | ||
660 | EReference TURNOUT__STRAIGHT = eINSTANCE.getTurnout_Straight(); | ||
661 | |||
662 | /** | ||
663 | * The meta object literal for the '<em><b>Divergent</b></em>' reference feature. | ||
664 | * <!-- begin-user-doc --> | ||
665 | * <!-- end-user-doc --> | ||
666 | * @generated | ||
667 | */ | ||
668 | EReference TURNOUT__DIVERGENT = eINSTANCE.getTurnout_Divergent(); | ||
669 | |||
670 | /** | ||
671 | * The meta object literal for the '{@link modes3.impl.TrainImpl <em>Train</em>}' class. | ||
672 | * <!-- begin-user-doc --> | ||
673 | * <!-- end-user-doc --> | ||
674 | * @see modes3.impl.TrainImpl | ||
675 | * @see modes3.impl.Modes3PackageImpl#getTrain() | ||
676 | * @generated | ||
677 | */ | ||
678 | EClass TRAIN = eINSTANCE.getTrain(); | ||
679 | |||
680 | /** | ||
681 | * The meta object literal for the '<em><b>Location</b></em>' reference feature. | ||
682 | * <!-- begin-user-doc --> | ||
683 | * <!-- end-user-doc --> | ||
684 | * @generated | ||
685 | */ | ||
686 | EReference TRAIN__LOCATION = eINSTANCE.getTrain_Location(); | ||
687 | |||
688 | /** | ||
689 | * The meta object literal for the '<em><b>Id</b></em>' attribute feature. | ||
690 | * <!-- begin-user-doc --> | ||
691 | * <!-- end-user-doc --> | ||
692 | * @generated | ||
693 | */ | ||
694 | EAttribute TRAIN__ID = eINSTANCE.getTrain_Id(); | ||
695 | |||
696 | /** | ||
697 | * The meta object literal for the '<em><b>Speed</b></em>' attribute feature. | ||
698 | * <!-- begin-user-doc --> | ||
699 | * <!-- end-user-doc --> | ||
700 | * @generated | ||
701 | */ | ||
702 | EAttribute TRAIN__SPEED = eINSTANCE.getTrain_Speed(); | ||
703 | |||
704 | /** | ||
705 | * The meta object literal for the '{@link modes3.impl.SimpleSegmentImpl <em>Simple Segment</em>}' class. | ||
706 | * <!-- begin-user-doc --> | ||
707 | * <!-- end-user-doc --> | ||
708 | * @see modes3.impl.SimpleSegmentImpl | ||
709 | * @see modes3.impl.Modes3PackageImpl#getSimpleSegment() | ||
710 | * @generated | ||
711 | */ | ||
712 | EClass SIMPLE_SEGMENT = eINSTANCE.getSimpleSegment(); | ||
713 | |||
714 | } | ||
715 | |||
716 | } //Modes3Package | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/ecore-gen/modes3/Segment.java b/Domains/ca.mcgill.rtgmrt.example.modes3/ecore-gen/modes3/Segment.java new file mode 100644 index 00000000..002f25a5 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/ecore-gen/modes3/Segment.java | |||
@@ -0,0 +1,86 @@ | |||
1 | /** | ||
2 | */ | ||
3 | package modes3; | ||
4 | |||
5 | import org.eclipse.emf.common.util.EList; | ||
6 | |||
7 | import org.eclipse.emf.ecore.EObject; | ||
8 | |||
9 | /** | ||
10 | * <!-- begin-user-doc --> | ||
11 | * A representation of the model object '<em><b>Segment</b></em>'. | ||
12 | * <!-- end-user-doc --> | ||
13 | * | ||
14 | * <p> | ||
15 | * The following features are supported: | ||
16 | * </p> | ||
17 | * <ul> | ||
18 | * <li>{@link modes3.Segment#getConnectedTo <em>Connected To</em>}</li> | ||
19 | * <li>{@link modes3.Segment#getOccupiedBy <em>Occupied By</em>}</li> | ||
20 | * <li>{@link modes3.Segment#getId <em>Id</em>}</li> | ||
21 | * </ul> | ||
22 | * | ||
23 | * @see modes3.Modes3Package#getSegment() | ||
24 | * @model | ||
25 | * @generated | ||
26 | */ | ||
27 | public interface Segment extends EObject { | ||
28 | /** | ||
29 | * Returns the value of the '<em><b>Connected To</b></em>' reference list. | ||
30 | * The list contents are of type {@link modes3.Segment}. | ||
31 | * <!-- begin-user-doc --> | ||
32 | * <!-- end-user-doc --> | ||
33 | * @return the value of the '<em>Connected To</em>' reference list. | ||
34 | * @see modes3.Modes3Package#getSegment_ConnectedTo() | ||
35 | * @model upper="2" | ||
36 | * @generated | ||
37 | */ | ||
38 | EList<Segment> getConnectedTo(); | ||
39 | |||
40 | /** | ||
41 | * Returns the value of the '<em><b>Occupied By</b></em>' reference. | ||
42 | * It is bidirectional and its opposite is '{@link modes3.Train#getLocation <em>Location</em>}'. | ||
43 | * <!-- begin-user-doc --> | ||
44 | * <!-- end-user-doc --> | ||
45 | * @return the value of the '<em>Occupied By</em>' reference. | ||
46 | * @see #setOccupiedBy(Train) | ||
47 | * @see modes3.Modes3Package#getSegment_OccupiedBy() | ||
48 | * @see modes3.Train#getLocation | ||
49 | * @model opposite="location" | ||
50 | * @generated | ||
51 | */ | ||
52 | Train getOccupiedBy(); | ||
53 | |||
54 | /** | ||
55 | * Sets the value of the '{@link modes3.Segment#getOccupiedBy <em>Occupied By</em>}' reference. | ||
56 | * <!-- begin-user-doc --> | ||
57 | * <!-- end-user-doc --> | ||
58 | * @param value the new value of the '<em>Occupied By</em>' reference. | ||
59 | * @see #getOccupiedBy() | ||
60 | * @generated | ||
61 | */ | ||
62 | void setOccupiedBy(Train value); | ||
63 | |||
64 | /** | ||
65 | * Returns the value of the '<em><b>Id</b></em>' attribute. | ||
66 | * <!-- begin-user-doc --> | ||
67 | * <!-- end-user-doc --> | ||
68 | * @return the value of the '<em>Id</em>' attribute. | ||
69 | * @see #setId(int) | ||
70 | * @see modes3.Modes3Package#getSegment_Id() | ||
71 | * @model | ||
72 | * @generated | ||
73 | */ | ||
74 | int getId(); | ||
75 | |||
76 | /** | ||
77 | * Sets the value of the '{@link modes3.Segment#getId <em>Id</em>}' attribute. | ||
78 | * <!-- begin-user-doc --> | ||
79 | * <!-- end-user-doc --> | ||
80 | * @param value the new value of the '<em>Id</em>' attribute. | ||
81 | * @see #getId() | ||
82 | * @generated | ||
83 | */ | ||
84 | void setId(int value); | ||
85 | |||
86 | } // Segment | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/ecore-gen/modes3/SimpleSegment.java b/Domains/ca.mcgill.rtgmrt.example.modes3/ecore-gen/modes3/SimpleSegment.java new file mode 100644 index 00000000..da77510f --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/ecore-gen/modes3/SimpleSegment.java | |||
@@ -0,0 +1,17 @@ | |||
1 | /** | ||
2 | */ | ||
3 | package modes3; | ||
4 | |||
5 | |||
6 | /** | ||
7 | * <!-- begin-user-doc --> | ||
8 | * A representation of the model object '<em><b>Simple Segment</b></em>'. | ||
9 | * <!-- end-user-doc --> | ||
10 | * | ||
11 | * | ||
12 | * @see modes3.Modes3Package#getSimpleSegment() | ||
13 | * @model | ||
14 | * @generated | ||
15 | */ | ||
16 | public interface SimpleSegment extends Segment { | ||
17 | } // SimpleSegment | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/ecore-gen/modes3/Train.java b/Domains/ca.mcgill.rtgmrt.example.modes3/ecore-gen/modes3/Train.java new file mode 100644 index 00000000..1829586d --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/ecore-gen/modes3/Train.java | |||
@@ -0,0 +1,94 @@ | |||
1 | /** | ||
2 | */ | ||
3 | package modes3; | ||
4 | |||
5 | import org.eclipse.emf.ecore.EObject; | ||
6 | |||
7 | /** | ||
8 | * <!-- begin-user-doc --> | ||
9 | * A representation of the model object '<em><b>Train</b></em>'. | ||
10 | * <!-- end-user-doc --> | ||
11 | * | ||
12 | * <p> | ||
13 | * The following features are supported: | ||
14 | * </p> | ||
15 | * <ul> | ||
16 | * <li>{@link modes3.Train#getLocation <em>Location</em>}</li> | ||
17 | * <li>{@link modes3.Train#getId <em>Id</em>}</li> | ||
18 | * <li>{@link modes3.Train#getSpeed <em>Speed</em>}</li> | ||
19 | * </ul> | ||
20 | * | ||
21 | * @see modes3.Modes3Package#getTrain() | ||
22 | * @model | ||
23 | * @generated | ||
24 | */ | ||
25 | public interface Train extends EObject { | ||
26 | /** | ||
27 | * Returns the value of the '<em><b>Location</b></em>' reference. | ||
28 | * It is bidirectional and its opposite is '{@link modes3.Segment#getOccupiedBy <em>Occupied By</em>}'. | ||
29 | * <!-- begin-user-doc --> | ||
30 | * <!-- end-user-doc --> | ||
31 | * @return the value of the '<em>Location</em>' reference. | ||
32 | * @see #setLocation(Segment) | ||
33 | * @see modes3.Modes3Package#getTrain_Location() | ||
34 | * @see modes3.Segment#getOccupiedBy | ||
35 | * @model opposite="occupiedBy" required="true" | ||
36 | * @generated | ||
37 | */ | ||
38 | Segment getLocation(); | ||
39 | |||
40 | /** | ||
41 | * Sets the value of the '{@link modes3.Train#getLocation <em>Location</em>}' reference. | ||
42 | * <!-- begin-user-doc --> | ||
43 | * <!-- end-user-doc --> | ||
44 | * @param value the new value of the '<em>Location</em>' reference. | ||
45 | * @see #getLocation() | ||
46 | * @generated | ||
47 | */ | ||
48 | void setLocation(Segment value); | ||
49 | |||
50 | /** | ||
51 | * Returns the value of the '<em><b>Id</b></em>' attribute. | ||
52 | * <!-- begin-user-doc --> | ||
53 | * <!-- end-user-doc --> | ||
54 | * @return the value of the '<em>Id</em>' attribute. | ||
55 | * @see #setId(int) | ||
56 | * @see modes3.Modes3Package#getTrain_Id() | ||
57 | * @model | ||
58 | * @generated | ||
59 | */ | ||
60 | int getId(); | ||
61 | |||
62 | /** | ||
63 | * Sets the value of the '{@link modes3.Train#getId <em>Id</em>}' attribute. | ||
64 | * <!-- begin-user-doc --> | ||
65 | * <!-- end-user-doc --> | ||
66 | * @param value the new value of the '<em>Id</em>' attribute. | ||
67 | * @see #getId() | ||
68 | * @generated | ||
69 | */ | ||
70 | void setId(int value); | ||
71 | |||
72 | /** | ||
73 | * Returns the value of the '<em><b>Speed</b></em>' attribute. | ||
74 | * <!-- begin-user-doc --> | ||
75 | * <!-- end-user-doc --> | ||
76 | * @return the value of the '<em>Speed</em>' attribute. | ||
77 | * @see #setSpeed(double) | ||
78 | * @see modes3.Modes3Package#getTrain_Speed() | ||
79 | * @model | ||
80 | * @generated | ||
81 | */ | ||
82 | double getSpeed(); | ||
83 | |||
84 | /** | ||
85 | * Sets the value of the '{@link modes3.Train#getSpeed <em>Speed</em>}' attribute. | ||
86 | * <!-- begin-user-doc --> | ||
87 | * <!-- end-user-doc --> | ||
88 | * @param value the new value of the '<em>Speed</em>' attribute. | ||
89 | * @see #getSpeed() | ||
90 | * @generated | ||
91 | */ | ||
92 | void setSpeed(double value); | ||
93 | |||
94 | } // Train | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/ecore-gen/modes3/Turnout.java b/Domains/ca.mcgill.rtgmrt.example.modes3/ecore-gen/modes3/Turnout.java new file mode 100644 index 00000000..799f8d7b --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/ecore-gen/modes3/Turnout.java | |||
@@ -0,0 +1,68 @@ | |||
1 | /** | ||
2 | */ | ||
3 | package modes3; | ||
4 | |||
5 | |||
6 | /** | ||
7 | * <!-- begin-user-doc --> | ||
8 | * A representation of the model object '<em><b>Turnout</b></em>'. | ||
9 | * <!-- end-user-doc --> | ||
10 | * | ||
11 | * <p> | ||
12 | * The following features are supported: | ||
13 | * </p> | ||
14 | * <ul> | ||
15 | * <li>{@link modes3.Turnout#getStraight <em>Straight</em>}</li> | ||
16 | * <li>{@link modes3.Turnout#getDivergent <em>Divergent</em>}</li> | ||
17 | * </ul> | ||
18 | * | ||
19 | * @see modes3.Modes3Package#getTurnout() | ||
20 | * @model | ||
21 | * @generated | ||
22 | */ | ||
23 | public interface Turnout extends Segment { | ||
24 | /** | ||
25 | * Returns the value of the '<em><b>Straight</b></em>' reference. | ||
26 | * <!-- begin-user-doc --> | ||
27 | * <!-- end-user-doc --> | ||
28 | * @return the value of the '<em>Straight</em>' reference. | ||
29 | * @see #setStraight(Segment) | ||
30 | * @see modes3.Modes3Package#getTurnout_Straight() | ||
31 | * @model required="true" | ||
32 | * @generated | ||
33 | */ | ||
34 | Segment getStraight(); | ||
35 | |||
36 | /** | ||
37 | * Sets the value of the '{@link modes3.Turnout#getStraight <em>Straight</em>}' reference. | ||
38 | * <!-- begin-user-doc --> | ||
39 | * <!-- end-user-doc --> | ||
40 | * @param value the new value of the '<em>Straight</em>' reference. | ||
41 | * @see #getStraight() | ||
42 | * @generated | ||
43 | */ | ||
44 | void setStraight(Segment value); | ||
45 | |||
46 | /** | ||
47 | * Returns the value of the '<em><b>Divergent</b></em>' reference. | ||
48 | * <!-- begin-user-doc --> | ||
49 | * <!-- end-user-doc --> | ||
50 | * @return the value of the '<em>Divergent</em>' reference. | ||
51 | * @see #setDivergent(Segment) | ||
52 | * @see modes3.Modes3Package#getTurnout_Divergent() | ||
53 | * @model required="true" | ||
54 | * @generated | ||
55 | */ | ||
56 | Segment getDivergent(); | ||
57 | |||
58 | /** | ||
59 | * Sets the value of the '{@link modes3.Turnout#getDivergent <em>Divergent</em>}' reference. | ||
60 | * <!-- begin-user-doc --> | ||
61 | * <!-- end-user-doc --> | ||
62 | * @param value the new value of the '<em>Divergent</em>' reference. | ||
63 | * @see #getDivergent() | ||
64 | * @generated | ||
65 | */ | ||
66 | void setDivergent(Segment value); | ||
67 | |||
68 | } // Turnout | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/ecore-gen/modes3/impl/Modes3FactoryImpl.java b/Domains/ca.mcgill.rtgmrt.example.modes3/ecore-gen/modes3/impl/Modes3FactoryImpl.java new file mode 100644 index 00000000..60947533 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/ecore-gen/modes3/impl/Modes3FactoryImpl.java | |||
@@ -0,0 +1,139 @@ | |||
1 | /** | ||
2 | */ | ||
3 | package modes3.impl; | ||
4 | |||
5 | import modes3.*; | ||
6 | |||
7 | import org.eclipse.emf.ecore.EClass; | ||
8 | import org.eclipse.emf.ecore.EObject; | ||
9 | import org.eclipse.emf.ecore.EPackage; | ||
10 | |||
11 | import org.eclipse.emf.ecore.impl.EFactoryImpl; | ||
12 | |||
13 | import org.eclipse.emf.ecore.plugin.EcorePlugin; | ||
14 | |||
15 | /** | ||
16 | * <!-- begin-user-doc --> | ||
17 | * An implementation of the model <b>Factory</b>. | ||
18 | * <!-- end-user-doc --> | ||
19 | * @generated | ||
20 | */ | ||
21 | public class Modes3FactoryImpl extends EFactoryImpl implements Modes3Factory { | ||
22 | /** | ||
23 | * Creates the default factory implementation. | ||
24 | * <!-- begin-user-doc --> | ||
25 | * <!-- end-user-doc --> | ||
26 | * @generated | ||
27 | */ | ||
28 | public static Modes3Factory init() { | ||
29 | try { | ||
30 | Modes3Factory theModes3Factory = (Modes3Factory)EPackage.Registry.INSTANCE.getEFactory(Modes3Package.eNS_URI); | ||
31 | if (theModes3Factory != null) { | ||
32 | return theModes3Factory; | ||
33 | } | ||
34 | } | ||
35 | catch (Exception exception) { | ||
36 | EcorePlugin.INSTANCE.log(exception); | ||
37 | } | ||
38 | return new Modes3FactoryImpl(); | ||
39 | } | ||
40 | |||
41 | /** | ||
42 | * Creates an instance of the factory. | ||
43 | * <!-- begin-user-doc --> | ||
44 | * <!-- end-user-doc --> | ||
45 | * @generated | ||
46 | */ | ||
47 | public Modes3FactoryImpl() { | ||
48 | super(); | ||
49 | } | ||
50 | |||
51 | /** | ||
52 | * <!-- begin-user-doc --> | ||
53 | * <!-- end-user-doc --> | ||
54 | * @generated | ||
55 | */ | ||
56 | @Override | ||
57 | public EObject create(EClass eClass) { | ||
58 | switch (eClass.getClassifierID()) { | ||
59 | case Modes3Package.SEGMENT: return createSegment(); | ||
60 | case Modes3Package.MODES3_MODEL_ROOT: return createModes3ModelRoot(); | ||
61 | case Modes3Package.TURNOUT: return createTurnout(); | ||
62 | case Modes3Package.TRAIN: return createTrain(); | ||
63 | case Modes3Package.SIMPLE_SEGMENT: return createSimpleSegment(); | ||
64 | default: | ||
65 | throw new IllegalArgumentException("The class '" + eClass.getName() + "' is not a valid classifier"); | ||
66 | } | ||
67 | } | ||
68 | |||
69 | /** | ||
70 | * <!-- begin-user-doc --> | ||
71 | * <!-- end-user-doc --> | ||
72 | * @generated | ||
73 | */ | ||
74 | public Segment createSegment() { | ||
75 | SegmentImpl segment = new SegmentImpl(); | ||
76 | return segment; | ||
77 | } | ||
78 | |||
79 | /** | ||
80 | * <!-- begin-user-doc --> | ||
81 | * <!-- end-user-doc --> | ||
82 | * @generated | ||
83 | */ | ||
84 | public Modes3ModelRoot createModes3ModelRoot() { | ||
85 | Modes3ModelRootImpl modes3ModelRoot = new Modes3ModelRootImpl(); | ||
86 | return modes3ModelRoot; | ||
87 | } | ||
88 | |||
89 | /** | ||
90 | * <!-- begin-user-doc --> | ||
91 | * <!-- end-user-doc --> | ||
92 | * @generated | ||
93 | */ | ||
94 | public Turnout createTurnout() { | ||
95 | TurnoutImpl turnout = new TurnoutImpl(); | ||
96 | return turnout; | ||
97 | } | ||
98 | |||
99 | /** | ||
100 | * <!-- begin-user-doc --> | ||
101 | * <!-- end-user-doc --> | ||
102 | * @generated | ||
103 | */ | ||
104 | public Train createTrain() { | ||
105 | TrainImpl train = new TrainImpl(); | ||
106 | return train; | ||
107 | } | ||
108 | |||
109 | /** | ||
110 | * <!-- begin-user-doc --> | ||
111 | * <!-- end-user-doc --> | ||
112 | * @generated | ||
113 | */ | ||
114 | public SimpleSegment createSimpleSegment() { | ||
115 | SimpleSegmentImpl simpleSegment = new SimpleSegmentImpl(); | ||
116 | return simpleSegment; | ||
117 | } | ||
118 | |||
119 | /** | ||
120 | * <!-- begin-user-doc --> | ||
121 | * <!-- end-user-doc --> | ||
122 | * @generated | ||
123 | */ | ||
124 | public Modes3Package getModes3Package() { | ||
125 | return (Modes3Package)getEPackage(); | ||
126 | } | ||
127 | |||
128 | /** | ||
129 | * <!-- begin-user-doc --> | ||
130 | * <!-- end-user-doc --> | ||
131 | * @deprecated | ||
132 | * @generated | ||
133 | */ | ||
134 | @Deprecated | ||
135 | public static Modes3Package getPackage() { | ||
136 | return Modes3Package.eINSTANCE; | ||
137 | } | ||
138 | |||
139 | } //Modes3FactoryImpl | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/ecore-gen/modes3/impl/Modes3ModelRootImpl.java b/Domains/ca.mcgill.rtgmrt.example.modes3/ecore-gen/modes3/impl/Modes3ModelRootImpl.java new file mode 100644 index 00000000..ccab1f29 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/ecore-gen/modes3/impl/Modes3ModelRootImpl.java | |||
@@ -0,0 +1,296 @@ | |||
1 | /** | ||
2 | */ | ||
3 | package modes3.impl; | ||
4 | |||
5 | import java.util.Collection; | ||
6 | |||
7 | import modes3.Modes3ModelRoot; | ||
8 | import modes3.Modes3Package; | ||
9 | import modes3.SimpleSegment; | ||
10 | import modes3.Train; | ||
11 | import modes3.Turnout; | ||
12 | |||
13 | import org.eclipse.emf.common.notify.Notification; | ||
14 | import org.eclipse.emf.common.notify.NotificationChain; | ||
15 | |||
16 | import org.eclipse.emf.common.util.EList; | ||
17 | |||
18 | import org.eclipse.emf.ecore.EClass; | ||
19 | import org.eclipse.emf.ecore.InternalEObject; | ||
20 | |||
21 | import org.eclipse.emf.ecore.impl.ENotificationImpl; | ||
22 | import org.eclipse.emf.ecore.impl.MinimalEObjectImpl; | ||
23 | |||
24 | import org.eclipse.emf.ecore.util.EObjectContainmentEList; | ||
25 | import org.eclipse.emf.ecore.util.InternalEList; | ||
26 | |||
27 | /** | ||
28 | * <!-- begin-user-doc --> | ||
29 | * An implementation of the model object '<em><b>Model Root</b></em>'. | ||
30 | * <!-- end-user-doc --> | ||
31 | * <p> | ||
32 | * The following features are implemented: | ||
33 | * </p> | ||
34 | * <ul> | ||
35 | * <li>{@link modes3.impl.Modes3ModelRootImpl#getId <em>Id</em>}</li> | ||
36 | * <li>{@link modes3.impl.Modes3ModelRootImpl#getTrains <em>Trains</em>}</li> | ||
37 | * <li>{@link modes3.impl.Modes3ModelRootImpl#getSegments <em>Segments</em>}</li> | ||
38 | * <li>{@link modes3.impl.Modes3ModelRootImpl#getTurnouts <em>Turnouts</em>}</li> | ||
39 | * </ul> | ||
40 | * | ||
41 | * @generated | ||
42 | */ | ||
43 | public class Modes3ModelRootImpl extends MinimalEObjectImpl.Container implements Modes3ModelRoot { | ||
44 | /** | ||
45 | * The default value of the '{@link #getId() <em>Id</em>}' attribute. | ||
46 | * <!-- begin-user-doc --> | ||
47 | * <!-- end-user-doc --> | ||
48 | * @see #getId() | ||
49 | * @generated | ||
50 | * @ordered | ||
51 | */ | ||
52 | protected static final int ID_EDEFAULT = 0; | ||
53 | |||
54 | /** | ||
55 | * The cached value of the '{@link #getId() <em>Id</em>}' attribute. | ||
56 | * <!-- begin-user-doc --> | ||
57 | * <!-- end-user-doc --> | ||
58 | * @see #getId() | ||
59 | * @generated | ||
60 | * @ordered | ||
61 | */ | ||
62 | protected int id = ID_EDEFAULT; | ||
63 | |||
64 | /** | ||
65 | * The cached value of the '{@link #getTrains() <em>Trains</em>}' containment reference list. | ||
66 | * <!-- begin-user-doc --> | ||
67 | * <!-- end-user-doc --> | ||
68 | * @see #getTrains() | ||
69 | * @generated | ||
70 | * @ordered | ||
71 | */ | ||
72 | protected EList<Train> trains; | ||
73 | |||
74 | /** | ||
75 | * The cached value of the '{@link #getSegments() <em>Segments</em>}' containment reference list. | ||
76 | * <!-- begin-user-doc --> | ||
77 | * <!-- end-user-doc --> | ||
78 | * @see #getSegments() | ||
79 | * @generated | ||
80 | * @ordered | ||
81 | */ | ||
82 | protected EList<SimpleSegment> segments; | ||
83 | |||
84 | /** | ||
85 | * The cached value of the '{@link #getTurnouts() <em>Turnouts</em>}' containment reference list. | ||
86 | * <!-- begin-user-doc --> | ||
87 | * <!-- end-user-doc --> | ||
88 | * @see #getTurnouts() | ||
89 | * @generated | ||
90 | * @ordered | ||
91 | */ | ||
92 | protected EList<Turnout> turnouts; | ||
93 | |||
94 | /** | ||
95 | * <!-- begin-user-doc --> | ||
96 | * <!-- end-user-doc --> | ||
97 | * @generated | ||
98 | */ | ||
99 | protected Modes3ModelRootImpl() { | ||
100 | super(); | ||
101 | } | ||
102 | |||
103 | /** | ||
104 | * <!-- begin-user-doc --> | ||
105 | * <!-- end-user-doc --> | ||
106 | * @generated | ||
107 | */ | ||
108 | @Override | ||
109 | protected EClass eStaticClass() { | ||
110 | return Modes3Package.Literals.MODES3_MODEL_ROOT; | ||
111 | } | ||
112 | |||
113 | /** | ||
114 | * <!-- begin-user-doc --> | ||
115 | * <!-- end-user-doc --> | ||
116 | * @generated | ||
117 | */ | ||
118 | public int getId() { | ||
119 | return id; | ||
120 | } | ||
121 | |||
122 | /** | ||
123 | * <!-- begin-user-doc --> | ||
124 | * <!-- end-user-doc --> | ||
125 | * @generated | ||
126 | */ | ||
127 | public void setId(int newId) { | ||
128 | int oldId = id; | ||
129 | id = newId; | ||
130 | if (eNotificationRequired()) | ||
131 | eNotify(new ENotificationImpl(this, Notification.SET, Modes3Package.MODES3_MODEL_ROOT__ID, oldId, id)); | ||
132 | } | ||
133 | |||
134 | /** | ||
135 | * <!-- begin-user-doc --> | ||
136 | * <!-- end-user-doc --> | ||
137 | * @generated | ||
138 | */ | ||
139 | public EList<Train> getTrains() { | ||
140 | if (trains == null) { | ||
141 | trains = new EObjectContainmentEList<Train>(Train.class, this, Modes3Package.MODES3_MODEL_ROOT__TRAINS); | ||
142 | } | ||
143 | return trains; | ||
144 | } | ||
145 | |||
146 | /** | ||
147 | * <!-- begin-user-doc --> | ||
148 | * <!-- end-user-doc --> | ||
149 | * @generated | ||
150 | */ | ||
151 | public EList<SimpleSegment> getSegments() { | ||
152 | if (segments == null) { | ||
153 | segments = new EObjectContainmentEList<SimpleSegment>(SimpleSegment.class, this, Modes3Package.MODES3_MODEL_ROOT__SEGMENTS); | ||
154 | } | ||
155 | return segments; | ||
156 | } | ||
157 | |||
158 | /** | ||
159 | * <!-- begin-user-doc --> | ||
160 | * <!-- end-user-doc --> | ||
161 | * @generated | ||
162 | */ | ||
163 | public EList<Turnout> getTurnouts() { | ||
164 | if (turnouts == null) { | ||
165 | turnouts = new EObjectContainmentEList<Turnout>(Turnout.class, this, Modes3Package.MODES3_MODEL_ROOT__TURNOUTS); | ||
166 | } | ||
167 | return turnouts; | ||
168 | } | ||
169 | |||
170 | /** | ||
171 | * <!-- begin-user-doc --> | ||
172 | * <!-- end-user-doc --> | ||
173 | * @generated | ||
174 | */ | ||
175 | @Override | ||
176 | public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) { | ||
177 | switch (featureID) { | ||
178 | case Modes3Package.MODES3_MODEL_ROOT__TRAINS: | ||
179 | return ((InternalEList<?>)getTrains()).basicRemove(otherEnd, msgs); | ||
180 | case Modes3Package.MODES3_MODEL_ROOT__SEGMENTS: | ||
181 | return ((InternalEList<?>)getSegments()).basicRemove(otherEnd, msgs); | ||
182 | case Modes3Package.MODES3_MODEL_ROOT__TURNOUTS: | ||
183 | return ((InternalEList<?>)getTurnouts()).basicRemove(otherEnd, msgs); | ||
184 | } | ||
185 | return super.eInverseRemove(otherEnd, featureID, msgs); | ||
186 | } | ||
187 | |||
188 | /** | ||
189 | * <!-- begin-user-doc --> | ||
190 | * <!-- end-user-doc --> | ||
191 | * @generated | ||
192 | */ | ||
193 | @Override | ||
194 | public Object eGet(int featureID, boolean resolve, boolean coreType) { | ||
195 | switch (featureID) { | ||
196 | case Modes3Package.MODES3_MODEL_ROOT__ID: | ||
197 | return getId(); | ||
198 | case Modes3Package.MODES3_MODEL_ROOT__TRAINS: | ||
199 | return getTrains(); | ||
200 | case Modes3Package.MODES3_MODEL_ROOT__SEGMENTS: | ||
201 | return getSegments(); | ||
202 | case Modes3Package.MODES3_MODEL_ROOT__TURNOUTS: | ||
203 | return getTurnouts(); | ||
204 | } | ||
205 | return super.eGet(featureID, resolve, coreType); | ||
206 | } | ||
207 | |||
208 | /** | ||
209 | * <!-- begin-user-doc --> | ||
210 | * <!-- end-user-doc --> | ||
211 | * @generated | ||
212 | */ | ||
213 | @SuppressWarnings("unchecked") | ||
214 | @Override | ||
215 | public void eSet(int featureID, Object newValue) { | ||
216 | switch (featureID) { | ||
217 | case Modes3Package.MODES3_MODEL_ROOT__ID: | ||
218 | setId((Integer)newValue); | ||
219 | return; | ||
220 | case Modes3Package.MODES3_MODEL_ROOT__TRAINS: | ||
221 | getTrains().clear(); | ||
222 | getTrains().addAll((Collection<? extends Train>)newValue); | ||
223 | return; | ||
224 | case Modes3Package.MODES3_MODEL_ROOT__SEGMENTS: | ||
225 | getSegments().clear(); | ||
226 | getSegments().addAll((Collection<? extends SimpleSegment>)newValue); | ||
227 | return; | ||
228 | case Modes3Package.MODES3_MODEL_ROOT__TURNOUTS: | ||
229 | getTurnouts().clear(); | ||
230 | getTurnouts().addAll((Collection<? extends Turnout>)newValue); | ||
231 | return; | ||
232 | } | ||
233 | super.eSet(featureID, newValue); | ||
234 | } | ||
235 | |||
236 | /** | ||
237 | * <!-- begin-user-doc --> | ||
238 | * <!-- end-user-doc --> | ||
239 | * @generated | ||
240 | */ | ||
241 | @Override | ||
242 | public void eUnset(int featureID) { | ||
243 | switch (featureID) { | ||
244 | case Modes3Package.MODES3_MODEL_ROOT__ID: | ||
245 | setId(ID_EDEFAULT); | ||
246 | return; | ||
247 | case Modes3Package.MODES3_MODEL_ROOT__TRAINS: | ||
248 | getTrains().clear(); | ||
249 | return; | ||
250 | case Modes3Package.MODES3_MODEL_ROOT__SEGMENTS: | ||
251 | getSegments().clear(); | ||
252 | return; | ||
253 | case Modes3Package.MODES3_MODEL_ROOT__TURNOUTS: | ||
254 | getTurnouts().clear(); | ||
255 | return; | ||
256 | } | ||
257 | super.eUnset(featureID); | ||
258 | } | ||
259 | |||
260 | /** | ||
261 | * <!-- begin-user-doc --> | ||
262 | * <!-- end-user-doc --> | ||
263 | * @generated | ||
264 | */ | ||
265 | @Override | ||
266 | public boolean eIsSet(int featureID) { | ||
267 | switch (featureID) { | ||
268 | case Modes3Package.MODES3_MODEL_ROOT__ID: | ||
269 | return id != ID_EDEFAULT; | ||
270 | case Modes3Package.MODES3_MODEL_ROOT__TRAINS: | ||
271 | return trains != null && !trains.isEmpty(); | ||
272 | case Modes3Package.MODES3_MODEL_ROOT__SEGMENTS: | ||
273 | return segments != null && !segments.isEmpty(); | ||
274 | case Modes3Package.MODES3_MODEL_ROOT__TURNOUTS: | ||
275 | return turnouts != null && !turnouts.isEmpty(); | ||
276 | } | ||
277 | return super.eIsSet(featureID); | ||
278 | } | ||
279 | |||
280 | /** | ||
281 | * <!-- begin-user-doc --> | ||
282 | * <!-- end-user-doc --> | ||
283 | * @generated | ||
284 | */ | ||
285 | @Override | ||
286 | public String toString() { | ||
287 | if (eIsProxy()) return super.toString(); | ||
288 | |||
289 | StringBuilder result = new StringBuilder(super.toString()); | ||
290 | result.append(" (id: "); | ||
291 | result.append(id); | ||
292 | result.append(')'); | ||
293 | return result.toString(); | ||
294 | } | ||
295 | |||
296 | } //Modes3ModelRootImpl | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/ecore-gen/modes3/impl/Modes3PackageImpl.java b/Domains/ca.mcgill.rtgmrt.example.modes3/ecore-gen/modes3/impl/Modes3PackageImpl.java new file mode 100644 index 00000000..557da4c1 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/ecore-gen/modes3/impl/Modes3PackageImpl.java | |||
@@ -0,0 +1,385 @@ | |||
1 | /** | ||
2 | */ | ||
3 | package modes3.impl; | ||
4 | |||
5 | import modes3.Modes3Factory; | ||
6 | import modes3.Modes3ModelRoot; | ||
7 | import modes3.Modes3Package; | ||
8 | import modes3.Segment; | ||
9 | import modes3.SimpleSegment; | ||
10 | import modes3.Train; | ||
11 | import modes3.Turnout; | ||
12 | |||
13 | import org.eclipse.emf.ecore.EAttribute; | ||
14 | import org.eclipse.emf.ecore.EClass; | ||
15 | import org.eclipse.emf.ecore.EPackage; | ||
16 | import org.eclipse.emf.ecore.EReference; | ||
17 | |||
18 | import org.eclipse.emf.ecore.impl.EPackageImpl; | ||
19 | |||
20 | /** | ||
21 | * <!-- begin-user-doc --> | ||
22 | * An implementation of the model <b>Package</b>. | ||
23 | * <!-- end-user-doc --> | ||
24 | * @generated | ||
25 | */ | ||
26 | public class Modes3PackageImpl extends EPackageImpl implements Modes3Package { | ||
27 | /** | ||
28 | * <!-- begin-user-doc --> | ||
29 | * <!-- end-user-doc --> | ||
30 | * @generated | ||
31 | */ | ||
32 | private EClass segmentEClass = null; | ||
33 | |||
34 | /** | ||
35 | * <!-- begin-user-doc --> | ||
36 | * <!-- end-user-doc --> | ||
37 | * @generated | ||
38 | */ | ||
39 | private EClass modes3ModelRootEClass = null; | ||
40 | |||
41 | /** | ||
42 | * <!-- begin-user-doc --> | ||
43 | * <!-- end-user-doc --> | ||
44 | * @generated | ||
45 | */ | ||
46 | private EClass turnoutEClass = null; | ||
47 | |||
48 | /** | ||
49 | * <!-- begin-user-doc --> | ||
50 | * <!-- end-user-doc --> | ||
51 | * @generated | ||
52 | */ | ||
53 | private EClass trainEClass = null; | ||
54 | |||
55 | /** | ||
56 | * <!-- begin-user-doc --> | ||
57 | * <!-- end-user-doc --> | ||
58 | * @generated | ||
59 | */ | ||
60 | private EClass simpleSegmentEClass = null; | ||
61 | |||
62 | /** | ||
63 | * Creates an instance of the model <b>Package</b>, registered with | ||
64 | * {@link org.eclipse.emf.ecore.EPackage.Registry EPackage.Registry} by the package | ||
65 | * package URI value. | ||
66 | * <p>Note: the correct way to create the package is via the static | ||
67 | * factory method {@link #init init()}, which also performs | ||
68 | * initialization of the package, or returns the registered package, | ||
69 | * if one already exists. | ||
70 | * <!-- begin-user-doc --> | ||
71 | * <!-- end-user-doc --> | ||
72 | * @see org.eclipse.emf.ecore.EPackage.Registry | ||
73 | * @see modes3.Modes3Package#eNS_URI | ||
74 | * @see #init() | ||
75 | * @generated | ||
76 | */ | ||
77 | private Modes3PackageImpl() { | ||
78 | super(eNS_URI, Modes3Factory.eINSTANCE); | ||
79 | } | ||
80 | |||
81 | /** | ||
82 | * <!-- begin-user-doc --> | ||
83 | * <!-- end-user-doc --> | ||
84 | * @generated | ||
85 | */ | ||
86 | private static boolean isInited = false; | ||
87 | |||
88 | /** | ||
89 | * Creates, registers, and initializes the <b>Package</b> for this model, and for any others upon which it depends. | ||
90 | * | ||
91 | * <p>This method is used to initialize {@link Modes3Package#eINSTANCE} when that field is accessed. | ||
92 | * Clients should not invoke it directly. Instead, they should simply access that field to obtain the package. | ||
93 | * <!-- begin-user-doc --> | ||
94 | * <!-- end-user-doc --> | ||
95 | * @see #eNS_URI | ||
96 | * @see #createPackageContents() | ||
97 | * @see #initializePackageContents() | ||
98 | * @generated | ||
99 | */ | ||
100 | public static Modes3Package init() { | ||
101 | if (isInited) return (Modes3Package)EPackage.Registry.INSTANCE.getEPackage(Modes3Package.eNS_URI); | ||
102 | |||
103 | // Obtain or create and register package | ||
104 | Object registeredModes3Package = EPackage.Registry.INSTANCE.get(eNS_URI); | ||
105 | Modes3PackageImpl theModes3Package = registeredModes3Package instanceof Modes3PackageImpl ? (Modes3PackageImpl)registeredModes3Package : new Modes3PackageImpl(); | ||
106 | |||
107 | isInited = true; | ||
108 | |||
109 | // Create package meta-data objects | ||
110 | theModes3Package.createPackageContents(); | ||
111 | |||
112 | // Initialize created meta-data | ||
113 | theModes3Package.initializePackageContents(); | ||
114 | |||
115 | // Mark meta-data to indicate it can't be changed | ||
116 | theModes3Package.freeze(); | ||
117 | |||
118 | // Update the registry and return the package | ||
119 | EPackage.Registry.INSTANCE.put(Modes3Package.eNS_URI, theModes3Package); | ||
120 | return theModes3Package; | ||
121 | } | ||
122 | |||
123 | /** | ||
124 | * <!-- begin-user-doc --> | ||
125 | * <!-- end-user-doc --> | ||
126 | * @generated | ||
127 | */ | ||
128 | public EClass getSegment() { | ||
129 | return segmentEClass; | ||
130 | } | ||
131 | |||
132 | /** | ||
133 | * <!-- begin-user-doc --> | ||
134 | * <!-- end-user-doc --> | ||
135 | * @generated | ||
136 | */ | ||
137 | public EReference getSegment_ConnectedTo() { | ||
138 | return (EReference)segmentEClass.getEStructuralFeatures().get(0); | ||
139 | } | ||
140 | |||
141 | /** | ||
142 | * <!-- begin-user-doc --> | ||
143 | * <!-- end-user-doc --> | ||
144 | * @generated | ||
145 | */ | ||
146 | public EReference getSegment_OccupiedBy() { | ||
147 | return (EReference)segmentEClass.getEStructuralFeatures().get(1); | ||
148 | } | ||
149 | |||
150 | /** | ||
151 | * <!-- begin-user-doc --> | ||
152 | * <!-- end-user-doc --> | ||
153 | * @generated | ||
154 | */ | ||
155 | public EAttribute getSegment_Id() { | ||
156 | return (EAttribute)segmentEClass.getEStructuralFeatures().get(2); | ||
157 | } | ||
158 | |||
159 | /** | ||
160 | * <!-- begin-user-doc --> | ||
161 | * <!-- end-user-doc --> | ||
162 | * @generated | ||
163 | */ | ||
164 | public EClass getModes3ModelRoot() { | ||
165 | return modes3ModelRootEClass; | ||
166 | } | ||
167 | |||
168 | /** | ||
169 | * <!-- begin-user-doc --> | ||
170 | * <!-- end-user-doc --> | ||
171 | * @generated | ||
172 | */ | ||
173 | public EAttribute getModes3ModelRoot_Id() { | ||
174 | return (EAttribute)modes3ModelRootEClass.getEStructuralFeatures().get(0); | ||
175 | } | ||
176 | |||
177 | /** | ||
178 | * <!-- begin-user-doc --> | ||
179 | * <!-- end-user-doc --> | ||
180 | * @generated | ||
181 | */ | ||
182 | public EReference getModes3ModelRoot_Trains() { | ||
183 | return (EReference)modes3ModelRootEClass.getEStructuralFeatures().get(1); | ||
184 | } | ||
185 | |||
186 | /** | ||
187 | * <!-- begin-user-doc --> | ||
188 | * <!-- end-user-doc --> | ||
189 | * @generated | ||
190 | */ | ||
191 | public EReference getModes3ModelRoot_Segments() { | ||
192 | return (EReference)modes3ModelRootEClass.getEStructuralFeatures().get(2); | ||
193 | } | ||
194 | |||
195 | /** | ||
196 | * <!-- begin-user-doc --> | ||
197 | * <!-- end-user-doc --> | ||
198 | * @generated | ||
199 | */ | ||
200 | public EReference getModes3ModelRoot_Turnouts() { | ||
201 | return (EReference)modes3ModelRootEClass.getEStructuralFeatures().get(3); | ||
202 | } | ||
203 | |||
204 | /** | ||
205 | * <!-- begin-user-doc --> | ||
206 | * <!-- end-user-doc --> | ||
207 | * @generated | ||
208 | */ | ||
209 | public EClass getTurnout() { | ||
210 | return turnoutEClass; | ||
211 | } | ||
212 | |||
213 | /** | ||
214 | * <!-- begin-user-doc --> | ||
215 | * <!-- end-user-doc --> | ||
216 | * @generated | ||
217 | */ | ||
218 | public EReference getTurnout_Straight() { | ||
219 | return (EReference)turnoutEClass.getEStructuralFeatures().get(0); | ||
220 | } | ||
221 | |||
222 | /** | ||
223 | * <!-- begin-user-doc --> | ||
224 | * <!-- end-user-doc --> | ||
225 | * @generated | ||
226 | */ | ||
227 | public EReference getTurnout_Divergent() { | ||
228 | return (EReference)turnoutEClass.getEStructuralFeatures().get(1); | ||
229 | } | ||
230 | |||
231 | /** | ||
232 | * <!-- begin-user-doc --> | ||
233 | * <!-- end-user-doc --> | ||
234 | * @generated | ||
235 | */ | ||
236 | public EClass getTrain() { | ||
237 | return trainEClass; | ||
238 | } | ||
239 | |||
240 | /** | ||
241 | * <!-- begin-user-doc --> | ||
242 | * <!-- end-user-doc --> | ||
243 | * @generated | ||
244 | */ | ||
245 | public EReference getTrain_Location() { | ||
246 | return (EReference)trainEClass.getEStructuralFeatures().get(0); | ||
247 | } | ||
248 | |||
249 | /** | ||
250 | * <!-- begin-user-doc --> | ||
251 | * <!-- end-user-doc --> | ||
252 | * @generated | ||
253 | */ | ||
254 | public EAttribute getTrain_Id() { | ||
255 | return (EAttribute)trainEClass.getEStructuralFeatures().get(1); | ||
256 | } | ||
257 | |||
258 | /** | ||
259 | * <!-- begin-user-doc --> | ||
260 | * <!-- end-user-doc --> | ||
261 | * @generated | ||
262 | */ | ||
263 | public EAttribute getTrain_Speed() { | ||
264 | return (EAttribute)trainEClass.getEStructuralFeatures().get(2); | ||
265 | } | ||
266 | |||
267 | /** | ||
268 | * <!-- begin-user-doc --> | ||
269 | * <!-- end-user-doc --> | ||
270 | * @generated | ||
271 | */ | ||
272 | public EClass getSimpleSegment() { | ||
273 | return simpleSegmentEClass; | ||
274 | } | ||
275 | |||
276 | /** | ||
277 | * <!-- begin-user-doc --> | ||
278 | * <!-- end-user-doc --> | ||
279 | * @generated | ||
280 | */ | ||
281 | public Modes3Factory getModes3Factory() { | ||
282 | return (Modes3Factory)getEFactoryInstance(); | ||
283 | } | ||
284 | |||
285 | /** | ||
286 | * <!-- begin-user-doc --> | ||
287 | * <!-- end-user-doc --> | ||
288 | * @generated | ||
289 | */ | ||
290 | private boolean isCreated = false; | ||
291 | |||
292 | /** | ||
293 | * Creates the meta-model objects for the package. This method is | ||
294 | * guarded to have no affect on any invocation but its first. | ||
295 | * <!-- begin-user-doc --> | ||
296 | * <!-- end-user-doc --> | ||
297 | * @generated | ||
298 | */ | ||
299 | public void createPackageContents() { | ||
300 | if (isCreated) return; | ||
301 | isCreated = true; | ||
302 | |||
303 | // Create classes and their features | ||
304 | segmentEClass = createEClass(SEGMENT); | ||
305 | createEReference(segmentEClass, SEGMENT__CONNECTED_TO); | ||
306 | createEReference(segmentEClass, SEGMENT__OCCUPIED_BY); | ||
307 | createEAttribute(segmentEClass, SEGMENT__ID); | ||
308 | |||
309 | modes3ModelRootEClass = createEClass(MODES3_MODEL_ROOT); | ||
310 | createEAttribute(modes3ModelRootEClass, MODES3_MODEL_ROOT__ID); | ||
311 | createEReference(modes3ModelRootEClass, MODES3_MODEL_ROOT__TRAINS); | ||
312 | createEReference(modes3ModelRootEClass, MODES3_MODEL_ROOT__SEGMENTS); | ||
313 | createEReference(modes3ModelRootEClass, MODES3_MODEL_ROOT__TURNOUTS); | ||
314 | |||
315 | turnoutEClass = createEClass(TURNOUT); | ||
316 | createEReference(turnoutEClass, TURNOUT__STRAIGHT); | ||
317 | createEReference(turnoutEClass, TURNOUT__DIVERGENT); | ||
318 | |||
319 | trainEClass = createEClass(TRAIN); | ||
320 | createEReference(trainEClass, TRAIN__LOCATION); | ||
321 | createEAttribute(trainEClass, TRAIN__ID); | ||
322 | createEAttribute(trainEClass, TRAIN__SPEED); | ||
323 | |||
324 | simpleSegmentEClass = createEClass(SIMPLE_SEGMENT); | ||
325 | } | ||
326 | |||
327 | /** | ||
328 | * <!-- begin-user-doc --> | ||
329 | * <!-- end-user-doc --> | ||
330 | * @generated | ||
331 | */ | ||
332 | private boolean isInitialized = false; | ||
333 | |||
334 | /** | ||
335 | * Complete the initialization of the package and its meta-model. This | ||
336 | * method is guarded to have no affect on any invocation but its first. | ||
337 | * <!-- begin-user-doc --> | ||
338 | * <!-- end-user-doc --> | ||
339 | * @generated | ||
340 | */ | ||
341 | public void initializePackageContents() { | ||
342 | if (isInitialized) return; | ||
343 | isInitialized = true; | ||
344 | |||
345 | // Initialize package | ||
346 | setName(eNAME); | ||
347 | setNsPrefix(eNS_PREFIX); | ||
348 | setNsURI(eNS_URI); | ||
349 | |||
350 | // Create type parameters | ||
351 | |||
352 | // Set bounds for type parameters | ||
353 | |||
354 | // Add supertypes to classes | ||
355 | turnoutEClass.getESuperTypes().add(this.getSegment()); | ||
356 | simpleSegmentEClass.getESuperTypes().add(this.getSegment()); | ||
357 | |||
358 | // Initialize classes, features, and operations; add parameters | ||
359 | initEClass(segmentEClass, Segment.class, "Segment", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS); | ||
360 | initEReference(getSegment_ConnectedTo(), this.getSegment(), null, "connectedTo", null, 0, 2, Segment.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); | ||
361 | initEReference(getSegment_OccupiedBy(), this.getTrain(), this.getTrain_Location(), "occupiedBy", null, 0, 1, Segment.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); | ||
362 | initEAttribute(getSegment_Id(), ecorePackage.getEInt(), "id", null, 0, 1, Segment.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); | ||
363 | |||
364 | initEClass(modes3ModelRootEClass, Modes3ModelRoot.class, "Modes3ModelRoot", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS); | ||
365 | initEAttribute(getModes3ModelRoot_Id(), ecorePackage.getEInt(), "id", null, 0, 1, Modes3ModelRoot.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); | ||
366 | initEReference(getModes3ModelRoot_Trains(), this.getTrain(), null, "trains", null, 0, -1, Modes3ModelRoot.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_COMPOSITE, !IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); | ||
367 | initEReference(getModes3ModelRoot_Segments(), this.getSimpleSegment(), null, "segments", null, 0, -1, Modes3ModelRoot.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_COMPOSITE, !IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); | ||
368 | initEReference(getModes3ModelRoot_Turnouts(), this.getTurnout(), null, "turnouts", null, 0, -1, Modes3ModelRoot.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_COMPOSITE, !IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); | ||
369 | |||
370 | initEClass(turnoutEClass, Turnout.class, "Turnout", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS); | ||
371 | initEReference(getTurnout_Straight(), this.getSegment(), null, "straight", null, 1, 1, Turnout.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); | ||
372 | initEReference(getTurnout_Divergent(), this.getSegment(), null, "divergent", null, 1, 1, Turnout.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); | ||
373 | |||
374 | initEClass(trainEClass, Train.class, "Train", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS); | ||
375 | initEReference(getTrain_Location(), this.getSegment(), this.getSegment_OccupiedBy(), "location", null, 1, 1, Train.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); | ||
376 | initEAttribute(getTrain_Id(), ecorePackage.getEInt(), "id", null, 0, 1, Train.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); | ||
377 | initEAttribute(getTrain_Speed(), ecorePackage.getEDouble(), "speed", null, 0, 1, Train.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); | ||
378 | |||
379 | initEClass(simpleSegmentEClass, SimpleSegment.class, "SimpleSegment", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS); | ||
380 | |||
381 | // Create resource | ||
382 | createResource(eNS_URI); | ||
383 | } | ||
384 | |||
385 | } //Modes3PackageImpl | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/ecore-gen/modes3/impl/SegmentImpl.java b/Domains/ca.mcgill.rtgmrt.example.modes3/ecore-gen/modes3/impl/SegmentImpl.java new file mode 100644 index 00000000..905bcec1 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/ecore-gen/modes3/impl/SegmentImpl.java | |||
@@ -0,0 +1,319 @@ | |||
1 | /** | ||
2 | */ | ||
3 | package modes3.impl; | ||
4 | |||
5 | import java.util.Collection; | ||
6 | |||
7 | import modes3.Modes3Package; | ||
8 | import modes3.Segment; | ||
9 | import modes3.Train; | ||
10 | |||
11 | import org.eclipse.emf.common.notify.Notification; | ||
12 | import org.eclipse.emf.common.notify.NotificationChain; | ||
13 | |||
14 | import org.eclipse.emf.common.util.EList; | ||
15 | |||
16 | import org.eclipse.emf.ecore.EClass; | ||
17 | import org.eclipse.emf.ecore.InternalEObject; | ||
18 | |||
19 | import org.eclipse.emf.ecore.impl.ENotificationImpl; | ||
20 | import org.eclipse.emf.ecore.impl.MinimalEObjectImpl; | ||
21 | |||
22 | import org.eclipse.emf.ecore.util.EObjectResolvingEList; | ||
23 | |||
24 | /** | ||
25 | * <!-- begin-user-doc --> | ||
26 | * An implementation of the model object '<em><b>Segment</b></em>'. | ||
27 | * <!-- end-user-doc --> | ||
28 | * <p> | ||
29 | * The following features are implemented: | ||
30 | * </p> | ||
31 | * <ul> | ||
32 | * <li>{@link modes3.impl.SegmentImpl#getConnectedTo <em>Connected To</em>}</li> | ||
33 | * <li>{@link modes3.impl.SegmentImpl#getOccupiedBy <em>Occupied By</em>}</li> | ||
34 | * <li>{@link modes3.impl.SegmentImpl#getId <em>Id</em>}</li> | ||
35 | * </ul> | ||
36 | * | ||
37 | * @generated | ||
38 | */ | ||
39 | public class SegmentImpl extends MinimalEObjectImpl.Container implements Segment { | ||
40 | /** | ||
41 | * The cached value of the '{@link #getConnectedTo() <em>Connected To</em>}' reference list. | ||
42 | * <!-- begin-user-doc --> | ||
43 | * <!-- end-user-doc --> | ||
44 | * @see #getConnectedTo() | ||
45 | * @generated | ||
46 | * @ordered | ||
47 | */ | ||
48 | protected EList<Segment> connectedTo; | ||
49 | |||
50 | /** | ||
51 | * The cached value of the '{@link #getOccupiedBy() <em>Occupied By</em>}' reference. | ||
52 | * <!-- begin-user-doc --> | ||
53 | * <!-- end-user-doc --> | ||
54 | * @see #getOccupiedBy() | ||
55 | * @generated | ||
56 | * @ordered | ||
57 | */ | ||
58 | protected Train occupiedBy; | ||
59 | |||
60 | /** | ||
61 | * The default value of the '{@link #getId() <em>Id</em>}' attribute. | ||
62 | * <!-- begin-user-doc --> | ||
63 | * <!-- end-user-doc --> | ||
64 | * @see #getId() | ||
65 | * @generated | ||
66 | * @ordered | ||
67 | */ | ||
68 | protected static final int ID_EDEFAULT = 0; | ||
69 | |||
70 | /** | ||
71 | * The cached value of the '{@link #getId() <em>Id</em>}' attribute. | ||
72 | * <!-- begin-user-doc --> | ||
73 | * <!-- end-user-doc --> | ||
74 | * @see #getId() | ||
75 | * @generated | ||
76 | * @ordered | ||
77 | */ | ||
78 | protected int id = ID_EDEFAULT; | ||
79 | |||
80 | /** | ||
81 | * <!-- begin-user-doc --> | ||
82 | * <!-- end-user-doc --> | ||
83 | * @generated | ||
84 | */ | ||
85 | protected SegmentImpl() { | ||
86 | super(); | ||
87 | } | ||
88 | |||
89 | /** | ||
90 | * <!-- begin-user-doc --> | ||
91 | * <!-- end-user-doc --> | ||
92 | * @generated | ||
93 | */ | ||
94 | @Override | ||
95 | protected EClass eStaticClass() { | ||
96 | return Modes3Package.Literals.SEGMENT; | ||
97 | } | ||
98 | |||
99 | /** | ||
100 | * <!-- begin-user-doc --> | ||
101 | * <!-- end-user-doc --> | ||
102 | * @generated | ||
103 | */ | ||
104 | public EList<Segment> getConnectedTo() { | ||
105 | if (connectedTo == null) { | ||
106 | connectedTo = new EObjectResolvingEList<Segment>(Segment.class, this, Modes3Package.SEGMENT__CONNECTED_TO); | ||
107 | } | ||
108 | return connectedTo; | ||
109 | } | ||
110 | |||
111 | /** | ||
112 | * <!-- begin-user-doc --> | ||
113 | * <!-- end-user-doc --> | ||
114 | * @generated | ||
115 | */ | ||
116 | public Train getOccupiedBy() { | ||
117 | if (occupiedBy != null && occupiedBy.eIsProxy()) { | ||
118 | InternalEObject oldOccupiedBy = (InternalEObject)occupiedBy; | ||
119 | occupiedBy = (Train)eResolveProxy(oldOccupiedBy); | ||
120 | if (occupiedBy != oldOccupiedBy) { | ||
121 | if (eNotificationRequired()) | ||
122 | eNotify(new ENotificationImpl(this, Notification.RESOLVE, Modes3Package.SEGMENT__OCCUPIED_BY, oldOccupiedBy, occupiedBy)); | ||
123 | } | ||
124 | } | ||
125 | return occupiedBy; | ||
126 | } | ||
127 | |||
128 | /** | ||
129 | * <!-- begin-user-doc --> | ||
130 | * <!-- end-user-doc --> | ||
131 | * @generated | ||
132 | */ | ||
133 | public Train basicGetOccupiedBy() { | ||
134 | return occupiedBy; | ||
135 | } | ||
136 | |||
137 | /** | ||
138 | * <!-- begin-user-doc --> | ||
139 | * <!-- end-user-doc --> | ||
140 | * @generated | ||
141 | */ | ||
142 | public NotificationChain basicSetOccupiedBy(Train newOccupiedBy, NotificationChain msgs) { | ||
143 | Train oldOccupiedBy = occupiedBy; | ||
144 | occupiedBy = newOccupiedBy; | ||
145 | if (eNotificationRequired()) { | ||
146 | ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, Modes3Package.SEGMENT__OCCUPIED_BY, oldOccupiedBy, newOccupiedBy); | ||
147 | if (msgs == null) msgs = notification; else msgs.add(notification); | ||
148 | } | ||
149 | return msgs; | ||
150 | } | ||
151 | |||
152 | /** | ||
153 | * <!-- begin-user-doc --> | ||
154 | * <!-- end-user-doc --> | ||
155 | * @generated | ||
156 | */ | ||
157 | public void setOccupiedBy(Train newOccupiedBy) { | ||
158 | if (newOccupiedBy != occupiedBy) { | ||
159 | NotificationChain msgs = null; | ||
160 | if (occupiedBy != null) | ||
161 | msgs = ((InternalEObject)occupiedBy).eInverseRemove(this, Modes3Package.TRAIN__LOCATION, Train.class, msgs); | ||
162 | if (newOccupiedBy != null) | ||
163 | msgs = ((InternalEObject)newOccupiedBy).eInverseAdd(this, Modes3Package.TRAIN__LOCATION, Train.class, msgs); | ||
164 | msgs = basicSetOccupiedBy(newOccupiedBy, msgs); | ||
165 | if (msgs != null) msgs.dispatch(); | ||
166 | } | ||
167 | else if (eNotificationRequired()) | ||
168 | eNotify(new ENotificationImpl(this, Notification.SET, Modes3Package.SEGMENT__OCCUPIED_BY, newOccupiedBy, newOccupiedBy)); | ||
169 | } | ||
170 | |||
171 | /** | ||
172 | * <!-- begin-user-doc --> | ||
173 | * <!-- end-user-doc --> | ||
174 | * @generated | ||
175 | */ | ||
176 | public int getId() { | ||
177 | return id; | ||
178 | } | ||
179 | |||
180 | /** | ||
181 | * <!-- begin-user-doc --> | ||
182 | * <!-- end-user-doc --> | ||
183 | * @generated | ||
184 | */ | ||
185 | public void setId(int newId) { | ||
186 | int oldId = id; | ||
187 | id = newId; | ||
188 | if (eNotificationRequired()) | ||
189 | eNotify(new ENotificationImpl(this, Notification.SET, Modes3Package.SEGMENT__ID, oldId, id)); | ||
190 | } | ||
191 | |||
192 | /** | ||
193 | * <!-- begin-user-doc --> | ||
194 | * <!-- end-user-doc --> | ||
195 | * @generated | ||
196 | */ | ||
197 | @Override | ||
198 | public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) { | ||
199 | switch (featureID) { | ||
200 | case Modes3Package.SEGMENT__OCCUPIED_BY: | ||
201 | if (occupiedBy != null) | ||
202 | msgs = ((InternalEObject)occupiedBy).eInverseRemove(this, Modes3Package.TRAIN__LOCATION, Train.class, msgs); | ||
203 | return basicSetOccupiedBy((Train)otherEnd, msgs); | ||
204 | } | ||
205 | return super.eInverseAdd(otherEnd, featureID, msgs); | ||
206 | } | ||
207 | |||
208 | /** | ||
209 | * <!-- begin-user-doc --> | ||
210 | * <!-- end-user-doc --> | ||
211 | * @generated | ||
212 | */ | ||
213 | @Override | ||
214 | public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) { | ||
215 | switch (featureID) { | ||
216 | case Modes3Package.SEGMENT__OCCUPIED_BY: | ||
217 | return basicSetOccupiedBy(null, msgs); | ||
218 | } | ||
219 | return super.eInverseRemove(otherEnd, featureID, msgs); | ||
220 | } | ||
221 | |||
222 | /** | ||
223 | * <!-- begin-user-doc --> | ||
224 | * <!-- end-user-doc --> | ||
225 | * @generated | ||
226 | */ | ||
227 | @Override | ||
228 | public Object eGet(int featureID, boolean resolve, boolean coreType) { | ||
229 | switch (featureID) { | ||
230 | case Modes3Package.SEGMENT__CONNECTED_TO: | ||
231 | return getConnectedTo(); | ||
232 | case Modes3Package.SEGMENT__OCCUPIED_BY: | ||
233 | if (resolve) return getOccupiedBy(); | ||
234 | return basicGetOccupiedBy(); | ||
235 | case Modes3Package.SEGMENT__ID: | ||
236 | return getId(); | ||
237 | } | ||
238 | return super.eGet(featureID, resolve, coreType); | ||
239 | } | ||
240 | |||
241 | /** | ||
242 | * <!-- begin-user-doc --> | ||
243 | * <!-- end-user-doc --> | ||
244 | * @generated | ||
245 | */ | ||
246 | @SuppressWarnings("unchecked") | ||
247 | @Override | ||
248 | public void eSet(int featureID, Object newValue) { | ||
249 | switch (featureID) { | ||
250 | case Modes3Package.SEGMENT__CONNECTED_TO: | ||
251 | getConnectedTo().clear(); | ||
252 | getConnectedTo().addAll((Collection<? extends Segment>)newValue); | ||
253 | return; | ||
254 | case Modes3Package.SEGMENT__OCCUPIED_BY: | ||
255 | setOccupiedBy((Train)newValue); | ||
256 | return; | ||
257 | case Modes3Package.SEGMENT__ID: | ||
258 | setId((Integer)newValue); | ||
259 | return; | ||
260 | } | ||
261 | super.eSet(featureID, newValue); | ||
262 | } | ||
263 | |||
264 | /** | ||
265 | * <!-- begin-user-doc --> | ||
266 | * <!-- end-user-doc --> | ||
267 | * @generated | ||
268 | */ | ||
269 | @Override | ||
270 | public void eUnset(int featureID) { | ||
271 | switch (featureID) { | ||
272 | case Modes3Package.SEGMENT__CONNECTED_TO: | ||
273 | getConnectedTo().clear(); | ||
274 | return; | ||
275 | case Modes3Package.SEGMENT__OCCUPIED_BY: | ||
276 | setOccupiedBy((Train)null); | ||
277 | return; | ||
278 | case Modes3Package.SEGMENT__ID: | ||
279 | setId(ID_EDEFAULT); | ||
280 | return; | ||
281 | } | ||
282 | super.eUnset(featureID); | ||
283 | } | ||
284 | |||
285 | /** | ||
286 | * <!-- begin-user-doc --> | ||
287 | * <!-- end-user-doc --> | ||
288 | * @generated | ||
289 | */ | ||
290 | @Override | ||
291 | public boolean eIsSet(int featureID) { | ||
292 | switch (featureID) { | ||
293 | case Modes3Package.SEGMENT__CONNECTED_TO: | ||
294 | return connectedTo != null && !connectedTo.isEmpty(); | ||
295 | case Modes3Package.SEGMENT__OCCUPIED_BY: | ||
296 | return occupiedBy != null; | ||
297 | case Modes3Package.SEGMENT__ID: | ||
298 | return id != ID_EDEFAULT; | ||
299 | } | ||
300 | return super.eIsSet(featureID); | ||
301 | } | ||
302 | |||
303 | /** | ||
304 | * <!-- begin-user-doc --> | ||
305 | * <!-- end-user-doc --> | ||
306 | * @generated | ||
307 | */ | ||
308 | @Override | ||
309 | public String toString() { | ||
310 | if (eIsProxy()) return super.toString(); | ||
311 | |||
312 | StringBuilder result = new StringBuilder(super.toString()); | ||
313 | result.append(" (id: "); | ||
314 | result.append(id); | ||
315 | result.append(')'); | ||
316 | return result.toString(); | ||
317 | } | ||
318 | |||
319 | } //SegmentImpl | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/ecore-gen/modes3/impl/SimpleSegmentImpl.java b/Domains/ca.mcgill.rtgmrt.example.modes3/ecore-gen/modes3/impl/SimpleSegmentImpl.java new file mode 100644 index 00000000..e3fd6c34 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/ecore-gen/modes3/impl/SimpleSegmentImpl.java | |||
@@ -0,0 +1,37 @@ | |||
1 | /** | ||
2 | */ | ||
3 | package modes3.impl; | ||
4 | |||
5 | import modes3.Modes3Package; | ||
6 | import modes3.SimpleSegment; | ||
7 | |||
8 | import org.eclipse.emf.ecore.EClass; | ||
9 | |||
10 | /** | ||
11 | * <!-- begin-user-doc --> | ||
12 | * An implementation of the model object '<em><b>Simple Segment</b></em>'. | ||
13 | * <!-- end-user-doc --> | ||
14 | * | ||
15 | * @generated | ||
16 | */ | ||
17 | public class SimpleSegmentImpl extends SegmentImpl implements SimpleSegment { | ||
18 | /** | ||
19 | * <!-- begin-user-doc --> | ||
20 | * <!-- end-user-doc --> | ||
21 | * @generated | ||
22 | */ | ||
23 | protected SimpleSegmentImpl() { | ||
24 | super(); | ||
25 | } | ||
26 | |||
27 | /** | ||
28 | * <!-- begin-user-doc --> | ||
29 | * <!-- end-user-doc --> | ||
30 | * @generated | ||
31 | */ | ||
32 | @Override | ||
33 | protected EClass eStaticClass() { | ||
34 | return Modes3Package.Literals.SIMPLE_SEGMENT; | ||
35 | } | ||
36 | |||
37 | } //SimpleSegmentImpl | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/ecore-gen/modes3/impl/TrainImpl.java b/Domains/ca.mcgill.rtgmrt.example.modes3/ecore-gen/modes3/impl/TrainImpl.java new file mode 100644 index 00000000..f096dca8 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/ecore-gen/modes3/impl/TrainImpl.java | |||
@@ -0,0 +1,332 @@ | |||
1 | /** | ||
2 | */ | ||
3 | package modes3.impl; | ||
4 | |||
5 | import modes3.Modes3Package; | ||
6 | import modes3.Segment; | ||
7 | import modes3.Train; | ||
8 | |||
9 | import org.eclipse.emf.common.notify.Notification; | ||
10 | import org.eclipse.emf.common.notify.NotificationChain; | ||
11 | |||
12 | import org.eclipse.emf.ecore.EClass; | ||
13 | import org.eclipse.emf.ecore.InternalEObject; | ||
14 | |||
15 | import org.eclipse.emf.ecore.impl.ENotificationImpl; | ||
16 | import org.eclipse.emf.ecore.impl.MinimalEObjectImpl; | ||
17 | |||
18 | /** | ||
19 | * <!-- begin-user-doc --> | ||
20 | * An implementation of the model object '<em><b>Train</b></em>'. | ||
21 | * <!-- end-user-doc --> | ||
22 | * <p> | ||
23 | * The following features are implemented: | ||
24 | * </p> | ||
25 | * <ul> | ||
26 | * <li>{@link modes3.impl.TrainImpl#getLocation <em>Location</em>}</li> | ||
27 | * <li>{@link modes3.impl.TrainImpl#getId <em>Id</em>}</li> | ||
28 | * <li>{@link modes3.impl.TrainImpl#getSpeed <em>Speed</em>}</li> | ||
29 | * </ul> | ||
30 | * | ||
31 | * @generated | ||
32 | */ | ||
33 | public class TrainImpl extends MinimalEObjectImpl.Container implements Train { | ||
34 | /** | ||
35 | * The cached value of the '{@link #getLocation() <em>Location</em>}' reference. | ||
36 | * <!-- begin-user-doc --> | ||
37 | * <!-- end-user-doc --> | ||
38 | * @see #getLocation() | ||
39 | * @generated | ||
40 | * @ordered | ||
41 | */ | ||
42 | protected Segment location; | ||
43 | |||
44 | /** | ||
45 | * The default value of the '{@link #getId() <em>Id</em>}' attribute. | ||
46 | * <!-- begin-user-doc --> | ||
47 | * <!-- end-user-doc --> | ||
48 | * @see #getId() | ||
49 | * @generated | ||
50 | * @ordered | ||
51 | */ | ||
52 | protected static final int ID_EDEFAULT = 0; | ||
53 | |||
54 | /** | ||
55 | * The cached value of the '{@link #getId() <em>Id</em>}' attribute. | ||
56 | * <!-- begin-user-doc --> | ||
57 | * <!-- end-user-doc --> | ||
58 | * @see #getId() | ||
59 | * @generated | ||
60 | * @ordered | ||
61 | */ | ||
62 | protected int id = ID_EDEFAULT; | ||
63 | |||
64 | /** | ||
65 | * The default value of the '{@link #getSpeed() <em>Speed</em>}' attribute. | ||
66 | * <!-- begin-user-doc --> | ||
67 | * <!-- end-user-doc --> | ||
68 | * @see #getSpeed() | ||
69 | * @generated | ||
70 | * @ordered | ||
71 | */ | ||
72 | protected static final double SPEED_EDEFAULT = 0.0; | ||
73 | |||
74 | /** | ||
75 | * The cached value of the '{@link #getSpeed() <em>Speed</em>}' attribute. | ||
76 | * <!-- begin-user-doc --> | ||
77 | * <!-- end-user-doc --> | ||
78 | * @see #getSpeed() | ||
79 | * @generated | ||
80 | * @ordered | ||
81 | */ | ||
82 | protected double speed = SPEED_EDEFAULT; | ||
83 | |||
84 | /** | ||
85 | * <!-- begin-user-doc --> | ||
86 | * <!-- end-user-doc --> | ||
87 | * @generated | ||
88 | */ | ||
89 | protected TrainImpl() { | ||
90 | super(); | ||
91 | } | ||
92 | |||
93 | /** | ||
94 | * <!-- begin-user-doc --> | ||
95 | * <!-- end-user-doc --> | ||
96 | * @generated | ||
97 | */ | ||
98 | @Override | ||
99 | protected EClass eStaticClass() { | ||
100 | return Modes3Package.Literals.TRAIN; | ||
101 | } | ||
102 | |||
103 | /** | ||
104 | * <!-- begin-user-doc --> | ||
105 | * <!-- end-user-doc --> | ||
106 | * @generated | ||
107 | */ | ||
108 | public Segment getLocation() { | ||
109 | if (location != null && location.eIsProxy()) { | ||
110 | InternalEObject oldLocation = (InternalEObject)location; | ||
111 | location = (Segment)eResolveProxy(oldLocation); | ||
112 | if (location != oldLocation) { | ||
113 | if (eNotificationRequired()) | ||
114 | eNotify(new ENotificationImpl(this, Notification.RESOLVE, Modes3Package.TRAIN__LOCATION, oldLocation, location)); | ||
115 | } | ||
116 | } | ||
117 | return location; | ||
118 | } | ||
119 | |||
120 | /** | ||
121 | * <!-- begin-user-doc --> | ||
122 | * <!-- end-user-doc --> | ||
123 | * @generated | ||
124 | */ | ||
125 | public Segment basicGetLocation() { | ||
126 | return location; | ||
127 | } | ||
128 | |||
129 | /** | ||
130 | * <!-- begin-user-doc --> | ||
131 | * <!-- end-user-doc --> | ||
132 | * @generated | ||
133 | */ | ||
134 | public NotificationChain basicSetLocation(Segment newLocation, NotificationChain msgs) { | ||
135 | Segment oldLocation = location; | ||
136 | location = newLocation; | ||
137 | if (eNotificationRequired()) { | ||
138 | ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, Modes3Package.TRAIN__LOCATION, oldLocation, newLocation); | ||
139 | if (msgs == null) msgs = notification; else msgs.add(notification); | ||
140 | } | ||
141 | return msgs; | ||
142 | } | ||
143 | |||
144 | /** | ||
145 | * <!-- begin-user-doc --> | ||
146 | * <!-- end-user-doc --> | ||
147 | * @generated | ||
148 | */ | ||
149 | public void setLocation(Segment newLocation) { | ||
150 | if (newLocation != location) { | ||
151 | NotificationChain msgs = null; | ||
152 | if (location != null) | ||
153 | msgs = ((InternalEObject)location).eInverseRemove(this, Modes3Package.SEGMENT__OCCUPIED_BY, Segment.class, msgs); | ||
154 | if (newLocation != null) | ||
155 | msgs = ((InternalEObject)newLocation).eInverseAdd(this, Modes3Package.SEGMENT__OCCUPIED_BY, Segment.class, msgs); | ||
156 | msgs = basicSetLocation(newLocation, msgs); | ||
157 | if (msgs != null) msgs.dispatch(); | ||
158 | } | ||
159 | else if (eNotificationRequired()) | ||
160 | eNotify(new ENotificationImpl(this, Notification.SET, Modes3Package.TRAIN__LOCATION, newLocation, newLocation)); | ||
161 | } | ||
162 | |||
163 | /** | ||
164 | * <!-- begin-user-doc --> | ||
165 | * <!-- end-user-doc --> | ||
166 | * @generated | ||
167 | */ | ||
168 | public int getId() { | ||
169 | return id; | ||
170 | } | ||
171 | |||
172 | /** | ||
173 | * <!-- begin-user-doc --> | ||
174 | * <!-- end-user-doc --> | ||
175 | * @generated | ||
176 | */ | ||
177 | public void setId(int newId) { | ||
178 | int oldId = id; | ||
179 | id = newId; | ||
180 | if (eNotificationRequired()) | ||
181 | eNotify(new ENotificationImpl(this, Notification.SET, Modes3Package.TRAIN__ID, oldId, id)); | ||
182 | } | ||
183 | |||
184 | /** | ||
185 | * <!-- begin-user-doc --> | ||
186 | * <!-- end-user-doc --> | ||
187 | * @generated | ||
188 | */ | ||
189 | public double getSpeed() { | ||
190 | return speed; | ||
191 | } | ||
192 | |||
193 | /** | ||
194 | * <!-- begin-user-doc --> | ||
195 | * <!-- end-user-doc --> | ||
196 | * @generated | ||
197 | */ | ||
198 | public void setSpeed(double newSpeed) { | ||
199 | double oldSpeed = speed; | ||
200 | speed = newSpeed; | ||
201 | if (eNotificationRequired()) | ||
202 | eNotify(new ENotificationImpl(this, Notification.SET, Modes3Package.TRAIN__SPEED, oldSpeed, speed)); | ||
203 | } | ||
204 | |||
205 | /** | ||
206 | * <!-- begin-user-doc --> | ||
207 | * <!-- end-user-doc --> | ||
208 | * @generated | ||
209 | */ | ||
210 | @Override | ||
211 | public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) { | ||
212 | switch (featureID) { | ||
213 | case Modes3Package.TRAIN__LOCATION: | ||
214 | if (location != null) | ||
215 | msgs = ((InternalEObject)location).eInverseRemove(this, Modes3Package.SEGMENT__OCCUPIED_BY, Segment.class, msgs); | ||
216 | return basicSetLocation((Segment)otherEnd, msgs); | ||
217 | } | ||
218 | return super.eInverseAdd(otherEnd, featureID, msgs); | ||
219 | } | ||
220 | |||
221 | /** | ||
222 | * <!-- begin-user-doc --> | ||
223 | * <!-- end-user-doc --> | ||
224 | * @generated | ||
225 | */ | ||
226 | @Override | ||
227 | public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) { | ||
228 | switch (featureID) { | ||
229 | case Modes3Package.TRAIN__LOCATION: | ||
230 | return basicSetLocation(null, msgs); | ||
231 | } | ||
232 | return super.eInverseRemove(otherEnd, featureID, msgs); | ||
233 | } | ||
234 | |||
235 | /** | ||
236 | * <!-- begin-user-doc --> | ||
237 | * <!-- end-user-doc --> | ||
238 | * @generated | ||
239 | */ | ||
240 | @Override | ||
241 | public Object eGet(int featureID, boolean resolve, boolean coreType) { | ||
242 | switch (featureID) { | ||
243 | case Modes3Package.TRAIN__LOCATION: | ||
244 | if (resolve) return getLocation(); | ||
245 | return basicGetLocation(); | ||
246 | case Modes3Package.TRAIN__ID: | ||
247 | return getId(); | ||
248 | case Modes3Package.TRAIN__SPEED: | ||
249 | return getSpeed(); | ||
250 | } | ||
251 | return super.eGet(featureID, resolve, coreType); | ||
252 | } | ||
253 | |||
254 | /** | ||
255 | * <!-- begin-user-doc --> | ||
256 | * <!-- end-user-doc --> | ||
257 | * @generated | ||
258 | */ | ||
259 | @Override | ||
260 | public void eSet(int featureID, Object newValue) { | ||
261 | switch (featureID) { | ||
262 | case Modes3Package.TRAIN__LOCATION: | ||
263 | setLocation((Segment)newValue); | ||
264 | return; | ||
265 | case Modes3Package.TRAIN__ID: | ||
266 | setId((Integer)newValue); | ||
267 | return; | ||
268 | case Modes3Package.TRAIN__SPEED: | ||
269 | setSpeed((Double)newValue); | ||
270 | return; | ||
271 | } | ||
272 | super.eSet(featureID, newValue); | ||
273 | } | ||
274 | |||
275 | /** | ||
276 | * <!-- begin-user-doc --> | ||
277 | * <!-- end-user-doc --> | ||
278 | * @generated | ||
279 | */ | ||
280 | @Override | ||
281 | public void eUnset(int featureID) { | ||
282 | switch (featureID) { | ||
283 | case Modes3Package.TRAIN__LOCATION: | ||
284 | setLocation((Segment)null); | ||
285 | return; | ||
286 | case Modes3Package.TRAIN__ID: | ||
287 | setId(ID_EDEFAULT); | ||
288 | return; | ||
289 | case Modes3Package.TRAIN__SPEED: | ||
290 | setSpeed(SPEED_EDEFAULT); | ||
291 | return; | ||
292 | } | ||
293 | super.eUnset(featureID); | ||
294 | } | ||
295 | |||
296 | /** | ||
297 | * <!-- begin-user-doc --> | ||
298 | * <!-- end-user-doc --> | ||
299 | * @generated | ||
300 | */ | ||
301 | @Override | ||
302 | public boolean eIsSet(int featureID) { | ||
303 | switch (featureID) { | ||
304 | case Modes3Package.TRAIN__LOCATION: | ||
305 | return location != null; | ||
306 | case Modes3Package.TRAIN__ID: | ||
307 | return id != ID_EDEFAULT; | ||
308 | case Modes3Package.TRAIN__SPEED: | ||
309 | return speed != SPEED_EDEFAULT; | ||
310 | } | ||
311 | return super.eIsSet(featureID); | ||
312 | } | ||
313 | |||
314 | /** | ||
315 | * <!-- begin-user-doc --> | ||
316 | * <!-- end-user-doc --> | ||
317 | * @generated | ||
318 | */ | ||
319 | @Override | ||
320 | public String toString() { | ||
321 | if (eIsProxy()) return super.toString(); | ||
322 | |||
323 | StringBuilder result = new StringBuilder(super.toString()); | ||
324 | result.append(" (id: "); | ||
325 | result.append(id); | ||
326 | result.append(", speed: "); | ||
327 | result.append(speed); | ||
328 | result.append(')'); | ||
329 | return result.toString(); | ||
330 | } | ||
331 | |||
332 | } //TrainImpl | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/ecore-gen/modes3/impl/TurnoutImpl.java b/Domains/ca.mcgill.rtgmrt.example.modes3/ecore-gen/modes3/impl/TurnoutImpl.java new file mode 100644 index 00000000..d20a104e --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/ecore-gen/modes3/impl/TurnoutImpl.java | |||
@@ -0,0 +1,216 @@ | |||
1 | /** | ||
2 | */ | ||
3 | package modes3.impl; | ||
4 | |||
5 | import modes3.Modes3Package; | ||
6 | import modes3.Segment; | ||
7 | import modes3.Turnout; | ||
8 | |||
9 | import org.eclipse.emf.common.notify.Notification; | ||
10 | |||
11 | import org.eclipse.emf.ecore.EClass; | ||
12 | import org.eclipse.emf.ecore.InternalEObject; | ||
13 | |||
14 | import org.eclipse.emf.ecore.impl.ENotificationImpl; | ||
15 | |||
16 | /** | ||
17 | * <!-- begin-user-doc --> | ||
18 | * An implementation of the model object '<em><b>Turnout</b></em>'. | ||
19 | * <!-- end-user-doc --> | ||
20 | * <p> | ||
21 | * The following features are implemented: | ||
22 | * </p> | ||
23 | * <ul> | ||
24 | * <li>{@link modes3.impl.TurnoutImpl#getStraight <em>Straight</em>}</li> | ||
25 | * <li>{@link modes3.impl.TurnoutImpl#getDivergent <em>Divergent</em>}</li> | ||
26 | * </ul> | ||
27 | * | ||
28 | * @generated | ||
29 | */ | ||
30 | public class TurnoutImpl extends SegmentImpl implements Turnout { | ||
31 | /** | ||
32 | * The cached value of the '{@link #getStraight() <em>Straight</em>}' reference. | ||
33 | * <!-- begin-user-doc --> | ||
34 | * <!-- end-user-doc --> | ||
35 | * @see #getStraight() | ||
36 | * @generated | ||
37 | * @ordered | ||
38 | */ | ||
39 | protected Segment straight; | ||
40 | |||
41 | /** | ||
42 | * The cached value of the '{@link #getDivergent() <em>Divergent</em>}' reference. | ||
43 | * <!-- begin-user-doc --> | ||
44 | * <!-- end-user-doc --> | ||
45 | * @see #getDivergent() | ||
46 | * @generated | ||
47 | * @ordered | ||
48 | */ | ||
49 | protected Segment divergent; | ||
50 | |||
51 | /** | ||
52 | * <!-- begin-user-doc --> | ||
53 | * <!-- end-user-doc --> | ||
54 | * @generated | ||
55 | */ | ||
56 | protected TurnoutImpl() { | ||
57 | super(); | ||
58 | } | ||
59 | |||
60 | /** | ||
61 | * <!-- begin-user-doc --> | ||
62 | * <!-- end-user-doc --> | ||
63 | * @generated | ||
64 | */ | ||
65 | @Override | ||
66 | protected EClass eStaticClass() { | ||
67 | return Modes3Package.Literals.TURNOUT; | ||
68 | } | ||
69 | |||
70 | /** | ||
71 | * <!-- begin-user-doc --> | ||
72 | * <!-- end-user-doc --> | ||
73 | * @generated | ||
74 | */ | ||
75 | public Segment getStraight() { | ||
76 | if (straight != null && straight.eIsProxy()) { | ||
77 | InternalEObject oldStraight = (InternalEObject)straight; | ||
78 | straight = (Segment)eResolveProxy(oldStraight); | ||
79 | if (straight != oldStraight) { | ||
80 | if (eNotificationRequired()) | ||
81 | eNotify(new ENotificationImpl(this, Notification.RESOLVE, Modes3Package.TURNOUT__STRAIGHT, oldStraight, straight)); | ||
82 | } | ||
83 | } | ||
84 | return straight; | ||
85 | } | ||
86 | |||
87 | /** | ||
88 | * <!-- begin-user-doc --> | ||
89 | * <!-- end-user-doc --> | ||
90 | * @generated | ||
91 | */ | ||
92 | public Segment basicGetStraight() { | ||
93 | return straight; | ||
94 | } | ||
95 | |||
96 | /** | ||
97 | * <!-- begin-user-doc --> | ||
98 | * <!-- end-user-doc --> | ||
99 | * @generated | ||
100 | */ | ||
101 | public void setStraight(Segment newStraight) { | ||
102 | Segment oldStraight = straight; | ||
103 | straight = newStraight; | ||
104 | if (eNotificationRequired()) | ||
105 | eNotify(new ENotificationImpl(this, Notification.SET, Modes3Package.TURNOUT__STRAIGHT, oldStraight, straight)); | ||
106 | } | ||
107 | |||
108 | /** | ||
109 | * <!-- begin-user-doc --> | ||
110 | * <!-- end-user-doc --> | ||
111 | * @generated | ||
112 | */ | ||
113 | public Segment getDivergent() { | ||
114 | if (divergent != null && divergent.eIsProxy()) { | ||
115 | InternalEObject oldDivergent = (InternalEObject)divergent; | ||
116 | divergent = (Segment)eResolveProxy(oldDivergent); | ||
117 | if (divergent != oldDivergent) { | ||
118 | if (eNotificationRequired()) | ||
119 | eNotify(new ENotificationImpl(this, Notification.RESOLVE, Modes3Package.TURNOUT__DIVERGENT, oldDivergent, divergent)); | ||
120 | } | ||
121 | } | ||
122 | return divergent; | ||
123 | } | ||
124 | |||
125 | /** | ||
126 | * <!-- begin-user-doc --> | ||
127 | * <!-- end-user-doc --> | ||
128 | * @generated | ||
129 | */ | ||
130 | public Segment basicGetDivergent() { | ||
131 | return divergent; | ||
132 | } | ||
133 | |||
134 | /** | ||
135 | * <!-- begin-user-doc --> | ||
136 | * <!-- end-user-doc --> | ||
137 | * @generated | ||
138 | */ | ||
139 | public void setDivergent(Segment newDivergent) { | ||
140 | Segment oldDivergent = divergent; | ||
141 | divergent = newDivergent; | ||
142 | if (eNotificationRequired()) | ||
143 | eNotify(new ENotificationImpl(this, Notification.SET, Modes3Package.TURNOUT__DIVERGENT, oldDivergent, divergent)); | ||
144 | } | ||
145 | |||
146 | /** | ||
147 | * <!-- begin-user-doc --> | ||
148 | * <!-- end-user-doc --> | ||
149 | * @generated | ||
150 | */ | ||
151 | @Override | ||
152 | public Object eGet(int featureID, boolean resolve, boolean coreType) { | ||
153 | switch (featureID) { | ||
154 | case Modes3Package.TURNOUT__STRAIGHT: | ||
155 | if (resolve) return getStraight(); | ||
156 | return basicGetStraight(); | ||
157 | case Modes3Package.TURNOUT__DIVERGENT: | ||
158 | if (resolve) return getDivergent(); | ||
159 | return basicGetDivergent(); | ||
160 | } | ||
161 | return super.eGet(featureID, resolve, coreType); | ||
162 | } | ||
163 | |||
164 | /** | ||
165 | * <!-- begin-user-doc --> | ||
166 | * <!-- end-user-doc --> | ||
167 | * @generated | ||
168 | */ | ||
169 | @Override | ||
170 | public void eSet(int featureID, Object newValue) { | ||
171 | switch (featureID) { | ||
172 | case Modes3Package.TURNOUT__STRAIGHT: | ||
173 | setStraight((Segment)newValue); | ||
174 | return; | ||
175 | case Modes3Package.TURNOUT__DIVERGENT: | ||
176 | setDivergent((Segment)newValue); | ||
177 | return; | ||
178 | } | ||
179 | super.eSet(featureID, newValue); | ||
180 | } | ||
181 | |||
182 | /** | ||
183 | * <!-- begin-user-doc --> | ||
184 | * <!-- end-user-doc --> | ||
185 | * @generated | ||
186 | */ | ||
187 | @Override | ||
188 | public void eUnset(int featureID) { | ||
189 | switch (featureID) { | ||
190 | case Modes3Package.TURNOUT__STRAIGHT: | ||
191 | setStraight((Segment)null); | ||
192 | return; | ||
193 | case Modes3Package.TURNOUT__DIVERGENT: | ||
194 | setDivergent((Segment)null); | ||
195 | return; | ||
196 | } | ||
197 | super.eUnset(featureID); | ||
198 | } | ||
199 | |||
200 | /** | ||
201 | * <!-- begin-user-doc --> | ||
202 | * <!-- end-user-doc --> | ||
203 | * @generated | ||
204 | */ | ||
205 | @Override | ||
206 | public boolean eIsSet(int featureID) { | ||
207 | switch (featureID) { | ||
208 | case Modes3Package.TURNOUT__STRAIGHT: | ||
209 | return straight != null; | ||
210 | case Modes3Package.TURNOUT__DIVERGENT: | ||
211 | return divergent != null; | ||
212 | } | ||
213 | return super.eIsSet(featureID); | ||
214 | } | ||
215 | |||
216 | } //TurnoutImpl | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/ecore-gen/modes3/util/Modes3AdapterFactory.java b/Domains/ca.mcgill.rtgmrt.example.modes3/ecore-gen/modes3/util/Modes3AdapterFactory.java new file mode 100644 index 00000000..9c5c8d2d --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/ecore-gen/modes3/util/Modes3AdapterFactory.java | |||
@@ -0,0 +1,192 @@ | |||
1 | /** | ||
2 | */ | ||
3 | package modes3.util; | ||
4 | |||
5 | import modes3.*; | ||
6 | |||
7 | import org.eclipse.emf.common.notify.Adapter; | ||
8 | import org.eclipse.emf.common.notify.Notifier; | ||
9 | |||
10 | import org.eclipse.emf.common.notify.impl.AdapterFactoryImpl; | ||
11 | |||
12 | import org.eclipse.emf.ecore.EObject; | ||
13 | |||
14 | /** | ||
15 | * <!-- begin-user-doc --> | ||
16 | * The <b>Adapter Factory</b> for the model. | ||
17 | * It provides an adapter <code>createXXX</code> method for each class of the model. | ||
18 | * <!-- end-user-doc --> | ||
19 | * @see modes3.Modes3Package | ||
20 | * @generated | ||
21 | */ | ||
22 | public class Modes3AdapterFactory extends AdapterFactoryImpl { | ||
23 | /** | ||
24 | * The cached model package. | ||
25 | * <!-- begin-user-doc --> | ||
26 | * <!-- end-user-doc --> | ||
27 | * @generated | ||
28 | */ | ||
29 | protected static Modes3Package modelPackage; | ||
30 | |||
31 | /** | ||
32 | * Creates an instance of the adapter factory. | ||
33 | * <!-- begin-user-doc --> | ||
34 | * <!-- end-user-doc --> | ||
35 | * @generated | ||
36 | */ | ||
37 | public Modes3AdapterFactory() { | ||
38 | if (modelPackage == null) { | ||
39 | modelPackage = Modes3Package.eINSTANCE; | ||
40 | } | ||
41 | } | ||
42 | |||
43 | /** | ||
44 | * Returns whether this factory is applicable for the type of the object. | ||
45 | * <!-- begin-user-doc --> | ||
46 | * This implementation returns <code>true</code> if the object is either the model's package or is an instance object of the model. | ||
47 | * <!-- end-user-doc --> | ||
48 | * @return whether this factory is applicable for the type of the object. | ||
49 | * @generated | ||
50 | */ | ||
51 | @Override | ||
52 | public boolean isFactoryForType(Object object) { | ||
53 | if (object == modelPackage) { | ||
54 | return true; | ||
55 | } | ||
56 | if (object instanceof EObject) { | ||
57 | return ((EObject)object).eClass().getEPackage() == modelPackage; | ||
58 | } | ||
59 | return false; | ||
60 | } | ||
61 | |||
62 | /** | ||
63 | * The switch that delegates to the <code>createXXX</code> methods. | ||
64 | * <!-- begin-user-doc --> | ||
65 | * <!-- end-user-doc --> | ||
66 | * @generated | ||
67 | */ | ||
68 | protected Modes3Switch<Adapter> modelSwitch = | ||
69 | new Modes3Switch<Adapter>() { | ||
70 | @Override | ||
71 | public Adapter caseSegment(Segment object) { | ||
72 | return createSegmentAdapter(); | ||
73 | } | ||
74 | @Override | ||
75 | public Adapter caseModes3ModelRoot(Modes3ModelRoot object) { | ||
76 | return createModes3ModelRootAdapter(); | ||
77 | } | ||
78 | @Override | ||
79 | public Adapter caseTurnout(Turnout object) { | ||
80 | return createTurnoutAdapter(); | ||
81 | } | ||
82 | @Override | ||
83 | public Adapter caseTrain(Train object) { | ||
84 | return createTrainAdapter(); | ||
85 | } | ||
86 | @Override | ||
87 | public Adapter caseSimpleSegment(SimpleSegment object) { | ||
88 | return createSimpleSegmentAdapter(); | ||
89 | } | ||
90 | @Override | ||
91 | public Adapter defaultCase(EObject object) { | ||
92 | return createEObjectAdapter(); | ||
93 | } | ||
94 | }; | ||
95 | |||
96 | /** | ||
97 | * Creates an adapter for the <code>target</code>. | ||
98 | * <!-- begin-user-doc --> | ||
99 | * <!-- end-user-doc --> | ||
100 | * @param target the object to adapt. | ||
101 | * @return the adapter for the <code>target</code>. | ||
102 | * @generated | ||
103 | */ | ||
104 | @Override | ||
105 | public Adapter createAdapter(Notifier target) { | ||
106 | return modelSwitch.doSwitch((EObject)target); | ||
107 | } | ||
108 | |||
109 | |||
110 | /** | ||
111 | * Creates a new adapter for an object of class '{@link modes3.Segment <em>Segment</em>}'. | ||
112 | * <!-- begin-user-doc --> | ||
113 | * This default implementation returns null so that we can easily ignore cases; | ||
114 | * it's useful to ignore a case when inheritance will catch all the cases anyway. | ||
115 | * <!-- end-user-doc --> | ||
116 | * @return the new adapter. | ||
117 | * @see modes3.Segment | ||
118 | * @generated | ||
119 | */ | ||
120 | public Adapter createSegmentAdapter() { | ||
121 | return null; | ||
122 | } | ||
123 | |||
124 | /** | ||
125 | * Creates a new adapter for an object of class '{@link modes3.Modes3ModelRoot <em>Model Root</em>}'. | ||
126 | * <!-- begin-user-doc --> | ||
127 | * This default implementation returns null so that we can easily ignore cases; | ||
128 | * it's useful to ignore a case when inheritance will catch all the cases anyway. | ||
129 | * <!-- end-user-doc --> | ||
130 | * @return the new adapter. | ||
131 | * @see modes3.Modes3ModelRoot | ||
132 | * @generated | ||
133 | */ | ||
134 | public Adapter createModes3ModelRootAdapter() { | ||
135 | return null; | ||
136 | } | ||
137 | |||
138 | /** | ||
139 | * Creates a new adapter for an object of class '{@link modes3.Turnout <em>Turnout</em>}'. | ||
140 | * <!-- begin-user-doc --> | ||
141 | * This default implementation returns null so that we can easily ignore cases; | ||
142 | * it's useful to ignore a case when inheritance will catch all the cases anyway. | ||
143 | * <!-- end-user-doc --> | ||
144 | * @return the new adapter. | ||
145 | * @see modes3.Turnout | ||
146 | * @generated | ||
147 | */ | ||
148 | public Adapter createTurnoutAdapter() { | ||
149 | return null; | ||
150 | } | ||
151 | |||
152 | /** | ||
153 | * Creates a new adapter for an object of class '{@link modes3.Train <em>Train</em>}'. | ||
154 | * <!-- begin-user-doc --> | ||
155 | * This default implementation returns null so that we can easily ignore cases; | ||
156 | * it's useful to ignore a case when inheritance will catch all the cases anyway. | ||
157 | * <!-- end-user-doc --> | ||
158 | * @return the new adapter. | ||
159 | * @see modes3.Train | ||
160 | * @generated | ||
161 | */ | ||
162 | public Adapter createTrainAdapter() { | ||
163 | return null; | ||
164 | } | ||
165 | |||
166 | /** | ||
167 | * Creates a new adapter for an object of class '{@link modes3.SimpleSegment <em>Simple Segment</em>}'. | ||
168 | * <!-- begin-user-doc --> | ||
169 | * This default implementation returns null so that we can easily ignore cases; | ||
170 | * it's useful to ignore a case when inheritance will catch all the cases anyway. | ||
171 | * <!-- end-user-doc --> | ||
172 | * @return the new adapter. | ||
173 | * @see modes3.SimpleSegment | ||
174 | * @generated | ||
175 | */ | ||
176 | public Adapter createSimpleSegmentAdapter() { | ||
177 | return null; | ||
178 | } | ||
179 | |||
180 | /** | ||
181 | * Creates a new adapter for the default case. | ||
182 | * <!-- begin-user-doc --> | ||
183 | * This default implementation returns null. | ||
184 | * <!-- end-user-doc --> | ||
185 | * @return the new adapter. | ||
186 | * @generated | ||
187 | */ | ||
188 | public Adapter createEObjectAdapter() { | ||
189 | return null; | ||
190 | } | ||
191 | |||
192 | } //Modes3AdapterFactory | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/ecore-gen/modes3/util/Modes3Switch.java b/Domains/ca.mcgill.rtgmrt.example.modes3/ecore-gen/modes3/util/Modes3Switch.java new file mode 100644 index 00000000..0c28861a --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/ecore-gen/modes3/util/Modes3Switch.java | |||
@@ -0,0 +1,196 @@ | |||
1 | /** | ||
2 | */ | ||
3 | package modes3.util; | ||
4 | |||
5 | import modes3.*; | ||
6 | |||
7 | import org.eclipse.emf.ecore.EObject; | ||
8 | import org.eclipse.emf.ecore.EPackage; | ||
9 | |||
10 | import org.eclipse.emf.ecore.util.Switch; | ||
11 | |||
12 | /** | ||
13 | * <!-- begin-user-doc --> | ||
14 | * The <b>Switch</b> for the model's inheritance hierarchy. | ||
15 | * It supports the call {@link #doSwitch(EObject) doSwitch(object)} | ||
16 | * to invoke the <code>caseXXX</code> method for each class of the model, | ||
17 | * starting with the actual class of the object | ||
18 | * and proceeding up the inheritance hierarchy | ||
19 | * until a non-null result is returned, | ||
20 | * which is the result of the switch. | ||
21 | * <!-- end-user-doc --> | ||
22 | * @see modes3.Modes3Package | ||
23 | * @generated | ||
24 | */ | ||
25 | public class Modes3Switch<T> extends Switch<T> { | ||
26 | /** | ||
27 | * The cached model package | ||
28 | * <!-- begin-user-doc --> | ||
29 | * <!-- end-user-doc --> | ||
30 | * @generated | ||
31 | */ | ||
32 | protected static Modes3Package modelPackage; | ||
33 | |||
34 | /** | ||
35 | * Creates an instance of the switch. | ||
36 | * <!-- begin-user-doc --> | ||
37 | * <!-- end-user-doc --> | ||
38 | * @generated | ||
39 | */ | ||
40 | public Modes3Switch() { | ||
41 | if (modelPackage == null) { | ||
42 | modelPackage = Modes3Package.eINSTANCE; | ||
43 | } | ||
44 | } | ||
45 | |||
46 | /** | ||
47 | * Checks whether this is a switch for the given package. | ||
48 | * <!-- begin-user-doc --> | ||
49 | * <!-- end-user-doc --> | ||
50 | * @param ePackage the package in question. | ||
51 | * @return whether this is a switch for the given package. | ||
52 | * @generated | ||
53 | */ | ||
54 | @Override | ||
55 | protected boolean isSwitchFor(EPackage ePackage) { | ||
56 | return ePackage == modelPackage; | ||
57 | } | ||
58 | |||
59 | /** | ||
60 | * Calls <code>caseXXX</code> for each class of the model until one returns a non null result; it yields that result. | ||
61 | * <!-- begin-user-doc --> | ||
62 | * <!-- end-user-doc --> | ||
63 | * @return the first non-null result returned by a <code>caseXXX</code> call. | ||
64 | * @generated | ||
65 | */ | ||
66 | @Override | ||
67 | protected T doSwitch(int classifierID, EObject theEObject) { | ||
68 | switch (classifierID) { | ||
69 | case Modes3Package.SEGMENT: { | ||
70 | Segment segment = (Segment)theEObject; | ||
71 | T result = caseSegment(segment); | ||
72 | if (result == null) result = defaultCase(theEObject); | ||
73 | return result; | ||
74 | } | ||
75 | case Modes3Package.MODES3_MODEL_ROOT: { | ||
76 | Modes3ModelRoot modes3ModelRoot = (Modes3ModelRoot)theEObject; | ||
77 | T result = caseModes3ModelRoot(modes3ModelRoot); | ||
78 | if (result == null) result = defaultCase(theEObject); | ||
79 | return result; | ||
80 | } | ||
81 | case Modes3Package.TURNOUT: { | ||
82 | Turnout turnout = (Turnout)theEObject; | ||
83 | T result = caseTurnout(turnout); | ||
84 | if (result == null) result = caseSegment(turnout); | ||
85 | if (result == null) result = defaultCase(theEObject); | ||
86 | return result; | ||
87 | } | ||
88 | case Modes3Package.TRAIN: { | ||
89 | Train train = (Train)theEObject; | ||
90 | T result = caseTrain(train); | ||
91 | if (result == null) result = defaultCase(theEObject); | ||
92 | return result; | ||
93 | } | ||
94 | case Modes3Package.SIMPLE_SEGMENT: { | ||
95 | SimpleSegment simpleSegment = (SimpleSegment)theEObject; | ||
96 | T result = caseSimpleSegment(simpleSegment); | ||
97 | if (result == null) result = caseSegment(simpleSegment); | ||
98 | if (result == null) result = defaultCase(theEObject); | ||
99 | return result; | ||
100 | } | ||
101 | default: return defaultCase(theEObject); | ||
102 | } | ||
103 | } | ||
104 | |||
105 | /** | ||
106 | * Returns the result of interpreting the object as an instance of '<em>Segment</em>'. | ||
107 | * <!-- begin-user-doc --> | ||
108 | * This implementation returns null; | ||
109 | * returning a non-null result will terminate the switch. | ||
110 | * <!-- end-user-doc --> | ||
111 | * @param object the target of the switch. | ||
112 | * @return the result of interpreting the object as an instance of '<em>Segment</em>'. | ||
113 | * @see #doSwitch(org.eclipse.emf.ecore.EObject) doSwitch(EObject) | ||
114 | * @generated | ||
115 | */ | ||
116 | public T caseSegment(Segment object) { | ||
117 | return null; | ||
118 | } | ||
119 | |||
120 | /** | ||
121 | * Returns the result of interpreting the object as an instance of '<em>Model Root</em>'. | ||
122 | * <!-- begin-user-doc --> | ||
123 | * This implementation returns null; | ||
124 | * returning a non-null result will terminate the switch. | ||
125 | * <!-- end-user-doc --> | ||
126 | * @param object the target of the switch. | ||
127 | * @return the result of interpreting the object as an instance of '<em>Model Root</em>'. | ||
128 | * @see #doSwitch(org.eclipse.emf.ecore.EObject) doSwitch(EObject) | ||
129 | * @generated | ||
130 | */ | ||
131 | public T caseModes3ModelRoot(Modes3ModelRoot object) { | ||
132 | return null; | ||
133 | } | ||
134 | |||
135 | /** | ||
136 | * Returns the result of interpreting the object as an instance of '<em>Turnout</em>'. | ||
137 | * <!-- begin-user-doc --> | ||
138 | * This implementation returns null; | ||
139 | * returning a non-null result will terminate the switch. | ||
140 | * <!-- end-user-doc --> | ||
141 | * @param object the target of the switch. | ||
142 | * @return the result of interpreting the object as an instance of '<em>Turnout</em>'. | ||
143 | * @see #doSwitch(org.eclipse.emf.ecore.EObject) doSwitch(EObject) | ||
144 | * @generated | ||
145 | */ | ||
146 | public T caseTurnout(Turnout object) { | ||
147 | return null; | ||
148 | } | ||
149 | |||
150 | /** | ||
151 | * Returns the result of interpreting the object as an instance of '<em>Train</em>'. | ||
152 | * <!-- begin-user-doc --> | ||
153 | * This implementation returns null; | ||
154 | * returning a non-null result will terminate the switch. | ||
155 | * <!-- end-user-doc --> | ||
156 | * @param object the target of the switch. | ||
157 | * @return the result of interpreting the object as an instance of '<em>Train</em>'. | ||
158 | * @see #doSwitch(org.eclipse.emf.ecore.EObject) doSwitch(EObject) | ||
159 | * @generated | ||
160 | */ | ||
161 | public T caseTrain(Train object) { | ||
162 | return null; | ||
163 | } | ||
164 | |||
165 | /** | ||
166 | * Returns the result of interpreting the object as an instance of '<em>Simple Segment</em>'. | ||
167 | * <!-- begin-user-doc --> | ||
168 | * This implementation returns null; | ||
169 | * returning a non-null result will terminate the switch. | ||
170 | * <!-- end-user-doc --> | ||
171 | * @param object the target of the switch. | ||
172 | * @return the result of interpreting the object as an instance of '<em>Simple Segment</em>'. | ||
173 | * @see #doSwitch(org.eclipse.emf.ecore.EObject) doSwitch(EObject) | ||
174 | * @generated | ||
175 | */ | ||
176 | public T caseSimpleSegment(SimpleSegment object) { | ||
177 | return null; | ||
178 | } | ||
179 | |||
180 | /** | ||
181 | * Returns the result of interpreting the object as an instance of '<em>EObject</em>'. | ||
182 | * <!-- begin-user-doc --> | ||
183 | * This implementation returns null; | ||
184 | * returning a non-null result will terminate the switch, but this is the last case anyway. | ||
185 | * <!-- end-user-doc --> | ||
186 | * @param object the target of the switch. | ||
187 | * @return the result of interpreting the object as an instance of '<em>EObject</em>'. | ||
188 | * @see #doSwitch(org.eclipse.emf.ecore.EObject) | ||
189 | * @generated | ||
190 | */ | ||
191 | @Override | ||
192 | public T defaultCase(EObject object) { | ||
193 | return null; | ||
194 | } | ||
195 | |||
196 | } //Modes3Switch | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/model/modes3.ecore b/Domains/ca.mcgill.rtgmrt.example.modes3/model/modes3.ecore new file mode 100644 index 00000000..f7cb28be --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/model/modes3.ecore | |||
@@ -0,0 +1,33 @@ | |||
1 | <?xml version="1.0" encoding="UTF-8"?> | ||
2 | <ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
3 | xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="modes3" nsURI="http://www.ece.mcgill.ca/wcet/modes3" nsPrefix="modes3"> | ||
4 | <eClassifiers xsi:type="ecore:EClass" name="Segment"> | ||
5 | <eStructuralFeatures xsi:type="ecore:EReference" name="connectedTo" upperBound="2" | ||
6 | eType="#//Segment"/> | ||
7 | <eStructuralFeatures xsi:type="ecore:EReference" name="occupiedBy" eType="#//Train" | ||
8 | eOpposite="#//Train/location"/> | ||
9 | <eStructuralFeatures xsi:type="ecore:EAttribute" name="id" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt"/> | ||
10 | </eClassifiers> | ||
11 | <eClassifiers xsi:type="ecore:EClass" name="Modes3ModelRoot"> | ||
12 | <eStructuralFeatures xsi:type="ecore:EAttribute" name="id" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt"/> | ||
13 | <eStructuralFeatures xsi:type="ecore:EReference" name="trains" upperBound="-1" | ||
14 | eType="#//Train" containment="true"/> | ||
15 | <eStructuralFeatures xsi:type="ecore:EReference" name="segments" upperBound="-1" | ||
16 | eType="#//SimpleSegment" containment="true"/> | ||
17 | <eStructuralFeatures xsi:type="ecore:EReference" name="turnouts" upperBound="-1" | ||
18 | eType="#//Turnout" containment="true"/> | ||
19 | </eClassifiers> | ||
20 | <eClassifiers xsi:type="ecore:EClass" name="Turnout" eSuperTypes="#//Segment"> | ||
21 | <eStructuralFeatures xsi:type="ecore:EReference" name="straight" lowerBound="1" | ||
22 | eType="#//Segment"/> | ||
23 | <eStructuralFeatures xsi:type="ecore:EReference" name="divergent" lowerBound="1" | ||
24 | eType="#//Segment"/> | ||
25 | </eClassifiers> | ||
26 | <eClassifiers xsi:type="ecore:EClass" name="Train"> | ||
27 | <eStructuralFeatures xsi:type="ecore:EReference" name="location" lowerBound="1" | ||
28 | eType="#//Segment" eOpposite="#//Segment/occupiedBy"/> | ||
29 | <eStructuralFeatures xsi:type="ecore:EAttribute" name="id" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt"/> | ||
30 | <eStructuralFeatures xsi:type="ecore:EAttribute" name="speed" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EDouble"/> | ||
31 | </eClassifiers> | ||
32 | <eClassifiers xsi:type="ecore:EClass" name="SimpleSegment" eSuperTypes="#//Segment"/> | ||
33 | </ecore:EPackage> | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/model/modes3.genmodel b/Domains/ca.mcgill.rtgmrt.example.modes3/model/modes3.genmodel new file mode 100644 index 00000000..1cd4ac41 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/model/modes3.genmodel | |||
@@ -0,0 +1,31 @@ | |||
1 | <?xml version="1.0" encoding="UTF-8"?> | ||
2 | <genmodel:GenModel xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" | ||
3 | xmlns:genmodel="http://www.eclipse.org/emf/2002/GenModel" modelDirectory="/ca.mcgill.rtgmrt.example.modes3/ecore-gen" modelPluginID="ca.mcgill.rtgmrt.example.modes3" | ||
4 | modelName="Modes3" rootExtendsClass="org.eclipse.emf.ecore.impl.MinimalEObjectImpl$Container" | ||
5 | importerID="org.eclipse.emf.importer.ecore" complianceLevel="5.0" copyrightFields="false" | ||
6 | operationReflection="true" importOrganizing="true"> | ||
7 | <foreignModel>modes3.ecore</foreignModel> | ||
8 | <genPackages prefix="Modes3" disposableProviderFactory="true" ecorePackage="modes3.ecore#/"> | ||
9 | <genClasses ecoreClass="modes3.ecore#//Segment"> | ||
10 | <genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference modes3.ecore#//Segment/connectedTo"/> | ||
11 | <genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference modes3.ecore#//Segment/occupiedBy"/> | ||
12 | <genFeatures createChild="false" ecoreFeature="ecore:EAttribute modes3.ecore#//Segment/id"/> | ||
13 | </genClasses> | ||
14 | <genClasses ecoreClass="modes3.ecore#//Modes3ModelRoot"> | ||
15 | <genFeatures createChild="false" ecoreFeature="ecore:EAttribute modes3.ecore#//Modes3ModelRoot/id"/> | ||
16 | <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference modes3.ecore#//Modes3ModelRoot/trains"/> | ||
17 | <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference modes3.ecore#//Modes3ModelRoot/segments"/> | ||
18 | <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference modes3.ecore#//Modes3ModelRoot/turnouts"/> | ||
19 | </genClasses> | ||
20 | <genClasses ecoreClass="modes3.ecore#//Turnout"> | ||
21 | <genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference modes3.ecore#//Turnout/straight"/> | ||
22 | <genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference modes3.ecore#//Turnout/divergent"/> | ||
23 | </genClasses> | ||
24 | <genClasses ecoreClass="modes3.ecore#//Train"> | ||
25 | <genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference modes3.ecore#//Train/location"/> | ||
26 | <genFeatures createChild="false" ecoreFeature="ecore:EAttribute modes3.ecore#//Train/id"/> | ||
27 | <genFeatures createChild="false" ecoreFeature="ecore:EAttribute modes3.ecore#//Train/speed"/> | ||
28 | </genClasses> | ||
29 | <genClasses ecoreClass="modes3.ecore#//SimpleSegment"/> | ||
30 | </genPackages> | ||
31 | </genmodel:GenModel> | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/plugin.properties b/Domains/ca.mcgill.rtgmrt.example.modes3/plugin.properties new file mode 100644 index 00000000..4eba0dd8 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/plugin.properties | |||
@@ -0,0 +1,4 @@ | |||
1 | # | ||
2 | |||
3 | pluginName = ca.mcgill.rtgmrt.example.modes3 | ||
4 | providerName = www.example.org | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/plugin.xml b/Domains/ca.mcgill.rtgmrt.example.modes3/plugin.xml new file mode 100644 index 00000000..f7d32541 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/plugin.xml | |||
@@ -0,0 +1,44 @@ | |||
1 | <?xml version="1.0" encoding="UTF-8"?><?eclipse version="3.0"?><!-- | ||
2 | --><plugin> | ||
3 | <extension point="org.eclipse.emf.ecore.generated_package"> | ||
4 | <!-- @generated modes3 --> | ||
5 | <package class="modes3.Modes3Package" genModel="model/modes3.genmodel" uri="http://www.ece.mcgill.ca/wcet/modes3"/> | ||
6 | </extension> | ||
7 | <extension id="modes3.queries.Modes3Queries" point="org.eclipse.viatra.query.runtime.queryspecification"> | ||
8 | <group group="org.eclipse.viatra.query.runtime.extensibility.SingletonExtensionFactory:modes3.queries.Modes3Queries" id="modes3.queries.Modes3Queries"> | ||
9 | <query-specification fqn="modes3.queries.connectedTo"/> | ||
10 | <query-specification fqn="modes3.queries.connectedToNotSymmetric"/> | ||
11 | <query-specification fqn="modes3.queries.connectedToReflexive"/> | ||
12 | <query-specification fqn="modes3.queries.turnoutOutput"/> | ||
13 | <query-specification fqn="modes3.queries.outputReflexive"/> | ||
14 | <query-specification fqn="modes3.queries.turnoutOutputsAreSame"/> | ||
15 | <query-specification fqn="modes3.queries.output"/> | ||
16 | <query-specification fqn="modes3.queries.tooManyInputsOfSegment"/> | ||
17 | <query-specification fqn="modes3.queries.turnoutConnectedToBothOutputs"/> | ||
18 | <query-specification fqn="modes3.queries.adjacent"/> | ||
19 | <query-specification fqn="modes3.queries.tooManyInputsOfTurnout"/> | ||
20 | <query-specification fqn="modes3.queries.inputsOfTurnout"/> | ||
21 | <query-specification fqn="modes3.queries.tooFewInputsOfTurnout"/> | ||
22 | <query-specification fqn="modes3.queries.reachable"/> | ||
23 | <query-specification fqn="modes3.queries.unreachable"/> | ||
24 | <query-specification fqn="modes3.queries.closeTrains_step_2"/> | ||
25 | <query-specification fqn="modes3.queries.closeTrains_step_3"/> | ||
26 | <query-specification fqn="modes3.queries.closeTrains_step_4"/> | ||
27 | <query-specification fqn="modes3.queries.closeTrains_step_5"/> | ||
28 | <query-specification fqn="modes3.queries.closeTrains_step_6"/> | ||
29 | <query-specification fqn="modes3.queries.closeTrains_step_7"/> | ||
30 | <query-specification fqn="modes3.queries.trainLocations_step_2"/> | ||
31 | <query-specification fqn="modes3.queries.trainLocations_step_3"/> | ||
32 | <query-specification fqn="modes3.queries.misalignedTurnout_step_2"/> | ||
33 | <query-specification fqn="modes3.queries.misalignedTurnout_step_3"/> | ||
34 | <query-specification fqn="modes3.queries.misalignedTurnout_step_4"/> | ||
35 | <query-specification fqn="modes3.queries.misalignedTurnout_step_5"/> | ||
36 | <query-specification fqn="modes3.queries.connectedSegmentsDirected"/> | ||
37 | <query-specification fqn="modes3.queries.endOfSiding_step_2"/> | ||
38 | <query-specification fqn="modes3.queries.endOfSiding_step_3"/> | ||
39 | <query-specification fqn="modes3.queries.endOfSiding_step_4"/> | ||
40 | <query-specification fqn="modes3.queries.endOfSiding_step_5"/> | ||
41 | <query-specification fqn="modes3.queries.multipleConnectedTo"/> | ||
42 | </group> | ||
43 | </extension> | ||
44 | </plugin> | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/src/modes3/queries/Modes3Queries.vql b/Domains/ca.mcgill.rtgmrt.example.modes3/src/modes3/queries/Modes3Queries.vql new file mode 100644 index 00000000..d22bdd8b --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/src/modes3/queries/Modes3Queries.vql | |||
@@ -0,0 +1,295 @@ | |||
1 | package modes3.queries | ||
2 | |||
3 | import "http://www.ece.mcgill.ca/wcet/modes3" | ||
4 | |||
5 | pattern connectedTo(S1 : Segment, S2 : Segment) { | ||
6 | Segment.connectedTo(S1, S2); | ||
7 | } | ||
8 | |||
9 | @Constraint(message = "connectedToNotSymmetric", severity = "error", key = { S1, S2 }) | ||
10 | pattern connectedToNotSymmetric(S1 : Segment, S2 : Segment) { | ||
11 | Segment.connectedTo(S1, S2); | ||
12 | neg find connectedTo(S2, S1); | ||
13 | } | ||
14 | |||
15 | @Constraint(message = "connectedToReflexive", severity = "error", key = { S }) | ||
16 | pattern connectedToReflexive(S : Segment) { | ||
17 | Segment.connectedTo(S, S); | ||
18 | } | ||
19 | |||
20 | pattern turnoutOutput(T : Turnout, S : Segment) { | ||
21 | Turnout.straight(T, S); | ||
22 | } or { | ||
23 | Turnout.divergent(T, S); | ||
24 | } | ||
25 | |||
26 | @Constraint(message = "outputReflexive", severity = "error", key = { T }) | ||
27 | pattern outputReflexive(T : Turnout) { | ||
28 | find turnoutOutput(T, T); | ||
29 | } | ||
30 | |||
31 | @Constraint(message = "turnoutOutputsAreSame", severity = "error", key = { T }) | ||
32 | pattern turnoutOutputsAreSame(T : Turnout) { | ||
33 | Turnout.straight(T, S); | ||
34 | Turnout.divergent(T, S); | ||
35 | } | ||
36 | |||
37 | pattern output(S1 : Segment, S2 : Segment) { | ||
38 | Segment.connectedTo(S1, S2); | ||
39 | } or { | ||
40 | find turnoutOutput(S1, S2); | ||
41 | } | ||
42 | |||
43 | @Constraint(message = "tooManyInputsOfSegment", severity = "error", key = { S }) | ||
44 | pattern tooManyInputsOfSegment(S : SimpleSegment) { | ||
45 | find output(I1, S); | ||
46 | find output(I2, S); | ||
47 | find output(I3, S); | ||
48 | I1 != I2; | ||
49 | I1 != I3; | ||
50 | I2 != I3; | ||
51 | } | ||
52 | |||
53 | @Constraint(message = "turnoutConnectedToBothOutputs", severity = "error", key = { T }) | ||
54 | pattern turnoutConnectedToBothOutputs(T : Turnout) { | ||
55 | Turnout.straight(T, Straight); | ||
56 | Turnout.divergent(T, Divergent); | ||
57 | Segment.connectedTo(T, Straight); | ||
58 | Segment.connectedTo(T, Divergent); | ||
59 | } | ||
60 | |||
61 | pattern adjacent(S1 : Segment, S2 : Segment) { | ||
62 | find output(S1, S2); | ||
63 | } or { | ||
64 | find turnoutOutput(S2, S1); | ||
65 | } | ||
66 | |||
67 | @Constraint(message = "turnoutConnectedToBothOutputs", severity = "error", key = { T }) | ||
68 | pattern tooManyInputsOfTurnout(T : Turnout) { | ||
69 | find adjacent(I1, T); | ||
70 | find adjacent(I2, T); | ||
71 | find adjacent(I3, T); | ||
72 | find adjacent(I4, T); | ||
73 | I1 != I2; | ||
74 | I1 != I3; | ||
75 | I1 != I4; | ||
76 | I2 != I3; | ||
77 | I2 != I4; | ||
78 | I3 != I4; | ||
79 | } | ||
80 | |||
81 | pattern inputsOfTurnout(T : Turnout) { | ||
82 | find adjacent(I1, T); | ||
83 | find adjacent(I2, T); | ||
84 | find adjacent(I3, T); | ||
85 | I1 != I2; | ||
86 | I1 != I3; | ||
87 | I2 != I3; | ||
88 | } | ||
89 | |||
90 | @Constraint(message = "tooFewInputsOfTurnout", severity = "error", key = { T }) | ||
91 | pattern tooFewInputsOfTurnout(T : Turnout) { | ||
92 | neg find inputsOfTurnout(T); | ||
93 | } | ||
94 | |||
95 | pattern reachable(S1 : Segment, S2 : Segment) { | ||
96 | S1 == S2; | ||
97 | } or { | ||
98 | find adjacent+(S1, S2); | ||
99 | } | ||
100 | |||
101 | @Constraint(message = "unreachable", severity = "error", key = { S1, S2 }) | ||
102 | pattern unreachable(S1 : Segment, S2 : Segment) { | ||
103 | neg find reachable(S1, S2); | ||
104 | } | ||
105 | |||
106 | // | ||
107 | // closeTrains | ||
108 | // | ||
109 | |||
110 | pattern closeTrains_step_2(in train : Train) { | ||
111 | // frame->t1 = model->trains[i0]; | ||
112 | // frame->start = frame->t1->location; | ||
113 | // if(frame->start != 0){ | ||
114 | // ... | ||
115 | // } | ||
116 | // + OUTER FOR LOOP COUNTER INCREMENT | ||
117 | Train(train); | ||
118 | } | ||
119 | |||
120 | pattern closeTrains_step_3(in train : Train, in start : Segment) { | ||
121 | // int loop_bound1 = frame->start->connected_to_count; | ||
122 | // for (int i1 = 0; i1 < loop_bound1; i1++) { LOOP COUNTER INCREMENT IS NOT INCLUDED HERE | ||
123 | // ... | ||
124 | // } | ||
125 | Train.location(train, start); | ||
126 | } | ||
127 | |||
128 | pattern closeTrains_step_4(in train : Train, in start : Segment, in middle : Segment) { | ||
129 | // frame->middle = frame->start->connected_to[i1]; | ||
130 | // int loop_bound2 = frame->middle->connected_to_count; | ||
131 | |||
132 | // for (int i2 = 0; i2 < loop_bound2; i2++) { LOOP COUNTER INCREMENT IS NOT INCLUDED HERE | ||
133 | // ... | ||
134 | // } | ||
135 | // + OUTER FOR LOOP COUNTER INCREMENT | ||
136 | Train.location(train, start); | ||
137 | Segment.connectedTo(start, middle); | ||
138 | } | ||
139 | |||
140 | pattern closeTrains_step_5(in train : Train, in start : Segment, in middle : Segment, in end : Segment) { | ||
141 | // frame->end = frame->middle->connected_to[i2]; | ||
142 | // if (frame->start != frame->end) { | ||
143 | // ... | ||
144 | // } | ||
145 | // + OUTER FOR LOOP COUNTER INCREMENT | ||
146 | Train.location(train, start); | ||
147 | Segment.connectedTo(start, middle); | ||
148 | Segment.connectedTo(middle, end); | ||
149 | } | ||
150 | |||
151 | pattern closeTrains_step_6(in train : Train, in start : Segment, in middle : Segment, in end : Segment) { | ||
152 | // frame->t2 = frame->end->train; | ||
153 | // if (frame->t2 != 0) { | ||
154 | // ... | ||
155 | // } | ||
156 | Train.location(train, start); | ||
157 | Segment.connectedTo(start, middle); | ||
158 | Segment.connectedTo(middle, end); | ||
159 | start != end; | ||
160 | } | ||
161 | |||
162 | pattern closeTrains_step_7(in train : Train, in start : Segment, in middle : Segment, in end : Segment, in otherTrain : Train) { | ||
163 | // results->matches[match_cntr].start = frame->start; | ||
164 | // results->matches[match_cntr++].end = frame->end; | ||
165 | Train.location(train, start); | ||
166 | Segment.connectedTo(start, middle); | ||
167 | Segment.connectedTo(middle, end); | ||
168 | start != end; | ||
169 | Segment.occupiedBy(end, otherTrain); | ||
170 | } | ||
171 | |||
172 | // | ||
173 | // trainLocations | ||
174 | // | ||
175 | |||
176 | pattern trainLocations_step_2(in train : Train) { | ||
177 | // frame->train = model->trains[i0]; | ||
178 | // frame->location = frame->train->location; | ||
179 | // if (frame->location != NULL) { | ||
180 | // ... | ||
181 | // } | ||
182 | |||
183 | Train(train); | ||
184 | } | ||
185 | |||
186 | pattern trainLocations_step_3(in train : Train, in location : Segment) { | ||
187 | // results->matches[match_cntr].location = frame->location; | ||
188 | // results->matches[match_cntr++].train = frame->train; | ||
189 | Train(train); | ||
190 | Train.location(train, location); | ||
191 | } | ||
192 | |||
193 | // | ||
194 | // misalignedTurnout | ||
195 | // | ||
196 | |||
197 | pattern misalignedTurnout_step_2(in turnout : Turnout) { | ||
198 | // frame->turnout = model->turnouts[i0]; | ||
199 | // frame->location = frame->turnout->straight; | ||
200 | // if (frame->location != NULL) { | ||
201 | // ... | ||
202 | // } | ||
203 | Turnout(turnout); | ||
204 | } | ||
205 | |||
206 | pattern misalignedTurnout_step_3(in turnout : Turnout, in location : Segment) { | ||
207 | // Segment *disconnected = ((Segment *)frame->turnout); | ||
208 | // if (disconnected->connected_to[0] != frame->location && | ||
209 | // disconnected->connected_to[1] != frame->location) { | ||
210 | // ... | ||
211 | // } | ||
212 | Turnout(turnout); | ||
213 | Turnout.straight(turnout, location); | ||
214 | } | ||
215 | |||
216 | pattern misalignedTurnout_step_4(in turnout : Turnout, in location : Segment) { | ||
217 | // frame->train = frame->location->train; | ||
218 | // if (frame->train != NULL) { | ||
219 | // ... | ||
220 | // } | ||
221 | Turnout(turnout); | ||
222 | Turnout.straight(turnout, location); | ||
223 | neg find connectedSegmentsDirected(turnout, location); | ||
224 | } | ||
225 | |||
226 | pattern misalignedTurnout_step_5(in turnout : Turnout, in location : Segment, in train : Train) { | ||
227 | // results->matches[match_cntr].start = frame->start; | ||
228 | // results->matches[match_cntr++].end = frame->end; | ||
229 | Turnout(turnout); | ||
230 | Turnout.straight(turnout, location); | ||
231 | neg find connectedSegmentsDirected(turnout, location); | ||
232 | Segment.occupiedBy(location, train); | ||
233 | } | ||
234 | |||
235 | pattern connectedSegmentsDirected(s1 : Segment, s2 : Segment) { | ||
236 | Segment.connectedTo(s1, s2); | ||
237 | } | ||
238 | |||
239 | // | ||
240 | // endOfSiding | ||
241 | // | ||
242 | |||
243 | pattern endOfSiding_step_2(in train : Train) { | ||
244 | // frame->train = model->trains[i0]; | ||
245 | // frame->location = frame->train->location; | ||
246 | // if (frame->location != NULL) { | ||
247 | // ... | ||
248 | // } | ||
249 | |||
250 | Train(train); | ||
251 | } | ||
252 | |||
253 | pattern endOfSiding_step_3(in train : Train, in location : Segment) { | ||
254 | // int loop_bound1 = frame->location->connected_to_count; | ||
255 | // for (int i1 = 0; i1 < loop_bound1; i1++) { | ||
256 | // ... | ||
257 | // } | ||
258 | Train(train); | ||
259 | Train.location(train, location); | ||
260 | } | ||
261 | |||
262 | pattern endOfSiding_step_4(in train : Train, in location : Segment, in end : Segment) { | ||
263 | // frame->end = frame->location->connected_to[i1]; | ||
264 | // if (frame->end != NULL && | ||
265 | // frame->end->connected_to[1] == frame->location && | ||
266 | // frame->end->connected_to[0] == NULL) { | ||
267 | // ... | ||
268 | // } | ||
269 | // if (frame->end != NULL && | ||
270 | // frame->end->connected_to[0] == frame->location && | ||
271 | // frame->end->connected_to[1] == NULL) { | ||
272 | // ... | ||
273 | // } | ||
274 | Train(train); | ||
275 | Train.location(train, location); | ||
276 | Segment.connectedTo(location, end); | ||
277 | } | ||
278 | |||
279 | pattern endOfSiding_step_5(in train : Train, in location : Segment, in end : Segment) { | ||
280 | // results->matches[match_cntr].location = frame->location; | ||
281 | // results->matches[match_cntr++].train = frame->train; | ||
282 | // ...OR... | ||
283 | // results->matches[match_cntr].location = frame->location; | ||
284 | // results->matches[match_cntr++].train = frame->train; | ||
285 | Train(train); | ||
286 | Train.location(train, location); | ||
287 | Segment.connectedTo(location, end); | ||
288 | neg find multipleConnectedTo(end); | ||
289 | } | ||
290 | |||
291 | pattern multipleConnectedTo(s : Segment) { | ||
292 | Segment.connectedTo(s, n1); | ||
293 | Segment.connectedTo(s, n2); | ||
294 | n1 != n2; | ||
295 | } | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/src/modes3/run/CloseTrainsObjectiveHint.xtend b/Domains/ca.mcgill.rtgmrt.example.modes3/src/modes3/run/CloseTrainsObjectiveHint.xtend new file mode 100644 index 00000000..519a228a --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/src/modes3/run/CloseTrainsObjectiveHint.xtend | |||
@@ -0,0 +1,201 @@ | |||
1 | package modes3.run | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic | ||
4 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace | ||
5 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type | ||
6 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.ExtendedLinearExpressionBuilderFactory | ||
7 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.CostElementMatch | ||
8 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.CostElementMatchers | ||
9 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.CostObjectiveHint | ||
10 | import java.util.Collection | ||
11 | import java.util.Map | ||
12 | import modes3.Modes3Package | ||
13 | import modes3.queries.CloseTrains_step_2 | ||
14 | import modes3.queries.CloseTrains_step_3 | ||
15 | import modes3.queries.CloseTrains_step_4 | ||
16 | import modes3.queries.CloseTrains_step_5 | ||
17 | import modes3.queries.CloseTrains_step_6 | ||
18 | import modes3.queries.CloseTrains_step_7 | ||
19 | |||
20 | class CloseTrainsObjectiveHint extends CostObjectiveHint { | ||
21 | val Type segmentType | ||
22 | val Type trainType | ||
23 | |||
24 | new(extension Ecore2Logic ecore2Logic, Ecore2Logic_Trace ecore2LogicTrace) { | ||
25 | extension val Modes3Package = Modes3Package.eINSTANCE | ||
26 | segmentType = ecore2LogicTrace.TypeofEClass(segment) | ||
27 | trainType = ecore2LogicTrace.TypeofEClass(train) | ||
28 | } | ||
29 | |||
30 | override isExact() { | ||
31 | true | ||
32 | } | ||
33 | |||
34 | override createPolyhedronExtensionOperator(Map<String, CostElementMatchers> costElementMatchers) { | ||
35 | val step2 = costElementMatchers.get(CloseTrains_step_2.instance.fullyQualifiedName) | ||
36 | val step3 = costElementMatchers.get(CloseTrains_step_3.instance.fullyQualifiedName) | ||
37 | val step4 = costElementMatchers.get(CloseTrains_step_4.instance.fullyQualifiedName) | ||
38 | val step5 = costElementMatchers.get(CloseTrains_step_5.instance.fullyQualifiedName) | ||
39 | val step6 = costElementMatchers.get(CloseTrains_step_6.instance.fullyQualifiedName) | ||
40 | val step7 = costElementMatchers.get(CloseTrains_step_7.instance.fullyQualifiedName); | ||
41 | |||
42 | [ | ||
43 | val objectiveBuilder = createBuilder | ||
44 | |||
45 | for (m : step2.matches) { | ||
46 | val dimension = getDimension(m.match) | ||
47 | objectiveBuilder.add(step2.weight, dimension) | ||
48 | dimension.tightenLowerBound(0) | ||
49 | if (m.multi) { | ||
50 | createBuilder.add(1, dimension).add(-1, trainType).build.assertEqualsTo(0) | ||
51 | } else { | ||
52 | dimension.tightenUpperBound(1) | ||
53 | if (m.must) { | ||
54 | dimension.tightenLowerBound(1) | ||
55 | } | ||
56 | } | ||
57 | } | ||
58 | |||
59 | val step3Matches = step3.matches | ||
60 | for (m : step3Matches) { | ||
61 | val dimension = getDimension(m.match) | ||
62 | objectiveBuilder.add(step3.weight, dimension) | ||
63 | dimension.tightenLowerBound(0) | ||
64 | if (!m.multi) { | ||
65 | dimension.tightenUpperBound(1) | ||
66 | if (m.must) { | ||
67 | dimension.tightenLowerBound(1) | ||
68 | } | ||
69 | } | ||
70 | } | ||
71 | for (pair : step3Matches.groupBy[step2.projectMayMatch(match, 2)].entrySet) { | ||
72 | val multiplicityBuilder = createBuilder | ||
73 | for (m : pair.value) { | ||
74 | multiplicityBuilder.add(1, m.match) | ||
75 | } | ||
76 | multiplicityBuilder.add(-1, pair.key) | ||
77 | multiplicityBuilder.build.assertEqualsTo(0) | ||
78 | } | ||
79 | boundLimit(step3Matches, 2, trainType, 1) | ||
80 | boundLimit(step3Matches, 3, segmentType, 1) | ||
81 | |||
82 | val step4Matches = step4.matches | ||
83 | for (m : step4Matches) { | ||
84 | val dimension = getDimension(m.match) | ||
85 | objectiveBuilder.add(step4.weight, dimension) | ||
86 | dimension.tightenLowerBound(0) | ||
87 | if (!m.multi) { | ||
88 | dimension.tightenUpperBound(1) | ||
89 | if (m.must) { | ||
90 | dimension.tightenLowerBound(1) | ||
91 | } | ||
92 | } | ||
93 | } | ||
94 | for (pair : step4Matches.groupBy[step3.projectMayMatch(match, 2, 3)].entrySet) { | ||
95 | val multiplicityBuilder = createBuilder | ||
96 | for (m : pair.value) { | ||
97 | multiplicityBuilder.add(1, m.match) | ||
98 | } | ||
99 | multiplicityBuilder.add(-2, pair.key) | ||
100 | multiplicityBuilder.build.tightenUpperBound(0) | ||
101 | } | ||
102 | boundLimit(step4Matches, 2, trainType, 2) | ||
103 | boundLimit(step4Matches, 3, segmentType, 2) | ||
104 | boundLimit(step4Matches, 4, segmentType, 2) | ||
105 | |||
106 | val step5Matches = step5.matches | ||
107 | for (m : step5Matches) { | ||
108 | val dimension = getDimension(m.match) | ||
109 | objectiveBuilder.add(step5.weight, dimension) | ||
110 | dimension.tightenLowerBound(0) | ||
111 | if (!m.multi) { | ||
112 | dimension.tightenUpperBound(1) | ||
113 | if (m.must) { | ||
114 | dimension.tightenLowerBound(1) | ||
115 | } | ||
116 | } | ||
117 | } | ||
118 | for (pair : step5Matches.groupBy[step4.projectMayMatch(match, 2, 3, 4)].entrySet) { | ||
119 | val multiplicityBuilder = createBuilder | ||
120 | for (m : pair.value) { | ||
121 | multiplicityBuilder.add(1, m.match) | ||
122 | } | ||
123 | multiplicityBuilder.add(-2, pair.key) | ||
124 | multiplicityBuilder.build.tightenUpperBound(0) | ||
125 | } | ||
126 | boundLimit(step5Matches, 2, trainType, 4) | ||
127 | boundLimit(step5Matches, 3, segmentType, 4) | ||
128 | boundLimit(step5Matches, 4, segmentType, 4) | ||
129 | boundLimit(step5Matches, 5, segmentType, 4) | ||
130 | |||
131 | val step6Matches = step6.matches | ||
132 | for (m : step6Matches) { | ||
133 | val dimension = getDimension(m.match) | ||
134 | objectiveBuilder.add(step6.weight, dimension) | ||
135 | dimension.tightenLowerBound(0) | ||
136 | if (m.multi) { | ||
137 | if (m.match.get(3) == m.match.get(5)) { | ||
138 | createBuilder.add(2, m.match).add(-1, step5.projectMayMatch(m.match, 2, 3, 4, 5)).build. | ||
139 | assertEqualsTo(0) | ||
140 | } else { | ||
141 | createBuilder.add(1, m.match).add(-1, step5.projectMayMatch(m.match, 2, 3, 4, 5)).build. | ||
142 | assertEqualsTo(0) | ||
143 | } | ||
144 | } else { | ||
145 | dimension.tightenUpperBound(1) | ||
146 | if (m.must) { | ||
147 | dimension.tightenLowerBound(1) | ||
148 | } | ||
149 | } | ||
150 | } | ||
151 | boundLimit(step6Matches, 2, trainType, 2) | ||
152 | boundLimit(step6Matches, 3, segmentType, 2) | ||
153 | boundLimit(step6Matches, 4, segmentType, 2) | ||
154 | boundLimit(step6Matches, 5, segmentType, 2) | ||
155 | |||
156 | val step7Matches = step7.matches | ||
157 | for (m : step7Matches) { | ||
158 | val dimension = getDimension(m.match) | ||
159 | objectiveBuilder.add(step7.weight, dimension) | ||
160 | dimension.tightenLowerBound(0) | ||
161 | if (!m.multi) { | ||
162 | dimension.tightenUpperBound(1) | ||
163 | if (m.must) { | ||
164 | dimension.tightenLowerBound(1) | ||
165 | } | ||
166 | } | ||
167 | } | ||
168 | for (pair : step7Matches.groupBy[step6.projectMayMatch(match, 2, 3, 4, 5)].entrySet) { | ||
169 | val multiplicityBuilder = createBuilder | ||
170 | for (m : pair.value) { | ||
171 | multiplicityBuilder.add(1, m.match) | ||
172 | } | ||
173 | multiplicityBuilder.add(-1, pair.key) | ||
174 | multiplicityBuilder.build.tightenUpperBound(0) | ||
175 | } | ||
176 | boundLimit(step7Matches, 2, trainType, 2) | ||
177 | boundLimit(step7Matches, 3, segmentType, 2) | ||
178 | boundLimit(step7Matches, 4, segmentType, 2) | ||
179 | boundLimit(step7Matches, 5, segmentType, 2) | ||
180 | boundLimit(step7Matches, 6, trainType, 2) | ||
181 | |||
182 | objectiveBuilder.buildWithBounds | ||
183 | ] | ||
184 | } | ||
185 | |||
186 | private static def boundLimit(extension ExtendedLinearExpressionBuilderFactory factory, | ||
187 | Collection<CostElementMatch> matches, int index, Type type, int count) { | ||
188 | for (pair : matches.groupBy[match.get(index)].entrySet) { | ||
189 | val multiplicityBuilder = createBuilder | ||
190 | for (m : pair.value) { | ||
191 | multiplicityBuilder.add(1, m.match) | ||
192 | } | ||
193 | if (CostElementMatchers.isMulti(pair.key)) { | ||
194 | multiplicityBuilder.add(-count, type) | ||
195 | multiplicityBuilder.build.tightenUpperBound(0) | ||
196 | } else { | ||
197 | multiplicityBuilder.build.tightenUpperBound(count) | ||
198 | } | ||
199 | } | ||
200 | } | ||
201 | } | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/src/modes3/run/EndOfSidingObjectiveHint.xtend b/Domains/ca.mcgill.rtgmrt.example.modes3/src/modes3/run/EndOfSidingObjectiveHint.xtend new file mode 100644 index 00000000..f7e23a57 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/src/modes3/run/EndOfSidingObjectiveHint.xtend | |||
@@ -0,0 +1,139 @@ | |||
1 | package modes3.run | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic | ||
4 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace | ||
5 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type | ||
6 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.ExtendedLinearExpressionBuilderFactory | ||
7 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.CostElementMatch | ||
8 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.CostElementMatchers | ||
9 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.CostObjectiveHint | ||
10 | import java.util.Collection | ||
11 | import java.util.Map | ||
12 | import modes3.Modes3Package | ||
13 | import modes3.queries.EndOfSiding_step_2 | ||
14 | import modes3.queries.EndOfSiding_step_3 | ||
15 | import modes3.queries.EndOfSiding_step_4 | ||
16 | import modes3.queries.EndOfSiding_step_5 | ||
17 | |||
18 | class EndOfSidingObjectiveHint extends CostObjectiveHint { | ||
19 | val Type segmentType | ||
20 | val Type trainType | ||
21 | |||
22 | new(extension Ecore2Logic ecore2Logic, Ecore2Logic_Trace ecore2LogicTrace) { | ||
23 | extension val Modes3Package = Modes3Package.eINSTANCE | ||
24 | segmentType = ecore2LogicTrace.TypeofEClass(segment) | ||
25 | trainType = ecore2LogicTrace.TypeofEClass(train) | ||
26 | } | ||
27 | |||
28 | override isExact() { | ||
29 | true | ||
30 | // false | ||
31 | } | ||
32 | |||
33 | override createPolyhedronExtensionOperator(Map<String, CostElementMatchers> costElementMatchers) { | ||
34 | val step2 = costElementMatchers.get(EndOfSiding_step_2.instance.fullyQualifiedName) | ||
35 | val step3 = costElementMatchers.get(EndOfSiding_step_3.instance.fullyQualifiedName) | ||
36 | val step4 = costElementMatchers.get(EndOfSiding_step_4.instance.fullyQualifiedName) | ||
37 | val step5 = costElementMatchers.get(EndOfSiding_step_5.instance.fullyQualifiedName); | ||
38 | |||
39 | [ | ||
40 | val objectiveBuilder = createBuilder | ||
41 | |||
42 | for (m : step2.matches) { | ||
43 | val dimension = getDimension(m.match) | ||
44 | objectiveBuilder.add(step2.weight, dimension) | ||
45 | dimension.tightenLowerBound(0) | ||
46 | if (m.multi) { | ||
47 | createBuilder.add(1, dimension).add(-1, trainType).build.assertEqualsTo(0) | ||
48 | } else { | ||
49 | dimension.tightenUpperBound(1) | ||
50 | if (m.must) { | ||
51 | dimension.tightenLowerBound(1) | ||
52 | } | ||
53 | } | ||
54 | } | ||
55 | |||
56 | val step3Matches = step3.matches | ||
57 | for (m : step3Matches) { | ||
58 | val dimension = getDimension(m.match) | ||
59 | objectiveBuilder.add(step3.weight, dimension) | ||
60 | dimension.tightenLowerBound(0) | ||
61 | if (!m.multi) { | ||
62 | dimension.tightenUpperBound(1) | ||
63 | if (m.must) { | ||
64 | dimension.tightenLowerBound(1) | ||
65 | } | ||
66 | } | ||
67 | } | ||
68 | for (pair : step3Matches.groupBy[step2.projectMayMatch(match, 2)].entrySet) { | ||
69 | val multiplicityBuilder = createBuilder | ||
70 | for (m : pair.value) { | ||
71 | multiplicityBuilder.add(1, m.match) | ||
72 | } | ||
73 | multiplicityBuilder.add(-1, pair.key) | ||
74 | multiplicityBuilder.build.assertEqualsTo(0) | ||
75 | } | ||
76 | boundLimit(step3Matches, 2, trainType, 1) | ||
77 | boundLimit(step3Matches, 3, segmentType, 1) | ||
78 | |||
79 | val step4Matches = step4.matches | ||
80 | for (m : step4Matches) { | ||
81 | val dimension = getDimension(m.match) | ||
82 | objectiveBuilder.add(step4.weight, dimension) | ||
83 | dimension.tightenLowerBound(0) | ||
84 | if (!m.multi) { | ||
85 | dimension.tightenUpperBound(1) | ||
86 | if (m.must) { | ||
87 | dimension.tightenLowerBound(1) | ||
88 | } | ||
89 | } | ||
90 | } | ||
91 | for (pair : step4Matches.groupBy[step3.projectMayMatch(match, 2, 3)].entrySet) { | ||
92 | val multiplicityBuilder = createBuilder | ||
93 | for (m : pair.value) { | ||
94 | multiplicityBuilder.add(1, m.match) | ||
95 | } | ||
96 | multiplicityBuilder.add(-2, pair.key) | ||
97 | multiplicityBuilder.build.tightenUpperBound(0) | ||
98 | } | ||
99 | boundLimit(step4Matches, 2, trainType, 2) | ||
100 | boundLimit(step4Matches, 3, segmentType, 2) | ||
101 | boundLimit(step4Matches, 4, segmentType, 2) | ||
102 | |||
103 | val step5Matches = step5.matches | ||
104 | for (m : step5Matches) { | ||
105 | val dimension = getDimension(m.match) | ||
106 | objectiveBuilder.add(step5.weight, dimension) | ||
107 | dimension.tightenLowerBound(0) | ||
108 | if (!m.multi) { | ||
109 | dimension.tightenUpperBound(1) | ||
110 | if (m.must) { | ||
111 | dimension.tightenLowerBound(1) | ||
112 | } | ||
113 | } | ||
114 | createBuilder.add(1, m.match).add(-1, step4.projectMayMatch(m.match, 2, 3, 4)).build.tightenUpperBound(0) | ||
115 | } | ||
116 | boundLimit(step5Matches, 2, trainType, 1) | ||
117 | boundLimit(step5Matches, 3, segmentType, 2) | ||
118 | boundLimit(step5Matches, 4, segmentType, 1) | ||
119 | |||
120 | objectiveBuilder.buildWithBounds | ||
121 | ] | ||
122 | } | ||
123 | |||
124 | private static def boundLimit(extension ExtendedLinearExpressionBuilderFactory factory, | ||
125 | Collection<CostElementMatch> matches, int index, Type type, int count) { | ||
126 | for (pair : matches.groupBy[match.get(index)].entrySet) { | ||
127 | val multiplicityBuilder = createBuilder | ||
128 | for (m : pair.value) { | ||
129 | multiplicityBuilder.add(1, m.match) | ||
130 | } | ||
131 | if (CostElementMatchers.isMulti(pair.key)) { | ||
132 | multiplicityBuilder.add(-count, type) | ||
133 | multiplicityBuilder.build.tightenUpperBound(0) | ||
134 | } else { | ||
135 | multiplicityBuilder.build.tightenUpperBound(count) | ||
136 | } | ||
137 | } | ||
138 | } | ||
139 | } \ No newline at end of file | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/src/modes3/run/MisalignedTurnoutObjectiveHint.xtend b/Domains/ca.mcgill.rtgmrt.example.modes3/src/modes3/run/MisalignedTurnoutObjectiveHint.xtend new file mode 100644 index 00000000..cb014dea --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/src/modes3/run/MisalignedTurnoutObjectiveHint.xtend | |||
@@ -0,0 +1,140 @@ | |||
1 | package modes3.run | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic | ||
4 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace | ||
5 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type | ||
6 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.ExtendedLinearExpressionBuilderFactory | ||
7 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.CostElementMatch | ||
8 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.CostElementMatchers | ||
9 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.CostObjectiveHint | ||
10 | import java.util.Collection | ||
11 | import java.util.Map | ||
12 | import modes3.Modes3Package | ||
13 | import modes3.queries.MisalignedTurnout_step_2 | ||
14 | import modes3.queries.MisalignedTurnout_step_3 | ||
15 | import modes3.queries.MisalignedTurnout_step_4 | ||
16 | import modes3.queries.MisalignedTurnout_step_5 | ||
17 | |||
18 | class MisalignedTurnoutObjectiveHint extends CostObjectiveHint { | ||
19 | val Type segmentType | ||
20 | val Type turnoutType | ||
21 | val Type trainType | ||
22 | |||
23 | new(extension Ecore2Logic ecore2Logic, Ecore2Logic_Trace ecore2LogicTrace) { | ||
24 | extension val Modes3Package = Modes3Package.eINSTANCE | ||
25 | segmentType = ecore2LogicTrace.TypeofEClass(segment) | ||
26 | turnoutType = ecore2LogicTrace.TypeofEClass(turnout) | ||
27 | trainType = ecore2LogicTrace.TypeofEClass(train) | ||
28 | } | ||
29 | |||
30 | override isExact() { | ||
31 | true | ||
32 | // false | ||
33 | } | ||
34 | |||
35 | override createPolyhedronExtensionOperator(Map<String, CostElementMatchers> costElementMatchers) { | ||
36 | val step2 = costElementMatchers.get(MisalignedTurnout_step_2.instance.fullyQualifiedName) | ||
37 | val step3 = costElementMatchers.get(MisalignedTurnout_step_3.instance.fullyQualifiedName) | ||
38 | val step4 = costElementMatchers.get(MisalignedTurnout_step_4.instance.fullyQualifiedName) | ||
39 | val step5 = costElementMatchers.get(MisalignedTurnout_step_5.instance.fullyQualifiedName); | ||
40 | |||
41 | [ | ||
42 | val objectiveBuilder = createBuilder | ||
43 | |||
44 | for (m : step2.matches) { | ||
45 | val dimension = getDimension(m.match) | ||
46 | objectiveBuilder.add(step2.weight, dimension) | ||
47 | dimension.tightenLowerBound(0) | ||
48 | if (m.multi) { | ||
49 | createBuilder.add(1, dimension).add(-1, turnoutType).build.assertEqualsTo(0) | ||
50 | } else { | ||
51 | dimension.tightenUpperBound(1) | ||
52 | if (m.must) { | ||
53 | dimension.tightenLowerBound(1) | ||
54 | } | ||
55 | } | ||
56 | } | ||
57 | |||
58 | val step3Matches = step3.matches | ||
59 | for (m : step3Matches) { | ||
60 | val dimension = getDimension(m.match) | ||
61 | objectiveBuilder.add(step3.weight, dimension) | ||
62 | dimension.tightenLowerBound(0) | ||
63 | if (!m.multi) { | ||
64 | dimension.tightenUpperBound(1) | ||
65 | if (m.must) { | ||
66 | dimension.tightenLowerBound(1) | ||
67 | } | ||
68 | } | ||
69 | } | ||
70 | for (pair : step3Matches.groupBy[step2.projectMayMatch(match, 2)].entrySet) { | ||
71 | val multiplicityBuilder = createBuilder | ||
72 | for (m : pair.value) { | ||
73 | multiplicityBuilder.add(1, m.match) | ||
74 | } | ||
75 | multiplicityBuilder.add(-1, pair.key) | ||
76 | multiplicityBuilder.build.tightenUpperBound(0) | ||
77 | } | ||
78 | boundLimit(step3Matches, 2, turnoutType, 1) | ||
79 | boundLimit(step3Matches, 3, segmentType, 2) | ||
80 | |||
81 | val step4Matches = step4.matches | ||
82 | for (m : step4Matches) { | ||
83 | val dimension = getDimension(m.match) | ||
84 | objectiveBuilder.add(step4.weight, dimension) | ||
85 | dimension.tightenLowerBound(0) | ||
86 | if (!m.multi) { | ||
87 | dimension.tightenUpperBound(1) | ||
88 | if (m.must) { | ||
89 | dimension.tightenLowerBound(1) | ||
90 | } | ||
91 | } | ||
92 | createBuilder.add(1, m.match).add(-1, step3.projectMayMatch(m.match, 2, 3)).build.tightenUpperBound(0) | ||
93 | } | ||
94 | boundLimit(step4Matches, 2, turnoutType, 1) | ||
95 | boundLimit(step4Matches, 3, segmentType, 2) | ||
96 | |||
97 | val step5Matches = step5.matches | ||
98 | for (m : step5Matches) { | ||
99 | val dimension = getDimension(m.match) | ||
100 | objectiveBuilder.add(step5.weight, dimension) | ||
101 | dimension.tightenLowerBound(0) | ||
102 | if (!m.multi) { | ||
103 | dimension.tightenUpperBound(1) | ||
104 | if (m.must) { | ||
105 | dimension.tightenLowerBound(1) | ||
106 | } | ||
107 | } | ||
108 | } | ||
109 | for (pair : step5Matches.groupBy[step4.projectMayMatch(match, 2, 3)].entrySet) { | ||
110 | val multiplicityBuilder = createBuilder | ||
111 | for (m : pair.value) { | ||
112 | multiplicityBuilder.add(1, m.match) | ||
113 | } | ||
114 | multiplicityBuilder.add(-1, pair.key) | ||
115 | multiplicityBuilder.build.tightenUpperBound(0) | ||
116 | } | ||
117 | boundLimit(step5Matches, 2, turnoutType, 1) | ||
118 | boundLimit(step5Matches, 3, segmentType, 2) | ||
119 | boundLimit(step5Matches, 4, trainType, 2) | ||
120 | |||
121 | objectiveBuilder.buildWithBounds | ||
122 | ] | ||
123 | } | ||
124 | |||
125 | private static def boundLimit(extension ExtendedLinearExpressionBuilderFactory factory, | ||
126 | Collection<CostElementMatch> matches, int index, Type type, int count) { | ||
127 | for (pair : matches.groupBy[match.get(index)].entrySet) { | ||
128 | val multiplicityBuilder = createBuilder | ||
129 | for (m : pair.value) { | ||
130 | multiplicityBuilder.add(1, m.match) | ||
131 | } | ||
132 | if (CostElementMatchers.isMulti(pair.key)) { | ||
133 | multiplicityBuilder.add(-count, type) | ||
134 | multiplicityBuilder.build.tightenUpperBound(0) | ||
135 | } else { | ||
136 | multiplicityBuilder.build.tightenUpperBound(count) | ||
137 | } | ||
138 | } | ||
139 | } | ||
140 | } | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/src/modes3/run/Modes3ModelGenerator.xtend b/Domains/ca.mcgill.rtgmrt.example.modes3/src/modes3/run/Modes3ModelGenerator.xtend new file mode 100644 index 00000000..288a7692 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/src/modes3/run/Modes3ModelGenerator.xtend | |||
@@ -0,0 +1,357 @@ | |||
1 | package modes3.run | ||
2 | |||
3 | import com.google.common.collect.ImmutableList | ||
4 | import com.google.common.collect.ImmutableSet | ||
5 | import hu.bme.mit.inf.dslreasoner.ecore2logic.EReferenceMapper_RelationsOverTypes_Trace | ||
6 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic | ||
7 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2LogicConfiguration | ||
8 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace | ||
9 | import hu.bme.mit.inf.dslreasoner.ecore2logic.EcoreMetamodelDescriptor | ||
10 | import hu.bme.mit.inf.dslreasoner.ecore2logic.ecore2logicannotations.Ecore2logicannotationsFactory | ||
11 | import hu.bme.mit.inf.dslreasoner.ecore2logic.ecore2logicannotations.Ecore2logicannotationsPackage | ||
12 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.DocumentationLevel | ||
13 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicProblemBuilder | ||
14 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.LogiclanguagePackage | ||
15 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TypeDefinition | ||
16 | import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicproblemPackage | ||
17 | import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.ModelResult | ||
18 | import hu.bme.mit.inf.dslreasoner.logic2ecore.Logic2Ecore | ||
19 | import hu.bme.mit.inf.dslreasoner.viatra2logic.Viatra2Logic | ||
20 | import hu.bme.mit.inf.dslreasoner.viatra2logic.Viatra2LogicConfiguration | ||
21 | import hu.bme.mit.inf.dslreasoner.viatra2logic.ViatraQuerySetDescriptor | ||
22 | import hu.bme.mit.inf.dslreasoner.viatra2logic.viatra2logicannotations.Viatra2LogicAnnotationsPackage | ||
23 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.TypeInferenceMethod | ||
24 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.PolyhedralScopePropagatorConstraints | ||
25 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.PolyhedralScopePropagatorSolver | ||
26 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.ScopePropagatorStrategy | ||
27 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic.InstanceModel2Logic | ||
28 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.BinaryElementRelationLink | ||
29 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialComplexTypeInterpretation | ||
30 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialinterpretationPackage | ||
31 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.visualisation.PartialInterpretation2Gml | ||
32 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.CostObjectiveConfiguration | ||
33 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.CostObjectiveElementConfiguration | ||
34 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.StateCoderStrategy | ||
35 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.ViatraReasoner | ||
36 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.ViatraReasonerConfiguration | ||
37 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.dse.PartialModelAsLogicInterpretation | ||
38 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.ObjectiveKind | ||
39 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.ObjectiveThreshold | ||
40 | import hu.bme.mit.inf.dslreasoner.visualisation.pi2graphviz.GraphvizVisualiser | ||
41 | import hu.bme.mit.inf.dslreasoner.workspace.FileSystemWorkspace | ||
42 | import java.util.List | ||
43 | import modes3.Modes3Factory | ||
44 | import modes3.Modes3Package | ||
45 | import modes3.queries.CloseTrains_step_2 | ||
46 | import modes3.queries.CloseTrains_step_3 | ||
47 | import modes3.queries.CloseTrains_step_4 | ||
48 | import modes3.queries.CloseTrains_step_5 | ||
49 | import modes3.queries.CloseTrains_step_6 | ||
50 | import modes3.queries.CloseTrains_step_7 | ||
51 | import modes3.queries.EndOfSiding_step_2 | ||
52 | import modes3.queries.EndOfSiding_step_3 | ||
53 | import modes3.queries.EndOfSiding_step_4 | ||
54 | import modes3.queries.EndOfSiding_step_5 | ||
55 | import modes3.queries.MisalignedTurnout_step_2 | ||
56 | import modes3.queries.MisalignedTurnout_step_3 | ||
57 | import modes3.queries.MisalignedTurnout_step_4 | ||
58 | import modes3.queries.MisalignedTurnout_step_5 | ||
59 | import modes3.queries.Modes3Queries | ||
60 | import modes3.queries.TrainLocations_step_2 | ||
61 | import modes3.queries.TrainLocations_step_3 | ||
62 | import org.eclipse.emf.ecore.EClass | ||
63 | import org.eclipse.emf.ecore.EObject | ||
64 | import org.eclipse.emf.ecore.resource.Resource | ||
65 | import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl | ||
66 | import org.eclipse.viatra.query.patternlanguage.emf.EMFPatternLanguageStandaloneSetup | ||
67 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngineOptions | ||
68 | import org.eclipse.viatra.query.runtime.localsearch.matcher.integration.LocalSearchEMFBackendFactory | ||
69 | import org.eclipse.viatra.query.runtime.rete.matcher.ReteBackendFactory | ||
70 | import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor | ||
71 | |||
72 | @FinalFieldsConstructor | ||
73 | class Modes3ModelGenerator { | ||
74 | val MonitoringQuery monitoringQuery | ||
75 | val int modelSize | ||
76 | |||
77 | val ecore2Logic = new Ecore2Logic | ||
78 | val instanceModel2Logic = new InstanceModel2Logic | ||
79 | val viatra2Logic = new Viatra2Logic(ecore2Logic) | ||
80 | val solver = new ViatraReasoner | ||
81 | extension val LogicProblemBuilder = new LogicProblemBuilder | ||
82 | |||
83 | def generate() { | ||
84 | val metamodel = createMetamodelDescriptor() | ||
85 | val metamodelLogic = ecore2Logic.transformMetamodel(metamodel, new Ecore2LogicConfiguration) | ||
86 | val segment = ecore2Logic.TypeofEClass(metamodelLogic.trace, Modes3Package.eINSTANCE.segment) | ||
87 | val connectedTo = ecore2Logic.relationOfReference(metamodelLogic.trace, | ||
88 | Modes3Package.eINSTANCE.segment_ConnectedTo) | ||
89 | val connectedToIndicator = (metamodelLogic.trace. | ||
90 | referenceMapperTrace as EReferenceMapper_RelationsOverTypes_Trace).indicators.get( | ||
91 | Modes3Package.eINSTANCE.segment_ConnectedTo) | ||
92 | val inverseAssertion = Assertion( | ||
93 | '''oppositeReference «connectedTo.name» «connectedTo.name»''', | ||
94 | Forall[ | ||
95 | val src = addVar('''src''', segment) | ||
96 | val trg = addVar('''trg''', segment) | ||
97 | connectedToIndicator.call(src, trg) <=> connectedToIndicator.call(trg, src) | ||
98 | ] | ||
99 | ) | ||
100 | metamodelLogic.output.assertions += inverseAssertion | ||
101 | val inverseAnnotation = Ecore2logicannotationsFactory.eINSTANCE.createInverseRelationAssertion => [ | ||
102 | target = inverseAssertion | ||
103 | inverseA = connectedTo | ||
104 | inverseB = connectedTo | ||
105 | ] | ||
106 | metamodelLogic.output.annotations += inverseAnnotation | ||
107 | val initialModel = loadInitialModel() | ||
108 | val initialModelLogic = instanceModel2Logic.transform(metamodelLogic, initialModel) | ||
109 | val queries = loadQueries | ||
110 | val logic = viatra2Logic.transformQueries(queries, initialModelLogic, new Viatra2LogicConfiguration) | ||
111 | val config = new ViatraReasonerConfiguration => [ | ||
112 | runtimeLimit = 3600 | ||
113 | typeScopes => [ | ||
114 | minNewElements = modelSize | ||
115 | maxNewElements = modelSize | ||
116 | minNewElementsByType => [ | ||
117 | // put(ecore2Logic.TypeofEClass(metamodelLogic.trace, Modes3Package.eINSTANCE.train), modelSize / 5) | ||
118 | // put(ecore2Logic.TypeofEClass(metamodelLogic.trace, Modes3Package.eINSTANCE.turnout), modelSize / 5) | ||
119 | // put(ecore2Logic.TypeofEClass(metamodelLogic.trace, Modes3Package.eINSTANCE.simpleSegment), 3 * modelSize / 5) | ||
120 | ] | ||
121 | maxNewElementsByType => [ | ||
122 | put(ecore2Logic.TypeofEClass(metamodelLogic.trace, Modes3Package.eINSTANCE.train), modelSize / 5) | ||
123 | put(ecore2Logic.TypeofEClass(metamodelLogic.trace, Modes3Package.eINSTANCE.turnout), modelSize / 5) | ||
124 | // put(ecore2Logic.TypeofEClass(metamodelLogic.trace, Modes3Package.eINSTANCE.simpleSegment), 3 * modelSize / 5) | ||
125 | ] | ||
126 | ] | ||
127 | solutionScope => [ | ||
128 | numberOfRequiredSolutions = 1 | ||
129 | ] | ||
130 | costObjectives += getObjective(ecore2Logic, metamodelLogic.trace) | ||
131 | scopeWeight = 6 | ||
132 | nameNewElements = false | ||
133 | typeInferenceMethod = TypeInferenceMethod.PreliminaryAnalysis | ||
134 | stateCoderStrategy = StateCoderStrategy.PairwiseNeighbourhood | ||
135 | scopePropagatorStrategy = new ScopePropagatorStrategy.Polyhedral( | ||
136 | PolyhedralScopePropagatorConstraints.Relational, PolyhedralScopePropagatorSolver.Clp) | ||
137 | hints += new Modes3TypeScopeHint(ecore2Logic, metamodelLogic.trace) | ||
138 | unitPropagationPatternGenerators += new Modes3UnitPropagationGenerator(ecore2Logic, metamodelLogic.trace) | ||
139 | debugConfiguration => [ | ||
140 | partialInterpretatioVisualiser = new GraphvizVisualiser | ||
141 | // partalInterpretationVisualisationFrequency = 50 | ||
142 | ] | ||
143 | documentationLevel = DocumentationLevel.NORMAL | ||
144 | ] | ||
145 | val workspace = new FileSystemWorkspace("output/", "") | ||
146 | workspace.writeModel(logic.output, "problem.logicproblem") | ||
147 | val solution = solver.solve(logic.output, config, workspace) | ||
148 | if (solution instanceof ModelResult) { | ||
149 | println("Saving generated solutions") | ||
150 | val logic2Ecore = new Logic2Ecore(ecore2Logic) | ||
151 | val interpretations = solver.getInterpretations(solution) | ||
152 | for (representationIndex : 0 ..< interpretations.size) { | ||
153 | val interpretation = interpretations.get(representationIndex) | ||
154 | val representationNumber = representationIndex + 1 | ||
155 | if (interpretation instanceof PartialModelAsLogicInterpretation) { | ||
156 | val representation = interpretation.partialInterpretation | ||
157 | workspace.writeModel(representation, '''solution«representationNumber».partialinterpretation''') | ||
158 | val partialInterpretation2GML = new PartialInterpretation2Gml | ||
159 | val gml = partialInterpretation2GML.transform(representation) | ||
160 | workspace.writeText('''solution«representationNumber».gml''', gml) | ||
161 | val model = logic2Ecore.transformInterpretation(interpretation, metamodelLogic.trace) | ||
162 | val iterator = model.eAllContents | ||
163 | var int id = 0 | ||
164 | while (iterator.hasNext) { | ||
165 | val obj = iterator.next | ||
166 | val idFeature = obj.eClass.EAllAttributes.findFirst[name == 'id'] | ||
167 | if (idFeature !== null) { | ||
168 | obj.eSet(idFeature, id) | ||
169 | id++ | ||
170 | } | ||
171 | } | ||
172 | workspace.writeModel(model, '''solution«representationNumber».modes3''') | ||
173 | if (representation.newElements.size < 160) { | ||
174 | val rootType = (representation.problem.types.findFirst [ | ||
175 | name == "Modes3ModelRoot class DefinedPart" | ||
176 | ] as TypeDefinition) | ||
177 | val rootIntepretation = representation.partialtypeinterpratation.filter( | ||
178 | PartialComplexTypeInterpretation).findFirst [ | ||
179 | interpretationOf.name == "Modes3ModelRoot class" | ||
180 | ] | ||
181 | rootIntepretation.elements.removeAll(rootType.elements) | ||
182 | representation.problem.elements.removeAll(rootType.elements) | ||
183 | for (relationInterpretation : representation.partialrelationinterpretation) { | ||
184 | relationInterpretation.relationlinks.removeIf [ link | | ||
185 | if (link instanceof BinaryElementRelationLink) { | ||
186 | rootType.elements.contains(link.param1) || | ||
187 | rootType.elements.contains(link.param2) | ||
188 | } else { | ||
189 | false | ||
190 | } | ||
191 | ] | ||
192 | } | ||
193 | rootType.elements.clear | ||
194 | val visualiser = new GraphvizVisualiser | ||
195 | val visualisation = visualiser.visualiseConcretization(representation) | ||
196 | visualisation.writeToFile(workspace, '''solution«representationNumber».png''') | ||
197 | } | ||
198 | } else { | ||
199 | workspace.writeText('''solution«representationNumber».txt''', interpretation.toString) | ||
200 | } | ||
201 | } | ||
202 | } else { | ||
203 | println("Failed to solve problem") | ||
204 | val partial = logic.output | ||
205 | workspace.writeModel(partial, "solution.partialinterpretation") | ||
206 | } | ||
207 | } | ||
208 | |||
209 | static def createMetamodelDescriptor() { | ||
210 | val eClasses = ImmutableList.copyOf(Modes3Package.eINSTANCE.EClassifiers.filter(EClass)) | ||
211 | new EcoreMetamodelDescriptor( | ||
212 | eClasses, | ||
213 | emptySet, | ||
214 | false, | ||
215 | emptyList, | ||
216 | emptyList, | ||
217 | ImmutableList.copyOf(eClasses.flatMap[EReferences]), | ||
218 | emptyList | ||
219 | ) | ||
220 | } | ||
221 | |||
222 | static def List<EObject> loadInitialModel() { | ||
223 | #[Modes3Factory.eINSTANCE.createModes3ModelRoot] | ||
224 | } | ||
225 | |||
226 | def loadQueries() { | ||
227 | val patternsBuilder = ImmutableList.builder | ||
228 | patternsBuilder.addAll(Modes3Queries.instance.specifications) | ||
229 | val patterns = patternsBuilder.build | ||
230 | val validationPatterns = ImmutableSet.copyOf(patterns.filter [ pattern | | ||
231 | pattern.allAnnotations.exists[name == "Constraint"] | ||
232 | ]) | ||
233 | new ViatraQuerySetDescriptor( | ||
234 | patterns, | ||
235 | validationPatterns, | ||
236 | emptyMap | ||
237 | ) | ||
238 | } | ||
239 | |||
240 | def getObjective(Ecore2Logic ecore2Logic, Ecore2Logic_Trace ecore2LogicTrace) { | ||
241 | new CostObjectiveConfiguration => [ | ||
242 | switch (monitoringQuery) { | ||
243 | case closeTrains: { | ||
244 | elements += new CostObjectiveElementConfiguration => [ | ||
245 | patternQualifiedName = CloseTrains_step_2.instance.fullyQualifiedName | ||
246 | weight = 14 + 53 + 11 | ||
247 | ] | ||
248 | elements += new CostObjectiveElementConfiguration => [ | ||
249 | patternQualifiedName = CloseTrains_step_3.instance.fullyQualifiedName | ||
250 | weight = 21 + 14 | ||
251 | ] | ||
252 | elements += new CostObjectiveElementConfiguration => [ | ||
253 | patternQualifiedName = CloseTrains_step_4.instance.fullyQualifiedName | ||
254 | weight = 14 + 44 + 14 + 9 | ||
255 | ] | ||
256 | elements += new CostObjectiveElementConfiguration => [ | ||
257 | patternQualifiedName = CloseTrains_step_5.instance.fullyQualifiedName | ||
258 | weight = 14 + 41 + 11 | ||
259 | ] | ||
260 | elements += new CostObjectiveElementConfiguration => [ | ||
261 | patternQualifiedName = CloseTrains_step_6.instance.fullyQualifiedName | ||
262 | weight = 27 | ||
263 | ] | ||
264 | elements += new CostObjectiveElementConfiguration => [ | ||
265 | patternQualifiedName = CloseTrains_step_7.instance.fullyQualifiedName | ||
266 | weight = 48 | ||
267 | ] | ||
268 | hint = new CloseTrainsObjectiveHint(ecore2Logic, ecore2LogicTrace) | ||
269 | } | ||
270 | case trainLocations: { | ||
271 | elements += new CostObjectiveElementConfiguration => [ | ||
272 | patternQualifiedName = TrainLocations_step_2.instance.fullyQualifiedName | ||
273 | weight = 14 + 53 + 11 | ||
274 | ] | ||
275 | elements += new CostObjectiveElementConfiguration => [ | ||
276 | patternQualifiedName = TrainLocations_step_3.instance.fullyQualifiedName | ||
277 | weight = 48 | ||
278 | ] | ||
279 | hint = new TrainLocationsObjectiveHint(ecore2Logic, ecore2LogicTrace) | ||
280 | } | ||
281 | case misalignedTurnout: { | ||
282 | elements += new CostObjectiveElementConfiguration => [ | ||
283 | patternQualifiedName = MisalignedTurnout_step_2.instance.fullyQualifiedName | ||
284 | weight = 14 + 53 + 11 | ||
285 | ] | ||
286 | elements += new CostObjectiveElementConfiguration => [ | ||
287 | patternQualifiedName = MisalignedTurnout_step_3.instance.fullyQualifiedName | ||
288 | weight = 108 | ||
289 | ] | ||
290 | elements += new CostObjectiveElementConfiguration => [ | ||
291 | patternQualifiedName = MisalignedTurnout_step_4.instance.fullyQualifiedName | ||
292 | weight = 27 | ||
293 | ] | ||
294 | elements += new CostObjectiveElementConfiguration => [ | ||
295 | patternQualifiedName = MisalignedTurnout_step_5.instance.fullyQualifiedName | ||
296 | weight = 48 | ||
297 | ] | ||
298 | hint = new MisalignedTurnoutObjectiveHint(ecore2Logic, ecore2LogicTrace) | ||
299 | } | ||
300 | case endOfSiding: { | ||
301 | elements += new CostObjectiveElementConfiguration => [ | ||
302 | patternQualifiedName = EndOfSiding_step_2.instance.fullyQualifiedName | ||
303 | weight = 14 + 53 + 11 | ||
304 | ] | ||
305 | elements += new CostObjectiveElementConfiguration => [ | ||
306 | patternQualifiedName = EndOfSiding_step_3.instance.fullyQualifiedName | ||
307 | weight = 21 + 14 | ||
308 | ] | ||
309 | elements += new CostObjectiveElementConfiguration => [ | ||
310 | patternQualifiedName = EndOfSiding_step_4.instance.fullyQualifiedName | ||
311 | weight = 14 + 35 + 21 + 15 + 14 + 21 + 15 + 11 | ||
312 | ] | ||
313 | elements += new CostObjectiveElementConfiguration => [ | ||
314 | patternQualifiedName = EndOfSiding_step_5.instance.fullyQualifiedName | ||
315 | weight = 48 | ||
316 | ] | ||
317 | hint = new EndOfSidingObjectiveHint(ecore2Logic, ecore2LogicTrace) | ||
318 | } | ||
319 | default: | ||
320 | throw new IllegalArgumentException("Unknown monitoring query: " + monitoringQuery) | ||
321 | } | ||
322 | kind = ObjectiveKind.HIGHER_IS_BETTER | ||
323 | threshold = ObjectiveThreshold.NO_THRESHOLD | ||
324 | findExtremum = true | ||
325 | ] | ||
326 | } | ||
327 | |||
328 | def static init() { | ||
329 | EMFPatternLanguageStandaloneSetup.doSetup | ||
330 | ViatraQueryEngineOptions.setSystemDefaultBackends(ReteBackendFactory.INSTANCE, ReteBackendFactory.INSTANCE, | ||
331 | LocalSearchEMFBackendFactory.INSTANCE) | ||
332 | LogiclanguagePackage.eINSTANCE.class | ||
333 | LogicproblemPackage.eINSTANCE.class | ||
334 | PartialinterpretationPackage.eINSTANCE.class | ||
335 | Ecore2logicannotationsPackage.eINSTANCE.class | ||
336 | Viatra2LogicAnnotationsPackage.eINSTANCE.class | ||
337 | Resource.Factory.Registry.INSTANCE.extensionToFactoryMap.put("*", new XMIResourceFactoryImpl) | ||
338 | } | ||
339 | |||
340 | def static void main(String[] args) { | ||
341 | if (args.length != 2) { | ||
342 | System.err.println("Usage: <query> <model size>") | ||
343 | } | ||
344 | val monitoringQuery = MonitoringQuery.valueOf(args.get(0)) | ||
345 | val modelSize = Integer.parseInt(args.get(1)) | ||
346 | init() | ||
347 | val generator = new Modes3ModelGenerator(monitoringQuery, modelSize) | ||
348 | generator.generate() | ||
349 | } | ||
350 | |||
351 | private static enum MonitoringQuery { | ||
352 | closeTrains, | ||
353 | trainLocations, | ||
354 | endOfSiding, | ||
355 | misalignedTurnout | ||
356 | } | ||
357 | } | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/src/modes3/run/Modes3TypeScopeHint.xtend b/Domains/ca.mcgill.rtgmrt.example.modes3/src/modes3/run/Modes3TypeScopeHint.xtend new file mode 100644 index 00000000..94e5eb08 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/src/modes3/run/Modes3TypeScopeHint.xtend | |||
@@ -0,0 +1,79 @@ | |||
1 | package modes3.run | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic | ||
4 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace | ||
5 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type | ||
6 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.Modality | ||
7 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.LinearTypeConstraintHint | ||
8 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.LinearTypeExpressionBuilderFactory | ||
9 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.patterns.PatternGenerator | ||
10 | import java.util.Map | ||
11 | import modes3.Modes3Package | ||
12 | import modes3.queries.Adjacent | ||
13 | import org.eclipse.viatra.query.runtime.api.IPatternMatch | ||
14 | import org.eclipse.viatra.query.runtime.api.ViatraQueryMatcher | ||
15 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PQuery | ||
16 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation | ||
17 | |||
18 | class Modes3TypeScopeHint implements LinearTypeConstraintHint { | ||
19 | static val TURNOUT_NEIGHBOR_COUNT = "turnoutNeighborCount" | ||
20 | |||
21 | val Type segmentType | ||
22 | val Type turnoutType | ||
23 | |||
24 | new(extension Ecore2Logic ecore2Logic, Ecore2Logic_Trace ecore2LogicTrace) { | ||
25 | extension val Modes3Package = Modes3Package.eINSTANCE | ||
26 | segmentType = ecore2LogicTrace.TypeofEClass(segment) | ||
27 | turnoutType = ecore2LogicTrace.TypeofEClass(turnout) | ||
28 | } | ||
29 | |||
30 | override getAdditionalPatterns(extension PatternGenerator patternGenerator, Map<String, PQuery> fqnToPQuery) { | ||
31 | ''' | ||
32 | pattern «TURNOUT_NEIGHBOR_COUNT»_helper(problem: LogicProblem, interpretation: PartialInterpretation, source: DefinedElement, target: DefinedElement) { | ||
33 | find interpretation(problem, interpretation); | ||
34 | find mustExist(problem, interpretation, source); | ||
35 | find mustExist(problem, interpretation, target); | ||
36 | «typeIndexer.referInstanceOf(turnoutType, Modality.MUST, "source")» | ||
37 | «typeIndexer.referInstanceOf(segmentType, Modality.MUST, "target")» | ||
38 | «relationDefinitionIndexer.referPattern(fqnToPQuery.get(Adjacent.instance.fullyQualifiedName), #["source", "target"], Modality.MUST, true, false)» | ||
39 | } | ||
40 | |||
41 | pattern «TURNOUT_NEIGHBOR_COUNT»(problem: LogicProblem, interpretation: PartialInterpretation, element: DefinedElement, N) { | ||
42 | find interpretation(problem, interpretation); | ||
43 | find mustExist(problem, interpretation, element); | ||
44 | «typeIndexer.referInstanceOf(turnoutType, Modality.MUST, "element")» | ||
45 | N == count find «TURNOUT_NEIGHBOR_COUNT»_helper(problem, interpretation, element, _); | ||
46 | } | ||
47 | ''' | ||
48 | } | ||
49 | |||
50 | override createConstraintUpdater(LinearTypeExpressionBuilderFactory builderFactory) { | ||
51 | val turnoutNeighborCountMatcher = builderFactory.createMatcher(TURNOUT_NEIGHBOR_COUNT) | ||
52 | val newNeighbors = builderFactory.createBuilder.add(1, segmentType).build | ||
53 | |||
54 | return [ partialInterpretation | | ||
55 | val requiredNeighbbors = turnoutNeighborCountMatcher.getRemainingCount(partialInterpretation, 3) | ||
56 | newNeighbors.tightenLowerBound(requiredNeighbbors) | ||
57 | ] | ||
58 | } | ||
59 | |||
60 | private static def <T extends IPatternMatch> getRemainingCount(ViatraQueryMatcher<T> matcher, | ||
61 | PartialInterpretation partialInterpretation, int capacity) { | ||
62 | val partialMatch = matcher.newEmptyMatch | ||
63 | partialMatch.set(0, partialInterpretation.problem) | ||
64 | partialMatch.set(1, partialInterpretation) | ||
65 | val iterator = matcher.streamAllMatches(partialMatch).iterator | ||
66 | var int max = 0 | ||
67 | while (iterator.hasNext) { | ||
68 | val match = iterator.next | ||
69 | val n = (match.get(3) as Integer).intValue | ||
70 | if (n < capacity) { | ||
71 | val required = capacity - n | ||
72 | if (max < required) { | ||
73 | max = required | ||
74 | } | ||
75 | } | ||
76 | } | ||
77 | max | ||
78 | } | ||
79 | } | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/src/modes3/run/Modes3UnitPropagationGenerator.xtend b/Domains/ca.mcgill.rtgmrt.example.modes3/src/modes3/run/Modes3UnitPropagationGenerator.xtend new file mode 100644 index 00000000..953a21d4 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/src/modes3/run/Modes3UnitPropagationGenerator.xtend | |||
@@ -0,0 +1,417 @@ | |||
1 | package modes3.run | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic | ||
4 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace | ||
5 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Relation | ||
6 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type | ||
7 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.Modality | ||
8 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.patterns.PatternGenerator | ||
9 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.patterns.UnitPropagationPatternGenerator | ||
10 | import java.util.Map | ||
11 | import modes3.Modes3Package | ||
12 | import modes3.queries.Adjacent | ||
13 | import modes3.queries.Output | ||
14 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PQuery | ||
15 | import org.eclipse.xtend2.lib.StringConcatenationClient | ||
16 | |||
17 | class Modes3UnitPropagationGenerator implements UnitPropagationPatternGenerator { | ||
18 | static val MUST_NOT_CONNECTED_TO = "mustNotConnectedTo" | ||
19 | static val MUST_NOT_STRAIGHT = "mustNotStraight" | ||
20 | static val MUST_NOT_DIVERGENT = "mustNotDivergent" | ||
21 | static val MUST_CONNECTED_TO = "mustConnectedTo" | ||
22 | static val MUST_STRAIGHT = "mustStraight" | ||
23 | static val MUST_DIVERGENT = "mustDivergent" | ||
24 | |||
25 | val Type segmentType | ||
26 | val Type simpleSegmentType | ||
27 | val Type turnoutType | ||
28 | val Relation connectedToRelation | ||
29 | val Relation straightRelation | ||
30 | val Relation divergentRelation | ||
31 | |||
32 | new(extension Ecore2Logic ecore2Logic, Ecore2Logic_Trace ecore2LogicTrace) { | ||
33 | extension val Modes3Package = Modes3Package.eINSTANCE | ||
34 | segmentType = ecore2LogicTrace.TypeofEClass(segment) | ||
35 | simpleSegmentType = ecore2LogicTrace.TypeofEClass(simpleSegment) | ||
36 | turnoutType = ecore2LogicTrace.TypeofEClass(turnout) | ||
37 | connectedToRelation = ecore2LogicTrace.relationOfReference(segment_ConnectedTo) | ||
38 | straightRelation = ecore2LogicTrace.relationOfReference(turnout_Straight) | ||
39 | divergentRelation = ecore2LogicTrace.relationOfReference(turnout_Divergent) | ||
40 | } | ||
41 | |||
42 | override getMustPatterns() { | ||
43 | #{ | ||
44 | connectedToRelation -> MUST_CONNECTED_TO, | ||
45 | straightRelation -> MUST_STRAIGHT, | ||
46 | divergentRelation -> MUST_DIVERGENT | ||
47 | } | ||
48 | } | ||
49 | |||
50 | override getMustNotPatterns() { | ||
51 | #{ | ||
52 | connectedToRelation -> MUST_NOT_CONNECTED_TO, | ||
53 | straightRelation -> MUST_NOT_STRAIGHT, | ||
54 | divergentRelation -> MUST_NOT_DIVERGENT | ||
55 | } | ||
56 | } | ||
57 | |||
58 | override getAdditionalPatterns(extension PatternGenerator generator, Map<String, PQuery> fqnToPQuery) { | ||
59 | val StringConcatenationClient parameters = ''' | ||
60 | problem: LogicProblem, interpretation: PartialInterpretation, | ||
61 | source: DefinedElement, target: DefinedElement | ||
62 | ''' | ||
63 | |||
64 | val StringConcatenationClient commonMustParameterConstraints = ''' | ||
65 | find interpretation(problem, interpretation); | ||
66 | find mustExist(problem, interpretation, source); | ||
67 | find mustExist(problem, interpretation, target); | ||
68 | ''' | ||
69 | |||
70 | val StringConcatenationClient commonMayParameterConstraints = ''' | ||
71 | find interpretation(problem, interpretation); | ||
72 | find mayExist(problem, interpretation, source); | ||
73 | find mayExist(problem, interpretation, target); | ||
74 | ''' | ||
75 | |||
76 | ''' | ||
77 | pattern mayInput(«parameters») { | ||
78 | «commonMayParameterConstraints» | ||
79 | «typeIndexer.referInstanceOf(segmentType, Modality.MAY, "target")» | ||
80 | «relationDefinitionIndexer.referPattern(fqnToPQuery.get(Adjacent.instance.fullyQualifiedName), #["target", "source"], Modality.MAY, true, false)» | ||
81 | neg «referRelation(straightRelation, "target", "source", Modality.MUST, fqnToPQuery)» | ||
82 | neg «referRelation(straightRelation, "target", "source", Modality.MUST, fqnToPQuery)» | ||
83 | } | ||
84 | |||
85 | pattern multipleMayInput(problem: LogicProblem, interpretation: PartialInterpretation, | ||
86 | target: DefinedElement) { | ||
87 | find interpretation(problem, interpretation); | ||
88 | find mustExist(problem, interpretation, target); | ||
89 | find mayInput(problem, interpretaton, source1, target); | ||
90 | find mayInput(problem, interpretaton, source2, target); | ||
91 | neg find mustEquivalent(problem, interpretation, source1, source2); | ||
92 | } | ||
93 | |||
94 | pattern multipleMayStraight(problem: LogicProblem, interpretation: PartialInterpretation, | ||
95 | source: DefinedElement) { | ||
96 | find interpretation(problem, interpretation); | ||
97 | find mustExist(problem, interpretation, source); | ||
98 | «typeIndexer.referInstanceOf(turnoutType, Modality.MAY, "source")» | ||
99 | «referRelation(straightRelation, "source", "target1", Modality.MAY, fqnToPQuery)» | ||
100 | «referRelation(straightRelation, "source", "target2", Modality.MAY, fqnToPQuery)» | ||
101 | neg find mustEquivalent(problem, interpretation, target1, target2); | ||
102 | } | ||
103 | |||
104 | pattern multipleMayDivergent(problem: LogicProblem, interpretation: PartialInterpretation, | ||
105 | source: DefinedElement) { | ||
106 | find interpretation(problem, interpretation); | ||
107 | find mustExist(problem, interpretation, source); | ||
108 | «typeIndexer.referInstanceOf(turnoutType, Modality.MAY, "source")» | ||
109 | «referRelation(divergentRelation, "source", "target1", Modality.MAY, fqnToPQuery)» | ||
110 | «referRelation(divergentRelation, "source", "target2", Modality.MAY, fqnToPQuery)» | ||
111 | neg find mustEquivalent(problem, interpretation, target1, target2); | ||
112 | } | ||
113 | |||
114 | pattern «MUST_CONNECTED_TO»(«parameters») { | ||
115 | «commonMustParameterConstraints» | ||
116 | «typeIndexer.referInstanceOf(segmentType, Modality.MAY, "target")» | ||
117 | find mayInput(problem, interpretaton, source, target); | ||
118 | neg find multipleMayInput(problem, interpretaton, target); | ||
119 | «referRelation(connectedToRelation, "source", "target", Modality.MAY, fqnToPQuery)» | ||
120 | neg «referRelation(connectedToRelation, "source", "target", Modality.MUST, fqnToPQuery)» | ||
121 | neg «referRelation(straightRelation, "source", "target", Modality.MAY, fqnToPQuery)» | ||
122 | neg «referRelation(divergentRelation, "source", "target", Modality.MAY, fqnToPQuery)» | ||
123 | } | ||
124 | |||
125 | pattern «MUST_STRAIGHT»(«parameters») { | ||
126 | «commonMustParameterConstraints» | ||
127 | neg «referRelation(straightRelation, "source", "_", Modality.MUST, fqnToPQuery)» | ||
128 | neg find multipleMayStraight(problem, interpretation, source); | ||
129 | «referRelation(straightRelation, "source", "target", Modality.MAY, fqnToPQuery)» | ||
130 | neg «referRelation(straightRelation, "source", "target", Modality.MUST, fqnToPQuery)» | ||
131 | } or { | ||
132 | «commonMustParameterConstraints» | ||
133 | «typeIndexer.referInstanceOf(segmentType, Modality.MAY, "target")» | ||
134 | find mayInput(problem, interpretaton, source, target); | ||
135 | neg find multipleMayInput(problem, interpretaton, target); | ||
136 | neg «referRelation(connectedToRelation, "source", "target", Modality.MAY, fqnToPQuery)» | ||
137 | «referRelation(straightRelation, "source", "target", Modality.MAY, fqnToPQuery)» | ||
138 | neg «referRelation(straightRelation, "source", "target", Modality.MUST, fqnToPQuery)» | ||
139 | neg «referRelation(divergentRelation, "source", "target", Modality.MAY, fqnToPQuery)» | ||
140 | } | ||
141 | |||
142 | pattern «MUST_DIVERGENT»(«parameters») { | ||
143 | «commonMustParameterConstraints» | ||
144 | neg «referRelation(divergentRelation, "source", "_", Modality.MUST, fqnToPQuery)» | ||
145 | neg find multipleMayDivergent(problem, interpretation, source); | ||
146 | «referRelation(divergentRelation, "source", "target", Modality.MAY, fqnToPQuery)» | ||
147 | neg «referRelation(divergentRelation, "source", "target", Modality.MUST, fqnToPQuery)» | ||
148 | } or { | ||
149 | «commonMustParameterConstraints» | ||
150 | «typeIndexer.referInstanceOf(segmentType, Modality.MAY, "target")» | ||
151 | find mayInput(problem, interpretaton, source, target); | ||
152 | neg find multipleMayInput(problem, interpretaton, target); | ||
153 | neg «referRelation(connectedToRelation, "source", "target", Modality.MAY, fqnToPQuery)» | ||
154 | neg «referRelation(straightRelation, "source", "target", Modality.MAY, fqnToPQuery)» | ||
155 | «referRelation(divergentRelation, "source", "target", Modality.MAY, fqnToPQuery)» | ||
156 | neg «referRelation(divergentRelation, "source", "target", Modality.MUST, fqnToPQuery)» | ||
157 | } | ||
158 | |||
159 | pattern turnoutOutput_must_to_true_by_straight(«parameters», T : DefinedElement, S : DefinedElement) { | ||
160 | «commonMayParameterConstraints» | ||
161 | «typeIndexer.referInstanceOf(turnoutType, Modality.MAY, "source")» | ||
162 | «typeIndexer.referInstanceOf(segmentType, Modality.MAY, "target")» | ||
163 | T == source; | ||
164 | S == target; | ||
165 | } | ||
166 | |||
167 | pattern turnoutOutput_must_to_true_by_divergent(«parameters», T : DefinedElement, S : DefinedElement) { | ||
168 | «commonMayParameterConstraints» | ||
169 | «typeIndexer.referInstanceOf(turnoutType, Modality.MAY, "source")» | ||
170 | «typeIndexer.referInstanceOf(segmentType, Modality.MAY, "target")» | ||
171 | T == source; | ||
172 | S == target; | ||
173 | } | ||
174 | |||
175 | pattern output_must_to_true_by_connectedTo(«parameters», S1 : DefinedElement, S2 : DefinedElement) { | ||
176 | «commonMayParameterConstraints» | ||
177 | «typeIndexer.referInstanceOf(segmentType, Modality.MAY, "source")» | ||
178 | «typeIndexer.referInstanceOf(segmentType, Modality.MAY, "target")» | ||
179 | S1 == source; | ||
180 | S2 == target; | ||
181 | } | ||
182 | |||
183 | pattern output_must_to_true_by_straight(«parameters», S1 : DefinedElement, S2 : DefinedElement) { | ||
184 | find turnoutOutput_must_to_true_by_straight(problem, interpretation, source, target, S1, S2); | ||
185 | } | ||
186 | |||
187 | pattern output_must_to_true_by_divergent(«parameters», S1 : DefinedElement, S2 : DefinedElement) { | ||
188 | find turnoutOutput_must_to_true_by_divergent(problem, interpretation, source, target, S1, S2); | ||
189 | } | ||
190 | |||
191 | pattern adjacent_must_to_true_by_connectedTo(«parameters», S1 : DefinedElement, S2 : DefinedElement) { | ||
192 | find output_must_to_true_by_connectedTo(problem, interpretation, source, target, S1, S2); | ||
193 | } | ||
194 | |||
195 | pattern adjacent_must_to_true_by_straight(«parameters», S1 : DefinedElement, S2 : DefinedElement) { | ||
196 | find output_must_to_true_by_straight(problem, interpretation, source, target, S1, S2); | ||
197 | } or { | ||
198 | find turnoutOutput_must_to_true_by_straight(problem, interpretation, source, target, S2, S1); | ||
199 | } | ||
200 | |||
201 | pattern adjacent_must_to_true_by_divergent(«parameters», S1 : DefinedElement, S2 : DefinedElement) { | ||
202 | find output_must_to_true_by_divergent(problem, interpretation, source, target, S1, S2); | ||
203 | } or { | ||
204 | find turnoutOutput_must_to_true_by_divergent(problem, interpretation, source, target, S2, S1); | ||
205 | } | ||
206 | |||
207 | pattern connectedToReflexive_must_to_true_by_connectedTo(«parameters», S : DefinedElement) { | ||
208 | find mustExist(problem, interpretation, source); | ||
209 | «typeIndexer.referInstanceOf(segmentType, Modality.MUST, "source")» | ||
210 | S == source; | ||
211 | S == target; | ||
212 | } | ||
213 | |||
214 | pattern outputReflexive_must_to_true_by_straight(«parameters», T : DefinedElement) { | ||
215 | find turnoutOutput_must_to_true_by_straight(problem, interpretation, source, target, T, T); | ||
216 | } | ||
217 | |||
218 | pattern outputReflexive_must_to_true_by_divergent(«parameters», T : DefinedElement) { | ||
219 | find turnoutOutput_must_to_true_by_divergent(problem, interpretation, source, target, T, T); | ||
220 | } | ||
221 | |||
222 | pattern turnoutOutputsAreSame_must_to_true_by_straight(«parameters», T : DefinedElement) { | ||
223 | «commonMayParameterConstraints» | ||
224 | «typeIndexer.referInstanceOf(turnoutType, Modality.MAY, "source")» | ||
225 | «typeIndexer.referInstanceOf(segmentType, Modality.MAY, "target")» | ||
226 | T == source; | ||
227 | S == target; | ||
228 | «referRelation(divergentRelation, "T", "S", Modality.MUST, fqnToPQuery)» | ||
229 | } | ||
230 | |||
231 | pattern turnoutOutputsAreSame_must_to_true_by_divergent(«parameters», T : DefinedElement) { | ||
232 | «commonMayParameterConstraints» | ||
233 | «typeIndexer.referInstanceOf(turnoutType, Modality.MAY, "source")» | ||
234 | «typeIndexer.referInstanceOf(segmentType, Modality.MAY, "target")» | ||
235 | T == source; | ||
236 | S == target; | ||
237 | «referRelation(straightRelation, "T", "S", Modality.MUST, fqnToPQuery)» | ||
238 | } | ||
239 | |||
240 | pattern tooManyInputsOfSegment_must_to_true_by_connectedTo(«parameters», S : DefinedElement) { | ||
241 | find mustExist(problem, interpretation, S); | ||
242 | «typeIndexer.referInstanceOf(simpleSegmentType, Modality.MUST, "S")» | ||
243 | find output_must_to_true_by_connectedTo(problem, interpretation, source, target, I1, S); | ||
244 | «relationDefinitionIndexer.referPattern(fqnToPQuery.get(Output.instance.fullyQualifiedName), #["I2", "S"], Modality.MUST, true, false)» | ||
245 | «relationDefinitionIndexer.referPattern(fqnToPQuery.get(Output.instance.fullyQualifiedName), #["I3", "S"], Modality.MUST, true, false)» | ||
246 | I1 != I2; | ||
247 | I1 != I3; | ||
248 | I2 != I3; | ||
249 | } | ||
250 | |||
251 | pattern tooManyInputsOfSegment_must_to_true_by_straight(«parameters», S : DefinedElement) { | ||
252 | find mustExist(problem, interpretation, S); | ||
253 | «typeIndexer.referInstanceOf(simpleSegmentType, Modality.MUST, "S")» | ||
254 | find output_must_to_true_by_straight(problem, interpretation, source, target, I1, S); | ||
255 | «relationDefinitionIndexer.referPattern(fqnToPQuery.get(Output.instance.fullyQualifiedName), #["I2", "S"], Modality.MUST, true, false)» | ||
256 | «relationDefinitionIndexer.referPattern(fqnToPQuery.get(Output.instance.fullyQualifiedName), #["I3", "S"], Modality.MUST, true, false)» | ||
257 | I1 != I2; | ||
258 | I1 != I3; | ||
259 | I2 != I3; | ||
260 | } | ||
261 | |||
262 | pattern tooManyInputsOfSegment_must_to_true_by_divergent(«parameters», S : DefinedElement) { | ||
263 | find mustExist(problem, interpretation, S); | ||
264 | «typeIndexer.referInstanceOf(simpleSegmentType, Modality.MUST, "S")» | ||
265 | find output_must_to_true_by_divergent(problem, interpretation, source, target, I1, S); | ||
266 | «relationDefinitionIndexer.referPattern(fqnToPQuery.get(Output.instance.fullyQualifiedName), #["I2", "S"], Modality.MUST, true, false)» | ||
267 | «relationDefinitionIndexer.referPattern(fqnToPQuery.get(Output.instance.fullyQualifiedName), #["I3", "S"], Modality.MUST, true, false)» | ||
268 | I1 != I2; | ||
269 | I1 != I3; | ||
270 | I2 != I3; | ||
271 | } | ||
272 | |||
273 | pattern turnoutConnectedToBothOutputs_must_to_true_by_connectedTo(«parameters», T : DefinedElement) { | ||
274 | «commonMayParameterConstraints» | ||
275 | find mustExist(problem, interpretation, Straight); | ||
276 | find mustExist(problem, interpretation, Divergent); | ||
277 | «typeIndexer.referInstanceOf(turnoutType, Modality.MAY, "source")» | ||
278 | «typeIndexer.referInstanceOf(segmentType, Modality.MAY, "target")» | ||
279 | «typeIndexer.referInstanceOf(segmentType, Modality.MUST, "Straight")» | ||
280 | «typeIndexer.referInstanceOf(segmentType, Modality.MUST, "Divergent")» | ||
281 | «referRelation(straightRelation, "T", "Straight", Modality.MUST, fqnToPQuery)» | ||
282 | «referRelation(divergentRelation, "T", "Divergent", Modality.MUST, fqnToPQuery)» | ||
283 | T == source; | ||
284 | Straight == target; | ||
285 | «referRelation(connectedToRelation, "T", "Divergent", Modality.MUST, fqnToPQuery)» | ||
286 | } or { | ||
287 | «commonMayParameterConstraints» | ||
288 | find mustExist(problem, interpretation, Straight); | ||
289 | find mustExist(problem, interpretation, Divergent); | ||
290 | «typeIndexer.referInstanceOf(turnoutType, Modality.MAY, "source")» | ||
291 | «typeIndexer.referInstanceOf(segmentType, Modality.MAY, "target")» | ||
292 | «typeIndexer.referInstanceOf(segmentType, Modality.MUST, "Straight")» | ||
293 | «typeIndexer.referInstanceOf(segmentType, Modality.MUST, "Divergent")» | ||
294 | «referRelation(straightRelation, "T", "Straight", Modality.MUST, fqnToPQuery)» | ||
295 | «referRelation(divergentRelation, "T", "Divergent", Modality.MUST, fqnToPQuery)» | ||
296 | «referRelation(connectedToRelation, "T", "Straight", Modality.MUST, fqnToPQuery)» | ||
297 | T == source; | ||
298 | Straight == target; | ||
299 | } | ||
300 | |||
301 | pattern turnoutConnectedToBothOutputs_must_to_true_by_straight(«parameters», T : DefinedElement) { | ||
302 | «commonMayParameterConstraints» | ||
303 | find mustExist(problem, interpretation, Straight); | ||
304 | find mustExist(problem, interpretation, Divergent); | ||
305 | «typeIndexer.referInstanceOf(turnoutType, Modality.MAY, "source")» | ||
306 | «typeIndexer.referInstanceOf(segmentType, Modality.MAY, "target")» | ||
307 | «typeIndexer.referInstanceOf(segmentType, Modality.MUST, "Straight")» | ||
308 | «typeIndexer.referInstanceOf(segmentType, Modality.MUST, "Divergent")» | ||
309 | T == source; | ||
310 | Straight == target; | ||
311 | «referRelation(divergentRelation, "T", "Divergent", Modality.MUST, fqnToPQuery)» | ||
312 | «referRelation(connectedToRelation, "T", "Straight", Modality.MUST, fqnToPQuery)» | ||
313 | «referRelation(connectedToRelation, "T", "Divergent", Modality.MUST, fqnToPQuery)» | ||
314 | } | ||
315 | |||
316 | pattern turnoutConnectedToBothOutputs_must_to_true_by_divergent(«parameters», T : DefinedElement) { | ||
317 | «commonMayParameterConstraints» | ||
318 | find mustExist(problem, interpretation, Straight); | ||
319 | find mustExist(problem, interpretation, Divergent); | ||
320 | «typeIndexer.referInstanceOf(turnoutType, Modality.MAY, "source")» | ||
321 | «typeIndexer.referInstanceOf(segmentType, Modality.MAY, "target")» | ||
322 | «typeIndexer.referInstanceOf(segmentType, Modality.MUST, "Straight")» | ||
323 | «typeIndexer.referInstanceOf(segmentType, Modality.MUST, "Divergent")» | ||
324 | «referRelation(straightRelation, "T", "Straight", Modality.MUST, fqnToPQuery)» | ||
325 | T == source; | ||
326 | Divergent == target; | ||
327 | «referRelation(connectedToRelation, "T", "Straight", Modality.MUST, fqnToPQuery)» | ||
328 | «referRelation(connectedToRelation, "T", "Divergent", Modality.MUST, fqnToPQuery)» | ||
329 | } | ||
330 | |||
331 | pattern tooManyInputsOfTurnout_must_to_true_by_connectedTo(«parameters», T : DefinedElement) { | ||
332 | find mustExist(problem, interpretation, S); | ||
333 | «typeIndexer.referInstanceOf(turnoutType, Modality.MUST, "S")» | ||
334 | find adjacent_must_to_true_by_connectedTo(problem, interpretation, source, target, I1, S); | ||
335 | «relationDefinitionIndexer.referPattern(fqnToPQuery.get(Adjacent.instance.fullyQualifiedName), #["I2", "S"], Modality.MUST, true, false)» | ||
336 | «relationDefinitionIndexer.referPattern(fqnToPQuery.get(Adjacent.instance.fullyQualifiedName), #["I3", "S"], Modality.MUST, true, false)» | ||
337 | «relationDefinitionIndexer.referPattern(fqnToPQuery.get(Adjacent.instance.fullyQualifiedName), #["I4", "S"], Modality.MUST, true, false)» | ||
338 | I1 != I2; | ||
339 | I1 != I3; | ||
340 | I1 != I4; | ||
341 | I2 != I3; | ||
342 | I2 != I4; | ||
343 | I3 != I4; | ||
344 | } | ||
345 | |||
346 | pattern tooManyInputsOfTurnout_must_to_true_by_straight(«parameters», T : DefinedElement) { | ||
347 | find mustExist(problem, interpretation, S); | ||
348 | «typeIndexer.referInstanceOf(turnoutType, Modality.MUST, "S")» | ||
349 | find adjacent_must_to_true_by_straight(problem, interpretation, source, target, I1, S); | ||
350 | «relationDefinitionIndexer.referPattern(fqnToPQuery.get(Adjacent.instance.fullyQualifiedName), #["I2", "S"], Modality.MUST, true, false)» | ||
351 | «relationDefinitionIndexer.referPattern(fqnToPQuery.get(Adjacent.instance.fullyQualifiedName), #["I3", "S"], Modality.MUST, true, false)» | ||
352 | «relationDefinitionIndexer.referPattern(fqnToPQuery.get(Adjacent.instance.fullyQualifiedName), #["I4", "S"], Modality.MUST, true, false)» | ||
353 | I1 != I2; | ||
354 | I1 != I3; | ||
355 | I1 != I4; | ||
356 | I2 != I3; | ||
357 | I2 != I4; | ||
358 | I3 != I4; | ||
359 | } | ||
360 | |||
361 | pattern tooManyInputsOfTurnout_must_to_true_by_divergent(«parameters», T : DefinedElement) { | ||
362 | find mustExist(problem, interpretation, S); | ||
363 | «typeIndexer.referInstanceOf(turnoutType, Modality.MUST, "S")» | ||
364 | find adjacent_must_to_true_by_divergent(problem, interpretation, source, target, I1, S); | ||
365 | «relationDefinitionIndexer.referPattern(fqnToPQuery.get(Adjacent.instance.fullyQualifiedName), #["I2", "S"], Modality.MUST, true, false)» | ||
366 | «relationDefinitionIndexer.referPattern(fqnToPQuery.get(Adjacent.instance.fullyQualifiedName), #["I3", "S"], Modality.MUST, true, false)» | ||
367 | «relationDefinitionIndexer.referPattern(fqnToPQuery.get(Adjacent.instance.fullyQualifiedName), #["I4", "S"], Modality.MUST, true, false)» | ||
368 | I1 != I2; | ||
369 | I1 != I3; | ||
370 | I1 != I4; | ||
371 | I2 != I3; | ||
372 | I2 != I4; | ||
373 | I3 != I4; | ||
374 | } | ||
375 | |||
376 | pattern «MUST_NOT_CONNECTED_TO»_helper(«parameters») { | ||
377 | find connectedToReflexive_must_to_true_by_connectedTo(problem, interpretation, source, target, _); | ||
378 | } or { | ||
379 | find tooManyInputsOfSegment_must_to_true_by_connectedTo(problem, interpretation, source, target, _); | ||
380 | } or { | ||
381 | find turnoutConnectedToBothOutputs_must_to_true_by_connectedTo(problem, interpretation, source, target, _); | ||
382 | } or { | ||
383 | find tooManyInputsOfTurnout_must_to_true_by_connectedTo(problem, interpretation, source, target, _); | ||
384 | } | ||
385 | |||
386 | pattern «MUST_NOT_CONNECTED_TO»(«parameters») { | ||
387 | find «MUST_NOT_CONNECTED_TO»_helper(problem, interpretation, source, target); | ||
388 | } or { | ||
389 | find «MUST_NOT_CONNECTED_TO»_helper(problem, interpretation, target, source); | ||
390 | } | ||
391 | |||
392 | pattern «MUST_NOT_STRAIGHT»(«parameters») { | ||
393 | find outputReflexive_must_to_true_by_straight(problem, interpretation, source, target, _); | ||
394 | } or { | ||
395 | find turnoutOutputsAreSame_must_to_true_by_straight(problem, interpretation, source, target, _); | ||
396 | } or { | ||
397 | find tooManyInputsOfSegment_must_to_true_by_straight(problem, interpretation, source, target, _); | ||
398 | } or { | ||
399 | find turnoutConnectedToBothOutputs_must_to_true_by_straight(problem, interpretation, source, target, _); | ||
400 | } or { | ||
401 | find tooManyInputsOfTurnout_must_to_true_by_straight(problem, interpretation, source, target, _); | ||
402 | } | ||
403 | |||
404 | pattern «MUST_NOT_DIVERGENT»(«parameters») { | ||
405 | find outputReflexive_must_to_true_by_divergent(problem, interpretation, source, target, _); | ||
406 | } or { | ||
407 | find turnoutOutputsAreSame_must_to_true_by_divergent(problem, interpretation, source, target, _); | ||
408 | } or { | ||
409 | find tooManyInputsOfSegment_must_to_true_by_divergent(problem, interpretation, source, target, _); | ||
410 | } or { | ||
411 | find turnoutConnectedToBothOutputs_must_to_true_by_divergent(problem, interpretation, source, target, _); | ||
412 | } or { | ||
413 | find tooManyInputsOfTurnout_must_to_true_by_divergent(problem, interpretation, source, target, _); | ||
414 | } | ||
415 | ''' | ||
416 | } | ||
417 | } | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/src/modes3/run/TrainLocationsObjectiveHint.xtend b/Domains/ca.mcgill.rtgmrt.example.modes3/src/modes3/run/TrainLocationsObjectiveHint.xtend new file mode 100644 index 00000000..cc2d7925 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/src/modes3/run/TrainLocationsObjectiveHint.xtend | |||
@@ -0,0 +1,85 @@ | |||
1 | package modes3.run | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic | ||
4 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace | ||
5 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type | ||
6 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.ExtendedLinearExpressionBuilderFactory | ||
7 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.CostElementMatch | ||
8 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.CostElementMatchers | ||
9 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.CostObjectiveHint | ||
10 | import java.util.Collection | ||
11 | import java.util.Map | ||
12 | import modes3.Modes3Package | ||
13 | import modes3.queries.TrainLocations_step_2 | ||
14 | import modes3.queries.TrainLocations_step_3 | ||
15 | |||
16 | class TrainLocationsObjectiveHint extends CostObjectiveHint { | ||
17 | val Type segmentType | ||
18 | val Type trainType | ||
19 | |||
20 | new(extension Ecore2Logic ecore2Logic, Ecore2Logic_Trace ecore2LogicTrace) { | ||
21 | extension val Modes3Package = Modes3Package.eINSTANCE | ||
22 | segmentType = ecore2LogicTrace.TypeofEClass(segment) | ||
23 | trainType = ecore2LogicTrace.TypeofEClass(train) | ||
24 | } | ||
25 | |||
26 | override isExact() { | ||
27 | true | ||
28 | } | ||
29 | |||
30 | override createPolyhedronExtensionOperator(Map<String, CostElementMatchers> costElementMatchers) { | ||
31 | val step2 = costElementMatchers.get(TrainLocations_step_2.instance.fullyQualifiedName) | ||
32 | val step3 = costElementMatchers.get(TrainLocations_step_3.instance.fullyQualifiedName); | ||
33 | |||
34 | [ | ||
35 | val objectiveBuilder = createBuilder | ||
36 | |||
37 | for (m : step2.matches) { | ||
38 | val dimension = getDimension(m.match) | ||
39 | objectiveBuilder.add(step2.weight, dimension) | ||
40 | dimension.tightenLowerBound(0) | ||
41 | if (m.multi) { | ||
42 | createBuilder.add(1, dimension).add(-1, trainType).build.assertEqualsTo(0) | ||
43 | } else { | ||
44 | dimension.tightenUpperBound(1) | ||
45 | if (m.must) { | ||
46 | dimension.tightenLowerBound(1) | ||
47 | } | ||
48 | } | ||
49 | } | ||
50 | |||
51 | val step3Matches = step3.matches | ||
52 | for (m : step3Matches) { | ||
53 | val dimension = getDimension(m.match) | ||
54 | objectiveBuilder.add(step3.weight, dimension) | ||
55 | dimension.tightenLowerBound(0) | ||
56 | if (!m.multi) { | ||
57 | dimension.tightenUpperBound(1) | ||
58 | if (m.must) { | ||
59 | dimension.tightenLowerBound(1) | ||
60 | } | ||
61 | } | ||
62 | } | ||
63 | boundLimit(step3Matches, 2, trainType, 1) | ||
64 | boundLimit(step3Matches, 3, segmentType, 1) | ||
65 | |||
66 | objectiveBuilder.buildWithBounds | ||
67 | ] | ||
68 | } | ||
69 | |||
70 | private static def boundLimit(extension ExtendedLinearExpressionBuilderFactory factory, | ||
71 | Collection<CostElementMatch> matches, int index, Type type, int count) { | ||
72 | for (pair : matches.groupBy[match.get(index)].entrySet) { | ||
73 | val multiplicityBuilder = createBuilder | ||
74 | for (m : pair.value) { | ||
75 | multiplicityBuilder.add(1, m.match) | ||
76 | } | ||
77 | if (CostElementMatchers.isMulti(pair.key)) { | ||
78 | multiplicityBuilder.add(-count, type) | ||
79 | multiplicityBuilder.build.tightenUpperBound(0) | ||
80 | } else { | ||
81 | multiplicityBuilder.build.tightenUpperBound(count) | ||
82 | } | ||
83 | } | ||
84 | } | ||
85 | } \ No newline at end of file | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/.gitignore b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/.gitignore new file mode 100644 index 00000000..a84c2906 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/.gitignore | |||
@@ -0,0 +1,78 @@ | |||
1 | /.ConnectedToReflexive.java._trace | ||
2 | /.Modes3Queries.java._trace | ||
3 | /.StraightReflexive.java._trace | ||
4 | /.DivergentReflexive.java._trace | ||
5 | /.TurnoutOutputsAreSame.java._trace | ||
6 | /.Adjacent.java._trace | ||
7 | /.Output.java._trace | ||
8 | /.OutputReflexive.java._trace | ||
9 | /.TooManyAdjacentSegmentsOfSegment.java._trace | ||
10 | /.Turnout.java._trace | ||
11 | /.ConnectedTo.java._trace | ||
12 | /.TurnoutNotConnectedToOutput.java._trace | ||
13 | /.DisjointNetwork.java._trace | ||
14 | /.Reachable.java._trace | ||
15 | /.Unreachable.java._trace | ||
16 | /.TurnoutInSegments.java._trace | ||
17 | /.ConnectedToNotSymmetric.java._trace | ||
18 | /.TurnoutConnectedToBothOutputs.java._trace | ||
19 | /.TooManyAdjacentTurnouts.java._trace | ||
20 | /.NoAdjacentSegmentOfSegment.java._trace | ||
21 | /.TurnoutOutput.java._trace | ||
22 | /.NoInputOfSegment.java._trace | ||
23 | /.TooManyInputsOfSegment.java._trace | ||
24 | /.ExtraInputOfTurnout.java._trace | ||
25 | /.NoExtraInputOfTurnout.java._trace | ||
26 | /.TooManyExtraInputsOfTurnout.java._trace | ||
27 | /.TooManyInputsOfTurnout.java._trace | ||
28 | /.NonDivergentInputOfTurnout.java._trace | ||
29 | /.NonStraightInputOfTurnout.java._trace | ||
30 | /.TooManyNonDivergentInputsOfTurnout.java._trace | ||
31 | /.TooManyNonStraightInputsOfTurnout.java._trace | ||
32 | /.InputsOfTurnout.java._trace | ||
33 | /.TooFewInputsOfTurnout.java._trace | ||
34 | /.CloseTrains_step_2.java._trace | ||
35 | /.CloseTrains_step_3.java._trace | ||
36 | /.CloseTrains_step_4.java._trace | ||
37 | /.CloseTrains_step_5.java._trace | ||
38 | /.CloseTrains_step_6.java._trace | ||
39 | /.CloseTrains_step_7.java._trace | ||
40 | /.MisalignedTurnout_step_2.java._trace | ||
41 | /.MisalignedTurnout_step_3.java._trace | ||
42 | /.MisalignedTurnout_step_4.java._trace | ||
43 | /.MisalignedTurnout_step_5.java._trace | ||
44 | /.ConnectedSegmentsDirected.java._trace | ||
45 | /Adjacent.java | ||
46 | /CloseTrains_step_2.java | ||
47 | /CloseTrains_step_3.java | ||
48 | /CloseTrains_step_4.java | ||
49 | /CloseTrains_step_5.java | ||
50 | /CloseTrains_step_6.java | ||
51 | /CloseTrains_step_7.java | ||
52 | /ConnectedSegmentsDirected.java | ||
53 | /ConnectedTo.java | ||
54 | /ConnectedToNotSymmetric.java | ||
55 | /ConnectedToReflexive.java | ||
56 | /InputsOfTurnout.java | ||
57 | /MisalignedTurnout_step_2.java | ||
58 | /MisalignedTurnout_step_3.java | ||
59 | /MisalignedTurnout_step_4.java | ||
60 | /MisalignedTurnout_step_5.java | ||
61 | /Modes3Queries.java | ||
62 | /Output.java | ||
63 | /OutputReflexive.java | ||
64 | /Reachable.java | ||
65 | /TooFewInputsOfTurnout.java | ||
66 | /TooManyInputsOfSegment.java | ||
67 | /TooManyInputsOfTurnout.java | ||
68 | /TurnoutConnectedToBothOutputs.java | ||
69 | /TurnoutOutput.java | ||
70 | /TurnoutOutputsAreSame.java | ||
71 | /Unreachable.java | ||
72 | /.TrainLocations_step_2.java._trace | ||
73 | /.TrainLocations_step_3.java._trace | ||
74 | /.EndOfSiding_step_2.java._trace | ||
75 | /.EndOfSiding_step_3.java._trace | ||
76 | /.EndOfSiding_step_4.java._trace | ||
77 | /.EndOfSiding_step_5.java._trace | ||
78 | /.MultipleConnectedTo.java._trace | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/Adjacent.java b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/Adjacent.java new file mode 100644 index 00000000..e87f9c18 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/Adjacent.java | |||
@@ -0,0 +1,719 @@ | |||
1 | /** | ||
2 | * Generated from platform:/resource/ca.mcgill.rtgmrt.example.modes3/src/modes3/queries/Modes3Queries.vql | ||
3 | */ | ||
4 | package modes3.queries; | ||
5 | |||
6 | import java.util.Arrays; | ||
7 | import java.util.Collection; | ||
8 | import java.util.LinkedHashSet; | ||
9 | import java.util.List; | ||
10 | import java.util.Objects; | ||
11 | import java.util.Optional; | ||
12 | import java.util.Set; | ||
13 | import java.util.function.Consumer; | ||
14 | import java.util.stream.Collectors; | ||
15 | import java.util.stream.Stream; | ||
16 | import modes3.Segment; | ||
17 | import modes3.queries.Output; | ||
18 | import modes3.queries.TurnoutOutput; | ||
19 | import org.apache.log4j.Logger; | ||
20 | import org.eclipse.emf.ecore.EClass; | ||
21 | import org.eclipse.viatra.query.runtime.api.IPatternMatch; | ||
22 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification; | ||
23 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; | ||
24 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; | ||
25 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; | ||
26 | import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; | ||
27 | import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; | ||
28 | import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; | ||
29 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
30 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | ||
31 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | ||
32 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
33 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall; | ||
34 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
35 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | ||
36 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; | ||
37 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | ||
38 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; | ||
39 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
40 | import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; | ||
41 | |||
42 | /** | ||
43 | * A pattern-specific query specification that can instantiate Matcher in a type-safe way. | ||
44 | * | ||
45 | * <p>Original source: | ||
46 | * <code><pre> | ||
47 | * pattern adjacent(S1 : Segment, S2 : Segment) { | ||
48 | * find output(S1, S2); | ||
49 | * } or { | ||
50 | * find turnoutOutput(S2, S1); | ||
51 | * } | ||
52 | * </pre></code> | ||
53 | * | ||
54 | * @see Matcher | ||
55 | * @see Match | ||
56 | * | ||
57 | */ | ||
58 | @SuppressWarnings("all") | ||
59 | public final class Adjacent extends BaseGeneratedEMFQuerySpecification<Adjacent.Matcher> { | ||
60 | /** | ||
61 | * Pattern-specific match representation of the modes3.queries.adjacent pattern, | ||
62 | * to be used in conjunction with {@link Matcher}. | ||
63 | * | ||
64 | * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. | ||
65 | * Each instance is a (possibly partial) substitution of pattern parameters, | ||
66 | * usable to represent a match of the pattern in the result of a query, | ||
67 | * or to specify the bound (fixed) input parameters when issuing a query. | ||
68 | * | ||
69 | * @see Matcher | ||
70 | * | ||
71 | */ | ||
72 | public static abstract class Match extends BasePatternMatch { | ||
73 | private Segment fS1; | ||
74 | |||
75 | private Segment fS2; | ||
76 | |||
77 | private static List<String> parameterNames = makeImmutableList("S1", "S2"); | ||
78 | |||
79 | private Match(final Segment pS1, final Segment pS2) { | ||
80 | this.fS1 = pS1; | ||
81 | this.fS2 = pS2; | ||
82 | } | ||
83 | |||
84 | @Override | ||
85 | public Object get(final String parameterName) { | ||
86 | switch(parameterName) { | ||
87 | case "S1": return this.fS1; | ||
88 | case "S2": return this.fS2; | ||
89 | default: return null; | ||
90 | } | ||
91 | } | ||
92 | |||
93 | @Override | ||
94 | public Object get(final int index) { | ||
95 | switch(index) { | ||
96 | case 0: return this.fS1; | ||
97 | case 1: return this.fS2; | ||
98 | default: return null; | ||
99 | } | ||
100 | } | ||
101 | |||
102 | public Segment getS1() { | ||
103 | return this.fS1; | ||
104 | } | ||
105 | |||
106 | public Segment getS2() { | ||
107 | return this.fS2; | ||
108 | } | ||
109 | |||
110 | @Override | ||
111 | public boolean set(final String parameterName, final Object newValue) { | ||
112 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
113 | if ("S1".equals(parameterName) ) { | ||
114 | this.fS1 = (Segment) newValue; | ||
115 | return true; | ||
116 | } | ||
117 | if ("S2".equals(parameterName) ) { | ||
118 | this.fS2 = (Segment) newValue; | ||
119 | return true; | ||
120 | } | ||
121 | return false; | ||
122 | } | ||
123 | |||
124 | public void setS1(final Segment pS1) { | ||
125 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
126 | this.fS1 = pS1; | ||
127 | } | ||
128 | |||
129 | public void setS2(final Segment pS2) { | ||
130 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
131 | this.fS2 = pS2; | ||
132 | } | ||
133 | |||
134 | @Override | ||
135 | public String patternName() { | ||
136 | return "modes3.queries.adjacent"; | ||
137 | } | ||
138 | |||
139 | @Override | ||
140 | public List<String> parameterNames() { | ||
141 | return Adjacent.Match.parameterNames; | ||
142 | } | ||
143 | |||
144 | @Override | ||
145 | public Object[] toArray() { | ||
146 | return new Object[]{fS1, fS2}; | ||
147 | } | ||
148 | |||
149 | @Override | ||
150 | public Adjacent.Match toImmutable() { | ||
151 | return isMutable() ? newMatch(fS1, fS2) : this; | ||
152 | } | ||
153 | |||
154 | @Override | ||
155 | public String prettyPrint() { | ||
156 | StringBuilder result = new StringBuilder(); | ||
157 | result.append("\"S1\"=" + prettyPrintValue(fS1) + ", "); | ||
158 | result.append("\"S2\"=" + prettyPrintValue(fS2)); | ||
159 | return result.toString(); | ||
160 | } | ||
161 | |||
162 | @Override | ||
163 | public int hashCode() { | ||
164 | return Objects.hash(fS1, fS2); | ||
165 | } | ||
166 | |||
167 | @Override | ||
168 | public boolean equals(final Object obj) { | ||
169 | if (this == obj) | ||
170 | return true; | ||
171 | if (obj == null) { | ||
172 | return false; | ||
173 | } | ||
174 | if ((obj instanceof Adjacent.Match)) { | ||
175 | Adjacent.Match other = (Adjacent.Match) obj; | ||
176 | return Objects.equals(fS1, other.fS1) && Objects.equals(fS2, other.fS2); | ||
177 | } else { | ||
178 | // this should be infrequent | ||
179 | if (!(obj instanceof IPatternMatch)) { | ||
180 | return false; | ||
181 | } | ||
182 | IPatternMatch otherSig = (IPatternMatch) obj; | ||
183 | return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); | ||
184 | } | ||
185 | } | ||
186 | |||
187 | @Override | ||
188 | public Adjacent specification() { | ||
189 | return Adjacent.instance(); | ||
190 | } | ||
191 | |||
192 | /** | ||
193 | * Returns an empty, mutable match. | ||
194 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
195 | * | ||
196 | * @return the empty match. | ||
197 | * | ||
198 | */ | ||
199 | public static Adjacent.Match newEmptyMatch() { | ||
200 | return new Mutable(null, null); | ||
201 | } | ||
202 | |||
203 | /** | ||
204 | * Returns a mutable (partial) match. | ||
205 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
206 | * | ||
207 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
208 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
209 | * @return the new, mutable (partial) match object. | ||
210 | * | ||
211 | */ | ||
212 | public static Adjacent.Match newMutableMatch(final Segment pS1, final Segment pS2) { | ||
213 | return new Mutable(pS1, pS2); | ||
214 | } | ||
215 | |||
216 | /** | ||
217 | * Returns a new (partial) match. | ||
218 | * This can be used e.g. to call the matcher with a partial match. | ||
219 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
220 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
221 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
222 | * @return the (partial) match object. | ||
223 | * | ||
224 | */ | ||
225 | public static Adjacent.Match newMatch(final Segment pS1, final Segment pS2) { | ||
226 | return new Immutable(pS1, pS2); | ||
227 | } | ||
228 | |||
229 | private static final class Mutable extends Adjacent.Match { | ||
230 | Mutable(final Segment pS1, final Segment pS2) { | ||
231 | super(pS1, pS2); | ||
232 | } | ||
233 | |||
234 | @Override | ||
235 | public boolean isMutable() { | ||
236 | return true; | ||
237 | } | ||
238 | } | ||
239 | |||
240 | private static final class Immutable extends Adjacent.Match { | ||
241 | Immutable(final Segment pS1, final Segment pS2) { | ||
242 | super(pS1, pS2); | ||
243 | } | ||
244 | |||
245 | @Override | ||
246 | public boolean isMutable() { | ||
247 | return false; | ||
248 | } | ||
249 | } | ||
250 | } | ||
251 | |||
252 | /** | ||
253 | * Generated pattern matcher API of the modes3.queries.adjacent pattern, | ||
254 | * providing pattern-specific query methods. | ||
255 | * | ||
256 | * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, | ||
257 | * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. | ||
258 | * | ||
259 | * <p>Matches of the pattern will be represented as {@link Match}. | ||
260 | * | ||
261 | * <p>Original source: | ||
262 | * <code><pre> | ||
263 | * pattern adjacent(S1 : Segment, S2 : Segment) { | ||
264 | * find output(S1, S2); | ||
265 | * } or { | ||
266 | * find turnoutOutput(S2, S1); | ||
267 | * } | ||
268 | * </pre></code> | ||
269 | * | ||
270 | * @see Match | ||
271 | * @see Adjacent | ||
272 | * | ||
273 | */ | ||
274 | public static class Matcher extends BaseMatcher<Adjacent.Match> { | ||
275 | /** | ||
276 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
277 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
278 | * | ||
279 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
280 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
281 | * | ||
282 | */ | ||
283 | public static Adjacent.Matcher on(final ViatraQueryEngine engine) { | ||
284 | // check if matcher already exists | ||
285 | Matcher matcher = engine.getExistingMatcher(querySpecification()); | ||
286 | if (matcher == null) { | ||
287 | matcher = (Matcher)engine.getMatcher(querySpecification()); | ||
288 | } | ||
289 | return matcher; | ||
290 | } | ||
291 | |||
292 | /** | ||
293 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
294 | * @return an initialized matcher | ||
295 | * @noreference This method is for internal matcher initialization by the framework, do not call it manually. | ||
296 | * | ||
297 | */ | ||
298 | public static Adjacent.Matcher create() { | ||
299 | return new Matcher(); | ||
300 | } | ||
301 | |||
302 | private static final int POSITION_S1 = 0; | ||
303 | |||
304 | private static final int POSITION_S2 = 1; | ||
305 | |||
306 | private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Adjacent.Matcher.class); | ||
307 | |||
308 | /** | ||
309 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
310 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
311 | * | ||
312 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
313 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
314 | * | ||
315 | */ | ||
316 | private Matcher() { | ||
317 | super(querySpecification()); | ||
318 | } | ||
319 | |||
320 | /** | ||
321 | * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. | ||
322 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
323 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
324 | * @return matches represented as a Match object. | ||
325 | * | ||
326 | */ | ||
327 | public Collection<Adjacent.Match> getAllMatches(final Segment pS1, final Segment pS2) { | ||
328 | return rawStreamAllMatches(new Object[]{pS1, pS2}).collect(Collectors.toSet()); | ||
329 | } | ||
330 | |||
331 | /** | ||
332 | * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. | ||
333 | * </p> | ||
334 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
335 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
336 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
337 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
338 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
339 | * @return a stream of matches represented as a Match object. | ||
340 | * | ||
341 | */ | ||
342 | public Stream<Adjacent.Match> streamAllMatches(final Segment pS1, final Segment pS2) { | ||
343 | return rawStreamAllMatches(new Object[]{pS1, pS2}); | ||
344 | } | ||
345 | |||
346 | /** | ||
347 | * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
348 | * Neither determinism nor randomness of selection is guaranteed. | ||
349 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
350 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
351 | * @return a match represented as a Match object, or null if no match is found. | ||
352 | * | ||
353 | */ | ||
354 | public Optional<Adjacent.Match> getOneArbitraryMatch(final Segment pS1, final Segment pS2) { | ||
355 | return rawGetOneArbitraryMatch(new Object[]{pS1, pS2}); | ||
356 | } | ||
357 | |||
358 | /** | ||
359 | * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, | ||
360 | * under any possible substitution of the unspecified parameters (if any). | ||
361 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
362 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
363 | * @return true if the input is a valid (partial) match of the pattern. | ||
364 | * | ||
365 | */ | ||
366 | public boolean hasMatch(final Segment pS1, final Segment pS2) { | ||
367 | return rawHasMatch(new Object[]{pS1, pS2}); | ||
368 | } | ||
369 | |||
370 | /** | ||
371 | * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. | ||
372 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
373 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
374 | * @return the number of pattern matches found. | ||
375 | * | ||
376 | */ | ||
377 | public int countMatches(final Segment pS1, final Segment pS2) { | ||
378 | return rawCountMatches(new Object[]{pS1, pS2}); | ||
379 | } | ||
380 | |||
381 | /** | ||
382 | * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
383 | * Neither determinism nor randomness of selection is guaranteed. | ||
384 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
385 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
386 | * @param processor the action that will process the selected match. | ||
387 | * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked | ||
388 | * | ||
389 | */ | ||
390 | public boolean forOneArbitraryMatch(final Segment pS1, final Segment pS2, final Consumer<? super Adjacent.Match> processor) { | ||
391 | return rawForOneArbitraryMatch(new Object[]{pS1, pS2}, processor); | ||
392 | } | ||
393 | |||
394 | /** | ||
395 | * Returns a new (partial) match. | ||
396 | * This can be used e.g. to call the matcher with a partial match. | ||
397 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
398 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
399 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
400 | * @return the (partial) match object. | ||
401 | * | ||
402 | */ | ||
403 | public Adjacent.Match newMatch(final Segment pS1, final Segment pS2) { | ||
404 | return Adjacent.Match.newMatch(pS1, pS2); | ||
405 | } | ||
406 | |||
407 | /** | ||
408 | * Retrieve the set of values that occur in matches for S1. | ||
409 | * @return the Set of all values or empty set if there are no matches | ||
410 | * | ||
411 | */ | ||
412 | protected Stream<Segment> rawStreamAllValuesOfS1(final Object[] parameters) { | ||
413 | return rawStreamAllValues(POSITION_S1, parameters).map(Segment.class::cast); | ||
414 | } | ||
415 | |||
416 | /** | ||
417 | * Retrieve the set of values that occur in matches for S1. | ||
418 | * @return the Set of all values or empty set if there are no matches | ||
419 | * | ||
420 | */ | ||
421 | public Set<Segment> getAllValuesOfS1() { | ||
422 | return rawStreamAllValuesOfS1(emptyArray()).collect(Collectors.toSet()); | ||
423 | } | ||
424 | |||
425 | /** | ||
426 | * Retrieve the set of values that occur in matches for S1. | ||
427 | * @return the Set of all values or empty set if there are no matches | ||
428 | * | ||
429 | */ | ||
430 | public Stream<Segment> streamAllValuesOfS1() { | ||
431 | return rawStreamAllValuesOfS1(emptyArray()); | ||
432 | } | ||
433 | |||
434 | /** | ||
435 | * Retrieve the set of values that occur in matches for S1. | ||
436 | * </p> | ||
437 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
438 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
439 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
440 | * | ||
441 | * @return the Stream of all values or empty set if there are no matches | ||
442 | * | ||
443 | */ | ||
444 | public Stream<Segment> streamAllValuesOfS1(final Adjacent.Match partialMatch) { | ||
445 | return rawStreamAllValuesOfS1(partialMatch.toArray()); | ||
446 | } | ||
447 | |||
448 | /** | ||
449 | * Retrieve the set of values that occur in matches for S1. | ||
450 | * </p> | ||
451 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
452 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
453 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
454 | * | ||
455 | * @return the Stream of all values or empty set if there are no matches | ||
456 | * | ||
457 | */ | ||
458 | public Stream<Segment> streamAllValuesOfS1(final Segment pS2) { | ||
459 | return rawStreamAllValuesOfS1(new Object[]{null, pS2}); | ||
460 | } | ||
461 | |||
462 | /** | ||
463 | * Retrieve the set of values that occur in matches for S1. | ||
464 | * @return the Set of all values or empty set if there are no matches | ||
465 | * | ||
466 | */ | ||
467 | public Set<Segment> getAllValuesOfS1(final Adjacent.Match partialMatch) { | ||
468 | return rawStreamAllValuesOfS1(partialMatch.toArray()).collect(Collectors.toSet()); | ||
469 | } | ||
470 | |||
471 | /** | ||
472 | * Retrieve the set of values that occur in matches for S1. | ||
473 | * @return the Set of all values or empty set if there are no matches | ||
474 | * | ||
475 | */ | ||
476 | public Set<Segment> getAllValuesOfS1(final Segment pS2) { | ||
477 | return rawStreamAllValuesOfS1(new Object[]{null, pS2}).collect(Collectors.toSet()); | ||
478 | } | ||
479 | |||
480 | /** | ||
481 | * Retrieve the set of values that occur in matches for S2. | ||
482 | * @return the Set of all values or empty set if there are no matches | ||
483 | * | ||
484 | */ | ||
485 | protected Stream<Segment> rawStreamAllValuesOfS2(final Object[] parameters) { | ||
486 | return rawStreamAllValues(POSITION_S2, parameters).map(Segment.class::cast); | ||
487 | } | ||
488 | |||
489 | /** | ||
490 | * Retrieve the set of values that occur in matches for S2. | ||
491 | * @return the Set of all values or empty set if there are no matches | ||
492 | * | ||
493 | */ | ||
494 | public Set<Segment> getAllValuesOfS2() { | ||
495 | return rawStreamAllValuesOfS2(emptyArray()).collect(Collectors.toSet()); | ||
496 | } | ||
497 | |||
498 | /** | ||
499 | * Retrieve the set of values that occur in matches for S2. | ||
500 | * @return the Set of all values or empty set if there are no matches | ||
501 | * | ||
502 | */ | ||
503 | public Stream<Segment> streamAllValuesOfS2() { | ||
504 | return rawStreamAllValuesOfS2(emptyArray()); | ||
505 | } | ||
506 | |||
507 | /** | ||
508 | * Retrieve the set of values that occur in matches for S2. | ||
509 | * </p> | ||
510 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
511 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
512 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
513 | * | ||
514 | * @return the Stream of all values or empty set if there are no matches | ||
515 | * | ||
516 | */ | ||
517 | public Stream<Segment> streamAllValuesOfS2(final Adjacent.Match partialMatch) { | ||
518 | return rawStreamAllValuesOfS2(partialMatch.toArray()); | ||
519 | } | ||
520 | |||
521 | /** | ||
522 | * Retrieve the set of values that occur in matches for S2. | ||
523 | * </p> | ||
524 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
525 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
526 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
527 | * | ||
528 | * @return the Stream of all values or empty set if there are no matches | ||
529 | * | ||
530 | */ | ||
531 | public Stream<Segment> streamAllValuesOfS2(final Segment pS1) { | ||
532 | return rawStreamAllValuesOfS2(new Object[]{pS1, null}); | ||
533 | } | ||
534 | |||
535 | /** | ||
536 | * Retrieve the set of values that occur in matches for S2. | ||
537 | * @return the Set of all values or empty set if there are no matches | ||
538 | * | ||
539 | */ | ||
540 | public Set<Segment> getAllValuesOfS2(final Adjacent.Match partialMatch) { | ||
541 | return rawStreamAllValuesOfS2(partialMatch.toArray()).collect(Collectors.toSet()); | ||
542 | } | ||
543 | |||
544 | /** | ||
545 | * Retrieve the set of values that occur in matches for S2. | ||
546 | * @return the Set of all values or empty set if there are no matches | ||
547 | * | ||
548 | */ | ||
549 | public Set<Segment> getAllValuesOfS2(final Segment pS1) { | ||
550 | return rawStreamAllValuesOfS2(new Object[]{pS1, null}).collect(Collectors.toSet()); | ||
551 | } | ||
552 | |||
553 | @Override | ||
554 | protected Adjacent.Match tupleToMatch(final Tuple t) { | ||
555 | try { | ||
556 | return Adjacent.Match.newMatch((Segment) t.get(POSITION_S1), (Segment) t.get(POSITION_S2)); | ||
557 | } catch(ClassCastException e) { | ||
558 | LOGGER.error("Element(s) in tuple not properly typed!",e); | ||
559 | return null; | ||
560 | } | ||
561 | } | ||
562 | |||
563 | @Override | ||
564 | protected Adjacent.Match arrayToMatch(final Object[] match) { | ||
565 | try { | ||
566 | return Adjacent.Match.newMatch((Segment) match[POSITION_S1], (Segment) match[POSITION_S2]); | ||
567 | } catch(ClassCastException e) { | ||
568 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
569 | return null; | ||
570 | } | ||
571 | } | ||
572 | |||
573 | @Override | ||
574 | protected Adjacent.Match arrayToMatchMutable(final Object[] match) { | ||
575 | try { | ||
576 | return Adjacent.Match.newMutableMatch((Segment) match[POSITION_S1], (Segment) match[POSITION_S2]); | ||
577 | } catch(ClassCastException e) { | ||
578 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
579 | return null; | ||
580 | } | ||
581 | } | ||
582 | |||
583 | /** | ||
584 | * @return the singleton instance of the query specification of this pattern | ||
585 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
586 | * | ||
587 | */ | ||
588 | public static IQuerySpecification<Adjacent.Matcher> querySpecification() { | ||
589 | return Adjacent.instance(); | ||
590 | } | ||
591 | } | ||
592 | |||
593 | private Adjacent() { | ||
594 | super(GeneratedPQuery.INSTANCE); | ||
595 | } | ||
596 | |||
597 | /** | ||
598 | * @return the singleton instance of the query specification | ||
599 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
600 | * | ||
601 | */ | ||
602 | public static Adjacent instance() { | ||
603 | try{ | ||
604 | return LazyHolder.INSTANCE; | ||
605 | } catch (ExceptionInInitializerError err) { | ||
606 | throw processInitializerError(err); | ||
607 | } | ||
608 | } | ||
609 | |||
610 | @Override | ||
611 | protected Adjacent.Matcher instantiate(final ViatraQueryEngine engine) { | ||
612 | return Adjacent.Matcher.on(engine); | ||
613 | } | ||
614 | |||
615 | @Override | ||
616 | public Adjacent.Matcher instantiate() { | ||
617 | return Adjacent.Matcher.create(); | ||
618 | } | ||
619 | |||
620 | @Override | ||
621 | public Adjacent.Match newEmptyMatch() { | ||
622 | return Adjacent.Match.newEmptyMatch(); | ||
623 | } | ||
624 | |||
625 | @Override | ||
626 | public Adjacent.Match newMatch(final Object... parameters) { | ||
627 | return Adjacent.Match.newMatch((modes3.Segment) parameters[0], (modes3.Segment) parameters[1]); | ||
628 | } | ||
629 | |||
630 | /** | ||
631 | * Inner class allowing the singleton instance of {@link Adjacent} to be created | ||
632 | * <b>not</b> at the class load time of the outer class, | ||
633 | * but rather at the first call to {@link Adjacent#instance()}. | ||
634 | * | ||
635 | * <p> This workaround is required e.g. to support recursion. | ||
636 | * | ||
637 | */ | ||
638 | private static class LazyHolder { | ||
639 | private static final Adjacent INSTANCE = new Adjacent(); | ||
640 | |||
641 | /** | ||
642 | * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned. | ||
643 | * This initialization order is required to support indirect recursion. | ||
644 | * | ||
645 | * <p> The static initializer is defined using a helper field to work around limitations of the code generator. | ||
646 | * | ||
647 | */ | ||
648 | private static final Object STATIC_INITIALIZER = ensureInitialized(); | ||
649 | |||
650 | public static Object ensureInitialized() { | ||
651 | INSTANCE.ensureInitializedInternal(); | ||
652 | return null; | ||
653 | } | ||
654 | } | ||
655 | |||
656 | private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { | ||
657 | private static final Adjacent.GeneratedPQuery INSTANCE = new GeneratedPQuery(); | ||
658 | |||
659 | private final PParameter parameter_S1 = new PParameter("S1", "modes3.Segment", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Segment")), PParameterDirection.INOUT); | ||
660 | |||
661 | private final PParameter parameter_S2 = new PParameter("S2", "modes3.Segment", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Segment")), PParameterDirection.INOUT); | ||
662 | |||
663 | private final List<PParameter> parameters = Arrays.asList(parameter_S1, parameter_S2); | ||
664 | |||
665 | private GeneratedPQuery() { | ||
666 | super(PVisibility.PUBLIC); | ||
667 | } | ||
668 | |||
669 | @Override | ||
670 | public String getFullyQualifiedName() { | ||
671 | return "modes3.queries.adjacent"; | ||
672 | } | ||
673 | |||
674 | @Override | ||
675 | public List<String> getParameterNames() { | ||
676 | return Arrays.asList("S1","S2"); | ||
677 | } | ||
678 | |||
679 | @Override | ||
680 | public List<PParameter> getParameters() { | ||
681 | return parameters; | ||
682 | } | ||
683 | |||
684 | @Override | ||
685 | public Set<PBody> doGetContainedBodies() { | ||
686 | setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); | ||
687 | Set<PBody> bodies = new LinkedHashSet<>(); | ||
688 | { | ||
689 | PBody body = new PBody(this); | ||
690 | PVariable var_S1 = body.getOrCreateVariableByName("S1"); | ||
691 | PVariable var_S2 = body.getOrCreateVariableByName("S2"); | ||
692 | new TypeConstraint(body, Tuples.flatTupleOf(var_S1), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
693 | new TypeConstraint(body, Tuples.flatTupleOf(var_S2), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
694 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
695 | new ExportedParameter(body, var_S1, parameter_S1), | ||
696 | new ExportedParameter(body, var_S2, parameter_S2) | ||
697 | )); | ||
698 | // find output(S1, S2) | ||
699 | new PositivePatternCall(body, Tuples.flatTupleOf(var_S1, var_S2), Output.instance().getInternalQueryRepresentation()); | ||
700 | bodies.add(body); | ||
701 | } | ||
702 | { | ||
703 | PBody body = new PBody(this); | ||
704 | PVariable var_S1 = body.getOrCreateVariableByName("S1"); | ||
705 | PVariable var_S2 = body.getOrCreateVariableByName("S2"); | ||
706 | new TypeConstraint(body, Tuples.flatTupleOf(var_S1), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
707 | new TypeConstraint(body, Tuples.flatTupleOf(var_S2), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
708 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
709 | new ExportedParameter(body, var_S1, parameter_S1), | ||
710 | new ExportedParameter(body, var_S2, parameter_S2) | ||
711 | )); | ||
712 | // find turnoutOutput(S2, S1) | ||
713 | new PositivePatternCall(body, Tuples.flatTupleOf(var_S2, var_S1), TurnoutOutput.instance().getInternalQueryRepresentation()); | ||
714 | bodies.add(body); | ||
715 | } | ||
716 | return bodies; | ||
717 | } | ||
718 | } | ||
719 | } | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/ConnectedTo.java b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/ConnectedTo.java new file mode 100644 index 00000000..a0f14958 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/ConnectedTo.java | |||
@@ -0,0 +1,704 @@ | |||
1 | /** | ||
2 | * Generated from platform:/resource/ca.mcgill.rtgmrt.example.modes3/src/modes3/queries/Modes3Queries.vql | ||
3 | */ | ||
4 | package modes3.queries; | ||
5 | |||
6 | import java.util.Arrays; | ||
7 | import java.util.Collection; | ||
8 | import java.util.LinkedHashSet; | ||
9 | import java.util.List; | ||
10 | import java.util.Objects; | ||
11 | import java.util.Optional; | ||
12 | import java.util.Set; | ||
13 | import java.util.function.Consumer; | ||
14 | import java.util.stream.Collectors; | ||
15 | import java.util.stream.Stream; | ||
16 | import modes3.Segment; | ||
17 | import org.apache.log4j.Logger; | ||
18 | import org.eclipse.emf.ecore.EClass; | ||
19 | import org.eclipse.viatra.query.runtime.api.IPatternMatch; | ||
20 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification; | ||
21 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; | ||
22 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; | ||
23 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; | ||
24 | import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; | ||
25 | import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; | ||
26 | import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; | ||
27 | import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; | ||
28 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
29 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | ||
30 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | ||
31 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; | ||
32 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
33 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
34 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | ||
35 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; | ||
36 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | ||
37 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; | ||
38 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
39 | import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; | ||
40 | |||
41 | /** | ||
42 | * A pattern-specific query specification that can instantiate Matcher in a type-safe way. | ||
43 | * | ||
44 | * <p>Original source: | ||
45 | * <code><pre> | ||
46 | * pattern connectedTo(S1 : Segment, S2 : Segment) { | ||
47 | * Segment.connectedTo(S1, S2); | ||
48 | * } | ||
49 | * </pre></code> | ||
50 | * | ||
51 | * @see Matcher | ||
52 | * @see Match | ||
53 | * | ||
54 | */ | ||
55 | @SuppressWarnings("all") | ||
56 | public final class ConnectedTo extends BaseGeneratedEMFQuerySpecification<ConnectedTo.Matcher> { | ||
57 | /** | ||
58 | * Pattern-specific match representation of the modes3.queries.connectedTo pattern, | ||
59 | * to be used in conjunction with {@link Matcher}. | ||
60 | * | ||
61 | * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. | ||
62 | * Each instance is a (possibly partial) substitution of pattern parameters, | ||
63 | * usable to represent a match of the pattern in the result of a query, | ||
64 | * or to specify the bound (fixed) input parameters when issuing a query. | ||
65 | * | ||
66 | * @see Matcher | ||
67 | * | ||
68 | */ | ||
69 | public static abstract class Match extends BasePatternMatch { | ||
70 | private Segment fS1; | ||
71 | |||
72 | private Segment fS2; | ||
73 | |||
74 | private static List<String> parameterNames = makeImmutableList("S1", "S2"); | ||
75 | |||
76 | private Match(final Segment pS1, final Segment pS2) { | ||
77 | this.fS1 = pS1; | ||
78 | this.fS2 = pS2; | ||
79 | } | ||
80 | |||
81 | @Override | ||
82 | public Object get(final String parameterName) { | ||
83 | switch(parameterName) { | ||
84 | case "S1": return this.fS1; | ||
85 | case "S2": return this.fS2; | ||
86 | default: return null; | ||
87 | } | ||
88 | } | ||
89 | |||
90 | @Override | ||
91 | public Object get(final int index) { | ||
92 | switch(index) { | ||
93 | case 0: return this.fS1; | ||
94 | case 1: return this.fS2; | ||
95 | default: return null; | ||
96 | } | ||
97 | } | ||
98 | |||
99 | public Segment getS1() { | ||
100 | return this.fS1; | ||
101 | } | ||
102 | |||
103 | public Segment getS2() { | ||
104 | return this.fS2; | ||
105 | } | ||
106 | |||
107 | @Override | ||
108 | public boolean set(final String parameterName, final Object newValue) { | ||
109 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
110 | if ("S1".equals(parameterName) ) { | ||
111 | this.fS1 = (Segment) newValue; | ||
112 | return true; | ||
113 | } | ||
114 | if ("S2".equals(parameterName) ) { | ||
115 | this.fS2 = (Segment) newValue; | ||
116 | return true; | ||
117 | } | ||
118 | return false; | ||
119 | } | ||
120 | |||
121 | public void setS1(final Segment pS1) { | ||
122 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
123 | this.fS1 = pS1; | ||
124 | } | ||
125 | |||
126 | public void setS2(final Segment pS2) { | ||
127 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
128 | this.fS2 = pS2; | ||
129 | } | ||
130 | |||
131 | @Override | ||
132 | public String patternName() { | ||
133 | return "modes3.queries.connectedTo"; | ||
134 | } | ||
135 | |||
136 | @Override | ||
137 | public List<String> parameterNames() { | ||
138 | return ConnectedTo.Match.parameterNames; | ||
139 | } | ||
140 | |||
141 | @Override | ||
142 | public Object[] toArray() { | ||
143 | return new Object[]{fS1, fS2}; | ||
144 | } | ||
145 | |||
146 | @Override | ||
147 | public ConnectedTo.Match toImmutable() { | ||
148 | return isMutable() ? newMatch(fS1, fS2) : this; | ||
149 | } | ||
150 | |||
151 | @Override | ||
152 | public String prettyPrint() { | ||
153 | StringBuilder result = new StringBuilder(); | ||
154 | result.append("\"S1\"=" + prettyPrintValue(fS1) + ", "); | ||
155 | result.append("\"S2\"=" + prettyPrintValue(fS2)); | ||
156 | return result.toString(); | ||
157 | } | ||
158 | |||
159 | @Override | ||
160 | public int hashCode() { | ||
161 | return Objects.hash(fS1, fS2); | ||
162 | } | ||
163 | |||
164 | @Override | ||
165 | public boolean equals(final Object obj) { | ||
166 | if (this == obj) | ||
167 | return true; | ||
168 | if (obj == null) { | ||
169 | return false; | ||
170 | } | ||
171 | if ((obj instanceof ConnectedTo.Match)) { | ||
172 | ConnectedTo.Match other = (ConnectedTo.Match) obj; | ||
173 | return Objects.equals(fS1, other.fS1) && Objects.equals(fS2, other.fS2); | ||
174 | } else { | ||
175 | // this should be infrequent | ||
176 | if (!(obj instanceof IPatternMatch)) { | ||
177 | return false; | ||
178 | } | ||
179 | IPatternMatch otherSig = (IPatternMatch) obj; | ||
180 | return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); | ||
181 | } | ||
182 | } | ||
183 | |||
184 | @Override | ||
185 | public ConnectedTo specification() { | ||
186 | return ConnectedTo.instance(); | ||
187 | } | ||
188 | |||
189 | /** | ||
190 | * Returns an empty, mutable match. | ||
191 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
192 | * | ||
193 | * @return the empty match. | ||
194 | * | ||
195 | */ | ||
196 | public static ConnectedTo.Match newEmptyMatch() { | ||
197 | return new Mutable(null, null); | ||
198 | } | ||
199 | |||
200 | /** | ||
201 | * Returns a mutable (partial) match. | ||
202 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
203 | * | ||
204 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
205 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
206 | * @return the new, mutable (partial) match object. | ||
207 | * | ||
208 | */ | ||
209 | public static ConnectedTo.Match newMutableMatch(final Segment pS1, final Segment pS2) { | ||
210 | return new Mutable(pS1, pS2); | ||
211 | } | ||
212 | |||
213 | /** | ||
214 | * Returns a new (partial) match. | ||
215 | * This can be used e.g. to call the matcher with a partial match. | ||
216 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
217 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
218 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
219 | * @return the (partial) match object. | ||
220 | * | ||
221 | */ | ||
222 | public static ConnectedTo.Match newMatch(final Segment pS1, final Segment pS2) { | ||
223 | return new Immutable(pS1, pS2); | ||
224 | } | ||
225 | |||
226 | private static final class Mutable extends ConnectedTo.Match { | ||
227 | Mutable(final Segment pS1, final Segment pS2) { | ||
228 | super(pS1, pS2); | ||
229 | } | ||
230 | |||
231 | @Override | ||
232 | public boolean isMutable() { | ||
233 | return true; | ||
234 | } | ||
235 | } | ||
236 | |||
237 | private static final class Immutable extends ConnectedTo.Match { | ||
238 | Immutable(final Segment pS1, final Segment pS2) { | ||
239 | super(pS1, pS2); | ||
240 | } | ||
241 | |||
242 | @Override | ||
243 | public boolean isMutable() { | ||
244 | return false; | ||
245 | } | ||
246 | } | ||
247 | } | ||
248 | |||
249 | /** | ||
250 | * Generated pattern matcher API of the modes3.queries.connectedTo pattern, | ||
251 | * providing pattern-specific query methods. | ||
252 | * | ||
253 | * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, | ||
254 | * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. | ||
255 | * | ||
256 | * <p>Matches of the pattern will be represented as {@link Match}. | ||
257 | * | ||
258 | * <p>Original source: | ||
259 | * <code><pre> | ||
260 | * pattern connectedTo(S1 : Segment, S2 : Segment) { | ||
261 | * Segment.connectedTo(S1, S2); | ||
262 | * } | ||
263 | * </pre></code> | ||
264 | * | ||
265 | * @see Match | ||
266 | * @see ConnectedTo | ||
267 | * | ||
268 | */ | ||
269 | public static class Matcher extends BaseMatcher<ConnectedTo.Match> { | ||
270 | /** | ||
271 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
272 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
273 | * | ||
274 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
275 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
276 | * | ||
277 | */ | ||
278 | public static ConnectedTo.Matcher on(final ViatraQueryEngine engine) { | ||
279 | // check if matcher already exists | ||
280 | Matcher matcher = engine.getExistingMatcher(querySpecification()); | ||
281 | if (matcher == null) { | ||
282 | matcher = (Matcher)engine.getMatcher(querySpecification()); | ||
283 | } | ||
284 | return matcher; | ||
285 | } | ||
286 | |||
287 | /** | ||
288 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
289 | * @return an initialized matcher | ||
290 | * @noreference This method is for internal matcher initialization by the framework, do not call it manually. | ||
291 | * | ||
292 | */ | ||
293 | public static ConnectedTo.Matcher create() { | ||
294 | return new Matcher(); | ||
295 | } | ||
296 | |||
297 | private static final int POSITION_S1 = 0; | ||
298 | |||
299 | private static final int POSITION_S2 = 1; | ||
300 | |||
301 | private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(ConnectedTo.Matcher.class); | ||
302 | |||
303 | /** | ||
304 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
305 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
306 | * | ||
307 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
308 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
309 | * | ||
310 | */ | ||
311 | private Matcher() { | ||
312 | super(querySpecification()); | ||
313 | } | ||
314 | |||
315 | /** | ||
316 | * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. | ||
317 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
318 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
319 | * @return matches represented as a Match object. | ||
320 | * | ||
321 | */ | ||
322 | public Collection<ConnectedTo.Match> getAllMatches(final Segment pS1, final Segment pS2) { | ||
323 | return rawStreamAllMatches(new Object[]{pS1, pS2}).collect(Collectors.toSet()); | ||
324 | } | ||
325 | |||
326 | /** | ||
327 | * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. | ||
328 | * </p> | ||
329 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
330 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
331 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
332 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
333 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
334 | * @return a stream of matches represented as a Match object. | ||
335 | * | ||
336 | */ | ||
337 | public Stream<ConnectedTo.Match> streamAllMatches(final Segment pS1, final Segment pS2) { | ||
338 | return rawStreamAllMatches(new Object[]{pS1, pS2}); | ||
339 | } | ||
340 | |||
341 | /** | ||
342 | * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
343 | * Neither determinism nor randomness of selection is guaranteed. | ||
344 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
345 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
346 | * @return a match represented as a Match object, or null if no match is found. | ||
347 | * | ||
348 | */ | ||
349 | public Optional<ConnectedTo.Match> getOneArbitraryMatch(final Segment pS1, final Segment pS2) { | ||
350 | return rawGetOneArbitraryMatch(new Object[]{pS1, pS2}); | ||
351 | } | ||
352 | |||
353 | /** | ||
354 | * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, | ||
355 | * under any possible substitution of the unspecified parameters (if any). | ||
356 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
357 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
358 | * @return true if the input is a valid (partial) match of the pattern. | ||
359 | * | ||
360 | */ | ||
361 | public boolean hasMatch(final Segment pS1, final Segment pS2) { | ||
362 | return rawHasMatch(new Object[]{pS1, pS2}); | ||
363 | } | ||
364 | |||
365 | /** | ||
366 | * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. | ||
367 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
368 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
369 | * @return the number of pattern matches found. | ||
370 | * | ||
371 | */ | ||
372 | public int countMatches(final Segment pS1, final Segment pS2) { | ||
373 | return rawCountMatches(new Object[]{pS1, pS2}); | ||
374 | } | ||
375 | |||
376 | /** | ||
377 | * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
378 | * Neither determinism nor randomness of selection is guaranteed. | ||
379 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
380 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
381 | * @param processor the action that will process the selected match. | ||
382 | * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked | ||
383 | * | ||
384 | */ | ||
385 | public boolean forOneArbitraryMatch(final Segment pS1, final Segment pS2, final Consumer<? super ConnectedTo.Match> processor) { | ||
386 | return rawForOneArbitraryMatch(new Object[]{pS1, pS2}, processor); | ||
387 | } | ||
388 | |||
389 | /** | ||
390 | * Returns a new (partial) match. | ||
391 | * This can be used e.g. to call the matcher with a partial match. | ||
392 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
393 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
394 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
395 | * @return the (partial) match object. | ||
396 | * | ||
397 | */ | ||
398 | public ConnectedTo.Match newMatch(final Segment pS1, final Segment pS2) { | ||
399 | return ConnectedTo.Match.newMatch(pS1, pS2); | ||
400 | } | ||
401 | |||
402 | /** | ||
403 | * Retrieve the set of values that occur in matches for S1. | ||
404 | * @return the Set of all values or empty set if there are no matches | ||
405 | * | ||
406 | */ | ||
407 | protected Stream<Segment> rawStreamAllValuesOfS1(final Object[] parameters) { | ||
408 | return rawStreamAllValues(POSITION_S1, parameters).map(Segment.class::cast); | ||
409 | } | ||
410 | |||
411 | /** | ||
412 | * Retrieve the set of values that occur in matches for S1. | ||
413 | * @return the Set of all values or empty set if there are no matches | ||
414 | * | ||
415 | */ | ||
416 | public Set<Segment> getAllValuesOfS1() { | ||
417 | return rawStreamAllValuesOfS1(emptyArray()).collect(Collectors.toSet()); | ||
418 | } | ||
419 | |||
420 | /** | ||
421 | * Retrieve the set of values that occur in matches for S1. | ||
422 | * @return the Set of all values or empty set if there are no matches | ||
423 | * | ||
424 | */ | ||
425 | public Stream<Segment> streamAllValuesOfS1() { | ||
426 | return rawStreamAllValuesOfS1(emptyArray()); | ||
427 | } | ||
428 | |||
429 | /** | ||
430 | * Retrieve the set of values that occur in matches for S1. | ||
431 | * </p> | ||
432 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
433 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
434 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
435 | * | ||
436 | * @return the Stream of all values or empty set if there are no matches | ||
437 | * | ||
438 | */ | ||
439 | public Stream<Segment> streamAllValuesOfS1(final ConnectedTo.Match partialMatch) { | ||
440 | return rawStreamAllValuesOfS1(partialMatch.toArray()); | ||
441 | } | ||
442 | |||
443 | /** | ||
444 | * Retrieve the set of values that occur in matches for S1. | ||
445 | * </p> | ||
446 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
447 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
448 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
449 | * | ||
450 | * @return the Stream of all values or empty set if there are no matches | ||
451 | * | ||
452 | */ | ||
453 | public Stream<Segment> streamAllValuesOfS1(final Segment pS2) { | ||
454 | return rawStreamAllValuesOfS1(new Object[]{null, pS2}); | ||
455 | } | ||
456 | |||
457 | /** | ||
458 | * Retrieve the set of values that occur in matches for S1. | ||
459 | * @return the Set of all values or empty set if there are no matches | ||
460 | * | ||
461 | */ | ||
462 | public Set<Segment> getAllValuesOfS1(final ConnectedTo.Match partialMatch) { | ||
463 | return rawStreamAllValuesOfS1(partialMatch.toArray()).collect(Collectors.toSet()); | ||
464 | } | ||
465 | |||
466 | /** | ||
467 | * Retrieve the set of values that occur in matches for S1. | ||
468 | * @return the Set of all values or empty set if there are no matches | ||
469 | * | ||
470 | */ | ||
471 | public Set<Segment> getAllValuesOfS1(final Segment pS2) { | ||
472 | return rawStreamAllValuesOfS1(new Object[]{null, pS2}).collect(Collectors.toSet()); | ||
473 | } | ||
474 | |||
475 | /** | ||
476 | * Retrieve the set of values that occur in matches for S2. | ||
477 | * @return the Set of all values or empty set if there are no matches | ||
478 | * | ||
479 | */ | ||
480 | protected Stream<Segment> rawStreamAllValuesOfS2(final Object[] parameters) { | ||
481 | return rawStreamAllValues(POSITION_S2, parameters).map(Segment.class::cast); | ||
482 | } | ||
483 | |||
484 | /** | ||
485 | * Retrieve the set of values that occur in matches for S2. | ||
486 | * @return the Set of all values or empty set if there are no matches | ||
487 | * | ||
488 | */ | ||
489 | public Set<Segment> getAllValuesOfS2() { | ||
490 | return rawStreamAllValuesOfS2(emptyArray()).collect(Collectors.toSet()); | ||
491 | } | ||
492 | |||
493 | /** | ||
494 | * Retrieve the set of values that occur in matches for S2. | ||
495 | * @return the Set of all values or empty set if there are no matches | ||
496 | * | ||
497 | */ | ||
498 | public Stream<Segment> streamAllValuesOfS2() { | ||
499 | return rawStreamAllValuesOfS2(emptyArray()); | ||
500 | } | ||
501 | |||
502 | /** | ||
503 | * Retrieve the set of values that occur in matches for S2. | ||
504 | * </p> | ||
505 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
506 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
507 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
508 | * | ||
509 | * @return the Stream of all values or empty set if there are no matches | ||
510 | * | ||
511 | */ | ||
512 | public Stream<Segment> streamAllValuesOfS2(final ConnectedTo.Match partialMatch) { | ||
513 | return rawStreamAllValuesOfS2(partialMatch.toArray()); | ||
514 | } | ||
515 | |||
516 | /** | ||
517 | * Retrieve the set of values that occur in matches for S2. | ||
518 | * </p> | ||
519 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
520 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
521 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
522 | * | ||
523 | * @return the Stream of all values or empty set if there are no matches | ||
524 | * | ||
525 | */ | ||
526 | public Stream<Segment> streamAllValuesOfS2(final Segment pS1) { | ||
527 | return rawStreamAllValuesOfS2(new Object[]{pS1, null}); | ||
528 | } | ||
529 | |||
530 | /** | ||
531 | * Retrieve the set of values that occur in matches for S2. | ||
532 | * @return the Set of all values or empty set if there are no matches | ||
533 | * | ||
534 | */ | ||
535 | public Set<Segment> getAllValuesOfS2(final ConnectedTo.Match partialMatch) { | ||
536 | return rawStreamAllValuesOfS2(partialMatch.toArray()).collect(Collectors.toSet()); | ||
537 | } | ||
538 | |||
539 | /** | ||
540 | * Retrieve the set of values that occur in matches for S2. | ||
541 | * @return the Set of all values or empty set if there are no matches | ||
542 | * | ||
543 | */ | ||
544 | public Set<Segment> getAllValuesOfS2(final Segment pS1) { | ||
545 | return rawStreamAllValuesOfS2(new Object[]{pS1, null}).collect(Collectors.toSet()); | ||
546 | } | ||
547 | |||
548 | @Override | ||
549 | protected ConnectedTo.Match tupleToMatch(final Tuple t) { | ||
550 | try { | ||
551 | return ConnectedTo.Match.newMatch((Segment) t.get(POSITION_S1), (Segment) t.get(POSITION_S2)); | ||
552 | } catch(ClassCastException e) { | ||
553 | LOGGER.error("Element(s) in tuple not properly typed!",e); | ||
554 | return null; | ||
555 | } | ||
556 | } | ||
557 | |||
558 | @Override | ||
559 | protected ConnectedTo.Match arrayToMatch(final Object[] match) { | ||
560 | try { | ||
561 | return ConnectedTo.Match.newMatch((Segment) match[POSITION_S1], (Segment) match[POSITION_S2]); | ||
562 | } catch(ClassCastException e) { | ||
563 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
564 | return null; | ||
565 | } | ||
566 | } | ||
567 | |||
568 | @Override | ||
569 | protected ConnectedTo.Match arrayToMatchMutable(final Object[] match) { | ||
570 | try { | ||
571 | return ConnectedTo.Match.newMutableMatch((Segment) match[POSITION_S1], (Segment) match[POSITION_S2]); | ||
572 | } catch(ClassCastException e) { | ||
573 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
574 | return null; | ||
575 | } | ||
576 | } | ||
577 | |||
578 | /** | ||
579 | * @return the singleton instance of the query specification of this pattern | ||
580 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
581 | * | ||
582 | */ | ||
583 | public static IQuerySpecification<ConnectedTo.Matcher> querySpecification() { | ||
584 | return ConnectedTo.instance(); | ||
585 | } | ||
586 | } | ||
587 | |||
588 | private ConnectedTo() { | ||
589 | super(GeneratedPQuery.INSTANCE); | ||
590 | } | ||
591 | |||
592 | /** | ||
593 | * @return the singleton instance of the query specification | ||
594 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
595 | * | ||
596 | */ | ||
597 | public static ConnectedTo instance() { | ||
598 | try{ | ||
599 | return LazyHolder.INSTANCE; | ||
600 | } catch (ExceptionInInitializerError err) { | ||
601 | throw processInitializerError(err); | ||
602 | } | ||
603 | } | ||
604 | |||
605 | @Override | ||
606 | protected ConnectedTo.Matcher instantiate(final ViatraQueryEngine engine) { | ||
607 | return ConnectedTo.Matcher.on(engine); | ||
608 | } | ||
609 | |||
610 | @Override | ||
611 | public ConnectedTo.Matcher instantiate() { | ||
612 | return ConnectedTo.Matcher.create(); | ||
613 | } | ||
614 | |||
615 | @Override | ||
616 | public ConnectedTo.Match newEmptyMatch() { | ||
617 | return ConnectedTo.Match.newEmptyMatch(); | ||
618 | } | ||
619 | |||
620 | @Override | ||
621 | public ConnectedTo.Match newMatch(final Object... parameters) { | ||
622 | return ConnectedTo.Match.newMatch((modes3.Segment) parameters[0], (modes3.Segment) parameters[1]); | ||
623 | } | ||
624 | |||
625 | /** | ||
626 | * Inner class allowing the singleton instance of {@link ConnectedTo} to be created | ||
627 | * <b>not</b> at the class load time of the outer class, | ||
628 | * but rather at the first call to {@link ConnectedTo#instance()}. | ||
629 | * | ||
630 | * <p> This workaround is required e.g. to support recursion. | ||
631 | * | ||
632 | */ | ||
633 | private static class LazyHolder { | ||
634 | private static final ConnectedTo INSTANCE = new ConnectedTo(); | ||
635 | |||
636 | /** | ||
637 | * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned. | ||
638 | * This initialization order is required to support indirect recursion. | ||
639 | * | ||
640 | * <p> The static initializer is defined using a helper field to work around limitations of the code generator. | ||
641 | * | ||
642 | */ | ||
643 | private static final Object STATIC_INITIALIZER = ensureInitialized(); | ||
644 | |||
645 | public static Object ensureInitialized() { | ||
646 | INSTANCE.ensureInitializedInternal(); | ||
647 | return null; | ||
648 | } | ||
649 | } | ||
650 | |||
651 | private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { | ||
652 | private static final ConnectedTo.GeneratedPQuery INSTANCE = new GeneratedPQuery(); | ||
653 | |||
654 | private final PParameter parameter_S1 = new PParameter("S1", "modes3.Segment", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Segment")), PParameterDirection.INOUT); | ||
655 | |||
656 | private final PParameter parameter_S2 = new PParameter("S2", "modes3.Segment", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Segment")), PParameterDirection.INOUT); | ||
657 | |||
658 | private final List<PParameter> parameters = Arrays.asList(parameter_S1, parameter_S2); | ||
659 | |||
660 | private GeneratedPQuery() { | ||
661 | super(PVisibility.PUBLIC); | ||
662 | } | ||
663 | |||
664 | @Override | ||
665 | public String getFullyQualifiedName() { | ||
666 | return "modes3.queries.connectedTo"; | ||
667 | } | ||
668 | |||
669 | @Override | ||
670 | public List<String> getParameterNames() { | ||
671 | return Arrays.asList("S1","S2"); | ||
672 | } | ||
673 | |||
674 | @Override | ||
675 | public List<PParameter> getParameters() { | ||
676 | return parameters; | ||
677 | } | ||
678 | |||
679 | @Override | ||
680 | public Set<PBody> doGetContainedBodies() { | ||
681 | setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); | ||
682 | Set<PBody> bodies = new LinkedHashSet<>(); | ||
683 | { | ||
684 | PBody body = new PBody(this); | ||
685 | PVariable var_S1 = body.getOrCreateVariableByName("S1"); | ||
686 | PVariable var_S2 = body.getOrCreateVariableByName("S2"); | ||
687 | new TypeConstraint(body, Tuples.flatTupleOf(var_S1), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
688 | new TypeConstraint(body, Tuples.flatTupleOf(var_S2), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
689 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
690 | new ExportedParameter(body, var_S1, parameter_S1), | ||
691 | new ExportedParameter(body, var_S2, parameter_S2) | ||
692 | )); | ||
693 | // Segment.connectedTo(S1, S2) | ||
694 | new TypeConstraint(body, Tuples.flatTupleOf(var_S1), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
695 | PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); | ||
696 | new TypeConstraint(body, Tuples.flatTupleOf(var_S1, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment", "connectedTo"))); | ||
697 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
698 | new Equality(body, var__virtual_0_, var_S2); | ||
699 | bodies.add(body); | ||
700 | } | ||
701 | return bodies; | ||
702 | } | ||
703 | } | ||
704 | } | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/ConnectedToNotSymmetric.java b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/ConnectedToNotSymmetric.java new file mode 100644 index 00000000..91b74c7e --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/ConnectedToNotSymmetric.java | |||
@@ -0,0 +1,724 @@ | |||
1 | /** | ||
2 | * Generated from platform:/resource/ca.mcgill.rtgmrt.example.modes3/src/modes3/queries/Modes3Queries.vql | ||
3 | */ | ||
4 | package modes3.queries; | ||
5 | |||
6 | import java.util.Arrays; | ||
7 | import java.util.Collection; | ||
8 | import java.util.LinkedHashSet; | ||
9 | import java.util.List; | ||
10 | import java.util.Objects; | ||
11 | import java.util.Optional; | ||
12 | import java.util.Set; | ||
13 | import java.util.function.Consumer; | ||
14 | import java.util.stream.Collectors; | ||
15 | import java.util.stream.Stream; | ||
16 | import modes3.Segment; | ||
17 | import modes3.queries.ConnectedTo; | ||
18 | import org.apache.log4j.Logger; | ||
19 | import org.eclipse.emf.ecore.EClass; | ||
20 | import org.eclipse.viatra.query.runtime.api.IPatternMatch; | ||
21 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification; | ||
22 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; | ||
23 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; | ||
24 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; | ||
25 | import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; | ||
26 | import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; | ||
27 | import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; | ||
28 | import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; | ||
29 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
30 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | ||
31 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | ||
32 | import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation; | ||
33 | import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference; | ||
34 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; | ||
35 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
36 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.NegativePatternCall; | ||
37 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
38 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | ||
39 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; | ||
40 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | ||
41 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; | ||
42 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
43 | import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; | ||
44 | |||
45 | /** | ||
46 | * A pattern-specific query specification that can instantiate Matcher in a type-safe way. | ||
47 | * | ||
48 | * <p>Original source: | ||
49 | * <code><pre> | ||
50 | * {@literal @}Constraint(message = "connectedToNotSymmetric", severity = "error", key = { S1, S2 }) | ||
51 | * pattern connectedToNotSymmetric(S1 : Segment, S2 : Segment) { | ||
52 | * Segment.connectedTo(S1, S2); | ||
53 | * neg find connectedTo(S2, S1); | ||
54 | * } | ||
55 | * </pre></code> | ||
56 | * | ||
57 | * @see Matcher | ||
58 | * @see Match | ||
59 | * | ||
60 | */ | ||
61 | @SuppressWarnings("all") | ||
62 | public final class ConnectedToNotSymmetric extends BaseGeneratedEMFQuerySpecification<ConnectedToNotSymmetric.Matcher> { | ||
63 | /** | ||
64 | * Pattern-specific match representation of the modes3.queries.connectedToNotSymmetric pattern, | ||
65 | * to be used in conjunction with {@link Matcher}. | ||
66 | * | ||
67 | * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. | ||
68 | * Each instance is a (possibly partial) substitution of pattern parameters, | ||
69 | * usable to represent a match of the pattern in the result of a query, | ||
70 | * or to specify the bound (fixed) input parameters when issuing a query. | ||
71 | * | ||
72 | * @see Matcher | ||
73 | * | ||
74 | */ | ||
75 | public static abstract class Match extends BasePatternMatch { | ||
76 | private Segment fS1; | ||
77 | |||
78 | private Segment fS2; | ||
79 | |||
80 | private static List<String> parameterNames = makeImmutableList("S1", "S2"); | ||
81 | |||
82 | private Match(final Segment pS1, final Segment pS2) { | ||
83 | this.fS1 = pS1; | ||
84 | this.fS2 = pS2; | ||
85 | } | ||
86 | |||
87 | @Override | ||
88 | public Object get(final String parameterName) { | ||
89 | switch(parameterName) { | ||
90 | case "S1": return this.fS1; | ||
91 | case "S2": return this.fS2; | ||
92 | default: return null; | ||
93 | } | ||
94 | } | ||
95 | |||
96 | @Override | ||
97 | public Object get(final int index) { | ||
98 | switch(index) { | ||
99 | case 0: return this.fS1; | ||
100 | case 1: return this.fS2; | ||
101 | default: return null; | ||
102 | } | ||
103 | } | ||
104 | |||
105 | public Segment getS1() { | ||
106 | return this.fS1; | ||
107 | } | ||
108 | |||
109 | public Segment getS2() { | ||
110 | return this.fS2; | ||
111 | } | ||
112 | |||
113 | @Override | ||
114 | public boolean set(final String parameterName, final Object newValue) { | ||
115 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
116 | if ("S1".equals(parameterName) ) { | ||
117 | this.fS1 = (Segment) newValue; | ||
118 | return true; | ||
119 | } | ||
120 | if ("S2".equals(parameterName) ) { | ||
121 | this.fS2 = (Segment) newValue; | ||
122 | return true; | ||
123 | } | ||
124 | return false; | ||
125 | } | ||
126 | |||
127 | public void setS1(final Segment pS1) { | ||
128 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
129 | this.fS1 = pS1; | ||
130 | } | ||
131 | |||
132 | public void setS2(final Segment pS2) { | ||
133 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
134 | this.fS2 = pS2; | ||
135 | } | ||
136 | |||
137 | @Override | ||
138 | public String patternName() { | ||
139 | return "modes3.queries.connectedToNotSymmetric"; | ||
140 | } | ||
141 | |||
142 | @Override | ||
143 | public List<String> parameterNames() { | ||
144 | return ConnectedToNotSymmetric.Match.parameterNames; | ||
145 | } | ||
146 | |||
147 | @Override | ||
148 | public Object[] toArray() { | ||
149 | return new Object[]{fS1, fS2}; | ||
150 | } | ||
151 | |||
152 | @Override | ||
153 | public ConnectedToNotSymmetric.Match toImmutable() { | ||
154 | return isMutable() ? newMatch(fS1, fS2) : this; | ||
155 | } | ||
156 | |||
157 | @Override | ||
158 | public String prettyPrint() { | ||
159 | StringBuilder result = new StringBuilder(); | ||
160 | result.append("\"S1\"=" + prettyPrintValue(fS1) + ", "); | ||
161 | result.append("\"S2\"=" + prettyPrintValue(fS2)); | ||
162 | return result.toString(); | ||
163 | } | ||
164 | |||
165 | @Override | ||
166 | public int hashCode() { | ||
167 | return Objects.hash(fS1, fS2); | ||
168 | } | ||
169 | |||
170 | @Override | ||
171 | public boolean equals(final Object obj) { | ||
172 | if (this == obj) | ||
173 | return true; | ||
174 | if (obj == null) { | ||
175 | return false; | ||
176 | } | ||
177 | if ((obj instanceof ConnectedToNotSymmetric.Match)) { | ||
178 | ConnectedToNotSymmetric.Match other = (ConnectedToNotSymmetric.Match) obj; | ||
179 | return Objects.equals(fS1, other.fS1) && Objects.equals(fS2, other.fS2); | ||
180 | } else { | ||
181 | // this should be infrequent | ||
182 | if (!(obj instanceof IPatternMatch)) { | ||
183 | return false; | ||
184 | } | ||
185 | IPatternMatch otherSig = (IPatternMatch) obj; | ||
186 | return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); | ||
187 | } | ||
188 | } | ||
189 | |||
190 | @Override | ||
191 | public ConnectedToNotSymmetric specification() { | ||
192 | return ConnectedToNotSymmetric.instance(); | ||
193 | } | ||
194 | |||
195 | /** | ||
196 | * Returns an empty, mutable match. | ||
197 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
198 | * | ||
199 | * @return the empty match. | ||
200 | * | ||
201 | */ | ||
202 | public static ConnectedToNotSymmetric.Match newEmptyMatch() { | ||
203 | return new Mutable(null, null); | ||
204 | } | ||
205 | |||
206 | /** | ||
207 | * Returns a mutable (partial) match. | ||
208 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
209 | * | ||
210 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
211 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
212 | * @return the new, mutable (partial) match object. | ||
213 | * | ||
214 | */ | ||
215 | public static ConnectedToNotSymmetric.Match newMutableMatch(final Segment pS1, final Segment pS2) { | ||
216 | return new Mutable(pS1, pS2); | ||
217 | } | ||
218 | |||
219 | /** | ||
220 | * Returns a new (partial) match. | ||
221 | * This can be used e.g. to call the matcher with a partial match. | ||
222 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
223 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
224 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
225 | * @return the (partial) match object. | ||
226 | * | ||
227 | */ | ||
228 | public static ConnectedToNotSymmetric.Match newMatch(final Segment pS1, final Segment pS2) { | ||
229 | return new Immutable(pS1, pS2); | ||
230 | } | ||
231 | |||
232 | private static final class Mutable extends ConnectedToNotSymmetric.Match { | ||
233 | Mutable(final Segment pS1, final Segment pS2) { | ||
234 | super(pS1, pS2); | ||
235 | } | ||
236 | |||
237 | @Override | ||
238 | public boolean isMutable() { | ||
239 | return true; | ||
240 | } | ||
241 | } | ||
242 | |||
243 | private static final class Immutable extends ConnectedToNotSymmetric.Match { | ||
244 | Immutable(final Segment pS1, final Segment pS2) { | ||
245 | super(pS1, pS2); | ||
246 | } | ||
247 | |||
248 | @Override | ||
249 | public boolean isMutable() { | ||
250 | return false; | ||
251 | } | ||
252 | } | ||
253 | } | ||
254 | |||
255 | /** | ||
256 | * Generated pattern matcher API of the modes3.queries.connectedToNotSymmetric pattern, | ||
257 | * providing pattern-specific query methods. | ||
258 | * | ||
259 | * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, | ||
260 | * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. | ||
261 | * | ||
262 | * <p>Matches of the pattern will be represented as {@link Match}. | ||
263 | * | ||
264 | * <p>Original source: | ||
265 | * <code><pre> | ||
266 | * {@literal @}Constraint(message = "connectedToNotSymmetric", severity = "error", key = { S1, S2 }) | ||
267 | * pattern connectedToNotSymmetric(S1 : Segment, S2 : Segment) { | ||
268 | * Segment.connectedTo(S1, S2); | ||
269 | * neg find connectedTo(S2, S1); | ||
270 | * } | ||
271 | * </pre></code> | ||
272 | * | ||
273 | * @see Match | ||
274 | * @see ConnectedToNotSymmetric | ||
275 | * | ||
276 | */ | ||
277 | public static class Matcher extends BaseMatcher<ConnectedToNotSymmetric.Match> { | ||
278 | /** | ||
279 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
280 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
281 | * | ||
282 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
283 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
284 | * | ||
285 | */ | ||
286 | public static ConnectedToNotSymmetric.Matcher on(final ViatraQueryEngine engine) { | ||
287 | // check if matcher already exists | ||
288 | Matcher matcher = engine.getExistingMatcher(querySpecification()); | ||
289 | if (matcher == null) { | ||
290 | matcher = (Matcher)engine.getMatcher(querySpecification()); | ||
291 | } | ||
292 | return matcher; | ||
293 | } | ||
294 | |||
295 | /** | ||
296 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
297 | * @return an initialized matcher | ||
298 | * @noreference This method is for internal matcher initialization by the framework, do not call it manually. | ||
299 | * | ||
300 | */ | ||
301 | public static ConnectedToNotSymmetric.Matcher create() { | ||
302 | return new Matcher(); | ||
303 | } | ||
304 | |||
305 | private static final int POSITION_S1 = 0; | ||
306 | |||
307 | private static final int POSITION_S2 = 1; | ||
308 | |||
309 | private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(ConnectedToNotSymmetric.Matcher.class); | ||
310 | |||
311 | /** | ||
312 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
313 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
314 | * | ||
315 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
316 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
317 | * | ||
318 | */ | ||
319 | private Matcher() { | ||
320 | super(querySpecification()); | ||
321 | } | ||
322 | |||
323 | /** | ||
324 | * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. | ||
325 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
326 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
327 | * @return matches represented as a Match object. | ||
328 | * | ||
329 | */ | ||
330 | public Collection<ConnectedToNotSymmetric.Match> getAllMatches(final Segment pS1, final Segment pS2) { | ||
331 | return rawStreamAllMatches(new Object[]{pS1, pS2}).collect(Collectors.toSet()); | ||
332 | } | ||
333 | |||
334 | /** | ||
335 | * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. | ||
336 | * </p> | ||
337 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
338 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
339 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
340 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
341 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
342 | * @return a stream of matches represented as a Match object. | ||
343 | * | ||
344 | */ | ||
345 | public Stream<ConnectedToNotSymmetric.Match> streamAllMatches(final Segment pS1, final Segment pS2) { | ||
346 | return rawStreamAllMatches(new Object[]{pS1, pS2}); | ||
347 | } | ||
348 | |||
349 | /** | ||
350 | * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
351 | * Neither determinism nor randomness of selection is guaranteed. | ||
352 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
353 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
354 | * @return a match represented as a Match object, or null if no match is found. | ||
355 | * | ||
356 | */ | ||
357 | public Optional<ConnectedToNotSymmetric.Match> getOneArbitraryMatch(final Segment pS1, final Segment pS2) { | ||
358 | return rawGetOneArbitraryMatch(new Object[]{pS1, pS2}); | ||
359 | } | ||
360 | |||
361 | /** | ||
362 | * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, | ||
363 | * under any possible substitution of the unspecified parameters (if any). | ||
364 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
365 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
366 | * @return true if the input is a valid (partial) match of the pattern. | ||
367 | * | ||
368 | */ | ||
369 | public boolean hasMatch(final Segment pS1, final Segment pS2) { | ||
370 | return rawHasMatch(new Object[]{pS1, pS2}); | ||
371 | } | ||
372 | |||
373 | /** | ||
374 | * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. | ||
375 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
376 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
377 | * @return the number of pattern matches found. | ||
378 | * | ||
379 | */ | ||
380 | public int countMatches(final Segment pS1, final Segment pS2) { | ||
381 | return rawCountMatches(new Object[]{pS1, pS2}); | ||
382 | } | ||
383 | |||
384 | /** | ||
385 | * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
386 | * Neither determinism nor randomness of selection is guaranteed. | ||
387 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
388 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
389 | * @param processor the action that will process the selected match. | ||
390 | * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked | ||
391 | * | ||
392 | */ | ||
393 | public boolean forOneArbitraryMatch(final Segment pS1, final Segment pS2, final Consumer<? super ConnectedToNotSymmetric.Match> processor) { | ||
394 | return rawForOneArbitraryMatch(new Object[]{pS1, pS2}, processor); | ||
395 | } | ||
396 | |||
397 | /** | ||
398 | * Returns a new (partial) match. | ||
399 | * This can be used e.g. to call the matcher with a partial match. | ||
400 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
401 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
402 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
403 | * @return the (partial) match object. | ||
404 | * | ||
405 | */ | ||
406 | public ConnectedToNotSymmetric.Match newMatch(final Segment pS1, final Segment pS2) { | ||
407 | return ConnectedToNotSymmetric.Match.newMatch(pS1, pS2); | ||
408 | } | ||
409 | |||
410 | /** | ||
411 | * Retrieve the set of values that occur in matches for S1. | ||
412 | * @return the Set of all values or empty set if there are no matches | ||
413 | * | ||
414 | */ | ||
415 | protected Stream<Segment> rawStreamAllValuesOfS1(final Object[] parameters) { | ||
416 | return rawStreamAllValues(POSITION_S1, parameters).map(Segment.class::cast); | ||
417 | } | ||
418 | |||
419 | /** | ||
420 | * Retrieve the set of values that occur in matches for S1. | ||
421 | * @return the Set of all values or empty set if there are no matches | ||
422 | * | ||
423 | */ | ||
424 | public Set<Segment> getAllValuesOfS1() { | ||
425 | return rawStreamAllValuesOfS1(emptyArray()).collect(Collectors.toSet()); | ||
426 | } | ||
427 | |||
428 | /** | ||
429 | * Retrieve the set of values that occur in matches for S1. | ||
430 | * @return the Set of all values or empty set if there are no matches | ||
431 | * | ||
432 | */ | ||
433 | public Stream<Segment> streamAllValuesOfS1() { | ||
434 | return rawStreamAllValuesOfS1(emptyArray()); | ||
435 | } | ||
436 | |||
437 | /** | ||
438 | * Retrieve the set of values that occur in matches for S1. | ||
439 | * </p> | ||
440 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
441 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
442 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
443 | * | ||
444 | * @return the Stream of all values or empty set if there are no matches | ||
445 | * | ||
446 | */ | ||
447 | public Stream<Segment> streamAllValuesOfS1(final ConnectedToNotSymmetric.Match partialMatch) { | ||
448 | return rawStreamAllValuesOfS1(partialMatch.toArray()); | ||
449 | } | ||
450 | |||
451 | /** | ||
452 | * Retrieve the set of values that occur in matches for S1. | ||
453 | * </p> | ||
454 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
455 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
456 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
457 | * | ||
458 | * @return the Stream of all values or empty set if there are no matches | ||
459 | * | ||
460 | */ | ||
461 | public Stream<Segment> streamAllValuesOfS1(final Segment pS2) { | ||
462 | return rawStreamAllValuesOfS1(new Object[]{null, pS2}); | ||
463 | } | ||
464 | |||
465 | /** | ||
466 | * Retrieve the set of values that occur in matches for S1. | ||
467 | * @return the Set of all values or empty set if there are no matches | ||
468 | * | ||
469 | */ | ||
470 | public Set<Segment> getAllValuesOfS1(final ConnectedToNotSymmetric.Match partialMatch) { | ||
471 | return rawStreamAllValuesOfS1(partialMatch.toArray()).collect(Collectors.toSet()); | ||
472 | } | ||
473 | |||
474 | /** | ||
475 | * Retrieve the set of values that occur in matches for S1. | ||
476 | * @return the Set of all values or empty set if there are no matches | ||
477 | * | ||
478 | */ | ||
479 | public Set<Segment> getAllValuesOfS1(final Segment pS2) { | ||
480 | return rawStreamAllValuesOfS1(new Object[]{null, pS2}).collect(Collectors.toSet()); | ||
481 | } | ||
482 | |||
483 | /** | ||
484 | * Retrieve the set of values that occur in matches for S2. | ||
485 | * @return the Set of all values or empty set if there are no matches | ||
486 | * | ||
487 | */ | ||
488 | protected Stream<Segment> rawStreamAllValuesOfS2(final Object[] parameters) { | ||
489 | return rawStreamAllValues(POSITION_S2, parameters).map(Segment.class::cast); | ||
490 | } | ||
491 | |||
492 | /** | ||
493 | * Retrieve the set of values that occur in matches for S2. | ||
494 | * @return the Set of all values or empty set if there are no matches | ||
495 | * | ||
496 | */ | ||
497 | public Set<Segment> getAllValuesOfS2() { | ||
498 | return rawStreamAllValuesOfS2(emptyArray()).collect(Collectors.toSet()); | ||
499 | } | ||
500 | |||
501 | /** | ||
502 | * Retrieve the set of values that occur in matches for S2. | ||
503 | * @return the Set of all values or empty set if there are no matches | ||
504 | * | ||
505 | */ | ||
506 | public Stream<Segment> streamAllValuesOfS2() { | ||
507 | return rawStreamAllValuesOfS2(emptyArray()); | ||
508 | } | ||
509 | |||
510 | /** | ||
511 | * Retrieve the set of values that occur in matches for S2. | ||
512 | * </p> | ||
513 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
514 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
515 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
516 | * | ||
517 | * @return the Stream of all values or empty set if there are no matches | ||
518 | * | ||
519 | */ | ||
520 | public Stream<Segment> streamAllValuesOfS2(final ConnectedToNotSymmetric.Match partialMatch) { | ||
521 | return rawStreamAllValuesOfS2(partialMatch.toArray()); | ||
522 | } | ||
523 | |||
524 | /** | ||
525 | * Retrieve the set of values that occur in matches for S2. | ||
526 | * </p> | ||
527 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
528 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
529 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
530 | * | ||
531 | * @return the Stream of all values or empty set if there are no matches | ||
532 | * | ||
533 | */ | ||
534 | public Stream<Segment> streamAllValuesOfS2(final Segment pS1) { | ||
535 | return rawStreamAllValuesOfS2(new Object[]{pS1, null}); | ||
536 | } | ||
537 | |||
538 | /** | ||
539 | * Retrieve the set of values that occur in matches for S2. | ||
540 | * @return the Set of all values or empty set if there are no matches | ||
541 | * | ||
542 | */ | ||
543 | public Set<Segment> getAllValuesOfS2(final ConnectedToNotSymmetric.Match partialMatch) { | ||
544 | return rawStreamAllValuesOfS2(partialMatch.toArray()).collect(Collectors.toSet()); | ||
545 | } | ||
546 | |||
547 | /** | ||
548 | * Retrieve the set of values that occur in matches for S2. | ||
549 | * @return the Set of all values or empty set if there are no matches | ||
550 | * | ||
551 | */ | ||
552 | public Set<Segment> getAllValuesOfS2(final Segment pS1) { | ||
553 | return rawStreamAllValuesOfS2(new Object[]{pS1, null}).collect(Collectors.toSet()); | ||
554 | } | ||
555 | |||
556 | @Override | ||
557 | protected ConnectedToNotSymmetric.Match tupleToMatch(final Tuple t) { | ||
558 | try { | ||
559 | return ConnectedToNotSymmetric.Match.newMatch((Segment) t.get(POSITION_S1), (Segment) t.get(POSITION_S2)); | ||
560 | } catch(ClassCastException e) { | ||
561 | LOGGER.error("Element(s) in tuple not properly typed!",e); | ||
562 | return null; | ||
563 | } | ||
564 | } | ||
565 | |||
566 | @Override | ||
567 | protected ConnectedToNotSymmetric.Match arrayToMatch(final Object[] match) { | ||
568 | try { | ||
569 | return ConnectedToNotSymmetric.Match.newMatch((Segment) match[POSITION_S1], (Segment) match[POSITION_S2]); | ||
570 | } catch(ClassCastException e) { | ||
571 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
572 | return null; | ||
573 | } | ||
574 | } | ||
575 | |||
576 | @Override | ||
577 | protected ConnectedToNotSymmetric.Match arrayToMatchMutable(final Object[] match) { | ||
578 | try { | ||
579 | return ConnectedToNotSymmetric.Match.newMutableMatch((Segment) match[POSITION_S1], (Segment) match[POSITION_S2]); | ||
580 | } catch(ClassCastException e) { | ||
581 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
582 | return null; | ||
583 | } | ||
584 | } | ||
585 | |||
586 | /** | ||
587 | * @return the singleton instance of the query specification of this pattern | ||
588 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
589 | * | ||
590 | */ | ||
591 | public static IQuerySpecification<ConnectedToNotSymmetric.Matcher> querySpecification() { | ||
592 | return ConnectedToNotSymmetric.instance(); | ||
593 | } | ||
594 | } | ||
595 | |||
596 | private ConnectedToNotSymmetric() { | ||
597 | super(GeneratedPQuery.INSTANCE); | ||
598 | } | ||
599 | |||
600 | /** | ||
601 | * @return the singleton instance of the query specification | ||
602 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
603 | * | ||
604 | */ | ||
605 | public static ConnectedToNotSymmetric instance() { | ||
606 | try{ | ||
607 | return LazyHolder.INSTANCE; | ||
608 | } catch (ExceptionInInitializerError err) { | ||
609 | throw processInitializerError(err); | ||
610 | } | ||
611 | } | ||
612 | |||
613 | @Override | ||
614 | protected ConnectedToNotSymmetric.Matcher instantiate(final ViatraQueryEngine engine) { | ||
615 | return ConnectedToNotSymmetric.Matcher.on(engine); | ||
616 | } | ||
617 | |||
618 | @Override | ||
619 | public ConnectedToNotSymmetric.Matcher instantiate() { | ||
620 | return ConnectedToNotSymmetric.Matcher.create(); | ||
621 | } | ||
622 | |||
623 | @Override | ||
624 | public ConnectedToNotSymmetric.Match newEmptyMatch() { | ||
625 | return ConnectedToNotSymmetric.Match.newEmptyMatch(); | ||
626 | } | ||
627 | |||
628 | @Override | ||
629 | public ConnectedToNotSymmetric.Match newMatch(final Object... parameters) { | ||
630 | return ConnectedToNotSymmetric.Match.newMatch((modes3.Segment) parameters[0], (modes3.Segment) parameters[1]); | ||
631 | } | ||
632 | |||
633 | /** | ||
634 | * Inner class allowing the singleton instance of {@link ConnectedToNotSymmetric} to be created | ||
635 | * <b>not</b> at the class load time of the outer class, | ||
636 | * but rather at the first call to {@link ConnectedToNotSymmetric#instance()}. | ||
637 | * | ||
638 | * <p> This workaround is required e.g. to support recursion. | ||
639 | * | ||
640 | */ | ||
641 | private static class LazyHolder { | ||
642 | private static final ConnectedToNotSymmetric INSTANCE = new ConnectedToNotSymmetric(); | ||
643 | |||
644 | /** | ||
645 | * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned. | ||
646 | * This initialization order is required to support indirect recursion. | ||
647 | * | ||
648 | * <p> The static initializer is defined using a helper field to work around limitations of the code generator. | ||
649 | * | ||
650 | */ | ||
651 | private static final Object STATIC_INITIALIZER = ensureInitialized(); | ||
652 | |||
653 | public static Object ensureInitialized() { | ||
654 | INSTANCE.ensureInitializedInternal(); | ||
655 | return null; | ||
656 | } | ||
657 | } | ||
658 | |||
659 | private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { | ||
660 | private static final ConnectedToNotSymmetric.GeneratedPQuery INSTANCE = new GeneratedPQuery(); | ||
661 | |||
662 | private final PParameter parameter_S1 = new PParameter("S1", "modes3.Segment", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Segment")), PParameterDirection.INOUT); | ||
663 | |||
664 | private final PParameter parameter_S2 = new PParameter("S2", "modes3.Segment", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Segment")), PParameterDirection.INOUT); | ||
665 | |||
666 | private final List<PParameter> parameters = Arrays.asList(parameter_S1, parameter_S2); | ||
667 | |||
668 | private GeneratedPQuery() { | ||
669 | super(PVisibility.PUBLIC); | ||
670 | } | ||
671 | |||
672 | @Override | ||
673 | public String getFullyQualifiedName() { | ||
674 | return "modes3.queries.connectedToNotSymmetric"; | ||
675 | } | ||
676 | |||
677 | @Override | ||
678 | public List<String> getParameterNames() { | ||
679 | return Arrays.asList("S1","S2"); | ||
680 | } | ||
681 | |||
682 | @Override | ||
683 | public List<PParameter> getParameters() { | ||
684 | return parameters; | ||
685 | } | ||
686 | |||
687 | @Override | ||
688 | public Set<PBody> doGetContainedBodies() { | ||
689 | setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); | ||
690 | Set<PBody> bodies = new LinkedHashSet<>(); | ||
691 | { | ||
692 | PBody body = new PBody(this); | ||
693 | PVariable var_S1 = body.getOrCreateVariableByName("S1"); | ||
694 | PVariable var_S2 = body.getOrCreateVariableByName("S2"); | ||
695 | new TypeConstraint(body, Tuples.flatTupleOf(var_S1), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
696 | new TypeConstraint(body, Tuples.flatTupleOf(var_S2), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
697 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
698 | new ExportedParameter(body, var_S1, parameter_S1), | ||
699 | new ExportedParameter(body, var_S2, parameter_S2) | ||
700 | )); | ||
701 | // Segment.connectedTo(S1, S2) | ||
702 | new TypeConstraint(body, Tuples.flatTupleOf(var_S1), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
703 | PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); | ||
704 | new TypeConstraint(body, Tuples.flatTupleOf(var_S1, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment", "connectedTo"))); | ||
705 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
706 | new Equality(body, var__virtual_0_, var_S2); | ||
707 | // neg find connectedTo(S2, S1) | ||
708 | new NegativePatternCall(body, Tuples.flatTupleOf(var_S2, var_S1), ConnectedTo.instance().getInternalQueryRepresentation()); | ||
709 | bodies.add(body); | ||
710 | } | ||
711 | { | ||
712 | PAnnotation annotation = new PAnnotation("Constraint"); | ||
713 | annotation.addAttribute("message", "connectedToNotSymmetric"); | ||
714 | annotation.addAttribute("severity", "error"); | ||
715 | annotation.addAttribute("key", Arrays.asList(new Object[] { | ||
716 | new ParameterReference("S1"), | ||
717 | new ParameterReference("S2") | ||
718 | })); | ||
719 | addAnnotation(annotation); | ||
720 | } | ||
721 | return bodies; | ||
722 | } | ||
723 | } | ||
724 | } | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/ConnectedToReflexive.java b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/ConnectedToReflexive.java new file mode 100644 index 00000000..948fec73 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/ConnectedToReflexive.java | |||
@@ -0,0 +1,563 @@ | |||
1 | /** | ||
2 | * Generated from platform:/resource/ca.mcgill.rtgmrt.example.modes3/src/modes3/queries/Modes3Queries.vql | ||
3 | */ | ||
4 | package modes3.queries; | ||
5 | |||
6 | import java.util.Arrays; | ||
7 | import java.util.Collection; | ||
8 | import java.util.LinkedHashSet; | ||
9 | import java.util.List; | ||
10 | import java.util.Objects; | ||
11 | import java.util.Optional; | ||
12 | import java.util.Set; | ||
13 | import java.util.function.Consumer; | ||
14 | import java.util.stream.Collectors; | ||
15 | import java.util.stream.Stream; | ||
16 | import modes3.Segment; | ||
17 | import org.apache.log4j.Logger; | ||
18 | import org.eclipse.emf.ecore.EClass; | ||
19 | import org.eclipse.viatra.query.runtime.api.IPatternMatch; | ||
20 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification; | ||
21 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; | ||
22 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; | ||
23 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; | ||
24 | import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; | ||
25 | import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; | ||
26 | import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; | ||
27 | import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; | ||
28 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
29 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | ||
30 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | ||
31 | import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation; | ||
32 | import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference; | ||
33 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; | ||
34 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
35 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
36 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | ||
37 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; | ||
38 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | ||
39 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; | ||
40 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
41 | import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; | ||
42 | |||
43 | /** | ||
44 | * A pattern-specific query specification that can instantiate Matcher in a type-safe way. | ||
45 | * | ||
46 | * <p>Original source: | ||
47 | * <code><pre> | ||
48 | * {@literal @}Constraint(message = "connectedToReflexive", severity = "error", key = { S }) | ||
49 | * pattern connectedToReflexive(S : Segment) { | ||
50 | * Segment.connectedTo(S, S); | ||
51 | * } | ||
52 | * </pre></code> | ||
53 | * | ||
54 | * @see Matcher | ||
55 | * @see Match | ||
56 | * | ||
57 | */ | ||
58 | @SuppressWarnings("all") | ||
59 | public final class ConnectedToReflexive extends BaseGeneratedEMFQuerySpecification<ConnectedToReflexive.Matcher> { | ||
60 | /** | ||
61 | * Pattern-specific match representation of the modes3.queries.connectedToReflexive pattern, | ||
62 | * to be used in conjunction with {@link Matcher}. | ||
63 | * | ||
64 | * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. | ||
65 | * Each instance is a (possibly partial) substitution of pattern parameters, | ||
66 | * usable to represent a match of the pattern in the result of a query, | ||
67 | * or to specify the bound (fixed) input parameters when issuing a query. | ||
68 | * | ||
69 | * @see Matcher | ||
70 | * | ||
71 | */ | ||
72 | public static abstract class Match extends BasePatternMatch { | ||
73 | private Segment fS; | ||
74 | |||
75 | private static List<String> parameterNames = makeImmutableList("S"); | ||
76 | |||
77 | private Match(final Segment pS) { | ||
78 | this.fS = pS; | ||
79 | } | ||
80 | |||
81 | @Override | ||
82 | public Object get(final String parameterName) { | ||
83 | switch(parameterName) { | ||
84 | case "S": return this.fS; | ||
85 | default: return null; | ||
86 | } | ||
87 | } | ||
88 | |||
89 | @Override | ||
90 | public Object get(final int index) { | ||
91 | switch(index) { | ||
92 | case 0: return this.fS; | ||
93 | default: return null; | ||
94 | } | ||
95 | } | ||
96 | |||
97 | public Segment getS() { | ||
98 | return this.fS; | ||
99 | } | ||
100 | |||
101 | @Override | ||
102 | public boolean set(final String parameterName, final Object newValue) { | ||
103 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
104 | if ("S".equals(parameterName) ) { | ||
105 | this.fS = (Segment) newValue; | ||
106 | return true; | ||
107 | } | ||
108 | return false; | ||
109 | } | ||
110 | |||
111 | public void setS(final Segment pS) { | ||
112 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
113 | this.fS = pS; | ||
114 | } | ||
115 | |||
116 | @Override | ||
117 | public String patternName() { | ||
118 | return "modes3.queries.connectedToReflexive"; | ||
119 | } | ||
120 | |||
121 | @Override | ||
122 | public List<String> parameterNames() { | ||
123 | return ConnectedToReflexive.Match.parameterNames; | ||
124 | } | ||
125 | |||
126 | @Override | ||
127 | public Object[] toArray() { | ||
128 | return new Object[]{fS}; | ||
129 | } | ||
130 | |||
131 | @Override | ||
132 | public ConnectedToReflexive.Match toImmutable() { | ||
133 | return isMutable() ? newMatch(fS) : this; | ||
134 | } | ||
135 | |||
136 | @Override | ||
137 | public String prettyPrint() { | ||
138 | StringBuilder result = new StringBuilder(); | ||
139 | result.append("\"S\"=" + prettyPrintValue(fS)); | ||
140 | return result.toString(); | ||
141 | } | ||
142 | |||
143 | @Override | ||
144 | public int hashCode() { | ||
145 | return Objects.hash(fS); | ||
146 | } | ||
147 | |||
148 | @Override | ||
149 | public boolean equals(final Object obj) { | ||
150 | if (this == obj) | ||
151 | return true; | ||
152 | if (obj == null) { | ||
153 | return false; | ||
154 | } | ||
155 | if ((obj instanceof ConnectedToReflexive.Match)) { | ||
156 | ConnectedToReflexive.Match other = (ConnectedToReflexive.Match) obj; | ||
157 | return Objects.equals(fS, other.fS); | ||
158 | } else { | ||
159 | // this should be infrequent | ||
160 | if (!(obj instanceof IPatternMatch)) { | ||
161 | return false; | ||
162 | } | ||
163 | IPatternMatch otherSig = (IPatternMatch) obj; | ||
164 | return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); | ||
165 | } | ||
166 | } | ||
167 | |||
168 | @Override | ||
169 | public ConnectedToReflexive specification() { | ||
170 | return ConnectedToReflexive.instance(); | ||
171 | } | ||
172 | |||
173 | /** | ||
174 | * Returns an empty, mutable match. | ||
175 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
176 | * | ||
177 | * @return the empty match. | ||
178 | * | ||
179 | */ | ||
180 | public static ConnectedToReflexive.Match newEmptyMatch() { | ||
181 | return new Mutable(null); | ||
182 | } | ||
183 | |||
184 | /** | ||
185 | * Returns a mutable (partial) match. | ||
186 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
187 | * | ||
188 | * @param pS the fixed value of pattern parameter S, or null if not bound. | ||
189 | * @return the new, mutable (partial) match object. | ||
190 | * | ||
191 | */ | ||
192 | public static ConnectedToReflexive.Match newMutableMatch(final Segment pS) { | ||
193 | return new Mutable(pS); | ||
194 | } | ||
195 | |||
196 | /** | ||
197 | * Returns a new (partial) match. | ||
198 | * This can be used e.g. to call the matcher with a partial match. | ||
199 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
200 | * @param pS the fixed value of pattern parameter S, or null if not bound. | ||
201 | * @return the (partial) match object. | ||
202 | * | ||
203 | */ | ||
204 | public static ConnectedToReflexive.Match newMatch(final Segment pS) { | ||
205 | return new Immutable(pS); | ||
206 | } | ||
207 | |||
208 | private static final class Mutable extends ConnectedToReflexive.Match { | ||
209 | Mutable(final Segment pS) { | ||
210 | super(pS); | ||
211 | } | ||
212 | |||
213 | @Override | ||
214 | public boolean isMutable() { | ||
215 | return true; | ||
216 | } | ||
217 | } | ||
218 | |||
219 | private static final class Immutable extends ConnectedToReflexive.Match { | ||
220 | Immutable(final Segment pS) { | ||
221 | super(pS); | ||
222 | } | ||
223 | |||
224 | @Override | ||
225 | public boolean isMutable() { | ||
226 | return false; | ||
227 | } | ||
228 | } | ||
229 | } | ||
230 | |||
231 | /** | ||
232 | * Generated pattern matcher API of the modes3.queries.connectedToReflexive pattern, | ||
233 | * providing pattern-specific query methods. | ||
234 | * | ||
235 | * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, | ||
236 | * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. | ||
237 | * | ||
238 | * <p>Matches of the pattern will be represented as {@link Match}. | ||
239 | * | ||
240 | * <p>Original source: | ||
241 | * <code><pre> | ||
242 | * {@literal @}Constraint(message = "connectedToReflexive", severity = "error", key = { S }) | ||
243 | * pattern connectedToReflexive(S : Segment) { | ||
244 | * Segment.connectedTo(S, S); | ||
245 | * } | ||
246 | * </pre></code> | ||
247 | * | ||
248 | * @see Match | ||
249 | * @see ConnectedToReflexive | ||
250 | * | ||
251 | */ | ||
252 | public static class Matcher extends BaseMatcher<ConnectedToReflexive.Match> { | ||
253 | /** | ||
254 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
255 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
256 | * | ||
257 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
258 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
259 | * | ||
260 | */ | ||
261 | public static ConnectedToReflexive.Matcher on(final ViatraQueryEngine engine) { | ||
262 | // check if matcher already exists | ||
263 | Matcher matcher = engine.getExistingMatcher(querySpecification()); | ||
264 | if (matcher == null) { | ||
265 | matcher = (Matcher)engine.getMatcher(querySpecification()); | ||
266 | } | ||
267 | return matcher; | ||
268 | } | ||
269 | |||
270 | /** | ||
271 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
272 | * @return an initialized matcher | ||
273 | * @noreference This method is for internal matcher initialization by the framework, do not call it manually. | ||
274 | * | ||
275 | */ | ||
276 | public static ConnectedToReflexive.Matcher create() { | ||
277 | return new Matcher(); | ||
278 | } | ||
279 | |||
280 | private static final int POSITION_S = 0; | ||
281 | |||
282 | private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(ConnectedToReflexive.Matcher.class); | ||
283 | |||
284 | /** | ||
285 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
286 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
287 | * | ||
288 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
289 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
290 | * | ||
291 | */ | ||
292 | private Matcher() { | ||
293 | super(querySpecification()); | ||
294 | } | ||
295 | |||
296 | /** | ||
297 | * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. | ||
298 | * @param pS the fixed value of pattern parameter S, or null if not bound. | ||
299 | * @return matches represented as a Match object. | ||
300 | * | ||
301 | */ | ||
302 | public Collection<ConnectedToReflexive.Match> getAllMatches(final Segment pS) { | ||
303 | return rawStreamAllMatches(new Object[]{pS}).collect(Collectors.toSet()); | ||
304 | } | ||
305 | |||
306 | /** | ||
307 | * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. | ||
308 | * </p> | ||
309 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
310 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
311 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
312 | * @param pS the fixed value of pattern parameter S, or null if not bound. | ||
313 | * @return a stream of matches represented as a Match object. | ||
314 | * | ||
315 | */ | ||
316 | public Stream<ConnectedToReflexive.Match> streamAllMatches(final Segment pS) { | ||
317 | return rawStreamAllMatches(new Object[]{pS}); | ||
318 | } | ||
319 | |||
320 | /** | ||
321 | * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
322 | * Neither determinism nor randomness of selection is guaranteed. | ||
323 | * @param pS the fixed value of pattern parameter S, or null if not bound. | ||
324 | * @return a match represented as a Match object, or null if no match is found. | ||
325 | * | ||
326 | */ | ||
327 | public Optional<ConnectedToReflexive.Match> getOneArbitraryMatch(final Segment pS) { | ||
328 | return rawGetOneArbitraryMatch(new Object[]{pS}); | ||
329 | } | ||
330 | |||
331 | /** | ||
332 | * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, | ||
333 | * under any possible substitution of the unspecified parameters (if any). | ||
334 | * @param pS the fixed value of pattern parameter S, or null if not bound. | ||
335 | * @return true if the input is a valid (partial) match of the pattern. | ||
336 | * | ||
337 | */ | ||
338 | public boolean hasMatch(final Segment pS) { | ||
339 | return rawHasMatch(new Object[]{pS}); | ||
340 | } | ||
341 | |||
342 | /** | ||
343 | * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. | ||
344 | * @param pS the fixed value of pattern parameter S, or null if not bound. | ||
345 | * @return the number of pattern matches found. | ||
346 | * | ||
347 | */ | ||
348 | public int countMatches(final Segment pS) { | ||
349 | return rawCountMatches(new Object[]{pS}); | ||
350 | } | ||
351 | |||
352 | /** | ||
353 | * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
354 | * Neither determinism nor randomness of selection is guaranteed. | ||
355 | * @param pS the fixed value of pattern parameter S, or null if not bound. | ||
356 | * @param processor the action that will process the selected match. | ||
357 | * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked | ||
358 | * | ||
359 | */ | ||
360 | public boolean forOneArbitraryMatch(final Segment pS, final Consumer<? super ConnectedToReflexive.Match> processor) { | ||
361 | return rawForOneArbitraryMatch(new Object[]{pS}, processor); | ||
362 | } | ||
363 | |||
364 | /** | ||
365 | * Returns a new (partial) match. | ||
366 | * This can be used e.g. to call the matcher with a partial match. | ||
367 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
368 | * @param pS the fixed value of pattern parameter S, or null if not bound. | ||
369 | * @return the (partial) match object. | ||
370 | * | ||
371 | */ | ||
372 | public ConnectedToReflexive.Match newMatch(final Segment pS) { | ||
373 | return ConnectedToReflexive.Match.newMatch(pS); | ||
374 | } | ||
375 | |||
376 | /** | ||
377 | * Retrieve the set of values that occur in matches for S. | ||
378 | * @return the Set of all values or empty set if there are no matches | ||
379 | * | ||
380 | */ | ||
381 | protected Stream<Segment> rawStreamAllValuesOfS(final Object[] parameters) { | ||
382 | return rawStreamAllValues(POSITION_S, parameters).map(Segment.class::cast); | ||
383 | } | ||
384 | |||
385 | /** | ||
386 | * Retrieve the set of values that occur in matches for S. | ||
387 | * @return the Set of all values or empty set if there are no matches | ||
388 | * | ||
389 | */ | ||
390 | public Set<Segment> getAllValuesOfS() { | ||
391 | return rawStreamAllValuesOfS(emptyArray()).collect(Collectors.toSet()); | ||
392 | } | ||
393 | |||
394 | /** | ||
395 | * Retrieve the set of values that occur in matches for S. | ||
396 | * @return the Set of all values or empty set if there are no matches | ||
397 | * | ||
398 | */ | ||
399 | public Stream<Segment> streamAllValuesOfS() { | ||
400 | return rawStreamAllValuesOfS(emptyArray()); | ||
401 | } | ||
402 | |||
403 | @Override | ||
404 | protected ConnectedToReflexive.Match tupleToMatch(final Tuple t) { | ||
405 | try { | ||
406 | return ConnectedToReflexive.Match.newMatch((Segment) t.get(POSITION_S)); | ||
407 | } catch(ClassCastException e) { | ||
408 | LOGGER.error("Element(s) in tuple not properly typed!",e); | ||
409 | return null; | ||
410 | } | ||
411 | } | ||
412 | |||
413 | @Override | ||
414 | protected ConnectedToReflexive.Match arrayToMatch(final Object[] match) { | ||
415 | try { | ||
416 | return ConnectedToReflexive.Match.newMatch((Segment) match[POSITION_S]); | ||
417 | } catch(ClassCastException e) { | ||
418 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
419 | return null; | ||
420 | } | ||
421 | } | ||
422 | |||
423 | @Override | ||
424 | protected ConnectedToReflexive.Match arrayToMatchMutable(final Object[] match) { | ||
425 | try { | ||
426 | return ConnectedToReflexive.Match.newMutableMatch((Segment) match[POSITION_S]); | ||
427 | } catch(ClassCastException e) { | ||
428 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
429 | return null; | ||
430 | } | ||
431 | } | ||
432 | |||
433 | /** | ||
434 | * @return the singleton instance of the query specification of this pattern | ||
435 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
436 | * | ||
437 | */ | ||
438 | public static IQuerySpecification<ConnectedToReflexive.Matcher> querySpecification() { | ||
439 | return ConnectedToReflexive.instance(); | ||
440 | } | ||
441 | } | ||
442 | |||
443 | private ConnectedToReflexive() { | ||
444 | super(GeneratedPQuery.INSTANCE); | ||
445 | } | ||
446 | |||
447 | /** | ||
448 | * @return the singleton instance of the query specification | ||
449 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
450 | * | ||
451 | */ | ||
452 | public static ConnectedToReflexive instance() { | ||
453 | try{ | ||
454 | return LazyHolder.INSTANCE; | ||
455 | } catch (ExceptionInInitializerError err) { | ||
456 | throw processInitializerError(err); | ||
457 | } | ||
458 | } | ||
459 | |||
460 | @Override | ||
461 | protected ConnectedToReflexive.Matcher instantiate(final ViatraQueryEngine engine) { | ||
462 | return ConnectedToReflexive.Matcher.on(engine); | ||
463 | } | ||
464 | |||
465 | @Override | ||
466 | public ConnectedToReflexive.Matcher instantiate() { | ||
467 | return ConnectedToReflexive.Matcher.create(); | ||
468 | } | ||
469 | |||
470 | @Override | ||
471 | public ConnectedToReflexive.Match newEmptyMatch() { | ||
472 | return ConnectedToReflexive.Match.newEmptyMatch(); | ||
473 | } | ||
474 | |||
475 | @Override | ||
476 | public ConnectedToReflexive.Match newMatch(final Object... parameters) { | ||
477 | return ConnectedToReflexive.Match.newMatch((modes3.Segment) parameters[0]); | ||
478 | } | ||
479 | |||
480 | /** | ||
481 | * Inner class allowing the singleton instance of {@link ConnectedToReflexive} to be created | ||
482 | * <b>not</b> at the class load time of the outer class, | ||
483 | * but rather at the first call to {@link ConnectedToReflexive#instance()}. | ||
484 | * | ||
485 | * <p> This workaround is required e.g. to support recursion. | ||
486 | * | ||
487 | */ | ||
488 | private static class LazyHolder { | ||
489 | private static final ConnectedToReflexive INSTANCE = new ConnectedToReflexive(); | ||
490 | |||
491 | /** | ||
492 | * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned. | ||
493 | * This initialization order is required to support indirect recursion. | ||
494 | * | ||
495 | * <p> The static initializer is defined using a helper field to work around limitations of the code generator. | ||
496 | * | ||
497 | */ | ||
498 | private static final Object STATIC_INITIALIZER = ensureInitialized(); | ||
499 | |||
500 | public static Object ensureInitialized() { | ||
501 | INSTANCE.ensureInitializedInternal(); | ||
502 | return null; | ||
503 | } | ||
504 | } | ||
505 | |||
506 | private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { | ||
507 | private static final ConnectedToReflexive.GeneratedPQuery INSTANCE = new GeneratedPQuery(); | ||
508 | |||
509 | private final PParameter parameter_S = new PParameter("S", "modes3.Segment", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Segment")), PParameterDirection.INOUT); | ||
510 | |||
511 | private final List<PParameter> parameters = Arrays.asList(parameter_S); | ||
512 | |||
513 | private GeneratedPQuery() { | ||
514 | super(PVisibility.PUBLIC); | ||
515 | } | ||
516 | |||
517 | @Override | ||
518 | public String getFullyQualifiedName() { | ||
519 | return "modes3.queries.connectedToReflexive"; | ||
520 | } | ||
521 | |||
522 | @Override | ||
523 | public List<String> getParameterNames() { | ||
524 | return Arrays.asList("S"); | ||
525 | } | ||
526 | |||
527 | @Override | ||
528 | public List<PParameter> getParameters() { | ||
529 | return parameters; | ||
530 | } | ||
531 | |||
532 | @Override | ||
533 | public Set<PBody> doGetContainedBodies() { | ||
534 | setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); | ||
535 | Set<PBody> bodies = new LinkedHashSet<>(); | ||
536 | { | ||
537 | PBody body = new PBody(this); | ||
538 | PVariable var_S = body.getOrCreateVariableByName("S"); | ||
539 | new TypeConstraint(body, Tuples.flatTupleOf(var_S), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
540 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
541 | new ExportedParameter(body, var_S, parameter_S) | ||
542 | )); | ||
543 | // Segment.connectedTo(S, S) | ||
544 | new TypeConstraint(body, Tuples.flatTupleOf(var_S), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
545 | PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); | ||
546 | new TypeConstraint(body, Tuples.flatTupleOf(var_S, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment", "connectedTo"))); | ||
547 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
548 | new Equality(body, var__virtual_0_, var_S); | ||
549 | bodies.add(body); | ||
550 | } | ||
551 | { | ||
552 | PAnnotation annotation = new PAnnotation("Constraint"); | ||
553 | annotation.addAttribute("message", "connectedToReflexive"); | ||
554 | annotation.addAttribute("severity", "error"); | ||
555 | annotation.addAttribute("key", Arrays.asList(new Object[] { | ||
556 | new ParameterReference("S") | ||
557 | })); | ||
558 | addAnnotation(annotation); | ||
559 | } | ||
560 | return bodies; | ||
561 | } | ||
562 | } | ||
563 | } | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/EndOfSiding_step_2.java b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/EndOfSiding_step_2.java new file mode 100644 index 00000000..a8f68dca --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/EndOfSiding_step_2.java | |||
@@ -0,0 +1,564 @@ | |||
1 | /** | ||
2 | * Generated from platform:/resource/ca.mcgill.rtgmrt.example.modes3/src/modes3/queries/Modes3Queries.vql | ||
3 | */ | ||
4 | package modes3.queries; | ||
5 | |||
6 | import java.util.Arrays; | ||
7 | import java.util.Collection; | ||
8 | import java.util.LinkedHashSet; | ||
9 | import java.util.List; | ||
10 | import java.util.Objects; | ||
11 | import java.util.Optional; | ||
12 | import java.util.Set; | ||
13 | import java.util.function.Consumer; | ||
14 | import java.util.stream.Collectors; | ||
15 | import java.util.stream.Stream; | ||
16 | import modes3.Train; | ||
17 | import org.apache.log4j.Logger; | ||
18 | import org.eclipse.emf.ecore.EClass; | ||
19 | import org.eclipse.viatra.query.runtime.api.IPatternMatch; | ||
20 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification; | ||
21 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; | ||
22 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; | ||
23 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; | ||
24 | import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; | ||
25 | import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; | ||
26 | import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; | ||
27 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
28 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | ||
29 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | ||
30 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
31 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
32 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | ||
33 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; | ||
34 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | ||
35 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; | ||
36 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
37 | import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; | ||
38 | |||
39 | /** | ||
40 | * A pattern-specific query specification that can instantiate Matcher in a type-safe way. | ||
41 | * | ||
42 | * <p>Original source: | ||
43 | * <code><pre> | ||
44 | * // | ||
45 | * // endOfSiding | ||
46 | * // | ||
47 | * | ||
48 | * pattern endOfSiding_step_2(in train : Train) { | ||
49 | * // frame-{@literal >}train = model-{@literal >}trains[i0]; | ||
50 | * // frame-{@literal >}location = frame-{@literal >}train-{@literal >}location; | ||
51 | * // if (frame-{@literal >}location != NULL) { | ||
52 | * // ... | ||
53 | * // } | ||
54 | * | ||
55 | * Train(train); | ||
56 | * } | ||
57 | * </pre></code> | ||
58 | * | ||
59 | * @see Matcher | ||
60 | * @see Match | ||
61 | * | ||
62 | */ | ||
63 | @SuppressWarnings("all") | ||
64 | public final class EndOfSiding_step_2 extends BaseGeneratedEMFQuerySpecification<EndOfSiding_step_2.Matcher> { | ||
65 | /** | ||
66 | * Pattern-specific match representation of the modes3.queries.endOfSiding_step_2 pattern, | ||
67 | * to be used in conjunction with {@link Matcher}. | ||
68 | * | ||
69 | * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. | ||
70 | * Each instance is a (possibly partial) substitution of pattern parameters, | ||
71 | * usable to represent a match of the pattern in the result of a query, | ||
72 | * or to specify the bound (fixed) input parameters when issuing a query. | ||
73 | * | ||
74 | * @see Matcher | ||
75 | * | ||
76 | */ | ||
77 | public static abstract class Match extends BasePatternMatch { | ||
78 | private Train fTrain; | ||
79 | |||
80 | private static List<String> parameterNames = makeImmutableList("train"); | ||
81 | |||
82 | private Match(final Train pTrain) { | ||
83 | this.fTrain = pTrain; | ||
84 | } | ||
85 | |||
86 | @Override | ||
87 | public Object get(final String parameterName) { | ||
88 | switch(parameterName) { | ||
89 | case "train": return this.fTrain; | ||
90 | default: return null; | ||
91 | } | ||
92 | } | ||
93 | |||
94 | @Override | ||
95 | public Object get(final int index) { | ||
96 | switch(index) { | ||
97 | case 0: return this.fTrain; | ||
98 | default: return null; | ||
99 | } | ||
100 | } | ||
101 | |||
102 | public Train getTrain() { | ||
103 | return this.fTrain; | ||
104 | } | ||
105 | |||
106 | @Override | ||
107 | public boolean set(final String parameterName, final Object newValue) { | ||
108 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
109 | if ("train".equals(parameterName) ) { | ||
110 | this.fTrain = (Train) newValue; | ||
111 | return true; | ||
112 | } | ||
113 | return false; | ||
114 | } | ||
115 | |||
116 | public void setTrain(final Train pTrain) { | ||
117 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
118 | this.fTrain = pTrain; | ||
119 | } | ||
120 | |||
121 | @Override | ||
122 | public String patternName() { | ||
123 | return "modes3.queries.endOfSiding_step_2"; | ||
124 | } | ||
125 | |||
126 | @Override | ||
127 | public List<String> parameterNames() { | ||
128 | return EndOfSiding_step_2.Match.parameterNames; | ||
129 | } | ||
130 | |||
131 | @Override | ||
132 | public Object[] toArray() { | ||
133 | return new Object[]{fTrain}; | ||
134 | } | ||
135 | |||
136 | @Override | ||
137 | public EndOfSiding_step_2.Match toImmutable() { | ||
138 | return isMutable() ? newMatch(fTrain) : this; | ||
139 | } | ||
140 | |||
141 | @Override | ||
142 | public String prettyPrint() { | ||
143 | StringBuilder result = new StringBuilder(); | ||
144 | result.append("\"train\"=" + prettyPrintValue(fTrain)); | ||
145 | return result.toString(); | ||
146 | } | ||
147 | |||
148 | @Override | ||
149 | public int hashCode() { | ||
150 | return Objects.hash(fTrain); | ||
151 | } | ||
152 | |||
153 | @Override | ||
154 | public boolean equals(final Object obj) { | ||
155 | if (this == obj) | ||
156 | return true; | ||
157 | if (obj == null) { | ||
158 | return false; | ||
159 | } | ||
160 | if ((obj instanceof EndOfSiding_step_2.Match)) { | ||
161 | EndOfSiding_step_2.Match other = (EndOfSiding_step_2.Match) obj; | ||
162 | return Objects.equals(fTrain, other.fTrain); | ||
163 | } else { | ||
164 | // this should be infrequent | ||
165 | if (!(obj instanceof IPatternMatch)) { | ||
166 | return false; | ||
167 | } | ||
168 | IPatternMatch otherSig = (IPatternMatch) obj; | ||
169 | return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); | ||
170 | } | ||
171 | } | ||
172 | |||
173 | @Override | ||
174 | public EndOfSiding_step_2 specification() { | ||
175 | return EndOfSiding_step_2.instance(); | ||
176 | } | ||
177 | |||
178 | /** | ||
179 | * Returns an empty, mutable match. | ||
180 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
181 | * | ||
182 | * @return the empty match. | ||
183 | * | ||
184 | */ | ||
185 | public static EndOfSiding_step_2.Match newEmptyMatch() { | ||
186 | return new Mutable(null); | ||
187 | } | ||
188 | |||
189 | /** | ||
190 | * Returns a mutable (partial) match. | ||
191 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
192 | * | ||
193 | * @param pTrain the fixed value of pattern parameter train, or null if not bound. | ||
194 | * @return the new, mutable (partial) match object. | ||
195 | * | ||
196 | */ | ||
197 | public static EndOfSiding_step_2.Match newMutableMatch(final Train pTrain) { | ||
198 | return new Mutable(pTrain); | ||
199 | } | ||
200 | |||
201 | /** | ||
202 | * Returns a new (partial) match. | ||
203 | * This can be used e.g. to call the matcher with a partial match. | ||
204 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
205 | * @param pTrain the fixed value of pattern parameter train, or null if not bound. | ||
206 | * @return the (partial) match object. | ||
207 | * | ||
208 | */ | ||
209 | public static EndOfSiding_step_2.Match newMatch(final Train pTrain) { | ||
210 | return new Immutable(pTrain); | ||
211 | } | ||
212 | |||
213 | private static final class Mutable extends EndOfSiding_step_2.Match { | ||
214 | Mutable(final Train pTrain) { | ||
215 | super(pTrain); | ||
216 | } | ||
217 | |||
218 | @Override | ||
219 | public boolean isMutable() { | ||
220 | return true; | ||
221 | } | ||
222 | } | ||
223 | |||
224 | private static final class Immutable extends EndOfSiding_step_2.Match { | ||
225 | Immutable(final Train pTrain) { | ||
226 | super(pTrain); | ||
227 | } | ||
228 | |||
229 | @Override | ||
230 | public boolean isMutable() { | ||
231 | return false; | ||
232 | } | ||
233 | } | ||
234 | } | ||
235 | |||
236 | /** | ||
237 | * Generated pattern matcher API of the modes3.queries.endOfSiding_step_2 pattern, | ||
238 | * providing pattern-specific query methods. | ||
239 | * | ||
240 | * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, | ||
241 | * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. | ||
242 | * | ||
243 | * <p>Matches of the pattern will be represented as {@link Match}. | ||
244 | * | ||
245 | * <p>Original source: | ||
246 | * <code><pre> | ||
247 | * // | ||
248 | * // endOfSiding | ||
249 | * // | ||
250 | * | ||
251 | * pattern endOfSiding_step_2(in train : Train) { | ||
252 | * // frame-{@literal >}train = model-{@literal >}trains[i0]; | ||
253 | * // frame-{@literal >}location = frame-{@literal >}train-{@literal >}location; | ||
254 | * // if (frame-{@literal >}location != NULL) { | ||
255 | * // ... | ||
256 | * // } | ||
257 | * | ||
258 | * Train(train); | ||
259 | * } | ||
260 | * </pre></code> | ||
261 | * | ||
262 | * @see Match | ||
263 | * @see EndOfSiding_step_2 | ||
264 | * | ||
265 | */ | ||
266 | public static class Matcher extends BaseMatcher<EndOfSiding_step_2.Match> { | ||
267 | /** | ||
268 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
269 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
270 | * | ||
271 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
272 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
273 | * | ||
274 | */ | ||
275 | public static EndOfSiding_step_2.Matcher on(final ViatraQueryEngine engine) { | ||
276 | // check if matcher already exists | ||
277 | Matcher matcher = engine.getExistingMatcher(querySpecification()); | ||
278 | if (matcher == null) { | ||
279 | matcher = (Matcher)engine.getMatcher(querySpecification()); | ||
280 | } | ||
281 | return matcher; | ||
282 | } | ||
283 | |||
284 | /** | ||
285 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
286 | * @return an initialized matcher | ||
287 | * @noreference This method is for internal matcher initialization by the framework, do not call it manually. | ||
288 | * | ||
289 | */ | ||
290 | public static EndOfSiding_step_2.Matcher create() { | ||
291 | return new Matcher(); | ||
292 | } | ||
293 | |||
294 | private static final int POSITION_TRAIN = 0; | ||
295 | |||
296 | private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(EndOfSiding_step_2.Matcher.class); | ||
297 | |||
298 | /** | ||
299 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
300 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
301 | * | ||
302 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
303 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
304 | * | ||
305 | */ | ||
306 | private Matcher() { | ||
307 | super(querySpecification()); | ||
308 | } | ||
309 | |||
310 | /** | ||
311 | * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. | ||
312 | * @param pTrain the fixed value of pattern parameter train, or null if not bound. | ||
313 | * @return matches represented as a Match object. | ||
314 | * | ||
315 | */ | ||
316 | public Collection<EndOfSiding_step_2.Match> getAllMatches(final Train pTrain) { | ||
317 | return rawStreamAllMatches(new Object[]{pTrain}).collect(Collectors.toSet()); | ||
318 | } | ||
319 | |||
320 | /** | ||
321 | * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. | ||
322 | * </p> | ||
323 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
324 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
325 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
326 | * @param pTrain the fixed value of pattern parameter train, or null if not bound. | ||
327 | * @return a stream of matches represented as a Match object. | ||
328 | * | ||
329 | */ | ||
330 | public Stream<EndOfSiding_step_2.Match> streamAllMatches(final Train pTrain) { | ||
331 | return rawStreamAllMatches(new Object[]{pTrain}); | ||
332 | } | ||
333 | |||
334 | /** | ||
335 | * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
336 | * Neither determinism nor randomness of selection is guaranteed. | ||
337 | * @param pTrain the fixed value of pattern parameter train, or null if not bound. | ||
338 | * @return a match represented as a Match object, or null if no match is found. | ||
339 | * | ||
340 | */ | ||
341 | public Optional<EndOfSiding_step_2.Match> getOneArbitraryMatch(final Train pTrain) { | ||
342 | return rawGetOneArbitraryMatch(new Object[]{pTrain}); | ||
343 | } | ||
344 | |||
345 | /** | ||
346 | * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, | ||
347 | * under any possible substitution of the unspecified parameters (if any). | ||
348 | * @param pTrain the fixed value of pattern parameter train, or null if not bound. | ||
349 | * @return true if the input is a valid (partial) match of the pattern. | ||
350 | * | ||
351 | */ | ||
352 | public boolean hasMatch(final Train pTrain) { | ||
353 | return rawHasMatch(new Object[]{pTrain}); | ||
354 | } | ||
355 | |||
356 | /** | ||
357 | * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. | ||
358 | * @param pTrain the fixed value of pattern parameter train, or null if not bound. | ||
359 | * @return the number of pattern matches found. | ||
360 | * | ||
361 | */ | ||
362 | public int countMatches(final Train pTrain) { | ||
363 | return rawCountMatches(new Object[]{pTrain}); | ||
364 | } | ||
365 | |||
366 | /** | ||
367 | * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
368 | * Neither determinism nor randomness of selection is guaranteed. | ||
369 | * @param pTrain the fixed value of pattern parameter train, or null if not bound. | ||
370 | * @param processor the action that will process the selected match. | ||
371 | * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked | ||
372 | * | ||
373 | */ | ||
374 | public boolean forOneArbitraryMatch(final Train pTrain, final Consumer<? super EndOfSiding_step_2.Match> processor) { | ||
375 | return rawForOneArbitraryMatch(new Object[]{pTrain}, processor); | ||
376 | } | ||
377 | |||
378 | /** | ||
379 | * Returns a new (partial) match. | ||
380 | * This can be used e.g. to call the matcher with a partial match. | ||
381 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
382 | * @param pTrain the fixed value of pattern parameter train, or null if not bound. | ||
383 | * @return the (partial) match object. | ||
384 | * | ||
385 | */ | ||
386 | public EndOfSiding_step_2.Match newMatch(final Train pTrain) { | ||
387 | return EndOfSiding_step_2.Match.newMatch(pTrain); | ||
388 | } | ||
389 | |||
390 | /** | ||
391 | * Retrieve the set of values that occur in matches for train. | ||
392 | * @return the Set of all values or empty set if there are no matches | ||
393 | * | ||
394 | */ | ||
395 | protected Stream<Train> rawStreamAllValuesOftrain(final Object[] parameters) { | ||
396 | return rawStreamAllValues(POSITION_TRAIN, parameters).map(Train.class::cast); | ||
397 | } | ||
398 | |||
399 | /** | ||
400 | * Retrieve the set of values that occur in matches for train. | ||
401 | * @return the Set of all values or empty set if there are no matches | ||
402 | * | ||
403 | */ | ||
404 | public Set<Train> getAllValuesOftrain() { | ||
405 | return rawStreamAllValuesOftrain(emptyArray()).collect(Collectors.toSet()); | ||
406 | } | ||
407 | |||
408 | /** | ||
409 | * Retrieve the set of values that occur in matches for train. | ||
410 | * @return the Set of all values or empty set if there are no matches | ||
411 | * | ||
412 | */ | ||
413 | public Stream<Train> streamAllValuesOftrain() { | ||
414 | return rawStreamAllValuesOftrain(emptyArray()); | ||
415 | } | ||
416 | |||
417 | @Override | ||
418 | protected EndOfSiding_step_2.Match tupleToMatch(final Tuple t) { | ||
419 | try { | ||
420 | return EndOfSiding_step_2.Match.newMatch((Train) t.get(POSITION_TRAIN)); | ||
421 | } catch(ClassCastException e) { | ||
422 | LOGGER.error("Element(s) in tuple not properly typed!",e); | ||
423 | return null; | ||
424 | } | ||
425 | } | ||
426 | |||
427 | @Override | ||
428 | protected EndOfSiding_step_2.Match arrayToMatch(final Object[] match) { | ||
429 | try { | ||
430 | return EndOfSiding_step_2.Match.newMatch((Train) match[POSITION_TRAIN]); | ||
431 | } catch(ClassCastException e) { | ||
432 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
433 | return null; | ||
434 | } | ||
435 | } | ||
436 | |||
437 | @Override | ||
438 | protected EndOfSiding_step_2.Match arrayToMatchMutable(final Object[] match) { | ||
439 | try { | ||
440 | return EndOfSiding_step_2.Match.newMutableMatch((Train) match[POSITION_TRAIN]); | ||
441 | } catch(ClassCastException e) { | ||
442 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
443 | return null; | ||
444 | } | ||
445 | } | ||
446 | |||
447 | /** | ||
448 | * @return the singleton instance of the query specification of this pattern | ||
449 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
450 | * | ||
451 | */ | ||
452 | public static IQuerySpecification<EndOfSiding_step_2.Matcher> querySpecification() { | ||
453 | return EndOfSiding_step_2.instance(); | ||
454 | } | ||
455 | } | ||
456 | |||
457 | private EndOfSiding_step_2() { | ||
458 | super(GeneratedPQuery.INSTANCE); | ||
459 | } | ||
460 | |||
461 | /** | ||
462 | * @return the singleton instance of the query specification | ||
463 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
464 | * | ||
465 | */ | ||
466 | public static EndOfSiding_step_2 instance() { | ||
467 | try{ | ||
468 | return LazyHolder.INSTANCE; | ||
469 | } catch (ExceptionInInitializerError err) { | ||
470 | throw processInitializerError(err); | ||
471 | } | ||
472 | } | ||
473 | |||
474 | @Override | ||
475 | protected EndOfSiding_step_2.Matcher instantiate(final ViatraQueryEngine engine) { | ||
476 | return EndOfSiding_step_2.Matcher.on(engine); | ||
477 | } | ||
478 | |||
479 | @Override | ||
480 | public EndOfSiding_step_2.Matcher instantiate() { | ||
481 | return EndOfSiding_step_2.Matcher.create(); | ||
482 | } | ||
483 | |||
484 | @Override | ||
485 | public EndOfSiding_step_2.Match newEmptyMatch() { | ||
486 | return EndOfSiding_step_2.Match.newEmptyMatch(); | ||
487 | } | ||
488 | |||
489 | @Override | ||
490 | public EndOfSiding_step_2.Match newMatch(final Object... parameters) { | ||
491 | return EndOfSiding_step_2.Match.newMatch((modes3.Train) parameters[0]); | ||
492 | } | ||
493 | |||
494 | /** | ||
495 | * Inner class allowing the singleton instance of {@link EndOfSiding_step_2} to be created | ||
496 | * <b>not</b> at the class load time of the outer class, | ||
497 | * but rather at the first call to {@link EndOfSiding_step_2#instance()}. | ||
498 | * | ||
499 | * <p> This workaround is required e.g. to support recursion. | ||
500 | * | ||
501 | */ | ||
502 | private static class LazyHolder { | ||
503 | private static final EndOfSiding_step_2 INSTANCE = new EndOfSiding_step_2(); | ||
504 | |||
505 | /** | ||
506 | * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned. | ||
507 | * This initialization order is required to support indirect recursion. | ||
508 | * | ||
509 | * <p> The static initializer is defined using a helper field to work around limitations of the code generator. | ||
510 | * | ||
511 | */ | ||
512 | private static final Object STATIC_INITIALIZER = ensureInitialized(); | ||
513 | |||
514 | public static Object ensureInitialized() { | ||
515 | INSTANCE.ensureInitializedInternal(); | ||
516 | return null; | ||
517 | } | ||
518 | } | ||
519 | |||
520 | private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { | ||
521 | private static final EndOfSiding_step_2.GeneratedPQuery INSTANCE = new GeneratedPQuery(); | ||
522 | |||
523 | private final PParameter parameter_train = new PParameter("train", "modes3.Train", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Train")), PParameterDirection.INOUT); | ||
524 | |||
525 | private final List<PParameter> parameters = Arrays.asList(parameter_train); | ||
526 | |||
527 | private GeneratedPQuery() { | ||
528 | super(PVisibility.PUBLIC); | ||
529 | } | ||
530 | |||
531 | @Override | ||
532 | public String getFullyQualifiedName() { | ||
533 | return "modes3.queries.endOfSiding_step_2"; | ||
534 | } | ||
535 | |||
536 | @Override | ||
537 | public List<String> getParameterNames() { | ||
538 | return Arrays.asList("train"); | ||
539 | } | ||
540 | |||
541 | @Override | ||
542 | public List<PParameter> getParameters() { | ||
543 | return parameters; | ||
544 | } | ||
545 | |||
546 | @Override | ||
547 | public Set<PBody> doGetContainedBodies() { | ||
548 | setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); | ||
549 | Set<PBody> bodies = new LinkedHashSet<>(); | ||
550 | { | ||
551 | PBody body = new PBody(this); | ||
552 | PVariable var_train = body.getOrCreateVariableByName("train"); | ||
553 | new TypeConstraint(body, Tuples.flatTupleOf(var_train), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Train"))); | ||
554 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
555 | new ExportedParameter(body, var_train, parameter_train) | ||
556 | )); | ||
557 | // // frame->train = model->trains[i0];// frame->location = frame->train->location;// if (frame->location != NULL) {// ...// } Train(train) | ||
558 | new TypeConstraint(body, Tuples.flatTupleOf(var_train), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Train"))); | ||
559 | bodies.add(body); | ||
560 | } | ||
561 | return bodies; | ||
562 | } | ||
563 | } | ||
564 | } | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/EndOfSiding_step_3.java b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/EndOfSiding_step_3.java new file mode 100644 index 00000000..16b28a9f --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/EndOfSiding_step_3.java | |||
@@ -0,0 +1,717 @@ | |||
1 | /** | ||
2 | * Generated from platform:/resource/ca.mcgill.rtgmrt.example.modes3/src/modes3/queries/Modes3Queries.vql | ||
3 | */ | ||
4 | package modes3.queries; | ||
5 | |||
6 | import java.util.Arrays; | ||
7 | import java.util.Collection; | ||
8 | import java.util.LinkedHashSet; | ||
9 | import java.util.List; | ||
10 | import java.util.Objects; | ||
11 | import java.util.Optional; | ||
12 | import java.util.Set; | ||
13 | import java.util.function.Consumer; | ||
14 | import java.util.stream.Collectors; | ||
15 | import java.util.stream.Stream; | ||
16 | import modes3.Segment; | ||
17 | import modes3.Train; | ||
18 | import org.apache.log4j.Logger; | ||
19 | import org.eclipse.emf.ecore.EClass; | ||
20 | import org.eclipse.viatra.query.runtime.api.IPatternMatch; | ||
21 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification; | ||
22 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; | ||
23 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; | ||
24 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; | ||
25 | import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; | ||
26 | import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; | ||
27 | import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; | ||
28 | import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; | ||
29 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
30 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | ||
31 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | ||
32 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; | ||
33 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
34 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
35 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | ||
36 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; | ||
37 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | ||
38 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; | ||
39 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
40 | import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; | ||
41 | |||
42 | /** | ||
43 | * A pattern-specific query specification that can instantiate Matcher in a type-safe way. | ||
44 | * | ||
45 | * <p>Original source: | ||
46 | * <code><pre> | ||
47 | * pattern endOfSiding_step_3(in train : Train, in location : Segment) { | ||
48 | * // int loop_bound1 = frame-{@literal >}location-{@literal >}connected_to_count; | ||
49 | * // for (int i1 = 0; i1 {@literal <} loop_bound1; i1++) { | ||
50 | * // ... | ||
51 | * // } | ||
52 | * Train(train); | ||
53 | * Train.location(train, location); | ||
54 | * } | ||
55 | * </pre></code> | ||
56 | * | ||
57 | * @see Matcher | ||
58 | * @see Match | ||
59 | * | ||
60 | */ | ||
61 | @SuppressWarnings("all") | ||
62 | public final class EndOfSiding_step_3 extends BaseGeneratedEMFQuerySpecification<EndOfSiding_step_3.Matcher> { | ||
63 | /** | ||
64 | * Pattern-specific match representation of the modes3.queries.endOfSiding_step_3 pattern, | ||
65 | * to be used in conjunction with {@link Matcher}. | ||
66 | * | ||
67 | * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. | ||
68 | * Each instance is a (possibly partial) substitution of pattern parameters, | ||
69 | * usable to represent a match of the pattern in the result of a query, | ||
70 | * or to specify the bound (fixed) input parameters when issuing a query. | ||
71 | * | ||
72 | * @see Matcher | ||
73 | * | ||
74 | */ | ||
75 | public static abstract class Match extends BasePatternMatch { | ||
76 | private Train fTrain; | ||
77 | |||
78 | private Segment fLocation; | ||
79 | |||
80 | private static List<String> parameterNames = makeImmutableList("train", "location"); | ||
81 | |||
82 | private Match(final Train pTrain, final Segment pLocation) { | ||
83 | this.fTrain = pTrain; | ||
84 | this.fLocation = pLocation; | ||
85 | } | ||
86 | |||
87 | @Override | ||
88 | public Object get(final String parameterName) { | ||
89 | switch(parameterName) { | ||
90 | case "train": return this.fTrain; | ||
91 | case "location": return this.fLocation; | ||
92 | default: return null; | ||
93 | } | ||
94 | } | ||
95 | |||
96 | @Override | ||
97 | public Object get(final int index) { | ||
98 | switch(index) { | ||
99 | case 0: return this.fTrain; | ||
100 | case 1: return this.fLocation; | ||
101 | default: return null; | ||
102 | } | ||
103 | } | ||
104 | |||
105 | public Train getTrain() { | ||
106 | return this.fTrain; | ||
107 | } | ||
108 | |||
109 | public Segment getLocation() { | ||
110 | return this.fLocation; | ||
111 | } | ||
112 | |||
113 | @Override | ||
114 | public boolean set(final String parameterName, final Object newValue) { | ||
115 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
116 | if ("train".equals(parameterName) ) { | ||
117 | this.fTrain = (Train) newValue; | ||
118 | return true; | ||
119 | } | ||
120 | if ("location".equals(parameterName) ) { | ||
121 | this.fLocation = (Segment) newValue; | ||
122 | return true; | ||
123 | } | ||
124 | return false; | ||
125 | } | ||
126 | |||
127 | public void setTrain(final Train pTrain) { | ||
128 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
129 | this.fTrain = pTrain; | ||
130 | } | ||
131 | |||
132 | public void setLocation(final Segment pLocation) { | ||
133 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
134 | this.fLocation = pLocation; | ||
135 | } | ||
136 | |||
137 | @Override | ||
138 | public String patternName() { | ||
139 | return "modes3.queries.endOfSiding_step_3"; | ||
140 | } | ||
141 | |||
142 | @Override | ||
143 | public List<String> parameterNames() { | ||
144 | return EndOfSiding_step_3.Match.parameterNames; | ||
145 | } | ||
146 | |||
147 | @Override | ||
148 | public Object[] toArray() { | ||
149 | return new Object[]{fTrain, fLocation}; | ||
150 | } | ||
151 | |||
152 | @Override | ||
153 | public EndOfSiding_step_3.Match toImmutable() { | ||
154 | return isMutable() ? newMatch(fTrain, fLocation) : this; | ||
155 | } | ||
156 | |||
157 | @Override | ||
158 | public String prettyPrint() { | ||
159 | StringBuilder result = new StringBuilder(); | ||
160 | result.append("\"train\"=" + prettyPrintValue(fTrain) + ", "); | ||
161 | result.append("\"location\"=" + prettyPrintValue(fLocation)); | ||
162 | return result.toString(); | ||
163 | } | ||
164 | |||
165 | @Override | ||
166 | public int hashCode() { | ||
167 | return Objects.hash(fTrain, fLocation); | ||
168 | } | ||
169 | |||
170 | @Override | ||
171 | public boolean equals(final Object obj) { | ||
172 | if (this == obj) | ||
173 | return true; | ||
174 | if (obj == null) { | ||
175 | return false; | ||
176 | } | ||
177 | if ((obj instanceof EndOfSiding_step_3.Match)) { | ||
178 | EndOfSiding_step_3.Match other = (EndOfSiding_step_3.Match) obj; | ||
179 | return Objects.equals(fTrain, other.fTrain) && Objects.equals(fLocation, other.fLocation); | ||
180 | } else { | ||
181 | // this should be infrequent | ||
182 | if (!(obj instanceof IPatternMatch)) { | ||
183 | return false; | ||
184 | } | ||
185 | IPatternMatch otherSig = (IPatternMatch) obj; | ||
186 | return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); | ||
187 | } | ||
188 | } | ||
189 | |||
190 | @Override | ||
191 | public EndOfSiding_step_3 specification() { | ||
192 | return EndOfSiding_step_3.instance(); | ||
193 | } | ||
194 | |||
195 | /** | ||
196 | * Returns an empty, mutable match. | ||
197 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
198 | * | ||
199 | * @return the empty match. | ||
200 | * | ||
201 | */ | ||
202 | public static EndOfSiding_step_3.Match newEmptyMatch() { | ||
203 | return new Mutable(null, null); | ||
204 | } | ||
205 | |||
206 | /** | ||
207 | * Returns a mutable (partial) match. | ||
208 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
209 | * | ||
210 | * @param pTrain the fixed value of pattern parameter train, or null if not bound. | ||
211 | * @param pLocation the fixed value of pattern parameter location, or null if not bound. | ||
212 | * @return the new, mutable (partial) match object. | ||
213 | * | ||
214 | */ | ||
215 | public static EndOfSiding_step_3.Match newMutableMatch(final Train pTrain, final Segment pLocation) { | ||
216 | return new Mutable(pTrain, pLocation); | ||
217 | } | ||
218 | |||
219 | /** | ||
220 | * Returns a new (partial) match. | ||
221 | * This can be used e.g. to call the matcher with a partial match. | ||
222 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
223 | * @param pTrain the fixed value of pattern parameter train, or null if not bound. | ||
224 | * @param pLocation the fixed value of pattern parameter location, or null if not bound. | ||
225 | * @return the (partial) match object. | ||
226 | * | ||
227 | */ | ||
228 | public static EndOfSiding_step_3.Match newMatch(final Train pTrain, final Segment pLocation) { | ||
229 | return new Immutable(pTrain, pLocation); | ||
230 | } | ||
231 | |||
232 | private static final class Mutable extends EndOfSiding_step_3.Match { | ||
233 | Mutable(final Train pTrain, final Segment pLocation) { | ||
234 | super(pTrain, pLocation); | ||
235 | } | ||
236 | |||
237 | @Override | ||
238 | public boolean isMutable() { | ||
239 | return true; | ||
240 | } | ||
241 | } | ||
242 | |||
243 | private static final class Immutable extends EndOfSiding_step_3.Match { | ||
244 | Immutable(final Train pTrain, final Segment pLocation) { | ||
245 | super(pTrain, pLocation); | ||
246 | } | ||
247 | |||
248 | @Override | ||
249 | public boolean isMutable() { | ||
250 | return false; | ||
251 | } | ||
252 | } | ||
253 | } | ||
254 | |||
255 | /** | ||
256 | * Generated pattern matcher API of the modes3.queries.endOfSiding_step_3 pattern, | ||
257 | * providing pattern-specific query methods. | ||
258 | * | ||
259 | * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, | ||
260 | * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. | ||
261 | * | ||
262 | * <p>Matches of the pattern will be represented as {@link Match}. | ||
263 | * | ||
264 | * <p>Original source: | ||
265 | * <code><pre> | ||
266 | * pattern endOfSiding_step_3(in train : Train, in location : Segment) { | ||
267 | * // int loop_bound1 = frame-{@literal >}location-{@literal >}connected_to_count; | ||
268 | * // for (int i1 = 0; i1 {@literal <} loop_bound1; i1++) { | ||
269 | * // ... | ||
270 | * // } | ||
271 | * Train(train); | ||
272 | * Train.location(train, location); | ||
273 | * } | ||
274 | * </pre></code> | ||
275 | * | ||
276 | * @see Match | ||
277 | * @see EndOfSiding_step_3 | ||
278 | * | ||
279 | */ | ||
280 | public static class Matcher extends BaseMatcher<EndOfSiding_step_3.Match> { | ||
281 | /** | ||
282 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
283 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
284 | * | ||
285 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
286 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
287 | * | ||
288 | */ | ||
289 | public static EndOfSiding_step_3.Matcher on(final ViatraQueryEngine engine) { | ||
290 | // check if matcher already exists | ||
291 | Matcher matcher = engine.getExistingMatcher(querySpecification()); | ||
292 | if (matcher == null) { | ||
293 | matcher = (Matcher)engine.getMatcher(querySpecification()); | ||
294 | } | ||
295 | return matcher; | ||
296 | } | ||
297 | |||
298 | /** | ||
299 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
300 | * @return an initialized matcher | ||
301 | * @noreference This method is for internal matcher initialization by the framework, do not call it manually. | ||
302 | * | ||
303 | */ | ||
304 | public static EndOfSiding_step_3.Matcher create() { | ||
305 | return new Matcher(); | ||
306 | } | ||
307 | |||
308 | private static final int POSITION_TRAIN = 0; | ||
309 | |||
310 | private static final int POSITION_LOCATION = 1; | ||
311 | |||
312 | private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(EndOfSiding_step_3.Matcher.class); | ||
313 | |||
314 | /** | ||
315 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
316 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
317 | * | ||
318 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
319 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
320 | * | ||
321 | */ | ||
322 | private Matcher() { | ||
323 | super(querySpecification()); | ||
324 | } | ||
325 | |||
326 | /** | ||
327 | * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. | ||
328 | * @param pTrain the fixed value of pattern parameter train, or null if not bound. | ||
329 | * @param pLocation the fixed value of pattern parameter location, or null if not bound. | ||
330 | * @return matches represented as a Match object. | ||
331 | * | ||
332 | */ | ||
333 | public Collection<EndOfSiding_step_3.Match> getAllMatches(final Train pTrain, final Segment pLocation) { | ||
334 | return rawStreamAllMatches(new Object[]{pTrain, pLocation}).collect(Collectors.toSet()); | ||
335 | } | ||
336 | |||
337 | /** | ||
338 | * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. | ||
339 | * </p> | ||
340 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
341 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
342 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
343 | * @param pTrain the fixed value of pattern parameter train, or null if not bound. | ||
344 | * @param pLocation the fixed value of pattern parameter location, or null if not bound. | ||
345 | * @return a stream of matches represented as a Match object. | ||
346 | * | ||
347 | */ | ||
348 | public Stream<EndOfSiding_step_3.Match> streamAllMatches(final Train pTrain, final Segment pLocation) { | ||
349 | return rawStreamAllMatches(new Object[]{pTrain, pLocation}); | ||
350 | } | ||
351 | |||
352 | /** | ||
353 | * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
354 | * Neither determinism nor randomness of selection is guaranteed. | ||
355 | * @param pTrain the fixed value of pattern parameter train, or null if not bound. | ||
356 | * @param pLocation the fixed value of pattern parameter location, or null if not bound. | ||
357 | * @return a match represented as a Match object, or null if no match is found. | ||
358 | * | ||
359 | */ | ||
360 | public Optional<EndOfSiding_step_3.Match> getOneArbitraryMatch(final Train pTrain, final Segment pLocation) { | ||
361 | return rawGetOneArbitraryMatch(new Object[]{pTrain, pLocation}); | ||
362 | } | ||
363 | |||
364 | /** | ||
365 | * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, | ||
366 | * under any possible substitution of the unspecified parameters (if any). | ||
367 | * @param pTrain the fixed value of pattern parameter train, or null if not bound. | ||
368 | * @param pLocation the fixed value of pattern parameter location, or null if not bound. | ||
369 | * @return true if the input is a valid (partial) match of the pattern. | ||
370 | * | ||
371 | */ | ||
372 | public boolean hasMatch(final Train pTrain, final Segment pLocation) { | ||
373 | return rawHasMatch(new Object[]{pTrain, pLocation}); | ||
374 | } | ||
375 | |||
376 | /** | ||
377 | * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. | ||
378 | * @param pTrain the fixed value of pattern parameter train, or null if not bound. | ||
379 | * @param pLocation the fixed value of pattern parameter location, or null if not bound. | ||
380 | * @return the number of pattern matches found. | ||
381 | * | ||
382 | */ | ||
383 | public int countMatches(final Train pTrain, final Segment pLocation) { | ||
384 | return rawCountMatches(new Object[]{pTrain, pLocation}); | ||
385 | } | ||
386 | |||
387 | /** | ||
388 | * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
389 | * Neither determinism nor randomness of selection is guaranteed. | ||
390 | * @param pTrain the fixed value of pattern parameter train, or null if not bound. | ||
391 | * @param pLocation the fixed value of pattern parameter location, or null if not bound. | ||
392 | * @param processor the action that will process the selected match. | ||
393 | * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked | ||
394 | * | ||
395 | */ | ||
396 | public boolean forOneArbitraryMatch(final Train pTrain, final Segment pLocation, final Consumer<? super EndOfSiding_step_3.Match> processor) { | ||
397 | return rawForOneArbitraryMatch(new Object[]{pTrain, pLocation}, processor); | ||
398 | } | ||
399 | |||
400 | /** | ||
401 | * Returns a new (partial) match. | ||
402 | * This can be used e.g. to call the matcher with a partial match. | ||
403 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
404 | * @param pTrain the fixed value of pattern parameter train, or null if not bound. | ||
405 | * @param pLocation the fixed value of pattern parameter location, or null if not bound. | ||
406 | * @return the (partial) match object. | ||
407 | * | ||
408 | */ | ||
409 | public EndOfSiding_step_3.Match newMatch(final Train pTrain, final Segment pLocation) { | ||
410 | return EndOfSiding_step_3.Match.newMatch(pTrain, pLocation); | ||
411 | } | ||
412 | |||
413 | /** | ||
414 | * Retrieve the set of values that occur in matches for train. | ||
415 | * @return the Set of all values or empty set if there are no matches | ||
416 | * | ||
417 | */ | ||
418 | protected Stream<Train> rawStreamAllValuesOftrain(final Object[] parameters) { | ||
419 | return rawStreamAllValues(POSITION_TRAIN, parameters).map(Train.class::cast); | ||
420 | } | ||
421 | |||
422 | /** | ||
423 | * Retrieve the set of values that occur in matches for train. | ||
424 | * @return the Set of all values or empty set if there are no matches | ||
425 | * | ||
426 | */ | ||
427 | public Set<Train> getAllValuesOftrain() { | ||
428 | return rawStreamAllValuesOftrain(emptyArray()).collect(Collectors.toSet()); | ||
429 | } | ||
430 | |||
431 | /** | ||
432 | * Retrieve the set of values that occur in matches for train. | ||
433 | * @return the Set of all values or empty set if there are no matches | ||
434 | * | ||
435 | */ | ||
436 | public Stream<Train> streamAllValuesOftrain() { | ||
437 | return rawStreamAllValuesOftrain(emptyArray()); | ||
438 | } | ||
439 | |||
440 | /** | ||
441 | * Retrieve the set of values that occur in matches for train. | ||
442 | * </p> | ||
443 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
444 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
445 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
446 | * | ||
447 | * @return the Stream of all values or empty set if there are no matches | ||
448 | * | ||
449 | */ | ||
450 | public Stream<Train> streamAllValuesOftrain(final EndOfSiding_step_3.Match partialMatch) { | ||
451 | return rawStreamAllValuesOftrain(partialMatch.toArray()); | ||
452 | } | ||
453 | |||
454 | /** | ||
455 | * Retrieve the set of values that occur in matches for train. | ||
456 | * </p> | ||
457 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
458 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
459 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
460 | * | ||
461 | * @return the Stream of all values or empty set if there are no matches | ||
462 | * | ||
463 | */ | ||
464 | public Stream<Train> streamAllValuesOftrain(final Segment pLocation) { | ||
465 | return rawStreamAllValuesOftrain(new Object[]{null, pLocation}); | ||
466 | } | ||
467 | |||
468 | /** | ||
469 | * Retrieve the set of values that occur in matches for train. | ||
470 | * @return the Set of all values or empty set if there are no matches | ||
471 | * | ||
472 | */ | ||
473 | public Set<Train> getAllValuesOftrain(final EndOfSiding_step_3.Match partialMatch) { | ||
474 | return rawStreamAllValuesOftrain(partialMatch.toArray()).collect(Collectors.toSet()); | ||
475 | } | ||
476 | |||
477 | /** | ||
478 | * Retrieve the set of values that occur in matches for train. | ||
479 | * @return the Set of all values or empty set if there are no matches | ||
480 | * | ||
481 | */ | ||
482 | public Set<Train> getAllValuesOftrain(final Segment pLocation) { | ||
483 | return rawStreamAllValuesOftrain(new Object[]{null, pLocation}).collect(Collectors.toSet()); | ||
484 | } | ||
485 | |||
486 | /** | ||
487 | * Retrieve the set of values that occur in matches for location. | ||
488 | * @return the Set of all values or empty set if there are no matches | ||
489 | * | ||
490 | */ | ||
491 | protected Stream<Segment> rawStreamAllValuesOflocation(final Object[] parameters) { | ||
492 | return rawStreamAllValues(POSITION_LOCATION, parameters).map(Segment.class::cast); | ||
493 | } | ||
494 | |||
495 | /** | ||
496 | * Retrieve the set of values that occur in matches for location. | ||
497 | * @return the Set of all values or empty set if there are no matches | ||
498 | * | ||
499 | */ | ||
500 | public Set<Segment> getAllValuesOflocation() { | ||
501 | return rawStreamAllValuesOflocation(emptyArray()).collect(Collectors.toSet()); | ||
502 | } | ||
503 | |||
504 | /** | ||
505 | * Retrieve the set of values that occur in matches for location. | ||
506 | * @return the Set of all values or empty set if there are no matches | ||
507 | * | ||
508 | */ | ||
509 | public Stream<Segment> streamAllValuesOflocation() { | ||
510 | return rawStreamAllValuesOflocation(emptyArray()); | ||
511 | } | ||
512 | |||
513 | /** | ||
514 | * Retrieve the set of values that occur in matches for location. | ||
515 | * </p> | ||
516 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
517 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
518 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
519 | * | ||
520 | * @return the Stream of all values or empty set if there are no matches | ||
521 | * | ||
522 | */ | ||
523 | public Stream<Segment> streamAllValuesOflocation(final EndOfSiding_step_3.Match partialMatch) { | ||
524 | return rawStreamAllValuesOflocation(partialMatch.toArray()); | ||
525 | } | ||
526 | |||
527 | /** | ||
528 | * Retrieve the set of values that occur in matches for location. | ||
529 | * </p> | ||
530 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
531 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
532 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
533 | * | ||
534 | * @return the Stream of all values or empty set if there are no matches | ||
535 | * | ||
536 | */ | ||
537 | public Stream<Segment> streamAllValuesOflocation(final Train pTrain) { | ||
538 | return rawStreamAllValuesOflocation(new Object[]{pTrain, null}); | ||
539 | } | ||
540 | |||
541 | /** | ||
542 | * Retrieve the set of values that occur in matches for location. | ||
543 | * @return the Set of all values or empty set if there are no matches | ||
544 | * | ||
545 | */ | ||
546 | public Set<Segment> getAllValuesOflocation(final EndOfSiding_step_3.Match partialMatch) { | ||
547 | return rawStreamAllValuesOflocation(partialMatch.toArray()).collect(Collectors.toSet()); | ||
548 | } | ||
549 | |||
550 | /** | ||
551 | * Retrieve the set of values that occur in matches for location. | ||
552 | * @return the Set of all values or empty set if there are no matches | ||
553 | * | ||
554 | */ | ||
555 | public Set<Segment> getAllValuesOflocation(final Train pTrain) { | ||
556 | return rawStreamAllValuesOflocation(new Object[]{pTrain, null}).collect(Collectors.toSet()); | ||
557 | } | ||
558 | |||
559 | @Override | ||
560 | protected EndOfSiding_step_3.Match tupleToMatch(final Tuple t) { | ||
561 | try { | ||
562 | return EndOfSiding_step_3.Match.newMatch((Train) t.get(POSITION_TRAIN), (Segment) t.get(POSITION_LOCATION)); | ||
563 | } catch(ClassCastException e) { | ||
564 | LOGGER.error("Element(s) in tuple not properly typed!",e); | ||
565 | return null; | ||
566 | } | ||
567 | } | ||
568 | |||
569 | @Override | ||
570 | protected EndOfSiding_step_3.Match arrayToMatch(final Object[] match) { | ||
571 | try { | ||
572 | return EndOfSiding_step_3.Match.newMatch((Train) match[POSITION_TRAIN], (Segment) match[POSITION_LOCATION]); | ||
573 | } catch(ClassCastException e) { | ||
574 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
575 | return null; | ||
576 | } | ||
577 | } | ||
578 | |||
579 | @Override | ||
580 | protected EndOfSiding_step_3.Match arrayToMatchMutable(final Object[] match) { | ||
581 | try { | ||
582 | return EndOfSiding_step_3.Match.newMutableMatch((Train) match[POSITION_TRAIN], (Segment) match[POSITION_LOCATION]); | ||
583 | } catch(ClassCastException e) { | ||
584 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
585 | return null; | ||
586 | } | ||
587 | } | ||
588 | |||
589 | /** | ||
590 | * @return the singleton instance of the query specification of this pattern | ||
591 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
592 | * | ||
593 | */ | ||
594 | public static IQuerySpecification<EndOfSiding_step_3.Matcher> querySpecification() { | ||
595 | return EndOfSiding_step_3.instance(); | ||
596 | } | ||
597 | } | ||
598 | |||
599 | private EndOfSiding_step_3() { | ||
600 | super(GeneratedPQuery.INSTANCE); | ||
601 | } | ||
602 | |||
603 | /** | ||
604 | * @return the singleton instance of the query specification | ||
605 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
606 | * | ||
607 | */ | ||
608 | public static EndOfSiding_step_3 instance() { | ||
609 | try{ | ||
610 | return LazyHolder.INSTANCE; | ||
611 | } catch (ExceptionInInitializerError err) { | ||
612 | throw processInitializerError(err); | ||
613 | } | ||
614 | } | ||
615 | |||
616 | @Override | ||
617 | protected EndOfSiding_step_3.Matcher instantiate(final ViatraQueryEngine engine) { | ||
618 | return EndOfSiding_step_3.Matcher.on(engine); | ||
619 | } | ||
620 | |||
621 | @Override | ||
622 | public EndOfSiding_step_3.Matcher instantiate() { | ||
623 | return EndOfSiding_step_3.Matcher.create(); | ||
624 | } | ||
625 | |||
626 | @Override | ||
627 | public EndOfSiding_step_3.Match newEmptyMatch() { | ||
628 | return EndOfSiding_step_3.Match.newEmptyMatch(); | ||
629 | } | ||
630 | |||
631 | @Override | ||
632 | public EndOfSiding_step_3.Match newMatch(final Object... parameters) { | ||
633 | return EndOfSiding_step_3.Match.newMatch((modes3.Train) parameters[0], (modes3.Segment) parameters[1]); | ||
634 | } | ||
635 | |||
636 | /** | ||
637 | * Inner class allowing the singleton instance of {@link EndOfSiding_step_3} to be created | ||
638 | * <b>not</b> at the class load time of the outer class, | ||
639 | * but rather at the first call to {@link EndOfSiding_step_3#instance()}. | ||
640 | * | ||
641 | * <p> This workaround is required e.g. to support recursion. | ||
642 | * | ||
643 | */ | ||
644 | private static class LazyHolder { | ||
645 | private static final EndOfSiding_step_3 INSTANCE = new EndOfSiding_step_3(); | ||
646 | |||
647 | /** | ||
648 | * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned. | ||
649 | * This initialization order is required to support indirect recursion. | ||
650 | * | ||
651 | * <p> The static initializer is defined using a helper field to work around limitations of the code generator. | ||
652 | * | ||
653 | */ | ||
654 | private static final Object STATIC_INITIALIZER = ensureInitialized(); | ||
655 | |||
656 | public static Object ensureInitialized() { | ||
657 | INSTANCE.ensureInitializedInternal(); | ||
658 | return null; | ||
659 | } | ||
660 | } | ||
661 | |||
662 | private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { | ||
663 | private static final EndOfSiding_step_3.GeneratedPQuery INSTANCE = new GeneratedPQuery(); | ||
664 | |||
665 | private final PParameter parameter_train = new PParameter("train", "modes3.Train", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Train")), PParameterDirection.INOUT); | ||
666 | |||
667 | private final PParameter parameter_location = new PParameter("location", "modes3.Segment", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Segment")), PParameterDirection.INOUT); | ||
668 | |||
669 | private final List<PParameter> parameters = Arrays.asList(parameter_train, parameter_location); | ||
670 | |||
671 | private GeneratedPQuery() { | ||
672 | super(PVisibility.PUBLIC); | ||
673 | } | ||
674 | |||
675 | @Override | ||
676 | public String getFullyQualifiedName() { | ||
677 | return "modes3.queries.endOfSiding_step_3"; | ||
678 | } | ||
679 | |||
680 | @Override | ||
681 | public List<String> getParameterNames() { | ||
682 | return Arrays.asList("train","location"); | ||
683 | } | ||
684 | |||
685 | @Override | ||
686 | public List<PParameter> getParameters() { | ||
687 | return parameters; | ||
688 | } | ||
689 | |||
690 | @Override | ||
691 | public Set<PBody> doGetContainedBodies() { | ||
692 | setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); | ||
693 | Set<PBody> bodies = new LinkedHashSet<>(); | ||
694 | { | ||
695 | PBody body = new PBody(this); | ||
696 | PVariable var_train = body.getOrCreateVariableByName("train"); | ||
697 | PVariable var_location = body.getOrCreateVariableByName("location"); | ||
698 | new TypeConstraint(body, Tuples.flatTupleOf(var_train), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Train"))); | ||
699 | new TypeConstraint(body, Tuples.flatTupleOf(var_location), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
700 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
701 | new ExportedParameter(body, var_train, parameter_train), | ||
702 | new ExportedParameter(body, var_location, parameter_location) | ||
703 | )); | ||
704 | // // int loop_bound1 = frame->location->connected_to_count;// for (int i1 = 0; i1 < loop_bound1; i1++) {// ...// } Train(train) | ||
705 | new TypeConstraint(body, Tuples.flatTupleOf(var_train), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Train"))); | ||
706 | // Train.location(train, location) | ||
707 | new TypeConstraint(body, Tuples.flatTupleOf(var_train), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Train"))); | ||
708 | PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); | ||
709 | new TypeConstraint(body, Tuples.flatTupleOf(var_train, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Train", "location"))); | ||
710 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
711 | new Equality(body, var__virtual_0_, var_location); | ||
712 | bodies.add(body); | ||
713 | } | ||
714 | return bodies; | ||
715 | } | ||
716 | } | ||
717 | } | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/EndOfSiding_step_4.java b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/EndOfSiding_step_4.java new file mode 100644 index 00000000..73df8514 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/EndOfSiding_step_4.java | |||
@@ -0,0 +1,847 @@ | |||
1 | /** | ||
2 | * Generated from platform:/resource/ca.mcgill.rtgmrt.example.modes3/src/modes3/queries/Modes3Queries.vql | ||
3 | */ | ||
4 | package modes3.queries; | ||
5 | |||
6 | import java.util.Arrays; | ||
7 | import java.util.Collection; | ||
8 | import java.util.LinkedHashSet; | ||
9 | import java.util.List; | ||
10 | import java.util.Objects; | ||
11 | import java.util.Optional; | ||
12 | import java.util.Set; | ||
13 | import java.util.function.Consumer; | ||
14 | import java.util.stream.Collectors; | ||
15 | import java.util.stream.Stream; | ||
16 | import modes3.Segment; | ||
17 | import modes3.Train; | ||
18 | import org.apache.log4j.Logger; | ||
19 | import org.eclipse.emf.ecore.EClass; | ||
20 | import org.eclipse.viatra.query.runtime.api.IPatternMatch; | ||
21 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification; | ||
22 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; | ||
23 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; | ||
24 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; | ||
25 | import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; | ||
26 | import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; | ||
27 | import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; | ||
28 | import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; | ||
29 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
30 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | ||
31 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | ||
32 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; | ||
33 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
34 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
35 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | ||
36 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; | ||
37 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | ||
38 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; | ||
39 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
40 | import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; | ||
41 | |||
42 | /** | ||
43 | * A pattern-specific query specification that can instantiate Matcher in a type-safe way. | ||
44 | * | ||
45 | * <p>Original source: | ||
46 | * <code><pre> | ||
47 | * pattern endOfSiding_step_4(in train : Train, in location : Segment, in end : Segment) { | ||
48 | * // frame-{@literal >}end = frame-{@literal >}location-{@literal >}connected_to[i1]; | ||
49 | * // if (frame-{@literal >}end != NULL && | ||
50 | * // frame-{@literal >}end-{@literal >}connected_to[1] == frame-{@literal >}location && | ||
51 | * // frame-{@literal >}end-{@literal >}connected_to[0] == NULL) { | ||
52 | * // ... | ||
53 | * // } | ||
54 | * // if (frame-{@literal >}end != NULL && | ||
55 | * // frame-{@literal >}end-{@literal >}connected_to[0] == frame-{@literal >}location && | ||
56 | * // frame-{@literal >}end-{@literal >}connected_to[1] == NULL) { | ||
57 | * // ... | ||
58 | * // } | ||
59 | * Train(train); | ||
60 | * Train.location(train, location); | ||
61 | * Segment.connectedTo(location, end); | ||
62 | * } | ||
63 | * </pre></code> | ||
64 | * | ||
65 | * @see Matcher | ||
66 | * @see Match | ||
67 | * | ||
68 | */ | ||
69 | @SuppressWarnings("all") | ||
70 | public final class EndOfSiding_step_4 extends BaseGeneratedEMFQuerySpecification<EndOfSiding_step_4.Matcher> { | ||
71 | /** | ||
72 | * Pattern-specific match representation of the modes3.queries.endOfSiding_step_4 pattern, | ||
73 | * to be used in conjunction with {@link Matcher}. | ||
74 | * | ||
75 | * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. | ||
76 | * Each instance is a (possibly partial) substitution of pattern parameters, | ||
77 | * usable to represent a match of the pattern in the result of a query, | ||
78 | * or to specify the bound (fixed) input parameters when issuing a query. | ||
79 | * | ||
80 | * @see Matcher | ||
81 | * | ||
82 | */ | ||
83 | public static abstract class Match extends BasePatternMatch { | ||
84 | private Train fTrain; | ||
85 | |||
86 | private Segment fLocation; | ||
87 | |||
88 | private Segment fEnd; | ||
89 | |||
90 | private static List<String> parameterNames = makeImmutableList("train", "location", "end"); | ||
91 | |||
92 | private Match(final Train pTrain, final Segment pLocation, final Segment pEnd) { | ||
93 | this.fTrain = pTrain; | ||
94 | this.fLocation = pLocation; | ||
95 | this.fEnd = pEnd; | ||
96 | } | ||
97 | |||
98 | @Override | ||
99 | public Object get(final String parameterName) { | ||
100 | switch(parameterName) { | ||
101 | case "train": return this.fTrain; | ||
102 | case "location": return this.fLocation; | ||
103 | case "end": return this.fEnd; | ||
104 | default: return null; | ||
105 | } | ||
106 | } | ||
107 | |||
108 | @Override | ||
109 | public Object get(final int index) { | ||
110 | switch(index) { | ||
111 | case 0: return this.fTrain; | ||
112 | case 1: return this.fLocation; | ||
113 | case 2: return this.fEnd; | ||
114 | default: return null; | ||
115 | } | ||
116 | } | ||
117 | |||
118 | public Train getTrain() { | ||
119 | return this.fTrain; | ||
120 | } | ||
121 | |||
122 | public Segment getLocation() { | ||
123 | return this.fLocation; | ||
124 | } | ||
125 | |||
126 | public Segment getEnd() { | ||
127 | return this.fEnd; | ||
128 | } | ||
129 | |||
130 | @Override | ||
131 | public boolean set(final String parameterName, final Object newValue) { | ||
132 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
133 | if ("train".equals(parameterName) ) { | ||
134 | this.fTrain = (Train) newValue; | ||
135 | return true; | ||
136 | } | ||
137 | if ("location".equals(parameterName) ) { | ||
138 | this.fLocation = (Segment) newValue; | ||
139 | return true; | ||
140 | } | ||
141 | if ("end".equals(parameterName) ) { | ||
142 | this.fEnd = (Segment) newValue; | ||
143 | return true; | ||
144 | } | ||
145 | return false; | ||
146 | } | ||
147 | |||
148 | public void setTrain(final Train pTrain) { | ||
149 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
150 | this.fTrain = pTrain; | ||
151 | } | ||
152 | |||
153 | public void setLocation(final Segment pLocation) { | ||
154 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
155 | this.fLocation = pLocation; | ||
156 | } | ||
157 | |||
158 | public void setEnd(final Segment pEnd) { | ||
159 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
160 | this.fEnd = pEnd; | ||
161 | } | ||
162 | |||
163 | @Override | ||
164 | public String patternName() { | ||
165 | return "modes3.queries.endOfSiding_step_4"; | ||
166 | } | ||
167 | |||
168 | @Override | ||
169 | public List<String> parameterNames() { | ||
170 | return EndOfSiding_step_4.Match.parameterNames; | ||
171 | } | ||
172 | |||
173 | @Override | ||
174 | public Object[] toArray() { | ||
175 | return new Object[]{fTrain, fLocation, fEnd}; | ||
176 | } | ||
177 | |||
178 | @Override | ||
179 | public EndOfSiding_step_4.Match toImmutable() { | ||
180 | return isMutable() ? newMatch(fTrain, fLocation, fEnd) : this; | ||
181 | } | ||
182 | |||
183 | @Override | ||
184 | public String prettyPrint() { | ||
185 | StringBuilder result = new StringBuilder(); | ||
186 | result.append("\"train\"=" + prettyPrintValue(fTrain) + ", "); | ||
187 | result.append("\"location\"=" + prettyPrintValue(fLocation) + ", "); | ||
188 | result.append("\"end\"=" + prettyPrintValue(fEnd)); | ||
189 | return result.toString(); | ||
190 | } | ||
191 | |||
192 | @Override | ||
193 | public int hashCode() { | ||
194 | return Objects.hash(fTrain, fLocation, fEnd); | ||
195 | } | ||
196 | |||
197 | @Override | ||
198 | public boolean equals(final Object obj) { | ||
199 | if (this == obj) | ||
200 | return true; | ||
201 | if (obj == null) { | ||
202 | return false; | ||
203 | } | ||
204 | if ((obj instanceof EndOfSiding_step_4.Match)) { | ||
205 | EndOfSiding_step_4.Match other = (EndOfSiding_step_4.Match) obj; | ||
206 | return Objects.equals(fTrain, other.fTrain) && Objects.equals(fLocation, other.fLocation) && Objects.equals(fEnd, other.fEnd); | ||
207 | } else { | ||
208 | // this should be infrequent | ||
209 | if (!(obj instanceof IPatternMatch)) { | ||
210 | return false; | ||
211 | } | ||
212 | IPatternMatch otherSig = (IPatternMatch) obj; | ||
213 | return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); | ||
214 | } | ||
215 | } | ||
216 | |||
217 | @Override | ||
218 | public EndOfSiding_step_4 specification() { | ||
219 | return EndOfSiding_step_4.instance(); | ||
220 | } | ||
221 | |||
222 | /** | ||
223 | * Returns an empty, mutable match. | ||
224 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
225 | * | ||
226 | * @return the empty match. | ||
227 | * | ||
228 | */ | ||
229 | public static EndOfSiding_step_4.Match newEmptyMatch() { | ||
230 | return new Mutable(null, null, null); | ||
231 | } | ||
232 | |||
233 | /** | ||
234 | * Returns a mutable (partial) match. | ||
235 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
236 | * | ||
237 | * @param pTrain the fixed value of pattern parameter train, or null if not bound. | ||
238 | * @param pLocation the fixed value of pattern parameter location, or null if not bound. | ||
239 | * @param pEnd the fixed value of pattern parameter end, or null if not bound. | ||
240 | * @return the new, mutable (partial) match object. | ||
241 | * | ||
242 | */ | ||
243 | public static EndOfSiding_step_4.Match newMutableMatch(final Train pTrain, final Segment pLocation, final Segment pEnd) { | ||
244 | return new Mutable(pTrain, pLocation, pEnd); | ||
245 | } | ||
246 | |||
247 | /** | ||
248 | * Returns a new (partial) match. | ||
249 | * This can be used e.g. to call the matcher with a partial match. | ||
250 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
251 | * @param pTrain the fixed value of pattern parameter train, or null if not bound. | ||
252 | * @param pLocation the fixed value of pattern parameter location, or null if not bound. | ||
253 | * @param pEnd the fixed value of pattern parameter end, or null if not bound. | ||
254 | * @return the (partial) match object. | ||
255 | * | ||
256 | */ | ||
257 | public static EndOfSiding_step_4.Match newMatch(final Train pTrain, final Segment pLocation, final Segment pEnd) { | ||
258 | return new Immutable(pTrain, pLocation, pEnd); | ||
259 | } | ||
260 | |||
261 | private static final class Mutable extends EndOfSiding_step_4.Match { | ||
262 | Mutable(final Train pTrain, final Segment pLocation, final Segment pEnd) { | ||
263 | super(pTrain, pLocation, pEnd); | ||
264 | } | ||
265 | |||
266 | @Override | ||
267 | public boolean isMutable() { | ||
268 | return true; | ||
269 | } | ||
270 | } | ||
271 | |||
272 | private static final class Immutable extends EndOfSiding_step_4.Match { | ||
273 | Immutable(final Train pTrain, final Segment pLocation, final Segment pEnd) { | ||
274 | super(pTrain, pLocation, pEnd); | ||
275 | } | ||
276 | |||
277 | @Override | ||
278 | public boolean isMutable() { | ||
279 | return false; | ||
280 | } | ||
281 | } | ||
282 | } | ||
283 | |||
284 | /** | ||
285 | * Generated pattern matcher API of the modes3.queries.endOfSiding_step_4 pattern, | ||
286 | * providing pattern-specific query methods. | ||
287 | * | ||
288 | * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, | ||
289 | * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. | ||
290 | * | ||
291 | * <p>Matches of the pattern will be represented as {@link Match}. | ||
292 | * | ||
293 | * <p>Original source: | ||
294 | * <code><pre> | ||
295 | * pattern endOfSiding_step_4(in train : Train, in location : Segment, in end : Segment) { | ||
296 | * // frame-{@literal >}end = frame-{@literal >}location-{@literal >}connected_to[i1]; | ||
297 | * // if (frame-{@literal >}end != NULL && | ||
298 | * // frame-{@literal >}end-{@literal >}connected_to[1] == frame-{@literal >}location && | ||
299 | * // frame-{@literal >}end-{@literal >}connected_to[0] == NULL) { | ||
300 | * // ... | ||
301 | * // } | ||
302 | * // if (frame-{@literal >}end != NULL && | ||
303 | * // frame-{@literal >}end-{@literal >}connected_to[0] == frame-{@literal >}location && | ||
304 | * // frame-{@literal >}end-{@literal >}connected_to[1] == NULL) { | ||
305 | * // ... | ||
306 | * // } | ||
307 | * Train(train); | ||
308 | * Train.location(train, location); | ||
309 | * Segment.connectedTo(location, end); | ||
310 | * } | ||
311 | * </pre></code> | ||
312 | * | ||
313 | * @see Match | ||
314 | * @see EndOfSiding_step_4 | ||
315 | * | ||
316 | */ | ||
317 | public static class Matcher extends BaseMatcher<EndOfSiding_step_4.Match> { | ||
318 | /** | ||
319 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
320 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
321 | * | ||
322 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
323 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
324 | * | ||
325 | */ | ||
326 | public static EndOfSiding_step_4.Matcher on(final ViatraQueryEngine engine) { | ||
327 | // check if matcher already exists | ||
328 | Matcher matcher = engine.getExistingMatcher(querySpecification()); | ||
329 | if (matcher == null) { | ||
330 | matcher = (Matcher)engine.getMatcher(querySpecification()); | ||
331 | } | ||
332 | return matcher; | ||
333 | } | ||
334 | |||
335 | /** | ||
336 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
337 | * @return an initialized matcher | ||
338 | * @noreference This method is for internal matcher initialization by the framework, do not call it manually. | ||
339 | * | ||
340 | */ | ||
341 | public static EndOfSiding_step_4.Matcher create() { | ||
342 | return new Matcher(); | ||
343 | } | ||
344 | |||
345 | private static final int POSITION_TRAIN = 0; | ||
346 | |||
347 | private static final int POSITION_LOCATION = 1; | ||
348 | |||
349 | private static final int POSITION_END = 2; | ||
350 | |||
351 | private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(EndOfSiding_step_4.Matcher.class); | ||
352 | |||
353 | /** | ||
354 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
355 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
356 | * | ||
357 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
358 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
359 | * | ||
360 | */ | ||
361 | private Matcher() { | ||
362 | super(querySpecification()); | ||
363 | } | ||
364 | |||
365 | /** | ||
366 | * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. | ||
367 | * @param pTrain the fixed value of pattern parameter train, or null if not bound. | ||
368 | * @param pLocation the fixed value of pattern parameter location, or null if not bound. | ||
369 | * @param pEnd the fixed value of pattern parameter end, or null if not bound. | ||
370 | * @return matches represented as a Match object. | ||
371 | * | ||
372 | */ | ||
373 | public Collection<EndOfSiding_step_4.Match> getAllMatches(final Train pTrain, final Segment pLocation, final Segment pEnd) { | ||
374 | return rawStreamAllMatches(new Object[]{pTrain, pLocation, pEnd}).collect(Collectors.toSet()); | ||
375 | } | ||
376 | |||
377 | /** | ||
378 | * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. | ||
379 | * </p> | ||
380 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
381 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
382 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
383 | * @param pTrain the fixed value of pattern parameter train, or null if not bound. | ||
384 | * @param pLocation the fixed value of pattern parameter location, or null if not bound. | ||
385 | * @param pEnd the fixed value of pattern parameter end, or null if not bound. | ||
386 | * @return a stream of matches represented as a Match object. | ||
387 | * | ||
388 | */ | ||
389 | public Stream<EndOfSiding_step_4.Match> streamAllMatches(final Train pTrain, final Segment pLocation, final Segment pEnd) { | ||
390 | return rawStreamAllMatches(new Object[]{pTrain, pLocation, pEnd}); | ||
391 | } | ||
392 | |||
393 | /** | ||
394 | * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
395 | * Neither determinism nor randomness of selection is guaranteed. | ||
396 | * @param pTrain the fixed value of pattern parameter train, or null if not bound. | ||
397 | * @param pLocation the fixed value of pattern parameter location, or null if not bound. | ||
398 | * @param pEnd the fixed value of pattern parameter end, or null if not bound. | ||
399 | * @return a match represented as a Match object, or null if no match is found. | ||
400 | * | ||
401 | */ | ||
402 | public Optional<EndOfSiding_step_4.Match> getOneArbitraryMatch(final Train pTrain, final Segment pLocation, final Segment pEnd) { | ||
403 | return rawGetOneArbitraryMatch(new Object[]{pTrain, pLocation, pEnd}); | ||
404 | } | ||
405 | |||
406 | /** | ||
407 | * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, | ||
408 | * under any possible substitution of the unspecified parameters (if any). | ||
409 | * @param pTrain the fixed value of pattern parameter train, or null if not bound. | ||
410 | * @param pLocation the fixed value of pattern parameter location, or null if not bound. | ||
411 | * @param pEnd the fixed value of pattern parameter end, or null if not bound. | ||
412 | * @return true if the input is a valid (partial) match of the pattern. | ||
413 | * | ||
414 | */ | ||
415 | public boolean hasMatch(final Train pTrain, final Segment pLocation, final Segment pEnd) { | ||
416 | return rawHasMatch(new Object[]{pTrain, pLocation, pEnd}); | ||
417 | } | ||
418 | |||
419 | /** | ||
420 | * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. | ||
421 | * @param pTrain the fixed value of pattern parameter train, or null if not bound. | ||
422 | * @param pLocation the fixed value of pattern parameter location, or null if not bound. | ||
423 | * @param pEnd the fixed value of pattern parameter end, or null if not bound. | ||
424 | * @return the number of pattern matches found. | ||
425 | * | ||
426 | */ | ||
427 | public int countMatches(final Train pTrain, final Segment pLocation, final Segment pEnd) { | ||
428 | return rawCountMatches(new Object[]{pTrain, pLocation, pEnd}); | ||
429 | } | ||
430 | |||
431 | /** | ||
432 | * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
433 | * Neither determinism nor randomness of selection is guaranteed. | ||
434 | * @param pTrain the fixed value of pattern parameter train, or null if not bound. | ||
435 | * @param pLocation the fixed value of pattern parameter location, or null if not bound. | ||
436 | * @param pEnd the fixed value of pattern parameter end, or null if not bound. | ||
437 | * @param processor the action that will process the selected match. | ||
438 | * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked | ||
439 | * | ||
440 | */ | ||
441 | public boolean forOneArbitraryMatch(final Train pTrain, final Segment pLocation, final Segment pEnd, final Consumer<? super EndOfSiding_step_4.Match> processor) { | ||
442 | return rawForOneArbitraryMatch(new Object[]{pTrain, pLocation, pEnd}, processor); | ||
443 | } | ||
444 | |||
445 | /** | ||
446 | * Returns a new (partial) match. | ||
447 | * This can be used e.g. to call the matcher with a partial match. | ||
448 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
449 | * @param pTrain the fixed value of pattern parameter train, or null if not bound. | ||
450 | * @param pLocation the fixed value of pattern parameter location, or null if not bound. | ||
451 | * @param pEnd the fixed value of pattern parameter end, or null if not bound. | ||
452 | * @return the (partial) match object. | ||
453 | * | ||
454 | */ | ||
455 | public EndOfSiding_step_4.Match newMatch(final Train pTrain, final Segment pLocation, final Segment pEnd) { | ||
456 | return EndOfSiding_step_4.Match.newMatch(pTrain, pLocation, pEnd); | ||
457 | } | ||
458 | |||
459 | /** | ||
460 | * Retrieve the set of values that occur in matches for train. | ||
461 | * @return the Set of all values or empty set if there are no matches | ||
462 | * | ||
463 | */ | ||
464 | protected Stream<Train> rawStreamAllValuesOftrain(final Object[] parameters) { | ||
465 | return rawStreamAllValues(POSITION_TRAIN, parameters).map(Train.class::cast); | ||
466 | } | ||
467 | |||
468 | /** | ||
469 | * Retrieve the set of values that occur in matches for train. | ||
470 | * @return the Set of all values or empty set if there are no matches | ||
471 | * | ||
472 | */ | ||
473 | public Set<Train> getAllValuesOftrain() { | ||
474 | return rawStreamAllValuesOftrain(emptyArray()).collect(Collectors.toSet()); | ||
475 | } | ||
476 | |||
477 | /** | ||
478 | * Retrieve the set of values that occur in matches for train. | ||
479 | * @return the Set of all values or empty set if there are no matches | ||
480 | * | ||
481 | */ | ||
482 | public Stream<Train> streamAllValuesOftrain() { | ||
483 | return rawStreamAllValuesOftrain(emptyArray()); | ||
484 | } | ||
485 | |||
486 | /** | ||
487 | * Retrieve the set of values that occur in matches for train. | ||
488 | * </p> | ||
489 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
490 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
491 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
492 | * | ||
493 | * @return the Stream of all values or empty set if there are no matches | ||
494 | * | ||
495 | */ | ||
496 | public Stream<Train> streamAllValuesOftrain(final EndOfSiding_step_4.Match partialMatch) { | ||
497 | return rawStreamAllValuesOftrain(partialMatch.toArray()); | ||
498 | } | ||
499 | |||
500 | /** | ||
501 | * Retrieve the set of values that occur in matches for train. | ||
502 | * </p> | ||
503 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
504 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
505 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
506 | * | ||
507 | * @return the Stream of all values or empty set if there are no matches | ||
508 | * | ||
509 | */ | ||
510 | public Stream<Train> streamAllValuesOftrain(final Segment pLocation, final Segment pEnd) { | ||
511 | return rawStreamAllValuesOftrain(new Object[]{null, pLocation, pEnd}); | ||
512 | } | ||
513 | |||
514 | /** | ||
515 | * Retrieve the set of values that occur in matches for train. | ||
516 | * @return the Set of all values or empty set if there are no matches | ||
517 | * | ||
518 | */ | ||
519 | public Set<Train> getAllValuesOftrain(final EndOfSiding_step_4.Match partialMatch) { | ||
520 | return rawStreamAllValuesOftrain(partialMatch.toArray()).collect(Collectors.toSet()); | ||
521 | } | ||
522 | |||
523 | /** | ||
524 | * Retrieve the set of values that occur in matches for train. | ||
525 | * @return the Set of all values or empty set if there are no matches | ||
526 | * | ||
527 | */ | ||
528 | public Set<Train> getAllValuesOftrain(final Segment pLocation, final Segment pEnd) { | ||
529 | return rawStreamAllValuesOftrain(new Object[]{null, pLocation, pEnd}).collect(Collectors.toSet()); | ||
530 | } | ||
531 | |||
532 | /** | ||
533 | * Retrieve the set of values that occur in matches for location. | ||
534 | * @return the Set of all values or empty set if there are no matches | ||
535 | * | ||
536 | */ | ||
537 | protected Stream<Segment> rawStreamAllValuesOflocation(final Object[] parameters) { | ||
538 | return rawStreamAllValues(POSITION_LOCATION, parameters).map(Segment.class::cast); | ||
539 | } | ||
540 | |||
541 | /** | ||
542 | * Retrieve the set of values that occur in matches for location. | ||
543 | * @return the Set of all values or empty set if there are no matches | ||
544 | * | ||
545 | */ | ||
546 | public Set<Segment> getAllValuesOflocation() { | ||
547 | return rawStreamAllValuesOflocation(emptyArray()).collect(Collectors.toSet()); | ||
548 | } | ||
549 | |||
550 | /** | ||
551 | * Retrieve the set of values that occur in matches for location. | ||
552 | * @return the Set of all values or empty set if there are no matches | ||
553 | * | ||
554 | */ | ||
555 | public Stream<Segment> streamAllValuesOflocation() { | ||
556 | return rawStreamAllValuesOflocation(emptyArray()); | ||
557 | } | ||
558 | |||
559 | /** | ||
560 | * Retrieve the set of values that occur in matches for location. | ||
561 | * </p> | ||
562 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
563 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
564 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
565 | * | ||
566 | * @return the Stream of all values or empty set if there are no matches | ||
567 | * | ||
568 | */ | ||
569 | public Stream<Segment> streamAllValuesOflocation(final EndOfSiding_step_4.Match partialMatch) { | ||
570 | return rawStreamAllValuesOflocation(partialMatch.toArray()); | ||
571 | } | ||
572 | |||
573 | /** | ||
574 | * Retrieve the set of values that occur in matches for location. | ||
575 | * </p> | ||
576 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
577 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
578 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
579 | * | ||
580 | * @return the Stream of all values or empty set if there are no matches | ||
581 | * | ||
582 | */ | ||
583 | public Stream<Segment> streamAllValuesOflocation(final Train pTrain, final Segment pEnd) { | ||
584 | return rawStreamAllValuesOflocation(new Object[]{pTrain, null, pEnd}); | ||
585 | } | ||
586 | |||
587 | /** | ||
588 | * Retrieve the set of values that occur in matches for location. | ||
589 | * @return the Set of all values or empty set if there are no matches | ||
590 | * | ||
591 | */ | ||
592 | public Set<Segment> getAllValuesOflocation(final EndOfSiding_step_4.Match partialMatch) { | ||
593 | return rawStreamAllValuesOflocation(partialMatch.toArray()).collect(Collectors.toSet()); | ||
594 | } | ||
595 | |||
596 | /** | ||
597 | * Retrieve the set of values that occur in matches for location. | ||
598 | * @return the Set of all values or empty set if there are no matches | ||
599 | * | ||
600 | */ | ||
601 | public Set<Segment> getAllValuesOflocation(final Train pTrain, final Segment pEnd) { | ||
602 | return rawStreamAllValuesOflocation(new Object[]{pTrain, null, pEnd}).collect(Collectors.toSet()); | ||
603 | } | ||
604 | |||
605 | /** | ||
606 | * Retrieve the set of values that occur in matches for end. | ||
607 | * @return the Set of all values or empty set if there are no matches | ||
608 | * | ||
609 | */ | ||
610 | protected Stream<Segment> rawStreamAllValuesOfend(final Object[] parameters) { | ||
611 | return rawStreamAllValues(POSITION_END, parameters).map(Segment.class::cast); | ||
612 | } | ||
613 | |||
614 | /** | ||
615 | * Retrieve the set of values that occur in matches for end. | ||
616 | * @return the Set of all values or empty set if there are no matches | ||
617 | * | ||
618 | */ | ||
619 | public Set<Segment> getAllValuesOfend() { | ||
620 | return rawStreamAllValuesOfend(emptyArray()).collect(Collectors.toSet()); | ||
621 | } | ||
622 | |||
623 | /** | ||
624 | * Retrieve the set of values that occur in matches for end. | ||
625 | * @return the Set of all values or empty set if there are no matches | ||
626 | * | ||
627 | */ | ||
628 | public Stream<Segment> streamAllValuesOfend() { | ||
629 | return rawStreamAllValuesOfend(emptyArray()); | ||
630 | } | ||
631 | |||
632 | /** | ||
633 | * Retrieve the set of values that occur in matches for end. | ||
634 | * </p> | ||
635 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
636 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
637 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
638 | * | ||
639 | * @return the Stream of all values or empty set if there are no matches | ||
640 | * | ||
641 | */ | ||
642 | public Stream<Segment> streamAllValuesOfend(final EndOfSiding_step_4.Match partialMatch) { | ||
643 | return rawStreamAllValuesOfend(partialMatch.toArray()); | ||
644 | } | ||
645 | |||
646 | /** | ||
647 | * Retrieve the set of values that occur in matches for end. | ||
648 | * </p> | ||
649 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
650 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
651 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
652 | * | ||
653 | * @return the Stream of all values or empty set if there are no matches | ||
654 | * | ||
655 | */ | ||
656 | public Stream<Segment> streamAllValuesOfend(final Train pTrain, final Segment pLocation) { | ||
657 | return rawStreamAllValuesOfend(new Object[]{pTrain, pLocation, null}); | ||
658 | } | ||
659 | |||
660 | /** | ||
661 | * Retrieve the set of values that occur in matches for end. | ||
662 | * @return the Set of all values or empty set if there are no matches | ||
663 | * | ||
664 | */ | ||
665 | public Set<Segment> getAllValuesOfend(final EndOfSiding_step_4.Match partialMatch) { | ||
666 | return rawStreamAllValuesOfend(partialMatch.toArray()).collect(Collectors.toSet()); | ||
667 | } | ||
668 | |||
669 | /** | ||
670 | * Retrieve the set of values that occur in matches for end. | ||
671 | * @return the Set of all values or empty set if there are no matches | ||
672 | * | ||
673 | */ | ||
674 | public Set<Segment> getAllValuesOfend(final Train pTrain, final Segment pLocation) { | ||
675 | return rawStreamAllValuesOfend(new Object[]{pTrain, pLocation, null}).collect(Collectors.toSet()); | ||
676 | } | ||
677 | |||
678 | @Override | ||
679 | protected EndOfSiding_step_4.Match tupleToMatch(final Tuple t) { | ||
680 | try { | ||
681 | return EndOfSiding_step_4.Match.newMatch((Train) t.get(POSITION_TRAIN), (Segment) t.get(POSITION_LOCATION), (Segment) t.get(POSITION_END)); | ||
682 | } catch(ClassCastException e) { | ||
683 | LOGGER.error("Element(s) in tuple not properly typed!",e); | ||
684 | return null; | ||
685 | } | ||
686 | } | ||
687 | |||
688 | @Override | ||
689 | protected EndOfSiding_step_4.Match arrayToMatch(final Object[] match) { | ||
690 | try { | ||
691 | return EndOfSiding_step_4.Match.newMatch((Train) match[POSITION_TRAIN], (Segment) match[POSITION_LOCATION], (Segment) match[POSITION_END]); | ||
692 | } catch(ClassCastException e) { | ||
693 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
694 | return null; | ||
695 | } | ||
696 | } | ||
697 | |||
698 | @Override | ||
699 | protected EndOfSiding_step_4.Match arrayToMatchMutable(final Object[] match) { | ||
700 | try { | ||
701 | return EndOfSiding_step_4.Match.newMutableMatch((Train) match[POSITION_TRAIN], (Segment) match[POSITION_LOCATION], (Segment) match[POSITION_END]); | ||
702 | } catch(ClassCastException e) { | ||
703 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
704 | return null; | ||
705 | } | ||
706 | } | ||
707 | |||
708 | /** | ||
709 | * @return the singleton instance of the query specification of this pattern | ||
710 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
711 | * | ||
712 | */ | ||
713 | public static IQuerySpecification<EndOfSiding_step_4.Matcher> querySpecification() { | ||
714 | return EndOfSiding_step_4.instance(); | ||
715 | } | ||
716 | } | ||
717 | |||
718 | private EndOfSiding_step_4() { | ||
719 | super(GeneratedPQuery.INSTANCE); | ||
720 | } | ||
721 | |||
722 | /** | ||
723 | * @return the singleton instance of the query specification | ||
724 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
725 | * | ||
726 | */ | ||
727 | public static EndOfSiding_step_4 instance() { | ||
728 | try{ | ||
729 | return LazyHolder.INSTANCE; | ||
730 | } catch (ExceptionInInitializerError err) { | ||
731 | throw processInitializerError(err); | ||
732 | } | ||
733 | } | ||
734 | |||
735 | @Override | ||
736 | protected EndOfSiding_step_4.Matcher instantiate(final ViatraQueryEngine engine) { | ||
737 | return EndOfSiding_step_4.Matcher.on(engine); | ||
738 | } | ||
739 | |||
740 | @Override | ||
741 | public EndOfSiding_step_4.Matcher instantiate() { | ||
742 | return EndOfSiding_step_4.Matcher.create(); | ||
743 | } | ||
744 | |||
745 | @Override | ||
746 | public EndOfSiding_step_4.Match newEmptyMatch() { | ||
747 | return EndOfSiding_step_4.Match.newEmptyMatch(); | ||
748 | } | ||
749 | |||
750 | @Override | ||
751 | public EndOfSiding_step_4.Match newMatch(final Object... parameters) { | ||
752 | return EndOfSiding_step_4.Match.newMatch((modes3.Train) parameters[0], (modes3.Segment) parameters[1], (modes3.Segment) parameters[2]); | ||
753 | } | ||
754 | |||
755 | /** | ||
756 | * Inner class allowing the singleton instance of {@link EndOfSiding_step_4} to be created | ||
757 | * <b>not</b> at the class load time of the outer class, | ||
758 | * but rather at the first call to {@link EndOfSiding_step_4#instance()}. | ||
759 | * | ||
760 | * <p> This workaround is required e.g. to support recursion. | ||
761 | * | ||
762 | */ | ||
763 | private static class LazyHolder { | ||
764 | private static final EndOfSiding_step_4 INSTANCE = new EndOfSiding_step_4(); | ||
765 | |||
766 | /** | ||
767 | * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned. | ||
768 | * This initialization order is required to support indirect recursion. | ||
769 | * | ||
770 | * <p> The static initializer is defined using a helper field to work around limitations of the code generator. | ||
771 | * | ||
772 | */ | ||
773 | private static final Object STATIC_INITIALIZER = ensureInitialized(); | ||
774 | |||
775 | public static Object ensureInitialized() { | ||
776 | INSTANCE.ensureInitializedInternal(); | ||
777 | return null; | ||
778 | } | ||
779 | } | ||
780 | |||
781 | private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { | ||
782 | private static final EndOfSiding_step_4.GeneratedPQuery INSTANCE = new GeneratedPQuery(); | ||
783 | |||
784 | private final PParameter parameter_train = new PParameter("train", "modes3.Train", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Train")), PParameterDirection.INOUT); | ||
785 | |||
786 | private final PParameter parameter_location = new PParameter("location", "modes3.Segment", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Segment")), PParameterDirection.INOUT); | ||
787 | |||
788 | private final PParameter parameter_end = new PParameter("end", "modes3.Segment", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Segment")), PParameterDirection.INOUT); | ||
789 | |||
790 | private final List<PParameter> parameters = Arrays.asList(parameter_train, parameter_location, parameter_end); | ||
791 | |||
792 | private GeneratedPQuery() { | ||
793 | super(PVisibility.PUBLIC); | ||
794 | } | ||
795 | |||
796 | @Override | ||
797 | public String getFullyQualifiedName() { | ||
798 | return "modes3.queries.endOfSiding_step_4"; | ||
799 | } | ||
800 | |||
801 | @Override | ||
802 | public List<String> getParameterNames() { | ||
803 | return Arrays.asList("train","location","end"); | ||
804 | } | ||
805 | |||
806 | @Override | ||
807 | public List<PParameter> getParameters() { | ||
808 | return parameters; | ||
809 | } | ||
810 | |||
811 | @Override | ||
812 | public Set<PBody> doGetContainedBodies() { | ||
813 | setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); | ||
814 | Set<PBody> bodies = new LinkedHashSet<>(); | ||
815 | { | ||
816 | PBody body = new PBody(this); | ||
817 | PVariable var_train = body.getOrCreateVariableByName("train"); | ||
818 | PVariable var_location = body.getOrCreateVariableByName("location"); | ||
819 | PVariable var_end = body.getOrCreateVariableByName("end"); | ||
820 | new TypeConstraint(body, Tuples.flatTupleOf(var_train), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Train"))); | ||
821 | new TypeConstraint(body, Tuples.flatTupleOf(var_location), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
822 | new TypeConstraint(body, Tuples.flatTupleOf(var_end), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
823 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
824 | new ExportedParameter(body, var_train, parameter_train), | ||
825 | new ExportedParameter(body, var_location, parameter_location), | ||
826 | new ExportedParameter(body, var_end, parameter_end) | ||
827 | )); | ||
828 | // // frame->end = frame->location->connected_to[i1];// if (frame->end != NULL &&// frame->end->connected_to[1] == frame->location &&// frame->end->connected_to[0] == NULL) {// ...// } // if (frame->end != NULL &&// frame->end->connected_to[0] == frame->location &&// frame->end->connected_to[1] == NULL) {// ...// } Train(train) | ||
829 | new TypeConstraint(body, Tuples.flatTupleOf(var_train), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Train"))); | ||
830 | // Train.location(train, location) | ||
831 | new TypeConstraint(body, Tuples.flatTupleOf(var_train), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Train"))); | ||
832 | PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); | ||
833 | new TypeConstraint(body, Tuples.flatTupleOf(var_train, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Train", "location"))); | ||
834 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
835 | new Equality(body, var__virtual_0_, var_location); | ||
836 | // Segment.connectedTo(location, end) | ||
837 | new TypeConstraint(body, Tuples.flatTupleOf(var_location), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
838 | PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); | ||
839 | new TypeConstraint(body, Tuples.flatTupleOf(var_location, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment", "connectedTo"))); | ||
840 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
841 | new Equality(body, var__virtual_1_, var_end); | ||
842 | bodies.add(body); | ||
843 | } | ||
844 | return bodies; | ||
845 | } | ||
846 | } | ||
847 | } | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/EndOfSiding_step_5.java b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/EndOfSiding_step_5.java new file mode 100644 index 00000000..48a2697d --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/EndOfSiding_step_5.java | |||
@@ -0,0 +1,841 @@ | |||
1 | /** | ||
2 | * Generated from platform:/resource/ca.mcgill.rtgmrt.example.modes3/src/modes3/queries/Modes3Queries.vql | ||
3 | */ | ||
4 | package modes3.queries; | ||
5 | |||
6 | import java.util.Arrays; | ||
7 | import java.util.Collection; | ||
8 | import java.util.LinkedHashSet; | ||
9 | import java.util.List; | ||
10 | import java.util.Objects; | ||
11 | import java.util.Optional; | ||
12 | import java.util.Set; | ||
13 | import java.util.function.Consumer; | ||
14 | import java.util.stream.Collectors; | ||
15 | import java.util.stream.Stream; | ||
16 | import modes3.Segment; | ||
17 | import modes3.Train; | ||
18 | import modes3.queries.MultipleConnectedTo; | ||
19 | import org.apache.log4j.Logger; | ||
20 | import org.eclipse.emf.ecore.EClass; | ||
21 | import org.eclipse.viatra.query.runtime.api.IPatternMatch; | ||
22 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification; | ||
23 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; | ||
24 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; | ||
25 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; | ||
26 | import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; | ||
27 | import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; | ||
28 | import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; | ||
29 | import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; | ||
30 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
31 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | ||
32 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | ||
33 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; | ||
34 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
35 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.NegativePatternCall; | ||
36 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
37 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | ||
38 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; | ||
39 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | ||
40 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; | ||
41 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
42 | import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; | ||
43 | |||
44 | /** | ||
45 | * A pattern-specific query specification that can instantiate Matcher in a type-safe way. | ||
46 | * | ||
47 | * <p>Original source: | ||
48 | * <code><pre> | ||
49 | * pattern endOfSiding_step_5(in train : Train, in location : Segment, in end : Segment) { | ||
50 | * // results-{@literal >}matches[match_cntr].location = frame-{@literal >}location; | ||
51 | * // results-{@literal >}matches[match_cntr++].train = frame-{@literal >}train; | ||
52 | * // ...OR... | ||
53 | * // results-{@literal >}matches[match_cntr].location = frame-{@literal >}location; | ||
54 | * // results-{@literal >}matches[match_cntr++].train = frame-{@literal >}train; | ||
55 | * Train(train); | ||
56 | * Train.location(train, location); | ||
57 | * Segment.connectedTo(location, end); | ||
58 | * neg find multipleConnectedTo(end); | ||
59 | * } | ||
60 | * </pre></code> | ||
61 | * | ||
62 | * @see Matcher | ||
63 | * @see Match | ||
64 | * | ||
65 | */ | ||
66 | @SuppressWarnings("all") | ||
67 | public final class EndOfSiding_step_5 extends BaseGeneratedEMFQuerySpecification<EndOfSiding_step_5.Matcher> { | ||
68 | /** | ||
69 | * Pattern-specific match representation of the modes3.queries.endOfSiding_step_5 pattern, | ||
70 | * to be used in conjunction with {@link Matcher}. | ||
71 | * | ||
72 | * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. | ||
73 | * Each instance is a (possibly partial) substitution of pattern parameters, | ||
74 | * usable to represent a match of the pattern in the result of a query, | ||
75 | * or to specify the bound (fixed) input parameters when issuing a query. | ||
76 | * | ||
77 | * @see Matcher | ||
78 | * | ||
79 | */ | ||
80 | public static abstract class Match extends BasePatternMatch { | ||
81 | private Train fTrain; | ||
82 | |||
83 | private Segment fLocation; | ||
84 | |||
85 | private Segment fEnd; | ||
86 | |||
87 | private static List<String> parameterNames = makeImmutableList("train", "location", "end"); | ||
88 | |||
89 | private Match(final Train pTrain, final Segment pLocation, final Segment pEnd) { | ||
90 | this.fTrain = pTrain; | ||
91 | this.fLocation = pLocation; | ||
92 | this.fEnd = pEnd; | ||
93 | } | ||
94 | |||
95 | @Override | ||
96 | public Object get(final String parameterName) { | ||
97 | switch(parameterName) { | ||
98 | case "train": return this.fTrain; | ||
99 | case "location": return this.fLocation; | ||
100 | case "end": return this.fEnd; | ||
101 | default: return null; | ||
102 | } | ||
103 | } | ||
104 | |||
105 | @Override | ||
106 | public Object get(final int index) { | ||
107 | switch(index) { | ||
108 | case 0: return this.fTrain; | ||
109 | case 1: return this.fLocation; | ||
110 | case 2: return this.fEnd; | ||
111 | default: return null; | ||
112 | } | ||
113 | } | ||
114 | |||
115 | public Train getTrain() { | ||
116 | return this.fTrain; | ||
117 | } | ||
118 | |||
119 | public Segment getLocation() { | ||
120 | return this.fLocation; | ||
121 | } | ||
122 | |||
123 | public Segment getEnd() { | ||
124 | return this.fEnd; | ||
125 | } | ||
126 | |||
127 | @Override | ||
128 | public boolean set(final String parameterName, final Object newValue) { | ||
129 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
130 | if ("train".equals(parameterName) ) { | ||
131 | this.fTrain = (Train) newValue; | ||
132 | return true; | ||
133 | } | ||
134 | if ("location".equals(parameterName) ) { | ||
135 | this.fLocation = (Segment) newValue; | ||
136 | return true; | ||
137 | } | ||
138 | if ("end".equals(parameterName) ) { | ||
139 | this.fEnd = (Segment) newValue; | ||
140 | return true; | ||
141 | } | ||
142 | return false; | ||
143 | } | ||
144 | |||
145 | public void setTrain(final Train pTrain) { | ||
146 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
147 | this.fTrain = pTrain; | ||
148 | } | ||
149 | |||
150 | public void setLocation(final Segment pLocation) { | ||
151 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
152 | this.fLocation = pLocation; | ||
153 | } | ||
154 | |||
155 | public void setEnd(final Segment pEnd) { | ||
156 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
157 | this.fEnd = pEnd; | ||
158 | } | ||
159 | |||
160 | @Override | ||
161 | public String patternName() { | ||
162 | return "modes3.queries.endOfSiding_step_5"; | ||
163 | } | ||
164 | |||
165 | @Override | ||
166 | public List<String> parameterNames() { | ||
167 | return EndOfSiding_step_5.Match.parameterNames; | ||
168 | } | ||
169 | |||
170 | @Override | ||
171 | public Object[] toArray() { | ||
172 | return new Object[]{fTrain, fLocation, fEnd}; | ||
173 | } | ||
174 | |||
175 | @Override | ||
176 | public EndOfSiding_step_5.Match toImmutable() { | ||
177 | return isMutable() ? newMatch(fTrain, fLocation, fEnd) : this; | ||
178 | } | ||
179 | |||
180 | @Override | ||
181 | public String prettyPrint() { | ||
182 | StringBuilder result = new StringBuilder(); | ||
183 | result.append("\"train\"=" + prettyPrintValue(fTrain) + ", "); | ||
184 | result.append("\"location\"=" + prettyPrintValue(fLocation) + ", "); | ||
185 | result.append("\"end\"=" + prettyPrintValue(fEnd)); | ||
186 | return result.toString(); | ||
187 | } | ||
188 | |||
189 | @Override | ||
190 | public int hashCode() { | ||
191 | return Objects.hash(fTrain, fLocation, fEnd); | ||
192 | } | ||
193 | |||
194 | @Override | ||
195 | public boolean equals(final Object obj) { | ||
196 | if (this == obj) | ||
197 | return true; | ||
198 | if (obj == null) { | ||
199 | return false; | ||
200 | } | ||
201 | if ((obj instanceof EndOfSiding_step_5.Match)) { | ||
202 | EndOfSiding_step_5.Match other = (EndOfSiding_step_5.Match) obj; | ||
203 | return Objects.equals(fTrain, other.fTrain) && Objects.equals(fLocation, other.fLocation) && Objects.equals(fEnd, other.fEnd); | ||
204 | } else { | ||
205 | // this should be infrequent | ||
206 | if (!(obj instanceof IPatternMatch)) { | ||
207 | return false; | ||
208 | } | ||
209 | IPatternMatch otherSig = (IPatternMatch) obj; | ||
210 | return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); | ||
211 | } | ||
212 | } | ||
213 | |||
214 | @Override | ||
215 | public EndOfSiding_step_5 specification() { | ||
216 | return EndOfSiding_step_5.instance(); | ||
217 | } | ||
218 | |||
219 | /** | ||
220 | * Returns an empty, mutable match. | ||
221 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
222 | * | ||
223 | * @return the empty match. | ||
224 | * | ||
225 | */ | ||
226 | public static EndOfSiding_step_5.Match newEmptyMatch() { | ||
227 | return new Mutable(null, null, null); | ||
228 | } | ||
229 | |||
230 | /** | ||
231 | * Returns a mutable (partial) match. | ||
232 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
233 | * | ||
234 | * @param pTrain the fixed value of pattern parameter train, or null if not bound. | ||
235 | * @param pLocation the fixed value of pattern parameter location, or null if not bound. | ||
236 | * @param pEnd the fixed value of pattern parameter end, or null if not bound. | ||
237 | * @return the new, mutable (partial) match object. | ||
238 | * | ||
239 | */ | ||
240 | public static EndOfSiding_step_5.Match newMutableMatch(final Train pTrain, final Segment pLocation, final Segment pEnd) { | ||
241 | return new Mutable(pTrain, pLocation, pEnd); | ||
242 | } | ||
243 | |||
244 | /** | ||
245 | * Returns a new (partial) match. | ||
246 | * This can be used e.g. to call the matcher with a partial match. | ||
247 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
248 | * @param pTrain the fixed value of pattern parameter train, or null if not bound. | ||
249 | * @param pLocation the fixed value of pattern parameter location, or null if not bound. | ||
250 | * @param pEnd the fixed value of pattern parameter end, or null if not bound. | ||
251 | * @return the (partial) match object. | ||
252 | * | ||
253 | */ | ||
254 | public static EndOfSiding_step_5.Match newMatch(final Train pTrain, final Segment pLocation, final Segment pEnd) { | ||
255 | return new Immutable(pTrain, pLocation, pEnd); | ||
256 | } | ||
257 | |||
258 | private static final class Mutable extends EndOfSiding_step_5.Match { | ||
259 | Mutable(final Train pTrain, final Segment pLocation, final Segment pEnd) { | ||
260 | super(pTrain, pLocation, pEnd); | ||
261 | } | ||
262 | |||
263 | @Override | ||
264 | public boolean isMutable() { | ||
265 | return true; | ||
266 | } | ||
267 | } | ||
268 | |||
269 | private static final class Immutable extends EndOfSiding_step_5.Match { | ||
270 | Immutable(final Train pTrain, final Segment pLocation, final Segment pEnd) { | ||
271 | super(pTrain, pLocation, pEnd); | ||
272 | } | ||
273 | |||
274 | @Override | ||
275 | public boolean isMutable() { | ||
276 | return false; | ||
277 | } | ||
278 | } | ||
279 | } | ||
280 | |||
281 | /** | ||
282 | * Generated pattern matcher API of the modes3.queries.endOfSiding_step_5 pattern, | ||
283 | * providing pattern-specific query methods. | ||
284 | * | ||
285 | * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, | ||
286 | * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. | ||
287 | * | ||
288 | * <p>Matches of the pattern will be represented as {@link Match}. | ||
289 | * | ||
290 | * <p>Original source: | ||
291 | * <code><pre> | ||
292 | * pattern endOfSiding_step_5(in train : Train, in location : Segment, in end : Segment) { | ||
293 | * // results-{@literal >}matches[match_cntr].location = frame-{@literal >}location; | ||
294 | * // results-{@literal >}matches[match_cntr++].train = frame-{@literal >}train; | ||
295 | * // ...OR... | ||
296 | * // results-{@literal >}matches[match_cntr].location = frame-{@literal >}location; | ||
297 | * // results-{@literal >}matches[match_cntr++].train = frame-{@literal >}train; | ||
298 | * Train(train); | ||
299 | * Train.location(train, location); | ||
300 | * Segment.connectedTo(location, end); | ||
301 | * neg find multipleConnectedTo(end); | ||
302 | * } | ||
303 | * </pre></code> | ||
304 | * | ||
305 | * @see Match | ||
306 | * @see EndOfSiding_step_5 | ||
307 | * | ||
308 | */ | ||
309 | public static class Matcher extends BaseMatcher<EndOfSiding_step_5.Match> { | ||
310 | /** | ||
311 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
312 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
313 | * | ||
314 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
315 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
316 | * | ||
317 | */ | ||
318 | public static EndOfSiding_step_5.Matcher on(final ViatraQueryEngine engine) { | ||
319 | // check if matcher already exists | ||
320 | Matcher matcher = engine.getExistingMatcher(querySpecification()); | ||
321 | if (matcher == null) { | ||
322 | matcher = (Matcher)engine.getMatcher(querySpecification()); | ||
323 | } | ||
324 | return matcher; | ||
325 | } | ||
326 | |||
327 | /** | ||
328 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
329 | * @return an initialized matcher | ||
330 | * @noreference This method is for internal matcher initialization by the framework, do not call it manually. | ||
331 | * | ||
332 | */ | ||
333 | public static EndOfSiding_step_5.Matcher create() { | ||
334 | return new Matcher(); | ||
335 | } | ||
336 | |||
337 | private static final int POSITION_TRAIN = 0; | ||
338 | |||
339 | private static final int POSITION_LOCATION = 1; | ||
340 | |||
341 | private static final int POSITION_END = 2; | ||
342 | |||
343 | private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(EndOfSiding_step_5.Matcher.class); | ||
344 | |||
345 | /** | ||
346 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
347 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
348 | * | ||
349 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
350 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
351 | * | ||
352 | */ | ||
353 | private Matcher() { | ||
354 | super(querySpecification()); | ||
355 | } | ||
356 | |||
357 | /** | ||
358 | * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. | ||
359 | * @param pTrain the fixed value of pattern parameter train, or null if not bound. | ||
360 | * @param pLocation the fixed value of pattern parameter location, or null if not bound. | ||
361 | * @param pEnd the fixed value of pattern parameter end, or null if not bound. | ||
362 | * @return matches represented as a Match object. | ||
363 | * | ||
364 | */ | ||
365 | public Collection<EndOfSiding_step_5.Match> getAllMatches(final Train pTrain, final Segment pLocation, final Segment pEnd) { | ||
366 | return rawStreamAllMatches(new Object[]{pTrain, pLocation, pEnd}).collect(Collectors.toSet()); | ||
367 | } | ||
368 | |||
369 | /** | ||
370 | * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. | ||
371 | * </p> | ||
372 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
373 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
374 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
375 | * @param pTrain the fixed value of pattern parameter train, or null if not bound. | ||
376 | * @param pLocation the fixed value of pattern parameter location, or null if not bound. | ||
377 | * @param pEnd the fixed value of pattern parameter end, or null if not bound. | ||
378 | * @return a stream of matches represented as a Match object. | ||
379 | * | ||
380 | */ | ||
381 | public Stream<EndOfSiding_step_5.Match> streamAllMatches(final Train pTrain, final Segment pLocation, final Segment pEnd) { | ||
382 | return rawStreamAllMatches(new Object[]{pTrain, pLocation, pEnd}); | ||
383 | } | ||
384 | |||
385 | /** | ||
386 | * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
387 | * Neither determinism nor randomness of selection is guaranteed. | ||
388 | * @param pTrain the fixed value of pattern parameter train, or null if not bound. | ||
389 | * @param pLocation the fixed value of pattern parameter location, or null if not bound. | ||
390 | * @param pEnd the fixed value of pattern parameter end, or null if not bound. | ||
391 | * @return a match represented as a Match object, or null if no match is found. | ||
392 | * | ||
393 | */ | ||
394 | public Optional<EndOfSiding_step_5.Match> getOneArbitraryMatch(final Train pTrain, final Segment pLocation, final Segment pEnd) { | ||
395 | return rawGetOneArbitraryMatch(new Object[]{pTrain, pLocation, pEnd}); | ||
396 | } | ||
397 | |||
398 | /** | ||
399 | * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, | ||
400 | * under any possible substitution of the unspecified parameters (if any). | ||
401 | * @param pTrain the fixed value of pattern parameter train, or null if not bound. | ||
402 | * @param pLocation the fixed value of pattern parameter location, or null if not bound. | ||
403 | * @param pEnd the fixed value of pattern parameter end, or null if not bound. | ||
404 | * @return true if the input is a valid (partial) match of the pattern. | ||
405 | * | ||
406 | */ | ||
407 | public boolean hasMatch(final Train pTrain, final Segment pLocation, final Segment pEnd) { | ||
408 | return rawHasMatch(new Object[]{pTrain, pLocation, pEnd}); | ||
409 | } | ||
410 | |||
411 | /** | ||
412 | * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. | ||
413 | * @param pTrain the fixed value of pattern parameter train, or null if not bound. | ||
414 | * @param pLocation the fixed value of pattern parameter location, or null if not bound. | ||
415 | * @param pEnd the fixed value of pattern parameter end, or null if not bound. | ||
416 | * @return the number of pattern matches found. | ||
417 | * | ||
418 | */ | ||
419 | public int countMatches(final Train pTrain, final Segment pLocation, final Segment pEnd) { | ||
420 | return rawCountMatches(new Object[]{pTrain, pLocation, pEnd}); | ||
421 | } | ||
422 | |||
423 | /** | ||
424 | * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
425 | * Neither determinism nor randomness of selection is guaranteed. | ||
426 | * @param pTrain the fixed value of pattern parameter train, or null if not bound. | ||
427 | * @param pLocation the fixed value of pattern parameter location, or null if not bound. | ||
428 | * @param pEnd the fixed value of pattern parameter end, or null if not bound. | ||
429 | * @param processor the action that will process the selected match. | ||
430 | * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked | ||
431 | * | ||
432 | */ | ||
433 | public boolean forOneArbitraryMatch(final Train pTrain, final Segment pLocation, final Segment pEnd, final Consumer<? super EndOfSiding_step_5.Match> processor) { | ||
434 | return rawForOneArbitraryMatch(new Object[]{pTrain, pLocation, pEnd}, processor); | ||
435 | } | ||
436 | |||
437 | /** | ||
438 | * Returns a new (partial) match. | ||
439 | * This can be used e.g. to call the matcher with a partial match. | ||
440 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
441 | * @param pTrain the fixed value of pattern parameter train, or null if not bound. | ||
442 | * @param pLocation the fixed value of pattern parameter location, or null if not bound. | ||
443 | * @param pEnd the fixed value of pattern parameter end, or null if not bound. | ||
444 | * @return the (partial) match object. | ||
445 | * | ||
446 | */ | ||
447 | public EndOfSiding_step_5.Match newMatch(final Train pTrain, final Segment pLocation, final Segment pEnd) { | ||
448 | return EndOfSiding_step_5.Match.newMatch(pTrain, pLocation, pEnd); | ||
449 | } | ||
450 | |||
451 | /** | ||
452 | * Retrieve the set of values that occur in matches for train. | ||
453 | * @return the Set of all values or empty set if there are no matches | ||
454 | * | ||
455 | */ | ||
456 | protected Stream<Train> rawStreamAllValuesOftrain(final Object[] parameters) { | ||
457 | return rawStreamAllValues(POSITION_TRAIN, parameters).map(Train.class::cast); | ||
458 | } | ||
459 | |||
460 | /** | ||
461 | * Retrieve the set of values that occur in matches for train. | ||
462 | * @return the Set of all values or empty set if there are no matches | ||
463 | * | ||
464 | */ | ||
465 | public Set<Train> getAllValuesOftrain() { | ||
466 | return rawStreamAllValuesOftrain(emptyArray()).collect(Collectors.toSet()); | ||
467 | } | ||
468 | |||
469 | /** | ||
470 | * Retrieve the set of values that occur in matches for train. | ||
471 | * @return the Set of all values or empty set if there are no matches | ||
472 | * | ||
473 | */ | ||
474 | public Stream<Train> streamAllValuesOftrain() { | ||
475 | return rawStreamAllValuesOftrain(emptyArray()); | ||
476 | } | ||
477 | |||
478 | /** | ||
479 | * Retrieve the set of values that occur in matches for train. | ||
480 | * </p> | ||
481 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
482 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
483 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
484 | * | ||
485 | * @return the Stream of all values or empty set if there are no matches | ||
486 | * | ||
487 | */ | ||
488 | public Stream<Train> streamAllValuesOftrain(final EndOfSiding_step_5.Match partialMatch) { | ||
489 | return rawStreamAllValuesOftrain(partialMatch.toArray()); | ||
490 | } | ||
491 | |||
492 | /** | ||
493 | * Retrieve the set of values that occur in matches for train. | ||
494 | * </p> | ||
495 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
496 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
497 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
498 | * | ||
499 | * @return the Stream of all values or empty set if there are no matches | ||
500 | * | ||
501 | */ | ||
502 | public Stream<Train> streamAllValuesOftrain(final Segment pLocation, final Segment pEnd) { | ||
503 | return rawStreamAllValuesOftrain(new Object[]{null, pLocation, pEnd}); | ||
504 | } | ||
505 | |||
506 | /** | ||
507 | * Retrieve the set of values that occur in matches for train. | ||
508 | * @return the Set of all values or empty set if there are no matches | ||
509 | * | ||
510 | */ | ||
511 | public Set<Train> getAllValuesOftrain(final EndOfSiding_step_5.Match partialMatch) { | ||
512 | return rawStreamAllValuesOftrain(partialMatch.toArray()).collect(Collectors.toSet()); | ||
513 | } | ||
514 | |||
515 | /** | ||
516 | * Retrieve the set of values that occur in matches for train. | ||
517 | * @return the Set of all values or empty set if there are no matches | ||
518 | * | ||
519 | */ | ||
520 | public Set<Train> getAllValuesOftrain(final Segment pLocation, final Segment pEnd) { | ||
521 | return rawStreamAllValuesOftrain(new Object[]{null, pLocation, pEnd}).collect(Collectors.toSet()); | ||
522 | } | ||
523 | |||
524 | /** | ||
525 | * Retrieve the set of values that occur in matches for location. | ||
526 | * @return the Set of all values or empty set if there are no matches | ||
527 | * | ||
528 | */ | ||
529 | protected Stream<Segment> rawStreamAllValuesOflocation(final Object[] parameters) { | ||
530 | return rawStreamAllValues(POSITION_LOCATION, parameters).map(Segment.class::cast); | ||
531 | } | ||
532 | |||
533 | /** | ||
534 | * Retrieve the set of values that occur in matches for location. | ||
535 | * @return the Set of all values or empty set if there are no matches | ||
536 | * | ||
537 | */ | ||
538 | public Set<Segment> getAllValuesOflocation() { | ||
539 | return rawStreamAllValuesOflocation(emptyArray()).collect(Collectors.toSet()); | ||
540 | } | ||
541 | |||
542 | /** | ||
543 | * Retrieve the set of values that occur in matches for location. | ||
544 | * @return the Set of all values or empty set if there are no matches | ||
545 | * | ||
546 | */ | ||
547 | public Stream<Segment> streamAllValuesOflocation() { | ||
548 | return rawStreamAllValuesOflocation(emptyArray()); | ||
549 | } | ||
550 | |||
551 | /** | ||
552 | * Retrieve the set of values that occur in matches for location. | ||
553 | * </p> | ||
554 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
555 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
556 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
557 | * | ||
558 | * @return the Stream of all values or empty set if there are no matches | ||
559 | * | ||
560 | */ | ||
561 | public Stream<Segment> streamAllValuesOflocation(final EndOfSiding_step_5.Match partialMatch) { | ||
562 | return rawStreamAllValuesOflocation(partialMatch.toArray()); | ||
563 | } | ||
564 | |||
565 | /** | ||
566 | * Retrieve the set of values that occur in matches for location. | ||
567 | * </p> | ||
568 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
569 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
570 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
571 | * | ||
572 | * @return the Stream of all values or empty set if there are no matches | ||
573 | * | ||
574 | */ | ||
575 | public Stream<Segment> streamAllValuesOflocation(final Train pTrain, final Segment pEnd) { | ||
576 | return rawStreamAllValuesOflocation(new Object[]{pTrain, null, pEnd}); | ||
577 | } | ||
578 | |||
579 | /** | ||
580 | * Retrieve the set of values that occur in matches for location. | ||
581 | * @return the Set of all values or empty set if there are no matches | ||
582 | * | ||
583 | */ | ||
584 | public Set<Segment> getAllValuesOflocation(final EndOfSiding_step_5.Match partialMatch) { | ||
585 | return rawStreamAllValuesOflocation(partialMatch.toArray()).collect(Collectors.toSet()); | ||
586 | } | ||
587 | |||
588 | /** | ||
589 | * Retrieve the set of values that occur in matches for location. | ||
590 | * @return the Set of all values or empty set if there are no matches | ||
591 | * | ||
592 | */ | ||
593 | public Set<Segment> getAllValuesOflocation(final Train pTrain, final Segment pEnd) { | ||
594 | return rawStreamAllValuesOflocation(new Object[]{pTrain, null, pEnd}).collect(Collectors.toSet()); | ||
595 | } | ||
596 | |||
597 | /** | ||
598 | * Retrieve the set of values that occur in matches for end. | ||
599 | * @return the Set of all values or empty set if there are no matches | ||
600 | * | ||
601 | */ | ||
602 | protected Stream<Segment> rawStreamAllValuesOfend(final Object[] parameters) { | ||
603 | return rawStreamAllValues(POSITION_END, parameters).map(Segment.class::cast); | ||
604 | } | ||
605 | |||
606 | /** | ||
607 | * Retrieve the set of values that occur in matches for end. | ||
608 | * @return the Set of all values or empty set if there are no matches | ||
609 | * | ||
610 | */ | ||
611 | public Set<Segment> getAllValuesOfend() { | ||
612 | return rawStreamAllValuesOfend(emptyArray()).collect(Collectors.toSet()); | ||
613 | } | ||
614 | |||
615 | /** | ||
616 | * Retrieve the set of values that occur in matches for end. | ||
617 | * @return the Set of all values or empty set if there are no matches | ||
618 | * | ||
619 | */ | ||
620 | public Stream<Segment> streamAllValuesOfend() { | ||
621 | return rawStreamAllValuesOfend(emptyArray()); | ||
622 | } | ||
623 | |||
624 | /** | ||
625 | * Retrieve the set of values that occur in matches for end. | ||
626 | * </p> | ||
627 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
628 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
629 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
630 | * | ||
631 | * @return the Stream of all values or empty set if there are no matches | ||
632 | * | ||
633 | */ | ||
634 | public Stream<Segment> streamAllValuesOfend(final EndOfSiding_step_5.Match partialMatch) { | ||
635 | return rawStreamAllValuesOfend(partialMatch.toArray()); | ||
636 | } | ||
637 | |||
638 | /** | ||
639 | * Retrieve the set of values that occur in matches for end. | ||
640 | * </p> | ||
641 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
642 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
643 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
644 | * | ||
645 | * @return the Stream of all values or empty set if there are no matches | ||
646 | * | ||
647 | */ | ||
648 | public Stream<Segment> streamAllValuesOfend(final Train pTrain, final Segment pLocation) { | ||
649 | return rawStreamAllValuesOfend(new Object[]{pTrain, pLocation, null}); | ||
650 | } | ||
651 | |||
652 | /** | ||
653 | * Retrieve the set of values that occur in matches for end. | ||
654 | * @return the Set of all values or empty set if there are no matches | ||
655 | * | ||
656 | */ | ||
657 | public Set<Segment> getAllValuesOfend(final EndOfSiding_step_5.Match partialMatch) { | ||
658 | return rawStreamAllValuesOfend(partialMatch.toArray()).collect(Collectors.toSet()); | ||
659 | } | ||
660 | |||
661 | /** | ||
662 | * Retrieve the set of values that occur in matches for end. | ||
663 | * @return the Set of all values or empty set if there are no matches | ||
664 | * | ||
665 | */ | ||
666 | public Set<Segment> getAllValuesOfend(final Train pTrain, final Segment pLocation) { | ||
667 | return rawStreamAllValuesOfend(new Object[]{pTrain, pLocation, null}).collect(Collectors.toSet()); | ||
668 | } | ||
669 | |||
670 | @Override | ||
671 | protected EndOfSiding_step_5.Match tupleToMatch(final Tuple t) { | ||
672 | try { | ||
673 | return EndOfSiding_step_5.Match.newMatch((Train) t.get(POSITION_TRAIN), (Segment) t.get(POSITION_LOCATION), (Segment) t.get(POSITION_END)); | ||
674 | } catch(ClassCastException e) { | ||
675 | LOGGER.error("Element(s) in tuple not properly typed!",e); | ||
676 | return null; | ||
677 | } | ||
678 | } | ||
679 | |||
680 | @Override | ||
681 | protected EndOfSiding_step_5.Match arrayToMatch(final Object[] match) { | ||
682 | try { | ||
683 | return EndOfSiding_step_5.Match.newMatch((Train) match[POSITION_TRAIN], (Segment) match[POSITION_LOCATION], (Segment) match[POSITION_END]); | ||
684 | } catch(ClassCastException e) { | ||
685 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
686 | return null; | ||
687 | } | ||
688 | } | ||
689 | |||
690 | @Override | ||
691 | protected EndOfSiding_step_5.Match arrayToMatchMutable(final Object[] match) { | ||
692 | try { | ||
693 | return EndOfSiding_step_5.Match.newMutableMatch((Train) match[POSITION_TRAIN], (Segment) match[POSITION_LOCATION], (Segment) match[POSITION_END]); | ||
694 | } catch(ClassCastException e) { | ||
695 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
696 | return null; | ||
697 | } | ||
698 | } | ||
699 | |||
700 | /** | ||
701 | * @return the singleton instance of the query specification of this pattern | ||
702 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
703 | * | ||
704 | */ | ||
705 | public static IQuerySpecification<EndOfSiding_step_5.Matcher> querySpecification() { | ||
706 | return EndOfSiding_step_5.instance(); | ||
707 | } | ||
708 | } | ||
709 | |||
710 | private EndOfSiding_step_5() { | ||
711 | super(GeneratedPQuery.INSTANCE); | ||
712 | } | ||
713 | |||
714 | /** | ||
715 | * @return the singleton instance of the query specification | ||
716 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
717 | * | ||
718 | */ | ||
719 | public static EndOfSiding_step_5 instance() { | ||
720 | try{ | ||
721 | return LazyHolder.INSTANCE; | ||
722 | } catch (ExceptionInInitializerError err) { | ||
723 | throw processInitializerError(err); | ||
724 | } | ||
725 | } | ||
726 | |||
727 | @Override | ||
728 | protected EndOfSiding_step_5.Matcher instantiate(final ViatraQueryEngine engine) { | ||
729 | return EndOfSiding_step_5.Matcher.on(engine); | ||
730 | } | ||
731 | |||
732 | @Override | ||
733 | public EndOfSiding_step_5.Matcher instantiate() { | ||
734 | return EndOfSiding_step_5.Matcher.create(); | ||
735 | } | ||
736 | |||
737 | @Override | ||
738 | public EndOfSiding_step_5.Match newEmptyMatch() { | ||
739 | return EndOfSiding_step_5.Match.newEmptyMatch(); | ||
740 | } | ||
741 | |||
742 | @Override | ||
743 | public EndOfSiding_step_5.Match newMatch(final Object... parameters) { | ||
744 | return EndOfSiding_step_5.Match.newMatch((modes3.Train) parameters[0], (modes3.Segment) parameters[1], (modes3.Segment) parameters[2]); | ||
745 | } | ||
746 | |||
747 | /** | ||
748 | * Inner class allowing the singleton instance of {@link EndOfSiding_step_5} to be created | ||
749 | * <b>not</b> at the class load time of the outer class, | ||
750 | * but rather at the first call to {@link EndOfSiding_step_5#instance()}. | ||
751 | * | ||
752 | * <p> This workaround is required e.g. to support recursion. | ||
753 | * | ||
754 | */ | ||
755 | private static class LazyHolder { | ||
756 | private static final EndOfSiding_step_5 INSTANCE = new EndOfSiding_step_5(); | ||
757 | |||
758 | /** | ||
759 | * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned. | ||
760 | * This initialization order is required to support indirect recursion. | ||
761 | * | ||
762 | * <p> The static initializer is defined using a helper field to work around limitations of the code generator. | ||
763 | * | ||
764 | */ | ||
765 | private static final Object STATIC_INITIALIZER = ensureInitialized(); | ||
766 | |||
767 | public static Object ensureInitialized() { | ||
768 | INSTANCE.ensureInitializedInternal(); | ||
769 | return null; | ||
770 | } | ||
771 | } | ||
772 | |||
773 | private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { | ||
774 | private static final EndOfSiding_step_5.GeneratedPQuery INSTANCE = new GeneratedPQuery(); | ||
775 | |||
776 | private final PParameter parameter_train = new PParameter("train", "modes3.Train", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Train")), PParameterDirection.INOUT); | ||
777 | |||
778 | private final PParameter parameter_location = new PParameter("location", "modes3.Segment", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Segment")), PParameterDirection.INOUT); | ||
779 | |||
780 | private final PParameter parameter_end = new PParameter("end", "modes3.Segment", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Segment")), PParameterDirection.INOUT); | ||
781 | |||
782 | private final List<PParameter> parameters = Arrays.asList(parameter_train, parameter_location, parameter_end); | ||
783 | |||
784 | private GeneratedPQuery() { | ||
785 | super(PVisibility.PUBLIC); | ||
786 | } | ||
787 | |||
788 | @Override | ||
789 | public String getFullyQualifiedName() { | ||
790 | return "modes3.queries.endOfSiding_step_5"; | ||
791 | } | ||
792 | |||
793 | @Override | ||
794 | public List<String> getParameterNames() { | ||
795 | return Arrays.asList("train","location","end"); | ||
796 | } | ||
797 | |||
798 | @Override | ||
799 | public List<PParameter> getParameters() { | ||
800 | return parameters; | ||
801 | } | ||
802 | |||
803 | @Override | ||
804 | public Set<PBody> doGetContainedBodies() { | ||
805 | setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); | ||
806 | Set<PBody> bodies = new LinkedHashSet<>(); | ||
807 | { | ||
808 | PBody body = new PBody(this); | ||
809 | PVariable var_train = body.getOrCreateVariableByName("train"); | ||
810 | PVariable var_location = body.getOrCreateVariableByName("location"); | ||
811 | PVariable var_end = body.getOrCreateVariableByName("end"); | ||
812 | new TypeConstraint(body, Tuples.flatTupleOf(var_train), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Train"))); | ||
813 | new TypeConstraint(body, Tuples.flatTupleOf(var_location), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
814 | new TypeConstraint(body, Tuples.flatTupleOf(var_end), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
815 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
816 | new ExportedParameter(body, var_train, parameter_train), | ||
817 | new ExportedParameter(body, var_location, parameter_location), | ||
818 | new ExportedParameter(body, var_end, parameter_end) | ||
819 | )); | ||
820 | // // results->matches[match_cntr].location = frame->location;// results->matches[match_cntr++].train = frame->train;// ...OR...// results->matches[match_cntr].location = frame->location;// results->matches[match_cntr++].train = frame->train; Train(train) | ||
821 | new TypeConstraint(body, Tuples.flatTupleOf(var_train), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Train"))); | ||
822 | // Train.location(train, location) | ||
823 | new TypeConstraint(body, Tuples.flatTupleOf(var_train), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Train"))); | ||
824 | PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); | ||
825 | new TypeConstraint(body, Tuples.flatTupleOf(var_train, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Train", "location"))); | ||
826 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
827 | new Equality(body, var__virtual_0_, var_location); | ||
828 | // Segment.connectedTo(location, end) | ||
829 | new TypeConstraint(body, Tuples.flatTupleOf(var_location), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
830 | PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); | ||
831 | new TypeConstraint(body, Tuples.flatTupleOf(var_location, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment", "connectedTo"))); | ||
832 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
833 | new Equality(body, var__virtual_1_, var_end); | ||
834 | // neg find multipleConnectedTo(end) | ||
835 | new NegativePatternCall(body, Tuples.flatTupleOf(var_end), MultipleConnectedTo.instance().getInternalQueryRepresentation()); | ||
836 | bodies.add(body); | ||
837 | } | ||
838 | return bodies; | ||
839 | } | ||
840 | } | ||
841 | } | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/InputsOfTurnout.java b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/InputsOfTurnout.java new file mode 100644 index 00000000..2f2eea11 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/InputsOfTurnout.java | |||
@@ -0,0 +1,570 @@ | |||
1 | /** | ||
2 | * Generated from platform:/resource/ca.mcgill.rtgmrt.example.modes3/src/modes3/queries/Modes3Queries.vql | ||
3 | */ | ||
4 | package modes3.queries; | ||
5 | |||
6 | import java.util.Arrays; | ||
7 | import java.util.Collection; | ||
8 | import java.util.LinkedHashSet; | ||
9 | import java.util.List; | ||
10 | import java.util.Objects; | ||
11 | import java.util.Optional; | ||
12 | import java.util.Set; | ||
13 | import java.util.function.Consumer; | ||
14 | import java.util.stream.Collectors; | ||
15 | import java.util.stream.Stream; | ||
16 | import modes3.Turnout; | ||
17 | import modes3.queries.Adjacent; | ||
18 | import org.apache.log4j.Logger; | ||
19 | import org.eclipse.emf.ecore.EClass; | ||
20 | import org.eclipse.viatra.query.runtime.api.IPatternMatch; | ||
21 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification; | ||
22 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; | ||
23 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; | ||
24 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; | ||
25 | import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; | ||
26 | import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; | ||
27 | import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; | ||
28 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
29 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | ||
30 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | ||
31 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
32 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Inequality; | ||
33 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall; | ||
34 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
35 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | ||
36 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; | ||
37 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | ||
38 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; | ||
39 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
40 | import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; | ||
41 | |||
42 | /** | ||
43 | * A pattern-specific query specification that can instantiate Matcher in a type-safe way. | ||
44 | * | ||
45 | * <p>Original source: | ||
46 | * <code><pre> | ||
47 | * pattern inputsOfTurnout(T : Turnout) { | ||
48 | * find adjacent(I1, T); | ||
49 | * find adjacent(I2, T); | ||
50 | * find adjacent(I3, T); | ||
51 | * I1 != I2; | ||
52 | * I1 != I3; | ||
53 | * I2 != I3; | ||
54 | * } | ||
55 | * </pre></code> | ||
56 | * | ||
57 | * @see Matcher | ||
58 | * @see Match | ||
59 | * | ||
60 | */ | ||
61 | @SuppressWarnings("all") | ||
62 | public final class InputsOfTurnout extends BaseGeneratedEMFQuerySpecification<InputsOfTurnout.Matcher> { | ||
63 | /** | ||
64 | * Pattern-specific match representation of the modes3.queries.inputsOfTurnout pattern, | ||
65 | * to be used in conjunction with {@link Matcher}. | ||
66 | * | ||
67 | * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. | ||
68 | * Each instance is a (possibly partial) substitution of pattern parameters, | ||
69 | * usable to represent a match of the pattern in the result of a query, | ||
70 | * or to specify the bound (fixed) input parameters when issuing a query. | ||
71 | * | ||
72 | * @see Matcher | ||
73 | * | ||
74 | */ | ||
75 | public static abstract class Match extends BasePatternMatch { | ||
76 | private Turnout fT; | ||
77 | |||
78 | private static List<String> parameterNames = makeImmutableList("T"); | ||
79 | |||
80 | private Match(final Turnout pT) { | ||
81 | this.fT = pT; | ||
82 | } | ||
83 | |||
84 | @Override | ||
85 | public Object get(final String parameterName) { | ||
86 | switch(parameterName) { | ||
87 | case "T": return this.fT; | ||
88 | default: return null; | ||
89 | } | ||
90 | } | ||
91 | |||
92 | @Override | ||
93 | public Object get(final int index) { | ||
94 | switch(index) { | ||
95 | case 0: return this.fT; | ||
96 | default: return null; | ||
97 | } | ||
98 | } | ||
99 | |||
100 | public Turnout getT() { | ||
101 | return this.fT; | ||
102 | } | ||
103 | |||
104 | @Override | ||
105 | public boolean set(final String parameterName, final Object newValue) { | ||
106 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
107 | if ("T".equals(parameterName) ) { | ||
108 | this.fT = (Turnout) newValue; | ||
109 | return true; | ||
110 | } | ||
111 | return false; | ||
112 | } | ||
113 | |||
114 | public void setT(final Turnout pT) { | ||
115 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
116 | this.fT = pT; | ||
117 | } | ||
118 | |||
119 | @Override | ||
120 | public String patternName() { | ||
121 | return "modes3.queries.inputsOfTurnout"; | ||
122 | } | ||
123 | |||
124 | @Override | ||
125 | public List<String> parameterNames() { | ||
126 | return InputsOfTurnout.Match.parameterNames; | ||
127 | } | ||
128 | |||
129 | @Override | ||
130 | public Object[] toArray() { | ||
131 | return new Object[]{fT}; | ||
132 | } | ||
133 | |||
134 | @Override | ||
135 | public InputsOfTurnout.Match toImmutable() { | ||
136 | return isMutable() ? newMatch(fT) : this; | ||
137 | } | ||
138 | |||
139 | @Override | ||
140 | public String prettyPrint() { | ||
141 | StringBuilder result = new StringBuilder(); | ||
142 | result.append("\"T\"=" + prettyPrintValue(fT)); | ||
143 | return result.toString(); | ||
144 | } | ||
145 | |||
146 | @Override | ||
147 | public int hashCode() { | ||
148 | return Objects.hash(fT); | ||
149 | } | ||
150 | |||
151 | @Override | ||
152 | public boolean equals(final Object obj) { | ||
153 | if (this == obj) | ||
154 | return true; | ||
155 | if (obj == null) { | ||
156 | return false; | ||
157 | } | ||
158 | if ((obj instanceof InputsOfTurnout.Match)) { | ||
159 | InputsOfTurnout.Match other = (InputsOfTurnout.Match) obj; | ||
160 | return Objects.equals(fT, other.fT); | ||
161 | } else { | ||
162 | // this should be infrequent | ||
163 | if (!(obj instanceof IPatternMatch)) { | ||
164 | return false; | ||
165 | } | ||
166 | IPatternMatch otherSig = (IPatternMatch) obj; | ||
167 | return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); | ||
168 | } | ||
169 | } | ||
170 | |||
171 | @Override | ||
172 | public InputsOfTurnout specification() { | ||
173 | return InputsOfTurnout.instance(); | ||
174 | } | ||
175 | |||
176 | /** | ||
177 | * Returns an empty, mutable match. | ||
178 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
179 | * | ||
180 | * @return the empty match. | ||
181 | * | ||
182 | */ | ||
183 | public static InputsOfTurnout.Match newEmptyMatch() { | ||
184 | return new Mutable(null); | ||
185 | } | ||
186 | |||
187 | /** | ||
188 | * Returns a mutable (partial) match. | ||
189 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
190 | * | ||
191 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
192 | * @return the new, mutable (partial) match object. | ||
193 | * | ||
194 | */ | ||
195 | public static InputsOfTurnout.Match newMutableMatch(final Turnout pT) { | ||
196 | return new Mutable(pT); | ||
197 | } | ||
198 | |||
199 | /** | ||
200 | * Returns a new (partial) match. | ||
201 | * This can be used e.g. to call the matcher with a partial match. | ||
202 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
203 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
204 | * @return the (partial) match object. | ||
205 | * | ||
206 | */ | ||
207 | public static InputsOfTurnout.Match newMatch(final Turnout pT) { | ||
208 | return new Immutable(pT); | ||
209 | } | ||
210 | |||
211 | private static final class Mutable extends InputsOfTurnout.Match { | ||
212 | Mutable(final Turnout pT) { | ||
213 | super(pT); | ||
214 | } | ||
215 | |||
216 | @Override | ||
217 | public boolean isMutable() { | ||
218 | return true; | ||
219 | } | ||
220 | } | ||
221 | |||
222 | private static final class Immutable extends InputsOfTurnout.Match { | ||
223 | Immutable(final Turnout pT) { | ||
224 | super(pT); | ||
225 | } | ||
226 | |||
227 | @Override | ||
228 | public boolean isMutable() { | ||
229 | return false; | ||
230 | } | ||
231 | } | ||
232 | } | ||
233 | |||
234 | /** | ||
235 | * Generated pattern matcher API of the modes3.queries.inputsOfTurnout pattern, | ||
236 | * providing pattern-specific query methods. | ||
237 | * | ||
238 | * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, | ||
239 | * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. | ||
240 | * | ||
241 | * <p>Matches of the pattern will be represented as {@link Match}. | ||
242 | * | ||
243 | * <p>Original source: | ||
244 | * <code><pre> | ||
245 | * pattern inputsOfTurnout(T : Turnout) { | ||
246 | * find adjacent(I1, T); | ||
247 | * find adjacent(I2, T); | ||
248 | * find adjacent(I3, T); | ||
249 | * I1 != I2; | ||
250 | * I1 != I3; | ||
251 | * I2 != I3; | ||
252 | * } | ||
253 | * </pre></code> | ||
254 | * | ||
255 | * @see Match | ||
256 | * @see InputsOfTurnout | ||
257 | * | ||
258 | */ | ||
259 | public static class Matcher extends BaseMatcher<InputsOfTurnout.Match> { | ||
260 | /** | ||
261 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
262 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
263 | * | ||
264 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
265 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
266 | * | ||
267 | */ | ||
268 | public static InputsOfTurnout.Matcher on(final ViatraQueryEngine engine) { | ||
269 | // check if matcher already exists | ||
270 | Matcher matcher = engine.getExistingMatcher(querySpecification()); | ||
271 | if (matcher == null) { | ||
272 | matcher = (Matcher)engine.getMatcher(querySpecification()); | ||
273 | } | ||
274 | return matcher; | ||
275 | } | ||
276 | |||
277 | /** | ||
278 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
279 | * @return an initialized matcher | ||
280 | * @noreference This method is for internal matcher initialization by the framework, do not call it manually. | ||
281 | * | ||
282 | */ | ||
283 | public static InputsOfTurnout.Matcher create() { | ||
284 | return new Matcher(); | ||
285 | } | ||
286 | |||
287 | private static final int POSITION_T = 0; | ||
288 | |||
289 | private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(InputsOfTurnout.Matcher.class); | ||
290 | |||
291 | /** | ||
292 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
293 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
294 | * | ||
295 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
296 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
297 | * | ||
298 | */ | ||
299 | private Matcher() { | ||
300 | super(querySpecification()); | ||
301 | } | ||
302 | |||
303 | /** | ||
304 | * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. | ||
305 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
306 | * @return matches represented as a Match object. | ||
307 | * | ||
308 | */ | ||
309 | public Collection<InputsOfTurnout.Match> getAllMatches(final Turnout pT) { | ||
310 | return rawStreamAllMatches(new Object[]{pT}).collect(Collectors.toSet()); | ||
311 | } | ||
312 | |||
313 | /** | ||
314 | * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. | ||
315 | * </p> | ||
316 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
317 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
318 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
319 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
320 | * @return a stream of matches represented as a Match object. | ||
321 | * | ||
322 | */ | ||
323 | public Stream<InputsOfTurnout.Match> streamAllMatches(final Turnout pT) { | ||
324 | return rawStreamAllMatches(new Object[]{pT}); | ||
325 | } | ||
326 | |||
327 | /** | ||
328 | * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
329 | * Neither determinism nor randomness of selection is guaranteed. | ||
330 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
331 | * @return a match represented as a Match object, or null if no match is found. | ||
332 | * | ||
333 | */ | ||
334 | public Optional<InputsOfTurnout.Match> getOneArbitraryMatch(final Turnout pT) { | ||
335 | return rawGetOneArbitraryMatch(new Object[]{pT}); | ||
336 | } | ||
337 | |||
338 | /** | ||
339 | * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, | ||
340 | * under any possible substitution of the unspecified parameters (if any). | ||
341 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
342 | * @return true if the input is a valid (partial) match of the pattern. | ||
343 | * | ||
344 | */ | ||
345 | public boolean hasMatch(final Turnout pT) { | ||
346 | return rawHasMatch(new Object[]{pT}); | ||
347 | } | ||
348 | |||
349 | /** | ||
350 | * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. | ||
351 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
352 | * @return the number of pattern matches found. | ||
353 | * | ||
354 | */ | ||
355 | public int countMatches(final Turnout pT) { | ||
356 | return rawCountMatches(new Object[]{pT}); | ||
357 | } | ||
358 | |||
359 | /** | ||
360 | * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
361 | * Neither determinism nor randomness of selection is guaranteed. | ||
362 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
363 | * @param processor the action that will process the selected match. | ||
364 | * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked | ||
365 | * | ||
366 | */ | ||
367 | public boolean forOneArbitraryMatch(final Turnout pT, final Consumer<? super InputsOfTurnout.Match> processor) { | ||
368 | return rawForOneArbitraryMatch(new Object[]{pT}, processor); | ||
369 | } | ||
370 | |||
371 | /** | ||
372 | * Returns a new (partial) match. | ||
373 | * This can be used e.g. to call the matcher with a partial match. | ||
374 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
375 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
376 | * @return the (partial) match object. | ||
377 | * | ||
378 | */ | ||
379 | public InputsOfTurnout.Match newMatch(final Turnout pT) { | ||
380 | return InputsOfTurnout.Match.newMatch(pT); | ||
381 | } | ||
382 | |||
383 | /** | ||
384 | * Retrieve the set of values that occur in matches for T. | ||
385 | * @return the Set of all values or empty set if there are no matches | ||
386 | * | ||
387 | */ | ||
388 | protected Stream<Turnout> rawStreamAllValuesOfT(final Object[] parameters) { | ||
389 | return rawStreamAllValues(POSITION_T, parameters).map(Turnout.class::cast); | ||
390 | } | ||
391 | |||
392 | /** | ||
393 | * Retrieve the set of values that occur in matches for T. | ||
394 | * @return the Set of all values or empty set if there are no matches | ||
395 | * | ||
396 | */ | ||
397 | public Set<Turnout> getAllValuesOfT() { | ||
398 | return rawStreamAllValuesOfT(emptyArray()).collect(Collectors.toSet()); | ||
399 | } | ||
400 | |||
401 | /** | ||
402 | * Retrieve the set of values that occur in matches for T. | ||
403 | * @return the Set of all values or empty set if there are no matches | ||
404 | * | ||
405 | */ | ||
406 | public Stream<Turnout> streamAllValuesOfT() { | ||
407 | return rawStreamAllValuesOfT(emptyArray()); | ||
408 | } | ||
409 | |||
410 | @Override | ||
411 | protected InputsOfTurnout.Match tupleToMatch(final Tuple t) { | ||
412 | try { | ||
413 | return InputsOfTurnout.Match.newMatch((Turnout) t.get(POSITION_T)); | ||
414 | } catch(ClassCastException e) { | ||
415 | LOGGER.error("Element(s) in tuple not properly typed!",e); | ||
416 | return null; | ||
417 | } | ||
418 | } | ||
419 | |||
420 | @Override | ||
421 | protected InputsOfTurnout.Match arrayToMatch(final Object[] match) { | ||
422 | try { | ||
423 | return InputsOfTurnout.Match.newMatch((Turnout) match[POSITION_T]); | ||
424 | } catch(ClassCastException e) { | ||
425 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
426 | return null; | ||
427 | } | ||
428 | } | ||
429 | |||
430 | @Override | ||
431 | protected InputsOfTurnout.Match arrayToMatchMutable(final Object[] match) { | ||
432 | try { | ||
433 | return InputsOfTurnout.Match.newMutableMatch((Turnout) match[POSITION_T]); | ||
434 | } catch(ClassCastException e) { | ||
435 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
436 | return null; | ||
437 | } | ||
438 | } | ||
439 | |||
440 | /** | ||
441 | * @return the singleton instance of the query specification of this pattern | ||
442 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
443 | * | ||
444 | */ | ||
445 | public static IQuerySpecification<InputsOfTurnout.Matcher> querySpecification() { | ||
446 | return InputsOfTurnout.instance(); | ||
447 | } | ||
448 | } | ||
449 | |||
450 | private InputsOfTurnout() { | ||
451 | super(GeneratedPQuery.INSTANCE); | ||
452 | } | ||
453 | |||
454 | /** | ||
455 | * @return the singleton instance of the query specification | ||
456 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
457 | * | ||
458 | */ | ||
459 | public static InputsOfTurnout instance() { | ||
460 | try{ | ||
461 | return LazyHolder.INSTANCE; | ||
462 | } catch (ExceptionInInitializerError err) { | ||
463 | throw processInitializerError(err); | ||
464 | } | ||
465 | } | ||
466 | |||
467 | @Override | ||
468 | protected InputsOfTurnout.Matcher instantiate(final ViatraQueryEngine engine) { | ||
469 | return InputsOfTurnout.Matcher.on(engine); | ||
470 | } | ||
471 | |||
472 | @Override | ||
473 | public InputsOfTurnout.Matcher instantiate() { | ||
474 | return InputsOfTurnout.Matcher.create(); | ||
475 | } | ||
476 | |||
477 | @Override | ||
478 | public InputsOfTurnout.Match newEmptyMatch() { | ||
479 | return InputsOfTurnout.Match.newEmptyMatch(); | ||
480 | } | ||
481 | |||
482 | @Override | ||
483 | public InputsOfTurnout.Match newMatch(final Object... parameters) { | ||
484 | return InputsOfTurnout.Match.newMatch((modes3.Turnout) parameters[0]); | ||
485 | } | ||
486 | |||
487 | /** | ||
488 | * Inner class allowing the singleton instance of {@link InputsOfTurnout} to be created | ||
489 | * <b>not</b> at the class load time of the outer class, | ||
490 | * but rather at the first call to {@link InputsOfTurnout#instance()}. | ||
491 | * | ||
492 | * <p> This workaround is required e.g. to support recursion. | ||
493 | * | ||
494 | */ | ||
495 | private static class LazyHolder { | ||
496 | private static final InputsOfTurnout INSTANCE = new InputsOfTurnout(); | ||
497 | |||
498 | /** | ||
499 | * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned. | ||
500 | * This initialization order is required to support indirect recursion. | ||
501 | * | ||
502 | * <p> The static initializer is defined using a helper field to work around limitations of the code generator. | ||
503 | * | ||
504 | */ | ||
505 | private static final Object STATIC_INITIALIZER = ensureInitialized(); | ||
506 | |||
507 | public static Object ensureInitialized() { | ||
508 | INSTANCE.ensureInitializedInternal(); | ||
509 | return null; | ||
510 | } | ||
511 | } | ||
512 | |||
513 | private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { | ||
514 | private static final InputsOfTurnout.GeneratedPQuery INSTANCE = new GeneratedPQuery(); | ||
515 | |||
516 | private final PParameter parameter_T = new PParameter("T", "modes3.Turnout", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Turnout")), PParameterDirection.INOUT); | ||
517 | |||
518 | private final List<PParameter> parameters = Arrays.asList(parameter_T); | ||
519 | |||
520 | private GeneratedPQuery() { | ||
521 | super(PVisibility.PUBLIC); | ||
522 | } | ||
523 | |||
524 | @Override | ||
525 | public String getFullyQualifiedName() { | ||
526 | return "modes3.queries.inputsOfTurnout"; | ||
527 | } | ||
528 | |||
529 | @Override | ||
530 | public List<String> getParameterNames() { | ||
531 | return Arrays.asList("T"); | ||
532 | } | ||
533 | |||
534 | @Override | ||
535 | public List<PParameter> getParameters() { | ||
536 | return parameters; | ||
537 | } | ||
538 | |||
539 | @Override | ||
540 | public Set<PBody> doGetContainedBodies() { | ||
541 | setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); | ||
542 | Set<PBody> bodies = new LinkedHashSet<>(); | ||
543 | { | ||
544 | PBody body = new PBody(this); | ||
545 | PVariable var_T = body.getOrCreateVariableByName("T"); | ||
546 | PVariable var_I1 = body.getOrCreateVariableByName("I1"); | ||
547 | PVariable var_I2 = body.getOrCreateVariableByName("I2"); | ||
548 | PVariable var_I3 = body.getOrCreateVariableByName("I3"); | ||
549 | new TypeConstraint(body, Tuples.flatTupleOf(var_T), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Turnout"))); | ||
550 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
551 | new ExportedParameter(body, var_T, parameter_T) | ||
552 | )); | ||
553 | // find adjacent(I1, T) | ||
554 | new PositivePatternCall(body, Tuples.flatTupleOf(var_I1, var_T), Adjacent.instance().getInternalQueryRepresentation()); | ||
555 | // find adjacent(I2, T) | ||
556 | new PositivePatternCall(body, Tuples.flatTupleOf(var_I2, var_T), Adjacent.instance().getInternalQueryRepresentation()); | ||
557 | // find adjacent(I3, T) | ||
558 | new PositivePatternCall(body, Tuples.flatTupleOf(var_I3, var_T), Adjacent.instance().getInternalQueryRepresentation()); | ||
559 | // I1 != I2 | ||
560 | new Inequality(body, var_I1, var_I2); | ||
561 | // I1 != I3 | ||
562 | new Inequality(body, var_I1, var_I3); | ||
563 | // I2 != I3 | ||
564 | new Inequality(body, var_I2, var_I3); | ||
565 | bodies.add(body); | ||
566 | } | ||
567 | return bodies; | ||
568 | } | ||
569 | } | ||
570 | } | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/Modes3Queries.java b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/Modes3Queries.java new file mode 100644 index 00000000..d1238d61 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/Modes3Queries.java | |||
@@ -0,0 +1,405 @@ | |||
1 | /** | ||
2 | * Generated from platform:/resource/ca.mcgill.rtgmrt.example.modes3/src/modes3/queries/Modes3Queries.vql | ||
3 | */ | ||
4 | package modes3.queries; | ||
5 | |||
6 | import modes3.queries.Adjacent; | ||
7 | import modes3.queries.CloseTrains_step_2; | ||
8 | import modes3.queries.CloseTrains_step_3; | ||
9 | import modes3.queries.CloseTrains_step_4; | ||
10 | import modes3.queries.CloseTrains_step_5; | ||
11 | import modes3.queries.CloseTrains_step_6; | ||
12 | import modes3.queries.CloseTrains_step_7; | ||
13 | import modes3.queries.ConnectedSegmentsDirected; | ||
14 | import modes3.queries.ConnectedTo; | ||
15 | import modes3.queries.ConnectedToNotSymmetric; | ||
16 | import modes3.queries.ConnectedToReflexive; | ||
17 | import modes3.queries.EndOfSiding_step_2; | ||
18 | import modes3.queries.EndOfSiding_step_3; | ||
19 | import modes3.queries.EndOfSiding_step_4; | ||
20 | import modes3.queries.EndOfSiding_step_5; | ||
21 | import modes3.queries.InputsOfTurnout; | ||
22 | import modes3.queries.MisalignedTurnout_step_2; | ||
23 | import modes3.queries.MisalignedTurnout_step_3; | ||
24 | import modes3.queries.MisalignedTurnout_step_4; | ||
25 | import modes3.queries.MisalignedTurnout_step_5; | ||
26 | import modes3.queries.MultipleConnectedTo; | ||
27 | import modes3.queries.Output; | ||
28 | import modes3.queries.OutputReflexive; | ||
29 | import modes3.queries.Reachable; | ||
30 | import modes3.queries.TooFewInputsOfTurnout; | ||
31 | import modes3.queries.TooManyInputsOfSegment; | ||
32 | import modes3.queries.TooManyInputsOfTurnout; | ||
33 | import modes3.queries.TrainLocations_step_2; | ||
34 | import modes3.queries.TrainLocations_step_3; | ||
35 | import modes3.queries.TurnoutConnectedToBothOutputs; | ||
36 | import modes3.queries.TurnoutOutput; | ||
37 | import modes3.queries.TurnoutOutputsAreSame; | ||
38 | import modes3.queries.Unreachable; | ||
39 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; | ||
40 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedPatternGroup; | ||
41 | |||
42 | /** | ||
43 | * A pattern group formed of all public patterns defined in Modes3Queries.vql. | ||
44 | * | ||
45 | * <p>Use the static instance as any {@link interface org.eclipse.viatra.query.runtime.api.IQueryGroup}, to conveniently prepare | ||
46 | * a VIATRA Query engine for matching all patterns originally defined in file Modes3Queries.vql, | ||
47 | * in order to achieve better performance than one-by-one on-demand matcher initialization. | ||
48 | * | ||
49 | * <p> From package modes3.queries, the group contains the definition of the following patterns: <ul> | ||
50 | * <li>connectedTo</li> | ||
51 | * <li>connectedToNotSymmetric</li> | ||
52 | * <li>connectedToReflexive</li> | ||
53 | * <li>turnoutOutput</li> | ||
54 | * <li>outputReflexive</li> | ||
55 | * <li>turnoutOutputsAreSame</li> | ||
56 | * <li>output</li> | ||
57 | * <li>tooManyInputsOfSegment</li> | ||
58 | * <li>turnoutConnectedToBothOutputs</li> | ||
59 | * <li>adjacent</li> | ||
60 | * <li>tooManyInputsOfTurnout</li> | ||
61 | * <li>inputsOfTurnout</li> | ||
62 | * <li>tooFewInputsOfTurnout</li> | ||
63 | * <li>reachable</li> | ||
64 | * <li>unreachable</li> | ||
65 | * <li>closeTrains_step_2</li> | ||
66 | * <li>closeTrains_step_3</li> | ||
67 | * <li>closeTrains_step_4</li> | ||
68 | * <li>closeTrains_step_5</li> | ||
69 | * <li>closeTrains_step_6</li> | ||
70 | * <li>closeTrains_step_7</li> | ||
71 | * <li>trainLocations_step_2</li> | ||
72 | * <li>trainLocations_step_3</li> | ||
73 | * <li>misalignedTurnout_step_2</li> | ||
74 | * <li>misalignedTurnout_step_3</li> | ||
75 | * <li>misalignedTurnout_step_4</li> | ||
76 | * <li>misalignedTurnout_step_5</li> | ||
77 | * <li>connectedSegmentsDirected</li> | ||
78 | * <li>endOfSiding_step_2</li> | ||
79 | * <li>endOfSiding_step_3</li> | ||
80 | * <li>endOfSiding_step_4</li> | ||
81 | * <li>endOfSiding_step_5</li> | ||
82 | * <li>multipleConnectedTo</li> | ||
83 | * </ul> | ||
84 | * | ||
85 | * @see IQueryGroup | ||
86 | * | ||
87 | */ | ||
88 | @SuppressWarnings("all") | ||
89 | public final class Modes3Queries extends BaseGeneratedPatternGroup { | ||
90 | /** | ||
91 | * Access the pattern group. | ||
92 | * | ||
93 | * @return the singleton instance of the group | ||
94 | * @throws ViatraQueryRuntimeException if there was an error loading the generated code of pattern specifications | ||
95 | * | ||
96 | */ | ||
97 | public static Modes3Queries instance() { | ||
98 | if (INSTANCE == null) { | ||
99 | INSTANCE = new Modes3Queries(); | ||
100 | } | ||
101 | return INSTANCE; | ||
102 | } | ||
103 | |||
104 | private static Modes3Queries INSTANCE; | ||
105 | |||
106 | private Modes3Queries() { | ||
107 | querySpecifications.add(ConnectedTo.instance()); | ||
108 | querySpecifications.add(ConnectedToNotSymmetric.instance()); | ||
109 | querySpecifications.add(ConnectedToReflexive.instance()); | ||
110 | querySpecifications.add(TurnoutOutput.instance()); | ||
111 | querySpecifications.add(OutputReflexive.instance()); | ||
112 | querySpecifications.add(TurnoutOutputsAreSame.instance()); | ||
113 | querySpecifications.add(Output.instance()); | ||
114 | querySpecifications.add(TooManyInputsOfSegment.instance()); | ||
115 | querySpecifications.add(TurnoutConnectedToBothOutputs.instance()); | ||
116 | querySpecifications.add(Adjacent.instance()); | ||
117 | querySpecifications.add(TooManyInputsOfTurnout.instance()); | ||
118 | querySpecifications.add(InputsOfTurnout.instance()); | ||
119 | querySpecifications.add(TooFewInputsOfTurnout.instance()); | ||
120 | querySpecifications.add(Reachable.instance()); | ||
121 | querySpecifications.add(Unreachable.instance()); | ||
122 | querySpecifications.add(CloseTrains_step_2.instance()); | ||
123 | querySpecifications.add(CloseTrains_step_3.instance()); | ||
124 | querySpecifications.add(CloseTrains_step_4.instance()); | ||
125 | querySpecifications.add(CloseTrains_step_5.instance()); | ||
126 | querySpecifications.add(CloseTrains_step_6.instance()); | ||
127 | querySpecifications.add(CloseTrains_step_7.instance()); | ||
128 | querySpecifications.add(TrainLocations_step_2.instance()); | ||
129 | querySpecifications.add(TrainLocations_step_3.instance()); | ||
130 | querySpecifications.add(MisalignedTurnout_step_2.instance()); | ||
131 | querySpecifications.add(MisalignedTurnout_step_3.instance()); | ||
132 | querySpecifications.add(MisalignedTurnout_step_4.instance()); | ||
133 | querySpecifications.add(MisalignedTurnout_step_5.instance()); | ||
134 | querySpecifications.add(ConnectedSegmentsDirected.instance()); | ||
135 | querySpecifications.add(EndOfSiding_step_2.instance()); | ||
136 | querySpecifications.add(EndOfSiding_step_3.instance()); | ||
137 | querySpecifications.add(EndOfSiding_step_4.instance()); | ||
138 | querySpecifications.add(EndOfSiding_step_5.instance()); | ||
139 | querySpecifications.add(MultipleConnectedTo.instance()); | ||
140 | } | ||
141 | |||
142 | public ConnectedTo getConnectedTo() { | ||
143 | return ConnectedTo.instance(); | ||
144 | } | ||
145 | |||
146 | public ConnectedTo.Matcher getConnectedTo(final ViatraQueryEngine engine) { | ||
147 | return ConnectedTo.Matcher.on(engine); | ||
148 | } | ||
149 | |||
150 | public ConnectedToNotSymmetric getConnectedToNotSymmetric() { | ||
151 | return ConnectedToNotSymmetric.instance(); | ||
152 | } | ||
153 | |||
154 | public ConnectedToNotSymmetric.Matcher getConnectedToNotSymmetric(final ViatraQueryEngine engine) { | ||
155 | return ConnectedToNotSymmetric.Matcher.on(engine); | ||
156 | } | ||
157 | |||
158 | public ConnectedToReflexive getConnectedToReflexive() { | ||
159 | return ConnectedToReflexive.instance(); | ||
160 | } | ||
161 | |||
162 | public ConnectedToReflexive.Matcher getConnectedToReflexive(final ViatraQueryEngine engine) { | ||
163 | return ConnectedToReflexive.Matcher.on(engine); | ||
164 | } | ||
165 | |||
166 | public TurnoutOutput getTurnoutOutput() { | ||
167 | return TurnoutOutput.instance(); | ||
168 | } | ||
169 | |||
170 | public TurnoutOutput.Matcher getTurnoutOutput(final ViatraQueryEngine engine) { | ||
171 | return TurnoutOutput.Matcher.on(engine); | ||
172 | } | ||
173 | |||
174 | public OutputReflexive getOutputReflexive() { | ||
175 | return OutputReflexive.instance(); | ||
176 | } | ||
177 | |||
178 | public OutputReflexive.Matcher getOutputReflexive(final ViatraQueryEngine engine) { | ||
179 | return OutputReflexive.Matcher.on(engine); | ||
180 | } | ||
181 | |||
182 | public TurnoutOutputsAreSame getTurnoutOutputsAreSame() { | ||
183 | return TurnoutOutputsAreSame.instance(); | ||
184 | } | ||
185 | |||
186 | public TurnoutOutputsAreSame.Matcher getTurnoutOutputsAreSame(final ViatraQueryEngine engine) { | ||
187 | return TurnoutOutputsAreSame.Matcher.on(engine); | ||
188 | } | ||
189 | |||
190 | public Output getOutput() { | ||
191 | return Output.instance(); | ||
192 | } | ||
193 | |||
194 | public Output.Matcher getOutput(final ViatraQueryEngine engine) { | ||
195 | return Output.Matcher.on(engine); | ||
196 | } | ||
197 | |||
198 | public TooManyInputsOfSegment getTooManyInputsOfSegment() { | ||
199 | return TooManyInputsOfSegment.instance(); | ||
200 | } | ||
201 | |||
202 | public TooManyInputsOfSegment.Matcher getTooManyInputsOfSegment(final ViatraQueryEngine engine) { | ||
203 | return TooManyInputsOfSegment.Matcher.on(engine); | ||
204 | } | ||
205 | |||
206 | public TurnoutConnectedToBothOutputs getTurnoutConnectedToBothOutputs() { | ||
207 | return TurnoutConnectedToBothOutputs.instance(); | ||
208 | } | ||
209 | |||
210 | public TurnoutConnectedToBothOutputs.Matcher getTurnoutConnectedToBothOutputs(final ViatraQueryEngine engine) { | ||
211 | return TurnoutConnectedToBothOutputs.Matcher.on(engine); | ||
212 | } | ||
213 | |||
214 | public Adjacent getAdjacent() { | ||
215 | return Adjacent.instance(); | ||
216 | } | ||
217 | |||
218 | public Adjacent.Matcher getAdjacent(final ViatraQueryEngine engine) { | ||
219 | return Adjacent.Matcher.on(engine); | ||
220 | } | ||
221 | |||
222 | public TooManyInputsOfTurnout getTooManyInputsOfTurnout() { | ||
223 | return TooManyInputsOfTurnout.instance(); | ||
224 | } | ||
225 | |||
226 | public TooManyInputsOfTurnout.Matcher getTooManyInputsOfTurnout(final ViatraQueryEngine engine) { | ||
227 | return TooManyInputsOfTurnout.Matcher.on(engine); | ||
228 | } | ||
229 | |||
230 | public InputsOfTurnout getInputsOfTurnout() { | ||
231 | return InputsOfTurnout.instance(); | ||
232 | } | ||
233 | |||
234 | public InputsOfTurnout.Matcher getInputsOfTurnout(final ViatraQueryEngine engine) { | ||
235 | return InputsOfTurnout.Matcher.on(engine); | ||
236 | } | ||
237 | |||
238 | public TooFewInputsOfTurnout getTooFewInputsOfTurnout() { | ||
239 | return TooFewInputsOfTurnout.instance(); | ||
240 | } | ||
241 | |||
242 | public TooFewInputsOfTurnout.Matcher getTooFewInputsOfTurnout(final ViatraQueryEngine engine) { | ||
243 | return TooFewInputsOfTurnout.Matcher.on(engine); | ||
244 | } | ||
245 | |||
246 | public Reachable getReachable() { | ||
247 | return Reachable.instance(); | ||
248 | } | ||
249 | |||
250 | public Reachable.Matcher getReachable(final ViatraQueryEngine engine) { | ||
251 | return Reachable.Matcher.on(engine); | ||
252 | } | ||
253 | |||
254 | public Unreachable getUnreachable() { | ||
255 | return Unreachable.instance(); | ||
256 | } | ||
257 | |||
258 | public Unreachable.Matcher getUnreachable(final ViatraQueryEngine engine) { | ||
259 | return Unreachable.Matcher.on(engine); | ||
260 | } | ||
261 | |||
262 | public CloseTrains_step_2 getCloseTrains_step_2() { | ||
263 | return CloseTrains_step_2.instance(); | ||
264 | } | ||
265 | |||
266 | public CloseTrains_step_2.Matcher getCloseTrains_step_2(final ViatraQueryEngine engine) { | ||
267 | return CloseTrains_step_2.Matcher.on(engine); | ||
268 | } | ||
269 | |||
270 | public CloseTrains_step_3 getCloseTrains_step_3() { | ||
271 | return CloseTrains_step_3.instance(); | ||
272 | } | ||
273 | |||
274 | public CloseTrains_step_3.Matcher getCloseTrains_step_3(final ViatraQueryEngine engine) { | ||
275 | return CloseTrains_step_3.Matcher.on(engine); | ||
276 | } | ||
277 | |||
278 | public CloseTrains_step_4 getCloseTrains_step_4() { | ||
279 | return CloseTrains_step_4.instance(); | ||
280 | } | ||
281 | |||
282 | public CloseTrains_step_4.Matcher getCloseTrains_step_4(final ViatraQueryEngine engine) { | ||
283 | return CloseTrains_step_4.Matcher.on(engine); | ||
284 | } | ||
285 | |||
286 | public CloseTrains_step_5 getCloseTrains_step_5() { | ||
287 | return CloseTrains_step_5.instance(); | ||
288 | } | ||
289 | |||
290 | public CloseTrains_step_5.Matcher getCloseTrains_step_5(final ViatraQueryEngine engine) { | ||
291 | return CloseTrains_step_5.Matcher.on(engine); | ||
292 | } | ||
293 | |||
294 | public CloseTrains_step_6 getCloseTrains_step_6() { | ||
295 | return CloseTrains_step_6.instance(); | ||
296 | } | ||
297 | |||
298 | public CloseTrains_step_6.Matcher getCloseTrains_step_6(final ViatraQueryEngine engine) { | ||
299 | return CloseTrains_step_6.Matcher.on(engine); | ||
300 | } | ||
301 | |||
302 | public CloseTrains_step_7 getCloseTrains_step_7() { | ||
303 | return CloseTrains_step_7.instance(); | ||
304 | } | ||
305 | |||
306 | public CloseTrains_step_7.Matcher getCloseTrains_step_7(final ViatraQueryEngine engine) { | ||
307 | return CloseTrains_step_7.Matcher.on(engine); | ||
308 | } | ||
309 | |||
310 | public TrainLocations_step_2 getTrainLocations_step_2() { | ||
311 | return TrainLocations_step_2.instance(); | ||
312 | } | ||
313 | |||
314 | public TrainLocations_step_2.Matcher getTrainLocations_step_2(final ViatraQueryEngine engine) { | ||
315 | return TrainLocations_step_2.Matcher.on(engine); | ||
316 | } | ||
317 | |||
318 | public TrainLocations_step_3 getTrainLocations_step_3() { | ||
319 | return TrainLocations_step_3.instance(); | ||
320 | } | ||
321 | |||
322 | public TrainLocations_step_3.Matcher getTrainLocations_step_3(final ViatraQueryEngine engine) { | ||
323 | return TrainLocations_step_3.Matcher.on(engine); | ||
324 | } | ||
325 | |||
326 | public MisalignedTurnout_step_2 getMisalignedTurnout_step_2() { | ||
327 | return MisalignedTurnout_step_2.instance(); | ||
328 | } | ||
329 | |||
330 | public MisalignedTurnout_step_2.Matcher getMisalignedTurnout_step_2(final ViatraQueryEngine engine) { | ||
331 | return MisalignedTurnout_step_2.Matcher.on(engine); | ||
332 | } | ||
333 | |||
334 | public MisalignedTurnout_step_3 getMisalignedTurnout_step_3() { | ||
335 | return MisalignedTurnout_step_3.instance(); | ||
336 | } | ||
337 | |||
338 | public MisalignedTurnout_step_3.Matcher getMisalignedTurnout_step_3(final ViatraQueryEngine engine) { | ||
339 | return MisalignedTurnout_step_3.Matcher.on(engine); | ||
340 | } | ||
341 | |||
342 | public MisalignedTurnout_step_4 getMisalignedTurnout_step_4() { | ||
343 | return MisalignedTurnout_step_4.instance(); | ||
344 | } | ||
345 | |||
346 | public MisalignedTurnout_step_4.Matcher getMisalignedTurnout_step_4(final ViatraQueryEngine engine) { | ||
347 | return MisalignedTurnout_step_4.Matcher.on(engine); | ||
348 | } | ||
349 | |||
350 | public MisalignedTurnout_step_5 getMisalignedTurnout_step_5() { | ||
351 | return MisalignedTurnout_step_5.instance(); | ||
352 | } | ||
353 | |||
354 | public MisalignedTurnout_step_5.Matcher getMisalignedTurnout_step_5(final ViatraQueryEngine engine) { | ||
355 | return MisalignedTurnout_step_5.Matcher.on(engine); | ||
356 | } | ||
357 | |||
358 | public ConnectedSegmentsDirected getConnectedSegmentsDirected() { | ||
359 | return ConnectedSegmentsDirected.instance(); | ||
360 | } | ||
361 | |||
362 | public ConnectedSegmentsDirected.Matcher getConnectedSegmentsDirected(final ViatraQueryEngine engine) { | ||
363 | return ConnectedSegmentsDirected.Matcher.on(engine); | ||
364 | } | ||
365 | |||
366 | public EndOfSiding_step_2 getEndOfSiding_step_2() { | ||
367 | return EndOfSiding_step_2.instance(); | ||
368 | } | ||
369 | |||
370 | public EndOfSiding_step_2.Matcher getEndOfSiding_step_2(final ViatraQueryEngine engine) { | ||
371 | return EndOfSiding_step_2.Matcher.on(engine); | ||
372 | } | ||
373 | |||
374 | public EndOfSiding_step_3 getEndOfSiding_step_3() { | ||
375 | return EndOfSiding_step_3.instance(); | ||
376 | } | ||
377 | |||
378 | public EndOfSiding_step_3.Matcher getEndOfSiding_step_3(final ViatraQueryEngine engine) { | ||
379 | return EndOfSiding_step_3.Matcher.on(engine); | ||
380 | } | ||
381 | |||
382 | public EndOfSiding_step_4 getEndOfSiding_step_4() { | ||
383 | return EndOfSiding_step_4.instance(); | ||
384 | } | ||
385 | |||
386 | public EndOfSiding_step_4.Matcher getEndOfSiding_step_4(final ViatraQueryEngine engine) { | ||
387 | return EndOfSiding_step_4.Matcher.on(engine); | ||
388 | } | ||
389 | |||
390 | public EndOfSiding_step_5 getEndOfSiding_step_5() { | ||
391 | return EndOfSiding_step_5.instance(); | ||
392 | } | ||
393 | |||
394 | public EndOfSiding_step_5.Matcher getEndOfSiding_step_5(final ViatraQueryEngine engine) { | ||
395 | return EndOfSiding_step_5.Matcher.on(engine); | ||
396 | } | ||
397 | |||
398 | public MultipleConnectedTo getMultipleConnectedTo() { | ||
399 | return MultipleConnectedTo.instance(); | ||
400 | } | ||
401 | |||
402 | public MultipleConnectedTo.Matcher getMultipleConnectedTo(final ViatraQueryEngine engine) { | ||
403 | return MultipleConnectedTo.Matcher.on(engine); | ||
404 | } | ||
405 | } | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/MultipleConnectedTo.java b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/MultipleConnectedTo.java new file mode 100644 index 00000000..277006c9 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/MultipleConnectedTo.java | |||
@@ -0,0 +1,565 @@ | |||
1 | /** | ||
2 | * Generated from platform:/resource/ca.mcgill.rtgmrt.example.modes3/src/modes3/queries/Modes3Queries.vql | ||
3 | */ | ||
4 | package modes3.queries; | ||
5 | |||
6 | import java.util.Arrays; | ||
7 | import java.util.Collection; | ||
8 | import java.util.LinkedHashSet; | ||
9 | import java.util.List; | ||
10 | import java.util.Objects; | ||
11 | import java.util.Optional; | ||
12 | import java.util.Set; | ||
13 | import java.util.function.Consumer; | ||
14 | import java.util.stream.Collectors; | ||
15 | import java.util.stream.Stream; | ||
16 | import modes3.Segment; | ||
17 | import org.apache.log4j.Logger; | ||
18 | import org.eclipse.emf.ecore.EClass; | ||
19 | import org.eclipse.viatra.query.runtime.api.IPatternMatch; | ||
20 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification; | ||
21 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; | ||
22 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; | ||
23 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; | ||
24 | import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; | ||
25 | import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; | ||
26 | import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; | ||
27 | import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; | ||
28 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
29 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | ||
30 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | ||
31 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; | ||
32 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
33 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Inequality; | ||
34 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
35 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | ||
36 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; | ||
37 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | ||
38 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; | ||
39 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
40 | import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; | ||
41 | |||
42 | /** | ||
43 | * A pattern-specific query specification that can instantiate Matcher in a type-safe way. | ||
44 | * | ||
45 | * <p>Original source: | ||
46 | * <code><pre> | ||
47 | * pattern multipleConnectedTo(s : Segment) { | ||
48 | * Segment.connectedTo(s, n1); | ||
49 | * Segment.connectedTo(s, n2); | ||
50 | * n1 != n2; | ||
51 | * } | ||
52 | * </pre></code> | ||
53 | * | ||
54 | * @see Matcher | ||
55 | * @see Match | ||
56 | * | ||
57 | */ | ||
58 | @SuppressWarnings("all") | ||
59 | public final class MultipleConnectedTo extends BaseGeneratedEMFQuerySpecification<MultipleConnectedTo.Matcher> { | ||
60 | /** | ||
61 | * Pattern-specific match representation of the modes3.queries.multipleConnectedTo pattern, | ||
62 | * to be used in conjunction with {@link Matcher}. | ||
63 | * | ||
64 | * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. | ||
65 | * Each instance is a (possibly partial) substitution of pattern parameters, | ||
66 | * usable to represent a match of the pattern in the result of a query, | ||
67 | * or to specify the bound (fixed) input parameters when issuing a query. | ||
68 | * | ||
69 | * @see Matcher | ||
70 | * | ||
71 | */ | ||
72 | public static abstract class Match extends BasePatternMatch { | ||
73 | private Segment fS; | ||
74 | |||
75 | private static List<String> parameterNames = makeImmutableList("s"); | ||
76 | |||
77 | private Match(final Segment pS) { | ||
78 | this.fS = pS; | ||
79 | } | ||
80 | |||
81 | @Override | ||
82 | public Object get(final String parameterName) { | ||
83 | switch(parameterName) { | ||
84 | case "s": return this.fS; | ||
85 | default: return null; | ||
86 | } | ||
87 | } | ||
88 | |||
89 | @Override | ||
90 | public Object get(final int index) { | ||
91 | switch(index) { | ||
92 | case 0: return this.fS; | ||
93 | default: return null; | ||
94 | } | ||
95 | } | ||
96 | |||
97 | public Segment getS() { | ||
98 | return this.fS; | ||
99 | } | ||
100 | |||
101 | @Override | ||
102 | public boolean set(final String parameterName, final Object newValue) { | ||
103 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
104 | if ("s".equals(parameterName) ) { | ||
105 | this.fS = (Segment) newValue; | ||
106 | return true; | ||
107 | } | ||
108 | return false; | ||
109 | } | ||
110 | |||
111 | public void setS(final Segment pS) { | ||
112 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
113 | this.fS = pS; | ||
114 | } | ||
115 | |||
116 | @Override | ||
117 | public String patternName() { | ||
118 | return "modes3.queries.multipleConnectedTo"; | ||
119 | } | ||
120 | |||
121 | @Override | ||
122 | public List<String> parameterNames() { | ||
123 | return MultipleConnectedTo.Match.parameterNames; | ||
124 | } | ||
125 | |||
126 | @Override | ||
127 | public Object[] toArray() { | ||
128 | return new Object[]{fS}; | ||
129 | } | ||
130 | |||
131 | @Override | ||
132 | public MultipleConnectedTo.Match toImmutable() { | ||
133 | return isMutable() ? newMatch(fS) : this; | ||
134 | } | ||
135 | |||
136 | @Override | ||
137 | public String prettyPrint() { | ||
138 | StringBuilder result = new StringBuilder(); | ||
139 | result.append("\"s\"=" + prettyPrintValue(fS)); | ||
140 | return result.toString(); | ||
141 | } | ||
142 | |||
143 | @Override | ||
144 | public int hashCode() { | ||
145 | return Objects.hash(fS); | ||
146 | } | ||
147 | |||
148 | @Override | ||
149 | public boolean equals(final Object obj) { | ||
150 | if (this == obj) | ||
151 | return true; | ||
152 | if (obj == null) { | ||
153 | return false; | ||
154 | } | ||
155 | if ((obj instanceof MultipleConnectedTo.Match)) { | ||
156 | MultipleConnectedTo.Match other = (MultipleConnectedTo.Match) obj; | ||
157 | return Objects.equals(fS, other.fS); | ||
158 | } else { | ||
159 | // this should be infrequent | ||
160 | if (!(obj instanceof IPatternMatch)) { | ||
161 | return false; | ||
162 | } | ||
163 | IPatternMatch otherSig = (IPatternMatch) obj; | ||
164 | return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); | ||
165 | } | ||
166 | } | ||
167 | |||
168 | @Override | ||
169 | public MultipleConnectedTo specification() { | ||
170 | return MultipleConnectedTo.instance(); | ||
171 | } | ||
172 | |||
173 | /** | ||
174 | * Returns an empty, mutable match. | ||
175 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
176 | * | ||
177 | * @return the empty match. | ||
178 | * | ||
179 | */ | ||
180 | public static MultipleConnectedTo.Match newEmptyMatch() { | ||
181 | return new Mutable(null); | ||
182 | } | ||
183 | |||
184 | /** | ||
185 | * Returns a mutable (partial) match. | ||
186 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
187 | * | ||
188 | * @param pS the fixed value of pattern parameter s, or null if not bound. | ||
189 | * @return the new, mutable (partial) match object. | ||
190 | * | ||
191 | */ | ||
192 | public static MultipleConnectedTo.Match newMutableMatch(final Segment pS) { | ||
193 | return new Mutable(pS); | ||
194 | } | ||
195 | |||
196 | /** | ||
197 | * Returns a new (partial) match. | ||
198 | * This can be used e.g. to call the matcher with a partial match. | ||
199 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
200 | * @param pS the fixed value of pattern parameter s, or null if not bound. | ||
201 | * @return the (partial) match object. | ||
202 | * | ||
203 | */ | ||
204 | public static MultipleConnectedTo.Match newMatch(final Segment pS) { | ||
205 | return new Immutable(pS); | ||
206 | } | ||
207 | |||
208 | private static final class Mutable extends MultipleConnectedTo.Match { | ||
209 | Mutable(final Segment pS) { | ||
210 | super(pS); | ||
211 | } | ||
212 | |||
213 | @Override | ||
214 | public boolean isMutable() { | ||
215 | return true; | ||
216 | } | ||
217 | } | ||
218 | |||
219 | private static final class Immutable extends MultipleConnectedTo.Match { | ||
220 | Immutable(final Segment pS) { | ||
221 | super(pS); | ||
222 | } | ||
223 | |||
224 | @Override | ||
225 | public boolean isMutable() { | ||
226 | return false; | ||
227 | } | ||
228 | } | ||
229 | } | ||
230 | |||
231 | /** | ||
232 | * Generated pattern matcher API of the modes3.queries.multipleConnectedTo pattern, | ||
233 | * providing pattern-specific query methods. | ||
234 | * | ||
235 | * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, | ||
236 | * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. | ||
237 | * | ||
238 | * <p>Matches of the pattern will be represented as {@link Match}. | ||
239 | * | ||
240 | * <p>Original source: | ||
241 | * <code><pre> | ||
242 | * pattern multipleConnectedTo(s : Segment) { | ||
243 | * Segment.connectedTo(s, n1); | ||
244 | * Segment.connectedTo(s, n2); | ||
245 | * n1 != n2; | ||
246 | * } | ||
247 | * </pre></code> | ||
248 | * | ||
249 | * @see Match | ||
250 | * @see MultipleConnectedTo | ||
251 | * | ||
252 | */ | ||
253 | public static class Matcher extends BaseMatcher<MultipleConnectedTo.Match> { | ||
254 | /** | ||
255 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
256 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
257 | * | ||
258 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
259 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
260 | * | ||
261 | */ | ||
262 | public static MultipleConnectedTo.Matcher on(final ViatraQueryEngine engine) { | ||
263 | // check if matcher already exists | ||
264 | Matcher matcher = engine.getExistingMatcher(querySpecification()); | ||
265 | if (matcher == null) { | ||
266 | matcher = (Matcher)engine.getMatcher(querySpecification()); | ||
267 | } | ||
268 | return matcher; | ||
269 | } | ||
270 | |||
271 | /** | ||
272 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
273 | * @return an initialized matcher | ||
274 | * @noreference This method is for internal matcher initialization by the framework, do not call it manually. | ||
275 | * | ||
276 | */ | ||
277 | public static MultipleConnectedTo.Matcher create() { | ||
278 | return new Matcher(); | ||
279 | } | ||
280 | |||
281 | private static final int POSITION_S = 0; | ||
282 | |||
283 | private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(MultipleConnectedTo.Matcher.class); | ||
284 | |||
285 | /** | ||
286 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
287 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
288 | * | ||
289 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
290 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
291 | * | ||
292 | */ | ||
293 | private Matcher() { | ||
294 | super(querySpecification()); | ||
295 | } | ||
296 | |||
297 | /** | ||
298 | * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. | ||
299 | * @param pS the fixed value of pattern parameter s, or null if not bound. | ||
300 | * @return matches represented as a Match object. | ||
301 | * | ||
302 | */ | ||
303 | public Collection<MultipleConnectedTo.Match> getAllMatches(final Segment pS) { | ||
304 | return rawStreamAllMatches(new Object[]{pS}).collect(Collectors.toSet()); | ||
305 | } | ||
306 | |||
307 | /** | ||
308 | * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. | ||
309 | * </p> | ||
310 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
311 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
312 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
313 | * @param pS the fixed value of pattern parameter s, or null if not bound. | ||
314 | * @return a stream of matches represented as a Match object. | ||
315 | * | ||
316 | */ | ||
317 | public Stream<MultipleConnectedTo.Match> streamAllMatches(final Segment pS) { | ||
318 | return rawStreamAllMatches(new Object[]{pS}); | ||
319 | } | ||
320 | |||
321 | /** | ||
322 | * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
323 | * Neither determinism nor randomness of selection is guaranteed. | ||
324 | * @param pS the fixed value of pattern parameter s, or null if not bound. | ||
325 | * @return a match represented as a Match object, or null if no match is found. | ||
326 | * | ||
327 | */ | ||
328 | public Optional<MultipleConnectedTo.Match> getOneArbitraryMatch(final Segment pS) { | ||
329 | return rawGetOneArbitraryMatch(new Object[]{pS}); | ||
330 | } | ||
331 | |||
332 | /** | ||
333 | * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, | ||
334 | * under any possible substitution of the unspecified parameters (if any). | ||
335 | * @param pS the fixed value of pattern parameter s, or null if not bound. | ||
336 | * @return true if the input is a valid (partial) match of the pattern. | ||
337 | * | ||
338 | */ | ||
339 | public boolean hasMatch(final Segment pS) { | ||
340 | return rawHasMatch(new Object[]{pS}); | ||
341 | } | ||
342 | |||
343 | /** | ||
344 | * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. | ||
345 | * @param pS the fixed value of pattern parameter s, or null if not bound. | ||
346 | * @return the number of pattern matches found. | ||
347 | * | ||
348 | */ | ||
349 | public int countMatches(final Segment pS) { | ||
350 | return rawCountMatches(new Object[]{pS}); | ||
351 | } | ||
352 | |||
353 | /** | ||
354 | * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
355 | * Neither determinism nor randomness of selection is guaranteed. | ||
356 | * @param pS the fixed value of pattern parameter s, or null if not bound. | ||
357 | * @param processor the action that will process the selected match. | ||
358 | * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked | ||
359 | * | ||
360 | */ | ||
361 | public boolean forOneArbitraryMatch(final Segment pS, final Consumer<? super MultipleConnectedTo.Match> processor) { | ||
362 | return rawForOneArbitraryMatch(new Object[]{pS}, processor); | ||
363 | } | ||
364 | |||
365 | /** | ||
366 | * Returns a new (partial) match. | ||
367 | * This can be used e.g. to call the matcher with a partial match. | ||
368 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
369 | * @param pS the fixed value of pattern parameter s, or null if not bound. | ||
370 | * @return the (partial) match object. | ||
371 | * | ||
372 | */ | ||
373 | public MultipleConnectedTo.Match newMatch(final Segment pS) { | ||
374 | return MultipleConnectedTo.Match.newMatch(pS); | ||
375 | } | ||
376 | |||
377 | /** | ||
378 | * Retrieve the set of values that occur in matches for s. | ||
379 | * @return the Set of all values or empty set if there are no matches | ||
380 | * | ||
381 | */ | ||
382 | protected Stream<Segment> rawStreamAllValuesOfs(final Object[] parameters) { | ||
383 | return rawStreamAllValues(POSITION_S, parameters).map(Segment.class::cast); | ||
384 | } | ||
385 | |||
386 | /** | ||
387 | * Retrieve the set of values that occur in matches for s. | ||
388 | * @return the Set of all values or empty set if there are no matches | ||
389 | * | ||
390 | */ | ||
391 | public Set<Segment> getAllValuesOfs() { | ||
392 | return rawStreamAllValuesOfs(emptyArray()).collect(Collectors.toSet()); | ||
393 | } | ||
394 | |||
395 | /** | ||
396 | * Retrieve the set of values that occur in matches for s. | ||
397 | * @return the Set of all values or empty set if there are no matches | ||
398 | * | ||
399 | */ | ||
400 | public Stream<Segment> streamAllValuesOfs() { | ||
401 | return rawStreamAllValuesOfs(emptyArray()); | ||
402 | } | ||
403 | |||
404 | @Override | ||
405 | protected MultipleConnectedTo.Match tupleToMatch(final Tuple t) { | ||
406 | try { | ||
407 | return MultipleConnectedTo.Match.newMatch((Segment) t.get(POSITION_S)); | ||
408 | } catch(ClassCastException e) { | ||
409 | LOGGER.error("Element(s) in tuple not properly typed!",e); | ||
410 | return null; | ||
411 | } | ||
412 | } | ||
413 | |||
414 | @Override | ||
415 | protected MultipleConnectedTo.Match arrayToMatch(final Object[] match) { | ||
416 | try { | ||
417 | return MultipleConnectedTo.Match.newMatch((Segment) match[POSITION_S]); | ||
418 | } catch(ClassCastException e) { | ||
419 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
420 | return null; | ||
421 | } | ||
422 | } | ||
423 | |||
424 | @Override | ||
425 | protected MultipleConnectedTo.Match arrayToMatchMutable(final Object[] match) { | ||
426 | try { | ||
427 | return MultipleConnectedTo.Match.newMutableMatch((Segment) match[POSITION_S]); | ||
428 | } catch(ClassCastException e) { | ||
429 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
430 | return null; | ||
431 | } | ||
432 | } | ||
433 | |||
434 | /** | ||
435 | * @return the singleton instance of the query specification of this pattern | ||
436 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
437 | * | ||
438 | */ | ||
439 | public static IQuerySpecification<MultipleConnectedTo.Matcher> querySpecification() { | ||
440 | return MultipleConnectedTo.instance(); | ||
441 | } | ||
442 | } | ||
443 | |||
444 | private MultipleConnectedTo() { | ||
445 | super(GeneratedPQuery.INSTANCE); | ||
446 | } | ||
447 | |||
448 | /** | ||
449 | * @return the singleton instance of the query specification | ||
450 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
451 | * | ||
452 | */ | ||
453 | public static MultipleConnectedTo instance() { | ||
454 | try{ | ||
455 | return LazyHolder.INSTANCE; | ||
456 | } catch (ExceptionInInitializerError err) { | ||
457 | throw processInitializerError(err); | ||
458 | } | ||
459 | } | ||
460 | |||
461 | @Override | ||
462 | protected MultipleConnectedTo.Matcher instantiate(final ViatraQueryEngine engine) { | ||
463 | return MultipleConnectedTo.Matcher.on(engine); | ||
464 | } | ||
465 | |||
466 | @Override | ||
467 | public MultipleConnectedTo.Matcher instantiate() { | ||
468 | return MultipleConnectedTo.Matcher.create(); | ||
469 | } | ||
470 | |||
471 | @Override | ||
472 | public MultipleConnectedTo.Match newEmptyMatch() { | ||
473 | return MultipleConnectedTo.Match.newEmptyMatch(); | ||
474 | } | ||
475 | |||
476 | @Override | ||
477 | public MultipleConnectedTo.Match newMatch(final Object... parameters) { | ||
478 | return MultipleConnectedTo.Match.newMatch((modes3.Segment) parameters[0]); | ||
479 | } | ||
480 | |||
481 | /** | ||
482 | * Inner class allowing the singleton instance of {@link MultipleConnectedTo} to be created | ||
483 | * <b>not</b> at the class load time of the outer class, | ||
484 | * but rather at the first call to {@link MultipleConnectedTo#instance()}. | ||
485 | * | ||
486 | * <p> This workaround is required e.g. to support recursion. | ||
487 | * | ||
488 | */ | ||
489 | private static class LazyHolder { | ||
490 | private static final MultipleConnectedTo INSTANCE = new MultipleConnectedTo(); | ||
491 | |||
492 | /** | ||
493 | * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned. | ||
494 | * This initialization order is required to support indirect recursion. | ||
495 | * | ||
496 | * <p> The static initializer is defined using a helper field to work around limitations of the code generator. | ||
497 | * | ||
498 | */ | ||
499 | private static final Object STATIC_INITIALIZER = ensureInitialized(); | ||
500 | |||
501 | public static Object ensureInitialized() { | ||
502 | INSTANCE.ensureInitializedInternal(); | ||
503 | return null; | ||
504 | } | ||
505 | } | ||
506 | |||
507 | private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { | ||
508 | private static final MultipleConnectedTo.GeneratedPQuery INSTANCE = new GeneratedPQuery(); | ||
509 | |||
510 | private final PParameter parameter_s = new PParameter("s", "modes3.Segment", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Segment")), PParameterDirection.INOUT); | ||
511 | |||
512 | private final List<PParameter> parameters = Arrays.asList(parameter_s); | ||
513 | |||
514 | private GeneratedPQuery() { | ||
515 | super(PVisibility.PUBLIC); | ||
516 | } | ||
517 | |||
518 | @Override | ||
519 | public String getFullyQualifiedName() { | ||
520 | return "modes3.queries.multipleConnectedTo"; | ||
521 | } | ||
522 | |||
523 | @Override | ||
524 | public List<String> getParameterNames() { | ||
525 | return Arrays.asList("s"); | ||
526 | } | ||
527 | |||
528 | @Override | ||
529 | public List<PParameter> getParameters() { | ||
530 | return parameters; | ||
531 | } | ||
532 | |||
533 | @Override | ||
534 | public Set<PBody> doGetContainedBodies() { | ||
535 | setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); | ||
536 | Set<PBody> bodies = new LinkedHashSet<>(); | ||
537 | { | ||
538 | PBody body = new PBody(this); | ||
539 | PVariable var_s = body.getOrCreateVariableByName("s"); | ||
540 | PVariable var_n1 = body.getOrCreateVariableByName("n1"); | ||
541 | PVariable var_n2 = body.getOrCreateVariableByName("n2"); | ||
542 | new TypeConstraint(body, Tuples.flatTupleOf(var_s), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
543 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
544 | new ExportedParameter(body, var_s, parameter_s) | ||
545 | )); | ||
546 | // Segment.connectedTo(s, n1) | ||
547 | new TypeConstraint(body, Tuples.flatTupleOf(var_s), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
548 | PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); | ||
549 | new TypeConstraint(body, Tuples.flatTupleOf(var_s, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment", "connectedTo"))); | ||
550 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
551 | new Equality(body, var__virtual_0_, var_n1); | ||
552 | // Segment.connectedTo(s, n2) | ||
553 | new TypeConstraint(body, Tuples.flatTupleOf(var_s), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
554 | PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); | ||
555 | new TypeConstraint(body, Tuples.flatTupleOf(var_s, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment", "connectedTo"))); | ||
556 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
557 | new Equality(body, var__virtual_1_, var_n2); | ||
558 | // n1 != n2 | ||
559 | new Inequality(body, var_n1, var_n2); | ||
560 | bodies.add(body); | ||
561 | } | ||
562 | return bodies; | ||
563 | } | ||
564 | } | ||
565 | } | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/Output.java b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/Output.java new file mode 100644 index 00000000..615b33af --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/Output.java | |||
@@ -0,0 +1,724 @@ | |||
1 | /** | ||
2 | * Generated from platform:/resource/ca.mcgill.rtgmrt.example.modes3/src/modes3/queries/Modes3Queries.vql | ||
3 | */ | ||
4 | package modes3.queries; | ||
5 | |||
6 | import java.util.Arrays; | ||
7 | import java.util.Collection; | ||
8 | import java.util.LinkedHashSet; | ||
9 | import java.util.List; | ||
10 | import java.util.Objects; | ||
11 | import java.util.Optional; | ||
12 | import java.util.Set; | ||
13 | import java.util.function.Consumer; | ||
14 | import java.util.stream.Collectors; | ||
15 | import java.util.stream.Stream; | ||
16 | import modes3.Segment; | ||
17 | import modes3.queries.TurnoutOutput; | ||
18 | import org.apache.log4j.Logger; | ||
19 | import org.eclipse.emf.ecore.EClass; | ||
20 | import org.eclipse.viatra.query.runtime.api.IPatternMatch; | ||
21 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification; | ||
22 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; | ||
23 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; | ||
24 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; | ||
25 | import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; | ||
26 | import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; | ||
27 | import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; | ||
28 | import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; | ||
29 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
30 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | ||
31 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | ||
32 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; | ||
33 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
34 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall; | ||
35 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
36 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | ||
37 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; | ||
38 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | ||
39 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; | ||
40 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
41 | import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; | ||
42 | |||
43 | /** | ||
44 | * A pattern-specific query specification that can instantiate Matcher in a type-safe way. | ||
45 | * | ||
46 | * <p>Original source: | ||
47 | * <code><pre> | ||
48 | * pattern output(S1 : Segment, S2 : Segment) { | ||
49 | * Segment.connectedTo(S1, S2); | ||
50 | * } or { | ||
51 | * find turnoutOutput(S1, S2); | ||
52 | * } | ||
53 | * </pre></code> | ||
54 | * | ||
55 | * @see Matcher | ||
56 | * @see Match | ||
57 | * | ||
58 | */ | ||
59 | @SuppressWarnings("all") | ||
60 | public final class Output extends BaseGeneratedEMFQuerySpecification<Output.Matcher> { | ||
61 | /** | ||
62 | * Pattern-specific match representation of the modes3.queries.output pattern, | ||
63 | * to be used in conjunction with {@link Matcher}. | ||
64 | * | ||
65 | * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. | ||
66 | * Each instance is a (possibly partial) substitution of pattern parameters, | ||
67 | * usable to represent a match of the pattern in the result of a query, | ||
68 | * or to specify the bound (fixed) input parameters when issuing a query. | ||
69 | * | ||
70 | * @see Matcher | ||
71 | * | ||
72 | */ | ||
73 | public static abstract class Match extends BasePatternMatch { | ||
74 | private Segment fS1; | ||
75 | |||
76 | private Segment fS2; | ||
77 | |||
78 | private static List<String> parameterNames = makeImmutableList("S1", "S2"); | ||
79 | |||
80 | private Match(final Segment pS1, final Segment pS2) { | ||
81 | this.fS1 = pS1; | ||
82 | this.fS2 = pS2; | ||
83 | } | ||
84 | |||
85 | @Override | ||
86 | public Object get(final String parameterName) { | ||
87 | switch(parameterName) { | ||
88 | case "S1": return this.fS1; | ||
89 | case "S2": return this.fS2; | ||
90 | default: return null; | ||
91 | } | ||
92 | } | ||
93 | |||
94 | @Override | ||
95 | public Object get(final int index) { | ||
96 | switch(index) { | ||
97 | case 0: return this.fS1; | ||
98 | case 1: return this.fS2; | ||
99 | default: return null; | ||
100 | } | ||
101 | } | ||
102 | |||
103 | public Segment getS1() { | ||
104 | return this.fS1; | ||
105 | } | ||
106 | |||
107 | public Segment getS2() { | ||
108 | return this.fS2; | ||
109 | } | ||
110 | |||
111 | @Override | ||
112 | public boolean set(final String parameterName, final Object newValue) { | ||
113 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
114 | if ("S1".equals(parameterName) ) { | ||
115 | this.fS1 = (Segment) newValue; | ||
116 | return true; | ||
117 | } | ||
118 | if ("S2".equals(parameterName) ) { | ||
119 | this.fS2 = (Segment) newValue; | ||
120 | return true; | ||
121 | } | ||
122 | return false; | ||
123 | } | ||
124 | |||
125 | public void setS1(final Segment pS1) { | ||
126 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
127 | this.fS1 = pS1; | ||
128 | } | ||
129 | |||
130 | public void setS2(final Segment pS2) { | ||
131 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
132 | this.fS2 = pS2; | ||
133 | } | ||
134 | |||
135 | @Override | ||
136 | public String patternName() { | ||
137 | return "modes3.queries.output"; | ||
138 | } | ||
139 | |||
140 | @Override | ||
141 | public List<String> parameterNames() { | ||
142 | return Output.Match.parameterNames; | ||
143 | } | ||
144 | |||
145 | @Override | ||
146 | public Object[] toArray() { | ||
147 | return new Object[]{fS1, fS2}; | ||
148 | } | ||
149 | |||
150 | @Override | ||
151 | public Output.Match toImmutable() { | ||
152 | return isMutable() ? newMatch(fS1, fS2) : this; | ||
153 | } | ||
154 | |||
155 | @Override | ||
156 | public String prettyPrint() { | ||
157 | StringBuilder result = new StringBuilder(); | ||
158 | result.append("\"S1\"=" + prettyPrintValue(fS1) + ", "); | ||
159 | result.append("\"S2\"=" + prettyPrintValue(fS2)); | ||
160 | return result.toString(); | ||
161 | } | ||
162 | |||
163 | @Override | ||
164 | public int hashCode() { | ||
165 | return Objects.hash(fS1, fS2); | ||
166 | } | ||
167 | |||
168 | @Override | ||
169 | public boolean equals(final Object obj) { | ||
170 | if (this == obj) | ||
171 | return true; | ||
172 | if (obj == null) { | ||
173 | return false; | ||
174 | } | ||
175 | if ((obj instanceof Output.Match)) { | ||
176 | Output.Match other = (Output.Match) obj; | ||
177 | return Objects.equals(fS1, other.fS1) && Objects.equals(fS2, other.fS2); | ||
178 | } else { | ||
179 | // this should be infrequent | ||
180 | if (!(obj instanceof IPatternMatch)) { | ||
181 | return false; | ||
182 | } | ||
183 | IPatternMatch otherSig = (IPatternMatch) obj; | ||
184 | return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); | ||
185 | } | ||
186 | } | ||
187 | |||
188 | @Override | ||
189 | public Output specification() { | ||
190 | return Output.instance(); | ||
191 | } | ||
192 | |||
193 | /** | ||
194 | * Returns an empty, mutable match. | ||
195 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
196 | * | ||
197 | * @return the empty match. | ||
198 | * | ||
199 | */ | ||
200 | public static Output.Match newEmptyMatch() { | ||
201 | return new Mutable(null, null); | ||
202 | } | ||
203 | |||
204 | /** | ||
205 | * Returns a mutable (partial) match. | ||
206 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
207 | * | ||
208 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
209 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
210 | * @return the new, mutable (partial) match object. | ||
211 | * | ||
212 | */ | ||
213 | public static Output.Match newMutableMatch(final Segment pS1, final Segment pS2) { | ||
214 | return new Mutable(pS1, pS2); | ||
215 | } | ||
216 | |||
217 | /** | ||
218 | * Returns a new (partial) match. | ||
219 | * This can be used e.g. to call the matcher with a partial match. | ||
220 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
221 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
222 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
223 | * @return the (partial) match object. | ||
224 | * | ||
225 | */ | ||
226 | public static Output.Match newMatch(final Segment pS1, final Segment pS2) { | ||
227 | return new Immutable(pS1, pS2); | ||
228 | } | ||
229 | |||
230 | private static final class Mutable extends Output.Match { | ||
231 | Mutable(final Segment pS1, final Segment pS2) { | ||
232 | super(pS1, pS2); | ||
233 | } | ||
234 | |||
235 | @Override | ||
236 | public boolean isMutable() { | ||
237 | return true; | ||
238 | } | ||
239 | } | ||
240 | |||
241 | private static final class Immutable extends Output.Match { | ||
242 | Immutable(final Segment pS1, final Segment pS2) { | ||
243 | super(pS1, pS2); | ||
244 | } | ||
245 | |||
246 | @Override | ||
247 | public boolean isMutable() { | ||
248 | return false; | ||
249 | } | ||
250 | } | ||
251 | } | ||
252 | |||
253 | /** | ||
254 | * Generated pattern matcher API of the modes3.queries.output pattern, | ||
255 | * providing pattern-specific query methods. | ||
256 | * | ||
257 | * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, | ||
258 | * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. | ||
259 | * | ||
260 | * <p>Matches of the pattern will be represented as {@link Match}. | ||
261 | * | ||
262 | * <p>Original source: | ||
263 | * <code><pre> | ||
264 | * pattern output(S1 : Segment, S2 : Segment) { | ||
265 | * Segment.connectedTo(S1, S2); | ||
266 | * } or { | ||
267 | * find turnoutOutput(S1, S2); | ||
268 | * } | ||
269 | * </pre></code> | ||
270 | * | ||
271 | * @see Match | ||
272 | * @see Output | ||
273 | * | ||
274 | */ | ||
275 | public static class Matcher extends BaseMatcher<Output.Match> { | ||
276 | /** | ||
277 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
278 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
279 | * | ||
280 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
281 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
282 | * | ||
283 | */ | ||
284 | public static Output.Matcher on(final ViatraQueryEngine engine) { | ||
285 | // check if matcher already exists | ||
286 | Matcher matcher = engine.getExistingMatcher(querySpecification()); | ||
287 | if (matcher == null) { | ||
288 | matcher = (Matcher)engine.getMatcher(querySpecification()); | ||
289 | } | ||
290 | return matcher; | ||
291 | } | ||
292 | |||
293 | /** | ||
294 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
295 | * @return an initialized matcher | ||
296 | * @noreference This method is for internal matcher initialization by the framework, do not call it manually. | ||
297 | * | ||
298 | */ | ||
299 | public static Output.Matcher create() { | ||
300 | return new Matcher(); | ||
301 | } | ||
302 | |||
303 | private static final int POSITION_S1 = 0; | ||
304 | |||
305 | private static final int POSITION_S2 = 1; | ||
306 | |||
307 | private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Output.Matcher.class); | ||
308 | |||
309 | /** | ||
310 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
311 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
312 | * | ||
313 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
314 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
315 | * | ||
316 | */ | ||
317 | private Matcher() { | ||
318 | super(querySpecification()); | ||
319 | } | ||
320 | |||
321 | /** | ||
322 | * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. | ||
323 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
324 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
325 | * @return matches represented as a Match object. | ||
326 | * | ||
327 | */ | ||
328 | public Collection<Output.Match> getAllMatches(final Segment pS1, final Segment pS2) { | ||
329 | return rawStreamAllMatches(new Object[]{pS1, pS2}).collect(Collectors.toSet()); | ||
330 | } | ||
331 | |||
332 | /** | ||
333 | * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. | ||
334 | * </p> | ||
335 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
336 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
337 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
338 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
339 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
340 | * @return a stream of matches represented as a Match object. | ||
341 | * | ||
342 | */ | ||
343 | public Stream<Output.Match> streamAllMatches(final Segment pS1, final Segment pS2) { | ||
344 | return rawStreamAllMatches(new Object[]{pS1, pS2}); | ||
345 | } | ||
346 | |||
347 | /** | ||
348 | * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
349 | * Neither determinism nor randomness of selection is guaranteed. | ||
350 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
351 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
352 | * @return a match represented as a Match object, or null if no match is found. | ||
353 | * | ||
354 | */ | ||
355 | public Optional<Output.Match> getOneArbitraryMatch(final Segment pS1, final Segment pS2) { | ||
356 | return rawGetOneArbitraryMatch(new Object[]{pS1, pS2}); | ||
357 | } | ||
358 | |||
359 | /** | ||
360 | * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, | ||
361 | * under any possible substitution of the unspecified parameters (if any). | ||
362 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
363 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
364 | * @return true if the input is a valid (partial) match of the pattern. | ||
365 | * | ||
366 | */ | ||
367 | public boolean hasMatch(final Segment pS1, final Segment pS2) { | ||
368 | return rawHasMatch(new Object[]{pS1, pS2}); | ||
369 | } | ||
370 | |||
371 | /** | ||
372 | * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. | ||
373 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
374 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
375 | * @return the number of pattern matches found. | ||
376 | * | ||
377 | */ | ||
378 | public int countMatches(final Segment pS1, final Segment pS2) { | ||
379 | return rawCountMatches(new Object[]{pS1, pS2}); | ||
380 | } | ||
381 | |||
382 | /** | ||
383 | * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
384 | * Neither determinism nor randomness of selection is guaranteed. | ||
385 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
386 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
387 | * @param processor the action that will process the selected match. | ||
388 | * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked | ||
389 | * | ||
390 | */ | ||
391 | public boolean forOneArbitraryMatch(final Segment pS1, final Segment pS2, final Consumer<? super Output.Match> processor) { | ||
392 | return rawForOneArbitraryMatch(new Object[]{pS1, pS2}, processor); | ||
393 | } | ||
394 | |||
395 | /** | ||
396 | * Returns a new (partial) match. | ||
397 | * This can be used e.g. to call the matcher with a partial match. | ||
398 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
399 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
400 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
401 | * @return the (partial) match object. | ||
402 | * | ||
403 | */ | ||
404 | public Output.Match newMatch(final Segment pS1, final Segment pS2) { | ||
405 | return Output.Match.newMatch(pS1, pS2); | ||
406 | } | ||
407 | |||
408 | /** | ||
409 | * Retrieve the set of values that occur in matches for S1. | ||
410 | * @return the Set of all values or empty set if there are no matches | ||
411 | * | ||
412 | */ | ||
413 | protected Stream<Segment> rawStreamAllValuesOfS1(final Object[] parameters) { | ||
414 | return rawStreamAllValues(POSITION_S1, parameters).map(Segment.class::cast); | ||
415 | } | ||
416 | |||
417 | /** | ||
418 | * Retrieve the set of values that occur in matches for S1. | ||
419 | * @return the Set of all values or empty set if there are no matches | ||
420 | * | ||
421 | */ | ||
422 | public Set<Segment> getAllValuesOfS1() { | ||
423 | return rawStreamAllValuesOfS1(emptyArray()).collect(Collectors.toSet()); | ||
424 | } | ||
425 | |||
426 | /** | ||
427 | * Retrieve the set of values that occur in matches for S1. | ||
428 | * @return the Set of all values or empty set if there are no matches | ||
429 | * | ||
430 | */ | ||
431 | public Stream<Segment> streamAllValuesOfS1() { | ||
432 | return rawStreamAllValuesOfS1(emptyArray()); | ||
433 | } | ||
434 | |||
435 | /** | ||
436 | * Retrieve the set of values that occur in matches for S1. | ||
437 | * </p> | ||
438 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
439 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
440 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
441 | * | ||
442 | * @return the Stream of all values or empty set if there are no matches | ||
443 | * | ||
444 | */ | ||
445 | public Stream<Segment> streamAllValuesOfS1(final Output.Match partialMatch) { | ||
446 | return rawStreamAllValuesOfS1(partialMatch.toArray()); | ||
447 | } | ||
448 | |||
449 | /** | ||
450 | * Retrieve the set of values that occur in matches for S1. | ||
451 | * </p> | ||
452 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
453 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
454 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
455 | * | ||
456 | * @return the Stream of all values or empty set if there are no matches | ||
457 | * | ||
458 | */ | ||
459 | public Stream<Segment> streamAllValuesOfS1(final Segment pS2) { | ||
460 | return rawStreamAllValuesOfS1(new Object[]{null, pS2}); | ||
461 | } | ||
462 | |||
463 | /** | ||
464 | * Retrieve the set of values that occur in matches for S1. | ||
465 | * @return the Set of all values or empty set if there are no matches | ||
466 | * | ||
467 | */ | ||
468 | public Set<Segment> getAllValuesOfS1(final Output.Match partialMatch) { | ||
469 | return rawStreamAllValuesOfS1(partialMatch.toArray()).collect(Collectors.toSet()); | ||
470 | } | ||
471 | |||
472 | /** | ||
473 | * Retrieve the set of values that occur in matches for S1. | ||
474 | * @return the Set of all values or empty set if there are no matches | ||
475 | * | ||
476 | */ | ||
477 | public Set<Segment> getAllValuesOfS1(final Segment pS2) { | ||
478 | return rawStreamAllValuesOfS1(new Object[]{null, pS2}).collect(Collectors.toSet()); | ||
479 | } | ||
480 | |||
481 | /** | ||
482 | * Retrieve the set of values that occur in matches for S2. | ||
483 | * @return the Set of all values or empty set if there are no matches | ||
484 | * | ||
485 | */ | ||
486 | protected Stream<Segment> rawStreamAllValuesOfS2(final Object[] parameters) { | ||
487 | return rawStreamAllValues(POSITION_S2, parameters).map(Segment.class::cast); | ||
488 | } | ||
489 | |||
490 | /** | ||
491 | * Retrieve the set of values that occur in matches for S2. | ||
492 | * @return the Set of all values or empty set if there are no matches | ||
493 | * | ||
494 | */ | ||
495 | public Set<Segment> getAllValuesOfS2() { | ||
496 | return rawStreamAllValuesOfS2(emptyArray()).collect(Collectors.toSet()); | ||
497 | } | ||
498 | |||
499 | /** | ||
500 | * Retrieve the set of values that occur in matches for S2. | ||
501 | * @return the Set of all values or empty set if there are no matches | ||
502 | * | ||
503 | */ | ||
504 | public Stream<Segment> streamAllValuesOfS2() { | ||
505 | return rawStreamAllValuesOfS2(emptyArray()); | ||
506 | } | ||
507 | |||
508 | /** | ||
509 | * Retrieve the set of values that occur in matches for S2. | ||
510 | * </p> | ||
511 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
512 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
513 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
514 | * | ||
515 | * @return the Stream of all values or empty set if there are no matches | ||
516 | * | ||
517 | */ | ||
518 | public Stream<Segment> streamAllValuesOfS2(final Output.Match partialMatch) { | ||
519 | return rawStreamAllValuesOfS2(partialMatch.toArray()); | ||
520 | } | ||
521 | |||
522 | /** | ||
523 | * Retrieve the set of values that occur in matches for S2. | ||
524 | * </p> | ||
525 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
526 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
527 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
528 | * | ||
529 | * @return the Stream of all values or empty set if there are no matches | ||
530 | * | ||
531 | */ | ||
532 | public Stream<Segment> streamAllValuesOfS2(final Segment pS1) { | ||
533 | return rawStreamAllValuesOfS2(new Object[]{pS1, null}); | ||
534 | } | ||
535 | |||
536 | /** | ||
537 | * Retrieve the set of values that occur in matches for S2. | ||
538 | * @return the Set of all values or empty set if there are no matches | ||
539 | * | ||
540 | */ | ||
541 | public Set<Segment> getAllValuesOfS2(final Output.Match partialMatch) { | ||
542 | return rawStreamAllValuesOfS2(partialMatch.toArray()).collect(Collectors.toSet()); | ||
543 | } | ||
544 | |||
545 | /** | ||
546 | * Retrieve the set of values that occur in matches for S2. | ||
547 | * @return the Set of all values or empty set if there are no matches | ||
548 | * | ||
549 | */ | ||
550 | public Set<Segment> getAllValuesOfS2(final Segment pS1) { | ||
551 | return rawStreamAllValuesOfS2(new Object[]{pS1, null}).collect(Collectors.toSet()); | ||
552 | } | ||
553 | |||
554 | @Override | ||
555 | protected Output.Match tupleToMatch(final Tuple t) { | ||
556 | try { | ||
557 | return Output.Match.newMatch((Segment) t.get(POSITION_S1), (Segment) t.get(POSITION_S2)); | ||
558 | } catch(ClassCastException e) { | ||
559 | LOGGER.error("Element(s) in tuple not properly typed!",e); | ||
560 | return null; | ||
561 | } | ||
562 | } | ||
563 | |||
564 | @Override | ||
565 | protected Output.Match arrayToMatch(final Object[] match) { | ||
566 | try { | ||
567 | return Output.Match.newMatch((Segment) match[POSITION_S1], (Segment) match[POSITION_S2]); | ||
568 | } catch(ClassCastException e) { | ||
569 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
570 | return null; | ||
571 | } | ||
572 | } | ||
573 | |||
574 | @Override | ||
575 | protected Output.Match arrayToMatchMutable(final Object[] match) { | ||
576 | try { | ||
577 | return Output.Match.newMutableMatch((Segment) match[POSITION_S1], (Segment) match[POSITION_S2]); | ||
578 | } catch(ClassCastException e) { | ||
579 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
580 | return null; | ||
581 | } | ||
582 | } | ||
583 | |||
584 | /** | ||
585 | * @return the singleton instance of the query specification of this pattern | ||
586 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
587 | * | ||
588 | */ | ||
589 | public static IQuerySpecification<Output.Matcher> querySpecification() { | ||
590 | return Output.instance(); | ||
591 | } | ||
592 | } | ||
593 | |||
594 | private Output() { | ||
595 | super(GeneratedPQuery.INSTANCE); | ||
596 | } | ||
597 | |||
598 | /** | ||
599 | * @return the singleton instance of the query specification | ||
600 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
601 | * | ||
602 | */ | ||
603 | public static Output instance() { | ||
604 | try{ | ||
605 | return LazyHolder.INSTANCE; | ||
606 | } catch (ExceptionInInitializerError err) { | ||
607 | throw processInitializerError(err); | ||
608 | } | ||
609 | } | ||
610 | |||
611 | @Override | ||
612 | protected Output.Matcher instantiate(final ViatraQueryEngine engine) { | ||
613 | return Output.Matcher.on(engine); | ||
614 | } | ||
615 | |||
616 | @Override | ||
617 | public Output.Matcher instantiate() { | ||
618 | return Output.Matcher.create(); | ||
619 | } | ||
620 | |||
621 | @Override | ||
622 | public Output.Match newEmptyMatch() { | ||
623 | return Output.Match.newEmptyMatch(); | ||
624 | } | ||
625 | |||
626 | @Override | ||
627 | public Output.Match newMatch(final Object... parameters) { | ||
628 | return Output.Match.newMatch((modes3.Segment) parameters[0], (modes3.Segment) parameters[1]); | ||
629 | } | ||
630 | |||
631 | /** | ||
632 | * Inner class allowing the singleton instance of {@link Output} to be created | ||
633 | * <b>not</b> at the class load time of the outer class, | ||
634 | * but rather at the first call to {@link Output#instance()}. | ||
635 | * | ||
636 | * <p> This workaround is required e.g. to support recursion. | ||
637 | * | ||
638 | */ | ||
639 | private static class LazyHolder { | ||
640 | private static final Output INSTANCE = new Output(); | ||
641 | |||
642 | /** | ||
643 | * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned. | ||
644 | * This initialization order is required to support indirect recursion. | ||
645 | * | ||
646 | * <p> The static initializer is defined using a helper field to work around limitations of the code generator. | ||
647 | * | ||
648 | */ | ||
649 | private static final Object STATIC_INITIALIZER = ensureInitialized(); | ||
650 | |||
651 | public static Object ensureInitialized() { | ||
652 | INSTANCE.ensureInitializedInternal(); | ||
653 | return null; | ||
654 | } | ||
655 | } | ||
656 | |||
657 | private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { | ||
658 | private static final Output.GeneratedPQuery INSTANCE = new GeneratedPQuery(); | ||
659 | |||
660 | private final PParameter parameter_S1 = new PParameter("S1", "modes3.Segment", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Segment")), PParameterDirection.INOUT); | ||
661 | |||
662 | private final PParameter parameter_S2 = new PParameter("S2", "modes3.Segment", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Segment")), PParameterDirection.INOUT); | ||
663 | |||
664 | private final List<PParameter> parameters = Arrays.asList(parameter_S1, parameter_S2); | ||
665 | |||
666 | private GeneratedPQuery() { | ||
667 | super(PVisibility.PUBLIC); | ||
668 | } | ||
669 | |||
670 | @Override | ||
671 | public String getFullyQualifiedName() { | ||
672 | return "modes3.queries.output"; | ||
673 | } | ||
674 | |||
675 | @Override | ||
676 | public List<String> getParameterNames() { | ||
677 | return Arrays.asList("S1","S2"); | ||
678 | } | ||
679 | |||
680 | @Override | ||
681 | public List<PParameter> getParameters() { | ||
682 | return parameters; | ||
683 | } | ||
684 | |||
685 | @Override | ||
686 | public Set<PBody> doGetContainedBodies() { | ||
687 | setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); | ||
688 | Set<PBody> bodies = new LinkedHashSet<>(); | ||
689 | { | ||
690 | PBody body = new PBody(this); | ||
691 | PVariable var_S1 = body.getOrCreateVariableByName("S1"); | ||
692 | PVariable var_S2 = body.getOrCreateVariableByName("S2"); | ||
693 | new TypeConstraint(body, Tuples.flatTupleOf(var_S1), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
694 | new TypeConstraint(body, Tuples.flatTupleOf(var_S2), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
695 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
696 | new ExportedParameter(body, var_S1, parameter_S1), | ||
697 | new ExportedParameter(body, var_S2, parameter_S2) | ||
698 | )); | ||
699 | // Segment.connectedTo(S1, S2) | ||
700 | new TypeConstraint(body, Tuples.flatTupleOf(var_S1), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
701 | PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); | ||
702 | new TypeConstraint(body, Tuples.flatTupleOf(var_S1, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment", "connectedTo"))); | ||
703 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
704 | new Equality(body, var__virtual_0_, var_S2); | ||
705 | bodies.add(body); | ||
706 | } | ||
707 | { | ||
708 | PBody body = new PBody(this); | ||
709 | PVariable var_S1 = body.getOrCreateVariableByName("S1"); | ||
710 | PVariable var_S2 = body.getOrCreateVariableByName("S2"); | ||
711 | new TypeConstraint(body, Tuples.flatTupleOf(var_S1), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
712 | new TypeConstraint(body, Tuples.flatTupleOf(var_S2), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
713 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
714 | new ExportedParameter(body, var_S1, parameter_S1), | ||
715 | new ExportedParameter(body, var_S2, parameter_S2) | ||
716 | )); | ||
717 | // find turnoutOutput(S1, S2) | ||
718 | new PositivePatternCall(body, Tuples.flatTupleOf(var_S1, var_S2), TurnoutOutput.instance().getInternalQueryRepresentation()); | ||
719 | bodies.add(body); | ||
720 | } | ||
721 | return bodies; | ||
722 | } | ||
723 | } | ||
724 | } | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/OutputReflexive.java b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/OutputReflexive.java new file mode 100644 index 00000000..3d90ede5 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/OutputReflexive.java | |||
@@ -0,0 +1,559 @@ | |||
1 | /** | ||
2 | * Generated from platform:/resource/ca.mcgill.rtgmrt.example.modes3/src/modes3/queries/Modes3Queries.vql | ||
3 | */ | ||
4 | package modes3.queries; | ||
5 | |||
6 | import java.util.Arrays; | ||
7 | import java.util.Collection; | ||
8 | import java.util.LinkedHashSet; | ||
9 | import java.util.List; | ||
10 | import java.util.Objects; | ||
11 | import java.util.Optional; | ||
12 | import java.util.Set; | ||
13 | import java.util.function.Consumer; | ||
14 | import java.util.stream.Collectors; | ||
15 | import java.util.stream.Stream; | ||
16 | import modes3.Turnout; | ||
17 | import modes3.queries.TurnoutOutput; | ||
18 | import org.apache.log4j.Logger; | ||
19 | import org.eclipse.emf.ecore.EClass; | ||
20 | import org.eclipse.viatra.query.runtime.api.IPatternMatch; | ||
21 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification; | ||
22 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; | ||
23 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; | ||
24 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; | ||
25 | import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; | ||
26 | import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; | ||
27 | import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; | ||
28 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
29 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | ||
30 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | ||
31 | import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation; | ||
32 | import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference; | ||
33 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
34 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall; | ||
35 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
36 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | ||
37 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; | ||
38 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | ||
39 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; | ||
40 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
41 | import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; | ||
42 | |||
43 | /** | ||
44 | * A pattern-specific query specification that can instantiate Matcher in a type-safe way. | ||
45 | * | ||
46 | * <p>Original source: | ||
47 | * <code><pre> | ||
48 | * {@literal @}Constraint(message = "outputReflexive", severity = "error", key = { T }) | ||
49 | * pattern outputReflexive(T : Turnout) { | ||
50 | * find turnoutOutput(T, T); | ||
51 | * } | ||
52 | * </pre></code> | ||
53 | * | ||
54 | * @see Matcher | ||
55 | * @see Match | ||
56 | * | ||
57 | */ | ||
58 | @SuppressWarnings("all") | ||
59 | public final class OutputReflexive extends BaseGeneratedEMFQuerySpecification<OutputReflexive.Matcher> { | ||
60 | /** | ||
61 | * Pattern-specific match representation of the modes3.queries.outputReflexive pattern, | ||
62 | * to be used in conjunction with {@link Matcher}. | ||
63 | * | ||
64 | * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. | ||
65 | * Each instance is a (possibly partial) substitution of pattern parameters, | ||
66 | * usable to represent a match of the pattern in the result of a query, | ||
67 | * or to specify the bound (fixed) input parameters when issuing a query. | ||
68 | * | ||
69 | * @see Matcher | ||
70 | * | ||
71 | */ | ||
72 | public static abstract class Match extends BasePatternMatch { | ||
73 | private Turnout fT; | ||
74 | |||
75 | private static List<String> parameterNames = makeImmutableList("T"); | ||
76 | |||
77 | private Match(final Turnout pT) { | ||
78 | this.fT = pT; | ||
79 | } | ||
80 | |||
81 | @Override | ||
82 | public Object get(final String parameterName) { | ||
83 | switch(parameterName) { | ||
84 | case "T": return this.fT; | ||
85 | default: return null; | ||
86 | } | ||
87 | } | ||
88 | |||
89 | @Override | ||
90 | public Object get(final int index) { | ||
91 | switch(index) { | ||
92 | case 0: return this.fT; | ||
93 | default: return null; | ||
94 | } | ||
95 | } | ||
96 | |||
97 | public Turnout getT() { | ||
98 | return this.fT; | ||
99 | } | ||
100 | |||
101 | @Override | ||
102 | public boolean set(final String parameterName, final Object newValue) { | ||
103 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
104 | if ("T".equals(parameterName) ) { | ||
105 | this.fT = (Turnout) newValue; | ||
106 | return true; | ||
107 | } | ||
108 | return false; | ||
109 | } | ||
110 | |||
111 | public void setT(final Turnout pT) { | ||
112 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
113 | this.fT = pT; | ||
114 | } | ||
115 | |||
116 | @Override | ||
117 | public String patternName() { | ||
118 | return "modes3.queries.outputReflexive"; | ||
119 | } | ||
120 | |||
121 | @Override | ||
122 | public List<String> parameterNames() { | ||
123 | return OutputReflexive.Match.parameterNames; | ||
124 | } | ||
125 | |||
126 | @Override | ||
127 | public Object[] toArray() { | ||
128 | return new Object[]{fT}; | ||
129 | } | ||
130 | |||
131 | @Override | ||
132 | public OutputReflexive.Match toImmutable() { | ||
133 | return isMutable() ? newMatch(fT) : this; | ||
134 | } | ||
135 | |||
136 | @Override | ||
137 | public String prettyPrint() { | ||
138 | StringBuilder result = new StringBuilder(); | ||
139 | result.append("\"T\"=" + prettyPrintValue(fT)); | ||
140 | return result.toString(); | ||
141 | } | ||
142 | |||
143 | @Override | ||
144 | public int hashCode() { | ||
145 | return Objects.hash(fT); | ||
146 | } | ||
147 | |||
148 | @Override | ||
149 | public boolean equals(final Object obj) { | ||
150 | if (this == obj) | ||
151 | return true; | ||
152 | if (obj == null) { | ||
153 | return false; | ||
154 | } | ||
155 | if ((obj instanceof OutputReflexive.Match)) { | ||
156 | OutputReflexive.Match other = (OutputReflexive.Match) obj; | ||
157 | return Objects.equals(fT, other.fT); | ||
158 | } else { | ||
159 | // this should be infrequent | ||
160 | if (!(obj instanceof IPatternMatch)) { | ||
161 | return false; | ||
162 | } | ||
163 | IPatternMatch otherSig = (IPatternMatch) obj; | ||
164 | return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); | ||
165 | } | ||
166 | } | ||
167 | |||
168 | @Override | ||
169 | public OutputReflexive specification() { | ||
170 | return OutputReflexive.instance(); | ||
171 | } | ||
172 | |||
173 | /** | ||
174 | * Returns an empty, mutable match. | ||
175 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
176 | * | ||
177 | * @return the empty match. | ||
178 | * | ||
179 | */ | ||
180 | public static OutputReflexive.Match newEmptyMatch() { | ||
181 | return new Mutable(null); | ||
182 | } | ||
183 | |||
184 | /** | ||
185 | * Returns a mutable (partial) match. | ||
186 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
187 | * | ||
188 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
189 | * @return the new, mutable (partial) match object. | ||
190 | * | ||
191 | */ | ||
192 | public static OutputReflexive.Match newMutableMatch(final Turnout pT) { | ||
193 | return new Mutable(pT); | ||
194 | } | ||
195 | |||
196 | /** | ||
197 | * Returns a new (partial) match. | ||
198 | * This can be used e.g. to call the matcher with a partial match. | ||
199 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
200 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
201 | * @return the (partial) match object. | ||
202 | * | ||
203 | */ | ||
204 | public static OutputReflexive.Match newMatch(final Turnout pT) { | ||
205 | return new Immutable(pT); | ||
206 | } | ||
207 | |||
208 | private static final class Mutable extends OutputReflexive.Match { | ||
209 | Mutable(final Turnout pT) { | ||
210 | super(pT); | ||
211 | } | ||
212 | |||
213 | @Override | ||
214 | public boolean isMutable() { | ||
215 | return true; | ||
216 | } | ||
217 | } | ||
218 | |||
219 | private static final class Immutable extends OutputReflexive.Match { | ||
220 | Immutable(final Turnout pT) { | ||
221 | super(pT); | ||
222 | } | ||
223 | |||
224 | @Override | ||
225 | public boolean isMutable() { | ||
226 | return false; | ||
227 | } | ||
228 | } | ||
229 | } | ||
230 | |||
231 | /** | ||
232 | * Generated pattern matcher API of the modes3.queries.outputReflexive pattern, | ||
233 | * providing pattern-specific query methods. | ||
234 | * | ||
235 | * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, | ||
236 | * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. | ||
237 | * | ||
238 | * <p>Matches of the pattern will be represented as {@link Match}. | ||
239 | * | ||
240 | * <p>Original source: | ||
241 | * <code><pre> | ||
242 | * {@literal @}Constraint(message = "outputReflexive", severity = "error", key = { T }) | ||
243 | * pattern outputReflexive(T : Turnout) { | ||
244 | * find turnoutOutput(T, T); | ||
245 | * } | ||
246 | * </pre></code> | ||
247 | * | ||
248 | * @see Match | ||
249 | * @see OutputReflexive | ||
250 | * | ||
251 | */ | ||
252 | public static class Matcher extends BaseMatcher<OutputReflexive.Match> { | ||
253 | /** | ||
254 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
255 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
256 | * | ||
257 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
258 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
259 | * | ||
260 | */ | ||
261 | public static OutputReflexive.Matcher on(final ViatraQueryEngine engine) { | ||
262 | // check if matcher already exists | ||
263 | Matcher matcher = engine.getExistingMatcher(querySpecification()); | ||
264 | if (matcher == null) { | ||
265 | matcher = (Matcher)engine.getMatcher(querySpecification()); | ||
266 | } | ||
267 | return matcher; | ||
268 | } | ||
269 | |||
270 | /** | ||
271 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
272 | * @return an initialized matcher | ||
273 | * @noreference This method is for internal matcher initialization by the framework, do not call it manually. | ||
274 | * | ||
275 | */ | ||
276 | public static OutputReflexive.Matcher create() { | ||
277 | return new Matcher(); | ||
278 | } | ||
279 | |||
280 | private static final int POSITION_T = 0; | ||
281 | |||
282 | private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(OutputReflexive.Matcher.class); | ||
283 | |||
284 | /** | ||
285 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
286 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
287 | * | ||
288 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
289 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
290 | * | ||
291 | */ | ||
292 | private Matcher() { | ||
293 | super(querySpecification()); | ||
294 | } | ||
295 | |||
296 | /** | ||
297 | * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. | ||
298 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
299 | * @return matches represented as a Match object. | ||
300 | * | ||
301 | */ | ||
302 | public Collection<OutputReflexive.Match> getAllMatches(final Turnout pT) { | ||
303 | return rawStreamAllMatches(new Object[]{pT}).collect(Collectors.toSet()); | ||
304 | } | ||
305 | |||
306 | /** | ||
307 | * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. | ||
308 | * </p> | ||
309 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
310 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
311 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
312 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
313 | * @return a stream of matches represented as a Match object. | ||
314 | * | ||
315 | */ | ||
316 | public Stream<OutputReflexive.Match> streamAllMatches(final Turnout pT) { | ||
317 | return rawStreamAllMatches(new Object[]{pT}); | ||
318 | } | ||
319 | |||
320 | /** | ||
321 | * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
322 | * Neither determinism nor randomness of selection is guaranteed. | ||
323 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
324 | * @return a match represented as a Match object, or null if no match is found. | ||
325 | * | ||
326 | */ | ||
327 | public Optional<OutputReflexive.Match> getOneArbitraryMatch(final Turnout pT) { | ||
328 | return rawGetOneArbitraryMatch(new Object[]{pT}); | ||
329 | } | ||
330 | |||
331 | /** | ||
332 | * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, | ||
333 | * under any possible substitution of the unspecified parameters (if any). | ||
334 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
335 | * @return true if the input is a valid (partial) match of the pattern. | ||
336 | * | ||
337 | */ | ||
338 | public boolean hasMatch(final Turnout pT) { | ||
339 | return rawHasMatch(new Object[]{pT}); | ||
340 | } | ||
341 | |||
342 | /** | ||
343 | * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. | ||
344 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
345 | * @return the number of pattern matches found. | ||
346 | * | ||
347 | */ | ||
348 | public int countMatches(final Turnout pT) { | ||
349 | return rawCountMatches(new Object[]{pT}); | ||
350 | } | ||
351 | |||
352 | /** | ||
353 | * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
354 | * Neither determinism nor randomness of selection is guaranteed. | ||
355 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
356 | * @param processor the action that will process the selected match. | ||
357 | * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked | ||
358 | * | ||
359 | */ | ||
360 | public boolean forOneArbitraryMatch(final Turnout pT, final Consumer<? super OutputReflexive.Match> processor) { | ||
361 | return rawForOneArbitraryMatch(new Object[]{pT}, processor); | ||
362 | } | ||
363 | |||
364 | /** | ||
365 | * Returns a new (partial) match. | ||
366 | * This can be used e.g. to call the matcher with a partial match. | ||
367 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
368 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
369 | * @return the (partial) match object. | ||
370 | * | ||
371 | */ | ||
372 | public OutputReflexive.Match newMatch(final Turnout pT) { | ||
373 | return OutputReflexive.Match.newMatch(pT); | ||
374 | } | ||
375 | |||
376 | /** | ||
377 | * Retrieve the set of values that occur in matches for T. | ||
378 | * @return the Set of all values or empty set if there are no matches | ||
379 | * | ||
380 | */ | ||
381 | protected Stream<Turnout> rawStreamAllValuesOfT(final Object[] parameters) { | ||
382 | return rawStreamAllValues(POSITION_T, parameters).map(Turnout.class::cast); | ||
383 | } | ||
384 | |||
385 | /** | ||
386 | * Retrieve the set of values that occur in matches for T. | ||
387 | * @return the Set of all values or empty set if there are no matches | ||
388 | * | ||
389 | */ | ||
390 | public Set<Turnout> getAllValuesOfT() { | ||
391 | return rawStreamAllValuesOfT(emptyArray()).collect(Collectors.toSet()); | ||
392 | } | ||
393 | |||
394 | /** | ||
395 | * Retrieve the set of values that occur in matches for T. | ||
396 | * @return the Set of all values or empty set if there are no matches | ||
397 | * | ||
398 | */ | ||
399 | public Stream<Turnout> streamAllValuesOfT() { | ||
400 | return rawStreamAllValuesOfT(emptyArray()); | ||
401 | } | ||
402 | |||
403 | @Override | ||
404 | protected OutputReflexive.Match tupleToMatch(final Tuple t) { | ||
405 | try { | ||
406 | return OutputReflexive.Match.newMatch((Turnout) t.get(POSITION_T)); | ||
407 | } catch(ClassCastException e) { | ||
408 | LOGGER.error("Element(s) in tuple not properly typed!",e); | ||
409 | return null; | ||
410 | } | ||
411 | } | ||
412 | |||
413 | @Override | ||
414 | protected OutputReflexive.Match arrayToMatch(final Object[] match) { | ||
415 | try { | ||
416 | return OutputReflexive.Match.newMatch((Turnout) match[POSITION_T]); | ||
417 | } catch(ClassCastException e) { | ||
418 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
419 | return null; | ||
420 | } | ||
421 | } | ||
422 | |||
423 | @Override | ||
424 | protected OutputReflexive.Match arrayToMatchMutable(final Object[] match) { | ||
425 | try { | ||
426 | return OutputReflexive.Match.newMutableMatch((Turnout) match[POSITION_T]); | ||
427 | } catch(ClassCastException e) { | ||
428 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
429 | return null; | ||
430 | } | ||
431 | } | ||
432 | |||
433 | /** | ||
434 | * @return the singleton instance of the query specification of this pattern | ||
435 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
436 | * | ||
437 | */ | ||
438 | public static IQuerySpecification<OutputReflexive.Matcher> querySpecification() { | ||
439 | return OutputReflexive.instance(); | ||
440 | } | ||
441 | } | ||
442 | |||
443 | private OutputReflexive() { | ||
444 | super(GeneratedPQuery.INSTANCE); | ||
445 | } | ||
446 | |||
447 | /** | ||
448 | * @return the singleton instance of the query specification | ||
449 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
450 | * | ||
451 | */ | ||
452 | public static OutputReflexive instance() { | ||
453 | try{ | ||
454 | return LazyHolder.INSTANCE; | ||
455 | } catch (ExceptionInInitializerError err) { | ||
456 | throw processInitializerError(err); | ||
457 | } | ||
458 | } | ||
459 | |||
460 | @Override | ||
461 | protected OutputReflexive.Matcher instantiate(final ViatraQueryEngine engine) { | ||
462 | return OutputReflexive.Matcher.on(engine); | ||
463 | } | ||
464 | |||
465 | @Override | ||
466 | public OutputReflexive.Matcher instantiate() { | ||
467 | return OutputReflexive.Matcher.create(); | ||
468 | } | ||
469 | |||
470 | @Override | ||
471 | public OutputReflexive.Match newEmptyMatch() { | ||
472 | return OutputReflexive.Match.newEmptyMatch(); | ||
473 | } | ||
474 | |||
475 | @Override | ||
476 | public OutputReflexive.Match newMatch(final Object... parameters) { | ||
477 | return OutputReflexive.Match.newMatch((modes3.Turnout) parameters[0]); | ||
478 | } | ||
479 | |||
480 | /** | ||
481 | * Inner class allowing the singleton instance of {@link OutputReflexive} to be created | ||
482 | * <b>not</b> at the class load time of the outer class, | ||
483 | * but rather at the first call to {@link OutputReflexive#instance()}. | ||
484 | * | ||
485 | * <p> This workaround is required e.g. to support recursion. | ||
486 | * | ||
487 | */ | ||
488 | private static class LazyHolder { | ||
489 | private static final OutputReflexive INSTANCE = new OutputReflexive(); | ||
490 | |||
491 | /** | ||
492 | * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned. | ||
493 | * This initialization order is required to support indirect recursion. | ||
494 | * | ||
495 | * <p> The static initializer is defined using a helper field to work around limitations of the code generator. | ||
496 | * | ||
497 | */ | ||
498 | private static final Object STATIC_INITIALIZER = ensureInitialized(); | ||
499 | |||
500 | public static Object ensureInitialized() { | ||
501 | INSTANCE.ensureInitializedInternal(); | ||
502 | return null; | ||
503 | } | ||
504 | } | ||
505 | |||
506 | private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { | ||
507 | private static final OutputReflexive.GeneratedPQuery INSTANCE = new GeneratedPQuery(); | ||
508 | |||
509 | private final PParameter parameter_T = new PParameter("T", "modes3.Turnout", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Turnout")), PParameterDirection.INOUT); | ||
510 | |||
511 | private final List<PParameter> parameters = Arrays.asList(parameter_T); | ||
512 | |||
513 | private GeneratedPQuery() { | ||
514 | super(PVisibility.PUBLIC); | ||
515 | } | ||
516 | |||
517 | @Override | ||
518 | public String getFullyQualifiedName() { | ||
519 | return "modes3.queries.outputReflexive"; | ||
520 | } | ||
521 | |||
522 | @Override | ||
523 | public List<String> getParameterNames() { | ||
524 | return Arrays.asList("T"); | ||
525 | } | ||
526 | |||
527 | @Override | ||
528 | public List<PParameter> getParameters() { | ||
529 | return parameters; | ||
530 | } | ||
531 | |||
532 | @Override | ||
533 | public Set<PBody> doGetContainedBodies() { | ||
534 | setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); | ||
535 | Set<PBody> bodies = new LinkedHashSet<>(); | ||
536 | { | ||
537 | PBody body = new PBody(this); | ||
538 | PVariable var_T = body.getOrCreateVariableByName("T"); | ||
539 | new TypeConstraint(body, Tuples.flatTupleOf(var_T), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Turnout"))); | ||
540 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
541 | new ExportedParameter(body, var_T, parameter_T) | ||
542 | )); | ||
543 | // find turnoutOutput(T, T) | ||
544 | new PositivePatternCall(body, Tuples.flatTupleOf(var_T, var_T), TurnoutOutput.instance().getInternalQueryRepresentation()); | ||
545 | bodies.add(body); | ||
546 | } | ||
547 | { | ||
548 | PAnnotation annotation = new PAnnotation("Constraint"); | ||
549 | annotation.addAttribute("message", "outputReflexive"); | ||
550 | annotation.addAttribute("severity", "error"); | ||
551 | annotation.addAttribute("key", Arrays.asList(new Object[] { | ||
552 | new ParameterReference("T") | ||
553 | })); | ||
554 | addAnnotation(annotation); | ||
555 | } | ||
556 | return bodies; | ||
557 | } | ||
558 | } | ||
559 | } | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/Reachable.java b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/Reachable.java new file mode 100644 index 00000000..93d43c21 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/Reachable.java | |||
@@ -0,0 +1,719 @@ | |||
1 | /** | ||
2 | * Generated from platform:/resource/ca.mcgill.rtgmrt.example.modes3/src/modes3/queries/Modes3Queries.vql | ||
3 | */ | ||
4 | package modes3.queries; | ||
5 | |||
6 | import java.util.Arrays; | ||
7 | import java.util.Collection; | ||
8 | import java.util.LinkedHashSet; | ||
9 | import java.util.List; | ||
10 | import java.util.Objects; | ||
11 | import java.util.Optional; | ||
12 | import java.util.Set; | ||
13 | import java.util.function.Consumer; | ||
14 | import java.util.stream.Collectors; | ||
15 | import java.util.stream.Stream; | ||
16 | import modes3.Segment; | ||
17 | import modes3.queries.Adjacent; | ||
18 | import org.apache.log4j.Logger; | ||
19 | import org.eclipse.emf.ecore.EClass; | ||
20 | import org.eclipse.viatra.query.runtime.api.IPatternMatch; | ||
21 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification; | ||
22 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; | ||
23 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; | ||
24 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; | ||
25 | import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; | ||
26 | import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; | ||
27 | import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; | ||
28 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
29 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | ||
30 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | ||
31 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; | ||
32 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
33 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.BinaryTransitiveClosure; | ||
34 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
35 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | ||
36 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; | ||
37 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | ||
38 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; | ||
39 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
40 | import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; | ||
41 | |||
42 | /** | ||
43 | * A pattern-specific query specification that can instantiate Matcher in a type-safe way. | ||
44 | * | ||
45 | * <p>Original source: | ||
46 | * <code><pre> | ||
47 | * pattern reachable(S1 : Segment, S2 : Segment) { | ||
48 | * S1 == S2; | ||
49 | * } or { | ||
50 | * find adjacent+(S1, S2); | ||
51 | * } | ||
52 | * </pre></code> | ||
53 | * | ||
54 | * @see Matcher | ||
55 | * @see Match | ||
56 | * | ||
57 | */ | ||
58 | @SuppressWarnings("all") | ||
59 | public final class Reachable extends BaseGeneratedEMFQuerySpecification<Reachable.Matcher> { | ||
60 | /** | ||
61 | * Pattern-specific match representation of the modes3.queries.reachable pattern, | ||
62 | * to be used in conjunction with {@link Matcher}. | ||
63 | * | ||
64 | * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. | ||
65 | * Each instance is a (possibly partial) substitution of pattern parameters, | ||
66 | * usable to represent a match of the pattern in the result of a query, | ||
67 | * or to specify the bound (fixed) input parameters when issuing a query. | ||
68 | * | ||
69 | * @see Matcher | ||
70 | * | ||
71 | */ | ||
72 | public static abstract class Match extends BasePatternMatch { | ||
73 | private Segment fS1; | ||
74 | |||
75 | private Segment fS2; | ||
76 | |||
77 | private static List<String> parameterNames = makeImmutableList("S1", "S2"); | ||
78 | |||
79 | private Match(final Segment pS1, final Segment pS2) { | ||
80 | this.fS1 = pS1; | ||
81 | this.fS2 = pS2; | ||
82 | } | ||
83 | |||
84 | @Override | ||
85 | public Object get(final String parameterName) { | ||
86 | switch(parameterName) { | ||
87 | case "S1": return this.fS1; | ||
88 | case "S2": return this.fS2; | ||
89 | default: return null; | ||
90 | } | ||
91 | } | ||
92 | |||
93 | @Override | ||
94 | public Object get(final int index) { | ||
95 | switch(index) { | ||
96 | case 0: return this.fS1; | ||
97 | case 1: return this.fS2; | ||
98 | default: return null; | ||
99 | } | ||
100 | } | ||
101 | |||
102 | public Segment getS1() { | ||
103 | return this.fS1; | ||
104 | } | ||
105 | |||
106 | public Segment getS2() { | ||
107 | return this.fS2; | ||
108 | } | ||
109 | |||
110 | @Override | ||
111 | public boolean set(final String parameterName, final Object newValue) { | ||
112 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
113 | if ("S1".equals(parameterName) ) { | ||
114 | this.fS1 = (Segment) newValue; | ||
115 | return true; | ||
116 | } | ||
117 | if ("S2".equals(parameterName) ) { | ||
118 | this.fS2 = (Segment) newValue; | ||
119 | return true; | ||
120 | } | ||
121 | return false; | ||
122 | } | ||
123 | |||
124 | public void setS1(final Segment pS1) { | ||
125 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
126 | this.fS1 = pS1; | ||
127 | } | ||
128 | |||
129 | public void setS2(final Segment pS2) { | ||
130 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
131 | this.fS2 = pS2; | ||
132 | } | ||
133 | |||
134 | @Override | ||
135 | public String patternName() { | ||
136 | return "modes3.queries.reachable"; | ||
137 | } | ||
138 | |||
139 | @Override | ||
140 | public List<String> parameterNames() { | ||
141 | return Reachable.Match.parameterNames; | ||
142 | } | ||
143 | |||
144 | @Override | ||
145 | public Object[] toArray() { | ||
146 | return new Object[]{fS1, fS2}; | ||
147 | } | ||
148 | |||
149 | @Override | ||
150 | public Reachable.Match toImmutable() { | ||
151 | return isMutable() ? newMatch(fS1, fS2) : this; | ||
152 | } | ||
153 | |||
154 | @Override | ||
155 | public String prettyPrint() { | ||
156 | StringBuilder result = new StringBuilder(); | ||
157 | result.append("\"S1\"=" + prettyPrintValue(fS1) + ", "); | ||
158 | result.append("\"S2\"=" + prettyPrintValue(fS2)); | ||
159 | return result.toString(); | ||
160 | } | ||
161 | |||
162 | @Override | ||
163 | public int hashCode() { | ||
164 | return Objects.hash(fS1, fS2); | ||
165 | } | ||
166 | |||
167 | @Override | ||
168 | public boolean equals(final Object obj) { | ||
169 | if (this == obj) | ||
170 | return true; | ||
171 | if (obj == null) { | ||
172 | return false; | ||
173 | } | ||
174 | if ((obj instanceof Reachable.Match)) { | ||
175 | Reachable.Match other = (Reachable.Match) obj; | ||
176 | return Objects.equals(fS1, other.fS1) && Objects.equals(fS2, other.fS2); | ||
177 | } else { | ||
178 | // this should be infrequent | ||
179 | if (!(obj instanceof IPatternMatch)) { | ||
180 | return false; | ||
181 | } | ||
182 | IPatternMatch otherSig = (IPatternMatch) obj; | ||
183 | return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); | ||
184 | } | ||
185 | } | ||
186 | |||
187 | @Override | ||
188 | public Reachable specification() { | ||
189 | return Reachable.instance(); | ||
190 | } | ||
191 | |||
192 | /** | ||
193 | * Returns an empty, mutable match. | ||
194 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
195 | * | ||
196 | * @return the empty match. | ||
197 | * | ||
198 | */ | ||
199 | public static Reachable.Match newEmptyMatch() { | ||
200 | return new Mutable(null, null); | ||
201 | } | ||
202 | |||
203 | /** | ||
204 | * Returns a mutable (partial) match. | ||
205 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
206 | * | ||
207 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
208 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
209 | * @return the new, mutable (partial) match object. | ||
210 | * | ||
211 | */ | ||
212 | public static Reachable.Match newMutableMatch(final Segment pS1, final Segment pS2) { | ||
213 | return new Mutable(pS1, pS2); | ||
214 | } | ||
215 | |||
216 | /** | ||
217 | * Returns a new (partial) match. | ||
218 | * This can be used e.g. to call the matcher with a partial match. | ||
219 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
220 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
221 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
222 | * @return the (partial) match object. | ||
223 | * | ||
224 | */ | ||
225 | public static Reachable.Match newMatch(final Segment pS1, final Segment pS2) { | ||
226 | return new Immutable(pS1, pS2); | ||
227 | } | ||
228 | |||
229 | private static final class Mutable extends Reachable.Match { | ||
230 | Mutable(final Segment pS1, final Segment pS2) { | ||
231 | super(pS1, pS2); | ||
232 | } | ||
233 | |||
234 | @Override | ||
235 | public boolean isMutable() { | ||
236 | return true; | ||
237 | } | ||
238 | } | ||
239 | |||
240 | private static final class Immutable extends Reachable.Match { | ||
241 | Immutable(final Segment pS1, final Segment pS2) { | ||
242 | super(pS1, pS2); | ||
243 | } | ||
244 | |||
245 | @Override | ||
246 | public boolean isMutable() { | ||
247 | return false; | ||
248 | } | ||
249 | } | ||
250 | } | ||
251 | |||
252 | /** | ||
253 | * Generated pattern matcher API of the modes3.queries.reachable pattern, | ||
254 | * providing pattern-specific query methods. | ||
255 | * | ||
256 | * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, | ||
257 | * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. | ||
258 | * | ||
259 | * <p>Matches of the pattern will be represented as {@link Match}. | ||
260 | * | ||
261 | * <p>Original source: | ||
262 | * <code><pre> | ||
263 | * pattern reachable(S1 : Segment, S2 : Segment) { | ||
264 | * S1 == S2; | ||
265 | * } or { | ||
266 | * find adjacent+(S1, S2); | ||
267 | * } | ||
268 | * </pre></code> | ||
269 | * | ||
270 | * @see Match | ||
271 | * @see Reachable | ||
272 | * | ||
273 | */ | ||
274 | public static class Matcher extends BaseMatcher<Reachable.Match> { | ||
275 | /** | ||
276 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
277 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
278 | * | ||
279 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
280 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
281 | * | ||
282 | */ | ||
283 | public static Reachable.Matcher on(final ViatraQueryEngine engine) { | ||
284 | // check if matcher already exists | ||
285 | Matcher matcher = engine.getExistingMatcher(querySpecification()); | ||
286 | if (matcher == null) { | ||
287 | matcher = (Matcher)engine.getMatcher(querySpecification()); | ||
288 | } | ||
289 | return matcher; | ||
290 | } | ||
291 | |||
292 | /** | ||
293 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
294 | * @return an initialized matcher | ||
295 | * @noreference This method is for internal matcher initialization by the framework, do not call it manually. | ||
296 | * | ||
297 | */ | ||
298 | public static Reachable.Matcher create() { | ||
299 | return new Matcher(); | ||
300 | } | ||
301 | |||
302 | private static final int POSITION_S1 = 0; | ||
303 | |||
304 | private static final int POSITION_S2 = 1; | ||
305 | |||
306 | private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Reachable.Matcher.class); | ||
307 | |||
308 | /** | ||
309 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
310 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
311 | * | ||
312 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
313 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
314 | * | ||
315 | */ | ||
316 | private Matcher() { | ||
317 | super(querySpecification()); | ||
318 | } | ||
319 | |||
320 | /** | ||
321 | * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. | ||
322 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
323 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
324 | * @return matches represented as a Match object. | ||
325 | * | ||
326 | */ | ||
327 | public Collection<Reachable.Match> getAllMatches(final Segment pS1, final Segment pS2) { | ||
328 | return rawStreamAllMatches(new Object[]{pS1, pS2}).collect(Collectors.toSet()); | ||
329 | } | ||
330 | |||
331 | /** | ||
332 | * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. | ||
333 | * </p> | ||
334 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
335 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
336 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
337 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
338 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
339 | * @return a stream of matches represented as a Match object. | ||
340 | * | ||
341 | */ | ||
342 | public Stream<Reachable.Match> streamAllMatches(final Segment pS1, final Segment pS2) { | ||
343 | return rawStreamAllMatches(new Object[]{pS1, pS2}); | ||
344 | } | ||
345 | |||
346 | /** | ||
347 | * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
348 | * Neither determinism nor randomness of selection is guaranteed. | ||
349 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
350 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
351 | * @return a match represented as a Match object, or null if no match is found. | ||
352 | * | ||
353 | */ | ||
354 | public Optional<Reachable.Match> getOneArbitraryMatch(final Segment pS1, final Segment pS2) { | ||
355 | return rawGetOneArbitraryMatch(new Object[]{pS1, pS2}); | ||
356 | } | ||
357 | |||
358 | /** | ||
359 | * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, | ||
360 | * under any possible substitution of the unspecified parameters (if any). | ||
361 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
362 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
363 | * @return true if the input is a valid (partial) match of the pattern. | ||
364 | * | ||
365 | */ | ||
366 | public boolean hasMatch(final Segment pS1, final Segment pS2) { | ||
367 | return rawHasMatch(new Object[]{pS1, pS2}); | ||
368 | } | ||
369 | |||
370 | /** | ||
371 | * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. | ||
372 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
373 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
374 | * @return the number of pattern matches found. | ||
375 | * | ||
376 | */ | ||
377 | public int countMatches(final Segment pS1, final Segment pS2) { | ||
378 | return rawCountMatches(new Object[]{pS1, pS2}); | ||
379 | } | ||
380 | |||
381 | /** | ||
382 | * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
383 | * Neither determinism nor randomness of selection is guaranteed. | ||
384 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
385 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
386 | * @param processor the action that will process the selected match. | ||
387 | * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked | ||
388 | * | ||
389 | */ | ||
390 | public boolean forOneArbitraryMatch(final Segment pS1, final Segment pS2, final Consumer<? super Reachable.Match> processor) { | ||
391 | return rawForOneArbitraryMatch(new Object[]{pS1, pS2}, processor); | ||
392 | } | ||
393 | |||
394 | /** | ||
395 | * Returns a new (partial) match. | ||
396 | * This can be used e.g. to call the matcher with a partial match. | ||
397 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
398 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
399 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
400 | * @return the (partial) match object. | ||
401 | * | ||
402 | */ | ||
403 | public Reachable.Match newMatch(final Segment pS1, final Segment pS2) { | ||
404 | return Reachable.Match.newMatch(pS1, pS2); | ||
405 | } | ||
406 | |||
407 | /** | ||
408 | * Retrieve the set of values that occur in matches for S1. | ||
409 | * @return the Set of all values or empty set if there are no matches | ||
410 | * | ||
411 | */ | ||
412 | protected Stream<Segment> rawStreamAllValuesOfS1(final Object[] parameters) { | ||
413 | return rawStreamAllValues(POSITION_S1, parameters).map(Segment.class::cast); | ||
414 | } | ||
415 | |||
416 | /** | ||
417 | * Retrieve the set of values that occur in matches for S1. | ||
418 | * @return the Set of all values or empty set if there are no matches | ||
419 | * | ||
420 | */ | ||
421 | public Set<Segment> getAllValuesOfS1() { | ||
422 | return rawStreamAllValuesOfS1(emptyArray()).collect(Collectors.toSet()); | ||
423 | } | ||
424 | |||
425 | /** | ||
426 | * Retrieve the set of values that occur in matches for S1. | ||
427 | * @return the Set of all values or empty set if there are no matches | ||
428 | * | ||
429 | */ | ||
430 | public Stream<Segment> streamAllValuesOfS1() { | ||
431 | return rawStreamAllValuesOfS1(emptyArray()); | ||
432 | } | ||
433 | |||
434 | /** | ||
435 | * Retrieve the set of values that occur in matches for S1. | ||
436 | * </p> | ||
437 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
438 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
439 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
440 | * | ||
441 | * @return the Stream of all values or empty set if there are no matches | ||
442 | * | ||
443 | */ | ||
444 | public Stream<Segment> streamAllValuesOfS1(final Reachable.Match partialMatch) { | ||
445 | return rawStreamAllValuesOfS1(partialMatch.toArray()); | ||
446 | } | ||
447 | |||
448 | /** | ||
449 | * Retrieve the set of values that occur in matches for S1. | ||
450 | * </p> | ||
451 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
452 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
453 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
454 | * | ||
455 | * @return the Stream of all values or empty set if there are no matches | ||
456 | * | ||
457 | */ | ||
458 | public Stream<Segment> streamAllValuesOfS1(final Segment pS2) { | ||
459 | return rawStreamAllValuesOfS1(new Object[]{null, pS2}); | ||
460 | } | ||
461 | |||
462 | /** | ||
463 | * Retrieve the set of values that occur in matches for S1. | ||
464 | * @return the Set of all values or empty set if there are no matches | ||
465 | * | ||
466 | */ | ||
467 | public Set<Segment> getAllValuesOfS1(final Reachable.Match partialMatch) { | ||
468 | return rawStreamAllValuesOfS1(partialMatch.toArray()).collect(Collectors.toSet()); | ||
469 | } | ||
470 | |||
471 | /** | ||
472 | * Retrieve the set of values that occur in matches for S1. | ||
473 | * @return the Set of all values or empty set if there are no matches | ||
474 | * | ||
475 | */ | ||
476 | public Set<Segment> getAllValuesOfS1(final Segment pS2) { | ||
477 | return rawStreamAllValuesOfS1(new Object[]{null, pS2}).collect(Collectors.toSet()); | ||
478 | } | ||
479 | |||
480 | /** | ||
481 | * Retrieve the set of values that occur in matches for S2. | ||
482 | * @return the Set of all values or empty set if there are no matches | ||
483 | * | ||
484 | */ | ||
485 | protected Stream<Segment> rawStreamAllValuesOfS2(final Object[] parameters) { | ||
486 | return rawStreamAllValues(POSITION_S2, parameters).map(Segment.class::cast); | ||
487 | } | ||
488 | |||
489 | /** | ||
490 | * Retrieve the set of values that occur in matches for S2. | ||
491 | * @return the Set of all values or empty set if there are no matches | ||
492 | * | ||
493 | */ | ||
494 | public Set<Segment> getAllValuesOfS2() { | ||
495 | return rawStreamAllValuesOfS2(emptyArray()).collect(Collectors.toSet()); | ||
496 | } | ||
497 | |||
498 | /** | ||
499 | * Retrieve the set of values that occur in matches for S2. | ||
500 | * @return the Set of all values or empty set if there are no matches | ||
501 | * | ||
502 | */ | ||
503 | public Stream<Segment> streamAllValuesOfS2() { | ||
504 | return rawStreamAllValuesOfS2(emptyArray()); | ||
505 | } | ||
506 | |||
507 | /** | ||
508 | * Retrieve the set of values that occur in matches for S2. | ||
509 | * </p> | ||
510 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
511 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
512 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
513 | * | ||
514 | * @return the Stream of all values or empty set if there are no matches | ||
515 | * | ||
516 | */ | ||
517 | public Stream<Segment> streamAllValuesOfS2(final Reachable.Match partialMatch) { | ||
518 | return rawStreamAllValuesOfS2(partialMatch.toArray()); | ||
519 | } | ||
520 | |||
521 | /** | ||
522 | * Retrieve the set of values that occur in matches for S2. | ||
523 | * </p> | ||
524 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
525 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
526 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
527 | * | ||
528 | * @return the Stream of all values or empty set if there are no matches | ||
529 | * | ||
530 | */ | ||
531 | public Stream<Segment> streamAllValuesOfS2(final Segment pS1) { | ||
532 | return rawStreamAllValuesOfS2(new Object[]{pS1, null}); | ||
533 | } | ||
534 | |||
535 | /** | ||
536 | * Retrieve the set of values that occur in matches for S2. | ||
537 | * @return the Set of all values or empty set if there are no matches | ||
538 | * | ||
539 | */ | ||
540 | public Set<Segment> getAllValuesOfS2(final Reachable.Match partialMatch) { | ||
541 | return rawStreamAllValuesOfS2(partialMatch.toArray()).collect(Collectors.toSet()); | ||
542 | } | ||
543 | |||
544 | /** | ||
545 | * Retrieve the set of values that occur in matches for S2. | ||
546 | * @return the Set of all values or empty set if there are no matches | ||
547 | * | ||
548 | */ | ||
549 | public Set<Segment> getAllValuesOfS2(final Segment pS1) { | ||
550 | return rawStreamAllValuesOfS2(new Object[]{pS1, null}).collect(Collectors.toSet()); | ||
551 | } | ||
552 | |||
553 | @Override | ||
554 | protected Reachable.Match tupleToMatch(final Tuple t) { | ||
555 | try { | ||
556 | return Reachable.Match.newMatch((Segment) t.get(POSITION_S1), (Segment) t.get(POSITION_S2)); | ||
557 | } catch(ClassCastException e) { | ||
558 | LOGGER.error("Element(s) in tuple not properly typed!",e); | ||
559 | return null; | ||
560 | } | ||
561 | } | ||
562 | |||
563 | @Override | ||
564 | protected Reachable.Match arrayToMatch(final Object[] match) { | ||
565 | try { | ||
566 | return Reachable.Match.newMatch((Segment) match[POSITION_S1], (Segment) match[POSITION_S2]); | ||
567 | } catch(ClassCastException e) { | ||
568 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
569 | return null; | ||
570 | } | ||
571 | } | ||
572 | |||
573 | @Override | ||
574 | protected Reachable.Match arrayToMatchMutable(final Object[] match) { | ||
575 | try { | ||
576 | return Reachable.Match.newMutableMatch((Segment) match[POSITION_S1], (Segment) match[POSITION_S2]); | ||
577 | } catch(ClassCastException e) { | ||
578 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
579 | return null; | ||
580 | } | ||
581 | } | ||
582 | |||
583 | /** | ||
584 | * @return the singleton instance of the query specification of this pattern | ||
585 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
586 | * | ||
587 | */ | ||
588 | public static IQuerySpecification<Reachable.Matcher> querySpecification() { | ||
589 | return Reachable.instance(); | ||
590 | } | ||
591 | } | ||
592 | |||
593 | private Reachable() { | ||
594 | super(GeneratedPQuery.INSTANCE); | ||
595 | } | ||
596 | |||
597 | /** | ||
598 | * @return the singleton instance of the query specification | ||
599 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
600 | * | ||
601 | */ | ||
602 | public static Reachable instance() { | ||
603 | try{ | ||
604 | return LazyHolder.INSTANCE; | ||
605 | } catch (ExceptionInInitializerError err) { | ||
606 | throw processInitializerError(err); | ||
607 | } | ||
608 | } | ||
609 | |||
610 | @Override | ||
611 | protected Reachable.Matcher instantiate(final ViatraQueryEngine engine) { | ||
612 | return Reachable.Matcher.on(engine); | ||
613 | } | ||
614 | |||
615 | @Override | ||
616 | public Reachable.Matcher instantiate() { | ||
617 | return Reachable.Matcher.create(); | ||
618 | } | ||
619 | |||
620 | @Override | ||
621 | public Reachable.Match newEmptyMatch() { | ||
622 | return Reachable.Match.newEmptyMatch(); | ||
623 | } | ||
624 | |||
625 | @Override | ||
626 | public Reachable.Match newMatch(final Object... parameters) { | ||
627 | return Reachable.Match.newMatch((modes3.Segment) parameters[0], (modes3.Segment) parameters[1]); | ||
628 | } | ||
629 | |||
630 | /** | ||
631 | * Inner class allowing the singleton instance of {@link Reachable} to be created | ||
632 | * <b>not</b> at the class load time of the outer class, | ||
633 | * but rather at the first call to {@link Reachable#instance()}. | ||
634 | * | ||
635 | * <p> This workaround is required e.g. to support recursion. | ||
636 | * | ||
637 | */ | ||
638 | private static class LazyHolder { | ||
639 | private static final Reachable INSTANCE = new Reachable(); | ||
640 | |||
641 | /** | ||
642 | * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned. | ||
643 | * This initialization order is required to support indirect recursion. | ||
644 | * | ||
645 | * <p> The static initializer is defined using a helper field to work around limitations of the code generator. | ||
646 | * | ||
647 | */ | ||
648 | private static final Object STATIC_INITIALIZER = ensureInitialized(); | ||
649 | |||
650 | public static Object ensureInitialized() { | ||
651 | INSTANCE.ensureInitializedInternal(); | ||
652 | return null; | ||
653 | } | ||
654 | } | ||
655 | |||
656 | private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { | ||
657 | private static final Reachable.GeneratedPQuery INSTANCE = new GeneratedPQuery(); | ||
658 | |||
659 | private final PParameter parameter_S1 = new PParameter("S1", "modes3.Segment", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Segment")), PParameterDirection.INOUT); | ||
660 | |||
661 | private final PParameter parameter_S2 = new PParameter("S2", "modes3.Segment", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Segment")), PParameterDirection.INOUT); | ||
662 | |||
663 | private final List<PParameter> parameters = Arrays.asList(parameter_S1, parameter_S2); | ||
664 | |||
665 | private GeneratedPQuery() { | ||
666 | super(PVisibility.PUBLIC); | ||
667 | } | ||
668 | |||
669 | @Override | ||
670 | public String getFullyQualifiedName() { | ||
671 | return "modes3.queries.reachable"; | ||
672 | } | ||
673 | |||
674 | @Override | ||
675 | public List<String> getParameterNames() { | ||
676 | return Arrays.asList("S1","S2"); | ||
677 | } | ||
678 | |||
679 | @Override | ||
680 | public List<PParameter> getParameters() { | ||
681 | return parameters; | ||
682 | } | ||
683 | |||
684 | @Override | ||
685 | public Set<PBody> doGetContainedBodies() { | ||
686 | setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); | ||
687 | Set<PBody> bodies = new LinkedHashSet<>(); | ||
688 | { | ||
689 | PBody body = new PBody(this); | ||
690 | PVariable var_S1 = body.getOrCreateVariableByName("S1"); | ||
691 | PVariable var_S2 = body.getOrCreateVariableByName("S2"); | ||
692 | new TypeConstraint(body, Tuples.flatTupleOf(var_S1), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
693 | new TypeConstraint(body, Tuples.flatTupleOf(var_S2), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
694 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
695 | new ExportedParameter(body, var_S1, parameter_S1), | ||
696 | new ExportedParameter(body, var_S2, parameter_S2) | ||
697 | )); | ||
698 | // S1 == S2 | ||
699 | new Equality(body, var_S1, var_S2); | ||
700 | bodies.add(body); | ||
701 | } | ||
702 | { | ||
703 | PBody body = new PBody(this); | ||
704 | PVariable var_S1 = body.getOrCreateVariableByName("S1"); | ||
705 | PVariable var_S2 = body.getOrCreateVariableByName("S2"); | ||
706 | new TypeConstraint(body, Tuples.flatTupleOf(var_S1), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
707 | new TypeConstraint(body, Tuples.flatTupleOf(var_S2), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
708 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
709 | new ExportedParameter(body, var_S1, parameter_S1), | ||
710 | new ExportedParameter(body, var_S2, parameter_S2) | ||
711 | )); | ||
712 | // find adjacent+(S1, S2) | ||
713 | new BinaryTransitiveClosure(body, Tuples.flatTupleOf(var_S1, var_S2), Adjacent.instance().getInternalQueryRepresentation()); | ||
714 | bodies.add(body); | ||
715 | } | ||
716 | return bodies; | ||
717 | } | ||
718 | } | ||
719 | } | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/TooFewInputsOfTurnout.java b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/TooFewInputsOfTurnout.java new file mode 100644 index 00000000..088640ca --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/TooFewInputsOfTurnout.java | |||
@@ -0,0 +1,559 @@ | |||
1 | /** | ||
2 | * Generated from platform:/resource/ca.mcgill.rtgmrt.example.modes3/src/modes3/queries/Modes3Queries.vql | ||
3 | */ | ||
4 | package modes3.queries; | ||
5 | |||
6 | import java.util.Arrays; | ||
7 | import java.util.Collection; | ||
8 | import java.util.LinkedHashSet; | ||
9 | import java.util.List; | ||
10 | import java.util.Objects; | ||
11 | import java.util.Optional; | ||
12 | import java.util.Set; | ||
13 | import java.util.function.Consumer; | ||
14 | import java.util.stream.Collectors; | ||
15 | import java.util.stream.Stream; | ||
16 | import modes3.Turnout; | ||
17 | import modes3.queries.InputsOfTurnout; | ||
18 | import org.apache.log4j.Logger; | ||
19 | import org.eclipse.emf.ecore.EClass; | ||
20 | import org.eclipse.viatra.query.runtime.api.IPatternMatch; | ||
21 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification; | ||
22 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; | ||
23 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; | ||
24 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; | ||
25 | import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; | ||
26 | import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; | ||
27 | import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; | ||
28 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
29 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | ||
30 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | ||
31 | import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation; | ||
32 | import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference; | ||
33 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
34 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.NegativePatternCall; | ||
35 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
36 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | ||
37 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; | ||
38 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | ||
39 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; | ||
40 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
41 | import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; | ||
42 | |||
43 | /** | ||
44 | * A pattern-specific query specification that can instantiate Matcher in a type-safe way. | ||
45 | * | ||
46 | * <p>Original source: | ||
47 | * <code><pre> | ||
48 | * {@literal @}Constraint(message = "tooFewInputsOfTurnout", severity = "error", key = { T }) | ||
49 | * pattern tooFewInputsOfTurnout(T : Turnout) { | ||
50 | * neg find inputsOfTurnout(T); | ||
51 | * } | ||
52 | * </pre></code> | ||
53 | * | ||
54 | * @see Matcher | ||
55 | * @see Match | ||
56 | * | ||
57 | */ | ||
58 | @SuppressWarnings("all") | ||
59 | public final class TooFewInputsOfTurnout extends BaseGeneratedEMFQuerySpecification<TooFewInputsOfTurnout.Matcher> { | ||
60 | /** | ||
61 | * Pattern-specific match representation of the modes3.queries.tooFewInputsOfTurnout pattern, | ||
62 | * to be used in conjunction with {@link Matcher}. | ||
63 | * | ||
64 | * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. | ||
65 | * Each instance is a (possibly partial) substitution of pattern parameters, | ||
66 | * usable to represent a match of the pattern in the result of a query, | ||
67 | * or to specify the bound (fixed) input parameters when issuing a query. | ||
68 | * | ||
69 | * @see Matcher | ||
70 | * | ||
71 | */ | ||
72 | public static abstract class Match extends BasePatternMatch { | ||
73 | private Turnout fT; | ||
74 | |||
75 | private static List<String> parameterNames = makeImmutableList("T"); | ||
76 | |||
77 | private Match(final Turnout pT) { | ||
78 | this.fT = pT; | ||
79 | } | ||
80 | |||
81 | @Override | ||
82 | public Object get(final String parameterName) { | ||
83 | switch(parameterName) { | ||
84 | case "T": return this.fT; | ||
85 | default: return null; | ||
86 | } | ||
87 | } | ||
88 | |||
89 | @Override | ||
90 | public Object get(final int index) { | ||
91 | switch(index) { | ||
92 | case 0: return this.fT; | ||
93 | default: return null; | ||
94 | } | ||
95 | } | ||
96 | |||
97 | public Turnout getT() { | ||
98 | return this.fT; | ||
99 | } | ||
100 | |||
101 | @Override | ||
102 | public boolean set(final String parameterName, final Object newValue) { | ||
103 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
104 | if ("T".equals(parameterName) ) { | ||
105 | this.fT = (Turnout) newValue; | ||
106 | return true; | ||
107 | } | ||
108 | return false; | ||
109 | } | ||
110 | |||
111 | public void setT(final Turnout pT) { | ||
112 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
113 | this.fT = pT; | ||
114 | } | ||
115 | |||
116 | @Override | ||
117 | public String patternName() { | ||
118 | return "modes3.queries.tooFewInputsOfTurnout"; | ||
119 | } | ||
120 | |||
121 | @Override | ||
122 | public List<String> parameterNames() { | ||
123 | return TooFewInputsOfTurnout.Match.parameterNames; | ||
124 | } | ||
125 | |||
126 | @Override | ||
127 | public Object[] toArray() { | ||
128 | return new Object[]{fT}; | ||
129 | } | ||
130 | |||
131 | @Override | ||
132 | public TooFewInputsOfTurnout.Match toImmutable() { | ||
133 | return isMutable() ? newMatch(fT) : this; | ||
134 | } | ||
135 | |||
136 | @Override | ||
137 | public String prettyPrint() { | ||
138 | StringBuilder result = new StringBuilder(); | ||
139 | result.append("\"T\"=" + prettyPrintValue(fT)); | ||
140 | return result.toString(); | ||
141 | } | ||
142 | |||
143 | @Override | ||
144 | public int hashCode() { | ||
145 | return Objects.hash(fT); | ||
146 | } | ||
147 | |||
148 | @Override | ||
149 | public boolean equals(final Object obj) { | ||
150 | if (this == obj) | ||
151 | return true; | ||
152 | if (obj == null) { | ||
153 | return false; | ||
154 | } | ||
155 | if ((obj instanceof TooFewInputsOfTurnout.Match)) { | ||
156 | TooFewInputsOfTurnout.Match other = (TooFewInputsOfTurnout.Match) obj; | ||
157 | return Objects.equals(fT, other.fT); | ||
158 | } else { | ||
159 | // this should be infrequent | ||
160 | if (!(obj instanceof IPatternMatch)) { | ||
161 | return false; | ||
162 | } | ||
163 | IPatternMatch otherSig = (IPatternMatch) obj; | ||
164 | return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); | ||
165 | } | ||
166 | } | ||
167 | |||
168 | @Override | ||
169 | public TooFewInputsOfTurnout specification() { | ||
170 | return TooFewInputsOfTurnout.instance(); | ||
171 | } | ||
172 | |||
173 | /** | ||
174 | * Returns an empty, mutable match. | ||
175 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
176 | * | ||
177 | * @return the empty match. | ||
178 | * | ||
179 | */ | ||
180 | public static TooFewInputsOfTurnout.Match newEmptyMatch() { | ||
181 | return new Mutable(null); | ||
182 | } | ||
183 | |||
184 | /** | ||
185 | * Returns a mutable (partial) match. | ||
186 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
187 | * | ||
188 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
189 | * @return the new, mutable (partial) match object. | ||
190 | * | ||
191 | */ | ||
192 | public static TooFewInputsOfTurnout.Match newMutableMatch(final Turnout pT) { | ||
193 | return new Mutable(pT); | ||
194 | } | ||
195 | |||
196 | /** | ||
197 | * Returns a new (partial) match. | ||
198 | * This can be used e.g. to call the matcher with a partial match. | ||
199 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
200 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
201 | * @return the (partial) match object. | ||
202 | * | ||
203 | */ | ||
204 | public static TooFewInputsOfTurnout.Match newMatch(final Turnout pT) { | ||
205 | return new Immutable(pT); | ||
206 | } | ||
207 | |||
208 | private static final class Mutable extends TooFewInputsOfTurnout.Match { | ||
209 | Mutable(final Turnout pT) { | ||
210 | super(pT); | ||
211 | } | ||
212 | |||
213 | @Override | ||
214 | public boolean isMutable() { | ||
215 | return true; | ||
216 | } | ||
217 | } | ||
218 | |||
219 | private static final class Immutable extends TooFewInputsOfTurnout.Match { | ||
220 | Immutable(final Turnout pT) { | ||
221 | super(pT); | ||
222 | } | ||
223 | |||
224 | @Override | ||
225 | public boolean isMutable() { | ||
226 | return false; | ||
227 | } | ||
228 | } | ||
229 | } | ||
230 | |||
231 | /** | ||
232 | * Generated pattern matcher API of the modes3.queries.tooFewInputsOfTurnout pattern, | ||
233 | * providing pattern-specific query methods. | ||
234 | * | ||
235 | * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, | ||
236 | * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. | ||
237 | * | ||
238 | * <p>Matches of the pattern will be represented as {@link Match}. | ||
239 | * | ||
240 | * <p>Original source: | ||
241 | * <code><pre> | ||
242 | * {@literal @}Constraint(message = "tooFewInputsOfTurnout", severity = "error", key = { T }) | ||
243 | * pattern tooFewInputsOfTurnout(T : Turnout) { | ||
244 | * neg find inputsOfTurnout(T); | ||
245 | * } | ||
246 | * </pre></code> | ||
247 | * | ||
248 | * @see Match | ||
249 | * @see TooFewInputsOfTurnout | ||
250 | * | ||
251 | */ | ||
252 | public static class Matcher extends BaseMatcher<TooFewInputsOfTurnout.Match> { | ||
253 | /** | ||
254 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
255 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
256 | * | ||
257 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
258 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
259 | * | ||
260 | */ | ||
261 | public static TooFewInputsOfTurnout.Matcher on(final ViatraQueryEngine engine) { | ||
262 | // check if matcher already exists | ||
263 | Matcher matcher = engine.getExistingMatcher(querySpecification()); | ||
264 | if (matcher == null) { | ||
265 | matcher = (Matcher)engine.getMatcher(querySpecification()); | ||
266 | } | ||
267 | return matcher; | ||
268 | } | ||
269 | |||
270 | /** | ||
271 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
272 | * @return an initialized matcher | ||
273 | * @noreference This method is for internal matcher initialization by the framework, do not call it manually. | ||
274 | * | ||
275 | */ | ||
276 | public static TooFewInputsOfTurnout.Matcher create() { | ||
277 | return new Matcher(); | ||
278 | } | ||
279 | |||
280 | private static final int POSITION_T = 0; | ||
281 | |||
282 | private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(TooFewInputsOfTurnout.Matcher.class); | ||
283 | |||
284 | /** | ||
285 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
286 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
287 | * | ||
288 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
289 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
290 | * | ||
291 | */ | ||
292 | private Matcher() { | ||
293 | super(querySpecification()); | ||
294 | } | ||
295 | |||
296 | /** | ||
297 | * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. | ||
298 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
299 | * @return matches represented as a Match object. | ||
300 | * | ||
301 | */ | ||
302 | public Collection<TooFewInputsOfTurnout.Match> getAllMatches(final Turnout pT) { | ||
303 | return rawStreamAllMatches(new Object[]{pT}).collect(Collectors.toSet()); | ||
304 | } | ||
305 | |||
306 | /** | ||
307 | * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. | ||
308 | * </p> | ||
309 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
310 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
311 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
312 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
313 | * @return a stream of matches represented as a Match object. | ||
314 | * | ||
315 | */ | ||
316 | public Stream<TooFewInputsOfTurnout.Match> streamAllMatches(final Turnout pT) { | ||
317 | return rawStreamAllMatches(new Object[]{pT}); | ||
318 | } | ||
319 | |||
320 | /** | ||
321 | * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
322 | * Neither determinism nor randomness of selection is guaranteed. | ||
323 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
324 | * @return a match represented as a Match object, or null if no match is found. | ||
325 | * | ||
326 | */ | ||
327 | public Optional<TooFewInputsOfTurnout.Match> getOneArbitraryMatch(final Turnout pT) { | ||
328 | return rawGetOneArbitraryMatch(new Object[]{pT}); | ||
329 | } | ||
330 | |||
331 | /** | ||
332 | * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, | ||
333 | * under any possible substitution of the unspecified parameters (if any). | ||
334 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
335 | * @return true if the input is a valid (partial) match of the pattern. | ||
336 | * | ||
337 | */ | ||
338 | public boolean hasMatch(final Turnout pT) { | ||
339 | return rawHasMatch(new Object[]{pT}); | ||
340 | } | ||
341 | |||
342 | /** | ||
343 | * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. | ||
344 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
345 | * @return the number of pattern matches found. | ||
346 | * | ||
347 | */ | ||
348 | public int countMatches(final Turnout pT) { | ||
349 | return rawCountMatches(new Object[]{pT}); | ||
350 | } | ||
351 | |||
352 | /** | ||
353 | * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
354 | * Neither determinism nor randomness of selection is guaranteed. | ||
355 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
356 | * @param processor the action that will process the selected match. | ||
357 | * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked | ||
358 | * | ||
359 | */ | ||
360 | public boolean forOneArbitraryMatch(final Turnout pT, final Consumer<? super TooFewInputsOfTurnout.Match> processor) { | ||
361 | return rawForOneArbitraryMatch(new Object[]{pT}, processor); | ||
362 | } | ||
363 | |||
364 | /** | ||
365 | * Returns a new (partial) match. | ||
366 | * This can be used e.g. to call the matcher with a partial match. | ||
367 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
368 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
369 | * @return the (partial) match object. | ||
370 | * | ||
371 | */ | ||
372 | public TooFewInputsOfTurnout.Match newMatch(final Turnout pT) { | ||
373 | return TooFewInputsOfTurnout.Match.newMatch(pT); | ||
374 | } | ||
375 | |||
376 | /** | ||
377 | * Retrieve the set of values that occur in matches for T. | ||
378 | * @return the Set of all values or empty set if there are no matches | ||
379 | * | ||
380 | */ | ||
381 | protected Stream<Turnout> rawStreamAllValuesOfT(final Object[] parameters) { | ||
382 | return rawStreamAllValues(POSITION_T, parameters).map(Turnout.class::cast); | ||
383 | } | ||
384 | |||
385 | /** | ||
386 | * Retrieve the set of values that occur in matches for T. | ||
387 | * @return the Set of all values or empty set if there are no matches | ||
388 | * | ||
389 | */ | ||
390 | public Set<Turnout> getAllValuesOfT() { | ||
391 | return rawStreamAllValuesOfT(emptyArray()).collect(Collectors.toSet()); | ||
392 | } | ||
393 | |||
394 | /** | ||
395 | * Retrieve the set of values that occur in matches for T. | ||
396 | * @return the Set of all values or empty set if there are no matches | ||
397 | * | ||
398 | */ | ||
399 | public Stream<Turnout> streamAllValuesOfT() { | ||
400 | return rawStreamAllValuesOfT(emptyArray()); | ||
401 | } | ||
402 | |||
403 | @Override | ||
404 | protected TooFewInputsOfTurnout.Match tupleToMatch(final Tuple t) { | ||
405 | try { | ||
406 | return TooFewInputsOfTurnout.Match.newMatch((Turnout) t.get(POSITION_T)); | ||
407 | } catch(ClassCastException e) { | ||
408 | LOGGER.error("Element(s) in tuple not properly typed!",e); | ||
409 | return null; | ||
410 | } | ||
411 | } | ||
412 | |||
413 | @Override | ||
414 | protected TooFewInputsOfTurnout.Match arrayToMatch(final Object[] match) { | ||
415 | try { | ||
416 | return TooFewInputsOfTurnout.Match.newMatch((Turnout) match[POSITION_T]); | ||
417 | } catch(ClassCastException e) { | ||
418 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
419 | return null; | ||
420 | } | ||
421 | } | ||
422 | |||
423 | @Override | ||
424 | protected TooFewInputsOfTurnout.Match arrayToMatchMutable(final Object[] match) { | ||
425 | try { | ||
426 | return TooFewInputsOfTurnout.Match.newMutableMatch((Turnout) match[POSITION_T]); | ||
427 | } catch(ClassCastException e) { | ||
428 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
429 | return null; | ||
430 | } | ||
431 | } | ||
432 | |||
433 | /** | ||
434 | * @return the singleton instance of the query specification of this pattern | ||
435 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
436 | * | ||
437 | */ | ||
438 | public static IQuerySpecification<TooFewInputsOfTurnout.Matcher> querySpecification() { | ||
439 | return TooFewInputsOfTurnout.instance(); | ||
440 | } | ||
441 | } | ||
442 | |||
443 | private TooFewInputsOfTurnout() { | ||
444 | super(GeneratedPQuery.INSTANCE); | ||
445 | } | ||
446 | |||
447 | /** | ||
448 | * @return the singleton instance of the query specification | ||
449 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
450 | * | ||
451 | */ | ||
452 | public static TooFewInputsOfTurnout instance() { | ||
453 | try{ | ||
454 | return LazyHolder.INSTANCE; | ||
455 | } catch (ExceptionInInitializerError err) { | ||
456 | throw processInitializerError(err); | ||
457 | } | ||
458 | } | ||
459 | |||
460 | @Override | ||
461 | protected TooFewInputsOfTurnout.Matcher instantiate(final ViatraQueryEngine engine) { | ||
462 | return TooFewInputsOfTurnout.Matcher.on(engine); | ||
463 | } | ||
464 | |||
465 | @Override | ||
466 | public TooFewInputsOfTurnout.Matcher instantiate() { | ||
467 | return TooFewInputsOfTurnout.Matcher.create(); | ||
468 | } | ||
469 | |||
470 | @Override | ||
471 | public TooFewInputsOfTurnout.Match newEmptyMatch() { | ||
472 | return TooFewInputsOfTurnout.Match.newEmptyMatch(); | ||
473 | } | ||
474 | |||
475 | @Override | ||
476 | public TooFewInputsOfTurnout.Match newMatch(final Object... parameters) { | ||
477 | return TooFewInputsOfTurnout.Match.newMatch((modes3.Turnout) parameters[0]); | ||
478 | } | ||
479 | |||
480 | /** | ||
481 | * Inner class allowing the singleton instance of {@link TooFewInputsOfTurnout} to be created | ||
482 | * <b>not</b> at the class load time of the outer class, | ||
483 | * but rather at the first call to {@link TooFewInputsOfTurnout#instance()}. | ||
484 | * | ||
485 | * <p> This workaround is required e.g. to support recursion. | ||
486 | * | ||
487 | */ | ||
488 | private static class LazyHolder { | ||
489 | private static final TooFewInputsOfTurnout INSTANCE = new TooFewInputsOfTurnout(); | ||
490 | |||
491 | /** | ||
492 | * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned. | ||
493 | * This initialization order is required to support indirect recursion. | ||
494 | * | ||
495 | * <p> The static initializer is defined using a helper field to work around limitations of the code generator. | ||
496 | * | ||
497 | */ | ||
498 | private static final Object STATIC_INITIALIZER = ensureInitialized(); | ||
499 | |||
500 | public static Object ensureInitialized() { | ||
501 | INSTANCE.ensureInitializedInternal(); | ||
502 | return null; | ||
503 | } | ||
504 | } | ||
505 | |||
506 | private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { | ||
507 | private static final TooFewInputsOfTurnout.GeneratedPQuery INSTANCE = new GeneratedPQuery(); | ||
508 | |||
509 | private final PParameter parameter_T = new PParameter("T", "modes3.Turnout", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Turnout")), PParameterDirection.INOUT); | ||
510 | |||
511 | private final List<PParameter> parameters = Arrays.asList(parameter_T); | ||
512 | |||
513 | private GeneratedPQuery() { | ||
514 | super(PVisibility.PUBLIC); | ||
515 | } | ||
516 | |||
517 | @Override | ||
518 | public String getFullyQualifiedName() { | ||
519 | return "modes3.queries.tooFewInputsOfTurnout"; | ||
520 | } | ||
521 | |||
522 | @Override | ||
523 | public List<String> getParameterNames() { | ||
524 | return Arrays.asList("T"); | ||
525 | } | ||
526 | |||
527 | @Override | ||
528 | public List<PParameter> getParameters() { | ||
529 | return parameters; | ||
530 | } | ||
531 | |||
532 | @Override | ||
533 | public Set<PBody> doGetContainedBodies() { | ||
534 | setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); | ||
535 | Set<PBody> bodies = new LinkedHashSet<>(); | ||
536 | { | ||
537 | PBody body = new PBody(this); | ||
538 | PVariable var_T = body.getOrCreateVariableByName("T"); | ||
539 | new TypeConstraint(body, Tuples.flatTupleOf(var_T), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Turnout"))); | ||
540 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
541 | new ExportedParameter(body, var_T, parameter_T) | ||
542 | )); | ||
543 | // neg find inputsOfTurnout(T) | ||
544 | new NegativePatternCall(body, Tuples.flatTupleOf(var_T), InputsOfTurnout.instance().getInternalQueryRepresentation()); | ||
545 | bodies.add(body); | ||
546 | } | ||
547 | { | ||
548 | PAnnotation annotation = new PAnnotation("Constraint"); | ||
549 | annotation.addAttribute("message", "tooFewInputsOfTurnout"); | ||
550 | annotation.addAttribute("severity", "error"); | ||
551 | annotation.addAttribute("key", Arrays.asList(new Object[] { | ||
552 | new ParameterReference("T") | ||
553 | })); | ||
554 | addAnnotation(annotation); | ||
555 | } | ||
556 | return bodies; | ||
557 | } | ||
558 | } | ||
559 | } | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/TooManyInputsOfSegment.java b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/TooManyInputsOfSegment.java new file mode 100644 index 00000000..d12ec23e --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/TooManyInputsOfSegment.java | |||
@@ -0,0 +1,583 @@ | |||
1 | /** | ||
2 | * Generated from platform:/resource/ca.mcgill.rtgmrt.example.modes3/src/modes3/queries/Modes3Queries.vql | ||
3 | */ | ||
4 | package modes3.queries; | ||
5 | |||
6 | import java.util.Arrays; | ||
7 | import java.util.Collection; | ||
8 | import java.util.LinkedHashSet; | ||
9 | import java.util.List; | ||
10 | import java.util.Objects; | ||
11 | import java.util.Optional; | ||
12 | import java.util.Set; | ||
13 | import java.util.function.Consumer; | ||
14 | import java.util.stream.Collectors; | ||
15 | import java.util.stream.Stream; | ||
16 | import modes3.SimpleSegment; | ||
17 | import modes3.queries.Output; | ||
18 | import org.apache.log4j.Logger; | ||
19 | import org.eclipse.emf.ecore.EClass; | ||
20 | import org.eclipse.viatra.query.runtime.api.IPatternMatch; | ||
21 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification; | ||
22 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; | ||
23 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; | ||
24 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; | ||
25 | import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; | ||
26 | import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; | ||
27 | import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; | ||
28 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
29 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | ||
30 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | ||
31 | import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation; | ||
32 | import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference; | ||
33 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
34 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Inequality; | ||
35 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall; | ||
36 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
37 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | ||
38 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; | ||
39 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | ||
40 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; | ||
41 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
42 | import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; | ||
43 | |||
44 | /** | ||
45 | * A pattern-specific query specification that can instantiate Matcher in a type-safe way. | ||
46 | * | ||
47 | * <p>Original source: | ||
48 | * <code><pre> | ||
49 | * {@literal @}Constraint(message = "tooManyInputsOfSegment", severity = "error", key = { S }) | ||
50 | * pattern tooManyInputsOfSegment(S : SimpleSegment) { | ||
51 | * find output(I1, S); | ||
52 | * find output(I2, S); | ||
53 | * find output(I3, S); | ||
54 | * I1 != I2; | ||
55 | * I1 != I3; | ||
56 | * I2 != I3; | ||
57 | * } | ||
58 | * </pre></code> | ||
59 | * | ||
60 | * @see Matcher | ||
61 | * @see Match | ||
62 | * | ||
63 | */ | ||
64 | @SuppressWarnings("all") | ||
65 | public final class TooManyInputsOfSegment extends BaseGeneratedEMFQuerySpecification<TooManyInputsOfSegment.Matcher> { | ||
66 | /** | ||
67 | * Pattern-specific match representation of the modes3.queries.tooManyInputsOfSegment pattern, | ||
68 | * to be used in conjunction with {@link Matcher}. | ||
69 | * | ||
70 | * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. | ||
71 | * Each instance is a (possibly partial) substitution of pattern parameters, | ||
72 | * usable to represent a match of the pattern in the result of a query, | ||
73 | * or to specify the bound (fixed) input parameters when issuing a query. | ||
74 | * | ||
75 | * @see Matcher | ||
76 | * | ||
77 | */ | ||
78 | public static abstract class Match extends BasePatternMatch { | ||
79 | private SimpleSegment fS; | ||
80 | |||
81 | private static List<String> parameterNames = makeImmutableList("S"); | ||
82 | |||
83 | private Match(final SimpleSegment pS) { | ||
84 | this.fS = pS; | ||
85 | } | ||
86 | |||
87 | @Override | ||
88 | public Object get(final String parameterName) { | ||
89 | switch(parameterName) { | ||
90 | case "S": return this.fS; | ||
91 | default: return null; | ||
92 | } | ||
93 | } | ||
94 | |||
95 | @Override | ||
96 | public Object get(final int index) { | ||
97 | switch(index) { | ||
98 | case 0: return this.fS; | ||
99 | default: return null; | ||
100 | } | ||
101 | } | ||
102 | |||
103 | public SimpleSegment getS() { | ||
104 | return this.fS; | ||
105 | } | ||
106 | |||
107 | @Override | ||
108 | public boolean set(final String parameterName, final Object newValue) { | ||
109 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
110 | if ("S".equals(parameterName) ) { | ||
111 | this.fS = (SimpleSegment) newValue; | ||
112 | return true; | ||
113 | } | ||
114 | return false; | ||
115 | } | ||
116 | |||
117 | public void setS(final SimpleSegment pS) { | ||
118 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
119 | this.fS = pS; | ||
120 | } | ||
121 | |||
122 | @Override | ||
123 | public String patternName() { | ||
124 | return "modes3.queries.tooManyInputsOfSegment"; | ||
125 | } | ||
126 | |||
127 | @Override | ||
128 | public List<String> parameterNames() { | ||
129 | return TooManyInputsOfSegment.Match.parameterNames; | ||
130 | } | ||
131 | |||
132 | @Override | ||
133 | public Object[] toArray() { | ||
134 | return new Object[]{fS}; | ||
135 | } | ||
136 | |||
137 | @Override | ||
138 | public TooManyInputsOfSegment.Match toImmutable() { | ||
139 | return isMutable() ? newMatch(fS) : this; | ||
140 | } | ||
141 | |||
142 | @Override | ||
143 | public String prettyPrint() { | ||
144 | StringBuilder result = new StringBuilder(); | ||
145 | result.append("\"S\"=" + prettyPrintValue(fS)); | ||
146 | return result.toString(); | ||
147 | } | ||
148 | |||
149 | @Override | ||
150 | public int hashCode() { | ||
151 | return Objects.hash(fS); | ||
152 | } | ||
153 | |||
154 | @Override | ||
155 | public boolean equals(final Object obj) { | ||
156 | if (this == obj) | ||
157 | return true; | ||
158 | if (obj == null) { | ||
159 | return false; | ||
160 | } | ||
161 | if ((obj instanceof TooManyInputsOfSegment.Match)) { | ||
162 | TooManyInputsOfSegment.Match other = (TooManyInputsOfSegment.Match) obj; | ||
163 | return Objects.equals(fS, other.fS); | ||
164 | } else { | ||
165 | // this should be infrequent | ||
166 | if (!(obj instanceof IPatternMatch)) { | ||
167 | return false; | ||
168 | } | ||
169 | IPatternMatch otherSig = (IPatternMatch) obj; | ||
170 | return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); | ||
171 | } | ||
172 | } | ||
173 | |||
174 | @Override | ||
175 | public TooManyInputsOfSegment specification() { | ||
176 | return TooManyInputsOfSegment.instance(); | ||
177 | } | ||
178 | |||
179 | /** | ||
180 | * Returns an empty, mutable match. | ||
181 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
182 | * | ||
183 | * @return the empty match. | ||
184 | * | ||
185 | */ | ||
186 | public static TooManyInputsOfSegment.Match newEmptyMatch() { | ||
187 | return new Mutable(null); | ||
188 | } | ||
189 | |||
190 | /** | ||
191 | * Returns a mutable (partial) match. | ||
192 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
193 | * | ||
194 | * @param pS the fixed value of pattern parameter S, or null if not bound. | ||
195 | * @return the new, mutable (partial) match object. | ||
196 | * | ||
197 | */ | ||
198 | public static TooManyInputsOfSegment.Match newMutableMatch(final SimpleSegment pS) { | ||
199 | return new Mutable(pS); | ||
200 | } | ||
201 | |||
202 | /** | ||
203 | * Returns a new (partial) match. | ||
204 | * This can be used e.g. to call the matcher with a partial match. | ||
205 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
206 | * @param pS the fixed value of pattern parameter S, or null if not bound. | ||
207 | * @return the (partial) match object. | ||
208 | * | ||
209 | */ | ||
210 | public static TooManyInputsOfSegment.Match newMatch(final SimpleSegment pS) { | ||
211 | return new Immutable(pS); | ||
212 | } | ||
213 | |||
214 | private static final class Mutable extends TooManyInputsOfSegment.Match { | ||
215 | Mutable(final SimpleSegment pS) { | ||
216 | super(pS); | ||
217 | } | ||
218 | |||
219 | @Override | ||
220 | public boolean isMutable() { | ||
221 | return true; | ||
222 | } | ||
223 | } | ||
224 | |||
225 | private static final class Immutable extends TooManyInputsOfSegment.Match { | ||
226 | Immutable(final SimpleSegment pS) { | ||
227 | super(pS); | ||
228 | } | ||
229 | |||
230 | @Override | ||
231 | public boolean isMutable() { | ||
232 | return false; | ||
233 | } | ||
234 | } | ||
235 | } | ||
236 | |||
237 | /** | ||
238 | * Generated pattern matcher API of the modes3.queries.tooManyInputsOfSegment pattern, | ||
239 | * providing pattern-specific query methods. | ||
240 | * | ||
241 | * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, | ||
242 | * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. | ||
243 | * | ||
244 | * <p>Matches of the pattern will be represented as {@link Match}. | ||
245 | * | ||
246 | * <p>Original source: | ||
247 | * <code><pre> | ||
248 | * {@literal @}Constraint(message = "tooManyInputsOfSegment", severity = "error", key = { S }) | ||
249 | * pattern tooManyInputsOfSegment(S : SimpleSegment) { | ||
250 | * find output(I1, S); | ||
251 | * find output(I2, S); | ||
252 | * find output(I3, S); | ||
253 | * I1 != I2; | ||
254 | * I1 != I3; | ||
255 | * I2 != I3; | ||
256 | * } | ||
257 | * </pre></code> | ||
258 | * | ||
259 | * @see Match | ||
260 | * @see TooManyInputsOfSegment | ||
261 | * | ||
262 | */ | ||
263 | public static class Matcher extends BaseMatcher<TooManyInputsOfSegment.Match> { | ||
264 | /** | ||
265 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
266 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
267 | * | ||
268 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
269 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
270 | * | ||
271 | */ | ||
272 | public static TooManyInputsOfSegment.Matcher on(final ViatraQueryEngine engine) { | ||
273 | // check if matcher already exists | ||
274 | Matcher matcher = engine.getExistingMatcher(querySpecification()); | ||
275 | if (matcher == null) { | ||
276 | matcher = (Matcher)engine.getMatcher(querySpecification()); | ||
277 | } | ||
278 | return matcher; | ||
279 | } | ||
280 | |||
281 | /** | ||
282 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
283 | * @return an initialized matcher | ||
284 | * @noreference This method is for internal matcher initialization by the framework, do not call it manually. | ||
285 | * | ||
286 | */ | ||
287 | public static TooManyInputsOfSegment.Matcher create() { | ||
288 | return new Matcher(); | ||
289 | } | ||
290 | |||
291 | private static final int POSITION_S = 0; | ||
292 | |||
293 | private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(TooManyInputsOfSegment.Matcher.class); | ||
294 | |||
295 | /** | ||
296 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
297 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
298 | * | ||
299 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
300 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
301 | * | ||
302 | */ | ||
303 | private Matcher() { | ||
304 | super(querySpecification()); | ||
305 | } | ||
306 | |||
307 | /** | ||
308 | * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. | ||
309 | * @param pS the fixed value of pattern parameter S, or null if not bound. | ||
310 | * @return matches represented as a Match object. | ||
311 | * | ||
312 | */ | ||
313 | public Collection<TooManyInputsOfSegment.Match> getAllMatches(final SimpleSegment pS) { | ||
314 | return rawStreamAllMatches(new Object[]{pS}).collect(Collectors.toSet()); | ||
315 | } | ||
316 | |||
317 | /** | ||
318 | * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. | ||
319 | * </p> | ||
320 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
321 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
322 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
323 | * @param pS the fixed value of pattern parameter S, or null if not bound. | ||
324 | * @return a stream of matches represented as a Match object. | ||
325 | * | ||
326 | */ | ||
327 | public Stream<TooManyInputsOfSegment.Match> streamAllMatches(final SimpleSegment pS) { | ||
328 | return rawStreamAllMatches(new Object[]{pS}); | ||
329 | } | ||
330 | |||
331 | /** | ||
332 | * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
333 | * Neither determinism nor randomness of selection is guaranteed. | ||
334 | * @param pS the fixed value of pattern parameter S, or null if not bound. | ||
335 | * @return a match represented as a Match object, or null if no match is found. | ||
336 | * | ||
337 | */ | ||
338 | public Optional<TooManyInputsOfSegment.Match> getOneArbitraryMatch(final SimpleSegment pS) { | ||
339 | return rawGetOneArbitraryMatch(new Object[]{pS}); | ||
340 | } | ||
341 | |||
342 | /** | ||
343 | * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, | ||
344 | * under any possible substitution of the unspecified parameters (if any). | ||
345 | * @param pS the fixed value of pattern parameter S, or null if not bound. | ||
346 | * @return true if the input is a valid (partial) match of the pattern. | ||
347 | * | ||
348 | */ | ||
349 | public boolean hasMatch(final SimpleSegment pS) { | ||
350 | return rawHasMatch(new Object[]{pS}); | ||
351 | } | ||
352 | |||
353 | /** | ||
354 | * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. | ||
355 | * @param pS the fixed value of pattern parameter S, or null if not bound. | ||
356 | * @return the number of pattern matches found. | ||
357 | * | ||
358 | */ | ||
359 | public int countMatches(final SimpleSegment pS) { | ||
360 | return rawCountMatches(new Object[]{pS}); | ||
361 | } | ||
362 | |||
363 | /** | ||
364 | * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
365 | * Neither determinism nor randomness of selection is guaranteed. | ||
366 | * @param pS the fixed value of pattern parameter S, or null if not bound. | ||
367 | * @param processor the action that will process the selected match. | ||
368 | * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked | ||
369 | * | ||
370 | */ | ||
371 | public boolean forOneArbitraryMatch(final SimpleSegment pS, final Consumer<? super TooManyInputsOfSegment.Match> processor) { | ||
372 | return rawForOneArbitraryMatch(new Object[]{pS}, processor); | ||
373 | } | ||
374 | |||
375 | /** | ||
376 | * Returns a new (partial) match. | ||
377 | * This can be used e.g. to call the matcher with a partial match. | ||
378 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
379 | * @param pS the fixed value of pattern parameter S, or null if not bound. | ||
380 | * @return the (partial) match object. | ||
381 | * | ||
382 | */ | ||
383 | public TooManyInputsOfSegment.Match newMatch(final SimpleSegment pS) { | ||
384 | return TooManyInputsOfSegment.Match.newMatch(pS); | ||
385 | } | ||
386 | |||
387 | /** | ||
388 | * Retrieve the set of values that occur in matches for S. | ||
389 | * @return the Set of all values or empty set if there are no matches | ||
390 | * | ||
391 | */ | ||
392 | protected Stream<SimpleSegment> rawStreamAllValuesOfS(final Object[] parameters) { | ||
393 | return rawStreamAllValues(POSITION_S, parameters).map(SimpleSegment.class::cast); | ||
394 | } | ||
395 | |||
396 | /** | ||
397 | * Retrieve the set of values that occur in matches for S. | ||
398 | * @return the Set of all values or empty set if there are no matches | ||
399 | * | ||
400 | */ | ||
401 | public Set<SimpleSegment> getAllValuesOfS() { | ||
402 | return rawStreamAllValuesOfS(emptyArray()).collect(Collectors.toSet()); | ||
403 | } | ||
404 | |||
405 | /** | ||
406 | * Retrieve the set of values that occur in matches for S. | ||
407 | * @return the Set of all values or empty set if there are no matches | ||
408 | * | ||
409 | */ | ||
410 | public Stream<SimpleSegment> streamAllValuesOfS() { | ||
411 | return rawStreamAllValuesOfS(emptyArray()); | ||
412 | } | ||
413 | |||
414 | @Override | ||
415 | protected TooManyInputsOfSegment.Match tupleToMatch(final Tuple t) { | ||
416 | try { | ||
417 | return TooManyInputsOfSegment.Match.newMatch((SimpleSegment) t.get(POSITION_S)); | ||
418 | } catch(ClassCastException e) { | ||
419 | LOGGER.error("Element(s) in tuple not properly typed!",e); | ||
420 | return null; | ||
421 | } | ||
422 | } | ||
423 | |||
424 | @Override | ||
425 | protected TooManyInputsOfSegment.Match arrayToMatch(final Object[] match) { | ||
426 | try { | ||
427 | return TooManyInputsOfSegment.Match.newMatch((SimpleSegment) match[POSITION_S]); | ||
428 | } catch(ClassCastException e) { | ||
429 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
430 | return null; | ||
431 | } | ||
432 | } | ||
433 | |||
434 | @Override | ||
435 | protected TooManyInputsOfSegment.Match arrayToMatchMutable(final Object[] match) { | ||
436 | try { | ||
437 | return TooManyInputsOfSegment.Match.newMutableMatch((SimpleSegment) match[POSITION_S]); | ||
438 | } catch(ClassCastException e) { | ||
439 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
440 | return null; | ||
441 | } | ||
442 | } | ||
443 | |||
444 | /** | ||
445 | * @return the singleton instance of the query specification of this pattern | ||
446 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
447 | * | ||
448 | */ | ||
449 | public static IQuerySpecification<TooManyInputsOfSegment.Matcher> querySpecification() { | ||
450 | return TooManyInputsOfSegment.instance(); | ||
451 | } | ||
452 | } | ||
453 | |||
454 | private TooManyInputsOfSegment() { | ||
455 | super(GeneratedPQuery.INSTANCE); | ||
456 | } | ||
457 | |||
458 | /** | ||
459 | * @return the singleton instance of the query specification | ||
460 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
461 | * | ||
462 | */ | ||
463 | public static TooManyInputsOfSegment instance() { | ||
464 | try{ | ||
465 | return LazyHolder.INSTANCE; | ||
466 | } catch (ExceptionInInitializerError err) { | ||
467 | throw processInitializerError(err); | ||
468 | } | ||
469 | } | ||
470 | |||
471 | @Override | ||
472 | protected TooManyInputsOfSegment.Matcher instantiate(final ViatraQueryEngine engine) { | ||
473 | return TooManyInputsOfSegment.Matcher.on(engine); | ||
474 | } | ||
475 | |||
476 | @Override | ||
477 | public TooManyInputsOfSegment.Matcher instantiate() { | ||
478 | return TooManyInputsOfSegment.Matcher.create(); | ||
479 | } | ||
480 | |||
481 | @Override | ||
482 | public TooManyInputsOfSegment.Match newEmptyMatch() { | ||
483 | return TooManyInputsOfSegment.Match.newEmptyMatch(); | ||
484 | } | ||
485 | |||
486 | @Override | ||
487 | public TooManyInputsOfSegment.Match newMatch(final Object... parameters) { | ||
488 | return TooManyInputsOfSegment.Match.newMatch((modes3.SimpleSegment) parameters[0]); | ||
489 | } | ||
490 | |||
491 | /** | ||
492 | * Inner class allowing the singleton instance of {@link TooManyInputsOfSegment} to be created | ||
493 | * <b>not</b> at the class load time of the outer class, | ||
494 | * but rather at the first call to {@link TooManyInputsOfSegment#instance()}. | ||
495 | * | ||
496 | * <p> This workaround is required e.g. to support recursion. | ||
497 | * | ||
498 | */ | ||
499 | private static class LazyHolder { | ||
500 | private static final TooManyInputsOfSegment INSTANCE = new TooManyInputsOfSegment(); | ||
501 | |||
502 | /** | ||
503 | * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned. | ||
504 | * This initialization order is required to support indirect recursion. | ||
505 | * | ||
506 | * <p> The static initializer is defined using a helper field to work around limitations of the code generator. | ||
507 | * | ||
508 | */ | ||
509 | private static final Object STATIC_INITIALIZER = ensureInitialized(); | ||
510 | |||
511 | public static Object ensureInitialized() { | ||
512 | INSTANCE.ensureInitializedInternal(); | ||
513 | return null; | ||
514 | } | ||
515 | } | ||
516 | |||
517 | private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { | ||
518 | private static final TooManyInputsOfSegment.GeneratedPQuery INSTANCE = new GeneratedPQuery(); | ||
519 | |||
520 | private final PParameter parameter_S = new PParameter("S", "modes3.SimpleSegment", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "SimpleSegment")), PParameterDirection.INOUT); | ||
521 | |||
522 | private final List<PParameter> parameters = Arrays.asList(parameter_S); | ||
523 | |||
524 | private GeneratedPQuery() { | ||
525 | super(PVisibility.PUBLIC); | ||
526 | } | ||
527 | |||
528 | @Override | ||
529 | public String getFullyQualifiedName() { | ||
530 | return "modes3.queries.tooManyInputsOfSegment"; | ||
531 | } | ||
532 | |||
533 | @Override | ||
534 | public List<String> getParameterNames() { | ||
535 | return Arrays.asList("S"); | ||
536 | } | ||
537 | |||
538 | @Override | ||
539 | public List<PParameter> getParameters() { | ||
540 | return parameters; | ||
541 | } | ||
542 | |||
543 | @Override | ||
544 | public Set<PBody> doGetContainedBodies() { | ||
545 | setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); | ||
546 | Set<PBody> bodies = new LinkedHashSet<>(); | ||
547 | { | ||
548 | PBody body = new PBody(this); | ||
549 | PVariable var_S = body.getOrCreateVariableByName("S"); | ||
550 | PVariable var_I1 = body.getOrCreateVariableByName("I1"); | ||
551 | PVariable var_I2 = body.getOrCreateVariableByName("I2"); | ||
552 | PVariable var_I3 = body.getOrCreateVariableByName("I3"); | ||
553 | new TypeConstraint(body, Tuples.flatTupleOf(var_S), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "SimpleSegment"))); | ||
554 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
555 | new ExportedParameter(body, var_S, parameter_S) | ||
556 | )); | ||
557 | // find output(I1, S) | ||
558 | new PositivePatternCall(body, Tuples.flatTupleOf(var_I1, var_S), Output.instance().getInternalQueryRepresentation()); | ||
559 | // find output(I2, S) | ||
560 | new PositivePatternCall(body, Tuples.flatTupleOf(var_I2, var_S), Output.instance().getInternalQueryRepresentation()); | ||
561 | // find output(I3, S) | ||
562 | new PositivePatternCall(body, Tuples.flatTupleOf(var_I3, var_S), Output.instance().getInternalQueryRepresentation()); | ||
563 | // I1 != I2 | ||
564 | new Inequality(body, var_I1, var_I2); | ||
565 | // I1 != I3 | ||
566 | new Inequality(body, var_I1, var_I3); | ||
567 | // I2 != I3 | ||
568 | new Inequality(body, var_I2, var_I3); | ||
569 | bodies.add(body); | ||
570 | } | ||
571 | { | ||
572 | PAnnotation annotation = new PAnnotation("Constraint"); | ||
573 | annotation.addAttribute("message", "tooManyInputsOfSegment"); | ||
574 | annotation.addAttribute("severity", "error"); | ||
575 | annotation.addAttribute("key", Arrays.asList(new Object[] { | ||
576 | new ParameterReference("S") | ||
577 | })); | ||
578 | addAnnotation(annotation); | ||
579 | } | ||
580 | return bodies; | ||
581 | } | ||
582 | } | ||
583 | } | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/TooManyInputsOfTurnout.java b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/TooManyInputsOfTurnout.java new file mode 100644 index 00000000..93076cbb --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/TooManyInputsOfTurnout.java | |||
@@ -0,0 +1,600 @@ | |||
1 | /** | ||
2 | * Generated from platform:/resource/ca.mcgill.rtgmrt.example.modes3/src/modes3/queries/Modes3Queries.vql | ||
3 | */ | ||
4 | package modes3.queries; | ||
5 | |||
6 | import java.util.Arrays; | ||
7 | import java.util.Collection; | ||
8 | import java.util.LinkedHashSet; | ||
9 | import java.util.List; | ||
10 | import java.util.Objects; | ||
11 | import java.util.Optional; | ||
12 | import java.util.Set; | ||
13 | import java.util.function.Consumer; | ||
14 | import java.util.stream.Collectors; | ||
15 | import java.util.stream.Stream; | ||
16 | import modes3.Turnout; | ||
17 | import modes3.queries.Adjacent; | ||
18 | import org.apache.log4j.Logger; | ||
19 | import org.eclipse.emf.ecore.EClass; | ||
20 | import org.eclipse.viatra.query.runtime.api.IPatternMatch; | ||
21 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification; | ||
22 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; | ||
23 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; | ||
24 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; | ||
25 | import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; | ||
26 | import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; | ||
27 | import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; | ||
28 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
29 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | ||
30 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | ||
31 | import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation; | ||
32 | import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference; | ||
33 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
34 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Inequality; | ||
35 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall; | ||
36 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
37 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | ||
38 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; | ||
39 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | ||
40 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; | ||
41 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
42 | import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; | ||
43 | |||
44 | /** | ||
45 | * A pattern-specific query specification that can instantiate Matcher in a type-safe way. | ||
46 | * | ||
47 | * <p>Original source: | ||
48 | * <code><pre> | ||
49 | * {@literal @}Constraint(message = "turnoutConnectedToBothOutputs", severity = "error", key = { T }) | ||
50 | * pattern tooManyInputsOfTurnout(T : Turnout) { | ||
51 | * find adjacent(I1, T); | ||
52 | * find adjacent(I2, T); | ||
53 | * find adjacent(I3, T); | ||
54 | * find adjacent(I4, T); | ||
55 | * I1 != I2; | ||
56 | * I1 != I3; | ||
57 | * I1 != I4; | ||
58 | * I2 != I3; | ||
59 | * I2 != I4; | ||
60 | * I3 != I4; | ||
61 | * } | ||
62 | * </pre></code> | ||
63 | * | ||
64 | * @see Matcher | ||
65 | * @see Match | ||
66 | * | ||
67 | */ | ||
68 | @SuppressWarnings("all") | ||
69 | public final class TooManyInputsOfTurnout extends BaseGeneratedEMFQuerySpecification<TooManyInputsOfTurnout.Matcher> { | ||
70 | /** | ||
71 | * Pattern-specific match representation of the modes3.queries.tooManyInputsOfTurnout pattern, | ||
72 | * to be used in conjunction with {@link Matcher}. | ||
73 | * | ||
74 | * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. | ||
75 | * Each instance is a (possibly partial) substitution of pattern parameters, | ||
76 | * usable to represent a match of the pattern in the result of a query, | ||
77 | * or to specify the bound (fixed) input parameters when issuing a query. | ||
78 | * | ||
79 | * @see Matcher | ||
80 | * | ||
81 | */ | ||
82 | public static abstract class Match extends BasePatternMatch { | ||
83 | private Turnout fT; | ||
84 | |||
85 | private static List<String> parameterNames = makeImmutableList("T"); | ||
86 | |||
87 | private Match(final Turnout pT) { | ||
88 | this.fT = pT; | ||
89 | } | ||
90 | |||
91 | @Override | ||
92 | public Object get(final String parameterName) { | ||
93 | switch(parameterName) { | ||
94 | case "T": return this.fT; | ||
95 | default: return null; | ||
96 | } | ||
97 | } | ||
98 | |||
99 | @Override | ||
100 | public Object get(final int index) { | ||
101 | switch(index) { | ||
102 | case 0: return this.fT; | ||
103 | default: return null; | ||
104 | } | ||
105 | } | ||
106 | |||
107 | public Turnout getT() { | ||
108 | return this.fT; | ||
109 | } | ||
110 | |||
111 | @Override | ||
112 | public boolean set(final String parameterName, final Object newValue) { | ||
113 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
114 | if ("T".equals(parameterName) ) { | ||
115 | this.fT = (Turnout) newValue; | ||
116 | return true; | ||
117 | } | ||
118 | return false; | ||
119 | } | ||
120 | |||
121 | public void setT(final Turnout pT) { | ||
122 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
123 | this.fT = pT; | ||
124 | } | ||
125 | |||
126 | @Override | ||
127 | public String patternName() { | ||
128 | return "modes3.queries.tooManyInputsOfTurnout"; | ||
129 | } | ||
130 | |||
131 | @Override | ||
132 | public List<String> parameterNames() { | ||
133 | return TooManyInputsOfTurnout.Match.parameterNames; | ||
134 | } | ||
135 | |||
136 | @Override | ||
137 | public Object[] toArray() { | ||
138 | return new Object[]{fT}; | ||
139 | } | ||
140 | |||
141 | @Override | ||
142 | public TooManyInputsOfTurnout.Match toImmutable() { | ||
143 | return isMutable() ? newMatch(fT) : this; | ||
144 | } | ||
145 | |||
146 | @Override | ||
147 | public String prettyPrint() { | ||
148 | StringBuilder result = new StringBuilder(); | ||
149 | result.append("\"T\"=" + prettyPrintValue(fT)); | ||
150 | return result.toString(); | ||
151 | } | ||
152 | |||
153 | @Override | ||
154 | public int hashCode() { | ||
155 | return Objects.hash(fT); | ||
156 | } | ||
157 | |||
158 | @Override | ||
159 | public boolean equals(final Object obj) { | ||
160 | if (this == obj) | ||
161 | return true; | ||
162 | if (obj == null) { | ||
163 | return false; | ||
164 | } | ||
165 | if ((obj instanceof TooManyInputsOfTurnout.Match)) { | ||
166 | TooManyInputsOfTurnout.Match other = (TooManyInputsOfTurnout.Match) obj; | ||
167 | return Objects.equals(fT, other.fT); | ||
168 | } else { | ||
169 | // this should be infrequent | ||
170 | if (!(obj instanceof IPatternMatch)) { | ||
171 | return false; | ||
172 | } | ||
173 | IPatternMatch otherSig = (IPatternMatch) obj; | ||
174 | return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); | ||
175 | } | ||
176 | } | ||
177 | |||
178 | @Override | ||
179 | public TooManyInputsOfTurnout specification() { | ||
180 | return TooManyInputsOfTurnout.instance(); | ||
181 | } | ||
182 | |||
183 | /** | ||
184 | * Returns an empty, mutable match. | ||
185 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
186 | * | ||
187 | * @return the empty match. | ||
188 | * | ||
189 | */ | ||
190 | public static TooManyInputsOfTurnout.Match newEmptyMatch() { | ||
191 | return new Mutable(null); | ||
192 | } | ||
193 | |||
194 | /** | ||
195 | * Returns a mutable (partial) match. | ||
196 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
197 | * | ||
198 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
199 | * @return the new, mutable (partial) match object. | ||
200 | * | ||
201 | */ | ||
202 | public static TooManyInputsOfTurnout.Match newMutableMatch(final Turnout pT) { | ||
203 | return new Mutable(pT); | ||
204 | } | ||
205 | |||
206 | /** | ||
207 | * Returns a new (partial) match. | ||
208 | * This can be used e.g. to call the matcher with a partial match. | ||
209 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
210 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
211 | * @return the (partial) match object. | ||
212 | * | ||
213 | */ | ||
214 | public static TooManyInputsOfTurnout.Match newMatch(final Turnout pT) { | ||
215 | return new Immutable(pT); | ||
216 | } | ||
217 | |||
218 | private static final class Mutable extends TooManyInputsOfTurnout.Match { | ||
219 | Mutable(final Turnout pT) { | ||
220 | super(pT); | ||
221 | } | ||
222 | |||
223 | @Override | ||
224 | public boolean isMutable() { | ||
225 | return true; | ||
226 | } | ||
227 | } | ||
228 | |||
229 | private static final class Immutable extends TooManyInputsOfTurnout.Match { | ||
230 | Immutable(final Turnout pT) { | ||
231 | super(pT); | ||
232 | } | ||
233 | |||
234 | @Override | ||
235 | public boolean isMutable() { | ||
236 | return false; | ||
237 | } | ||
238 | } | ||
239 | } | ||
240 | |||
241 | /** | ||
242 | * Generated pattern matcher API of the modes3.queries.tooManyInputsOfTurnout pattern, | ||
243 | * providing pattern-specific query methods. | ||
244 | * | ||
245 | * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, | ||
246 | * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. | ||
247 | * | ||
248 | * <p>Matches of the pattern will be represented as {@link Match}. | ||
249 | * | ||
250 | * <p>Original source: | ||
251 | * <code><pre> | ||
252 | * {@literal @}Constraint(message = "turnoutConnectedToBothOutputs", severity = "error", key = { T }) | ||
253 | * pattern tooManyInputsOfTurnout(T : Turnout) { | ||
254 | * find adjacent(I1, T); | ||
255 | * find adjacent(I2, T); | ||
256 | * find adjacent(I3, T); | ||
257 | * find adjacent(I4, T); | ||
258 | * I1 != I2; | ||
259 | * I1 != I3; | ||
260 | * I1 != I4; | ||
261 | * I2 != I3; | ||
262 | * I2 != I4; | ||
263 | * I3 != I4; | ||
264 | * } | ||
265 | * </pre></code> | ||
266 | * | ||
267 | * @see Match | ||
268 | * @see TooManyInputsOfTurnout | ||
269 | * | ||
270 | */ | ||
271 | public static class Matcher extends BaseMatcher<TooManyInputsOfTurnout.Match> { | ||
272 | /** | ||
273 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
274 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
275 | * | ||
276 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
277 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
278 | * | ||
279 | */ | ||
280 | public static TooManyInputsOfTurnout.Matcher on(final ViatraQueryEngine engine) { | ||
281 | // check if matcher already exists | ||
282 | Matcher matcher = engine.getExistingMatcher(querySpecification()); | ||
283 | if (matcher == null) { | ||
284 | matcher = (Matcher)engine.getMatcher(querySpecification()); | ||
285 | } | ||
286 | return matcher; | ||
287 | } | ||
288 | |||
289 | /** | ||
290 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
291 | * @return an initialized matcher | ||
292 | * @noreference This method is for internal matcher initialization by the framework, do not call it manually. | ||
293 | * | ||
294 | */ | ||
295 | public static TooManyInputsOfTurnout.Matcher create() { | ||
296 | return new Matcher(); | ||
297 | } | ||
298 | |||
299 | private static final int POSITION_T = 0; | ||
300 | |||
301 | private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(TooManyInputsOfTurnout.Matcher.class); | ||
302 | |||
303 | /** | ||
304 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
305 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
306 | * | ||
307 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
308 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
309 | * | ||
310 | */ | ||
311 | private Matcher() { | ||
312 | super(querySpecification()); | ||
313 | } | ||
314 | |||
315 | /** | ||
316 | * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. | ||
317 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
318 | * @return matches represented as a Match object. | ||
319 | * | ||
320 | */ | ||
321 | public Collection<TooManyInputsOfTurnout.Match> getAllMatches(final Turnout pT) { | ||
322 | return rawStreamAllMatches(new Object[]{pT}).collect(Collectors.toSet()); | ||
323 | } | ||
324 | |||
325 | /** | ||
326 | * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. | ||
327 | * </p> | ||
328 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
329 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
330 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
331 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
332 | * @return a stream of matches represented as a Match object. | ||
333 | * | ||
334 | */ | ||
335 | public Stream<TooManyInputsOfTurnout.Match> streamAllMatches(final Turnout pT) { | ||
336 | return rawStreamAllMatches(new Object[]{pT}); | ||
337 | } | ||
338 | |||
339 | /** | ||
340 | * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
341 | * Neither determinism nor randomness of selection is guaranteed. | ||
342 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
343 | * @return a match represented as a Match object, or null if no match is found. | ||
344 | * | ||
345 | */ | ||
346 | public Optional<TooManyInputsOfTurnout.Match> getOneArbitraryMatch(final Turnout pT) { | ||
347 | return rawGetOneArbitraryMatch(new Object[]{pT}); | ||
348 | } | ||
349 | |||
350 | /** | ||
351 | * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, | ||
352 | * under any possible substitution of the unspecified parameters (if any). | ||
353 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
354 | * @return true if the input is a valid (partial) match of the pattern. | ||
355 | * | ||
356 | */ | ||
357 | public boolean hasMatch(final Turnout pT) { | ||
358 | return rawHasMatch(new Object[]{pT}); | ||
359 | } | ||
360 | |||
361 | /** | ||
362 | * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. | ||
363 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
364 | * @return the number of pattern matches found. | ||
365 | * | ||
366 | */ | ||
367 | public int countMatches(final Turnout pT) { | ||
368 | return rawCountMatches(new Object[]{pT}); | ||
369 | } | ||
370 | |||
371 | /** | ||
372 | * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
373 | * Neither determinism nor randomness of selection is guaranteed. | ||
374 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
375 | * @param processor the action that will process the selected match. | ||
376 | * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked | ||
377 | * | ||
378 | */ | ||
379 | public boolean forOneArbitraryMatch(final Turnout pT, final Consumer<? super TooManyInputsOfTurnout.Match> processor) { | ||
380 | return rawForOneArbitraryMatch(new Object[]{pT}, processor); | ||
381 | } | ||
382 | |||
383 | /** | ||
384 | * Returns a new (partial) match. | ||
385 | * This can be used e.g. to call the matcher with a partial match. | ||
386 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
387 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
388 | * @return the (partial) match object. | ||
389 | * | ||
390 | */ | ||
391 | public TooManyInputsOfTurnout.Match newMatch(final Turnout pT) { | ||
392 | return TooManyInputsOfTurnout.Match.newMatch(pT); | ||
393 | } | ||
394 | |||
395 | /** | ||
396 | * Retrieve the set of values that occur in matches for T. | ||
397 | * @return the Set of all values or empty set if there are no matches | ||
398 | * | ||
399 | */ | ||
400 | protected Stream<Turnout> rawStreamAllValuesOfT(final Object[] parameters) { | ||
401 | return rawStreamAllValues(POSITION_T, parameters).map(Turnout.class::cast); | ||
402 | } | ||
403 | |||
404 | /** | ||
405 | * Retrieve the set of values that occur in matches for T. | ||
406 | * @return the Set of all values or empty set if there are no matches | ||
407 | * | ||
408 | */ | ||
409 | public Set<Turnout> getAllValuesOfT() { | ||
410 | return rawStreamAllValuesOfT(emptyArray()).collect(Collectors.toSet()); | ||
411 | } | ||
412 | |||
413 | /** | ||
414 | * Retrieve the set of values that occur in matches for T. | ||
415 | * @return the Set of all values or empty set if there are no matches | ||
416 | * | ||
417 | */ | ||
418 | public Stream<Turnout> streamAllValuesOfT() { | ||
419 | return rawStreamAllValuesOfT(emptyArray()); | ||
420 | } | ||
421 | |||
422 | @Override | ||
423 | protected TooManyInputsOfTurnout.Match tupleToMatch(final Tuple t) { | ||
424 | try { | ||
425 | return TooManyInputsOfTurnout.Match.newMatch((Turnout) t.get(POSITION_T)); | ||
426 | } catch(ClassCastException e) { | ||
427 | LOGGER.error("Element(s) in tuple not properly typed!",e); | ||
428 | return null; | ||
429 | } | ||
430 | } | ||
431 | |||
432 | @Override | ||
433 | protected TooManyInputsOfTurnout.Match arrayToMatch(final Object[] match) { | ||
434 | try { | ||
435 | return TooManyInputsOfTurnout.Match.newMatch((Turnout) match[POSITION_T]); | ||
436 | } catch(ClassCastException e) { | ||
437 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
438 | return null; | ||
439 | } | ||
440 | } | ||
441 | |||
442 | @Override | ||
443 | protected TooManyInputsOfTurnout.Match arrayToMatchMutable(final Object[] match) { | ||
444 | try { | ||
445 | return TooManyInputsOfTurnout.Match.newMutableMatch((Turnout) match[POSITION_T]); | ||
446 | } catch(ClassCastException e) { | ||
447 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
448 | return null; | ||
449 | } | ||
450 | } | ||
451 | |||
452 | /** | ||
453 | * @return the singleton instance of the query specification of this pattern | ||
454 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
455 | * | ||
456 | */ | ||
457 | public static IQuerySpecification<TooManyInputsOfTurnout.Matcher> querySpecification() { | ||
458 | return TooManyInputsOfTurnout.instance(); | ||
459 | } | ||
460 | } | ||
461 | |||
462 | private TooManyInputsOfTurnout() { | ||
463 | super(GeneratedPQuery.INSTANCE); | ||
464 | } | ||
465 | |||
466 | /** | ||
467 | * @return the singleton instance of the query specification | ||
468 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
469 | * | ||
470 | */ | ||
471 | public static TooManyInputsOfTurnout instance() { | ||
472 | try{ | ||
473 | return LazyHolder.INSTANCE; | ||
474 | } catch (ExceptionInInitializerError err) { | ||
475 | throw processInitializerError(err); | ||
476 | } | ||
477 | } | ||
478 | |||
479 | @Override | ||
480 | protected TooManyInputsOfTurnout.Matcher instantiate(final ViatraQueryEngine engine) { | ||
481 | return TooManyInputsOfTurnout.Matcher.on(engine); | ||
482 | } | ||
483 | |||
484 | @Override | ||
485 | public TooManyInputsOfTurnout.Matcher instantiate() { | ||
486 | return TooManyInputsOfTurnout.Matcher.create(); | ||
487 | } | ||
488 | |||
489 | @Override | ||
490 | public TooManyInputsOfTurnout.Match newEmptyMatch() { | ||
491 | return TooManyInputsOfTurnout.Match.newEmptyMatch(); | ||
492 | } | ||
493 | |||
494 | @Override | ||
495 | public TooManyInputsOfTurnout.Match newMatch(final Object... parameters) { | ||
496 | return TooManyInputsOfTurnout.Match.newMatch((modes3.Turnout) parameters[0]); | ||
497 | } | ||
498 | |||
499 | /** | ||
500 | * Inner class allowing the singleton instance of {@link TooManyInputsOfTurnout} to be created | ||
501 | * <b>not</b> at the class load time of the outer class, | ||
502 | * but rather at the first call to {@link TooManyInputsOfTurnout#instance()}. | ||
503 | * | ||
504 | * <p> This workaround is required e.g. to support recursion. | ||
505 | * | ||
506 | */ | ||
507 | private static class LazyHolder { | ||
508 | private static final TooManyInputsOfTurnout INSTANCE = new TooManyInputsOfTurnout(); | ||
509 | |||
510 | /** | ||
511 | * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned. | ||
512 | * This initialization order is required to support indirect recursion. | ||
513 | * | ||
514 | * <p> The static initializer is defined using a helper field to work around limitations of the code generator. | ||
515 | * | ||
516 | */ | ||
517 | private static final Object STATIC_INITIALIZER = ensureInitialized(); | ||
518 | |||
519 | public static Object ensureInitialized() { | ||
520 | INSTANCE.ensureInitializedInternal(); | ||
521 | return null; | ||
522 | } | ||
523 | } | ||
524 | |||
525 | private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { | ||
526 | private static final TooManyInputsOfTurnout.GeneratedPQuery INSTANCE = new GeneratedPQuery(); | ||
527 | |||
528 | private final PParameter parameter_T = new PParameter("T", "modes3.Turnout", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Turnout")), PParameterDirection.INOUT); | ||
529 | |||
530 | private final List<PParameter> parameters = Arrays.asList(parameter_T); | ||
531 | |||
532 | private GeneratedPQuery() { | ||
533 | super(PVisibility.PUBLIC); | ||
534 | } | ||
535 | |||
536 | @Override | ||
537 | public String getFullyQualifiedName() { | ||
538 | return "modes3.queries.tooManyInputsOfTurnout"; | ||
539 | } | ||
540 | |||
541 | @Override | ||
542 | public List<String> getParameterNames() { | ||
543 | return Arrays.asList("T"); | ||
544 | } | ||
545 | |||
546 | @Override | ||
547 | public List<PParameter> getParameters() { | ||
548 | return parameters; | ||
549 | } | ||
550 | |||
551 | @Override | ||
552 | public Set<PBody> doGetContainedBodies() { | ||
553 | setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); | ||
554 | Set<PBody> bodies = new LinkedHashSet<>(); | ||
555 | { | ||
556 | PBody body = new PBody(this); | ||
557 | PVariable var_T = body.getOrCreateVariableByName("T"); | ||
558 | PVariable var_I1 = body.getOrCreateVariableByName("I1"); | ||
559 | PVariable var_I2 = body.getOrCreateVariableByName("I2"); | ||
560 | PVariable var_I3 = body.getOrCreateVariableByName("I3"); | ||
561 | PVariable var_I4 = body.getOrCreateVariableByName("I4"); | ||
562 | new TypeConstraint(body, Tuples.flatTupleOf(var_T), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Turnout"))); | ||
563 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
564 | new ExportedParameter(body, var_T, parameter_T) | ||
565 | )); | ||
566 | // find adjacent(I1, T) | ||
567 | new PositivePatternCall(body, Tuples.flatTupleOf(var_I1, var_T), Adjacent.instance().getInternalQueryRepresentation()); | ||
568 | // find adjacent(I2, T) | ||
569 | new PositivePatternCall(body, Tuples.flatTupleOf(var_I2, var_T), Adjacent.instance().getInternalQueryRepresentation()); | ||
570 | // find adjacent(I3, T) | ||
571 | new PositivePatternCall(body, Tuples.flatTupleOf(var_I3, var_T), Adjacent.instance().getInternalQueryRepresentation()); | ||
572 | // find adjacent(I4, T) | ||
573 | new PositivePatternCall(body, Tuples.flatTupleOf(var_I4, var_T), Adjacent.instance().getInternalQueryRepresentation()); | ||
574 | // I1 != I2 | ||
575 | new Inequality(body, var_I1, var_I2); | ||
576 | // I1 != I3 | ||
577 | new Inequality(body, var_I1, var_I3); | ||
578 | // I1 != I4 | ||
579 | new Inequality(body, var_I1, var_I4); | ||
580 | // I2 != I3 | ||
581 | new Inequality(body, var_I2, var_I3); | ||
582 | // I2 != I4 | ||
583 | new Inequality(body, var_I2, var_I4); | ||
584 | // I3 != I4 | ||
585 | new Inequality(body, var_I3, var_I4); | ||
586 | bodies.add(body); | ||
587 | } | ||
588 | { | ||
589 | PAnnotation annotation = new PAnnotation("Constraint"); | ||
590 | annotation.addAttribute("message", "turnoutConnectedToBothOutputs"); | ||
591 | annotation.addAttribute("severity", "error"); | ||
592 | annotation.addAttribute("key", Arrays.asList(new Object[] { | ||
593 | new ParameterReference("T") | ||
594 | })); | ||
595 | addAnnotation(annotation); | ||
596 | } | ||
597 | return bodies; | ||
598 | } | ||
599 | } | ||
600 | } | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/TrainLocations_step_2.java b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/TrainLocations_step_2.java new file mode 100644 index 00000000..5bf153c3 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/TrainLocations_step_2.java | |||
@@ -0,0 +1,564 @@ | |||
1 | /** | ||
2 | * Generated from platform:/resource/ca.mcgill.rtgmrt.example.modes3/src/modes3/queries/Modes3Queries.vql | ||
3 | */ | ||
4 | package modes3.queries; | ||
5 | |||
6 | import java.util.Arrays; | ||
7 | import java.util.Collection; | ||
8 | import java.util.LinkedHashSet; | ||
9 | import java.util.List; | ||
10 | import java.util.Objects; | ||
11 | import java.util.Optional; | ||
12 | import java.util.Set; | ||
13 | import java.util.function.Consumer; | ||
14 | import java.util.stream.Collectors; | ||
15 | import java.util.stream.Stream; | ||
16 | import modes3.Train; | ||
17 | import org.apache.log4j.Logger; | ||
18 | import org.eclipse.emf.ecore.EClass; | ||
19 | import org.eclipse.viatra.query.runtime.api.IPatternMatch; | ||
20 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification; | ||
21 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; | ||
22 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; | ||
23 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; | ||
24 | import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; | ||
25 | import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; | ||
26 | import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; | ||
27 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
28 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | ||
29 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | ||
30 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
31 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
32 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | ||
33 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; | ||
34 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | ||
35 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; | ||
36 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
37 | import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; | ||
38 | |||
39 | /** | ||
40 | * A pattern-specific query specification that can instantiate Matcher in a type-safe way. | ||
41 | * | ||
42 | * <p>Original source: | ||
43 | * <code><pre> | ||
44 | * // | ||
45 | * // trainLocations | ||
46 | * // | ||
47 | * | ||
48 | * pattern trainLocations_step_2(in train : Train) { | ||
49 | * // frame-{@literal >}train = model-{@literal >}trains[i0]; | ||
50 | * // frame-{@literal >}location = frame-{@literal >}train-{@literal >}location; | ||
51 | * // if (frame-{@literal >}location != NULL) { | ||
52 | * // ... | ||
53 | * // } | ||
54 | * | ||
55 | * Train(train); | ||
56 | * } | ||
57 | * </pre></code> | ||
58 | * | ||
59 | * @see Matcher | ||
60 | * @see Match | ||
61 | * | ||
62 | */ | ||
63 | @SuppressWarnings("all") | ||
64 | public final class TrainLocations_step_2 extends BaseGeneratedEMFQuerySpecification<TrainLocations_step_2.Matcher> { | ||
65 | /** | ||
66 | * Pattern-specific match representation of the modes3.queries.trainLocations_step_2 pattern, | ||
67 | * to be used in conjunction with {@link Matcher}. | ||
68 | * | ||
69 | * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. | ||
70 | * Each instance is a (possibly partial) substitution of pattern parameters, | ||
71 | * usable to represent a match of the pattern in the result of a query, | ||
72 | * or to specify the bound (fixed) input parameters when issuing a query. | ||
73 | * | ||
74 | * @see Matcher | ||
75 | * | ||
76 | */ | ||
77 | public static abstract class Match extends BasePatternMatch { | ||
78 | private Train fTrain; | ||
79 | |||
80 | private static List<String> parameterNames = makeImmutableList("train"); | ||
81 | |||
82 | private Match(final Train pTrain) { | ||
83 | this.fTrain = pTrain; | ||
84 | } | ||
85 | |||
86 | @Override | ||
87 | public Object get(final String parameterName) { | ||
88 | switch(parameterName) { | ||
89 | case "train": return this.fTrain; | ||
90 | default: return null; | ||
91 | } | ||
92 | } | ||
93 | |||
94 | @Override | ||
95 | public Object get(final int index) { | ||
96 | switch(index) { | ||
97 | case 0: return this.fTrain; | ||
98 | default: return null; | ||
99 | } | ||
100 | } | ||
101 | |||
102 | public Train getTrain() { | ||
103 | return this.fTrain; | ||
104 | } | ||
105 | |||
106 | @Override | ||
107 | public boolean set(final String parameterName, final Object newValue) { | ||
108 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
109 | if ("train".equals(parameterName) ) { | ||
110 | this.fTrain = (Train) newValue; | ||
111 | return true; | ||
112 | } | ||
113 | return false; | ||
114 | } | ||
115 | |||
116 | public void setTrain(final Train pTrain) { | ||
117 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
118 | this.fTrain = pTrain; | ||
119 | } | ||
120 | |||
121 | @Override | ||
122 | public String patternName() { | ||
123 | return "modes3.queries.trainLocations_step_2"; | ||
124 | } | ||
125 | |||
126 | @Override | ||
127 | public List<String> parameterNames() { | ||
128 | return TrainLocations_step_2.Match.parameterNames; | ||
129 | } | ||
130 | |||
131 | @Override | ||
132 | public Object[] toArray() { | ||
133 | return new Object[]{fTrain}; | ||
134 | } | ||
135 | |||
136 | @Override | ||
137 | public TrainLocations_step_2.Match toImmutable() { | ||
138 | return isMutable() ? newMatch(fTrain) : this; | ||
139 | } | ||
140 | |||
141 | @Override | ||
142 | public String prettyPrint() { | ||
143 | StringBuilder result = new StringBuilder(); | ||
144 | result.append("\"train\"=" + prettyPrintValue(fTrain)); | ||
145 | return result.toString(); | ||
146 | } | ||
147 | |||
148 | @Override | ||
149 | public int hashCode() { | ||
150 | return Objects.hash(fTrain); | ||
151 | } | ||
152 | |||
153 | @Override | ||
154 | public boolean equals(final Object obj) { | ||
155 | if (this == obj) | ||
156 | return true; | ||
157 | if (obj == null) { | ||
158 | return false; | ||
159 | } | ||
160 | if ((obj instanceof TrainLocations_step_2.Match)) { | ||
161 | TrainLocations_step_2.Match other = (TrainLocations_step_2.Match) obj; | ||
162 | return Objects.equals(fTrain, other.fTrain); | ||
163 | } else { | ||
164 | // this should be infrequent | ||
165 | if (!(obj instanceof IPatternMatch)) { | ||
166 | return false; | ||
167 | } | ||
168 | IPatternMatch otherSig = (IPatternMatch) obj; | ||
169 | return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); | ||
170 | } | ||
171 | } | ||
172 | |||
173 | @Override | ||
174 | public TrainLocations_step_2 specification() { | ||
175 | return TrainLocations_step_2.instance(); | ||
176 | } | ||
177 | |||
178 | /** | ||
179 | * Returns an empty, mutable match. | ||
180 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
181 | * | ||
182 | * @return the empty match. | ||
183 | * | ||
184 | */ | ||
185 | public static TrainLocations_step_2.Match newEmptyMatch() { | ||
186 | return new Mutable(null); | ||
187 | } | ||
188 | |||
189 | /** | ||
190 | * Returns a mutable (partial) match. | ||
191 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
192 | * | ||
193 | * @param pTrain the fixed value of pattern parameter train, or null if not bound. | ||
194 | * @return the new, mutable (partial) match object. | ||
195 | * | ||
196 | */ | ||
197 | public static TrainLocations_step_2.Match newMutableMatch(final Train pTrain) { | ||
198 | return new Mutable(pTrain); | ||
199 | } | ||
200 | |||
201 | /** | ||
202 | * Returns a new (partial) match. | ||
203 | * This can be used e.g. to call the matcher with a partial match. | ||
204 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
205 | * @param pTrain the fixed value of pattern parameter train, or null if not bound. | ||
206 | * @return the (partial) match object. | ||
207 | * | ||
208 | */ | ||
209 | public static TrainLocations_step_2.Match newMatch(final Train pTrain) { | ||
210 | return new Immutable(pTrain); | ||
211 | } | ||
212 | |||
213 | private static final class Mutable extends TrainLocations_step_2.Match { | ||
214 | Mutable(final Train pTrain) { | ||
215 | super(pTrain); | ||
216 | } | ||
217 | |||
218 | @Override | ||
219 | public boolean isMutable() { | ||
220 | return true; | ||
221 | } | ||
222 | } | ||
223 | |||
224 | private static final class Immutable extends TrainLocations_step_2.Match { | ||
225 | Immutable(final Train pTrain) { | ||
226 | super(pTrain); | ||
227 | } | ||
228 | |||
229 | @Override | ||
230 | public boolean isMutable() { | ||
231 | return false; | ||
232 | } | ||
233 | } | ||
234 | } | ||
235 | |||
236 | /** | ||
237 | * Generated pattern matcher API of the modes3.queries.trainLocations_step_2 pattern, | ||
238 | * providing pattern-specific query methods. | ||
239 | * | ||
240 | * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, | ||
241 | * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. | ||
242 | * | ||
243 | * <p>Matches of the pattern will be represented as {@link Match}. | ||
244 | * | ||
245 | * <p>Original source: | ||
246 | * <code><pre> | ||
247 | * // | ||
248 | * // trainLocations | ||
249 | * // | ||
250 | * | ||
251 | * pattern trainLocations_step_2(in train : Train) { | ||
252 | * // frame-{@literal >}train = model-{@literal >}trains[i0]; | ||
253 | * // frame-{@literal >}location = frame-{@literal >}train-{@literal >}location; | ||
254 | * // if (frame-{@literal >}location != NULL) { | ||
255 | * // ... | ||
256 | * // } | ||
257 | * | ||
258 | * Train(train); | ||
259 | * } | ||
260 | * </pre></code> | ||
261 | * | ||
262 | * @see Match | ||
263 | * @see TrainLocations_step_2 | ||
264 | * | ||
265 | */ | ||
266 | public static class Matcher extends BaseMatcher<TrainLocations_step_2.Match> { | ||
267 | /** | ||
268 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
269 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
270 | * | ||
271 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
272 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
273 | * | ||
274 | */ | ||
275 | public static TrainLocations_step_2.Matcher on(final ViatraQueryEngine engine) { | ||
276 | // check if matcher already exists | ||
277 | Matcher matcher = engine.getExistingMatcher(querySpecification()); | ||
278 | if (matcher == null) { | ||
279 | matcher = (Matcher)engine.getMatcher(querySpecification()); | ||
280 | } | ||
281 | return matcher; | ||
282 | } | ||
283 | |||
284 | /** | ||
285 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
286 | * @return an initialized matcher | ||
287 | * @noreference This method is for internal matcher initialization by the framework, do not call it manually. | ||
288 | * | ||
289 | */ | ||
290 | public static TrainLocations_step_2.Matcher create() { | ||
291 | return new Matcher(); | ||
292 | } | ||
293 | |||
294 | private static final int POSITION_TRAIN = 0; | ||
295 | |||
296 | private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(TrainLocations_step_2.Matcher.class); | ||
297 | |||
298 | /** | ||
299 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
300 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
301 | * | ||
302 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
303 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
304 | * | ||
305 | */ | ||
306 | private Matcher() { | ||
307 | super(querySpecification()); | ||
308 | } | ||
309 | |||
310 | /** | ||
311 | * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. | ||
312 | * @param pTrain the fixed value of pattern parameter train, or null if not bound. | ||
313 | * @return matches represented as a Match object. | ||
314 | * | ||
315 | */ | ||
316 | public Collection<TrainLocations_step_2.Match> getAllMatches(final Train pTrain) { | ||
317 | return rawStreamAllMatches(new Object[]{pTrain}).collect(Collectors.toSet()); | ||
318 | } | ||
319 | |||
320 | /** | ||
321 | * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. | ||
322 | * </p> | ||
323 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
324 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
325 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
326 | * @param pTrain the fixed value of pattern parameter train, or null if not bound. | ||
327 | * @return a stream of matches represented as a Match object. | ||
328 | * | ||
329 | */ | ||
330 | public Stream<TrainLocations_step_2.Match> streamAllMatches(final Train pTrain) { | ||
331 | return rawStreamAllMatches(new Object[]{pTrain}); | ||
332 | } | ||
333 | |||
334 | /** | ||
335 | * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
336 | * Neither determinism nor randomness of selection is guaranteed. | ||
337 | * @param pTrain the fixed value of pattern parameter train, or null if not bound. | ||
338 | * @return a match represented as a Match object, or null if no match is found. | ||
339 | * | ||
340 | */ | ||
341 | public Optional<TrainLocations_step_2.Match> getOneArbitraryMatch(final Train pTrain) { | ||
342 | return rawGetOneArbitraryMatch(new Object[]{pTrain}); | ||
343 | } | ||
344 | |||
345 | /** | ||
346 | * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, | ||
347 | * under any possible substitution of the unspecified parameters (if any). | ||
348 | * @param pTrain the fixed value of pattern parameter train, or null if not bound. | ||
349 | * @return true if the input is a valid (partial) match of the pattern. | ||
350 | * | ||
351 | */ | ||
352 | public boolean hasMatch(final Train pTrain) { | ||
353 | return rawHasMatch(new Object[]{pTrain}); | ||
354 | } | ||
355 | |||
356 | /** | ||
357 | * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. | ||
358 | * @param pTrain the fixed value of pattern parameter train, or null if not bound. | ||
359 | * @return the number of pattern matches found. | ||
360 | * | ||
361 | */ | ||
362 | public int countMatches(final Train pTrain) { | ||
363 | return rawCountMatches(new Object[]{pTrain}); | ||
364 | } | ||
365 | |||
366 | /** | ||
367 | * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
368 | * Neither determinism nor randomness of selection is guaranteed. | ||
369 | * @param pTrain the fixed value of pattern parameter train, or null if not bound. | ||
370 | * @param processor the action that will process the selected match. | ||
371 | * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked | ||
372 | * | ||
373 | */ | ||
374 | public boolean forOneArbitraryMatch(final Train pTrain, final Consumer<? super TrainLocations_step_2.Match> processor) { | ||
375 | return rawForOneArbitraryMatch(new Object[]{pTrain}, processor); | ||
376 | } | ||
377 | |||
378 | /** | ||
379 | * Returns a new (partial) match. | ||
380 | * This can be used e.g. to call the matcher with a partial match. | ||
381 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
382 | * @param pTrain the fixed value of pattern parameter train, or null if not bound. | ||
383 | * @return the (partial) match object. | ||
384 | * | ||
385 | */ | ||
386 | public TrainLocations_step_2.Match newMatch(final Train pTrain) { | ||
387 | return TrainLocations_step_2.Match.newMatch(pTrain); | ||
388 | } | ||
389 | |||
390 | /** | ||
391 | * Retrieve the set of values that occur in matches for train. | ||
392 | * @return the Set of all values or empty set if there are no matches | ||
393 | * | ||
394 | */ | ||
395 | protected Stream<Train> rawStreamAllValuesOftrain(final Object[] parameters) { | ||
396 | return rawStreamAllValues(POSITION_TRAIN, parameters).map(Train.class::cast); | ||
397 | } | ||
398 | |||
399 | /** | ||
400 | * Retrieve the set of values that occur in matches for train. | ||
401 | * @return the Set of all values or empty set if there are no matches | ||
402 | * | ||
403 | */ | ||
404 | public Set<Train> getAllValuesOftrain() { | ||
405 | return rawStreamAllValuesOftrain(emptyArray()).collect(Collectors.toSet()); | ||
406 | } | ||
407 | |||
408 | /** | ||
409 | * Retrieve the set of values that occur in matches for train. | ||
410 | * @return the Set of all values or empty set if there are no matches | ||
411 | * | ||
412 | */ | ||
413 | public Stream<Train> streamAllValuesOftrain() { | ||
414 | return rawStreamAllValuesOftrain(emptyArray()); | ||
415 | } | ||
416 | |||
417 | @Override | ||
418 | protected TrainLocations_step_2.Match tupleToMatch(final Tuple t) { | ||
419 | try { | ||
420 | return TrainLocations_step_2.Match.newMatch((Train) t.get(POSITION_TRAIN)); | ||
421 | } catch(ClassCastException e) { | ||
422 | LOGGER.error("Element(s) in tuple not properly typed!",e); | ||
423 | return null; | ||
424 | } | ||
425 | } | ||
426 | |||
427 | @Override | ||
428 | protected TrainLocations_step_2.Match arrayToMatch(final Object[] match) { | ||
429 | try { | ||
430 | return TrainLocations_step_2.Match.newMatch((Train) match[POSITION_TRAIN]); | ||
431 | } catch(ClassCastException e) { | ||
432 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
433 | return null; | ||
434 | } | ||
435 | } | ||
436 | |||
437 | @Override | ||
438 | protected TrainLocations_step_2.Match arrayToMatchMutable(final Object[] match) { | ||
439 | try { | ||
440 | return TrainLocations_step_2.Match.newMutableMatch((Train) match[POSITION_TRAIN]); | ||
441 | } catch(ClassCastException e) { | ||
442 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
443 | return null; | ||
444 | } | ||
445 | } | ||
446 | |||
447 | /** | ||
448 | * @return the singleton instance of the query specification of this pattern | ||
449 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
450 | * | ||
451 | */ | ||
452 | public static IQuerySpecification<TrainLocations_step_2.Matcher> querySpecification() { | ||
453 | return TrainLocations_step_2.instance(); | ||
454 | } | ||
455 | } | ||
456 | |||
457 | private TrainLocations_step_2() { | ||
458 | super(GeneratedPQuery.INSTANCE); | ||
459 | } | ||
460 | |||
461 | /** | ||
462 | * @return the singleton instance of the query specification | ||
463 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
464 | * | ||
465 | */ | ||
466 | public static TrainLocations_step_2 instance() { | ||
467 | try{ | ||
468 | return LazyHolder.INSTANCE; | ||
469 | } catch (ExceptionInInitializerError err) { | ||
470 | throw processInitializerError(err); | ||
471 | } | ||
472 | } | ||
473 | |||
474 | @Override | ||
475 | protected TrainLocations_step_2.Matcher instantiate(final ViatraQueryEngine engine) { | ||
476 | return TrainLocations_step_2.Matcher.on(engine); | ||
477 | } | ||
478 | |||
479 | @Override | ||
480 | public TrainLocations_step_2.Matcher instantiate() { | ||
481 | return TrainLocations_step_2.Matcher.create(); | ||
482 | } | ||
483 | |||
484 | @Override | ||
485 | public TrainLocations_step_2.Match newEmptyMatch() { | ||
486 | return TrainLocations_step_2.Match.newEmptyMatch(); | ||
487 | } | ||
488 | |||
489 | @Override | ||
490 | public TrainLocations_step_2.Match newMatch(final Object... parameters) { | ||
491 | return TrainLocations_step_2.Match.newMatch((modes3.Train) parameters[0]); | ||
492 | } | ||
493 | |||
494 | /** | ||
495 | * Inner class allowing the singleton instance of {@link TrainLocations_step_2} to be created | ||
496 | * <b>not</b> at the class load time of the outer class, | ||
497 | * but rather at the first call to {@link TrainLocations_step_2#instance()}. | ||
498 | * | ||
499 | * <p> This workaround is required e.g. to support recursion. | ||
500 | * | ||
501 | */ | ||
502 | private static class LazyHolder { | ||
503 | private static final TrainLocations_step_2 INSTANCE = new TrainLocations_step_2(); | ||
504 | |||
505 | /** | ||
506 | * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned. | ||
507 | * This initialization order is required to support indirect recursion. | ||
508 | * | ||
509 | * <p> The static initializer is defined using a helper field to work around limitations of the code generator. | ||
510 | * | ||
511 | */ | ||
512 | private static final Object STATIC_INITIALIZER = ensureInitialized(); | ||
513 | |||
514 | public static Object ensureInitialized() { | ||
515 | INSTANCE.ensureInitializedInternal(); | ||
516 | return null; | ||
517 | } | ||
518 | } | ||
519 | |||
520 | private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { | ||
521 | private static final TrainLocations_step_2.GeneratedPQuery INSTANCE = new GeneratedPQuery(); | ||
522 | |||
523 | private final PParameter parameter_train = new PParameter("train", "modes3.Train", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Train")), PParameterDirection.INOUT); | ||
524 | |||
525 | private final List<PParameter> parameters = Arrays.asList(parameter_train); | ||
526 | |||
527 | private GeneratedPQuery() { | ||
528 | super(PVisibility.PUBLIC); | ||
529 | } | ||
530 | |||
531 | @Override | ||
532 | public String getFullyQualifiedName() { | ||
533 | return "modes3.queries.trainLocations_step_2"; | ||
534 | } | ||
535 | |||
536 | @Override | ||
537 | public List<String> getParameterNames() { | ||
538 | return Arrays.asList("train"); | ||
539 | } | ||
540 | |||
541 | @Override | ||
542 | public List<PParameter> getParameters() { | ||
543 | return parameters; | ||
544 | } | ||
545 | |||
546 | @Override | ||
547 | public Set<PBody> doGetContainedBodies() { | ||
548 | setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); | ||
549 | Set<PBody> bodies = new LinkedHashSet<>(); | ||
550 | { | ||
551 | PBody body = new PBody(this); | ||
552 | PVariable var_train = body.getOrCreateVariableByName("train"); | ||
553 | new TypeConstraint(body, Tuples.flatTupleOf(var_train), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Train"))); | ||
554 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
555 | new ExportedParameter(body, var_train, parameter_train) | ||
556 | )); | ||
557 | // // frame->train = model->trains[i0];// frame->location = frame->train->location;// if (frame->location != NULL) {// ...// } Train(train) | ||
558 | new TypeConstraint(body, Tuples.flatTupleOf(var_train), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Train"))); | ||
559 | bodies.add(body); | ||
560 | } | ||
561 | return bodies; | ||
562 | } | ||
563 | } | ||
564 | } | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/TrainLocations_step_3.java b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/TrainLocations_step_3.java new file mode 100644 index 00000000..edbd4af3 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/TrainLocations_step_3.java | |||
@@ -0,0 +1,713 @@ | |||
1 | /** | ||
2 | * Generated from platform:/resource/ca.mcgill.rtgmrt.example.modes3/src/modes3/queries/Modes3Queries.vql | ||
3 | */ | ||
4 | package modes3.queries; | ||
5 | |||
6 | import java.util.Arrays; | ||
7 | import java.util.Collection; | ||
8 | import java.util.LinkedHashSet; | ||
9 | import java.util.List; | ||
10 | import java.util.Objects; | ||
11 | import java.util.Optional; | ||
12 | import java.util.Set; | ||
13 | import java.util.function.Consumer; | ||
14 | import java.util.stream.Collectors; | ||
15 | import java.util.stream.Stream; | ||
16 | import modes3.Segment; | ||
17 | import modes3.Train; | ||
18 | import org.apache.log4j.Logger; | ||
19 | import org.eclipse.emf.ecore.EClass; | ||
20 | import org.eclipse.viatra.query.runtime.api.IPatternMatch; | ||
21 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification; | ||
22 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; | ||
23 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; | ||
24 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; | ||
25 | import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; | ||
26 | import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; | ||
27 | import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; | ||
28 | import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; | ||
29 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
30 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | ||
31 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | ||
32 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; | ||
33 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
34 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
35 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | ||
36 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; | ||
37 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | ||
38 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; | ||
39 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
40 | import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; | ||
41 | |||
42 | /** | ||
43 | * A pattern-specific query specification that can instantiate Matcher in a type-safe way. | ||
44 | * | ||
45 | * <p>Original source: | ||
46 | * <code><pre> | ||
47 | * pattern trainLocations_step_3(in train : Train, in location : Segment) { | ||
48 | * // results-{@literal >}matches[match_cntr].location = frame-{@literal >}location; | ||
49 | * // results-{@literal >}matches[match_cntr++].train = frame-{@literal >}train; | ||
50 | * Train(train); | ||
51 | * Train.location(train, location); | ||
52 | * } | ||
53 | * </pre></code> | ||
54 | * | ||
55 | * @see Matcher | ||
56 | * @see Match | ||
57 | * | ||
58 | */ | ||
59 | @SuppressWarnings("all") | ||
60 | public final class TrainLocations_step_3 extends BaseGeneratedEMFQuerySpecification<TrainLocations_step_3.Matcher> { | ||
61 | /** | ||
62 | * Pattern-specific match representation of the modes3.queries.trainLocations_step_3 pattern, | ||
63 | * to be used in conjunction with {@link Matcher}. | ||
64 | * | ||
65 | * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. | ||
66 | * Each instance is a (possibly partial) substitution of pattern parameters, | ||
67 | * usable to represent a match of the pattern in the result of a query, | ||
68 | * or to specify the bound (fixed) input parameters when issuing a query. | ||
69 | * | ||
70 | * @see Matcher | ||
71 | * | ||
72 | */ | ||
73 | public static abstract class Match extends BasePatternMatch { | ||
74 | private Train fTrain; | ||
75 | |||
76 | private Segment fLocation; | ||
77 | |||
78 | private static List<String> parameterNames = makeImmutableList("train", "location"); | ||
79 | |||
80 | private Match(final Train pTrain, final Segment pLocation) { | ||
81 | this.fTrain = pTrain; | ||
82 | this.fLocation = pLocation; | ||
83 | } | ||
84 | |||
85 | @Override | ||
86 | public Object get(final String parameterName) { | ||
87 | switch(parameterName) { | ||
88 | case "train": return this.fTrain; | ||
89 | case "location": return this.fLocation; | ||
90 | default: return null; | ||
91 | } | ||
92 | } | ||
93 | |||
94 | @Override | ||
95 | public Object get(final int index) { | ||
96 | switch(index) { | ||
97 | case 0: return this.fTrain; | ||
98 | case 1: return this.fLocation; | ||
99 | default: return null; | ||
100 | } | ||
101 | } | ||
102 | |||
103 | public Train getTrain() { | ||
104 | return this.fTrain; | ||
105 | } | ||
106 | |||
107 | public Segment getLocation() { | ||
108 | return this.fLocation; | ||
109 | } | ||
110 | |||
111 | @Override | ||
112 | public boolean set(final String parameterName, final Object newValue) { | ||
113 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
114 | if ("train".equals(parameterName) ) { | ||
115 | this.fTrain = (Train) newValue; | ||
116 | return true; | ||
117 | } | ||
118 | if ("location".equals(parameterName) ) { | ||
119 | this.fLocation = (Segment) newValue; | ||
120 | return true; | ||
121 | } | ||
122 | return false; | ||
123 | } | ||
124 | |||
125 | public void setTrain(final Train pTrain) { | ||
126 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
127 | this.fTrain = pTrain; | ||
128 | } | ||
129 | |||
130 | public void setLocation(final Segment pLocation) { | ||
131 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
132 | this.fLocation = pLocation; | ||
133 | } | ||
134 | |||
135 | @Override | ||
136 | public String patternName() { | ||
137 | return "modes3.queries.trainLocations_step_3"; | ||
138 | } | ||
139 | |||
140 | @Override | ||
141 | public List<String> parameterNames() { | ||
142 | return TrainLocations_step_3.Match.parameterNames; | ||
143 | } | ||
144 | |||
145 | @Override | ||
146 | public Object[] toArray() { | ||
147 | return new Object[]{fTrain, fLocation}; | ||
148 | } | ||
149 | |||
150 | @Override | ||
151 | public TrainLocations_step_3.Match toImmutable() { | ||
152 | return isMutable() ? newMatch(fTrain, fLocation) : this; | ||
153 | } | ||
154 | |||
155 | @Override | ||
156 | public String prettyPrint() { | ||
157 | StringBuilder result = new StringBuilder(); | ||
158 | result.append("\"train\"=" + prettyPrintValue(fTrain) + ", "); | ||
159 | result.append("\"location\"=" + prettyPrintValue(fLocation)); | ||
160 | return result.toString(); | ||
161 | } | ||
162 | |||
163 | @Override | ||
164 | public int hashCode() { | ||
165 | return Objects.hash(fTrain, fLocation); | ||
166 | } | ||
167 | |||
168 | @Override | ||
169 | public boolean equals(final Object obj) { | ||
170 | if (this == obj) | ||
171 | return true; | ||
172 | if (obj == null) { | ||
173 | return false; | ||
174 | } | ||
175 | if ((obj instanceof TrainLocations_step_3.Match)) { | ||
176 | TrainLocations_step_3.Match other = (TrainLocations_step_3.Match) obj; | ||
177 | return Objects.equals(fTrain, other.fTrain) && Objects.equals(fLocation, other.fLocation); | ||
178 | } else { | ||
179 | // this should be infrequent | ||
180 | if (!(obj instanceof IPatternMatch)) { | ||
181 | return false; | ||
182 | } | ||
183 | IPatternMatch otherSig = (IPatternMatch) obj; | ||
184 | return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); | ||
185 | } | ||
186 | } | ||
187 | |||
188 | @Override | ||
189 | public TrainLocations_step_3 specification() { | ||
190 | return TrainLocations_step_3.instance(); | ||
191 | } | ||
192 | |||
193 | /** | ||
194 | * Returns an empty, mutable match. | ||
195 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
196 | * | ||
197 | * @return the empty match. | ||
198 | * | ||
199 | */ | ||
200 | public static TrainLocations_step_3.Match newEmptyMatch() { | ||
201 | return new Mutable(null, null); | ||
202 | } | ||
203 | |||
204 | /** | ||
205 | * Returns a mutable (partial) match. | ||
206 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
207 | * | ||
208 | * @param pTrain the fixed value of pattern parameter train, or null if not bound. | ||
209 | * @param pLocation the fixed value of pattern parameter location, or null if not bound. | ||
210 | * @return the new, mutable (partial) match object. | ||
211 | * | ||
212 | */ | ||
213 | public static TrainLocations_step_3.Match newMutableMatch(final Train pTrain, final Segment pLocation) { | ||
214 | return new Mutable(pTrain, pLocation); | ||
215 | } | ||
216 | |||
217 | /** | ||
218 | * Returns a new (partial) match. | ||
219 | * This can be used e.g. to call the matcher with a partial match. | ||
220 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
221 | * @param pTrain the fixed value of pattern parameter train, or null if not bound. | ||
222 | * @param pLocation the fixed value of pattern parameter location, or null if not bound. | ||
223 | * @return the (partial) match object. | ||
224 | * | ||
225 | */ | ||
226 | public static TrainLocations_step_3.Match newMatch(final Train pTrain, final Segment pLocation) { | ||
227 | return new Immutable(pTrain, pLocation); | ||
228 | } | ||
229 | |||
230 | private static final class Mutable extends TrainLocations_step_3.Match { | ||
231 | Mutable(final Train pTrain, final Segment pLocation) { | ||
232 | super(pTrain, pLocation); | ||
233 | } | ||
234 | |||
235 | @Override | ||
236 | public boolean isMutable() { | ||
237 | return true; | ||
238 | } | ||
239 | } | ||
240 | |||
241 | private static final class Immutable extends TrainLocations_step_3.Match { | ||
242 | Immutable(final Train pTrain, final Segment pLocation) { | ||
243 | super(pTrain, pLocation); | ||
244 | } | ||
245 | |||
246 | @Override | ||
247 | public boolean isMutable() { | ||
248 | return false; | ||
249 | } | ||
250 | } | ||
251 | } | ||
252 | |||
253 | /** | ||
254 | * Generated pattern matcher API of the modes3.queries.trainLocations_step_3 pattern, | ||
255 | * providing pattern-specific query methods. | ||
256 | * | ||
257 | * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, | ||
258 | * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. | ||
259 | * | ||
260 | * <p>Matches of the pattern will be represented as {@link Match}. | ||
261 | * | ||
262 | * <p>Original source: | ||
263 | * <code><pre> | ||
264 | * pattern trainLocations_step_3(in train : Train, in location : Segment) { | ||
265 | * // results-{@literal >}matches[match_cntr].location = frame-{@literal >}location; | ||
266 | * // results-{@literal >}matches[match_cntr++].train = frame-{@literal >}train; | ||
267 | * Train(train); | ||
268 | * Train.location(train, location); | ||
269 | * } | ||
270 | * </pre></code> | ||
271 | * | ||
272 | * @see Match | ||
273 | * @see TrainLocations_step_3 | ||
274 | * | ||
275 | */ | ||
276 | public static class Matcher extends BaseMatcher<TrainLocations_step_3.Match> { | ||
277 | /** | ||
278 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
279 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
280 | * | ||
281 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
282 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
283 | * | ||
284 | */ | ||
285 | public static TrainLocations_step_3.Matcher on(final ViatraQueryEngine engine) { | ||
286 | // check if matcher already exists | ||
287 | Matcher matcher = engine.getExistingMatcher(querySpecification()); | ||
288 | if (matcher == null) { | ||
289 | matcher = (Matcher)engine.getMatcher(querySpecification()); | ||
290 | } | ||
291 | return matcher; | ||
292 | } | ||
293 | |||
294 | /** | ||
295 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
296 | * @return an initialized matcher | ||
297 | * @noreference This method is for internal matcher initialization by the framework, do not call it manually. | ||
298 | * | ||
299 | */ | ||
300 | public static TrainLocations_step_3.Matcher create() { | ||
301 | return new Matcher(); | ||
302 | } | ||
303 | |||
304 | private static final int POSITION_TRAIN = 0; | ||
305 | |||
306 | private static final int POSITION_LOCATION = 1; | ||
307 | |||
308 | private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(TrainLocations_step_3.Matcher.class); | ||
309 | |||
310 | /** | ||
311 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
312 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
313 | * | ||
314 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
315 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
316 | * | ||
317 | */ | ||
318 | private Matcher() { | ||
319 | super(querySpecification()); | ||
320 | } | ||
321 | |||
322 | /** | ||
323 | * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. | ||
324 | * @param pTrain the fixed value of pattern parameter train, or null if not bound. | ||
325 | * @param pLocation the fixed value of pattern parameter location, or null if not bound. | ||
326 | * @return matches represented as a Match object. | ||
327 | * | ||
328 | */ | ||
329 | public Collection<TrainLocations_step_3.Match> getAllMatches(final Train pTrain, final Segment pLocation) { | ||
330 | return rawStreamAllMatches(new Object[]{pTrain, pLocation}).collect(Collectors.toSet()); | ||
331 | } | ||
332 | |||
333 | /** | ||
334 | * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. | ||
335 | * </p> | ||
336 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
337 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
338 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
339 | * @param pTrain the fixed value of pattern parameter train, or null if not bound. | ||
340 | * @param pLocation the fixed value of pattern parameter location, or null if not bound. | ||
341 | * @return a stream of matches represented as a Match object. | ||
342 | * | ||
343 | */ | ||
344 | public Stream<TrainLocations_step_3.Match> streamAllMatches(final Train pTrain, final Segment pLocation) { | ||
345 | return rawStreamAllMatches(new Object[]{pTrain, pLocation}); | ||
346 | } | ||
347 | |||
348 | /** | ||
349 | * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
350 | * Neither determinism nor randomness of selection is guaranteed. | ||
351 | * @param pTrain the fixed value of pattern parameter train, or null if not bound. | ||
352 | * @param pLocation the fixed value of pattern parameter location, or null if not bound. | ||
353 | * @return a match represented as a Match object, or null if no match is found. | ||
354 | * | ||
355 | */ | ||
356 | public Optional<TrainLocations_step_3.Match> getOneArbitraryMatch(final Train pTrain, final Segment pLocation) { | ||
357 | return rawGetOneArbitraryMatch(new Object[]{pTrain, pLocation}); | ||
358 | } | ||
359 | |||
360 | /** | ||
361 | * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, | ||
362 | * under any possible substitution of the unspecified parameters (if any). | ||
363 | * @param pTrain the fixed value of pattern parameter train, or null if not bound. | ||
364 | * @param pLocation the fixed value of pattern parameter location, or null if not bound. | ||
365 | * @return true if the input is a valid (partial) match of the pattern. | ||
366 | * | ||
367 | */ | ||
368 | public boolean hasMatch(final Train pTrain, final Segment pLocation) { | ||
369 | return rawHasMatch(new Object[]{pTrain, pLocation}); | ||
370 | } | ||
371 | |||
372 | /** | ||
373 | * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. | ||
374 | * @param pTrain the fixed value of pattern parameter train, or null if not bound. | ||
375 | * @param pLocation the fixed value of pattern parameter location, or null if not bound. | ||
376 | * @return the number of pattern matches found. | ||
377 | * | ||
378 | */ | ||
379 | public int countMatches(final Train pTrain, final Segment pLocation) { | ||
380 | return rawCountMatches(new Object[]{pTrain, pLocation}); | ||
381 | } | ||
382 | |||
383 | /** | ||
384 | * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
385 | * Neither determinism nor randomness of selection is guaranteed. | ||
386 | * @param pTrain the fixed value of pattern parameter train, or null if not bound. | ||
387 | * @param pLocation the fixed value of pattern parameter location, or null if not bound. | ||
388 | * @param processor the action that will process the selected match. | ||
389 | * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked | ||
390 | * | ||
391 | */ | ||
392 | public boolean forOneArbitraryMatch(final Train pTrain, final Segment pLocation, final Consumer<? super TrainLocations_step_3.Match> processor) { | ||
393 | return rawForOneArbitraryMatch(new Object[]{pTrain, pLocation}, processor); | ||
394 | } | ||
395 | |||
396 | /** | ||
397 | * Returns a new (partial) match. | ||
398 | * This can be used e.g. to call the matcher with a partial match. | ||
399 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
400 | * @param pTrain the fixed value of pattern parameter train, or null if not bound. | ||
401 | * @param pLocation the fixed value of pattern parameter location, or null if not bound. | ||
402 | * @return the (partial) match object. | ||
403 | * | ||
404 | */ | ||
405 | public TrainLocations_step_3.Match newMatch(final Train pTrain, final Segment pLocation) { | ||
406 | return TrainLocations_step_3.Match.newMatch(pTrain, pLocation); | ||
407 | } | ||
408 | |||
409 | /** | ||
410 | * Retrieve the set of values that occur in matches for train. | ||
411 | * @return the Set of all values or empty set if there are no matches | ||
412 | * | ||
413 | */ | ||
414 | protected Stream<Train> rawStreamAllValuesOftrain(final Object[] parameters) { | ||
415 | return rawStreamAllValues(POSITION_TRAIN, parameters).map(Train.class::cast); | ||
416 | } | ||
417 | |||
418 | /** | ||
419 | * Retrieve the set of values that occur in matches for train. | ||
420 | * @return the Set of all values or empty set if there are no matches | ||
421 | * | ||
422 | */ | ||
423 | public Set<Train> getAllValuesOftrain() { | ||
424 | return rawStreamAllValuesOftrain(emptyArray()).collect(Collectors.toSet()); | ||
425 | } | ||
426 | |||
427 | /** | ||
428 | * Retrieve the set of values that occur in matches for train. | ||
429 | * @return the Set of all values or empty set if there are no matches | ||
430 | * | ||
431 | */ | ||
432 | public Stream<Train> streamAllValuesOftrain() { | ||
433 | return rawStreamAllValuesOftrain(emptyArray()); | ||
434 | } | ||
435 | |||
436 | /** | ||
437 | * Retrieve the set of values that occur in matches for train. | ||
438 | * </p> | ||
439 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
440 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
441 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
442 | * | ||
443 | * @return the Stream of all values or empty set if there are no matches | ||
444 | * | ||
445 | */ | ||
446 | public Stream<Train> streamAllValuesOftrain(final TrainLocations_step_3.Match partialMatch) { | ||
447 | return rawStreamAllValuesOftrain(partialMatch.toArray()); | ||
448 | } | ||
449 | |||
450 | /** | ||
451 | * Retrieve the set of values that occur in matches for train. | ||
452 | * </p> | ||
453 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
454 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
455 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
456 | * | ||
457 | * @return the Stream of all values or empty set if there are no matches | ||
458 | * | ||
459 | */ | ||
460 | public Stream<Train> streamAllValuesOftrain(final Segment pLocation) { | ||
461 | return rawStreamAllValuesOftrain(new Object[]{null, pLocation}); | ||
462 | } | ||
463 | |||
464 | /** | ||
465 | * Retrieve the set of values that occur in matches for train. | ||
466 | * @return the Set of all values or empty set if there are no matches | ||
467 | * | ||
468 | */ | ||
469 | public Set<Train> getAllValuesOftrain(final TrainLocations_step_3.Match partialMatch) { | ||
470 | return rawStreamAllValuesOftrain(partialMatch.toArray()).collect(Collectors.toSet()); | ||
471 | } | ||
472 | |||
473 | /** | ||
474 | * Retrieve the set of values that occur in matches for train. | ||
475 | * @return the Set of all values or empty set if there are no matches | ||
476 | * | ||
477 | */ | ||
478 | public Set<Train> getAllValuesOftrain(final Segment pLocation) { | ||
479 | return rawStreamAllValuesOftrain(new Object[]{null, pLocation}).collect(Collectors.toSet()); | ||
480 | } | ||
481 | |||
482 | /** | ||
483 | * Retrieve the set of values that occur in matches for location. | ||
484 | * @return the Set of all values or empty set if there are no matches | ||
485 | * | ||
486 | */ | ||
487 | protected Stream<Segment> rawStreamAllValuesOflocation(final Object[] parameters) { | ||
488 | return rawStreamAllValues(POSITION_LOCATION, parameters).map(Segment.class::cast); | ||
489 | } | ||
490 | |||
491 | /** | ||
492 | * Retrieve the set of values that occur in matches for location. | ||
493 | * @return the Set of all values or empty set if there are no matches | ||
494 | * | ||
495 | */ | ||
496 | public Set<Segment> getAllValuesOflocation() { | ||
497 | return rawStreamAllValuesOflocation(emptyArray()).collect(Collectors.toSet()); | ||
498 | } | ||
499 | |||
500 | /** | ||
501 | * Retrieve the set of values that occur in matches for location. | ||
502 | * @return the Set of all values or empty set if there are no matches | ||
503 | * | ||
504 | */ | ||
505 | public Stream<Segment> streamAllValuesOflocation() { | ||
506 | return rawStreamAllValuesOflocation(emptyArray()); | ||
507 | } | ||
508 | |||
509 | /** | ||
510 | * Retrieve the set of values that occur in matches for location. | ||
511 | * </p> | ||
512 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
513 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
514 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
515 | * | ||
516 | * @return the Stream of all values or empty set if there are no matches | ||
517 | * | ||
518 | */ | ||
519 | public Stream<Segment> streamAllValuesOflocation(final TrainLocations_step_3.Match partialMatch) { | ||
520 | return rawStreamAllValuesOflocation(partialMatch.toArray()); | ||
521 | } | ||
522 | |||
523 | /** | ||
524 | * Retrieve the set of values that occur in matches for location. | ||
525 | * </p> | ||
526 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
527 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
528 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
529 | * | ||
530 | * @return the Stream of all values or empty set if there are no matches | ||
531 | * | ||
532 | */ | ||
533 | public Stream<Segment> streamAllValuesOflocation(final Train pTrain) { | ||
534 | return rawStreamAllValuesOflocation(new Object[]{pTrain, null}); | ||
535 | } | ||
536 | |||
537 | /** | ||
538 | * Retrieve the set of values that occur in matches for location. | ||
539 | * @return the Set of all values or empty set if there are no matches | ||
540 | * | ||
541 | */ | ||
542 | public Set<Segment> getAllValuesOflocation(final TrainLocations_step_3.Match partialMatch) { | ||
543 | return rawStreamAllValuesOflocation(partialMatch.toArray()).collect(Collectors.toSet()); | ||
544 | } | ||
545 | |||
546 | /** | ||
547 | * Retrieve the set of values that occur in matches for location. | ||
548 | * @return the Set of all values or empty set if there are no matches | ||
549 | * | ||
550 | */ | ||
551 | public Set<Segment> getAllValuesOflocation(final Train pTrain) { | ||
552 | return rawStreamAllValuesOflocation(new Object[]{pTrain, null}).collect(Collectors.toSet()); | ||
553 | } | ||
554 | |||
555 | @Override | ||
556 | protected TrainLocations_step_3.Match tupleToMatch(final Tuple t) { | ||
557 | try { | ||
558 | return TrainLocations_step_3.Match.newMatch((Train) t.get(POSITION_TRAIN), (Segment) t.get(POSITION_LOCATION)); | ||
559 | } catch(ClassCastException e) { | ||
560 | LOGGER.error("Element(s) in tuple not properly typed!",e); | ||
561 | return null; | ||
562 | } | ||
563 | } | ||
564 | |||
565 | @Override | ||
566 | protected TrainLocations_step_3.Match arrayToMatch(final Object[] match) { | ||
567 | try { | ||
568 | return TrainLocations_step_3.Match.newMatch((Train) match[POSITION_TRAIN], (Segment) match[POSITION_LOCATION]); | ||
569 | } catch(ClassCastException e) { | ||
570 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
571 | return null; | ||
572 | } | ||
573 | } | ||
574 | |||
575 | @Override | ||
576 | protected TrainLocations_step_3.Match arrayToMatchMutable(final Object[] match) { | ||
577 | try { | ||
578 | return TrainLocations_step_3.Match.newMutableMatch((Train) match[POSITION_TRAIN], (Segment) match[POSITION_LOCATION]); | ||
579 | } catch(ClassCastException e) { | ||
580 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
581 | return null; | ||
582 | } | ||
583 | } | ||
584 | |||
585 | /** | ||
586 | * @return the singleton instance of the query specification of this pattern | ||
587 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
588 | * | ||
589 | */ | ||
590 | public static IQuerySpecification<TrainLocations_step_3.Matcher> querySpecification() { | ||
591 | return TrainLocations_step_3.instance(); | ||
592 | } | ||
593 | } | ||
594 | |||
595 | private TrainLocations_step_3() { | ||
596 | super(GeneratedPQuery.INSTANCE); | ||
597 | } | ||
598 | |||
599 | /** | ||
600 | * @return the singleton instance of the query specification | ||
601 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
602 | * | ||
603 | */ | ||
604 | public static TrainLocations_step_3 instance() { | ||
605 | try{ | ||
606 | return LazyHolder.INSTANCE; | ||
607 | } catch (ExceptionInInitializerError err) { | ||
608 | throw processInitializerError(err); | ||
609 | } | ||
610 | } | ||
611 | |||
612 | @Override | ||
613 | protected TrainLocations_step_3.Matcher instantiate(final ViatraQueryEngine engine) { | ||
614 | return TrainLocations_step_3.Matcher.on(engine); | ||
615 | } | ||
616 | |||
617 | @Override | ||
618 | public TrainLocations_step_3.Matcher instantiate() { | ||
619 | return TrainLocations_step_3.Matcher.create(); | ||
620 | } | ||
621 | |||
622 | @Override | ||
623 | public TrainLocations_step_3.Match newEmptyMatch() { | ||
624 | return TrainLocations_step_3.Match.newEmptyMatch(); | ||
625 | } | ||
626 | |||
627 | @Override | ||
628 | public TrainLocations_step_3.Match newMatch(final Object... parameters) { | ||
629 | return TrainLocations_step_3.Match.newMatch((modes3.Train) parameters[0], (modes3.Segment) parameters[1]); | ||
630 | } | ||
631 | |||
632 | /** | ||
633 | * Inner class allowing the singleton instance of {@link TrainLocations_step_3} to be created | ||
634 | * <b>not</b> at the class load time of the outer class, | ||
635 | * but rather at the first call to {@link TrainLocations_step_3#instance()}. | ||
636 | * | ||
637 | * <p> This workaround is required e.g. to support recursion. | ||
638 | * | ||
639 | */ | ||
640 | private static class LazyHolder { | ||
641 | private static final TrainLocations_step_3 INSTANCE = new TrainLocations_step_3(); | ||
642 | |||
643 | /** | ||
644 | * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned. | ||
645 | * This initialization order is required to support indirect recursion. | ||
646 | * | ||
647 | * <p> The static initializer is defined using a helper field to work around limitations of the code generator. | ||
648 | * | ||
649 | */ | ||
650 | private static final Object STATIC_INITIALIZER = ensureInitialized(); | ||
651 | |||
652 | public static Object ensureInitialized() { | ||
653 | INSTANCE.ensureInitializedInternal(); | ||
654 | return null; | ||
655 | } | ||
656 | } | ||
657 | |||
658 | private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { | ||
659 | private static final TrainLocations_step_3.GeneratedPQuery INSTANCE = new GeneratedPQuery(); | ||
660 | |||
661 | private final PParameter parameter_train = new PParameter("train", "modes3.Train", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Train")), PParameterDirection.INOUT); | ||
662 | |||
663 | private final PParameter parameter_location = new PParameter("location", "modes3.Segment", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Segment")), PParameterDirection.INOUT); | ||
664 | |||
665 | private final List<PParameter> parameters = Arrays.asList(parameter_train, parameter_location); | ||
666 | |||
667 | private GeneratedPQuery() { | ||
668 | super(PVisibility.PUBLIC); | ||
669 | } | ||
670 | |||
671 | @Override | ||
672 | public String getFullyQualifiedName() { | ||
673 | return "modes3.queries.trainLocations_step_3"; | ||
674 | } | ||
675 | |||
676 | @Override | ||
677 | public List<String> getParameterNames() { | ||
678 | return Arrays.asList("train","location"); | ||
679 | } | ||
680 | |||
681 | @Override | ||
682 | public List<PParameter> getParameters() { | ||
683 | return parameters; | ||
684 | } | ||
685 | |||
686 | @Override | ||
687 | public Set<PBody> doGetContainedBodies() { | ||
688 | setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); | ||
689 | Set<PBody> bodies = new LinkedHashSet<>(); | ||
690 | { | ||
691 | PBody body = new PBody(this); | ||
692 | PVariable var_train = body.getOrCreateVariableByName("train"); | ||
693 | PVariable var_location = body.getOrCreateVariableByName("location"); | ||
694 | new TypeConstraint(body, Tuples.flatTupleOf(var_train), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Train"))); | ||
695 | new TypeConstraint(body, Tuples.flatTupleOf(var_location), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
696 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
697 | new ExportedParameter(body, var_train, parameter_train), | ||
698 | new ExportedParameter(body, var_location, parameter_location) | ||
699 | )); | ||
700 | // // results->matches[match_cntr].location = frame->location;// results->matches[match_cntr++].train = frame->train; Train(train) | ||
701 | new TypeConstraint(body, Tuples.flatTupleOf(var_train), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Train"))); | ||
702 | // Train.location(train, location) | ||
703 | new TypeConstraint(body, Tuples.flatTupleOf(var_train), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Train"))); | ||
704 | PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); | ||
705 | new TypeConstraint(body, Tuples.flatTupleOf(var_train, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Train", "location"))); | ||
706 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
707 | new Equality(body, var__virtual_0_, var_location); | ||
708 | bodies.add(body); | ||
709 | } | ||
710 | return bodies; | ||
711 | } | ||
712 | } | ||
713 | } | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/TurnoutConnectedToBothOutputs.java b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/TurnoutConnectedToBothOutputs.java new file mode 100644 index 00000000..674bb275 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/TurnoutConnectedToBothOutputs.java | |||
@@ -0,0 +1,589 @@ | |||
1 | /** | ||
2 | * Generated from platform:/resource/ca.mcgill.rtgmrt.example.modes3/src/modes3/queries/Modes3Queries.vql | ||
3 | */ | ||
4 | package modes3.queries; | ||
5 | |||
6 | import java.util.Arrays; | ||
7 | import java.util.Collection; | ||
8 | import java.util.LinkedHashSet; | ||
9 | import java.util.List; | ||
10 | import java.util.Objects; | ||
11 | import java.util.Optional; | ||
12 | import java.util.Set; | ||
13 | import java.util.function.Consumer; | ||
14 | import java.util.stream.Collectors; | ||
15 | import java.util.stream.Stream; | ||
16 | import modes3.Turnout; | ||
17 | import org.apache.log4j.Logger; | ||
18 | import org.eclipse.emf.ecore.EClass; | ||
19 | import org.eclipse.viatra.query.runtime.api.IPatternMatch; | ||
20 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification; | ||
21 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; | ||
22 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; | ||
23 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; | ||
24 | import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; | ||
25 | import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; | ||
26 | import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; | ||
27 | import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; | ||
28 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
29 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | ||
30 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | ||
31 | import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation; | ||
32 | import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference; | ||
33 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; | ||
34 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
35 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
36 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | ||
37 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; | ||
38 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | ||
39 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; | ||
40 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
41 | import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; | ||
42 | |||
43 | /** | ||
44 | * A pattern-specific query specification that can instantiate Matcher in a type-safe way. | ||
45 | * | ||
46 | * <p>Original source: | ||
47 | * <code><pre> | ||
48 | * {@literal @}Constraint(message = "turnoutConnectedToBothOutputs", severity = "error", key = { T }) | ||
49 | * pattern turnoutConnectedToBothOutputs(T : Turnout) { | ||
50 | * Turnout.straight(T, Straight); | ||
51 | * Turnout.divergent(T, Divergent); | ||
52 | * Segment.connectedTo(T, Straight); | ||
53 | * Segment.connectedTo(T, Divergent); | ||
54 | * } | ||
55 | * </pre></code> | ||
56 | * | ||
57 | * @see Matcher | ||
58 | * @see Match | ||
59 | * | ||
60 | */ | ||
61 | @SuppressWarnings("all") | ||
62 | public final class TurnoutConnectedToBothOutputs extends BaseGeneratedEMFQuerySpecification<TurnoutConnectedToBothOutputs.Matcher> { | ||
63 | /** | ||
64 | * Pattern-specific match representation of the modes3.queries.turnoutConnectedToBothOutputs pattern, | ||
65 | * to be used in conjunction with {@link Matcher}. | ||
66 | * | ||
67 | * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. | ||
68 | * Each instance is a (possibly partial) substitution of pattern parameters, | ||
69 | * usable to represent a match of the pattern in the result of a query, | ||
70 | * or to specify the bound (fixed) input parameters when issuing a query. | ||
71 | * | ||
72 | * @see Matcher | ||
73 | * | ||
74 | */ | ||
75 | public static abstract class Match extends BasePatternMatch { | ||
76 | private Turnout fT; | ||
77 | |||
78 | private static List<String> parameterNames = makeImmutableList("T"); | ||
79 | |||
80 | private Match(final Turnout pT) { | ||
81 | this.fT = pT; | ||
82 | } | ||
83 | |||
84 | @Override | ||
85 | public Object get(final String parameterName) { | ||
86 | switch(parameterName) { | ||
87 | case "T": return this.fT; | ||
88 | default: return null; | ||
89 | } | ||
90 | } | ||
91 | |||
92 | @Override | ||
93 | public Object get(final int index) { | ||
94 | switch(index) { | ||
95 | case 0: return this.fT; | ||
96 | default: return null; | ||
97 | } | ||
98 | } | ||
99 | |||
100 | public Turnout getT() { | ||
101 | return this.fT; | ||
102 | } | ||
103 | |||
104 | @Override | ||
105 | public boolean set(final String parameterName, final Object newValue) { | ||
106 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
107 | if ("T".equals(parameterName) ) { | ||
108 | this.fT = (Turnout) newValue; | ||
109 | return true; | ||
110 | } | ||
111 | return false; | ||
112 | } | ||
113 | |||
114 | public void setT(final Turnout pT) { | ||
115 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
116 | this.fT = pT; | ||
117 | } | ||
118 | |||
119 | @Override | ||
120 | public String patternName() { | ||
121 | return "modes3.queries.turnoutConnectedToBothOutputs"; | ||
122 | } | ||
123 | |||
124 | @Override | ||
125 | public List<String> parameterNames() { | ||
126 | return TurnoutConnectedToBothOutputs.Match.parameterNames; | ||
127 | } | ||
128 | |||
129 | @Override | ||
130 | public Object[] toArray() { | ||
131 | return new Object[]{fT}; | ||
132 | } | ||
133 | |||
134 | @Override | ||
135 | public TurnoutConnectedToBothOutputs.Match toImmutable() { | ||
136 | return isMutable() ? newMatch(fT) : this; | ||
137 | } | ||
138 | |||
139 | @Override | ||
140 | public String prettyPrint() { | ||
141 | StringBuilder result = new StringBuilder(); | ||
142 | result.append("\"T\"=" + prettyPrintValue(fT)); | ||
143 | return result.toString(); | ||
144 | } | ||
145 | |||
146 | @Override | ||
147 | public int hashCode() { | ||
148 | return Objects.hash(fT); | ||
149 | } | ||
150 | |||
151 | @Override | ||
152 | public boolean equals(final Object obj) { | ||
153 | if (this == obj) | ||
154 | return true; | ||
155 | if (obj == null) { | ||
156 | return false; | ||
157 | } | ||
158 | if ((obj instanceof TurnoutConnectedToBothOutputs.Match)) { | ||
159 | TurnoutConnectedToBothOutputs.Match other = (TurnoutConnectedToBothOutputs.Match) obj; | ||
160 | return Objects.equals(fT, other.fT); | ||
161 | } else { | ||
162 | // this should be infrequent | ||
163 | if (!(obj instanceof IPatternMatch)) { | ||
164 | return false; | ||
165 | } | ||
166 | IPatternMatch otherSig = (IPatternMatch) obj; | ||
167 | return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); | ||
168 | } | ||
169 | } | ||
170 | |||
171 | @Override | ||
172 | public TurnoutConnectedToBothOutputs specification() { | ||
173 | return TurnoutConnectedToBothOutputs.instance(); | ||
174 | } | ||
175 | |||
176 | /** | ||
177 | * Returns an empty, mutable match. | ||
178 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
179 | * | ||
180 | * @return the empty match. | ||
181 | * | ||
182 | */ | ||
183 | public static TurnoutConnectedToBothOutputs.Match newEmptyMatch() { | ||
184 | return new Mutable(null); | ||
185 | } | ||
186 | |||
187 | /** | ||
188 | * Returns a mutable (partial) match. | ||
189 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
190 | * | ||
191 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
192 | * @return the new, mutable (partial) match object. | ||
193 | * | ||
194 | */ | ||
195 | public static TurnoutConnectedToBothOutputs.Match newMutableMatch(final Turnout pT) { | ||
196 | return new Mutable(pT); | ||
197 | } | ||
198 | |||
199 | /** | ||
200 | * Returns a new (partial) match. | ||
201 | * This can be used e.g. to call the matcher with a partial match. | ||
202 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
203 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
204 | * @return the (partial) match object. | ||
205 | * | ||
206 | */ | ||
207 | public static TurnoutConnectedToBothOutputs.Match newMatch(final Turnout pT) { | ||
208 | return new Immutable(pT); | ||
209 | } | ||
210 | |||
211 | private static final class Mutable extends TurnoutConnectedToBothOutputs.Match { | ||
212 | Mutable(final Turnout pT) { | ||
213 | super(pT); | ||
214 | } | ||
215 | |||
216 | @Override | ||
217 | public boolean isMutable() { | ||
218 | return true; | ||
219 | } | ||
220 | } | ||
221 | |||
222 | private static final class Immutable extends TurnoutConnectedToBothOutputs.Match { | ||
223 | Immutable(final Turnout pT) { | ||
224 | super(pT); | ||
225 | } | ||
226 | |||
227 | @Override | ||
228 | public boolean isMutable() { | ||
229 | return false; | ||
230 | } | ||
231 | } | ||
232 | } | ||
233 | |||
234 | /** | ||
235 | * Generated pattern matcher API of the modes3.queries.turnoutConnectedToBothOutputs pattern, | ||
236 | * providing pattern-specific query methods. | ||
237 | * | ||
238 | * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, | ||
239 | * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. | ||
240 | * | ||
241 | * <p>Matches of the pattern will be represented as {@link Match}. | ||
242 | * | ||
243 | * <p>Original source: | ||
244 | * <code><pre> | ||
245 | * {@literal @}Constraint(message = "turnoutConnectedToBothOutputs", severity = "error", key = { T }) | ||
246 | * pattern turnoutConnectedToBothOutputs(T : Turnout) { | ||
247 | * Turnout.straight(T, Straight); | ||
248 | * Turnout.divergent(T, Divergent); | ||
249 | * Segment.connectedTo(T, Straight); | ||
250 | * Segment.connectedTo(T, Divergent); | ||
251 | * } | ||
252 | * </pre></code> | ||
253 | * | ||
254 | * @see Match | ||
255 | * @see TurnoutConnectedToBothOutputs | ||
256 | * | ||
257 | */ | ||
258 | public static class Matcher extends BaseMatcher<TurnoutConnectedToBothOutputs.Match> { | ||
259 | /** | ||
260 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
261 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
262 | * | ||
263 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
264 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
265 | * | ||
266 | */ | ||
267 | public static TurnoutConnectedToBothOutputs.Matcher on(final ViatraQueryEngine engine) { | ||
268 | // check if matcher already exists | ||
269 | Matcher matcher = engine.getExistingMatcher(querySpecification()); | ||
270 | if (matcher == null) { | ||
271 | matcher = (Matcher)engine.getMatcher(querySpecification()); | ||
272 | } | ||
273 | return matcher; | ||
274 | } | ||
275 | |||
276 | /** | ||
277 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
278 | * @return an initialized matcher | ||
279 | * @noreference This method is for internal matcher initialization by the framework, do not call it manually. | ||
280 | * | ||
281 | */ | ||
282 | public static TurnoutConnectedToBothOutputs.Matcher create() { | ||
283 | return new Matcher(); | ||
284 | } | ||
285 | |||
286 | private static final int POSITION_T = 0; | ||
287 | |||
288 | private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(TurnoutConnectedToBothOutputs.Matcher.class); | ||
289 | |||
290 | /** | ||
291 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
292 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
293 | * | ||
294 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
295 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
296 | * | ||
297 | */ | ||
298 | private Matcher() { | ||
299 | super(querySpecification()); | ||
300 | } | ||
301 | |||
302 | /** | ||
303 | * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. | ||
304 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
305 | * @return matches represented as a Match object. | ||
306 | * | ||
307 | */ | ||
308 | public Collection<TurnoutConnectedToBothOutputs.Match> getAllMatches(final Turnout pT) { | ||
309 | return rawStreamAllMatches(new Object[]{pT}).collect(Collectors.toSet()); | ||
310 | } | ||
311 | |||
312 | /** | ||
313 | * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. | ||
314 | * </p> | ||
315 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
316 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
317 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
318 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
319 | * @return a stream of matches represented as a Match object. | ||
320 | * | ||
321 | */ | ||
322 | public Stream<TurnoutConnectedToBothOutputs.Match> streamAllMatches(final Turnout pT) { | ||
323 | return rawStreamAllMatches(new Object[]{pT}); | ||
324 | } | ||
325 | |||
326 | /** | ||
327 | * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
328 | * Neither determinism nor randomness of selection is guaranteed. | ||
329 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
330 | * @return a match represented as a Match object, or null if no match is found. | ||
331 | * | ||
332 | */ | ||
333 | public Optional<TurnoutConnectedToBothOutputs.Match> getOneArbitraryMatch(final Turnout pT) { | ||
334 | return rawGetOneArbitraryMatch(new Object[]{pT}); | ||
335 | } | ||
336 | |||
337 | /** | ||
338 | * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, | ||
339 | * under any possible substitution of the unspecified parameters (if any). | ||
340 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
341 | * @return true if the input is a valid (partial) match of the pattern. | ||
342 | * | ||
343 | */ | ||
344 | public boolean hasMatch(final Turnout pT) { | ||
345 | return rawHasMatch(new Object[]{pT}); | ||
346 | } | ||
347 | |||
348 | /** | ||
349 | * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. | ||
350 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
351 | * @return the number of pattern matches found. | ||
352 | * | ||
353 | */ | ||
354 | public int countMatches(final Turnout pT) { | ||
355 | return rawCountMatches(new Object[]{pT}); | ||
356 | } | ||
357 | |||
358 | /** | ||
359 | * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
360 | * Neither determinism nor randomness of selection is guaranteed. | ||
361 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
362 | * @param processor the action that will process the selected match. | ||
363 | * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked | ||
364 | * | ||
365 | */ | ||
366 | public boolean forOneArbitraryMatch(final Turnout pT, final Consumer<? super TurnoutConnectedToBothOutputs.Match> processor) { | ||
367 | return rawForOneArbitraryMatch(new Object[]{pT}, processor); | ||
368 | } | ||
369 | |||
370 | /** | ||
371 | * Returns a new (partial) match. | ||
372 | * This can be used e.g. to call the matcher with a partial match. | ||
373 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
374 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
375 | * @return the (partial) match object. | ||
376 | * | ||
377 | */ | ||
378 | public TurnoutConnectedToBothOutputs.Match newMatch(final Turnout pT) { | ||
379 | return TurnoutConnectedToBothOutputs.Match.newMatch(pT); | ||
380 | } | ||
381 | |||
382 | /** | ||
383 | * Retrieve the set of values that occur in matches for T. | ||
384 | * @return the Set of all values or empty set if there are no matches | ||
385 | * | ||
386 | */ | ||
387 | protected Stream<Turnout> rawStreamAllValuesOfT(final Object[] parameters) { | ||
388 | return rawStreamAllValues(POSITION_T, parameters).map(Turnout.class::cast); | ||
389 | } | ||
390 | |||
391 | /** | ||
392 | * Retrieve the set of values that occur in matches for T. | ||
393 | * @return the Set of all values or empty set if there are no matches | ||
394 | * | ||
395 | */ | ||
396 | public Set<Turnout> getAllValuesOfT() { | ||
397 | return rawStreamAllValuesOfT(emptyArray()).collect(Collectors.toSet()); | ||
398 | } | ||
399 | |||
400 | /** | ||
401 | * Retrieve the set of values that occur in matches for T. | ||
402 | * @return the Set of all values or empty set if there are no matches | ||
403 | * | ||
404 | */ | ||
405 | public Stream<Turnout> streamAllValuesOfT() { | ||
406 | return rawStreamAllValuesOfT(emptyArray()); | ||
407 | } | ||
408 | |||
409 | @Override | ||
410 | protected TurnoutConnectedToBothOutputs.Match tupleToMatch(final Tuple t) { | ||
411 | try { | ||
412 | return TurnoutConnectedToBothOutputs.Match.newMatch((Turnout) t.get(POSITION_T)); | ||
413 | } catch(ClassCastException e) { | ||
414 | LOGGER.error("Element(s) in tuple not properly typed!",e); | ||
415 | return null; | ||
416 | } | ||
417 | } | ||
418 | |||
419 | @Override | ||
420 | protected TurnoutConnectedToBothOutputs.Match arrayToMatch(final Object[] match) { | ||
421 | try { | ||
422 | return TurnoutConnectedToBothOutputs.Match.newMatch((Turnout) match[POSITION_T]); | ||
423 | } catch(ClassCastException e) { | ||
424 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
425 | return null; | ||
426 | } | ||
427 | } | ||
428 | |||
429 | @Override | ||
430 | protected TurnoutConnectedToBothOutputs.Match arrayToMatchMutable(final Object[] match) { | ||
431 | try { | ||
432 | return TurnoutConnectedToBothOutputs.Match.newMutableMatch((Turnout) match[POSITION_T]); | ||
433 | } catch(ClassCastException e) { | ||
434 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
435 | return null; | ||
436 | } | ||
437 | } | ||
438 | |||
439 | /** | ||
440 | * @return the singleton instance of the query specification of this pattern | ||
441 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
442 | * | ||
443 | */ | ||
444 | public static IQuerySpecification<TurnoutConnectedToBothOutputs.Matcher> querySpecification() { | ||
445 | return TurnoutConnectedToBothOutputs.instance(); | ||
446 | } | ||
447 | } | ||
448 | |||
449 | private TurnoutConnectedToBothOutputs() { | ||
450 | super(GeneratedPQuery.INSTANCE); | ||
451 | } | ||
452 | |||
453 | /** | ||
454 | * @return the singleton instance of the query specification | ||
455 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
456 | * | ||
457 | */ | ||
458 | public static TurnoutConnectedToBothOutputs instance() { | ||
459 | try{ | ||
460 | return LazyHolder.INSTANCE; | ||
461 | } catch (ExceptionInInitializerError err) { | ||
462 | throw processInitializerError(err); | ||
463 | } | ||
464 | } | ||
465 | |||
466 | @Override | ||
467 | protected TurnoutConnectedToBothOutputs.Matcher instantiate(final ViatraQueryEngine engine) { | ||
468 | return TurnoutConnectedToBothOutputs.Matcher.on(engine); | ||
469 | } | ||
470 | |||
471 | @Override | ||
472 | public TurnoutConnectedToBothOutputs.Matcher instantiate() { | ||
473 | return TurnoutConnectedToBothOutputs.Matcher.create(); | ||
474 | } | ||
475 | |||
476 | @Override | ||
477 | public TurnoutConnectedToBothOutputs.Match newEmptyMatch() { | ||
478 | return TurnoutConnectedToBothOutputs.Match.newEmptyMatch(); | ||
479 | } | ||
480 | |||
481 | @Override | ||
482 | public TurnoutConnectedToBothOutputs.Match newMatch(final Object... parameters) { | ||
483 | return TurnoutConnectedToBothOutputs.Match.newMatch((modes3.Turnout) parameters[0]); | ||
484 | } | ||
485 | |||
486 | /** | ||
487 | * Inner class allowing the singleton instance of {@link TurnoutConnectedToBothOutputs} to be created | ||
488 | * <b>not</b> at the class load time of the outer class, | ||
489 | * but rather at the first call to {@link TurnoutConnectedToBothOutputs#instance()}. | ||
490 | * | ||
491 | * <p> This workaround is required e.g. to support recursion. | ||
492 | * | ||
493 | */ | ||
494 | private static class LazyHolder { | ||
495 | private static final TurnoutConnectedToBothOutputs INSTANCE = new TurnoutConnectedToBothOutputs(); | ||
496 | |||
497 | /** | ||
498 | * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned. | ||
499 | * This initialization order is required to support indirect recursion. | ||
500 | * | ||
501 | * <p> The static initializer is defined using a helper field to work around limitations of the code generator. | ||
502 | * | ||
503 | */ | ||
504 | private static final Object STATIC_INITIALIZER = ensureInitialized(); | ||
505 | |||
506 | public static Object ensureInitialized() { | ||
507 | INSTANCE.ensureInitializedInternal(); | ||
508 | return null; | ||
509 | } | ||
510 | } | ||
511 | |||
512 | private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { | ||
513 | private static final TurnoutConnectedToBothOutputs.GeneratedPQuery INSTANCE = new GeneratedPQuery(); | ||
514 | |||
515 | private final PParameter parameter_T = new PParameter("T", "modes3.Turnout", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Turnout")), PParameterDirection.INOUT); | ||
516 | |||
517 | private final List<PParameter> parameters = Arrays.asList(parameter_T); | ||
518 | |||
519 | private GeneratedPQuery() { | ||
520 | super(PVisibility.PUBLIC); | ||
521 | } | ||
522 | |||
523 | @Override | ||
524 | public String getFullyQualifiedName() { | ||
525 | return "modes3.queries.turnoutConnectedToBothOutputs"; | ||
526 | } | ||
527 | |||
528 | @Override | ||
529 | public List<String> getParameterNames() { | ||
530 | return Arrays.asList("T"); | ||
531 | } | ||
532 | |||
533 | @Override | ||
534 | public List<PParameter> getParameters() { | ||
535 | return parameters; | ||
536 | } | ||
537 | |||
538 | @Override | ||
539 | public Set<PBody> doGetContainedBodies() { | ||
540 | setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); | ||
541 | Set<PBody> bodies = new LinkedHashSet<>(); | ||
542 | { | ||
543 | PBody body = new PBody(this); | ||
544 | PVariable var_T = body.getOrCreateVariableByName("T"); | ||
545 | PVariable var_Straight = body.getOrCreateVariableByName("Straight"); | ||
546 | PVariable var_Divergent = body.getOrCreateVariableByName("Divergent"); | ||
547 | new TypeConstraint(body, Tuples.flatTupleOf(var_T), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Turnout"))); | ||
548 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
549 | new ExportedParameter(body, var_T, parameter_T) | ||
550 | )); | ||
551 | // Turnout.straight(T, Straight) | ||
552 | new TypeConstraint(body, Tuples.flatTupleOf(var_T), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Turnout"))); | ||
553 | PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); | ||
554 | new TypeConstraint(body, Tuples.flatTupleOf(var_T, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Turnout", "straight"))); | ||
555 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
556 | new Equality(body, var__virtual_0_, var_Straight); | ||
557 | // Turnout.divergent(T, Divergent) | ||
558 | new TypeConstraint(body, Tuples.flatTupleOf(var_T), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Turnout"))); | ||
559 | PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); | ||
560 | new TypeConstraint(body, Tuples.flatTupleOf(var_T, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Turnout", "divergent"))); | ||
561 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
562 | new Equality(body, var__virtual_1_, var_Divergent); | ||
563 | // Segment.connectedTo(T, Straight) | ||
564 | new TypeConstraint(body, Tuples.flatTupleOf(var_T), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
565 | PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}"); | ||
566 | new TypeConstraint(body, Tuples.flatTupleOf(var_T, var__virtual_2_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment", "connectedTo"))); | ||
567 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
568 | new Equality(body, var__virtual_2_, var_Straight); | ||
569 | // Segment.connectedTo(T, Divergent) | ||
570 | new TypeConstraint(body, Tuples.flatTupleOf(var_T), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
571 | PVariable var__virtual_3_ = body.getOrCreateVariableByName(".virtual{3}"); | ||
572 | new TypeConstraint(body, Tuples.flatTupleOf(var_T, var__virtual_3_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment", "connectedTo"))); | ||
573 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_3_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
574 | new Equality(body, var__virtual_3_, var_Divergent); | ||
575 | bodies.add(body); | ||
576 | } | ||
577 | { | ||
578 | PAnnotation annotation = new PAnnotation("Constraint"); | ||
579 | annotation.addAttribute("message", "turnoutConnectedToBothOutputs"); | ||
580 | annotation.addAttribute("severity", "error"); | ||
581 | annotation.addAttribute("key", Arrays.asList(new Object[] { | ||
582 | new ParameterReference("T") | ||
583 | })); | ||
584 | addAnnotation(annotation); | ||
585 | } | ||
586 | return bodies; | ||
587 | } | ||
588 | } | ||
589 | } | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/TurnoutOutput.java b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/TurnoutOutput.java new file mode 100644 index 00000000..87cccfde --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/TurnoutOutput.java | |||
@@ -0,0 +1,727 @@ | |||
1 | /** | ||
2 | * Generated from platform:/resource/ca.mcgill.rtgmrt.example.modes3/src/modes3/queries/Modes3Queries.vql | ||
3 | */ | ||
4 | package modes3.queries; | ||
5 | |||
6 | import java.util.Arrays; | ||
7 | import java.util.Collection; | ||
8 | import java.util.LinkedHashSet; | ||
9 | import java.util.List; | ||
10 | import java.util.Objects; | ||
11 | import java.util.Optional; | ||
12 | import java.util.Set; | ||
13 | import java.util.function.Consumer; | ||
14 | import java.util.stream.Collectors; | ||
15 | import java.util.stream.Stream; | ||
16 | import modes3.Segment; | ||
17 | import modes3.Turnout; | ||
18 | import org.apache.log4j.Logger; | ||
19 | import org.eclipse.emf.ecore.EClass; | ||
20 | import org.eclipse.viatra.query.runtime.api.IPatternMatch; | ||
21 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification; | ||
22 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; | ||
23 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; | ||
24 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; | ||
25 | import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; | ||
26 | import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; | ||
27 | import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; | ||
28 | import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; | ||
29 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
30 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | ||
31 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | ||
32 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; | ||
33 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
34 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
35 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | ||
36 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; | ||
37 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | ||
38 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; | ||
39 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
40 | import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; | ||
41 | |||
42 | /** | ||
43 | * A pattern-specific query specification that can instantiate Matcher in a type-safe way. | ||
44 | * | ||
45 | * <p>Original source: | ||
46 | * <code><pre> | ||
47 | * pattern turnoutOutput(T : Turnout, S : Segment) { | ||
48 | * Turnout.straight(T, S); | ||
49 | * } or { | ||
50 | * Turnout.divergent(T, S); | ||
51 | * } | ||
52 | * </pre></code> | ||
53 | * | ||
54 | * @see Matcher | ||
55 | * @see Match | ||
56 | * | ||
57 | */ | ||
58 | @SuppressWarnings("all") | ||
59 | public final class TurnoutOutput extends BaseGeneratedEMFQuerySpecification<TurnoutOutput.Matcher> { | ||
60 | /** | ||
61 | * Pattern-specific match representation of the modes3.queries.turnoutOutput pattern, | ||
62 | * to be used in conjunction with {@link Matcher}. | ||
63 | * | ||
64 | * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. | ||
65 | * Each instance is a (possibly partial) substitution of pattern parameters, | ||
66 | * usable to represent a match of the pattern in the result of a query, | ||
67 | * or to specify the bound (fixed) input parameters when issuing a query. | ||
68 | * | ||
69 | * @see Matcher | ||
70 | * | ||
71 | */ | ||
72 | public static abstract class Match extends BasePatternMatch { | ||
73 | private Turnout fT; | ||
74 | |||
75 | private Segment fS; | ||
76 | |||
77 | private static List<String> parameterNames = makeImmutableList("T", "S"); | ||
78 | |||
79 | private Match(final Turnout pT, final Segment pS) { | ||
80 | this.fT = pT; | ||
81 | this.fS = pS; | ||
82 | } | ||
83 | |||
84 | @Override | ||
85 | public Object get(final String parameterName) { | ||
86 | switch(parameterName) { | ||
87 | case "T": return this.fT; | ||
88 | case "S": return this.fS; | ||
89 | default: return null; | ||
90 | } | ||
91 | } | ||
92 | |||
93 | @Override | ||
94 | public Object get(final int index) { | ||
95 | switch(index) { | ||
96 | case 0: return this.fT; | ||
97 | case 1: return this.fS; | ||
98 | default: return null; | ||
99 | } | ||
100 | } | ||
101 | |||
102 | public Turnout getT() { | ||
103 | return this.fT; | ||
104 | } | ||
105 | |||
106 | public Segment getS() { | ||
107 | return this.fS; | ||
108 | } | ||
109 | |||
110 | @Override | ||
111 | public boolean set(final String parameterName, final Object newValue) { | ||
112 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
113 | if ("T".equals(parameterName) ) { | ||
114 | this.fT = (Turnout) newValue; | ||
115 | return true; | ||
116 | } | ||
117 | if ("S".equals(parameterName) ) { | ||
118 | this.fS = (Segment) newValue; | ||
119 | return true; | ||
120 | } | ||
121 | return false; | ||
122 | } | ||
123 | |||
124 | public void setT(final Turnout pT) { | ||
125 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
126 | this.fT = pT; | ||
127 | } | ||
128 | |||
129 | public void setS(final Segment pS) { | ||
130 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
131 | this.fS = pS; | ||
132 | } | ||
133 | |||
134 | @Override | ||
135 | public String patternName() { | ||
136 | return "modes3.queries.turnoutOutput"; | ||
137 | } | ||
138 | |||
139 | @Override | ||
140 | public List<String> parameterNames() { | ||
141 | return TurnoutOutput.Match.parameterNames; | ||
142 | } | ||
143 | |||
144 | @Override | ||
145 | public Object[] toArray() { | ||
146 | return new Object[]{fT, fS}; | ||
147 | } | ||
148 | |||
149 | @Override | ||
150 | public TurnoutOutput.Match toImmutable() { | ||
151 | return isMutable() ? newMatch(fT, fS) : this; | ||
152 | } | ||
153 | |||
154 | @Override | ||
155 | public String prettyPrint() { | ||
156 | StringBuilder result = new StringBuilder(); | ||
157 | result.append("\"T\"=" + prettyPrintValue(fT) + ", "); | ||
158 | result.append("\"S\"=" + prettyPrintValue(fS)); | ||
159 | return result.toString(); | ||
160 | } | ||
161 | |||
162 | @Override | ||
163 | public int hashCode() { | ||
164 | return Objects.hash(fT, fS); | ||
165 | } | ||
166 | |||
167 | @Override | ||
168 | public boolean equals(final Object obj) { | ||
169 | if (this == obj) | ||
170 | return true; | ||
171 | if (obj == null) { | ||
172 | return false; | ||
173 | } | ||
174 | if ((obj instanceof TurnoutOutput.Match)) { | ||
175 | TurnoutOutput.Match other = (TurnoutOutput.Match) obj; | ||
176 | return Objects.equals(fT, other.fT) && Objects.equals(fS, other.fS); | ||
177 | } else { | ||
178 | // this should be infrequent | ||
179 | if (!(obj instanceof IPatternMatch)) { | ||
180 | return false; | ||
181 | } | ||
182 | IPatternMatch otherSig = (IPatternMatch) obj; | ||
183 | return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); | ||
184 | } | ||
185 | } | ||
186 | |||
187 | @Override | ||
188 | public TurnoutOutput specification() { | ||
189 | return TurnoutOutput.instance(); | ||
190 | } | ||
191 | |||
192 | /** | ||
193 | * Returns an empty, mutable match. | ||
194 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
195 | * | ||
196 | * @return the empty match. | ||
197 | * | ||
198 | */ | ||
199 | public static TurnoutOutput.Match newEmptyMatch() { | ||
200 | return new Mutable(null, null); | ||
201 | } | ||
202 | |||
203 | /** | ||
204 | * Returns a mutable (partial) match. | ||
205 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
206 | * | ||
207 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
208 | * @param pS the fixed value of pattern parameter S, or null if not bound. | ||
209 | * @return the new, mutable (partial) match object. | ||
210 | * | ||
211 | */ | ||
212 | public static TurnoutOutput.Match newMutableMatch(final Turnout pT, final Segment pS) { | ||
213 | return new Mutable(pT, pS); | ||
214 | } | ||
215 | |||
216 | /** | ||
217 | * Returns a new (partial) match. | ||
218 | * This can be used e.g. to call the matcher with a partial match. | ||
219 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
220 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
221 | * @param pS the fixed value of pattern parameter S, or null if not bound. | ||
222 | * @return the (partial) match object. | ||
223 | * | ||
224 | */ | ||
225 | public static TurnoutOutput.Match newMatch(final Turnout pT, final Segment pS) { | ||
226 | return new Immutable(pT, pS); | ||
227 | } | ||
228 | |||
229 | private static final class Mutable extends TurnoutOutput.Match { | ||
230 | Mutable(final Turnout pT, final Segment pS) { | ||
231 | super(pT, pS); | ||
232 | } | ||
233 | |||
234 | @Override | ||
235 | public boolean isMutable() { | ||
236 | return true; | ||
237 | } | ||
238 | } | ||
239 | |||
240 | private static final class Immutable extends TurnoutOutput.Match { | ||
241 | Immutable(final Turnout pT, final Segment pS) { | ||
242 | super(pT, pS); | ||
243 | } | ||
244 | |||
245 | @Override | ||
246 | public boolean isMutable() { | ||
247 | return false; | ||
248 | } | ||
249 | } | ||
250 | } | ||
251 | |||
252 | /** | ||
253 | * Generated pattern matcher API of the modes3.queries.turnoutOutput pattern, | ||
254 | * providing pattern-specific query methods. | ||
255 | * | ||
256 | * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, | ||
257 | * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. | ||
258 | * | ||
259 | * <p>Matches of the pattern will be represented as {@link Match}. | ||
260 | * | ||
261 | * <p>Original source: | ||
262 | * <code><pre> | ||
263 | * pattern turnoutOutput(T : Turnout, S : Segment) { | ||
264 | * Turnout.straight(T, S); | ||
265 | * } or { | ||
266 | * Turnout.divergent(T, S); | ||
267 | * } | ||
268 | * </pre></code> | ||
269 | * | ||
270 | * @see Match | ||
271 | * @see TurnoutOutput | ||
272 | * | ||
273 | */ | ||
274 | public static class Matcher extends BaseMatcher<TurnoutOutput.Match> { | ||
275 | /** | ||
276 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
277 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
278 | * | ||
279 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
280 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
281 | * | ||
282 | */ | ||
283 | public static TurnoutOutput.Matcher on(final ViatraQueryEngine engine) { | ||
284 | // check if matcher already exists | ||
285 | Matcher matcher = engine.getExistingMatcher(querySpecification()); | ||
286 | if (matcher == null) { | ||
287 | matcher = (Matcher)engine.getMatcher(querySpecification()); | ||
288 | } | ||
289 | return matcher; | ||
290 | } | ||
291 | |||
292 | /** | ||
293 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
294 | * @return an initialized matcher | ||
295 | * @noreference This method is for internal matcher initialization by the framework, do not call it manually. | ||
296 | * | ||
297 | */ | ||
298 | public static TurnoutOutput.Matcher create() { | ||
299 | return new Matcher(); | ||
300 | } | ||
301 | |||
302 | private static final int POSITION_T = 0; | ||
303 | |||
304 | private static final int POSITION_S = 1; | ||
305 | |||
306 | private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(TurnoutOutput.Matcher.class); | ||
307 | |||
308 | /** | ||
309 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
310 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
311 | * | ||
312 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
313 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
314 | * | ||
315 | */ | ||
316 | private Matcher() { | ||
317 | super(querySpecification()); | ||
318 | } | ||
319 | |||
320 | /** | ||
321 | * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. | ||
322 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
323 | * @param pS the fixed value of pattern parameter S, or null if not bound. | ||
324 | * @return matches represented as a Match object. | ||
325 | * | ||
326 | */ | ||
327 | public Collection<TurnoutOutput.Match> getAllMatches(final Turnout pT, final Segment pS) { | ||
328 | return rawStreamAllMatches(new Object[]{pT, pS}).collect(Collectors.toSet()); | ||
329 | } | ||
330 | |||
331 | /** | ||
332 | * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. | ||
333 | * </p> | ||
334 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
335 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
336 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
337 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
338 | * @param pS the fixed value of pattern parameter S, or null if not bound. | ||
339 | * @return a stream of matches represented as a Match object. | ||
340 | * | ||
341 | */ | ||
342 | public Stream<TurnoutOutput.Match> streamAllMatches(final Turnout pT, final Segment pS) { | ||
343 | return rawStreamAllMatches(new Object[]{pT, pS}); | ||
344 | } | ||
345 | |||
346 | /** | ||
347 | * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
348 | * Neither determinism nor randomness of selection is guaranteed. | ||
349 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
350 | * @param pS the fixed value of pattern parameter S, or null if not bound. | ||
351 | * @return a match represented as a Match object, or null if no match is found. | ||
352 | * | ||
353 | */ | ||
354 | public Optional<TurnoutOutput.Match> getOneArbitraryMatch(final Turnout pT, final Segment pS) { | ||
355 | return rawGetOneArbitraryMatch(new Object[]{pT, pS}); | ||
356 | } | ||
357 | |||
358 | /** | ||
359 | * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, | ||
360 | * under any possible substitution of the unspecified parameters (if any). | ||
361 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
362 | * @param pS the fixed value of pattern parameter S, or null if not bound. | ||
363 | * @return true if the input is a valid (partial) match of the pattern. | ||
364 | * | ||
365 | */ | ||
366 | public boolean hasMatch(final Turnout pT, final Segment pS) { | ||
367 | return rawHasMatch(new Object[]{pT, pS}); | ||
368 | } | ||
369 | |||
370 | /** | ||
371 | * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. | ||
372 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
373 | * @param pS the fixed value of pattern parameter S, or null if not bound. | ||
374 | * @return the number of pattern matches found. | ||
375 | * | ||
376 | */ | ||
377 | public int countMatches(final Turnout pT, final Segment pS) { | ||
378 | return rawCountMatches(new Object[]{pT, pS}); | ||
379 | } | ||
380 | |||
381 | /** | ||
382 | * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
383 | * Neither determinism nor randomness of selection is guaranteed. | ||
384 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
385 | * @param pS the fixed value of pattern parameter S, or null if not bound. | ||
386 | * @param processor the action that will process the selected match. | ||
387 | * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked | ||
388 | * | ||
389 | */ | ||
390 | public boolean forOneArbitraryMatch(final Turnout pT, final Segment pS, final Consumer<? super TurnoutOutput.Match> processor) { | ||
391 | return rawForOneArbitraryMatch(new Object[]{pT, pS}, processor); | ||
392 | } | ||
393 | |||
394 | /** | ||
395 | * Returns a new (partial) match. | ||
396 | * This can be used e.g. to call the matcher with a partial match. | ||
397 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
398 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
399 | * @param pS the fixed value of pattern parameter S, or null if not bound. | ||
400 | * @return the (partial) match object. | ||
401 | * | ||
402 | */ | ||
403 | public TurnoutOutput.Match newMatch(final Turnout pT, final Segment pS) { | ||
404 | return TurnoutOutput.Match.newMatch(pT, pS); | ||
405 | } | ||
406 | |||
407 | /** | ||
408 | * Retrieve the set of values that occur in matches for T. | ||
409 | * @return the Set of all values or empty set if there are no matches | ||
410 | * | ||
411 | */ | ||
412 | protected Stream<Turnout> rawStreamAllValuesOfT(final Object[] parameters) { | ||
413 | return rawStreamAllValues(POSITION_T, parameters).map(Turnout.class::cast); | ||
414 | } | ||
415 | |||
416 | /** | ||
417 | * Retrieve the set of values that occur in matches for T. | ||
418 | * @return the Set of all values or empty set if there are no matches | ||
419 | * | ||
420 | */ | ||
421 | public Set<Turnout> getAllValuesOfT() { | ||
422 | return rawStreamAllValuesOfT(emptyArray()).collect(Collectors.toSet()); | ||
423 | } | ||
424 | |||
425 | /** | ||
426 | * Retrieve the set of values that occur in matches for T. | ||
427 | * @return the Set of all values or empty set if there are no matches | ||
428 | * | ||
429 | */ | ||
430 | public Stream<Turnout> streamAllValuesOfT() { | ||
431 | return rawStreamAllValuesOfT(emptyArray()); | ||
432 | } | ||
433 | |||
434 | /** | ||
435 | * Retrieve the set of values that occur in matches for T. | ||
436 | * </p> | ||
437 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
438 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
439 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
440 | * | ||
441 | * @return the Stream of all values or empty set if there are no matches | ||
442 | * | ||
443 | */ | ||
444 | public Stream<Turnout> streamAllValuesOfT(final TurnoutOutput.Match partialMatch) { | ||
445 | return rawStreamAllValuesOfT(partialMatch.toArray()); | ||
446 | } | ||
447 | |||
448 | /** | ||
449 | * Retrieve the set of values that occur in matches for T. | ||
450 | * </p> | ||
451 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
452 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
453 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
454 | * | ||
455 | * @return the Stream of all values or empty set if there are no matches | ||
456 | * | ||
457 | */ | ||
458 | public Stream<Turnout> streamAllValuesOfT(final Segment pS) { | ||
459 | return rawStreamAllValuesOfT(new Object[]{null, pS}); | ||
460 | } | ||
461 | |||
462 | /** | ||
463 | * Retrieve the set of values that occur in matches for T. | ||
464 | * @return the Set of all values or empty set if there are no matches | ||
465 | * | ||
466 | */ | ||
467 | public Set<Turnout> getAllValuesOfT(final TurnoutOutput.Match partialMatch) { | ||
468 | return rawStreamAllValuesOfT(partialMatch.toArray()).collect(Collectors.toSet()); | ||
469 | } | ||
470 | |||
471 | /** | ||
472 | * Retrieve the set of values that occur in matches for T. | ||
473 | * @return the Set of all values or empty set if there are no matches | ||
474 | * | ||
475 | */ | ||
476 | public Set<Turnout> getAllValuesOfT(final Segment pS) { | ||
477 | return rawStreamAllValuesOfT(new Object[]{null, pS}).collect(Collectors.toSet()); | ||
478 | } | ||
479 | |||
480 | /** | ||
481 | * Retrieve the set of values that occur in matches for S. | ||
482 | * @return the Set of all values or empty set if there are no matches | ||
483 | * | ||
484 | */ | ||
485 | protected Stream<Segment> rawStreamAllValuesOfS(final Object[] parameters) { | ||
486 | return rawStreamAllValues(POSITION_S, parameters).map(Segment.class::cast); | ||
487 | } | ||
488 | |||
489 | /** | ||
490 | * Retrieve the set of values that occur in matches for S. | ||
491 | * @return the Set of all values or empty set if there are no matches | ||
492 | * | ||
493 | */ | ||
494 | public Set<Segment> getAllValuesOfS() { | ||
495 | return rawStreamAllValuesOfS(emptyArray()).collect(Collectors.toSet()); | ||
496 | } | ||
497 | |||
498 | /** | ||
499 | * Retrieve the set of values that occur in matches for S. | ||
500 | * @return the Set of all values or empty set if there are no matches | ||
501 | * | ||
502 | */ | ||
503 | public Stream<Segment> streamAllValuesOfS() { | ||
504 | return rawStreamAllValuesOfS(emptyArray()); | ||
505 | } | ||
506 | |||
507 | /** | ||
508 | * Retrieve the set of values that occur in matches for S. | ||
509 | * </p> | ||
510 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
511 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
512 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
513 | * | ||
514 | * @return the Stream of all values or empty set if there are no matches | ||
515 | * | ||
516 | */ | ||
517 | public Stream<Segment> streamAllValuesOfS(final TurnoutOutput.Match partialMatch) { | ||
518 | return rawStreamAllValuesOfS(partialMatch.toArray()); | ||
519 | } | ||
520 | |||
521 | /** | ||
522 | * Retrieve the set of values that occur in matches for S. | ||
523 | * </p> | ||
524 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
525 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
526 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
527 | * | ||
528 | * @return the Stream of all values or empty set if there are no matches | ||
529 | * | ||
530 | */ | ||
531 | public Stream<Segment> streamAllValuesOfS(final Turnout pT) { | ||
532 | return rawStreamAllValuesOfS(new Object[]{pT, null}); | ||
533 | } | ||
534 | |||
535 | /** | ||
536 | * Retrieve the set of values that occur in matches for S. | ||
537 | * @return the Set of all values or empty set if there are no matches | ||
538 | * | ||
539 | */ | ||
540 | public Set<Segment> getAllValuesOfS(final TurnoutOutput.Match partialMatch) { | ||
541 | return rawStreamAllValuesOfS(partialMatch.toArray()).collect(Collectors.toSet()); | ||
542 | } | ||
543 | |||
544 | /** | ||
545 | * Retrieve the set of values that occur in matches for S. | ||
546 | * @return the Set of all values or empty set if there are no matches | ||
547 | * | ||
548 | */ | ||
549 | public Set<Segment> getAllValuesOfS(final Turnout pT) { | ||
550 | return rawStreamAllValuesOfS(new Object[]{pT, null}).collect(Collectors.toSet()); | ||
551 | } | ||
552 | |||
553 | @Override | ||
554 | protected TurnoutOutput.Match tupleToMatch(final Tuple t) { | ||
555 | try { | ||
556 | return TurnoutOutput.Match.newMatch((Turnout) t.get(POSITION_T), (Segment) t.get(POSITION_S)); | ||
557 | } catch(ClassCastException e) { | ||
558 | LOGGER.error("Element(s) in tuple not properly typed!",e); | ||
559 | return null; | ||
560 | } | ||
561 | } | ||
562 | |||
563 | @Override | ||
564 | protected TurnoutOutput.Match arrayToMatch(final Object[] match) { | ||
565 | try { | ||
566 | return TurnoutOutput.Match.newMatch((Turnout) match[POSITION_T], (Segment) match[POSITION_S]); | ||
567 | } catch(ClassCastException e) { | ||
568 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
569 | return null; | ||
570 | } | ||
571 | } | ||
572 | |||
573 | @Override | ||
574 | protected TurnoutOutput.Match arrayToMatchMutable(final Object[] match) { | ||
575 | try { | ||
576 | return TurnoutOutput.Match.newMutableMatch((Turnout) match[POSITION_T], (Segment) match[POSITION_S]); | ||
577 | } catch(ClassCastException e) { | ||
578 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
579 | return null; | ||
580 | } | ||
581 | } | ||
582 | |||
583 | /** | ||
584 | * @return the singleton instance of the query specification of this pattern | ||
585 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
586 | * | ||
587 | */ | ||
588 | public static IQuerySpecification<TurnoutOutput.Matcher> querySpecification() { | ||
589 | return TurnoutOutput.instance(); | ||
590 | } | ||
591 | } | ||
592 | |||
593 | private TurnoutOutput() { | ||
594 | super(GeneratedPQuery.INSTANCE); | ||
595 | } | ||
596 | |||
597 | /** | ||
598 | * @return the singleton instance of the query specification | ||
599 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
600 | * | ||
601 | */ | ||
602 | public static TurnoutOutput instance() { | ||
603 | try{ | ||
604 | return LazyHolder.INSTANCE; | ||
605 | } catch (ExceptionInInitializerError err) { | ||
606 | throw processInitializerError(err); | ||
607 | } | ||
608 | } | ||
609 | |||
610 | @Override | ||
611 | protected TurnoutOutput.Matcher instantiate(final ViatraQueryEngine engine) { | ||
612 | return TurnoutOutput.Matcher.on(engine); | ||
613 | } | ||
614 | |||
615 | @Override | ||
616 | public TurnoutOutput.Matcher instantiate() { | ||
617 | return TurnoutOutput.Matcher.create(); | ||
618 | } | ||
619 | |||
620 | @Override | ||
621 | public TurnoutOutput.Match newEmptyMatch() { | ||
622 | return TurnoutOutput.Match.newEmptyMatch(); | ||
623 | } | ||
624 | |||
625 | @Override | ||
626 | public TurnoutOutput.Match newMatch(final Object... parameters) { | ||
627 | return TurnoutOutput.Match.newMatch((modes3.Turnout) parameters[0], (modes3.Segment) parameters[1]); | ||
628 | } | ||
629 | |||
630 | /** | ||
631 | * Inner class allowing the singleton instance of {@link TurnoutOutput} to be created | ||
632 | * <b>not</b> at the class load time of the outer class, | ||
633 | * but rather at the first call to {@link TurnoutOutput#instance()}. | ||
634 | * | ||
635 | * <p> This workaround is required e.g. to support recursion. | ||
636 | * | ||
637 | */ | ||
638 | private static class LazyHolder { | ||
639 | private static final TurnoutOutput INSTANCE = new TurnoutOutput(); | ||
640 | |||
641 | /** | ||
642 | * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned. | ||
643 | * This initialization order is required to support indirect recursion. | ||
644 | * | ||
645 | * <p> The static initializer is defined using a helper field to work around limitations of the code generator. | ||
646 | * | ||
647 | */ | ||
648 | private static final Object STATIC_INITIALIZER = ensureInitialized(); | ||
649 | |||
650 | public static Object ensureInitialized() { | ||
651 | INSTANCE.ensureInitializedInternal(); | ||
652 | return null; | ||
653 | } | ||
654 | } | ||
655 | |||
656 | private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { | ||
657 | private static final TurnoutOutput.GeneratedPQuery INSTANCE = new GeneratedPQuery(); | ||
658 | |||
659 | private final PParameter parameter_T = new PParameter("T", "modes3.Turnout", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Turnout")), PParameterDirection.INOUT); | ||
660 | |||
661 | private final PParameter parameter_S = new PParameter("S", "modes3.Segment", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Segment")), PParameterDirection.INOUT); | ||
662 | |||
663 | private final List<PParameter> parameters = Arrays.asList(parameter_T, parameter_S); | ||
664 | |||
665 | private GeneratedPQuery() { | ||
666 | super(PVisibility.PUBLIC); | ||
667 | } | ||
668 | |||
669 | @Override | ||
670 | public String getFullyQualifiedName() { | ||
671 | return "modes3.queries.turnoutOutput"; | ||
672 | } | ||
673 | |||
674 | @Override | ||
675 | public List<String> getParameterNames() { | ||
676 | return Arrays.asList("T","S"); | ||
677 | } | ||
678 | |||
679 | @Override | ||
680 | public List<PParameter> getParameters() { | ||
681 | return parameters; | ||
682 | } | ||
683 | |||
684 | @Override | ||
685 | public Set<PBody> doGetContainedBodies() { | ||
686 | setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); | ||
687 | Set<PBody> bodies = new LinkedHashSet<>(); | ||
688 | { | ||
689 | PBody body = new PBody(this); | ||
690 | PVariable var_T = body.getOrCreateVariableByName("T"); | ||
691 | PVariable var_S = body.getOrCreateVariableByName("S"); | ||
692 | new TypeConstraint(body, Tuples.flatTupleOf(var_T), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Turnout"))); | ||
693 | new TypeConstraint(body, Tuples.flatTupleOf(var_S), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
694 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
695 | new ExportedParameter(body, var_T, parameter_T), | ||
696 | new ExportedParameter(body, var_S, parameter_S) | ||
697 | )); | ||
698 | // Turnout.straight(T, S) | ||
699 | new TypeConstraint(body, Tuples.flatTupleOf(var_T), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Turnout"))); | ||
700 | PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); | ||
701 | new TypeConstraint(body, Tuples.flatTupleOf(var_T, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Turnout", "straight"))); | ||
702 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
703 | new Equality(body, var__virtual_0_, var_S); | ||
704 | bodies.add(body); | ||
705 | } | ||
706 | { | ||
707 | PBody body = new PBody(this); | ||
708 | PVariable var_T = body.getOrCreateVariableByName("T"); | ||
709 | PVariable var_S = body.getOrCreateVariableByName("S"); | ||
710 | new TypeConstraint(body, Tuples.flatTupleOf(var_T), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Turnout"))); | ||
711 | new TypeConstraint(body, Tuples.flatTupleOf(var_S), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
712 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
713 | new ExportedParameter(body, var_T, parameter_T), | ||
714 | new ExportedParameter(body, var_S, parameter_S) | ||
715 | )); | ||
716 | // Turnout.divergent(T, S) | ||
717 | new TypeConstraint(body, Tuples.flatTupleOf(var_T), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Turnout"))); | ||
718 | PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); | ||
719 | new TypeConstraint(body, Tuples.flatTupleOf(var_T, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Turnout", "divergent"))); | ||
720 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
721 | new Equality(body, var__virtual_0_, var_S); | ||
722 | bodies.add(body); | ||
723 | } | ||
724 | return bodies; | ||
725 | } | ||
726 | } | ||
727 | } | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/TurnoutOutputsAreSame.java b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/TurnoutOutputsAreSame.java new file mode 100644 index 00000000..ba59d45c --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/TurnoutOutputsAreSame.java | |||
@@ -0,0 +1,572 @@ | |||
1 | /** | ||
2 | * Generated from platform:/resource/ca.mcgill.rtgmrt.example.modes3/src/modes3/queries/Modes3Queries.vql | ||
3 | */ | ||
4 | package modes3.queries; | ||
5 | |||
6 | import java.util.Arrays; | ||
7 | import java.util.Collection; | ||
8 | import java.util.LinkedHashSet; | ||
9 | import java.util.List; | ||
10 | import java.util.Objects; | ||
11 | import java.util.Optional; | ||
12 | import java.util.Set; | ||
13 | import java.util.function.Consumer; | ||
14 | import java.util.stream.Collectors; | ||
15 | import java.util.stream.Stream; | ||
16 | import modes3.Turnout; | ||
17 | import org.apache.log4j.Logger; | ||
18 | import org.eclipse.emf.ecore.EClass; | ||
19 | import org.eclipse.viatra.query.runtime.api.IPatternMatch; | ||
20 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification; | ||
21 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; | ||
22 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; | ||
23 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; | ||
24 | import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; | ||
25 | import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; | ||
26 | import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; | ||
27 | import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; | ||
28 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
29 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | ||
30 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | ||
31 | import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation; | ||
32 | import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference; | ||
33 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; | ||
34 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
35 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
36 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | ||
37 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; | ||
38 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | ||
39 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; | ||
40 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
41 | import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; | ||
42 | |||
43 | /** | ||
44 | * A pattern-specific query specification that can instantiate Matcher in a type-safe way. | ||
45 | * | ||
46 | * <p>Original source: | ||
47 | * <code><pre> | ||
48 | * {@literal @}Constraint(message = "turnoutOutputsAreSame", severity = "error", key = { T }) | ||
49 | * pattern turnoutOutputsAreSame(T : Turnout) { | ||
50 | * Turnout.straight(T, S); | ||
51 | * Turnout.divergent(T, S); | ||
52 | * } | ||
53 | * </pre></code> | ||
54 | * | ||
55 | * @see Matcher | ||
56 | * @see Match | ||
57 | * | ||
58 | */ | ||
59 | @SuppressWarnings("all") | ||
60 | public final class TurnoutOutputsAreSame extends BaseGeneratedEMFQuerySpecification<TurnoutOutputsAreSame.Matcher> { | ||
61 | /** | ||
62 | * Pattern-specific match representation of the modes3.queries.turnoutOutputsAreSame pattern, | ||
63 | * to be used in conjunction with {@link Matcher}. | ||
64 | * | ||
65 | * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. | ||
66 | * Each instance is a (possibly partial) substitution of pattern parameters, | ||
67 | * usable to represent a match of the pattern in the result of a query, | ||
68 | * or to specify the bound (fixed) input parameters when issuing a query. | ||
69 | * | ||
70 | * @see Matcher | ||
71 | * | ||
72 | */ | ||
73 | public static abstract class Match extends BasePatternMatch { | ||
74 | private Turnout fT; | ||
75 | |||
76 | private static List<String> parameterNames = makeImmutableList("T"); | ||
77 | |||
78 | private Match(final Turnout pT) { | ||
79 | this.fT = pT; | ||
80 | } | ||
81 | |||
82 | @Override | ||
83 | public Object get(final String parameterName) { | ||
84 | switch(parameterName) { | ||
85 | case "T": return this.fT; | ||
86 | default: return null; | ||
87 | } | ||
88 | } | ||
89 | |||
90 | @Override | ||
91 | public Object get(final int index) { | ||
92 | switch(index) { | ||
93 | case 0: return this.fT; | ||
94 | default: return null; | ||
95 | } | ||
96 | } | ||
97 | |||
98 | public Turnout getT() { | ||
99 | return this.fT; | ||
100 | } | ||
101 | |||
102 | @Override | ||
103 | public boolean set(final String parameterName, final Object newValue) { | ||
104 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
105 | if ("T".equals(parameterName) ) { | ||
106 | this.fT = (Turnout) newValue; | ||
107 | return true; | ||
108 | } | ||
109 | return false; | ||
110 | } | ||
111 | |||
112 | public void setT(final Turnout pT) { | ||
113 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
114 | this.fT = pT; | ||
115 | } | ||
116 | |||
117 | @Override | ||
118 | public String patternName() { | ||
119 | return "modes3.queries.turnoutOutputsAreSame"; | ||
120 | } | ||
121 | |||
122 | @Override | ||
123 | public List<String> parameterNames() { | ||
124 | return TurnoutOutputsAreSame.Match.parameterNames; | ||
125 | } | ||
126 | |||
127 | @Override | ||
128 | public Object[] toArray() { | ||
129 | return new Object[]{fT}; | ||
130 | } | ||
131 | |||
132 | @Override | ||
133 | public TurnoutOutputsAreSame.Match toImmutable() { | ||
134 | return isMutable() ? newMatch(fT) : this; | ||
135 | } | ||
136 | |||
137 | @Override | ||
138 | public String prettyPrint() { | ||
139 | StringBuilder result = new StringBuilder(); | ||
140 | result.append("\"T\"=" + prettyPrintValue(fT)); | ||
141 | return result.toString(); | ||
142 | } | ||
143 | |||
144 | @Override | ||
145 | public int hashCode() { | ||
146 | return Objects.hash(fT); | ||
147 | } | ||
148 | |||
149 | @Override | ||
150 | public boolean equals(final Object obj) { | ||
151 | if (this == obj) | ||
152 | return true; | ||
153 | if (obj == null) { | ||
154 | return false; | ||
155 | } | ||
156 | if ((obj instanceof TurnoutOutputsAreSame.Match)) { | ||
157 | TurnoutOutputsAreSame.Match other = (TurnoutOutputsAreSame.Match) obj; | ||
158 | return Objects.equals(fT, other.fT); | ||
159 | } else { | ||
160 | // this should be infrequent | ||
161 | if (!(obj instanceof IPatternMatch)) { | ||
162 | return false; | ||
163 | } | ||
164 | IPatternMatch otherSig = (IPatternMatch) obj; | ||
165 | return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); | ||
166 | } | ||
167 | } | ||
168 | |||
169 | @Override | ||
170 | public TurnoutOutputsAreSame specification() { | ||
171 | return TurnoutOutputsAreSame.instance(); | ||
172 | } | ||
173 | |||
174 | /** | ||
175 | * Returns an empty, mutable match. | ||
176 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
177 | * | ||
178 | * @return the empty match. | ||
179 | * | ||
180 | */ | ||
181 | public static TurnoutOutputsAreSame.Match newEmptyMatch() { | ||
182 | return new Mutable(null); | ||
183 | } | ||
184 | |||
185 | /** | ||
186 | * Returns a mutable (partial) match. | ||
187 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
188 | * | ||
189 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
190 | * @return the new, mutable (partial) match object. | ||
191 | * | ||
192 | */ | ||
193 | public static TurnoutOutputsAreSame.Match newMutableMatch(final Turnout pT) { | ||
194 | return new Mutable(pT); | ||
195 | } | ||
196 | |||
197 | /** | ||
198 | * Returns a new (partial) match. | ||
199 | * This can be used e.g. to call the matcher with a partial match. | ||
200 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
201 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
202 | * @return the (partial) match object. | ||
203 | * | ||
204 | */ | ||
205 | public static TurnoutOutputsAreSame.Match newMatch(final Turnout pT) { | ||
206 | return new Immutable(pT); | ||
207 | } | ||
208 | |||
209 | private static final class Mutable extends TurnoutOutputsAreSame.Match { | ||
210 | Mutable(final Turnout pT) { | ||
211 | super(pT); | ||
212 | } | ||
213 | |||
214 | @Override | ||
215 | public boolean isMutable() { | ||
216 | return true; | ||
217 | } | ||
218 | } | ||
219 | |||
220 | private static final class Immutable extends TurnoutOutputsAreSame.Match { | ||
221 | Immutable(final Turnout pT) { | ||
222 | super(pT); | ||
223 | } | ||
224 | |||
225 | @Override | ||
226 | public boolean isMutable() { | ||
227 | return false; | ||
228 | } | ||
229 | } | ||
230 | } | ||
231 | |||
232 | /** | ||
233 | * Generated pattern matcher API of the modes3.queries.turnoutOutputsAreSame pattern, | ||
234 | * providing pattern-specific query methods. | ||
235 | * | ||
236 | * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, | ||
237 | * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. | ||
238 | * | ||
239 | * <p>Matches of the pattern will be represented as {@link Match}. | ||
240 | * | ||
241 | * <p>Original source: | ||
242 | * <code><pre> | ||
243 | * {@literal @}Constraint(message = "turnoutOutputsAreSame", severity = "error", key = { T }) | ||
244 | * pattern turnoutOutputsAreSame(T : Turnout) { | ||
245 | * Turnout.straight(T, S); | ||
246 | * Turnout.divergent(T, S); | ||
247 | * } | ||
248 | * </pre></code> | ||
249 | * | ||
250 | * @see Match | ||
251 | * @see TurnoutOutputsAreSame | ||
252 | * | ||
253 | */ | ||
254 | public static class Matcher extends BaseMatcher<TurnoutOutputsAreSame.Match> { | ||
255 | /** | ||
256 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
257 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
258 | * | ||
259 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
260 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
261 | * | ||
262 | */ | ||
263 | public static TurnoutOutputsAreSame.Matcher on(final ViatraQueryEngine engine) { | ||
264 | // check if matcher already exists | ||
265 | Matcher matcher = engine.getExistingMatcher(querySpecification()); | ||
266 | if (matcher == null) { | ||
267 | matcher = (Matcher)engine.getMatcher(querySpecification()); | ||
268 | } | ||
269 | return matcher; | ||
270 | } | ||
271 | |||
272 | /** | ||
273 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
274 | * @return an initialized matcher | ||
275 | * @noreference This method is for internal matcher initialization by the framework, do not call it manually. | ||
276 | * | ||
277 | */ | ||
278 | public static TurnoutOutputsAreSame.Matcher create() { | ||
279 | return new Matcher(); | ||
280 | } | ||
281 | |||
282 | private static final int POSITION_T = 0; | ||
283 | |||
284 | private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(TurnoutOutputsAreSame.Matcher.class); | ||
285 | |||
286 | /** | ||
287 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
288 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
289 | * | ||
290 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
291 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
292 | * | ||
293 | */ | ||
294 | private Matcher() { | ||
295 | super(querySpecification()); | ||
296 | } | ||
297 | |||
298 | /** | ||
299 | * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. | ||
300 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
301 | * @return matches represented as a Match object. | ||
302 | * | ||
303 | */ | ||
304 | public Collection<TurnoutOutputsAreSame.Match> getAllMatches(final Turnout pT) { | ||
305 | return rawStreamAllMatches(new Object[]{pT}).collect(Collectors.toSet()); | ||
306 | } | ||
307 | |||
308 | /** | ||
309 | * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. | ||
310 | * </p> | ||
311 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
312 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
313 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
314 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
315 | * @return a stream of matches represented as a Match object. | ||
316 | * | ||
317 | */ | ||
318 | public Stream<TurnoutOutputsAreSame.Match> streamAllMatches(final Turnout pT) { | ||
319 | return rawStreamAllMatches(new Object[]{pT}); | ||
320 | } | ||
321 | |||
322 | /** | ||
323 | * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
324 | * Neither determinism nor randomness of selection is guaranteed. | ||
325 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
326 | * @return a match represented as a Match object, or null if no match is found. | ||
327 | * | ||
328 | */ | ||
329 | public Optional<TurnoutOutputsAreSame.Match> getOneArbitraryMatch(final Turnout pT) { | ||
330 | return rawGetOneArbitraryMatch(new Object[]{pT}); | ||
331 | } | ||
332 | |||
333 | /** | ||
334 | * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, | ||
335 | * under any possible substitution of the unspecified parameters (if any). | ||
336 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
337 | * @return true if the input is a valid (partial) match of the pattern. | ||
338 | * | ||
339 | */ | ||
340 | public boolean hasMatch(final Turnout pT) { | ||
341 | return rawHasMatch(new Object[]{pT}); | ||
342 | } | ||
343 | |||
344 | /** | ||
345 | * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. | ||
346 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
347 | * @return the number of pattern matches found. | ||
348 | * | ||
349 | */ | ||
350 | public int countMatches(final Turnout pT) { | ||
351 | return rawCountMatches(new Object[]{pT}); | ||
352 | } | ||
353 | |||
354 | /** | ||
355 | * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
356 | * Neither determinism nor randomness of selection is guaranteed. | ||
357 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
358 | * @param processor the action that will process the selected match. | ||
359 | * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked | ||
360 | * | ||
361 | */ | ||
362 | public boolean forOneArbitraryMatch(final Turnout pT, final Consumer<? super TurnoutOutputsAreSame.Match> processor) { | ||
363 | return rawForOneArbitraryMatch(new Object[]{pT}, processor); | ||
364 | } | ||
365 | |||
366 | /** | ||
367 | * Returns a new (partial) match. | ||
368 | * This can be used e.g. to call the matcher with a partial match. | ||
369 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
370 | * @param pT the fixed value of pattern parameter T, or null if not bound. | ||
371 | * @return the (partial) match object. | ||
372 | * | ||
373 | */ | ||
374 | public TurnoutOutputsAreSame.Match newMatch(final Turnout pT) { | ||
375 | return TurnoutOutputsAreSame.Match.newMatch(pT); | ||
376 | } | ||
377 | |||
378 | /** | ||
379 | * Retrieve the set of values that occur in matches for T. | ||
380 | * @return the Set of all values or empty set if there are no matches | ||
381 | * | ||
382 | */ | ||
383 | protected Stream<Turnout> rawStreamAllValuesOfT(final Object[] parameters) { | ||
384 | return rawStreamAllValues(POSITION_T, parameters).map(Turnout.class::cast); | ||
385 | } | ||
386 | |||
387 | /** | ||
388 | * Retrieve the set of values that occur in matches for T. | ||
389 | * @return the Set of all values or empty set if there are no matches | ||
390 | * | ||
391 | */ | ||
392 | public Set<Turnout> getAllValuesOfT() { | ||
393 | return rawStreamAllValuesOfT(emptyArray()).collect(Collectors.toSet()); | ||
394 | } | ||
395 | |||
396 | /** | ||
397 | * Retrieve the set of values that occur in matches for T. | ||
398 | * @return the Set of all values or empty set if there are no matches | ||
399 | * | ||
400 | */ | ||
401 | public Stream<Turnout> streamAllValuesOfT() { | ||
402 | return rawStreamAllValuesOfT(emptyArray()); | ||
403 | } | ||
404 | |||
405 | @Override | ||
406 | protected TurnoutOutputsAreSame.Match tupleToMatch(final Tuple t) { | ||
407 | try { | ||
408 | return TurnoutOutputsAreSame.Match.newMatch((Turnout) t.get(POSITION_T)); | ||
409 | } catch(ClassCastException e) { | ||
410 | LOGGER.error("Element(s) in tuple not properly typed!",e); | ||
411 | return null; | ||
412 | } | ||
413 | } | ||
414 | |||
415 | @Override | ||
416 | protected TurnoutOutputsAreSame.Match arrayToMatch(final Object[] match) { | ||
417 | try { | ||
418 | return TurnoutOutputsAreSame.Match.newMatch((Turnout) match[POSITION_T]); | ||
419 | } catch(ClassCastException e) { | ||
420 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
421 | return null; | ||
422 | } | ||
423 | } | ||
424 | |||
425 | @Override | ||
426 | protected TurnoutOutputsAreSame.Match arrayToMatchMutable(final Object[] match) { | ||
427 | try { | ||
428 | return TurnoutOutputsAreSame.Match.newMutableMatch((Turnout) match[POSITION_T]); | ||
429 | } catch(ClassCastException e) { | ||
430 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
431 | return null; | ||
432 | } | ||
433 | } | ||
434 | |||
435 | /** | ||
436 | * @return the singleton instance of the query specification of this pattern | ||
437 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
438 | * | ||
439 | */ | ||
440 | public static IQuerySpecification<TurnoutOutputsAreSame.Matcher> querySpecification() { | ||
441 | return TurnoutOutputsAreSame.instance(); | ||
442 | } | ||
443 | } | ||
444 | |||
445 | private TurnoutOutputsAreSame() { | ||
446 | super(GeneratedPQuery.INSTANCE); | ||
447 | } | ||
448 | |||
449 | /** | ||
450 | * @return the singleton instance of the query specification | ||
451 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
452 | * | ||
453 | */ | ||
454 | public static TurnoutOutputsAreSame instance() { | ||
455 | try{ | ||
456 | return LazyHolder.INSTANCE; | ||
457 | } catch (ExceptionInInitializerError err) { | ||
458 | throw processInitializerError(err); | ||
459 | } | ||
460 | } | ||
461 | |||
462 | @Override | ||
463 | protected TurnoutOutputsAreSame.Matcher instantiate(final ViatraQueryEngine engine) { | ||
464 | return TurnoutOutputsAreSame.Matcher.on(engine); | ||
465 | } | ||
466 | |||
467 | @Override | ||
468 | public TurnoutOutputsAreSame.Matcher instantiate() { | ||
469 | return TurnoutOutputsAreSame.Matcher.create(); | ||
470 | } | ||
471 | |||
472 | @Override | ||
473 | public TurnoutOutputsAreSame.Match newEmptyMatch() { | ||
474 | return TurnoutOutputsAreSame.Match.newEmptyMatch(); | ||
475 | } | ||
476 | |||
477 | @Override | ||
478 | public TurnoutOutputsAreSame.Match newMatch(final Object... parameters) { | ||
479 | return TurnoutOutputsAreSame.Match.newMatch((modes3.Turnout) parameters[0]); | ||
480 | } | ||
481 | |||
482 | /** | ||
483 | * Inner class allowing the singleton instance of {@link TurnoutOutputsAreSame} to be created | ||
484 | * <b>not</b> at the class load time of the outer class, | ||
485 | * but rather at the first call to {@link TurnoutOutputsAreSame#instance()}. | ||
486 | * | ||
487 | * <p> This workaround is required e.g. to support recursion. | ||
488 | * | ||
489 | */ | ||
490 | private static class LazyHolder { | ||
491 | private static final TurnoutOutputsAreSame INSTANCE = new TurnoutOutputsAreSame(); | ||
492 | |||
493 | /** | ||
494 | * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned. | ||
495 | * This initialization order is required to support indirect recursion. | ||
496 | * | ||
497 | * <p> The static initializer is defined using a helper field to work around limitations of the code generator. | ||
498 | * | ||
499 | */ | ||
500 | private static final Object STATIC_INITIALIZER = ensureInitialized(); | ||
501 | |||
502 | public static Object ensureInitialized() { | ||
503 | INSTANCE.ensureInitializedInternal(); | ||
504 | return null; | ||
505 | } | ||
506 | } | ||
507 | |||
508 | private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { | ||
509 | private static final TurnoutOutputsAreSame.GeneratedPQuery INSTANCE = new GeneratedPQuery(); | ||
510 | |||
511 | private final PParameter parameter_T = new PParameter("T", "modes3.Turnout", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Turnout")), PParameterDirection.INOUT); | ||
512 | |||
513 | private final List<PParameter> parameters = Arrays.asList(parameter_T); | ||
514 | |||
515 | private GeneratedPQuery() { | ||
516 | super(PVisibility.PUBLIC); | ||
517 | } | ||
518 | |||
519 | @Override | ||
520 | public String getFullyQualifiedName() { | ||
521 | return "modes3.queries.turnoutOutputsAreSame"; | ||
522 | } | ||
523 | |||
524 | @Override | ||
525 | public List<String> getParameterNames() { | ||
526 | return Arrays.asList("T"); | ||
527 | } | ||
528 | |||
529 | @Override | ||
530 | public List<PParameter> getParameters() { | ||
531 | return parameters; | ||
532 | } | ||
533 | |||
534 | @Override | ||
535 | public Set<PBody> doGetContainedBodies() { | ||
536 | setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); | ||
537 | Set<PBody> bodies = new LinkedHashSet<>(); | ||
538 | { | ||
539 | PBody body = new PBody(this); | ||
540 | PVariable var_T = body.getOrCreateVariableByName("T"); | ||
541 | PVariable var_S = body.getOrCreateVariableByName("S"); | ||
542 | new TypeConstraint(body, Tuples.flatTupleOf(var_T), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Turnout"))); | ||
543 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
544 | new ExportedParameter(body, var_T, parameter_T) | ||
545 | )); | ||
546 | // Turnout.straight(T, S) | ||
547 | new TypeConstraint(body, Tuples.flatTupleOf(var_T), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Turnout"))); | ||
548 | PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); | ||
549 | new TypeConstraint(body, Tuples.flatTupleOf(var_T, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Turnout", "straight"))); | ||
550 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
551 | new Equality(body, var__virtual_0_, var_S); | ||
552 | // Turnout.divergent(T, S) | ||
553 | new TypeConstraint(body, Tuples.flatTupleOf(var_T), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Turnout"))); | ||
554 | PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); | ||
555 | new TypeConstraint(body, Tuples.flatTupleOf(var_T, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Turnout", "divergent"))); | ||
556 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
557 | new Equality(body, var__virtual_1_, var_S); | ||
558 | bodies.add(body); | ||
559 | } | ||
560 | { | ||
561 | PAnnotation annotation = new PAnnotation("Constraint"); | ||
562 | annotation.addAttribute("message", "turnoutOutputsAreSame"); | ||
563 | annotation.addAttribute("severity", "error"); | ||
564 | annotation.addAttribute("key", Arrays.asList(new Object[] { | ||
565 | new ParameterReference("T") | ||
566 | })); | ||
567 | addAnnotation(annotation); | ||
568 | } | ||
569 | return bodies; | ||
570 | } | ||
571 | } | ||
572 | } | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/Unreachable.java b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/Unreachable.java new file mode 100644 index 00000000..a1b76f83 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/Unreachable.java | |||
@@ -0,0 +1,714 @@ | |||
1 | /** | ||
2 | * Generated from platform:/resource/ca.mcgill.rtgmrt.example.modes3/src/modes3/queries/Modes3Queries.vql | ||
3 | */ | ||
4 | package modes3.queries; | ||
5 | |||
6 | import java.util.Arrays; | ||
7 | import java.util.Collection; | ||
8 | import java.util.LinkedHashSet; | ||
9 | import java.util.List; | ||
10 | import java.util.Objects; | ||
11 | import java.util.Optional; | ||
12 | import java.util.Set; | ||
13 | import java.util.function.Consumer; | ||
14 | import java.util.stream.Collectors; | ||
15 | import java.util.stream.Stream; | ||
16 | import modes3.Segment; | ||
17 | import modes3.queries.Reachable; | ||
18 | import org.apache.log4j.Logger; | ||
19 | import org.eclipse.emf.ecore.EClass; | ||
20 | import org.eclipse.viatra.query.runtime.api.IPatternMatch; | ||
21 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification; | ||
22 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; | ||
23 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; | ||
24 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; | ||
25 | import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; | ||
26 | import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; | ||
27 | import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; | ||
28 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
29 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | ||
30 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | ||
31 | import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation; | ||
32 | import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference; | ||
33 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
34 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.NegativePatternCall; | ||
35 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
36 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | ||
37 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; | ||
38 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | ||
39 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; | ||
40 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
41 | import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; | ||
42 | |||
43 | /** | ||
44 | * A pattern-specific query specification that can instantiate Matcher in a type-safe way. | ||
45 | * | ||
46 | * <p>Original source: | ||
47 | * <code><pre> | ||
48 | * {@literal @}Constraint(message = "unreachable", severity = "error", key = { S1, S2 }) | ||
49 | * pattern unreachable(S1 : Segment, S2 : Segment) { | ||
50 | * neg find reachable(S1, S2); | ||
51 | * } | ||
52 | * </pre></code> | ||
53 | * | ||
54 | * @see Matcher | ||
55 | * @see Match | ||
56 | * | ||
57 | */ | ||
58 | @SuppressWarnings("all") | ||
59 | public final class Unreachable extends BaseGeneratedEMFQuerySpecification<Unreachable.Matcher> { | ||
60 | /** | ||
61 | * Pattern-specific match representation of the modes3.queries.unreachable pattern, | ||
62 | * to be used in conjunction with {@link Matcher}. | ||
63 | * | ||
64 | * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. | ||
65 | * Each instance is a (possibly partial) substitution of pattern parameters, | ||
66 | * usable to represent a match of the pattern in the result of a query, | ||
67 | * or to specify the bound (fixed) input parameters when issuing a query. | ||
68 | * | ||
69 | * @see Matcher | ||
70 | * | ||
71 | */ | ||
72 | public static abstract class Match extends BasePatternMatch { | ||
73 | private Segment fS1; | ||
74 | |||
75 | private Segment fS2; | ||
76 | |||
77 | private static List<String> parameterNames = makeImmutableList("S1", "S2"); | ||
78 | |||
79 | private Match(final Segment pS1, final Segment pS2) { | ||
80 | this.fS1 = pS1; | ||
81 | this.fS2 = pS2; | ||
82 | } | ||
83 | |||
84 | @Override | ||
85 | public Object get(final String parameterName) { | ||
86 | switch(parameterName) { | ||
87 | case "S1": return this.fS1; | ||
88 | case "S2": return this.fS2; | ||
89 | default: return null; | ||
90 | } | ||
91 | } | ||
92 | |||
93 | @Override | ||
94 | public Object get(final int index) { | ||
95 | switch(index) { | ||
96 | case 0: return this.fS1; | ||
97 | case 1: return this.fS2; | ||
98 | default: return null; | ||
99 | } | ||
100 | } | ||
101 | |||
102 | public Segment getS1() { | ||
103 | return this.fS1; | ||
104 | } | ||
105 | |||
106 | public Segment getS2() { | ||
107 | return this.fS2; | ||
108 | } | ||
109 | |||
110 | @Override | ||
111 | public boolean set(final String parameterName, final Object newValue) { | ||
112 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
113 | if ("S1".equals(parameterName) ) { | ||
114 | this.fS1 = (Segment) newValue; | ||
115 | return true; | ||
116 | } | ||
117 | if ("S2".equals(parameterName) ) { | ||
118 | this.fS2 = (Segment) newValue; | ||
119 | return true; | ||
120 | } | ||
121 | return false; | ||
122 | } | ||
123 | |||
124 | public void setS1(final Segment pS1) { | ||
125 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
126 | this.fS1 = pS1; | ||
127 | } | ||
128 | |||
129 | public void setS2(final Segment pS2) { | ||
130 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
131 | this.fS2 = pS2; | ||
132 | } | ||
133 | |||
134 | @Override | ||
135 | public String patternName() { | ||
136 | return "modes3.queries.unreachable"; | ||
137 | } | ||
138 | |||
139 | @Override | ||
140 | public List<String> parameterNames() { | ||
141 | return Unreachable.Match.parameterNames; | ||
142 | } | ||
143 | |||
144 | @Override | ||
145 | public Object[] toArray() { | ||
146 | return new Object[]{fS1, fS2}; | ||
147 | } | ||
148 | |||
149 | @Override | ||
150 | public Unreachable.Match toImmutable() { | ||
151 | return isMutable() ? newMatch(fS1, fS2) : this; | ||
152 | } | ||
153 | |||
154 | @Override | ||
155 | public String prettyPrint() { | ||
156 | StringBuilder result = new StringBuilder(); | ||
157 | result.append("\"S1\"=" + prettyPrintValue(fS1) + ", "); | ||
158 | result.append("\"S2\"=" + prettyPrintValue(fS2)); | ||
159 | return result.toString(); | ||
160 | } | ||
161 | |||
162 | @Override | ||
163 | public int hashCode() { | ||
164 | return Objects.hash(fS1, fS2); | ||
165 | } | ||
166 | |||
167 | @Override | ||
168 | public boolean equals(final Object obj) { | ||
169 | if (this == obj) | ||
170 | return true; | ||
171 | if (obj == null) { | ||
172 | return false; | ||
173 | } | ||
174 | if ((obj instanceof Unreachable.Match)) { | ||
175 | Unreachable.Match other = (Unreachable.Match) obj; | ||
176 | return Objects.equals(fS1, other.fS1) && Objects.equals(fS2, other.fS2); | ||
177 | } else { | ||
178 | // this should be infrequent | ||
179 | if (!(obj instanceof IPatternMatch)) { | ||
180 | return false; | ||
181 | } | ||
182 | IPatternMatch otherSig = (IPatternMatch) obj; | ||
183 | return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); | ||
184 | } | ||
185 | } | ||
186 | |||
187 | @Override | ||
188 | public Unreachable specification() { | ||
189 | return Unreachable.instance(); | ||
190 | } | ||
191 | |||
192 | /** | ||
193 | * Returns an empty, mutable match. | ||
194 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
195 | * | ||
196 | * @return the empty match. | ||
197 | * | ||
198 | */ | ||
199 | public static Unreachable.Match newEmptyMatch() { | ||
200 | return new Mutable(null, null); | ||
201 | } | ||
202 | |||
203 | /** | ||
204 | * Returns a mutable (partial) match. | ||
205 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
206 | * | ||
207 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
208 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
209 | * @return the new, mutable (partial) match object. | ||
210 | * | ||
211 | */ | ||
212 | public static Unreachable.Match newMutableMatch(final Segment pS1, final Segment pS2) { | ||
213 | return new Mutable(pS1, pS2); | ||
214 | } | ||
215 | |||
216 | /** | ||
217 | * Returns a new (partial) match. | ||
218 | * This can be used e.g. to call the matcher with a partial match. | ||
219 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
220 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
221 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
222 | * @return the (partial) match object. | ||
223 | * | ||
224 | */ | ||
225 | public static Unreachable.Match newMatch(final Segment pS1, final Segment pS2) { | ||
226 | return new Immutable(pS1, pS2); | ||
227 | } | ||
228 | |||
229 | private static final class Mutable extends Unreachable.Match { | ||
230 | Mutable(final Segment pS1, final Segment pS2) { | ||
231 | super(pS1, pS2); | ||
232 | } | ||
233 | |||
234 | @Override | ||
235 | public boolean isMutable() { | ||
236 | return true; | ||
237 | } | ||
238 | } | ||
239 | |||
240 | private static final class Immutable extends Unreachable.Match { | ||
241 | Immutable(final Segment pS1, final Segment pS2) { | ||
242 | super(pS1, pS2); | ||
243 | } | ||
244 | |||
245 | @Override | ||
246 | public boolean isMutable() { | ||
247 | return false; | ||
248 | } | ||
249 | } | ||
250 | } | ||
251 | |||
252 | /** | ||
253 | * Generated pattern matcher API of the modes3.queries.unreachable pattern, | ||
254 | * providing pattern-specific query methods. | ||
255 | * | ||
256 | * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, | ||
257 | * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. | ||
258 | * | ||
259 | * <p>Matches of the pattern will be represented as {@link Match}. | ||
260 | * | ||
261 | * <p>Original source: | ||
262 | * <code><pre> | ||
263 | * {@literal @}Constraint(message = "unreachable", severity = "error", key = { S1, S2 }) | ||
264 | * pattern unreachable(S1 : Segment, S2 : Segment) { | ||
265 | * neg find reachable(S1, S2); | ||
266 | * } | ||
267 | * </pre></code> | ||
268 | * | ||
269 | * @see Match | ||
270 | * @see Unreachable | ||
271 | * | ||
272 | */ | ||
273 | public static class Matcher extends BaseMatcher<Unreachable.Match> { | ||
274 | /** | ||
275 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
276 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
277 | * | ||
278 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
279 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
280 | * | ||
281 | */ | ||
282 | public static Unreachable.Matcher on(final ViatraQueryEngine engine) { | ||
283 | // check if matcher already exists | ||
284 | Matcher matcher = engine.getExistingMatcher(querySpecification()); | ||
285 | if (matcher == null) { | ||
286 | matcher = (Matcher)engine.getMatcher(querySpecification()); | ||
287 | } | ||
288 | return matcher; | ||
289 | } | ||
290 | |||
291 | /** | ||
292 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
293 | * @return an initialized matcher | ||
294 | * @noreference This method is for internal matcher initialization by the framework, do not call it manually. | ||
295 | * | ||
296 | */ | ||
297 | public static Unreachable.Matcher create() { | ||
298 | return new Matcher(); | ||
299 | } | ||
300 | |||
301 | private static final int POSITION_S1 = 0; | ||
302 | |||
303 | private static final int POSITION_S2 = 1; | ||
304 | |||
305 | private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Unreachable.Matcher.class); | ||
306 | |||
307 | /** | ||
308 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
309 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
310 | * | ||
311 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
312 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
313 | * | ||
314 | */ | ||
315 | private Matcher() { | ||
316 | super(querySpecification()); | ||
317 | } | ||
318 | |||
319 | /** | ||
320 | * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. | ||
321 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
322 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
323 | * @return matches represented as a Match object. | ||
324 | * | ||
325 | */ | ||
326 | public Collection<Unreachable.Match> getAllMatches(final Segment pS1, final Segment pS2) { | ||
327 | return rawStreamAllMatches(new Object[]{pS1, pS2}).collect(Collectors.toSet()); | ||
328 | } | ||
329 | |||
330 | /** | ||
331 | * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. | ||
332 | * </p> | ||
333 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
334 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
335 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
336 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
337 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
338 | * @return a stream of matches represented as a Match object. | ||
339 | * | ||
340 | */ | ||
341 | public Stream<Unreachable.Match> streamAllMatches(final Segment pS1, final Segment pS2) { | ||
342 | return rawStreamAllMatches(new Object[]{pS1, pS2}); | ||
343 | } | ||
344 | |||
345 | /** | ||
346 | * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
347 | * Neither determinism nor randomness of selection is guaranteed. | ||
348 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
349 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
350 | * @return a match represented as a Match object, or null if no match is found. | ||
351 | * | ||
352 | */ | ||
353 | public Optional<Unreachable.Match> getOneArbitraryMatch(final Segment pS1, final Segment pS2) { | ||
354 | return rawGetOneArbitraryMatch(new Object[]{pS1, pS2}); | ||
355 | } | ||
356 | |||
357 | /** | ||
358 | * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, | ||
359 | * under any possible substitution of the unspecified parameters (if any). | ||
360 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
361 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
362 | * @return true if the input is a valid (partial) match of the pattern. | ||
363 | * | ||
364 | */ | ||
365 | public boolean hasMatch(final Segment pS1, final Segment pS2) { | ||
366 | return rawHasMatch(new Object[]{pS1, pS2}); | ||
367 | } | ||
368 | |||
369 | /** | ||
370 | * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. | ||
371 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
372 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
373 | * @return the number of pattern matches found. | ||
374 | * | ||
375 | */ | ||
376 | public int countMatches(final Segment pS1, final Segment pS2) { | ||
377 | return rawCountMatches(new Object[]{pS1, pS2}); | ||
378 | } | ||
379 | |||
380 | /** | ||
381 | * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
382 | * Neither determinism nor randomness of selection is guaranteed. | ||
383 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
384 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
385 | * @param processor the action that will process the selected match. | ||
386 | * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked | ||
387 | * | ||
388 | */ | ||
389 | public boolean forOneArbitraryMatch(final Segment pS1, final Segment pS2, final Consumer<? super Unreachable.Match> processor) { | ||
390 | return rawForOneArbitraryMatch(new Object[]{pS1, pS2}, processor); | ||
391 | } | ||
392 | |||
393 | /** | ||
394 | * Returns a new (partial) match. | ||
395 | * This can be used e.g. to call the matcher with a partial match. | ||
396 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
397 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
398 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
399 | * @return the (partial) match object. | ||
400 | * | ||
401 | */ | ||
402 | public Unreachable.Match newMatch(final Segment pS1, final Segment pS2) { | ||
403 | return Unreachable.Match.newMatch(pS1, pS2); | ||
404 | } | ||
405 | |||
406 | /** | ||
407 | * Retrieve the set of values that occur in matches for S1. | ||
408 | * @return the Set of all values or empty set if there are no matches | ||
409 | * | ||
410 | */ | ||
411 | protected Stream<Segment> rawStreamAllValuesOfS1(final Object[] parameters) { | ||
412 | return rawStreamAllValues(POSITION_S1, parameters).map(Segment.class::cast); | ||
413 | } | ||
414 | |||
415 | /** | ||
416 | * Retrieve the set of values that occur in matches for S1. | ||
417 | * @return the Set of all values or empty set if there are no matches | ||
418 | * | ||
419 | */ | ||
420 | public Set<Segment> getAllValuesOfS1() { | ||
421 | return rawStreamAllValuesOfS1(emptyArray()).collect(Collectors.toSet()); | ||
422 | } | ||
423 | |||
424 | /** | ||
425 | * Retrieve the set of values that occur in matches for S1. | ||
426 | * @return the Set of all values or empty set if there are no matches | ||
427 | * | ||
428 | */ | ||
429 | public Stream<Segment> streamAllValuesOfS1() { | ||
430 | return rawStreamAllValuesOfS1(emptyArray()); | ||
431 | } | ||
432 | |||
433 | /** | ||
434 | * Retrieve the set of values that occur in matches for S1. | ||
435 | * </p> | ||
436 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
437 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
438 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
439 | * | ||
440 | * @return the Stream of all values or empty set if there are no matches | ||
441 | * | ||
442 | */ | ||
443 | public Stream<Segment> streamAllValuesOfS1(final Unreachable.Match partialMatch) { | ||
444 | return rawStreamAllValuesOfS1(partialMatch.toArray()); | ||
445 | } | ||
446 | |||
447 | /** | ||
448 | * Retrieve the set of values that occur in matches for S1. | ||
449 | * </p> | ||
450 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
451 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
452 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
453 | * | ||
454 | * @return the Stream of all values or empty set if there are no matches | ||
455 | * | ||
456 | */ | ||
457 | public Stream<Segment> streamAllValuesOfS1(final Segment pS2) { | ||
458 | return rawStreamAllValuesOfS1(new Object[]{null, pS2}); | ||
459 | } | ||
460 | |||
461 | /** | ||
462 | * Retrieve the set of values that occur in matches for S1. | ||
463 | * @return the Set of all values or empty set if there are no matches | ||
464 | * | ||
465 | */ | ||
466 | public Set<Segment> getAllValuesOfS1(final Unreachable.Match partialMatch) { | ||
467 | return rawStreamAllValuesOfS1(partialMatch.toArray()).collect(Collectors.toSet()); | ||
468 | } | ||
469 | |||
470 | /** | ||
471 | * Retrieve the set of values that occur in matches for S1. | ||
472 | * @return the Set of all values or empty set if there are no matches | ||
473 | * | ||
474 | */ | ||
475 | public Set<Segment> getAllValuesOfS1(final Segment pS2) { | ||
476 | return rawStreamAllValuesOfS1(new Object[]{null, pS2}).collect(Collectors.toSet()); | ||
477 | } | ||
478 | |||
479 | /** | ||
480 | * Retrieve the set of values that occur in matches for S2. | ||
481 | * @return the Set of all values or empty set if there are no matches | ||
482 | * | ||
483 | */ | ||
484 | protected Stream<Segment> rawStreamAllValuesOfS2(final Object[] parameters) { | ||
485 | return rawStreamAllValues(POSITION_S2, parameters).map(Segment.class::cast); | ||
486 | } | ||
487 | |||
488 | /** | ||
489 | * Retrieve the set of values that occur in matches for S2. | ||
490 | * @return the Set of all values or empty set if there are no matches | ||
491 | * | ||
492 | */ | ||
493 | public Set<Segment> getAllValuesOfS2() { | ||
494 | return rawStreamAllValuesOfS2(emptyArray()).collect(Collectors.toSet()); | ||
495 | } | ||
496 | |||
497 | /** | ||
498 | * Retrieve the set of values that occur in matches for S2. | ||
499 | * @return the Set of all values or empty set if there are no matches | ||
500 | * | ||
501 | */ | ||
502 | public Stream<Segment> streamAllValuesOfS2() { | ||
503 | return rawStreamAllValuesOfS2(emptyArray()); | ||
504 | } | ||
505 | |||
506 | /** | ||
507 | * Retrieve the set of values that occur in matches for S2. | ||
508 | * </p> | ||
509 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
510 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
511 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
512 | * | ||
513 | * @return the Stream of all values or empty set if there are no matches | ||
514 | * | ||
515 | */ | ||
516 | public Stream<Segment> streamAllValuesOfS2(final Unreachable.Match partialMatch) { | ||
517 | return rawStreamAllValuesOfS2(partialMatch.toArray()); | ||
518 | } | ||
519 | |||
520 | /** | ||
521 | * Retrieve the set of values that occur in matches for S2. | ||
522 | * </p> | ||
523 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
524 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
525 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
526 | * | ||
527 | * @return the Stream of all values or empty set if there are no matches | ||
528 | * | ||
529 | */ | ||
530 | public Stream<Segment> streamAllValuesOfS2(final Segment pS1) { | ||
531 | return rawStreamAllValuesOfS2(new Object[]{pS1, null}); | ||
532 | } | ||
533 | |||
534 | /** | ||
535 | * Retrieve the set of values that occur in matches for S2. | ||
536 | * @return the Set of all values or empty set if there are no matches | ||
537 | * | ||
538 | */ | ||
539 | public Set<Segment> getAllValuesOfS2(final Unreachable.Match partialMatch) { | ||
540 | return rawStreamAllValuesOfS2(partialMatch.toArray()).collect(Collectors.toSet()); | ||
541 | } | ||
542 | |||
543 | /** | ||
544 | * Retrieve the set of values that occur in matches for S2. | ||
545 | * @return the Set of all values or empty set if there are no matches | ||
546 | * | ||
547 | */ | ||
548 | public Set<Segment> getAllValuesOfS2(final Segment pS1) { | ||
549 | return rawStreamAllValuesOfS2(new Object[]{pS1, null}).collect(Collectors.toSet()); | ||
550 | } | ||
551 | |||
552 | @Override | ||
553 | protected Unreachable.Match tupleToMatch(final Tuple t) { | ||
554 | try { | ||
555 | return Unreachable.Match.newMatch((Segment) t.get(POSITION_S1), (Segment) t.get(POSITION_S2)); | ||
556 | } catch(ClassCastException e) { | ||
557 | LOGGER.error("Element(s) in tuple not properly typed!",e); | ||
558 | return null; | ||
559 | } | ||
560 | } | ||
561 | |||
562 | @Override | ||
563 | protected Unreachable.Match arrayToMatch(final Object[] match) { | ||
564 | try { | ||
565 | return Unreachable.Match.newMatch((Segment) match[POSITION_S1], (Segment) match[POSITION_S2]); | ||
566 | } catch(ClassCastException e) { | ||
567 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
568 | return null; | ||
569 | } | ||
570 | } | ||
571 | |||
572 | @Override | ||
573 | protected Unreachable.Match arrayToMatchMutable(final Object[] match) { | ||
574 | try { | ||
575 | return Unreachable.Match.newMutableMatch((Segment) match[POSITION_S1], (Segment) match[POSITION_S2]); | ||
576 | } catch(ClassCastException e) { | ||
577 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
578 | return null; | ||
579 | } | ||
580 | } | ||
581 | |||
582 | /** | ||
583 | * @return the singleton instance of the query specification of this pattern | ||
584 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
585 | * | ||
586 | */ | ||
587 | public static IQuerySpecification<Unreachable.Matcher> querySpecification() { | ||
588 | return Unreachable.instance(); | ||
589 | } | ||
590 | } | ||
591 | |||
592 | private Unreachable() { | ||
593 | super(GeneratedPQuery.INSTANCE); | ||
594 | } | ||
595 | |||
596 | /** | ||
597 | * @return the singleton instance of the query specification | ||
598 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
599 | * | ||
600 | */ | ||
601 | public static Unreachable instance() { | ||
602 | try{ | ||
603 | return LazyHolder.INSTANCE; | ||
604 | } catch (ExceptionInInitializerError err) { | ||
605 | throw processInitializerError(err); | ||
606 | } | ||
607 | } | ||
608 | |||
609 | @Override | ||
610 | protected Unreachable.Matcher instantiate(final ViatraQueryEngine engine) { | ||
611 | return Unreachable.Matcher.on(engine); | ||
612 | } | ||
613 | |||
614 | @Override | ||
615 | public Unreachable.Matcher instantiate() { | ||
616 | return Unreachable.Matcher.create(); | ||
617 | } | ||
618 | |||
619 | @Override | ||
620 | public Unreachable.Match newEmptyMatch() { | ||
621 | return Unreachable.Match.newEmptyMatch(); | ||
622 | } | ||
623 | |||
624 | @Override | ||
625 | public Unreachable.Match newMatch(final Object... parameters) { | ||
626 | return Unreachable.Match.newMatch((modes3.Segment) parameters[0], (modes3.Segment) parameters[1]); | ||
627 | } | ||
628 | |||
629 | /** | ||
630 | * Inner class allowing the singleton instance of {@link Unreachable} to be created | ||
631 | * <b>not</b> at the class load time of the outer class, | ||
632 | * but rather at the first call to {@link Unreachable#instance()}. | ||
633 | * | ||
634 | * <p> This workaround is required e.g. to support recursion. | ||
635 | * | ||
636 | */ | ||
637 | private static class LazyHolder { | ||
638 | private static final Unreachable INSTANCE = new Unreachable(); | ||
639 | |||
640 | /** | ||
641 | * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned. | ||
642 | * This initialization order is required to support indirect recursion. | ||
643 | * | ||
644 | * <p> The static initializer is defined using a helper field to work around limitations of the code generator. | ||
645 | * | ||
646 | */ | ||
647 | private static final Object STATIC_INITIALIZER = ensureInitialized(); | ||
648 | |||
649 | public static Object ensureInitialized() { | ||
650 | INSTANCE.ensureInitializedInternal(); | ||
651 | return null; | ||
652 | } | ||
653 | } | ||
654 | |||
655 | private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { | ||
656 | private static final Unreachable.GeneratedPQuery INSTANCE = new GeneratedPQuery(); | ||
657 | |||
658 | private final PParameter parameter_S1 = new PParameter("S1", "modes3.Segment", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Segment")), PParameterDirection.INOUT); | ||
659 | |||
660 | private final PParameter parameter_S2 = new PParameter("S2", "modes3.Segment", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Segment")), PParameterDirection.INOUT); | ||
661 | |||
662 | private final List<PParameter> parameters = Arrays.asList(parameter_S1, parameter_S2); | ||
663 | |||
664 | private GeneratedPQuery() { | ||
665 | super(PVisibility.PUBLIC); | ||
666 | } | ||
667 | |||
668 | @Override | ||
669 | public String getFullyQualifiedName() { | ||
670 | return "modes3.queries.unreachable"; | ||
671 | } | ||
672 | |||
673 | @Override | ||
674 | public List<String> getParameterNames() { | ||
675 | return Arrays.asList("S1","S2"); | ||
676 | } | ||
677 | |||
678 | @Override | ||
679 | public List<PParameter> getParameters() { | ||
680 | return parameters; | ||
681 | } | ||
682 | |||
683 | @Override | ||
684 | public Set<PBody> doGetContainedBodies() { | ||
685 | setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); | ||
686 | Set<PBody> bodies = new LinkedHashSet<>(); | ||
687 | { | ||
688 | PBody body = new PBody(this); | ||
689 | PVariable var_S1 = body.getOrCreateVariableByName("S1"); | ||
690 | PVariable var_S2 = body.getOrCreateVariableByName("S2"); | ||
691 | new TypeConstraint(body, Tuples.flatTupleOf(var_S1), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
692 | new TypeConstraint(body, Tuples.flatTupleOf(var_S2), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
693 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
694 | new ExportedParameter(body, var_S1, parameter_S1), | ||
695 | new ExportedParameter(body, var_S2, parameter_S2) | ||
696 | )); | ||
697 | // neg find reachable(S1, S2) | ||
698 | new NegativePatternCall(body, Tuples.flatTupleOf(var_S1, var_S2), Reachable.instance().getInternalQueryRepresentation()); | ||
699 | bodies.add(body); | ||
700 | } | ||
701 | { | ||
702 | PAnnotation annotation = new PAnnotation("Constraint"); | ||
703 | annotation.addAttribute("message", "unreachable"); | ||
704 | annotation.addAttribute("severity", "error"); | ||
705 | annotation.addAttribute("key", Arrays.asList(new Object[] { | ||
706 | new ParameterReference("S1"), | ||
707 | new ParameterReference("S2") | ||
708 | })); | ||
709 | addAnnotation(annotation); | ||
710 | } | ||
711 | return bodies; | ||
712 | } | ||
713 | } | ||
714 | } | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/.CloseTrainsObjectiveHint.xtendbin b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/.CloseTrainsObjectiveHint.xtendbin new file mode 100644 index 00000000..ddc8ea74 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/.CloseTrainsObjectiveHint.xtendbin | |||
Binary files differ | |||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/.EndOfSidingObjectiveHint.xtendbin b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/.EndOfSidingObjectiveHint.xtendbin new file mode 100644 index 00000000..e89ea81c --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/.EndOfSidingObjectiveHint.xtendbin | |||
Binary files differ | |||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/.MisalignedTurnoutObjectiveHint.xtendbin b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/.MisalignedTurnoutObjectiveHint.xtendbin new file mode 100644 index 00000000..e006abd7 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/.MisalignedTurnoutObjectiveHint.xtendbin | |||
Binary files differ | |||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/.Modes3ModelGenerator.xtendbin b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/.Modes3ModelGenerator.xtendbin new file mode 100644 index 00000000..11227a1c --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/.Modes3ModelGenerator.xtendbin | |||
Binary files differ | |||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/.Modes3TypeScopeHint.xtendbin b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/.Modes3TypeScopeHint.xtendbin new file mode 100644 index 00000000..90728c00 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/.Modes3TypeScopeHint.xtendbin | |||
Binary files differ | |||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/.Modes3UnitPropagationGenerator.xtendbin b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/.Modes3UnitPropagationGenerator.xtendbin new file mode 100644 index 00000000..4625dcf2 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/.Modes3UnitPropagationGenerator.xtendbin | |||
Binary files differ | |||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/.TrainLocationsObjectiveHint.xtendbin b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/.TrainLocationsObjectiveHint.xtendbin new file mode 100644 index 00000000..d74342ba --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/.TrainLocationsObjectiveHint.xtendbin | |||
Binary files differ | |||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/.gitignore b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/.gitignore new file mode 100644 index 00000000..1a7df1d9 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/.gitignore | |||
@@ -0,0 +1,13 @@ | |||
1 | /.Modes3ModelGenerator.java._trace | ||
2 | /.Modes3UnitPropagationGenerator.java._trace | ||
3 | /.Modes3TypeScopeHint.java._trace | ||
4 | /.Modes3TypeScopeHint.xtendbin | ||
5 | /.Modes3UnitPropagationGenerator.xtendbin | ||
6 | /Modes3TypeScopeHint.java | ||
7 | /.Modes3ModelGenerator.xtendbin | ||
8 | /Modes3ModelGenerator.java | ||
9 | /Modes3UnitPropagationGenerator.java | ||
10 | /.CloseTrainsObjectiveHint.java._trace | ||
11 | /.TrainLocationsObjectiveHint.java._trace | ||
12 | /.MisalignedTurnoutObjectiveHint.java._trace | ||
13 | /.EndOfSidingObjectiveHint.java._trace | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/CloseTrainsObjectiveHint.java b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/CloseTrainsObjectiveHint.java new file mode 100644 index 00000000..babfa7e1 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/CloseTrainsObjectiveHint.java | |||
@@ -0,0 +1,279 @@ | |||
1 | package modes3.run; | ||
2 | |||
3 | import com.google.common.base.Objects; | ||
4 | import com.google.common.collect.ImmutableList; | ||
5 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic; | ||
6 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace; | ||
7 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type; | ||
8 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.Dimension; | ||
9 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.ExtendedLinearExpressionBuilder; | ||
10 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.ExtendedLinearExpressionBuilderFactory; | ||
11 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.PolyhedronExtensionOperator; | ||
12 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.CostElementMatch; | ||
13 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.CostElementMatchers; | ||
14 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.CostObjectiveHint; | ||
15 | import java.util.Collection; | ||
16 | import java.util.List; | ||
17 | import java.util.Map; | ||
18 | import java.util.Set; | ||
19 | import modes3.Modes3Package; | ||
20 | import modes3.queries.CloseTrains_step_2; | ||
21 | import modes3.queries.CloseTrains_step_3; | ||
22 | import modes3.queries.CloseTrains_step_4; | ||
23 | import modes3.queries.CloseTrains_step_5; | ||
24 | import modes3.queries.CloseTrains_step_6; | ||
25 | import modes3.queries.CloseTrains_step_7; | ||
26 | import org.eclipse.viatra.query.runtime.api.IPatternMatch; | ||
27 | import org.eclipse.xtext.xbase.lib.Extension; | ||
28 | import org.eclipse.xtext.xbase.lib.Functions.Function1; | ||
29 | import org.eclipse.xtext.xbase.lib.IterableExtensions; | ||
30 | |||
31 | @SuppressWarnings("all") | ||
32 | public class CloseTrainsObjectiveHint extends CostObjectiveHint { | ||
33 | private final Type segmentType; | ||
34 | |||
35 | private final Type trainType; | ||
36 | |||
37 | public CloseTrainsObjectiveHint(@Extension final Ecore2Logic ecore2Logic, final Ecore2Logic_Trace ecore2LogicTrace) { | ||
38 | @Extension | ||
39 | final Modes3Package Modes3Package = modes3.Modes3Package.eINSTANCE; | ||
40 | this.segmentType = ecore2Logic.TypeofEClass(ecore2LogicTrace, Modes3Package.getSegment()); | ||
41 | this.trainType = ecore2Logic.TypeofEClass(ecore2LogicTrace, Modes3Package.getTrain()); | ||
42 | } | ||
43 | |||
44 | @Override | ||
45 | public boolean isExact() { | ||
46 | return true; | ||
47 | } | ||
48 | |||
49 | @Override | ||
50 | public PolyhedronExtensionOperator createPolyhedronExtensionOperator(final Map<String, CostElementMatchers> costElementMatchers) { | ||
51 | PolyhedronExtensionOperator _xblockexpression = null; | ||
52 | { | ||
53 | final CostElementMatchers step2 = costElementMatchers.get(CloseTrains_step_2.instance().getFullyQualifiedName()); | ||
54 | final CostElementMatchers step3 = costElementMatchers.get(CloseTrains_step_3.instance().getFullyQualifiedName()); | ||
55 | final CostElementMatchers step4 = costElementMatchers.get(CloseTrains_step_4.instance().getFullyQualifiedName()); | ||
56 | final CostElementMatchers step5 = costElementMatchers.get(CloseTrains_step_5.instance().getFullyQualifiedName()); | ||
57 | final CostElementMatchers step6 = costElementMatchers.get(CloseTrains_step_6.instance().getFullyQualifiedName()); | ||
58 | final CostElementMatchers step7 = costElementMatchers.get(CloseTrains_step_7.instance().getFullyQualifiedName()); | ||
59 | final PolyhedronExtensionOperator _function = (ExtendedLinearExpressionBuilderFactory it) -> { | ||
60 | final ExtendedLinearExpressionBuilder objectiveBuilder = it.createBuilder(); | ||
61 | ImmutableList<CostElementMatch> _matches = step2.getMatches(); | ||
62 | for (final CostElementMatch m : _matches) { | ||
63 | { | ||
64 | final Dimension dimension = it.getDimension(m.getMatch()); | ||
65 | objectiveBuilder.add(step2.getWeight(), dimension); | ||
66 | dimension.tightenLowerBound(Integer.valueOf(0)); | ||
67 | boolean _isMulti = m.isMulti(); | ||
68 | if (_isMulti) { | ||
69 | it.createBuilder().add(1, dimension).add((-1), this.trainType).build().assertEqualsTo(0); | ||
70 | } else { | ||
71 | dimension.tightenUpperBound(Integer.valueOf(1)); | ||
72 | boolean _isMust = m.isMust(); | ||
73 | if (_isMust) { | ||
74 | dimension.tightenLowerBound(Integer.valueOf(1)); | ||
75 | } | ||
76 | } | ||
77 | } | ||
78 | } | ||
79 | final ImmutableList<CostElementMatch> step3Matches = step3.getMatches(); | ||
80 | for (final CostElementMatch m_1 : step3Matches) { | ||
81 | { | ||
82 | final Dimension dimension = it.getDimension(m_1.getMatch()); | ||
83 | objectiveBuilder.add(step3.getWeight(), dimension); | ||
84 | dimension.tightenLowerBound(Integer.valueOf(0)); | ||
85 | boolean _isMulti = m_1.isMulti(); | ||
86 | boolean _not = (!_isMulti); | ||
87 | if (_not) { | ||
88 | dimension.tightenUpperBound(Integer.valueOf(1)); | ||
89 | boolean _isMust = m_1.isMust(); | ||
90 | if (_isMust) { | ||
91 | dimension.tightenLowerBound(Integer.valueOf(1)); | ||
92 | } | ||
93 | } | ||
94 | } | ||
95 | } | ||
96 | final Function1<CostElementMatch, IPatternMatch> _function_1 = (CostElementMatch it_1) -> { | ||
97 | return step2.projectMayMatch(it_1.getMatch(), 2); | ||
98 | }; | ||
99 | Set<Map.Entry<IPatternMatch, List<CostElementMatch>>> _entrySet = IterableExtensions.<IPatternMatch, CostElementMatch>groupBy(step3Matches, _function_1).entrySet(); | ||
100 | for (final Map.Entry<IPatternMatch, List<CostElementMatch>> pair : _entrySet) { | ||
101 | { | ||
102 | final ExtendedLinearExpressionBuilder multiplicityBuilder = it.createBuilder(); | ||
103 | List<CostElementMatch> _value = pair.getValue(); | ||
104 | for (final CostElementMatch m_2 : _value) { | ||
105 | multiplicityBuilder.add(1, m_2.getMatch()); | ||
106 | } | ||
107 | multiplicityBuilder.add((-1), pair.getKey()); | ||
108 | multiplicityBuilder.build().assertEqualsTo(0); | ||
109 | } | ||
110 | } | ||
111 | CloseTrainsObjectiveHint.boundLimit(it, step3Matches, 2, this.trainType, 1); | ||
112 | CloseTrainsObjectiveHint.boundLimit(it, step3Matches, 3, this.segmentType, 1); | ||
113 | final ImmutableList<CostElementMatch> step4Matches = step4.getMatches(); | ||
114 | for (final CostElementMatch m_2 : step4Matches) { | ||
115 | { | ||
116 | final Dimension dimension = it.getDimension(m_2.getMatch()); | ||
117 | objectiveBuilder.add(step4.getWeight(), dimension); | ||
118 | dimension.tightenLowerBound(Integer.valueOf(0)); | ||
119 | boolean _isMulti = m_2.isMulti(); | ||
120 | boolean _not = (!_isMulti); | ||
121 | if (_not) { | ||
122 | dimension.tightenUpperBound(Integer.valueOf(1)); | ||
123 | boolean _isMust = m_2.isMust(); | ||
124 | if (_isMust) { | ||
125 | dimension.tightenLowerBound(Integer.valueOf(1)); | ||
126 | } | ||
127 | } | ||
128 | } | ||
129 | } | ||
130 | final Function1<CostElementMatch, IPatternMatch> _function_2 = (CostElementMatch it_1) -> { | ||
131 | return step3.projectMayMatch(it_1.getMatch(), 2, 3); | ||
132 | }; | ||
133 | Set<Map.Entry<IPatternMatch, List<CostElementMatch>>> _entrySet_1 = IterableExtensions.<IPatternMatch, CostElementMatch>groupBy(step4Matches, _function_2).entrySet(); | ||
134 | for (final Map.Entry<IPatternMatch, List<CostElementMatch>> pair_1 : _entrySet_1) { | ||
135 | { | ||
136 | final ExtendedLinearExpressionBuilder multiplicityBuilder = it.createBuilder(); | ||
137 | List<CostElementMatch> _value = pair_1.getValue(); | ||
138 | for (final CostElementMatch m_3 : _value) { | ||
139 | multiplicityBuilder.add(1, m_3.getMatch()); | ||
140 | } | ||
141 | multiplicityBuilder.add((-2), pair_1.getKey()); | ||
142 | multiplicityBuilder.build().tightenUpperBound(Integer.valueOf(0)); | ||
143 | } | ||
144 | } | ||
145 | CloseTrainsObjectiveHint.boundLimit(it, step4Matches, 2, this.trainType, 2); | ||
146 | CloseTrainsObjectiveHint.boundLimit(it, step4Matches, 3, this.segmentType, 2); | ||
147 | CloseTrainsObjectiveHint.boundLimit(it, step4Matches, 4, this.segmentType, 2); | ||
148 | final ImmutableList<CostElementMatch> step5Matches = step5.getMatches(); | ||
149 | for (final CostElementMatch m_3 : step5Matches) { | ||
150 | { | ||
151 | final Dimension dimension = it.getDimension(m_3.getMatch()); | ||
152 | objectiveBuilder.add(step5.getWeight(), dimension); | ||
153 | dimension.tightenLowerBound(Integer.valueOf(0)); | ||
154 | boolean _isMulti = m_3.isMulti(); | ||
155 | boolean _not = (!_isMulti); | ||
156 | if (_not) { | ||
157 | dimension.tightenUpperBound(Integer.valueOf(1)); | ||
158 | boolean _isMust = m_3.isMust(); | ||
159 | if (_isMust) { | ||
160 | dimension.tightenLowerBound(Integer.valueOf(1)); | ||
161 | } | ||
162 | } | ||
163 | } | ||
164 | } | ||
165 | final Function1<CostElementMatch, IPatternMatch> _function_3 = (CostElementMatch it_1) -> { | ||
166 | return step4.projectMayMatch(it_1.getMatch(), 2, 3, 4); | ||
167 | }; | ||
168 | Set<Map.Entry<IPatternMatch, List<CostElementMatch>>> _entrySet_2 = IterableExtensions.<IPatternMatch, CostElementMatch>groupBy(step5Matches, _function_3).entrySet(); | ||
169 | for (final Map.Entry<IPatternMatch, List<CostElementMatch>> pair_2 : _entrySet_2) { | ||
170 | { | ||
171 | final ExtendedLinearExpressionBuilder multiplicityBuilder = it.createBuilder(); | ||
172 | List<CostElementMatch> _value = pair_2.getValue(); | ||
173 | for (final CostElementMatch m_4 : _value) { | ||
174 | multiplicityBuilder.add(1, m_4.getMatch()); | ||
175 | } | ||
176 | multiplicityBuilder.add((-2), pair_2.getKey()); | ||
177 | multiplicityBuilder.build().tightenUpperBound(Integer.valueOf(0)); | ||
178 | } | ||
179 | } | ||
180 | CloseTrainsObjectiveHint.boundLimit(it, step5Matches, 2, this.trainType, 4); | ||
181 | CloseTrainsObjectiveHint.boundLimit(it, step5Matches, 3, this.segmentType, 4); | ||
182 | CloseTrainsObjectiveHint.boundLimit(it, step5Matches, 4, this.segmentType, 4); | ||
183 | CloseTrainsObjectiveHint.boundLimit(it, step5Matches, 5, this.segmentType, 4); | ||
184 | final ImmutableList<CostElementMatch> step6Matches = step6.getMatches(); | ||
185 | for (final CostElementMatch m_4 : step6Matches) { | ||
186 | { | ||
187 | final Dimension dimension = it.getDimension(m_4.getMatch()); | ||
188 | objectiveBuilder.add(step6.getWeight(), dimension); | ||
189 | dimension.tightenLowerBound(Integer.valueOf(0)); | ||
190 | boolean _isMulti = m_4.isMulti(); | ||
191 | if (_isMulti) { | ||
192 | Object _get = m_4.getMatch().get(3); | ||
193 | Object _get_1 = m_4.getMatch().get(5); | ||
194 | boolean _equals = Objects.equal(_get, _get_1); | ||
195 | if (_equals) { | ||
196 | it.createBuilder().add(2, m_4.getMatch()).add((-1), step5.projectMayMatch(m_4.getMatch(), 2, 3, 4, 5)).build().assertEqualsTo(0); | ||
197 | } else { | ||
198 | it.createBuilder().add(1, m_4.getMatch()).add((-1), step5.projectMayMatch(m_4.getMatch(), 2, 3, 4, 5)).build().assertEqualsTo(0); | ||
199 | } | ||
200 | } else { | ||
201 | dimension.tightenUpperBound(Integer.valueOf(1)); | ||
202 | boolean _isMust = m_4.isMust(); | ||
203 | if (_isMust) { | ||
204 | dimension.tightenLowerBound(Integer.valueOf(1)); | ||
205 | } | ||
206 | } | ||
207 | } | ||
208 | } | ||
209 | CloseTrainsObjectiveHint.boundLimit(it, step6Matches, 2, this.trainType, 2); | ||
210 | CloseTrainsObjectiveHint.boundLimit(it, step6Matches, 3, this.segmentType, 2); | ||
211 | CloseTrainsObjectiveHint.boundLimit(it, step6Matches, 4, this.segmentType, 2); | ||
212 | CloseTrainsObjectiveHint.boundLimit(it, step6Matches, 5, this.segmentType, 2); | ||
213 | final ImmutableList<CostElementMatch> step7Matches = step7.getMatches(); | ||
214 | for (final CostElementMatch m_5 : step7Matches) { | ||
215 | { | ||
216 | final Dimension dimension = it.getDimension(m_5.getMatch()); | ||
217 | objectiveBuilder.add(step7.getWeight(), dimension); | ||
218 | dimension.tightenLowerBound(Integer.valueOf(0)); | ||
219 | boolean _isMulti = m_5.isMulti(); | ||
220 | boolean _not = (!_isMulti); | ||
221 | if (_not) { | ||
222 | dimension.tightenUpperBound(Integer.valueOf(1)); | ||
223 | boolean _isMust = m_5.isMust(); | ||
224 | if (_isMust) { | ||
225 | dimension.tightenLowerBound(Integer.valueOf(1)); | ||
226 | } | ||
227 | } | ||
228 | } | ||
229 | } | ||
230 | final Function1<CostElementMatch, IPatternMatch> _function_4 = (CostElementMatch it_1) -> { | ||
231 | return step6.projectMayMatch(it_1.getMatch(), 2, 3, 4, 5); | ||
232 | }; | ||
233 | Set<Map.Entry<IPatternMatch, List<CostElementMatch>>> _entrySet_3 = IterableExtensions.<IPatternMatch, CostElementMatch>groupBy(step7Matches, _function_4).entrySet(); | ||
234 | for (final Map.Entry<IPatternMatch, List<CostElementMatch>> pair_3 : _entrySet_3) { | ||
235 | { | ||
236 | final ExtendedLinearExpressionBuilder multiplicityBuilder = it.createBuilder(); | ||
237 | List<CostElementMatch> _value = pair_3.getValue(); | ||
238 | for (final CostElementMatch m_6 : _value) { | ||
239 | multiplicityBuilder.add(1, m_6.getMatch()); | ||
240 | } | ||
241 | multiplicityBuilder.add((-1), pair_3.getKey()); | ||
242 | multiplicityBuilder.build().tightenUpperBound(Integer.valueOf(0)); | ||
243 | } | ||
244 | } | ||
245 | CloseTrainsObjectiveHint.boundLimit(it, step7Matches, 2, this.trainType, 2); | ||
246 | CloseTrainsObjectiveHint.boundLimit(it, step7Matches, 3, this.segmentType, 2); | ||
247 | CloseTrainsObjectiveHint.boundLimit(it, step7Matches, 4, this.segmentType, 2); | ||
248 | CloseTrainsObjectiveHint.boundLimit(it, step7Matches, 5, this.segmentType, 2); | ||
249 | CloseTrainsObjectiveHint.boundLimit(it, step7Matches, 6, this.trainType, 2); | ||
250 | this.buildWithBounds(objectiveBuilder); | ||
251 | }; | ||
252 | _xblockexpression = _function; | ||
253 | } | ||
254 | return _xblockexpression; | ||
255 | } | ||
256 | |||
257 | private static void boundLimit(@Extension final ExtendedLinearExpressionBuilderFactory factory, final Collection<CostElementMatch> matches, final int index, final Type type, final int count) { | ||
258 | final Function1<CostElementMatch, Object> _function = (CostElementMatch it) -> { | ||
259 | return it.getMatch().get(index); | ||
260 | }; | ||
261 | Set<Map.Entry<Object, List<CostElementMatch>>> _entrySet = IterableExtensions.<Object, CostElementMatch>groupBy(matches, _function).entrySet(); | ||
262 | for (final Map.Entry<Object, List<CostElementMatch>> pair : _entrySet) { | ||
263 | { | ||
264 | final ExtendedLinearExpressionBuilder multiplicityBuilder = factory.createBuilder(); | ||
265 | List<CostElementMatch> _value = pair.getValue(); | ||
266 | for (final CostElementMatch m : _value) { | ||
267 | multiplicityBuilder.add(1, m.getMatch()); | ||
268 | } | ||
269 | boolean _isMulti = CostElementMatchers.isMulti(pair.getKey()); | ||
270 | if (_isMulti) { | ||
271 | multiplicityBuilder.add((-count), type); | ||
272 | multiplicityBuilder.build().tightenUpperBound(Integer.valueOf(0)); | ||
273 | } else { | ||
274 | multiplicityBuilder.build().tightenUpperBound(Integer.valueOf(count)); | ||
275 | } | ||
276 | } | ||
277 | } | ||
278 | } | ||
279 | } | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/EndOfSidingObjectiveHint.java b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/EndOfSidingObjectiveHint.java new file mode 100644 index 00000000..77c513e1 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/EndOfSidingObjectiveHint.java | |||
@@ -0,0 +1,193 @@ | |||
1 | package modes3.run; | ||
2 | |||
3 | import com.google.common.collect.ImmutableList; | ||
4 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic; | ||
5 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace; | ||
6 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type; | ||
7 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.Dimension; | ||
8 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.ExtendedLinearExpressionBuilder; | ||
9 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.ExtendedLinearExpressionBuilderFactory; | ||
10 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.PolyhedronExtensionOperator; | ||
11 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.CostElementMatch; | ||
12 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.CostElementMatchers; | ||
13 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.CostObjectiveHint; | ||
14 | import java.util.Collection; | ||
15 | import java.util.List; | ||
16 | import java.util.Map; | ||
17 | import java.util.Set; | ||
18 | import modes3.Modes3Package; | ||
19 | import modes3.queries.EndOfSiding_step_2; | ||
20 | import modes3.queries.EndOfSiding_step_3; | ||
21 | import modes3.queries.EndOfSiding_step_4; | ||
22 | import modes3.queries.EndOfSiding_step_5; | ||
23 | import org.eclipse.viatra.query.runtime.api.IPatternMatch; | ||
24 | import org.eclipse.xtext.xbase.lib.Extension; | ||
25 | import org.eclipse.xtext.xbase.lib.Functions.Function1; | ||
26 | import org.eclipse.xtext.xbase.lib.IterableExtensions; | ||
27 | |||
28 | @SuppressWarnings("all") | ||
29 | public class EndOfSidingObjectiveHint extends CostObjectiveHint { | ||
30 | private final Type segmentType; | ||
31 | |||
32 | private final Type trainType; | ||
33 | |||
34 | public EndOfSidingObjectiveHint(@Extension final Ecore2Logic ecore2Logic, final Ecore2Logic_Trace ecore2LogicTrace) { | ||
35 | @Extension | ||
36 | final Modes3Package Modes3Package = modes3.Modes3Package.eINSTANCE; | ||
37 | this.segmentType = ecore2Logic.TypeofEClass(ecore2LogicTrace, Modes3Package.getSegment()); | ||
38 | this.trainType = ecore2Logic.TypeofEClass(ecore2LogicTrace, Modes3Package.getTrain()); | ||
39 | } | ||
40 | |||
41 | @Override | ||
42 | public boolean isExact() { | ||
43 | return true; | ||
44 | } | ||
45 | |||
46 | @Override | ||
47 | public PolyhedronExtensionOperator createPolyhedronExtensionOperator(final Map<String, CostElementMatchers> costElementMatchers) { | ||
48 | PolyhedronExtensionOperator _xblockexpression = null; | ||
49 | { | ||
50 | final CostElementMatchers step2 = costElementMatchers.get(EndOfSiding_step_2.instance().getFullyQualifiedName()); | ||
51 | final CostElementMatchers step3 = costElementMatchers.get(EndOfSiding_step_3.instance().getFullyQualifiedName()); | ||
52 | final CostElementMatchers step4 = costElementMatchers.get(EndOfSiding_step_4.instance().getFullyQualifiedName()); | ||
53 | final CostElementMatchers step5 = costElementMatchers.get(EndOfSiding_step_5.instance().getFullyQualifiedName()); | ||
54 | final PolyhedronExtensionOperator _function = (ExtendedLinearExpressionBuilderFactory it) -> { | ||
55 | final ExtendedLinearExpressionBuilder objectiveBuilder = it.createBuilder(); | ||
56 | ImmutableList<CostElementMatch> _matches = step2.getMatches(); | ||
57 | for (final CostElementMatch m : _matches) { | ||
58 | { | ||
59 | final Dimension dimension = it.getDimension(m.getMatch()); | ||
60 | objectiveBuilder.add(step2.getWeight(), dimension); | ||
61 | dimension.tightenLowerBound(Integer.valueOf(0)); | ||
62 | boolean _isMulti = m.isMulti(); | ||
63 | if (_isMulti) { | ||
64 | it.createBuilder().add(1, dimension).add((-1), this.trainType).build().assertEqualsTo(0); | ||
65 | } else { | ||
66 | dimension.tightenUpperBound(Integer.valueOf(1)); | ||
67 | boolean _isMust = m.isMust(); | ||
68 | if (_isMust) { | ||
69 | dimension.tightenLowerBound(Integer.valueOf(1)); | ||
70 | } | ||
71 | } | ||
72 | } | ||
73 | } | ||
74 | final ImmutableList<CostElementMatch> step3Matches = step3.getMatches(); | ||
75 | for (final CostElementMatch m_1 : step3Matches) { | ||
76 | { | ||
77 | final Dimension dimension = it.getDimension(m_1.getMatch()); | ||
78 | objectiveBuilder.add(step3.getWeight(), dimension); | ||
79 | dimension.tightenLowerBound(Integer.valueOf(0)); | ||
80 | boolean _isMulti = m_1.isMulti(); | ||
81 | boolean _not = (!_isMulti); | ||
82 | if (_not) { | ||
83 | dimension.tightenUpperBound(Integer.valueOf(1)); | ||
84 | boolean _isMust = m_1.isMust(); | ||
85 | if (_isMust) { | ||
86 | dimension.tightenLowerBound(Integer.valueOf(1)); | ||
87 | } | ||
88 | } | ||
89 | } | ||
90 | } | ||
91 | final Function1<CostElementMatch, IPatternMatch> _function_1 = (CostElementMatch it_1) -> { | ||
92 | return step2.projectMayMatch(it_1.getMatch(), 2); | ||
93 | }; | ||
94 | Set<Map.Entry<IPatternMatch, List<CostElementMatch>>> _entrySet = IterableExtensions.<IPatternMatch, CostElementMatch>groupBy(step3Matches, _function_1).entrySet(); | ||
95 | for (final Map.Entry<IPatternMatch, List<CostElementMatch>> pair : _entrySet) { | ||
96 | { | ||
97 | final ExtendedLinearExpressionBuilder multiplicityBuilder = it.createBuilder(); | ||
98 | List<CostElementMatch> _value = pair.getValue(); | ||
99 | for (final CostElementMatch m_2 : _value) { | ||
100 | multiplicityBuilder.add(1, m_2.getMatch()); | ||
101 | } | ||
102 | multiplicityBuilder.add((-1), pair.getKey()); | ||
103 | multiplicityBuilder.build().assertEqualsTo(0); | ||
104 | } | ||
105 | } | ||
106 | EndOfSidingObjectiveHint.boundLimit(it, step3Matches, 2, this.trainType, 1); | ||
107 | EndOfSidingObjectiveHint.boundLimit(it, step3Matches, 3, this.segmentType, 1); | ||
108 | final ImmutableList<CostElementMatch> step4Matches = step4.getMatches(); | ||
109 | for (final CostElementMatch m_2 : step4Matches) { | ||
110 | { | ||
111 | final Dimension dimension = it.getDimension(m_2.getMatch()); | ||
112 | objectiveBuilder.add(step4.getWeight(), dimension); | ||
113 | dimension.tightenLowerBound(Integer.valueOf(0)); | ||
114 | boolean _isMulti = m_2.isMulti(); | ||
115 | boolean _not = (!_isMulti); | ||
116 | if (_not) { | ||
117 | dimension.tightenUpperBound(Integer.valueOf(1)); | ||
118 | boolean _isMust = m_2.isMust(); | ||
119 | if (_isMust) { | ||
120 | dimension.tightenLowerBound(Integer.valueOf(1)); | ||
121 | } | ||
122 | } | ||
123 | } | ||
124 | } | ||
125 | final Function1<CostElementMatch, IPatternMatch> _function_2 = (CostElementMatch it_1) -> { | ||
126 | return step3.projectMayMatch(it_1.getMatch(), 2, 3); | ||
127 | }; | ||
128 | Set<Map.Entry<IPatternMatch, List<CostElementMatch>>> _entrySet_1 = IterableExtensions.<IPatternMatch, CostElementMatch>groupBy(step4Matches, _function_2).entrySet(); | ||
129 | for (final Map.Entry<IPatternMatch, List<CostElementMatch>> pair_1 : _entrySet_1) { | ||
130 | { | ||
131 | final ExtendedLinearExpressionBuilder multiplicityBuilder = it.createBuilder(); | ||
132 | List<CostElementMatch> _value = pair_1.getValue(); | ||
133 | for (final CostElementMatch m_3 : _value) { | ||
134 | multiplicityBuilder.add(1, m_3.getMatch()); | ||
135 | } | ||
136 | multiplicityBuilder.add((-2), pair_1.getKey()); | ||
137 | multiplicityBuilder.build().tightenUpperBound(Integer.valueOf(0)); | ||
138 | } | ||
139 | } | ||
140 | EndOfSidingObjectiveHint.boundLimit(it, step4Matches, 2, this.trainType, 2); | ||
141 | EndOfSidingObjectiveHint.boundLimit(it, step4Matches, 3, this.segmentType, 2); | ||
142 | EndOfSidingObjectiveHint.boundLimit(it, step4Matches, 4, this.segmentType, 2); | ||
143 | final ImmutableList<CostElementMatch> step5Matches = step5.getMatches(); | ||
144 | for (final CostElementMatch m_3 : step5Matches) { | ||
145 | { | ||
146 | final Dimension dimension = it.getDimension(m_3.getMatch()); | ||
147 | objectiveBuilder.add(step5.getWeight(), dimension); | ||
148 | dimension.tightenLowerBound(Integer.valueOf(0)); | ||
149 | boolean _isMulti = m_3.isMulti(); | ||
150 | boolean _not = (!_isMulti); | ||
151 | if (_not) { | ||
152 | dimension.tightenUpperBound(Integer.valueOf(1)); | ||
153 | boolean _isMust = m_3.isMust(); | ||
154 | if (_isMust) { | ||
155 | dimension.tightenLowerBound(Integer.valueOf(1)); | ||
156 | } | ||
157 | } | ||
158 | it.createBuilder().add(1, m_3.getMatch()).add((-1), step4.projectMayMatch(m_3.getMatch(), 2, 3, 4)).build().tightenUpperBound(Integer.valueOf(0)); | ||
159 | } | ||
160 | } | ||
161 | EndOfSidingObjectiveHint.boundLimit(it, step5Matches, 2, this.trainType, 1); | ||
162 | EndOfSidingObjectiveHint.boundLimit(it, step5Matches, 3, this.segmentType, 2); | ||
163 | EndOfSidingObjectiveHint.boundLimit(it, step5Matches, 4, this.segmentType, 1); | ||
164 | this.buildWithBounds(objectiveBuilder); | ||
165 | }; | ||
166 | _xblockexpression = _function; | ||
167 | } | ||
168 | return _xblockexpression; | ||
169 | } | ||
170 | |||
171 | private static void boundLimit(@Extension final ExtendedLinearExpressionBuilderFactory factory, final Collection<CostElementMatch> matches, final int index, final Type type, final int count) { | ||
172 | final Function1<CostElementMatch, Object> _function = (CostElementMatch it) -> { | ||
173 | return it.getMatch().get(index); | ||
174 | }; | ||
175 | Set<Map.Entry<Object, List<CostElementMatch>>> _entrySet = IterableExtensions.<Object, CostElementMatch>groupBy(matches, _function).entrySet(); | ||
176 | for (final Map.Entry<Object, List<CostElementMatch>> pair : _entrySet) { | ||
177 | { | ||
178 | final ExtendedLinearExpressionBuilder multiplicityBuilder = factory.createBuilder(); | ||
179 | List<CostElementMatch> _value = pair.getValue(); | ||
180 | for (final CostElementMatch m : _value) { | ||
181 | multiplicityBuilder.add(1, m.getMatch()); | ||
182 | } | ||
183 | boolean _isMulti = CostElementMatchers.isMulti(pair.getKey()); | ||
184 | if (_isMulti) { | ||
185 | multiplicityBuilder.add((-count), type); | ||
186 | multiplicityBuilder.build().tightenUpperBound(Integer.valueOf(0)); | ||
187 | } else { | ||
188 | multiplicityBuilder.build().tightenUpperBound(Integer.valueOf(count)); | ||
189 | } | ||
190 | } | ||
191 | } | ||
192 | } | ||
193 | } | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/MisalignedTurnoutObjectiveHint.java b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/MisalignedTurnoutObjectiveHint.java new file mode 100644 index 00000000..835a6559 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/MisalignedTurnoutObjectiveHint.java | |||
@@ -0,0 +1,195 @@ | |||
1 | package modes3.run; | ||
2 | |||
3 | import com.google.common.collect.ImmutableList; | ||
4 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic; | ||
5 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace; | ||
6 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type; | ||
7 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.Dimension; | ||
8 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.ExtendedLinearExpressionBuilder; | ||
9 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.ExtendedLinearExpressionBuilderFactory; | ||
10 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.PolyhedronExtensionOperator; | ||
11 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.CostElementMatch; | ||
12 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.CostElementMatchers; | ||
13 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.CostObjectiveHint; | ||
14 | import java.util.Collection; | ||
15 | import java.util.List; | ||
16 | import java.util.Map; | ||
17 | import java.util.Set; | ||
18 | import modes3.Modes3Package; | ||
19 | import modes3.queries.MisalignedTurnout_step_2; | ||
20 | import modes3.queries.MisalignedTurnout_step_3; | ||
21 | import modes3.queries.MisalignedTurnout_step_4; | ||
22 | import modes3.queries.MisalignedTurnout_step_5; | ||
23 | import org.eclipse.viatra.query.runtime.api.IPatternMatch; | ||
24 | import org.eclipse.xtext.xbase.lib.Extension; | ||
25 | import org.eclipse.xtext.xbase.lib.Functions.Function1; | ||
26 | import org.eclipse.xtext.xbase.lib.IterableExtensions; | ||
27 | |||
28 | @SuppressWarnings("all") | ||
29 | public class MisalignedTurnoutObjectiveHint extends CostObjectiveHint { | ||
30 | private final Type segmentType; | ||
31 | |||
32 | private final Type turnoutType; | ||
33 | |||
34 | private final Type trainType; | ||
35 | |||
36 | public MisalignedTurnoutObjectiveHint(@Extension final Ecore2Logic ecore2Logic, final Ecore2Logic_Trace ecore2LogicTrace) { | ||
37 | @Extension | ||
38 | final Modes3Package Modes3Package = modes3.Modes3Package.eINSTANCE; | ||
39 | this.segmentType = ecore2Logic.TypeofEClass(ecore2LogicTrace, Modes3Package.getSegment()); | ||
40 | this.turnoutType = ecore2Logic.TypeofEClass(ecore2LogicTrace, Modes3Package.getTurnout()); | ||
41 | this.trainType = ecore2Logic.TypeofEClass(ecore2LogicTrace, Modes3Package.getTrain()); | ||
42 | } | ||
43 | |||
44 | @Override | ||
45 | public boolean isExact() { | ||
46 | return true; | ||
47 | } | ||
48 | |||
49 | @Override | ||
50 | public PolyhedronExtensionOperator createPolyhedronExtensionOperator(final Map<String, CostElementMatchers> costElementMatchers) { | ||
51 | PolyhedronExtensionOperator _xblockexpression = null; | ||
52 | { | ||
53 | final CostElementMatchers step2 = costElementMatchers.get(MisalignedTurnout_step_2.instance().getFullyQualifiedName()); | ||
54 | final CostElementMatchers step3 = costElementMatchers.get(MisalignedTurnout_step_3.instance().getFullyQualifiedName()); | ||
55 | final CostElementMatchers step4 = costElementMatchers.get(MisalignedTurnout_step_4.instance().getFullyQualifiedName()); | ||
56 | final CostElementMatchers step5 = costElementMatchers.get(MisalignedTurnout_step_5.instance().getFullyQualifiedName()); | ||
57 | final PolyhedronExtensionOperator _function = (ExtendedLinearExpressionBuilderFactory it) -> { | ||
58 | final ExtendedLinearExpressionBuilder objectiveBuilder = it.createBuilder(); | ||
59 | ImmutableList<CostElementMatch> _matches = step2.getMatches(); | ||
60 | for (final CostElementMatch m : _matches) { | ||
61 | { | ||
62 | final Dimension dimension = it.getDimension(m.getMatch()); | ||
63 | objectiveBuilder.add(step2.getWeight(), dimension); | ||
64 | dimension.tightenLowerBound(Integer.valueOf(0)); | ||
65 | boolean _isMulti = m.isMulti(); | ||
66 | if (_isMulti) { | ||
67 | it.createBuilder().add(1, dimension).add((-1), this.turnoutType).build().assertEqualsTo(0); | ||
68 | } else { | ||
69 | dimension.tightenUpperBound(Integer.valueOf(1)); | ||
70 | boolean _isMust = m.isMust(); | ||
71 | if (_isMust) { | ||
72 | dimension.tightenLowerBound(Integer.valueOf(1)); | ||
73 | } | ||
74 | } | ||
75 | } | ||
76 | } | ||
77 | final ImmutableList<CostElementMatch> step3Matches = step3.getMatches(); | ||
78 | for (final CostElementMatch m_1 : step3Matches) { | ||
79 | { | ||
80 | final Dimension dimension = it.getDimension(m_1.getMatch()); | ||
81 | objectiveBuilder.add(step3.getWeight(), dimension); | ||
82 | dimension.tightenLowerBound(Integer.valueOf(0)); | ||
83 | boolean _isMulti = m_1.isMulti(); | ||
84 | boolean _not = (!_isMulti); | ||
85 | if (_not) { | ||
86 | dimension.tightenUpperBound(Integer.valueOf(1)); | ||
87 | boolean _isMust = m_1.isMust(); | ||
88 | if (_isMust) { | ||
89 | dimension.tightenLowerBound(Integer.valueOf(1)); | ||
90 | } | ||
91 | } | ||
92 | } | ||
93 | } | ||
94 | final Function1<CostElementMatch, IPatternMatch> _function_1 = (CostElementMatch it_1) -> { | ||
95 | return step2.projectMayMatch(it_1.getMatch(), 2); | ||
96 | }; | ||
97 | Set<Map.Entry<IPatternMatch, List<CostElementMatch>>> _entrySet = IterableExtensions.<IPatternMatch, CostElementMatch>groupBy(step3Matches, _function_1).entrySet(); | ||
98 | for (final Map.Entry<IPatternMatch, List<CostElementMatch>> pair : _entrySet) { | ||
99 | { | ||
100 | final ExtendedLinearExpressionBuilder multiplicityBuilder = it.createBuilder(); | ||
101 | List<CostElementMatch> _value = pair.getValue(); | ||
102 | for (final CostElementMatch m_2 : _value) { | ||
103 | multiplicityBuilder.add(1, m_2.getMatch()); | ||
104 | } | ||
105 | multiplicityBuilder.add((-1), pair.getKey()); | ||
106 | multiplicityBuilder.build().tightenUpperBound(Integer.valueOf(0)); | ||
107 | } | ||
108 | } | ||
109 | MisalignedTurnoutObjectiveHint.boundLimit(it, step3Matches, 2, this.turnoutType, 1); | ||
110 | MisalignedTurnoutObjectiveHint.boundLimit(it, step3Matches, 3, this.segmentType, 2); | ||
111 | final ImmutableList<CostElementMatch> step4Matches = step4.getMatches(); | ||
112 | for (final CostElementMatch m_2 : step4Matches) { | ||
113 | { | ||
114 | final Dimension dimension = it.getDimension(m_2.getMatch()); | ||
115 | objectiveBuilder.add(step4.getWeight(), dimension); | ||
116 | dimension.tightenLowerBound(Integer.valueOf(0)); | ||
117 | boolean _isMulti = m_2.isMulti(); | ||
118 | boolean _not = (!_isMulti); | ||
119 | if (_not) { | ||
120 | dimension.tightenUpperBound(Integer.valueOf(1)); | ||
121 | boolean _isMust = m_2.isMust(); | ||
122 | if (_isMust) { | ||
123 | dimension.tightenLowerBound(Integer.valueOf(1)); | ||
124 | } | ||
125 | } | ||
126 | it.createBuilder().add(1, m_2.getMatch()).add((-1), step3.projectMayMatch(m_2.getMatch(), 2, 3)).build().tightenUpperBound(Integer.valueOf(0)); | ||
127 | } | ||
128 | } | ||
129 | MisalignedTurnoutObjectiveHint.boundLimit(it, step4Matches, 2, this.turnoutType, 1); | ||
130 | MisalignedTurnoutObjectiveHint.boundLimit(it, step4Matches, 3, this.segmentType, 2); | ||
131 | final ImmutableList<CostElementMatch> step5Matches = step5.getMatches(); | ||
132 | for (final CostElementMatch m_3 : step5Matches) { | ||
133 | { | ||
134 | final Dimension dimension = it.getDimension(m_3.getMatch()); | ||
135 | objectiveBuilder.add(step5.getWeight(), dimension); | ||
136 | dimension.tightenLowerBound(Integer.valueOf(0)); | ||
137 | boolean _isMulti = m_3.isMulti(); | ||
138 | boolean _not = (!_isMulti); | ||
139 | if (_not) { | ||
140 | dimension.tightenUpperBound(Integer.valueOf(1)); | ||
141 | boolean _isMust = m_3.isMust(); | ||
142 | if (_isMust) { | ||
143 | dimension.tightenLowerBound(Integer.valueOf(1)); | ||
144 | } | ||
145 | } | ||
146 | } | ||
147 | } | ||
148 | final Function1<CostElementMatch, IPatternMatch> _function_2 = (CostElementMatch it_1) -> { | ||
149 | return step4.projectMayMatch(it_1.getMatch(), 2, 3); | ||
150 | }; | ||
151 | Set<Map.Entry<IPatternMatch, List<CostElementMatch>>> _entrySet_1 = IterableExtensions.<IPatternMatch, CostElementMatch>groupBy(step5Matches, _function_2).entrySet(); | ||
152 | for (final Map.Entry<IPatternMatch, List<CostElementMatch>> pair_1 : _entrySet_1) { | ||
153 | { | ||
154 | final ExtendedLinearExpressionBuilder multiplicityBuilder = it.createBuilder(); | ||
155 | List<CostElementMatch> _value = pair_1.getValue(); | ||
156 | for (final CostElementMatch m_4 : _value) { | ||
157 | multiplicityBuilder.add(1, m_4.getMatch()); | ||
158 | } | ||
159 | multiplicityBuilder.add((-1), pair_1.getKey()); | ||
160 | multiplicityBuilder.build().tightenUpperBound(Integer.valueOf(0)); | ||
161 | } | ||
162 | } | ||
163 | MisalignedTurnoutObjectiveHint.boundLimit(it, step5Matches, 2, this.turnoutType, 1); | ||
164 | MisalignedTurnoutObjectiveHint.boundLimit(it, step5Matches, 3, this.segmentType, 2); | ||
165 | MisalignedTurnoutObjectiveHint.boundLimit(it, step5Matches, 4, this.trainType, 2); | ||
166 | this.buildWithBounds(objectiveBuilder); | ||
167 | }; | ||
168 | _xblockexpression = _function; | ||
169 | } | ||
170 | return _xblockexpression; | ||
171 | } | ||
172 | |||
173 | private static void boundLimit(@Extension final ExtendedLinearExpressionBuilderFactory factory, final Collection<CostElementMatch> matches, final int index, final Type type, final int count) { | ||
174 | final Function1<CostElementMatch, Object> _function = (CostElementMatch it) -> { | ||
175 | return it.getMatch().get(index); | ||
176 | }; | ||
177 | Set<Map.Entry<Object, List<CostElementMatch>>> _entrySet = IterableExtensions.<Object, CostElementMatch>groupBy(matches, _function).entrySet(); | ||
178 | for (final Map.Entry<Object, List<CostElementMatch>> pair : _entrySet) { | ||
179 | { | ||
180 | final ExtendedLinearExpressionBuilder multiplicityBuilder = factory.createBuilder(); | ||
181 | List<CostElementMatch> _value = pair.getValue(); | ||
182 | for (final CostElementMatch m : _value) { | ||
183 | multiplicityBuilder.add(1, m.getMatch()); | ||
184 | } | ||
185 | boolean _isMulti = CostElementMatchers.isMulti(pair.getKey()); | ||
186 | if (_isMulti) { | ||
187 | multiplicityBuilder.add((-count), type); | ||
188 | multiplicityBuilder.build().tightenUpperBound(Integer.valueOf(0)); | ||
189 | } else { | ||
190 | multiplicityBuilder.build().tightenUpperBound(Integer.valueOf(count)); | ||
191 | } | ||
192 | } | ||
193 | } | ||
194 | } | ||
195 | } | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/Modes3ModelGenerator.java b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/Modes3ModelGenerator.java new file mode 100644 index 00000000..a0661c87 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/Modes3ModelGenerator.java | |||
@@ -0,0 +1,597 @@ | |||
1 | package modes3.run; | ||
2 | |||
3 | import com.google.common.base.Objects; | ||
4 | import com.google.common.collect.ImmutableList; | ||
5 | import com.google.common.collect.ImmutableSet; | ||
6 | import com.google.common.collect.Iterables; | ||
7 | import hu.bme.mit.inf.dslreasoner.ecore2logic.EReferenceMapper_RelationsOverTypes_Trace; | ||
8 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic; | ||
9 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2LogicConfiguration; | ||
10 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace; | ||
11 | import hu.bme.mit.inf.dslreasoner.ecore2logic.EcoreMetamodelDescriptor; | ||
12 | import hu.bme.mit.inf.dslreasoner.ecore2logic.ecore2logicannotations.Ecore2logicannotationsFactory; | ||
13 | import hu.bme.mit.inf.dslreasoner.ecore2logic.ecore2logicannotations.Ecore2logicannotationsPackage; | ||
14 | import hu.bme.mit.inf.dslreasoner.ecore2logic.ecore2logicannotations.InverseRelationAssertion; | ||
15 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.DocumentationLevel; | ||
16 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicModelInterpretation; | ||
17 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicProblemBuilder; | ||
18 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.SolutionScope; | ||
19 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.TracedOutput; | ||
20 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.TypeScopes; | ||
21 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.VariableContext; | ||
22 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Assertion; | ||
23 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Iff; | ||
24 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.LogiclanguagePackage; | ||
25 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RelationDeclaration; | ||
26 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.SymbolicValue; | ||
27 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TermDescription; | ||
28 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type; | ||
29 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TypeDefinition; | ||
30 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Variable; | ||
31 | import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.Annotation; | ||
32 | import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem; | ||
33 | import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicproblemPackage; | ||
34 | import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.LogicResult; | ||
35 | import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.ModelResult; | ||
36 | import hu.bme.mit.inf.dslreasoner.logic2ecore.Logic2Ecore; | ||
37 | import hu.bme.mit.inf.dslreasoner.viatra2logic.Viatra2Logic; | ||
38 | import hu.bme.mit.inf.dslreasoner.viatra2logic.Viatra2LogicConfiguration; | ||
39 | import hu.bme.mit.inf.dslreasoner.viatra2logic.Viatra2LogicTrace; | ||
40 | import hu.bme.mit.inf.dslreasoner.viatra2logic.ViatraQuerySetDescriptor; | ||
41 | import hu.bme.mit.inf.dslreasoner.viatra2logic.viatra2logicannotations.Viatra2LogicAnnotationsPackage; | ||
42 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.TypeInferenceMethod; | ||
43 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.PolyhedralScopePropagatorConstraints; | ||
44 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.PolyhedralScopePropagatorSolver; | ||
45 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.ScopePropagatorStrategy; | ||
46 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic.InstanceModel2Logic; | ||
47 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.BinaryElementRelationLink; | ||
48 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialComplexTypeInterpretation; | ||
49 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation; | ||
50 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialRelationInterpretation; | ||
51 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialinterpretationPackage; | ||
52 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.RelationLink; | ||
53 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.visualisation.PartialInterpretation2Gml; | ||
54 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.visualisation.PartialInterpretationVisualisation; | ||
55 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.CostObjectiveConfiguration; | ||
56 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.CostObjectiveElementConfiguration; | ||
57 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.DebugConfiguration; | ||
58 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.StateCoderStrategy; | ||
59 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.ViatraReasoner; | ||
60 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.ViatraReasonerConfiguration; | ||
61 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.dse.PartialModelAsLogicInterpretation; | ||
62 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.ObjectiveKind; | ||
63 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.ObjectiveThreshold; | ||
64 | import hu.bme.mit.inf.dslreasoner.visualisation.pi2graphviz.GraphvizVisualiser; | ||
65 | import hu.bme.mit.inf.dslreasoner.workspace.FileSystemWorkspace; | ||
66 | import java.util.Collections; | ||
67 | import java.util.List; | ||
68 | import java.util.Map; | ||
69 | import java.util.Set; | ||
70 | import java.util.function.Predicate; | ||
71 | import modes3.Modes3Factory; | ||
72 | import modes3.Modes3ModelRoot; | ||
73 | import modes3.Modes3Package; | ||
74 | import modes3.queries.CloseTrains_step_2; | ||
75 | import modes3.queries.CloseTrains_step_3; | ||
76 | import modes3.queries.CloseTrains_step_4; | ||
77 | import modes3.queries.CloseTrains_step_5; | ||
78 | import modes3.queries.CloseTrains_step_6; | ||
79 | import modes3.queries.CloseTrains_step_7; | ||
80 | import modes3.queries.EndOfSiding_step_2; | ||
81 | import modes3.queries.EndOfSiding_step_3; | ||
82 | import modes3.queries.EndOfSiding_step_4; | ||
83 | import modes3.queries.EndOfSiding_step_5; | ||
84 | import modes3.queries.MisalignedTurnout_step_2; | ||
85 | import modes3.queries.MisalignedTurnout_step_3; | ||
86 | import modes3.queries.MisalignedTurnout_step_4; | ||
87 | import modes3.queries.MisalignedTurnout_step_5; | ||
88 | import modes3.queries.Modes3Queries; | ||
89 | import modes3.queries.TrainLocations_step_2; | ||
90 | import modes3.queries.TrainLocations_step_3; | ||
91 | import modes3.run.CloseTrainsObjectiveHint; | ||
92 | import modes3.run.EndOfSidingObjectiveHint; | ||
93 | import modes3.run.MisalignedTurnoutObjectiveHint; | ||
94 | import modes3.run.Modes3TypeScopeHint; | ||
95 | import modes3.run.Modes3UnitPropagationGenerator; | ||
96 | import modes3.run.TrainLocationsObjectiveHint; | ||
97 | import org.eclipse.emf.common.util.EList; | ||
98 | import org.eclipse.emf.common.util.TreeIterator; | ||
99 | import org.eclipse.emf.common.util.URI; | ||
100 | import org.eclipse.emf.ecore.EAttribute; | ||
101 | import org.eclipse.emf.ecore.EClass; | ||
102 | import org.eclipse.emf.ecore.EEnum; | ||
103 | import org.eclipse.emf.ecore.EEnumLiteral; | ||
104 | import org.eclipse.emf.ecore.EObject; | ||
105 | import org.eclipse.emf.ecore.EReference; | ||
106 | import org.eclipse.emf.ecore.EStructuralFeature; | ||
107 | import org.eclipse.emf.ecore.resource.Resource; | ||
108 | import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; | ||
109 | import org.eclipse.viatra.query.patternlanguage.emf.EMFPatternLanguageStandaloneSetup; | ||
110 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification; | ||
111 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngineOptions; | ||
112 | import org.eclipse.viatra.query.runtime.localsearch.matcher.integration.LocalSearchEMFBackendFactory; | ||
113 | import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation; | ||
114 | import org.eclipse.viatra.query.runtime.rete.matcher.ReteBackendFactory; | ||
115 | import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor; | ||
116 | import org.eclipse.xtend2.lib.StringConcatenation; | ||
117 | import org.eclipse.xtext.xbase.lib.CollectionLiterals; | ||
118 | import org.eclipse.xtext.xbase.lib.Exceptions; | ||
119 | import org.eclipse.xtext.xbase.lib.ExclusiveRange; | ||
120 | import org.eclipse.xtext.xbase.lib.Extension; | ||
121 | import org.eclipse.xtext.xbase.lib.Functions.Function1; | ||
122 | import org.eclipse.xtext.xbase.lib.InputOutput; | ||
123 | import org.eclipse.xtext.xbase.lib.IterableExtensions; | ||
124 | import org.eclipse.xtext.xbase.lib.ObjectExtensions; | ||
125 | import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; | ||
126 | |||
127 | @FinalFieldsConstructor | ||
128 | @SuppressWarnings("all") | ||
129 | public class Modes3ModelGenerator { | ||
130 | private enum MonitoringQuery { | ||
131 | closeTrains, | ||
132 | |||
133 | trainLocations, | ||
134 | |||
135 | endOfSiding, | ||
136 | |||
137 | misalignedTurnout; | ||
138 | } | ||
139 | |||
140 | private final Modes3ModelGenerator.MonitoringQuery monitoringQuery; | ||
141 | |||
142 | private final int modelSize; | ||
143 | |||
144 | private final Ecore2Logic ecore2Logic = new Ecore2Logic(); | ||
145 | |||
146 | private final InstanceModel2Logic instanceModel2Logic = new InstanceModel2Logic(); | ||
147 | |||
148 | private final Viatra2Logic viatra2Logic = new Viatra2Logic(this.ecore2Logic); | ||
149 | |||
150 | private final ViatraReasoner solver = new ViatraReasoner(); | ||
151 | |||
152 | @Extension | ||
153 | private final LogicProblemBuilder _logicProblemBuilder = new LogicProblemBuilder(); | ||
154 | |||
155 | public URI generate() { | ||
156 | try { | ||
157 | URI _xblockexpression = null; | ||
158 | { | ||
159 | final EcoreMetamodelDescriptor metamodel = Modes3ModelGenerator.createMetamodelDescriptor(); | ||
160 | Ecore2LogicConfiguration _ecore2LogicConfiguration = new Ecore2LogicConfiguration(); | ||
161 | final TracedOutput<LogicProblem, Ecore2Logic_Trace> metamodelLogic = this.ecore2Logic.transformMetamodel(metamodel, _ecore2LogicConfiguration); | ||
162 | final Type segment = this.ecore2Logic.TypeofEClass(metamodelLogic.getTrace(), Modes3Package.eINSTANCE.getSegment()); | ||
163 | final RelationDeclaration connectedTo = this.ecore2Logic.relationOfReference(metamodelLogic.getTrace(), | ||
164 | Modes3Package.eINSTANCE.getSegment_ConnectedTo()); | ||
165 | final RelationDeclaration connectedToIndicator = ((EReferenceMapper_RelationsOverTypes_Trace) metamodelLogic.getTrace().referenceMapperTrace).indicators.get( | ||
166 | Modes3Package.eINSTANCE.getSegment_ConnectedTo()); | ||
167 | StringConcatenation _builder = new StringConcatenation(); | ||
168 | _builder.append("oppositeReference "); | ||
169 | String _name = connectedTo.getName(); | ||
170 | _builder.append(_name); | ||
171 | _builder.append(" "); | ||
172 | String _name_1 = connectedTo.getName(); | ||
173 | _builder.append(_name_1); | ||
174 | final Function1<VariableContext, TermDescription> _function = (VariableContext it) -> { | ||
175 | Iff _xblockexpression_1 = null; | ||
176 | { | ||
177 | StringConcatenation _builder_1 = new StringConcatenation(); | ||
178 | _builder_1.append("src"); | ||
179 | final Variable src = it.addVar(_builder_1, segment); | ||
180 | StringConcatenation _builder_2 = new StringConcatenation(); | ||
181 | _builder_2.append("trg"); | ||
182 | final Variable trg = it.addVar(_builder_2, segment); | ||
183 | SymbolicValue _call = this._logicProblemBuilder.call(connectedToIndicator, src, trg); | ||
184 | SymbolicValue _call_1 = this._logicProblemBuilder.call(connectedToIndicator, trg, src); | ||
185 | _xblockexpression_1 = this._logicProblemBuilder.operator_spaceship(_call, _call_1); | ||
186 | } | ||
187 | return _xblockexpression_1; | ||
188 | }; | ||
189 | final Assertion inverseAssertion = this._logicProblemBuilder.Assertion(_builder, | ||
190 | this._logicProblemBuilder.Forall(_function)); | ||
191 | EList<Assertion> _assertions = metamodelLogic.getOutput().getAssertions(); | ||
192 | _assertions.add(inverseAssertion); | ||
193 | InverseRelationAssertion _createInverseRelationAssertion = Ecore2logicannotationsFactory.eINSTANCE.createInverseRelationAssertion(); | ||
194 | final Procedure1<InverseRelationAssertion> _function_1 = (InverseRelationAssertion it) -> { | ||
195 | it.setTarget(inverseAssertion); | ||
196 | it.setInverseA(connectedTo); | ||
197 | it.setInverseB(connectedTo); | ||
198 | }; | ||
199 | final InverseRelationAssertion inverseAnnotation = ObjectExtensions.<InverseRelationAssertion>operator_doubleArrow(_createInverseRelationAssertion, _function_1); | ||
200 | EList<Annotation> _annotations = metamodelLogic.getOutput().getAnnotations(); | ||
201 | _annotations.add(inverseAnnotation); | ||
202 | final List<EObject> initialModel = Modes3ModelGenerator.loadInitialModel(); | ||
203 | final TracedOutput<LogicProblem, Ecore2Logic_Trace> initialModelLogic = this.instanceModel2Logic.transform(metamodelLogic, initialModel); | ||
204 | final ViatraQuerySetDescriptor queries = this.loadQueries(); | ||
205 | Viatra2LogicConfiguration _viatra2LogicConfiguration = new Viatra2LogicConfiguration(); | ||
206 | final TracedOutput<LogicProblem, Viatra2LogicTrace> logic = this.viatra2Logic.transformQueries(queries, initialModelLogic, _viatra2LogicConfiguration); | ||
207 | ViatraReasonerConfiguration _viatraReasonerConfiguration = new ViatraReasonerConfiguration(); | ||
208 | final Procedure1<ViatraReasonerConfiguration> _function_2 = (ViatraReasonerConfiguration it) -> { | ||
209 | it.runtimeLimit = 3600; | ||
210 | final Procedure1<TypeScopes> _function_3 = (TypeScopes it_1) -> { | ||
211 | it_1.minNewElements = this.modelSize; | ||
212 | it_1.maxNewElements = this.modelSize; | ||
213 | final Procedure1<Map<Type, Integer>> _function_4 = (Map<Type, Integer> it_2) -> { | ||
214 | }; | ||
215 | ObjectExtensions.<Map<Type, Integer>>operator_doubleArrow( | ||
216 | it_1.minNewElementsByType, _function_4); | ||
217 | final Procedure1<Map<Type, Integer>> _function_5 = (Map<Type, Integer> it_2) -> { | ||
218 | it_2.put(this.ecore2Logic.TypeofEClass(metamodelLogic.getTrace(), Modes3Package.eINSTANCE.getTrain()), Integer.valueOf((this.modelSize / 5))); | ||
219 | it_2.put(this.ecore2Logic.TypeofEClass(metamodelLogic.getTrace(), Modes3Package.eINSTANCE.getTurnout()), Integer.valueOf((this.modelSize / 5))); | ||
220 | }; | ||
221 | ObjectExtensions.<Map<Type, Integer>>operator_doubleArrow( | ||
222 | it_1.maxNewElementsByType, _function_5); | ||
223 | }; | ||
224 | ObjectExtensions.<TypeScopes>operator_doubleArrow( | ||
225 | it.typeScopes, _function_3); | ||
226 | final Procedure1<SolutionScope> _function_4 = (SolutionScope it_1) -> { | ||
227 | it_1.numberOfRequiredSolutions = 1; | ||
228 | }; | ||
229 | ObjectExtensions.<SolutionScope>operator_doubleArrow( | ||
230 | it.solutionScope, _function_4); | ||
231 | CostObjectiveConfiguration _objective = this.getObjective(this.ecore2Logic, metamodelLogic.getTrace()); | ||
232 | it.costObjectives.add(_objective); | ||
233 | it.scopeWeight = 6; | ||
234 | it.nameNewElements = false; | ||
235 | it.typeInferenceMethod = TypeInferenceMethod.PreliminaryAnalysis; | ||
236 | it.stateCoderStrategy = StateCoderStrategy.PairwiseNeighbourhood; | ||
237 | ScopePropagatorStrategy.Polyhedral _polyhedral = new ScopePropagatorStrategy.Polyhedral( | ||
238 | PolyhedralScopePropagatorConstraints.Relational, PolyhedralScopePropagatorSolver.Clp); | ||
239 | it.scopePropagatorStrategy = _polyhedral; | ||
240 | Ecore2Logic_Trace _trace = metamodelLogic.getTrace(); | ||
241 | Modes3TypeScopeHint _modes3TypeScopeHint = new Modes3TypeScopeHint(this.ecore2Logic, _trace); | ||
242 | it.hints.add(_modes3TypeScopeHint); | ||
243 | Ecore2Logic_Trace _trace_1 = metamodelLogic.getTrace(); | ||
244 | Modes3UnitPropagationGenerator _modes3UnitPropagationGenerator = new Modes3UnitPropagationGenerator(this.ecore2Logic, _trace_1); | ||
245 | it.unitPropagationPatternGenerators.add(_modes3UnitPropagationGenerator); | ||
246 | final Procedure1<DebugConfiguration> _function_5 = (DebugConfiguration it_1) -> { | ||
247 | GraphvizVisualiser _graphvizVisualiser = new GraphvizVisualiser(); | ||
248 | it_1.partialInterpretatioVisualiser = _graphvizVisualiser; | ||
249 | }; | ||
250 | ObjectExtensions.<DebugConfiguration>operator_doubleArrow( | ||
251 | it.debugConfiguration, _function_5); | ||
252 | it.documentationLevel = DocumentationLevel.NORMAL; | ||
253 | }; | ||
254 | final ViatraReasonerConfiguration config = ObjectExtensions.<ViatraReasonerConfiguration>operator_doubleArrow(_viatraReasonerConfiguration, _function_2); | ||
255 | final FileSystemWorkspace workspace = new FileSystemWorkspace("output/", ""); | ||
256 | workspace.writeModel(logic.getOutput(), "problem.logicproblem"); | ||
257 | final LogicResult solution = this.solver.solve(logic.getOutput(), config, workspace); | ||
258 | URI _xifexpression = null; | ||
259 | if ((solution instanceof ModelResult)) { | ||
260 | InputOutput.<String>println("Saving generated solutions"); | ||
261 | final Logic2Ecore logic2Ecore = new Logic2Ecore(this.ecore2Logic); | ||
262 | final List<? extends LogicModelInterpretation> interpretations = this.solver.getInterpretations(((ModelResult)solution)); | ||
263 | int _size = interpretations.size(); | ||
264 | ExclusiveRange _doubleDotLessThan = new ExclusiveRange(0, _size, true); | ||
265 | for (final Integer representationIndex : _doubleDotLessThan) { | ||
266 | { | ||
267 | final LogicModelInterpretation interpretation = interpretations.get((representationIndex).intValue()); | ||
268 | final int representationNumber = ((representationIndex).intValue() + 1); | ||
269 | if ((interpretation instanceof PartialModelAsLogicInterpretation)) { | ||
270 | final PartialInterpretation representation = ((PartialModelAsLogicInterpretation)interpretation).getPartialInterpretation(); | ||
271 | StringConcatenation _builder_1 = new StringConcatenation(); | ||
272 | _builder_1.append("solution"); | ||
273 | _builder_1.append(representationNumber); | ||
274 | _builder_1.append(".partialinterpretation"); | ||
275 | workspace.writeModel(representation, _builder_1.toString()); | ||
276 | final PartialInterpretation2Gml partialInterpretation2GML = new PartialInterpretation2Gml(); | ||
277 | final String gml = partialInterpretation2GML.transform(representation); | ||
278 | StringConcatenation _builder_2 = new StringConcatenation(); | ||
279 | _builder_2.append("solution"); | ||
280 | _builder_2.append(representationNumber); | ||
281 | _builder_2.append(".gml"); | ||
282 | workspace.writeText(_builder_2.toString(), gml); | ||
283 | final EObject model = logic2Ecore.transformInterpretation(interpretation, metamodelLogic.getTrace()); | ||
284 | final TreeIterator<EObject> iterator = model.eAllContents(); | ||
285 | int id = 0; | ||
286 | while (iterator.hasNext()) { | ||
287 | { | ||
288 | final EObject obj = iterator.next(); | ||
289 | final Function1<EAttribute, Boolean> _function_3 = (EAttribute it) -> { | ||
290 | String _name_2 = it.getName(); | ||
291 | return Boolean.valueOf(Objects.equal(_name_2, "id")); | ||
292 | }; | ||
293 | final EAttribute idFeature = IterableExtensions.<EAttribute>findFirst(obj.eClass().getEAllAttributes(), _function_3); | ||
294 | if ((idFeature != null)) { | ||
295 | obj.eSet(idFeature, Integer.valueOf(id)); | ||
296 | id++; | ||
297 | } | ||
298 | } | ||
299 | } | ||
300 | StringConcatenation _builder_3 = new StringConcatenation(); | ||
301 | _builder_3.append("solution"); | ||
302 | _builder_3.append(representationNumber); | ||
303 | _builder_3.append(".modes3"); | ||
304 | workspace.writeModel(model, _builder_3.toString()); | ||
305 | int _size_1 = representation.getNewElements().size(); | ||
306 | boolean _lessThan = (_size_1 < 160); | ||
307 | if (_lessThan) { | ||
308 | final Function1<Type, Boolean> _function_3 = (Type it) -> { | ||
309 | String _name_2 = it.getName(); | ||
310 | return Boolean.valueOf(Objects.equal(_name_2, "Modes3ModelRoot class DefinedPart")); | ||
311 | }; | ||
312 | Type _findFirst = IterableExtensions.<Type>findFirst(representation.getProblem().getTypes(), _function_3); | ||
313 | final TypeDefinition rootType = ((TypeDefinition) _findFirst); | ||
314 | final Function1<PartialComplexTypeInterpretation, Boolean> _function_4 = (PartialComplexTypeInterpretation it) -> { | ||
315 | String _name_2 = it.getInterpretationOf().getName(); | ||
316 | return Boolean.valueOf(Objects.equal(_name_2, "Modes3ModelRoot class")); | ||
317 | }; | ||
318 | final PartialComplexTypeInterpretation rootIntepretation = IterableExtensions.<PartialComplexTypeInterpretation>findFirst(Iterables.<PartialComplexTypeInterpretation>filter(representation.getPartialtypeinterpratation(), | ||
319 | PartialComplexTypeInterpretation.class), _function_4); | ||
320 | rootIntepretation.getElements().removeAll(rootType.getElements()); | ||
321 | representation.getProblem().getElements().removeAll(rootType.getElements()); | ||
322 | EList<PartialRelationInterpretation> _partialrelationinterpretation = representation.getPartialrelationinterpretation(); | ||
323 | for (final PartialRelationInterpretation relationInterpretation : _partialrelationinterpretation) { | ||
324 | final Predicate<RelationLink> _function_5 = (RelationLink link) -> { | ||
325 | boolean _xifexpression_1 = false; | ||
326 | if ((link instanceof BinaryElementRelationLink)) { | ||
327 | _xifexpression_1 = (rootType.getElements().contains(((BinaryElementRelationLink)link).getParam1()) || | ||
328 | rootType.getElements().contains(((BinaryElementRelationLink)link).getParam2())); | ||
329 | } else { | ||
330 | _xifexpression_1 = false; | ||
331 | } | ||
332 | return _xifexpression_1; | ||
333 | }; | ||
334 | relationInterpretation.getRelationlinks().removeIf(_function_5); | ||
335 | } | ||
336 | rootType.getElements().clear(); | ||
337 | final GraphvizVisualiser visualiser = new GraphvizVisualiser(); | ||
338 | final PartialInterpretationVisualisation visualisation = visualiser.visualiseConcretization(representation); | ||
339 | StringConcatenation _builder_4 = new StringConcatenation(); | ||
340 | _builder_4.append("solution"); | ||
341 | _builder_4.append(representationNumber); | ||
342 | _builder_4.append(".png"); | ||
343 | visualisation.writeToFile(workspace, _builder_4.toString()); | ||
344 | } | ||
345 | } else { | ||
346 | StringConcatenation _builder_5 = new StringConcatenation(); | ||
347 | _builder_5.append("solution"); | ||
348 | _builder_5.append(representationNumber); | ||
349 | _builder_5.append(".txt"); | ||
350 | workspace.writeText(_builder_5.toString(), interpretation.toString()); | ||
351 | } | ||
352 | } | ||
353 | } | ||
354 | } else { | ||
355 | URI _xblockexpression_1 = null; | ||
356 | { | ||
357 | InputOutput.<String>println("Failed to solve problem"); | ||
358 | final LogicProblem partial = logic.getOutput(); | ||
359 | _xblockexpression_1 = workspace.writeModel(partial, "solution.partialinterpretation"); | ||
360 | } | ||
361 | _xifexpression = _xblockexpression_1; | ||
362 | } | ||
363 | _xblockexpression = _xifexpression; | ||
364 | } | ||
365 | return _xblockexpression; | ||
366 | } catch (Throwable _e) { | ||
367 | throw Exceptions.sneakyThrow(_e); | ||
368 | } | ||
369 | } | ||
370 | |||
371 | public static EcoreMetamodelDescriptor createMetamodelDescriptor() { | ||
372 | EcoreMetamodelDescriptor _xblockexpression = null; | ||
373 | { | ||
374 | final ImmutableList<EClass> eClasses = ImmutableList.<EClass>copyOf(Iterables.<EClass>filter(Modes3Package.eINSTANCE.getEClassifiers(), EClass.class)); | ||
375 | Set<EClass> _emptySet = CollectionLiterals.<EClass>emptySet(); | ||
376 | List<EEnum> _emptyList = CollectionLiterals.<EEnum>emptyList(); | ||
377 | List<EEnumLiteral> _emptyList_1 = CollectionLiterals.<EEnumLiteral>emptyList(); | ||
378 | final Function1<EClass, EList<EReference>> _function = (EClass it) -> { | ||
379 | return it.getEReferences(); | ||
380 | }; | ||
381 | ImmutableList<EReference> _copyOf = ImmutableList.<EReference>copyOf(IterableExtensions.<EClass, EReference>flatMap(eClasses, _function)); | ||
382 | List<EAttribute> _emptyList_2 = CollectionLiterals.<EAttribute>emptyList(); | ||
383 | _xblockexpression = new EcoreMetamodelDescriptor(eClasses, _emptySet, | ||
384 | false, _emptyList, _emptyList_1, _copyOf, _emptyList_2); | ||
385 | } | ||
386 | return _xblockexpression; | ||
387 | } | ||
388 | |||
389 | public static List<EObject> loadInitialModel() { | ||
390 | Modes3ModelRoot _createModes3ModelRoot = Modes3Factory.eINSTANCE.createModes3ModelRoot(); | ||
391 | return Collections.<EObject>unmodifiableList(CollectionLiterals.<EObject>newArrayList(_createModes3ModelRoot)); | ||
392 | } | ||
393 | |||
394 | public ViatraQuerySetDescriptor loadQueries() { | ||
395 | ViatraQuerySetDescriptor _xblockexpression = null; | ||
396 | { | ||
397 | final ImmutableList.Builder<IQuerySpecification<?>> patternsBuilder = ImmutableList.<IQuerySpecification<?>>builder(); | ||
398 | patternsBuilder.addAll(Modes3Queries.instance().getSpecifications()); | ||
399 | final ImmutableList<IQuerySpecification<?>> patterns = patternsBuilder.build(); | ||
400 | final Function1<IQuerySpecification<?>, Boolean> _function = (IQuerySpecification<?> pattern) -> { | ||
401 | final Function1<PAnnotation, Boolean> _function_1 = (PAnnotation it) -> { | ||
402 | String _name = it.getName(); | ||
403 | return Boolean.valueOf(Objects.equal(_name, "Constraint")); | ||
404 | }; | ||
405 | return Boolean.valueOf(IterableExtensions.<PAnnotation>exists(pattern.getAllAnnotations(), _function_1)); | ||
406 | }; | ||
407 | final ImmutableSet<IQuerySpecification<?>> validationPatterns = ImmutableSet.<IQuerySpecification<?>>copyOf(IterableExtensions.<IQuerySpecification<?>>filter(patterns, _function)); | ||
408 | Map<IQuerySpecification<?>, EStructuralFeature> _emptyMap = CollectionLiterals.<IQuerySpecification<?>, EStructuralFeature>emptyMap(); | ||
409 | _xblockexpression = new ViatraQuerySetDescriptor(patterns, validationPatterns, _emptyMap); | ||
410 | } | ||
411 | return _xblockexpression; | ||
412 | } | ||
413 | |||
414 | public CostObjectiveConfiguration getObjective(final Ecore2Logic ecore2Logic, final Ecore2Logic_Trace ecore2LogicTrace) { | ||
415 | CostObjectiveConfiguration _costObjectiveConfiguration = new CostObjectiveConfiguration(); | ||
416 | final Procedure1<CostObjectiveConfiguration> _function = (CostObjectiveConfiguration it) -> { | ||
417 | final Modes3ModelGenerator.MonitoringQuery monitoringQuery = this.monitoringQuery; | ||
418 | if (monitoringQuery != null) { | ||
419 | switch (monitoringQuery) { | ||
420 | case closeTrains: | ||
421 | CostObjectiveElementConfiguration _costObjectiveElementConfiguration = new CostObjectiveElementConfiguration(); | ||
422 | final Procedure1<CostObjectiveElementConfiguration> _function_1 = (CostObjectiveElementConfiguration it_1) -> { | ||
423 | it_1.patternQualifiedName = CloseTrains_step_2.instance().getFullyQualifiedName(); | ||
424 | it_1.weight = ((14 + 53) + 11); | ||
425 | }; | ||
426 | CostObjectiveElementConfiguration _doubleArrow = ObjectExtensions.<CostObjectiveElementConfiguration>operator_doubleArrow(_costObjectiveElementConfiguration, _function_1); | ||
427 | it.elements.add(_doubleArrow); | ||
428 | CostObjectiveElementConfiguration _costObjectiveElementConfiguration_1 = new CostObjectiveElementConfiguration(); | ||
429 | final Procedure1<CostObjectiveElementConfiguration> _function_2 = (CostObjectiveElementConfiguration it_1) -> { | ||
430 | it_1.patternQualifiedName = CloseTrains_step_3.instance().getFullyQualifiedName(); | ||
431 | it_1.weight = (21 + 14); | ||
432 | }; | ||
433 | CostObjectiveElementConfiguration _doubleArrow_1 = ObjectExtensions.<CostObjectiveElementConfiguration>operator_doubleArrow(_costObjectiveElementConfiguration_1, _function_2); | ||
434 | it.elements.add(_doubleArrow_1); | ||
435 | CostObjectiveElementConfiguration _costObjectiveElementConfiguration_2 = new CostObjectiveElementConfiguration(); | ||
436 | final Procedure1<CostObjectiveElementConfiguration> _function_3 = (CostObjectiveElementConfiguration it_1) -> { | ||
437 | it_1.patternQualifiedName = CloseTrains_step_4.instance().getFullyQualifiedName(); | ||
438 | it_1.weight = (((14 + 44) + 14) + 9); | ||
439 | }; | ||
440 | CostObjectiveElementConfiguration _doubleArrow_2 = ObjectExtensions.<CostObjectiveElementConfiguration>operator_doubleArrow(_costObjectiveElementConfiguration_2, _function_3); | ||
441 | it.elements.add(_doubleArrow_2); | ||
442 | CostObjectiveElementConfiguration _costObjectiveElementConfiguration_3 = new CostObjectiveElementConfiguration(); | ||
443 | final Procedure1<CostObjectiveElementConfiguration> _function_4 = (CostObjectiveElementConfiguration it_1) -> { | ||
444 | it_1.patternQualifiedName = CloseTrains_step_5.instance().getFullyQualifiedName(); | ||
445 | it_1.weight = ((14 + 41) + 11); | ||
446 | }; | ||
447 | CostObjectiveElementConfiguration _doubleArrow_3 = ObjectExtensions.<CostObjectiveElementConfiguration>operator_doubleArrow(_costObjectiveElementConfiguration_3, _function_4); | ||
448 | it.elements.add(_doubleArrow_3); | ||
449 | CostObjectiveElementConfiguration _costObjectiveElementConfiguration_4 = new CostObjectiveElementConfiguration(); | ||
450 | final Procedure1<CostObjectiveElementConfiguration> _function_5 = (CostObjectiveElementConfiguration it_1) -> { | ||
451 | it_1.patternQualifiedName = CloseTrains_step_6.instance().getFullyQualifiedName(); | ||
452 | it_1.weight = 27; | ||
453 | }; | ||
454 | CostObjectiveElementConfiguration _doubleArrow_4 = ObjectExtensions.<CostObjectiveElementConfiguration>operator_doubleArrow(_costObjectiveElementConfiguration_4, _function_5); | ||
455 | it.elements.add(_doubleArrow_4); | ||
456 | CostObjectiveElementConfiguration _costObjectiveElementConfiguration_5 = new CostObjectiveElementConfiguration(); | ||
457 | final Procedure1<CostObjectiveElementConfiguration> _function_6 = (CostObjectiveElementConfiguration it_1) -> { | ||
458 | it_1.patternQualifiedName = CloseTrains_step_7.instance().getFullyQualifiedName(); | ||
459 | it_1.weight = 48; | ||
460 | }; | ||
461 | CostObjectiveElementConfiguration _doubleArrow_5 = ObjectExtensions.<CostObjectiveElementConfiguration>operator_doubleArrow(_costObjectiveElementConfiguration_5, _function_6); | ||
462 | it.elements.add(_doubleArrow_5); | ||
463 | CloseTrainsObjectiveHint _closeTrainsObjectiveHint = new CloseTrainsObjectiveHint(ecore2Logic, ecore2LogicTrace); | ||
464 | it.hint = _closeTrainsObjectiveHint; | ||
465 | break; | ||
466 | case trainLocations: | ||
467 | CostObjectiveElementConfiguration _costObjectiveElementConfiguration_6 = new CostObjectiveElementConfiguration(); | ||
468 | final Procedure1<CostObjectiveElementConfiguration> _function_7 = (CostObjectiveElementConfiguration it_1) -> { | ||
469 | it_1.patternQualifiedName = TrainLocations_step_2.instance().getFullyQualifiedName(); | ||
470 | it_1.weight = ((14 + 53) + 11); | ||
471 | }; | ||
472 | CostObjectiveElementConfiguration _doubleArrow_6 = ObjectExtensions.<CostObjectiveElementConfiguration>operator_doubleArrow(_costObjectiveElementConfiguration_6, _function_7); | ||
473 | it.elements.add(_doubleArrow_6); | ||
474 | CostObjectiveElementConfiguration _costObjectiveElementConfiguration_7 = new CostObjectiveElementConfiguration(); | ||
475 | final Procedure1<CostObjectiveElementConfiguration> _function_8 = (CostObjectiveElementConfiguration it_1) -> { | ||
476 | it_1.patternQualifiedName = TrainLocations_step_3.instance().getFullyQualifiedName(); | ||
477 | it_1.weight = 48; | ||
478 | }; | ||
479 | CostObjectiveElementConfiguration _doubleArrow_7 = ObjectExtensions.<CostObjectiveElementConfiguration>operator_doubleArrow(_costObjectiveElementConfiguration_7, _function_8); | ||
480 | it.elements.add(_doubleArrow_7); | ||
481 | TrainLocationsObjectiveHint _trainLocationsObjectiveHint = new TrainLocationsObjectiveHint(ecore2Logic, ecore2LogicTrace); | ||
482 | it.hint = _trainLocationsObjectiveHint; | ||
483 | break; | ||
484 | case misalignedTurnout: | ||
485 | CostObjectiveElementConfiguration _costObjectiveElementConfiguration_8 = new CostObjectiveElementConfiguration(); | ||
486 | final Procedure1<CostObjectiveElementConfiguration> _function_9 = (CostObjectiveElementConfiguration it_1) -> { | ||
487 | it_1.patternQualifiedName = MisalignedTurnout_step_2.instance().getFullyQualifiedName(); | ||
488 | it_1.weight = ((14 + 53) + 11); | ||
489 | }; | ||
490 | CostObjectiveElementConfiguration _doubleArrow_8 = ObjectExtensions.<CostObjectiveElementConfiguration>operator_doubleArrow(_costObjectiveElementConfiguration_8, _function_9); | ||
491 | it.elements.add(_doubleArrow_8); | ||
492 | CostObjectiveElementConfiguration _costObjectiveElementConfiguration_9 = new CostObjectiveElementConfiguration(); | ||
493 | final Procedure1<CostObjectiveElementConfiguration> _function_10 = (CostObjectiveElementConfiguration it_1) -> { | ||
494 | it_1.patternQualifiedName = MisalignedTurnout_step_3.instance().getFullyQualifiedName(); | ||
495 | it_1.weight = 108; | ||
496 | }; | ||
497 | CostObjectiveElementConfiguration _doubleArrow_9 = ObjectExtensions.<CostObjectiveElementConfiguration>operator_doubleArrow(_costObjectiveElementConfiguration_9, _function_10); | ||
498 | it.elements.add(_doubleArrow_9); | ||
499 | CostObjectiveElementConfiguration _costObjectiveElementConfiguration_10 = new CostObjectiveElementConfiguration(); | ||
500 | final Procedure1<CostObjectiveElementConfiguration> _function_11 = (CostObjectiveElementConfiguration it_1) -> { | ||
501 | it_1.patternQualifiedName = MisalignedTurnout_step_4.instance().getFullyQualifiedName(); | ||
502 | it_1.weight = 27; | ||
503 | }; | ||
504 | CostObjectiveElementConfiguration _doubleArrow_10 = ObjectExtensions.<CostObjectiveElementConfiguration>operator_doubleArrow(_costObjectiveElementConfiguration_10, _function_11); | ||
505 | it.elements.add(_doubleArrow_10); | ||
506 | CostObjectiveElementConfiguration _costObjectiveElementConfiguration_11 = new CostObjectiveElementConfiguration(); | ||
507 | final Procedure1<CostObjectiveElementConfiguration> _function_12 = (CostObjectiveElementConfiguration it_1) -> { | ||
508 | it_1.patternQualifiedName = MisalignedTurnout_step_5.instance().getFullyQualifiedName(); | ||
509 | it_1.weight = 48; | ||
510 | }; | ||
511 | CostObjectiveElementConfiguration _doubleArrow_11 = ObjectExtensions.<CostObjectiveElementConfiguration>operator_doubleArrow(_costObjectiveElementConfiguration_11, _function_12); | ||
512 | it.elements.add(_doubleArrow_11); | ||
513 | MisalignedTurnoutObjectiveHint _misalignedTurnoutObjectiveHint = new MisalignedTurnoutObjectiveHint(ecore2Logic, ecore2LogicTrace); | ||
514 | it.hint = _misalignedTurnoutObjectiveHint; | ||
515 | break; | ||
516 | case endOfSiding: | ||
517 | CostObjectiveElementConfiguration _costObjectiveElementConfiguration_12 = new CostObjectiveElementConfiguration(); | ||
518 | final Procedure1<CostObjectiveElementConfiguration> _function_13 = (CostObjectiveElementConfiguration it_1) -> { | ||
519 | it_1.patternQualifiedName = EndOfSiding_step_2.instance().getFullyQualifiedName(); | ||
520 | it_1.weight = ((14 + 53) + 11); | ||
521 | }; | ||
522 | CostObjectiveElementConfiguration _doubleArrow_12 = ObjectExtensions.<CostObjectiveElementConfiguration>operator_doubleArrow(_costObjectiveElementConfiguration_12, _function_13); | ||
523 | it.elements.add(_doubleArrow_12); | ||
524 | CostObjectiveElementConfiguration _costObjectiveElementConfiguration_13 = new CostObjectiveElementConfiguration(); | ||
525 | final Procedure1<CostObjectiveElementConfiguration> _function_14 = (CostObjectiveElementConfiguration it_1) -> { | ||
526 | it_1.patternQualifiedName = EndOfSiding_step_3.instance().getFullyQualifiedName(); | ||
527 | it_1.weight = (21 + 14); | ||
528 | }; | ||
529 | CostObjectiveElementConfiguration _doubleArrow_13 = ObjectExtensions.<CostObjectiveElementConfiguration>operator_doubleArrow(_costObjectiveElementConfiguration_13, _function_14); | ||
530 | it.elements.add(_doubleArrow_13); | ||
531 | CostObjectiveElementConfiguration _costObjectiveElementConfiguration_14 = new CostObjectiveElementConfiguration(); | ||
532 | final Procedure1<CostObjectiveElementConfiguration> _function_15 = (CostObjectiveElementConfiguration it_1) -> { | ||
533 | it_1.patternQualifiedName = EndOfSiding_step_4.instance().getFullyQualifiedName(); | ||
534 | it_1.weight = (((((((14 + 35) + 21) + 15) + 14) + 21) + 15) + 11); | ||
535 | }; | ||
536 | CostObjectiveElementConfiguration _doubleArrow_14 = ObjectExtensions.<CostObjectiveElementConfiguration>operator_doubleArrow(_costObjectiveElementConfiguration_14, _function_15); | ||
537 | it.elements.add(_doubleArrow_14); | ||
538 | CostObjectiveElementConfiguration _costObjectiveElementConfiguration_15 = new CostObjectiveElementConfiguration(); | ||
539 | final Procedure1<CostObjectiveElementConfiguration> _function_16 = (CostObjectiveElementConfiguration it_1) -> { | ||
540 | it_1.patternQualifiedName = EndOfSiding_step_5.instance().getFullyQualifiedName(); | ||
541 | it_1.weight = 48; | ||
542 | }; | ||
543 | CostObjectiveElementConfiguration _doubleArrow_15 = ObjectExtensions.<CostObjectiveElementConfiguration>operator_doubleArrow(_costObjectiveElementConfiguration_15, _function_16); | ||
544 | it.elements.add(_doubleArrow_15); | ||
545 | EndOfSidingObjectiveHint _endOfSidingObjectiveHint = new EndOfSidingObjectiveHint(ecore2Logic, ecore2LogicTrace); | ||
546 | it.hint = _endOfSidingObjectiveHint; | ||
547 | break; | ||
548 | default: | ||
549 | throw new IllegalArgumentException(("Unknown monitoring query: " + this.monitoringQuery)); | ||
550 | } | ||
551 | } else { | ||
552 | throw new IllegalArgumentException(("Unknown monitoring query: " + this.monitoringQuery)); | ||
553 | } | ||
554 | it.kind = ObjectiveKind.HIGHER_IS_BETTER; | ||
555 | it.threshold = ObjectiveThreshold.NO_THRESHOLD; | ||
556 | it.findExtremum = true; | ||
557 | }; | ||
558 | return ObjectExtensions.<CostObjectiveConfiguration>operator_doubleArrow(_costObjectiveConfiguration, _function); | ||
559 | } | ||
560 | |||
561 | public static Object init() { | ||
562 | Object _xblockexpression = null; | ||
563 | { | ||
564 | EMFPatternLanguageStandaloneSetup.doSetup(); | ||
565 | ViatraQueryEngineOptions.setSystemDefaultBackends(ReteBackendFactory.INSTANCE, ReteBackendFactory.INSTANCE, | ||
566 | LocalSearchEMFBackendFactory.INSTANCE); | ||
567 | LogiclanguagePackage.eINSTANCE.getClass(); | ||
568 | LogicproblemPackage.eINSTANCE.getClass(); | ||
569 | PartialinterpretationPackage.eINSTANCE.getClass(); | ||
570 | Ecore2logicannotationsPackage.eINSTANCE.getClass(); | ||
571 | Viatra2LogicAnnotationsPackage.eINSTANCE.getClass(); | ||
572 | Map<String, Object> _extensionToFactoryMap = Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap(); | ||
573 | XMIResourceFactoryImpl _xMIResourceFactoryImpl = new XMIResourceFactoryImpl(); | ||
574 | _xblockexpression = _extensionToFactoryMap.put("*", _xMIResourceFactoryImpl); | ||
575 | } | ||
576 | return _xblockexpression; | ||
577 | } | ||
578 | |||
579 | public static void main(final String[] args) { | ||
580 | int _length = args.length; | ||
581 | boolean _notEquals = (_length != 2); | ||
582 | if (_notEquals) { | ||
583 | System.err.println("Usage: <query> <model size>"); | ||
584 | } | ||
585 | final Modes3ModelGenerator.MonitoringQuery monitoringQuery = Modes3ModelGenerator.MonitoringQuery.valueOf(args[0]); | ||
586 | final int modelSize = Integer.parseInt(args[1]); | ||
587 | Modes3ModelGenerator.init(); | ||
588 | final Modes3ModelGenerator generator = new Modes3ModelGenerator(monitoringQuery, modelSize); | ||
589 | generator.generate(); | ||
590 | } | ||
591 | |||
592 | public Modes3ModelGenerator(final Modes3ModelGenerator.MonitoringQuery monitoringQuery, final int modelSize) { | ||
593 | super(); | ||
594 | this.monitoringQuery = monitoringQuery; | ||
595 | this.modelSize = modelSize; | ||
596 | } | ||
597 | } | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/Modes3TypeScopeHint.java b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/Modes3TypeScopeHint.java new file mode 100644 index 00000000..adb69760 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/Modes3TypeScopeHint.java | |||
@@ -0,0 +1,133 @@ | |||
1 | package modes3.run; | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic; | ||
4 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace; | ||
5 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type; | ||
6 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.Modality; | ||
7 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.LinearBoundedExpression; | ||
8 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.LinearTypeConstraintHint; | ||
9 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.LinearTypeExpressionBuilderFactory; | ||
10 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.RelationConstraintUpdater; | ||
11 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.patterns.PatternGenerator; | ||
12 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation; | ||
13 | import java.util.Iterator; | ||
14 | import java.util.Map; | ||
15 | import modes3.Modes3Package; | ||
16 | import modes3.queries.Adjacent; | ||
17 | import org.eclipse.viatra.query.runtime.api.IPatternMatch; | ||
18 | import org.eclipse.viatra.query.runtime.api.ViatraQueryMatcher; | ||
19 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PQuery; | ||
20 | import org.eclipse.xtend2.lib.StringConcatenation; | ||
21 | import org.eclipse.xtext.xbase.lib.Extension; | ||
22 | |||
23 | @SuppressWarnings("all") | ||
24 | public class Modes3TypeScopeHint implements LinearTypeConstraintHint { | ||
25 | private static final String TURNOUT_NEIGHBOR_COUNT = "turnoutNeighborCount"; | ||
26 | |||
27 | private final Type segmentType; | ||
28 | |||
29 | private final Type turnoutType; | ||
30 | |||
31 | public Modes3TypeScopeHint(@Extension final Ecore2Logic ecore2Logic, final Ecore2Logic_Trace ecore2LogicTrace) { | ||
32 | @Extension | ||
33 | final Modes3Package Modes3Package = modes3.Modes3Package.eINSTANCE; | ||
34 | this.segmentType = ecore2Logic.TypeofEClass(ecore2LogicTrace, Modes3Package.getSegment()); | ||
35 | this.turnoutType = ecore2Logic.TypeofEClass(ecore2LogicTrace, Modes3Package.getTurnout()); | ||
36 | } | ||
37 | |||
38 | @Override | ||
39 | public CharSequence getAdditionalPatterns(@Extension final PatternGenerator patternGenerator, final Map<String, PQuery> fqnToPQuery) { | ||
40 | StringConcatenation _builder = new StringConcatenation(); | ||
41 | _builder.append("\t"); | ||
42 | _builder.append("pattern "); | ||
43 | _builder.append(Modes3TypeScopeHint.TURNOUT_NEIGHBOR_COUNT, "\t"); | ||
44 | _builder.append("_helper(problem: LogicProblem, interpretation: PartialInterpretation, source: DefinedElement, target: DefinedElement) {"); | ||
45 | _builder.newLineIfNotEmpty(); | ||
46 | _builder.append("\t\t"); | ||
47 | _builder.append("find interpretation(problem, interpretation);"); | ||
48 | _builder.newLine(); | ||
49 | _builder.append("\t\t"); | ||
50 | _builder.append("find mustExist(problem, interpretation, source);"); | ||
51 | _builder.newLine(); | ||
52 | _builder.append("\t\t"); | ||
53 | _builder.append("find mustExist(problem, interpretation, target);"); | ||
54 | _builder.newLine(); | ||
55 | _builder.append("\t\t"); | ||
56 | CharSequence _referInstanceOf = patternGenerator.getTypeIndexer().referInstanceOf(this.turnoutType, Modality.MUST, "source"); | ||
57 | _builder.append(_referInstanceOf, "\t\t"); | ||
58 | _builder.newLineIfNotEmpty(); | ||
59 | _builder.append("\t\t"); | ||
60 | CharSequence _referInstanceOf_1 = patternGenerator.getTypeIndexer().referInstanceOf(this.segmentType, Modality.MUST, "target"); | ||
61 | _builder.append(_referInstanceOf_1, "\t\t"); | ||
62 | _builder.newLineIfNotEmpty(); | ||
63 | _builder.append("\t\t"); | ||
64 | CharSequence _referPattern = patternGenerator.getRelationDefinitionIndexer().referPattern(fqnToPQuery.get(Adjacent.instance().getFullyQualifiedName()), new String[] { "source", "target" }, Modality.MUST, true, false); | ||
65 | _builder.append(_referPattern, "\t\t"); | ||
66 | _builder.newLineIfNotEmpty(); | ||
67 | _builder.append("\t"); | ||
68 | _builder.append("}"); | ||
69 | _builder.newLine(); | ||
70 | _builder.newLine(); | ||
71 | _builder.append("\t"); | ||
72 | _builder.append("pattern "); | ||
73 | _builder.append(Modes3TypeScopeHint.TURNOUT_NEIGHBOR_COUNT, "\t"); | ||
74 | _builder.append("(problem: LogicProblem, interpretation: PartialInterpretation, element: DefinedElement, N) {"); | ||
75 | _builder.newLineIfNotEmpty(); | ||
76 | _builder.append("\t\t"); | ||
77 | _builder.append("find interpretation(problem, interpretation);"); | ||
78 | _builder.newLine(); | ||
79 | _builder.append("\t\t"); | ||
80 | _builder.append("find mustExist(problem, interpretation, element);"); | ||
81 | _builder.newLine(); | ||
82 | _builder.append("\t\t"); | ||
83 | CharSequence _referInstanceOf_2 = patternGenerator.getTypeIndexer().referInstanceOf(this.turnoutType, Modality.MUST, "element"); | ||
84 | _builder.append(_referInstanceOf_2, "\t\t"); | ||
85 | _builder.newLineIfNotEmpty(); | ||
86 | _builder.append("\t\t"); | ||
87 | _builder.append("N == count find "); | ||
88 | _builder.append(Modes3TypeScopeHint.TURNOUT_NEIGHBOR_COUNT, "\t\t"); | ||
89 | _builder.append("_helper(problem, interpretation, element, _);"); | ||
90 | _builder.newLineIfNotEmpty(); | ||
91 | _builder.append("\t"); | ||
92 | _builder.append("}"); | ||
93 | _builder.newLine(); | ||
94 | return _builder; | ||
95 | } | ||
96 | |||
97 | @Override | ||
98 | public RelationConstraintUpdater createConstraintUpdater(final LinearTypeExpressionBuilderFactory builderFactory) { | ||
99 | final ViatraQueryMatcher<? extends IPatternMatch> turnoutNeighborCountMatcher = builderFactory.createMatcher(Modes3TypeScopeHint.TURNOUT_NEIGHBOR_COUNT); | ||
100 | final LinearBoundedExpression newNeighbors = builderFactory.createBuilder().add(1, this.segmentType).build(); | ||
101 | final RelationConstraintUpdater _function = (PartialInterpretation partialInterpretation) -> { | ||
102 | final int requiredNeighbbors = Modes3TypeScopeHint.getRemainingCount(turnoutNeighborCountMatcher, partialInterpretation, 3); | ||
103 | newNeighbors.tightenLowerBound(Integer.valueOf(requiredNeighbbors)); | ||
104 | }; | ||
105 | return _function; | ||
106 | } | ||
107 | |||
108 | private static <T extends IPatternMatch> int getRemainingCount(final ViatraQueryMatcher<T> matcher, final PartialInterpretation partialInterpretation, final int capacity) { | ||
109 | int _xblockexpression = (int) 0; | ||
110 | { | ||
111 | final T partialMatch = matcher.newEmptyMatch(); | ||
112 | partialMatch.set(0, partialInterpretation.getProblem()); | ||
113 | partialMatch.set(1, partialInterpretation); | ||
114 | final Iterator<T> iterator = matcher.streamAllMatches(partialMatch).iterator(); | ||
115 | int max = 0; | ||
116 | while (iterator.hasNext()) { | ||
117 | { | ||
118 | final T match = iterator.next(); | ||
119 | Object _get = match.get(3); | ||
120 | final int n = ((Integer) _get).intValue(); | ||
121 | if ((n < capacity)) { | ||
122 | final int required = (capacity - n); | ||
123 | if ((max < required)) { | ||
124 | max = required; | ||
125 | } | ||
126 | } | ||
127 | } | ||
128 | } | ||
129 | _xblockexpression = max; | ||
130 | } | ||
131 | return _xblockexpression; | ||
132 | } | ||
133 | } | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/Modes3UnitPropagationGenerator.java b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/Modes3UnitPropagationGenerator.java new file mode 100644 index 00000000..5c5f82c5 --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/Modes3UnitPropagationGenerator.java | |||
@@ -0,0 +1,1174 @@ | |||
1 | package modes3.run; | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic; | ||
4 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace; | ||
5 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Relation; | ||
6 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type; | ||
7 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.Modality; | ||
8 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.patterns.PatternGenerator; | ||
9 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.patterns.UnitPropagationPatternGenerator; | ||
10 | import java.util.Collections; | ||
11 | import java.util.Map; | ||
12 | import modes3.Modes3Package; | ||
13 | import modes3.queries.Adjacent; | ||
14 | import modes3.queries.Output; | ||
15 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PQuery; | ||
16 | import org.eclipse.xtend2.lib.StringConcatenationClient; | ||
17 | import org.eclipse.xtext.xbase.lib.CollectionLiterals; | ||
18 | import org.eclipse.xtext.xbase.lib.Extension; | ||
19 | import org.eclipse.xtext.xbase.lib.Pair; | ||
20 | |||
21 | @SuppressWarnings("all") | ||
22 | public class Modes3UnitPropagationGenerator implements UnitPropagationPatternGenerator { | ||
23 | private static final String MUST_NOT_CONNECTED_TO = "mustNotConnectedTo"; | ||
24 | |||
25 | private static final String MUST_NOT_STRAIGHT = "mustNotStraight"; | ||
26 | |||
27 | private static final String MUST_NOT_DIVERGENT = "mustNotDivergent"; | ||
28 | |||
29 | private static final String MUST_CONNECTED_TO = "mustConnectedTo"; | ||
30 | |||
31 | private static final String MUST_STRAIGHT = "mustStraight"; | ||
32 | |||
33 | private static final String MUST_DIVERGENT = "mustDivergent"; | ||
34 | |||
35 | private final Type segmentType; | ||
36 | |||
37 | private final Type simpleSegmentType; | ||
38 | |||
39 | private final Type turnoutType; | ||
40 | |||
41 | private final Relation connectedToRelation; | ||
42 | |||
43 | private final Relation straightRelation; | ||
44 | |||
45 | private final Relation divergentRelation; | ||
46 | |||
47 | public Modes3UnitPropagationGenerator(@Extension final Ecore2Logic ecore2Logic, final Ecore2Logic_Trace ecore2LogicTrace) { | ||
48 | @Extension | ||
49 | final Modes3Package Modes3Package = modes3.Modes3Package.eINSTANCE; | ||
50 | this.segmentType = ecore2Logic.TypeofEClass(ecore2LogicTrace, Modes3Package.getSegment()); | ||
51 | this.simpleSegmentType = ecore2Logic.TypeofEClass(ecore2LogicTrace, Modes3Package.getSimpleSegment()); | ||
52 | this.turnoutType = ecore2Logic.TypeofEClass(ecore2LogicTrace, Modes3Package.getTurnout()); | ||
53 | this.connectedToRelation = ecore2Logic.relationOfReference(ecore2LogicTrace, Modes3Package.getSegment_ConnectedTo()); | ||
54 | this.straightRelation = ecore2Logic.relationOfReference(ecore2LogicTrace, Modes3Package.getTurnout_Straight()); | ||
55 | this.divergentRelation = ecore2Logic.relationOfReference(ecore2LogicTrace, Modes3Package.getTurnout_Divergent()); | ||
56 | } | ||
57 | |||
58 | @Override | ||
59 | public Map<Relation, String> getMustPatterns() { | ||
60 | Pair<Relation, String> _mappedTo = Pair.<Relation, String>of(this.connectedToRelation, Modes3UnitPropagationGenerator.MUST_CONNECTED_TO); | ||
61 | Pair<Relation, String> _mappedTo_1 = Pair.<Relation, String>of(this.straightRelation, Modes3UnitPropagationGenerator.MUST_STRAIGHT); | ||
62 | Pair<Relation, String> _mappedTo_2 = Pair.<Relation, String>of(this.divergentRelation, Modes3UnitPropagationGenerator.MUST_DIVERGENT); | ||
63 | return Collections.<Relation, String>unmodifiableMap(CollectionLiterals.<Relation, String>newHashMap(_mappedTo, _mappedTo_1, _mappedTo_2)); | ||
64 | } | ||
65 | |||
66 | @Override | ||
67 | public Map<Relation, String> getMustNotPatterns() { | ||
68 | Pair<Relation, String> _mappedTo = Pair.<Relation, String>of(this.connectedToRelation, Modes3UnitPropagationGenerator.MUST_NOT_CONNECTED_TO); | ||
69 | Pair<Relation, String> _mappedTo_1 = Pair.<Relation, String>of(this.straightRelation, Modes3UnitPropagationGenerator.MUST_NOT_STRAIGHT); | ||
70 | Pair<Relation, String> _mappedTo_2 = Pair.<Relation, String>of(this.divergentRelation, Modes3UnitPropagationGenerator.MUST_NOT_DIVERGENT); | ||
71 | return Collections.<Relation, String>unmodifiableMap(CollectionLiterals.<Relation, String>newHashMap(_mappedTo, _mappedTo_1, _mappedTo_2)); | ||
72 | } | ||
73 | |||
74 | @Override | ||
75 | public StringConcatenationClient getAdditionalPatterns(@Extension final PatternGenerator generator, final Map<String, PQuery> fqnToPQuery) { | ||
76 | StringConcatenationClient _xblockexpression = null; | ||
77 | { | ||
78 | StringConcatenationClient _client = new StringConcatenationClient() { | ||
79 | @Override | ||
80 | protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) { | ||
81 | _builder.append("problem: LogicProblem, interpretation: PartialInterpretation,"); | ||
82 | _builder.newLine(); | ||
83 | _builder.append("source: DefinedElement, target: DefinedElement"); | ||
84 | _builder.newLine(); | ||
85 | } | ||
86 | }; | ||
87 | final StringConcatenationClient parameters = _client; | ||
88 | StringConcatenationClient _client_1 = new StringConcatenationClient() { | ||
89 | @Override | ||
90 | protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) { | ||
91 | _builder.append("find interpretation(problem, interpretation);"); | ||
92 | _builder.newLine(); | ||
93 | _builder.append("find mustExist(problem, interpretation, source);"); | ||
94 | _builder.newLine(); | ||
95 | _builder.append("find mustExist(problem, interpretation, target);"); | ||
96 | _builder.newLine(); | ||
97 | } | ||
98 | }; | ||
99 | final StringConcatenationClient commonMustParameterConstraints = _client_1; | ||
100 | StringConcatenationClient _client_2 = new StringConcatenationClient() { | ||
101 | @Override | ||
102 | protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) { | ||
103 | _builder.append("find interpretation(problem, interpretation);"); | ||
104 | _builder.newLine(); | ||
105 | _builder.append("find mayExist(problem, interpretation, source);"); | ||
106 | _builder.newLine(); | ||
107 | _builder.append("find mayExist(problem, interpretation, target);"); | ||
108 | _builder.newLine(); | ||
109 | } | ||
110 | }; | ||
111 | final StringConcatenationClient commonMayParameterConstraints = _client_2; | ||
112 | StringConcatenationClient _client_3 = new StringConcatenationClient() { | ||
113 | @Override | ||
114 | protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) { | ||
115 | _builder.append("pattern mayInput("); | ||
116 | _builder.append(parameters); | ||
117 | _builder.append(") {"); | ||
118 | _builder.newLineIfNotEmpty(); | ||
119 | _builder.append("\t"); | ||
120 | _builder.append(commonMayParameterConstraints, "\t"); | ||
121 | _builder.newLineIfNotEmpty(); | ||
122 | _builder.append("\t"); | ||
123 | CharSequence _referInstanceOf = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.segmentType, Modality.MAY, "target"); | ||
124 | _builder.append(_referInstanceOf, "\t"); | ||
125 | _builder.newLineIfNotEmpty(); | ||
126 | _builder.append("\t"); | ||
127 | CharSequence _referPattern = generator.getRelationDefinitionIndexer().referPattern(fqnToPQuery.get(Adjacent.instance().getFullyQualifiedName()), new String[] { "target", "source" }, Modality.MAY, true, false); | ||
128 | _builder.append(_referPattern, "\t"); | ||
129 | _builder.newLineIfNotEmpty(); | ||
130 | _builder.append("\t"); | ||
131 | _builder.append("neg "); | ||
132 | CharSequence _referRelation = generator.referRelation(Modes3UnitPropagationGenerator.this.straightRelation, "target", "source", Modality.MUST, fqnToPQuery); | ||
133 | _builder.append(_referRelation, "\t"); | ||
134 | _builder.newLineIfNotEmpty(); | ||
135 | _builder.append("\t"); | ||
136 | _builder.append("neg "); | ||
137 | CharSequence _referRelation_1 = generator.referRelation(Modes3UnitPropagationGenerator.this.straightRelation, "target", "source", Modality.MUST, fqnToPQuery); | ||
138 | _builder.append(_referRelation_1, "\t"); | ||
139 | _builder.newLineIfNotEmpty(); | ||
140 | _builder.append("}"); | ||
141 | _builder.newLine(); | ||
142 | _builder.newLine(); | ||
143 | _builder.append("pattern multipleMayInput(problem: LogicProblem, interpretation: PartialInterpretation,"); | ||
144 | _builder.newLine(); | ||
145 | _builder.append("\t\t\t"); | ||
146 | _builder.append("target: DefinedElement) {"); | ||
147 | _builder.newLine(); | ||
148 | _builder.append("\t"); | ||
149 | _builder.append("find interpretation(problem, interpretation);"); | ||
150 | _builder.newLine(); | ||
151 | _builder.append("\t"); | ||
152 | _builder.append("find mustExist(problem, interpretation, target);"); | ||
153 | _builder.newLine(); | ||
154 | _builder.append("\t"); | ||
155 | _builder.append("find mayInput(problem, interpretaton, source1, target);"); | ||
156 | _builder.newLine(); | ||
157 | _builder.append("\t"); | ||
158 | _builder.append("find mayInput(problem, interpretaton, source2, target);"); | ||
159 | _builder.newLine(); | ||
160 | _builder.append("\t"); | ||
161 | _builder.append("neg find mustEquivalent(problem, interpretation, source1, source2);"); | ||
162 | _builder.newLine(); | ||
163 | _builder.append("}"); | ||
164 | _builder.newLine(); | ||
165 | _builder.newLine(); | ||
166 | _builder.append("pattern multipleMayStraight(problem: LogicProblem, interpretation: PartialInterpretation,"); | ||
167 | _builder.newLine(); | ||
168 | _builder.append("\t\t\t"); | ||
169 | _builder.append("source: DefinedElement) {"); | ||
170 | _builder.newLine(); | ||
171 | _builder.append("\t"); | ||
172 | _builder.append("find interpretation(problem, interpretation);"); | ||
173 | _builder.newLine(); | ||
174 | _builder.append("\t"); | ||
175 | _builder.append("find mustExist(problem, interpretation, source);"); | ||
176 | _builder.newLine(); | ||
177 | _builder.append("\t"); | ||
178 | CharSequence _referInstanceOf_1 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.turnoutType, Modality.MAY, "source"); | ||
179 | _builder.append(_referInstanceOf_1, "\t"); | ||
180 | _builder.newLineIfNotEmpty(); | ||
181 | _builder.append("\t"); | ||
182 | CharSequence _referRelation_2 = generator.referRelation(Modes3UnitPropagationGenerator.this.straightRelation, "source", "target1", Modality.MAY, fqnToPQuery); | ||
183 | _builder.append(_referRelation_2, "\t"); | ||
184 | _builder.newLineIfNotEmpty(); | ||
185 | _builder.append("\t"); | ||
186 | CharSequence _referRelation_3 = generator.referRelation(Modes3UnitPropagationGenerator.this.straightRelation, "source", "target2", Modality.MAY, fqnToPQuery); | ||
187 | _builder.append(_referRelation_3, "\t"); | ||
188 | _builder.newLineIfNotEmpty(); | ||
189 | _builder.append("\t"); | ||
190 | _builder.append("neg find mustEquivalent(problem, interpretation, target1, target2);"); | ||
191 | _builder.newLine(); | ||
192 | _builder.append("}"); | ||
193 | _builder.newLine(); | ||
194 | _builder.newLine(); | ||
195 | _builder.append("pattern multipleMayDivergent(problem: LogicProblem, interpretation: PartialInterpretation,"); | ||
196 | _builder.newLine(); | ||
197 | _builder.append("\t\t\t"); | ||
198 | _builder.append("source: DefinedElement) {"); | ||
199 | _builder.newLine(); | ||
200 | _builder.append("\t"); | ||
201 | _builder.append("find interpretation(problem, interpretation);"); | ||
202 | _builder.newLine(); | ||
203 | _builder.append("\t"); | ||
204 | _builder.append("find mustExist(problem, interpretation, source);"); | ||
205 | _builder.newLine(); | ||
206 | _builder.append("\t"); | ||
207 | CharSequence _referInstanceOf_2 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.turnoutType, Modality.MAY, "source"); | ||
208 | _builder.append(_referInstanceOf_2, "\t"); | ||
209 | _builder.newLineIfNotEmpty(); | ||
210 | _builder.append("\t"); | ||
211 | CharSequence _referRelation_4 = generator.referRelation(Modes3UnitPropagationGenerator.this.divergentRelation, "source", "target1", Modality.MAY, fqnToPQuery); | ||
212 | _builder.append(_referRelation_4, "\t"); | ||
213 | _builder.newLineIfNotEmpty(); | ||
214 | _builder.append("\t"); | ||
215 | CharSequence _referRelation_5 = generator.referRelation(Modes3UnitPropagationGenerator.this.divergentRelation, "source", "target2", Modality.MAY, fqnToPQuery); | ||
216 | _builder.append(_referRelation_5, "\t"); | ||
217 | _builder.newLineIfNotEmpty(); | ||
218 | _builder.append("\t"); | ||
219 | _builder.append("neg find mustEquivalent(problem, interpretation, target1, target2);"); | ||
220 | _builder.newLine(); | ||
221 | _builder.append("}"); | ||
222 | _builder.newLine(); | ||
223 | _builder.newLine(); | ||
224 | _builder.append("pattern "); | ||
225 | _builder.append(Modes3UnitPropagationGenerator.MUST_CONNECTED_TO); | ||
226 | _builder.append("("); | ||
227 | _builder.append(parameters); | ||
228 | _builder.append(") {"); | ||
229 | _builder.newLineIfNotEmpty(); | ||
230 | _builder.append("\t"); | ||
231 | _builder.append(commonMustParameterConstraints, "\t"); | ||
232 | _builder.newLineIfNotEmpty(); | ||
233 | _builder.append("\t"); | ||
234 | CharSequence _referInstanceOf_3 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.segmentType, Modality.MAY, "target"); | ||
235 | _builder.append(_referInstanceOf_3, "\t"); | ||
236 | _builder.newLineIfNotEmpty(); | ||
237 | _builder.append("\t"); | ||
238 | _builder.append("find mayInput(problem, interpretaton, source, target);"); | ||
239 | _builder.newLine(); | ||
240 | _builder.append("\t"); | ||
241 | _builder.append("neg find multipleMayInput(problem, interpretaton, target);"); | ||
242 | _builder.newLine(); | ||
243 | _builder.append("\t"); | ||
244 | CharSequence _referRelation_6 = generator.referRelation(Modes3UnitPropagationGenerator.this.connectedToRelation, "source", "target", Modality.MAY, fqnToPQuery); | ||
245 | _builder.append(_referRelation_6, "\t"); | ||
246 | _builder.newLineIfNotEmpty(); | ||
247 | _builder.append("\t"); | ||
248 | _builder.append("neg "); | ||
249 | CharSequence _referRelation_7 = generator.referRelation(Modes3UnitPropagationGenerator.this.connectedToRelation, "source", "target", Modality.MUST, fqnToPQuery); | ||
250 | _builder.append(_referRelation_7, "\t"); | ||
251 | _builder.newLineIfNotEmpty(); | ||
252 | _builder.append("\t"); | ||
253 | _builder.append("neg "); | ||
254 | CharSequence _referRelation_8 = generator.referRelation(Modes3UnitPropagationGenerator.this.straightRelation, "source", "target", Modality.MAY, fqnToPQuery); | ||
255 | _builder.append(_referRelation_8, "\t"); | ||
256 | _builder.newLineIfNotEmpty(); | ||
257 | _builder.append("\t"); | ||
258 | _builder.append("neg "); | ||
259 | CharSequence _referRelation_9 = generator.referRelation(Modes3UnitPropagationGenerator.this.divergentRelation, "source", "target", Modality.MAY, fqnToPQuery); | ||
260 | _builder.append(_referRelation_9, "\t"); | ||
261 | _builder.newLineIfNotEmpty(); | ||
262 | _builder.append("}"); | ||
263 | _builder.newLine(); | ||
264 | _builder.newLine(); | ||
265 | _builder.append("pattern "); | ||
266 | _builder.append(Modes3UnitPropagationGenerator.MUST_STRAIGHT); | ||
267 | _builder.append("("); | ||
268 | _builder.append(parameters); | ||
269 | _builder.append(") {"); | ||
270 | _builder.newLineIfNotEmpty(); | ||
271 | _builder.append("\t"); | ||
272 | _builder.append(commonMustParameterConstraints, "\t"); | ||
273 | _builder.newLineIfNotEmpty(); | ||
274 | _builder.append("\t"); | ||
275 | _builder.append("neg "); | ||
276 | CharSequence _referRelation_10 = generator.referRelation(Modes3UnitPropagationGenerator.this.straightRelation, "source", "_", Modality.MUST, fqnToPQuery); | ||
277 | _builder.append(_referRelation_10, "\t"); | ||
278 | _builder.newLineIfNotEmpty(); | ||
279 | _builder.append("\t"); | ||
280 | _builder.append("neg find multipleMayStraight(problem, interpretation, source);"); | ||
281 | _builder.newLine(); | ||
282 | _builder.append("\t"); | ||
283 | CharSequence _referRelation_11 = generator.referRelation(Modes3UnitPropagationGenerator.this.straightRelation, "source", "target", Modality.MAY, fqnToPQuery); | ||
284 | _builder.append(_referRelation_11, "\t"); | ||
285 | _builder.newLineIfNotEmpty(); | ||
286 | _builder.append("\t"); | ||
287 | _builder.append("neg "); | ||
288 | CharSequence _referRelation_12 = generator.referRelation(Modes3UnitPropagationGenerator.this.straightRelation, "source", "target", Modality.MUST, fqnToPQuery); | ||
289 | _builder.append(_referRelation_12, "\t"); | ||
290 | _builder.newLineIfNotEmpty(); | ||
291 | _builder.append("} or {"); | ||
292 | _builder.newLine(); | ||
293 | _builder.append("\t"); | ||
294 | _builder.append(commonMustParameterConstraints, "\t"); | ||
295 | _builder.newLineIfNotEmpty(); | ||
296 | _builder.append("\t"); | ||
297 | CharSequence _referInstanceOf_4 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.segmentType, Modality.MAY, "target"); | ||
298 | _builder.append(_referInstanceOf_4, "\t"); | ||
299 | _builder.newLineIfNotEmpty(); | ||
300 | _builder.append("\t"); | ||
301 | _builder.append("find mayInput(problem, interpretaton, source, target);"); | ||
302 | _builder.newLine(); | ||
303 | _builder.append("\t"); | ||
304 | _builder.append("neg find multipleMayInput(problem, interpretaton, target);"); | ||
305 | _builder.newLine(); | ||
306 | _builder.append("\t"); | ||
307 | _builder.append("neg "); | ||
308 | CharSequence _referRelation_13 = generator.referRelation(Modes3UnitPropagationGenerator.this.connectedToRelation, "source", "target", Modality.MAY, fqnToPQuery); | ||
309 | _builder.append(_referRelation_13, "\t"); | ||
310 | _builder.newLineIfNotEmpty(); | ||
311 | _builder.append("\t"); | ||
312 | CharSequence _referRelation_14 = generator.referRelation(Modes3UnitPropagationGenerator.this.straightRelation, "source", "target", Modality.MAY, fqnToPQuery); | ||
313 | _builder.append(_referRelation_14, "\t"); | ||
314 | _builder.newLineIfNotEmpty(); | ||
315 | _builder.append("\t"); | ||
316 | _builder.append("neg "); | ||
317 | CharSequence _referRelation_15 = generator.referRelation(Modes3UnitPropagationGenerator.this.straightRelation, "source", "target", Modality.MUST, fqnToPQuery); | ||
318 | _builder.append(_referRelation_15, "\t"); | ||
319 | _builder.newLineIfNotEmpty(); | ||
320 | _builder.append("\t"); | ||
321 | _builder.append("neg "); | ||
322 | CharSequence _referRelation_16 = generator.referRelation(Modes3UnitPropagationGenerator.this.divergentRelation, "source", "target", Modality.MAY, fqnToPQuery); | ||
323 | _builder.append(_referRelation_16, "\t"); | ||
324 | _builder.newLineIfNotEmpty(); | ||
325 | _builder.append("}"); | ||
326 | _builder.newLine(); | ||
327 | _builder.newLine(); | ||
328 | _builder.append("pattern "); | ||
329 | _builder.append(Modes3UnitPropagationGenerator.MUST_DIVERGENT); | ||
330 | _builder.append("("); | ||
331 | _builder.append(parameters); | ||
332 | _builder.append(") {"); | ||
333 | _builder.newLineIfNotEmpty(); | ||
334 | _builder.append("\t"); | ||
335 | _builder.append(commonMustParameterConstraints, "\t"); | ||
336 | _builder.newLineIfNotEmpty(); | ||
337 | _builder.append("\t"); | ||
338 | _builder.append("neg "); | ||
339 | CharSequence _referRelation_17 = generator.referRelation(Modes3UnitPropagationGenerator.this.divergentRelation, "source", "_", Modality.MUST, fqnToPQuery); | ||
340 | _builder.append(_referRelation_17, "\t"); | ||
341 | _builder.newLineIfNotEmpty(); | ||
342 | _builder.append("\t"); | ||
343 | _builder.append("neg find multipleMayDivergent(problem, interpretation, source);"); | ||
344 | _builder.newLine(); | ||
345 | _builder.append("\t"); | ||
346 | CharSequence _referRelation_18 = generator.referRelation(Modes3UnitPropagationGenerator.this.divergentRelation, "source", "target", Modality.MAY, fqnToPQuery); | ||
347 | _builder.append(_referRelation_18, "\t"); | ||
348 | _builder.newLineIfNotEmpty(); | ||
349 | _builder.append("\t"); | ||
350 | _builder.append("neg "); | ||
351 | CharSequence _referRelation_19 = generator.referRelation(Modes3UnitPropagationGenerator.this.divergentRelation, "source", "target", Modality.MUST, fqnToPQuery); | ||
352 | _builder.append(_referRelation_19, "\t"); | ||
353 | _builder.newLineIfNotEmpty(); | ||
354 | _builder.append("} or {"); | ||
355 | _builder.newLine(); | ||
356 | _builder.append("\t"); | ||
357 | _builder.append(commonMustParameterConstraints, "\t"); | ||
358 | _builder.newLineIfNotEmpty(); | ||
359 | _builder.append("\t"); | ||
360 | CharSequence _referInstanceOf_5 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.segmentType, Modality.MAY, "target"); | ||
361 | _builder.append(_referInstanceOf_5, "\t"); | ||
362 | _builder.newLineIfNotEmpty(); | ||
363 | _builder.append("\t"); | ||
364 | _builder.append("find mayInput(problem, interpretaton, source, target);"); | ||
365 | _builder.newLine(); | ||
366 | _builder.append("\t"); | ||
367 | _builder.append("neg find multipleMayInput(problem, interpretaton, target);"); | ||
368 | _builder.newLine(); | ||
369 | _builder.append("\t"); | ||
370 | _builder.append("neg "); | ||
371 | CharSequence _referRelation_20 = generator.referRelation(Modes3UnitPropagationGenerator.this.connectedToRelation, "source", "target", Modality.MAY, fqnToPQuery); | ||
372 | _builder.append(_referRelation_20, "\t"); | ||
373 | _builder.newLineIfNotEmpty(); | ||
374 | _builder.append("\t"); | ||
375 | _builder.append("neg "); | ||
376 | CharSequence _referRelation_21 = generator.referRelation(Modes3UnitPropagationGenerator.this.straightRelation, "source", "target", Modality.MAY, fqnToPQuery); | ||
377 | _builder.append(_referRelation_21, "\t"); | ||
378 | _builder.newLineIfNotEmpty(); | ||
379 | _builder.append("\t"); | ||
380 | CharSequence _referRelation_22 = generator.referRelation(Modes3UnitPropagationGenerator.this.divergentRelation, "source", "target", Modality.MAY, fqnToPQuery); | ||
381 | _builder.append(_referRelation_22, "\t"); | ||
382 | _builder.newLineIfNotEmpty(); | ||
383 | _builder.append("\t"); | ||
384 | _builder.append("neg "); | ||
385 | CharSequence _referRelation_23 = generator.referRelation(Modes3UnitPropagationGenerator.this.divergentRelation, "source", "target", Modality.MUST, fqnToPQuery); | ||
386 | _builder.append(_referRelation_23, "\t"); | ||
387 | _builder.newLineIfNotEmpty(); | ||
388 | _builder.append("}"); | ||
389 | _builder.newLine(); | ||
390 | _builder.newLine(); | ||
391 | _builder.append("pattern turnoutOutput_must_to_true_by_straight("); | ||
392 | _builder.append(parameters); | ||
393 | _builder.append(", T : DefinedElement, S : DefinedElement) {"); | ||
394 | _builder.newLineIfNotEmpty(); | ||
395 | _builder.append("\t"); | ||
396 | _builder.append(commonMayParameterConstraints, "\t"); | ||
397 | _builder.newLineIfNotEmpty(); | ||
398 | _builder.append("\t"); | ||
399 | CharSequence _referInstanceOf_6 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.turnoutType, Modality.MAY, "source"); | ||
400 | _builder.append(_referInstanceOf_6, "\t"); | ||
401 | _builder.newLineIfNotEmpty(); | ||
402 | _builder.append("\t"); | ||
403 | CharSequence _referInstanceOf_7 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.segmentType, Modality.MAY, "target"); | ||
404 | _builder.append(_referInstanceOf_7, "\t"); | ||
405 | _builder.newLineIfNotEmpty(); | ||
406 | _builder.append("\t"); | ||
407 | _builder.append("T == source;"); | ||
408 | _builder.newLine(); | ||
409 | _builder.append("\t"); | ||
410 | _builder.append("S == target;"); | ||
411 | _builder.newLine(); | ||
412 | _builder.append("}"); | ||
413 | _builder.newLine(); | ||
414 | _builder.newLine(); | ||
415 | _builder.append("pattern turnoutOutput_must_to_true_by_divergent("); | ||
416 | _builder.append(parameters); | ||
417 | _builder.append(", T : DefinedElement, S : DefinedElement) {"); | ||
418 | _builder.newLineIfNotEmpty(); | ||
419 | _builder.append("\t"); | ||
420 | _builder.append(commonMayParameterConstraints, "\t"); | ||
421 | _builder.newLineIfNotEmpty(); | ||
422 | _builder.append("\t"); | ||
423 | CharSequence _referInstanceOf_8 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.turnoutType, Modality.MAY, "source"); | ||
424 | _builder.append(_referInstanceOf_8, "\t"); | ||
425 | _builder.newLineIfNotEmpty(); | ||
426 | _builder.append("\t"); | ||
427 | CharSequence _referInstanceOf_9 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.segmentType, Modality.MAY, "target"); | ||
428 | _builder.append(_referInstanceOf_9, "\t"); | ||
429 | _builder.newLineIfNotEmpty(); | ||
430 | _builder.append("\t"); | ||
431 | _builder.append("T == source;"); | ||
432 | _builder.newLine(); | ||
433 | _builder.append("\t"); | ||
434 | _builder.append("S == target;"); | ||
435 | _builder.newLine(); | ||
436 | _builder.append("}"); | ||
437 | _builder.newLine(); | ||
438 | _builder.newLine(); | ||
439 | _builder.append("pattern output_must_to_true_by_connectedTo("); | ||
440 | _builder.append(parameters); | ||
441 | _builder.append(", S1 : DefinedElement, S2 : DefinedElement) {"); | ||
442 | _builder.newLineIfNotEmpty(); | ||
443 | _builder.append("\t"); | ||
444 | _builder.append(commonMayParameterConstraints, "\t"); | ||
445 | _builder.newLineIfNotEmpty(); | ||
446 | _builder.append("\t"); | ||
447 | CharSequence _referInstanceOf_10 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.segmentType, Modality.MAY, "source"); | ||
448 | _builder.append(_referInstanceOf_10, "\t"); | ||
449 | _builder.newLineIfNotEmpty(); | ||
450 | _builder.append("\t"); | ||
451 | CharSequence _referInstanceOf_11 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.segmentType, Modality.MAY, "target"); | ||
452 | _builder.append(_referInstanceOf_11, "\t"); | ||
453 | _builder.newLineIfNotEmpty(); | ||
454 | _builder.append("\t"); | ||
455 | _builder.append("S1 == source;"); | ||
456 | _builder.newLine(); | ||
457 | _builder.append("\t"); | ||
458 | _builder.append("S2 == target;"); | ||
459 | _builder.newLine(); | ||
460 | _builder.append("}"); | ||
461 | _builder.newLine(); | ||
462 | _builder.newLine(); | ||
463 | _builder.append("pattern output_must_to_true_by_straight("); | ||
464 | _builder.append(parameters); | ||
465 | _builder.append(", S1 : DefinedElement, S2 : DefinedElement) {"); | ||
466 | _builder.newLineIfNotEmpty(); | ||
467 | _builder.append("\t"); | ||
468 | _builder.append("find turnoutOutput_must_to_true_by_straight(problem, interpretation, source, target, S1, S2);"); | ||
469 | _builder.newLine(); | ||
470 | _builder.append("}"); | ||
471 | _builder.newLine(); | ||
472 | _builder.newLine(); | ||
473 | _builder.append("pattern output_must_to_true_by_divergent("); | ||
474 | _builder.append(parameters); | ||
475 | _builder.append(", S1 : DefinedElement, S2 : DefinedElement) {"); | ||
476 | _builder.newLineIfNotEmpty(); | ||
477 | _builder.append("\t"); | ||
478 | _builder.append("find turnoutOutput_must_to_true_by_divergent(problem, interpretation, source, target, S1, S2);"); | ||
479 | _builder.newLine(); | ||
480 | _builder.append("}"); | ||
481 | _builder.newLine(); | ||
482 | _builder.newLine(); | ||
483 | _builder.append("pattern adjacent_must_to_true_by_connectedTo("); | ||
484 | _builder.append(parameters); | ||
485 | _builder.append(", S1 : DefinedElement, S2 : DefinedElement) {"); | ||
486 | _builder.newLineIfNotEmpty(); | ||
487 | _builder.append("\t"); | ||
488 | _builder.append("find output_must_to_true_by_connectedTo(problem, interpretation, source, target, S1, S2);"); | ||
489 | _builder.newLine(); | ||
490 | _builder.append("}"); | ||
491 | _builder.newLine(); | ||
492 | _builder.newLine(); | ||
493 | _builder.append("pattern adjacent_must_to_true_by_straight("); | ||
494 | _builder.append(parameters); | ||
495 | _builder.append(", S1 : DefinedElement, S2 : DefinedElement) {"); | ||
496 | _builder.newLineIfNotEmpty(); | ||
497 | _builder.append("\t"); | ||
498 | _builder.append("find output_must_to_true_by_straight(problem, interpretation, source, target, S1, S2);"); | ||
499 | _builder.newLine(); | ||
500 | _builder.append("} or {"); | ||
501 | _builder.newLine(); | ||
502 | _builder.append("\t"); | ||
503 | _builder.append("find turnoutOutput_must_to_true_by_straight(problem, interpretation, source, target, S2, S1);"); | ||
504 | _builder.newLine(); | ||
505 | _builder.append("}"); | ||
506 | _builder.newLine(); | ||
507 | _builder.newLine(); | ||
508 | _builder.append("pattern adjacent_must_to_true_by_divergent("); | ||
509 | _builder.append(parameters); | ||
510 | _builder.append(", S1 : DefinedElement, S2 : DefinedElement) {"); | ||
511 | _builder.newLineIfNotEmpty(); | ||
512 | _builder.append("\t"); | ||
513 | _builder.append("find output_must_to_true_by_divergent(problem, interpretation, source, target, S1, S2);"); | ||
514 | _builder.newLine(); | ||
515 | _builder.append("} or {"); | ||
516 | _builder.newLine(); | ||
517 | _builder.append("\t"); | ||
518 | _builder.append("find turnoutOutput_must_to_true_by_divergent(problem, interpretation, source, target, S2, S1);"); | ||
519 | _builder.newLine(); | ||
520 | _builder.append("}"); | ||
521 | _builder.newLine(); | ||
522 | _builder.newLine(); | ||
523 | _builder.append("pattern connectedToReflexive_must_to_true_by_connectedTo("); | ||
524 | _builder.append(parameters); | ||
525 | _builder.append(", S : DefinedElement) {"); | ||
526 | _builder.newLineIfNotEmpty(); | ||
527 | _builder.append("\t"); | ||
528 | _builder.append("find mustExist(problem, interpretation, source);"); | ||
529 | _builder.newLine(); | ||
530 | _builder.append("\t"); | ||
531 | CharSequence _referInstanceOf_12 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.segmentType, Modality.MUST, "source"); | ||
532 | _builder.append(_referInstanceOf_12, "\t"); | ||
533 | _builder.newLineIfNotEmpty(); | ||
534 | _builder.append("\t"); | ||
535 | _builder.append("S == source;"); | ||
536 | _builder.newLine(); | ||
537 | _builder.append("\t"); | ||
538 | _builder.append("S == target;"); | ||
539 | _builder.newLine(); | ||
540 | _builder.append("}"); | ||
541 | _builder.newLine(); | ||
542 | _builder.newLine(); | ||
543 | _builder.append("pattern outputReflexive_must_to_true_by_straight("); | ||
544 | _builder.append(parameters); | ||
545 | _builder.append(", T : DefinedElement) {"); | ||
546 | _builder.newLineIfNotEmpty(); | ||
547 | _builder.append("\t"); | ||
548 | _builder.append("find turnoutOutput_must_to_true_by_straight(problem, interpretation, source, target, T, T);"); | ||
549 | _builder.newLine(); | ||
550 | _builder.append("}"); | ||
551 | _builder.newLine(); | ||
552 | _builder.newLine(); | ||
553 | _builder.append("pattern outputReflexive_must_to_true_by_divergent("); | ||
554 | _builder.append(parameters); | ||
555 | _builder.append(", T : DefinedElement) {"); | ||
556 | _builder.newLineIfNotEmpty(); | ||
557 | _builder.append("\t"); | ||
558 | _builder.append("find turnoutOutput_must_to_true_by_divergent(problem, interpretation, source, target, T, T);"); | ||
559 | _builder.newLine(); | ||
560 | _builder.append("}"); | ||
561 | _builder.newLine(); | ||
562 | _builder.newLine(); | ||
563 | _builder.append("pattern turnoutOutputsAreSame_must_to_true_by_straight("); | ||
564 | _builder.append(parameters); | ||
565 | _builder.append(", T : DefinedElement) {"); | ||
566 | _builder.newLineIfNotEmpty(); | ||
567 | _builder.append("\t"); | ||
568 | _builder.append(commonMayParameterConstraints, "\t"); | ||
569 | _builder.newLineIfNotEmpty(); | ||
570 | _builder.append("\t"); | ||
571 | CharSequence _referInstanceOf_13 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.turnoutType, Modality.MAY, "source"); | ||
572 | _builder.append(_referInstanceOf_13, "\t"); | ||
573 | _builder.newLineIfNotEmpty(); | ||
574 | _builder.append("\t"); | ||
575 | CharSequence _referInstanceOf_14 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.segmentType, Modality.MAY, "target"); | ||
576 | _builder.append(_referInstanceOf_14, "\t"); | ||
577 | _builder.newLineIfNotEmpty(); | ||
578 | _builder.append("\t"); | ||
579 | _builder.append("T == source;"); | ||
580 | _builder.newLine(); | ||
581 | _builder.append("\t"); | ||
582 | _builder.append("S == target;"); | ||
583 | _builder.newLine(); | ||
584 | _builder.append("\t"); | ||
585 | CharSequence _referRelation_24 = generator.referRelation(Modes3UnitPropagationGenerator.this.divergentRelation, "T", "S", Modality.MUST, fqnToPQuery); | ||
586 | _builder.append(_referRelation_24, "\t"); | ||
587 | _builder.newLineIfNotEmpty(); | ||
588 | _builder.append("}"); | ||
589 | _builder.newLine(); | ||
590 | _builder.newLine(); | ||
591 | _builder.append("pattern turnoutOutputsAreSame_must_to_true_by_divergent("); | ||
592 | _builder.append(parameters); | ||
593 | _builder.append(", T : DefinedElement) {"); | ||
594 | _builder.newLineIfNotEmpty(); | ||
595 | _builder.append("\t"); | ||
596 | _builder.append(commonMayParameterConstraints, "\t"); | ||
597 | _builder.newLineIfNotEmpty(); | ||
598 | _builder.append("\t"); | ||
599 | CharSequence _referInstanceOf_15 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.turnoutType, Modality.MAY, "source"); | ||
600 | _builder.append(_referInstanceOf_15, "\t"); | ||
601 | _builder.newLineIfNotEmpty(); | ||
602 | _builder.append("\t"); | ||
603 | CharSequence _referInstanceOf_16 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.segmentType, Modality.MAY, "target"); | ||
604 | _builder.append(_referInstanceOf_16, "\t"); | ||
605 | _builder.newLineIfNotEmpty(); | ||
606 | _builder.append("\t"); | ||
607 | _builder.append("T == source;"); | ||
608 | _builder.newLine(); | ||
609 | _builder.append("\t"); | ||
610 | _builder.append("S == target;"); | ||
611 | _builder.newLine(); | ||
612 | _builder.append("\t"); | ||
613 | CharSequence _referRelation_25 = generator.referRelation(Modes3UnitPropagationGenerator.this.straightRelation, "T", "S", Modality.MUST, fqnToPQuery); | ||
614 | _builder.append(_referRelation_25, "\t"); | ||
615 | _builder.newLineIfNotEmpty(); | ||
616 | _builder.append("}"); | ||
617 | _builder.newLine(); | ||
618 | _builder.newLine(); | ||
619 | _builder.append("pattern tooManyInputsOfSegment_must_to_true_by_connectedTo("); | ||
620 | _builder.append(parameters); | ||
621 | _builder.append(", S : DefinedElement) {"); | ||
622 | _builder.newLineIfNotEmpty(); | ||
623 | _builder.append("\t"); | ||
624 | _builder.append("find mustExist(problem, interpretation, S);"); | ||
625 | _builder.newLine(); | ||
626 | _builder.append("\t"); | ||
627 | CharSequence _referInstanceOf_17 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.simpleSegmentType, Modality.MUST, "S"); | ||
628 | _builder.append(_referInstanceOf_17, "\t"); | ||
629 | _builder.newLineIfNotEmpty(); | ||
630 | _builder.append("\t"); | ||
631 | _builder.append("find output_must_to_true_by_connectedTo(problem, interpretation, source, target, I1, S);"); | ||
632 | _builder.newLine(); | ||
633 | _builder.append("\t"); | ||
634 | CharSequence _referPattern_1 = generator.getRelationDefinitionIndexer().referPattern(fqnToPQuery.get(Output.instance().getFullyQualifiedName()), new String[] { "I2", "S" }, Modality.MUST, true, false); | ||
635 | _builder.append(_referPattern_1, "\t"); | ||
636 | _builder.newLineIfNotEmpty(); | ||
637 | _builder.append("\t"); | ||
638 | CharSequence _referPattern_2 = generator.getRelationDefinitionIndexer().referPattern(fqnToPQuery.get(Output.instance().getFullyQualifiedName()), new String[] { "I3", "S" }, Modality.MUST, true, false); | ||
639 | _builder.append(_referPattern_2, "\t"); | ||
640 | _builder.newLineIfNotEmpty(); | ||
641 | _builder.append("\t"); | ||
642 | _builder.append("I1 != I2;"); | ||
643 | _builder.newLine(); | ||
644 | _builder.append("\t"); | ||
645 | _builder.append("I1 != I3;"); | ||
646 | _builder.newLine(); | ||
647 | _builder.append("\t"); | ||
648 | _builder.append("I2 != I3;"); | ||
649 | _builder.newLine(); | ||
650 | _builder.append("}"); | ||
651 | _builder.newLine(); | ||
652 | _builder.newLine(); | ||
653 | _builder.append("pattern tooManyInputsOfSegment_must_to_true_by_straight("); | ||
654 | _builder.append(parameters); | ||
655 | _builder.append(", S : DefinedElement) {"); | ||
656 | _builder.newLineIfNotEmpty(); | ||
657 | _builder.append("\t"); | ||
658 | _builder.append("find mustExist(problem, interpretation, S);"); | ||
659 | _builder.newLine(); | ||
660 | _builder.append("\t"); | ||
661 | CharSequence _referInstanceOf_18 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.simpleSegmentType, Modality.MUST, "S"); | ||
662 | _builder.append(_referInstanceOf_18, "\t"); | ||
663 | _builder.newLineIfNotEmpty(); | ||
664 | _builder.append("\t"); | ||
665 | _builder.append("find output_must_to_true_by_straight(problem, interpretation, source, target, I1, S);"); | ||
666 | _builder.newLine(); | ||
667 | _builder.append("\t"); | ||
668 | CharSequence _referPattern_3 = generator.getRelationDefinitionIndexer().referPattern(fqnToPQuery.get(Output.instance().getFullyQualifiedName()), new String[] { "I2", "S" }, Modality.MUST, true, false); | ||
669 | _builder.append(_referPattern_3, "\t"); | ||
670 | _builder.newLineIfNotEmpty(); | ||
671 | _builder.append("\t"); | ||
672 | CharSequence _referPattern_4 = generator.getRelationDefinitionIndexer().referPattern(fqnToPQuery.get(Output.instance().getFullyQualifiedName()), new String[] { "I3", "S" }, Modality.MUST, true, false); | ||
673 | _builder.append(_referPattern_4, "\t"); | ||
674 | _builder.newLineIfNotEmpty(); | ||
675 | _builder.append("\t"); | ||
676 | _builder.append("I1 != I2;"); | ||
677 | _builder.newLine(); | ||
678 | _builder.append("\t"); | ||
679 | _builder.append("I1 != I3;"); | ||
680 | _builder.newLine(); | ||
681 | _builder.append("\t"); | ||
682 | _builder.append("I2 != I3;"); | ||
683 | _builder.newLine(); | ||
684 | _builder.append("}"); | ||
685 | _builder.newLine(); | ||
686 | _builder.newLine(); | ||
687 | _builder.append("pattern tooManyInputsOfSegment_must_to_true_by_divergent("); | ||
688 | _builder.append(parameters); | ||
689 | _builder.append(", S : DefinedElement) {"); | ||
690 | _builder.newLineIfNotEmpty(); | ||
691 | _builder.append("\t"); | ||
692 | _builder.append("find mustExist(problem, interpretation, S);"); | ||
693 | _builder.newLine(); | ||
694 | _builder.append("\t"); | ||
695 | CharSequence _referInstanceOf_19 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.simpleSegmentType, Modality.MUST, "S"); | ||
696 | _builder.append(_referInstanceOf_19, "\t"); | ||
697 | _builder.newLineIfNotEmpty(); | ||
698 | _builder.append("\t"); | ||
699 | _builder.append("find output_must_to_true_by_divergent(problem, interpretation, source, target, I1, S);"); | ||
700 | _builder.newLine(); | ||
701 | _builder.append("\t"); | ||
702 | CharSequence _referPattern_5 = generator.getRelationDefinitionIndexer().referPattern(fqnToPQuery.get(Output.instance().getFullyQualifiedName()), new String[] { "I2", "S" }, Modality.MUST, true, false); | ||
703 | _builder.append(_referPattern_5, "\t"); | ||
704 | _builder.newLineIfNotEmpty(); | ||
705 | _builder.append("\t"); | ||
706 | CharSequence _referPattern_6 = generator.getRelationDefinitionIndexer().referPattern(fqnToPQuery.get(Output.instance().getFullyQualifiedName()), new String[] { "I3", "S" }, Modality.MUST, true, false); | ||
707 | _builder.append(_referPattern_6, "\t"); | ||
708 | _builder.newLineIfNotEmpty(); | ||
709 | _builder.append("\t"); | ||
710 | _builder.append("I1 != I2;"); | ||
711 | _builder.newLine(); | ||
712 | _builder.append("\t"); | ||
713 | _builder.append("I1 != I3;"); | ||
714 | _builder.newLine(); | ||
715 | _builder.append("\t"); | ||
716 | _builder.append("I2 != I3;"); | ||
717 | _builder.newLine(); | ||
718 | _builder.append("}"); | ||
719 | _builder.newLine(); | ||
720 | _builder.newLine(); | ||
721 | _builder.append("pattern turnoutConnectedToBothOutputs_must_to_true_by_connectedTo("); | ||
722 | _builder.append(parameters); | ||
723 | _builder.append(", T : DefinedElement) {"); | ||
724 | _builder.newLineIfNotEmpty(); | ||
725 | _builder.append("\t"); | ||
726 | _builder.append(commonMayParameterConstraints, "\t"); | ||
727 | _builder.newLineIfNotEmpty(); | ||
728 | _builder.append("\t"); | ||
729 | _builder.append("find mustExist(problem, interpretation, Straight);"); | ||
730 | _builder.newLine(); | ||
731 | _builder.append("\t"); | ||
732 | _builder.append("find mustExist(problem, interpretation, Divergent);"); | ||
733 | _builder.newLine(); | ||
734 | _builder.append("\t"); | ||
735 | CharSequence _referInstanceOf_20 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.turnoutType, Modality.MAY, "source"); | ||
736 | _builder.append(_referInstanceOf_20, "\t"); | ||
737 | _builder.newLineIfNotEmpty(); | ||
738 | _builder.append("\t"); | ||
739 | CharSequence _referInstanceOf_21 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.segmentType, Modality.MAY, "target"); | ||
740 | _builder.append(_referInstanceOf_21, "\t"); | ||
741 | _builder.newLineIfNotEmpty(); | ||
742 | _builder.append("\t"); | ||
743 | CharSequence _referInstanceOf_22 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.segmentType, Modality.MUST, "Straight"); | ||
744 | _builder.append(_referInstanceOf_22, "\t"); | ||
745 | _builder.newLineIfNotEmpty(); | ||
746 | _builder.append("\t"); | ||
747 | CharSequence _referInstanceOf_23 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.segmentType, Modality.MUST, "Divergent"); | ||
748 | _builder.append(_referInstanceOf_23, "\t"); | ||
749 | _builder.newLineIfNotEmpty(); | ||
750 | _builder.append("\t"); | ||
751 | CharSequence _referRelation_26 = generator.referRelation(Modes3UnitPropagationGenerator.this.straightRelation, "T", "Straight", Modality.MUST, fqnToPQuery); | ||
752 | _builder.append(_referRelation_26, "\t"); | ||
753 | _builder.newLineIfNotEmpty(); | ||
754 | _builder.append("\t"); | ||
755 | CharSequence _referRelation_27 = generator.referRelation(Modes3UnitPropagationGenerator.this.divergentRelation, "T", "Divergent", Modality.MUST, fqnToPQuery); | ||
756 | _builder.append(_referRelation_27, "\t"); | ||
757 | _builder.newLineIfNotEmpty(); | ||
758 | _builder.append("\t"); | ||
759 | _builder.append("T == source;"); | ||
760 | _builder.newLine(); | ||
761 | _builder.append("\t"); | ||
762 | _builder.append("Straight == target;"); | ||
763 | _builder.newLine(); | ||
764 | _builder.append("\t"); | ||
765 | CharSequence _referRelation_28 = generator.referRelation(Modes3UnitPropagationGenerator.this.connectedToRelation, "T", "Divergent", Modality.MUST, fqnToPQuery); | ||
766 | _builder.append(_referRelation_28, "\t"); | ||
767 | _builder.newLineIfNotEmpty(); | ||
768 | _builder.append("} or {"); | ||
769 | _builder.newLine(); | ||
770 | _builder.append("\t"); | ||
771 | _builder.append(commonMayParameterConstraints, "\t"); | ||
772 | _builder.newLineIfNotEmpty(); | ||
773 | _builder.append("\t"); | ||
774 | _builder.append("find mustExist(problem, interpretation, Straight);"); | ||
775 | _builder.newLine(); | ||
776 | _builder.append("\t"); | ||
777 | _builder.append("find mustExist(problem, interpretation, Divergent);"); | ||
778 | _builder.newLine(); | ||
779 | _builder.append("\t"); | ||
780 | CharSequence _referInstanceOf_24 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.turnoutType, Modality.MAY, "source"); | ||
781 | _builder.append(_referInstanceOf_24, "\t"); | ||
782 | _builder.newLineIfNotEmpty(); | ||
783 | _builder.append("\t"); | ||
784 | CharSequence _referInstanceOf_25 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.segmentType, Modality.MAY, "target"); | ||
785 | _builder.append(_referInstanceOf_25, "\t"); | ||
786 | _builder.newLineIfNotEmpty(); | ||
787 | _builder.append("\t"); | ||
788 | CharSequence _referInstanceOf_26 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.segmentType, Modality.MUST, "Straight"); | ||
789 | _builder.append(_referInstanceOf_26, "\t"); | ||
790 | _builder.newLineIfNotEmpty(); | ||
791 | _builder.append("\t"); | ||
792 | CharSequence _referInstanceOf_27 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.segmentType, Modality.MUST, "Divergent"); | ||
793 | _builder.append(_referInstanceOf_27, "\t"); | ||
794 | _builder.newLineIfNotEmpty(); | ||
795 | _builder.append("\t"); | ||
796 | CharSequence _referRelation_29 = generator.referRelation(Modes3UnitPropagationGenerator.this.straightRelation, "T", "Straight", Modality.MUST, fqnToPQuery); | ||
797 | _builder.append(_referRelation_29, "\t"); | ||
798 | _builder.newLineIfNotEmpty(); | ||
799 | _builder.append("\t"); | ||
800 | CharSequence _referRelation_30 = generator.referRelation(Modes3UnitPropagationGenerator.this.divergentRelation, "T", "Divergent", Modality.MUST, fqnToPQuery); | ||
801 | _builder.append(_referRelation_30, "\t"); | ||
802 | _builder.newLineIfNotEmpty(); | ||
803 | _builder.append("\t"); | ||
804 | CharSequence _referRelation_31 = generator.referRelation(Modes3UnitPropagationGenerator.this.connectedToRelation, "T", "Straight", Modality.MUST, fqnToPQuery); | ||
805 | _builder.append(_referRelation_31, "\t"); | ||
806 | _builder.newLineIfNotEmpty(); | ||
807 | _builder.append("\t"); | ||
808 | _builder.append("T == source;"); | ||
809 | _builder.newLine(); | ||
810 | _builder.append("\t"); | ||
811 | _builder.append("Straight == target;"); | ||
812 | _builder.newLine(); | ||
813 | _builder.append("}"); | ||
814 | _builder.newLine(); | ||
815 | _builder.newLine(); | ||
816 | _builder.append("pattern turnoutConnectedToBothOutputs_must_to_true_by_straight("); | ||
817 | _builder.append(parameters); | ||
818 | _builder.append(", T : DefinedElement) {"); | ||
819 | _builder.newLineIfNotEmpty(); | ||
820 | _builder.append("\t"); | ||
821 | _builder.append(commonMayParameterConstraints, "\t"); | ||
822 | _builder.newLineIfNotEmpty(); | ||
823 | _builder.append("\t"); | ||
824 | _builder.append("find mustExist(problem, interpretation, Straight);"); | ||
825 | _builder.newLine(); | ||
826 | _builder.append("\t"); | ||
827 | _builder.append("find mustExist(problem, interpretation, Divergent);"); | ||
828 | _builder.newLine(); | ||
829 | _builder.append("\t"); | ||
830 | CharSequence _referInstanceOf_28 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.turnoutType, Modality.MAY, "source"); | ||
831 | _builder.append(_referInstanceOf_28, "\t"); | ||
832 | _builder.newLineIfNotEmpty(); | ||
833 | _builder.append("\t"); | ||
834 | CharSequence _referInstanceOf_29 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.segmentType, Modality.MAY, "target"); | ||
835 | _builder.append(_referInstanceOf_29, "\t"); | ||
836 | _builder.newLineIfNotEmpty(); | ||
837 | _builder.append("\t"); | ||
838 | CharSequence _referInstanceOf_30 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.segmentType, Modality.MUST, "Straight"); | ||
839 | _builder.append(_referInstanceOf_30, "\t"); | ||
840 | _builder.newLineIfNotEmpty(); | ||
841 | _builder.append("\t"); | ||
842 | CharSequence _referInstanceOf_31 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.segmentType, Modality.MUST, "Divergent"); | ||
843 | _builder.append(_referInstanceOf_31, "\t"); | ||
844 | _builder.newLineIfNotEmpty(); | ||
845 | _builder.append("\t"); | ||
846 | _builder.append("T == source;"); | ||
847 | _builder.newLine(); | ||
848 | _builder.append("\t"); | ||
849 | _builder.append("Straight == target;"); | ||
850 | _builder.newLine(); | ||
851 | _builder.append("\t"); | ||
852 | CharSequence _referRelation_32 = generator.referRelation(Modes3UnitPropagationGenerator.this.divergentRelation, "T", "Divergent", Modality.MUST, fqnToPQuery); | ||
853 | _builder.append(_referRelation_32, "\t"); | ||
854 | _builder.newLineIfNotEmpty(); | ||
855 | _builder.append("\t"); | ||
856 | CharSequence _referRelation_33 = generator.referRelation(Modes3UnitPropagationGenerator.this.connectedToRelation, "T", "Straight", Modality.MUST, fqnToPQuery); | ||
857 | _builder.append(_referRelation_33, "\t"); | ||
858 | _builder.newLineIfNotEmpty(); | ||
859 | _builder.append("\t"); | ||
860 | CharSequence _referRelation_34 = generator.referRelation(Modes3UnitPropagationGenerator.this.connectedToRelation, "T", "Divergent", Modality.MUST, fqnToPQuery); | ||
861 | _builder.append(_referRelation_34, "\t"); | ||
862 | _builder.newLineIfNotEmpty(); | ||
863 | _builder.append("}"); | ||
864 | _builder.newLine(); | ||
865 | _builder.newLine(); | ||
866 | _builder.append("pattern turnoutConnectedToBothOutputs_must_to_true_by_divergent("); | ||
867 | _builder.append(parameters); | ||
868 | _builder.append(", T : DefinedElement) {"); | ||
869 | _builder.newLineIfNotEmpty(); | ||
870 | _builder.append("\t"); | ||
871 | _builder.append(commonMayParameterConstraints, "\t"); | ||
872 | _builder.newLineIfNotEmpty(); | ||
873 | _builder.append("\t"); | ||
874 | _builder.append("find mustExist(problem, interpretation, Straight);"); | ||
875 | _builder.newLine(); | ||
876 | _builder.append("\t"); | ||
877 | _builder.append("find mustExist(problem, interpretation, Divergent);"); | ||
878 | _builder.newLine(); | ||
879 | _builder.append("\t"); | ||
880 | CharSequence _referInstanceOf_32 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.turnoutType, Modality.MAY, "source"); | ||
881 | _builder.append(_referInstanceOf_32, "\t"); | ||
882 | _builder.newLineIfNotEmpty(); | ||
883 | _builder.append("\t"); | ||
884 | CharSequence _referInstanceOf_33 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.segmentType, Modality.MAY, "target"); | ||
885 | _builder.append(_referInstanceOf_33, "\t"); | ||
886 | _builder.newLineIfNotEmpty(); | ||
887 | _builder.append("\t"); | ||
888 | CharSequence _referInstanceOf_34 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.segmentType, Modality.MUST, "Straight"); | ||
889 | _builder.append(_referInstanceOf_34, "\t"); | ||
890 | _builder.newLineIfNotEmpty(); | ||
891 | _builder.append("\t"); | ||
892 | CharSequence _referInstanceOf_35 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.segmentType, Modality.MUST, "Divergent"); | ||
893 | _builder.append(_referInstanceOf_35, "\t"); | ||
894 | _builder.newLineIfNotEmpty(); | ||
895 | _builder.append("\t"); | ||
896 | CharSequence _referRelation_35 = generator.referRelation(Modes3UnitPropagationGenerator.this.straightRelation, "T", "Straight", Modality.MUST, fqnToPQuery); | ||
897 | _builder.append(_referRelation_35, "\t"); | ||
898 | _builder.newLineIfNotEmpty(); | ||
899 | _builder.append("\t"); | ||
900 | _builder.append("T == source;"); | ||
901 | _builder.newLine(); | ||
902 | _builder.append("\t"); | ||
903 | _builder.append("Divergent == target;"); | ||
904 | _builder.newLine(); | ||
905 | _builder.append("\t"); | ||
906 | CharSequence _referRelation_36 = generator.referRelation(Modes3UnitPropagationGenerator.this.connectedToRelation, "T", "Straight", Modality.MUST, fqnToPQuery); | ||
907 | _builder.append(_referRelation_36, "\t"); | ||
908 | _builder.newLineIfNotEmpty(); | ||
909 | _builder.append("\t"); | ||
910 | CharSequence _referRelation_37 = generator.referRelation(Modes3UnitPropagationGenerator.this.connectedToRelation, "T", "Divergent", Modality.MUST, fqnToPQuery); | ||
911 | _builder.append(_referRelation_37, "\t"); | ||
912 | _builder.newLineIfNotEmpty(); | ||
913 | _builder.append("}"); | ||
914 | _builder.newLine(); | ||
915 | _builder.newLine(); | ||
916 | _builder.append("pattern tooManyInputsOfTurnout_must_to_true_by_connectedTo("); | ||
917 | _builder.append(parameters); | ||
918 | _builder.append(", T : DefinedElement) {"); | ||
919 | _builder.newLineIfNotEmpty(); | ||
920 | _builder.append("\t"); | ||
921 | _builder.append("find mustExist(problem, interpretation, S);"); | ||
922 | _builder.newLine(); | ||
923 | _builder.append("\t"); | ||
924 | CharSequence _referInstanceOf_36 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.turnoutType, Modality.MUST, "S"); | ||
925 | _builder.append(_referInstanceOf_36, "\t"); | ||
926 | _builder.newLineIfNotEmpty(); | ||
927 | _builder.append("\t"); | ||
928 | _builder.append("find adjacent_must_to_true_by_connectedTo(problem, interpretation, source, target, I1, S);"); | ||
929 | _builder.newLine(); | ||
930 | _builder.append("\t"); | ||
931 | CharSequence _referPattern_7 = generator.getRelationDefinitionIndexer().referPattern(fqnToPQuery.get(Adjacent.instance().getFullyQualifiedName()), new String[] { "I2", "S" }, Modality.MUST, true, false); | ||
932 | _builder.append(_referPattern_7, "\t"); | ||
933 | _builder.newLineIfNotEmpty(); | ||
934 | _builder.append("\t"); | ||
935 | CharSequence _referPattern_8 = generator.getRelationDefinitionIndexer().referPattern(fqnToPQuery.get(Adjacent.instance().getFullyQualifiedName()), new String[] { "I3", "S" }, Modality.MUST, true, false); | ||
936 | _builder.append(_referPattern_8, "\t"); | ||
937 | _builder.newLineIfNotEmpty(); | ||
938 | _builder.append("\t"); | ||
939 | CharSequence _referPattern_9 = generator.getRelationDefinitionIndexer().referPattern(fqnToPQuery.get(Adjacent.instance().getFullyQualifiedName()), new String[] { "I4", "S" }, Modality.MUST, true, false); | ||
940 | _builder.append(_referPattern_9, "\t"); | ||
941 | _builder.newLineIfNotEmpty(); | ||
942 | _builder.append("\t"); | ||
943 | _builder.append("I1 != I2;"); | ||
944 | _builder.newLine(); | ||
945 | _builder.append("\t"); | ||
946 | _builder.append("I1 != I3;"); | ||
947 | _builder.newLine(); | ||
948 | _builder.append("\t"); | ||
949 | _builder.append("I1 != I4;"); | ||
950 | _builder.newLine(); | ||
951 | _builder.append("\t"); | ||
952 | _builder.append("I2 != I3;"); | ||
953 | _builder.newLine(); | ||
954 | _builder.append("\t"); | ||
955 | _builder.append("I2 != I4;"); | ||
956 | _builder.newLine(); | ||
957 | _builder.append("\t"); | ||
958 | _builder.append("I3 != I4;"); | ||
959 | _builder.newLine(); | ||
960 | _builder.append("}"); | ||
961 | _builder.newLine(); | ||
962 | _builder.newLine(); | ||
963 | _builder.append("pattern tooManyInputsOfTurnout_must_to_true_by_straight("); | ||
964 | _builder.append(parameters); | ||
965 | _builder.append(", T : DefinedElement) {"); | ||
966 | _builder.newLineIfNotEmpty(); | ||
967 | _builder.append("\t"); | ||
968 | _builder.append("find mustExist(problem, interpretation, S);"); | ||
969 | _builder.newLine(); | ||
970 | _builder.append("\t"); | ||
971 | CharSequence _referInstanceOf_37 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.turnoutType, Modality.MUST, "S"); | ||
972 | _builder.append(_referInstanceOf_37, "\t"); | ||
973 | _builder.newLineIfNotEmpty(); | ||
974 | _builder.append("\t"); | ||
975 | _builder.append("find adjacent_must_to_true_by_straight(problem, interpretation, source, target, I1, S);"); | ||
976 | _builder.newLine(); | ||
977 | _builder.append("\t"); | ||
978 | CharSequence _referPattern_10 = generator.getRelationDefinitionIndexer().referPattern(fqnToPQuery.get(Adjacent.instance().getFullyQualifiedName()), new String[] { "I2", "S" }, Modality.MUST, true, false); | ||
979 | _builder.append(_referPattern_10, "\t"); | ||
980 | _builder.newLineIfNotEmpty(); | ||
981 | _builder.append("\t"); | ||
982 | CharSequence _referPattern_11 = generator.getRelationDefinitionIndexer().referPattern(fqnToPQuery.get(Adjacent.instance().getFullyQualifiedName()), new String[] { "I3", "S" }, Modality.MUST, true, false); | ||
983 | _builder.append(_referPattern_11, "\t"); | ||
984 | _builder.newLineIfNotEmpty(); | ||
985 | _builder.append("\t"); | ||
986 | CharSequence _referPattern_12 = generator.getRelationDefinitionIndexer().referPattern(fqnToPQuery.get(Adjacent.instance().getFullyQualifiedName()), new String[] { "I4", "S" }, Modality.MUST, true, false); | ||
987 | _builder.append(_referPattern_12, "\t"); | ||
988 | _builder.newLineIfNotEmpty(); | ||
989 | _builder.append("\t"); | ||
990 | _builder.append("I1 != I2;"); | ||
991 | _builder.newLine(); | ||
992 | _builder.append("\t"); | ||
993 | _builder.append("I1 != I3;"); | ||
994 | _builder.newLine(); | ||
995 | _builder.append("\t"); | ||
996 | _builder.append("I1 != I4;"); | ||
997 | _builder.newLine(); | ||
998 | _builder.append("\t"); | ||
999 | _builder.append("I2 != I3;"); | ||
1000 | _builder.newLine(); | ||
1001 | _builder.append("\t"); | ||
1002 | _builder.append("I2 != I4;"); | ||
1003 | _builder.newLine(); | ||
1004 | _builder.append("\t"); | ||
1005 | _builder.append("I3 != I4;"); | ||
1006 | _builder.newLine(); | ||
1007 | _builder.append("}"); | ||
1008 | _builder.newLine(); | ||
1009 | _builder.newLine(); | ||
1010 | _builder.append("pattern tooManyInputsOfTurnout_must_to_true_by_divergent("); | ||
1011 | _builder.append(parameters); | ||
1012 | _builder.append(", T : DefinedElement) {"); | ||
1013 | _builder.newLineIfNotEmpty(); | ||
1014 | _builder.append("\t"); | ||
1015 | _builder.append("find mustExist(problem, interpretation, S);"); | ||
1016 | _builder.newLine(); | ||
1017 | _builder.append("\t"); | ||
1018 | CharSequence _referInstanceOf_38 = generator.getTypeIndexer().referInstanceOf(Modes3UnitPropagationGenerator.this.turnoutType, Modality.MUST, "S"); | ||
1019 | _builder.append(_referInstanceOf_38, "\t"); | ||
1020 | _builder.newLineIfNotEmpty(); | ||
1021 | _builder.append("\t"); | ||
1022 | _builder.append("find adjacent_must_to_true_by_divergent(problem, interpretation, source, target, I1, S);"); | ||
1023 | _builder.newLine(); | ||
1024 | _builder.append("\t"); | ||
1025 | CharSequence _referPattern_13 = generator.getRelationDefinitionIndexer().referPattern(fqnToPQuery.get(Adjacent.instance().getFullyQualifiedName()), new String[] { "I2", "S" }, Modality.MUST, true, false); | ||
1026 | _builder.append(_referPattern_13, "\t"); | ||
1027 | _builder.newLineIfNotEmpty(); | ||
1028 | _builder.append("\t"); | ||
1029 | CharSequence _referPattern_14 = generator.getRelationDefinitionIndexer().referPattern(fqnToPQuery.get(Adjacent.instance().getFullyQualifiedName()), new String[] { "I3", "S" }, Modality.MUST, true, false); | ||
1030 | _builder.append(_referPattern_14, "\t"); | ||
1031 | _builder.newLineIfNotEmpty(); | ||
1032 | _builder.append("\t"); | ||
1033 | CharSequence _referPattern_15 = generator.getRelationDefinitionIndexer().referPattern(fqnToPQuery.get(Adjacent.instance().getFullyQualifiedName()), new String[] { "I4", "S" }, Modality.MUST, true, false); | ||
1034 | _builder.append(_referPattern_15, "\t"); | ||
1035 | _builder.newLineIfNotEmpty(); | ||
1036 | _builder.append("\t"); | ||
1037 | _builder.append("I1 != I2;"); | ||
1038 | _builder.newLine(); | ||
1039 | _builder.append("\t"); | ||
1040 | _builder.append("I1 != I3;"); | ||
1041 | _builder.newLine(); | ||
1042 | _builder.append("\t"); | ||
1043 | _builder.append("I1 != I4;"); | ||
1044 | _builder.newLine(); | ||
1045 | _builder.append("\t"); | ||
1046 | _builder.append("I2 != I3;"); | ||
1047 | _builder.newLine(); | ||
1048 | _builder.append("\t"); | ||
1049 | _builder.append("I2 != I4;"); | ||
1050 | _builder.newLine(); | ||
1051 | _builder.append("\t"); | ||
1052 | _builder.append("I3 != I4;"); | ||
1053 | _builder.newLine(); | ||
1054 | _builder.append("}"); | ||
1055 | _builder.newLine(); | ||
1056 | _builder.newLine(); | ||
1057 | _builder.append("pattern "); | ||
1058 | _builder.append(Modes3UnitPropagationGenerator.MUST_NOT_CONNECTED_TO); | ||
1059 | _builder.append("_helper("); | ||
1060 | _builder.append(parameters); | ||
1061 | _builder.append(") {"); | ||
1062 | _builder.newLineIfNotEmpty(); | ||
1063 | _builder.append("\t"); | ||
1064 | _builder.append("find connectedToReflexive_must_to_true_by_connectedTo(problem, interpretation, source, target, _);"); | ||
1065 | _builder.newLine(); | ||
1066 | _builder.append("} or {"); | ||
1067 | _builder.newLine(); | ||
1068 | _builder.append("\t"); | ||
1069 | _builder.append("find tooManyInputsOfSegment_must_to_true_by_connectedTo(problem, interpretation, source, target, _);"); | ||
1070 | _builder.newLine(); | ||
1071 | _builder.append("} or {"); | ||
1072 | _builder.newLine(); | ||
1073 | _builder.append("\t"); | ||
1074 | _builder.append("find turnoutConnectedToBothOutputs_must_to_true_by_connectedTo(problem, interpretation, source, target, _);"); | ||
1075 | _builder.newLine(); | ||
1076 | _builder.append("} or {"); | ||
1077 | _builder.newLine(); | ||
1078 | _builder.append("\t"); | ||
1079 | _builder.append("find tooManyInputsOfTurnout_must_to_true_by_connectedTo(problem, interpretation, source, target, _);"); | ||
1080 | _builder.newLine(); | ||
1081 | _builder.append("}"); | ||
1082 | _builder.newLine(); | ||
1083 | _builder.newLine(); | ||
1084 | _builder.append("pattern "); | ||
1085 | _builder.append(Modes3UnitPropagationGenerator.MUST_NOT_CONNECTED_TO); | ||
1086 | _builder.append("("); | ||
1087 | _builder.append(parameters); | ||
1088 | _builder.append(") {"); | ||
1089 | _builder.newLineIfNotEmpty(); | ||
1090 | _builder.append("\t"); | ||
1091 | _builder.append("find "); | ||
1092 | _builder.append(Modes3UnitPropagationGenerator.MUST_NOT_CONNECTED_TO, "\t"); | ||
1093 | _builder.append("_helper(problem, interpretation, source, target);"); | ||
1094 | _builder.newLineIfNotEmpty(); | ||
1095 | _builder.append("} or {"); | ||
1096 | _builder.newLine(); | ||
1097 | _builder.append("\t"); | ||
1098 | _builder.append("find "); | ||
1099 | _builder.append(Modes3UnitPropagationGenerator.MUST_NOT_CONNECTED_TO, "\t"); | ||
1100 | _builder.append("_helper(problem, interpretation, target, source);"); | ||
1101 | _builder.newLineIfNotEmpty(); | ||
1102 | _builder.append("}"); | ||
1103 | _builder.newLine(); | ||
1104 | _builder.newLine(); | ||
1105 | _builder.append("pattern "); | ||
1106 | _builder.append(Modes3UnitPropagationGenerator.MUST_NOT_STRAIGHT); | ||
1107 | _builder.append("("); | ||
1108 | _builder.append(parameters); | ||
1109 | _builder.append(") {"); | ||
1110 | _builder.newLineIfNotEmpty(); | ||
1111 | _builder.append("\t"); | ||
1112 | _builder.append("find outputReflexive_must_to_true_by_straight(problem, interpretation, source, target, _);"); | ||
1113 | _builder.newLine(); | ||
1114 | _builder.append("} or {"); | ||
1115 | _builder.newLine(); | ||
1116 | _builder.append("\t"); | ||
1117 | _builder.append("find turnoutOutputsAreSame_must_to_true_by_straight(problem, interpretation, source, target, _);"); | ||
1118 | _builder.newLine(); | ||
1119 | _builder.append("} or {"); | ||
1120 | _builder.newLine(); | ||
1121 | _builder.append("\t"); | ||
1122 | _builder.append("find tooManyInputsOfSegment_must_to_true_by_straight(problem, interpretation, source, target, _);"); | ||
1123 | _builder.newLine(); | ||
1124 | _builder.append("} or {"); | ||
1125 | _builder.newLine(); | ||
1126 | _builder.append("\t"); | ||
1127 | _builder.append("find turnoutConnectedToBothOutputs_must_to_true_by_straight(problem, interpretation, source, target, _);"); | ||
1128 | _builder.newLine(); | ||
1129 | _builder.append("} or {"); | ||
1130 | _builder.newLine(); | ||
1131 | _builder.append("\t"); | ||
1132 | _builder.append("find tooManyInputsOfTurnout_must_to_true_by_straight(problem, interpretation, source, target, _);"); | ||
1133 | _builder.newLine(); | ||
1134 | _builder.append("}"); | ||
1135 | _builder.newLine(); | ||
1136 | _builder.newLine(); | ||
1137 | _builder.append("pattern "); | ||
1138 | _builder.append(Modes3UnitPropagationGenerator.MUST_NOT_DIVERGENT); | ||
1139 | _builder.append("("); | ||
1140 | _builder.append(parameters); | ||
1141 | _builder.append(") {"); | ||
1142 | _builder.newLineIfNotEmpty(); | ||
1143 | _builder.append("\t"); | ||
1144 | _builder.append("find outputReflexive_must_to_true_by_divergent(problem, interpretation, source, target, _);"); | ||
1145 | _builder.newLine(); | ||
1146 | _builder.append("} or {"); | ||
1147 | _builder.newLine(); | ||
1148 | _builder.append("\t"); | ||
1149 | _builder.append("find turnoutOutputsAreSame_must_to_true_by_divergent(problem, interpretation, source, target, _);"); | ||
1150 | _builder.newLine(); | ||
1151 | _builder.append("} or {"); | ||
1152 | _builder.newLine(); | ||
1153 | _builder.append("\t"); | ||
1154 | _builder.append("find tooManyInputsOfSegment_must_to_true_by_divergent(problem, interpretation, source, target, _);"); | ||
1155 | _builder.newLine(); | ||
1156 | _builder.append("} or {"); | ||
1157 | _builder.newLine(); | ||
1158 | _builder.append("\t"); | ||
1159 | _builder.append("find turnoutConnectedToBothOutputs_must_to_true_by_divergent(problem, interpretation, source, target, _);"); | ||
1160 | _builder.newLine(); | ||
1161 | _builder.append("} or {"); | ||
1162 | _builder.newLine(); | ||
1163 | _builder.append("\t"); | ||
1164 | _builder.append("find tooManyInputsOfTurnout_must_to_true_by_divergent(problem, interpretation, source, target, _);"); | ||
1165 | _builder.newLine(); | ||
1166 | _builder.append("}"); | ||
1167 | _builder.newLine(); | ||
1168 | } | ||
1169 | }; | ||
1170 | _xblockexpression = _client_3; | ||
1171 | } | ||
1172 | return _xblockexpression; | ||
1173 | } | ||
1174 | } | ||
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/TrainLocationsObjectiveHint.java b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/TrainLocationsObjectiveHint.java new file mode 100644 index 00000000..570f9deb --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/TrainLocationsObjectiveHint.java | |||
@@ -0,0 +1,117 @@ | |||
1 | package modes3.run; | ||
2 | |||
3 | import com.google.common.collect.ImmutableList; | ||
4 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic; | ||
5 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace; | ||
6 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type; | ||
7 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.Dimension; | ||
8 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.ExtendedLinearExpressionBuilder; | ||
9 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.ExtendedLinearExpressionBuilderFactory; | ||
10 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.PolyhedronExtensionOperator; | ||
11 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.CostElementMatch; | ||
12 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.CostElementMatchers; | ||
13 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.CostObjectiveHint; | ||
14 | import java.util.Collection; | ||
15 | import java.util.List; | ||
16 | import java.util.Map; | ||
17 | import java.util.Set; | ||
18 | import modes3.Modes3Package; | ||
19 | import modes3.queries.TrainLocations_step_2; | ||
20 | import modes3.queries.TrainLocations_step_3; | ||
21 | import org.eclipse.xtext.xbase.lib.Extension; | ||
22 | import org.eclipse.xtext.xbase.lib.Functions.Function1; | ||
23 | import org.eclipse.xtext.xbase.lib.IterableExtensions; | ||
24 | |||
25 | @SuppressWarnings("all") | ||
26 | public class TrainLocationsObjectiveHint extends CostObjectiveHint { | ||
27 | private final Type segmentType; | ||
28 | |||
29 | private final Type trainType; | ||
30 | |||
31 | public TrainLocationsObjectiveHint(@Extension final Ecore2Logic ecore2Logic, final Ecore2Logic_Trace ecore2LogicTrace) { | ||
32 | @Extension | ||
33 | final Modes3Package Modes3Package = modes3.Modes3Package.eINSTANCE; | ||
34 | this.segmentType = ecore2Logic.TypeofEClass(ecore2LogicTrace, Modes3Package.getSegment()); | ||
35 | this.trainType = ecore2Logic.TypeofEClass(ecore2LogicTrace, Modes3Package.getTrain()); | ||
36 | } | ||
37 | |||
38 | @Override | ||
39 | public boolean isExact() { | ||
40 | return true; | ||
41 | } | ||
42 | |||
43 | @Override | ||
44 | public PolyhedronExtensionOperator createPolyhedronExtensionOperator(final Map<String, CostElementMatchers> costElementMatchers) { | ||
45 | PolyhedronExtensionOperator _xblockexpression = null; | ||
46 | { | ||
47 | final CostElementMatchers step2 = costElementMatchers.get(TrainLocations_step_2.instance().getFullyQualifiedName()); | ||
48 | final CostElementMatchers step3 = costElementMatchers.get(TrainLocations_step_3.instance().getFullyQualifiedName()); | ||
49 | final PolyhedronExtensionOperator _function = (ExtendedLinearExpressionBuilderFactory it) -> { | ||
50 | final ExtendedLinearExpressionBuilder objectiveBuilder = it.createBuilder(); | ||
51 | ImmutableList<CostElementMatch> _matches = step2.getMatches(); | ||
52 | for (final CostElementMatch m : _matches) { | ||
53 | { | ||
54 | final Dimension dimension = it.getDimension(m.getMatch()); | ||
55 | objectiveBuilder.add(step2.getWeight(), dimension); | ||
56 | dimension.tightenLowerBound(Integer.valueOf(0)); | ||
57 | boolean _isMulti = m.isMulti(); | ||
58 | if (_isMulti) { | ||
59 | it.createBuilder().add(1, dimension).add((-1), this.trainType).build().assertEqualsTo(0); | ||
60 | } else { | ||
61 | dimension.tightenUpperBound(Integer.valueOf(1)); | ||
62 | boolean _isMust = m.isMust(); | ||
63 | if (_isMust) { | ||
64 | dimension.tightenLowerBound(Integer.valueOf(1)); | ||
65 | } | ||
66 | } | ||
67 | } | ||
68 | } | ||
69 | final ImmutableList<CostElementMatch> step3Matches = step3.getMatches(); | ||
70 | for (final CostElementMatch m_1 : step3Matches) { | ||
71 | { | ||
72 | final Dimension dimension = it.getDimension(m_1.getMatch()); | ||
73 | objectiveBuilder.add(step3.getWeight(), dimension); | ||
74 | dimension.tightenLowerBound(Integer.valueOf(0)); | ||
75 | boolean _isMulti = m_1.isMulti(); | ||
76 | boolean _not = (!_isMulti); | ||
77 | if (_not) { | ||
78 | dimension.tightenUpperBound(Integer.valueOf(1)); | ||
79 | boolean _isMust = m_1.isMust(); | ||
80 | if (_isMust) { | ||
81 | dimension.tightenLowerBound(Integer.valueOf(1)); | ||
82 | } | ||
83 | } | ||
84 | } | ||
85 | } | ||
86 | TrainLocationsObjectiveHint.boundLimit(it, step3Matches, 2, this.trainType, 1); | ||
87 | TrainLocationsObjectiveHint.boundLimit(it, step3Matches, 3, this.segmentType, 1); | ||
88 | this.buildWithBounds(objectiveBuilder); | ||
89 | }; | ||
90 | _xblockexpression = _function; | ||
91 | } | ||
92 | return _xblockexpression; | ||
93 | } | ||
94 | |||
95 | private static void boundLimit(@Extension final ExtendedLinearExpressionBuilderFactory factory, final Collection<CostElementMatch> matches, final int index, final Type type, final int count) { | ||
96 | final Function1<CostElementMatch, Object> _function = (CostElementMatch it) -> { | ||
97 | return it.getMatch().get(index); | ||
98 | }; | ||
99 | Set<Map.Entry<Object, List<CostElementMatch>>> _entrySet = IterableExtensions.<Object, CostElementMatch>groupBy(matches, _function).entrySet(); | ||
100 | for (final Map.Entry<Object, List<CostElementMatch>> pair : _entrySet) { | ||
101 | { | ||
102 | final ExtendedLinearExpressionBuilder multiplicityBuilder = factory.createBuilder(); | ||
103 | List<CostElementMatch> _value = pair.getValue(); | ||
104 | for (final CostElementMatch m : _value) { | ||
105 | multiplicityBuilder.add(1, m.getMatch()); | ||
106 | } | ||
107 | boolean _isMulti = CostElementMatchers.isMulti(pair.getKey()); | ||
108 | if (_isMulti) { | ||
109 | multiplicityBuilder.add((-count), type); | ||
110 | multiplicityBuilder.build().tightenUpperBound(Integer.valueOf(0)); | ||
111 | } else { | ||
112 | multiplicityBuilder.build().tightenUpperBound(Integer.valueOf(count)); | ||
113 | } | ||
114 | } | ||
115 | } | ||
116 | } | ||
117 | } | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.alloyexamples/META-INF/MANIFEST.MF b/Domains/hu.bme.mit.inf.dslreasoner.domains.alloyexamples/META-INF/MANIFEST.MF index 5fb85170..cc71bd06 100644 --- a/Domains/hu.bme.mit.inf.dslreasoner.domains.alloyexamples/META-INF/MANIFEST.MF +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.alloyexamples/META-INF/MANIFEST.MF | |||
@@ -15,7 +15,6 @@ Require-Bundle: org.eclipse.viatra.addon.querybasedfeatures.runtime, | |||
15 | org.eclipse.viatra.query.runtime, | 15 | org.eclipse.viatra.query.runtime, |
16 | org.eclipse.core.runtime, | 16 | org.eclipse.core.runtime, |
17 | org.eclipse.emf.ecore;visibility:=reexport, | 17 | org.eclipse.emf.ecore;visibility:=reexport, |
18 | org.eclipse.emf.emfstore.common, | ||
19 | com.google.guava, | 18 | com.google.guava, |
20 | org.eclipse.xtext.xbase.lib, | 19 | org.eclipse.xtext.xbase.lib, |
21 | org.eclipse.xtend.lib, | 20 | org.eclipse.xtend.lib, |
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.yakindu.sgraph/plugin.xml b/Domains/hu.bme.mit.inf.dslreasoner.domains.yakindu.sgraph/plugin.xml index 331e2b61..d4ab204e 100644 --- a/Domains/hu.bme.mit.inf.dslreasoner.domains.yakindu.sgraph/plugin.xml +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.yakindu.sgraph/plugin.xml | |||
@@ -39,72 +39,4 @@ | |||
39 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.twoSynch"/> | 39 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.twoSynch"/> |
40 | </group> | 40 | </group> |
41 | </extension> | 41 | </extension> |
42 | <extension id="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.Mutated" point="org.eclipse.viatra.query.runtime.queryspecification"> | ||
43 | <group group="org.eclipse.viatra.query.runtime.extensibility.SingletonExtensionFactory:hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.Mutated" id="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.Mutated"> | ||
44 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.entryInRegion_M0"/> | ||
45 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.entryInRegion_M1"/> | ||
46 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.entryInRegion_M2"/> | ||
47 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.noEntryInRegion_M0"/> | ||
48 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.noEntryInRegion_M1"/> | ||
49 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.noEntryInRegion_M2"/> | ||
50 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.noEntryInRegion_M3"/> | ||
51 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.noEntryInRegion_M4"/> | ||
52 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.noEntryInRegion_M5"/> | ||
53 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.multipleEntryInRegion_M0"/> | ||
54 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.multipleEntryInRegion_M1"/> | ||
55 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.multipleEntryInRegion_M2"/> | ||
56 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.multipleEntryInRegion_M3"/> | ||
57 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.multipleEntryInRegion_M4"/> | ||
58 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.multipleEntryInRegion_M5"/> | ||
59 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.transition_M0"/> | ||
60 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.transition_M1"/> | ||
61 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.transition_M2"/> | ||
62 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.transition_M3"/> | ||
63 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.transition_M4"/> | ||
64 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.incomingToEntry_M0"/> | ||
65 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.incomingToEntry_1"/> | ||
66 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.incomingToEntry_2"/> | ||
67 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.incomingToEntry_3"/> | ||
68 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.incomingToEntry_4"/> | ||
69 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.incomingToEntry_5"/> | ||
70 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.noOutgoingTransitionFromEntry_M0"/> | ||
71 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.noOutgoingTransitionFromEntry_M1"/> | ||
72 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.noOutgoingTransitionFromEntry_M2"/> | ||
73 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.noOutgoingTransitionFromEntry_M3"/> | ||
74 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.noOutgoingTransitionFromEntry_M4"/> | ||
75 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.noOutgoingTransitionFromEntry_M5"/> | ||
76 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.multipleTransitionFromEntry_M0"/> | ||
77 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.multipleTransitionFromEntry_M1"/> | ||
78 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.multipleTransitionFromEntry_M2"/> | ||
79 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.multipleTransitionFromEntry_M3"/> | ||
80 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.multipleTransitionFromEntry_M4"/> | ||
81 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.outgoingFromExit_M0"/> | ||
82 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.outgoingFromExit_M1"/> | ||
83 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.outgoingFromExit_M2"/> | ||
84 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.outgoingFromFinal_M0"/> | ||
85 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.outgoingFromFinal_M1"/> | ||
86 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.outgoingFromFinal_M2"/> | ||
87 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.noStateInRegion_M0"/> | ||
88 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.noStateInRegion_M1"/> | ||
89 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.noStateInRegion_M2"/> | ||
90 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.noStateInRegion_M3"/> | ||
91 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.StateInRegion_M0"/> | ||
92 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.StateInRegion_M1"/> | ||
93 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.StateInRegion_M2"/> | ||
94 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.choiceHasNoOutgoing_M0"/> | ||
95 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.choiceHasNoOutgoing_M1"/> | ||
96 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.choiceHasNoOutgoing_M2"/> | ||
97 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.choiceHasNoOutgoing_M3"/> | ||
98 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.choiceHasNoOutgoing_M4"/> | ||
99 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.choiceHasNoOutgoing_M5"/> | ||
100 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.choiceHasNoOutgoing_M6"/> | ||
101 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.choiceHasNoIncoming_M0"/> | ||
102 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.choiceHasNoIncoming_M1"/> | ||
103 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.choiceHasNoIncoming_M2"/> | ||
104 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.choiceHasNoIncoming_M3"/> | ||
105 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.choiceHasNoIncoming_M4"/> | ||
106 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.choiceHasNoIncoming_M5"/> | ||
107 | <query-specification fqn="hu.bme.mit.inf.dslreasoner.partialsnapshot_mavo.yakindu.mutated.choiceHasNoIncoming_M6"/> | ||
108 | </group> | ||
109 | </extension> | ||
110 | </plugin> | 42 | </plugin> |