Rulebased Graph Repair^{†}^{†}thanks: This work is partly supported by the German Research Foundation (DFG), Grants HA 2936/42 and TA 2941/32 (MetaModeling and Graph Grammars: Generating Development Environments for Modeling Languages).
Abstract
Model repair is an essential topic in modeldriven engineering. Since models are suitably formalized as graphlike structures, we consider the problem of rulebased graph repair: Given a rule set and a graph constraint, try to construct a graph program based on the given set of rules, such that the application to any graph yields a graph satisfying the graph constraint. We show the existence of repair programs for specific constraints, and show the existence of rulebased repair programs for specific constraints compatible with the rule set.
1 Introduction
In modeldriven software engineering the primary artifacts are models, which have to be consistent w.r.t. a set of constraints (see e.g. [6]). These constraints can be specified by the Object Constraint Language (OCL) [14]. To increase the productivity of software development, it is necessary to automatically detect and resolve inconsistencies arising during the development process, called model repair (see, e.g. [13, 11, 12]). Since models can be represented as graphlike structures [3] and a subset of OCL constraints can be represented as graph conditions [17, 2], we investigate graph repair and rulebased graph repair.
Firstly, the problem of graph repair is considered: Given a graph constraint , we derive repairing sets from the constraint and try to construct a graph program using this rule set, called repair program. The repair program is constructed, such that the application to any graph yields a graph satisfying the graph constraint. Secondly, we consider the problem of rulebased graph repair: Given a set of rules and a constraint , try to construct a repair program based on the rule set , i.e., we allow to equip the rules of with the danglingedges operator, context, application conditions [7], and interface [15].
Rulebased repair problem
If a graph is generated by a grammar with rule set , then, after the application of an based program, the result can be generated by the grammar, too. This is interesting in contexts where the language is defined by a grammar, like triple graph grammars [19].
As main results, we show that, (1) there are repair programs for all “proper” conditions, and (2) there are rulebased repair programs for proper conditions provided that the given rule set is compatible with the rule sets of the original program.
We illustrate our approach by a small railroad system. {example}[railroad system]The specification of a railroad system is given in terms of graphs, rules (for moving the trains), and conditions. The basic items are waypoints, bidirectional tracks and trains. The static part of the system is given by a directed rail net graph: tracks are modeled by undirected edges (or a pair of directed edges, respectively) and trains are modeled by edges. Source and target nodes of a train edge encode the train’s position on the track and the direction of its movement.
The dynamic part of the system is specified by graph transformation rules. The rules model the movement and deletion of trains thereon. Application of the rule () means to find an occurrence of the lefthand side in the rail net graph and to replace it with the righthand side of the rule.
In the following, we consider the constraint below, meaning that there are no two trains occupying the same piece of track.
One may look for repair programs for the constraint NoTwo based on the rule sets , , and such that the application to any graph yields a graph satisfying the constraint .
The structure of the paper is as follows. In Section 2, we review the definitions of graphs, graph conditions, and graph programs. In Section 3, we introduce repair programs and show that there are repair programs for socalled proper conditions. In Section 4, we introduce rulebased programs, show that there are rulebased programs for transformations, and rulebased repair programs for proper conditions compatible with a rule set. In Section 5, we present some related concepts. In Section 6, we give a conclusion and mention some further work.
2 Preliminaries
In the following, we recall the definitions of directed, labelled graphs, graph conditions, rules and transformations [5], graph programs [8], and basic transformations [7].
A directed, labelled graph consists of a set of nodes and a set of edges where each edge is equipped with a source and a target node and where each node and edge is equipped with a label. {definition}[graphs & morphisms] A (directed, labelled) graph (over a label alphabet ) is a system where and are finite sets of nodes (or vertices) and edges, are total functions assigning source and target to each edge, and , are total labeling functions. If , then is the empty graph, denoted by . A graph is unlabelled if the label alphabet is a singleton. Given graphs and , a (graph) morphism consists of total functions and that preserve sources, targets, and labels, that is, , , , . The morphism is injective (surjective) if and are injective (surjective), and an isomorphism if it is injective and surjective. In the latter case, and are isomorphic, which is denoted by . An injective morphism is an inclusion morphism if and for all and all .
Drawing a graph, nodes are drawn as circles with their labels (if existent) inside, and edges are drawn as arrows with their labels (if existent) placed next to them. Arbitrary graph morphisms are drawn by usual arrows , injective graph morphisms are distinguished by .
Graph conditions are nested constructs, which can be represented as trees of morphisms equipped with quantifiers and Boolean connectives. Graph conditions and firstorder graph formulas are expressively equivalent [7].
[graph conditions]A (graph) condition over a graph is of the form (a) or where is a proper inclusion morphism^{1}^{1}1Without loss of generality, we may assume that for all inclusion morphisms in the condition, is a proper subgraph of . and is a condition over . (b) For a condition over , is a condition over . (c) For conditions ( for some finite index set ^{2}^{2}2In this paper, we consider graph conditions with finite index sets.) over , is a condition over . Conditions over the empty graph are called constraints. In the context of rules, conditions are called application conditions. Conditions built by (a) and (b) are called linear.
Any injective morphism satisfies . An injective morphism satisfies with if there exists an injective morphism such that and satisfies .
An injective morphism satisfies if does not satisfy , and satisfies if satisfies each (). We write if satisfies the condition (over ). A condition over is satisfiable if there is a morphism that satisfies . A graph satisfies a constraint , , if the morphism satisfies . A constraint is satisfiable if there is a graph that satisfies .
Two conditions and over are equivalent, denoted by , if for all graphs and all injective morphisms , iff . A condition implies a condition , denoted by , if for all graphs and all injective morphisms , implies .
Graph conditions may be written in a more compact form: , and , and . The expressions and are defined as usual. For an inclusion morphism in a condition, we just depict the codomain , if the domain can be unambiguously inferred.
The expression
[equivalences [15]]There are the following equivalences:
To simplify our reasoning, the repair program operates on a subset of conditions in normal form, socalled conditions with alternating quantifiers. {definition}[alternating quantifiers, proper and basic conditions] A linear condition of the form with , , ending with or is a condition with alternating quantifiers (ANF). Such a condition in ANF is proper if it ends with a condition or it is a condition of the form or . A proper condition is basic if it is of the form or .
The linear conditions and are proper. Moreover, are conditions with alternating quantifiers. and
By a normal form result for conditions [15], we obtain a normal form result for linear conditions saying that every linear condition effectively can be transformed into an equivalent condition with alternating quantifiers.
[normal form] For every linear condition, there exists an equivalent condition with alternating quantifiers. {proof}By a conjunctive normal form result in [15], every condition can be effectively transformed equivalent condition in normal form. The application of the rule as long as possible yields an equivalent condition with alternating quantifiers.
By definition, proper conditions are satisfiable. {fact}[proper conditions are satisfiable] Every proper condition is satisfiable. {proof}By Definition 2, a proper condition is , ends with a condition of the form , , or is of the form or and is not an isomorphism. Thus, it is satisfiable.
[nonproper satisfiable conditions] There are nonproper conditions that are satisfiable.
The nonproper condition can be transformed into a proper one: . By Fact 2, the condition is satisfiable.
Plain rules are specified by a pair of injective graph morphisms. They may be equipped with context, application conditions, and interfaces. For restricting the applicability of rules, the rules are equipped with a left application condition. By extending the rules with a context, it is possible to require an application condition over an extended lefthand side (see Example 4). By the interfaces, it becomes possible to hand over information between the transformation steps.
[rules and transformations] A plain rule consists of two inclusion morphisms and . The rule equipped with context is the rule where and are the pushout objects in the diagrams (1) and (2) below.
A rule with interfaces and consists of a plain rule with left application condition and two injective morphisms , , called the (left and right) interface morphisms. If both interfaces are empty, i.e., the domains of the interface morphisms are empty, we write . If additionally , we write or short . A direct transformation or short from to applying at consists of the following steps:

Select a match such that and .

Apply the plain rule^{4}^{4}4The application of a plain rule is as in the doublepushout approach [5]. at (possibly) yielding a comatch .

Unselect , i.e., define .

A triple with partial^{5}^{5}5A partial morphism is an injective morphism such that . morphism (called interface relation) is in the semantics of , denoted by , if there is an injective morphism such that and , , and . We write or short . Given graphs , and a finite set of rules, derives by if or there is a sequence of direct transformations with . In this case, we write or just .
If both interfaces of are empty, we write . If additionally , we write or short . A plain rule sometimes is denoted by where indexes in and refer to the corresponding nodes. Moreover, and denote the rules (selection of elements) and (unselection of selected elements), respectively, where denotes the identical rule . Additionally, abbreviates .
Consider the rule with the plain rule , and the interface morphisms , (see Figure 2).

Each injective morphism
With every transformation , a partial track morphism can be associated that “follows” the items of through the transformation: this morphism is undefined for all items in that are removed by , and maps all other items to the corresponding items in . {definition}[track morphism [16]]The track morphism from to is the partial morphism defined by if and undefined otherwise, where the morphisms and are the induced morphisms of and , respectively (see Figure 1). Given a transformation , is defined by induction on the length of the transformation: for an isomorphism and for . {example}For the direct transformation in Example 2, the track morphism is . For the direct inverse transformation , is partial.
Graph programs are made of sets of rules with interface, nondeterministic choice, sequential composition, aslongas possible iteration, and the trystatement. {definition}[graph programs] The set of (graph) programs with interface , , is defined inductively: Consider

The semantics of a program with interface , denoted by , is a set of triples such that, for all , ^{6}^{6}6For a partial morphism , and denote the domain and codomain of , respectively. and , and is defined as follows:
where with , for and . Two programs are equivalent, denoted , if . A program is terminating if the relation is terminating.
The statement is the identity element of sequential composition.
Consider a slightly modified example as in Example 2. For restricting the applicability of the plain rule to a fixed node, the rule is equipped with a right interface yielding the rule as well as with a left interface yielding the rule . By Definitions 2 and 2, , i.e., the middle diagram commutes (see Figure 3).
The construction “shifts” existential conditions over morphisms into a disjunction of existential application conditions.
[ [7]] There is a construction , such that the following holds. Let be condition over and . Then .
For rules with plain rule , the construction is as follows.
[] The application of Shift to the injective morphism and the condition yields the condition . The application of to and of the condition over yields the condition .
3 Graph repair
In this section, we define repair programs and look for repair programs for graph conditions.
A repair program for a constraint is a program such that, for every application to a graph, the resulting graph satisfies the constraint. More generally, a repair program for a condition over a graph is a program with interface such that for every triple in the semantics of , the composition of the interface relation and the comatch satisfies the condition.
[repair programs] A program is a repair program for a constraint if, for all transformations , . An preserving program ^{8}^{8}8A program is preserving if the dependency relation of the program is total. If, additionally, the codomain of is , the program is a program with interfaces or short program. For a rule set with interfaces , we speak of set. is a repair program for a condition over , if, for all triples , .
For the condition , the preserving program is a repair program for , where , with the interface morphisms . For the constraint , meaning that every node has a loop, the program is a repair program for .
A program for a condition is destructive, if it deletes the input graph and creates a graph satisfying the condition from the empty graph. In general, destructive programs are no repair programs for over , because it is not preserving.
The most significant point are the repair programs for the basic conditions and . Whenever we have repairing sets, we obtain a repair program for proper conditions.
[repairing sets]Let with . An set is repairing for if is a repair program for . An set is repairing for if (see Definition 3) is a repair program for .
For the condition from Example 3, the repairing set is .
[The danglingedges operator]
For nodedeleting rules , the dangling condition^{9}^{9}9The dangling condition for a rule and an injective morphism requires: “No edge in is incident to a node in ”. may be not satisfied. In this case, we consider the program that fixes a match for the rule, deletes the dangling edges, and afterwards applies the rule at the match. The program corresponds with the SPOway of rewriting [10]. The proceeding can be extended to sets of rules: For a rule set , .
In the following, we show that, for basic conditions and over , there are repairing sets and , respectively.
The rules in are increasing and of the form where and an application condition requiring that no larger subgraph of occurs and the shifted condition is satisfied. By the application condition, each rule can only be applied iff the condition is not satisfied and no other rule whose lefthand side includes and is larger can be applied.
The rules in are decreasing and of the form where such that, if the number of edges in is larger than the one in , they delete one edge and no node, and delete a node, otherwise. By , both rule sets do not contain identical rules.
The rule set can be used, e.g., for the repair program of the condition , the rule set for the condition (see Construction 3).
[basic repair] For basic conditions over , there are repairing sets with interfaces .
There are several repairing sets for a basic condition: We present two examples of repairing sets. The first one is quite intuitive, but, in general does not lead to a terminating and maximally preserving repair program. The second one is more complicated, but yields a terminating and maximally preserving repair program.
For () with , , the sets and are constructed as follows.

and