Skip to content

[Model] Betweenness #839

@isPANN

Description

@isPANN

Motivation

BETWEENNESS (P313) from Garey & Johnson, A12 MS1. A classical NP-complete problem in order theory, asking whether a set of elements can be linearly ordered so that specified betweenness constraints are satisfied. Has applications in computational biology (gene mapping).

Associated rules:

Definition

Name: Betweenness
Reference: Garey & Johnson, Computers and Intractability, A12 MS1

Mathematical definition:

INSTANCE: Finite set A, collection C of ordered triples (a,b,c) of distinct elements from A.
QUESTION: Is there a one-to-one function f: A→{1,2,...,|A|} such that for each (a,b,c) ∈ C, we have either f(a) < f(b) < f(c) or f(c) < f(b) < f(a)?

Variables

  • Count: |A| (one variable per element, representing its position in the linear order)
  • Per-variable domain: {0, 1, ..., |A|-1} — a permutation of positions
  • Meaning: x_i = k means element a_i is placed at position k in the linear order. The assignment must be a permutation (all positions distinct). For each triple (a, b, c) ∈ C, element b must appear between a and c in the ordering.

Schema (data type)

Type name: Betweenness
Variants: none

Field Type Description
num_elements usize Number of elements in the finite set A
triples Vec<(usize, usize, usize)> Collection C of ordered triples (a, b, c) where b must be between a and c; elements are 0-based indices

Notes:

  • This is a feasibility (decision) problem: Value = Or.
  • Key getter methods: num_elements() (= |A|), num_triples() (= |C|).

Complexity

  • Decision complexity: NP-complete (Opatrný, 1979; transformation from SET SPLITTING). The related optimization problem (maximize satisfied triples) is MAX-SNP-hard (Chor & Sudan, 1998).
  • Best known exact algorithm: As a Permutation CSP of arity 3, solvable by Held-Karp style DP in O*(2^n) time and space. Naive approach: O(n!) by enumerating all permutations.
  • Concrete complexity expression: "2^num_elements" (for declare_variants!)
  • References:
    • J. Opatrný (1979). "Total Ordering Problem." SIAM J. Comput. 8(1), pp. 111-114.
    • B. Chor, M. Sudan (1998). "A Geometric Approach to Betweenness." SIAM J. Discrete Math. 11(4), pp. 511-523.

Extra Remark

Full book text:

INSTANCE: Finite set A, collection C of ordered triples (a,b,c) of distinct elements from A.
QUESTION: Is there a one-to-one function f: A→{1,2,...,|A|} such that for each (a,b,c) ∈ C, we have either f(a) < f(b) < f(c) or f(c) < f(b) < f(a)?
Reference: [Opatrný, 1978]. Transformation from SET SPLITTING.

How to solve

  • It can be solved by (existing) bruteforce. (Enumerate all |A|! permutations; for each, check that all betweenness triples are satisfied.)
  • It can be solved by reducing to integer programming. (Integer variables p_i ∈ {1,...,n} for positions, all-different constraints, and for each triple (a,b,c): introduce binary indicator to select between f(a)<f(b)<f(c) or f(c)<f(b)<f(a). Companion rule issue to be filed separately.)
  • Other:

Example Instance

Input:
A = {0, 1, 2, 3, 4} (5 elements)
C = {(0,1,2), (2,3,4), (0,2,4), (1,3,4)} — "b is between a and c"

Satisfying ordering: f = [0→0, 1→1, 2→2, 3→3, 4→4] (identity permutation):

  • (0,1,2): f(0)=0 < f(1)=1 < f(2)=2 ✓
  • (2,3,4): f(2)=2 < f(3)=3 < f(4)=4 ✓
  • (0,2,4): f(0)=0 < f(2)=2 < f(4)=4 ✓
  • (1,3,4): f(1)=1 < f(3)=3 < f(4)=4 ✓

Answer: YES — 2 valid orderings out of 120 (identity and reverse).

Non-satisfying ordering: f = [0→0, 1→2, 2→1, 3→3, 4→4]:

  • (0,1,2): f(0)=0 < f(1)=2 > f(2)=1, but f(2)=1 < f(1)=2 < f(0)=0 is false → 1 not between 0 and 2 ✗
Python validation script
from itertools import permutations

triples = [(0,1,2), (2,3,4), (0,2,4), (1,3,4)]
count = 0
for perm in permutations(range(5)):
    f = {i: perm[i] for i in range(5)}
    if all((f[a]<f[b]<f[c]) or (f[c]<f[b]<f[a]) for a,b,c in triples):
        count += 1

assert count == 2  # identity and reverse
print(f"Valid orderings: {count}/120")

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    Status

    Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions