Tutorial

Configuration

Environment managment

Graph managment

Rules managment

Execution managment

Rewrite rules Management

In the formalism of pregraphs, a rewrite rule l → r is such that the left-hand side l is a graph and the right-hand side r is a graph. Roughly speaking, in the rewrite process and for all the rewrite rules defined, GPaR selects all the occurrences of l within g and rewrites g into g' by using r. In order to specify, for instance, the way new elements are going to be connected to existing elements of g, we have to identify specific parts of l and r.

  • l will be decomposed into an environment part and a cut part.
  • r will be decomposed into an environment part and a new part.
The cut part is the part to be removed, the new part is the part to be added whereas the environment part is intended to stay unchanged. It allows to connect the new part and define the states of the new part. A formal definition of a rewrite rule is available in "Parallel graph rewriting with overlapping rules" of Rachid Echahed and Aude Maignan ( CoRR, abs/1701.06790, 2017).
A valid rewrite rules must satisfies the following constraints :
  • If an element (a port or a node) is in the cut part then all the edges partially defined by this element have to be in the cut part;
  • If an element is in a new part it cannot appear in the environment part;
  • the environment part of r must be included in the environment part of l.

The strategy of GPaR is to represent l and r in a single drawing. Some of the constraints are automatically fulfilled by GPaR. To create the graph of a rule in the Rule Graph Window, we have to specify for each port and each node whereas it belongs to the Left Hand Side or the Right Hand Side. In a second step, 2 labels can be added : The label trigger cut action and the label trigger keep action.

  • Nodes, ports or edges of the Left Hand Side with a trigger cut action label belong to the cut part of l. In the tutorial, those elements are in red.
  • Nodes, ports or edges of the Left Hand Side without a trigger cut action label and without a trigger keep action label belong to the environment part of l. Those elements will be in purple.
  • Nodes, ports or edges of the Left Hand Side without a trigger cut action but with a trigger keep action label belong to the commune environment part of l and r. Those elements will be in black.
  • Nodes, ports or edges of the Right Hand Side cannot have labels and belong to the new part of r. Those elements will be in green.

Note that edges between two green vertices will be automatically green; edges between two red vertices will be automatically red. If an edge is created between a green vertex and a purple vertex then the purple vertex become automatically black (meaning that the trigger keep action is activated) and the edges will be blue. This new color is devoted to edges of the new part which are used to connect the new part with an existing part of the graph g. The vertex in black can be forced to be in purple in GPaR. This kind of manipulation is not suitable and must be done accurately.
Note that specific colors have been defined for, for instance, the items belonging to the Left Hand Side or for the items the Right Hand Side. All those colors can be redefined by the users in the preferences window.

Attributes and variables definition

The vertices and edges involving in a rewrite rule have potentially attributes. The attributes are defined by the user in the Environment Window.
Once an item (a vertex or an edge) is physically defined thanks to the Rule Graph Window, variables are allocated to this item. The name of a variable depends on the type (vertex or edge) and the color (Left Hand Side, Right Hand Side or in between) of the item. It also depends on the attribute it refers to.
  • We use the letter P to designate the item variables of the Left Hand Side.
  • We use the letter T to designate the item variables of the Left Hand Side.
  • We use the letter C to designate the variables of the blue edges (i.e. edges of the Right Hand Side such that one target belongs to the Left Hand Side).
  • We use the letter E to designate the variables of the edges which are not blue.
The variable is indexed by the id of the element.
Thus, the name of the variable corresponding to the attribute named attribute is of the form _{T,P,C}{E,}_. The name of the coordinate of a vertex is of the form {T,P}_{id of the element}.
If the variable x is an array, x[i] gives the value of the i-th element of the array x where i in {0,1,2...,x[]-1} when x[]describes the length of the array.
For example, if the attribute name is state, the variable name of an element with id 3 is :
  • state_P_3 for a vertex in the Left Hand Side,
  • state_T_3 for a vertex in the Right Hand Side
  • state_PE_3 for an edge in the Left Hand Side
  • state_TE_3 for an edge in the Right Hand Side
  • state_C_3 for a blue edge which connect a vertex of the Left Hand Side with a vertex of the Right Hand Side.

The coordinates of a vertex with id 3 are :
  • P_3 for a vertex in the Left Hand Side,
  • T_3 for a vertex in the Right Hand Side.
The coordinates variable is an array of size 3. P_3[i] gives the i-coordinates of the vertex 3 of the Left Hand Side graph where i is in {0,1,2}.

Match conditions

A match is defined in the theoretical paper as an injective graph homomorphism with an injective homomorphism over attributes. In GPaR we have a more flexible notion of match and the attributes involving in the matches have to be specified in the Rules Window. If the match is defined as an injective graph homomorphism and do not depend on the value of the attributes then the boxes node attribute to be matched and port matching attributes have to remain empty. At the opposite, if some attribute variables are needed for the matches, they have to be selected and must appear in the node or port boxes (see next section for more explanations). The mapping algorithm to find a graph l into a larger graph g consists in searching morphism from nodes to nodes, ports to ports and edges to edges between l graph and g graph.
The cost of this algorithm is the (#Nodes)! here #Nodes is the number of nodes of the large graph g (see Herb Sutter and Andrei Alexandrescu isomorphism sub graph method).
To reduce the time for searching subgraphs, it is advised to define an attribute which makes a partition of the nodes.
For each rule, the set of matches considered during the rewriting process is determined by the parallel rewrite relation. Two parallel rewrite relations have been implemented in GPaR, it is
  • full parallel rewrite relation : there g is rewritten in g' using all the possible matches.
  • parallel rewrite relation up to automorphisms : If a set of matches is obtained from one rewrite rule on a same set of nodes and ports then only one match of this set is used during the rewriting process. Confluence results can be found in the cited paper.
By default the full parallel rewrite relation is activated, check parallel rewrite relation up to automorphisms in the combo box to apply the parallel rewrite relation up to automorphisms. In order to deal with match overlapping, we follow the rewriting modulo approach (see, e.g. PetersonS81) where a rewrite step can be composed with an equivalence relation.

Rules Window

The rules are defined by clicking in the rules button to show the rule window. The rules settings window is as follow:

Rules Window


  • To select a rule, select the index of the rule (1).
  • To add a rule, click on the add button (2).
  • To copy a rule, click on the duplicate button (3).
  • To delete a rule, click on the delete button (4).
  • To clear all the rules, click on the clear button (5).
  • To select the parallel rewrite relation use the combo box (6).
  • To define the left and right hand side graphs, clicked on the ... button (7).
Buttons (8), (9), (10) and (11) are devoted to the designation of the attributes involving in the match process. If a node attribute involves in the match process, it must be added in the node attributes to be matched box (11). Select it in the combo box (8) and add it by clicking in the << button (9).
The button (10) allows to remove an attribute from the box (11). In the same way port attributes to be matched can be defined.
Buttons (12), (13) and (14) allow to define a restriction on matches. A mapping condition is an additional constraint on attributes which has to be fulfilled in order to select the match. The constraint is a function which has to return a boolean. When the Left Hand Side of a rule match a subgraph of g, the constraint defined in boxes (12) and (14) is tested. If it returns the boolean TRUE the subgraph is selected.
To add a mapping condition , define the function in the box (12) and click on << button (13). It appears in the mapping condition box (14). The box (12) become empty and you can add another condition.
Note that in a complexity point view, it is more efficient to introduce nodes and ports attributes to be matched instead of mapping conditions. Attributes to be matched create partition of vertices during the match process whereas mapping conditions correspond to additional tests after the match process.
the body of a mapping rule is as follow:
var isValid:=true;
return [isValid];
See the math formula section, for more explanations about writing a function.

Once the set of matches is found for each rewriting rules, the rules is performed on all the matches simultaneously. If some incompatibilities are detected at the execution, an error message appears and the process stops.
In the next section, additional explanations are given to define a rewriting rule.

Trigger actions on items

Example of rewriting rule in the Rule Graph Window


To define a rewriting rule, click on the button (7), the Rule Graph Window appears. The way to define graphically the Left and Right Hand Side graph is similar to the way to define the initial graph in graph window section.
The difference is that we define 2 graphs in the same window. So, to create nodes or ports, it is necessary to indicate in which graph, either Left Hand Side graph or Right Hand Side graph, the vertex has to be added. Moreover trigger labels have to be specified.
Trigger labels have been defined in the Rewrite rules Management section and is sum up in tabular form :
add trigger cut action the element (vertex or edge) will be deleted during the rewriting process
delete trigger cut action the previous action is deleted
add trigger keep action the element (vertex or edge) must be kept during the parallel rewriting process
delete trigger keep action the previous action is deleted

The colors of the remove/keep trigger action are defined in the preferences window.

Note that when an edge is created between a vertex of the Left Hand Side and a vertex of the Right Hand Side, a trigger keep action is added automatically to the vertex of the Left Hand Side.
If a graph item must be kept by the application of one rewriting rule and must be deleted by the application of another rewriting rule then an error occurs at execution.
Note that the user can remove a trigger keep action which has been activated automatically, but if, for instance, the vertex is deleted during the application of a rule, all the edges connected to the vertex will be connected to nothing without any error.
In the popup menu of each elements of the rewriting rule, some trigger actions on attributes can be defined. Those functionally will be explained in the next section.

Trigger actions on states

If an item belongs to the Left Hand Side and one of its attributes is an attribute to be matched then the value of this attribute has to be specified. Select the attribute in the combo box (1), its type appears in box (2) and its default value appears in the box (3), change this value into the suitable value.
Nodes coordinates and attributes of the Right Hand side have to be defined. If it is not be done, the coordinates and the attributes of those new nodes will be the default values (the coordinate (0,0,0) is the default coordinate). Attributes of new items often depend on the state of the environmental parts. By hence, the state of the items of the Right Hand Side has to be defined thanks to a function and this function has to be computed during the rewriting process. In GPaR, it corresponds to a trigger action.

Example of trigger action in the vertex window


To set an attribute, click on the graph element and the vertex or edge window will appear. Select the attribute to modify on the trigger action combo box button (4) and define the new value in area (5) by using the variable name definition.
For example, to set the coordinate of the node T_0 to the middle of the segment [P_0,P_1], select T_0 form the trigger action combo box attribute and set the body of the rule in section 2:
return [0.5*(P_0+P_1)];
See the math formula section, for more explanations about defining a function.