• No results found

Fge: Feature Graph Extraction Algorithm

In document Feature Model Synthesis (Page 96-101)

We now introduce the pseudocode for the generic FEATURE-GRAPH-EXTRACTION(FGE) in

FEATURE-GRAPH-EXTRACTION(ϕ : formula over F rooted in r, r ∈ F)

Find and remove all dead features 1 D= {f ∈ F | ϕ ∧ r → ¬f }

2 ϕ = ϕ[d 7→ 0]d∈D

Compute the implication graphG(V, E)

3 V = F \ D

4 E= {(u, v) ∈ V × V | ϕ ∧ u → v}

Compute strongly connected components 5 V0= {S ⊆ V | S is a SCC of G}

Make edges between SCCs creating a DAG 6 E0= {(u, v) ∈ V0× V0| u 6= v and

7 ∃u0∈ u, v0∈ v. (u0, v0) ∈ E} Compute the mutex graphM(V, Ex)

8 Ex= {{u, v} ⊆ V0| ∃u0∈ u, v0∈ v. ϕ ∧ u0→ ¬v0}

Compute mutex-groups

9 Gm= {{(f1, p), . . . , (fk, p)} | {f1, . . . , fk} is

10 a maximal clique in M and∀ fi.(fi, p) ∈ E0} Compute or-groups

11 Go= {{(f1, p), . . . , (fk, p)} | f10∨ · · · ∨ fk0is a prime implicate ofϕ ∧ p0where

12 p0∈ p and

13 ∀i ∈ {1, . . . , k}. fi0∈ fi∧ ( fi, p) ∈ E0} Compute xor-groups

14 Gx= Go∩ Gm

15 return FG(V0, E0, Ex,(Go\ Gx, Gx, Gm\ Gx))

Figure 5.2: Generic feature graph extraction algorithm, adapted from [ACSW12,

F, FGE constructs a feature graph as defined in Definition 5.2. This algorithm was

first introduced by Czarnecki and W ˛asowski and assumed the use of binary decision diagrams (BDDs) for reasoning [CW07]. Our contribution is the adaptation of this

algorithm to support reasoning with a SAT solver on input in conjunctive normal form (Section5.4) and disjunction normal form (Section5.5). We begin by describing each

step of the generic FGEalgorithm:

Lines1–2, Dead Features: The first step is the removal of dead features (Lines1–2). A dead feature inϕ is one that is false in all satisfying assignments of ϕ. Dead features do not contribute to the set of legal configurations and can always be added back to the model after synthesis.

Lines3–4, Implications: The second step is the construction of the implication graph,

defined below:

Definition 5.4. The implication graph (V, E) of a formula ϕ is a directed graph

where the vertices V are features and an edge(v1, v2) ∈ E exists if ϕ ∧ v1 → v2.

Line 5, And Groups: AND-groups are features that always co-occur together in any

satisfying assignment. We findAND-groups by identifying strongly connected compo-

nents (SCCs) in the implication graph. A SCCs is a group of vertices such that there exists a path from each vertex to all other vertices in the group. We lift the implication graph to sets of vertices, such that each SCC becomes a single vertex. (V0, E0) is an implication graph such that V0is a set of features from V , and an edge(u, v) ∈ E0exist if any feature in u implies a feature in v givenϕ. The resulting graph forms a DAG since implications are transitive and any cycle between features in the original implication graph is contained in a SCC. Note that from this line onward, a vertex contains a set of features.

Line8, Mutual Exclusions: We now move to identifying mutual exclusions by com-

puting the mutex graph, defined as:

Definition 5.5. The mutex graph (V, E) of a formula ϕ is an undirected graph

where vertices V are features and an edge (u, v) ∈ E exists if ϕ ∧ u → ¬v.

The mutex graph uses the SCCs as vertices and an edge (i.e., mutual exclusion)(u, v) exists between two vertices if any feature in u excludes a feature in v.

Line9, Mutex Groups: We use the mutex graph to computeMUTEX-groups by identify-

ing all maximal cliques in M . Each clique becomes the members of theMUTEX-group

and the common ancestor in the implication graph(V0, E0) becomes group’s parent p.

Lines11–12, Or Groups: We now finds OR-groups by computing prime implicates for

each variable p0. An implicate D of a propositional formulaϕ is a clause such that (i) D

itself is not a tautology, and (ii)ϕ → D is a tautology [ACSW12]. D is a prime implicate

iff it is minimal such that no literal can be removed from D without violating (ii).

Line14, Xor Groups: Having computed bothMUTEX-, andOR-groups in the previous

steps, XOR-groups are simply the intersection of both OR-groups and MUTEX-groups.

However, computingOR-groups is the most computationally complex step of the synthe-

sis algorithm[ACSW12,SRA+13]. All other steps that involve reasoning on ϕ reduce

to computing binary implications. We define an alternative XOR-group computation

that does not depend onOR-groups next.

Alternative Xor Group Computation: An alternative method of computingXOR-groups is

to check for eachMUTEX-group, given the group parent, if at least one group member

must be present in ϕ. This is equivalent to checking if ϕ ∧ p ∧ ¬f1 ∧ · · · ∧ ¬ fk is

inconsistent. Using this computation, the set of XOR-groups is alternatively defined

as:

G0x{( f1, p), . . . , (fk, p)} ∈ Gm| ϕ ∧ p0→ f10∨ · · · ∨ fk0

where p0∈ p and ∀i ∈ {1, . . . , k}, f0

i ∈ fi

©

(5.1)

Consistency Between the Inputϕ and the Produced Feature Graph FGEproduces

a feature graph that is weaker thanϕ, i.e., ϕ → [[FG]] given aFG produced by FGE.

We define the following theorem:

Theorem 5.2. Given an input formulaϕ with no dead variables and equivalent

variables (i.e., variables that would participate in anAND-group), FGEproduces a

feature graphFGthat is weaker than ϕ in the sense that ϕ → [[FG]].

Proof. We assume for this proof that there are no dead variables and no equivalent variables in the input formulaϕ. If there exists any dead or equivalent variables, then FGEproduces an isomorphic set of satisfying assignments. We prove that every element

• The vertices of a feature graph, V0, consists of the set of variables inϕ (Lines3 and5).

• Since there are no dead or equivalent variables inϕ, the set of edges, E0consists of edges from E with edges between variables inϕ by construction (Line6). It is clear that each edge(u, v) ∈ E satisfies ϕ → (u → v) (Line4).

• Similarly, for the set of excludes edges Ex,ϕ → (u → ¬v) for each undirected edge{u, v} ∈ Ex by construction (Line8).

• For each OR-group{( f1, p), . . . , (fk, p)} ∈ Go, f10∨ . . . ∨ fk0 is a prime implicante

of ϕ ∧ p0 where ∀i∈1..kfi0 ∈ fi (Line 11). This can be rewritten as ϕ → (p0 →

f10∨ . . . ∨ f0

k).

• For each MUTEX-group {( f1, p, . . . ,(fk, p)} ∈ Gx, ∀i, j∈{ f

1,... fk}; fi6= fjϕ → (fi → ¬ fj) holds since each MUTEX-group is a clique in the mutex graph that consists of

excludes edges from Ex (Line 9). We showed earlier than the set of excludes edges is entailed byϕ.

• Finally,XOR-groups consists of feature groups that are bothOR- andMUTEX-groups

(Line14). We proved earlier that both the set ofOR-groups andMUTEX-groups are

entailed byϕ.

Since ϕ entails the semantics of every element of the feature graphFG, thenϕ → [[FG]].

Furthermore, the feature graph produced by FGE is a maximal, transitively closed

feature graph. We define a maximal feature graph as the following:

Definition 5.6. A feature graphFG over F is maximal such that (i) no element can be added to the sets of child-parent edges E, excludes edges Em, andOR-,XOR-,

andMUTEX- groups (Go, Gx, Gm) without violatingϕ → [[FG]], and (ii) no group

can be moved from Go∪ Gm to Gx without violating the above implication.

Note that the above definition of maximality requires that the child-parent edges be transitively closed by condition (i). We can now state the following theorem:

Proof sketch. We sketch a proof that the produced feature graph is maximal by a contradiction argument. Assume that the feature graph produced by FGElacks an edge

(u, v) in the set of child-parent edges. We know that ϕ cannot entail u → v, otherwise the edge would have already been in the set of child-parent edges by Line4. Thus, any feature graph containing more edges must not be entailed byϕ. Such a feature graph would be unsound, contradicting condition (i) in Definition5.6.

The argument for the remaining components of the feature graph showing that all sets created by FGEare maximal is structured similarly.

In document Feature Model Synthesis (Page 96-101)