Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "VIATRA2/Examples/VTCL/GraphPattern"

< VIATRA2‎ | Examples‎ | VTCL
m (Pattern Matching Semantics)
m (Added outdated page notice)
 
(3 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 +
== Outdated page ==
 +
This page contains obsolete information about the VPM based VIATRA2 and preserved for archive purposes only.<br />
 +
The currently maintained wiki is available at http://wiki.eclipse.org/VIATRA
 +
 +
__TOC__
 +
 
== Overview: Graph patterns ==
 
== Overview: Graph patterns ==
  
 
=== Pattern Matching Semantics ===
 
=== Pattern Matching Semantics ===
  
'''NOTE: The shareable keyword and thus noninjective matches will be available starting from the next service release (expected by the end of June, 2009) of VIATRA2 R3.
 
This description serves as a documentation of the new features.'''
 
  
 
Patterns may be composed in VTCL a complex way by using the '''find''' construct.  
 
Patterns may be composed in VTCL a complex way by using the '''find''' construct.  
Line 14: Line 18:
 
a simple state machine formalism (with states as entities and transitions as relations), which potentially contain loop transitions (where the source and target state of a transition is the same).
 
a simple state machine formalism (with states as entities and transitions as relations), which potentially contain loop transitions (where the source and target state of a transition is the same).
  
<source lang="text">
 
// A and B should be different, i.e. loop transitions are not matched
 
pattern childPatternInj1(A, B) = {
 
  state(A);
 
  state.transition(T, A, B);
 
  state(B);
 
}
 
  
// A and B may be equal, loop transitions are matched
+
  // A and B should be different, i.e. loop transitions are not matched
shareable pattern childPatternSha1(A, B) = {
+
  pattern childPatternInj1(A, B) = {
  state(A);
+
    state(A);
  state.transition(T, A, B);
+
    state.transition(T, A, B);
  state(B);
+
    state(B);
}
+
  }
 +
 
 +
  // A and B may be equal, loop transitions are matched
 +
  shareable pattern childPatternSha1(A, B) = {
 +
    state(A);
 +
    state.transition(T, A, B);
 +
    state(B);
 +
  }
  
// Equivalent match set with childPatternInj1: A =/= B
+
  // Equivalent match set with childPatternInj1: A =/= B
pattern childPatternInj2(A, B) = {
+
  pattern childPatternInj2(A, B) = {
  find childPatternSha1(A, B);
+
    find childPatternSha1(A, B);
}
+
  }
  
// Equivalent match set with childPatternInj1: A =/= B
+
  // Equivalent match set with childPatternInj1: A =/= B
shareable pattern childPatternSha2(A, B) = {
+
  shareable pattern childPatternSha2(A, B) = {
  find childPatternSha1(A, B);
+
    find childPatternSha1(A, B);
  A =/= B;
+
    A =/= B;
}
+
  }
</source>
+
  
 
And now, let us present some more complex scenarios. As a general rule, the caller (parent) pattern  
 
And now, let us present some more complex scenarios. As a general rule, the caller (parent) pattern  
 
may prescribe additional injectivity constraints for the local variables.  
 
may prescribe additional injectivity constraints for the local variables.  
  
<source lang="text">
 
// Constraints: X =/= Y, Y =/Z, X =/= Z (thanks to the injectivity of the parent pattern)
 
pattern parentPattern1(X, Y, Z) = {
 
  find childPatternInj1(X, Y);
 
  find childPatternInj1(Y, Z);
 
}
 
  
// Constraints: X =/= Y, Y =/Z, X =/= Z (thanks to the injectivity of the parent pattern)
+
  // Constraints: X =/= Y, Y =/Z, X =/= Z (thanks to the injectivity of the parent pattern)
pattern parentPattern2(X, Y, Z) = {
+
  pattern parentPattern1(X, Y, Z) = {
  find childPatternInj1(X, Y);
+
    find childPatternInj1(X, Y);  
  find childPatternSha1(Y, Z);  
+
    find childPatternInj1(Y, Z);
}
+
  }
  
// Constraints: X =/= Y, Y =/Z, X =/= Z (thanks to the injectivity of the parent pattern)
+
  // Constraints: X =/= Y, Y =/Z, X =/= Z (thanks to the injectivity of the parent pattern)
pattern parentPattern3(X, Y, Z) = {
+
  pattern parentPattern2(X, Y, Z) = {
  find childPatternSha1(X, Y);
+
    find childPatternInj1(X, Y);
  find childPatternSha1(Y, Z);  
+
    find childPatternSha1(Y, Z);  
}
+
  }
  
// Constraints: X =/= Y, Y =/Z (thanks to the injectivity of the child pattern)
+
  // Constraints: X =/= Y, Y =/Z, X =/= Z (thanks to the injectivity of the parent pattern)
shareable pattern parentPattern4(X, Y, Z) = {
+
  pattern parentPattern3(X, Y, Z) = {
  find childPatternInj1(X, Y);
+
    find childPatternSha1(X, Y);
  find childPatternInj1(Y, Z);
+
    find childPatternSha1(Y, Z);  
}
+
  }
  
// Constraints: X =/= Y (thanks to the injectivity of the child pattern)
+
  // Constraints: X =/= Y, Y =/Z (thanks to the injectivity of the child pattern)
shareable pattern parentPattern5(X, Y, Z) = {
+
  shareable pattern parentPattern4(X, Y, Z) = {
  find childPatternInj1(X, Y);
+
    find childPatternInj1(X, Y);
  find childPatternSha1(Y, Z);
+
    find childPatternInj1(Y, Z);
}
+
  }
  
// Constraints: none
+
  // Constraints: X =/= Y (thanks to the injectivity of the child pattern)
shareable pattern parentPattern6(X, Y, Z) = {
+
  shareable pattern parentPattern5(X, Y, Z) = {
  find childPatternSha1(X, Y);
+
    find childPatternInj1(X, Y);
  find childPatternSha1(Y, Z);
+
    find childPatternSha1(Y, Z);
}
+
  }
</source>
+
  
--[[User:Varro.mit.bme.hu|Varro.mit.bme.hu]] 14:07, 25 May 2009 (UTC)
+
  // Constraints: none
 +
  shareable pattern parentPattern6(X, Y, Z) = {
 +
    find childPatternSha1(X, Y);
 +
    find childPatternSha1(Y, Z);
 +
  }

Latest revision as of 04:17, 30 April 2015

Outdated page

This page contains obsolete information about the VPM based VIATRA2 and preserved for archive purposes only.
The currently maintained wiki is available at http://wiki.eclipse.org/VIATRA

Overview: Graph patterns

Pattern Matching Semantics

Patterns may be composed in VTCL a complex way by using the find construct. Moreover, the injectivity of pattern matching can be further controlled by using the new shareable keyword as follows:

  • Injective pattern matching (default): the default behavior of the pattern matcher is that two pattern variables cannot be bound to the same value (i.e. element in the model space). Explicit pattern variable assignments (in the form of A=B) can enforce that the two variables do take the same value during pattern matching.
  • Shareable (or non-injective) pattern matching: the injectivity condition is not checked for local pattern variables (thus two variables may be bound to the same value) unless a non-injectvity constraint (in the form of A =/= B) is prescribed explicitly for a pair of variables.

The following examples highlight the semantic corner cases using of pattern composition and injective pattern matching. As a example, we use a simple state machine formalism (with states as entities and transitions as relations), which potentially contain loop transitions (where the source and target state of a transition is the same).


 // A and B should be different, i.e. loop transitions are not matched
 pattern childPatternInj1(A, B) = {
   state(A);
   state.transition(T, A, B);
   state(B);
 }
 // A and B may be equal, loop transitions are matched
 shareable pattern childPatternSha1(A, B) = {
   state(A);
   state.transition(T, A, B);
   state(B);
 }
 // Equivalent match set with childPatternInj1: A =/= B
 pattern childPatternInj2(A, B) = {
   find childPatternSha1(A, B);
 }
 // Equivalent match set with childPatternInj1: A =/= B
 shareable pattern childPatternSha2(A, B) = {
   find childPatternSha1(A, B);
   A =/= B;
 }

And now, let us present some more complex scenarios. As a general rule, the caller (parent) pattern may prescribe additional injectivity constraints for the local variables.


 // Constraints: X =/= Y, Y =/Z, X =/= Z (thanks to the injectivity of the parent pattern)
 pattern parentPattern1(X, Y, Z) = {
   find childPatternInj1(X, Y); 
   find childPatternInj1(Y, Z);
 }
 // Constraints: X =/= Y, Y =/Z, X =/= Z (thanks to the injectivity of the parent pattern)
 pattern parentPattern2(X, Y, Z) = {
   find childPatternInj1(X, Y);
   find childPatternSha1(Y, Z); 
 }
 // Constraints: X =/= Y, Y =/Z, X =/= Z (thanks to the injectivity of the parent pattern)
 pattern parentPattern3(X, Y, Z) = {
   find childPatternSha1(X, Y);
   find childPatternSha1(Y, Z); 
 }
 // Constraints: X =/= Y, Y =/Z (thanks to the injectivity of the child pattern)
 shareable pattern parentPattern4(X, Y, Z) = {
   find childPatternInj1(X, Y);
   find childPatternInj1(Y, Z);
 }
 // Constraints: X =/= Y (thanks to the injectivity of the child pattern)
 shareable pattern parentPattern5(X, Y, Z) = {
   find childPatternInj1(X, Y);
   find childPatternSha1(Y, Z);
 }
 // Constraints: none
 shareable pattern parentPattern6(X, Y, Z) = {
   find childPatternSha1(X, Y);
   find childPatternSha1(Y, Z);
 }

Back to the top