Hypergraph Analysis and Visualization in PythonThe hatvis toolbox

Chapter 10
Combinatorial problem solving

Many planning and design questions are classical problems on hypergraphs in disguise: which resources must be monitored so that every activity is observed (a hitting set), which activities cover all resources (a set cover), which groups can run in parallel (a matching), which tables can be joined efficiently (acyclicity and join trees), which products can be made from the available parts and at what cost (reachability and shortest paths in a directed hypergraph), and which engineering specifications should be developed to satisfy the customers (quality function deployment). This chapter states these problems, their integer-programming formulations, the greedy and exact algorithms of hatvis, and the structural results (duality, Berge’s transversal theorem, the join-tree characterization) that make them tractable or explain why they are hard. The examples come from the manufacturing space, a database schema, a wire-harness assembly, and the electric-car house of quality.

10.1 Problem and idea

A graph models a requirement on pairs: an edge must be covered by one of its endpoints, two adjacent vertices must get different colors, a path passes through pairs. Real requirements often involve groups. An activity is observed if any one of its resources carries a sensor; an assembly step can start only when all its parts are available; a requirement of a product is met by some combination of specifications; a database query joins several tables that share attributes. Encoding these as graphs either loses the group (a set cover becomes a vertex cover of the clique expansion, which is a different and usually larger problem) or needs auxiliary constructions that hide the structure.

The idea of this chapter is to formulate the problems directly on the hypergraph, where they have short integer programs and well-understood theory. Two dualities run through the chapter (fig. 10.1). The hitting set of H is the set cover of its dual H∗, so every covering algorithm solves both; and for a simple hypergraph the family of minimal transversals determines the hypergraph again, Tr(Tr(H)) = H [16], so the “what must I monitor” and “what can fail” questions are two views of one object.

Figure 10.1

Figure 10.1. Hitting set and set cover are dual problems. Left: a single vertex c meets every hyperedge, so the minimum hitting set has size one. Right: covering all vertices by hyperedges needs all three. A hitting set of H is a set cover of the dual hypergraph H∗, whose hyperedges are the vertex memberships.

10.2 Theory

10.2.1 Covering and hitting

A set cover of H is a family of hyperedges whose union contains every vertex (of a given universe U, by default all non-isolated vertices); a hitting set or transversal is a set of vertices that meets every hyperedge. With costs ce and ci, the minimum-cost versions are the integer programs

set cover: min ⁡ ∑ ecexes.t.∑ e∋ixe ≥1∀ ⁡i ∈U,xe ∈{0,1}, (10.1) hitting set: min ⁡ ∑ iciyis.t.∑ i∈eyi ≥1∀ ⁡e ∈E,yi ∈{0,1}. (10.2)

The constraint matrix of one is the transpose of the other, which is the duality of fig. 10.1. Both are NP-hard [107], but integer programs of a few thousand variables are solved to optimality in seconds by branch and bound; hatvis passes them to the HiGHS solver [28] through scipy.optimize.milp. The greedy algorithm repeatedly takes the hyperedge with the smallest cost per newly covered vertex, ce∕|e ∩U|, until everything is covered; Chvátal [130] proved that its cost is at most H(max ⁡ e|e|) ≤1 + ln ⁡ max ⁡ e|e| times the optimum, where H(k) = ∑ ⁡ j≤k1∕j. The greedy hitting set is the greedy set cover of the dual.

Minimal transversals. A transversal is minimal if no proper subset is a transversal. The family of all minimal transversals is the transversal (or blocker) hypergraph Tr(H), and for a simple hypergraph Tr(Tr(H)) = H [16]. Minimal transversals answer “what are all the irredundant ways to monitor the system” and, read the other way, “what are all the minimal sets of failures that disable every activity”. Berge’s sequential algorithm processes the hyperedges one at a time,

Tr(e1,…,ek) = min ⁡ {T ∪{v}: T ∈Tr(e1,… ⁡ ,ek−1),v ∈ek },
(10.3)

where min ⁡ keeps the inclusion-minimal sets. The output can be exponential in the input, so the right measure of efficiency is the time per output set; Eiter and Gottlob [131] showed that enumerating minimal transversals is equivalent to a family of problems in logic, databases, and artificial intelligence, and Fredman and Khachiyan [132] gave an algorithm that is quasi-polynomial in the combined size of input and output. hatvis implements Berge’s method with an optional size limit, adequate for subsystems of moderate size.

10.2.2 Matching and coloring

A matching is a set of pairwise disjoint hyperedges; a maximum-weight matching, max ⁡ ∑ ⁡ ewexe subject to ∑ ⁡ e∋ixe ≤1, selects the largest set of groups that can act simultaneously when every vertex can take part in only one group, such as a schedule of activities that do not share resources. A weak (proper) coloring assigns colors to vertices so that no hyperedge of size at least two is monochromatic; a strong coloring requires all members of every hyperedge to have different colors, which is a proper coloring of the clique expansion. A hypergraph with a weak 2-coloring has Property B; deciding Property B is the NP-complete set splitting problem [133]. Strong colorings assign time slots to the vertices so that no group has two members in the same slot; weak 2-colorings split a set of items into two parts so that every group is represented in both. hatvis provides greedy colorings of both kinds and a backtracking decision procedure for Property B on small hypergraphs.

10.2.3 Acyclicity and join trees

A hypergraph is α-acyclic if it can be reduced to nothing (or to a single hyperedge) by the GYO reduction [134]: repeatedly delete a vertex that belongs to exactly one hyperedge (an ear vertex), and delete a hyperedge that is empty or contained in another hyperedge. The order of the deletions does not affect the outcome, and Tarjan and Yannakakis [135] gave a linear-time test. Acyclicity has an equivalent characterization by join trees: a tree on the hyperedges is a join tree if, for every vertex, the hyperedges that contain it form a connected subtree (the running intersection property). A hypergraph has a join tree if and only if it is α-acyclic, and the join trees are exactly the maximum-weight spanning trees of the intersection graph of the hyperedges with weights |e ∩f| [136, 137]. hatvis computes a join tree in this way and rejects cyclic inputs.

Acyclicity was identified in database theory as the property of a relational schema that makes queries efficient [138]: the tables are the hyperedges, the attributes the vertices, and for an acyclic schema a join of all tables can be computed by semijoins along the join tree in time polynomial in the size of input and output [139], while for cyclic schemas the intermediate results can blow up. Fagin [140] defined a hierarchy of stronger notions (β-, γ-, and Berge-acyclicity). The same structure appears in probabilistic inference, where junction trees of graphical models are join trees of the hypergraph of cliques, and in constraint satisfaction.

Two further properties are tested by hatvis: conformality (section 2.2.4) and the Helly property, which holds when every pairwise intersecting family of hyperedges has a common vertex. A hypergraph is conformal exactly when its dual has the Helly property, and the Helly property can be tested with the triangle criterion of Berge and Duchet in O(n3m) time [16].

10.2.4 Directed hypergraphs: reachability and hyperpaths

A directed hypergraph whose hyperarcs have a single head vertex is a set of B-arcs, and it models AND-dependencies: the head can be produced only when every tail vertex is available [33, 34]. A vertex is B-reachable from a set S of sources if it is in S or is the head of a hyperarc all of whose tail vertices are B-reachable. The B-visit computes the reachable set in linear time by keeping, for every hyperarc, the number of tail vertices not yet reached and firing the hyperarc when the counter drops to zero. A B-hyperpath to a vertex is the set of hyperarcs used to reach it.

With a weight we on every hyperarc, Gallo et al. [33] define the cost of reaching a head vertex v through hyperarc e as

d(v) = min ⁡ e:v∈H(e) (we + F ({d(t) : t ∈T(e)} ) ),d(s) = 0(s ∈S),
(10.4)

with F = ∑ ⁡ (the total effort of all steps needed, counting every sub-assembly) or F = max ⁡ (the completion time when independent preparations run in parallel, the makespan). Both are computed by a Dijkstra-like procedure (the SBT procedure of Gallo et al.) that settles the vertices in order of increasing d and evaluates a hyperarc once all its tail vertices are settled. The additive cost counts a sub-assembly once for every use, so it is exact for tree-shaped assemblies and an upper bound when a part feeds several branches. Directed hypergraphs of this kind describe assembly and disassembly sequences, chemical reaction networks [141], Horn-clause inference, and the association rules of section 8.2.2.

10.2.5 Quality function deployment

The house of quality of section 5.2.6 relates customer requirements i with importances λi to design parameters (engineering specifications) k by relationship scores aik ∈{0,1,3,9}, and its roof records correlations ckl between parameters [80, 82]. The classical evaluation computes the technical importance

tk = ∑ iλiaik
(10.5)

and develops the parameters in decreasing order of tk. Abonyi and Czvetkó [3] pointed out that this ranking ignores costs and the fact that parameters act in combination, and proposed three complementary formulations.

Mixed-integer selection. With a binary decision uk for every parameter, the roof spreads the effect of a developed parameter to its correlated ones, u~l = ∑ ⁡ kclkuk (with ckk = 1), and the satisfaction of requirement i is yi = ∑ ⁡ lailu~l. The selection maximizes the total satisfaction under a budget C and a limit K on the number of parameters,

max ⁡ u∈{0,1}m ∑ iyis.t.∑ kckuk ≤C,∑ kuk ≤K,yi ≥λi(optional),
(10.6)

or minimizes the cost subject to minimum satisfaction levels.

Minimum-cost assignment. A flow network source → parameters → requirements → sink, with capacity 1 and cost ck on the arc into parameter k, an arc from k to i whenever aik > 0, and demand di (default 1) at requirement i, selects the cheapest set of parameters that serves every requirement, each parameter serving one requirement. The model guarantees coverage but treats requirement and parameter in pairs: it cannot reward a parameter that serves several requirements at once.

The hypergraph view. With the requirements as vertices and the parameters as hyperedges (eq. (5.6)), the parameters can be ranked by a hyperedge centrality such as the node–edge eigenvector centrality of section 6.2.5, which rewards a parameter for serving important requirements that are also served by other important parameters, i.e. for its role in the group structure of the house of quality. Abonyi and Czvetkó also defined a generalized hypergraph whose hyperedges may contain other hyperedges: the hyperedge of parameter k contains the requirements it influences and the parameters it is correlated with, so that direct and indirect effects can be analyzed in one incidence matrix of size (|V |+ |E|) ×|E|.

In a nutshell: Combinatorial problems on hypergraphs

  • Set cover (10.1) and hitting set (10.2) are dual (hitting set of H = set cover of H∗); exact by integer programming (HiGHS), greedy within 1 + ln ⁡ max ⁡ |e| of the optimum.
  • Minimal transversals by Berge’s algorithm (10.3); Tr(Tr(H)) = H for simple H; output-sensitive complexity.
  • Matching (disjoint groups), weak and strong coloring, Property B (NP-complete).
  • α-acyclicity by GYO reduction; join tree = maximum spanning tree of the intersection graph iff acyclic; efficient joins; conformality and Helly property.
  • Directed hypergraphs: B-reachability (linear), minimum hyperpaths with sum or max cost (10.4).
  • QFD: technical importance (10.5), MILP selection (10.6), min-cost assignment, hypergraph centrality, generalized hypergraph with correlations.

10.3 Using it in hatvis

problems.hitting_set(H, costs=None)

Returns

a minimum-cost hitting set (list of vertices) by integer programming.

Related

greedy_hitting_set, set_cover(H, universe, costs), greedy_set_cover, minimal_transversals(H, max_size), transversal_hypergraph, maximum_matching(H, weighted), greedy_coloring(H, strong), is_two_colorable, gyo_reduction, is_alpha_acyclic, join_tree, is_conformal, has_helly_property, b_reachable(D, sources), shortest_hyperpaths(D, sources, cost="sum"|"max").

qfd.qfd_select(relationship, costs, correlation=None, requirement=None, budget=None, max_actions=None, objective="max_satisfaction")

Returns

a table with the decision, cost, and contribution of every parameter; .attrs holds the total satisfaction, the total cost, and the satisfaction vector.

Related

qfd_min_cost_assignment(relationship, costs, demand), technical_importance, qfd_hypergraph, correlation_hypergraph, generalized_qfd_hypergraph, plot_house_of_quality.

10.4 Examples

Minimal monitoring sets. The physical resources of the wire-harness space (operators, robots, the AGV, and the crimping machines) are restricted to the activities in which they take part, and two questions are asked: which resources must carry a sensor so that every activity involves a monitored resource (a hitting set), and which activities must be observed so that every resource is seen (a set cover).

hs_exact = problems.hitting_set(people) 
hs_greedy = problems.greedy_hitting_set(people) 
sc_exact = problems.set_cover(people) 
sc_greedy = problems.greedy_set_cover(people)
   

The minimum hitting set has nine resources: six operators (O2–O7), the robots R2 and R5, and the AGV (fig. 10.2); the greedy rule also finds nine. Every member of this set is forced: each of them is the only physical resource of at least one activity (the AGV of the six transport steps, each operator of a manual handling or assembly step, and R2 and R5 of the handling steps into the stations they operate), so any hitting set must contain them, and together they already meet every activity. The operator O1 is not needed, because every activity of O1 also involves the AGV. The minimum set cover needs nine activities, the greedy one ten, within Chvátal’s bound. Restricted to the first crimping and assembly stations of line 1, the subsystem has exactly two minimal transversals, {M1,O3} and {O2,O3}: the assembly operator O3 must be monitored in any case, and the crimping station can be monitored either at its machine or at its operator. Read as failure sets, these are also the two minimal combinations of failures that would stop every activity of the subsystem.

Figure 10.2

Figure 10.2. A minimum hitting set of the activities of the physical resources of the wire-harness space: the nine resources in orange meet every activity.

Open in ColabExample plot_31_sensor_placement.py in the gallery

Acyclic schemas and join trees. A small order-processing schema with four tables is a hypergraph whose hyperedges are the tables and whose vertices are the attributes.

schema = hv.Hypergraph({"Orders": ["order", "customer", "date"], "Lines": ["order", "item", "qty"], 
                        "Items": ["item", "supplier", "price"], "Customers": ["customer", "city"]}) 
cycle = hv.Hypergraph({"R": ["a", "b"], "S": ["b", "c"], "T": ["a", "c"]}) 
for H in (schema, cycle): 
    ok, steps = problems.gyo_reduction(H) 
    print(f"alpha-acyclic: {ok}; first steps: {steps[:4]}") 
tree = problems.join_tree(schema)
   

The GYO reduction starts by deleting the ear attributes date, qty, supplier, and price, each of which occurs in a single table, then removes the tables that have become subsets of others, and continues until nothing is left: the schema is α-acyclic. The join tree links Customers–Orders through customer, Orders–Lines through order, and Lines–Items through item (fig. 10.3); every attribute occurs in a connected part of the tree, so the four tables can be joined by three semijoin passes along it. The three tables R(a,b), S(b,c), T(a,c), in contrast, have no ear vertex and no contained table; the reduction stops immediately, and the 3-cycle is the smallest cyclic schema.

Figure 10.3

Figure 10.3. A database schema as a hypergraph (left) and its join tree (right), with the shared attributes on the links.

Open in ColabExample plot_32_acyclicity.py in the gallery

Assembly feasibility and cost. The wire-harness process is reduced to eight steps, each a hyperarc from its input parts to its output: cutting wires, crimping a cut wire with a terminal, mounting a seal in a housing to obtain a connector, inserting the crimped wire into the connector, taping, routing on a jig, and testing; the finished harness can alternatively be bought from a supplier. The weights are the step durations.

D = hv.DirectedHypergraph({ 
    "cut wires":      (["wire"], ["cut wire"]), 
    "crimp":          (["cut wire", "terminal"], ["crimped wire"]), 
    "mount housing":  (["housing", "seal"], ["connector"]), 
    "insert":         (["crimped wire", "connector"], ["sub-harness"]), 
    "tape":           (["sub-harness", "tape"], ["taped sub-harness"]), 
    "route":          (["taped sub-harness", "jig"], ["harness"]), 
    "buy harness":    (["supplier"], ["harness"]), 
    "test":           (["harness", "tester"], ["tested harness"]), 
}, weights=[2, 3, 3, 4, 2, 5, 30, 3]) 
available = ["wire", "terminal", "housing", "seal", "tape", "jig", "tester"] 
print("producible:", sorted(problems.b_reachable(D, available) - set(available))) 
cost = pd.DataFrame({"sum": problems.shortest_hyperpaths(D, available, "sum"), 
                     "max": problems.shortest_hyperpaths(D, available, "max")})
   

From the available parts all intermediate and final products are B-reachable, but the supplier is not available, so the purchase arc never fires. The minimum hyperpath costs of fig. 10.4 distinguish total effort and makespan. The sub-harness needs 12 time units of work in total (cutting 2, crimping 3, mounting 3, inserting 4), but only 9 if the connector is mounted while the wire is cut and crimped; the tested harness needs 22 units of work and can be completed in 19. The difference is exactly the parallelism of the AND-dependency, which a path in a graph cannot express: in a graph, reaching the sub-harness through the crimped wire would ignore that the connector must also be there.

Figure 10.4

Figure 10.4. Minimum B-hyperpath costs of the products of a simplified wire-harness assembly: total effort (sum over all steps) and makespan with parallel preparation (max over the inputs).

Open in ColabExample plot_33_directed_assembly.py in the gallery

Which specifications should be developed? The three QFD formulations are applied to the electric-car house of quality of section 5.4 with illustrative development costs (4, 3, 3, 2, 3, 4, 1, 1, 2, 1, 1 for ES1–ES11); the satisfaction of a selection is measured, for comparability, as the sum of its relationship scores.

lp = hv.qfd.qfd_select(R, costs=costs, budget=12, max_actions=6) 
flow = hv.qfd.qfd_min_cost_assignment(R, costs=costs) 
_, edge_c = hv.node_edge_eigenvector(q.hypergraph, "linear") 
n_lp = int(lp["selected"].sum())                     # as many as the LP selected 
hyper = edge_c.sort_values(ascending=False).index[:n_lp]
   

Table 10.1. Three readings of the electric-car house of quality with illustrative costs: the selected specifications, their total cost, and their total relationship score.
Model

selected specifications

cost score
MILP, budget 12, at most 6

ES4, ES5, ES6, ES7, ES10, ES11

12 101
min-cost assignment

ES1, ES4, ES5, ES7, ES8, ES9, ES10, ES11

15 117
hypergraph centrality (top 6)

ES1, ES5, ES6, ES7, ES10, ES11

14 111

Table 10.1 shows how the models answer different questions. The technical importance (10.5) ranks sensors and algorithms first (103 each), followed by LiDAR (95) and GPS navigation (72), without regard to cost. The MILP spends the budget of 12 on the cheap and broadly useful specifications: the vehicle classification, airbags, and the restraint system cost 1 each, grid charging 2, and sensors and algorithms take the rest; LiDAR does not fit. The min-cost assignment must give every requirement its own specification and therefore buys eight, including the number of seats for boot space and the brakes for the braking requirement, at cost 15; it covers every requirement with a dedicated specification, which the MILP does not guarantee. The hypergraph centrality ranks LiDAR, sensors, and algorithms highest because they jointly serve the two most important requirements, and its top six reach a score of 111 at cost 14, more than the MILP but over its budget. None of the three is “the” answer: the MILP is the right tool when the budget is fixed, the assignment when every requirement must have an owner, and the hypergraph view when the question is which specifications form the core of the design. Figure 10.5 shows the house of quality drawn by hatvis with an illustrative roof.

Figure 10.5

Figure 10.5. The electric-car house of quality drawn by plot_house_of_quality: relationship symbols (filled circle 9, circle 3, triangle 1), importance ratings, technical importances, and an illustrative correlation roof.

Open in ColabExample plot_34_qfd_optimization.py in the gallery

10.5 Further reading

Berge [16] covers transversals, matchings, colorings, and the Helly property; Chvátal [130] analyzes the greedy set cover, and Eiter and Gottlob [131] and Fredman and Khachiyan [132] the enumeration of minimal transversals. Beeri et al. [138], Fagin [140], and Tarjan and Yannakakis [135] are the classical references on acyclic hypergraphs, and Maier [137] treats join trees in the context of relational databases. Gallo et al. [33] introduce directed hypergraphs, B-reachability, and hyperpaths, and Ausiello and Laura [34] survey the algorithms. The hypergraph and network-flow formulations of QFD are developed in [3]; Chan and Wu [81] review the QFD literature.