+ *
+ * @see modes3.Modes3Package#getModes3ModelRoot()
+ * @model
+ * @generated
+ */
+public interface Modes3ModelRoot extends EObject {
+ /**
+ * Returns the value of the 'Id' attribute.
+ *
+ *
+ * @return the value of the 'Id' attribute.
+ * @see #setId(int)
+ * @see modes3.Modes3Package#getModes3ModelRoot_Id()
+ * @model
+ * @generated
+ */
+ int getId();
+
+ /**
+ * Sets the value of the '{@link modes3.Modes3ModelRoot#getId Id}' attribute.
+ *
+ *
+ * @param value the new value of the 'Id' attribute.
+ * @see #getId()
+ * @generated
+ */
+ void setId(int value);
+
+ /**
+ * Returns the value of the 'Trains' containment reference list.
+ * The list contents are of type {@link modes3.Train}.
+ *
+ *
+ * @return the value of the 'Trains' containment reference list.
+ * @see modes3.Modes3Package#getModes3ModelRoot_Trains()
+ * @model containment="true"
+ * @generated
+ */
+ EList getTrains();
+
+ /**
+ * Returns the value of the 'Segments' containment reference list.
+ * The list contents are of type {@link modes3.Segment}.
+ *
+ *
+ * @return the value of the 'Segments' containment reference list.
+ * @see modes3.Modes3Package#getModes3ModelRoot_Segments()
+ * @model containment="true"
+ * @generated
+ */
+ EList getSegments();
+
+ /**
+ * Returns the value of the 'Turnouts' containment reference list.
+ * The list contents are of type {@link modes3.Turnout}.
+ *
+ *
+ * @return the value of the 'Turnouts' containment reference list.
+ * @see modes3.Modes3Package#getModes3ModelRoot_Turnouts()
+ * @model containment="true"
+ * @generated
+ */
+ EList getTurnouts();
+
+} // 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..4760af9d
--- /dev/null
+++ b/Domains/ca.mcgill.rtgmrt.example.modes3/ecore-gen/modes3/Modes3Package.java
@@ -0,0 +1,640 @@
+/**
+ */
+package modes3;
+
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EReference;
+
+/**
+ *
+ * The Package for the model.
+ * It contains accessors for the meta objects to represent
+ *
+ *
each class,
+ *
each feature of each class,
+ *
each operation of each class,
+ *
each enum,
+ *
and each data type
+ *
+ *
+ * @see modes3.Modes3Factory
+ * @model kind="package"
+ * @generated
+ */
+public interface Modes3Package extends EPackage {
+ /**
+ * The package name.
+ *
+ *
+ * @generated
+ */
+ String eNAME = "modes3";
+
+ /**
+ * The package namespace URI.
+ *
+ *
+ * @generated
+ */
+ String eNS_URI = "http://www.ece.mcgill.ca/wcet/modes3";
+
+ /**
+ * The package namespace name.
+ *
+ *
+ * @generated
+ */
+ String eNS_PREFIX = "modes3";
+
+ /**
+ * The singleton instance of the package.
+ *
+ *
+ * @generated
+ */
+ Modes3Package eINSTANCE = modes3.impl.Modes3PackageImpl.init();
+
+ /**
+ * The meta object id for the '{@link modes3.impl.SegmentImpl Segment}' class.
+ *
+ *
+ * @see modes3.impl.SegmentImpl
+ * @see modes3.impl.Modes3PackageImpl#getSegment()
+ * @generated
+ */
+ int SEGMENT = 0;
+
+ /**
+ * The feature id for the 'Connected To' reference list.
+ *
+ *
+ * @generated
+ * @ordered
+ */
+ int SEGMENT__CONNECTED_TO = 0;
+
+ /**
+ * The feature id for the 'Occupied By' reference.
+ *
+ *
+ * @generated
+ * @ordered
+ */
+ int SEGMENT__OCCUPIED_BY = 1;
+
+ /**
+ * The feature id for the 'Id' attribute.
+ *
+ *
+ * @generated
+ * @ordered
+ */
+ int SEGMENT__ID = 2;
+
+ /**
+ * The number of structural features of the 'Segment' class.
+ *
+ *
+ * @generated
+ * @ordered
+ */
+ int SEGMENT_FEATURE_COUNT = 3;
+
+ /**
+ * The number of operations of the 'Segment' class.
+ *
+ *
+ * @generated
+ * @ordered
+ */
+ int SEGMENT_OPERATION_COUNT = 0;
+
+ /**
+ * The meta object id for the '{@link modes3.impl.Modes3ModelRootImpl Model Root}' class.
+ *
+ *
+ * @see modes3.impl.Modes3ModelRootImpl
+ * @see modes3.impl.Modes3PackageImpl#getModes3ModelRoot()
+ * @generated
+ */
+ int MODES3_MODEL_ROOT = 1;
+
+ /**
+ * The feature id for the 'Id' attribute.
+ *
+ *
+ * @generated
+ * @ordered
+ */
+ int MODES3_MODEL_ROOT__ID = 0;
+
+ /**
+ * The feature id for the 'Trains' containment reference list.
+ *
+ *
+ * @generated
+ * @ordered
+ */
+ int MODES3_MODEL_ROOT__TRAINS = 1;
+
+ /**
+ * The feature id for the 'Segments' containment reference list.
+ *
+ *
+ * @generated
+ * @ordered
+ */
+ int MODES3_MODEL_ROOT__SEGMENTS = 2;
+
+ /**
+ * The feature id for the 'Turnouts' containment reference list.
+ *
+ *
+ * @generated
+ * @ordered
+ */
+ int MODES3_MODEL_ROOT__TURNOUTS = 3;
+
+ /**
+ * The number of structural features of the 'Model Root' class.
+ *
+ *
+ * @generated
+ * @ordered
+ */
+ int MODES3_MODEL_ROOT_FEATURE_COUNT = 4;
+
+ /**
+ * The number of operations of the 'Model Root' class.
+ *
+ *
+ * @generated
+ * @ordered
+ */
+ int MODES3_MODEL_ROOT_OPERATION_COUNT = 0;
+
+ /**
+ * The meta object id for the '{@link modes3.impl.TurnoutImpl Turnout}' class.
+ *
+ *
+ * @see modes3.impl.TurnoutImpl
+ * @see modes3.impl.Modes3PackageImpl#getTurnout()
+ * @generated
+ */
+ int TURNOUT = 2;
+
+ /**
+ * The feature id for the 'Connected To' reference list.
+ *
+ *
+ * @generated
+ * @ordered
+ */
+ int TURNOUT__CONNECTED_TO = SEGMENT__CONNECTED_TO;
+
+ /**
+ * The feature id for the 'Occupied By' reference.
+ *
+ *
+ * @generated
+ * @ordered
+ */
+ int TURNOUT__OCCUPIED_BY = SEGMENT__OCCUPIED_BY;
+
+ /**
+ * The feature id for the 'Id' attribute.
+ *
+ *
+ * @generated
+ * @ordered
+ */
+ int TURNOUT__ID = SEGMENT__ID;
+
+ /**
+ * The feature id for the 'Straight' reference.
+ *
+ *
+ * @generated
+ * @ordered
+ */
+ int TURNOUT__STRAIGHT = SEGMENT_FEATURE_COUNT + 0;
+
+ /**
+ * The feature id for the 'Divergent' reference.
+ *
+ *
+ * @generated
+ * @ordered
+ */
+ int TURNOUT__DIVERGENT = SEGMENT_FEATURE_COUNT + 1;
+
+ /**
+ * The number of structural features of the 'Turnout' class.
+ *
+ *
+ * @generated
+ * @ordered
+ */
+ int TURNOUT_FEATURE_COUNT = SEGMENT_FEATURE_COUNT + 2;
+
+ /**
+ * The number of operations of the 'Turnout' class.
+ *
+ *
+ * @generated
+ * @ordered
+ */
+ int TURNOUT_OPERATION_COUNT = SEGMENT_OPERATION_COUNT + 0;
+
+ /**
+ * The meta object id for the '{@link modes3.impl.TrainImpl Train}' class.
+ *
+ *
+ * @see modes3.impl.TrainImpl
+ * @see modes3.impl.Modes3PackageImpl#getTrain()
+ * @generated
+ */
+ int TRAIN = 3;
+
+ /**
+ * The feature id for the 'Location' reference.
+ *
+ *
+ * @generated
+ * @ordered
+ */
+ int TRAIN__LOCATION = 0;
+
+ /**
+ * The feature id for the 'Id' attribute.
+ *
+ *
+ * @generated
+ * @ordered
+ */
+ int TRAIN__ID = 1;
+
+ /**
+ * The feature id for the 'Speed' attribute.
+ *
+ *
+ * @generated
+ * @ordered
+ */
+ int TRAIN__SPEED = 2;
+
+ /**
+ * The number of structural features of the 'Train' class.
+ *
+ *
+ * @generated
+ * @ordered
+ */
+ int TRAIN_FEATURE_COUNT = 3;
+
+ /**
+ * The number of operations of the 'Train' class.
+ *
+ *
+ * @generated
+ * @ordered
+ */
+ int TRAIN_OPERATION_COUNT = 0;
+
+
+ /**
+ * Returns the meta object for class '{@link modes3.Segment Segment}'.
+ *
+ *
+ * @return the meta object for class 'Segment'.
+ * @see modes3.Segment
+ * @generated
+ */
+ EClass getSegment();
+
+ /**
+ * Returns the meta object for the reference list '{@link modes3.Segment#getConnectedTo Connected To}'.
+ *
+ *
+ * @return the meta object for the reference list 'Connected To'.
+ * @see modes3.Segment#getConnectedTo()
+ * @see #getSegment()
+ * @generated
+ */
+ EReference getSegment_ConnectedTo();
+
+ /**
+ * Returns the meta object for the reference '{@link modes3.Segment#getOccupiedBy Occupied By}'.
+ *
+ *
+ * @return the meta object for the reference 'Occupied By'.
+ * @see modes3.Segment#getOccupiedBy()
+ * @see #getSegment()
+ * @generated
+ */
+ EReference getSegment_OccupiedBy();
+
+ /**
+ * Returns the meta object for the attribute '{@link modes3.Segment#getId Id}'.
+ *
+ *
+ * @return the meta object for the attribute 'Id'.
+ * @see modes3.Segment#getId()
+ * @see #getSegment()
+ * @generated
+ */
+ EAttribute getSegment_Id();
+
+ /**
+ * Returns the meta object for class '{@link modes3.Modes3ModelRoot Model Root}'.
+ *
+ *
+ * @return the meta object for class 'Model Root'.
+ * @see modes3.Modes3ModelRoot
+ * @generated
+ */
+ EClass getModes3ModelRoot();
+
+ /**
+ * Returns the meta object for the attribute '{@link modes3.Modes3ModelRoot#getId Id}'.
+ *
+ *
+ * @return the meta object for the attribute 'Id'.
+ * @see modes3.Modes3ModelRoot#getId()
+ * @see #getModes3ModelRoot()
+ * @generated
+ */
+ EAttribute getModes3ModelRoot_Id();
+
+ /**
+ * Returns the meta object for the containment reference list '{@link modes3.Modes3ModelRoot#getTrains Trains}'.
+ *
+ *
+ * @return the meta object for the containment reference list 'Trains'.
+ * @see modes3.Modes3ModelRoot#getTrains()
+ * @see #getModes3ModelRoot()
+ * @generated
+ */
+ EReference getModes3ModelRoot_Trains();
+
+ /**
+ * Returns the meta object for the containment reference list '{@link modes3.Modes3ModelRoot#getSegments Segments}'.
+ *
+ *
+ * @return the meta object for the containment reference list 'Segments'.
+ * @see modes3.Modes3ModelRoot#getSegments()
+ * @see #getModes3ModelRoot()
+ * @generated
+ */
+ EReference getModes3ModelRoot_Segments();
+
+ /**
+ * Returns the meta object for the containment reference list '{@link modes3.Modes3ModelRoot#getTurnouts Turnouts}'.
+ *
+ *
+ * @return the meta object for the containment reference list 'Turnouts'.
+ * @see modes3.Modes3ModelRoot#getTurnouts()
+ * @see #getModes3ModelRoot()
+ * @generated
+ */
+ EReference getModes3ModelRoot_Turnouts();
+
+ /**
+ * Returns the meta object for class '{@link modes3.Turnout Turnout}'.
+ *
+ *
+ * @return the meta object for class 'Turnout'.
+ * @see modes3.Turnout
+ * @generated
+ */
+ EClass getTurnout();
+
+ /**
+ * Returns the meta object for the reference '{@link modes3.Turnout#getStraight Straight}'.
+ *
+ *
+ * @return the meta object for the reference 'Straight'.
+ * @see modes3.Turnout#getStraight()
+ * @see #getTurnout()
+ * @generated
+ */
+ EReference getTurnout_Straight();
+
+ /**
+ * Returns the meta object for the reference '{@link modes3.Turnout#getDivergent Divergent}'.
+ *
+ *
+ * @return the meta object for the reference 'Divergent'.
+ * @see modes3.Turnout#getDivergent()
+ * @see #getTurnout()
+ * @generated
+ */
+ EReference getTurnout_Divergent();
+
+ /**
+ * Returns the meta object for class '{@link modes3.Train Train}'.
+ *
+ *
+ * @return the meta object for class 'Train'.
+ * @see modes3.Train
+ * @generated
+ */
+ EClass getTrain();
+
+ /**
+ * Returns the meta object for the reference '{@link modes3.Train#getLocation Location}'.
+ *
+ *
+ * @return the meta object for the reference 'Location'.
+ * @see modes3.Train#getLocation()
+ * @see #getTrain()
+ * @generated
+ */
+ EReference getTrain_Location();
+
+ /**
+ * Returns the meta object for the attribute '{@link modes3.Train#getId Id}'.
+ *
+ *
+ * @return the meta object for the attribute 'Id'.
+ * @see modes3.Train#getId()
+ * @see #getTrain()
+ * @generated
+ */
+ EAttribute getTrain_Id();
+
+ /**
+ * Returns the meta object for the attribute '{@link modes3.Train#getSpeed Speed}'.
+ *
+ *
+ * @return the meta object for the attribute 'Speed'.
+ * @see modes3.Train#getSpeed()
+ * @see #getTrain()
+ * @generated
+ */
+ EAttribute getTrain_Speed();
+
+ /**
+ * Returns the factory that creates the instances of the model.
+ *
+ *
+ * @return the factory that creates the instances of the model.
+ * @generated
+ */
+ Modes3Factory getModes3Factory();
+
+ /**
+ *
+ * Defines literals for the meta objects that represent
+ *
+ *
each class,
+ *
each feature of each class,
+ *
each operation of each class,
+ *
each enum,
+ *
and each data type
+ *
+ *
+ * @generated
+ */
+ interface Literals {
+ /**
+ * The meta object literal for the '{@link modes3.impl.SegmentImpl Segment}' class.
+ *
+ *
+ * @see modes3.impl.SegmentImpl
+ * @see modes3.impl.Modes3PackageImpl#getSegment()
+ * @generated
+ */
+ EClass SEGMENT = eINSTANCE.getSegment();
+
+ /**
+ * The meta object literal for the 'Connected To' reference list feature.
+ *
+ *
+ * @generated
+ */
+ EReference SEGMENT__CONNECTED_TO = eINSTANCE.getSegment_ConnectedTo();
+
+ /**
+ * The meta object literal for the 'Occupied By' reference feature.
+ *
+ *
+ * @generated
+ */
+ EReference SEGMENT__OCCUPIED_BY = eINSTANCE.getSegment_OccupiedBy();
+
+ /**
+ * The meta object literal for the 'Id' attribute feature.
+ *
+ *
+ * @generated
+ */
+ EAttribute SEGMENT__ID = eINSTANCE.getSegment_Id();
+
+ /**
+ * The meta object literal for the '{@link modes3.impl.Modes3ModelRootImpl Model Root}' class.
+ *
+ *
+ * @see modes3.impl.Modes3ModelRootImpl
+ * @see modes3.impl.Modes3PackageImpl#getModes3ModelRoot()
+ * @generated
+ */
+ EClass MODES3_MODEL_ROOT = eINSTANCE.getModes3ModelRoot();
+
+ /**
+ * The meta object literal for the 'Id' attribute feature.
+ *
+ *
+ * @generated
+ */
+ EAttribute MODES3_MODEL_ROOT__ID = eINSTANCE.getModes3ModelRoot_Id();
+
+ /**
+ * The meta object literal for the 'Trains' containment reference list feature.
+ *
+ *
+ * @generated
+ */
+ EReference MODES3_MODEL_ROOT__TRAINS = eINSTANCE.getModes3ModelRoot_Trains();
+
+ /**
+ * The meta object literal for the 'Segments' containment reference list feature.
+ *
+ *
+ * @generated
+ */
+ EReference MODES3_MODEL_ROOT__SEGMENTS = eINSTANCE.getModes3ModelRoot_Segments();
+
+ /**
+ * The meta object literal for the 'Turnouts' containment reference list feature.
+ *
+ *
+ * @generated
+ */
+ EReference MODES3_MODEL_ROOT__TURNOUTS = eINSTANCE.getModes3ModelRoot_Turnouts();
+
+ /**
+ * The meta object literal for the '{@link modes3.impl.TurnoutImpl Turnout}' class.
+ *
+ *
+ * @see modes3.impl.TurnoutImpl
+ * @see modes3.impl.Modes3PackageImpl#getTurnout()
+ * @generated
+ */
+ EClass TURNOUT = eINSTANCE.getTurnout();
+
+ /**
+ * The meta object literal for the 'Straight' reference feature.
+ *
+ *
+ * @generated
+ */
+ EReference TURNOUT__STRAIGHT = eINSTANCE.getTurnout_Straight();
+
+ /**
+ * The meta object literal for the 'Divergent' reference feature.
+ *
+ *
+ * @generated
+ */
+ EReference TURNOUT__DIVERGENT = eINSTANCE.getTurnout_Divergent();
+
+ /**
+ * The meta object literal for the '{@link modes3.impl.TrainImpl Train}' class.
+ *
+ *
+ * @see modes3.impl.TrainImpl
+ * @see modes3.impl.Modes3PackageImpl#getTrain()
+ * @generated
+ */
+ EClass TRAIN = eINSTANCE.getTrain();
+
+ /**
+ * The meta object literal for the 'Location' reference feature.
+ *
+ *
+ * @generated
+ */
+ EReference TRAIN__LOCATION = eINSTANCE.getTrain_Location();
+
+ /**
+ * The meta object literal for the 'Id' attribute feature.
+ *
+ *
+ * @generated
+ */
+ EAttribute TRAIN__ID = eINSTANCE.getTrain_Id();
+
+ /**
+ * The meta object literal for the 'Speed' attribute feature.
+ *
+ *
+ * @generated
+ */
+ EAttribute TRAIN__SPEED = eINSTANCE.getTrain_Speed();
+
+ }
+
+} //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 @@
+/**
+ */
+package modes3;
+
+import org.eclipse.emf.common.util.EList;
+
+import org.eclipse.emf.ecore.EObject;
+
+/**
+ *
+ * A representation of the model object 'Segment'.
+ *
+ *
+ *
+ *
+ * @see modes3.Modes3Package#getSegment()
+ * @model
+ * @generated
+ */
+public interface Segment extends EObject {
+ /**
+ * Returns the value of the 'Connected To' reference list.
+ * The list contents are of type {@link modes3.Segment}.
+ *
+ *
+ * @return the value of the 'Connected To' reference list.
+ * @see modes3.Modes3Package#getSegment_ConnectedTo()
+ * @model upper="2"
+ * @generated
+ */
+ EList getConnectedTo();
+
+ /**
+ * Returns the value of the 'Occupied By' reference.
+ * It is bidirectional and its opposite is '{@link modes3.Train#getLocation Location}'.
+ *
+ *
+ * @return the value of the 'Occupied By' reference.
+ * @see #setOccupiedBy(Train)
+ * @see modes3.Modes3Package#getSegment_OccupiedBy()
+ * @see modes3.Train#getLocation
+ * @model opposite="location"
+ * @generated
+ */
+ Train getOccupiedBy();
+
+ /**
+ * Sets the value of the '{@link modes3.Segment#getOccupiedBy Occupied By}' reference.
+ *
+ *
+ * @param value the new value of the 'Occupied By' reference.
+ * @see #getOccupiedBy()
+ * @generated
+ */
+ void setOccupiedBy(Train value);
+
+ /**
+ * Returns the value of the 'Id' attribute.
+ *
+ *
+ * @return the value of the 'Id' attribute.
+ * @see #setId(int)
+ * @see modes3.Modes3Package#getSegment_Id()
+ * @model
+ * @generated
+ */
+ int getId();
+
+ /**
+ * Sets the value of the '{@link modes3.Segment#getId Id}' attribute.
+ *
+ *
+ * @param value the new value of the 'Id' attribute.
+ * @see #getId()
+ * @generated
+ */
+ void setId(int value);
+
+} // Segment
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 @@
+/**
+ */
+package modes3;
+
+import org.eclipse.emf.ecore.EObject;
+
+/**
+ *
+ * A representation of the model object 'Train'.
+ *
+ *
+ *
+ * The following features are supported:
+ *
+ *
+ *
{@link modes3.Train#getLocation Location}
+ *
{@link modes3.Train#getId Id}
+ *
{@link modes3.Train#getSpeed Speed}
+ *
+ *
+ * @see modes3.Modes3Package#getTrain()
+ * @model
+ * @generated
+ */
+public interface Train extends EObject {
+ /**
+ * Returns the value of the 'Location' reference.
+ * It is bidirectional and its opposite is '{@link modes3.Segment#getOccupiedBy Occupied By}'.
+ *
+ *
+ * @return the value of the 'Location' reference.
+ * @see #setLocation(Segment)
+ * @see modes3.Modes3Package#getTrain_Location()
+ * @see modes3.Segment#getOccupiedBy
+ * @model opposite="occupiedBy" required="true"
+ * @generated
+ */
+ Segment getLocation();
+
+ /**
+ * Sets the value of the '{@link modes3.Train#getLocation Location}' reference.
+ *
+ *
+ * @param value the new value of the 'Location' reference.
+ * @see #getLocation()
+ * @generated
+ */
+ void setLocation(Segment value);
+
+ /**
+ * Returns the value of the 'Id' attribute.
+ *
+ *
+ * @return the value of the 'Id' attribute.
+ * @see #setId(int)
+ * @see modes3.Modes3Package#getTrain_Id()
+ * @model
+ * @generated
+ */
+ int getId();
+
+ /**
+ * Sets the value of the '{@link modes3.Train#getId Id}' attribute.
+ *
+ *
+ * @param value the new value of the 'Id' attribute.
+ * @see #getId()
+ * @generated
+ */
+ void setId(int value);
+
+ /**
+ * Returns the value of the 'Speed' attribute.
+ *
+ *
+ * @return the value of the 'Speed' attribute.
+ * @see #setSpeed(double)
+ * @see modes3.Modes3Package#getTrain_Speed()
+ * @model
+ * @generated
+ */
+ double getSpeed();
+
+ /**
+ * Sets the value of the '{@link modes3.Train#getSpeed Speed}' attribute.
+ *
+ *
+ * @param value the new value of the 'Speed' attribute.
+ * @see #getSpeed()
+ * @generated
+ */
+ void setSpeed(double value);
+
+} // 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 @@
+/**
+ */
+package modes3;
+
+
+/**
+ *
+ * A representation of the model object 'Turnout'.
+ *
+ *
+ *
+ * The following features are supported:
+ *
+ *
+ *
{@link modes3.Turnout#getStraight Straight}
+ *
{@link modes3.Turnout#getDivergent Divergent}
+ *
+ *
+ * @see modes3.Modes3Package#getTurnout()
+ * @model
+ * @generated
+ */
+public interface Turnout extends Segment {
+ /**
+ * Returns the value of the 'Straight' reference.
+ *
+ *
+ * @return the value of the 'Straight' reference.
+ * @see #setStraight(Segment)
+ * @see modes3.Modes3Package#getTurnout_Straight()
+ * @model required="true"
+ * @generated
+ */
+ Segment getStraight();
+
+ /**
+ * Sets the value of the '{@link modes3.Turnout#getStraight Straight}' reference.
+ *
+ *
+ * @param value the new value of the 'Straight' reference.
+ * @see #getStraight()
+ * @generated
+ */
+ void setStraight(Segment value);
+
+ /**
+ * Returns the value of the 'Divergent' reference.
+ *
+ *
+ * @return the value of the 'Divergent' reference.
+ * @see #setDivergent(Segment)
+ * @see modes3.Modes3Package#getTurnout_Divergent()
+ * @model required="true"
+ * @generated
+ */
+ Segment getDivergent();
+
+ /**
+ * Sets the value of the '{@link modes3.Turnout#getDivergent Divergent}' reference.
+ *
+ *
+ * @param value the new value of the 'Divergent' reference.
+ * @see #getDivergent()
+ * @generated
+ */
+ void setDivergent(Segment value);
+
+} // 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..6ec86cb6
--- /dev/null
+++ b/Domains/ca.mcgill.rtgmrt.example.modes3/ecore-gen/modes3/impl/Modes3FactoryImpl.java
@@ -0,0 +1,128 @@
+/**
+ */
+package modes3.impl;
+
+import modes3.*;
+
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+
+import org.eclipse.emf.ecore.impl.EFactoryImpl;
+
+import org.eclipse.emf.ecore.plugin.EcorePlugin;
+
+/**
+ *
+ * An implementation of the model Factory.
+ *
+ * @generated
+ */
+public class Modes3FactoryImpl extends EFactoryImpl implements Modes3Factory {
+ /**
+ * Creates the default factory implementation.
+ *
+ *
+ * @generated
+ */
+ public static Modes3Factory init() {
+ try {
+ Modes3Factory theModes3Factory = (Modes3Factory)EPackage.Registry.INSTANCE.getEFactory(Modes3Package.eNS_URI);
+ if (theModes3Factory != null) {
+ return theModes3Factory;
+ }
+ }
+ catch (Exception exception) {
+ EcorePlugin.INSTANCE.log(exception);
+ }
+ return new Modes3FactoryImpl();
+ }
+
+ /**
+ * Creates an instance of the factory.
+ *
+ *
+ * @generated
+ */
+ public Modes3FactoryImpl() {
+ super();
+ }
+
+ /**
+ *
+ *
+ * @generated
+ */
+ @Override
+ public EObject create(EClass eClass) {
+ switch (eClass.getClassifierID()) {
+ case Modes3Package.SEGMENT: return createSegment();
+ case Modes3Package.MODES3_MODEL_ROOT: return createModes3ModelRoot();
+ case Modes3Package.TURNOUT: return createTurnout();
+ case Modes3Package.TRAIN: return createTrain();
+ default:
+ throw new IllegalArgumentException("The class '" + eClass.getName() + "' is not a valid classifier");
+ }
+ }
+
+ /**
+ *
+ *
+ * @generated
+ */
+ public Segment createSegment() {
+ SegmentImpl segment = new SegmentImpl();
+ return segment;
+ }
+
+ /**
+ *
+ *
+ * @generated
+ */
+ public Modes3ModelRoot createModes3ModelRoot() {
+ Modes3ModelRootImpl modes3ModelRoot = new Modes3ModelRootImpl();
+ return modes3ModelRoot;
+ }
+
+ /**
+ *
+ *
+ * @generated
+ */
+ public Turnout createTurnout() {
+ TurnoutImpl turnout = new TurnoutImpl();
+ return turnout;
+ }
+
+ /**
+ *
+ *
+ * @generated
+ */
+ public Train createTrain() {
+ TrainImpl train = new TrainImpl();
+ return train;
+ }
+
+ /**
+ *
+ *
+ * @generated
+ */
+ public Modes3Package getModes3Package() {
+ return (Modes3Package)getEPackage();
+ }
+
+ /**
+ *
+ *
+ * @deprecated
+ * @generated
+ */
+ @Deprecated
+ public static Modes3Package getPackage() {
+ return Modes3Package.eINSTANCE;
+ }
+
+} //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..d1ee25ff
--- /dev/null
+++ b/Domains/ca.mcgill.rtgmrt.example.modes3/ecore-gen/modes3/impl/Modes3ModelRootImpl.java
@@ -0,0 +1,296 @@
+/**
+ */
+package modes3.impl;
+
+import java.util.Collection;
+
+import modes3.Modes3ModelRoot;
+import modes3.Modes3Package;
+import modes3.Segment;
+import modes3.Train;
+import modes3.Turnout;
+
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.common.notify.NotificationChain;
+
+import org.eclipse.emf.common.util.EList;
+
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.InternalEObject;
+
+import org.eclipse.emf.ecore.impl.ENotificationImpl;
+import org.eclipse.emf.ecore.impl.MinimalEObjectImpl;
+
+import org.eclipse.emf.ecore.util.EObjectContainmentEList;
+import org.eclipse.emf.ecore.util.InternalEList;
+
+/**
+ *
+ * An implementation of the model object 'Model Root'.
+ *
+ *
Note: the correct way to create the package is via the static
+ * factory method {@link #init init()}, which also performs
+ * initialization of the package, or returns the registered package,
+ * if one already exists.
+ *
+ *
+ * @see org.eclipse.emf.ecore.EPackage.Registry
+ * @see modes3.Modes3Package#eNS_URI
+ * @see #init()
+ * @generated
+ */
+ private Modes3PackageImpl() {
+ super(eNS_URI, Modes3Factory.eINSTANCE);
+ }
+
+ /**
+ *
+ *
+ * @generated
+ */
+ private static boolean isInited = false;
+
+ /**
+ * Creates, registers, and initializes the Package for this model, and for any others upon which it depends.
+ *
+ *
+ *
+ * @see Matcher
+ * @see Match
+ *
+ */
+@SuppressWarnings("all")
+public final class Adjacent extends BaseGeneratedEMFQuerySpecification {
+ /**
+ * Pattern-specific match representation of the modes3.queries.adjacent pattern,
+ * to be used in conjunction with {@link Matcher}.
+ *
+ *
Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
+ * Each instance is a (possibly partial) substitution of pattern parameters,
+ * usable to represent a match of the pattern in the result of a query,
+ * or to specify the bound (fixed) input parameters when issuing a query.
+ *
+ * @see Matcher
+ *
+ */
+ public static abstract class Match extends BasePatternMatch {
+ private Segment fS1;
+
+ private Segment fS2;
+
+ private static List parameterNames = makeImmutableList("S1", "S2");
+
+ private Match(final Segment pS1, final Segment pS2) {
+ this.fS1 = pS1;
+ this.fS2 = pS2;
+ }
+
+ @Override
+ public Object get(final String parameterName) {
+ switch(parameterName) {
+ case "S1": return this.fS1;
+ case "S2": return this.fS2;
+ default: return null;
+ }
+ }
+
+ @Override
+ public Object get(final int index) {
+ switch(index) {
+ case 0: return this.fS1;
+ case 1: return this.fS2;
+ default: return null;
+ }
+ }
+
+ public Segment getS1() {
+ return this.fS1;
+ }
+
+ public Segment getS2() {
+ return this.fS2;
+ }
+
+ @Override
+ public boolean set(final String parameterName, final Object newValue) {
+ if (!isMutable()) throw new java.lang.UnsupportedOperationException();
+ if ("S1".equals(parameterName) ) {
+ this.fS1 = (Segment) newValue;
+ return true;
+ }
+ if ("S2".equals(parameterName) ) {
+ this.fS2 = (Segment) newValue;
+ return true;
+ }
+ return false;
+ }
+
+ public void setS1(final Segment pS1) {
+ if (!isMutable()) throw new java.lang.UnsupportedOperationException();
+ this.fS1 = pS1;
+ }
+
+ public void setS2(final Segment pS2) {
+ if (!isMutable()) throw new java.lang.UnsupportedOperationException();
+ this.fS2 = pS2;
+ }
+
+ @Override
+ public String patternName() {
+ return "modes3.queries.adjacent";
+ }
+
+ @Override
+ public List parameterNames() {
+ return Adjacent.Match.parameterNames;
+ }
+
+ @Override
+ public Object[] toArray() {
+ return new Object[]{fS1, fS2};
+ }
+
+ @Override
+ public Adjacent.Match toImmutable() {
+ return isMutable() ? newMatch(fS1, fS2) : this;
+ }
+
+ @Override
+ public String prettyPrint() {
+ StringBuilder result = new StringBuilder();
+ result.append("\"S1\"=" + prettyPrintValue(fS1) + ", ");
+ result.append("\"S2\"=" + prettyPrintValue(fS2));
+ return result.toString();
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(fS1, fS2);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null) {
+ return false;
+ }
+ if ((obj instanceof Adjacent.Match)) {
+ Adjacent.Match other = (Adjacent.Match) obj;
+ return Objects.equals(fS1, other.fS1) && Objects.equals(fS2, other.fS2);
+ } else {
+ // this should be infrequent
+ if (!(obj instanceof IPatternMatch)) {
+ return false;
+ }
+ IPatternMatch otherSig = (IPatternMatch) obj;
+ return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
+ }
+ }
+
+ @Override
+ public Adjacent specification() {
+ return Adjacent.instance();
+ }
+
+ /**
+ * Returns an empty, mutable match.
+ * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
+ *
+ * @return the empty match.
+ *
+ */
+ public static Adjacent.Match newEmptyMatch() {
+ return new Mutable(null, null);
+ }
+
+ /**
+ * Returns a mutable (partial) match.
+ * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
+ *
+ * @param pS1 the fixed value of pattern parameter S1, or null if not bound.
+ * @param pS2 the fixed value of pattern parameter S2, or null if not bound.
+ * @return the new, mutable (partial) match object.
+ *
+ */
+ public static Adjacent.Match newMutableMatch(final Segment pS1, final Segment pS2) {
+ return new Mutable(pS1, pS2);
+ }
+
+ /**
+ * Returns a new (partial) match.
+ * This can be used e.g. to call the matcher with a partial match.
+ *
The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
+ * @param pS1 the fixed value of pattern parameter S1, or null if not bound.
+ * @param pS2 the fixed value of pattern parameter S2, or null if not bound.
+ * @return the (partial) match object.
+ *
+ */
+ public static Adjacent.Match newMatch(final Segment pS1, final Segment pS2) {
+ return new Immutable(pS1, pS2);
+ }
+
+ private static final class Mutable extends Adjacent.Match {
+ Mutable(final Segment pS1, final Segment pS2) {
+ super(pS1, pS2);
+ }
+
+ @Override
+ public boolean isMutable() {
+ return true;
+ }
+ }
+
+ private static final class Immutable extends Adjacent.Match {
+ Immutable(final Segment pS1, final Segment pS2) {
+ super(pS1, pS2);
+ }
+
+ @Override
+ public boolean isMutable() {
+ return false;
+ }
+ }
+ }
+
+ /**
+ * Generated pattern matcher API of the modes3.queries.adjacent pattern,
+ * providing pattern-specific query methods.
+ *
+ *
Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
+ * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
+ *
+ *
Matches of the pattern will be represented as {@link Match}.
+ *
+ *
+ *
+ * @see Match
+ * @see Adjacent
+ *
+ */
+ public static class Matcher extends BaseMatcher {
+ /**
+ * Initializes the pattern matcher within an existing VIATRA Query engine.
+ * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
+ *
+ * @param engine the existing VIATRA Query engine in which this matcher will be created.
+ * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
+ *
+ */
+ public static Adjacent.Matcher on(final ViatraQueryEngine engine) {
+ // check if matcher already exists
+ Matcher matcher = engine.getExistingMatcher(querySpecification());
+ if (matcher == null) {
+ matcher = (Matcher)engine.getMatcher(querySpecification());
+ }
+ return matcher;
+ }
+
+ /**
+ * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
+ * @return an initialized matcher
+ * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
+ *
+ */
+ public static Adjacent.Matcher create() {
+ return new Matcher();
+ }
+
+ private static final int POSITION_S1 = 0;
+
+ private static final int POSITION_S2 = 1;
+
+ private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Adjacent.Matcher.class);
+
+ /**
+ * Initializes the pattern matcher within an existing VIATRA Query engine.
+ * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
+ *
+ * @param engine the existing VIATRA Query engine in which this matcher will be created.
+ * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
+ *
+ */
+ private Matcher() {
+ super(querySpecification());
+ }
+
+ /**
+ * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
+ * @param pS1 the fixed value of pattern parameter S1, or null if not bound.
+ * @param pS2 the fixed value of pattern parameter S2, or null if not bound.
+ * @return matches represented as a Match object.
+ *
+ */
+ public Collection getAllMatches(final Segment pS1, final Segment pS2) {
+ return rawStreamAllMatches(new Object[]{pS1, pS2}).collect(Collectors.toSet());
+ }
+
+ /**
+ * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
+ *
+ * NOTE: It is important not to modify the source model while the stream is being processed.
+ * If the match set of the pattern changes during processing, the contents of the stream is undefined.
+ * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
+ * @param pS1 the fixed value of pattern parameter S1, or null if not bound.
+ * @param pS2 the fixed value of pattern parameter S2, or null if not bound.
+ * @return a stream of matches represented as a Match object.
+ *
+ */
+ public Stream streamAllMatches(final Segment pS1, final Segment pS2) {
+ return rawStreamAllMatches(new Object[]{pS1, pS2});
+ }
+
+ /**
+ * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
+ * Neither determinism nor randomness of selection is guaranteed.
+ * @param pS1 the fixed value of pattern parameter S1, or null if not bound.
+ * @param pS2 the fixed value of pattern parameter S2, or null if not bound.
+ * @return a match represented as a Match object, or null if no match is found.
+ *
+ */
+ public Optional getOneArbitraryMatch(final Segment pS1, final Segment pS2) {
+ return rawGetOneArbitraryMatch(new Object[]{pS1, pS2});
+ }
+
+ /**
+ * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
+ * under any possible substitution of the unspecified parameters (if any).
+ * @param pS1 the fixed value of pattern parameter S1, or null if not bound.
+ * @param pS2 the fixed value of pattern parameter S2, or null if not bound.
+ * @return true if the input is a valid (partial) match of the pattern.
+ *
+ */
+ public boolean hasMatch(final Segment pS1, final Segment pS2) {
+ return rawHasMatch(new Object[]{pS1, pS2});
+ }
+
+ /**
+ * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
+ * @param pS1 the fixed value of pattern parameter S1, or null if not bound.
+ * @param pS2 the fixed value of pattern parameter S2, or null if not bound.
+ * @return the number of pattern matches found.
+ *
+ */
+ public int countMatches(final Segment pS1, final Segment pS2) {
+ return rawCountMatches(new Object[]{pS1, pS2});
+ }
+
+ /**
+ * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
+ * Neither determinism nor randomness of selection is guaranteed.
+ * @param pS1 the fixed value of pattern parameter S1, or null if not bound.
+ * @param pS2 the fixed value of pattern parameter S2, or null if not bound.
+ * @param processor the action that will process the selected match.
+ * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
+ *
+ */
+ public boolean forOneArbitraryMatch(final Segment pS1, final Segment pS2, final Consumer super Adjacent.Match> processor) {
+ return rawForOneArbitraryMatch(new Object[]{pS1, pS2}, processor);
+ }
+
+ /**
+ * Returns a new (partial) match.
+ * This can be used e.g. to call the matcher with a partial match.
+ *
The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
+ * @param pS1 the fixed value of pattern parameter S1, or null if not bound.
+ * @param pS2 the fixed value of pattern parameter S2, or null if not bound.
+ * @return the (partial) match object.
+ *
+ */
+ public Adjacent.Match newMatch(final Segment pS1, final Segment pS2) {
+ return Adjacent.Match.newMatch(pS1, pS2);
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S1.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ protected Stream rawStreamAllValuesOfS1(final Object[] parameters) {
+ return rawStreamAllValues(POSITION_S1, parameters).map(Segment.class::cast);
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S1.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Set getAllValuesOfS1() {
+ return rawStreamAllValuesOfS1(emptyArray()).collect(Collectors.toSet());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S1.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Stream streamAllValuesOfS1() {
+ return rawStreamAllValuesOfS1(emptyArray());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S1.
+ *
+ * NOTE: It is important not to modify the source model while the stream is being processed.
+ * If the match set of the pattern changes during processing, the contents of the stream is undefined.
+ * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
+ *
+ * @return the Stream of all values or empty set if there are no matches
+ *
+ */
+ public Stream streamAllValuesOfS1(final Adjacent.Match partialMatch) {
+ return rawStreamAllValuesOfS1(partialMatch.toArray());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S1.
+ *
+ * NOTE: It is important not to modify the source model while the stream is being processed.
+ * If the match set of the pattern changes during processing, the contents of the stream is undefined.
+ * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
+ *
+ * @return the Stream of all values or empty set if there are no matches
+ *
+ */
+ public Stream streamAllValuesOfS1(final Segment pS2) {
+ return rawStreamAllValuesOfS1(new Object[]{null, pS2});
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S1.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Set getAllValuesOfS1(final Adjacent.Match partialMatch) {
+ return rawStreamAllValuesOfS1(partialMatch.toArray()).collect(Collectors.toSet());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S1.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Set getAllValuesOfS1(final Segment pS2) {
+ return rawStreamAllValuesOfS1(new Object[]{null, pS2}).collect(Collectors.toSet());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S2.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ protected Stream rawStreamAllValuesOfS2(final Object[] parameters) {
+ return rawStreamAllValues(POSITION_S2, parameters).map(Segment.class::cast);
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S2.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Set getAllValuesOfS2() {
+ return rawStreamAllValuesOfS2(emptyArray()).collect(Collectors.toSet());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S2.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Stream streamAllValuesOfS2() {
+ return rawStreamAllValuesOfS2(emptyArray());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S2.
+ *
+ * NOTE: It is important not to modify the source model while the stream is being processed.
+ * If the match set of the pattern changes during processing, the contents of the stream is undefined.
+ * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
+ *
+ * @return the Stream of all values or empty set if there are no matches
+ *
+ */
+ public Stream streamAllValuesOfS2(final Adjacent.Match partialMatch) {
+ return rawStreamAllValuesOfS2(partialMatch.toArray());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S2.
+ *
+ * NOTE: It is important not to modify the source model while the stream is being processed.
+ * If the match set of the pattern changes during processing, the contents of the stream is undefined.
+ * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
+ *
+ * @return the Stream of all values or empty set if there are no matches
+ *
+ */
+ public Stream streamAllValuesOfS2(final Segment pS1) {
+ return rawStreamAllValuesOfS2(new Object[]{pS1, null});
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S2.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Set getAllValuesOfS2(final Adjacent.Match partialMatch) {
+ return rawStreamAllValuesOfS2(partialMatch.toArray()).collect(Collectors.toSet());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S2.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Set getAllValuesOfS2(final Segment pS1) {
+ return rawStreamAllValuesOfS2(new Object[]{pS1, null}).collect(Collectors.toSet());
+ }
+
+ @Override
+ protected Adjacent.Match tupleToMatch(final Tuple t) {
+ try {
+ return Adjacent.Match.newMatch((Segment) t.get(POSITION_S1), (Segment) t.get(POSITION_S2));
+ } catch(ClassCastException e) {
+ LOGGER.error("Element(s) in tuple not properly typed!",e);
+ return null;
+ }
+ }
+
+ @Override
+ protected Adjacent.Match arrayToMatch(final Object[] match) {
+ try {
+ return Adjacent.Match.newMatch((Segment) match[POSITION_S1], (Segment) match[POSITION_S2]);
+ } catch(ClassCastException e) {
+ LOGGER.error("Element(s) in array not properly typed!",e);
+ return null;
+ }
+ }
+
+ @Override
+ protected Adjacent.Match arrayToMatchMutable(final Object[] match) {
+ try {
+ return Adjacent.Match.newMutableMatch((Segment) match[POSITION_S1], (Segment) match[POSITION_S2]);
+ } catch(ClassCastException e) {
+ LOGGER.error("Element(s) in array not properly typed!",e);
+ return null;
+ }
+ }
+
+ /**
+ * @return the singleton instance of the query specification of this pattern
+ * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
+ *
+ */
+ public static IQuerySpecification querySpecification() {
+ return Adjacent.instance();
+ }
+ }
+
+ private Adjacent() {
+ super(GeneratedPQuery.INSTANCE);
+ }
+
+ /**
+ * @return the singleton instance of the query specification
+ * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
+ *
+ */
+ public static Adjacent instance() {
+ try{
+ return LazyHolder.INSTANCE;
+ } catch (ExceptionInInitializerError err) {
+ throw processInitializerError(err);
+ }
+ }
+
+ @Override
+ protected Adjacent.Matcher instantiate(final ViatraQueryEngine engine) {
+ return Adjacent.Matcher.on(engine);
+ }
+
+ @Override
+ public Adjacent.Matcher instantiate() {
+ return Adjacent.Matcher.create();
+ }
+
+ @Override
+ public Adjacent.Match newEmptyMatch() {
+ return Adjacent.Match.newEmptyMatch();
+ }
+
+ @Override
+ public Adjacent.Match newMatch(final Object... parameters) {
+ return Adjacent.Match.newMatch((modes3.Segment) parameters[0], (modes3.Segment) parameters[1]);
+ }
+
+ /**
+ * Inner class allowing the singleton instance of {@link Adjacent} to be created
+ * not at the class load time of the outer class,
+ * but rather at the first call to {@link Adjacent#instance()}.
+ *
+ *
This workaround is required e.g. to support recursion.
+ *
+ */
+ private static class LazyHolder {
+ private static final Adjacent INSTANCE = new Adjacent();
+
+ /**
+ * Statically initializes the query specification after the field {@link #INSTANCE} is assigned.
+ * This initialization order is required to support indirect recursion.
+ *
+ *
The static initializer is defined using a helper field to work around limitations of the code generator.
+ *
+ */
+ private static final Object STATIC_INITIALIZER = ensureInitialized();
+
+ public static Object ensureInitialized() {
+ INSTANCE.ensureInitializedInternal();
+ return null;
+ }
+ }
+
+ private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
+ private static final Adjacent.GeneratedPQuery INSTANCE = new GeneratedPQuery();
+
+ private final PParameter parameter_S1 = new PParameter("S1", "modes3.Segment", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Segment")), PParameterDirection.INOUT);
+
+ private final PParameter parameter_S2 = new PParameter("S2", "modes3.Segment", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Segment")), PParameterDirection.INOUT);
+
+ private final List parameters = Arrays.asList(parameter_S1, parameter_S2);
+
+ private GeneratedPQuery() {
+ super(PVisibility.PUBLIC);
+ }
+
+ @Override
+ public String getFullyQualifiedName() {
+ return "modes3.queries.adjacent";
+ }
+
+ @Override
+ public List getParameterNames() {
+ return Arrays.asList("S1","S2");
+ }
+
+ @Override
+ public List getParameters() {
+ return parameters;
+ }
+
+ @Override
+ public Set doGetContainedBodies() {
+ setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
+ Set bodies = new LinkedHashSet<>();
+ {
+ PBody body = new PBody(this);
+ PVariable var_S1 = body.getOrCreateVariableByName("S1");
+ PVariable var_S2 = body.getOrCreateVariableByName("S2");
+ new TypeConstraint(body, Tuples.flatTupleOf(var_S1), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
+ new TypeConstraint(body, Tuples.flatTupleOf(var_S2), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
+ body.setSymbolicParameters(Arrays.asList(
+ new ExportedParameter(body, var_S1, parameter_S1),
+ new ExportedParameter(body, var_S2, parameter_S2)
+ ));
+ // find output(S1, S2)
+ new PositivePatternCall(body, Tuples.flatTupleOf(var_S1, var_S2), Output.instance().getInternalQueryRepresentation());
+ bodies.add(body);
+ }
+ {
+ PBody body = new PBody(this);
+ PVariable var_S1 = body.getOrCreateVariableByName("S1");
+ PVariable var_S2 = body.getOrCreateVariableByName("S2");
+ new TypeConstraint(body, Tuples.flatTupleOf(var_S1), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
+ new TypeConstraint(body, Tuples.flatTupleOf(var_S2), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
+ body.setSymbolicParameters(Arrays.asList(
+ new ExportedParameter(body, var_S1, parameter_S1),
+ new ExportedParameter(body, var_S2, parameter_S2)
+ ));
+ // find turnoutOutput(S2, S1)
+ new PositivePatternCall(body, Tuples.flatTupleOf(var_S2, var_S1), TurnoutOutput.instance().getInternalQueryRepresentation());
+ bodies.add(body);
+ }
+ return bodies;
+ }
+ }
+}
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 @@
+/**
+ * Generated from platform:/resource/ca.mcgill.rtgmrt.example.modes3/src/modes3/queries/Modes3Queries.vql
+ */
+package modes3.queries;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+import java.util.function.Consumer;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import modes3.Segment;
+import org.apache.log4j.Logger;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.viatra.query.runtime.api.IPatternMatch;
+import org.eclipse.viatra.query.runtime.api.IQuerySpecification;
+import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine;
+import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
+import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification;
+import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher;
+import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch;
+import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey;
+import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey;
+import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
+import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
+import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality;
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
+import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
+import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
+import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
+import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
+import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
+import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
+
+/**
+ * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
+ *
+ *
+ *
+ * @see Matcher
+ * @see Match
+ *
+ */
+@SuppressWarnings("all")
+public final class ConnectedTo extends BaseGeneratedEMFQuerySpecification {
+ /**
+ * Pattern-specific match representation of the modes3.queries.connectedTo pattern,
+ * to be used in conjunction with {@link Matcher}.
+ *
+ *
Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
+ * Each instance is a (possibly partial) substitution of pattern parameters,
+ * usable to represent a match of the pattern in the result of a query,
+ * or to specify the bound (fixed) input parameters when issuing a query.
+ *
+ * @see Matcher
+ *
+ */
+ public static abstract class Match extends BasePatternMatch {
+ private Segment fS1;
+
+ private Segment fS2;
+
+ private static List parameterNames = makeImmutableList("S1", "S2");
+
+ private Match(final Segment pS1, final Segment pS2) {
+ this.fS1 = pS1;
+ this.fS2 = pS2;
+ }
+
+ @Override
+ public Object get(final String parameterName) {
+ switch(parameterName) {
+ case "S1": return this.fS1;
+ case "S2": return this.fS2;
+ default: return null;
+ }
+ }
+
+ @Override
+ public Object get(final int index) {
+ switch(index) {
+ case 0: return this.fS1;
+ case 1: return this.fS2;
+ default: return null;
+ }
+ }
+
+ public Segment getS1() {
+ return this.fS1;
+ }
+
+ public Segment getS2() {
+ return this.fS2;
+ }
+
+ @Override
+ public boolean set(final String parameterName, final Object newValue) {
+ if (!isMutable()) throw new java.lang.UnsupportedOperationException();
+ if ("S1".equals(parameterName) ) {
+ this.fS1 = (Segment) newValue;
+ return true;
+ }
+ if ("S2".equals(parameterName) ) {
+ this.fS2 = (Segment) newValue;
+ return true;
+ }
+ return false;
+ }
+
+ public void setS1(final Segment pS1) {
+ if (!isMutable()) throw new java.lang.UnsupportedOperationException();
+ this.fS1 = pS1;
+ }
+
+ public void setS2(final Segment pS2) {
+ if (!isMutable()) throw new java.lang.UnsupportedOperationException();
+ this.fS2 = pS2;
+ }
+
+ @Override
+ public String patternName() {
+ return "modes3.queries.connectedTo";
+ }
+
+ @Override
+ public List parameterNames() {
+ return ConnectedTo.Match.parameterNames;
+ }
+
+ @Override
+ public Object[] toArray() {
+ return new Object[]{fS1, fS2};
+ }
+
+ @Override
+ public ConnectedTo.Match toImmutable() {
+ return isMutable() ? newMatch(fS1, fS2) : this;
+ }
+
+ @Override
+ public String prettyPrint() {
+ StringBuilder result = new StringBuilder();
+ result.append("\"S1\"=" + prettyPrintValue(fS1) + ", ");
+ result.append("\"S2\"=" + prettyPrintValue(fS2));
+ return result.toString();
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(fS1, fS2);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null) {
+ return false;
+ }
+ if ((obj instanceof ConnectedTo.Match)) {
+ ConnectedTo.Match other = (ConnectedTo.Match) obj;
+ return Objects.equals(fS1, other.fS1) && Objects.equals(fS2, other.fS2);
+ } else {
+ // this should be infrequent
+ if (!(obj instanceof IPatternMatch)) {
+ return false;
+ }
+ IPatternMatch otherSig = (IPatternMatch) obj;
+ return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
+ }
+ }
+
+ @Override
+ public ConnectedTo specification() {
+ return ConnectedTo.instance();
+ }
+
+ /**
+ * Returns an empty, mutable match.
+ * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
+ *
+ * @return the empty match.
+ *
+ */
+ public static ConnectedTo.Match newEmptyMatch() {
+ return new Mutable(null, null);
+ }
+
+ /**
+ * Returns a mutable (partial) match.
+ * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
+ *
+ * @param pS1 the fixed value of pattern parameter S1, or null if not bound.
+ * @param pS2 the fixed value of pattern parameter S2, or null if not bound.
+ * @return the new, mutable (partial) match object.
+ *
+ */
+ public static ConnectedTo.Match newMutableMatch(final Segment pS1, final Segment pS2) {
+ return new Mutable(pS1, pS2);
+ }
+
+ /**
+ * Returns a new (partial) match.
+ * This can be used e.g. to call the matcher with a partial match.
+ *
The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
+ * @param pS1 the fixed value of pattern parameter S1, or null if not bound.
+ * @param pS2 the fixed value of pattern parameter S2, or null if not bound.
+ * @return the (partial) match object.
+ *
+ */
+ public static ConnectedTo.Match newMatch(final Segment pS1, final Segment pS2) {
+ return new Immutable(pS1, pS2);
+ }
+
+ private static final class Mutable extends ConnectedTo.Match {
+ Mutable(final Segment pS1, final Segment pS2) {
+ super(pS1, pS2);
+ }
+
+ @Override
+ public boolean isMutable() {
+ return true;
+ }
+ }
+
+ private static final class Immutable extends ConnectedTo.Match {
+ Immutable(final Segment pS1, final Segment pS2) {
+ super(pS1, pS2);
+ }
+
+ @Override
+ public boolean isMutable() {
+ return false;
+ }
+ }
+ }
+
+ /**
+ * Generated pattern matcher API of the modes3.queries.connectedTo pattern,
+ * providing pattern-specific query methods.
+ *
+ *
Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
+ * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
+ *
+ *
Matches of the pattern will be represented as {@link Match}.
+ *
+ *
+ *
+ * @see Match
+ * @see ConnectedTo
+ *
+ */
+ public static class Matcher extends BaseMatcher {
+ /**
+ * Initializes the pattern matcher within an existing VIATRA Query engine.
+ * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
+ *
+ * @param engine the existing VIATRA Query engine in which this matcher will be created.
+ * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
+ *
+ */
+ public static ConnectedTo.Matcher on(final ViatraQueryEngine engine) {
+ // check if matcher already exists
+ Matcher matcher = engine.getExistingMatcher(querySpecification());
+ if (matcher == null) {
+ matcher = (Matcher)engine.getMatcher(querySpecification());
+ }
+ return matcher;
+ }
+
+ /**
+ * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
+ * @return an initialized matcher
+ * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
+ *
+ */
+ public static ConnectedTo.Matcher create() {
+ return new Matcher();
+ }
+
+ private static final int POSITION_S1 = 0;
+
+ private static final int POSITION_S2 = 1;
+
+ private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(ConnectedTo.Matcher.class);
+
+ /**
+ * Initializes the pattern matcher within an existing VIATRA Query engine.
+ * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
+ *
+ * @param engine the existing VIATRA Query engine in which this matcher will be created.
+ * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
+ *
+ */
+ private Matcher() {
+ super(querySpecification());
+ }
+
+ /**
+ * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
+ * @param pS1 the fixed value of pattern parameter S1, or null if not bound.
+ * @param pS2 the fixed value of pattern parameter S2, or null if not bound.
+ * @return matches represented as a Match object.
+ *
+ */
+ public Collection getAllMatches(final Segment pS1, final Segment pS2) {
+ return rawStreamAllMatches(new Object[]{pS1, pS2}).collect(Collectors.toSet());
+ }
+
+ /**
+ * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
+ *
+ * NOTE: It is important not to modify the source model while the stream is being processed.
+ * If the match set of the pattern changes during processing, the contents of the stream is undefined.
+ * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
+ * @param pS1 the fixed value of pattern parameter S1, or null if not bound.
+ * @param pS2 the fixed value of pattern parameter S2, or null if not bound.
+ * @return a stream of matches represented as a Match object.
+ *
+ */
+ public Stream streamAllMatches(final Segment pS1, final Segment pS2) {
+ return rawStreamAllMatches(new Object[]{pS1, pS2});
+ }
+
+ /**
+ * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
+ * Neither determinism nor randomness of selection is guaranteed.
+ * @param pS1 the fixed value of pattern parameter S1, or null if not bound.
+ * @param pS2 the fixed value of pattern parameter S2, or null if not bound.
+ * @return a match represented as a Match object, or null if no match is found.
+ *
+ */
+ public Optional getOneArbitraryMatch(final Segment pS1, final Segment pS2) {
+ return rawGetOneArbitraryMatch(new Object[]{pS1, pS2});
+ }
+
+ /**
+ * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
+ * under any possible substitution of the unspecified parameters (if any).
+ * @param pS1 the fixed value of pattern parameter S1, or null if not bound.
+ * @param pS2 the fixed value of pattern parameter S2, or null if not bound.
+ * @return true if the input is a valid (partial) match of the pattern.
+ *
+ */
+ public boolean hasMatch(final Segment pS1, final Segment pS2) {
+ return rawHasMatch(new Object[]{pS1, pS2});
+ }
+
+ /**
+ * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
+ * @param pS1 the fixed value of pattern parameter S1, or null if not bound.
+ * @param pS2 the fixed value of pattern parameter S2, or null if not bound.
+ * @return the number of pattern matches found.
+ *
+ */
+ public int countMatches(final Segment pS1, final Segment pS2) {
+ return rawCountMatches(new Object[]{pS1, pS2});
+ }
+
+ /**
+ * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
+ * Neither determinism nor randomness of selection is guaranteed.
+ * @param pS1 the fixed value of pattern parameter S1, or null if not bound.
+ * @param pS2 the fixed value of pattern parameter S2, or null if not bound.
+ * @param processor the action that will process the selected match.
+ * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
+ *
+ */
+ public boolean forOneArbitraryMatch(final Segment pS1, final Segment pS2, final Consumer super ConnectedTo.Match> processor) {
+ return rawForOneArbitraryMatch(new Object[]{pS1, pS2}, processor);
+ }
+
+ /**
+ * Returns a new (partial) match.
+ * This can be used e.g. to call the matcher with a partial match.
+ *
The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
+ * @param pS1 the fixed value of pattern parameter S1, or null if not bound.
+ * @param pS2 the fixed value of pattern parameter S2, or null if not bound.
+ * @return the (partial) match object.
+ *
+ */
+ public ConnectedTo.Match newMatch(final Segment pS1, final Segment pS2) {
+ return ConnectedTo.Match.newMatch(pS1, pS2);
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S1.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ protected Stream rawStreamAllValuesOfS1(final Object[] parameters) {
+ return rawStreamAllValues(POSITION_S1, parameters).map(Segment.class::cast);
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S1.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Set getAllValuesOfS1() {
+ return rawStreamAllValuesOfS1(emptyArray()).collect(Collectors.toSet());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S1.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Stream streamAllValuesOfS1() {
+ return rawStreamAllValuesOfS1(emptyArray());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S1.
+ *
+ * NOTE: It is important not to modify the source model while the stream is being processed.
+ * If the match set of the pattern changes during processing, the contents of the stream is undefined.
+ * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
+ *
+ * @return the Stream of all values or empty set if there are no matches
+ *
+ */
+ public Stream streamAllValuesOfS1(final ConnectedTo.Match partialMatch) {
+ return rawStreamAllValuesOfS1(partialMatch.toArray());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S1.
+ *
+ * NOTE: It is important not to modify the source model while the stream is being processed.
+ * If the match set of the pattern changes during processing, the contents of the stream is undefined.
+ * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
+ *
+ * @return the Stream of all values or empty set if there are no matches
+ *
+ */
+ public Stream streamAllValuesOfS1(final Segment pS2) {
+ return rawStreamAllValuesOfS1(new Object[]{null, pS2});
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S1.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Set getAllValuesOfS1(final ConnectedTo.Match partialMatch) {
+ return rawStreamAllValuesOfS1(partialMatch.toArray()).collect(Collectors.toSet());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S1.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Set getAllValuesOfS1(final Segment pS2) {
+ return rawStreamAllValuesOfS1(new Object[]{null, pS2}).collect(Collectors.toSet());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S2.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ protected Stream rawStreamAllValuesOfS2(final Object[] parameters) {
+ return rawStreamAllValues(POSITION_S2, parameters).map(Segment.class::cast);
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S2.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Set getAllValuesOfS2() {
+ return rawStreamAllValuesOfS2(emptyArray()).collect(Collectors.toSet());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S2.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Stream streamAllValuesOfS2() {
+ return rawStreamAllValuesOfS2(emptyArray());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S2.
+ *
+ * NOTE: It is important not to modify the source model while the stream is being processed.
+ * If the match set of the pattern changes during processing, the contents of the stream is undefined.
+ * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
+ *
+ * @return the Stream of all values or empty set if there are no matches
+ *
+ */
+ public Stream streamAllValuesOfS2(final ConnectedTo.Match partialMatch) {
+ return rawStreamAllValuesOfS2(partialMatch.toArray());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S2.
+ *
+ * NOTE: It is important not to modify the source model while the stream is being processed.
+ * If the match set of the pattern changes during processing, the contents of the stream is undefined.
+ * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
+ *
+ * @return the Stream of all values or empty set if there are no matches
+ *
+ */
+ public Stream streamAllValuesOfS2(final Segment pS1) {
+ return rawStreamAllValuesOfS2(new Object[]{pS1, null});
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S2.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Set getAllValuesOfS2(final ConnectedTo.Match partialMatch) {
+ return rawStreamAllValuesOfS2(partialMatch.toArray()).collect(Collectors.toSet());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S2.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Set getAllValuesOfS2(final Segment pS1) {
+ return rawStreamAllValuesOfS2(new Object[]{pS1, null}).collect(Collectors.toSet());
+ }
+
+ @Override
+ protected ConnectedTo.Match tupleToMatch(final Tuple t) {
+ try {
+ return ConnectedTo.Match.newMatch((Segment) t.get(POSITION_S1), (Segment) t.get(POSITION_S2));
+ } catch(ClassCastException e) {
+ LOGGER.error("Element(s) in tuple not properly typed!",e);
+ return null;
+ }
+ }
+
+ @Override
+ protected ConnectedTo.Match arrayToMatch(final Object[] match) {
+ try {
+ return ConnectedTo.Match.newMatch((Segment) match[POSITION_S1], (Segment) match[POSITION_S2]);
+ } catch(ClassCastException e) {
+ LOGGER.error("Element(s) in array not properly typed!",e);
+ return null;
+ }
+ }
+
+ @Override
+ protected ConnectedTo.Match arrayToMatchMutable(final Object[] match) {
+ try {
+ return ConnectedTo.Match.newMutableMatch((Segment) match[POSITION_S1], (Segment) match[POSITION_S2]);
+ } catch(ClassCastException e) {
+ LOGGER.error("Element(s) in array not properly typed!",e);
+ return null;
+ }
+ }
+
+ /**
+ * @return the singleton instance of the query specification of this pattern
+ * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
+ *
+ */
+ public static IQuerySpecification querySpecification() {
+ return ConnectedTo.instance();
+ }
+ }
+
+ private ConnectedTo() {
+ super(GeneratedPQuery.INSTANCE);
+ }
+
+ /**
+ * @return the singleton instance of the query specification
+ * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
+ *
+ */
+ public static ConnectedTo instance() {
+ try{
+ return LazyHolder.INSTANCE;
+ } catch (ExceptionInInitializerError err) {
+ throw processInitializerError(err);
+ }
+ }
+
+ @Override
+ protected ConnectedTo.Matcher instantiate(final ViatraQueryEngine engine) {
+ return ConnectedTo.Matcher.on(engine);
+ }
+
+ @Override
+ public ConnectedTo.Matcher instantiate() {
+ return ConnectedTo.Matcher.create();
+ }
+
+ @Override
+ public ConnectedTo.Match newEmptyMatch() {
+ return ConnectedTo.Match.newEmptyMatch();
+ }
+
+ @Override
+ public ConnectedTo.Match newMatch(final Object... parameters) {
+ return ConnectedTo.Match.newMatch((modes3.Segment) parameters[0], (modes3.Segment) parameters[1]);
+ }
+
+ /**
+ * Inner class allowing the singleton instance of {@link ConnectedTo} to be created
+ * not at the class load time of the outer class,
+ * but rather at the first call to {@link ConnectedTo#instance()}.
+ *
+ *
This workaround is required e.g. to support recursion.
+ *
+ */
+ private static class LazyHolder {
+ private static final ConnectedTo INSTANCE = new ConnectedTo();
+
+ /**
+ * Statically initializes the query specification after the field {@link #INSTANCE} is assigned.
+ * This initialization order is required to support indirect recursion.
+ *
+ *
The static initializer is defined using a helper field to work around limitations of the code generator.
+ *
+ */
+ private static final Object STATIC_INITIALIZER = ensureInitialized();
+
+ public static Object ensureInitialized() {
+ INSTANCE.ensureInitializedInternal();
+ return null;
+ }
+ }
+
+ private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
+ private static final ConnectedTo.GeneratedPQuery INSTANCE = new GeneratedPQuery();
+
+ private final PParameter parameter_S1 = new PParameter("S1", "modes3.Segment", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Segment")), PParameterDirection.INOUT);
+
+ private final PParameter parameter_S2 = new PParameter("S2", "modes3.Segment", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Segment")), PParameterDirection.INOUT);
+
+ private final List parameters = Arrays.asList(parameter_S1, parameter_S2);
+
+ private GeneratedPQuery() {
+ super(PVisibility.PUBLIC);
+ }
+
+ @Override
+ public String getFullyQualifiedName() {
+ return "modes3.queries.connectedTo";
+ }
+
+ @Override
+ public List getParameterNames() {
+ return Arrays.asList("S1","S2");
+ }
+
+ @Override
+ public List getParameters() {
+ return parameters;
+ }
+
+ @Override
+ public Set doGetContainedBodies() {
+ setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
+ Set bodies = new LinkedHashSet<>();
+ {
+ PBody body = new PBody(this);
+ PVariable var_S1 = body.getOrCreateVariableByName("S1");
+ PVariable var_S2 = body.getOrCreateVariableByName("S2");
+ new TypeConstraint(body, Tuples.flatTupleOf(var_S1), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
+ new TypeConstraint(body, Tuples.flatTupleOf(var_S2), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
+ body.setSymbolicParameters(Arrays.asList(
+ new ExportedParameter(body, var_S1, parameter_S1),
+ new ExportedParameter(body, var_S2, parameter_S2)
+ ));
+ // Segment.connectedTo(S1, S2)
+ new TypeConstraint(body, Tuples.flatTupleOf(var_S1), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
+ PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
+ new TypeConstraint(body, Tuples.flatTupleOf(var_S1, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment", "connectedTo")));
+ new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
+ new Equality(body, var__virtual_0_, var_S2);
+ bodies.add(body);
+ }
+ return bodies;
+ }
+ }
+}
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 @@
+/**
+ * Generated from platform:/resource/ca.mcgill.rtgmrt.example.modes3/src/modes3/queries/Modes3Queries.vql
+ */
+package modes3.queries;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+import java.util.function.Consumer;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import modes3.Segment;
+import modes3.queries.ConnectedTo;
+import org.apache.log4j.Logger;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.viatra.query.runtime.api.IPatternMatch;
+import org.eclipse.viatra.query.runtime.api.IQuerySpecification;
+import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine;
+import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
+import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification;
+import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher;
+import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch;
+import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey;
+import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey;
+import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
+import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
+import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
+import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation;
+import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference;
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality;
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.NegativePatternCall;
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
+import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
+import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
+import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
+import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
+import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
+import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
+
+/**
+ * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
+ *
+ *
+ *
+ * @see Matcher
+ * @see Match
+ *
+ */
+@SuppressWarnings("all")
+public final class ConnectedToNotSymmetric extends BaseGeneratedEMFQuerySpecification {
+ /**
+ * Pattern-specific match representation of the modes3.queries.connectedToNotSymmetric pattern,
+ * to be used in conjunction with {@link Matcher}.
+ *
+ *
Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
+ * Each instance is a (possibly partial) substitution of pattern parameters,
+ * usable to represent a match of the pattern in the result of a query,
+ * or to specify the bound (fixed) input parameters when issuing a query.
+ *
+ * @see Matcher
+ *
+ */
+ public static abstract class Match extends BasePatternMatch {
+ private Segment fS1;
+
+ private Segment fS2;
+
+ private static List parameterNames = makeImmutableList("S1", "S2");
+
+ private Match(final Segment pS1, final Segment pS2) {
+ this.fS1 = pS1;
+ this.fS2 = pS2;
+ }
+
+ @Override
+ public Object get(final String parameterName) {
+ switch(parameterName) {
+ case "S1": return this.fS1;
+ case "S2": return this.fS2;
+ default: return null;
+ }
+ }
+
+ @Override
+ public Object get(final int index) {
+ switch(index) {
+ case 0: return this.fS1;
+ case 1: return this.fS2;
+ default: return null;
+ }
+ }
+
+ public Segment getS1() {
+ return this.fS1;
+ }
+
+ public Segment getS2() {
+ return this.fS2;
+ }
+
+ @Override
+ public boolean set(final String parameterName, final Object newValue) {
+ if (!isMutable()) throw new java.lang.UnsupportedOperationException();
+ if ("S1".equals(parameterName) ) {
+ this.fS1 = (Segment) newValue;
+ return true;
+ }
+ if ("S2".equals(parameterName) ) {
+ this.fS2 = (Segment) newValue;
+ return true;
+ }
+ return false;
+ }
+
+ public void setS1(final Segment pS1) {
+ if (!isMutable()) throw new java.lang.UnsupportedOperationException();
+ this.fS1 = pS1;
+ }
+
+ public void setS2(final Segment pS2) {
+ if (!isMutable()) throw new java.lang.UnsupportedOperationException();
+ this.fS2 = pS2;
+ }
+
+ @Override
+ public String patternName() {
+ return "modes3.queries.connectedToNotSymmetric";
+ }
+
+ @Override
+ public List parameterNames() {
+ return ConnectedToNotSymmetric.Match.parameterNames;
+ }
+
+ @Override
+ public Object[] toArray() {
+ return new Object[]{fS1, fS2};
+ }
+
+ @Override
+ public ConnectedToNotSymmetric.Match toImmutable() {
+ return isMutable() ? newMatch(fS1, fS2) : this;
+ }
+
+ @Override
+ public String prettyPrint() {
+ StringBuilder result = new StringBuilder();
+ result.append("\"S1\"=" + prettyPrintValue(fS1) + ", ");
+ result.append("\"S2\"=" + prettyPrintValue(fS2));
+ return result.toString();
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(fS1, fS2);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null) {
+ return false;
+ }
+ if ((obj instanceof ConnectedToNotSymmetric.Match)) {
+ ConnectedToNotSymmetric.Match other = (ConnectedToNotSymmetric.Match) obj;
+ return Objects.equals(fS1, other.fS1) && Objects.equals(fS2, other.fS2);
+ } else {
+ // this should be infrequent
+ if (!(obj instanceof IPatternMatch)) {
+ return false;
+ }
+ IPatternMatch otherSig = (IPatternMatch) obj;
+ return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
+ }
+ }
+
+ @Override
+ public ConnectedToNotSymmetric specification() {
+ return ConnectedToNotSymmetric.instance();
+ }
+
+ /**
+ * Returns an empty, mutable match.
+ * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
+ *
+ * @return the empty match.
+ *
+ */
+ public static ConnectedToNotSymmetric.Match newEmptyMatch() {
+ return new Mutable(null, null);
+ }
+
+ /**
+ * Returns a mutable (partial) match.
+ * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
+ *
+ * @param pS1 the fixed value of pattern parameter S1, or null if not bound.
+ * @param pS2 the fixed value of pattern parameter S2, or null if not bound.
+ * @return the new, mutable (partial) match object.
+ *
+ */
+ public static ConnectedToNotSymmetric.Match newMutableMatch(final Segment pS1, final Segment pS2) {
+ return new Mutable(pS1, pS2);
+ }
+
+ /**
+ * Returns a new (partial) match.
+ * This can be used e.g. to call the matcher with a partial match.
+ *
The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
+ * @param pS1 the fixed value of pattern parameter S1, or null if not bound.
+ * @param pS2 the fixed value of pattern parameter S2, or null if not bound.
+ * @return the (partial) match object.
+ *
+ */
+ public static ConnectedToNotSymmetric.Match newMatch(final Segment pS1, final Segment pS2) {
+ return new Immutable(pS1, pS2);
+ }
+
+ private static final class Mutable extends ConnectedToNotSymmetric.Match {
+ Mutable(final Segment pS1, final Segment pS2) {
+ super(pS1, pS2);
+ }
+
+ @Override
+ public boolean isMutable() {
+ return true;
+ }
+ }
+
+ private static final class Immutable extends ConnectedToNotSymmetric.Match {
+ Immutable(final Segment pS1, final Segment pS2) {
+ super(pS1, pS2);
+ }
+
+ @Override
+ public boolean isMutable() {
+ return false;
+ }
+ }
+ }
+
+ /**
+ * Generated pattern matcher API of the modes3.queries.connectedToNotSymmetric pattern,
+ * providing pattern-specific query methods.
+ *
+ *
Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
+ * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
+ *
+ *
Matches of the pattern will be represented as {@link Match}.
+ *
+ *
+ *
+ * @see Match
+ * @see ConnectedToNotSymmetric
+ *
+ */
+ public static class Matcher extends BaseMatcher {
+ /**
+ * Initializes the pattern matcher within an existing VIATRA Query engine.
+ * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
+ *
+ * @param engine the existing VIATRA Query engine in which this matcher will be created.
+ * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
+ *
+ */
+ public static ConnectedToNotSymmetric.Matcher on(final ViatraQueryEngine engine) {
+ // check if matcher already exists
+ Matcher matcher = engine.getExistingMatcher(querySpecification());
+ if (matcher == null) {
+ matcher = (Matcher)engine.getMatcher(querySpecification());
+ }
+ return matcher;
+ }
+
+ /**
+ * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
+ * @return an initialized matcher
+ * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
+ *
+ */
+ public static ConnectedToNotSymmetric.Matcher create() {
+ return new Matcher();
+ }
+
+ private static final int POSITION_S1 = 0;
+
+ private static final int POSITION_S2 = 1;
+
+ private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(ConnectedToNotSymmetric.Matcher.class);
+
+ /**
+ * Initializes the pattern matcher within an existing VIATRA Query engine.
+ * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
+ *
+ * @param engine the existing VIATRA Query engine in which this matcher will be created.
+ * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
+ *
+ */
+ private Matcher() {
+ super(querySpecification());
+ }
+
+ /**
+ * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
+ * @param pS1 the fixed value of pattern parameter S1, or null if not bound.
+ * @param pS2 the fixed value of pattern parameter S2, or null if not bound.
+ * @return matches represented as a Match object.
+ *
+ */
+ public Collection getAllMatches(final Segment pS1, final Segment pS2) {
+ return rawStreamAllMatches(new Object[]{pS1, pS2}).collect(Collectors.toSet());
+ }
+
+ /**
+ * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
+ *
+ * NOTE: It is important not to modify the source model while the stream is being processed.
+ * If the match set of the pattern changes during processing, the contents of the stream is undefined.
+ * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
+ * @param pS1 the fixed value of pattern parameter S1, or null if not bound.
+ * @param pS2 the fixed value of pattern parameter S2, or null if not bound.
+ * @return a stream of matches represented as a Match object.
+ *
+ */
+ public Stream streamAllMatches(final Segment pS1, final Segment pS2) {
+ return rawStreamAllMatches(new Object[]{pS1, pS2});
+ }
+
+ /**
+ * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
+ * Neither determinism nor randomness of selection is guaranteed.
+ * @param pS1 the fixed value of pattern parameter S1, or null if not bound.
+ * @param pS2 the fixed value of pattern parameter S2, or null if not bound.
+ * @return a match represented as a Match object, or null if no match is found.
+ *
+ */
+ public Optional getOneArbitraryMatch(final Segment pS1, final Segment pS2) {
+ return rawGetOneArbitraryMatch(new Object[]{pS1, pS2});
+ }
+
+ /**
+ * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
+ * under any possible substitution of the unspecified parameters (if any).
+ * @param pS1 the fixed value of pattern parameter S1, or null if not bound.
+ * @param pS2 the fixed value of pattern parameter S2, or null if not bound.
+ * @return true if the input is a valid (partial) match of the pattern.
+ *
+ */
+ public boolean hasMatch(final Segment pS1, final Segment pS2) {
+ return rawHasMatch(new Object[]{pS1, pS2});
+ }
+
+ /**
+ * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
+ * @param pS1 the fixed value of pattern parameter S1, or null if not bound.
+ * @param pS2 the fixed value of pattern parameter S2, or null if not bound.
+ * @return the number of pattern matches found.
+ *
+ */
+ public int countMatches(final Segment pS1, final Segment pS2) {
+ return rawCountMatches(new Object[]{pS1, pS2});
+ }
+
+ /**
+ * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
+ * Neither determinism nor randomness of selection is guaranteed.
+ * @param pS1 the fixed value of pattern parameter S1, or null if not bound.
+ * @param pS2 the fixed value of pattern parameter S2, or null if not bound.
+ * @param processor the action that will process the selected match.
+ * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
+ *
+ */
+ public boolean forOneArbitraryMatch(final Segment pS1, final Segment pS2, final Consumer super ConnectedToNotSymmetric.Match> processor) {
+ return rawForOneArbitraryMatch(new Object[]{pS1, pS2}, processor);
+ }
+
+ /**
+ * Returns a new (partial) match.
+ * This can be used e.g. to call the matcher with a partial match.
+ *
The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
+ * @param pS1 the fixed value of pattern parameter S1, or null if not bound.
+ * @param pS2 the fixed value of pattern parameter S2, or null if not bound.
+ * @return the (partial) match object.
+ *
+ */
+ public ConnectedToNotSymmetric.Match newMatch(final Segment pS1, final Segment pS2) {
+ return ConnectedToNotSymmetric.Match.newMatch(pS1, pS2);
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S1.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ protected Stream rawStreamAllValuesOfS1(final Object[] parameters) {
+ return rawStreamAllValues(POSITION_S1, parameters).map(Segment.class::cast);
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S1.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Set getAllValuesOfS1() {
+ return rawStreamAllValuesOfS1(emptyArray()).collect(Collectors.toSet());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S1.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Stream streamAllValuesOfS1() {
+ return rawStreamAllValuesOfS1(emptyArray());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S1.
+ *
+ * NOTE: It is important not to modify the source model while the stream is being processed.
+ * If the match set of the pattern changes during processing, the contents of the stream is undefined.
+ * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
+ *
+ * @return the Stream of all values or empty set if there are no matches
+ *
+ */
+ public Stream streamAllValuesOfS1(final ConnectedToNotSymmetric.Match partialMatch) {
+ return rawStreamAllValuesOfS1(partialMatch.toArray());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S1.
+ *
+ * NOTE: It is important not to modify the source model while the stream is being processed.
+ * If the match set of the pattern changes during processing, the contents of the stream is undefined.
+ * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
+ *
+ * @return the Stream of all values or empty set if there are no matches
+ *
+ */
+ public Stream streamAllValuesOfS1(final Segment pS2) {
+ return rawStreamAllValuesOfS1(new Object[]{null, pS2});
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S1.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Set getAllValuesOfS1(final ConnectedToNotSymmetric.Match partialMatch) {
+ return rawStreamAllValuesOfS1(partialMatch.toArray()).collect(Collectors.toSet());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S1.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Set getAllValuesOfS1(final Segment pS2) {
+ return rawStreamAllValuesOfS1(new Object[]{null, pS2}).collect(Collectors.toSet());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S2.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ protected Stream rawStreamAllValuesOfS2(final Object[] parameters) {
+ return rawStreamAllValues(POSITION_S2, parameters).map(Segment.class::cast);
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S2.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Set getAllValuesOfS2() {
+ return rawStreamAllValuesOfS2(emptyArray()).collect(Collectors.toSet());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S2.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Stream streamAllValuesOfS2() {
+ return rawStreamAllValuesOfS2(emptyArray());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S2.
+ *
+ * NOTE: It is important not to modify the source model while the stream is being processed.
+ * If the match set of the pattern changes during processing, the contents of the stream is undefined.
+ * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
+ *
+ * @return the Stream of all values or empty set if there are no matches
+ *
+ */
+ public Stream streamAllValuesOfS2(final ConnectedToNotSymmetric.Match partialMatch) {
+ return rawStreamAllValuesOfS2(partialMatch.toArray());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S2.
+ *
+ * NOTE: It is important not to modify the source model while the stream is being processed.
+ * If the match set of the pattern changes during processing, the contents of the stream is undefined.
+ * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
+ *
+ * @return the Stream of all values or empty set if there are no matches
+ *
+ */
+ public Stream streamAllValuesOfS2(final Segment pS1) {
+ return rawStreamAllValuesOfS2(new Object[]{pS1, null});
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S2.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Set getAllValuesOfS2(final ConnectedToNotSymmetric.Match partialMatch) {
+ return rawStreamAllValuesOfS2(partialMatch.toArray()).collect(Collectors.toSet());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S2.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Set getAllValuesOfS2(final Segment pS1) {
+ return rawStreamAllValuesOfS2(new Object[]{pS1, null}).collect(Collectors.toSet());
+ }
+
+ @Override
+ protected ConnectedToNotSymmetric.Match tupleToMatch(final Tuple t) {
+ try {
+ return ConnectedToNotSymmetric.Match.newMatch((Segment) t.get(POSITION_S1), (Segment) t.get(POSITION_S2));
+ } catch(ClassCastException e) {
+ LOGGER.error("Element(s) in tuple not properly typed!",e);
+ return null;
+ }
+ }
+
+ @Override
+ protected ConnectedToNotSymmetric.Match arrayToMatch(final Object[] match) {
+ try {
+ return ConnectedToNotSymmetric.Match.newMatch((Segment) match[POSITION_S1], (Segment) match[POSITION_S2]);
+ } catch(ClassCastException e) {
+ LOGGER.error("Element(s) in array not properly typed!",e);
+ return null;
+ }
+ }
+
+ @Override
+ protected ConnectedToNotSymmetric.Match arrayToMatchMutable(final Object[] match) {
+ try {
+ return ConnectedToNotSymmetric.Match.newMutableMatch((Segment) match[POSITION_S1], (Segment) match[POSITION_S2]);
+ } catch(ClassCastException e) {
+ LOGGER.error("Element(s) in array not properly typed!",e);
+ return null;
+ }
+ }
+
+ /**
+ * @return the singleton instance of the query specification of this pattern
+ * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
+ *
+ */
+ public static IQuerySpecification querySpecification() {
+ return ConnectedToNotSymmetric.instance();
+ }
+ }
+
+ private ConnectedToNotSymmetric() {
+ super(GeneratedPQuery.INSTANCE);
+ }
+
+ /**
+ * @return the singleton instance of the query specification
+ * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
+ *
+ */
+ public static ConnectedToNotSymmetric instance() {
+ try{
+ return LazyHolder.INSTANCE;
+ } catch (ExceptionInInitializerError err) {
+ throw processInitializerError(err);
+ }
+ }
+
+ @Override
+ protected ConnectedToNotSymmetric.Matcher instantiate(final ViatraQueryEngine engine) {
+ return ConnectedToNotSymmetric.Matcher.on(engine);
+ }
+
+ @Override
+ public ConnectedToNotSymmetric.Matcher instantiate() {
+ return ConnectedToNotSymmetric.Matcher.create();
+ }
+
+ @Override
+ public ConnectedToNotSymmetric.Match newEmptyMatch() {
+ return ConnectedToNotSymmetric.Match.newEmptyMatch();
+ }
+
+ @Override
+ public ConnectedToNotSymmetric.Match newMatch(final Object... parameters) {
+ return ConnectedToNotSymmetric.Match.newMatch((modes3.Segment) parameters[0], (modes3.Segment) parameters[1]);
+ }
+
+ /**
+ * Inner class allowing the singleton instance of {@link ConnectedToNotSymmetric} to be created
+ * not at the class load time of the outer class,
+ * but rather at the first call to {@link ConnectedToNotSymmetric#instance()}.
+ *
+ *
This workaround is required e.g. to support recursion.
+ *
+ */
+ private static class LazyHolder {
+ private static final ConnectedToNotSymmetric INSTANCE = new ConnectedToNotSymmetric();
+
+ /**
+ * Statically initializes the query specification after the field {@link #INSTANCE} is assigned.
+ * This initialization order is required to support indirect recursion.
+ *
+ *
The static initializer is defined using a helper field to work around limitations of the code generator.
+ *
+ */
+ private static final Object STATIC_INITIALIZER = ensureInitialized();
+
+ public static Object ensureInitialized() {
+ INSTANCE.ensureInitializedInternal();
+ return null;
+ }
+ }
+
+ private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
+ private static final ConnectedToNotSymmetric.GeneratedPQuery INSTANCE = new GeneratedPQuery();
+
+ private final PParameter parameter_S1 = new PParameter("S1", "modes3.Segment", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Segment")), PParameterDirection.INOUT);
+
+ private final PParameter parameter_S2 = new PParameter("S2", "modes3.Segment", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Segment")), PParameterDirection.INOUT);
+
+ private final List parameters = Arrays.asList(parameter_S1, parameter_S2);
+
+ private GeneratedPQuery() {
+ super(PVisibility.PUBLIC);
+ }
+
+ @Override
+ public String getFullyQualifiedName() {
+ return "modes3.queries.connectedToNotSymmetric";
+ }
+
+ @Override
+ public List getParameterNames() {
+ return Arrays.asList("S1","S2");
+ }
+
+ @Override
+ public List getParameters() {
+ return parameters;
+ }
+
+ @Override
+ public Set doGetContainedBodies() {
+ setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
+ Set bodies = new LinkedHashSet<>();
+ {
+ PBody body = new PBody(this);
+ PVariable var_S1 = body.getOrCreateVariableByName("S1");
+ PVariable var_S2 = body.getOrCreateVariableByName("S2");
+ new TypeConstraint(body, Tuples.flatTupleOf(var_S1), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
+ new TypeConstraint(body, Tuples.flatTupleOf(var_S2), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
+ body.setSymbolicParameters(Arrays.asList(
+ new ExportedParameter(body, var_S1, parameter_S1),
+ new ExportedParameter(body, var_S2, parameter_S2)
+ ));
+ // Segment.connectedTo(S1, S2)
+ new TypeConstraint(body, Tuples.flatTupleOf(var_S1), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
+ PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
+ new TypeConstraint(body, Tuples.flatTupleOf(var_S1, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment", "connectedTo")));
+ new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
+ new Equality(body, var__virtual_0_, var_S2);
+ // neg find connectedTo(S2, S1)
+ new NegativePatternCall(body, Tuples.flatTupleOf(var_S2, var_S1), ConnectedTo.instance().getInternalQueryRepresentation());
+ bodies.add(body);
+ }
+ {
+ PAnnotation annotation = new PAnnotation("Constraint");
+ annotation.addAttribute("message", "connectedToNotSymmetric");
+ annotation.addAttribute("severity", "error");
+ annotation.addAttribute("key", Arrays.asList(new Object[] {
+ new ParameterReference("S1"),
+ new ParameterReference("S2")
+ }));
+ addAnnotation(annotation);
+ }
+ return bodies;
+ }
+ }
+}
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 @@
+/**
+ * Generated from platform:/resource/ca.mcgill.rtgmrt.example.modes3/src/modes3/queries/Modes3Queries.vql
+ */
+package modes3.queries;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+import java.util.function.Consumer;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import modes3.Segment;
+import org.apache.log4j.Logger;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.viatra.query.runtime.api.IPatternMatch;
+import org.eclipse.viatra.query.runtime.api.IQuerySpecification;
+import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine;
+import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
+import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification;
+import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher;
+import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch;
+import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey;
+import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey;
+import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
+import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
+import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
+import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation;
+import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference;
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality;
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
+import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
+import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
+import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
+import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
+import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
+import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
+
+/**
+ * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
+ *
+ *
+ *
+ * @see Matcher
+ * @see Match
+ *
+ */
+@SuppressWarnings("all")
+public final class ConnectedToReflexive extends BaseGeneratedEMFQuerySpecification {
+ /**
+ * Pattern-specific match representation of the modes3.queries.connectedToReflexive pattern,
+ * to be used in conjunction with {@link Matcher}.
+ *
+ *
Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
+ * Each instance is a (possibly partial) substitution of pattern parameters,
+ * usable to represent a match of the pattern in the result of a query,
+ * or to specify the bound (fixed) input parameters when issuing a query.
+ *
+ * @see Matcher
+ *
+ */
+ public static abstract class Match extends BasePatternMatch {
+ private Segment fS;
+
+ private static List parameterNames = makeImmutableList("S");
+
+ private Match(final Segment pS) {
+ this.fS = pS;
+ }
+
+ @Override
+ public Object get(final String parameterName) {
+ switch(parameterName) {
+ case "S": return this.fS;
+ default: return null;
+ }
+ }
+
+ @Override
+ public Object get(final int index) {
+ switch(index) {
+ case 0: return this.fS;
+ default: return null;
+ }
+ }
+
+ public Segment getS() {
+ return this.fS;
+ }
+
+ @Override
+ public boolean set(final String parameterName, final Object newValue) {
+ if (!isMutable()) throw new java.lang.UnsupportedOperationException();
+ if ("S".equals(parameterName) ) {
+ this.fS = (Segment) newValue;
+ return true;
+ }
+ return false;
+ }
+
+ public void setS(final Segment pS) {
+ if (!isMutable()) throw new java.lang.UnsupportedOperationException();
+ this.fS = pS;
+ }
+
+ @Override
+ public String patternName() {
+ return "modes3.queries.connectedToReflexive";
+ }
+
+ @Override
+ public List parameterNames() {
+ return ConnectedToReflexive.Match.parameterNames;
+ }
+
+ @Override
+ public Object[] toArray() {
+ return new Object[]{fS};
+ }
+
+ @Override
+ public ConnectedToReflexive.Match toImmutable() {
+ return isMutable() ? newMatch(fS) : this;
+ }
+
+ @Override
+ public String prettyPrint() {
+ StringBuilder result = new StringBuilder();
+ result.append("\"S\"=" + prettyPrintValue(fS));
+ return result.toString();
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(fS);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null) {
+ return false;
+ }
+ if ((obj instanceof ConnectedToReflexive.Match)) {
+ ConnectedToReflexive.Match other = (ConnectedToReflexive.Match) obj;
+ return Objects.equals(fS, other.fS);
+ } else {
+ // this should be infrequent
+ if (!(obj instanceof IPatternMatch)) {
+ return false;
+ }
+ IPatternMatch otherSig = (IPatternMatch) obj;
+ return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
+ }
+ }
+
+ @Override
+ public ConnectedToReflexive specification() {
+ return ConnectedToReflexive.instance();
+ }
+
+ /**
+ * Returns an empty, mutable match.
+ * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
+ *
+ * @return the empty match.
+ *
+ */
+ public static ConnectedToReflexive.Match newEmptyMatch() {
+ return new Mutable(null);
+ }
+
+ /**
+ * Returns a mutable (partial) match.
+ * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
+ *
+ * @param pS the fixed value of pattern parameter S, or null if not bound.
+ * @return the new, mutable (partial) match object.
+ *
+ */
+ public static ConnectedToReflexive.Match newMutableMatch(final Segment pS) {
+ return new Mutable(pS);
+ }
+
+ /**
+ * Returns a new (partial) match.
+ * This can be used e.g. to call the matcher with a partial match.
+ *
The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
+ * @param pS the fixed value of pattern parameter S, or null if not bound.
+ * @return the (partial) match object.
+ *
+ */
+ public static ConnectedToReflexive.Match newMatch(final Segment pS) {
+ return new Immutable(pS);
+ }
+
+ private static final class Mutable extends ConnectedToReflexive.Match {
+ Mutable(final Segment pS) {
+ super(pS);
+ }
+
+ @Override
+ public boolean isMutable() {
+ return true;
+ }
+ }
+
+ private static final class Immutable extends ConnectedToReflexive.Match {
+ Immutable(final Segment pS) {
+ super(pS);
+ }
+
+ @Override
+ public boolean isMutable() {
+ return false;
+ }
+ }
+ }
+
+ /**
+ * Generated pattern matcher API of the modes3.queries.connectedToReflexive pattern,
+ * providing pattern-specific query methods.
+ *
+ *
Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
+ * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
+ *
+ *
Matches of the pattern will be represented as {@link Match}.
+ *
+ *
+ *
+ * @see Match
+ * @see ConnectedToReflexive
+ *
+ */
+ public static class Matcher extends BaseMatcher {
+ /**
+ * Initializes the pattern matcher within an existing VIATRA Query engine.
+ * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
+ *
+ * @param engine the existing VIATRA Query engine in which this matcher will be created.
+ * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
+ *
+ */
+ public static ConnectedToReflexive.Matcher on(final ViatraQueryEngine engine) {
+ // check if matcher already exists
+ Matcher matcher = engine.getExistingMatcher(querySpecification());
+ if (matcher == null) {
+ matcher = (Matcher)engine.getMatcher(querySpecification());
+ }
+ return matcher;
+ }
+
+ /**
+ * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
+ * @return an initialized matcher
+ * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
+ *
+ */
+ public static ConnectedToReflexive.Matcher create() {
+ return new Matcher();
+ }
+
+ private static final int POSITION_S = 0;
+
+ private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(ConnectedToReflexive.Matcher.class);
+
+ /**
+ * Initializes the pattern matcher within an existing VIATRA Query engine.
+ * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
+ *
+ * @param engine the existing VIATRA Query engine in which this matcher will be created.
+ * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
+ *
+ */
+ private Matcher() {
+ super(querySpecification());
+ }
+
+ /**
+ * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
+ * @param pS the fixed value of pattern parameter S, or null if not bound.
+ * @return matches represented as a Match object.
+ *
+ */
+ public Collection getAllMatches(final Segment pS) {
+ return rawStreamAllMatches(new Object[]{pS}).collect(Collectors.toSet());
+ }
+
+ /**
+ * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
+ *
+ * NOTE: It is important not to modify the source model while the stream is being processed.
+ * If the match set of the pattern changes during processing, the contents of the stream is undefined.
+ * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
+ * @param pS the fixed value of pattern parameter S, or null if not bound.
+ * @return a stream of matches represented as a Match object.
+ *
+ */
+ public Stream streamAllMatches(final Segment pS) {
+ return rawStreamAllMatches(new Object[]{pS});
+ }
+
+ /**
+ * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
+ * Neither determinism nor randomness of selection is guaranteed.
+ * @param pS the fixed value of pattern parameter S, or null if not bound.
+ * @return a match represented as a Match object, or null if no match is found.
+ *
+ */
+ public Optional getOneArbitraryMatch(final Segment pS) {
+ return rawGetOneArbitraryMatch(new Object[]{pS});
+ }
+
+ /**
+ * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
+ * under any possible substitution of the unspecified parameters (if any).
+ * @param pS the fixed value of pattern parameter S, or null if not bound.
+ * @return true if the input is a valid (partial) match of the pattern.
+ *
+ */
+ public boolean hasMatch(final Segment pS) {
+ return rawHasMatch(new Object[]{pS});
+ }
+
+ /**
+ * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
+ * @param pS the fixed value of pattern parameter S, or null if not bound.
+ * @return the number of pattern matches found.
+ *
+ */
+ public int countMatches(final Segment pS) {
+ return rawCountMatches(new Object[]{pS});
+ }
+
+ /**
+ * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
+ * Neither determinism nor randomness of selection is guaranteed.
+ * @param pS the fixed value of pattern parameter S, or null if not bound.
+ * @param processor the action that will process the selected match.
+ * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
+ *
+ */
+ public boolean forOneArbitraryMatch(final Segment pS, final Consumer super ConnectedToReflexive.Match> processor) {
+ return rawForOneArbitraryMatch(new Object[]{pS}, processor);
+ }
+
+ /**
+ * Returns a new (partial) match.
+ * This can be used e.g. to call the matcher with a partial match.
+ *
The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
+ * @param pS the fixed value of pattern parameter S, or null if not bound.
+ * @return the (partial) match object.
+ *
+ */
+ public ConnectedToReflexive.Match newMatch(final Segment pS) {
+ return ConnectedToReflexive.Match.newMatch(pS);
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ protected Stream rawStreamAllValuesOfS(final Object[] parameters) {
+ return rawStreamAllValues(POSITION_S, parameters).map(Segment.class::cast);
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Set getAllValuesOfS() {
+ return rawStreamAllValuesOfS(emptyArray()).collect(Collectors.toSet());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Stream streamAllValuesOfS() {
+ return rawStreamAllValuesOfS(emptyArray());
+ }
+
+ @Override
+ protected ConnectedToReflexive.Match tupleToMatch(final Tuple t) {
+ try {
+ return ConnectedToReflexive.Match.newMatch((Segment) t.get(POSITION_S));
+ } catch(ClassCastException e) {
+ LOGGER.error("Element(s) in tuple not properly typed!",e);
+ return null;
+ }
+ }
+
+ @Override
+ protected ConnectedToReflexive.Match arrayToMatch(final Object[] match) {
+ try {
+ return ConnectedToReflexive.Match.newMatch((Segment) match[POSITION_S]);
+ } catch(ClassCastException e) {
+ LOGGER.error("Element(s) in array not properly typed!",e);
+ return null;
+ }
+ }
+
+ @Override
+ protected ConnectedToReflexive.Match arrayToMatchMutable(final Object[] match) {
+ try {
+ return ConnectedToReflexive.Match.newMutableMatch((Segment) match[POSITION_S]);
+ } catch(ClassCastException e) {
+ LOGGER.error("Element(s) in array not properly typed!",e);
+ return null;
+ }
+ }
+
+ /**
+ * @return the singleton instance of the query specification of this pattern
+ * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
+ *
+ */
+ public static IQuerySpecification querySpecification() {
+ return ConnectedToReflexive.instance();
+ }
+ }
+
+ private ConnectedToReflexive() {
+ super(GeneratedPQuery.INSTANCE);
+ }
+
+ /**
+ * @return the singleton instance of the query specification
+ * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
+ *
+ */
+ public static ConnectedToReflexive instance() {
+ try{
+ return LazyHolder.INSTANCE;
+ } catch (ExceptionInInitializerError err) {
+ throw processInitializerError(err);
+ }
+ }
+
+ @Override
+ protected ConnectedToReflexive.Matcher instantiate(final ViatraQueryEngine engine) {
+ return ConnectedToReflexive.Matcher.on(engine);
+ }
+
+ @Override
+ public ConnectedToReflexive.Matcher instantiate() {
+ return ConnectedToReflexive.Matcher.create();
+ }
+
+ @Override
+ public ConnectedToReflexive.Match newEmptyMatch() {
+ return ConnectedToReflexive.Match.newEmptyMatch();
+ }
+
+ @Override
+ public ConnectedToReflexive.Match newMatch(final Object... parameters) {
+ return ConnectedToReflexive.Match.newMatch((modes3.Segment) parameters[0]);
+ }
+
+ /**
+ * Inner class allowing the singleton instance of {@link ConnectedToReflexive} to be created
+ * not at the class load time of the outer class,
+ * but rather at the first call to {@link ConnectedToReflexive#instance()}.
+ *
+ *
This workaround is required e.g. to support recursion.
+ *
+ */
+ private static class LazyHolder {
+ private static final ConnectedToReflexive INSTANCE = new ConnectedToReflexive();
+
+ /**
+ * Statically initializes the query specification after the field {@link #INSTANCE} is assigned.
+ * This initialization order is required to support indirect recursion.
+ *
+ *
The static initializer is defined using a helper field to work around limitations of the code generator.
+ *
+ */
+ private static final Object STATIC_INITIALIZER = ensureInitialized();
+
+ public static Object ensureInitialized() {
+ INSTANCE.ensureInitializedInternal();
+ return null;
+ }
+ }
+
+ private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
+ private static final ConnectedToReflexive.GeneratedPQuery INSTANCE = new GeneratedPQuery();
+
+ private final PParameter parameter_S = new PParameter("S", "modes3.Segment", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Segment")), PParameterDirection.INOUT);
+
+ private final List parameters = Arrays.asList(parameter_S);
+
+ private GeneratedPQuery() {
+ super(PVisibility.PUBLIC);
+ }
+
+ @Override
+ public String getFullyQualifiedName() {
+ return "modes3.queries.connectedToReflexive";
+ }
+
+ @Override
+ public List getParameterNames() {
+ return Arrays.asList("S");
+ }
+
+ @Override
+ public List getParameters() {
+ return parameters;
+ }
+
+ @Override
+ public Set doGetContainedBodies() {
+ setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
+ Set bodies = new LinkedHashSet<>();
+ {
+ PBody body = new PBody(this);
+ PVariable var_S = body.getOrCreateVariableByName("S");
+ new TypeConstraint(body, Tuples.flatTupleOf(var_S), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
+ body.setSymbolicParameters(Arrays.asList(
+ new ExportedParameter(body, var_S, parameter_S)
+ ));
+ // Segment.connectedTo(S, S)
+ new TypeConstraint(body, Tuples.flatTupleOf(var_S), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
+ PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
+ new TypeConstraint(body, Tuples.flatTupleOf(var_S, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment", "connectedTo")));
+ new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
+ new Equality(body, var__virtual_0_, var_S);
+ bodies.add(body);
+ }
+ {
+ PAnnotation annotation = new PAnnotation("Constraint");
+ annotation.addAttribute("message", "connectedToReflexive");
+ annotation.addAttribute("severity", "error");
+ annotation.addAttribute("key", Arrays.asList(new Object[] {
+ new ParameterReference("S")
+ }));
+ addAnnotation(annotation);
+ }
+ return bodies;
+ }
+ }
+}
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/ExtraInputOfTurnout.java b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/ExtraInputOfTurnout.java
new file mode 100644
index 00000000..62e2a54d
--- /dev/null
+++ b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/ExtraInputOfTurnout.java
@@ -0,0 +1,730 @@
+/**
+ * Generated from platform:/resource/ca.mcgill.rtgmrt.example.modes3/src/modes3/queries/Modes3Queries.vql
+ */
+package modes3.queries;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+import java.util.function.Consumer;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import modes3.Segment;
+import modes3.Turnout;
+import modes3.queries.Output;
+import org.apache.log4j.Logger;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.viatra.query.runtime.api.IPatternMatch;
+import org.eclipse.viatra.query.runtime.api.IQuerySpecification;
+import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine;
+import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
+import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification;
+import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher;
+import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch;
+import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey;
+import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey;
+import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
+import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
+import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality;
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Inequality;
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall;
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
+import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
+import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
+import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
+import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
+import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
+import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
+
+/**
+ * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
+ *
+ *
+ *
+ * @see Matcher
+ * @see Match
+ *
+ */
+@SuppressWarnings("all")
+public final class ExtraInputOfTurnout extends BaseGeneratedEMFQuerySpecification {
+ /**
+ * Pattern-specific match representation of the modes3.queries.extraInputOfTurnout pattern,
+ * to be used in conjunction with {@link Matcher}.
+ *
+ *
Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
+ * Each instance is a (possibly partial) substitution of pattern parameters,
+ * usable to represent a match of the pattern in the result of a query,
+ * or to specify the bound (fixed) input parameters when issuing a query.
+ *
+ * @see Matcher
+ *
+ */
+ public static abstract class Match extends BasePatternMatch {
+ private Turnout fT;
+
+ private Segment fS;
+
+ private static List parameterNames = makeImmutableList("T", "S");
+
+ private Match(final Turnout pT, final Segment pS) {
+ this.fT = pT;
+ this.fS = pS;
+ }
+
+ @Override
+ public Object get(final String parameterName) {
+ switch(parameterName) {
+ case "T": return this.fT;
+ case "S": return this.fS;
+ default: return null;
+ }
+ }
+
+ @Override
+ public Object get(final int index) {
+ switch(index) {
+ case 0: return this.fT;
+ case 1: return this.fS;
+ default: return null;
+ }
+ }
+
+ public Turnout getT() {
+ return this.fT;
+ }
+
+ public Segment getS() {
+ return this.fS;
+ }
+
+ @Override
+ public boolean set(final String parameterName, final Object newValue) {
+ if (!isMutable()) throw new java.lang.UnsupportedOperationException();
+ if ("T".equals(parameterName) ) {
+ this.fT = (Turnout) newValue;
+ return true;
+ }
+ if ("S".equals(parameterName) ) {
+ this.fS = (Segment) newValue;
+ return true;
+ }
+ return false;
+ }
+
+ public void setT(final Turnout pT) {
+ if (!isMutable()) throw new java.lang.UnsupportedOperationException();
+ this.fT = pT;
+ }
+
+ public void setS(final Segment pS) {
+ if (!isMutable()) throw new java.lang.UnsupportedOperationException();
+ this.fS = pS;
+ }
+
+ @Override
+ public String patternName() {
+ return "modes3.queries.extraInputOfTurnout";
+ }
+
+ @Override
+ public List parameterNames() {
+ return ExtraInputOfTurnout.Match.parameterNames;
+ }
+
+ @Override
+ public Object[] toArray() {
+ return new Object[]{fT, fS};
+ }
+
+ @Override
+ public ExtraInputOfTurnout.Match toImmutable() {
+ return isMutable() ? newMatch(fT, fS) : this;
+ }
+
+ @Override
+ public String prettyPrint() {
+ StringBuilder result = new StringBuilder();
+ result.append("\"T\"=" + prettyPrintValue(fT) + ", ");
+ result.append("\"S\"=" + prettyPrintValue(fS));
+ return result.toString();
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(fT, fS);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null) {
+ return false;
+ }
+ if ((obj instanceof ExtraInputOfTurnout.Match)) {
+ ExtraInputOfTurnout.Match other = (ExtraInputOfTurnout.Match) obj;
+ return Objects.equals(fT, other.fT) && Objects.equals(fS, other.fS);
+ } else {
+ // this should be infrequent
+ if (!(obj instanceof IPatternMatch)) {
+ return false;
+ }
+ IPatternMatch otherSig = (IPatternMatch) obj;
+ return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
+ }
+ }
+
+ @Override
+ public ExtraInputOfTurnout specification() {
+ return ExtraInputOfTurnout.instance();
+ }
+
+ /**
+ * Returns an empty, mutable match.
+ * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
+ *
+ * @return the empty match.
+ *
+ */
+ public static ExtraInputOfTurnout.Match newEmptyMatch() {
+ return new Mutable(null, null);
+ }
+
+ /**
+ * Returns a mutable (partial) match.
+ * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
+ *
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @param pS the fixed value of pattern parameter S, or null if not bound.
+ * @return the new, mutable (partial) match object.
+ *
+ */
+ public static ExtraInputOfTurnout.Match newMutableMatch(final Turnout pT, final Segment pS) {
+ return new Mutable(pT, pS);
+ }
+
+ /**
+ * Returns a new (partial) match.
+ * This can be used e.g. to call the matcher with a partial match.
+ *
The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @param pS the fixed value of pattern parameter S, or null if not bound.
+ * @return the (partial) match object.
+ *
+ */
+ public static ExtraInputOfTurnout.Match newMatch(final Turnout pT, final Segment pS) {
+ return new Immutable(pT, pS);
+ }
+
+ private static final class Mutable extends ExtraInputOfTurnout.Match {
+ Mutable(final Turnout pT, final Segment pS) {
+ super(pT, pS);
+ }
+
+ @Override
+ public boolean isMutable() {
+ return true;
+ }
+ }
+
+ private static final class Immutable extends ExtraInputOfTurnout.Match {
+ Immutable(final Turnout pT, final Segment pS) {
+ super(pT, pS);
+ }
+
+ @Override
+ public boolean isMutable() {
+ return false;
+ }
+ }
+ }
+
+ /**
+ * Generated pattern matcher API of the modes3.queries.extraInputOfTurnout pattern,
+ * providing pattern-specific query methods.
+ *
+ *
Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
+ * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
+ *
+ *
Matches of the pattern will be represented as {@link Match}.
+ *
+ *
+ *
+ * @see Match
+ * @see ExtraInputOfTurnout
+ *
+ */
+ public static class Matcher extends BaseMatcher {
+ /**
+ * Initializes the pattern matcher within an existing VIATRA Query engine.
+ * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
+ *
+ * @param engine the existing VIATRA Query engine in which this matcher will be created.
+ * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
+ *
+ */
+ public static ExtraInputOfTurnout.Matcher on(final ViatraQueryEngine engine) {
+ // check if matcher already exists
+ Matcher matcher = engine.getExistingMatcher(querySpecification());
+ if (matcher == null) {
+ matcher = (Matcher)engine.getMatcher(querySpecification());
+ }
+ return matcher;
+ }
+
+ /**
+ * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
+ * @return an initialized matcher
+ * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
+ *
+ */
+ public static ExtraInputOfTurnout.Matcher create() {
+ return new Matcher();
+ }
+
+ private static final int POSITION_T = 0;
+
+ private static final int POSITION_S = 1;
+
+ private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(ExtraInputOfTurnout.Matcher.class);
+
+ /**
+ * Initializes the pattern matcher within an existing VIATRA Query engine.
+ * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
+ *
+ * @param engine the existing VIATRA Query engine in which this matcher will be created.
+ * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
+ *
+ */
+ private Matcher() {
+ super(querySpecification());
+ }
+
+ /**
+ * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @param pS the fixed value of pattern parameter S, or null if not bound.
+ * @return matches represented as a Match object.
+ *
+ */
+ public Collection getAllMatches(final Turnout pT, final Segment pS) {
+ return rawStreamAllMatches(new Object[]{pT, pS}).collect(Collectors.toSet());
+ }
+
+ /**
+ * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
+ *
+ * NOTE: It is important not to modify the source model while the stream is being processed.
+ * If the match set of the pattern changes during processing, the contents of the stream is undefined.
+ * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @param pS the fixed value of pattern parameter S, or null if not bound.
+ * @return a stream of matches represented as a Match object.
+ *
+ */
+ public Stream streamAllMatches(final Turnout pT, final Segment pS) {
+ return rawStreamAllMatches(new Object[]{pT, pS});
+ }
+
+ /**
+ * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
+ * Neither determinism nor randomness of selection is guaranteed.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @param pS the fixed value of pattern parameter S, or null if not bound.
+ * @return a match represented as a Match object, or null if no match is found.
+ *
+ */
+ public Optional getOneArbitraryMatch(final Turnout pT, final Segment pS) {
+ return rawGetOneArbitraryMatch(new Object[]{pT, pS});
+ }
+
+ /**
+ * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
+ * under any possible substitution of the unspecified parameters (if any).
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @param pS the fixed value of pattern parameter S, or null if not bound.
+ * @return true if the input is a valid (partial) match of the pattern.
+ *
+ */
+ public boolean hasMatch(final Turnout pT, final Segment pS) {
+ return rawHasMatch(new Object[]{pT, pS});
+ }
+
+ /**
+ * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @param pS the fixed value of pattern parameter S, or null if not bound.
+ * @return the number of pattern matches found.
+ *
+ */
+ public int countMatches(final Turnout pT, final Segment pS) {
+ return rawCountMatches(new Object[]{pT, pS});
+ }
+
+ /**
+ * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
+ * Neither determinism nor randomness of selection is guaranteed.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @param pS the fixed value of pattern parameter S, or null if not bound.
+ * @param processor the action that will process the selected match.
+ * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
+ *
+ */
+ public boolean forOneArbitraryMatch(final Turnout pT, final Segment pS, final Consumer super ExtraInputOfTurnout.Match> processor) {
+ return rawForOneArbitraryMatch(new Object[]{pT, pS}, processor);
+ }
+
+ /**
+ * Returns a new (partial) match.
+ * This can be used e.g. to call the matcher with a partial match.
+ *
The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @param pS the fixed value of pattern parameter S, or null if not bound.
+ * @return the (partial) match object.
+ *
+ */
+ public ExtraInputOfTurnout.Match newMatch(final Turnout pT, final Segment pS) {
+ return ExtraInputOfTurnout.Match.newMatch(pT, pS);
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for T.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ protected Stream rawStreamAllValuesOfT(final Object[] parameters) {
+ return rawStreamAllValues(POSITION_T, parameters).map(Turnout.class::cast);
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for T.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Set getAllValuesOfT() {
+ return rawStreamAllValuesOfT(emptyArray()).collect(Collectors.toSet());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for T.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Stream streamAllValuesOfT() {
+ return rawStreamAllValuesOfT(emptyArray());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for T.
+ *
+ * NOTE: It is important not to modify the source model while the stream is being processed.
+ * If the match set of the pattern changes during processing, the contents of the stream is undefined.
+ * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
+ *
+ * @return the Stream of all values or empty set if there are no matches
+ *
+ */
+ public Stream streamAllValuesOfT(final ExtraInputOfTurnout.Match partialMatch) {
+ return rawStreamAllValuesOfT(partialMatch.toArray());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for T.
+ *
+ * NOTE: It is important not to modify the source model while the stream is being processed.
+ * If the match set of the pattern changes during processing, the contents of the stream is undefined.
+ * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
+ *
+ * @return the Stream of all values or empty set if there are no matches
+ *
+ */
+ public Stream streamAllValuesOfT(final Segment pS) {
+ return rawStreamAllValuesOfT(new Object[]{null, pS});
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for T.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Set getAllValuesOfT(final ExtraInputOfTurnout.Match partialMatch) {
+ return rawStreamAllValuesOfT(partialMatch.toArray()).collect(Collectors.toSet());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for T.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Set getAllValuesOfT(final Segment pS) {
+ return rawStreamAllValuesOfT(new Object[]{null, pS}).collect(Collectors.toSet());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ protected Stream rawStreamAllValuesOfS(final Object[] parameters) {
+ return rawStreamAllValues(POSITION_S, parameters).map(Segment.class::cast);
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Set getAllValuesOfS() {
+ return rawStreamAllValuesOfS(emptyArray()).collect(Collectors.toSet());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Stream streamAllValuesOfS() {
+ return rawStreamAllValuesOfS(emptyArray());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S.
+ *
+ * NOTE: It is important not to modify the source model while the stream is being processed.
+ * If the match set of the pattern changes during processing, the contents of the stream is undefined.
+ * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
+ *
+ * @return the Stream of all values or empty set if there are no matches
+ *
+ */
+ public Stream streamAllValuesOfS(final ExtraInputOfTurnout.Match partialMatch) {
+ return rawStreamAllValuesOfS(partialMatch.toArray());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S.
+ *
+ * NOTE: It is important not to modify the source model while the stream is being processed.
+ * If the match set of the pattern changes during processing, the contents of the stream is undefined.
+ * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
+ *
+ * @return the Stream of all values or empty set if there are no matches
+ *
+ */
+ public Stream streamAllValuesOfS(final Turnout pT) {
+ return rawStreamAllValuesOfS(new Object[]{pT, null});
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Set getAllValuesOfS(final ExtraInputOfTurnout.Match partialMatch) {
+ return rawStreamAllValuesOfS(partialMatch.toArray()).collect(Collectors.toSet());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Set getAllValuesOfS(final Turnout pT) {
+ return rawStreamAllValuesOfS(new Object[]{pT, null}).collect(Collectors.toSet());
+ }
+
+ @Override
+ protected ExtraInputOfTurnout.Match tupleToMatch(final Tuple t) {
+ try {
+ return ExtraInputOfTurnout.Match.newMatch((Turnout) t.get(POSITION_T), (Segment) t.get(POSITION_S));
+ } catch(ClassCastException e) {
+ LOGGER.error("Element(s) in tuple not properly typed!",e);
+ return null;
+ }
+ }
+
+ @Override
+ protected ExtraInputOfTurnout.Match arrayToMatch(final Object[] match) {
+ try {
+ return ExtraInputOfTurnout.Match.newMatch((Turnout) match[POSITION_T], (Segment) match[POSITION_S]);
+ } catch(ClassCastException e) {
+ LOGGER.error("Element(s) in array not properly typed!",e);
+ return null;
+ }
+ }
+
+ @Override
+ protected ExtraInputOfTurnout.Match arrayToMatchMutable(final Object[] match) {
+ try {
+ return ExtraInputOfTurnout.Match.newMutableMatch((Turnout) match[POSITION_T], (Segment) match[POSITION_S]);
+ } catch(ClassCastException e) {
+ LOGGER.error("Element(s) in array not properly typed!",e);
+ return null;
+ }
+ }
+
+ /**
+ * @return the singleton instance of the query specification of this pattern
+ * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
+ *
+ */
+ public static IQuerySpecification querySpecification() {
+ return ExtraInputOfTurnout.instance();
+ }
+ }
+
+ private ExtraInputOfTurnout() {
+ super(GeneratedPQuery.INSTANCE);
+ }
+
+ /**
+ * @return the singleton instance of the query specification
+ * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
+ *
+ */
+ public static ExtraInputOfTurnout instance() {
+ try{
+ return LazyHolder.INSTANCE;
+ } catch (ExceptionInInitializerError err) {
+ throw processInitializerError(err);
+ }
+ }
+
+ @Override
+ protected ExtraInputOfTurnout.Matcher instantiate(final ViatraQueryEngine engine) {
+ return ExtraInputOfTurnout.Matcher.on(engine);
+ }
+
+ @Override
+ public ExtraInputOfTurnout.Matcher instantiate() {
+ return ExtraInputOfTurnout.Matcher.create();
+ }
+
+ @Override
+ public ExtraInputOfTurnout.Match newEmptyMatch() {
+ return ExtraInputOfTurnout.Match.newEmptyMatch();
+ }
+
+ @Override
+ public ExtraInputOfTurnout.Match newMatch(final Object... parameters) {
+ return ExtraInputOfTurnout.Match.newMatch((modes3.Turnout) parameters[0], (modes3.Segment) parameters[1]);
+ }
+
+ /**
+ * Inner class allowing the singleton instance of {@link ExtraInputOfTurnout} to be created
+ * not at the class load time of the outer class,
+ * but rather at the first call to {@link ExtraInputOfTurnout#instance()}.
+ *
+ *
This workaround is required e.g. to support recursion.
+ *
+ */
+ private static class LazyHolder {
+ private static final ExtraInputOfTurnout INSTANCE = new ExtraInputOfTurnout();
+
+ /**
+ * Statically initializes the query specification after the field {@link #INSTANCE} is assigned.
+ * This initialization order is required to support indirect recursion.
+ *
+ *
The static initializer is defined using a helper field to work around limitations of the code generator.
+ *
+ */
+ private static final Object STATIC_INITIALIZER = ensureInitialized();
+
+ public static Object ensureInitialized() {
+ INSTANCE.ensureInitializedInternal();
+ return null;
+ }
+ }
+
+ private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
+ private static final ExtraInputOfTurnout.GeneratedPQuery INSTANCE = new GeneratedPQuery();
+
+ private final PParameter parameter_T = new PParameter("T", "modes3.Turnout", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Turnout")), PParameterDirection.INOUT);
+
+ private final PParameter parameter_S = new PParameter("S", "modes3.Segment", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Segment")), PParameterDirection.INOUT);
+
+ private final List parameters = Arrays.asList(parameter_T, parameter_S);
+
+ private GeneratedPQuery() {
+ super(PVisibility.PUBLIC);
+ }
+
+ @Override
+ public String getFullyQualifiedName() {
+ return "modes3.queries.extraInputOfTurnout";
+ }
+
+ @Override
+ public List getParameterNames() {
+ return Arrays.asList("T","S");
+ }
+
+ @Override
+ public List getParameters() {
+ return parameters;
+ }
+
+ @Override
+ public Set doGetContainedBodies() {
+ setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
+ Set bodies = new LinkedHashSet<>();
+ {
+ PBody body = new PBody(this);
+ PVariable var_T = body.getOrCreateVariableByName("T");
+ PVariable var_S = body.getOrCreateVariableByName("S");
+ PVariable var_Straight = body.getOrCreateVariableByName("Straight");
+ PVariable var_Divergent = body.getOrCreateVariableByName("Divergent");
+ new TypeConstraint(body, Tuples.flatTupleOf(var_T), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Turnout")));
+ new TypeConstraint(body, Tuples.flatTupleOf(var_S), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
+ body.setSymbolicParameters(Arrays.asList(
+ new ExportedParameter(body, var_T, parameter_T),
+ new ExportedParameter(body, var_S, parameter_S)
+ ));
+ // Turnout.straight(T, Straight)
+ new TypeConstraint(body, Tuples.flatTupleOf(var_T), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Turnout")));
+ PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
+ new TypeConstraint(body, Tuples.flatTupleOf(var_T, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Turnout", "straight")));
+ new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
+ new Equality(body, var__virtual_0_, var_Straight);
+ // Turnout.divergent(T, Divergent)
+ new TypeConstraint(body, Tuples.flatTupleOf(var_T), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Turnout")));
+ PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
+ new TypeConstraint(body, Tuples.flatTupleOf(var_T, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Turnout", "divergent")));
+ new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
+ new Equality(body, var__virtual_1_, var_Divergent);
+ // find output(S, T)
+ new PositivePatternCall(body, Tuples.flatTupleOf(var_S, var_T), Output.instance().getInternalQueryRepresentation());
+ // S != Straight
+ new Inequality(body, var_S, var_Straight);
+ // S != Divergent
+ new Inequality(body, var_S, var_Divergent);
+ bodies.add(body);
+ }
+ return bodies;
+ }
+ }
+}
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..01ec77a1
--- /dev/null
+++ b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/Modes3Queries.java
@@ -0,0 +1,229 @@
+/**
+ * Generated from platform:/resource/ca.mcgill.rtgmrt.example.modes3/src/modes3/queries/Modes3Queries.vql
+ */
+package modes3.queries;
+
+import modes3.queries.Adjacent;
+import modes3.queries.ConnectedTo;
+import modes3.queries.ConnectedToNotSymmetric;
+import modes3.queries.ConnectedToReflexive;
+import modes3.queries.ExtraInputOfTurnout;
+import modes3.queries.NoExtraInputOfTurnout;
+import modes3.queries.Output;
+import modes3.queries.OutputReflexive;
+import modes3.queries.Reachable;
+import modes3.queries.TooManyExtraInputsOfTurnout;
+import modes3.queries.TooManyInputsOfSegment;
+import modes3.queries.Turnout;
+import modes3.queries.TurnoutConnectedToBothOutputs;
+import modes3.queries.TurnoutInSegments;
+import modes3.queries.TurnoutOutput;
+import modes3.queries.TurnoutOutputsAreSame;
+import modes3.queries.Unreachable;
+import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine;
+import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedPatternGroup;
+
+/**
+ * A pattern group formed of all public patterns defined in Modes3Queries.vql.
+ *
+ *
Use the static instance as any {@link interface org.eclipse.viatra.query.runtime.api.IQueryGroup}, to conveniently prepare
+ * a VIATRA Query engine for matching all patterns originally defined in file Modes3Queries.vql,
+ * in order to achieve better performance than one-by-one on-demand matcher initialization.
+ *
+ *
From package modes3.queries, the group contains the definition of the following patterns:
+ *
+ * @see Matcher
+ * @see Match
+ *
+ */
+@SuppressWarnings("all")
+public final class NoExtraInputOfTurnout extends BaseGeneratedEMFQuerySpecification {
+ /**
+ * Pattern-specific match representation of the modes3.queries.noExtraInputOfTurnout pattern,
+ * to be used in conjunction with {@link Matcher}.
+ *
+ *
Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
+ * Each instance is a (possibly partial) substitution of pattern parameters,
+ * usable to represent a match of the pattern in the result of a query,
+ * or to specify the bound (fixed) input parameters when issuing a query.
+ *
+ * @see Matcher
+ *
+ */
+ public static abstract class Match extends BasePatternMatch {
+ private Turnout fT;
+
+ private static List parameterNames = makeImmutableList("T");
+
+ private Match(final Turnout pT) {
+ this.fT = pT;
+ }
+
+ @Override
+ public Object get(final String parameterName) {
+ switch(parameterName) {
+ case "T": return this.fT;
+ default: return null;
+ }
+ }
+
+ @Override
+ public Object get(final int index) {
+ switch(index) {
+ case 0: return this.fT;
+ default: return null;
+ }
+ }
+
+ public Turnout getT() {
+ return this.fT;
+ }
+
+ @Override
+ public boolean set(final String parameterName, final Object newValue) {
+ if (!isMutable()) throw new java.lang.UnsupportedOperationException();
+ if ("T".equals(parameterName) ) {
+ this.fT = (Turnout) newValue;
+ return true;
+ }
+ return false;
+ }
+
+ public void setT(final Turnout pT) {
+ if (!isMutable()) throw new java.lang.UnsupportedOperationException();
+ this.fT = pT;
+ }
+
+ @Override
+ public String patternName() {
+ return "modes3.queries.noExtraInputOfTurnout";
+ }
+
+ @Override
+ public List parameterNames() {
+ return NoExtraInputOfTurnout.Match.parameterNames;
+ }
+
+ @Override
+ public Object[] toArray() {
+ return new Object[]{fT};
+ }
+
+ @Override
+ public NoExtraInputOfTurnout.Match toImmutable() {
+ return isMutable() ? newMatch(fT) : this;
+ }
+
+ @Override
+ public String prettyPrint() {
+ StringBuilder result = new StringBuilder();
+ result.append("\"T\"=" + prettyPrintValue(fT));
+ return result.toString();
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(fT);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null) {
+ return false;
+ }
+ if ((obj instanceof NoExtraInputOfTurnout.Match)) {
+ NoExtraInputOfTurnout.Match other = (NoExtraInputOfTurnout.Match) obj;
+ return Objects.equals(fT, other.fT);
+ } else {
+ // this should be infrequent
+ if (!(obj instanceof IPatternMatch)) {
+ return false;
+ }
+ IPatternMatch otherSig = (IPatternMatch) obj;
+ return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
+ }
+ }
+
+ @Override
+ public NoExtraInputOfTurnout specification() {
+ return NoExtraInputOfTurnout.instance();
+ }
+
+ /**
+ * Returns an empty, mutable match.
+ * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
+ *
+ * @return the empty match.
+ *
+ */
+ public static NoExtraInputOfTurnout.Match newEmptyMatch() {
+ return new Mutable(null);
+ }
+
+ /**
+ * Returns a mutable (partial) match.
+ * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
+ *
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @return the new, mutable (partial) match object.
+ *
+ */
+ public static NoExtraInputOfTurnout.Match newMutableMatch(final Turnout pT) {
+ return new Mutable(pT);
+ }
+
+ /**
+ * Returns a new (partial) match.
+ * This can be used e.g. to call the matcher with a partial match.
+ *
The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @return the (partial) match object.
+ *
+ */
+ public static NoExtraInputOfTurnout.Match newMatch(final Turnout pT) {
+ return new Immutable(pT);
+ }
+
+ private static final class Mutable extends NoExtraInputOfTurnout.Match {
+ Mutable(final Turnout pT) {
+ super(pT);
+ }
+
+ @Override
+ public boolean isMutable() {
+ return true;
+ }
+ }
+
+ private static final class Immutable extends NoExtraInputOfTurnout.Match {
+ Immutable(final Turnout pT) {
+ super(pT);
+ }
+
+ @Override
+ public boolean isMutable() {
+ return false;
+ }
+ }
+ }
+
+ /**
+ * Generated pattern matcher API of the modes3.queries.noExtraInputOfTurnout pattern,
+ * providing pattern-specific query methods.
+ *
+ *
Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
+ * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
+ *
+ *
Matches of the pattern will be represented as {@link Match}.
+ *
+ *
+ *
+ * @see Match
+ * @see NoExtraInputOfTurnout
+ *
+ */
+ public static class Matcher extends BaseMatcher {
+ /**
+ * Initializes the pattern matcher within an existing VIATRA Query engine.
+ * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
+ *
+ * @param engine the existing VIATRA Query engine in which this matcher will be created.
+ * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
+ *
+ */
+ public static NoExtraInputOfTurnout.Matcher on(final ViatraQueryEngine engine) {
+ // check if matcher already exists
+ Matcher matcher = engine.getExistingMatcher(querySpecification());
+ if (matcher == null) {
+ matcher = (Matcher)engine.getMatcher(querySpecification());
+ }
+ return matcher;
+ }
+
+ /**
+ * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
+ * @return an initialized matcher
+ * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
+ *
+ */
+ public static NoExtraInputOfTurnout.Matcher create() {
+ return new Matcher();
+ }
+
+ private static final int POSITION_T = 0;
+
+ private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(NoExtraInputOfTurnout.Matcher.class);
+
+ /**
+ * Initializes the pattern matcher within an existing VIATRA Query engine.
+ * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
+ *
+ * @param engine the existing VIATRA Query engine in which this matcher will be created.
+ * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
+ *
+ */
+ private Matcher() {
+ super(querySpecification());
+ }
+
+ /**
+ * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @return matches represented as a Match object.
+ *
+ */
+ public Collection getAllMatches(final Turnout pT) {
+ return rawStreamAllMatches(new Object[]{pT}).collect(Collectors.toSet());
+ }
+
+ /**
+ * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
+ *
+ * NOTE: It is important not to modify the source model while the stream is being processed.
+ * If the match set of the pattern changes during processing, the contents of the stream is undefined.
+ * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @return a stream of matches represented as a Match object.
+ *
+ */
+ public Stream streamAllMatches(final Turnout pT) {
+ return rawStreamAllMatches(new Object[]{pT});
+ }
+
+ /**
+ * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
+ * Neither determinism nor randomness of selection is guaranteed.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @return a match represented as a Match object, or null if no match is found.
+ *
+ */
+ public Optional getOneArbitraryMatch(final Turnout pT) {
+ return rawGetOneArbitraryMatch(new Object[]{pT});
+ }
+
+ /**
+ * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
+ * under any possible substitution of the unspecified parameters (if any).
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @return true if the input is a valid (partial) match of the pattern.
+ *
+ */
+ public boolean hasMatch(final Turnout pT) {
+ return rawHasMatch(new Object[]{pT});
+ }
+
+ /**
+ * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @return the number of pattern matches found.
+ *
+ */
+ public int countMatches(final Turnout pT) {
+ return rawCountMatches(new Object[]{pT});
+ }
+
+ /**
+ * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
+ * Neither determinism nor randomness of selection is guaranteed.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @param processor the action that will process the selected match.
+ * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
+ *
+ */
+ public boolean forOneArbitraryMatch(final Turnout pT, final Consumer super NoExtraInputOfTurnout.Match> processor) {
+ return rawForOneArbitraryMatch(new Object[]{pT}, processor);
+ }
+
+ /**
+ * Returns a new (partial) match.
+ * This can be used e.g. to call the matcher with a partial match.
+ *
The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @return the (partial) match object.
+ *
+ */
+ public NoExtraInputOfTurnout.Match newMatch(final Turnout pT) {
+ return NoExtraInputOfTurnout.Match.newMatch(pT);
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for T.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ protected Stream rawStreamAllValuesOfT(final Object[] parameters) {
+ return rawStreamAllValues(POSITION_T, parameters).map(Turnout.class::cast);
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for T.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Set getAllValuesOfT() {
+ return rawStreamAllValuesOfT(emptyArray()).collect(Collectors.toSet());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for T.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Stream streamAllValuesOfT() {
+ return rawStreamAllValuesOfT(emptyArray());
+ }
+
+ @Override
+ protected NoExtraInputOfTurnout.Match tupleToMatch(final Tuple t) {
+ try {
+ return NoExtraInputOfTurnout.Match.newMatch((Turnout) t.get(POSITION_T));
+ } catch(ClassCastException e) {
+ LOGGER.error("Element(s) in tuple not properly typed!",e);
+ return null;
+ }
+ }
+
+ @Override
+ protected NoExtraInputOfTurnout.Match arrayToMatch(final Object[] match) {
+ try {
+ return NoExtraInputOfTurnout.Match.newMatch((Turnout) match[POSITION_T]);
+ } catch(ClassCastException e) {
+ LOGGER.error("Element(s) in array not properly typed!",e);
+ return null;
+ }
+ }
+
+ @Override
+ protected NoExtraInputOfTurnout.Match arrayToMatchMutable(final Object[] match) {
+ try {
+ return NoExtraInputOfTurnout.Match.newMutableMatch((Turnout) match[POSITION_T]);
+ } catch(ClassCastException e) {
+ LOGGER.error("Element(s) in array not properly typed!",e);
+ return null;
+ }
+ }
+
+ /**
+ * @return the singleton instance of the query specification of this pattern
+ * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
+ *
+ */
+ public static IQuerySpecification querySpecification() {
+ return NoExtraInputOfTurnout.instance();
+ }
+ }
+
+ private NoExtraInputOfTurnout() {
+ super(GeneratedPQuery.INSTANCE);
+ }
+
+ /**
+ * @return the singleton instance of the query specification
+ * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
+ *
+ */
+ public static NoExtraInputOfTurnout instance() {
+ try{
+ return LazyHolder.INSTANCE;
+ } catch (ExceptionInInitializerError err) {
+ throw processInitializerError(err);
+ }
+ }
+
+ @Override
+ protected NoExtraInputOfTurnout.Matcher instantiate(final ViatraQueryEngine engine) {
+ return NoExtraInputOfTurnout.Matcher.on(engine);
+ }
+
+ @Override
+ public NoExtraInputOfTurnout.Matcher instantiate() {
+ return NoExtraInputOfTurnout.Matcher.create();
+ }
+
+ @Override
+ public NoExtraInputOfTurnout.Match newEmptyMatch() {
+ return NoExtraInputOfTurnout.Match.newEmptyMatch();
+ }
+
+ @Override
+ public NoExtraInputOfTurnout.Match newMatch(final Object... parameters) {
+ return NoExtraInputOfTurnout.Match.newMatch((modes3.Turnout) parameters[0]);
+ }
+
+ /**
+ * Inner class allowing the singleton instance of {@link NoExtraInputOfTurnout} to be created
+ * not at the class load time of the outer class,
+ * but rather at the first call to {@link NoExtraInputOfTurnout#instance()}.
+ *
+ *
This workaround is required e.g. to support recursion.
+ *
+ */
+ private static class LazyHolder {
+ private static final NoExtraInputOfTurnout INSTANCE = new NoExtraInputOfTurnout();
+
+ /**
+ * Statically initializes the query specification after the field {@link #INSTANCE} is assigned.
+ * This initialization order is required to support indirect recursion.
+ *
+ *
The static initializer is defined using a helper field to work around limitations of the code generator.
+ *
+ */
+ private static final Object STATIC_INITIALIZER = ensureInitialized();
+
+ public static Object ensureInitialized() {
+ INSTANCE.ensureInitializedInternal();
+ return null;
+ }
+ }
+
+ private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
+ private static final NoExtraInputOfTurnout.GeneratedPQuery INSTANCE = new GeneratedPQuery();
+
+ private final PParameter parameter_T = new PParameter("T", "modes3.Turnout", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Turnout")), PParameterDirection.INOUT);
+
+ private final List parameters = Arrays.asList(parameter_T);
+
+ private GeneratedPQuery() {
+ super(PVisibility.PUBLIC);
+ }
+
+ @Override
+ public String getFullyQualifiedName() {
+ return "modes3.queries.noExtraInputOfTurnout";
+ }
+
+ @Override
+ public List getParameterNames() {
+ return Arrays.asList("T");
+ }
+
+ @Override
+ public List getParameters() {
+ return parameters;
+ }
+
+ @Override
+ public Set doGetContainedBodies() {
+ setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
+ Set bodies = new LinkedHashSet<>();
+ {
+ PBody body = new PBody(this);
+ PVariable var_T = body.getOrCreateVariableByName("T");
+ PVariable var___0_ = body.getOrCreateVariableByName("_<0>");
+ new TypeConstraint(body, Tuples.flatTupleOf(var_T), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Turnout")));
+ body.setSymbolicParameters(Arrays.asList(
+ new ExportedParameter(body, var_T, parameter_T)
+ ));
+ // neg find extraInputOfTurnout(T, _)
+ new NegativePatternCall(body, Tuples.flatTupleOf(var_T, var___0_), ExtraInputOfTurnout.instance().getInternalQueryRepresentation());
+ bodies.add(body);
+ }
+ {
+ PAnnotation annotation = new PAnnotation("Constraint");
+ annotation.addAttribute("message", "noExtraInputOfTurnout");
+ annotation.addAttribute("severity", "error");
+ annotation.addAttribute("key", Arrays.asList(new Object[] {
+ new ParameterReference("T")
+ }));
+ addAnnotation(annotation);
+ }
+ return bodies;
+ }
+ }
+}
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 @@
+/**
+ * Generated from platform:/resource/ca.mcgill.rtgmrt.example.modes3/src/modes3/queries/Modes3Queries.vql
+ */
+package modes3.queries;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+import java.util.function.Consumer;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import modes3.Segment;
+import modes3.queries.TurnoutOutput;
+import org.apache.log4j.Logger;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.viatra.query.runtime.api.IPatternMatch;
+import org.eclipse.viatra.query.runtime.api.IQuerySpecification;
+import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine;
+import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
+import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification;
+import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher;
+import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch;
+import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey;
+import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey;
+import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
+import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
+import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality;
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall;
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
+import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
+import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
+import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
+import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
+import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
+import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
+
+/**
+ * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
+ *
+ *
+ *
+ * @see Matcher
+ * @see Match
+ *
+ */
+@SuppressWarnings("all")
+public final class Output extends BaseGeneratedEMFQuerySpecification {
+ /**
+ * Pattern-specific match representation of the modes3.queries.output pattern,
+ * to be used in conjunction with {@link Matcher}.
+ *
+ *
Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
+ * Each instance is a (possibly partial) substitution of pattern parameters,
+ * usable to represent a match of the pattern in the result of a query,
+ * or to specify the bound (fixed) input parameters when issuing a query.
+ *
+ * @see Matcher
+ *
+ */
+ public static abstract class Match extends BasePatternMatch {
+ private Segment fS1;
+
+ private Segment fS2;
+
+ private static List parameterNames = makeImmutableList("S1", "S2");
+
+ private Match(final Segment pS1, final Segment pS2) {
+ this.fS1 = pS1;
+ this.fS2 = pS2;
+ }
+
+ @Override
+ public Object get(final String parameterName) {
+ switch(parameterName) {
+ case "S1": return this.fS1;
+ case "S2": return this.fS2;
+ default: return null;
+ }
+ }
+
+ @Override
+ public Object get(final int index) {
+ switch(index) {
+ case 0: return this.fS1;
+ case 1: return this.fS2;
+ default: return null;
+ }
+ }
+
+ public Segment getS1() {
+ return this.fS1;
+ }
+
+ public Segment getS2() {
+ return this.fS2;
+ }
+
+ @Override
+ public boolean set(final String parameterName, final Object newValue) {
+ if (!isMutable()) throw new java.lang.UnsupportedOperationException();
+ if ("S1".equals(parameterName) ) {
+ this.fS1 = (Segment) newValue;
+ return true;
+ }
+ if ("S2".equals(parameterName) ) {
+ this.fS2 = (Segment) newValue;
+ return true;
+ }
+ return false;
+ }
+
+ public void setS1(final Segment pS1) {
+ if (!isMutable()) throw new java.lang.UnsupportedOperationException();
+ this.fS1 = pS1;
+ }
+
+ public void setS2(final Segment pS2) {
+ if (!isMutable()) throw new java.lang.UnsupportedOperationException();
+ this.fS2 = pS2;
+ }
+
+ @Override
+ public String patternName() {
+ return "modes3.queries.output";
+ }
+
+ @Override
+ public List parameterNames() {
+ return Output.Match.parameterNames;
+ }
+
+ @Override
+ public Object[] toArray() {
+ return new Object[]{fS1, fS2};
+ }
+
+ @Override
+ public Output.Match toImmutable() {
+ return isMutable() ? newMatch(fS1, fS2) : this;
+ }
+
+ @Override
+ public String prettyPrint() {
+ StringBuilder result = new StringBuilder();
+ result.append("\"S1\"=" + prettyPrintValue(fS1) + ", ");
+ result.append("\"S2\"=" + prettyPrintValue(fS2));
+ return result.toString();
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(fS1, fS2);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null) {
+ return false;
+ }
+ if ((obj instanceof Output.Match)) {
+ Output.Match other = (Output.Match) obj;
+ return Objects.equals(fS1, other.fS1) && Objects.equals(fS2, other.fS2);
+ } else {
+ // this should be infrequent
+ if (!(obj instanceof IPatternMatch)) {
+ return false;
+ }
+ IPatternMatch otherSig = (IPatternMatch) obj;
+ return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
+ }
+ }
+
+ @Override
+ public Output specification() {
+ return Output.instance();
+ }
+
+ /**
+ * Returns an empty, mutable match.
+ * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
+ *
+ * @return the empty match.
+ *
+ */
+ public static Output.Match newEmptyMatch() {
+ return new Mutable(null, null);
+ }
+
+ /**
+ * Returns a mutable (partial) match.
+ * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
+ *
+ * @param pS1 the fixed value of pattern parameter S1, or null if not bound.
+ * @param pS2 the fixed value of pattern parameter S2, or null if not bound.
+ * @return the new, mutable (partial) match object.
+ *
+ */
+ public static Output.Match newMutableMatch(final Segment pS1, final Segment pS2) {
+ return new Mutable(pS1, pS2);
+ }
+
+ /**
+ * Returns a new (partial) match.
+ * This can be used e.g. to call the matcher with a partial match.
+ *
The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
+ * @param pS1 the fixed value of pattern parameter S1, or null if not bound.
+ * @param pS2 the fixed value of pattern parameter S2, or null if not bound.
+ * @return the (partial) match object.
+ *
+ */
+ public static Output.Match newMatch(final Segment pS1, final Segment pS2) {
+ return new Immutable(pS1, pS2);
+ }
+
+ private static final class Mutable extends Output.Match {
+ Mutable(final Segment pS1, final Segment pS2) {
+ super(pS1, pS2);
+ }
+
+ @Override
+ public boolean isMutable() {
+ return true;
+ }
+ }
+
+ private static final class Immutable extends Output.Match {
+ Immutable(final Segment pS1, final Segment pS2) {
+ super(pS1, pS2);
+ }
+
+ @Override
+ public boolean isMutable() {
+ return false;
+ }
+ }
+ }
+
+ /**
+ * Generated pattern matcher API of the modes3.queries.output pattern,
+ * providing pattern-specific query methods.
+ *
+ *
Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
+ * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
+ *
+ *
Matches of the pattern will be represented as {@link Match}.
+ *
+ *
+ *
+ * @see Match
+ * @see Output
+ *
+ */
+ public static class Matcher extends BaseMatcher {
+ /**
+ * Initializes the pattern matcher within an existing VIATRA Query engine.
+ * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
+ *
+ * @param engine the existing VIATRA Query engine in which this matcher will be created.
+ * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
+ *
+ */
+ public static Output.Matcher on(final ViatraQueryEngine engine) {
+ // check if matcher already exists
+ Matcher matcher = engine.getExistingMatcher(querySpecification());
+ if (matcher == null) {
+ matcher = (Matcher)engine.getMatcher(querySpecification());
+ }
+ return matcher;
+ }
+
+ /**
+ * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
+ * @return an initialized matcher
+ * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
+ *
+ */
+ public static Output.Matcher create() {
+ return new Matcher();
+ }
+
+ private static final int POSITION_S1 = 0;
+
+ private static final int POSITION_S2 = 1;
+
+ private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Output.Matcher.class);
+
+ /**
+ * Initializes the pattern matcher within an existing VIATRA Query engine.
+ * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
+ *
+ * @param engine the existing VIATRA Query engine in which this matcher will be created.
+ * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
+ *
+ */
+ private Matcher() {
+ super(querySpecification());
+ }
+
+ /**
+ * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
+ * @param pS1 the fixed value of pattern parameter S1, or null if not bound.
+ * @param pS2 the fixed value of pattern parameter S2, or null if not bound.
+ * @return matches represented as a Match object.
+ *
+ */
+ public Collection getAllMatches(final Segment pS1, final Segment pS2) {
+ return rawStreamAllMatches(new Object[]{pS1, pS2}).collect(Collectors.toSet());
+ }
+
+ /**
+ * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
+ *
+ * NOTE: It is important not to modify the source model while the stream is being processed.
+ * If the match set of the pattern changes during processing, the contents of the stream is undefined.
+ * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
+ * @param pS1 the fixed value of pattern parameter S1, or null if not bound.
+ * @param pS2 the fixed value of pattern parameter S2, or null if not bound.
+ * @return a stream of matches represented as a Match object.
+ *
+ */
+ public Stream streamAllMatches(final Segment pS1, final Segment pS2) {
+ return rawStreamAllMatches(new Object[]{pS1, pS2});
+ }
+
+ /**
+ * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
+ * Neither determinism nor randomness of selection is guaranteed.
+ * @param pS1 the fixed value of pattern parameter S1, or null if not bound.
+ * @param pS2 the fixed value of pattern parameter S2, or null if not bound.
+ * @return a match represented as a Match object, or null if no match is found.
+ *
+ */
+ public Optional getOneArbitraryMatch(final Segment pS1, final Segment pS2) {
+ return rawGetOneArbitraryMatch(new Object[]{pS1, pS2});
+ }
+
+ /**
+ * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
+ * under any possible substitution of the unspecified parameters (if any).
+ * @param pS1 the fixed value of pattern parameter S1, or null if not bound.
+ * @param pS2 the fixed value of pattern parameter S2, or null if not bound.
+ * @return true if the input is a valid (partial) match of the pattern.
+ *
+ */
+ public boolean hasMatch(final Segment pS1, final Segment pS2) {
+ return rawHasMatch(new Object[]{pS1, pS2});
+ }
+
+ /**
+ * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
+ * @param pS1 the fixed value of pattern parameter S1, or null if not bound.
+ * @param pS2 the fixed value of pattern parameter S2, or null if not bound.
+ * @return the number of pattern matches found.
+ *
+ */
+ public int countMatches(final Segment pS1, final Segment pS2) {
+ return rawCountMatches(new Object[]{pS1, pS2});
+ }
+
+ /**
+ * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
+ * Neither determinism nor randomness of selection is guaranteed.
+ * @param pS1 the fixed value of pattern parameter S1, or null if not bound.
+ * @param pS2 the fixed value of pattern parameter S2, or null if not bound.
+ * @param processor the action that will process the selected match.
+ * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
+ *
+ */
+ public boolean forOneArbitraryMatch(final Segment pS1, final Segment pS2, final Consumer super Output.Match> processor) {
+ return rawForOneArbitraryMatch(new Object[]{pS1, pS2}, processor);
+ }
+
+ /**
+ * Returns a new (partial) match.
+ * This can be used e.g. to call the matcher with a partial match.
+ *
The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
+ * @param pS1 the fixed value of pattern parameter S1, or null if not bound.
+ * @param pS2 the fixed value of pattern parameter S2, or null if not bound.
+ * @return the (partial) match object.
+ *
+ */
+ public Output.Match newMatch(final Segment pS1, final Segment pS2) {
+ return Output.Match.newMatch(pS1, pS2);
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S1.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ protected Stream rawStreamAllValuesOfS1(final Object[] parameters) {
+ return rawStreamAllValues(POSITION_S1, parameters).map(Segment.class::cast);
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S1.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Set getAllValuesOfS1() {
+ return rawStreamAllValuesOfS1(emptyArray()).collect(Collectors.toSet());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S1.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Stream streamAllValuesOfS1() {
+ return rawStreamAllValuesOfS1(emptyArray());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S1.
+ *
+ * NOTE: It is important not to modify the source model while the stream is being processed.
+ * If the match set of the pattern changes during processing, the contents of the stream is undefined.
+ * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
+ *
+ * @return the Stream of all values or empty set if there are no matches
+ *
+ */
+ public Stream streamAllValuesOfS1(final Output.Match partialMatch) {
+ return rawStreamAllValuesOfS1(partialMatch.toArray());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S1.
+ *
+ * NOTE: It is important not to modify the source model while the stream is being processed.
+ * If the match set of the pattern changes during processing, the contents of the stream is undefined.
+ * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
+ *
+ * @return the Stream of all values or empty set if there are no matches
+ *
+ */
+ public Stream streamAllValuesOfS1(final Segment pS2) {
+ return rawStreamAllValuesOfS1(new Object[]{null, pS2});
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S1.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Set getAllValuesOfS1(final Output.Match partialMatch) {
+ return rawStreamAllValuesOfS1(partialMatch.toArray()).collect(Collectors.toSet());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S1.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Set getAllValuesOfS1(final Segment pS2) {
+ return rawStreamAllValuesOfS1(new Object[]{null, pS2}).collect(Collectors.toSet());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S2.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ protected Stream rawStreamAllValuesOfS2(final Object[] parameters) {
+ return rawStreamAllValues(POSITION_S2, parameters).map(Segment.class::cast);
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S2.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Set getAllValuesOfS2() {
+ return rawStreamAllValuesOfS2(emptyArray()).collect(Collectors.toSet());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S2.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Stream streamAllValuesOfS2() {
+ return rawStreamAllValuesOfS2(emptyArray());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S2.
+ *
+ * NOTE: It is important not to modify the source model while the stream is being processed.
+ * If the match set of the pattern changes during processing, the contents of the stream is undefined.
+ * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
+ *
+ * @return the Stream of all values or empty set if there are no matches
+ *
+ */
+ public Stream streamAllValuesOfS2(final Output.Match partialMatch) {
+ return rawStreamAllValuesOfS2(partialMatch.toArray());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S2.
+ *
+ * NOTE: It is important not to modify the source model while the stream is being processed.
+ * If the match set of the pattern changes during processing, the contents of the stream is undefined.
+ * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
+ *
+ * @return the Stream of all values or empty set if there are no matches
+ *
+ */
+ public Stream streamAllValuesOfS2(final Segment pS1) {
+ return rawStreamAllValuesOfS2(new Object[]{pS1, null});
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S2.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Set getAllValuesOfS2(final Output.Match partialMatch) {
+ return rawStreamAllValuesOfS2(partialMatch.toArray()).collect(Collectors.toSet());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S2.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Set getAllValuesOfS2(final Segment pS1) {
+ return rawStreamAllValuesOfS2(new Object[]{pS1, null}).collect(Collectors.toSet());
+ }
+
+ @Override
+ protected Output.Match tupleToMatch(final Tuple t) {
+ try {
+ return Output.Match.newMatch((Segment) t.get(POSITION_S1), (Segment) t.get(POSITION_S2));
+ } catch(ClassCastException e) {
+ LOGGER.error("Element(s) in tuple not properly typed!",e);
+ return null;
+ }
+ }
+
+ @Override
+ protected Output.Match arrayToMatch(final Object[] match) {
+ try {
+ return Output.Match.newMatch((Segment) match[POSITION_S1], (Segment) match[POSITION_S2]);
+ } catch(ClassCastException e) {
+ LOGGER.error("Element(s) in array not properly typed!",e);
+ return null;
+ }
+ }
+
+ @Override
+ protected Output.Match arrayToMatchMutable(final Object[] match) {
+ try {
+ return Output.Match.newMutableMatch((Segment) match[POSITION_S1], (Segment) match[POSITION_S2]);
+ } catch(ClassCastException e) {
+ LOGGER.error("Element(s) in array not properly typed!",e);
+ return null;
+ }
+ }
+
+ /**
+ * @return the singleton instance of the query specification of this pattern
+ * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
+ *
+ */
+ public static IQuerySpecification querySpecification() {
+ return Output.instance();
+ }
+ }
+
+ private Output() {
+ super(GeneratedPQuery.INSTANCE);
+ }
+
+ /**
+ * @return the singleton instance of the query specification
+ * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
+ *
+ */
+ public static Output instance() {
+ try{
+ return LazyHolder.INSTANCE;
+ } catch (ExceptionInInitializerError err) {
+ throw processInitializerError(err);
+ }
+ }
+
+ @Override
+ protected Output.Matcher instantiate(final ViatraQueryEngine engine) {
+ return Output.Matcher.on(engine);
+ }
+
+ @Override
+ public Output.Matcher instantiate() {
+ return Output.Matcher.create();
+ }
+
+ @Override
+ public Output.Match newEmptyMatch() {
+ return Output.Match.newEmptyMatch();
+ }
+
+ @Override
+ public Output.Match newMatch(final Object... parameters) {
+ return Output.Match.newMatch((modes3.Segment) parameters[0], (modes3.Segment) parameters[1]);
+ }
+
+ /**
+ * Inner class allowing the singleton instance of {@link Output} to be created
+ * not at the class load time of the outer class,
+ * but rather at the first call to {@link Output#instance()}.
+ *
+ *
This workaround is required e.g. to support recursion.
+ *
+ */
+ private static class LazyHolder {
+ private static final Output INSTANCE = new Output();
+
+ /**
+ * Statically initializes the query specification after the field {@link #INSTANCE} is assigned.
+ * This initialization order is required to support indirect recursion.
+ *
+ *
The static initializer is defined using a helper field to work around limitations of the code generator.
+ *
+ */
+ private static final Object STATIC_INITIALIZER = ensureInitialized();
+
+ public static Object ensureInitialized() {
+ INSTANCE.ensureInitializedInternal();
+ return null;
+ }
+ }
+
+ private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
+ private static final Output.GeneratedPQuery INSTANCE = new GeneratedPQuery();
+
+ private final PParameter parameter_S1 = new PParameter("S1", "modes3.Segment", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Segment")), PParameterDirection.INOUT);
+
+ private final PParameter parameter_S2 = new PParameter("S2", "modes3.Segment", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Segment")), PParameterDirection.INOUT);
+
+ private final List parameters = Arrays.asList(parameter_S1, parameter_S2);
+
+ private GeneratedPQuery() {
+ super(PVisibility.PUBLIC);
+ }
+
+ @Override
+ public String getFullyQualifiedName() {
+ return "modes3.queries.output";
+ }
+
+ @Override
+ public List getParameterNames() {
+ return Arrays.asList("S1","S2");
+ }
+
+ @Override
+ public List getParameters() {
+ return parameters;
+ }
+
+ @Override
+ public Set doGetContainedBodies() {
+ setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
+ Set bodies = new LinkedHashSet<>();
+ {
+ PBody body = new PBody(this);
+ PVariable var_S1 = body.getOrCreateVariableByName("S1");
+ PVariable var_S2 = body.getOrCreateVariableByName("S2");
+ new TypeConstraint(body, Tuples.flatTupleOf(var_S1), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
+ new TypeConstraint(body, Tuples.flatTupleOf(var_S2), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
+ body.setSymbolicParameters(Arrays.asList(
+ new ExportedParameter(body, var_S1, parameter_S1),
+ new ExportedParameter(body, var_S2, parameter_S2)
+ ));
+ // Segment.connectedTo(S1, S2)
+ new TypeConstraint(body, Tuples.flatTupleOf(var_S1), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
+ PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
+ new TypeConstraint(body, Tuples.flatTupleOf(var_S1, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment", "connectedTo")));
+ new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
+ new Equality(body, var__virtual_0_, var_S2);
+ bodies.add(body);
+ }
+ {
+ PBody body = new PBody(this);
+ PVariable var_S1 = body.getOrCreateVariableByName("S1");
+ PVariable var_S2 = body.getOrCreateVariableByName("S2");
+ new TypeConstraint(body, Tuples.flatTupleOf(var_S1), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
+ new TypeConstraint(body, Tuples.flatTupleOf(var_S2), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
+ body.setSymbolicParameters(Arrays.asList(
+ new ExportedParameter(body, var_S1, parameter_S1),
+ new ExportedParameter(body, var_S2, parameter_S2)
+ ));
+ // find turnoutOutput(S1, S2)
+ new PositivePatternCall(body, Tuples.flatTupleOf(var_S1, var_S2), TurnoutOutput.instance().getInternalQueryRepresentation());
+ bodies.add(body);
+ }
+ return bodies;
+ }
+ }
+}
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 @@
+/**
+ * Generated from platform:/resource/ca.mcgill.rtgmrt.example.modes3/src/modes3/queries/Modes3Queries.vql
+ */
+package modes3.queries;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+import java.util.function.Consumer;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import modes3.Turnout;
+import modes3.queries.TurnoutOutput;
+import org.apache.log4j.Logger;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.viatra.query.runtime.api.IPatternMatch;
+import org.eclipse.viatra.query.runtime.api.IQuerySpecification;
+import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine;
+import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
+import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification;
+import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher;
+import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch;
+import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey;
+import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
+import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
+import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
+import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation;
+import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference;
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall;
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
+import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
+import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
+import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
+import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
+import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
+import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
+
+/**
+ * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
+ *
+ *
+ *
+ * @see Matcher
+ * @see Match
+ *
+ */
+@SuppressWarnings("all")
+public final class OutputReflexive extends BaseGeneratedEMFQuerySpecification {
+ /**
+ * Pattern-specific match representation of the modes3.queries.outputReflexive pattern,
+ * to be used in conjunction with {@link Matcher}.
+ *
+ *
Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
+ * Each instance is a (possibly partial) substitution of pattern parameters,
+ * usable to represent a match of the pattern in the result of a query,
+ * or to specify the bound (fixed) input parameters when issuing a query.
+ *
+ * @see Matcher
+ *
+ */
+ public static abstract class Match extends BasePatternMatch {
+ private Turnout fT;
+
+ private static List parameterNames = makeImmutableList("T");
+
+ private Match(final Turnout pT) {
+ this.fT = pT;
+ }
+
+ @Override
+ public Object get(final String parameterName) {
+ switch(parameterName) {
+ case "T": return this.fT;
+ default: return null;
+ }
+ }
+
+ @Override
+ public Object get(final int index) {
+ switch(index) {
+ case 0: return this.fT;
+ default: return null;
+ }
+ }
+
+ public Turnout getT() {
+ return this.fT;
+ }
+
+ @Override
+ public boolean set(final String parameterName, final Object newValue) {
+ if (!isMutable()) throw new java.lang.UnsupportedOperationException();
+ if ("T".equals(parameterName) ) {
+ this.fT = (Turnout) newValue;
+ return true;
+ }
+ return false;
+ }
+
+ public void setT(final Turnout pT) {
+ if (!isMutable()) throw new java.lang.UnsupportedOperationException();
+ this.fT = pT;
+ }
+
+ @Override
+ public String patternName() {
+ return "modes3.queries.outputReflexive";
+ }
+
+ @Override
+ public List parameterNames() {
+ return OutputReflexive.Match.parameterNames;
+ }
+
+ @Override
+ public Object[] toArray() {
+ return new Object[]{fT};
+ }
+
+ @Override
+ public OutputReflexive.Match toImmutable() {
+ return isMutable() ? newMatch(fT) : this;
+ }
+
+ @Override
+ public String prettyPrint() {
+ StringBuilder result = new StringBuilder();
+ result.append("\"T\"=" + prettyPrintValue(fT));
+ return result.toString();
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(fT);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null) {
+ return false;
+ }
+ if ((obj instanceof OutputReflexive.Match)) {
+ OutputReflexive.Match other = (OutputReflexive.Match) obj;
+ return Objects.equals(fT, other.fT);
+ } else {
+ // this should be infrequent
+ if (!(obj instanceof IPatternMatch)) {
+ return false;
+ }
+ IPatternMatch otherSig = (IPatternMatch) obj;
+ return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
+ }
+ }
+
+ @Override
+ public OutputReflexive specification() {
+ return OutputReflexive.instance();
+ }
+
+ /**
+ * Returns an empty, mutable match.
+ * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
+ *
+ * @return the empty match.
+ *
+ */
+ public static OutputReflexive.Match newEmptyMatch() {
+ return new Mutable(null);
+ }
+
+ /**
+ * Returns a mutable (partial) match.
+ * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
+ *
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @return the new, mutable (partial) match object.
+ *
+ */
+ public static OutputReflexive.Match newMutableMatch(final Turnout pT) {
+ return new Mutable(pT);
+ }
+
+ /**
+ * Returns a new (partial) match.
+ * This can be used e.g. to call the matcher with a partial match.
+ *
The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @return the (partial) match object.
+ *
+ */
+ public static OutputReflexive.Match newMatch(final Turnout pT) {
+ return new Immutable(pT);
+ }
+
+ private static final class Mutable extends OutputReflexive.Match {
+ Mutable(final Turnout pT) {
+ super(pT);
+ }
+
+ @Override
+ public boolean isMutable() {
+ return true;
+ }
+ }
+
+ private static final class Immutable extends OutputReflexive.Match {
+ Immutable(final Turnout pT) {
+ super(pT);
+ }
+
+ @Override
+ public boolean isMutable() {
+ return false;
+ }
+ }
+ }
+
+ /**
+ * Generated pattern matcher API of the modes3.queries.outputReflexive pattern,
+ * providing pattern-specific query methods.
+ *
+ *
Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
+ * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
+ *
+ *
Matches of the pattern will be represented as {@link Match}.
+ *
+ *
+ *
+ * @see Match
+ * @see OutputReflexive
+ *
+ */
+ public static class Matcher extends BaseMatcher {
+ /**
+ * Initializes the pattern matcher within an existing VIATRA Query engine.
+ * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
+ *
+ * @param engine the existing VIATRA Query engine in which this matcher will be created.
+ * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
+ *
+ */
+ public static OutputReflexive.Matcher on(final ViatraQueryEngine engine) {
+ // check if matcher already exists
+ Matcher matcher = engine.getExistingMatcher(querySpecification());
+ if (matcher == null) {
+ matcher = (Matcher)engine.getMatcher(querySpecification());
+ }
+ return matcher;
+ }
+
+ /**
+ * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
+ * @return an initialized matcher
+ * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
+ *
+ */
+ public static OutputReflexive.Matcher create() {
+ return new Matcher();
+ }
+
+ private static final int POSITION_T = 0;
+
+ private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(OutputReflexive.Matcher.class);
+
+ /**
+ * Initializes the pattern matcher within an existing VIATRA Query engine.
+ * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
+ *
+ * @param engine the existing VIATRA Query engine in which this matcher will be created.
+ * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
+ *
+ */
+ private Matcher() {
+ super(querySpecification());
+ }
+
+ /**
+ * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @return matches represented as a Match object.
+ *
+ */
+ public Collection getAllMatches(final Turnout pT) {
+ return rawStreamAllMatches(new Object[]{pT}).collect(Collectors.toSet());
+ }
+
+ /**
+ * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
+ *
+ * NOTE: It is important not to modify the source model while the stream is being processed.
+ * If the match set of the pattern changes during processing, the contents of the stream is undefined.
+ * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @return a stream of matches represented as a Match object.
+ *
+ */
+ public Stream streamAllMatches(final Turnout pT) {
+ return rawStreamAllMatches(new Object[]{pT});
+ }
+
+ /**
+ * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
+ * Neither determinism nor randomness of selection is guaranteed.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @return a match represented as a Match object, or null if no match is found.
+ *
+ */
+ public Optional getOneArbitraryMatch(final Turnout pT) {
+ return rawGetOneArbitraryMatch(new Object[]{pT});
+ }
+
+ /**
+ * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
+ * under any possible substitution of the unspecified parameters (if any).
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @return true if the input is a valid (partial) match of the pattern.
+ *
+ */
+ public boolean hasMatch(final Turnout pT) {
+ return rawHasMatch(new Object[]{pT});
+ }
+
+ /**
+ * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @return the number of pattern matches found.
+ *
+ */
+ public int countMatches(final Turnout pT) {
+ return rawCountMatches(new Object[]{pT});
+ }
+
+ /**
+ * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
+ * Neither determinism nor randomness of selection is guaranteed.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @param processor the action that will process the selected match.
+ * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
+ *
+ */
+ public boolean forOneArbitraryMatch(final Turnout pT, final Consumer super OutputReflexive.Match> processor) {
+ return rawForOneArbitraryMatch(new Object[]{pT}, processor);
+ }
+
+ /**
+ * Returns a new (partial) match.
+ * This can be used e.g. to call the matcher with a partial match.
+ *
The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @return the (partial) match object.
+ *
+ */
+ public OutputReflexive.Match newMatch(final Turnout pT) {
+ return OutputReflexive.Match.newMatch(pT);
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for T.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ protected Stream rawStreamAllValuesOfT(final Object[] parameters) {
+ return rawStreamAllValues(POSITION_T, parameters).map(Turnout.class::cast);
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for T.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Set getAllValuesOfT() {
+ return rawStreamAllValuesOfT(emptyArray()).collect(Collectors.toSet());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for T.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Stream streamAllValuesOfT() {
+ return rawStreamAllValuesOfT(emptyArray());
+ }
+
+ @Override
+ protected OutputReflexive.Match tupleToMatch(final Tuple t) {
+ try {
+ return OutputReflexive.Match.newMatch((Turnout) t.get(POSITION_T));
+ } catch(ClassCastException e) {
+ LOGGER.error("Element(s) in tuple not properly typed!",e);
+ return null;
+ }
+ }
+
+ @Override
+ protected OutputReflexive.Match arrayToMatch(final Object[] match) {
+ try {
+ return OutputReflexive.Match.newMatch((Turnout) match[POSITION_T]);
+ } catch(ClassCastException e) {
+ LOGGER.error("Element(s) in array not properly typed!",e);
+ return null;
+ }
+ }
+
+ @Override
+ protected OutputReflexive.Match arrayToMatchMutable(final Object[] match) {
+ try {
+ return OutputReflexive.Match.newMutableMatch((Turnout) match[POSITION_T]);
+ } catch(ClassCastException e) {
+ LOGGER.error("Element(s) in array not properly typed!",e);
+ return null;
+ }
+ }
+
+ /**
+ * @return the singleton instance of the query specification of this pattern
+ * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
+ *
+ */
+ public static IQuerySpecification querySpecification() {
+ return OutputReflexive.instance();
+ }
+ }
+
+ private OutputReflexive() {
+ super(GeneratedPQuery.INSTANCE);
+ }
+
+ /**
+ * @return the singleton instance of the query specification
+ * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
+ *
+ */
+ public static OutputReflexive instance() {
+ try{
+ return LazyHolder.INSTANCE;
+ } catch (ExceptionInInitializerError err) {
+ throw processInitializerError(err);
+ }
+ }
+
+ @Override
+ protected OutputReflexive.Matcher instantiate(final ViatraQueryEngine engine) {
+ return OutputReflexive.Matcher.on(engine);
+ }
+
+ @Override
+ public OutputReflexive.Matcher instantiate() {
+ return OutputReflexive.Matcher.create();
+ }
+
+ @Override
+ public OutputReflexive.Match newEmptyMatch() {
+ return OutputReflexive.Match.newEmptyMatch();
+ }
+
+ @Override
+ public OutputReflexive.Match newMatch(final Object... parameters) {
+ return OutputReflexive.Match.newMatch((modes3.Turnout) parameters[0]);
+ }
+
+ /**
+ * Inner class allowing the singleton instance of {@link OutputReflexive} to be created
+ * not at the class load time of the outer class,
+ * but rather at the first call to {@link OutputReflexive#instance()}.
+ *
+ *
This workaround is required e.g. to support recursion.
+ *
+ */
+ private static class LazyHolder {
+ private static final OutputReflexive INSTANCE = new OutputReflexive();
+
+ /**
+ * Statically initializes the query specification after the field {@link #INSTANCE} is assigned.
+ * This initialization order is required to support indirect recursion.
+ *
+ *
The static initializer is defined using a helper field to work around limitations of the code generator.
+ *
+ */
+ private static final Object STATIC_INITIALIZER = ensureInitialized();
+
+ public static Object ensureInitialized() {
+ INSTANCE.ensureInitializedInternal();
+ return null;
+ }
+ }
+
+ private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
+ private static final OutputReflexive.GeneratedPQuery INSTANCE = new GeneratedPQuery();
+
+ private final PParameter parameter_T = new PParameter("T", "modes3.Turnout", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Turnout")), PParameterDirection.INOUT);
+
+ private final List parameters = Arrays.asList(parameter_T);
+
+ private GeneratedPQuery() {
+ super(PVisibility.PUBLIC);
+ }
+
+ @Override
+ public String getFullyQualifiedName() {
+ return "modes3.queries.outputReflexive";
+ }
+
+ @Override
+ public List getParameterNames() {
+ return Arrays.asList("T");
+ }
+
+ @Override
+ public List getParameters() {
+ return parameters;
+ }
+
+ @Override
+ public Set doGetContainedBodies() {
+ setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
+ Set bodies = new LinkedHashSet<>();
+ {
+ PBody body = new PBody(this);
+ PVariable var_T = body.getOrCreateVariableByName("T");
+ new TypeConstraint(body, Tuples.flatTupleOf(var_T), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Turnout")));
+ body.setSymbolicParameters(Arrays.asList(
+ new ExportedParameter(body, var_T, parameter_T)
+ ));
+ // find turnoutOutput(T, T)
+ new PositivePatternCall(body, Tuples.flatTupleOf(var_T, var_T), TurnoutOutput.instance().getInternalQueryRepresentation());
+ bodies.add(body);
+ }
+ {
+ PAnnotation annotation = new PAnnotation("Constraint");
+ annotation.addAttribute("message", "outputReflexive");
+ annotation.addAttribute("severity", "error");
+ annotation.addAttribute("key", Arrays.asList(new Object[] {
+ new ParameterReference("T")
+ }));
+ addAnnotation(annotation);
+ }
+ return bodies;
+ }
+ }
+}
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 @@
+/**
+ * Generated from platform:/resource/ca.mcgill.rtgmrt.example.modes3/src/modes3/queries/Modes3Queries.vql
+ */
+package modes3.queries;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+import java.util.function.Consumer;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import modes3.Segment;
+import modes3.queries.Adjacent;
+import org.apache.log4j.Logger;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.viatra.query.runtime.api.IPatternMatch;
+import org.eclipse.viatra.query.runtime.api.IQuerySpecification;
+import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine;
+import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
+import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification;
+import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher;
+import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch;
+import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey;
+import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
+import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
+import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality;
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.BinaryTransitiveClosure;
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
+import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
+import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
+import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
+import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
+import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
+import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
+
+/**
+ * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
+ *
+ *
+ *
+ * @see Matcher
+ * @see Match
+ *
+ */
+@SuppressWarnings("all")
+public final class Reachable extends BaseGeneratedEMFQuerySpecification {
+ /**
+ * Pattern-specific match representation of the modes3.queries.reachable pattern,
+ * to be used in conjunction with {@link Matcher}.
+ *
+ *
Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
+ * Each instance is a (possibly partial) substitution of pattern parameters,
+ * usable to represent a match of the pattern in the result of a query,
+ * or to specify the bound (fixed) input parameters when issuing a query.
+ *
+ * @see Matcher
+ *
+ */
+ public static abstract class Match extends BasePatternMatch {
+ private Segment fS1;
+
+ private Segment fS2;
+
+ private static List parameterNames = makeImmutableList("S1", "S2");
+
+ private Match(final Segment pS1, final Segment pS2) {
+ this.fS1 = pS1;
+ this.fS2 = pS2;
+ }
+
+ @Override
+ public Object get(final String parameterName) {
+ switch(parameterName) {
+ case "S1": return this.fS1;
+ case "S2": return this.fS2;
+ default: return null;
+ }
+ }
+
+ @Override
+ public Object get(final int index) {
+ switch(index) {
+ case 0: return this.fS1;
+ case 1: return this.fS2;
+ default: return null;
+ }
+ }
+
+ public Segment getS1() {
+ return this.fS1;
+ }
+
+ public Segment getS2() {
+ return this.fS2;
+ }
+
+ @Override
+ public boolean set(final String parameterName, final Object newValue) {
+ if (!isMutable()) throw new java.lang.UnsupportedOperationException();
+ if ("S1".equals(parameterName) ) {
+ this.fS1 = (Segment) newValue;
+ return true;
+ }
+ if ("S2".equals(parameterName) ) {
+ this.fS2 = (Segment) newValue;
+ return true;
+ }
+ return false;
+ }
+
+ public void setS1(final Segment pS1) {
+ if (!isMutable()) throw new java.lang.UnsupportedOperationException();
+ this.fS1 = pS1;
+ }
+
+ public void setS2(final Segment pS2) {
+ if (!isMutable()) throw new java.lang.UnsupportedOperationException();
+ this.fS2 = pS2;
+ }
+
+ @Override
+ public String patternName() {
+ return "modes3.queries.reachable";
+ }
+
+ @Override
+ public List parameterNames() {
+ return Reachable.Match.parameterNames;
+ }
+
+ @Override
+ public Object[] toArray() {
+ return new Object[]{fS1, fS2};
+ }
+
+ @Override
+ public Reachable.Match toImmutable() {
+ return isMutable() ? newMatch(fS1, fS2) : this;
+ }
+
+ @Override
+ public String prettyPrint() {
+ StringBuilder result = new StringBuilder();
+ result.append("\"S1\"=" + prettyPrintValue(fS1) + ", ");
+ result.append("\"S2\"=" + prettyPrintValue(fS2));
+ return result.toString();
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(fS1, fS2);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null) {
+ return false;
+ }
+ if ((obj instanceof Reachable.Match)) {
+ Reachable.Match other = (Reachable.Match) obj;
+ return Objects.equals(fS1, other.fS1) && Objects.equals(fS2, other.fS2);
+ } else {
+ // this should be infrequent
+ if (!(obj instanceof IPatternMatch)) {
+ return false;
+ }
+ IPatternMatch otherSig = (IPatternMatch) obj;
+ return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
+ }
+ }
+
+ @Override
+ public Reachable specification() {
+ return Reachable.instance();
+ }
+
+ /**
+ * Returns an empty, mutable match.
+ * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
+ *
+ * @return the empty match.
+ *
+ */
+ public static Reachable.Match newEmptyMatch() {
+ return new Mutable(null, null);
+ }
+
+ /**
+ * Returns a mutable (partial) match.
+ * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
+ *
+ * @param pS1 the fixed value of pattern parameter S1, or null if not bound.
+ * @param pS2 the fixed value of pattern parameter S2, or null if not bound.
+ * @return the new, mutable (partial) match object.
+ *
+ */
+ public static Reachable.Match newMutableMatch(final Segment pS1, final Segment pS2) {
+ return new Mutable(pS1, pS2);
+ }
+
+ /**
+ * Returns a new (partial) match.
+ * This can be used e.g. to call the matcher with a partial match.
+ *
The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
+ * @param pS1 the fixed value of pattern parameter S1, or null if not bound.
+ * @param pS2 the fixed value of pattern parameter S2, or null if not bound.
+ * @return the (partial) match object.
+ *
+ */
+ public static Reachable.Match newMatch(final Segment pS1, final Segment pS2) {
+ return new Immutable(pS1, pS2);
+ }
+
+ private static final class Mutable extends Reachable.Match {
+ Mutable(final Segment pS1, final Segment pS2) {
+ super(pS1, pS2);
+ }
+
+ @Override
+ public boolean isMutable() {
+ return true;
+ }
+ }
+
+ private static final class Immutable extends Reachable.Match {
+ Immutable(final Segment pS1, final Segment pS2) {
+ super(pS1, pS2);
+ }
+
+ @Override
+ public boolean isMutable() {
+ return false;
+ }
+ }
+ }
+
+ /**
+ * Generated pattern matcher API of the modes3.queries.reachable pattern,
+ * providing pattern-specific query methods.
+ *
+ *
Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
+ * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
+ *
+ *
Matches of the pattern will be represented as {@link Match}.
+ *
+ *
+ *
+ * @see Match
+ * @see Reachable
+ *
+ */
+ public static class Matcher extends BaseMatcher {
+ /**
+ * Initializes the pattern matcher within an existing VIATRA Query engine.
+ * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
+ *
+ * @param engine the existing VIATRA Query engine in which this matcher will be created.
+ * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
+ *
+ */
+ public static Reachable.Matcher on(final ViatraQueryEngine engine) {
+ // check if matcher already exists
+ Matcher matcher = engine.getExistingMatcher(querySpecification());
+ if (matcher == null) {
+ matcher = (Matcher)engine.getMatcher(querySpecification());
+ }
+ return matcher;
+ }
+
+ /**
+ * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
+ * @return an initialized matcher
+ * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
+ *
+ */
+ public static Reachable.Matcher create() {
+ return new Matcher();
+ }
+
+ private static final int POSITION_S1 = 0;
+
+ private static final int POSITION_S2 = 1;
+
+ private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Reachable.Matcher.class);
+
+ /**
+ * Initializes the pattern matcher within an existing VIATRA Query engine.
+ * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
+ *
+ * @param engine the existing VIATRA Query engine in which this matcher will be created.
+ * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
+ *
+ */
+ private Matcher() {
+ super(querySpecification());
+ }
+
+ /**
+ * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
+ * @param pS1 the fixed value of pattern parameter S1, or null if not bound.
+ * @param pS2 the fixed value of pattern parameter S2, or null if not bound.
+ * @return matches represented as a Match object.
+ *
+ */
+ public Collection getAllMatches(final Segment pS1, final Segment pS2) {
+ return rawStreamAllMatches(new Object[]{pS1, pS2}).collect(Collectors.toSet());
+ }
+
+ /**
+ * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
+ *
+ * NOTE: It is important not to modify the source model while the stream is being processed.
+ * If the match set of the pattern changes during processing, the contents of the stream is undefined.
+ * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
+ * @param pS1 the fixed value of pattern parameter S1, or null if not bound.
+ * @param pS2 the fixed value of pattern parameter S2, or null if not bound.
+ * @return a stream of matches represented as a Match object.
+ *
+ */
+ public Stream streamAllMatches(final Segment pS1, final Segment pS2) {
+ return rawStreamAllMatches(new Object[]{pS1, pS2});
+ }
+
+ /**
+ * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
+ * Neither determinism nor randomness of selection is guaranteed.
+ * @param pS1 the fixed value of pattern parameter S1, or null if not bound.
+ * @param pS2 the fixed value of pattern parameter S2, or null if not bound.
+ * @return a match represented as a Match object, or null if no match is found.
+ *
+ */
+ public Optional getOneArbitraryMatch(final Segment pS1, final Segment pS2) {
+ return rawGetOneArbitraryMatch(new Object[]{pS1, pS2});
+ }
+
+ /**
+ * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
+ * under any possible substitution of the unspecified parameters (if any).
+ * @param pS1 the fixed value of pattern parameter S1, or null if not bound.
+ * @param pS2 the fixed value of pattern parameter S2, or null if not bound.
+ * @return true if the input is a valid (partial) match of the pattern.
+ *
+ */
+ public boolean hasMatch(final Segment pS1, final Segment pS2) {
+ return rawHasMatch(new Object[]{pS1, pS2});
+ }
+
+ /**
+ * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
+ * @param pS1 the fixed value of pattern parameter S1, or null if not bound.
+ * @param pS2 the fixed value of pattern parameter S2, or null if not bound.
+ * @return the number of pattern matches found.
+ *
+ */
+ public int countMatches(final Segment pS1, final Segment pS2) {
+ return rawCountMatches(new Object[]{pS1, pS2});
+ }
+
+ /**
+ * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
+ * Neither determinism nor randomness of selection is guaranteed.
+ * @param pS1 the fixed value of pattern parameter S1, or null if not bound.
+ * @param pS2 the fixed value of pattern parameter S2, or null if not bound.
+ * @param processor the action that will process the selected match.
+ * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
+ *
+ */
+ public boolean forOneArbitraryMatch(final Segment pS1, final Segment pS2, final Consumer super Reachable.Match> processor) {
+ return rawForOneArbitraryMatch(new Object[]{pS1, pS2}, processor);
+ }
+
+ /**
+ * Returns a new (partial) match.
+ * This can be used e.g. to call the matcher with a partial match.
+ *
The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
+ * @param pS1 the fixed value of pattern parameter S1, or null if not bound.
+ * @param pS2 the fixed value of pattern parameter S2, or null if not bound.
+ * @return the (partial) match object.
+ *
+ */
+ public Reachable.Match newMatch(final Segment pS1, final Segment pS2) {
+ return Reachable.Match.newMatch(pS1, pS2);
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S1.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ protected Stream rawStreamAllValuesOfS1(final Object[] parameters) {
+ return rawStreamAllValues(POSITION_S1, parameters).map(Segment.class::cast);
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S1.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Set getAllValuesOfS1() {
+ return rawStreamAllValuesOfS1(emptyArray()).collect(Collectors.toSet());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S1.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Stream streamAllValuesOfS1() {
+ return rawStreamAllValuesOfS1(emptyArray());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S1.
+ *
+ * NOTE: It is important not to modify the source model while the stream is being processed.
+ * If the match set of the pattern changes during processing, the contents of the stream is undefined.
+ * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
+ *
+ * @return the Stream of all values or empty set if there are no matches
+ *
+ */
+ public Stream streamAllValuesOfS1(final Reachable.Match partialMatch) {
+ return rawStreamAllValuesOfS1(partialMatch.toArray());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S1.
+ *
+ * NOTE: It is important not to modify the source model while the stream is being processed.
+ * If the match set of the pattern changes during processing, the contents of the stream is undefined.
+ * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
+ *
+ * @return the Stream of all values or empty set if there are no matches
+ *
+ */
+ public Stream streamAllValuesOfS1(final Segment pS2) {
+ return rawStreamAllValuesOfS1(new Object[]{null, pS2});
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S1.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Set getAllValuesOfS1(final Reachable.Match partialMatch) {
+ return rawStreamAllValuesOfS1(partialMatch.toArray()).collect(Collectors.toSet());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S1.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Set getAllValuesOfS1(final Segment pS2) {
+ return rawStreamAllValuesOfS1(new Object[]{null, pS2}).collect(Collectors.toSet());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S2.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ protected Stream rawStreamAllValuesOfS2(final Object[] parameters) {
+ return rawStreamAllValues(POSITION_S2, parameters).map(Segment.class::cast);
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S2.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Set getAllValuesOfS2() {
+ return rawStreamAllValuesOfS2(emptyArray()).collect(Collectors.toSet());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S2.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Stream streamAllValuesOfS2() {
+ return rawStreamAllValuesOfS2(emptyArray());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S2.
+ *
+ * NOTE: It is important not to modify the source model while the stream is being processed.
+ * If the match set of the pattern changes during processing, the contents of the stream is undefined.
+ * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
+ *
+ * @return the Stream of all values or empty set if there are no matches
+ *
+ */
+ public Stream streamAllValuesOfS2(final Reachable.Match partialMatch) {
+ return rawStreamAllValuesOfS2(partialMatch.toArray());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S2.
+ *
+ * NOTE: It is important not to modify the source model while the stream is being processed.
+ * If the match set of the pattern changes during processing, the contents of the stream is undefined.
+ * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
+ *
+ * @return the Stream of all values or empty set if there are no matches
+ *
+ */
+ public Stream streamAllValuesOfS2(final Segment pS1) {
+ return rawStreamAllValuesOfS2(new Object[]{pS1, null});
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S2.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Set getAllValuesOfS2(final Reachable.Match partialMatch) {
+ return rawStreamAllValuesOfS2(partialMatch.toArray()).collect(Collectors.toSet());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S2.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Set getAllValuesOfS2(final Segment pS1) {
+ return rawStreamAllValuesOfS2(new Object[]{pS1, null}).collect(Collectors.toSet());
+ }
+
+ @Override
+ protected Reachable.Match tupleToMatch(final Tuple t) {
+ try {
+ return Reachable.Match.newMatch((Segment) t.get(POSITION_S1), (Segment) t.get(POSITION_S2));
+ } catch(ClassCastException e) {
+ LOGGER.error("Element(s) in tuple not properly typed!",e);
+ return null;
+ }
+ }
+
+ @Override
+ protected Reachable.Match arrayToMatch(final Object[] match) {
+ try {
+ return Reachable.Match.newMatch((Segment) match[POSITION_S1], (Segment) match[POSITION_S2]);
+ } catch(ClassCastException e) {
+ LOGGER.error("Element(s) in array not properly typed!",e);
+ return null;
+ }
+ }
+
+ @Override
+ protected Reachable.Match arrayToMatchMutable(final Object[] match) {
+ try {
+ return Reachable.Match.newMutableMatch((Segment) match[POSITION_S1], (Segment) match[POSITION_S2]);
+ } catch(ClassCastException e) {
+ LOGGER.error("Element(s) in array not properly typed!",e);
+ return null;
+ }
+ }
+
+ /**
+ * @return the singleton instance of the query specification of this pattern
+ * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
+ *
+ */
+ public static IQuerySpecification querySpecification() {
+ return Reachable.instance();
+ }
+ }
+
+ private Reachable() {
+ super(GeneratedPQuery.INSTANCE);
+ }
+
+ /**
+ * @return the singleton instance of the query specification
+ * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
+ *
+ */
+ public static Reachable instance() {
+ try{
+ return LazyHolder.INSTANCE;
+ } catch (ExceptionInInitializerError err) {
+ throw processInitializerError(err);
+ }
+ }
+
+ @Override
+ protected Reachable.Matcher instantiate(final ViatraQueryEngine engine) {
+ return Reachable.Matcher.on(engine);
+ }
+
+ @Override
+ public Reachable.Matcher instantiate() {
+ return Reachable.Matcher.create();
+ }
+
+ @Override
+ public Reachable.Match newEmptyMatch() {
+ return Reachable.Match.newEmptyMatch();
+ }
+
+ @Override
+ public Reachable.Match newMatch(final Object... parameters) {
+ return Reachable.Match.newMatch((modes3.Segment) parameters[0], (modes3.Segment) parameters[1]);
+ }
+
+ /**
+ * Inner class allowing the singleton instance of {@link Reachable} to be created
+ * not at the class load time of the outer class,
+ * but rather at the first call to {@link Reachable#instance()}.
+ *
+ *
This workaround is required e.g. to support recursion.
+ *
+ */
+ private static class LazyHolder {
+ private static final Reachable INSTANCE = new Reachable();
+
+ /**
+ * Statically initializes the query specification after the field {@link #INSTANCE} is assigned.
+ * This initialization order is required to support indirect recursion.
+ *
+ *
The static initializer is defined using a helper field to work around limitations of the code generator.
+ *
+ */
+ private static final Object STATIC_INITIALIZER = ensureInitialized();
+
+ public static Object ensureInitialized() {
+ INSTANCE.ensureInitializedInternal();
+ return null;
+ }
+ }
+
+ private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
+ private static final Reachable.GeneratedPQuery INSTANCE = new GeneratedPQuery();
+
+ private final PParameter parameter_S1 = new PParameter("S1", "modes3.Segment", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Segment")), PParameterDirection.INOUT);
+
+ private final PParameter parameter_S2 = new PParameter("S2", "modes3.Segment", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Segment")), PParameterDirection.INOUT);
+
+ private final List parameters = Arrays.asList(parameter_S1, parameter_S2);
+
+ private GeneratedPQuery() {
+ super(PVisibility.PUBLIC);
+ }
+
+ @Override
+ public String getFullyQualifiedName() {
+ return "modes3.queries.reachable";
+ }
+
+ @Override
+ public List getParameterNames() {
+ return Arrays.asList("S1","S2");
+ }
+
+ @Override
+ public List getParameters() {
+ return parameters;
+ }
+
+ @Override
+ public Set doGetContainedBodies() {
+ setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
+ Set bodies = new LinkedHashSet<>();
+ {
+ PBody body = new PBody(this);
+ PVariable var_S1 = body.getOrCreateVariableByName("S1");
+ PVariable var_S2 = body.getOrCreateVariableByName("S2");
+ new TypeConstraint(body, Tuples.flatTupleOf(var_S1), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
+ new TypeConstraint(body, Tuples.flatTupleOf(var_S2), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
+ body.setSymbolicParameters(Arrays.asList(
+ new ExportedParameter(body, var_S1, parameter_S1),
+ new ExportedParameter(body, var_S2, parameter_S2)
+ ));
+ // S1 == S2
+ new Equality(body, var_S1, var_S2);
+ bodies.add(body);
+ }
+ {
+ PBody body = new PBody(this);
+ PVariable var_S1 = body.getOrCreateVariableByName("S1");
+ PVariable var_S2 = body.getOrCreateVariableByName("S2");
+ new TypeConstraint(body, Tuples.flatTupleOf(var_S1), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
+ new TypeConstraint(body, Tuples.flatTupleOf(var_S2), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
+ body.setSymbolicParameters(Arrays.asList(
+ new ExportedParameter(body, var_S1, parameter_S1),
+ new ExportedParameter(body, var_S2, parameter_S2)
+ ));
+ // find adjacent+(S1, S2)
+ new BinaryTransitiveClosure(body, Tuples.flatTupleOf(var_S1, var_S2), Adjacent.instance().getInternalQueryRepresentation());
+ bodies.add(body);
+ }
+ return bodies;
+ }
+ }
+}
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/TooManyExtraInputsOfTurnout.java b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/TooManyExtraInputsOfTurnout.java
new file mode 100644
index 00000000..9f417795
--- /dev/null
+++ b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/TooManyExtraInputsOfTurnout.java
@@ -0,0 +1,570 @@
+/**
+ * Generated from platform:/resource/ca.mcgill.rtgmrt.example.modes3/src/modes3/queries/Modes3Queries.vql
+ */
+package modes3.queries;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+import java.util.function.Consumer;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import modes3.Turnout;
+import modes3.queries.ExtraInputOfTurnout;
+import org.apache.log4j.Logger;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.viatra.query.runtime.api.IPatternMatch;
+import org.eclipse.viatra.query.runtime.api.IQuerySpecification;
+import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine;
+import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
+import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification;
+import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher;
+import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch;
+import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey;
+import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
+import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
+import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
+import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation;
+import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference;
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Inequality;
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall;
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
+import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
+import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
+import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
+import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
+import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
+import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
+
+/**
+ * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
+ *
+ *
+ *
+ * @see Matcher
+ * @see Match
+ *
+ */
+@SuppressWarnings("all")
+public final class TooManyExtraInputsOfTurnout extends BaseGeneratedEMFQuerySpecification {
+ /**
+ * Pattern-specific match representation of the modes3.queries.tooManyExtraInputsOfTurnout pattern,
+ * to be used in conjunction with {@link Matcher}.
+ *
+ *
Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
+ * Each instance is a (possibly partial) substitution of pattern parameters,
+ * usable to represent a match of the pattern in the result of a query,
+ * or to specify the bound (fixed) input parameters when issuing a query.
+ *
+ * @see Matcher
+ *
+ */
+ public static abstract class Match extends BasePatternMatch {
+ private Turnout fT;
+
+ private static List parameterNames = makeImmutableList("T");
+
+ private Match(final Turnout pT) {
+ this.fT = pT;
+ }
+
+ @Override
+ public Object get(final String parameterName) {
+ switch(parameterName) {
+ case "T": return this.fT;
+ default: return null;
+ }
+ }
+
+ @Override
+ public Object get(final int index) {
+ switch(index) {
+ case 0: return this.fT;
+ default: return null;
+ }
+ }
+
+ public Turnout getT() {
+ return this.fT;
+ }
+
+ @Override
+ public boolean set(final String parameterName, final Object newValue) {
+ if (!isMutable()) throw new java.lang.UnsupportedOperationException();
+ if ("T".equals(parameterName) ) {
+ this.fT = (Turnout) newValue;
+ return true;
+ }
+ return false;
+ }
+
+ public void setT(final Turnout pT) {
+ if (!isMutable()) throw new java.lang.UnsupportedOperationException();
+ this.fT = pT;
+ }
+
+ @Override
+ public String patternName() {
+ return "modes3.queries.tooManyExtraInputsOfTurnout";
+ }
+
+ @Override
+ public List parameterNames() {
+ return TooManyExtraInputsOfTurnout.Match.parameterNames;
+ }
+
+ @Override
+ public Object[] toArray() {
+ return new Object[]{fT};
+ }
+
+ @Override
+ public TooManyExtraInputsOfTurnout.Match toImmutable() {
+ return isMutable() ? newMatch(fT) : this;
+ }
+
+ @Override
+ public String prettyPrint() {
+ StringBuilder result = new StringBuilder();
+ result.append("\"T\"=" + prettyPrintValue(fT));
+ return result.toString();
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(fT);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null) {
+ return false;
+ }
+ if ((obj instanceof TooManyExtraInputsOfTurnout.Match)) {
+ TooManyExtraInputsOfTurnout.Match other = (TooManyExtraInputsOfTurnout.Match) obj;
+ return Objects.equals(fT, other.fT);
+ } else {
+ // this should be infrequent
+ if (!(obj instanceof IPatternMatch)) {
+ return false;
+ }
+ IPatternMatch otherSig = (IPatternMatch) obj;
+ return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
+ }
+ }
+
+ @Override
+ public TooManyExtraInputsOfTurnout specification() {
+ return TooManyExtraInputsOfTurnout.instance();
+ }
+
+ /**
+ * Returns an empty, mutable match.
+ * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
+ *
+ * @return the empty match.
+ *
+ */
+ public static TooManyExtraInputsOfTurnout.Match newEmptyMatch() {
+ return new Mutable(null);
+ }
+
+ /**
+ * Returns a mutable (partial) match.
+ * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
+ *
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @return the new, mutable (partial) match object.
+ *
+ */
+ public static TooManyExtraInputsOfTurnout.Match newMutableMatch(final Turnout pT) {
+ return new Mutable(pT);
+ }
+
+ /**
+ * Returns a new (partial) match.
+ * This can be used e.g. to call the matcher with a partial match.
+ *
The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @return the (partial) match object.
+ *
+ */
+ public static TooManyExtraInputsOfTurnout.Match newMatch(final Turnout pT) {
+ return new Immutable(pT);
+ }
+
+ private static final class Mutable extends TooManyExtraInputsOfTurnout.Match {
+ Mutable(final Turnout pT) {
+ super(pT);
+ }
+
+ @Override
+ public boolean isMutable() {
+ return true;
+ }
+ }
+
+ private static final class Immutable extends TooManyExtraInputsOfTurnout.Match {
+ Immutable(final Turnout pT) {
+ super(pT);
+ }
+
+ @Override
+ public boolean isMutable() {
+ return false;
+ }
+ }
+ }
+
+ /**
+ * Generated pattern matcher API of the modes3.queries.tooManyExtraInputsOfTurnout pattern,
+ * providing pattern-specific query methods.
+ *
+ *
Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
+ * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
+ *
+ *
Matches of the pattern will be represented as {@link Match}.
+ *
+ *
+ *
+ * @see Match
+ * @see TooManyExtraInputsOfTurnout
+ *
+ */
+ public static class Matcher extends BaseMatcher {
+ /**
+ * Initializes the pattern matcher within an existing VIATRA Query engine.
+ * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
+ *
+ * @param engine the existing VIATRA Query engine in which this matcher will be created.
+ * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
+ *
+ */
+ public static TooManyExtraInputsOfTurnout.Matcher on(final ViatraQueryEngine engine) {
+ // check if matcher already exists
+ Matcher matcher = engine.getExistingMatcher(querySpecification());
+ if (matcher == null) {
+ matcher = (Matcher)engine.getMatcher(querySpecification());
+ }
+ return matcher;
+ }
+
+ /**
+ * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
+ * @return an initialized matcher
+ * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
+ *
+ */
+ public static TooManyExtraInputsOfTurnout.Matcher create() {
+ return new Matcher();
+ }
+
+ private static final int POSITION_T = 0;
+
+ private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(TooManyExtraInputsOfTurnout.Matcher.class);
+
+ /**
+ * Initializes the pattern matcher within an existing VIATRA Query engine.
+ * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
+ *
+ * @param engine the existing VIATRA Query engine in which this matcher will be created.
+ * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
+ *
+ */
+ private Matcher() {
+ super(querySpecification());
+ }
+
+ /**
+ * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @return matches represented as a Match object.
+ *
+ */
+ public Collection getAllMatches(final Turnout pT) {
+ return rawStreamAllMatches(new Object[]{pT}).collect(Collectors.toSet());
+ }
+
+ /**
+ * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
+ *
+ * NOTE: It is important not to modify the source model while the stream is being processed.
+ * If the match set of the pattern changes during processing, the contents of the stream is undefined.
+ * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @return a stream of matches represented as a Match object.
+ *
+ */
+ public Stream streamAllMatches(final Turnout pT) {
+ return rawStreamAllMatches(new Object[]{pT});
+ }
+
+ /**
+ * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
+ * Neither determinism nor randomness of selection is guaranteed.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @return a match represented as a Match object, or null if no match is found.
+ *
+ */
+ public Optional getOneArbitraryMatch(final Turnout pT) {
+ return rawGetOneArbitraryMatch(new Object[]{pT});
+ }
+
+ /**
+ * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
+ * under any possible substitution of the unspecified parameters (if any).
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @return true if the input is a valid (partial) match of the pattern.
+ *
+ */
+ public boolean hasMatch(final Turnout pT) {
+ return rawHasMatch(new Object[]{pT});
+ }
+
+ /**
+ * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @return the number of pattern matches found.
+ *
+ */
+ public int countMatches(final Turnout pT) {
+ return rawCountMatches(new Object[]{pT});
+ }
+
+ /**
+ * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
+ * Neither determinism nor randomness of selection is guaranteed.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @param processor the action that will process the selected match.
+ * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
+ *
+ */
+ public boolean forOneArbitraryMatch(final Turnout pT, final Consumer super TooManyExtraInputsOfTurnout.Match> processor) {
+ return rawForOneArbitraryMatch(new Object[]{pT}, processor);
+ }
+
+ /**
+ * Returns a new (partial) match.
+ * This can be used e.g. to call the matcher with a partial match.
+ *
The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @return the (partial) match object.
+ *
+ */
+ public TooManyExtraInputsOfTurnout.Match newMatch(final Turnout pT) {
+ return TooManyExtraInputsOfTurnout.Match.newMatch(pT);
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for T.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ protected Stream rawStreamAllValuesOfT(final Object[] parameters) {
+ return rawStreamAllValues(POSITION_T, parameters).map(Turnout.class::cast);
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for T.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Set getAllValuesOfT() {
+ return rawStreamAllValuesOfT(emptyArray()).collect(Collectors.toSet());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for T.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Stream streamAllValuesOfT() {
+ return rawStreamAllValuesOfT(emptyArray());
+ }
+
+ @Override
+ protected TooManyExtraInputsOfTurnout.Match tupleToMatch(final Tuple t) {
+ try {
+ return TooManyExtraInputsOfTurnout.Match.newMatch((Turnout) t.get(POSITION_T));
+ } catch(ClassCastException e) {
+ LOGGER.error("Element(s) in tuple not properly typed!",e);
+ return null;
+ }
+ }
+
+ @Override
+ protected TooManyExtraInputsOfTurnout.Match arrayToMatch(final Object[] match) {
+ try {
+ return TooManyExtraInputsOfTurnout.Match.newMatch((Turnout) match[POSITION_T]);
+ } catch(ClassCastException e) {
+ LOGGER.error("Element(s) in array not properly typed!",e);
+ return null;
+ }
+ }
+
+ @Override
+ protected TooManyExtraInputsOfTurnout.Match arrayToMatchMutable(final Object[] match) {
+ try {
+ return TooManyExtraInputsOfTurnout.Match.newMutableMatch((Turnout) match[POSITION_T]);
+ } catch(ClassCastException e) {
+ LOGGER.error("Element(s) in array not properly typed!",e);
+ return null;
+ }
+ }
+
+ /**
+ * @return the singleton instance of the query specification of this pattern
+ * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
+ *
+ */
+ public static IQuerySpecification querySpecification() {
+ return TooManyExtraInputsOfTurnout.instance();
+ }
+ }
+
+ private TooManyExtraInputsOfTurnout() {
+ super(GeneratedPQuery.INSTANCE);
+ }
+
+ /**
+ * @return the singleton instance of the query specification
+ * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
+ *
+ */
+ public static TooManyExtraInputsOfTurnout instance() {
+ try{
+ return LazyHolder.INSTANCE;
+ } catch (ExceptionInInitializerError err) {
+ throw processInitializerError(err);
+ }
+ }
+
+ @Override
+ protected TooManyExtraInputsOfTurnout.Matcher instantiate(final ViatraQueryEngine engine) {
+ return TooManyExtraInputsOfTurnout.Matcher.on(engine);
+ }
+
+ @Override
+ public TooManyExtraInputsOfTurnout.Matcher instantiate() {
+ return TooManyExtraInputsOfTurnout.Matcher.create();
+ }
+
+ @Override
+ public TooManyExtraInputsOfTurnout.Match newEmptyMatch() {
+ return TooManyExtraInputsOfTurnout.Match.newEmptyMatch();
+ }
+
+ @Override
+ public TooManyExtraInputsOfTurnout.Match newMatch(final Object... parameters) {
+ return TooManyExtraInputsOfTurnout.Match.newMatch((modes3.Turnout) parameters[0]);
+ }
+
+ /**
+ * Inner class allowing the singleton instance of {@link TooManyExtraInputsOfTurnout} to be created
+ * not at the class load time of the outer class,
+ * but rather at the first call to {@link TooManyExtraInputsOfTurnout#instance()}.
+ *
+ *
This workaround is required e.g. to support recursion.
+ *
+ */
+ private static class LazyHolder {
+ private static final TooManyExtraInputsOfTurnout INSTANCE = new TooManyExtraInputsOfTurnout();
+
+ /**
+ * Statically initializes the query specification after the field {@link #INSTANCE} is assigned.
+ * This initialization order is required to support indirect recursion.
+ *
+ *
The static initializer is defined using a helper field to work around limitations of the code generator.
+ *
+ */
+ private static final Object STATIC_INITIALIZER = ensureInitialized();
+
+ public static Object ensureInitialized() {
+ INSTANCE.ensureInitializedInternal();
+ return null;
+ }
+ }
+
+ private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
+ private static final TooManyExtraInputsOfTurnout.GeneratedPQuery INSTANCE = new GeneratedPQuery();
+
+ private final PParameter parameter_T = new PParameter("T", "modes3.Turnout", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Turnout")), PParameterDirection.INOUT);
+
+ private final List parameters = Arrays.asList(parameter_T);
+
+ private GeneratedPQuery() {
+ super(PVisibility.PUBLIC);
+ }
+
+ @Override
+ public String getFullyQualifiedName() {
+ return "modes3.queries.tooManyExtraInputsOfTurnout";
+ }
+
+ @Override
+ public List getParameterNames() {
+ return Arrays.asList("T");
+ }
+
+ @Override
+ public List getParameters() {
+ return parameters;
+ }
+
+ @Override
+ public Set doGetContainedBodies() {
+ setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
+ Set bodies = new LinkedHashSet<>();
+ {
+ PBody body = new PBody(this);
+ PVariable var_T = body.getOrCreateVariableByName("T");
+ PVariable var_I1 = body.getOrCreateVariableByName("I1");
+ PVariable var_I2 = body.getOrCreateVariableByName("I2");
+ new TypeConstraint(body, Tuples.flatTupleOf(var_T), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Turnout")));
+ body.setSymbolicParameters(Arrays.asList(
+ new ExportedParameter(body, var_T, parameter_T)
+ ));
+ // find extraInputOfTurnout(T, I1)
+ new PositivePatternCall(body, Tuples.flatTupleOf(var_T, var_I1), ExtraInputOfTurnout.instance().getInternalQueryRepresentation());
+ // find extraInputOfTurnout(T, I2)
+ new PositivePatternCall(body, Tuples.flatTupleOf(var_T, var_I2), ExtraInputOfTurnout.instance().getInternalQueryRepresentation());
+ // I1 != I2
+ new Inequality(body, var_I1, var_I2);
+ bodies.add(body);
+ }
+ {
+ PAnnotation annotation = new PAnnotation("Constraint");
+ annotation.addAttribute("message", "tooManyExtraInputsOfTurnout");
+ annotation.addAttribute("severity", "error");
+ annotation.addAttribute("key", Arrays.asList(new Object[] {
+ new ParameterReference("T")
+ }));
+ addAnnotation(annotation);
+ }
+ return bodies;
+ }
+ }
+}
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..e5e8827c
--- /dev/null
+++ b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/TooManyInputsOfSegment.java
@@ -0,0 +1,601 @@
+/**
+ * Generated from platform:/resource/ca.mcgill.rtgmrt.example.modes3/src/modes3/queries/Modes3Queries.vql
+ */
+package modes3.queries;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+import java.util.function.Consumer;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import modes3.Segment;
+import modes3.queries.Output;
+import modes3.queries.Turnout;
+import org.apache.log4j.Logger;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.viatra.query.runtime.api.IPatternMatch;
+import org.eclipse.viatra.query.runtime.api.IQuerySpecification;
+import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine;
+import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
+import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification;
+import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher;
+import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch;
+import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey;
+import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
+import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
+import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
+import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation;
+import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference;
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Inequality;
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.NegativePatternCall;
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall;
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
+import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
+import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
+import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
+import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
+import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
+import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
+
+/**
+ * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
+ *
+ *
+ *
+ * @see Matcher
+ * @see Match
+ *
+ */
+@SuppressWarnings("all")
+public final class TooManyInputsOfSegment extends BaseGeneratedEMFQuerySpecification {
+ /**
+ * Pattern-specific match representation of the modes3.queries.tooManyInputsOfSegment pattern,
+ * to be used in conjunction with {@link Matcher}.
+ *
+ *
Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
+ * Each instance is a (possibly partial) substitution of pattern parameters,
+ * usable to represent a match of the pattern in the result of a query,
+ * or to specify the bound (fixed) input parameters when issuing a query.
+ *
+ * @see Matcher
+ *
+ */
+ public static abstract class Match extends BasePatternMatch {
+ private Segment fS;
+
+ private static List parameterNames = makeImmutableList("S");
+
+ private Match(final Segment pS) {
+ this.fS = pS;
+ }
+
+ @Override
+ public Object get(final String parameterName) {
+ switch(parameterName) {
+ case "S": return this.fS;
+ default: return null;
+ }
+ }
+
+ @Override
+ public Object get(final int index) {
+ switch(index) {
+ case 0: return this.fS;
+ default: return null;
+ }
+ }
+
+ public Segment getS() {
+ return this.fS;
+ }
+
+ @Override
+ public boolean set(final String parameterName, final Object newValue) {
+ if (!isMutable()) throw new java.lang.UnsupportedOperationException();
+ if ("S".equals(parameterName) ) {
+ this.fS = (Segment) newValue;
+ return true;
+ }
+ return false;
+ }
+
+ public void setS(final Segment pS) {
+ if (!isMutable()) throw new java.lang.UnsupportedOperationException();
+ this.fS = pS;
+ }
+
+ @Override
+ public String patternName() {
+ return "modes3.queries.tooManyInputsOfSegment";
+ }
+
+ @Override
+ public List parameterNames() {
+ return TooManyInputsOfSegment.Match.parameterNames;
+ }
+
+ @Override
+ public Object[] toArray() {
+ return new Object[]{fS};
+ }
+
+ @Override
+ public TooManyInputsOfSegment.Match toImmutable() {
+ return isMutable() ? newMatch(fS) : this;
+ }
+
+ @Override
+ public String prettyPrint() {
+ StringBuilder result = new StringBuilder();
+ result.append("\"S\"=" + prettyPrintValue(fS));
+ return result.toString();
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(fS);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null) {
+ return false;
+ }
+ if ((obj instanceof TooManyInputsOfSegment.Match)) {
+ TooManyInputsOfSegment.Match other = (TooManyInputsOfSegment.Match) obj;
+ return Objects.equals(fS, other.fS);
+ } else {
+ // this should be infrequent
+ if (!(obj instanceof IPatternMatch)) {
+ return false;
+ }
+ IPatternMatch otherSig = (IPatternMatch) obj;
+ return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
+ }
+ }
+
+ @Override
+ public TooManyInputsOfSegment specification() {
+ return TooManyInputsOfSegment.instance();
+ }
+
+ /**
+ * Returns an empty, mutable match.
+ * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
+ *
+ * @return the empty match.
+ *
+ */
+ public static TooManyInputsOfSegment.Match newEmptyMatch() {
+ return new Mutable(null);
+ }
+
+ /**
+ * Returns a mutable (partial) match.
+ * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
+ *
+ * @param pS the fixed value of pattern parameter S, or null if not bound.
+ * @return the new, mutable (partial) match object.
+ *
+ */
+ public static TooManyInputsOfSegment.Match newMutableMatch(final Segment pS) {
+ return new Mutable(pS);
+ }
+
+ /**
+ * Returns a new (partial) match.
+ * This can be used e.g. to call the matcher with a partial match.
+ *
The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
+ * @param pS the fixed value of pattern parameter S, or null if not bound.
+ * @return the (partial) match object.
+ *
+ */
+ public static TooManyInputsOfSegment.Match newMatch(final Segment pS) {
+ return new Immutable(pS);
+ }
+
+ private static final class Mutable extends TooManyInputsOfSegment.Match {
+ Mutable(final Segment pS) {
+ super(pS);
+ }
+
+ @Override
+ public boolean isMutable() {
+ return true;
+ }
+ }
+
+ private static final class Immutable extends TooManyInputsOfSegment.Match {
+ Immutable(final Segment pS) {
+ super(pS);
+ }
+
+ @Override
+ public boolean isMutable() {
+ return false;
+ }
+ }
+ }
+
+ /**
+ * Generated pattern matcher API of the modes3.queries.tooManyInputsOfSegment pattern,
+ * providing pattern-specific query methods.
+ *
+ *
Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
+ * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
+ *
+ *
Matches of the pattern will be represented as {@link Match}.
+ *
+ *
+ *
+ * @see Match
+ * @see TooManyInputsOfSegment
+ *
+ */
+ public static class Matcher extends BaseMatcher {
+ /**
+ * Initializes the pattern matcher within an existing VIATRA Query engine.
+ * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
+ *
+ * @param engine the existing VIATRA Query engine in which this matcher will be created.
+ * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
+ *
+ */
+ public static TooManyInputsOfSegment.Matcher on(final ViatraQueryEngine engine) {
+ // check if matcher already exists
+ Matcher matcher = engine.getExistingMatcher(querySpecification());
+ if (matcher == null) {
+ matcher = (Matcher)engine.getMatcher(querySpecification());
+ }
+ return matcher;
+ }
+
+ /**
+ * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
+ * @return an initialized matcher
+ * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
+ *
+ */
+ public static TooManyInputsOfSegment.Matcher create() {
+ return new Matcher();
+ }
+
+ private static final int POSITION_S = 0;
+
+ private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(TooManyInputsOfSegment.Matcher.class);
+
+ /**
+ * Initializes the pattern matcher within an existing VIATRA Query engine.
+ * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
+ *
+ * @param engine the existing VIATRA Query engine in which this matcher will be created.
+ * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
+ *
+ */
+ private Matcher() {
+ super(querySpecification());
+ }
+
+ /**
+ * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
+ * @param pS the fixed value of pattern parameter S, or null if not bound.
+ * @return matches represented as a Match object.
+ *
+ */
+ public Collection getAllMatches(final Segment pS) {
+ return rawStreamAllMatches(new Object[]{pS}).collect(Collectors.toSet());
+ }
+
+ /**
+ * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
+ *
+ * NOTE: It is important not to modify the source model while the stream is being processed.
+ * If the match set of the pattern changes during processing, the contents of the stream is undefined.
+ * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
+ * @param pS the fixed value of pattern parameter S, or null if not bound.
+ * @return a stream of matches represented as a Match object.
+ *
+ */
+ public Stream streamAllMatches(final Segment pS) {
+ return rawStreamAllMatches(new Object[]{pS});
+ }
+
+ /**
+ * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
+ * Neither determinism nor randomness of selection is guaranteed.
+ * @param pS the fixed value of pattern parameter S, or null if not bound.
+ * @return a match represented as a Match object, or null if no match is found.
+ *
+ */
+ public Optional getOneArbitraryMatch(final Segment pS) {
+ return rawGetOneArbitraryMatch(new Object[]{pS});
+ }
+
+ /**
+ * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
+ * under any possible substitution of the unspecified parameters (if any).
+ * @param pS the fixed value of pattern parameter S, or null if not bound.
+ * @return true if the input is a valid (partial) match of the pattern.
+ *
+ */
+ public boolean hasMatch(final Segment pS) {
+ return rawHasMatch(new Object[]{pS});
+ }
+
+ /**
+ * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
+ * @param pS the fixed value of pattern parameter S, or null if not bound.
+ * @return the number of pattern matches found.
+ *
+ */
+ public int countMatches(final Segment pS) {
+ return rawCountMatches(new Object[]{pS});
+ }
+
+ /**
+ * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
+ * Neither determinism nor randomness of selection is guaranteed.
+ * @param pS the fixed value of pattern parameter S, or null if not bound.
+ * @param processor the action that will process the selected match.
+ * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
+ *
+ */
+ public boolean forOneArbitraryMatch(final Segment pS, final Consumer super TooManyInputsOfSegment.Match> processor) {
+ return rawForOneArbitraryMatch(new Object[]{pS}, processor);
+ }
+
+ /**
+ * Returns a new (partial) match.
+ * This can be used e.g. to call the matcher with a partial match.
+ *
The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
+ * @param pS the fixed value of pattern parameter S, or null if not bound.
+ * @return the (partial) match object.
+ *
+ */
+ public TooManyInputsOfSegment.Match newMatch(final Segment pS) {
+ return TooManyInputsOfSegment.Match.newMatch(pS);
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ protected Stream rawStreamAllValuesOfS(final Object[] parameters) {
+ return rawStreamAllValues(POSITION_S, parameters).map(Segment.class::cast);
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Set getAllValuesOfS() {
+ return rawStreamAllValuesOfS(emptyArray()).collect(Collectors.toSet());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Stream streamAllValuesOfS() {
+ return rawStreamAllValuesOfS(emptyArray());
+ }
+
+ @Override
+ protected TooManyInputsOfSegment.Match tupleToMatch(final Tuple t) {
+ try {
+ return TooManyInputsOfSegment.Match.newMatch((Segment) t.get(POSITION_S));
+ } catch(ClassCastException e) {
+ LOGGER.error("Element(s) in tuple not properly typed!",e);
+ return null;
+ }
+ }
+
+ @Override
+ protected TooManyInputsOfSegment.Match arrayToMatch(final Object[] match) {
+ try {
+ return TooManyInputsOfSegment.Match.newMatch((Segment) match[POSITION_S]);
+ } catch(ClassCastException e) {
+ LOGGER.error("Element(s) in array not properly typed!",e);
+ return null;
+ }
+ }
+
+ @Override
+ protected TooManyInputsOfSegment.Match arrayToMatchMutable(final Object[] match) {
+ try {
+ return TooManyInputsOfSegment.Match.newMutableMatch((Segment) match[POSITION_S]);
+ } catch(ClassCastException e) {
+ LOGGER.error("Element(s) in array not properly typed!",e);
+ return null;
+ }
+ }
+
+ /**
+ * @return the singleton instance of the query specification of this pattern
+ * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
+ *
+ */
+ public static IQuerySpecification querySpecification() {
+ return TooManyInputsOfSegment.instance();
+ }
+ }
+
+ private TooManyInputsOfSegment() {
+ super(GeneratedPQuery.INSTANCE);
+ }
+
+ /**
+ * @return the singleton instance of the query specification
+ * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
+ *
+ */
+ public static TooManyInputsOfSegment instance() {
+ try{
+ return LazyHolder.INSTANCE;
+ } catch (ExceptionInInitializerError err) {
+ throw processInitializerError(err);
+ }
+ }
+
+ @Override
+ protected TooManyInputsOfSegment.Matcher instantiate(final ViatraQueryEngine engine) {
+ return TooManyInputsOfSegment.Matcher.on(engine);
+ }
+
+ @Override
+ public TooManyInputsOfSegment.Matcher instantiate() {
+ return TooManyInputsOfSegment.Matcher.create();
+ }
+
+ @Override
+ public TooManyInputsOfSegment.Match newEmptyMatch() {
+ return TooManyInputsOfSegment.Match.newEmptyMatch();
+ }
+
+ @Override
+ public TooManyInputsOfSegment.Match newMatch(final Object... parameters) {
+ return TooManyInputsOfSegment.Match.newMatch((modes3.Segment) parameters[0]);
+ }
+
+ /**
+ * Inner class allowing the singleton instance of {@link TooManyInputsOfSegment} to be created
+ * not at the class load time of the outer class,
+ * but rather at the first call to {@link TooManyInputsOfSegment#instance()}.
+ *
+ *
This workaround is required e.g. to support recursion.
+ *
+ */
+ private static class LazyHolder {
+ private static final TooManyInputsOfSegment INSTANCE = new TooManyInputsOfSegment();
+
+ /**
+ * Statically initializes the query specification after the field {@link #INSTANCE} is assigned.
+ * This initialization order is required to support indirect recursion.
+ *
+ *
The static initializer is defined using a helper field to work around limitations of the code generator.
+ *
+ */
+ private static final Object STATIC_INITIALIZER = ensureInitialized();
+
+ public static Object ensureInitialized() {
+ INSTANCE.ensureInitializedInternal();
+ return null;
+ }
+ }
+
+ private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
+ private static final TooManyInputsOfSegment.GeneratedPQuery INSTANCE = new GeneratedPQuery();
+
+ private final PParameter parameter_S = new PParameter("S", "modes3.Segment", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Segment")), PParameterDirection.INOUT);
+
+ private final List parameters = Arrays.asList(parameter_S);
+
+ private GeneratedPQuery() {
+ super(PVisibility.PUBLIC);
+ }
+
+ @Override
+ public String getFullyQualifiedName() {
+ return "modes3.queries.tooManyInputsOfSegment";
+ }
+
+ @Override
+ public List getParameterNames() {
+ return Arrays.asList("S");
+ }
+
+ @Override
+ public List getParameters() {
+ return parameters;
+ }
+
+ @Override
+ public Set doGetContainedBodies() {
+ setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
+ Set bodies = new LinkedHashSet<>();
+ {
+ PBody body = new PBody(this);
+ PVariable var_S = body.getOrCreateVariableByName("S");
+ PVariable var_I1 = body.getOrCreateVariableByName("I1");
+ PVariable var_I2 = body.getOrCreateVariableByName("I2");
+ PVariable var_I3 = body.getOrCreateVariableByName("I3");
+ new TypeConstraint(body, Tuples.flatTupleOf(var_S), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
+ body.setSymbolicParameters(Arrays.asList(
+ new ExportedParameter(body, var_S, parameter_S)
+ ));
+ // neg find turnout(S)
+ new NegativePatternCall(body, Tuples.flatTupleOf(var_S), Turnout.instance().getInternalQueryRepresentation());
+ // find output(I1, S)
+ new PositivePatternCall(body, Tuples.flatTupleOf(var_I1, var_S), Output.instance().getInternalQueryRepresentation());
+ // find output(I2, S)
+ new PositivePatternCall(body, Tuples.flatTupleOf(var_I2, var_S), Output.instance().getInternalQueryRepresentation());
+ // find output(I3, S)
+ new PositivePatternCall(body, Tuples.flatTupleOf(var_I3, var_S), Output.instance().getInternalQueryRepresentation());
+ // I1 != I2
+ new Inequality(body, var_I1, var_I2);
+ // I1 != I3
+ new Inequality(body, var_I1, var_I3);
+ // I2 != I3
+ new Inequality(body, var_I2, var_I3);
+ bodies.add(body);
+ }
+ {
+ PAnnotation annotation = new PAnnotation("Constraint");
+ annotation.addAttribute("message", "tooManyInputsOfSegment");
+ annotation.addAttribute("severity", "error");
+ annotation.addAttribute("key", Arrays.asList(new Object[] {
+ new ParameterReference("S")
+ }));
+ addAnnotation(annotation);
+ }
+ return bodies;
+ }
+ }
+}
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/Turnout.java b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/Turnout.java
new file mode 100644
index 00000000..34c7631c
--- /dev/null
+++ b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/Turnout.java
@@ -0,0 +1,543 @@
+/**
+ * Generated from platform:/resource/ca.mcgill.rtgmrt.example.modes3/src/modes3/queries/Modes3Queries.vql
+ */
+package modes3.queries;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+import java.util.function.Consumer;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import org.apache.log4j.Logger;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.viatra.query.runtime.api.IPatternMatch;
+import org.eclipse.viatra.query.runtime.api.IQuerySpecification;
+import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine;
+import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
+import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification;
+import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher;
+import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch;
+import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey;
+import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
+import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
+import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
+import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
+import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
+import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
+import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
+import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
+import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
+
+/**
+ * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
+ *
+ *
+ *
+ * @see Matcher
+ * @see Match
+ *
+ */
+@SuppressWarnings("all")
+public final class Turnout extends BaseGeneratedEMFQuerySpecification {
+ /**
+ * Pattern-specific match representation of the modes3.queries.turnout pattern,
+ * to be used in conjunction with {@link Matcher}.
+ *
+ *
Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
+ * Each instance is a (possibly partial) substitution of pattern parameters,
+ * usable to represent a match of the pattern in the result of a query,
+ * or to specify the bound (fixed) input parameters when issuing a query.
+ *
+ * @see Matcher
+ *
+ */
+ public static abstract class Match extends BasePatternMatch {
+ private modes3.Turnout fT;
+
+ private static List parameterNames = makeImmutableList("T");
+
+ private Match(final modes3.Turnout pT) {
+ this.fT = pT;
+ }
+
+ @Override
+ public Object get(final String parameterName) {
+ switch(parameterName) {
+ case "T": return this.fT;
+ default: return null;
+ }
+ }
+
+ @Override
+ public Object get(final int index) {
+ switch(index) {
+ case 0: return this.fT;
+ default: return null;
+ }
+ }
+
+ public modes3.Turnout getT() {
+ return this.fT;
+ }
+
+ @Override
+ public boolean set(final String parameterName, final Object newValue) {
+ if (!isMutable()) throw new java.lang.UnsupportedOperationException();
+ if ("T".equals(parameterName) ) {
+ this.fT = (modes3.Turnout) newValue;
+ return true;
+ }
+ return false;
+ }
+
+ public void setT(final modes3.Turnout pT) {
+ if (!isMutable()) throw new java.lang.UnsupportedOperationException();
+ this.fT = pT;
+ }
+
+ @Override
+ public String patternName() {
+ return "modes3.queries.turnout";
+ }
+
+ @Override
+ public List parameterNames() {
+ return Turnout.Match.parameterNames;
+ }
+
+ @Override
+ public Object[] toArray() {
+ return new Object[]{fT};
+ }
+
+ @Override
+ public Turnout.Match toImmutable() {
+ return isMutable() ? newMatch(fT) : this;
+ }
+
+ @Override
+ public String prettyPrint() {
+ StringBuilder result = new StringBuilder();
+ result.append("\"T\"=" + prettyPrintValue(fT));
+ return result.toString();
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(fT);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null) {
+ return false;
+ }
+ if ((obj instanceof Turnout.Match)) {
+ Turnout.Match other = (Turnout.Match) obj;
+ return Objects.equals(fT, other.fT);
+ } else {
+ // this should be infrequent
+ if (!(obj instanceof IPatternMatch)) {
+ return false;
+ }
+ IPatternMatch otherSig = (IPatternMatch) obj;
+ return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
+ }
+ }
+
+ @Override
+ public Turnout specification() {
+ return Turnout.instance();
+ }
+
+ /**
+ * Returns an empty, mutable match.
+ * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
+ *
+ * @return the empty match.
+ *
+ */
+ public static Turnout.Match newEmptyMatch() {
+ return new Mutable(null);
+ }
+
+ /**
+ * Returns a mutable (partial) match.
+ * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
+ *
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @return the new, mutable (partial) match object.
+ *
+ */
+ public static Turnout.Match newMutableMatch(final modes3.Turnout pT) {
+ return new Mutable(pT);
+ }
+
+ /**
+ * Returns a new (partial) match.
+ * This can be used e.g. to call the matcher with a partial match.
+ *
The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @return the (partial) match object.
+ *
+ */
+ public static Turnout.Match newMatch(final modes3.Turnout pT) {
+ return new Immutable(pT);
+ }
+
+ private static final class Mutable extends Turnout.Match {
+ Mutable(final modes3.Turnout pT) {
+ super(pT);
+ }
+
+ @Override
+ public boolean isMutable() {
+ return true;
+ }
+ }
+
+ private static final class Immutable extends Turnout.Match {
+ Immutable(final modes3.Turnout pT) {
+ super(pT);
+ }
+
+ @Override
+ public boolean isMutable() {
+ return false;
+ }
+ }
+ }
+
+ /**
+ * Generated pattern matcher API of the modes3.queries.turnout pattern,
+ * providing pattern-specific query methods.
+ *
+ *
Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
+ * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
+ *
+ *
Matches of the pattern will be represented as {@link Match}.
+ *
+ *
+ *
+ * @see Match
+ * @see Turnout
+ *
+ */
+ public static class Matcher extends BaseMatcher {
+ /**
+ * Initializes the pattern matcher within an existing VIATRA Query engine.
+ * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
+ *
+ * @param engine the existing VIATRA Query engine in which this matcher will be created.
+ * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
+ *
+ */
+ public static Turnout.Matcher on(final ViatraQueryEngine engine) {
+ // check if matcher already exists
+ Matcher matcher = engine.getExistingMatcher(querySpecification());
+ if (matcher == null) {
+ matcher = (Matcher)engine.getMatcher(querySpecification());
+ }
+ return matcher;
+ }
+
+ /**
+ * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
+ * @return an initialized matcher
+ * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
+ *
+ */
+ public static Turnout.Matcher create() {
+ return new Matcher();
+ }
+
+ private static final int POSITION_T = 0;
+
+ private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Turnout.Matcher.class);
+
+ /**
+ * Initializes the pattern matcher within an existing VIATRA Query engine.
+ * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
+ *
+ * @param engine the existing VIATRA Query engine in which this matcher will be created.
+ * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
+ *
+ */
+ private Matcher() {
+ super(querySpecification());
+ }
+
+ /**
+ * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @return matches represented as a Match object.
+ *
+ */
+ public Collection getAllMatches(final modes3.Turnout pT) {
+ return rawStreamAllMatches(new Object[]{pT}).collect(Collectors.toSet());
+ }
+
+ /**
+ * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
+ *
+ * NOTE: It is important not to modify the source model while the stream is being processed.
+ * If the match set of the pattern changes during processing, the contents of the stream is undefined.
+ * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @return a stream of matches represented as a Match object.
+ *
+ */
+ public Stream streamAllMatches(final modes3.Turnout pT) {
+ return rawStreamAllMatches(new Object[]{pT});
+ }
+
+ /**
+ * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
+ * Neither determinism nor randomness of selection is guaranteed.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @return a match represented as a Match object, or null if no match is found.
+ *
+ */
+ public Optional getOneArbitraryMatch(final modes3.Turnout pT) {
+ return rawGetOneArbitraryMatch(new Object[]{pT});
+ }
+
+ /**
+ * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
+ * under any possible substitution of the unspecified parameters (if any).
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @return true if the input is a valid (partial) match of the pattern.
+ *
+ */
+ public boolean hasMatch(final modes3.Turnout pT) {
+ return rawHasMatch(new Object[]{pT});
+ }
+
+ /**
+ * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @return the number of pattern matches found.
+ *
+ */
+ public int countMatches(final modes3.Turnout pT) {
+ return rawCountMatches(new Object[]{pT});
+ }
+
+ /**
+ * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
+ * Neither determinism nor randomness of selection is guaranteed.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @param processor the action that will process the selected match.
+ * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
+ *
+ */
+ public boolean forOneArbitraryMatch(final modes3.Turnout pT, final Consumer super Turnout.Match> processor) {
+ return rawForOneArbitraryMatch(new Object[]{pT}, processor);
+ }
+
+ /**
+ * Returns a new (partial) match.
+ * This can be used e.g. to call the matcher with a partial match.
+ *
The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @return the (partial) match object.
+ *
+ */
+ public Turnout.Match newMatch(final modes3.Turnout pT) {
+ return Turnout.Match.newMatch(pT);
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for T.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ protected Stream rawStreamAllValuesOfT(final Object[] parameters) {
+ return rawStreamAllValues(POSITION_T, parameters).map(modes3.Turnout.class::cast);
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for T.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Set getAllValuesOfT() {
+ return rawStreamAllValuesOfT(emptyArray()).collect(Collectors.toSet());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for T.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Stream streamAllValuesOfT() {
+ return rawStreamAllValuesOfT(emptyArray());
+ }
+
+ @Override
+ protected Turnout.Match tupleToMatch(final Tuple t) {
+ try {
+ return Turnout.Match.newMatch((modes3.Turnout) t.get(POSITION_T));
+ } catch(ClassCastException e) {
+ LOGGER.error("Element(s) in tuple not properly typed!",e);
+ return null;
+ }
+ }
+
+ @Override
+ protected Turnout.Match arrayToMatch(final Object[] match) {
+ try {
+ return Turnout.Match.newMatch((modes3.Turnout) match[POSITION_T]);
+ } catch(ClassCastException e) {
+ LOGGER.error("Element(s) in array not properly typed!",e);
+ return null;
+ }
+ }
+
+ @Override
+ protected Turnout.Match arrayToMatchMutable(final Object[] match) {
+ try {
+ return Turnout.Match.newMutableMatch((modes3.Turnout) match[POSITION_T]);
+ } catch(ClassCastException e) {
+ LOGGER.error("Element(s) in array not properly typed!",e);
+ return null;
+ }
+ }
+
+ /**
+ * @return the singleton instance of the query specification of this pattern
+ * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
+ *
+ */
+ public static IQuerySpecification querySpecification() {
+ return Turnout.instance();
+ }
+ }
+
+ private Turnout() {
+ super(GeneratedPQuery.INSTANCE);
+ }
+
+ /**
+ * @return the singleton instance of the query specification
+ * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
+ *
+ */
+ public static Turnout instance() {
+ try{
+ return LazyHolder.INSTANCE;
+ } catch (ExceptionInInitializerError err) {
+ throw processInitializerError(err);
+ }
+ }
+
+ @Override
+ protected Turnout.Matcher instantiate(final ViatraQueryEngine engine) {
+ return Turnout.Matcher.on(engine);
+ }
+
+ @Override
+ public Turnout.Matcher instantiate() {
+ return Turnout.Matcher.create();
+ }
+
+ @Override
+ public Turnout.Match newEmptyMatch() {
+ return Turnout.Match.newEmptyMatch();
+ }
+
+ @Override
+ public Turnout.Match newMatch(final Object... parameters) {
+ return Turnout.Match.newMatch((modes3.Turnout) parameters[0]);
+ }
+
+ /**
+ * Inner class allowing the singleton instance of {@link Turnout} to be created
+ * not at the class load time of the outer class,
+ * but rather at the first call to {@link Turnout#instance()}.
+ *
+ *
This workaround is required e.g. to support recursion.
+ *
+ */
+ private static class LazyHolder {
+ private static final Turnout INSTANCE = new Turnout();
+
+ /**
+ * Statically initializes the query specification after the field {@link #INSTANCE} is assigned.
+ * This initialization order is required to support indirect recursion.
+ *
+ *
The static initializer is defined using a helper field to work around limitations of the code generator.
+ *
+ */
+ private static final Object STATIC_INITIALIZER = ensureInitialized();
+
+ public static Object ensureInitialized() {
+ INSTANCE.ensureInitializedInternal();
+ return null;
+ }
+ }
+
+ private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
+ private static final Turnout.GeneratedPQuery INSTANCE = new GeneratedPQuery();
+
+ private final PParameter parameter_T = new PParameter("T", "modes3.Turnout", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Turnout")), PParameterDirection.INOUT);
+
+ private final List parameters = Arrays.asList(parameter_T);
+
+ private GeneratedPQuery() {
+ super(PVisibility.PUBLIC);
+ }
+
+ @Override
+ public String getFullyQualifiedName() {
+ return "modes3.queries.turnout";
+ }
+
+ @Override
+ public List getParameterNames() {
+ return Arrays.asList("T");
+ }
+
+ @Override
+ public List getParameters() {
+ return parameters;
+ }
+
+ @Override
+ public Set doGetContainedBodies() {
+ setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
+ Set bodies = new LinkedHashSet<>();
+ {
+ PBody body = new PBody(this);
+ PVariable var_T = body.getOrCreateVariableByName("T");
+ new TypeConstraint(body, Tuples.flatTupleOf(var_T), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Turnout")));
+ body.setSymbolicParameters(Arrays.asList(
+ new ExportedParameter(body, var_T, parameter_T)
+ ));
+ // Turnout(T)
+ new TypeConstraint(body, Tuples.flatTupleOf(var_T), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Turnout")));
+ bodies.add(body);
+ }
+ return bodies;
+ }
+ }
+}
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 @@
+/**
+ * Generated from platform:/resource/ca.mcgill.rtgmrt.example.modes3/src/modes3/queries/Modes3Queries.vql
+ */
+package modes3.queries;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+import java.util.function.Consumer;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import modes3.Turnout;
+import org.apache.log4j.Logger;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.viatra.query.runtime.api.IPatternMatch;
+import org.eclipse.viatra.query.runtime.api.IQuerySpecification;
+import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine;
+import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
+import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification;
+import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher;
+import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch;
+import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey;
+import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey;
+import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
+import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
+import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
+import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation;
+import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference;
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality;
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
+import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
+import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
+import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
+import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
+import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
+import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
+
+/**
+ * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
+ *
+ *
+ *
+ * @see Matcher
+ * @see Match
+ *
+ */
+@SuppressWarnings("all")
+public final class TurnoutConnectedToBothOutputs extends BaseGeneratedEMFQuerySpecification {
+ /**
+ * Pattern-specific match representation of the modes3.queries.turnoutConnectedToBothOutputs pattern,
+ * to be used in conjunction with {@link Matcher}.
+ *
+ *
Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
+ * Each instance is a (possibly partial) substitution of pattern parameters,
+ * usable to represent a match of the pattern in the result of a query,
+ * or to specify the bound (fixed) input parameters when issuing a query.
+ *
+ * @see Matcher
+ *
+ */
+ public static abstract class Match extends BasePatternMatch {
+ private Turnout fT;
+
+ private static List parameterNames = makeImmutableList("T");
+
+ private Match(final Turnout pT) {
+ this.fT = pT;
+ }
+
+ @Override
+ public Object get(final String parameterName) {
+ switch(parameterName) {
+ case "T": return this.fT;
+ default: return null;
+ }
+ }
+
+ @Override
+ public Object get(final int index) {
+ switch(index) {
+ case 0: return this.fT;
+ default: return null;
+ }
+ }
+
+ public Turnout getT() {
+ return this.fT;
+ }
+
+ @Override
+ public boolean set(final String parameterName, final Object newValue) {
+ if (!isMutable()) throw new java.lang.UnsupportedOperationException();
+ if ("T".equals(parameterName) ) {
+ this.fT = (Turnout) newValue;
+ return true;
+ }
+ return false;
+ }
+
+ public void setT(final Turnout pT) {
+ if (!isMutable()) throw new java.lang.UnsupportedOperationException();
+ this.fT = pT;
+ }
+
+ @Override
+ public String patternName() {
+ return "modes3.queries.turnoutConnectedToBothOutputs";
+ }
+
+ @Override
+ public List parameterNames() {
+ return TurnoutConnectedToBothOutputs.Match.parameterNames;
+ }
+
+ @Override
+ public Object[] toArray() {
+ return new Object[]{fT};
+ }
+
+ @Override
+ public TurnoutConnectedToBothOutputs.Match toImmutable() {
+ return isMutable() ? newMatch(fT) : this;
+ }
+
+ @Override
+ public String prettyPrint() {
+ StringBuilder result = new StringBuilder();
+ result.append("\"T\"=" + prettyPrintValue(fT));
+ return result.toString();
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(fT);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null) {
+ return false;
+ }
+ if ((obj instanceof TurnoutConnectedToBothOutputs.Match)) {
+ TurnoutConnectedToBothOutputs.Match other = (TurnoutConnectedToBothOutputs.Match) obj;
+ return Objects.equals(fT, other.fT);
+ } else {
+ // this should be infrequent
+ if (!(obj instanceof IPatternMatch)) {
+ return false;
+ }
+ IPatternMatch otherSig = (IPatternMatch) obj;
+ return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
+ }
+ }
+
+ @Override
+ public TurnoutConnectedToBothOutputs specification() {
+ return TurnoutConnectedToBothOutputs.instance();
+ }
+
+ /**
+ * Returns an empty, mutable match.
+ * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
+ *
+ * @return the empty match.
+ *
+ */
+ public static TurnoutConnectedToBothOutputs.Match newEmptyMatch() {
+ return new Mutable(null);
+ }
+
+ /**
+ * Returns a mutable (partial) match.
+ * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
+ *
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @return the new, mutable (partial) match object.
+ *
+ */
+ public static TurnoutConnectedToBothOutputs.Match newMutableMatch(final Turnout pT) {
+ return new Mutable(pT);
+ }
+
+ /**
+ * Returns a new (partial) match.
+ * This can be used e.g. to call the matcher with a partial match.
+ *
The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @return the (partial) match object.
+ *
+ */
+ public static TurnoutConnectedToBothOutputs.Match newMatch(final Turnout pT) {
+ return new Immutable(pT);
+ }
+
+ private static final class Mutable extends TurnoutConnectedToBothOutputs.Match {
+ Mutable(final Turnout pT) {
+ super(pT);
+ }
+
+ @Override
+ public boolean isMutable() {
+ return true;
+ }
+ }
+
+ private static final class Immutable extends TurnoutConnectedToBothOutputs.Match {
+ Immutable(final Turnout pT) {
+ super(pT);
+ }
+
+ @Override
+ public boolean isMutable() {
+ return false;
+ }
+ }
+ }
+
+ /**
+ * Generated pattern matcher API of the modes3.queries.turnoutConnectedToBothOutputs pattern,
+ * providing pattern-specific query methods.
+ *
+ *
Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
+ * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
+ *
+ *
Matches of the pattern will be represented as {@link Match}.
+ *
+ *
+ *
+ * @see Match
+ * @see TurnoutConnectedToBothOutputs
+ *
+ */
+ public static class Matcher extends BaseMatcher {
+ /**
+ * Initializes the pattern matcher within an existing VIATRA Query engine.
+ * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
+ *
+ * @param engine the existing VIATRA Query engine in which this matcher will be created.
+ * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
+ *
+ */
+ public static TurnoutConnectedToBothOutputs.Matcher on(final ViatraQueryEngine engine) {
+ // check if matcher already exists
+ Matcher matcher = engine.getExistingMatcher(querySpecification());
+ if (matcher == null) {
+ matcher = (Matcher)engine.getMatcher(querySpecification());
+ }
+ return matcher;
+ }
+
+ /**
+ * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
+ * @return an initialized matcher
+ * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
+ *
+ */
+ public static TurnoutConnectedToBothOutputs.Matcher create() {
+ return new Matcher();
+ }
+
+ private static final int POSITION_T = 0;
+
+ private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(TurnoutConnectedToBothOutputs.Matcher.class);
+
+ /**
+ * Initializes the pattern matcher within an existing VIATRA Query engine.
+ * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
+ *
+ * @param engine the existing VIATRA Query engine in which this matcher will be created.
+ * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
+ *
+ */
+ private Matcher() {
+ super(querySpecification());
+ }
+
+ /**
+ * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @return matches represented as a Match object.
+ *
+ */
+ public Collection getAllMatches(final Turnout pT) {
+ return rawStreamAllMatches(new Object[]{pT}).collect(Collectors.toSet());
+ }
+
+ /**
+ * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
+ *
+ * NOTE: It is important not to modify the source model while the stream is being processed.
+ * If the match set of the pattern changes during processing, the contents of the stream is undefined.
+ * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @return a stream of matches represented as a Match object.
+ *
+ */
+ public Stream streamAllMatches(final Turnout pT) {
+ return rawStreamAllMatches(new Object[]{pT});
+ }
+
+ /**
+ * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
+ * Neither determinism nor randomness of selection is guaranteed.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @return a match represented as a Match object, or null if no match is found.
+ *
+ */
+ public Optional getOneArbitraryMatch(final Turnout pT) {
+ return rawGetOneArbitraryMatch(new Object[]{pT});
+ }
+
+ /**
+ * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
+ * under any possible substitution of the unspecified parameters (if any).
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @return true if the input is a valid (partial) match of the pattern.
+ *
+ */
+ public boolean hasMatch(final Turnout pT) {
+ return rawHasMatch(new Object[]{pT});
+ }
+
+ /**
+ * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @return the number of pattern matches found.
+ *
+ */
+ public int countMatches(final Turnout pT) {
+ return rawCountMatches(new Object[]{pT});
+ }
+
+ /**
+ * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
+ * Neither determinism nor randomness of selection is guaranteed.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @param processor the action that will process the selected match.
+ * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
+ *
+ */
+ public boolean forOneArbitraryMatch(final Turnout pT, final Consumer super TurnoutConnectedToBothOutputs.Match> processor) {
+ return rawForOneArbitraryMatch(new Object[]{pT}, processor);
+ }
+
+ /**
+ * Returns a new (partial) match.
+ * This can be used e.g. to call the matcher with a partial match.
+ *
The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @return the (partial) match object.
+ *
+ */
+ public TurnoutConnectedToBothOutputs.Match newMatch(final Turnout pT) {
+ return TurnoutConnectedToBothOutputs.Match.newMatch(pT);
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for T.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ protected Stream rawStreamAllValuesOfT(final Object[] parameters) {
+ return rawStreamAllValues(POSITION_T, parameters).map(Turnout.class::cast);
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for T.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Set getAllValuesOfT() {
+ return rawStreamAllValuesOfT(emptyArray()).collect(Collectors.toSet());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for T.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Stream streamAllValuesOfT() {
+ return rawStreamAllValuesOfT(emptyArray());
+ }
+
+ @Override
+ protected TurnoutConnectedToBothOutputs.Match tupleToMatch(final Tuple t) {
+ try {
+ return TurnoutConnectedToBothOutputs.Match.newMatch((Turnout) t.get(POSITION_T));
+ } catch(ClassCastException e) {
+ LOGGER.error("Element(s) in tuple not properly typed!",e);
+ return null;
+ }
+ }
+
+ @Override
+ protected TurnoutConnectedToBothOutputs.Match arrayToMatch(final Object[] match) {
+ try {
+ return TurnoutConnectedToBothOutputs.Match.newMatch((Turnout) match[POSITION_T]);
+ } catch(ClassCastException e) {
+ LOGGER.error("Element(s) in array not properly typed!",e);
+ return null;
+ }
+ }
+
+ @Override
+ protected TurnoutConnectedToBothOutputs.Match arrayToMatchMutable(final Object[] match) {
+ try {
+ return TurnoutConnectedToBothOutputs.Match.newMutableMatch((Turnout) match[POSITION_T]);
+ } catch(ClassCastException e) {
+ LOGGER.error("Element(s) in array not properly typed!",e);
+ return null;
+ }
+ }
+
+ /**
+ * @return the singleton instance of the query specification of this pattern
+ * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
+ *
+ */
+ public static IQuerySpecification querySpecification() {
+ return TurnoutConnectedToBothOutputs.instance();
+ }
+ }
+
+ private TurnoutConnectedToBothOutputs() {
+ super(GeneratedPQuery.INSTANCE);
+ }
+
+ /**
+ * @return the singleton instance of the query specification
+ * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
+ *
+ */
+ public static TurnoutConnectedToBothOutputs instance() {
+ try{
+ return LazyHolder.INSTANCE;
+ } catch (ExceptionInInitializerError err) {
+ throw processInitializerError(err);
+ }
+ }
+
+ @Override
+ protected TurnoutConnectedToBothOutputs.Matcher instantiate(final ViatraQueryEngine engine) {
+ return TurnoutConnectedToBothOutputs.Matcher.on(engine);
+ }
+
+ @Override
+ public TurnoutConnectedToBothOutputs.Matcher instantiate() {
+ return TurnoutConnectedToBothOutputs.Matcher.create();
+ }
+
+ @Override
+ public TurnoutConnectedToBothOutputs.Match newEmptyMatch() {
+ return TurnoutConnectedToBothOutputs.Match.newEmptyMatch();
+ }
+
+ @Override
+ public TurnoutConnectedToBothOutputs.Match newMatch(final Object... parameters) {
+ return TurnoutConnectedToBothOutputs.Match.newMatch((modes3.Turnout) parameters[0]);
+ }
+
+ /**
+ * Inner class allowing the singleton instance of {@link TurnoutConnectedToBothOutputs} to be created
+ * not at the class load time of the outer class,
+ * but rather at the first call to {@link TurnoutConnectedToBothOutputs#instance()}.
+ *
+ *
This workaround is required e.g. to support recursion.
+ *
+ */
+ private static class LazyHolder {
+ private static final TurnoutConnectedToBothOutputs INSTANCE = new TurnoutConnectedToBothOutputs();
+
+ /**
+ * Statically initializes the query specification after the field {@link #INSTANCE} is assigned.
+ * This initialization order is required to support indirect recursion.
+ *
+ *
The static initializer is defined using a helper field to work around limitations of the code generator.
+ *
+ */
+ private static final Object STATIC_INITIALIZER = ensureInitialized();
+
+ public static Object ensureInitialized() {
+ INSTANCE.ensureInitializedInternal();
+ return null;
+ }
+ }
+
+ private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
+ private static final TurnoutConnectedToBothOutputs.GeneratedPQuery INSTANCE = new GeneratedPQuery();
+
+ private final PParameter parameter_T = new PParameter("T", "modes3.Turnout", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Turnout")), PParameterDirection.INOUT);
+
+ private final List parameters = Arrays.asList(parameter_T);
+
+ private GeneratedPQuery() {
+ super(PVisibility.PUBLIC);
+ }
+
+ @Override
+ public String getFullyQualifiedName() {
+ return "modes3.queries.turnoutConnectedToBothOutputs";
+ }
+
+ @Override
+ public List getParameterNames() {
+ return Arrays.asList("T");
+ }
+
+ @Override
+ public List getParameters() {
+ return parameters;
+ }
+
+ @Override
+ public Set doGetContainedBodies() {
+ setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
+ Set bodies = new LinkedHashSet<>();
+ {
+ PBody body = new PBody(this);
+ PVariable var_T = body.getOrCreateVariableByName("T");
+ PVariable var_Straight = body.getOrCreateVariableByName("Straight");
+ PVariable var_Divergent = body.getOrCreateVariableByName("Divergent");
+ new TypeConstraint(body, Tuples.flatTupleOf(var_T), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Turnout")));
+ body.setSymbolicParameters(Arrays.asList(
+ new ExportedParameter(body, var_T, parameter_T)
+ ));
+ // Turnout.straight(T, Straight)
+ new TypeConstraint(body, Tuples.flatTupleOf(var_T), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Turnout")));
+ PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
+ new TypeConstraint(body, Tuples.flatTupleOf(var_T, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Turnout", "straight")));
+ new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
+ new Equality(body, var__virtual_0_, var_Straight);
+ // Turnout.divergent(T, Divergent)
+ new TypeConstraint(body, Tuples.flatTupleOf(var_T), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Turnout")));
+ PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
+ new TypeConstraint(body, Tuples.flatTupleOf(var_T, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Turnout", "divergent")));
+ new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
+ new Equality(body, var__virtual_1_, var_Divergent);
+ // Segment.connectedTo(T, Straight)
+ new TypeConstraint(body, Tuples.flatTupleOf(var_T), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
+ PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}");
+ new TypeConstraint(body, Tuples.flatTupleOf(var_T, var__virtual_2_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment", "connectedTo")));
+ new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
+ new Equality(body, var__virtual_2_, var_Straight);
+ // Segment.connectedTo(T, Divergent)
+ new TypeConstraint(body, Tuples.flatTupleOf(var_T), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
+ PVariable var__virtual_3_ = body.getOrCreateVariableByName(".virtual{3}");
+ new TypeConstraint(body, Tuples.flatTupleOf(var_T, var__virtual_3_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment", "connectedTo")));
+ new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_3_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
+ new Equality(body, var__virtual_3_, var_Divergent);
+ bodies.add(body);
+ }
+ {
+ PAnnotation annotation = new PAnnotation("Constraint");
+ annotation.addAttribute("message", "turnoutConnectedToBothOutputs");
+ annotation.addAttribute("severity", "error");
+ annotation.addAttribute("key", Arrays.asList(new Object[] {
+ new ParameterReference("T")
+ }));
+ addAnnotation(annotation);
+ }
+ return bodies;
+ }
+ }
+}
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/TurnoutInSegments.java b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/TurnoutInSegments.java
new file mode 100644
index 00000000..9c9a5d18
--- /dev/null
+++ b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/TurnoutInSegments.java
@@ -0,0 +1,564 @@
+/**
+ * Generated from platform:/resource/ca.mcgill.rtgmrt.example.modes3/src/modes3/queries/Modes3Queries.vql
+ */
+package modes3.queries;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+import java.util.function.Consumer;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import modes3.Turnout;
+import org.apache.log4j.Logger;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.viatra.query.runtime.api.IPatternMatch;
+import org.eclipse.viatra.query.runtime.api.IQuerySpecification;
+import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine;
+import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
+import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification;
+import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher;
+import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch;
+import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey;
+import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey;
+import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
+import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
+import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
+import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation;
+import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference;
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality;
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
+import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
+import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
+import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
+import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
+import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
+import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
+
+/**
+ * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
+ *
+ *
+ *
+ * @see Matcher
+ * @see Match
+ *
+ */
+@SuppressWarnings("all")
+public final class TurnoutInSegments extends BaseGeneratedEMFQuerySpecification {
+ /**
+ * Pattern-specific match representation of the modes3.queries.turnoutInSegments pattern,
+ * to be used in conjunction with {@link Matcher}.
+ *
+ *
Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
+ * Each instance is a (possibly partial) substitution of pattern parameters,
+ * usable to represent a match of the pattern in the result of a query,
+ * or to specify the bound (fixed) input parameters when issuing a query.
+ *
+ * @see Matcher
+ *
+ */
+ public static abstract class Match extends BasePatternMatch {
+ private Turnout fT;
+
+ private static List parameterNames = makeImmutableList("T");
+
+ private Match(final Turnout pT) {
+ this.fT = pT;
+ }
+
+ @Override
+ public Object get(final String parameterName) {
+ switch(parameterName) {
+ case "T": return this.fT;
+ default: return null;
+ }
+ }
+
+ @Override
+ public Object get(final int index) {
+ switch(index) {
+ case 0: return this.fT;
+ default: return null;
+ }
+ }
+
+ public Turnout getT() {
+ return this.fT;
+ }
+
+ @Override
+ public boolean set(final String parameterName, final Object newValue) {
+ if (!isMutable()) throw new java.lang.UnsupportedOperationException();
+ if ("T".equals(parameterName) ) {
+ this.fT = (Turnout) newValue;
+ return true;
+ }
+ return false;
+ }
+
+ public void setT(final Turnout pT) {
+ if (!isMutable()) throw new java.lang.UnsupportedOperationException();
+ this.fT = pT;
+ }
+
+ @Override
+ public String patternName() {
+ return "modes3.queries.turnoutInSegments";
+ }
+
+ @Override
+ public List parameterNames() {
+ return TurnoutInSegments.Match.parameterNames;
+ }
+
+ @Override
+ public Object[] toArray() {
+ return new Object[]{fT};
+ }
+
+ @Override
+ public TurnoutInSegments.Match toImmutable() {
+ return isMutable() ? newMatch(fT) : this;
+ }
+
+ @Override
+ public String prettyPrint() {
+ StringBuilder result = new StringBuilder();
+ result.append("\"T\"=" + prettyPrintValue(fT));
+ return result.toString();
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(fT);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null) {
+ return false;
+ }
+ if ((obj instanceof TurnoutInSegments.Match)) {
+ TurnoutInSegments.Match other = (TurnoutInSegments.Match) obj;
+ return Objects.equals(fT, other.fT);
+ } else {
+ // this should be infrequent
+ if (!(obj instanceof IPatternMatch)) {
+ return false;
+ }
+ IPatternMatch otherSig = (IPatternMatch) obj;
+ return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
+ }
+ }
+
+ @Override
+ public TurnoutInSegments specification() {
+ return TurnoutInSegments.instance();
+ }
+
+ /**
+ * Returns an empty, mutable match.
+ * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
+ *
+ * @return the empty match.
+ *
+ */
+ public static TurnoutInSegments.Match newEmptyMatch() {
+ return new Mutable(null);
+ }
+
+ /**
+ * Returns a mutable (partial) match.
+ * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
+ *
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @return the new, mutable (partial) match object.
+ *
+ */
+ public static TurnoutInSegments.Match newMutableMatch(final Turnout pT) {
+ return new Mutable(pT);
+ }
+
+ /**
+ * Returns a new (partial) match.
+ * This can be used e.g. to call the matcher with a partial match.
+ *
The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @return the (partial) match object.
+ *
+ */
+ public static TurnoutInSegments.Match newMatch(final Turnout pT) {
+ return new Immutable(pT);
+ }
+
+ private static final class Mutable extends TurnoutInSegments.Match {
+ Mutable(final Turnout pT) {
+ super(pT);
+ }
+
+ @Override
+ public boolean isMutable() {
+ return true;
+ }
+ }
+
+ private static final class Immutable extends TurnoutInSegments.Match {
+ Immutable(final Turnout pT) {
+ super(pT);
+ }
+
+ @Override
+ public boolean isMutable() {
+ return false;
+ }
+ }
+ }
+
+ /**
+ * Generated pattern matcher API of the modes3.queries.turnoutInSegments pattern,
+ * providing pattern-specific query methods.
+ *
+ *
Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
+ * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
+ *
+ *
Matches of the pattern will be represented as {@link Match}.
+ *
+ *
+ *
+ * @see Match
+ * @see TurnoutInSegments
+ *
+ */
+ public static class Matcher extends BaseMatcher {
+ /**
+ * Initializes the pattern matcher within an existing VIATRA Query engine.
+ * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
+ *
+ * @param engine the existing VIATRA Query engine in which this matcher will be created.
+ * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
+ *
+ */
+ public static TurnoutInSegments.Matcher on(final ViatraQueryEngine engine) {
+ // check if matcher already exists
+ Matcher matcher = engine.getExistingMatcher(querySpecification());
+ if (matcher == null) {
+ matcher = (Matcher)engine.getMatcher(querySpecification());
+ }
+ return matcher;
+ }
+
+ /**
+ * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
+ * @return an initialized matcher
+ * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
+ *
+ */
+ public static TurnoutInSegments.Matcher create() {
+ return new Matcher();
+ }
+
+ private static final int POSITION_T = 0;
+
+ private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(TurnoutInSegments.Matcher.class);
+
+ /**
+ * Initializes the pattern matcher within an existing VIATRA Query engine.
+ * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
+ *
+ * @param engine the existing VIATRA Query engine in which this matcher will be created.
+ * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
+ *
+ */
+ private Matcher() {
+ super(querySpecification());
+ }
+
+ /**
+ * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @return matches represented as a Match object.
+ *
+ */
+ public Collection getAllMatches(final Turnout pT) {
+ return rawStreamAllMatches(new Object[]{pT}).collect(Collectors.toSet());
+ }
+
+ /**
+ * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
+ *
+ * NOTE: It is important not to modify the source model while the stream is being processed.
+ * If the match set of the pattern changes during processing, the contents of the stream is undefined.
+ * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @return a stream of matches represented as a Match object.
+ *
+ */
+ public Stream streamAllMatches(final Turnout pT) {
+ return rawStreamAllMatches(new Object[]{pT});
+ }
+
+ /**
+ * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
+ * Neither determinism nor randomness of selection is guaranteed.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @return a match represented as a Match object, or null if no match is found.
+ *
+ */
+ public Optional getOneArbitraryMatch(final Turnout pT) {
+ return rawGetOneArbitraryMatch(new Object[]{pT});
+ }
+
+ /**
+ * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
+ * under any possible substitution of the unspecified parameters (if any).
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @return true if the input is a valid (partial) match of the pattern.
+ *
+ */
+ public boolean hasMatch(final Turnout pT) {
+ return rawHasMatch(new Object[]{pT});
+ }
+
+ /**
+ * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @return the number of pattern matches found.
+ *
+ */
+ public int countMatches(final Turnout pT) {
+ return rawCountMatches(new Object[]{pT});
+ }
+
+ /**
+ * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
+ * Neither determinism nor randomness of selection is guaranteed.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @param processor the action that will process the selected match.
+ * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
+ *
+ */
+ public boolean forOneArbitraryMatch(final Turnout pT, final Consumer super TurnoutInSegments.Match> processor) {
+ return rawForOneArbitraryMatch(new Object[]{pT}, processor);
+ }
+
+ /**
+ * Returns a new (partial) match.
+ * This can be used e.g. to call the matcher with a partial match.
+ *
The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @return the (partial) match object.
+ *
+ */
+ public TurnoutInSegments.Match newMatch(final Turnout pT) {
+ return TurnoutInSegments.Match.newMatch(pT);
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for T.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ protected Stream rawStreamAllValuesOfT(final Object[] parameters) {
+ return rawStreamAllValues(POSITION_T, parameters).map(Turnout.class::cast);
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for T.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Set getAllValuesOfT() {
+ return rawStreamAllValuesOfT(emptyArray()).collect(Collectors.toSet());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for T.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Stream streamAllValuesOfT() {
+ return rawStreamAllValuesOfT(emptyArray());
+ }
+
+ @Override
+ protected TurnoutInSegments.Match tupleToMatch(final Tuple t) {
+ try {
+ return TurnoutInSegments.Match.newMatch((Turnout) t.get(POSITION_T));
+ } catch(ClassCastException e) {
+ LOGGER.error("Element(s) in tuple not properly typed!",e);
+ return null;
+ }
+ }
+
+ @Override
+ protected TurnoutInSegments.Match arrayToMatch(final Object[] match) {
+ try {
+ return TurnoutInSegments.Match.newMatch((Turnout) match[POSITION_T]);
+ } catch(ClassCastException e) {
+ LOGGER.error("Element(s) in array not properly typed!",e);
+ return null;
+ }
+ }
+
+ @Override
+ protected TurnoutInSegments.Match arrayToMatchMutable(final Object[] match) {
+ try {
+ return TurnoutInSegments.Match.newMutableMatch((Turnout) match[POSITION_T]);
+ } catch(ClassCastException e) {
+ LOGGER.error("Element(s) in array not properly typed!",e);
+ return null;
+ }
+ }
+
+ /**
+ * @return the singleton instance of the query specification of this pattern
+ * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
+ *
+ */
+ public static IQuerySpecification querySpecification() {
+ return TurnoutInSegments.instance();
+ }
+ }
+
+ private TurnoutInSegments() {
+ super(GeneratedPQuery.INSTANCE);
+ }
+
+ /**
+ * @return the singleton instance of the query specification
+ * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
+ *
+ */
+ public static TurnoutInSegments instance() {
+ try{
+ return LazyHolder.INSTANCE;
+ } catch (ExceptionInInitializerError err) {
+ throw processInitializerError(err);
+ }
+ }
+
+ @Override
+ protected TurnoutInSegments.Matcher instantiate(final ViatraQueryEngine engine) {
+ return TurnoutInSegments.Matcher.on(engine);
+ }
+
+ @Override
+ public TurnoutInSegments.Matcher instantiate() {
+ return TurnoutInSegments.Matcher.create();
+ }
+
+ @Override
+ public TurnoutInSegments.Match newEmptyMatch() {
+ return TurnoutInSegments.Match.newEmptyMatch();
+ }
+
+ @Override
+ public TurnoutInSegments.Match newMatch(final Object... parameters) {
+ return TurnoutInSegments.Match.newMatch((modes3.Turnout) parameters[0]);
+ }
+
+ /**
+ * Inner class allowing the singleton instance of {@link TurnoutInSegments} to be created
+ * not at the class load time of the outer class,
+ * but rather at the first call to {@link TurnoutInSegments#instance()}.
+ *
+ *
This workaround is required e.g. to support recursion.
+ *
+ */
+ private static class LazyHolder {
+ private static final TurnoutInSegments INSTANCE = new TurnoutInSegments();
+
+ /**
+ * Statically initializes the query specification after the field {@link #INSTANCE} is assigned.
+ * This initialization order is required to support indirect recursion.
+ *
+ *
The static initializer is defined using a helper field to work around limitations of the code generator.
+ *
+ */
+ private static final Object STATIC_INITIALIZER = ensureInitialized();
+
+ public static Object ensureInitialized() {
+ INSTANCE.ensureInitializedInternal();
+ return null;
+ }
+ }
+
+ private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
+ private static final TurnoutInSegments.GeneratedPQuery INSTANCE = new GeneratedPQuery();
+
+ private final PParameter parameter_T = new PParameter("T", "modes3.Turnout", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Turnout")), PParameterDirection.INOUT);
+
+ private final List parameters = Arrays.asList(parameter_T);
+
+ private GeneratedPQuery() {
+ super(PVisibility.PUBLIC);
+ }
+
+ @Override
+ public String getFullyQualifiedName() {
+ return "modes3.queries.turnoutInSegments";
+ }
+
+ @Override
+ public List getParameterNames() {
+ return Arrays.asList("T");
+ }
+
+ @Override
+ public List getParameters() {
+ return parameters;
+ }
+
+ @Override
+ public Set doGetContainedBodies() {
+ setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
+ Set bodies = new LinkedHashSet<>();
+ {
+ PBody body = new PBody(this);
+ PVariable var_T = body.getOrCreateVariableByName("T");
+ PVariable var___0_ = body.getOrCreateVariableByName("_<0>");
+ new TypeConstraint(body, Tuples.flatTupleOf(var_T), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Turnout")));
+ body.setSymbolicParameters(Arrays.asList(
+ new ExportedParameter(body, var_T, parameter_T)
+ ));
+ // Modes3ModelRoot.segments(_, T)
+ new TypeConstraint(body, Tuples.flatTupleOf(var___0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Modes3ModelRoot")));
+ PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
+ new TypeConstraint(body, Tuples.flatTupleOf(var___0_, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Modes3ModelRoot", "segments")));
+ new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
+ new Equality(body, var__virtual_0_, var_T);
+ bodies.add(body);
+ }
+ {
+ PAnnotation annotation = new PAnnotation("Constraint");
+ annotation.addAttribute("message", "turnoutInSegments");
+ annotation.addAttribute("severity", "error");
+ annotation.addAttribute("key", Arrays.asList(new Object[] {
+ new ParameterReference("T")
+ }));
+ addAnnotation(annotation);
+ }
+ return bodies;
+ }
+ }
+}
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 @@
+/**
+ * Generated from platform:/resource/ca.mcgill.rtgmrt.example.modes3/src/modes3/queries/Modes3Queries.vql
+ */
+package modes3.queries;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+import java.util.function.Consumer;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import modes3.Segment;
+import modes3.Turnout;
+import org.apache.log4j.Logger;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.viatra.query.runtime.api.IPatternMatch;
+import org.eclipse.viatra.query.runtime.api.IQuerySpecification;
+import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine;
+import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
+import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification;
+import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher;
+import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch;
+import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey;
+import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey;
+import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
+import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
+import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality;
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
+import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
+import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
+import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
+import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
+import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
+import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
+
+/**
+ * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
+ *
+ *
+ *
+ * @see Matcher
+ * @see Match
+ *
+ */
+@SuppressWarnings("all")
+public final class TurnoutOutput extends BaseGeneratedEMFQuerySpecification {
+ /**
+ * Pattern-specific match representation of the modes3.queries.turnoutOutput pattern,
+ * to be used in conjunction with {@link Matcher}.
+ *
+ *
Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
+ * Each instance is a (possibly partial) substitution of pattern parameters,
+ * usable to represent a match of the pattern in the result of a query,
+ * or to specify the bound (fixed) input parameters when issuing a query.
+ *
+ * @see Matcher
+ *
+ */
+ public static abstract class Match extends BasePatternMatch {
+ private Turnout fT;
+
+ private Segment fS;
+
+ private static List parameterNames = makeImmutableList("T", "S");
+
+ private Match(final Turnout pT, final Segment pS) {
+ this.fT = pT;
+ this.fS = pS;
+ }
+
+ @Override
+ public Object get(final String parameterName) {
+ switch(parameterName) {
+ case "T": return this.fT;
+ case "S": return this.fS;
+ default: return null;
+ }
+ }
+
+ @Override
+ public Object get(final int index) {
+ switch(index) {
+ case 0: return this.fT;
+ case 1: return this.fS;
+ default: return null;
+ }
+ }
+
+ public Turnout getT() {
+ return this.fT;
+ }
+
+ public Segment getS() {
+ return this.fS;
+ }
+
+ @Override
+ public boolean set(final String parameterName, final Object newValue) {
+ if (!isMutable()) throw new java.lang.UnsupportedOperationException();
+ if ("T".equals(parameterName) ) {
+ this.fT = (Turnout) newValue;
+ return true;
+ }
+ if ("S".equals(parameterName) ) {
+ this.fS = (Segment) newValue;
+ return true;
+ }
+ return false;
+ }
+
+ public void setT(final Turnout pT) {
+ if (!isMutable()) throw new java.lang.UnsupportedOperationException();
+ this.fT = pT;
+ }
+
+ public void setS(final Segment pS) {
+ if (!isMutable()) throw new java.lang.UnsupportedOperationException();
+ this.fS = pS;
+ }
+
+ @Override
+ public String patternName() {
+ return "modes3.queries.turnoutOutput";
+ }
+
+ @Override
+ public List parameterNames() {
+ return TurnoutOutput.Match.parameterNames;
+ }
+
+ @Override
+ public Object[] toArray() {
+ return new Object[]{fT, fS};
+ }
+
+ @Override
+ public TurnoutOutput.Match toImmutable() {
+ return isMutable() ? newMatch(fT, fS) : this;
+ }
+
+ @Override
+ public String prettyPrint() {
+ StringBuilder result = new StringBuilder();
+ result.append("\"T\"=" + prettyPrintValue(fT) + ", ");
+ result.append("\"S\"=" + prettyPrintValue(fS));
+ return result.toString();
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(fT, fS);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null) {
+ return false;
+ }
+ if ((obj instanceof TurnoutOutput.Match)) {
+ TurnoutOutput.Match other = (TurnoutOutput.Match) obj;
+ return Objects.equals(fT, other.fT) && Objects.equals(fS, other.fS);
+ } else {
+ // this should be infrequent
+ if (!(obj instanceof IPatternMatch)) {
+ return false;
+ }
+ IPatternMatch otherSig = (IPatternMatch) obj;
+ return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
+ }
+ }
+
+ @Override
+ public TurnoutOutput specification() {
+ return TurnoutOutput.instance();
+ }
+
+ /**
+ * Returns an empty, mutable match.
+ * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
+ *
+ * @return the empty match.
+ *
+ */
+ public static TurnoutOutput.Match newEmptyMatch() {
+ return new Mutable(null, null);
+ }
+
+ /**
+ * Returns a mutable (partial) match.
+ * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
+ *
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @param pS the fixed value of pattern parameter S, or null if not bound.
+ * @return the new, mutable (partial) match object.
+ *
+ */
+ public static TurnoutOutput.Match newMutableMatch(final Turnout pT, final Segment pS) {
+ return new Mutable(pT, pS);
+ }
+
+ /**
+ * Returns a new (partial) match.
+ * This can be used e.g. to call the matcher with a partial match.
+ *
The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @param pS the fixed value of pattern parameter S, or null if not bound.
+ * @return the (partial) match object.
+ *
+ */
+ public static TurnoutOutput.Match newMatch(final Turnout pT, final Segment pS) {
+ return new Immutable(pT, pS);
+ }
+
+ private static final class Mutable extends TurnoutOutput.Match {
+ Mutable(final Turnout pT, final Segment pS) {
+ super(pT, pS);
+ }
+
+ @Override
+ public boolean isMutable() {
+ return true;
+ }
+ }
+
+ private static final class Immutable extends TurnoutOutput.Match {
+ Immutable(final Turnout pT, final Segment pS) {
+ super(pT, pS);
+ }
+
+ @Override
+ public boolean isMutable() {
+ return false;
+ }
+ }
+ }
+
+ /**
+ * Generated pattern matcher API of the modes3.queries.turnoutOutput pattern,
+ * providing pattern-specific query methods.
+ *
+ *
Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
+ * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
+ *
+ *
Matches of the pattern will be represented as {@link Match}.
+ *
+ *
+ *
+ * @see Match
+ * @see TurnoutOutput
+ *
+ */
+ public static class Matcher extends BaseMatcher {
+ /**
+ * Initializes the pattern matcher within an existing VIATRA Query engine.
+ * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
+ *
+ * @param engine the existing VIATRA Query engine in which this matcher will be created.
+ * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
+ *
+ */
+ public static TurnoutOutput.Matcher on(final ViatraQueryEngine engine) {
+ // check if matcher already exists
+ Matcher matcher = engine.getExistingMatcher(querySpecification());
+ if (matcher == null) {
+ matcher = (Matcher)engine.getMatcher(querySpecification());
+ }
+ return matcher;
+ }
+
+ /**
+ * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
+ * @return an initialized matcher
+ * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
+ *
+ */
+ public static TurnoutOutput.Matcher create() {
+ return new Matcher();
+ }
+
+ private static final int POSITION_T = 0;
+
+ private static final int POSITION_S = 1;
+
+ private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(TurnoutOutput.Matcher.class);
+
+ /**
+ * Initializes the pattern matcher within an existing VIATRA Query engine.
+ * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
+ *
+ * @param engine the existing VIATRA Query engine in which this matcher will be created.
+ * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
+ *
+ */
+ private Matcher() {
+ super(querySpecification());
+ }
+
+ /**
+ * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @param pS the fixed value of pattern parameter S, or null if not bound.
+ * @return matches represented as a Match object.
+ *
+ */
+ public Collection getAllMatches(final Turnout pT, final Segment pS) {
+ return rawStreamAllMatches(new Object[]{pT, pS}).collect(Collectors.toSet());
+ }
+
+ /**
+ * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
+ *
+ * NOTE: It is important not to modify the source model while the stream is being processed.
+ * If the match set of the pattern changes during processing, the contents of the stream is undefined.
+ * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @param pS the fixed value of pattern parameter S, or null if not bound.
+ * @return a stream of matches represented as a Match object.
+ *
+ */
+ public Stream streamAllMatches(final Turnout pT, final Segment pS) {
+ return rawStreamAllMatches(new Object[]{pT, pS});
+ }
+
+ /**
+ * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
+ * Neither determinism nor randomness of selection is guaranteed.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @param pS the fixed value of pattern parameter S, or null if not bound.
+ * @return a match represented as a Match object, or null if no match is found.
+ *
+ */
+ public Optional getOneArbitraryMatch(final Turnout pT, final Segment pS) {
+ return rawGetOneArbitraryMatch(new Object[]{pT, pS});
+ }
+
+ /**
+ * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
+ * under any possible substitution of the unspecified parameters (if any).
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @param pS the fixed value of pattern parameter S, or null if not bound.
+ * @return true if the input is a valid (partial) match of the pattern.
+ *
+ */
+ public boolean hasMatch(final Turnout pT, final Segment pS) {
+ return rawHasMatch(new Object[]{pT, pS});
+ }
+
+ /**
+ * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @param pS the fixed value of pattern parameter S, or null if not bound.
+ * @return the number of pattern matches found.
+ *
+ */
+ public int countMatches(final Turnout pT, final Segment pS) {
+ return rawCountMatches(new Object[]{pT, pS});
+ }
+
+ /**
+ * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
+ * Neither determinism nor randomness of selection is guaranteed.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @param pS the fixed value of pattern parameter S, or null if not bound.
+ * @param processor the action that will process the selected match.
+ * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
+ *
+ */
+ public boolean forOneArbitraryMatch(final Turnout pT, final Segment pS, final Consumer super TurnoutOutput.Match> processor) {
+ return rawForOneArbitraryMatch(new Object[]{pT, pS}, processor);
+ }
+
+ /**
+ * Returns a new (partial) match.
+ * This can be used e.g. to call the matcher with a partial match.
+ *
The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @param pS the fixed value of pattern parameter S, or null if not bound.
+ * @return the (partial) match object.
+ *
+ */
+ public TurnoutOutput.Match newMatch(final Turnout pT, final Segment pS) {
+ return TurnoutOutput.Match.newMatch(pT, pS);
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for T.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ protected Stream rawStreamAllValuesOfT(final Object[] parameters) {
+ return rawStreamAllValues(POSITION_T, parameters).map(Turnout.class::cast);
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for T.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Set getAllValuesOfT() {
+ return rawStreamAllValuesOfT(emptyArray()).collect(Collectors.toSet());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for T.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Stream streamAllValuesOfT() {
+ return rawStreamAllValuesOfT(emptyArray());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for T.
+ *
+ * NOTE: It is important not to modify the source model while the stream is being processed.
+ * If the match set of the pattern changes during processing, the contents of the stream is undefined.
+ * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
+ *
+ * @return the Stream of all values or empty set if there are no matches
+ *
+ */
+ public Stream streamAllValuesOfT(final TurnoutOutput.Match partialMatch) {
+ return rawStreamAllValuesOfT(partialMatch.toArray());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for T.
+ *
+ * NOTE: It is important not to modify the source model while the stream is being processed.
+ * If the match set of the pattern changes during processing, the contents of the stream is undefined.
+ * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
+ *
+ * @return the Stream of all values or empty set if there are no matches
+ *
+ */
+ public Stream streamAllValuesOfT(final Segment pS) {
+ return rawStreamAllValuesOfT(new Object[]{null, pS});
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for T.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Set getAllValuesOfT(final TurnoutOutput.Match partialMatch) {
+ return rawStreamAllValuesOfT(partialMatch.toArray()).collect(Collectors.toSet());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for T.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Set getAllValuesOfT(final Segment pS) {
+ return rawStreamAllValuesOfT(new Object[]{null, pS}).collect(Collectors.toSet());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ protected Stream rawStreamAllValuesOfS(final Object[] parameters) {
+ return rawStreamAllValues(POSITION_S, parameters).map(Segment.class::cast);
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Set getAllValuesOfS() {
+ return rawStreamAllValuesOfS(emptyArray()).collect(Collectors.toSet());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Stream streamAllValuesOfS() {
+ return rawStreamAllValuesOfS(emptyArray());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S.
+ *
+ * NOTE: It is important not to modify the source model while the stream is being processed.
+ * If the match set of the pattern changes during processing, the contents of the stream is undefined.
+ * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
+ *
+ * @return the Stream of all values or empty set if there are no matches
+ *
+ */
+ public Stream streamAllValuesOfS(final TurnoutOutput.Match partialMatch) {
+ return rawStreamAllValuesOfS(partialMatch.toArray());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S.
+ *
+ * NOTE: It is important not to modify the source model while the stream is being processed.
+ * If the match set of the pattern changes during processing, the contents of the stream is undefined.
+ * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
+ *
+ * @return the Stream of all values or empty set if there are no matches
+ *
+ */
+ public Stream streamAllValuesOfS(final Turnout pT) {
+ return rawStreamAllValuesOfS(new Object[]{pT, null});
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Set getAllValuesOfS(final TurnoutOutput.Match partialMatch) {
+ return rawStreamAllValuesOfS(partialMatch.toArray()).collect(Collectors.toSet());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Set getAllValuesOfS(final Turnout pT) {
+ return rawStreamAllValuesOfS(new Object[]{pT, null}).collect(Collectors.toSet());
+ }
+
+ @Override
+ protected TurnoutOutput.Match tupleToMatch(final Tuple t) {
+ try {
+ return TurnoutOutput.Match.newMatch((Turnout) t.get(POSITION_T), (Segment) t.get(POSITION_S));
+ } catch(ClassCastException e) {
+ LOGGER.error("Element(s) in tuple not properly typed!",e);
+ return null;
+ }
+ }
+
+ @Override
+ protected TurnoutOutput.Match arrayToMatch(final Object[] match) {
+ try {
+ return TurnoutOutput.Match.newMatch((Turnout) match[POSITION_T], (Segment) match[POSITION_S]);
+ } catch(ClassCastException e) {
+ LOGGER.error("Element(s) in array not properly typed!",e);
+ return null;
+ }
+ }
+
+ @Override
+ protected TurnoutOutput.Match arrayToMatchMutable(final Object[] match) {
+ try {
+ return TurnoutOutput.Match.newMutableMatch((Turnout) match[POSITION_T], (Segment) match[POSITION_S]);
+ } catch(ClassCastException e) {
+ LOGGER.error("Element(s) in array not properly typed!",e);
+ return null;
+ }
+ }
+
+ /**
+ * @return the singleton instance of the query specification of this pattern
+ * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
+ *
+ */
+ public static IQuerySpecification querySpecification() {
+ return TurnoutOutput.instance();
+ }
+ }
+
+ private TurnoutOutput() {
+ super(GeneratedPQuery.INSTANCE);
+ }
+
+ /**
+ * @return the singleton instance of the query specification
+ * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
+ *
+ */
+ public static TurnoutOutput instance() {
+ try{
+ return LazyHolder.INSTANCE;
+ } catch (ExceptionInInitializerError err) {
+ throw processInitializerError(err);
+ }
+ }
+
+ @Override
+ protected TurnoutOutput.Matcher instantiate(final ViatraQueryEngine engine) {
+ return TurnoutOutput.Matcher.on(engine);
+ }
+
+ @Override
+ public TurnoutOutput.Matcher instantiate() {
+ return TurnoutOutput.Matcher.create();
+ }
+
+ @Override
+ public TurnoutOutput.Match newEmptyMatch() {
+ return TurnoutOutput.Match.newEmptyMatch();
+ }
+
+ @Override
+ public TurnoutOutput.Match newMatch(final Object... parameters) {
+ return TurnoutOutput.Match.newMatch((modes3.Turnout) parameters[0], (modes3.Segment) parameters[1]);
+ }
+
+ /**
+ * Inner class allowing the singleton instance of {@link TurnoutOutput} to be created
+ * not at the class load time of the outer class,
+ * but rather at the first call to {@link TurnoutOutput#instance()}.
+ *
+ *
This workaround is required e.g. to support recursion.
+ *
+ */
+ private static class LazyHolder {
+ private static final TurnoutOutput INSTANCE = new TurnoutOutput();
+
+ /**
+ * Statically initializes the query specification after the field {@link #INSTANCE} is assigned.
+ * This initialization order is required to support indirect recursion.
+ *
+ *
The static initializer is defined using a helper field to work around limitations of the code generator.
+ *
+ */
+ private static final Object STATIC_INITIALIZER = ensureInitialized();
+
+ public static Object ensureInitialized() {
+ INSTANCE.ensureInitializedInternal();
+ return null;
+ }
+ }
+
+ private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
+ private static final TurnoutOutput.GeneratedPQuery INSTANCE = new GeneratedPQuery();
+
+ private final PParameter parameter_T = new PParameter("T", "modes3.Turnout", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Turnout")), PParameterDirection.INOUT);
+
+ private final PParameter parameter_S = new PParameter("S", "modes3.Segment", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Segment")), PParameterDirection.INOUT);
+
+ private final List parameters = Arrays.asList(parameter_T, parameter_S);
+
+ private GeneratedPQuery() {
+ super(PVisibility.PUBLIC);
+ }
+
+ @Override
+ public String getFullyQualifiedName() {
+ return "modes3.queries.turnoutOutput";
+ }
+
+ @Override
+ public List getParameterNames() {
+ return Arrays.asList("T","S");
+ }
+
+ @Override
+ public List getParameters() {
+ return parameters;
+ }
+
+ @Override
+ public Set doGetContainedBodies() {
+ setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
+ Set bodies = new LinkedHashSet<>();
+ {
+ PBody body = new PBody(this);
+ PVariable var_T = body.getOrCreateVariableByName("T");
+ PVariable var_S = body.getOrCreateVariableByName("S");
+ new TypeConstraint(body, Tuples.flatTupleOf(var_T), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Turnout")));
+ new TypeConstraint(body, Tuples.flatTupleOf(var_S), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
+ body.setSymbolicParameters(Arrays.asList(
+ new ExportedParameter(body, var_T, parameter_T),
+ new ExportedParameter(body, var_S, parameter_S)
+ ));
+ // Turnout.straight(T, S)
+ new TypeConstraint(body, Tuples.flatTupleOf(var_T), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Turnout")));
+ PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
+ new TypeConstraint(body, Tuples.flatTupleOf(var_T, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Turnout", "straight")));
+ new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
+ new Equality(body, var__virtual_0_, var_S);
+ bodies.add(body);
+ }
+ {
+ PBody body = new PBody(this);
+ PVariable var_T = body.getOrCreateVariableByName("T");
+ PVariable var_S = body.getOrCreateVariableByName("S");
+ new TypeConstraint(body, Tuples.flatTupleOf(var_T), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Turnout")));
+ new TypeConstraint(body, Tuples.flatTupleOf(var_S), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
+ body.setSymbolicParameters(Arrays.asList(
+ new ExportedParameter(body, var_T, parameter_T),
+ new ExportedParameter(body, var_S, parameter_S)
+ ));
+ // Turnout.divergent(T, S)
+ new TypeConstraint(body, Tuples.flatTupleOf(var_T), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Turnout")));
+ PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
+ new TypeConstraint(body, Tuples.flatTupleOf(var_T, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Turnout", "divergent")));
+ new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
+ new Equality(body, var__virtual_0_, var_S);
+ bodies.add(body);
+ }
+ return bodies;
+ }
+ }
+}
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 @@
+/**
+ * Generated from platform:/resource/ca.mcgill.rtgmrt.example.modes3/src/modes3/queries/Modes3Queries.vql
+ */
+package modes3.queries;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+import java.util.function.Consumer;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import modes3.Turnout;
+import org.apache.log4j.Logger;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.viatra.query.runtime.api.IPatternMatch;
+import org.eclipse.viatra.query.runtime.api.IQuerySpecification;
+import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine;
+import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
+import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification;
+import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher;
+import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch;
+import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey;
+import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey;
+import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
+import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
+import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
+import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation;
+import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference;
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality;
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
+import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
+import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
+import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
+import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
+import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
+import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
+
+/**
+ * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
+ *
+ *
+ *
+ * @see Matcher
+ * @see Match
+ *
+ */
+@SuppressWarnings("all")
+public final class TurnoutOutputsAreSame extends BaseGeneratedEMFQuerySpecification {
+ /**
+ * Pattern-specific match representation of the modes3.queries.turnoutOutputsAreSame pattern,
+ * to be used in conjunction with {@link Matcher}.
+ *
+ *
Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
+ * Each instance is a (possibly partial) substitution of pattern parameters,
+ * usable to represent a match of the pattern in the result of a query,
+ * or to specify the bound (fixed) input parameters when issuing a query.
+ *
+ * @see Matcher
+ *
+ */
+ public static abstract class Match extends BasePatternMatch {
+ private Turnout fT;
+
+ private static List parameterNames = makeImmutableList("T");
+
+ private Match(final Turnout pT) {
+ this.fT = pT;
+ }
+
+ @Override
+ public Object get(final String parameterName) {
+ switch(parameterName) {
+ case "T": return this.fT;
+ default: return null;
+ }
+ }
+
+ @Override
+ public Object get(final int index) {
+ switch(index) {
+ case 0: return this.fT;
+ default: return null;
+ }
+ }
+
+ public Turnout getT() {
+ return this.fT;
+ }
+
+ @Override
+ public boolean set(final String parameterName, final Object newValue) {
+ if (!isMutable()) throw new java.lang.UnsupportedOperationException();
+ if ("T".equals(parameterName) ) {
+ this.fT = (Turnout) newValue;
+ return true;
+ }
+ return false;
+ }
+
+ public void setT(final Turnout pT) {
+ if (!isMutable()) throw new java.lang.UnsupportedOperationException();
+ this.fT = pT;
+ }
+
+ @Override
+ public String patternName() {
+ return "modes3.queries.turnoutOutputsAreSame";
+ }
+
+ @Override
+ public List parameterNames() {
+ return TurnoutOutputsAreSame.Match.parameterNames;
+ }
+
+ @Override
+ public Object[] toArray() {
+ return new Object[]{fT};
+ }
+
+ @Override
+ public TurnoutOutputsAreSame.Match toImmutable() {
+ return isMutable() ? newMatch(fT) : this;
+ }
+
+ @Override
+ public String prettyPrint() {
+ StringBuilder result = new StringBuilder();
+ result.append("\"T\"=" + prettyPrintValue(fT));
+ return result.toString();
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(fT);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null) {
+ return false;
+ }
+ if ((obj instanceof TurnoutOutputsAreSame.Match)) {
+ TurnoutOutputsAreSame.Match other = (TurnoutOutputsAreSame.Match) obj;
+ return Objects.equals(fT, other.fT);
+ } else {
+ // this should be infrequent
+ if (!(obj instanceof IPatternMatch)) {
+ return false;
+ }
+ IPatternMatch otherSig = (IPatternMatch) obj;
+ return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
+ }
+ }
+
+ @Override
+ public TurnoutOutputsAreSame specification() {
+ return TurnoutOutputsAreSame.instance();
+ }
+
+ /**
+ * Returns an empty, mutable match.
+ * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
+ *
+ * @return the empty match.
+ *
+ */
+ public static TurnoutOutputsAreSame.Match newEmptyMatch() {
+ return new Mutable(null);
+ }
+
+ /**
+ * Returns a mutable (partial) match.
+ * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
+ *
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @return the new, mutable (partial) match object.
+ *
+ */
+ public static TurnoutOutputsAreSame.Match newMutableMatch(final Turnout pT) {
+ return new Mutable(pT);
+ }
+
+ /**
+ * Returns a new (partial) match.
+ * This can be used e.g. to call the matcher with a partial match.
+ *
The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @return the (partial) match object.
+ *
+ */
+ public static TurnoutOutputsAreSame.Match newMatch(final Turnout pT) {
+ return new Immutable(pT);
+ }
+
+ private static final class Mutable extends TurnoutOutputsAreSame.Match {
+ Mutable(final Turnout pT) {
+ super(pT);
+ }
+
+ @Override
+ public boolean isMutable() {
+ return true;
+ }
+ }
+
+ private static final class Immutable extends TurnoutOutputsAreSame.Match {
+ Immutable(final Turnout pT) {
+ super(pT);
+ }
+
+ @Override
+ public boolean isMutable() {
+ return false;
+ }
+ }
+ }
+
+ /**
+ * Generated pattern matcher API of the modes3.queries.turnoutOutputsAreSame pattern,
+ * providing pattern-specific query methods.
+ *
+ *
Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
+ * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
+ *
+ *
Matches of the pattern will be represented as {@link Match}.
+ *
+ *
+ *
+ * @see Match
+ * @see TurnoutOutputsAreSame
+ *
+ */
+ public static class Matcher extends BaseMatcher {
+ /**
+ * Initializes the pattern matcher within an existing VIATRA Query engine.
+ * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
+ *
+ * @param engine the existing VIATRA Query engine in which this matcher will be created.
+ * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
+ *
+ */
+ public static TurnoutOutputsAreSame.Matcher on(final ViatraQueryEngine engine) {
+ // check if matcher already exists
+ Matcher matcher = engine.getExistingMatcher(querySpecification());
+ if (matcher == null) {
+ matcher = (Matcher)engine.getMatcher(querySpecification());
+ }
+ return matcher;
+ }
+
+ /**
+ * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
+ * @return an initialized matcher
+ * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
+ *
+ */
+ public static TurnoutOutputsAreSame.Matcher create() {
+ return new Matcher();
+ }
+
+ private static final int POSITION_T = 0;
+
+ private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(TurnoutOutputsAreSame.Matcher.class);
+
+ /**
+ * Initializes the pattern matcher within an existing VIATRA Query engine.
+ * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
+ *
+ * @param engine the existing VIATRA Query engine in which this matcher will be created.
+ * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
+ *
+ */
+ private Matcher() {
+ super(querySpecification());
+ }
+
+ /**
+ * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @return matches represented as a Match object.
+ *
+ */
+ public Collection getAllMatches(final Turnout pT) {
+ return rawStreamAllMatches(new Object[]{pT}).collect(Collectors.toSet());
+ }
+
+ /**
+ * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
+ *
+ * NOTE: It is important not to modify the source model while the stream is being processed.
+ * If the match set of the pattern changes during processing, the contents of the stream is undefined.
+ * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @return a stream of matches represented as a Match object.
+ *
+ */
+ public Stream streamAllMatches(final Turnout pT) {
+ return rawStreamAllMatches(new Object[]{pT});
+ }
+
+ /**
+ * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
+ * Neither determinism nor randomness of selection is guaranteed.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @return a match represented as a Match object, or null if no match is found.
+ *
+ */
+ public Optional getOneArbitraryMatch(final Turnout pT) {
+ return rawGetOneArbitraryMatch(new Object[]{pT});
+ }
+
+ /**
+ * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
+ * under any possible substitution of the unspecified parameters (if any).
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @return true if the input is a valid (partial) match of the pattern.
+ *
+ */
+ public boolean hasMatch(final Turnout pT) {
+ return rawHasMatch(new Object[]{pT});
+ }
+
+ /**
+ * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @return the number of pattern matches found.
+ *
+ */
+ public int countMatches(final Turnout pT) {
+ return rawCountMatches(new Object[]{pT});
+ }
+
+ /**
+ * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
+ * Neither determinism nor randomness of selection is guaranteed.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @param processor the action that will process the selected match.
+ * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
+ *
+ */
+ public boolean forOneArbitraryMatch(final Turnout pT, final Consumer super TurnoutOutputsAreSame.Match> processor) {
+ return rawForOneArbitraryMatch(new Object[]{pT}, processor);
+ }
+
+ /**
+ * Returns a new (partial) match.
+ * This can be used e.g. to call the matcher with a partial match.
+ *
The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
+ * @param pT the fixed value of pattern parameter T, or null if not bound.
+ * @return the (partial) match object.
+ *
+ */
+ public TurnoutOutputsAreSame.Match newMatch(final Turnout pT) {
+ return TurnoutOutputsAreSame.Match.newMatch(pT);
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for T.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ protected Stream rawStreamAllValuesOfT(final Object[] parameters) {
+ return rawStreamAllValues(POSITION_T, parameters).map(Turnout.class::cast);
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for T.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Set getAllValuesOfT() {
+ return rawStreamAllValuesOfT(emptyArray()).collect(Collectors.toSet());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for T.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Stream streamAllValuesOfT() {
+ return rawStreamAllValuesOfT(emptyArray());
+ }
+
+ @Override
+ protected TurnoutOutputsAreSame.Match tupleToMatch(final Tuple t) {
+ try {
+ return TurnoutOutputsAreSame.Match.newMatch((Turnout) t.get(POSITION_T));
+ } catch(ClassCastException e) {
+ LOGGER.error("Element(s) in tuple not properly typed!",e);
+ return null;
+ }
+ }
+
+ @Override
+ protected TurnoutOutputsAreSame.Match arrayToMatch(final Object[] match) {
+ try {
+ return TurnoutOutputsAreSame.Match.newMatch((Turnout) match[POSITION_T]);
+ } catch(ClassCastException e) {
+ LOGGER.error("Element(s) in array not properly typed!",e);
+ return null;
+ }
+ }
+
+ @Override
+ protected TurnoutOutputsAreSame.Match arrayToMatchMutable(final Object[] match) {
+ try {
+ return TurnoutOutputsAreSame.Match.newMutableMatch((Turnout) match[POSITION_T]);
+ } catch(ClassCastException e) {
+ LOGGER.error("Element(s) in array not properly typed!",e);
+ return null;
+ }
+ }
+
+ /**
+ * @return the singleton instance of the query specification of this pattern
+ * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
+ *
+ */
+ public static IQuerySpecification querySpecification() {
+ return TurnoutOutputsAreSame.instance();
+ }
+ }
+
+ private TurnoutOutputsAreSame() {
+ super(GeneratedPQuery.INSTANCE);
+ }
+
+ /**
+ * @return the singleton instance of the query specification
+ * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
+ *
+ */
+ public static TurnoutOutputsAreSame instance() {
+ try{
+ return LazyHolder.INSTANCE;
+ } catch (ExceptionInInitializerError err) {
+ throw processInitializerError(err);
+ }
+ }
+
+ @Override
+ protected TurnoutOutputsAreSame.Matcher instantiate(final ViatraQueryEngine engine) {
+ return TurnoutOutputsAreSame.Matcher.on(engine);
+ }
+
+ @Override
+ public TurnoutOutputsAreSame.Matcher instantiate() {
+ return TurnoutOutputsAreSame.Matcher.create();
+ }
+
+ @Override
+ public TurnoutOutputsAreSame.Match newEmptyMatch() {
+ return TurnoutOutputsAreSame.Match.newEmptyMatch();
+ }
+
+ @Override
+ public TurnoutOutputsAreSame.Match newMatch(final Object... parameters) {
+ return TurnoutOutputsAreSame.Match.newMatch((modes3.Turnout) parameters[0]);
+ }
+
+ /**
+ * Inner class allowing the singleton instance of {@link TurnoutOutputsAreSame} to be created
+ * not at the class load time of the outer class,
+ * but rather at the first call to {@link TurnoutOutputsAreSame#instance()}.
+ *
+ *
This workaround is required e.g. to support recursion.
+ *
+ */
+ private static class LazyHolder {
+ private static final TurnoutOutputsAreSame INSTANCE = new TurnoutOutputsAreSame();
+
+ /**
+ * Statically initializes the query specification after the field {@link #INSTANCE} is assigned.
+ * This initialization order is required to support indirect recursion.
+ *
+ *
The static initializer is defined using a helper field to work around limitations of the code generator.
+ *
+ */
+ private static final Object STATIC_INITIALIZER = ensureInitialized();
+
+ public static Object ensureInitialized() {
+ INSTANCE.ensureInitializedInternal();
+ return null;
+ }
+ }
+
+ private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
+ private static final TurnoutOutputsAreSame.GeneratedPQuery INSTANCE = new GeneratedPQuery();
+
+ private final PParameter parameter_T = new PParameter("T", "modes3.Turnout", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Turnout")), PParameterDirection.INOUT);
+
+ private final List parameters = Arrays.asList(parameter_T);
+
+ private GeneratedPQuery() {
+ super(PVisibility.PUBLIC);
+ }
+
+ @Override
+ public String getFullyQualifiedName() {
+ return "modes3.queries.turnoutOutputsAreSame";
+ }
+
+ @Override
+ public List getParameterNames() {
+ return Arrays.asList("T");
+ }
+
+ @Override
+ public List getParameters() {
+ return parameters;
+ }
+
+ @Override
+ public Set doGetContainedBodies() {
+ setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
+ Set bodies = new LinkedHashSet<>();
+ {
+ PBody body = new PBody(this);
+ PVariable var_T = body.getOrCreateVariableByName("T");
+ PVariable var_S = body.getOrCreateVariableByName("S");
+ new TypeConstraint(body, Tuples.flatTupleOf(var_T), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Turnout")));
+ body.setSymbolicParameters(Arrays.asList(
+ new ExportedParameter(body, var_T, parameter_T)
+ ));
+ // Turnout.straight(T, S)
+ new TypeConstraint(body, Tuples.flatTupleOf(var_T), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Turnout")));
+ PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
+ new TypeConstraint(body, Tuples.flatTupleOf(var_T, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Turnout", "straight")));
+ new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
+ new Equality(body, var__virtual_0_, var_S);
+ // Turnout.divergent(T, S)
+ new TypeConstraint(body, Tuples.flatTupleOf(var_T), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Turnout")));
+ PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
+ new TypeConstraint(body, Tuples.flatTupleOf(var_T, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Turnout", "divergent")));
+ new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
+ new Equality(body, var__virtual_1_, var_S);
+ bodies.add(body);
+ }
+ {
+ PAnnotation annotation = new PAnnotation("Constraint");
+ annotation.addAttribute("message", "turnoutOutputsAreSame");
+ annotation.addAttribute("severity", "error");
+ annotation.addAttribute("key", Arrays.asList(new Object[] {
+ new ParameterReference("T")
+ }));
+ addAnnotation(annotation);
+ }
+ return bodies;
+ }
+ }
+}
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 @@
+/**
+ * Generated from platform:/resource/ca.mcgill.rtgmrt.example.modes3/src/modes3/queries/Modes3Queries.vql
+ */
+package modes3.queries;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+import java.util.function.Consumer;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import modes3.Segment;
+import modes3.queries.Reachable;
+import org.apache.log4j.Logger;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.viatra.query.runtime.api.IPatternMatch;
+import org.eclipse.viatra.query.runtime.api.IQuerySpecification;
+import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine;
+import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
+import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification;
+import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher;
+import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch;
+import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey;
+import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
+import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
+import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
+import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation;
+import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference;
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.NegativePatternCall;
+import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
+import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
+import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
+import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
+import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
+import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
+import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
+
+/**
+ * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
+ *
+ *
+ *
+ * @see Matcher
+ * @see Match
+ *
+ */
+@SuppressWarnings("all")
+public final class Unreachable extends BaseGeneratedEMFQuerySpecification {
+ /**
+ * Pattern-specific match representation of the modes3.queries.unreachable pattern,
+ * to be used in conjunction with {@link Matcher}.
+ *
+ *
Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
+ * Each instance is a (possibly partial) substitution of pattern parameters,
+ * usable to represent a match of the pattern in the result of a query,
+ * or to specify the bound (fixed) input parameters when issuing a query.
+ *
+ * @see Matcher
+ *
+ */
+ public static abstract class Match extends BasePatternMatch {
+ private Segment fS1;
+
+ private Segment fS2;
+
+ private static List parameterNames = makeImmutableList("S1", "S2");
+
+ private Match(final Segment pS1, final Segment pS2) {
+ this.fS1 = pS1;
+ this.fS2 = pS2;
+ }
+
+ @Override
+ public Object get(final String parameterName) {
+ switch(parameterName) {
+ case "S1": return this.fS1;
+ case "S2": return this.fS2;
+ default: return null;
+ }
+ }
+
+ @Override
+ public Object get(final int index) {
+ switch(index) {
+ case 0: return this.fS1;
+ case 1: return this.fS2;
+ default: return null;
+ }
+ }
+
+ public Segment getS1() {
+ return this.fS1;
+ }
+
+ public Segment getS2() {
+ return this.fS2;
+ }
+
+ @Override
+ public boolean set(final String parameterName, final Object newValue) {
+ if (!isMutable()) throw new java.lang.UnsupportedOperationException();
+ if ("S1".equals(parameterName) ) {
+ this.fS1 = (Segment) newValue;
+ return true;
+ }
+ if ("S2".equals(parameterName) ) {
+ this.fS2 = (Segment) newValue;
+ return true;
+ }
+ return false;
+ }
+
+ public void setS1(final Segment pS1) {
+ if (!isMutable()) throw new java.lang.UnsupportedOperationException();
+ this.fS1 = pS1;
+ }
+
+ public void setS2(final Segment pS2) {
+ if (!isMutable()) throw new java.lang.UnsupportedOperationException();
+ this.fS2 = pS2;
+ }
+
+ @Override
+ public String patternName() {
+ return "modes3.queries.unreachable";
+ }
+
+ @Override
+ public List parameterNames() {
+ return Unreachable.Match.parameterNames;
+ }
+
+ @Override
+ public Object[] toArray() {
+ return new Object[]{fS1, fS2};
+ }
+
+ @Override
+ public Unreachable.Match toImmutable() {
+ return isMutable() ? newMatch(fS1, fS2) : this;
+ }
+
+ @Override
+ public String prettyPrint() {
+ StringBuilder result = new StringBuilder();
+ result.append("\"S1\"=" + prettyPrintValue(fS1) + ", ");
+ result.append("\"S2\"=" + prettyPrintValue(fS2));
+ return result.toString();
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(fS1, fS2);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null) {
+ return false;
+ }
+ if ((obj instanceof Unreachable.Match)) {
+ Unreachable.Match other = (Unreachable.Match) obj;
+ return Objects.equals(fS1, other.fS1) && Objects.equals(fS2, other.fS2);
+ } else {
+ // this should be infrequent
+ if (!(obj instanceof IPatternMatch)) {
+ return false;
+ }
+ IPatternMatch otherSig = (IPatternMatch) obj;
+ return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
+ }
+ }
+
+ @Override
+ public Unreachable specification() {
+ return Unreachable.instance();
+ }
+
+ /**
+ * Returns an empty, mutable match.
+ * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
+ *
+ * @return the empty match.
+ *
+ */
+ public static Unreachable.Match newEmptyMatch() {
+ return new Mutable(null, null);
+ }
+
+ /**
+ * Returns a mutable (partial) match.
+ * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
+ *
+ * @param pS1 the fixed value of pattern parameter S1, or null if not bound.
+ * @param pS2 the fixed value of pattern parameter S2, or null if not bound.
+ * @return the new, mutable (partial) match object.
+ *
+ */
+ public static Unreachable.Match newMutableMatch(final Segment pS1, final Segment pS2) {
+ return new Mutable(pS1, pS2);
+ }
+
+ /**
+ * Returns a new (partial) match.
+ * This can be used e.g. to call the matcher with a partial match.
+ *
The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
+ * @param pS1 the fixed value of pattern parameter S1, or null if not bound.
+ * @param pS2 the fixed value of pattern parameter S2, or null if not bound.
+ * @return the (partial) match object.
+ *
+ */
+ public static Unreachable.Match newMatch(final Segment pS1, final Segment pS2) {
+ return new Immutable(pS1, pS2);
+ }
+
+ private static final class Mutable extends Unreachable.Match {
+ Mutable(final Segment pS1, final Segment pS2) {
+ super(pS1, pS2);
+ }
+
+ @Override
+ public boolean isMutable() {
+ return true;
+ }
+ }
+
+ private static final class Immutable extends Unreachable.Match {
+ Immutable(final Segment pS1, final Segment pS2) {
+ super(pS1, pS2);
+ }
+
+ @Override
+ public boolean isMutable() {
+ return false;
+ }
+ }
+ }
+
+ /**
+ * Generated pattern matcher API of the modes3.queries.unreachable pattern,
+ * providing pattern-specific query methods.
+ *
+ *
Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
+ * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
+ *
+ *
Matches of the pattern will be represented as {@link Match}.
+ *
+ *
+ *
+ * @see Match
+ * @see Unreachable
+ *
+ */
+ public static class Matcher extends BaseMatcher {
+ /**
+ * Initializes the pattern matcher within an existing VIATRA Query engine.
+ * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
+ *
+ * @param engine the existing VIATRA Query engine in which this matcher will be created.
+ * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
+ *
+ */
+ public static Unreachable.Matcher on(final ViatraQueryEngine engine) {
+ // check if matcher already exists
+ Matcher matcher = engine.getExistingMatcher(querySpecification());
+ if (matcher == null) {
+ matcher = (Matcher)engine.getMatcher(querySpecification());
+ }
+ return matcher;
+ }
+
+ /**
+ * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
+ * @return an initialized matcher
+ * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
+ *
+ */
+ public static Unreachable.Matcher create() {
+ return new Matcher();
+ }
+
+ private static final int POSITION_S1 = 0;
+
+ private static final int POSITION_S2 = 1;
+
+ private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Unreachable.Matcher.class);
+
+ /**
+ * Initializes the pattern matcher within an existing VIATRA Query engine.
+ * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
+ *
+ * @param engine the existing VIATRA Query engine in which this matcher will be created.
+ * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
+ *
+ */
+ private Matcher() {
+ super(querySpecification());
+ }
+
+ /**
+ * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
+ * @param pS1 the fixed value of pattern parameter S1, or null if not bound.
+ * @param pS2 the fixed value of pattern parameter S2, or null if not bound.
+ * @return matches represented as a Match object.
+ *
+ */
+ public Collection getAllMatches(final Segment pS1, final Segment pS2) {
+ return rawStreamAllMatches(new Object[]{pS1, pS2}).collect(Collectors.toSet());
+ }
+
+ /**
+ * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
+ *
+ * NOTE: It is important not to modify the source model while the stream is being processed.
+ * If the match set of the pattern changes during processing, the contents of the stream is undefined.
+ * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
+ * @param pS1 the fixed value of pattern parameter S1, or null if not bound.
+ * @param pS2 the fixed value of pattern parameter S2, or null if not bound.
+ * @return a stream of matches represented as a Match object.
+ *
+ */
+ public Stream streamAllMatches(final Segment pS1, final Segment pS2) {
+ return rawStreamAllMatches(new Object[]{pS1, pS2});
+ }
+
+ /**
+ * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
+ * Neither determinism nor randomness of selection is guaranteed.
+ * @param pS1 the fixed value of pattern parameter S1, or null if not bound.
+ * @param pS2 the fixed value of pattern parameter S2, or null if not bound.
+ * @return a match represented as a Match object, or null if no match is found.
+ *
+ */
+ public Optional getOneArbitraryMatch(final Segment pS1, final Segment pS2) {
+ return rawGetOneArbitraryMatch(new Object[]{pS1, pS2});
+ }
+
+ /**
+ * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
+ * under any possible substitution of the unspecified parameters (if any).
+ * @param pS1 the fixed value of pattern parameter S1, or null if not bound.
+ * @param pS2 the fixed value of pattern parameter S2, or null if not bound.
+ * @return true if the input is a valid (partial) match of the pattern.
+ *
+ */
+ public boolean hasMatch(final Segment pS1, final Segment pS2) {
+ return rawHasMatch(new Object[]{pS1, pS2});
+ }
+
+ /**
+ * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
+ * @param pS1 the fixed value of pattern parameter S1, or null if not bound.
+ * @param pS2 the fixed value of pattern parameter S2, or null if not bound.
+ * @return the number of pattern matches found.
+ *
+ */
+ public int countMatches(final Segment pS1, final Segment pS2) {
+ return rawCountMatches(new Object[]{pS1, pS2});
+ }
+
+ /**
+ * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
+ * Neither determinism nor randomness of selection is guaranteed.
+ * @param pS1 the fixed value of pattern parameter S1, or null if not bound.
+ * @param pS2 the fixed value of pattern parameter S2, or null if not bound.
+ * @param processor the action that will process the selected match.
+ * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
+ *
+ */
+ public boolean forOneArbitraryMatch(final Segment pS1, final Segment pS2, final Consumer super Unreachable.Match> processor) {
+ return rawForOneArbitraryMatch(new Object[]{pS1, pS2}, processor);
+ }
+
+ /**
+ * Returns a new (partial) match.
+ * This can be used e.g. to call the matcher with a partial match.
+ *
The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
+ * @param pS1 the fixed value of pattern parameter S1, or null if not bound.
+ * @param pS2 the fixed value of pattern parameter S2, or null if not bound.
+ * @return the (partial) match object.
+ *
+ */
+ public Unreachable.Match newMatch(final Segment pS1, final Segment pS2) {
+ return Unreachable.Match.newMatch(pS1, pS2);
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S1.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ protected Stream rawStreamAllValuesOfS1(final Object[] parameters) {
+ return rawStreamAllValues(POSITION_S1, parameters).map(Segment.class::cast);
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S1.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Set getAllValuesOfS1() {
+ return rawStreamAllValuesOfS1(emptyArray()).collect(Collectors.toSet());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S1.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Stream streamAllValuesOfS1() {
+ return rawStreamAllValuesOfS1(emptyArray());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S1.
+ *
+ * NOTE: It is important not to modify the source model while the stream is being processed.
+ * If the match set of the pattern changes during processing, the contents of the stream is undefined.
+ * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
+ *
+ * @return the Stream of all values or empty set if there are no matches
+ *
+ */
+ public Stream streamAllValuesOfS1(final Unreachable.Match partialMatch) {
+ return rawStreamAllValuesOfS1(partialMatch.toArray());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S1.
+ *
+ * NOTE: It is important not to modify the source model while the stream is being processed.
+ * If the match set of the pattern changes during processing, the contents of the stream is undefined.
+ * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
+ *
+ * @return the Stream of all values or empty set if there are no matches
+ *
+ */
+ public Stream streamAllValuesOfS1(final Segment pS2) {
+ return rawStreamAllValuesOfS1(new Object[]{null, pS2});
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S1.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Set getAllValuesOfS1(final Unreachable.Match partialMatch) {
+ return rawStreamAllValuesOfS1(partialMatch.toArray()).collect(Collectors.toSet());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S1.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Set getAllValuesOfS1(final Segment pS2) {
+ return rawStreamAllValuesOfS1(new Object[]{null, pS2}).collect(Collectors.toSet());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S2.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ protected Stream rawStreamAllValuesOfS2(final Object[] parameters) {
+ return rawStreamAllValues(POSITION_S2, parameters).map(Segment.class::cast);
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S2.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Set getAllValuesOfS2() {
+ return rawStreamAllValuesOfS2(emptyArray()).collect(Collectors.toSet());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S2.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Stream streamAllValuesOfS2() {
+ return rawStreamAllValuesOfS2(emptyArray());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S2.
+ *
+ * NOTE: It is important not to modify the source model while the stream is being processed.
+ * If the match set of the pattern changes during processing, the contents of the stream is undefined.
+ * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
+ *
+ * @return the Stream of all values or empty set if there are no matches
+ *
+ */
+ public Stream streamAllValuesOfS2(final Unreachable.Match partialMatch) {
+ return rawStreamAllValuesOfS2(partialMatch.toArray());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S2.
+ *
+ * NOTE: It is important not to modify the source model while the stream is being processed.
+ * If the match set of the pattern changes during processing, the contents of the stream is undefined.
+ * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
+ *
+ * @return the Stream of all values or empty set if there are no matches
+ *
+ */
+ public Stream streamAllValuesOfS2(final Segment pS1) {
+ return rawStreamAllValuesOfS2(new Object[]{pS1, null});
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S2.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Set getAllValuesOfS2(final Unreachable.Match partialMatch) {
+ return rawStreamAllValuesOfS2(partialMatch.toArray()).collect(Collectors.toSet());
+ }
+
+ /**
+ * Retrieve the set of values that occur in matches for S2.
+ * @return the Set of all values or empty set if there are no matches
+ *
+ */
+ public Set getAllValuesOfS2(final Segment pS1) {
+ return rawStreamAllValuesOfS2(new Object[]{pS1, null}).collect(Collectors.toSet());
+ }
+
+ @Override
+ protected Unreachable.Match tupleToMatch(final Tuple t) {
+ try {
+ return Unreachable.Match.newMatch((Segment) t.get(POSITION_S1), (Segment) t.get(POSITION_S2));
+ } catch(ClassCastException e) {
+ LOGGER.error("Element(s) in tuple not properly typed!",e);
+ return null;
+ }
+ }
+
+ @Override
+ protected Unreachable.Match arrayToMatch(final Object[] match) {
+ try {
+ return Unreachable.Match.newMatch((Segment) match[POSITION_S1], (Segment) match[POSITION_S2]);
+ } catch(ClassCastException e) {
+ LOGGER.error("Element(s) in array not properly typed!",e);
+ return null;
+ }
+ }
+
+ @Override
+ protected Unreachable.Match arrayToMatchMutable(final Object[] match) {
+ try {
+ return Unreachable.Match.newMutableMatch((Segment) match[POSITION_S1], (Segment) match[POSITION_S2]);
+ } catch(ClassCastException e) {
+ LOGGER.error("Element(s) in array not properly typed!",e);
+ return null;
+ }
+ }
+
+ /**
+ * @return the singleton instance of the query specification of this pattern
+ * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
+ *
+ */
+ public static IQuerySpecification querySpecification() {
+ return Unreachable.instance();
+ }
+ }
+
+ private Unreachable() {
+ super(GeneratedPQuery.INSTANCE);
+ }
+
+ /**
+ * @return the singleton instance of the query specification
+ * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
+ *
+ */
+ public static Unreachable instance() {
+ try{
+ return LazyHolder.INSTANCE;
+ } catch (ExceptionInInitializerError err) {
+ throw processInitializerError(err);
+ }
+ }
+
+ @Override
+ protected Unreachable.Matcher instantiate(final ViatraQueryEngine engine) {
+ return Unreachable.Matcher.on(engine);
+ }
+
+ @Override
+ public Unreachable.Matcher instantiate() {
+ return Unreachable.Matcher.create();
+ }
+
+ @Override
+ public Unreachable.Match newEmptyMatch() {
+ return Unreachable.Match.newEmptyMatch();
+ }
+
+ @Override
+ public Unreachable.Match newMatch(final Object... parameters) {
+ return Unreachable.Match.newMatch((modes3.Segment) parameters[0], (modes3.Segment) parameters[1]);
+ }
+
+ /**
+ * Inner class allowing the singleton instance of {@link Unreachable} to be created
+ * not at the class load time of the outer class,
+ * but rather at the first call to {@link Unreachable#instance()}.
+ *
+ *
This workaround is required e.g. to support recursion.
+ *
+ */
+ private static class LazyHolder {
+ private static final Unreachable INSTANCE = new Unreachable();
+
+ /**
+ * Statically initializes the query specification after the field {@link #INSTANCE} is assigned.
+ * This initialization order is required to support indirect recursion.
+ *
+ *
The static initializer is defined using a helper field to work around limitations of the code generator.
+ *
+ */
+ private static final Object STATIC_INITIALIZER = ensureInitialized();
+
+ public static Object ensureInitialized() {
+ INSTANCE.ensureInitializedInternal();
+ return null;
+ }
+ }
+
+ private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
+ private static final Unreachable.GeneratedPQuery INSTANCE = new GeneratedPQuery();
+
+ private final PParameter parameter_S1 = new PParameter("S1", "modes3.Segment", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Segment")), PParameterDirection.INOUT);
+
+ private final PParameter parameter_S2 = new PParameter("S2", "modes3.Segment", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Segment")), PParameterDirection.INOUT);
+
+ private final List parameters = Arrays.asList(parameter_S1, parameter_S2);
+
+ private GeneratedPQuery() {
+ super(PVisibility.PUBLIC);
+ }
+
+ @Override
+ public String getFullyQualifiedName() {
+ return "modes3.queries.unreachable";
+ }
+
+ @Override
+ public List getParameterNames() {
+ return Arrays.asList("S1","S2");
+ }
+
+ @Override
+ public List getParameters() {
+ return parameters;
+ }
+
+ @Override
+ public Set doGetContainedBodies() {
+ setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
+ Set bodies = new LinkedHashSet<>();
+ {
+ PBody body = new PBody(this);
+ PVariable var_S1 = body.getOrCreateVariableByName("S1");
+ PVariable var_S2 = body.getOrCreateVariableByName("S2");
+ new TypeConstraint(body, Tuples.flatTupleOf(var_S1), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
+ new TypeConstraint(body, Tuples.flatTupleOf(var_S2), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
+ body.setSymbolicParameters(Arrays.asList(
+ new ExportedParameter(body, var_S1, parameter_S1),
+ new ExportedParameter(body, var_S2, parameter_S2)
+ ));
+ // neg find reachable(S1, S2)
+ new NegativePatternCall(body, Tuples.flatTupleOf(var_S1, var_S2), Reachable.instance().getInternalQueryRepresentation());
+ bodies.add(body);
+ }
+ {
+ PAnnotation annotation = new PAnnotation("Constraint");
+ annotation.addAttribute("message", "unreachable");
+ annotation.addAttribute("severity", "error");
+ annotation.addAttribute("key", Arrays.asList(new Object[] {
+ new ParameterReference("S1"),
+ new ParameterReference("S2")
+ }));
+ addAnnotation(annotation);
+ }
+ return bodies;
+ }
+ }
+}
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..4f542a67
Binary files /dev/null and b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/.Modes3ModelGenerator.xtendbin 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..28e763b9
Binary files /dev/null and b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/.Modes3UnitPropagationGenerator.xtendbin 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..53dcf60f
--- /dev/null
+++ b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/.gitignore
@@ -0,0 +1,2 @@
+/.Modes3ModelGenerator.java._trace
+/.Modes3UnitPropagationGenerator.java._trace
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..c7364257
--- /dev/null
+++ b/Domains/ca.mcgill.rtgmrt.example.modes3/xtend-gen/modes3/run/Modes3ModelGenerator.java
@@ -0,0 +1,381 @@
+package modes3.run;
+
+import com.google.common.base.Objects;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterables;
+import hu.bme.mit.inf.dslreasoner.ecore2logic.EReferenceMapper_RelationsOverTypes_Trace;
+import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic;
+import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2LogicConfiguration;
+import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace;
+import hu.bme.mit.inf.dslreasoner.ecore2logic.EcoreMetamodelDescriptor;
+import hu.bme.mit.inf.dslreasoner.ecore2logic.ecore2logicannotations.Ecore2logicannotationsFactory;
+import hu.bme.mit.inf.dslreasoner.ecore2logic.ecore2logicannotations.Ecore2logicannotationsPackage;
+import hu.bme.mit.inf.dslreasoner.ecore2logic.ecore2logicannotations.InverseRelationAssertion;
+import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicProblemBuilder;
+import hu.bme.mit.inf.dslreasoner.logic.model.builder.TracedOutput;
+import hu.bme.mit.inf.dslreasoner.logic.model.builder.TypeScopes;
+import hu.bme.mit.inf.dslreasoner.logic.model.builder.VariableContext;
+import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Assertion;
+import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Iff;
+import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.LogiclanguagePackage;
+import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RelationDeclaration;
+import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.SymbolicValue;
+import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TermDescription;
+import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type;
+import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TypeDefinition;
+import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Variable;
+import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.Annotation;
+import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem;
+import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicproblemPackage;
+import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.LogicResult;
+import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.ModelResult;
+import hu.bme.mit.inf.dslreasoner.viatra2logic.Viatra2Logic;
+import hu.bme.mit.inf.dslreasoner.viatra2logic.Viatra2LogicConfiguration;
+import hu.bme.mit.inf.dslreasoner.viatra2logic.Viatra2LogicTrace;
+import hu.bme.mit.inf.dslreasoner.viatra2logic.ViatraQuerySetDescriptor;
+import hu.bme.mit.inf.dslreasoner.viatra2logic.viatra2logicannotations.Viatra2LogicAnnotationsPackage;
+import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.TypeInferenceMethod;
+import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.PolyhedralScopePropagatorConstraints;
+import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.PolyhedralScopePropagatorSolver;
+import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.ScopePropagatorStrategy;
+import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic.InstanceModel2Logic;
+import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.BinaryElementRelationLink;
+import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialComplexTypeInterpretation;
+import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation;
+import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialRelationInterpretation;
+import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialinterpretationPackage;
+import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.RelationLink;
+import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.visualisation.PartialInterpretation2Gml;
+import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.visualisation.PartialInterpretationVisualisation;
+import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.StateCoderStrategy;
+import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.ViatraReasoner;
+import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.ViatraReasonerConfiguration;
+import hu.bme.mit.inf.dslreasoner.visualisation.pi2graphviz.GraphvizVisualiser;
+import hu.bme.mit.inf.dslreasoner.workspace.FileSystemWorkspace;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Consumer;
+import java.util.function.Predicate;
+import modes3.Modes3Factory;
+import modes3.Modes3ModelRoot;
+import modes3.Modes3Package;
+import modes3.queries.Modes3Queries;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EEnum;
+import org.eclipse.emf.ecore.EEnumLiteral;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
+import org.eclipse.viatra.query.patternlanguage.emf.EMFPatternLanguageStandaloneSetup;
+import org.eclipse.viatra.query.runtime.api.IQuerySpecification;
+import org.eclipse.viatra.query.runtime.api.ViatraQueryEngineOptions;
+import org.eclipse.viatra.query.runtime.localsearch.matcher.integration.LocalSearchEMFBackendFactory;
+import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation;
+import org.eclipse.viatra.query.runtime.rete.matcher.ReteBackendFactory;
+import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor;
+import org.eclipse.xtend2.lib.StringConcatenation;
+import org.eclipse.xtext.xbase.lib.CollectionLiterals;
+import org.eclipse.xtext.xbase.lib.Exceptions;
+import org.eclipse.xtext.xbase.lib.ExclusiveRange;
+import org.eclipse.xtext.xbase.lib.Extension;
+import org.eclipse.xtext.xbase.lib.Functions.Function1;
+import org.eclipse.xtext.xbase.lib.InputOutput;
+import org.eclipse.xtext.xbase.lib.IterableExtensions;
+import org.eclipse.xtext.xbase.lib.ObjectExtensions;
+import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
+
+@FinalFieldsConstructor
+@SuppressWarnings("all")
+public class Modes3ModelGenerator {
+ private enum MonitoringQuery {
+ closeTrains,
+
+ misalignedTurnout;
+ }
+
+ private final Modes3ModelGenerator.MonitoringQuery monitoringQuery;
+
+ private final int modelSize;
+
+ private final Ecore2Logic ecore2Logic = new Ecore2Logic();
+
+ private final InstanceModel2Logic instanceModel2Logic = new InstanceModel2Logic();
+
+ private final Viatra2Logic viatra2Logic = new Viatra2Logic(this.ecore2Logic);
+
+ private final ViatraReasoner solver = new ViatraReasoner();
+
+ @Extension
+ private final LogicProblemBuilder _logicProblemBuilder = new LogicProblemBuilder();
+
+ public URI generate() {
+ try {
+ URI _xblockexpression = null;
+ {
+ final EcoreMetamodelDescriptor metamodel = Modes3ModelGenerator.createMetamodelDescriptor();
+ Ecore2LogicConfiguration _ecore2LogicConfiguration = new Ecore2LogicConfiguration();
+ final TracedOutput metamodelLogic = this.ecore2Logic.transformMetamodel(metamodel, _ecore2LogicConfiguration);
+ final Type segment = this.ecore2Logic.TypeofEClass(metamodelLogic.getTrace(), Modes3Package.eINSTANCE.getSegment());
+ final RelationDeclaration connectedTo = this.ecore2Logic.relationOfReference(metamodelLogic.getTrace(),
+ Modes3Package.eINSTANCE.getSegment_ConnectedTo());
+ final RelationDeclaration connectedToIndicator = ((EReferenceMapper_RelationsOverTypes_Trace) metamodelLogic.getTrace().referenceMapperTrace).indicators.get(
+ Modes3Package.eINSTANCE.getSegment_ConnectedTo());
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("oppositeReference ");
+ String _name = connectedTo.getName();
+ _builder.append(_name);
+ _builder.append(" ");
+ String _name_1 = connectedTo.getName();
+ _builder.append(_name_1);
+ final Function1 _function = (VariableContext it) -> {
+ Iff _xblockexpression_1 = null;
+ {
+ StringConcatenation _builder_1 = new StringConcatenation();
+ _builder_1.append("src");
+ final Variable src = it.addVar(_builder_1, segment);
+ StringConcatenation _builder_2 = new StringConcatenation();
+ _builder_2.append("trg");
+ final Variable trg = it.addVar(_builder_2, segment);
+ SymbolicValue _call = this._logicProblemBuilder.call(connectedToIndicator, src, trg);
+ SymbolicValue _call_1 = this._logicProblemBuilder.call(connectedToIndicator, trg, src);
+ _xblockexpression_1 = this._logicProblemBuilder.operator_spaceship(_call, _call_1);
+ }
+ return _xblockexpression_1;
+ };
+ final Assertion inverseAssertion = this._logicProblemBuilder.Assertion(_builder,
+ this._logicProblemBuilder.Forall(_function));
+ EList _assertions = metamodelLogic.getOutput().getAssertions();
+ _assertions.add(inverseAssertion);
+ InverseRelationAssertion _createInverseRelationAssertion = Ecore2logicannotationsFactory.eINSTANCE.createInverseRelationAssertion();
+ final Procedure1 _function_1 = (InverseRelationAssertion it) -> {
+ it.setTarget(inverseAssertion);
+ it.setInverseA(connectedTo);
+ it.setInverseB(connectedTo);
+ };
+ final InverseRelationAssertion inverseAnnotation = ObjectExtensions.operator_doubleArrow(_createInverseRelationAssertion, _function_1);
+ EList _annotations = metamodelLogic.getOutput().getAnnotations();
+ _annotations.add(inverseAnnotation);
+ final List initialModel = Modes3ModelGenerator.loadInitialModel();
+ final TracedOutput initialModelLogic = this.instanceModel2Logic.transform(metamodelLogic, initialModel);
+ final ViatraQuerySetDescriptor queries = this.loadQueries();
+ Viatra2LogicConfiguration _viatra2LogicConfiguration = new Viatra2LogicConfiguration();
+ final TracedOutput logic = this.viatra2Logic.transformQueries(queries, initialModelLogic, _viatra2LogicConfiguration);
+ ViatraReasonerConfiguration _viatraReasonerConfiguration = new ViatraReasonerConfiguration();
+ final Procedure1 _function_2 = (ViatraReasonerConfiguration it) -> {
+ it.runtimeLimit = 3600;
+ final Procedure1 _function_3 = (TypeScopes it_1) -> {
+ it_1.minNewElements = this.modelSize;
+ it_1.maxNewElements = this.modelSize;
+ final Procedure1