Skip to content

[Model] MinimumWeightAndOrGraph #933

@isPANN

Description

@isPANN

Motivation

MINIMUM WEIGHT AND/OR GRAPH SOLUTION (MS16) from Garey & Johnson, A12. Given a DAG with a single source, where each non-leaf vertex is labeled AND or OR, and arcs have positive integer weights, find a minimum-weight solution subgraph rooted at the source. An AND vertex requires all its children in the solution; an OR vertex requires at least one child. This models AI game tree search (AND/OR trees), the AO* algorithm, and hierarchical planning. NP-hard even with unit weights (Sahni 1974). Polynomial for rooted trees via dynamic programming.

Definition

Name: MinimumWeightAndOrGraph
Reference: Garey & Johnson, Computers and Intractability, A12 MS16; Sahni 1974

Mathematical definition:

INSTANCE: A directed acyclic graph G = (V, A) with a single source s (a vertex with in-degree 0 from which all other vertices are reachable), a function f: V \ Leaves → {AND, OR} labeling each non-leaf vertex, and a weight function w: A → Z⁺ assigning positive integer weights to arcs.
OBJECTIVE: Find a solution subgraph G' = (V', A') of G of minimum total arc weight such that:

  1. s ∈ V';
  2. For every AND vertex v ∈ V', all children of v (and the corresponding arcs) are in G';
  3. For every OR vertex v ∈ V', at least one child of v (and the corresponding arc) is in G';
  4. Every non-leaf vertex in V' satisfies its AND/OR constraint.

The objective value is Min(Σ_{a ∈ A'} w(a)).

Variables

  • Count: m = |A| (one per arc)
  • Per-variable domain: {0, 1}
  • Meaning: Whether each arc is included in the solution subgraph. The source must be solved (its AND/OR constraint satisfied), propagating recursively to all included non-leaf vertices.

Schema

Type name: MinimumWeightAndOrGraph
Variants: none

Field Type Description
num_vertices usize Number of vertices
arcs Vec<(usize, usize)> Directed arcs A, each (u, v) where u is parent, v is child
source usize The single source vertex s
gate_types Vec<Option<bool>> Gate type for each vertex: Some(true) = AND, Some(false) = OR, None = leaf
arc_weights Vec<i32> Positive integer weight for each arc (parallel to arcs vector)

Complexity

  • NP-hardness: NP-hard even with unit weights (Sahni 1974). The NP-completeness proof reduces from 3-SATISFIABILITY (see npcomplete.owu.edu).
  • Best known exact algorithm: O*(2^num_arcs) by brute-force. A smarter approach enumerates choices for each OR vertex: O*(∏ out-degree of OR vertices).
  • Complexity string: "2^num_arcs"
  • Polynomial special cases: Rooted trees (O(|V|) via bottom-up DP). OR-only graphs reduce to shortest path.

Extra Remark

Full book text:

INSTANCE: Directed acyclic graph G = (V, A) with a designated source vertex s having in-degree 0, a labeling function f: V \ Leaves → {AND, OR}, a weight function w: A → Z⁺, positive integer K.
QUESTION: Is there a solution subgraph G' = (V', A') with s ∈ V' satisfying AND/OR constraints and Σ_{a ∈ A'} w(a) ≤ K?

Reference: [Sahni, 1974].
Comment: NP-complete even with unit weights.

Note: The original G&J formulation is a decision problem with bound K. We use the equivalent optimization formulation: minimize total arc weight.

How to solve

  • It can be solved by (existing) bruteforce. (Enumerate choices for each OR vertex; AND constraints are then deterministic. Evaluate total weight; return minimum.)
  • It can be solved by reducing to integer programming.
  • Other:

Reduction Rule Crossref

Example Instance

Input:
DAG with V = {v0, v1, v2, v3, v4, v5, v6} (7 vertices), source s = v0.

Gate types:

  • v0: AND (source — must include both children)
  • v1: OR (choose one child)
  • v2: OR (choose one child)
  • v3, v4, v5, v6: LEAF

Arcs with weights:

  • (v0, v1): w=1, (v0, v2): w=2
  • (v1, v3): w=3, (v1, v4): w=1
  • (v2, v5): w=4, (v2, v6): w=2

Since v0 is AND, both arcs (v0,v1) and (v0,v2) are always included (cost 1+2=3). The choices are:

  • OR at v1: pick v3 (cost +3) or v4 (cost +1)
  • OR at v2: pick v5 (cost +4) or v6 (cost +2)

All 4 feasible solutions:

  1. v1→v4, v2→v6: total = 1+2+1+2 = 6 (optimal)
  2. v1→v3, v2→v6: total = 1+2+3+2 = 8
  3. v1→v4, v2→v5: total = 1+2+1+4 = 8
  4. v1→v3, v2→v5: total = 1+2+3+4 = 10

Optimal solution: arcs {(v0,v1), (v0,v2), (v1,v4), (v2,v6)}, total weight = 6. The optimal strategy is to pick the cheapest child at each OR gate.

Expected Outcome

Optimal value: Min(6) — the minimum total arc weight is 6. There are 4 feasible solutions with 3 distinct weight values (6, 8, 10). The two independent OR choices (v1 and v2) multiply to give 2×2 = 4 solutions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    GoodAn issue passed all checks.modelA model problem to be implemented.

    Type

    No type

    Projects

    Status

    Ready

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions